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"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },

  {
    path: "/merchant",
    component: Layout,
    redirect: "/merchant/index",
    name: "merchant",
    meta: { title: "服务商平台管理", icon: "el-icon-s-shop" },
    children: [
      {
        path: "index",
        name: "index",
        component: () => import("@/views/merchant/index"),
        meta: { title: "服务商平台列表" },
      },
    ],
  },

  {
    path: "/scene",
    component: Layout,
    redirect: "/scene/index",
    name: "scene",
    meta: { title: "场景管理", icon: "el-icon-office-building" },
    children: [
      {
        path: "index",
        name: "index",
        component: () => import("@/views/scene/index"),
        meta: { title: "场景列表" },
      },
    ],
  },

  {
    path: "/userlib",
    component: Layout,
    redirect: "/userlib/index",
    name: "userlib",
    meta: { title: "用户库管理", icon: "el-icon-user-solid" },
    children: [
      {
        path: "index",
        name: "index",
        component: () => import("@/views/userlib/index"),
        meta: { title: "用户库列表" },
      },
    ],
  },

  {
    path: "/device",
    component: Layout,
    redirect: "/device/index",
    name: "device",
    meta: { title: "设备授权管理", icon: "el-icon-s-platform" },
    children: [
      {
        path: "index",
        name: "index",
        component: () => import("@/views/device/index"),
        meta: { title: "设备授权列表" },
      },
      {
        path: "add",
        name: "add",
        hidden: true,
        component: () => import("@/views/device/add"),
        meta: { title: "添加设备" },
      },
      {
        path: "change",
        name: "change",
        hidden: true,
        component: () => import("@/views/device/change"),
        meta: { title: "编辑设备" },
      },
    ],
  },

  {
    path: "/auth",
    component: Layout,
    redirect: "/auth/index",
    name: "auth",
    meta: { title: "支付宝三要素授权管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "index",
        name: "index",
        component: () => import("@/views/auth/index"),
        meta: { title: "支付宝三要素授权列表" },
      },
    ],
  },
  {
    path: "/tempoIDManage",
    component: Layout,
    meta: { title: "临时身份证明管理", icon: "el-icon-s-claim" },
    children: [
      {
        path: "/titleLib/index",
        name: "titleLib",
        component: () => import("@/views/tempoIDManage/titleLib/index"),
        meta: { title: "标题和须知列表", icon: "el-icon-info" },
      },
      {
        path: "/deviceLib/index",
        name: "deviceLib",
        component: () => import("@/views/tempoIDManage/deviceLib/index"),
        meta: { title: "设备配置列表", icon: "el-icon-document" },
      },
    ],
  },
  {
    path: "/K8ContainerList",
    component: Layout,
    children: [
      {
        path: "/K8ContainerList/index",
        name: "K8ContainerList",
        component: () => import("@/views/K8ContainerList/index.vue"),
        meta: { title: "K8小程序容器授权列表", icon: "el-icon-s-order" },
      },
    ],
  },
  {
    path: "/installationTask",
    component: Layout,
    meta: { title: "升级安装管理", icon: "el-icon-upload" },
    children: [
      {
        path: "/installationPackage/index",
        name: "installationPackage",
        component: () => import("@/views/installationPackage/index"),
        meta: { title: "安装包列表", icon: "el-icon-folder-opened" },
      },
      {
        path: "/installationTask/index",
        name: "installationTask",
        component: () => import("@/views/installationTask/index"),
        meta: { title: "安装任务列表", icon: "el-icon-document" },
      },
    ],
  },
  // {
  //   path: "/installationPackage",
  //   component: Layout,
  //   redirect: "/installationPackage/index",
  //   name: "installationPackage",
  //   meta: { title: "安装包列表", icon: "el-icon-folder-opened" },
  //   children: [
  //     {
  //       path: "index",
  //       name: "index",
  //       component: () => import("@/views/installationPackage/index"),
  //       meta: { title: "安装包列表" },
  //     },
  //   ],
  // },
  // {
  //   path: "/installationTask",
  //   component: Layout,
  //   redirect: "/installationTask/index",
  //   name: "installationTask",
  //   meta: { title: "安装任务列表", icon: "el-icon-document" },
  //   children: [
  //     {
  //       path: "index",
  //       name: "index",
  //       component: () => import("@/views/installationTask/index"),
  //       meta: { title: "安装任务列表" },
  //     },
  //   ],
  // },
  // 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;
