import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
  },
  {
    path: "/test",
    component: () => import("@/views/test/index"),
  },
  {
    path: "/screenHome",
    name:"screenHome",
    component: () => import("@/views/screenHome/index"),
  },
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "index",
        name: "dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "账号列表", role: [1, 2], icon: "el-icon-notebook-2" },
      },
    ],
  },
  {
    path: "/putStorage",
    component: Layout,
    children: [
      {
        path: "index",
        name: "putStorage",
        component: () => import("@/views/putStorage/index"),
        meta: { title: "组织架构", role: [2, 3], icon: "el-icon-s-help" },
      },
    ],
  },
  {
    path: "/personnelFiles",
    component: Layout,
    children: [
      {
        path: "index",
        name: "personnelFiles",
        component: () => import("@/views/personnelFiles/index"),
        meta: {
          title: "人员档案查询",
          role: [2, 3, 4],
          icon: "el-icon-notebook-2",
        },
      },
    ],
  },
  {
    path: "/personnelCarRecord",
    component: Layout,
    meta: {
      title: "人员/车辆行为记录",
      role: [2, 3, 4],
      icon: "el-icon-cpu",
    },
    children: [
      {
        path: "personnelGateRecord",
        name: "personnelGateRecord",
        component: () => import("@/views/personnelGateRecord/index"),
        meta: {
          title: "人员闸口记录",
          role: [2, 3, 4],
          icon: "el-icon-notebook-2",
        },
      },
      {
        path: "personnelCaptureRecord",
        name: "personnelCaptureRecord",
        component: () => import("@/views/personnelCaptureRecord/index"),
        meta: {
          title: "人员摄像头抓拍记录",
          role: [2, 3, 4],
          icon: "el-icon-notebook-2",
        },
      },
      {
        path: "personnelPortRecord",
        name: "personnelPortRecord",
        component: () => import("@/views/personnelPortRecord/index"),
        meta: {
          title: "人员进出港记录",
          role: [2, 3, 4],
          icon: "el-icon-notebook-2",
        },
      },
      {
        path: "carCaptureRecord",
        name: "carCaptureRecord",
        component: () => import("@/views/carCaptureRecord/index"),
        meta: {
          title: "车辆卡口记录",
          role: [2, 3, 4],
          icon: "el-icon-notebook-2",
        },
      },
    ],
  },
  {
    path: "/personnelCarWarning",
    component: Layout,
    meta: {
      title: "人员/车辆预警",
      role: [2, 3, 4],
      icon: "el-icon-cpu",
    },
    children: [
      {
        path: "personnelRecord",
        name: "personnelRecord",
        component: () => import("@/views/personnelRecord/index"),
        meta: {
          title: "人员预警记录",
          role: [2, 3, 4],
          icon: "el-icon-document",
        },
      },
      {
        path: "personnelManage",
        name: "personnelManage",
        component: () => import("@/views/personnelManage/index"),
        meta: {
          title: "人员布控名单配置",
          icon: "el-icon-s-platform",
          role: [2, 3, 4],
        },
      },
      {
        path: "personnelReview",
        name: "personnelReview",
        component: () => import("@/views/personnelReview/index"),
        meta: {
          title: "人员布控名单审核",
          icon: "el-icon-s-platform",
          role: [2, 3, 4],
        },
      },
      {
        path: "personnelWarningManage",
        name: "personnelWarningManage",
        component: () => import("@/views/personnelWarningManage/index"),
        meta: {
          title: "人员属性预警配置",
          icon: "el-icon-s-platform",
          role: [2],
        },
      },
      {
        path: "carRecord",
        name: "carRecord",
        component: () => import("@/views/carRecord/index"),
        meta: {
          title: "车牌号预警记录",
          icon: "el-icon-s-platform",
          role: [2, 3, 4],
        },
      },
      {
        path: "carManage",
        name: "carManage",
        component: () => import("@/views/carManage/index"),
        meta: {
          title: "车牌号布控配置",
          icon: "el-icon-s-platform",
          role: [2, 3, 4],
        },
      },
      {
        path: "carReview",
        name: "carReview",
        component: () => import("@/views/carReview/index"),
        meta: {
          title: "车牌号布控审核",
          icon: "el-icon-s-platform",
          role: [2, 3, 4],
        },
      },
      {
        path: "carWarningManage",
        name: "carWarningManage",
        component: () => import("@/views/carWarningManage/index"),
        meta: {
          title: "车辆属性预警配置",
          icon: "el-icon-s-platform",
          role: [2],
        },
      },
    ],
  },
  // {
  //   path: "/functionAuth",
  //   component: Layout,
  //   meta: {
  //     title: "单功能板块",
  //     role: [2, 3, 4],
  //     icon: "el-icon-cpu",
  //   },
  //   children: [
  //     {
  //       path: "uavAuth",
  //       name: "uavAuth",
  //       component: () => import("@/views/uavAuth/index"),
  //       meta: {
  //         title: "无人机反制",
  //         role: [2, 3, 4],
  //         icon: "el-icon-notebook-2",
  //       },
  //     },
  //     {
  //       path: "trafficLightsAuth",
  //       name: "trafficLightsAuth",
  //       component: () => import("@/views/trafficLightsAuth/index"),
  //       meta: {
  //         title: "红绿灯实时监控",
  //         role: [2, 3, 4],
  //         icon: "el-icon-notebook-2",
  //       },
  //     },
  //     {
  //       path: "rainSnowAuth",
  //       name: "rainSnowAuth",
  //       component: () => import("@/views/rainSnowAuth/index"),
  //       meta: {
  //         title: "冰冻雨雪监控",
  //         role: [2, 3, 4],
  //         icon: "el-icon-notebook-2",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/dutyList",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "index",
  //       name: "dutyList",
  //       component: () => import("@/views/dutyList/index"),
  //       meta: {
  //         title: "值班名单",
  //         icon: "el-icon-s-platform",
  //         role: [2, 3, 4],
  //       },
  //     },
  //   ],
  // },
  {
    path: "/screen",
    component: Layout,
    children: [
      {
        path: "index",
        name: "screen",
        component: () => import("@/views/screen/index"),
        meta: {
          title: "大屏",
          icon: "el-icon-s-platform",
          role: [2, 3, 4],
        },
      },
    ],
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  // 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();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
