#!/usr/bin/env node
/**
 * pres-single — emit a one-slide PPTX so we can render PNG for visual QA.
 *
 *   node scripts/verify/pres-single.mjs <archetype> <theme> [outfile]
 *
 * The pptxgenjs file holds a single slide of the requested archetype
 * with example content; LibreOffice's PNG export does the first slide
 * only, which is exactly what we need here.
 */
import path from 'path';
import { fileURLToPath } from 'url';
import { buildThemedPres } from '../../src/tools/office/pres/index.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const args = process.argv.slice(2);
const archetype = args[0] || 'bigStat';
const theme     = args[1] || 'tech-bold';
const outFile   = path.resolve(args[2] || path.join(__dirname, '../../bench-out/pres-showcase', `single-${archetype}-${theme}.pptx`));

const EXAMPLES = {
  hero: {
    eyebrow: 'Q4 2026', title: 'Higher gear.',
    subtitle: 'A presentation system that does the design work for you.',
    author: 'Loxia', date: '2026-05-29',
  },
  agenda: {
    title: 'Agenda',
    items: [
      { title: 'Where we are',  hint: 'Growth, retention, runway' },
      { title: 'What changed',  hint: 'Three big shifts since Q3' },
      { title: 'What\'s next',  hint: 'The next four sprints' },
    ],
  },
  sectionHeader: {
    number: '02', title: 'Where we\'re going',
    subtitle: 'The roadmap, the bets, the timing.',
  },
  statCallout: {
    eyebrow: 'ARR growth', stat: '+47%', label: 'Year-over-year',
    footnote: 'Through April 2026',
  },
  bigStat: {
    eyebrow: 'Headline metric',
    stat: '143',
    unit: '%',
    label: 'Net retention across mid-market cohorts',
    delta: { value: '+8pp vs Q3', direction: 'up' },
    tags: [
      { label: 'design system', kind: 'highlight' },
      { label: 'measured',       kind: 'subtle' },
    ],
    footnote: 'Source: internal billing. Cohort: mid-market (>$50k ARR).',
  },
  statTrio: {
    title: 'The dashboard view',
    subtitle: 'Three KPI cards, deltas + units styled by the theme.',
    stats: [
      { label: 'ARR',            value: '$8.3', unit: 'M', delta: '+47% YoY', deltaDirection: 'up' },
      { label: 'Net retention',  value: '143',  unit: '%', delta: '+8pp QoQ', deltaDirection: 'up' },
      { label: 'Burn',           value: '14',   unit: 'mo', delta: '-3mo',    deltaDirection: 'down' },
    ],
    footnote: 'Through April 2026 · billing source',
  },
  comparisonGrid: {
    title: 'Before vs after',
    subtitle: 'Same agent, same prompt, different system.',
    cells: [
      { eyebrow: 'Before', headline: 'Hand-placed',  accent: 'subtle',    body: 'Agent picks coordinates, colours, fonts ad-hoc. Decks come out inconsistent — some slides feel finished, others feel like wireframes.' },
      { eyebrow: 'After',  headline: 'Curated',       accent: 'primary',   body: 'Agent picks a theme + an archetype per slide. Every choice is from a vocabulary that\'s already been designed to work together.' },
      { eyebrow: 'Before', headline: '60pt titles',   accent: 'subtle',    body: 'Hero titles read fine on a laptop but disappear on a projector. Body text feels like a Word document.' },
      { eyebrow: 'After',  headline: '120pt display', accent: 'highlight', body: 'Hero titles fill the slide. Body copy is conference-readable. Type scale and spacing are tuned per theme.' },
    ],
  },
  bullets: {
    title: 'Key wins this quarter',
    subtitle: 'Pick the archetype; the rest is rhythm.',
    items: [
      'Every archetype reads its colour from one of 8 semantic palette roles.',
      'Spacing comes from one of three presets — tight / cozy / airy.',
      'Shape comes from one of four — sharp / soft / round / pill.',
      'Backgrounds are native PPTX shapes — fully editable, no rasterised images.',
      'Charts inherit the theme\'s palette + gridline policy automatically.',
    ],
  },
  twoColChart: {
    title: 'Revenue mix',
    leftText: {
      headline: 'Composition shifted',
      body: 'Self-serve became the dominant motion — but enterprise contracts now have the largest average annual contract value.',
    },
    chart: { type: 'donut', data: [{ label: 'Pro', value: 62 }, { label: 'Team', value: 28 }, { label: 'Enterprise', value: 10 }] },
  },
  quote: {
    quote: 'The first time I used the new system, I genuinely thought a designer had made the deck. I closed PowerPoint and opened it again to double-check.',
    attribution: 'Internal beta — May 2026',
    subtext: 'Reaction after seeing the second pass.',
  },
  closing: {
    eyebrow: 'Thank you',
    title: 'Decks that look designed.',
    cta:  { label: 'See the spec', url: 'https://github.com/loxia/autopilot' },
    contact: [
      { label: 'Themes',      value: '3' },
      { label: 'Archetypes',  value: '16' },
      { label: 'Backgrounds', value: '7' },
    ],
  },
  headlineMessage: {
    eyebrow: 'Q4 2026',
    message: 'Decks that look designed by default.',
    footnote: 'Loxia Presentation System · May 2026',
  },
  productHero: {
    eyebrow: 'New for May 2026',
    title: 'Decks that look designed by default.',
    subtitle: 'A presentation system the agent never has to design.',
    imagePosition: 'bottom',
  },
  bentoGrid: {
    title: "What's inside",
    tiles: [
      { colStart: 1, colSpan: 8, rowStart: 1, rowSpan: 2, kind: 'stat',
        eyebrow: 'Net retention', value: '143', unit: '%',
        label: 'Mid-market cohorts, Q4 2026', accent: 'primary', icon: 'arc' },
      { colStart: 9, colSpan: 4, rowStart: 1, rowSpan: 1, kind: 'stat',
        eyebrow: 'ARR', value: '$8.3', unit: 'M', label: '+47% YoY',
        accent: 'accent', icon: 'circle' },
      { colStart: 9, colSpan: 4, rowStart: 2, rowSpan: 1, kind: 'stat',
        eyebrow: 'Burn', value: '14', unit: 'mo', label: 'runway remaining',
        accent: 'highlight', icon: 'square' },
      { colStart: 1, colSpan: 6, rowStart: 3, rowSpan: 1, kind: 'feature',
        eyebrow: 'Product', headline: 'Shipped 11 features',
        body: 'Auth, billing, search — all live in Q4.', accent: 'primary' },
      { colStart: 7, colSpan: 6, rowStart: 3, rowSpan: 1, kind: 'callout',
        eyebrow: 'Next', headline: 'Series B in motion',
        body: 'Targeting close by Q1 2027.', accent: 'accent', icon: 'chevron' },
    ],
  },
};

async function main() {
  const slide = EXAMPLES[archetype];
  if (!slide) {
    console.error(`Unknown archetype: ${archetype}. Known: ${Object.keys(EXAMPLES).join(', ')}`);
    process.exit(1);
  }

  // Build a tiny 1-slide deck so soffice's PNG export captures it.
  const r = await buildThemedPres({
    title: `Single-slide preview — ${archetype}`,
    company: 'Loxia',
    theme,
    slides: [{ archetype, ...slide }],
  }, outFile);

  console.log(`Wrote ${r.path}  (${(r.size / 1024).toFixed(1)} KB)`);
  console.log(`theme=${r.theme}  palette=${r.palette}  bg=${r.background}`);
}

main().catch(e => { console.error(e); process.exit(1); });
