/**
 * @author https://gitee.com/chu1204505056/vue-admin-better （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },

  {
    path: '/vab',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Vab',
    alwaysShow: true,
    meta: { title: '基本信息', icon: 'briefcase' },
    children: [
      {
        path: 'station',
        component: () => import('@/views/vab/station/index'),
        name: 'station',
        meta: {
          title: '场站信息',
          permissions: ['admin'],
        },
      },
      {
        path: 'inCompany',
        component: () => import('@/views/vab/inCompany/index'),
        name: 'inCompany',
        meta: {
          title: '公司信息',
          permissions: ['admin'],
        },
      },
    ],
  },
  {
    path: '/quartz',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Quartz',
    alwaysShow: true,
    meta: { title: '定时任务', icon: 'clock' },
    children: [
      {
        path: 'quartzInfo',
        component: () => import('@/views/quartz/quartzInfo/index'),
        name: 'quartzInfo',
        meta: {
          title: '定时任务',
          permissions: ['admin'],
        },
      },
      {
        path: 'quartzBase',
        component: () => import('@/views/quartz/quartzBase/index'),
        name: 'quartzBase',
        meta: {
          title: '任务初始',
          permissions: ['admin'],
        },
      },
    ],
  },

  {
    path: '/forecastData',
    component: Layout,
    redirect: '/forecastData',
    children: [
      {
        path: 'forecastData',
        name: 'forecastData',
        component: () => import('@/views/forecastData/index'),
        meta: {
          title: '数据查询', icon: 'bell',
        },
      },
    ],
  },
  {
    path: '/record',
    component: Layout,
    redirect: '/record',
    children: [
      {
        path: 'record',
        name: 'record',
        component: () => import('@/views/record/index'),
        meta: {
          title: '日志', icon: 'bell',
        },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
