import Vue          from 'vue';
import Router       from 'vue-router';
import { getAuth }  from '@/utils/auth';
import { getGuide } from '@/utils/guide';
import {
    getTenantCode, getSystemConfig,
    getUserIcon, shitiStatusControl,
    saveHistoryPaths,
}                   from '@/utils/common';

Vue.use(Router);

const aRootDisplay = {
    RYGL: '人员管理',
    PXGL: '培训管理',
    KWGL: '考务管理',
    ZSGL: '证书管理',
    LXGL: '练习管理',
    ZYGL: '资源管理',
    SJTJ: '数据统计',
    GGGL: '公告管理',
    XTSZ: '系统设置',
    FWGL: '服务管理',
};

const router = new Router({
                              mode:   'history',
                              base:   process.env.BASE_URL,
                              routes: [
                                  {
                                      path:     '/',
                                      redirect: '/index',
                                  },
                                  {
                                      name:      '首页',
                                      path:      '/index',
                                      component: () => {
                                          return import(/* webpackChunkName: "index" */ './views/client/Index.vue');
                                      },
                                  },
                                  {
                                      name:      '课程开发',
                                      path:      '/courseDev',
                                      component: () => {
                                          return import(/* webpackChunkName: "index" */ './views/client/CourseDev.vue');
                                      },
                                  },
                                  {
                                      name:      '首页',
                                      path:      '/Index',
                                      component: () => {
                                          return import(/* webpackChunkName: "index" */ './views/client/Index.vue');
                                      },
                                  },
                                  {
                                      name:      '首页',
                                      path:      '/Index',
                                      component: () => {
                                          return import(/* webpackChunkName: "index" */ './views/client/Index.vue');
                                      },
                                  },

                              ],
                          });

function dispatchScss(path) {
    if (!path) {
        return;
    }
    if (path.indexOf('/a/') > -1) {
        require('@/assets/css/main/main-a.scss');
    } else if (path.indexOf('/c/') > -1) {
        require('@/assets/css/main/main-c.scss');
    } else {
        require('@/assets/css/main/main-z.scss');
    }
}


router.beforeEach((to, from, next) => {
    dispatchScss(to.fullPath);
    getAuth();
    getGuide();
    // getTenantCode();
    getSystemConfig();
    if (getSystemConfig()) {
        document.title = getSystemConfig().logoText; //  describe: 更改title（刷新问题待优化） author: Wgy date:2019-12-04
    }
    //个人头像
    getUserIcon();
    shitiStatusControl(to);
    saveHistoryPaths(to, from, next);
    next();
});

export default router;
