import { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
import useUserStore from 'Store/modules/user'
import useCommonStore from 'Store/modules/common'
// import path from 'path'

// userStore.authLogin().then((res) => {
//   console.log(res)
// })
const whiteList = ['/login','/register', '/forgetPwd', '/accountStatus', '/accountStatus/fail', '/agreement', '/welcome', '/404']
export async function routerBeforeEachFunc(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) {
  const userStore = useUserStore()
  const commonStore = useCommonStore()
  console.log(to)
  // TODO 解除注释
  if (!userStore.token) {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  } else {
    // 获取全局字典 分类
    // commonStore.getCategory()
    // if (!data) return
    if (['/login', '/register', '/forgetPwd', '/welcome'].includes(to.path)) {
      // console.log('已登录')
      next({ path: '/dashboard', replace: true })
    } else {
      next()
    }
  }
  // console.log(userStore.token)
  // 路由进入前的操作
  next()
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function routerAfterEachFunc(to: RouteLocationNormalized, from: RouteLocationNormalized) {
  // 路由进入后的操作
}

