import { createRouter, createWebHashHistory } from 'vue-router'
import { $read } from '@/commons/utils'
import Loading from '@/pages/Loading.vue'
import Game1 from '@/pages/game1/Game.vue'
import Game2 from '@/pages/game2/Game.vue'
import Game3 from '@/pages/game3/Game3.vue'
import Game4 from '@/pages/game4/Game4.vue'
import Game5 from '@/pages/game5/Game5.vue'
import Game6 from '@/pages/game6/Game.vue'

const getWechatId = () => {
    return $read('token', '')
}

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/loading',
            name: 'Loading',
            component: Loading,
        },
        {
            path: '/game1',
            name: 'Game1',
            component: Game1,
        },
        {
            path: '/game2',
            name: 'Game2',
            component: Game2,
        },
        {
            path: '/game3',
            name: 'Game3',
            component: Game3,
        },
        {
            path: '/game4',
            name: 'Game4',
            component: Game4,
        },
        {
            path: '/game5',
            name: 'Game5',
            component: Game5,
        },
        {
            path: '/game6',
            name: 'Game6',
            component: Game6,
        }
    ],
})

router.beforeEach((to) => {
    const wechatId = getWechatId()

    if (to.meta.requiresAuth && !wechatId) {
        return '/login'
    }

    return true
})

export default router
