export type Campaign = {
  slug: string;
  promoCode: string;
  discountLabel: string;
  bannerText: string;
  menuLabel: string;
  eyebrow: string;
  title: string;
  subtitle: string;
  ctaLabel: string;
  /** Mot-clé recherché dans les titres de thèmes Sanity pour lister les produits de la campagne. */
  themeKeyword: string;
  startsAt: string | null;
  endsAt: string;
  endsLabel: string;
};

// Pour lancer une nouvelle campagne : ajouter une entrée et aligner les dates sur le code promo Medusa.
const CAMPAIGNS: Campaign[] = [
  {
    slug: "halloween",
    promoCode: "HALLOWEEN10",
    discountLabel: "-10 %",
    bannerText: "🎃 Halloween : -10 % avec le code HALLOWEEN10",
    menuLabel: "🎃 Halloween",
    eyebrow: "Collection Halloween",
    title: "Une fête qui fait\ntrembler de plaisir",
    subtitle:
      "Sachets de bonbons, étiquettes, coloriages et gourmandises personnalisés aux couleurs d'Halloween. Choisissez votre thème, on s'occupe du reste.",
    ctaLabel: "Découvrir la collection",
    themeKeyword: "halloween",
    startsAt: null,
    endsAt: "2026-11-01T00:00:00+01:00",
    endsLabel: "jusqu'au 31 octobre",
  },
];

export function getActiveCampaign(now = new Date()): Campaign | null {
  const time = now.getTime();

  return (
    CAMPAIGNS.find((campaign) => {
      const startsAt = campaign.startsAt ? new Date(campaign.startsAt).getTime() : Number.NEGATIVE_INFINITY;
      return time >= startsAt && time < new Date(campaign.endsAt).getTime();
    }) || null
  );
}

export function getCampaignHref(campaign: Campaign) {
  return `/${campaign.slug}`;
}
