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

Vue.use(Router)
/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  { path: '/', redirect: '/power-change-monitoring'},
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/power-change-monitoring',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/power-change-monitoring/index'),
        name: 'PowerChangeMonitoring',
        meta: { title: '换电监控', icon: 'hdjk' }
      }
    ]
  },
  {
    path: '/equipment-monitoring',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/equipment-monitoring/index'),
        name: 'EquipmentMonitoring',
        meta: { title: '设备监控', icon: 'sbjk'}
      }
    ]
  },
  {
    path: '/statistical-analysis',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/statistical-analysis/index'),
        name: 'StatisticalAnalysis',
        meta: { title: '统计分析', icon: 'tjfx', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/page',
    name: 'Permission',
    meta: {
      title: '站控管理',
      icon: 'zkgl',
      roles: ['admin', 'manage'] // you can set roles in root nav
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {title: '充电记录'}
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {title: '换电记录'}
      },
      {
        path: 'record-alarm',
        component: () => import('@/views/permission/record-alarm/index'),
        name: 'RecordAlarm',
        meta: {title: '告警记录'}
      },
      {
        path: 'car-manage',
        component: () => import('@/views/permission/car-manage/index'),
        name: 'CarManage',
        meta: {title: '车辆管理'}
      },
      {
        path: 'cartype-manage',
        component: () => import('@/views/permission/cartype-manage/index'),
        name: 'CarTypeManage',
        meta: {title: '车型管理'}
      },
      {
        path: 'driver-manage',
        component: () => import('@/views/permission/driver-manage/index'),
        name: 'DriverManage',
        meta: {title: '司机管理'}
      },
      {
        path: 'role',
        component: () => import('@/views/permission/role'),
        name: 'RolePermission',
        meta: {
          title: '账号管理',
          roles: ['admin']
        }
      },
      {
        path: 'updatepwd',
        hidden: true,
        component: () => import('@/views/permission/updatepwd'),
        name: 'UpdatePassword',
        meta: {title: '修改密码'}
      }
    ]
  },
  {
    path: '/manage-log',
    component: Layout,
    redirect: '/manage-log/robot',
    name: 'ManageLog',
    meta: {
      title: '日志管理',
      icon: 'rzgl'
    },
    children: [
      {
        path: 'robot',
        component: () => import('@/views/manage-log/robot'),
        name: 'Robot',
        meta: { title: '机器人' }
      },
      {
        path: 'battery-charger',
        component: () => import('@/views/manage-log/battery-charger'),
        name: 'BatteryCharger',
        meta: { title: '充电机' }
      },
      {
        path: 'bms',
        component: () => import('@/views/manage-log/bms'),
        name: 'Bms',
        meta: { title: 'BMS' }
      },
      {
        path: 'change-record',
        component: () => import('@/views/manage-log/change-record'),
        name: 'ChangeRecord',
        meta: { title: '换电记录' }
      }
    ]
  },
  {
    path: '/control-config',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/control-config/index'),
        name: 'ControlConfig',
        meta: { title: '控制配置', icon: 'kzpz', }
      }
    ]
  },
  /** when your routing map is too long, you can split it into small modules **/

  // 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()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
