/**
 * slides/13-triggers-overview.js
 * ----------------------------------------------------------------------------
 * Slide 13 -- Triggers: 3 surface overview
 * Slack / Linear / GitHub with @open-swe pattern.
 */
'use strict';

const { helpers, layouts } = require('../../design-system');

function buildTriggersOverview(pres, theme) {
  const slide = pres.addSlide();
  helpers.slideBase(slide, pres, theme);
  helpers.addHeader(slide, pres, theme, {
    eyebrow: 'STAGE 4',
    sectionNumber: 4,
    title: 'Triggers overview',
  });

  // 3 trigger cards
  const cardY = layouts.CONTENT_TOP;
  const cardH = 3.5;
  const cardW = 2.95;
  const gap = 0.13;

  const triggers = [
    {
      name: 'Slack',
      icon: '@',
      desc: 'В любом thread канала. Поддерживает синтаксис repo:owner/name.',
      syntax: '@open-swe fix the auth bug\nrepo:acme/api',
      color: theme.palette.accent.primary,
    },
    {
      name: 'Linear',
      icon: '#',
      desc: 'В комментарии к issue. Привязывает thread к Linear-тикету.',
      syntax: '@openswe implement the\nacceptance criteria',
      color: theme.palette.accent.secondary,
    },
    {
      name: 'GitHub',
      icon: 'PR',
      desc: 'В PR-комментарии для авто-ответа на review-комментарии.',
      syntax: '@openswe address\nthe review comments',
      color: theme.palette.accent.tertiary,
    },
  ];

  triggers.forEach(function (t, idx) {
    const cx = 0.5 + idx * (cardW + gap);

    slide.addShape(pres.ShapeType.roundRect, {
      x: cx, y: cardY, w: cardW, h: cardH,
      fill: { color: theme.palette.bg.elevated },
      line: { color: t.color, width: 1.2 },
      rectRadius: 0.08,
    });

    // Icon badge
    slide.addShape(pres.ShapeType.roundRect, {
      x: cx + 0.2, y: cardY + 0.2, w: 0.55, h: 0.55,
      fill: { color: t.color },
      line: { color: t.color, width: 1 },
      rectRadius: 0.08,
    });
    slide.addText(t.icon, {
      x: cx + 0.2, y: cardY + 0.2, w: 0.55, h: 0.55,
      fontFace: helpers.withFallback(theme.fonts.ui),
      fontSize: 18,
      color: theme.palette.text.inverse,
      bold: true,
      align: 'center',
      valign: 'middle',
    });

    // Name
    slide.addText(t.name, {
      x: cx + 0.85, y: cardY + 0.2, w: cardW - 1.0, h: 0.55,
      fontFace: helpers.withFallback(theme.fonts.ui),
      fontSize: theme.sizes.h3,
      color: theme.palette.text.primary,
      bold: true,
      valign: 'middle',
    });

    // Desc
    slide.addText(t.desc, {
      x: cx + 0.2, y: cardY + 0.9, w: cardW - 0.4, h: 1.05,
      fontFace: helpers.withFallback(theme.fonts.ui),
      fontSize: theme.sizes.body,
      color: theme.palette.text.secondary,
      valign: 'top',
    });

    // Syntax code
    slide.addShape(pres.ShapeType.roundRect, {
      x: cx + 0.2, y: cardY + 2.05, w: cardW - 0.4, h: 1.25,
      fill: { color: theme.palette.bg.code },
      line: { color: theme.palette.border.subtle, width: 0.5 },
      rectRadius: 0.06,
    });
    slide.addText(t.syntax, {
      x: cx + 0.3, y: cardY + 2.1, w: cardW - 0.6, h: 1.15,
      fontFace: helpers.withFallback(theme.fonts.code),
      fontSize: theme.sizes.code,
      color: theme.palette.text.primary,
      valign: 'top',
    });
  });

  helpers.addPageNumber(slide, pres, theme, 13);
  helpers.addSourceLine(slide, pres, theme, {
    source: 'research/per-tech/openswe.md: 90-97',
  });
  return slide;
}

module.exports = { buildTriggersOverview };
