/**
 * pres/archetypes — registry + dispatch.
 *
 * The agent picks an archetype id per slide; this module routes to the
 * matching renderer. Unknown ids fall back to `freeform` so the deck
 * still builds.
 */
import hero from './hero.js';
import agenda from './agenda.js';
import sectionHeader from './sectionHeader.js';
import headlineMessage from './headlineMessage.js';
import productHero from './productHero.js';
import statCallout from './statCallout.js';
import bigStat from './bigStat.js';
import statTrio from './statTrio.js';
import comparisonGrid from './comparisonGrid.js';
import bentoGrid from './bentoGrid.js';
import bullets from './bullets.js';
import twoColText from './twoColText.js';
import twoColChart from './twoColChart.js';
import quote from './quote.js';
import imageFullBleed from './imageFullBleed.js';
import table from './table.js';
import closing from './closing.js';
import freeform from './freeform.js';

const ARCHETYPES = {
  hero, agenda, sectionHeader, headlineMessage, productHero,
  statCallout, bigStat, statTrio, comparisonGrid, bentoGrid,
  bullets, twoColText, twoColChart, quote, imageFullBleed, table,
  closing, freeform,
};

export function listArchetypes() {
  return Object.keys(ARCHETYPES);
}

/**
 * Render one slide given the slide spec (with `archetype` field).
 * Always renders something — unknown archetypes route to freeform.
 *
 *   `ctx` carries deck-level state: slideIndex, totalSlides,
 *   sectionName, sectionIdx, sectionTotal, brand, isSectionStart.
 *   Archetypes use it to render the chrome (page number, section
 *   progress dots) without the agent having to thread it through
 *   every slide spec.
 */
export function renderArchetype(slide, resolved, slideSpec, pptx, ctx = {}) {
  const id = slideSpec.archetype || 'freeform';
  const fn = ARCHETYPES[id] || ARCHETYPES.freeform;
  fn(slide, resolved, slideSpec, pptx, ctx);

  // Speaker notes — supported on every archetype.
  if (slideSpec.notes) {
    slide.addNotes(String(slideSpec.notes));
  }
}
