/**
 * Archetype: twoColText — title + two text columns side by side.
 *
 * Slots:
 *   - title         (optional)
 *   - left  { headline, body }   (required)
 *   - right { headline, body }   (required)
 *
 * Each column shares one column of the 12-col grid (6 wide each with
 * a single gutter between). Headlines render in subtitle weight,
 * body text in body weight, both colored from the palette.
 */
import { applyChrome, placeText } from './_helpers.js';

export const id = 'twoColText';
export const slots = ['title', 'left', 'right'];

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

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

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

  const leftFrame  = { ...col(1, 6),  y: body.y, h: body.h };
  const rightFrame = { ...col(7, 6),  y: body.y, h: body.h };

  for (const [frame, side] of [[leftFrame, content.left], [rightFrame, content.right]]) {
    if (!side) continue;
    placeText(slide, resolved, 'subtitle', side.headline, {
      x: frame.x, y: frame.y, w: frame.w, h: 0.6,
    }, { color: resolved.palette.primary, align: 'left', bold: true });

    placeText(slide, resolved, 'body', side.body, {
      x: frame.x, y: frame.y + 0.7, w: frame.w, h: frame.h - 0.7,
    }, { color: resolved.palette.text, align: 'left', valign: 'top' });
  }
}
