import manifest from "./archive-manifest.json";

/**
 * The Genesis visual archive, 576 photographs from the house's own record,
 * 2013–2017, recovered in full from the original website. Events are labelled
 * from the photographic evidence and the dates encoded in the files;
 * nothing is invented.
 */

export type ArchiveEvent = {
  key: string;
  title: string;
  when: string;
  note: string;
  category: "Exhibitions" | "Private Events" | "The Collection" | "Acquisitions";
};

export const archiveEvents: ArchiveEvent[] = [
  {
    key: "2013_03_05",
    title: "The First Presentation",
    when: "January 2013",
    note: "The house's early vitrines: creations shown to Singapore for the first time.",
    category: "Exhibitions",
  },
  {
    key: "2013_04_15",
    title: "A Private Viewing",
    when: "February 2013",
    note: "Guests with the collection, jewellery examined at close range, the way the house prefers.",
    category: "Private Events",
  },
  {
    key: "2013_04_30",
    title: "Yacht Fest, ONE°15 Marina",
    when: "April 2013",
    note: "Genesis among the yachts at Sentosa Cove's marina festival.",
    category: "Exhibitions",
  },
  {
    key: "2013_12_03",
    title: "An Evening of Couture and Jewels",
    when: "December 2013",
    note: "The house's diamonds and coloured stones on stage and in vitrines at a couture evening.",
    category: "Exhibitions",
  },
  {
    key: "2014_07_03",
    title: "The Hangar Evening",
    when: "July 2014",
    note: "A private aviation showcase, jewels presented beside private jets.",
    category: "Private Events",
  },
  {
    key: "2015_11_02",
    title: "The Showroom Collection",
    when: "November 2015",
    note: "Cabochon necklaces, coloured stones and high jewellery in the showroom vitrines.",
    category: "The Collection",
  },
  {
    key: "2015_11_30",
    title: "An Evening with Private Clients",
    when: "November 2015",
    note: "The house's clients and friends, glasses raised in the showroom.",
    category: "Private Events",
  },
  {
    key: "2016_10_16",
    title: "A Boutique Celebration",
    when: "October 2016",
    note: "An opening marked with music, a children's choir among the vitrines.",
    category: "Exhibitions",
  },
  {
    key: "2017_11_27",
    title: "A Formal Reception",
    when: "November 2017",
    note: "The house among collectors at a formal gathering.",
    category: "Private Events",
  },
];

const groups = manifest as Record<string, string[]>;

export function eventImages(key: string): string[] {
  return (groups[key] ?? []).map((f) => `/archive/thumbs/${f}`);
}

export function eventImagesFull(key: string): string[] {
  return (groups[key] ?? []).map((f) => `/archive/full/${f}`);
}

export function archiveCount(): number {
  return Object.values(groups).reduce((n, v) => n + v.length, 0);
}

/** A curated strip for the homepage, one image per event, chronological. */
export function archiveStrip(): { src: string; event: ArchiveEvent }[] {
  return archiveEvents
    .map((e) => {
      const imgs = eventImages(e.key);
      return imgs.length ? { src: imgs[Math.min(2, imgs.length - 1)], event: e } : null;
    })
    .filter(Boolean) as { src: string; event: ArchiveEvent }[];
}
