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/transfer',
      name:'NftTransfer',
      component: () => import('@/view/NFT/Transfer/index.vue'),
      redirect:'/Nft/transfer/form',
      children:[
        {
          path:'/Nft/transfer/form',
          name:'NftTransfer_form',
          component: () => import('@/view/NFT/Transfer/form.vue'),
          meta:{
            title: 'NFT转让'
          },
        },
        {
          path:'/Nft/transfer/confirm',
          name:'NftTransfer_confirm',
          component: () => import('@/view/NFT/Transfer/confirm.vue'),
          meta:{
            title: '确认信息'
          },
        },
      ]
    },
    {
      path:'/Nft/transfer/camera',
      name:'NftTransferCamera',
      component: () => import('@/view/NFT/Transfer/camera.vue'),
      meta:{
        title: 'NFT转让扫描'
      }
    },
    {
      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:'/TransferList',
      name: 'TransferList',
      meta:{
        title: '转让记录'
      },
      component: () => import('@/view/NFT/TransferList/index.vue')
    },
    {
      path:'/TransferDetail/:id',
      name: 'TransferDetail',
      meta:{
        title: '转让详情'
      },
      component: () => import('@/view/NFT/TransferDetail/index.vue')
    },
    {
      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:'/UserDetail',
      name:'UserDetail',
      meta: {
        title: '用户中心'
      },
      component: () => import('@/view/UserDetail/index.vue')
    },
    {
      path:'/User/edit/:type',
      name:'Edit',
      component:()=>import('@/view/User/Edit.vue'),
      meta:{
        title:''
      }
    },
    {
      path:'/photo/edit',
      name:'PhotoEdit',
      component:()=>import('@/view/Other/PhotoEdit.vue'),
      meta:{
        title:'上传头像'
      }
    },
  {
    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:'/deving',
    name:'Deving',
    component: () => import("@/view/Other/Ondev.vue"),
    meta:{
      title: '该功能未开放'
    }
  },
  {
    path:'/safe',
    name:'Safe',
    component: () => import("@/view/Safe/Safe.vue"),
    meta:{
      title: '安全中心'
    },
  },
  {
    path:'/certificationPersion',
    name:'CertificationPersion',
    component: ()=>import("@/view/Safe/CertificationPersion.vue"),
    meta:{
      title: '实名认证'
    },
  },
  {
    path:'/contact',
    name:'Contact',
    component: () => import("@/view/Other/Contact.vue"),
    meta:{
      title: '联系我们'
    }
  },
  {
    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
