import { token } from '@/util/userInfoUtils'
import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import App from '../App.vue'

Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
  {
    path: '/',
    name: 'App',
    component: App,
    children: [
      {
        path: '/Home',
        name: 'Home',
        component: () => import('@/view/Home/index.vue')
      },
      {
        path: '/Mine',
        name: 'Mine',
        component: () => import('@/view/Mine/index.vue')
      }
    ]
  },
  {
    path: '/Nft/create',
    name: 'createNft',
    component: () => import('@/view/NFT/Create.vue'),
    meta: {
      title: 'NFT发行'
    }
  },
  {
    path: '/auth',
    component: () => import("@/view/Auth/index.vue"),
    redirect: { name: 'Login' },
    children: [
      {
        path: '/auth/Login',
        name: 'Login',
        component: () => import("@/view/Auth/Login/index.vue")
      },
      // {
      //   path: '/auth/PwdSetting',
      //   name: 'PwdSetting',
      //   component: () => import("@/view/Auth/PwdSetting/index.vue")
      // },
      // {
      //   path: '/auth/PwdFind',
      //   name: 'PwdFind',
      //   component: () => import("@/view/Auth/PwdFind/index.vue")
      // },
      // {
      //   path: '/auth/PwdModify',
      //   name: 'PwdModify',
      //   component: () => import("@/view/Auth/PwdModify/index.vue")
      // },
    ]
  },
  {
    path: '*',
    redirect: { name: 'Home' }
  }
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.name !== 'Login' && token.getToken() === null) {
    next({ name: 'Login' })
  } else {
    next()
  }
})

export default router
