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
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  { 
    path: '/', 
    redirect: '/equipment-monitoring',
    component: Layout,
    hidden: true,
  },
  {
    path: '/equipment-monitoring',
    component: Layout,
    children: [
      {
        path: '/',
        component: () => import('@/views/equipment-monitoring/index'),
        name: 'EquipmentMonitoring',
        meta: { title: '设备监控'}
      },
      {
        path: '/manage-log/robot',
        component: () => import('@/views/manage-log/robot'),
        name: 'Robot',
        meta: { title: '机器人日志' }
      },
      {
        path: '/manage-log/battery-charger',
        component: () => import('@/views/manage-log/battery-charger'),
        name: 'BatteryCharger',
        meta: { title: '充电机日志' }
      },
      {
        path: '/manage-log/bms',
        component: () => import('@/views/manage-log/bms'),
        name: 'Bms',
        meta: { title: 'BMS日志' }
      },
      {
        path: '/manage-log/data-export',
        component: () => import('@/views/manage-log/data-export'),
        name: 'DataExport',
        meta: { title: '数据导出' }
      },
    ]
  },
]

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
