// Editorial — new marketing-page components for the 2026 redesign.
// Built to express the asset / sovereignty / democratization positioning.

// ---------------------------------------------------------------------------
// EditorialHero — left-aligned headline with vertical fire rule + side image
// title accepts plain string or array; wrap an italic-fire span via <em>
// ---------------------------------------------------------------------------
const EditorialHero = ({
  eyebrow,
  title,
  body,
  ctas = [],
  image,
  imageAlt = "",
  caption,
  variant = "default", // "default" | "compact"
}) => (
  <section className={`pyrra-ehero ${variant === "compact" ? "pyrra-ehero--compact" : ""}`}>
    <div className="pyrra-ehero__text">
      {eyebrow ? <div className="pyrra-ehero__eyebrow">{eyebrow}</div> : null}
      <h1 className="pyrra-ehero__title">{title}</h1>
      {body ? <p className="pyrra-ehero__body">{body}</p> : null}
      {ctas.length ? (
        <div className="pyrra-ehero__ctas">
          {ctas.map((cta, i) => (
            <Button key={i} variant={cta.variant || (i === 0 ? "primary" : "secondary")} size="lg" onClick={cta.onClick}>
              {cta.label}
            </Button>
          ))}
        </div>
      ) : null}
    </div>
    <div className="pyrra-ehero__media">
      <img src={image} alt={imageAlt} />
    </div>
  </section>
);

// ---------------------------------------------------------------------------
// AssetNumbers — three confident serif callouts (replaces SpecBar in hero)
// ---------------------------------------------------------------------------
const AssetNumbers = ({ items }) => (
  <div className="pyrra-anums">
    {items.map((it, i) => (
      <div className="pyrra-anums__item" key={i}>
        <div className="pyrra-anums__label">{it.label}</div>
        <div className="pyrra-anums__value">{it.value}</div>
        {it.sub ? <div className="pyrra-anums__sub">{it.sub}</div> : null}
      </div>
    ))}
  </div>
);

// ---------------------------------------------------------------------------
// EditorialHeader — section heading with optional index + side lede column
// ---------------------------------------------------------------------------
const EditorialHeader = ({ index, title, lede, layout = "split" }) => (
  <header className={`pyrra-eheader ${layout === "stack" ? "pyrra-eheader--stack" : ""}`}>
    <div className="pyrra-eheader__left">
      {index ? <div className="pyrra-eheader__index">{index}</div> : null}
      <h2 className="pyrra-eheader__title">{title}</h2>
    </div>
    {lede ? <p className="pyrra-eheader__lede">{lede}</p> : null}
  </header>
);

// ---------------------------------------------------------------------------
// RolesGrid — three-column card system for the three Pyrra relationships
// items: [{ num, name, who, gets, cta: { label, onClick } }]
// ---------------------------------------------------------------------------
const RolesGrid = ({ items }) => (
  <div className="pyrra-roles">
    {items.map((it, i) => (
      <div className="pyrra-role" key={i}>
        <div className="pyrra-role__num">{it.num}</div>
        <h3 className="pyrra-role__name">{it.name}</h3>
        <p className="pyrra-role__gets">{it.gets}</p>
        <div className="pyrra-role__who"><strong>Who they are</strong>{it.who}</div>
        {it.cta ? (
          <a
            className="pyrra-role__cta"
            href="#"
            onClick={(e) => { e.preventDefault(); it.cta.onClick && it.cta.onClick(); }}
          >
            {it.cta.label}
          </a>
        ) : null}
      </div>
    ))}
  </div>
);

