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: '主板',
        component: () => import('@/views/dashboard/index'),
        meta: {
          title: '主板',
          icon: 'dashboard'
        }
      }
    ]
  },

  // // 404 page must be placed at the end !!!
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true
  // }
];

// TODO 上方菜单搬运下方，在meta追加roles
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/statistics',
    component: Layout,
    redirect: '/statistics/DownloadImage',
    name: '数据统计',
    meta: {
      title: '数据统计',
      icon: 'el-icon-s-help',
      roles: ['admin', 'operate']
    },
    children: [
      {
        path: 'DownloadImage',
        name: '下载照片',
        component: () => import('@/views/statistics/downloadImage/index'),
        meta: {
          title: '下载照片',
          // icon: 'table'
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'UploadImage',
        name: '上传照片',
        component: () => import('@/views/statistics/uploadImage/index'),
        meta: {
          title: '上传照片',
          // icon: 'tree'
          roles: ['admin', 'operate']
        }
      }
    ]
  },

  {
    path: '/photographerManagement',
    component: Layout,
    redirect: '/photographerManagement/PhotoVerify',
    name: '摄影师',
    meta: {
      title: '摄影师',
      icon: 'el-icon-s-help',
      roles: ['admin', 'photoer', 'photoer_management']
    },
    children: [
      {
        path: 'PhotoVerify',
        name: '摄影师', // add by 梁展鹏 20210723 因为只有一个菜单，所以暂时把菜单名称写到这里。实际上这里是"照片管理"
        component: () =>
        import('@/views/photographerManagement/photoVerify/index'),
        meta: {
          title: '摄影师',
          // icon: 'tree',
          roles: ['admin', 'photoer', 'photoer_management']
        }
      }
    ]
  },

  {
    path: '/photoManagement',
    component: Layout,
    redirect: '/photoManagement/ImageGoodsManagement',
    name: '图片库管理',
    meta: {
      title: '图片库管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'photo_management', 'photoer_management']
    },
    children: [
      {
        path: 'EventsList',
        name: '活动列表',
        component: () => import('@/views/photoManagement/eventsList/index'),
        meta: {
          title: '活动列表',
          // icon: 'tree',
          roles: ['admin', 'photoer_management']
        }
      },
      {
        path: 'ImageGoodsManagement',
        name: '照片商品管理',
        component: () =>
        import('@/views/photoManagement/imageGoodsManagement/index'),
        meta: {
          title: '照片商品管理',
          // icon: 'table',
          roles: ['admin', 'photo_management']
        }
      },
      {
        path: 'PhotoVerifyManagement',
        name: '上传照片审核',
        component: () =>
        import('@/views/photoManagement/photoVerifyManagement/index'),
        meta: {
          title: '上传照片审核',
          // icon: 'tree',
          roles: ['admin', 'photoer_management']
        }
      }
    ]
  },

  {
    path: '/certification-management',
    component: Layout,
    redirect: '/certification-management/PhotographerVerify',
    name: '认证管理',
    meta: {
      title: '认证管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'photoer_management', 'business']
    },
    children: [
      {
        path: 'PhotographerVerify',
        name: '摄影师认证审核',
        component: () =>
        import('@/views/photographerManagement/photographerVerify/index'),
        meta: {
          title: '摄影师认证审核',
          // icon: 'table',
          roles: ['admin', 'photoer_management']
        }
      },
      {
        path: 'SceneVerify',
        name: '场景审核',
        component: () => import('@/views/sceneManagement/sceneVerify/index'),
        meta: {
          title: '场景审核',
          // icon: 'tree',
          roles: ['admin', 'business']
        }
      },
      {
        path: 'SceneList',
        name: '场景列表',
        component: () => import('@/views/sceneManagement/sceneList/index'),
        meta: {
          title: '场景列表',
          // icon: 'table',
          roles: ['admin', 'business']
        }
      }
    ]
  },

  {
    path: '/memberManagement',
    component: Layout,
    redirect: '/memberManagement/MemberLever',
    name: '会员管理',
    meta: {
      title: '会员管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'operate']
    },
    children: [
      {
        path: 'MemberLever',
        name: '会员等级',
        component: () => import('@/views/memberManagement/memberLever/index'),
        meta: {
          title: '会员等级',
          // icon: 'table',
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'MemberList',
        name: '会员列表',
        component: () => import('@/views/memberManagement/memberList/index'),
        meta: {
          title: '会员列表',
          // icon: 'tree',
          roles: ['admin', 'operate']
        }
      }
    ]
  },

  {
    path: '/financialManagement',
    component: Layout,
    redirect: '/financialManagement/OrderManagement',
    name: '财务管理',
    meta: {
      title: '财务管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'finance']
    },
    children: [
      {
        path: 'OrderManagement',
        name: '订单列表',
        component: () =>
        import('@/views/financialManagement/orderManagement/index'),
        meta: {
          title: '订单列表',
          // icon: 'table',
          roles: ['admin', 'finance']
        }
      },
      {
        path: 'CashDetail',
        name: '用户资金明细',
        component: () => import('@/views/financialManagement/cashDetail/index'),
        meta: {
          title: '用户资金明细',
          // icon: 'tree',
          roles: ['admin', 'finance']
        }
      },
      {
        path: 'WithdrawalRecord',
        name: '提现记录',
        component: () => import('@/views/statistics/withdrawalRecord/index'),
        meta: {
          title: '提现记录',
          // icon: 'tree'
          roles: ['admin', 'finance']
        }
      },
      {
        path: 'PointsSetting',
        name: '积分设置',
        component: () => import('@/views/pointsManagement/pointsSetting/index'),
        meta: {
          title: '积分设置',
          // icon: 'tree',
          roles: ['admin', 'finance']
        }
      }
    ]
  },

  {
    path: '/pointsManagement',
    component: Layout,
    redirect: '/pointsManagement/PointsDetail',
    name: '积分管理',
    meta: {
      title: '积分管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'operate']
    },
    children: [
      {
        path: 'PointsDetail',
        name: '积分明细',
        component: () => import('@/views/pointsManagement/pointsDetail/index'),
        meta: {
          title: '积分明细',
          // icon: 'table',
          roles: ['admin', 'operate']
        }
      }
    ]
  },

  {
    path: '/baseManagement',
    component: Layout,
    redirect: '/baseManagement/BannerManagement',
    name: '基础管理',
    meta: {
      title: '基础管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'operate', 'designer']
    },
    children: [
      {
        path: 'TrendManagement',
        name: '热搜词管理',
        component: () => import('@/views/baseManagement/trending/index'),
        meta: {
          title: '热搜词管理',
          // icon: 'tree',
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'BannerManagement',
        name: 'Banner管理',
        component: () =>
        import('@/views/baseManagement/bannerManagement/index'),
        meta: {
          title: 'Banner管理',
          // icon: 'table',
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'InfoManagement',
        name: '资讯管理',
        component: () => import('@/views/baseManagement/infoManagement/index'),
        meta: {
          title: '资讯管理',
          // icon: 'tree',
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'ProblemFeedbackManagement',
        name: '问题管理',
        component: () =>
        import('@/views/baseManagement/problemFeedbackManagement/index'),
        meta: {
          title: '问题管理',
          // icon: 'tree',
          roles: ['admin', 'operate']
        }
      }
    ]
  },

  {
    path: '/systemManagement',
    component: Layout,
    redirect: '/systemManagement/AccountManagement',
    name: '系统管理',
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-help',
      roles: ['admin', 'operate']
    },
    children: [
      {
        path: 'AccountManagement',
        name: '账号列表',
        component: () =>
        import('@/views/systemManagement/accountManagement/index'),
        meta: {
          title: '账号列表',
          // icon: 'table',
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'RoleManagement',
        name: '角色列表',
        component: () =>
        import('@/views/systemManagement/roleManagement/index'),
        meta: {
          title: '角色列表',
          // icon: 'tree',
          roles: ['admin']
        }
      }
    ]
  },

  {
    path: '/helpInfo',
    component: Layout,
    redirect: '/helpInfo/IssueType',
    name: '帮助信息',
    meta: {
      title: '帮助信息',
      icon: 'el-icon-s-help',
      roles: ['admin', 'operate']
    },
    children: [
      {
        path: 'IssueType',
        name: '问题分类',
        component: () => import('@/views/helpInfo/issueType/index'),
        meta: {
          title: '问题分类',
          // icon: 'table',
          roles: ['admin', 'operate']
        }
      },
      {
        path: 'Information',
        name: '信息内容',
        component: () => import('@/views/helpInfo/information/index'),
        meta: {
          title: '信息内容',
          // icon: 'tree',
          roles: ['admin', 'operate']
        }
      }
    ]
  }
];

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;
