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 asyncRoutes = [
  {
    path: '/organization',
    component: Layout,
    redirect: '/organization/list',
    name: 'organization',
    meta: { title: '组织管理', icon: 'tree', roles: ['Super admin', 'Admin'] },
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/organization/list'),
        meta: { title: '组织列表', icon: 'danglist' }
      },
      {
        path: 'detail',
        name: 'detail',
        component: () => import('@/views/organization/detail'),
        meta: { title: '组织详情', icon: 'model' },
        hidden: true
      }
    ]
  },
  {
    path: '/users',
    component: Layout,
    redirect: '/users/users_message',
    name: 'usersmessage',
    meta: { title: '个人信息', icon: 'geren', roles: ['Student'] },
    children: [{
      path: 'users_message',
      name: 'usersmessage',
      component: () => import('@/views/users/users_message'),
      meta: { title: '个人信息', icon: 'geren' }
    },
    {
      path: 'change_message',
      name: 'changemessage',
      component: () => import('@/views/users/change_message'),
      meta: { title: '完善个人信息', icon: 'geren' },
      hidden: true
    }
    ]
  },
  {
    path: '/personnel',
    component: Layout,
    redirect: '/personnel/index',
    name: 'personnel',
    meta: { title: '党员管理', icon: 'peoples', roles: ['Super admin', 'Admin'] },
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/personnel/index'),
      meta: { title: '党员管理', icon: 'peoples' }
    },
    {
      path: 'operation',
      name: 'operation',
      component: () => import('@/views/personnel/operation'),
      meta: { title: '编辑党员信息', icon: 'peoples' },
      hidden: true
    },
    {
      path: 'file_list',
      name: 'filelist',
      component: () => import('@/views/personnel/file_list'),
      meta: { title: '党员资料列表', icon: 'peoples' },
      hidden: true
    }

    ]
  },
  {
    path: '/process',
    component: Layout,
    redirect: '/process/apply',
    name: 'process',
    meta: { title: '党员流程管理', icon: 'dang', roles: ['Student', 'Super admin', 'Admin'] },
    children: [{
      path: 'apply',
      name: 'apply',
      component: () => import('@/views/process/apply'),
      meta: { title: '申请入党', icon: 'apply' }
    },

    {
      path: 'application',
      name: 'application',
      component: () => import('@/views/process/application'),
      meta: { title: '上传文件', icon: 'danyuan' },
      hidden: true
    },
    {
      path: 'apply_stu',
      name: 'student',
      component: () => import('@/views/process/apply_stu'),
      meta: { title: '文件列表', icon: 'danyuan' },
      hidden: true
    },
    {
      path: 'upload',
      name: 'upload',
      component: () => import('@/views/process/upload'),
      meta: { title: '上传文件', icon: 'danyuan' },
      hidden: true
    },
    {
      path: 'apply_list',
      name: 'applylist',
      component: () => import('@/views/process/apply_list'),
      meta: { title: '文件列表', icon: 'danyuan' },
      hidden: true
    },
    {
      path: 'activist',
      name: 'activist',
      component: () => import('@/views/process/activist'),
      meta: { title: '积极分子确定和培养', icon: 'activist' }
    },
    {
      path: 'develop_target',
      name: 'develop_target',
      component: () => import('@/views/process/develop_target'),
      meta: { title: '发展对象确定和考察', icon: 'develop' }
    },
    {
      path: 'prepare_accept',
      name: 'prepare_accept',
      component: () => import('@/views/process/prepare_accept'),
      meta: { title: '预备党员的接收', icon: 'accept' }
    },
    {
      path: 'prepare_process',
      name: 'prepare_process',
      component: () => import('@/views/process/prepare_process'),
      meta: { title: '预备党员考察和转正', icon: 'process' }
    }
    ]
  },
  {
    path: '/administrator',
    component: Layout,
    redirect: '/administrator',
    index: '',
    children: [{
      path: 'administrator',
      name: 'administrator',
      component: () => import('@/views/administrator/index'),
      meta: { title: '管理员管理', icon: 'admin', roles: ['Super admin'] }
    }]
    // Super admin
  },
  {
    path: '/administrator',
    component: Layout,
    redirect: '/administrator',
    index: '',
    children: [{
      path: 'student',
      name: 'students',
      component: () => import('@/views/administrator/student'),
      meta: { title: '学生管理', icon: 'admin', roles: ['Admin'] }
    }]
  },
  {
    path: '/setup',
    component: Layout,
    redirect: '/setup/system_set',
    name: 'setup',
    meta: { title: '系统配置', icon: 'setup', roles: ['Super admin', 'Admin'] },
    children: [{
      path: 'system_set',
      name: 'system_set',
      component: () => import('@/views/setup/system_set'),
      meta: { title: '系统设置', icon: 'systemset' },
      hidden: true
    },
    {
      path: 'template_set',
      name: 'template_set',
      component: () => import('@/views/setup/template_set'),
      meta: { title: '模板设置', icon: 'model' }
    }]
  },

  {
    path: '/reminder',
    component: Layout,
    redirect: '/reminder',
    index: '',
    children: [{
      path: 'reminder',
      name: 'reminder',
      component: () => import('@/views/reminder/index'),
      meta: { title: '消息提醒', icon: 'message', roles: ['Super admin', 'Admin'] }
    }]
  }
]

// 用户权限路由表
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'component' }
    }]
  },
  {
    path: '/users',
    component: Layout,
    redirect: '/users/reset_password',
    children: [{
      path: 'resetpassword',
      name: 'resetpassword',
      component: () => import('@/views/users/reset_password'),
      meta: { title: '修改密码', icon: 'component' },
      hidden: true
    }]
  },
  {
    path: '/transfer',
    component: Layout,
    redirect: '/transfer',
    children: [{
      path: 'transfer',
      name: 'transfer',
      component: () => import('@/views/transfer/index'),
      meta: { title: '组织转接', icon: 'zhuajnie' },
      hidden: true
    }]
  },
  {
    path: '/notice',
    component: Layout,
    redirect: '/notice',
    hidden: true,
    children: [{
      path: 'notice',
      name: 'notice',
      component: () => import('@/views/notice/notice'),
      meta: { title: '通知公告', icon: 'component' }
    }]
  }
  // {
  //   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,
  mode: 'history'
})

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