// ---------------------------------------------------------------------------
// RolesGraphic — two-party relationship diagram. The Owner-Host (the same
// entity who buys the Node and hosts it on their property) on the left,
// Pyrra in the center, the Inference Buyer on the right. Animated orange
// flow lines connect each party to the hub. Stacks on narrow viewports.
// items: [{ tag, name, who, benefits: [{ tag, text }], cta }]
// ---------------------------------------------------------------------------
const RolesGraphic = ({ items = [] }) => {
  const slots = ["left", "right"];
  return (
    <div className="pyrra-rg" role="presentation">
      <svg
        className="pyrra-rg__lines"
        viewBox="0 0 1600 900"
        preserveAspectRatio="none"
        aria-hidden="true"
      >
        {/* Left card → Pyrra */}
        <line x1="358" y1="450" x2="710" y2="450" />
        {/* Pyrra → Right card */}
        <line x1="890" y1="450" x2="1242" y2="450" />
      </svg>

      <div className="pyrra-rg__hub">
        <img src={R("assets/pyrra-flame.png")} alt="" />
        <strong>PYRRA</strong>
        <span>Network</span>
      </div>

      {items.slice(0, 2).map((it, i) => (
        <div className={`pyrra-rg__role pyrra-rg__role--${slots[i]}`} key={i}>
          <div className="pyrra-rg__tag">{it.tag || ""}</div>
          <h3 className="pyrra-rg__name">{it.name}</h3>
          {it.who ? <p className="pyrra-rg__who">{it.who}</p> : null}
          {it.benefits ? (
            <ul className="pyrra-rg__benefits">
              {it.benefits.map((b, j) => (
                <li key={j}>
                  <strong>{b.tag}</strong>
                  <span>{b.text}</span>
                </li>
              ))}
            </ul>
          ) : it.gets ? (
            <span className="pyrra-rg__gets">{it.gets}</span>
          ) : null}
          {it.cta ? (
            <a
              className="pyrra-rg__cta"
              href="#"
              onClick={(e) => { e.preventDefault(); it.cta.onClick && it.cta.onClick(); }}
            >
              {it.cta.label}
            </a>
          ) : null}
        </div>
      ))}
    </div>
  );
};
const PillarsNum = ({ items }) => (
  <div className="pyrra-pillars-num">
    {items.map((it, i) => (
      <div className="pyrra-pillarn" key={i}>
        {it.tag ? <div className="pyrra-pillarn__tag">{it.tag}</div> : null}
        <h3 className="pyrra-pillarn__title">{it.title}</h3>
        <p className="pyrra-pillarn__body">{it.body}</p>
      </div>
    ))}
  </div>
);

// ---------------------------------------------------------------------------
// DarkSection — full-bleed ink-900 panel for sovereignty / asset class moment
// ---------------------------------------------------------------------------
const DarkSection = ({ eyebrow, title, lede, principles = [] }) => (
  <section className="pyrra-dark">
    <div className="pyrra-dark__inner">
      <div>
        {eyebrow ? <div className="pyrra-dark__eyebrow">{eyebrow}</div> : null}
        <h2 className="pyrra-dark__title">{title}</h2>
        {lede ? <p className="pyrra-dark__lede">{lede}</p> : null}
      </div>
      {principles.length ? (
        <div className="pyrra-principles">
          {principles.map((p, i) => (
            <div className="pyrra-principle" key={i}>
              <div className="pyrra-principle__num">{p.num || `0${i + 1}`}</div>
              <p className="pyrra-principle__text">{p.text}</p>
            </div>
          ))}
        </div>
      ) : null}
    </div>
  </section>
);

// ---------------------------------------------------------------------------
// HostsGrid — 5-column broader fit grid (residential, campus, office, etc.)
// ---------------------------------------------------------------------------
const HostsGrid = ({ items }) => (
  <div className="pyrra-hosts">
    {items.map((it, i) => (
      <div className="pyrra-host" key={i}>
        <div className="pyrra-host__icon">{it.icon}</div>
        <h4 className="pyrra-host__name">{it.name}</h4>
        <p className="pyrra-host__body">{it.body}</p>
      </div>
    ))}
  </div>
);

// ---------------------------------------------------------------------------
// HostsImageCards — boxed cards with real images and subtext beneath.
// items: [{ name, body, image }]
// ---------------------------------------------------------------------------
const HostsImageCards = ({ items = [] }) => (
  <div className="pyrra-hic">
    {items.map((it, i) => (
      <article className="pyrra-hic__card" key={i}>
        <div
          className="pyrra-hic__image"
          style={{ backgroundImage: `url(${it.image})` }}
          role="img"
          aria-label={it.name}
        ></div>
        <div className="pyrra-hic__body">
          <h4 className="pyrra-hic__name">{it.name}</h4>
          <p className="pyrra-hic__sub">{it.body}</p>
        </div>
      </article>
    ))}
  </div>
);

