/**
 * Archetype: headlineMessage — one sentence, the entire slide.
 *
 * The YC / Apple / a16z move: a single message that fills the whole
 * canvas. No supporting copy, no decoration. The headline carries it.
 *
 * Slots:
 *   eyebrow   (optional) small upper label
 *   message   (required) the sentence itself
 *   footnote  (optional) tiny source/credit
 */
import { applyChrome, eyebrow, placeText, rule } from './_helpers.js';
import { textStyle } from '../typography.js';

export const id = 'headlineMessage';
export const slots = ['eyebrow', 'message', 'footnote'];

export default function render(slide, resolved, content, _pptx, _ctx) {
  applyChrome(slide, resolved, { bgOverride: content.background, seed: 137, chrome: false });

  const { safe } = resolved.spacing;
  const palette = resolved.palette;

  if (content.eyebrow) {
    eyebrow(slide, resolved, content.eyebrow, {
      x: safe.x, y: safe.y, w: safe.w * 0.5, color: palette.primary,
    });
  }

  // The message fills the upper 65% of the slide. fit:'shrink' lets
  // PPTX scale the text down if the agent passes a longer sentence so
  // we never overflow.
  const msgY = safe.y + 0.6;
  const msgH = safe.h * 0.65;
  slide.addText(String(content.message ?? ''), {
    x: safe.x, y: msgY, w: safe.w * 0.85, h: msgH,
    ...textStyle(resolved.typography, 'display', {
      color: palette.ink,
      align: 'left',
      valign: 'middle',
      fit: 'shrink',
    }),
  });

  if (content.footnote) {
    const footY = safe.y + safe.h - 0.35;
    rule(slide, safe.x, footY - 0.08, 0.6, palette.primary, 1.2);
    placeText(slide, resolved, 'caption', content.footnote, {
      x: safe.x, y: footY, w: safe.w * 0.8, h: 0.3,
    }, { color: palette.subtle, align: 'left' });
  }
}
