import type { LucideIcon } from "lucide-react";
import {
  ArmchairIcon,
  BrushIcon,
  CarFrontIcon,
  CarIcon,
  CogIcon,
  DropletsIcon,
  GemIcon,
  ShieldCheckIcon,
  SparklesIcon,
  SprayCanIcon,
  WindIcon,
} from "lucide-react";

/**
 * Wash package icons.
 *
 * `WashPackage.icon` is a free-text identifier backend-side (its DTO examples
 * are `exterior_wash` / `internal_external_wash`) — NOT a URL. The backend
 * stores whatever string it is given and never renders it, so the identifier →
 * glyph mapping is owned here, and this map is the list the admin picks from.
 *
 * Adding an option to the catalog form = adding one entry below, plus its
 * label under `catalog.icons.*` in both dictionaries.
 */
export const PACKAGE_ICONS = {
  external_wash: CarFrontIcon,
  interior_wash: ArmchairIcon,
  internal_external_wash: CarIcon,
  full_detail: SparklesIcon,
  polish: GemIcon,
  wax_coating: ShieldCheckIcon,
  engine_wash: CogIcon,
  steam_wash: DropletsIcon,
  dry_wash: WindIcon,
  upholstery: BrushIcon,
  add_on: SprayCanIcon,
} satisfies Record<string, LucideIcon>;

export type PackageIconId = keyof typeof PACKAGE_ICONS;

export const PACKAGE_ICON_IDS = Object.keys(PACKAGE_ICONS) as PackageIconId[];

/**
 * Identifiers that already exist in stored data but aren't offered in the
 * picker, so those rows still draw the right glyph.
 *
 * `exterior_wash` is the spelling in the backend's own DTO examples; the seed
 * writes `external_wash`. Both are in the wild — the seeded spelling is the
 * canonical one above, this covers anything created from the docs.
 */
const PACKAGE_ICON_ALIASES: Record<string, LucideIcon> = {
  exterior_wash: CarFrontIcon,
};

/**
 * Glyph for a stored identifier, falling back for anything not in the map —
 * the column is free text, so rows created outside this UI (seeds, direct DB
 * writes, a future admin tool) must still render something.
 */
export function getPackageIcon(icon: string | null): LucideIcon {
  if (!icon) return SparklesIcon;
  if (icon in PACKAGE_ICONS) return PACKAGE_ICONS[icon as PackageIconId];
  return PACKAGE_ICON_ALIASES[icon] ?? SparklesIcon;
}
