/**
 * Archetype: agenda — numbered list of sections the deck will cover.
 *
 * Slots:
 *   - title  (optional, default "Agenda")
 *   - items  (required) array of strings or { title, hint } objects
 *
 * Numbers are rendered in display-weight; titles in body weight; hints
 * (when present) in caption colour. Density depends on the spacing
 * preset — `tight` allows ~10 items, `airy` ~6.
 */
import { applyChrome, placeText } from './_helpers.js';
import { textStyle } from '../typography.js';

export const id = 'agenda';
export const slots = ['title', 'items'];

export default function render(slide, resolved, content, _pptx, ctx) {
  applyChrome(slide, resolved, { bgOverride: content.background, seed: 7, ctx });

  const { safe, header, body } = resolved.spacing;

  placeText(slide, resolved, 'title', content.title || 'Agenda', {
    x: header.x, y: header.y, w: header.w, h: header.h,
  }, { color: resolved.palette.text, align: 'left' });

  const items = Array.isArray(content.items) ? content.items : [];
  const n = items.length || 1;
  const rowH = Math.min(0.9, body.h / Math.max(n, 4));

  items.forEach((raw, i) => {
    const item = typeof raw === 'string' ? { title: raw } : raw;
    const y = body.y + i * rowH;

    // Number column
    slide.addText(String(i + 1).padStart(2, '0'), {
      x: body.x, y, w: 0.9, h: rowH,
      ...textStyle(resolved.typography, 'title', {
        color: resolved.palette.subtle, align: 'left', valign: 'middle',
      }),
    });

    // Title column
    slide.addText(item.title || '', {
      x: body.x + 1.1, y, w: body.w - 1.1, h: rowH * 0.55,
      ...textStyle(resolved.typography, 'subtitle', {
        color: resolved.palette.text, align: 'left', valign: 'middle', bold: true,
      }),
    });

    // Hint column (optional, shown beneath title)
    if (item.hint) {
      slide.addText(item.hint, {
        x: body.x + 1.1, y: y + rowH * 0.5, w: body.w - 1.1, h: rowH * 0.5,
        ...textStyle(resolved.typography, 'caption', {
          color: resolved.palette.subtle, align: 'left', valign: 'top',
        }),
      });
    }
  });
}
