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

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

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta:{title:'用户登录'},
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  { 
    path: '/', 
    redirect: '/power-change-monitoring',
    component: Layout,
    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: '/current-alarm',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/current-alarm/index'),
        name: 'StatisticalAnalysis',
        meta: { title: '当前告警', icon: 'tjfx', noCache: true }
      }
    ]
  },
  {
    path: '/Real-time-image',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/Real-time-image/index'),
        name: 'RealTimeImage',
        meta: { title: '实时影像', icon: 'tjfx',}
      }
    ]
  },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */

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
