import { defaultTheme } from "@/themes/default";
import { vitrineTheme } from "@/themes/vitrine";
import { vendorTheme } from "@/themes/vendor";
import { boutiqueTheme } from "@/themes/boutique";
import type { CatalogThemeDefinition, CatalogThemeKey } from "@/themes/types";

export const catalogThemes: Record<CatalogThemeKey, CatalogThemeDefinition> = {
  default: defaultTheme,
  vitrine: vitrineTheme,
  vendor: vendorTheme,
  boutique: boutiqueTheme,
};

export const catalogThemeList = Object.values(catalogThemes);

export function resolveCatalogThemeKey(value: string | null | undefined): CatalogThemeKey {
  const normalized = String(value || "").trim().toLowerCase();
  if (normalized === "vitrine") return "vitrine";
  if (normalized === "vendor") return "vendor";
  if (normalized === "boutique") return "boutique";
  return "default";
}

/* A família Vendor: templates sem grade fixa, com home automática até a
   primeira publicação no editor e seções que seguem só o desenho do tema
   (sem cor, largura ou título por seção). Hoje: Vendor e Boutique. Toda
   decisão "faz como o Vendor" passa por aqui, para o tema novo não ficar de
   fora de nenhuma. */
export function ehFamiliaVendor(value: string | null | undefined): boolean {
  const tema = resolveCatalogThemeKey(value);
  return tema === "vendor" || tema === "boutique";
}

export function getCatalogThemeDefinition(value: string | null | undefined): CatalogThemeDefinition {
  return catalogThemes[resolveCatalogThemeKey(value)];
}
