import type { ThemeConfig } from "@menulio/shared";

export interface ThemePreset {
  key: string;
  name: string;
  fontFamily: "serif" | "sans" | "heading";
  config: ThemeConfig;
  cardBg: string;
  cardBorder: string;
  textPrimary: string;
  textSecondary: string;
  accentBg: string;
  headerGradient: string;
  badgeBg: string;
  badgeText: string;
}

export const THEME_PRESETS: Record<string, ThemePreset> = {
  coastal: {
    key: "coastal",
    name: "Eleia Coastal Kitchen",
    fontFamily: "serif",
    config: {
      primaryColor: "#BF614B",
      background: "#F7F3EC",
      productLayout: "card",
      categoryLayout: "tabs",
      headerLayout: "centered",
    },
    cardBg: "#FCFAF6",
    cardBorder: "#E4DBCF",
    textPrimary: "#1A1615",
    textSecondary: "#6B635B",
    accentBg: "rgba(101, 109, 74, 0.12)",
    headerGradient: "linear-gradient(180deg, #2D231E 0%, #1A1615 100%)",
    badgeBg: "#656D4A",
    badgeText: "#FFFFFF",
  },
  neon: {
    key: "neon",
    name: "Neon Street Fuze",
    fontFamily: "heading",
    config: {
      primaryColor: "#FF2A85",
      background: "#0D1117",
      productLayout: "card",
      categoryLayout: "tabs",
      headerLayout: "left",
    },
    cardBg: "#FCF7EC",
    cardBorder: "rgba(255, 42, 133, 0.3)",
    textPrimary: "#101419",
    textSecondary: "#4B5563",
    accentBg: "rgba(0, 255, 135, 0.15)",
    headerGradient: "linear-gradient(180deg, #161B22 0%, #0D1117 100%)",
    badgeBg: "#0070F3",
    badgeText: "#FFFFFF",
  },
  maison: {
    key: "maison",
    name: "La Maison d'Élève",
    fontFamily: "serif",
    config: {
      primaryColor: "#24463A",
      background: "#EEEAE4",
      productLayout: "card",
      categoryLayout: "tabs",
      headerLayout: "centered",
    },
    cardBg: "#F7F4EF",
    cardBorder: "rgba(36, 70, 58, 0.2)",
    textPrimary: "#1A1A1A",
    textSecondary: "#5C5852",
    accentBg: "rgba(36, 70, 58, 0.08)",
    headerGradient: "linear-gradient(180deg, #182C24 0%, #11201A 100%)",
    badgeBg: "#E3DDD4",
    badgeText: "#24463A",
  },
  swiss: {
    key: "swiss",
    name: "Swiss Brutalist",
    fontFamily: "heading",
    config: {
      primaryColor: "#000000",
      background: "#FFFFFF",
      productLayout: "card",
      categoryLayout: "tabs",
      headerLayout: "left",
    },
    cardBg: "#FFFFFF",
    cardBorder: "#000000",
    textPrimary: "#000000",
    textSecondary: "#666666",
    accentBg: "#F0F0F0",
    headerGradient: "linear-gradient(180deg, #000000 0%, #111111 100%)",
    badgeBg: "#000000",
    badgeText: "#FFFFFF",
  },
  artisan: {
    key: "artisan",
    name: "Amber Artisan",
    fontFamily: "heading",
    config: {
      primaryColor: "#E5A855",
      background: "#121316",
      productLayout: "card",
      categoryLayout: "tabs",
      headerLayout: "centered",
    },
    cardBg: "#1C1E24",
    cardBorder: "rgba(255, 255, 255, 0.08)",
    textPrimary: "#FFFFFF",
    textSecondary: "#9DA3AF",
    accentBg: "rgba(229, 168, 85, 0.14)",
    headerGradient: "linear-gradient(180deg, #1A1C22 0%, #121316 100%)",
    badgeBg: "#282B34",
    badgeText: "#E5A855",
  },
  elegant: {
    key: "elegant",
    name: "Elegant Gold",
    fontFamily: "serif",
    config: {
      primaryColor: "#C8A96B",
      background: "#FAF8F5",
      productLayout: "card",
      categoryLayout: "accordion",
      headerLayout: "centered",
    },
    cardBg: "#FFFFFF",
    cardBorder: "rgba(200, 169, 107, 0.18)",
    textPrimary: "#1C1917",
    textSecondary: "#78716C",
    accentBg: "rgba(200, 169, 107, 0.12)",
    headerGradient: "linear-gradient(180deg, #1C1917 0%, #292524 100%)",
    badgeBg: "#F5F0E6",
    badgeText: "#926E27",
  },
  modern: {
    key: "modern",
    name: "Modern Sapphire",
    fontFamily: "sans",
    config: {
      primaryColor: "#2563EB",
      background: "#F8FAFC",
      productLayout: "card",
      categoryLayout: "tabs",
      headerLayout: "left",
    },
    cardBg: "#FFFFFF",
    cardBorder: "rgba(226, 232, 240, 0.9)",
    textPrimary: "#0F172A",
    textSecondary: "#64748B",
    accentBg: "rgba(37, 99, 235, 0.08)",
    headerGradient: "linear-gradient(135deg, #1E293B 0%, #0F172A 100%)",
    badgeBg: "#EFF6FF",
    badgeText: "#1D4ED8",
  },
  dark: {
    key: "dark",
    name: "Luxury Dark",
    fontFamily: "heading",
    config: {
      primaryColor: "#F59E0B",
      background: "#0F0F12",
      productLayout: "card",
      categoryLayout: "accordion",
      headerLayout: "centered",
    },
    cardBg: "#18181D",
    cardBorder: "rgba(255, 255, 255, 0.07)",
    textPrimary: "#F8FAFC",
    textSecondary: "#94A3B8",
    accentBg: "rgba(245, 158, 11, 0.12)",
    headerGradient: "linear-gradient(180deg, #09090B 0%, #18181B 100%)",
    badgeBg: "#27272A",
    badgeText: "#FBBF24",
  },
  minimal: {
    key: "minimal",
    name: "Nordic Minimal",
    fontFamily: "sans",
    config: {
      primaryColor: "#18181B",
      background: "#FAFAFA",
      productLayout: "list",
      categoryLayout: "flat",
      headerLayout: "left",
    },
    cardBg: "#FFFFFF",
    cardBorder: "#E4E4E7",
    textPrimary: "#18181B",
    textSecondary: "#71717A",
    accentBg: "#F4F4F5",
    headerGradient: "linear-gradient(180deg, #27272A 0%, #18181B 100%)",
    badgeBg: "#F4F4F5",
    badgeText: "#27272A",
  },
  classic: {
    key: "classic",
    name: "Classic Bistro",
    fontFamily: "serif",
    config: {
      primaryColor: "#8B1E1E",
      background: "#FFF9F2",
      productLayout: "list",
      categoryLayout: "accordion",
      headerLayout: "centered",
    },
    cardBg: "#FFFFFF",
    cardBorder: "rgba(139, 30, 30, 0.15)",
    textPrimary: "#2D1B18",
    textSecondary: "#7A6966",
    accentBg: "rgba(139, 30, 30, 0.08)",
    headerGradient: "linear-gradient(180deg, #38120F 0%, #240B0A 100%)",
    badgeBg: "#FDF2F0",
    badgeText: "#8B1E1E",
  },
};

const ELEGANT_PRESET: ThemePreset = THEME_PRESETS.elegant!;

export const DEFAULT_THEME: ThemeConfig = ELEGANT_PRESET.config;

export function resolveThemePreset(themeKey?: string, customConfig?: Partial<ThemeConfig>): ThemePreset {
  const base = (themeKey ? THEME_PRESETS[themeKey] : undefined) ?? ELEGANT_PRESET;
  if (!customConfig) return base;

  return {
    ...base,
    config: {
      ...base.config,
      ...customConfig,
    },
  };
}
