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
    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: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: { title: '首页', icon: 'dashboard'}
  //   }]
  // },
  // {
  //   path: '/goods',
  //   component: Layout,
  //   name: 'goods',
  //   meta: { title: '商品管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'goods_index',
  //       name: 'goods_index',
  //       component: () => import('@/views/goods/goods_index'),
  //       meta: { title: '商品列表', icon: 'form' }
  //     },
  //     {
  //       path: 'goods_add',
  //       name: 'goods_add',
  //       hidden: true,
  //       component: () => import('@/views/goods/goods_add'),
  //       meta: { title: '添加商品', icon: 'form', parent:{ name:'goods_index' }}
  //     },
  //     {
  //       path: 'classify_index',
  //       name: 'classify',
  //       component: () => import('@/views/goods/classify_index'),
  //       meta: { title: '分类管理', icon: 'form' }
  //     }
  //   ]
  // },
  // {
  //   path: '/order',
  //   component: Layout,
  //   name: 'order',
  //   meta: { title: '订单管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'order_list',
  //       name: 'order_list',
  //       component: () => import('@/views/order/order_list'),
  //       meta: { title: '订单列表', icon: 'form'}
  //     },
  //     {
  //       path: 'detail',
  //       name: 'detail',
  //       hidden: true,
  //       component: () => import('@/views/order/detail'),
  //       meta: { title: '订单详情', parent:{ name:'order_list' } },
  //     },
  //     {
  //       path: 'order_refund',
  //       name: 'order_refund',
  //       component: () => import('@/views/order/order_refund'),
  //       meta: { title: '维权订单', icon: 'form'},
  //     },
  //     {
  //       path: 'order_refund/order_refund_detail',
  //       name: 'order_refund_detail',
  //       hidden: true,
  //       component: () => import('@/views/order/order_refund_detail'),
  //       meta: { title: '维权详情', parent:{ name:'order_refund' } }
  //     },
  //     {
  //       path: 'invoice',
  //       name: 'invoice',
  //       component: () => import('@/views/order/invoice'),
  //       meta: { title: '开发票', icon: 'form' }
  //     }
  //   ]
  // },
  // {
  //   path: '/activity',
  //   component: Layout,
  //   name: 'activity',
  //   meta: { title: '活动管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'seckill_index',
  //       name: 'seckill_index',
  //       component: () => import('@/views/activity/seckill_index'),
  //       meta: { title: '秒杀活动', icon: 'form' }
  //     },
  //     {
  //       path: 'seckill_add',
  //       name: 'seckill_add',
  //       hidden: true,
  //       component: () => import('@/views/activity/seckill_add'),
  //       meta: { title: '添加商品', icon: 'form', parent:{ name:'seckill_index' }}
  //     },
  //     {
  //       path: 'coupon_index',
  //       name: 'coupon',
  //       component: () => import('@/views/activity/coupon_index'),
  //       meta: { title: '优惠券设置', icon: 'form' }
  //     }
  //   ]
  // },
  
  // {
  //   path: '/member',
  //   component: Layout,
  //   name: 'member',
  //   meta: { title: '会员管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'index',
  //       component: () => import('@/views/member/index'),
  //       meta: { title: '会员管理', icon: 'form' }
  //     }
  //   ]
  // },
  // {
  //   path: '/settlement',
  //   component: Layout,
  //   name: 'settlement',
  //   meta: { title: '结算管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'settlement_index',
  //       component: () => import('@/views/settlement/index'),
  //       meta: { title: '结算管理', icon: 'form' }
  //     }
  //   ]
  // },
  // {
  //   path: '/freight',
  //   component: Layout,
  //   name: 'freight',
  //   meta: { title: '配送管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'freight_index',
  //       component: () => import('@/views/freight/index'),
  //       meta: { title: '配送管理', icon: 'form' }
  //     }
  //   ]
  // },
  // {
  //   path: '/storage',
  //   component: Layout,
  //   name: 'storage',
  //   meta: { title: '仓储管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'storage_index',
  //       component: () => import('@/views/storage/index'),
  //       meta: { title: '仓储管理', icon: 'form' }
  //     }
  //   ]
  // },
  // {
  //   path: '/notice',
  //   component: Layout,
  //   name: 'notice',
  //   meta: { title: '消息中心', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'notice_index',
  //       component: () => import('@/views/notice/index'),
  //       meta: { title: '消息列表', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/setting',
  //   component: Layout,
  //   name: 'Setting',
  //   meta: { title: '系统设置', icon: 'el-icon-s-tools' },
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'personal',
  //       name: 'personal',
  //       component: () => import('@/views/setting/personal'),
  //       meta: { title: '个人信息', icon: 'table' }
  //     },
  //     {
  //       path: 'account',
  //       name: 'account',
  //       component: () => import('@/views/setting/account'),
  //       meta: { title: '账户管理', icon: 'table' }
  //     },
  //     {
  //       path: 'role',
  //       name: 'role',
  //       component: () => import('@/views/setting/role'),
  //       meta: { title: '权限管理', icon: 'table' }
  //     },
  //     {
  //       path: 'oplog',
  //       name: 'oplog',
  //       component: () => import('@/views/setting/oplog'),
  //       meta: { title: '操作日志', icon: 'table' }
  //     },
  //     {
  //       path: 'banner',
  //       name: 'banner',
  //       component: () => import('@/views/setting/banner'),
  //       meta: { title: '轮播图管理', icon: 'table' }
  //     }
  //   ]
  // },


  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

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
