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,
    redirect:'/Home',
    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/index.vue'),
    redirect:'/Nft/create/form',
    children: [
      {
        path: '/Nft/create/form',
        name:'NftForm',
        component: () => import('@/view/NFT/Create/form.vue'),
        meta: {
          title: 'NFT发行'
        }
      },
      {
        path: '/Nft/create/pick',
        name:'NftPick',
        component: () => import('@/view/NFT/Create/pick.vue'),
        meta: {
          title: '剧本题材'
        }
      },
      {
        path: '/Nft/create/upload',
        name:'NftUpload',
        component: () => import('@/view/NFT/Create/upload.vue'),
        meta: {
          title: '剧本附件'
        }
      },
    ]
    },
    {
      path:'/Nft/MyList',
      name:'myListNft',
      component: () => import('@/view/NFT/Mynft/index.vue'),
      meta:{
        title: '我的NFT'
      }
    },
    {
      path:'/Nft/:id',
      name:'Nftdetail',
      component:()=> import('@/view/NFT/Detail/index.vue'),
      meta:{
        title: 'NFT详情'
      }
    },
    {
      path:'/Collection',
      name: 'Collection',
      meta:{
        title: '我的收藏'
      },
      component: () => import('@/view/NFT//Collection/index.vue')
    },
    {
      path:'/User',
      name:'User',
      meta: {
        title: '个人中心'
      },
      component: () => import('@/view/User/index.vue')
    },
    {
      path:'/User/edit/:type',
      name:'Edit',
      meta:{}
    },
  {
    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: 'Home' })
  } else {
    next()
  }
})

export default router
