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
 */

// accountType 账号类型 0:超级管理员 1:普通管理员 2:授权账号
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/home/index'),
        meta: { title: '首页', icon: 'el-icon-s-home' }
      }
    ]
  },
  {
    path: '/authAccount',
    component: Layout,
    meta: {
      accountType: [0, 1]
    },
    name: 'AuthAccount',
    children: [
      {
        path: 'index',
        name: 'AuthAccountIndex',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '授权账号列表', icon: 'dashboard', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/purchaser',
    component: Layout,
    redirect: '/purchaser/index',
    name: 'Purchaser',
    meta: { title: '购买方公司管理', icon: 'el-icon-s-shop', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'PurchaserIndex',
        component: () => import('@/views/purchaser/index'),
        meta: { title: '购买方公司管理', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/applicationType',
    component: Layout,
    redirect: '/applicationType/index',
    name: 'ApplicationType',
    meta: { title: '应用类型列表', icon: 'el-icon-bank-card', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'ApplicationTypeIndex',
        component: () => import('@/views/applicationType/index'),
        meta: { title: '应用类型列表', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/unitType',
    component: Layout,
    redirect: '/unitType/index',
    name: 'UnitType',
    meta: { title: '设备型号列表', icon: 'el-icon-set-up', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'UnitTypeIndex',
        component: () => import('@/views/unitType/index'),
        meta: { title: '设备型号列表', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/merchant',
    component: Layout,
    redirect: '/merchant/index',
    name: 'Merchant',
    meta: { title: '服务商平台管理', icon: 'el-icon-s-shop', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'MerchantIndex',
        component: () => import('@/views/merchant/index'),
        meta: { title: '服务商平台列表', accountType: [0, 1] }
      }
    ]
  },

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

  {
    path: '/userlib',
    component: Layout,
    redirect: '/userlib/index',
    name: 'UserLib',
    meta: { title: '用户库管理', icon: 'el-icon-user-solid', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'UserLibIndex',
        component: () => import('@/views/userlib/index'),
        meta: { title: '用户库列表', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/HHFaceDeviceList',
    component: Layout,
    name: 'HHFaceDeviceList',
    alwaysShow: true,
    meta: { title: 'HHFace设备授权管理', icon: 'el-icon-s-platform', accountType: [0, 1, 2], authType: ['HHFace'] },
    children: [
      {
        path: '/deviceTemplate/index',
        name: 'HHFaceDeviceListTemplate',
        component: () => import('@/views/HHFaceDeviceListTemplate/index.vue'),
        meta: { title: '配置模板管理', icon: 'el-icon-crop', accountType: [0, 1] }
      },
      {
        path: 'addTemplate',
        name: 'AddHHFaceDeviceListTemplate',
        hidden: true,
        component: () => import('@/views/HHFaceDeviceListTemplate/add'),
        meta: { title: '添加配置模板', accountType: [0, 1] }
      },
      {
        path: 'index',
        name: 'HHFaceDeviceListIndex',
        component: () => import('@/views/HHFaceDeviceList/index'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      },
      {
        path: 'add',
        name: 'HHFaceDeviceListAdd',
        hidden: true,
        component: () => import('@/views/HHFaceDeviceList/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      },
      {
        path: '/HHFaceDeviceAuth/index',
        name: 'HHFaceDeviceAuthIndex',
        component: () => import('@/views/HHFaceDeviceAuth/index.vue'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [2], authType: ['HHFace'] }
      }
    ]
  },
  {
    path: '/HHLocalDevice',
    component: Layout,
    name: 'HHLocalDevice',
    alwaysShow: true,
    meta: { title: 'HHLocal设备授权管理', icon: 'el-icon-s-shop', accountType: [0, 1] },
    children: [
      {
        path: '/HHLocalDeviceTemplate/index',
        name: 'HHLocalDeviceTemplate',
        component: () => import('@/views/HHLocalDeviceTemplate/index.vue'),
        meta: { title: '配置模板管理', icon: 'el-icon-crop', accountType: [0, 1] }
      },
      {
        path: 'addTemplate',
        name: 'AddHHLocalDeviceTemplate',
        hidden: true,
        component: () => import('@/views/HHLocalDeviceTemplate/add'),
        meta: { title: '添加配置模板', accountType: [0, 1] }
      },
      {
        path: 'index',
        name: 'HHLocalDeviceIndex',
        component: () => import('@/views/HHLocalDevice/index'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      },
      {
        path: 'add',
        name: 'HHLocalDeviceAdd',
        hidden: true,
        component: () => import('@/views/HHLocalDevice/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/HHCultureDevice',
    component: Layout,
    redirect: '/HHCultureDevice/index',
    name: 'HHCultureDevice',
    meta: { title: 'HHCulture设备授权管理', icon: 'el-icon-s-opportunity', accountType: [0, 1] },
    children: [
      {
        path: '/HHCultureDeviceTemplate/index',
        name: 'HHCultureDeviceTemplate',
        component: () => import('@/views/HHCultureDeviceTemplate/index.vue'),
        meta: { title: '配置模板管理', icon: 'el-icon-crop', accountType: [0, 1] }
      },
      {
        path: 'addTemplate',
        name: 'AddHHCultureTemplate',
        hidden: true,
        component: () => import('@/views/HHCultureDeviceTemplate/add'),
        meta: { title: '添加配置模板', accountType: [0, 1] }
      },
      {
        path: 'index',
        name: 'HHCultureDeviceIndex',
        component: () => import('@/views/HHCultureDevice/index'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      },
      {
        path: 'add',
        name: 'HHCultureDeviceAdd',
        hidden: true,
        component: () => import('@/views/HHCultureDevice/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/HHAromeDevice',
    component: Layout,
    alwaysShow: true,
    meta: { title: 'HHArome设备授权管理', icon: 'el-icon-copy-document', accountType: [0, 1, 2], authType: ['HHArome'] },
    children: [
      {
        path: '/HHAromeDeviceTemplate/index',
        name: 'HHAromeDeviceTemplate',
        component: () => import('@/views/HHAromeDeviceTemplate/index.vue'),
        meta: { title: '配置模板管理', icon: 'el-icon-crop', accountType: [0, 1] }
      },
      {
        path: 'addTemplate',
        name: 'AddHHAromeDeviceTemplate',
        hidden: true,
        component: () => import('@/views/HHAromeDeviceTemplate/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      },
      {
        path: '/AmpePlatform/index',
        name: 'AmpePlatform',
        component: () => import('@/views/AmpePlatform/index.vue'),
        meta: { title: 'Ampe平台列表', icon: 'el-icon-data-board', accountType: [0, 1] }
      },
      {
        path: '/HHAromeDevice/index',
        name: 'HHAromeDeviceIndex',
        component: () => import('@/views/HHAromeDevice/index.vue'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      },
      {
        path: 'add',
        name: 'AddHHAromeDevice',
        hidden: true,
        component: () => import('@/views/HHAromeDevice/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      },
      {
        path: '/HHAromeDeviceAuth/index',
        name: 'HHAromeDeviceAuthIndex',
        component: () => import('@/views/HHAromeDeviceAuth/index.vue'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [2], authType: ['HHArome'] }
      }
    ]
  },
  {
    path: '/FKJDeviceList',
    component: Layout,
    redirect: '/FKJDeviceList/index',
    name: 'FKJDeviceList',
    meta: { title: '访客机设备授权管理', icon: 'el-icon-files', accountType: [0, 1] },
    children: [
      {
        path: '/FKJDeviceListTemplate',
        name: 'FKJDeviceListTemplate',
        component: () => import('@/views/FKJDeviceListTemplate/index.vue'),
        meta: { title: '配置模板管理', icon: 'el-icon-crop', accountType: [0, 1] }
      },
      {
        path: '/FKJAddTemplate/add',
        name: 'FKJAddTemplate',
        hidden: true,
        component: () => import('@/views/FKJDeviceListTemplate/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      },
      {
        path: '/FKJIndex',
        name: 'FKJIndex',
        component: () => import('@/views/FKJDeviceList/index'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      },
      {
        path: '/FKJDeviceList/add',
        name: 'FKJAdd',
        hidden: true,
        component: () => import('@/views/FKJDeviceList/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/tempoIDManage',
    component: Layout,
    meta: { title: '临时身份证明管理', icon: 'el-icon-s-claim', accountType: [0, 1] },
    children: [
      {
        path: '/titleLib/index',
        name: 'TitleLib',
        component: () => import('@/views/tempoIDManage/titleLib/index'),
        meta: { title: '小程序授权配置', icon: 'el-icon-info', accountType: [0, 1] }
      },
      {
        path: '/tempoIDManageTemplate',
        name: 'TempoIDManageTemplate',
        component: () => import('@/views/tempoIDManageTemplate/index.vue'),
        meta: { title: '配置模板管理', icon: 'el-icon-crop', accountType: [0, 1] }
      },
      {
        path: '/tempoIDManageTemplate/add',
        name: 'AddTempoIDTemplate',
        hidden: true,
        component: () => import('@/views/tempoIDManageTemplate/add'),
        meta: { title: '添加配置模板', accountType: [0, 1] }
      },

      {
        path: 'index',
        name: 'TempoIDIndex',
        component: () => import('@/views/tempoIDManage/index'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      },
      {
        path: '/tempoIDManage/add',
        name: 'AddTempoID',
        hidden: true,
        component: () => import('@/views/tempoIDManage/add'),
        meta: { title: '添加设备', accountType: [0, 1] }
      }

      // {
      //   path: "/deviceLib/index",
      //   name: "deviceLib",
      //   component: () => import("@/views/tempoIDManage/deviceLib/index"),
      //   meta: { title: "设备配置列表", icon: "el-icon-document" },
      // },
    ]
  },
  {
    path: '/blacklist',
    component: Layout,
    name: 'Blacklist',
    meta: { title: '黑名单', icon: 'el-icon-user-solid', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/blacklist/index'),
        meta: { title: '黑名单', icon: 'el-icon-user-solid', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/installationTask',
    component: Layout,
    meta: { title: '升级安装管理', icon: 'el-icon-upload', accountType: [0, 1] },
    children: [
      {
        path: '/installationPackage/index',
        name: 'InstallationPackage',
        component: () => import('@/views/installationPackage/index'),
        meta: { title: '安装包列表', icon: 'el-icon-folder-opened', accountType: [0, 1] }
      },
      {
        path: '/installationTask/index',
        name: 'InstallationTask',
        component: () => import('@/views/installationTask/index'),
        meta: { title: '安装任务列表', icon: 'el-icon-document', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/auth',
    component: Layout,
    redirect: '/auth/index',
    name: 'Auth',
    meta: { title: '支付宝三要素授权管理', icon: 'el-icon-s-help', accountType: [0, 1] },
    children: [
      {
        path: 'index',
        name: 'AuthIndex',
        component: () => import('@/views/auth/index'),
        meta: { title: '支付宝三要素授权列表', accountType: [0, 1] }
      }
    ]
  },
  {
    path: '/tripartiteApi',
    component: Layout,
    meta: { title: '三方Api调用管理', icon: 'el-icon-cpu', accountType: [0, 1] },
    children: [
      {
        path: '/tripartiteApi/service',
        name: 'TripartiteApiService',
        component: () => import('@/views/tripartiteApi/service'),
        meta: { title: '服务权限管理', icon: 'el-icon-s-claim', accountType: [0, 1] }
      },
      {
        path: '/tripartiteApi/equipment',
        name: 'TripartiteApiEquipment',
        component: () => import('@/views/tripartiteApi/equipment'),
        meta: { title: '设备授权列表', icon: 'el-icon-suitcase-1', accountType: [0, 1] }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => {
  return 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
