/* BZK-specifieke layouts: genummerde lijst, drie kolommen met lijstjes,
   markdown-codeblok met voor-en-na. Zelfde tokens en animatieklassen. */

function Footnote({ children }) {
  return (
    <p className="muted" style={{ fontSize: TYPE_SCALE.small, margin: "28px 0 0", maxWidth: 1500, lineHeight: 1.45 }}>
      {children}
    </p>
  );
}

/* Genummerde lijst met kop en toelichting, 3 tot 5 items */
function NumberedList({ eyebrow, title, items = [], footnote, idx, total, layoutLabel }) {
  const many = items.length > 4;
  const tight = many;
  const foot = !many && (!!footnote || items.length === 4);
  return (
    <div className="slide bg-white" style={{ position: "relative" }}>
      <Frame>
        {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
        <h2 className="slide-title" style={{ fontSize: TYPE_SCALE.titleSm, maxWidth: 1500 }}>{title}</h2>
        <div style={{ marginTop: tight ? 28 : (foot ? 40 : 56), display: "flex", flexDirection: "column", gap: tight ? 12 : (foot ? 20 : 26), flex: 1, justifyContent: "center" }}>
          {items.map((it, i) => (
            <div key={i} className="mr-card" style={{ display: "grid", gridTemplateColumns: "auto 1fr", gap: 32, alignItems: "flex-start", padding: tight ? "16px 32px" : (foot ? "24px 40px" : "30px 40px"), background: "#fff", border: "1px solid var(--border)", boxShadow: "none" }}>
              <div style={{
                width: tight ? 48 : (foot ? 60 : 66), height: tight ? 48 : (foot ? 60 : 66), borderRadius: "50%",
                background: "linear-gradient(135deg, var(--coral) 0%, var(--coral-light) 100%)",
                color: "#fff", display: "inline-flex", alignItems: "center", justifyContent: "center",
                fontSize: tight ? 23 : (many ? 26 : 30), fontWeight: 700, fontFamily: "var(--font-heading)", flexShrink: 0,
              }}>{it.num || i + 1}</div>
              <div>
                <div style={{ fontFamily: "var(--font-heading)", fontSize: tight ? 30 : (foot ? 36 : 40), fontWeight: 600, lineHeight: 1.2 }}>{it.head}</div>
                {it.body && <p style={{ fontSize: tight ? TYPE_SCALE.caption : (foot ? TYPE_SCALE.small : TYPE_SCALE.body), lineHeight: 1.45, color: "var(--muted)", margin: "8px 0 0" }}>{it.body}</p>}
              </div>
            </div>
          ))}
        </div>
        {footnote && <p className="muted" style={{ fontSize: TYPE_SCALE.small, margin: "18px 0 0", maxWidth: 1500, lineHeight: 1.45 }}>{footnote}</p>}
      </Frame>
      {idx && <SlideChrome idx={idx} total={total} />}
      <LayoutLabel>{layoutLabel || "Numbered list"}</LayoutLabel>
    </div>
  );
}

/* Drie kolommen, elk een kopje met een lijstje eronder */
function ThreeListGrid({ eyebrow, title, lead, columns = [], footnote, idx, total, layoutLabel }) {
  return (
    <div className="slide bg-light" style={{ position: "relative" }}>
      <Frame>
        {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
        <h2 className="slide-title" style={{ fontSize: TYPE_SCALE.titleSm, maxWidth: 1500 }}>{title}</h2>
        {lead && <p className="muted" style={{ fontSize: TYPE_SCALE.body, margin: "24px 0 0", maxWidth: 1500, lineHeight: 1.45 }}>{lead}</p>}
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 32, marginTop: 48, flex: 1 }}>
          {columns.map((c, i) => (
            <div key={i} className="mr-card" style={{ padding: 40, background: c.tone === "coral" ? "var(--coral-soft)" : "#fff", border: "1px solid var(--border)", boxShadow: "none" }}>
              <div style={{ display: "flex", alignItems: "center", gap: 16, marginBottom: 22 }}>
                <Icon name={c.icon || "check"} size={32} color="var(--coral)" strokeWidth={2} />
                <div style={{ fontFamily: "var(--font-heading)", fontSize: 36, fontWeight: 600 }}>{c.title}</div>
              </div>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 14 }}>
                {(c.items || []).map((t, j) => (
                  <li key={j} style={{ display: "grid", gridTemplateColumns: "auto 1fr", gap: 14, alignItems: "baseline", fontSize: TYPE_SCALE.small, lineHeight: 1.4, color: "var(--muted)" }}>
                    <span style={{ width: 9, height: 9, borderRadius: "50%", background: "var(--coral)", display: "inline-block" }} />
                    <span>{t}</span>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>
        {footnote && <p className="muted" style={{ fontSize: TYPE_SCALE.small, margin: "18px 0 0", maxWidth: 1500, lineHeight: 1.45 }}>{footnote}</p>}
      </Frame>
      {idx && <SlideChrome idx={idx} total={total} />}
      <LayoutLabel>{layoutLabel || "Three lists"}</LayoutLabel>
    </div>
  );
}

/* Markdown-bestand als code, met twee panelen ernaast */
function CodeCompare({ eyebrow, title, filename, fileNote, lines = [], panels = [], footnote, idx, total, layoutLabel }) {
  return (
    <div className="slide bg-white" style={{ position: "relative" }}>
      <Frame padBottom={70}>
        {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
        <h2 className="slide-title" style={{ fontSize: TYPE_SCALE.titleSm, maxWidth: 1500 }}>{title}</h2>
        <div style={{ display: "grid", gridTemplateColumns: "1.15fr 1fr", gap: 36, marginTop: 36, flex: 1, minHeight: 0 }}>
          <div className="mr-card" style={{ padding: 0, overflow: "hidden", border: "1px solid var(--border)", boxShadow: "none", display: "flex", flexDirection: "column" }}>
            <div style={{ background: "var(--navy)", color: "rgba(255,255,255,0.72)", display: "flex", justifyContent: "space-between", alignItems: "center", gap: 24, padding: "16px 28px", fontSize: 20 }}>
              <span style={{ fontFamily: "ui-monospace, 'SF Mono', Menlo, monospace", color: "#fff", fontWeight: 600, whiteSpace: "nowrap" }}>{filename}</span>
              <span style={{ textAlign: "right", lineHeight: 1.3 }}>{fileNote}</span>
            </div>
            <pre style={{
              margin: 0, flex: 1, padding: "26px 30px", background: "#FCFDFE",
              fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, monospace",
              fontSize: 23, lineHeight: 1.5, whiteSpace: "pre-wrap", color: "var(--foreground)",
            }}>
              {lines.map((l, i) => {
                const t = typeof l === "string" ? { t: l } : l;
                const style = t.k === "h" ? { color: "var(--coral)", fontWeight: 700 }
                  : t.k === "b" ? { fontWeight: 700 }
                  : t.k === "li" ? { color: "var(--muted)" }
                  : {};
                return <div key={i} style={{ minHeight: t.t ? 0 : "0.9em", ...style }}>{t.t || ""}</div>;
              })}
            </pre>
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 28 }}>
            {panels.map((p, i) => (
              <div key={i} className="mr-card" style={{ flex: 1, padding: 34, background: p.tone === "coral" ? "var(--coral-soft)" : "#fff", border: "1px solid var(--border)", boxShadow: "none" }}>
                <div style={{ fontFamily: "var(--font-heading)", fontSize: 32, fontWeight: 600, marginBottom: 16 }}>{p.label}</div>
                <p style={{ fontSize: TYPE_SCALE.small, lineHeight: 1.45, margin: 0, fontStyle: "normal", color: "var(--foreground)" }}>{p.quote}</p>
                {p.body && <p className="muted" style={{ fontSize: 22, lineHeight: 1.4, margin: "16px 0 0" }}>{p.body}</p>}
              </div>
            ))}
          </div>
        </div>
        {footnote && <p className="muted" style={{ fontSize: TYPE_SCALE.small, margin: "18px 0 0", maxWidth: 1500, lineHeight: 1.45 }}>{footnote}</p>}
      </Frame>
      {idx && <SlideChrome idx={idx} total={total} />}
      <LayoutLabel>{layoutLabel || "Code compare"}</LayoutLabel>
    </div>
  );
}

Object.assign(window, { Footnote, NumberedList, ThreeListGrid, CodeCompare });
