// blog.jsx - "Latest writing" homepage teaser strip, 5 layout variations.
// Each exported component takes the same 3 posts and renders a full-width
// section in the RecLab editorial system. Exports window.RecLabBlog.
// Posts are placeholders shaped like real AI-for-recruiters content - swap freely.

const MONOF = "'Space Mono', ui-monospace, Menlo, monospace";

const POSTS = [
  {
    cat: "Process",
    title: "The art of process optimisation",
    excerpt: "Over time, things change. You can either react to it or drive it. Here are some guidelines to help you change and optimise your processes.",
    date: "May 2026", read: "6 min",
    link: "https://www.linkedin.com/pulse/art-process-optimisation-jamie-lyons-znpue/",
    img: "images/article-process.jpg",
    g1: "#f1d6c0", g2: "#d98a5a", ac: "#b06a3e",
  },
  {
    cat: "Talent Ops",
    title: "What your talent team can learn from product ops",
    excerpt: "Co-written with Nitin Moorjani, Global Talent & Ops Director at Automattic and founder of Peak Grid. Releasing June 2026.",
    date: "Coming June 2026", read: "",
    img: "images/article-talentops.jpg",
    authorPhoto: "images/author-nitin.jpg",
    g1: "#d6e1c2", g2: "#9bb06f", ac: "#697d43",
  },
  {
    cat: "RecOps",
    title: "What US and UK RecOps can learn from each other",
    excerpt: "Co-written with Jeremy Lyons, US-based RecOps leader. Two very different versions of RecOps, and what each side can learn from the other. Releasing June 2026.",
    date: "Coming June 2026", read: "",
    img: "images/article-usuk.jpg",
    authorPhoto: "images/author-jeremy.jpg",
    g1: "#ece0c2", g2: "#cdb072", ac: "#8f7636",
  },
];

// Shared section header (eyebrow + heading + optional "view all" link).
function Head({ heading = "Latest writing", link = true, onDark = false, align = "split" }) {
  const eyebrow = onDark ? "var(--terra-soft)" : "var(--terra-deep)";
  const head = onDark ? "#fff" : "var(--ink)";
  return (
    <div style={{ display: "flex", alignItems: "flex-end", justifyContent: "space-between", gap: 40, flexWrap: "wrap", marginBottom: 52 }}>
      <div style={{ maxWidth: 720 }}>
        <h2 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 54, lineHeight: 1.02, letterSpacing: "-0.035em", color: head, margin: 0 }}>{heading}</h2>
      </div>
      {link && (
        <a href="#" style={{ flex: "none", display: "inline-flex", alignItems: "center", gap: 8, fontFamily: "var(--sans)", fontSize: 15.5, fontWeight: 600,
          color: onDark ? "var(--terra-soft)" : "var(--terra-deep)", textDecoration: "none",
          borderBottom: `1px solid ${onDark ? "rgba(224,165,137,0.4)" : "rgba(154,71,44,0.35)"}`, paddingBottom: 4 }}>
          All articles <span style={{ fontSize: 17 }}>&rarr;</span>
        </a>
      )}
    </div>
  );
}

const wrap = (children, bg) => (
  <section style={{ background: bg, fontFamily: "var(--sans)", padding: "92px 80px 104px" }}>
    <div style={{ maxWidth: 1360, margin: "0 auto" }}>{children}</div>
  </section>
);

// ── V1 · Card row - three thumbnail cards, echoes the Builds grid ──────────
function CardRow() {
  return wrap(
    <React.Fragment>
      <Head link={false} />
      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 24 }}>
        {POSTS.map((p, i) => (
          <a key={i} className="build-card" href={p.link || "#"} target={p.link ? "_blank" : undefined} rel={p.link ? "noopener" : undefined} style={{ display: "block", textDecoration: "none", background: "#fff",
            borderRadius: 20, overflow: "hidden", border: "1px solid rgba(28,26,22,0.08)" }}>
            <div style={{ height: 188, background: p.img ? "var(--paper-2)" : `linear-gradient(145deg, ${p.g1}, ${p.g2})`, position: "relative", overflow: "hidden" }}>
              {p.img && <img src={p.img} alt={p.title} loading="lazy" style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: "center top" }} />}
              {p.authorPhoto && !p.img && <img src={p.authorPhoto} alt={p.title} loading="lazy" style={{ position: "absolute", left: "50%", top: "50%", transform: "translate(-50%,-50%)", width: 94, height: 94, borderRadius: "50%", objectFit: "cover", border: "3px solid rgba(255,255,255,0.92)", boxShadow: "0 10px 24px -8px rgba(0,0,0,0.35)" }} />}
            </div>
            <div style={{ padding: "24px 26px 28px" }}>
              <h3 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 22, lineHeight: 1.18, letterSpacing: "-0.02em", color: "var(--ink)", margin: 0 }}>{p.title}</h3>
              <p style={{ fontFamily: "var(--sans)", fontSize: 15, lineHeight: 1.5, color: "var(--ink-soft)", margin: "12px 0 0" }}>{p.excerpt}</p>
              <div style={{ display: "flex", alignItems: "center", gap: 10, marginTop: 20, fontFamily: MONOF, fontSize: 12.5, color: "var(--concrete)" }}>
                <span>{p.date}</span>{p.read && (<React.Fragment><span style={{ opacity: 0.5 }}>/</span><span>{p.read} read</span></React.Fragment>)}
              </div>
            </div>
          </a>
        ))}
      </div>
    </React.Fragment>, "var(--paper)");
}

