import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  {
    path: '/community',
    component: Layout,
    redirect: '/conmmunity/download',
    name: 'community-parent',
    alwaysShow: true,
    meta: { title: '社区数据', icon: 'zip' },
    children: [
      {
        path: 'community',
        component: () => import('@/views/community/communityTable'),
        name: 'community',
        meta: { title: '社区列表', icon: 'community' }
      },
      {
        path: '/user/management',
        component: () => import('@/views/community/user/index'),
        name: 'user-management',
        meta: { title: '用户列表', icon: 'user' }
      },
      {
        path: '/user/log',
        component: () => import('@/views/community/user/log/index'),
        name: 'user-log',
        meta: { title: '用户日志', icon: 'user' }
      }
    ]
  },

  {
    path: '/banner',
    component: Layout,
    redirect: '/banner/index',
    name: 'banner',
    alwaysShow: true,
    meta: { title: '运营数据', icon: 'zip' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/banner/index'),
        name: 'banner-index',
        meta: { title: 'banner运营', icon: 'banner' }
      },
      {
        path: '/banner/addBanner',
        component: () => import('@/views/banner/addBanner/index'),
        name: 'banner-add',
        hidden: true,
        meta: { title: '添加banner', icon: 'table' }
      },
      {
        path: '/banner/ediBanner',
        component: () => import('@/views/banner/ediBanner/index'),
        name: 'banner-edi',
        hidden: true,
        meta: { title: '修改banner', icon: 'table' }
      },
      {
        path: '/banner/infoBanner',
        component: () => import('@/views/banner/infoBanner/index'),
        name: 'banner-info',
        hidden: true,
        meta: { title: '查看banner', icon: 'table' }
      }
    ]
  },
  {
    path: '/account',
    component: Layout,
    redirect: '/account/index',
    name: 'account',
    alwaysShow: true,
    meta: { title: '账号管理', icon: 'zip' },
    children: [
      {
        path: '/account/user',
        component: () => import('@/views/account/user/index'),
        name: 'user-index',
        meta: { title: '员工管理', icon: 'table' }
      },
      {
        path: '/account/role',
        component: () => import('@/views/account/role/index'),
        name: 'role-index',
        meta: { title: '角色管理', icon: 'table' }
      },
      {
        path: '/account/role/add',
        component: () => import('@/views/account/role/add/index'),
        name: 'role-add',
        hidden: true,
        meta: { title: '添加角色', icon: 'table' }
      },
      {
        path: '/account/role/edi',
        component: () => import('@/views/account/role/edi/index'),
        name: 'role-edi',
        hidden: true,
        meta: { title: '修改角色', icon: 'table' }
      },
      {
        path: '/account/role/info',
        component: () => import('@/views/account/role/info/index'),
        name: 'role-info',
        hidden: true,
        meta: { title: '角色详情', icon: 'table' }
      },
      {
        path: '/account/user/addUser',
        component: () => import('@/views/account/user/addUser'),
        name: 'user-addUser',
        hidden: true,
        meta: { title: '添加成员', icon: 'table' }
      },
      {
        path: '/account/user/edit',
        component: () => import('@/views/account/user/edit'),
        name: 'user-edit',
        hidden: true,
        meta: { title: '添加成员', icon: 'table' }
      }
    ]
  }
]

export const currentRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '',
        component: () => import('@/views/index/index'),
        name: 'index',
        meta: { title: '首页', icon: 'index' }
      }
    ]
  }

  // { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: currentRouterMap
})
