import {
  Globe,
  Github,
  Code,
  Terminal,
  FileText,
  Hammer,
  Play,
  Folder,
  Music,
  Image,
  Mail,
  Search,
  Zap,
  Star,
  Heart,
  Bookmark,
  Settings,
  Chrome,
  Cpu,
  Bot,
  Box,
  Cloud,
  Coffee,
  Calendar,
  Send,
  Download,
  Power,
  type LucideIcon,
} from "lucide-react";

/** 可在编辑器中选择的图标白名单（保持小而精，避免引入全量图标） */
export const ICON_OPTIONS: { name: string; Icon: LucideIcon }[] = [
  { name: "globe", Icon: Globe },
  { name: "github", Icon: Github },
  { name: "code", Icon: Code },
  { name: "terminal", Icon: Terminal },
  { name: "file-text", Icon: FileText },
  { name: "hammer", Icon: Hammer },
  { name: "play", Icon: Play },
  { name: "folder", Icon: Folder },
  { name: "music", Icon: Music },
  { name: "image", Icon: Image },
  { name: "mail", Icon: Mail },
  { name: "search", Icon: Search },
  { name: "zap", Icon: Zap },
  { name: "star", Icon: Star },
  { name: "heart", Icon: Heart },
  { name: "bookmark", Icon: Bookmark },
  { name: "settings", Icon: Settings },
  { name: "chrome", Icon: Chrome },
  { name: "cpu", Icon: Cpu },
  { name: "bot", Icon: Bot },
  { name: "box", Icon: Box },
  { name: "cloud", Icon: Cloud },
  { name: "coffee", Icon: Coffee },
  { name: "calendar", Icon: Calendar },
  { name: "send", Icon: Send },
  { name: "download", Icon: Download },
  { name: "power", Icon: Power },
];

const MAP: Record<string, LucideIcon> = ICON_OPTIONS.reduce(
  (acc, o) => ({ ...acc, [o.name]: o.Icon }),
  {} as Record<string, LucideIcon>
);

/** 根据 icon 名取组件，找不到时回退到 Zap */
export function getIcon(name: string | undefined): LucideIcon {
  if (!name) return Zap;
  return MAP[name] ?? Zap;
}
