import User from '../pages/User';
import Role from '../pages/Role';
import Button from '../pages/Button';
import File from '../pages/File';
import Config from '../pages/Config';
import Configuration from '../pages/Configuration';
import Menu from '../pages/Menu';
import Region from '../pages/Region';
import Org from '../pages/Org';
import Dept from '../pages/Dept';
import Doctor from '../pages/Doctor';
import Bed from '../pages/Bed';
import Login from '../pages/Login';
import Dict from '../pages/Dict';
import DictData from '../pages/Dict/Data';
import NotFound from '../pages/NotFound';
import { pathHolder } from './route';

// const Login = React.lazy(() => import('../pages/Login'));
// const User = React.lazy(() => import('../pages/User'));
// const Role = React.lazy(() => import('../pages/Role'));
// const Menu = React.lazy(() => import('../pages/Menu'));
// const File = React.lazy(() => import('../pages/File'));
// const Button = React.lazy(() => import('../pages/Button'));
// const Configuration = React.lazy(() => import('../pages/Configuration'));
// const Config = React.lazy(() => import('../pages/Config'));
// const Dict = React.lazy(() => import('../pages/Dict'));
// const DictData = React.lazy(() => import('../pages/Dict/Data'));
// const Bed = React.lazy(() => import('../pages/Bed'));
// const Dept = React.lazy(() => import('../pages/Dept'));
// const Doctor = React.lazy(() => import('../pages/Doctor'));
// const Org = React.lazy(() => import('../pages/Org'));
// const Region = React.lazy(() => import('../pages/Region'));

export default function patchRoutes(clientRoutes: any) {
  // 添加到第一层的不需要走layout组件
  const login = {
    path: '/login',
    component: Login,
  };
  const notFound = {
    path: '/notFound',
    component: NotFound,
  };
  const layoutBlackRoutes = [login, notFound].map((item) => ({
    ...item,
    path: pathHolder(item.path),
  }));
  clientRoutes.routes.unshift(...layoutBlackRoutes);

  // 需要走layout组件
  const layoutIndex = clientRoutes.routes.findIndex(
    (item: any) => item.path === '/',
  );

  const user = {
    path: '/administration/user',
    component: User,
    exact: true,
    name: '用户管理',
  };

  const role = {
    path: '/administration/role',
    component: Role,
    exact: true,
    name: '角色管理',
  };
  const menu = {
    path: '/administration/menu',
    component: Menu,
    exact: true,
    name: '菜单管理',
  };
  const file = {
    path: '/administration/file',
    component: File,
    exact: true,
    name: '资源管理',
  };
  const button = {
    path: '/administration/button',
    component: Button,
    exact: true,
    name: '按钮管理',
  };
  const configuration = {
    path: '/administration/configuration',
    component: Configuration,
    exact: true,
    name: '系统设置',
  };
  const config = {
    path: '/sysSetting/config',
    component: Config,
    exact: true,
    name: '平台设置',
  };
  const dict = {
    path: '/sysSetting/dict',
    component: Dict,
    exact: true,
    name: '字典类型管理',
  };
  const dictData = {
    path: '/sysSetting/dict/data',
    component: DictData,
    exact: true,
    name: '字典数据管理',
  };
  const bed = {
    path: '/masterdata/bed',
    component: Bed,
    exact: true,
    name: '床位管理',
  };
  const dept = {
    path: '/masterdata/dept',
    component: Dept,
    exact: true,
    name: '科室管理',
  };
  const doctor = {
    path: '/masterdata/doctor',
    component: Doctor,
    exact: true,
    name: '医护管理',
  };
  const org = {
    path: '/masterdata/org',
    component: Org,
    exact: true,
    name: '机构管理',
  };
  const region = {
    path: '/masterdata/region',
    component: Region,
    exact: true,
    name: '区划管理',
  };

  const layoutRoutes = [
    user,
    role,
    menu,
    file,
    button,
    configuration,
    config,
    dict,
    dictData,
    bed,
    dept,
    doctor,
    org,
    region,
  ].map((item) => ({
    ...item,
    path: pathHolder(item.path),
  }));
  clientRoutes.routes[layoutIndex]['routes'].push(...layoutRoutes);
}