// ---------------------------------------------------------------------------
// HostsBoxes — single composite "skyline" graphic. Five stylized building
// silhouettes share a baseline; each contains a small fire-colored Node box
// at the mechanical-room position; labels and one-liners sit beneath.
// items: [{ name, body }] in skyline order.
// ---------------------------------------------------------------------------
const HostsBoxes = ({ items = [] }) => {
  // SVG silhouettes — each renders inside its own viewBox so widths can vary.
  // The Node marker is the small fire-orange square at the building's MEP spot.
  const buildings = {
    Residential: (
      <svg viewBox="0 0 120 180" className="pyrra-hb__svg" aria-hidden="true">
        <rect x="20" y="10" width="80" height="170" className="pyrra-hb__shell" />
        {/* window grid */}
        {Array.from({ length: 7 }).map((_, r) =>
          Array.from({ length: 4 }).map((_, c) => (
            <rect key={`${r}-${c}`} x={28 + c * 17} y={24 + r * 21} width="11" height="11" className="pyrra-hb__win" />
          ))
        )}
        {/* roof element */}
        <rect x="44" y="3" width="32" height="7" className="pyrra-hb__roof" />
        {/* Node marker — ground floor MEP */}
        <rect x="52" y="156" width="16" height="16" className="pyrra-hb__node" />
      </svg>
    ),
    Universities: (
      <svg viewBox="0 0 160 180" className="pyrra-hb__svg" aria-hidden="true">
        {/* main hall */}
        <rect x="20" y="50" width="120" height="130" className="pyrra-hb__shell" />
        {/* pediment */}
        <polygon points="20,50 80,18 140,50" className="pyrra-hb__shell" />
        {/* columns */}
        {[0,1,2,3,4,5].map((i) => (
          <rect key={i} x={30 + i * 17} y="78" width="6" height="80" className="pyrra-hb__win" />
        ))}
        {/* base */}
        <rect x="14" y="160" width="132" height="20" className="pyrra-hb__shell pyrra-hb__shell--alt" />
        {/* Node marker */}
        <rect x="72" y="162" width="16" height="16" className="pyrra-hb__node" />
      </svg>
    ),
    "Office Parks": (
      <svg viewBox="0 0 200 180" className="pyrra-hb__svg" aria-hidden="true">
        {/* two wings */}
        <rect x="10" y="60" width="80" height="120" className="pyrra-hb__shell" />
        <rect x="110" y="30" width="80" height="150" className="pyrra-hb__shell" />
        {/* horizontal window bands */}
        {Array.from({ length: 5 }).map((_, r) => (
          <rect key={`a-${r}`} x="18" y={70 + r * 20} width="64" height="9" className="pyrra-hb__win" />
        ))}
        {Array.from({ length: 7 }).map((_, r) => (
          <rect key={`b-${r}`} x="118" y={40 + r * 20} width="64" height="9" className="pyrra-hb__win" />
        ))}
        {/* connector */}
        <rect x="86" y="140" width="28" height="40" className="pyrra-hb__shell pyrra-hb__shell--alt" />
        {/* Node marker */}
        <rect x="92" y="156" width="16" height="16" className="pyrra-hb__node" />
      </svg>
    ),
    Industrial: (
      <svg viewBox="0 0 220 180" className="pyrra-hb__svg" aria-hidden="true">
        {/* warehouse body */}
        <rect x="10" y="80" width="200" height="100" className="pyrra-hb__shell" />
        {/* sawtooth roof */}
        {[0,1,2,3,4,5].map((i) => (
          <polygon
            key={i}
            points={`${10 + i*33},80 ${10 + i*33 + 16},58 ${10 + i*33 + 33},80`}
            className="pyrra-hb__shell"
          />
        ))}
        {/* big roll-up door */}
        <rect x="28" y="110" width="52" height="70" className="pyrra-hb__win" />
        {/* small windows */}
        {[0,1,2,3].map((i) => (
          <rect key={i} x={108 + i * 22} y="118" width="14" height="14" className="pyrra-hb__win" />
        ))}
        {/* Node marker */}
        <rect x="186" y="156" width="16" height="16" className="pyrra-hb__node" />
      </svg>
    ),
    Government: (
      <svg viewBox="0 0 160 180" className="pyrra-hb__svg" aria-hidden="true">
        {/* base */}
        <rect x="10" y="80" width="140" height="100" className="pyrra-hb__shell" />
        {/* steps */}
        <rect x="4" y="170" width="152" height="10" className="pyrra-hb__shell pyrra-hb__shell--alt" />
        {/* portico */}
        <rect x="34" y="60" width="92" height="20" className="pyrra-hb__shell" />
        <polygon points="34,60 80,28 126,60" className="pyrra-hb__shell" />
        {/* dome */}
        <circle cx="80" cy="36" r="8" className="pyrra-hb__shell pyrra-hb__shell--alt" />
        <rect x="78" y="14" width="4" height="14" className="pyrra-hb__shell pyrra-hb__shell--alt" />
        {/* columns */}
        {[0,1,2,3].map((i) => (
          <rect key={i} x={42 + i * 22} y="82" width="6" height="78" className="pyrra-hb__win" />
        ))}
        {/* Node marker */}
        <rect x="72" y="162" width="16" height="16" className="pyrra-hb__node" />
      </svg>
    ),
  };

  return (
    <div className="pyrra-hb" role="presentation">
      <div className="pyrra-hb__ground" aria-hidden="true"></div>
      <div className="pyrra-hb__row">
        {items.map((it, i) => (
          <div className="pyrra-hb__cell" key={i}>
            <div className="pyrra-hb__art">{buildings[it.name] || buildings.Residential}</div>
            <div className="pyrra-hb__label">
              <h4>{it.name}</h4>
              {it.body ? <p>{it.body}</p> : null}
            </div>
          </div>
        ))}
      </div>
      <div className="pyrra-hb__legend" aria-hidden="true">
        <span className="pyrra-hb__legend-swatch"></span>
        <span>Pyrra node placement</span>
      </div>
    </div>
  );
};