// ── V2 · Editorial index - numbered rows, no images, type-led ──────────────
function Index() {
  return wrap(
    <React.Fragment>
      <Head />
      <div style={{ borderTop: "1px solid var(--ink)" }}>
        {POSTS.map((p, i) => (
          <a key={i} href="#" style={{ display: "grid", gridTemplateColumns: "auto 1fr auto", gap: 40, alignItems: "baseline",
            textDecoration: "none", padding: "34px 0", borderBottom: "1px solid rgba(28,26,22,0.18)" }}>
            <span style={{ fontFamily: "var(--serif)", fontStyle: "italic", fontSize: 40, lineHeight: 1, color: "var(--terra)" }}>0{i + 1}</span>
            <div>
              <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 12 }}>
                <span style={{ fontFamily: "var(--sans)", fontSize: 12, fontWeight: 700, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--terra-deep)" }}>{p.cat}</span>
                <span style={{ fontFamily: MONOF, fontSize: 12, color: "var(--concrete)" }}>{p.date} · {p.read}</span>
              </div>
              <h3 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 30, lineHeight: 1.1, letterSpacing: "-0.025em", color: "var(--ink)", margin: 0, maxWidth: 720 }}>{p.title}</h3>
              <p style={{ fontFamily: "var(--sans)", fontSize: 16, lineHeight: 1.55, color: "var(--ink-soft)", margin: "10px 0 0", maxWidth: 680 }}>{p.excerpt}</p>
            </div>
            <span style={{ fontFamily: "var(--sans)", fontSize: 22, color: "var(--terra)", alignSelf: "center" }}>&rarr;</span>
          </a>
        ))}
      </div>
    </React.Fragment>, "var(--paper)");
}

// ── V3 · Featured + two - asymmetric bento, echoes Case Studies ────────────
function Featured() {
  const [f, ...rest] = POSTS;
  return wrap(
    <React.Fragment>
      <Head />
      <div style={{ display: "grid", gridTemplateColumns: "1.25fr 1fr", gap: 24 }}>
        <a className="build-card" href="#" style={{ display: "flex", flexDirection: "column", textDecoration: "none", background: "#fff",
          borderRadius: 22, overflow: "hidden", border: "1px solid rgba(28,26,22,0.08)" }}>
          <div style={{ height: 300, background: `linear-gradient(145deg, ${f.g1}, ${f.g2})`, position: "relative" }}>
            <span style={{ position: "absolute", top: 20, left: 20, background: "rgba(255,255,255,0.92)", borderRadius: 100,
              padding: "7px 15px", fontFamily: "var(--sans)", fontSize: 12.5, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: f.ac }}>{f.cat}</span>
          </div>
          <div style={{ padding: "28px 32px 32px" }}>
            <h3 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 30, lineHeight: 1.12, letterSpacing: "-0.025em", color: "var(--ink)", margin: 0 }}>{f.title}</h3>
            <p style={{ fontFamily: "var(--sans)", fontSize: 16.5, lineHeight: 1.55, color: "var(--ink-soft)", margin: "14px 0 0" }}>{f.excerpt}</p>
            <div style={{ marginTop: 20, fontFamily: MONOF, fontSize: 12.5, color: "var(--concrete)" }}>{f.date} · {f.read} read</div>
          </div>
        </a>
        <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
          {rest.map((p, i) => (
            <a key={i} className="build-card" href="#" style={{ flex: 1, display: "flex", gap: 22, textDecoration: "none", background: "#fff",
              borderRadius: 18, overflow: "hidden", border: "1px solid rgba(28,26,22,0.08)", padding: 18 }}>
              <div style={{ flex: "none", width: 132, borderRadius: 12, background: `linear-gradient(145deg, ${p.g1}, ${p.g2})` }} />
              <div style={{ display: "flex", flexDirection: "column", justifyContent: "center", paddingRight: 8 }}>
                <span style={{ fontFamily: "var(--sans)", fontSize: 11.5, fontWeight: 700, letterSpacing: "0.14em", textTransform: "uppercase", color: p.ac }}>{p.cat}</span>
                <h3 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 21, lineHeight: 1.18, letterSpacing: "-0.02em", color: "var(--ink)", margin: "9px 0 0" }}>{p.title}</h3>
                <div style={{ marginTop: 12, fontFamily: MONOF, fontSize: 12, color: "var(--concrete)" }}>{p.date} · {p.read}</div>
              </div>
            </a>
          ))}
        </div>
      </div>
    </React.Fragment>, "var(--paper)");
}

