import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/indexs',
    children: [{
      path: '/indexs',
      component: () => import('@/views/homePage/Index'),
      name: '首页',
      meta: {
        title: '首页',
        affix: true
      }

    }]
  },
//  {
//     path: '/jurisdiction',
//     component: Layout,
//     redirect: '/jurisdictionList',
//     meta: {
//       title: "权限管理"
//     },
//     children: [{
//         path: '/jurisdictionList',
//         component: () => import('@/views/jurisdiction/jurisdiction'),
//         name: '权限管理列表',
//         meta: {
//           title: '权限管理列表',
//           affix: false
//         }
//       },{
//         path: '/jurisdictionmodify',
//         component: () => import('@/views/jurisdiction/modify'),
//         name: '修改信息',
//         meta: {
//           title: '修改信息',
//           affix: false
//         },
//         hidden:true
//       },
//       {
//         path: '/jurisdictionadd',
//         component: () => import('@/views/jurisdiction/add'),
//         name: '添加账号',
//         meta: {
//           title: '添加账号',
//           affix: false
//         }
//       }
//     ]
//   }, {
//     path: '/shop',
//     component: Layout,
//     redirect: '/collection',
//     meta: {
//       title: "综合检索"
//     },
//     children: [{
//         path: '/retrievalcollection',
//         component: () => import('@/views/shop/collection'),
//         name: '藏品检索',
//         meta: {
//           title: '藏品检索',
//           affix: false
//         }
//       },
//       {
//         path: '/collectionInfo',
//         component: () => import('@/views/shop/collectionInfo'),
//         name: '藏品详情',
//         meta: {
//           title: '藏品详情',
//           affix: false
//         } ,
//         hidden:true
//       },
//       {
//         path: '/retrievalcommemorative',
//         component: () => import('@/views/shop/commemorative'),
//         name: '纪念币检索',
//         meta: {
//           title: '纪念币检索',
//           affix: false
//         }
//       },
//       {
//         path: '/editcommemo',
//         component: () => import('@/views/shop/editcommemo'),
//         name: '纪念币详情',
//         meta: {
//           title: '纪念币详情',
//           affix: false
//         },
//         hidden:true
//       }
//     ]
//   }, {
//     path: '/user',
//     component: Layout,
//     redirect: '/user',
//     meta: {
//       title: "藏品管理"
//     },
//     children: [{
//         path: '/addscollection',
//         component: () => import('@/views/user/collection'),
//         name: '新增藏品',
//         meta: {
//           title: '新增藏品',
//           affix: false
//         }
//       },
//       {
//         path: '/addscommemorative',
//         component: () => import('@/views/user/commemorative'),
//         name: '新增纪念币',
//         meta: {
//           title: '新增纪念币',
//           affix: false
//         }
//       }
//     ]
//   }, {
//     path: '/white',
//     component: Layout,
//     redirect: '/white',
//     meta: {
//       title: "流程管理"
//     },
//     children: [{
//         path: '/collectionout',
//         component: () => import('@/views/white/collectionout'),
//         name: '借出申请',
//         meta: {
//           title: '借出申请',
//           affix: false
//         }
//       },
//     //   {
//     //     path: '/collectionin',
//     //     component: () => import('@/views/white/collectionin'),
//     //     name: '藏品归还申请',
//     //     meta: {
//     //       title: '藏品归还申请',
//     //       affix: false
//     //     }
//     //   },
//       {
//         path: '/myprocess',
//         component: () => import('@/views/white/myprocess'),
//         name: '我的申请',
//         meta: {
//           title: '我的申请',
//           affix: false
//         }
//       },
//       {
//         path: '/collectionprocess',
//         component: () => import('@/views/white/collectionprocess'),
//         name: '审批',
//         meta: {
//           title: '审批',
//           affix: false
//         }
//       }
//     ]
//   }, {
//     path: '/adminlog',
//     component: Layout,
//     redirect: '/adminlog',
//     meta: {
//       title: "系统日志"
//     },
//     children: [{
//       path: '/adminlogs',
//       component: () => import('@/views/adminlog/adminlog'),
//       name: '系统日志',
//       meta: {
//         title: '系统日志',
//         affix: false
//       }
//     }]
//   }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

export const allRouters = []

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
