import { eRole } from '@/types/role'
import { iMenuConfigItem, iMenuList } from './types'
/* 
  无需显示在菜单中的路由需额外配置
    hiddeInMenu: true,
    belongToMenuName: 父路由的routeName,
*/
export const menuList: iMenuConfigItem[] = [
  {
    getName: () => '首页',
    onClick: (e: Event) => {},
    routeName: 'home',
    path: '/backend/home',
    component: () => import('@/views/Root/Home/index.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_branch,
      eRole.secondary_sub_branch,
      eRole.firstLevel_sub_clientManager,
      eRole.secondary_sub_clientManager,
    ],
  },
  {
    getName: () => 'Banner管理',
    onClick: (e: Event) => {},
    routeName: 'banner',
    path: '/backend/banner',
    component: () => import('@/views/Root/Banner/index.vue'),
    roles: [eRole.superManager],
  },
  // {
  //   getName: () => '产品管理',
  //   path: '/backend/product',
  //   routeName: 'productManagement',
  //   onClick: (e: Event) => {},
  //   getChildren: () => [
  //     {
  //       getName: () => '贷款产品',
  //       routeName: 'loan',
  //       path: '/backend/product/loan',
  //       hiddeInMenu: false,
  //       belongToMenuName: 'productManagement',
  //       component: () => import('@/views/Root/Banner/index.vue'),
  //       roles: [eRole.superManager],
  //       onClick: (e: Event) => {},
  //     },
  //     {
  //       getName: () => '理财产品',
  //       roles: [eRole.superManager],
  //       routeName: 'financialManagement',
  //       hiddeInMenu: false,
  //       path: '/backend/product/financialManagement',
  //       component: () => import('@/views/Root/Banner/index.vue'),
  //       onClick: (e: Event) => {},
  //     },
  //     {
  //       getName: () => '股权融资',
  //       roles: [eRole.superManager],
  //       routeName: 'equityFinancing',
  //       hiddeInMenu: false,
  //       path: '/backend/product/equityFinancing',
  //       component: () => import('@/views/Root/Banner/index.vue'),
  //       onClick: (e: Event) => {},
  //     },
  //   ],
  //   roles: [eRole.superManager],
  // },
  {
    getName: () => '用户管理',
    onClick: (e: Event) => {},
    routeName: 'userManage',
    path: '/backend/user',
    component: () => import('@/views/Root/User/index.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_branch,
      eRole.secondary_sub_branch,
    ],
  },
  {
    getName: () => '网点管理',
    routeName: 'outletManagement',
    path: '/backend/outletManagement',
    component: () => import('@/views/Root/OutletManagement/index.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.secondary_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_sub_branch,
      eRole.secondary_sub_clientManager,
      eRole.firstLevel_sub_clientManager,
    ],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '贷款产品管理',
    onClick: (e: Event) => {},
    routeName: 'loanProduct',
    path: '/backend/loanProduct',
    component: () => import('@/views/Root/Product/Loan/index.vue'),
    roles: [eRole.superManager],
  },
  {
    getName: () => '发布贷款产品',
    routeName: 'publishLoanProduct',
    hiddeInMenu: true,
    belongToMenuName: 'loanProduct',
    path: '/backend/loanProduct/publish',
    component: () => import('@/views/Root/Product/Loan/publish.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '编辑贷款产品',
    routeName: 'editLoanProduct',
    hiddeInMenu: true,
    belongToMenuName: 'loanProduct',
    path: '/backend/loanProduct/edit/:uuid',
    component: () => import('@/views/Root/Product/Loan/publish.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '一级支行客户名单',
    onClick: (e: Event) => {},
    routeName: 'firstSubClient',
    path: '/backend/user/firstSubClient',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/client.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_clientManager,
    ],
  },
  {
    getName: () => '一级分行搜索结果',
    onClick: (e: Event) => {},
    routeName: 'firstLevel',
    path: '/backend/user/firstLevel',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/firstLevel.vue'),
    roles: [eRole.superManager],
  },
  {
    getName: () => '二级分行搜索结果',
    onClick: (e: Event) => {},
    routeName: 'secondary',
    path: '/backend/user/secondary',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/secondary.vue'),
    roles: [eRole.superManager, eRole.firstLevel_branch],
  },
  {
    getName: () => '一级支行搜索结果',
    onClick: (e: Event) => {},
    routeName: 'firstSub',
    path: '/backend/user/firstSub',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/firstSub.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.secondary_branch,
    ],
  },
  {
    getName: () => '一级支行客户经理',
    onClick: (e: Event) => {},
    routeName: 'firstSubClientManager',
    path: '/backend/user/firstSubClientManager',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/firstSubClientManager.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_branch,
    ],
  },
  {
    getName: () => '二级支行管理',
    onClick: (e: Event) => {},
    routeName: 'secondarySub',
    path: '/backend/user/secondarySub',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/secondarySub.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.secondary_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_sub_branch,
    ],
  },
  {
    getName: () => '二级支行客户经理',
    onClick: (e: Event) => {},
    routeName: 'secondarySubClientManager',
    path: '/backend/user/secondarySubClientManager',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/secondarySubClientManager.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_sub_branch,
    ],
  },
  {
    getName: () => '二级支行客户名单',
    onClick: (e: Event) => {},
    routeName: 'secondarySubClient',
    path: '/backend/user/secondarySubClient',
    hiddeInMenu: true,
    belongToMenuName: 'userManage',
    component: () => import('@/views/Root/User/client.vue'),
    roles: [
      eRole.superManager,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_sub_branch,
      eRole.firstLevel_sub_clientManager,
      eRole.secondary_sub_clientManager,
    ],
  },
  {
    getName: () => '资讯管理',
    routeName: 'newsManage',
    onClick: (e: Event) => {},
    path: '/backend/user/staff',
    component: () => import('@/views/Root/News/index.vue'),
    roles: [eRole.superManager],
  },
  {
    getName: () => '发布内容',
    routeName: 'publishNews',
    hiddeInMenu: true,
    belongToMenuName: 'newsManage',
    path: '/backend/news/publish',
    component: () => import('@/views/Root/News/publish.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '查看新闻内容',
    routeName: 'newsDetail',
    hiddeInMenu: true,
    belongToMenuName: 'newsManage',
    path: '/backend/news/detail',
    component: () => import('@/views/Root/News/detail.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '消息管理',
    onClick: (e: Event) => {},
    routeName: 'msgManage',
    path: '/backend/msgManage',
    component: () => import('@/views/Root/Msg/index.vue'),
    roles: [eRole.superManager],
  },
  {
    getName: () => '活动管理',
    onClick: (e: Event) => {},
    routeName: 'activity',
    path: '/backend/activity',
    component: () => import('@/views/Root/Activity/index.vue'),
    roles: [eRole.superManager],
  },
  {
    getName: () => '用户管理',
    onClick: (e: Event) => {},
    routeName: 'platformUserManagement',
    path: '/backend/platformUserManagement',
    component: () => import('@/views/Root/Platform_UserManagement/index.vue'),
    roles: [eRole.platform_management],
  },
  {
    getName: () => '安全设置',
    onClick: (e: Event) => {},
    component: () => import('@/views/Root/Security/index.vue'),
    path: '/backend/security',
    getChildren: () => [
      {
        getName: () => '修改密码',
        routeName: 'changePwd',
        path: '/backend/security/changePwd',
        component: () => import('@/views/Root/Security/changePwd.vue'),
        roles: [
          eRole.superManager,
          eRole.platform_management,
          eRole.firstLevel_branch,
          eRole.firstLevel_sub_branch,
          eRole.secondary_branch,
          eRole.secondary_sub_branch,
          eRole.firstLevel_sub_clientManager,
          eRole.secondary_sub_clientManager,
        ],
        onClick: (e: Event) => {},
      },
      {
        getName: () => '换绑手机',
        routeName: 'changePhone',
        path: '/backend/security/changePhone',
        component: () => import('@/views/Root/Security/changePhone.vue'),
        onClick: (e: Event) => {},
        roles: [
          eRole.superManager,
          eRole.platform_management,
          eRole.firstLevel_branch,
          eRole.firstLevel_sub_branch,
          eRole.secondary_branch,
          eRole.secondary_sub_branch,
          eRole.firstLevel_sub_clientManager,
          eRole.secondary_sub_clientManager,
        ],
      },
    ],
    roles: [
      eRole.superManager,
      eRole.platform_management,
      eRole.firstLevel_branch,
      eRole.firstLevel_sub_branch,
      eRole.secondary_branch,
      eRole.secondary_sub_branch,
      eRole.firstLevel_sub_clientManager,
      eRole.secondary_sub_clientManager,
    ],
  },
  {
    getName: () => '聊天管理',
    onClick: (e: Event) => {},
    routeName: 'chat',
    path: '/backend/chat',
    component: () => import('@/views/Root/Chat/index.vue'),
    roles: [eRole.superManager],
  },
  {
    getName: () => '发布活动内容',
    routeName: 'publishActivity',
    hiddeInMenu: true,
    belongToMenuName: 'activity',
    path: '/backend/activity/publish',
    component: () => import('@/views/Root/Activity/publish.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '编辑活动内容',
    routeName: 'editActivity',
    hiddeInMenu: true,
    belongToMenuName: 'activity',
    path: '/backend/activity/edit/:uuid',
    component: () => import('@/views/Root/Activity/publish.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
  {
    getName: () => '查看活动内容',
    routeName: 'activityDetail',
    hiddeInMenu: true,
    belongToMenuName: 'activity',
    path: '/backend/activity/detail/:uuid',
    component: () => import('@/views/Root/Activity/detail.vue'),
    roles: [eRole.superManager],
    onClick: (e: Event) => {},
  },
]

export default function getMenuList(role: eRole): iMenuList {
  return menuList
    .filter((i) => {
      const visible = i.roles.includes(role)
      return visible
    })
    .map((i) => {
      const children = i.getChildren && i.getChildren()
      const { getChildren, ...rest } = i
      if (children && children.length !== 0) {
        return {
          ...rest,
          children: children.filter((c) => c.roles.includes(role)),
        }
      } else {
        return {
          ...rest,
        }
      }
    })
}
