/**
 * 图标注册表 — 菜单图标名称 → React 组件的单一真相源
 *
 * 后端 menus.icon 字段存储图标名称字符串（如 "HomeOutlined"），
 * 前端通过此注册表将其转换为对应的 Ant Design 图标组件。
 *
 * 新增后端 seed 图标时必须同步在此添加映射，否则侧边栏回退为 AppstoreOutlined。
 */

import {
  HomeOutlined,
  UserOutlined,
  SafetyOutlined,
  ApartmentOutlined,
  SettingOutlined,
  PartitionOutlined,
  MessageOutlined,
  AppstoreOutlined,
  TeamOutlined,
  TableOutlined,
  TagsOutlined,
  HeartOutlined,
  CalendarOutlined,
  PhoneOutlined,
  CommentOutlined,
  MedicineBoxOutlined,
  TrophyOutlined,
  ShopOutlined,
  FileTextOutlined,
  DashboardOutlined,
  RobotOutlined,
  HistoryOutlined,
  BarChartOutlined,
  AlertOutlined,
  BellOutlined,
  ControlOutlined,
  InboxOutlined,
  ApiOutlined,
  ReadOutlined,
  ExperimentOutlined,
  // 以下为后端 seed 使用但原 iconMap 缺失的图标
  AuditOutlined,
  ClockCircleOutlined,
  FileSearchOutlined,
  FormOutlined,
  MonitorOutlined,
  PictureOutlined,
  SafetyCertificateOutlined,
  SolutionOutlined,
  SwapOutlined,
  WifiOutlined,
} from '@ant-design/icons';
import type { ReactNode } from 'react';

export const iconRegistry: Record<string, ReactNode> = {
  // 基础模块
  HomeOutlined: <HomeOutlined />,
  UserOutlined: <UserOutlined />,
  SafetyOutlined: <SafetyOutlined />,
  ApartmentOutlined: <ApartmentOutlined />,
  SettingOutlined: <SettingOutlined />,
  PartitionOutlined: <PartitionOutlined />,
  MessageOutlined: <MessageOutlined />,
  AppstoreOutlined: <AppstoreOutlined />,
  TeamOutlined: <TeamOutlined />,
  TableOutlined: <TableOutlined />,
  TagsOutlined: <TagsOutlined />,
  SearchOutlined: <AppstoreOutlined />, // 搜索无专属侧边栏图标

  // 健康模块
  HeartOutlined: <HeartOutlined />,
  CalendarOutlined: <CalendarOutlined />,
  PhoneOutlined: <PhoneOutlined />,
  CommentOutlined: <CommentOutlined />,
  MedicineBoxOutlined: <MedicineBoxOutlined />,
  TrophyOutlined: <TrophyOutlined />,
  ShopOutlined: <ShopOutlined />,
  FileTextOutlined: <FileTextOutlined />,
  DashboardOutlined: <DashboardOutlined />,
  RobotOutlined: <RobotOutlined />,
  HistoryOutlined: <HistoryOutlined />,
  BarChartOutlined: <BarChartOutlined />,
  AlertOutlined: <AlertOutlined />,
  BellOutlined: <BellOutlined />,
  ControlOutlined: <ControlOutlined />,
  InboxOutlined: <InboxOutlined />,
  ApiOutlined: <ApiOutlined />,
  ReadOutlined: <ReadOutlined />,
  ExperimentOutlined: <ExperimentOutlined />,

  // 健康模块（补充原缺失）
  AuditOutlined: <AuditOutlined />,
  ClockCircleOutlined: <ClockCircleOutlined />,
  FileSearchOutlined: <FileSearchOutlined />,
  FormOutlined: <FormOutlined />,
  MonitorOutlined: <MonitorOutlined />,
  PictureOutlined: <PictureOutlined />,
  SafetyCertificateOutlined: <SafetyCertificateOutlined />,
  SolutionOutlined: <SolutionOutlined />,
  SwapOutlined: <SwapOutlined />,
  WifiOutlined: <WifiOutlined />,
};

export function getIcon(name?: string): ReactNode {
  if (!name) return <AppstoreOutlined />;
  return iconRegistry[name] || <AppstoreOutlined />;
}