// ── V4 · Dark band - contrast rhythm, echoes the About section ─────────────
function DarkBand() {
  return (
    <section style={{ background: "#161410", fontFamily: "var(--sans)", position: "relative", overflow: "hidden", padding: "92px 80px 104px" }}>
      <div style={{ position: "absolute", inset: 0, background: "radial-gradient(820px 420px at 85% 0%, rgba(191,92,58,0.18), transparent 70%)" }} />
      <div style={{ maxWidth: 1360, margin: "0 auto", position: "relative" }}>
        <Head onDark />
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 0, borderTop: "1px solid rgba(255,255,255,0.16)" }}>
          {POSTS.map((p, i) => (
            <a key={i} href="#" style={{ display: "block", textDecoration: "none", padding: "32px 32px 36px",
              borderRight: i < 2 ? "1px solid rgba(255,255,255,0.14)" : "none" }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 22 }}>
                <span style={{ width: 7, height: 7, borderRadius: "50%", background: p.g2 }} />
                <span style={{ fontFamily: "var(--sans)", fontSize: 12, fontWeight: 700, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--terra-soft)" }}>{p.cat}</span>
              </div>
              <h3 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 25, lineHeight: 1.16, letterSpacing: "-0.02em", color: "#fff", margin: 0 }}>{p.title}</h3>
              <p style={{ fontFamily: "var(--sans)", fontSize: 15.5, lineHeight: 1.55, color: "rgba(255,255,255,0.7)", margin: "14px 0 0" }}>{p.excerpt}</p>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginTop: 26 }}>
                <span style={{ fontFamily: MONOF, fontSize: 12, color: "rgba(255,255,255,0.45)" }}>{p.date} · {p.read}</span>
                <span style={{ fontFamily: "var(--sans)", fontSize: 20, color: "var(--terra-soft)" }}>&rarr;</span>
              </div>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── V5 · Magazine columns - hairline-ruled, serif accents, newspaper feel ──
function Magazine() {
  return wrap(
    <React.Fragment>
      <Head link={false} heading="From the notebook" />
      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)" }}>
        {POSTS.map((p, i) => (
          <a key={i} href="#" style={{ display: "block", textDecoration: "none", padding: i === 0 ? "0 40px 0 0" : "0 40px",
            borderLeft: i > 0 ? "1px solid rgba(28,26,22,0.18)" : "none", paddingLeft: i > 0 ? 40 : 0 }}>
            <div style={{ fontFamily: MONOF, fontSize: 12, letterSpacing: "0.04em", color: "var(--concrete)", marginBottom: 18 }}>{p.date.toUpperCase()} - {p.read.toUpperCase()}</div>
            <span style={{ fontFamily: "var(--serif)", fontStyle: "italic", fontSize: 19, color: "var(--terra)" }}>{p.cat}</span>
            <h3 style={{ fontFamily: "var(--sans)", fontWeight: 600, fontSize: 27, lineHeight: 1.16, letterSpacing: "-0.025em", color: "var(--ink)", margin: "10px 0 0" }}>{p.title}</h3>
            <p style={{ fontFamily: "var(--news)", fontSize: 16.5, lineHeight: 1.6, color: "var(--ink-soft)", margin: "16px 0 0" }}>{p.excerpt}</p>
            <span style={{ display: "inline-flex", alignItems: "center", gap: 7, marginTop: 22, fontFamily: "var(--sans)", fontSize: 14.5, fontWeight: 600, color: "var(--terra-deep)" }}>Read article &rarr;</span>
          </a>
        ))}
      </div>
    </React.Fragment>, "var(--paper)");
}

window.RecLabBlog = { CardRow, Index, Featured, DarkBand, Magazine };
