import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css' //这个样式必须引入
import Index from '@/views/index/index.vue'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/overview'
  },
  {
    path: '/view-video',
    name: 'view-video',
    component: () => import('@/views/equipment-center/video-surveillance/video.vue')
  },
  ,
  {
    path: '/big-screen/synthesis',
    name: 'synthesis',
    meta: {
      title: '综合显示'
    },
    component: () => import('@/views/big-screen/synthesis.vue')
  },
  {
    path: '/big-screen/single',
    name: 'single',
    meta: {
      title: '大屏显示'
    },
    component: () => import('@/views/big-screen/single.vue')
  },
  {
    path: '/',
    name: 'index',
    component: Index,
    children: [
      {
        path: '/overview',
        name: 'overview',
        meta: {
          title: '概览'
        },
        component: () => import('@/views/overview/index.vue')
      },
      {
        path: '/equipment-center/list/all-equipment',
        name: 'all-equipment',
        meta: {
          title: '全部设备'
        },
        component: () => import('@/views/equipment-center/list/all-equipment.vue')
      },
      {
        path: '/equipment-center/list',
        name: 'EquipmentCenter',
        meta: {
          title: '设备中心'
        },
        children: [
          {
            path: '/equipment-center/list',
            name: 'list',
            meta: {
              title: '设备列表'
            },
            component: () => import('@/views/equipment-center/list/index.vue')
          },
          {
            path: '/equipment-center/real-time-data',
            name: 'real-time-data',
            meta: {
              title: '实时数据',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/real-time-data/index.vue')
          },
          {
            path: '/equipment-center/european-gourd',
            name: 'european-gourd',
            meta: {
              title: '实时数据',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/real-time-data/european-gourd.vue')
          },
          {
            path: '/equipment-center/alarm-record',
            name: 'alarm-record',
            meta: {
              title: '报警记录',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/alarm-record/index.vue')
          },
          {
            path: '/equipment-center/history-data',
            name: 'history-data',
            meta: {
              title: '历史数据',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/history-data/index.vue')
          },
          {
            path: '/equipment-center/video-surveillance',
            name: 'video-surveillance',
            meta: {
              title: '视频监控',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/video-surveillance/index.vue')
          },
          {
            path: '/equipment-center/maintenance-record',
            name: 'maintenance-record',
            meta: {
              title: '维修记录',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/maintenance-record/index.vue')
          },
          {
            path: '/equipment-center/maintenance-record/details',
            name: 'maintenance-record-details',
            meta: {
              title: '维修记录',
              pitch: '/equipment-center/maintenance-record',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/maintenance-record/details.vue')
          },
          {
            path: '/equipment-center/statistic-analysis',
            name: 'statistic-analysis',
            meta: {
              title: '统计分析',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/statistic-analysis/index.vue')
          },
          {
            path: '/equipment-center/maintenance-schedule',
            name: 'maintenance-schedule',
            meta: {
              title: '维保计划',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/maintenance-schedule/index.vue')
          },
          {
            path: '/equipment-center/component-life',
            name: 'component-life',
            meta: {
              title: '部件寿命',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/component-life/index.vue')
          },
          {
            path: '/equipment-center/spare-part',
            name: 'spare-part',
            meta: {
              title: '备品备件',
              parent: '设备中心'
            },
            component: () => import('@/views/equipment-center/spare-part/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/user',
            name: 'user',
            meta: {
              title: '个人中心'
            },
            component: () => import('@/views/user/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/message-center',
            name: 'message',
            meta: {
              title: '消息中心'
            },
            component: () => import('@/views/message-center/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/equipment-map',
            name: 'equipment-map',
            meta: {
              title: '设备地图'
            },
            component: () => import('@/views/equipment-map/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/order-center/all-order',
            name: 'all-order',
            meta: {
              title: '全部工单',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/all-order/index.vue')
          },
          {
            path: '/order-center/my-order',
            name: 'my-order',
            meta: {
              title: '我的工单',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/my-order/index.vue')
          },
          {
            path: '/order-center/my-order/send-orders',
            name: 'send-orders',
            meta: {
              title: '待派单',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/my-order/send-orders.vue')
          },
          {
            path: '/order-center/my-order/take-orders',
            name: 'take-orders',
            meta: {
              title: '待接单',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/my-order/take-orders.vue')
          },
          {
            path: '/order-center/my-order/completed',
            name: 'completed',
            meta: {
              title: '待完成',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/my-order/completed.vue')
          },
          {
            path: '/order-center/my-order/audit',
            name: 'audit',
            meta: {
              title: '待审核',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/my-order/audit.vue')
          },
          {
            path: '/order-center/my-order/details',
            name: 'details',
            meta: {
              title: '工单详情',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/my-order/details.vue')
          },
          {
            path: '/order-center/knowledge-management',
            name: 'knowledge-management',
            meta: {
              title: '知识管理',
              parent: '工单中心'
            },
            component: () => import('@/views/order-center/knowledge-management/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/equipment-life',
            name: 'equipment-life',
            meta: {
              title: '设备寿命'
            },
            component: () => import('@/views/equipment-life/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/maintenance-plan',
            name: 'maintenance-plan',
            meta: {
              title: '维保计划'
            },
            component: () => import('@/views/maintenance-plan/index.vue')
          }
        ]
      },
      {
        path: '/',
        children: [
          {
            path: '/alarm-center/real-alarm',
            name: 'real-alarm',
            meta: {
              parent: '报警中心',
              title: '实时报警'
            },
            component: () => import('@/views/alarm-center/real-alarm/index.vue')
          },
          {
            path: '/alarm-center/history-alarm',
            name: 'history-alarm',
            meta: {
              parent: '报警中心',
              title: '历史报警'
            },
            component: () => import('@/views/alarm-center/history-alarm/index.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    meta: {
      title: '登录'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/login/index.vue')
  },
  {
    path: '/404',
    name: '404',
    meta: {
      title: '没有权限'
    },
    component: () => import('@/views/404.vue')
  },
  {
    path: '/:catchAll(.*)',
    redirect: '/404'
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  const token = localStorage.getItem('yz-Token')
  if (!token && to.path !== '/login') {
    next('/login')
  } else {
    next()
  }
  NProgress.done()
})

export default router
