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: '存证查询'
      }
    },
    {
      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:'/Copyright/List',
      name: 'CopyrightList',
      meta:{
        title: '版权认证',
        rightBtn: {
          text: '版权申请',
          path: '/Copyright/Step'
        }
      },
      component: () => import('@/view/NFT/Copyright/CopyrightList/index.vue')
    },
    {
      path:'/Copyright/Step',
      name: 'CopyrightStep',
      meta:{
        title: '版权认证'
      },
      component: () => import('@/view/NFT/Copyright/CopyrightStep/index.vue')
    },
    {
      path:'/Copyright/AddCprOwner',
      name: 'AddCprOwner',
      meta:{
        title: '新增著作权人'
      },
      component: () => import('@/view/NFT/Copyright/AddCprOwner/index.vue')
    },
    {
      path:'/Copyright/Res',
      name: 'CopyrightRes',
      meta:{
        title: '版权登记'
      },
      component: () => import('@/view/NFT/Copyright/CopyrightRes/index.vue')
    },
    {
      path:'/Copyright/Verified',
      name: 'CopyrightVerified',
      meta:{
        title: '实名认证'
      },
      component: () => import('@/view/NFT/Copyright/CopyrightVerified/index.vue')
    },
    {
      path:'/Copyright/Guarantee',
      name: 'CopyrightGuarantee',
      meta: {
        title: '权利保证书'
      },
      component: () => import('@/view/NFT/Copyright/Guarantee/index.vue')
    },
    {
      path: '/Copyright/PaperCer',
      name: 'CopyrightPaperCer',
      meta: {
        title: '申请纸质证书'
      },
      component: () => import('@/view/NFT/Copyright/PaperCer/index.vue')
    },
    {
      path: '/Copyright/CopyrightCer',
      name: 'CopyrightCer',
      meta: {
        title: '查看版权证书'
      },
      component: () => import('@/view/NFT/Copyright/CopyrightCer/index.vue')
    },
    {
      path:'/Collection',
      name: 'Collection',
      meta:{
        title: '我的收藏'
      },
      component: () => import('@/view/NFT/Collection/index.vue')
    },
    {
      path:'/Browser',
      name: 'Browser',
      meta:{
        title: '存证查询'
      },
      component: () => import('@/view/NFT/Browser/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:'/download',
    name:'Download',
    component: () => import("@/view/Download/index.vue"),
    meta:{
      title: 'app下载'
    }
  },
  {
    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
