/*
 * @Author: donghao donghao@supervision.ltd
 * @Date: 2024-03-29 17:42:08
 * @LastEditors: donghao donghao@supervision.ltd
 * @LastEditTime: 2024-04-01 14:52:43
 * @FilePath: \general\general-ai-manage\src\utils\FixMenuItemIcon.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 * @FixMenuItemIcon 菜单图标手动导入
 *
 *
 */
import {
  AreaChartOutlined,
  BellOutlined,
  BlockOutlined,
  BugOutlined,
  CalendarOutlined,
  CarOutlined,
  ContactsOutlined,
  DatabaseOutlined,
  DesktopOutlined,
  DollarCircleOutlined,
  DotChartOutlined,
  ExperimentOutlined,
  GatewayOutlined,
  HomeOutlined,
  PictureOutlined,
  SettingOutlined,
  ShopOutlined,
  TableOutlined,
  TeamOutlined,
  ThunderboltOutlined,
  UserOutlined,
  UserSwitchOutlined,
  WarningOutlined,
} from '@ant-design/icons';
import { MenuDataItem } from '@ant-design/pro-layout';
import { ReactComponent as TestIcon } from '../../public/icons/testIcon.svg';

const iconMap: any = {
  CarOutlined: <CarOutlined />,
  UserOutlined: <UserOutlined />,
  TableOutlined: <TableOutlined />,
  DollarCircleOutlined: <DollarCircleOutlined />,
  ShopOutlined: <ShopOutlined />,
  UserSwitchOutlined: <UserSwitchOutlined />,
  HomeOutlined: <HomeOutlined />,
  SettingOutlined: <SettingOutlined />,
  TeamOutlined: <TeamOutlined />,
  DotChartOutlined: <DotChartOutlined />,
  BlockOutlined: <BlockOutlined />,
  DesktopOutlined: <DesktopOutlined />,
  DatabaseOutlined: <DatabaseOutlined />,
  WarningOutlined: <WarningOutlined />,
  CalendarOutlined: <CalendarOutlined />,
  ExperimentOutlined: <ExperimentOutlined />,
  ThunderboltOutlined: <ThunderboltOutlined />,
  BugOutlined: <BugOutlined />,
  AreaChartOutlined: <AreaChartOutlined />,
  ContactsOutlined: <ContactsOutlined />,
  GatewayOutlined: <GatewayOutlined />,
  BellOutlined: <BellOutlined />,
  PictureOutlined: <PictureOutlined />,
  TestIcon: <TestIcon />,
};
// FIX从接口获取菜单时icon为string类型
const fixMenuItemIcon = (menus: MenuDataItem[]): MenuDataItem[] => {
  menus.forEach((item) => {
    const { icon, children } = item;
    if (typeof icon === 'string') {
      console.log(22, icon);
      if (icon in iconMap) {
        item.icon = iconMap[icon];
      } else {
        item.icon = '';
      }
      // let fixIconName = icon.slice(0, 1).toLocaleUpperCase() + icon.slice(1) + iconType;
      // // @ts-ignore
      // item.icon = React.createElement(allIcons[fixIconName] || allIcons[icon]);
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-expressions
    children && children.length > 0 ? (item.children = fixMenuItemIcon(children)) : null;
  });
  return menus;
};

export default fixMenuItemIcon;
