import {
  Beef,
  Beer,
  CakeSlice,
  ChefHat,
  Cherry,
  Citrus,
  Coffee,
  Cookie,
  CupSoda,
  Donut,
  EggFried,
  Fish,
  Flame,
  GlassWater,
  IceCreamCone,
  Leaf,
  Milk,
  Pizza,
  Salad,
  Sandwich,
  Soup,
  Sprout,
  Star,
  UtensilsCrossed,
  Wheat,
  Wine,
  type LucideIcon,
} from "lucide-react";

/** Visual variant for preset category icons */
export const CATEGORY_ICON_STYLES = [
  "flat",
  "modern",
  "real",
  "minimal",
  "outline",
  "soft",
  "bold",
  "gradient",
  "pastel",
  "duotone",
] as const;

export type CategoryIconStyleId = (typeof CATEGORY_ICON_STYLES)[number];

export function isCategoryIconStyle(value: string | null | undefined): value is CategoryIconStyleId {
  return CATEGORY_ICON_STYLES.includes(value as CategoryIconStyleId);
}

export type CategoryIconPresetKind = "drink" | "food";

export type CategoryIconPresetDef = {
  id: string;
  kind: CategoryIconPresetKind;
  icon: LucideIcon;
  /** Photo used when style is "real" */
  realImageUrl: string;
};