// ---------------------------------------------------------------------------
// EditorialCta — full-bleed dark CTA strip (replaces the cta-band image)
// Pass bgImage to use a photographic background with a darkening gradient.
// ---------------------------------------------------------------------------
const EditorialCta = ({ title, body, ctaLabel, onCta, bgImage }) => (
  <section className={`pyrra-ecta ${bgImage ? "pyrra-ecta--photo" : ""}`}>
    {bgImage ? <div className="pyrra-ecta__bg" style={{ backgroundImage: `url(${bgImage})` }} /> : null}
    <div className="pyrra-ecta__inner">
      <div>
        <h2 className="pyrra-ecta__title">{title}</h2>
        {body ? <p className="pyrra-ecta__body">{body}</p> : null}
      </div>
      <button className="pyrra-ecta__cta" onClick={onCta}>
        {ctaLabel} <span aria-hidden="true">→</span>
      </button>
    </div>
  </section>
);

// ---------------------------------------------------------------------------
// MechSteps — 3-step staircase (how it works)
// ---------------------------------------------------------------------------
const MechSteps = ({ items, variant }) => (
  <div className={`pyrra-mech ${variant === "cards" ? "pyrra-mech--cards" : ""}`}>
    {items.map((it, i) => (
      <div className="pyrra-mech__step" key={i}>
        {it.image ? (
          <div
            className="pyrra-mech__image"
            style={{ backgroundImage: `url(${it.image})` }}
            role="img"
            aria-label={it.title}
          />
        ) : null}
        <div className="pyrra-mech__num">{it.num || `0${i + 1}`}</div>
        <h3 className="pyrra-mech__title">{it.title}</h3>
        <p className="pyrra-mech__body">{it.body}</p>
      </div>
    ))}
  </div>
);

// ---------------------------------------------------------------------------
// BriefBlock — large left headline + multi-paragraph right column
// ---------------------------------------------------------------------------
const BriefBlock = ({ headline, paragraphs = [] }) => (
  <div className="pyrra-brief">
    <h2 className="pyrra-brief__left">{headline}</h2>
    <div className="pyrra-brief__right">
      {paragraphs.map((p, i) => <p key={i}>{p}</p>)}
    </div>
  </div>
);

// ---------------------------------------------------------------------------
// PullStatement — big serif manifesto line with eyebrow + bold orange mark.
// Used as a typographic breathing room between dense sections.
// ---------------------------------------------------------------------------
const PullStatement = ({ tag, children, attribution }) => (
  <section className="pyrra-pull">
    {tag ? <div className="pyrra-pull__tag">{tag}</div> : null}
    <p className="pyrra-pull__text">{children}</p>
    {attribution ? <div className="pyrra-pull__attr">{attribution}</div> : null}
  </section>
);

