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

import BasicVersionRoutes from './routes-basic-version'
import DJZVersionRoutes from './routes-djz-version'

Vue.use(Router)

/* Routes Config
* @meta
* icon: ''                      菜单图标（支持svg-icon、el-icon）
* title: ''                     菜单标题
* login: false                  是否需要登录
* ss: 'admin' || ['admin']    是否需要权限
* keep: false                   是否需要缓存（需要name才能生效）
* hidden: false                 是否显示在菜单
* open: false                   是否展开菜单（有子菜单前提下）
* redirectIndex: 0              重定向到第index位子菜单（有子菜单前提下）
* affix: false                  是否常驻在tagView组件上（外链无效）
*
* 新增
* dynamic                       动态做一些事情，是一个函数
*/

const getAsyncRoutes = () => {
    console.log('软件版本模式：')
    console.log(process.env.VUE_APP_VERSION_MODE)
    if (process.env.VUE_APP_VERSION_MODE === 'basic') {
        // 基础版本路由
        return BasicVersionRoutes
    } else if (process.env.VUE_APP_VERSION_MODE === 'djz') {
        // 代记账版本路由
        return DJZVersionRoutes
    } else {
        // 默认基础版本路由
        return BasicVersionRoutes
    }
}

// 异步路由
export const asyncRoutes = getAsyncRoutes();

// 本地路由
export const localRoutes = [
    {
        path: '',
        redirect: '/login'
    },
    {
        path: '/notice',
        component: () => import('@/components/notice/notice')
    },
    {
        path: '/login',
        component: () => import('@/pages/login/login')
    },
    {
        path: '/page401',
        component: () => import('@/pages/other/page401')
    },
    {
        path: '/page404',
        component: () => import('@/pages/other/page404')
    },
    {
        path: '/operating_instructions',
        component: () => import('@/pages/login/operating_instructions')
    },
    {
        path: '/red_letter_info_print',
        component: () => import('@/pages/invoice_management/components/red_letter_info_print')
    },
    {
        path: '/delivery',
        component: () => import('@/pages/invoice_delivery/invoice_delivery'),
        props: (route) => ({ invoiceReqFlowNo: route.query.invoiceReqFlowNo })
    },
]

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

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