export const CATEGORY_ICON_PRESETS: CategoryIconPresetDef[] = [
  {
    id: "drinks-hot",
    kind: "drink",
    icon: Coffee,
    realImageUrl: "https://images.unsplash.com/photo-1509042239860-f550ce710b93?w=200&h=200&fit=crop",
  },
  {
    id: "drinks-cold",
    kind: "drink",
    icon: CupSoda,
    realImageUrl: "https://images.unsplash.com/photo-1517487881594-2787aeee8f58?w=200&h=200&fit=crop",
  },
  {
    id: "drinks-tea",
    kind: "drink",
    icon: GlassWater,
    realImageUrl: "https://images.unsplash.com/photo-1556679343-c7306c1976bc?w=200&h=200&fit=crop",
  },
  {
    id: "drinks-juice",
    kind: "drink",
    icon: Citrus,
    realImageUrl: "https://images.unsplash.com/photo-1523672990561-64c16245f769?w=200&h=200&fit=crop",
  },
  {
    id: "drinks-milkshake",
    kind: "drink",
    icon: Milk,
    realImageUrl: "https://images.unsplash.com/photo-1505252585463-0433371f7f6b?w=200&h=200&fit=crop",
  },
  {
    id: "drinks-alcohol",
    kind: "drink",
    icon: Wine,
    realImageUrl: "https://images.unsplash.com/photo-1510812431401-41d2bd2722f3?w=200&h=200&fit=crop",
  },
  {
    id: "drinks-beer",
    kind: "drink",
    icon: Beer,
    realImageUrl: "https://images.unsplash.com/photo-1608270586620-916524e5f405?w=200&h=200&fit=crop",
  },
  {
    id: "breakfast",
    kind: "food",
    icon: EggFried,
    realImageUrl: "https://images.unsplash.com/photo-1525351484343-752d43d363f1?w=200&h=200&fit=crop",
  },
  {
    id: "food-mains",
    kind: "food",
    icon: UtensilsCrossed,
    realImageUrl: "https://images.unsplash.com/photo-1546069901-ba9599a7e63c?w=200&h=200&fit=crop",
  },
  {
    id: "food-fastfood",
    kind: "food",
    icon: Sandwich,
    realImageUrl: "https://images.unsplash.com/photo-1568901346375-23c9450c58cd?w=200&h=200&fit=crop",
  },
  {
    id: "food-rice",
    kind: "food",
    icon: Wheat,
    realImageUrl: "https://images.unsplash.com/photo-1534084650011-4c4d81e8ca4b?w=200&h=200&fit=crop",
  },
  {
    id: "pasta-pizza",
    kind: "food",
    icon: Pizza,
    realImageUrl: "https://images.unsplash.com/photo-1513104890138-7c749659a591?w=200&h=200&fit=crop",
  },
  {
    id: "dessert",
    kind: "food",
    icon: CakeSlice,
    realImageUrl: "https://images.unsplash.com/photo-1578985545062-69928b1d9587?w=200&h=200&fit=crop",
  },
  {
    id: "ice-cream",
    kind: "food",
    icon: IceCreamCone,
    realImageUrl: "https://images.unsplash.com/photo-1563805042-7684c019e1cb?w=200&h=200&fit=crop",
  },
  {
    id: "bakery",
    kind: "food",
    icon: Cookie,
    realImageUrl: "https://images.unsplash.com/photo-1555507036342-9231d37c10f3?w=200&h=200&fit=crop",
  },
  {
    id: "salad",
    kind: "food",
    icon: Salad,
    realImageUrl: "https://images.unsplash.com/photo-1546793665-c74683f339c1?w=200&h=200&fit=crop",
  },
  {
    id: "grill",
    kind: "food",
    icon: Flame,
    realImageUrl: "https://images.unsplash.com/photo-1600891963295-d66a269b9202?w=200&h=200&fit=crop",
  },
  {
    id: "seafood",
    kind: "food",
    icon: Fish,
    realImageUrl: "https://images.unsplash.com/photo-1467003909585-2f8a72700288?w=200&h=200&fit=crop",
  },
  {
    id: "snacks",
    kind: "food",
    icon: Sandwich,
    realImageUrl: "https://images.unsplash.com/photo-1528735602780-2552fd46c7af?w=200&h=200&fit=crop",
  },
  {
    id: "snacks-sweet",
    kind: "food",
    icon: Donut,
    realImageUrl: "https://images.unsplash.com/photo-1551024506-0bccd28d3071?w=200&h=200&fit=crop",
  },
  {
    id: "appetizers",
    kind: "food",
    icon: Soup,
    realImageUrl: "https://images.unsplash.com/photo-1547592160-23ac45744acd?w=200&h=200&fit=crop",
  },
  {
    id: "vegan",
    kind: "food",
    icon: Sprout,
    realImageUrl: "https://images.unsplash.com/photo-1512621776951-a57141f2eefd?w=200&h=200&fit=crop",
  },
  {
    id: "fruits",
    kind: "food",
    icon: Cherry,
    realImageUrl: "https://images.unsplash.com/photo-1464965911861-746a04a4c36e?w=200&h=200&fit=crop",
  },
  {
    id: "specials",
    kind: "food",
    icon: Star,
    realImageUrl: "https://images.unsplash.com/photo-1504674900247-0877df9cc836?w=200&h=200&fit=crop",
  },
  {
    id: "chef-special",
    kind: "food",
    icon: ChefHat,
    realImageUrl: "https://images.unsplash.com/photo-1414235077428-338989a2e8c0?w=200&h=200&fit=crop",
  },
  {
    id: "generic",
    kind: "food",
    icon: Beef,
    realImageUrl: "https://images.unsplash.com/photo-1546069901-ba9599a7e63c?w=200&h=200&fit=crop",
  },
];

const presetById = new Map(CATEGORY_ICON_PRESETS.map((p) => [p.id, p]));

export function getCategoryIconPreset(presetId: string | null | undefined): CategoryIconPresetDef | null {
  if (!presetId) return null;
  return presetById.get(presetId) ?? null;
}

export const DEFAULT_CATEGORY_ICON_STYLE: CategoryIconStyleId = "flat";

export type CategoryIconStroke = { strokeWidth: number; className?: string };

export function getCategoryIconStroke(style: CategoryIconStyleId): CategoryIconStroke {
  switch (style) {
    case "minimal":
      return { strokeWidth: 1.35, className: "stroke-[1.35]" };
    case "outline":
      return { strokeWidth: 2.35 };
    case "bold":
      return { strokeWidth: 2.75 };
    case "soft":
    case "pastel":
      return { strokeWidth: 1.85 };
    case "duotone":
      return { strokeWidth: 2, className: "opacity-90" };
    default:
      return { strokeWidth: 2 };
  }
}