// ---------------------------------------------------------------------------
// NodeAdvantage — bold dark callout that pairs three quick stat cards with a
// large-type statement contrasting Pyrra Nodes against traditional data
// centers. Used on the Nodes page as a featured visual moment.
// ---------------------------------------------------------------------------
const NodeAdvantage = () => (
  <section className="pyrra-advantage">
    <div className="pyrra-advantage__bg" aria-hidden="true"></div>
    <div className="pyrra-advantage__inner">
      <div className="pyrra-advantage__eyebrow">The Pyrra advantage</div>

      <div className="pyrra-advantage__stats">
        <div className="pyrra-advantage__stat">
          <span className="pyrra-advantage__stat-num"><em>&lt;</em>30<span className="pyrra-advantage__stat-unit">ft²</span></span>
          <span className="pyrra-advantage__stat-label">Smaller than a coat closet</span>
        </div>
        <div className="pyrra-advantage__stat">
          <span className="pyrra-advantage__stat-num">Local</span>
          <span className="pyrra-advantage__stat-label">Faster inference, better rates</span>
        </div>
        <div className="pyrra-advantage__stat">
          <span className="pyrra-advantage__stat-num">0</span>
          <span className="pyrra-advantage__stat-label">New environmental or community impact</span>
        </div>
      </div>

      <div className="pyrra-advantage__rule" aria-hidden="true"></div>

      <p className="pyrra-advantage__statement">
        Pyrra nodes provide <em>faster inference</em> at <em>better rates</em> and require
        <em> less space than a coat closet</em>. All the benefits with
        <em> none of the negative environmental or community impacts</em>.
      </p>
    </div>
  </section>
);

// ---------------------------------------------------------------------------
// Marquee — single oversized display word as a typographic section divider.
// Use sparingly for visual rhythm between sections.
// ---------------------------------------------------------------------------
const Marquee = ({ children }) => (
  <div className="pyrra-marquee" aria-hidden="true">
    <span>{children}</span>
  </div>
);

// ---------------------------------------------------------------------------
// ScarcityNote — first-run callout. Giant numeral on the left, body and supply
// facts on the right. Used on Home and Nodes pages to make the limited
// initial allotment explicit.
// ---------------------------------------------------------------------------
const ScarcityNote = ({ onCta, ctaLabel = "Buy a node", compact = false }) => {
  if (compact) {
    return (
      <section className="pyrra-section pyrra-scarcity pyrra-scarcity--compact">
        <div className="pyrra-scarcity__inner">
          <div className="pyrra-scarcity__num">
            <span className="pyrra-scarcity__pretitle">Own The First</span>
            <span className="pyrra-scarcity__count" aria-label="One hundred">100</span>
          </div>
          <div className="pyrra-scarcity__body">
            <h2>Only one hundred nodes ship in the inaugural run.</h2>
            <p>
              Nvidia silicon is allocated by quarter and host buildings have to qualify before a node is
              committed. Reservations are first-come, first-served.
            </p>
          </div>
          <div className="pyrra-scarcity__cta">
            <Button size="md" onClick={onCta}>{ctaLabel}</Button>
          </div>
        </div>
      </section>
    );
  }
  return (
    <section className="pyrra-section pyrra-scarcity">
      <div className="pyrra-scarcity__inner">
        <div className="pyrra-scarcity__num">
          <span className="pyrra-scarcity__pretitle">Own The First</span>
          <span className="pyrra-scarcity__count" aria-label="One hundred">100</span>
          <span className="pyrra-scarcity__caption">nodes worldwide</span>
        </div>
        <div className="pyrra-scarcity__body">
          <h2>Be among the first to own a Pyrra node.</h2>
          <ul className="pyrra-scarcity__facts">
            <li>
              <strong>GPU supply</strong>
              <span>Nvidia silicon is contracted by quarter, supply is limited.</span>
            </li>
            <li>
              <strong>Host qualification</strong>
              <span>Site approval is required before a node is allocated.</span>
            </li>
            <li>
              <strong>Allocation order</strong>
              <span>First-come, first-served by reservation date.</span>
            </li>
          </ul>
          <div className="pyrra-scarcity__cta">
            <Button size="lg" onClick={onCta}>{ctaLabel}</Button>
          </div>
        </div>
      </div>
    </section>
  );
};

Object.assign(window, {
  EditorialHero,
  AssetNumbers,
  EditorialHeader,
  RolesGrid,
  RolesGraphic,
  PillarsNum,
  DarkSection,
  HostsGrid,
  HostsBoxes,
  HostsImageCards,
  EditorialCta,
  MechSteps,
  BriefBlock,
  PullStatement,
  Marquee,
  NodeAdvantage,
  ScarcityNote,
});
