import { Jiesuanzonghetongji, JiesuanzonghetongjiFill } from '@firesoon/icons-react';
import { Menu } from '@firesoon/ant-ui/es/components/Sider/interface';

export type IMenu = Menu;
export const iconMap = {
  home: [Jiesuanzonghetongji, JiesuanzonghetongjiFill],
  drgAnalysis: [Jiesuanzonghetongji, JiesuanzonghetongjiFill],
  medicare: [Jiesuanzonghetongji, JiesuanzonghetongjiFill],
  setting: [Jiesuanzonghetongji, JiesuanzonghetongjiFill],
};

const menu: Array<Menu> = [
  {
    route: '/home',
    id: 'home',
    title: '首页',
    icons: iconMap.home,
  },
  {
    route: '/home/detail',
    id: 'homeDetail',
    title: '详情',
    isHide: true, // 不显示导航菜单
  },
  {
    route: '/analysis',
    id: 'drgAnalysis',
    title: 'DRG分析',
    icons: iconMap.setting,
    children: [
      {
        title: '科室DRG分析',
        id: 'deptAnalysis',
        route: '/analysis/dept',
        children: [
          {
            id: 'dept1',
            route: '/analysis/dept/hello',
            title: '三级菜单',
          },
        ],
      },
      {
        title: '病组DRG分析',
        id: 'dGroupAnalysis',
        route: '/analysis/diseaseGroup',
      },
      {
        title: '病例DRG分析',
        id: 'caseAnalysis',
        route: '/analysis/case',
      },
      {
        id: 'medicare',
        title: '医保结算管理',
        route: '/medicare',
        icons: iconMap.medicare,
        isHideChild: true,
        children: [
          {
            title: '科室结算编辑',
            id: 'medicareEdit',
            route: '/medicare/edit',
          },
        ],
      },
      {
        id: 'setting',
        route: '/setting',
        title: '系统设置',
        icons: iconMap.setting,
        children: [
          {
            route: '/setting/feeLimit',
            id: 'feeLimitSetting',
            title: '费用标准设置',
          },
          {
            route: '/setting/assess',
            id: 'assessSetting',
            title: '考核单位设置',
          },
        ],
      },
    ],
  },
];

export const originFlatMenu = treeToArray(menu);

export interface IAuthMenu {
  searchTree: Menu[] | [];
  tree: Menu[] | [];
}
// 用来保存权限菜单和用来搜索的flat菜单
export const authMenu: IAuthMenu = {
  searchTree: [],
  set tree(list) {
    this.innerTree = list;
    this.searchTree = treeToArray(list);
  },
  get tree() {
    return this.innerTree || [];
  },
};

function treeToArray(tree) {
  const arr: Array<any> = [];
  const loop = (data) => {
    data.forEach((k: any) => {
      if (k.children?.length) {
        arr.push(k);
        loop(k.children);
      } else {
        arr.push(k);
      }
    });
  };
  loop(tree);
  return arr;
}

export default menu;
