import {
  Baby,
  BookOpen,
  CakeSlice,
  CarFront,
  Gift,
  GraduationCap,
  Hammer,
  Heart,
  House,
  Luggage,
  Map as MapIcon,
  Milk,
  PaintBucket,
  PartyPopper,
  Sofa,
  ToyBrick,
  Utensils,
  Users,
  WalletCards,
  Wrench,
  ShoppingBag,
  ShoppingCart,
} from "@lucide/vue";
import type { Component } from "vue";
import type { LedgerIconKey } from "@cents/domain";

export type LedgerIconOption = {
  key: LedgerIconKey;
  label: string;
  icon: Component;
};

export type LedgerIconPreset = {
  id: string;
  name: string;
  options: LedgerIconOption[];
};

export const ledgerIconPresets: LedgerIconPreset[] = [
  {
    id: "daily",
    name: "日常",
    options: [
      { key: "wallet", label: "钱包", icon: WalletCards },
      { key: "house", label: "家庭", icon: House },
      { key: "shopping-bag", label: "购物", icon: ShoppingBag },
      { key: "shopping-cart", label: "购物车", icon: ShoppingCart },
      { key: "utensils", label: "餐饮", icon: Utensils },
    ],
  },
  {
    id: "travel",
    name: "旅行",
    options: [
      { key: "luggage", label: "行李", icon: Luggage },
      { key: "map", label: "地图", icon: MapIcon },
    ],
  },
  {
    id: "parenting",
    name: "育儿",
    options: [
      { key: "baby", label: "育儿", icon: Baby },
      { key: "milk", label: "奶瓶", icon: Milk },
      { key: "heart", label: "关爱", icon: Heart },
      { key: "graduation-cap", label: "教育", icon: GraduationCap },
      { key: "toy-brick", label: "玩具", icon: ToyBrick },
    ],
  },
  {
    id: "gathering",
    name: "聚会",
    options: [
      { key: "party-popper", label: "庆祝", icon: PartyPopper },
      { key: "cake", label: "蛋糕", icon: CakeSlice },
      { key: "gift", label: "礼物", icon: Gift },
      { key: "users", label: "聚会", icon: Users },
    ],
  },
  {
    id: "renovation",
    name: "装修",
    options: [
      { key: "paint-bucket", label: "涂料", icon: PaintBucket },
      { key: "hammer", label: "施工", icon: Hammer },
      { key: "sofa", label: "家具", icon: Sofa },
      { key: "house", label: "家装", icon: House },
    ],
  },
  {
    id: "learning",
    name: "教育",
    options: [
      { key: "book-open", label: "书籍", icon: BookOpen },
      { key: "graduation-cap", label: "学业", icon: GraduationCap },
    ],
  },
  {
    id: "car-care",
    name: "养车",
    options: [
      { key: "car", label: "汽车", icon: CarFront },
      { key: "wrench", label: "维修", icon: Wrench },
    ],
  },
];

const ledgerIconMap = new Map<string, Component>(
  ledgerIconPresets.flatMap((preset) => preset.options.map((option) => [option.key, option.icon] as const)),
);

export function ledgerIconComponent(key?: LedgerIconKey | string) {
  return ledgerIconMap.get(key ?? "wallet") ?? ledgerIconMap.get("wallet")!;
}
