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

Vue.use(Router)

// base
import baseRoutes from './module/base'

// 引入公共路由
import commonHelper from './module/common/helper'
import commonShare from './module/common/share'

// 管理员端路由
import adminSupplierRoutes from './module/admin/supplier'
import adminLogistics from './module/admin/logistics'
import admimAudit from './module/admin/audit'
import adminMember from './module/admin/member'
import adminSettings from './module/admin/settings'

// 供应商端路由
import normalAduit from './module/normal/audit'
import normalClub from './module/normal/club'
import normalFeedback from './module/normal/feedback'
import normalMaterial from './module/normal/material'
import docsRoutes from './module/normal/docs'
import normalPersonal from './module/normal/personal'
import normalPersonnel from './module/normal/personnel'
import normalVip from './module/normal/vip'
import normalUser from './module/normal/user'
import normalSettings from './module/normal/settings'

// 需要权限访问的路由列表
export const asyncRoutes = [
  ...commonHelper,
  ...adminSupplierRoutes,
  ...adminLogistics,
  ...admimAudit,
  ...adminMember,
  ...adminSettings,
  ...normalAduit,
  ...normalClub,
  ...normalFeedback,
  ...normalMaterial,
  ...docsRoutes,
  ...normalPersonal,
  ...normalPersonnel,
  ...normalSettings,
  ...normalUser
]

// 默认路由列表 全部用户都可以访问
export const constantRoutes = [...normalVip, ...commonShare, ...baseRoutes]

// 创建路由对象
const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
