// Solo home page — defence-tech identity.
//
// Operates by different rules than the rest of the site:
//   - Hero is a full-bleed dark HUD with live world map + operator panels
//   - Below-fold sections favour large photography and large numerals over
//     the eyebrow/numeral/H2/grid pattern used elsewhere
//   - No section padding rhythm — instead, full-bleed images act as
//     chapter breaks between content blocks
//
// First-load curtain mounts here (sessionStorage-gated, fires once).

function HomePage({ onNavigate }) {
  return (
    <>
      {/* HERO — the wow moment */}
      <HomeHUDHero onNavigate={onNavigate} />

      {/* TRUSTED BY — generic sector logos on black, single line */}
      <SectorMarquee />

      {/* THE PLATFORM — three featured products, photo-led, no cards */}
      <PlatformBand onNavigate={onNavigate} />

      {/* CHAPTER BREAK — deployment photograph.
          Uses the construction-dusk hero from the asset library.
          objectPosition biased to the top: the tower's camera housing
          sits near the top edge of the source photo, so the default
          center-crop of a 21:9 letterbox clipped its cap off. */}
      <ChapterPhoto
        id="home-photo-deployment"
        src="assets/hero-construction-dusk.png"
        objectPosition="center top"
        caption="Pro Tower · Tier-1 construction · Bedfordshire"
      />

      {/* OPERATING MODEL — three numerals, brutal type */}
      <OperatingModel onNavigate={onNavigate} />

      {/* CHAPTER BREAK — operator monitoring console. */}
      <ChapterPhoto
        id="home-photo-console"
        src="assets/hero-monitoring-console.png"
        caption="Solo monitoring · 24/7 deployment view"
      />

      {/* PARTNER CHANNEL — short callout */}
      <PartnerCallout onNavigate={onNavigate} />

      {/* CHAPTER BREAK — factory floor. Uses the Bedfordshire HQ shot. */}
      <ChapterPhoto
        id="home-photo-factory"
        src="assets/about-bedfordshire-hq.jpg"
        caption="Bedfordshire production · 2,000+ units shipped"
      />

      {/* FINAL CTA — full-black band with massive type */}
      <FinalBigCTA onNavigate={onNavigate} />
    </>
  );
}

/* ──────────── SectorMarquee ──────────── */
// Generic sector logos — single line of large uppercase type on black.
// Reads as a "trusted by" wall without claiming specific clients.
function SectorMarquee() {
  const sectors = [
    "Tier-1 construction",
    "Utilities",
    "Rail",
    "Highways",
    "Oil & gas",
    "BESS",
    "Private estates",
    "Defence",
    "Events",
    "Government",
  ];
  // Render twice for seamless horizontal scroll.
  const items = [...sectors, ...sectors];
  return (
    <section style={{
      background: "#000", color: "#fff",
      padding: "44px 0",
      borderBottom: "1px solid rgba(255,255,255,0.1)",
      overflow: "hidden",
      position: "relative",
    }}>
      <style>{`
        @keyframes solo-sector-marquee {
          0%   { transform: translateX(0); }
          100% { transform: translateX(-50%); }
        }
      `}</style>
      <div style={{
        display: "flex", gap: 56,
        // 50% width per loop = continuous; 60s = languid pace
        animation: "solo-sector-marquee 60s linear infinite",
        whiteSpace: "nowrap",
        width: "max-content",
      }}>
        {items.map((s, i) => (
          <span key={`${s}-${i}`} style={{
            display: "inline-flex", alignItems: "center", gap: 56,
            fontFamily: "var(--font-display)", fontWeight: 700,
            fontSize: "clamp(20px, 2.6vw, 36px)",
            letterSpacing: "0.005em", textTransform: "uppercase",
            color: "rgba(255,255,255,0.7)",
          }}>
            {s}
            <span style={{ color: "rgba(255,255,255,0.25)" }}>·</span>
          </span>
        ))}
      </div>
    </section>
  );
}

/* ──────────── PlatformBand ──────────── */
// Photo-led product showcase. Big monochrome image slots.
// Different visual treatment than the rest of the site's product grids.
function PlatformBand({ onNavigate }) {
  const featured = (window.SOLO_DATA?.products || [])
    .filter(p => !p.isLegacy && !p.comingSoon)
    .slice(0, 3);

  return (
    <section style={{
      background: "var(--bg)",
      borderBottom: "1px solid var(--line)",
      padding: "120px 36px 80px",
    }}>
      <div style={{ maxWidth: 1480, margin: "0 auto" }}>
        {/* Left-rail eyebrow / right-rail h2 — same rhythm as elsewhere on site
            so it doesn't fight the brand system, just different content treatment below */}
        <div style={{
          display: "grid", gridTemplateColumns: "1fr 1.6fr",
          gap: 80, marginBottom: 64, alignItems: "end",
        }}>
          <Eyebrow>The platform</Eyebrow>
          <h2 style={{
            fontFamily: "var(--font-display)", fontWeight: 700,
            fontSize: "clamp(40px, 5.4vw, 84px)", lineHeight: 0.96,
            letterSpacing: "-0.005em", textTransform: "uppercase",
            margin: 0, color: "var(--fg)", maxWidth: 900,
          }}>
            Seven units. One operating system.
          </h2>
        </div>

        <div style={{
          display: "grid", gridTemplateColumns: "repeat(3, 1fr)",
          gap: 24,
        }}>
          {featured.map((p, i) => (
            <PlatformProductCard key={p.id} product={p} index={i} onNavigate={onNavigate} />
          ))}
        </div>

        <div style={{ marginTop: 32, display: "flex", justifyContent: "flex-end" }}>
          <Button onClick={() => onNavigate("product")}>View all 7 products →</Button>
        </div>
      </div>
    </section>
  );
}

function PlatformProductCard({ product, index, onNavigate }) {
  return (
    <button
      type="button"
      onClick={() => onNavigate("product-detail", product.id)}
      style={{
        all: "unset", cursor: "pointer",
        display: "flex", flexDirection: "column",
        background: "var(--surface)",
        border: "1px solid var(--line)",
        transition: "border-color 160ms",
      }}
      onMouseEnter={(e) => e.currentTarget.style.borderColor = "var(--fg)"}
      onMouseLeave={(e) => e.currentTarget.style.borderColor = "var(--line)"}
    >
      {/* Product hero — dark studio background, per-product photo.
          Uses the shared productImage() resolver from pages.jsx so every
          platform card automatically picks up new product renders when
          they're swapped in (e.g. the RS1 update). */}
      <div style={{
        position: "relative",
        aspectRatio: "4 / 3",
        background: "#ffffff",
        borderBottom: "1px solid var(--line)",
        overflow: "hidden",
      }}>
        <img
          src={window.productImage ? window.productImage(product.id) : "assets/hero-studio-product.png"}
          alt={`${product.name} — product photograph`}
          style={{
            position: "absolute", inset: 0,
            width: "100%", height: "100%",
            objectFit: "contain",
            display: "block",
          }}
          loading="lazy"
        />
      </div>
      <div style={{ padding: "26px 26px 28px" }}>
        <div style={{
          fontFamily: "var(--font-body)", fontSize: 11,
          letterSpacing: "0.22em", color: "var(--fg-dim)",
          textTransform: "uppercase", marginBottom: 10, fontWeight: 500,
        }}>{product.type}</div>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 700,
          fontSize: 24, letterSpacing: "0.005em",
          textTransform: "uppercase", color: "var(--fg)",
          marginBottom: 12,
        }}>{product.name}</div>
        <p style={{
          fontFamily: "var(--font-body)", fontSize: 14,
          lineHeight: 1.55, color: "var(--fg-soft)",
          margin: 0,
        }}>{product.tagline}</p>
        <div style={{
          marginTop: 22, paddingTop: 16, borderTop: "1px solid var(--line)",
          display: "flex", justifyContent: "space-between", alignItems: "center",
          fontFamily: "var(--font-body)", fontSize: 11,
          letterSpacing: "0.22em", textTransform: "uppercase",
          color: "var(--fg)", fontWeight: 500,
        }}>
          <span>View specifications</span>
          <span>→</span>
        </div>
      </div>
    </button>
  );
}

/* ──────────── ChapterPhoto ──────────── */
// Full-bleed image break between content sections — no headline, no card,
// just an arresting photo. Acts as a visual chapter divider.
function ChapterPhoto({ id, placeholder, caption, src, pendingLabel, objectPosition }) {
  // Three rendering modes:
  //   1) src supplied            → render <img>, caption overlay bottom-left
  //   2) pendingLabel supplied   → render "photo pending" chapter card
  //                                 (production-safe holding state)
  //   3) neither supplied        → don't render (defensive; keeps launch clean)
  const showImage = !!src;
  const showPending = !src && !!pendingLabel;
  if (!showImage && !showPending) return null;

  return (
    <section style={{
      position: "relative",
      width: "100%",
      aspectRatio: "21 / 9",
      maxHeight: "70vh",
      background: "#000",
      borderBottom: "1px solid var(--line)",
      overflow: "hidden",
    }}>
      {showImage && (
        <>
          <img
            src={src}
            alt={caption || ""}
            style={{
              position: "absolute", inset: 0,
              width: "100%", height: "100%",
              objectFit: "cover",
              objectPosition: objectPosition || "center center",
              display: "block",
            }}
            loading="lazy"
          />
          {/* Slight bottom vignette so the caption stays legible on
              light image regions */}
          <div aria-hidden style={{
            position: "absolute", left: 0, right: 0, bottom: 0,
            height: "40%",
            background: "linear-gradient(to top, rgba(0,0,0,0.6), rgba(0,0,0,0))",
            pointerEvents: "none",
          }} />
        </>
      )}

      {showPending && (
        <div style={{
          position: "absolute", inset: 0,
          display: "flex", alignItems: "center", justifyContent: "center",
          flexDirection: "column", gap: 14,
          textAlign: "center", padding: 40,
        }}>
          <div style={{
            fontFamily: "var(--font-body)", fontSize: 10, fontWeight: 500,
            letterSpacing: "0.32em", textTransform: "uppercase",
            color: "rgba(255,255,255,0.35)",
          }}>Photo pending</div>
          <div style={{
            fontFamily: "var(--font-display)", fontWeight: 700,
            fontSize: "clamp(28px, 3.6vw, 52px)", lineHeight: 1.05,
            letterSpacing: "-0.005em", textTransform: "uppercase",
            color: "rgba(255,255,255,0.85)", maxWidth: 720,
          }}>{pendingLabel}</div>
        </div>
      )}

      {caption && (
        <div style={{
          position: "absolute", bottom: 22, left: 28,
          fontFamily: "var(--font-body)", fontSize: 11,
          letterSpacing: "0.22em", textTransform: "uppercase",
          color: "rgba(255,255,255,0.7)",
          background: "rgba(0,0,0,0.45)",
          padding: "6px 10px",
          backdropFilter: "blur(4px)",
          fontWeight: 500,
          zIndex: 2,
        }}>{caption}</div>
      )}
    </section>
  );
}

/* ──────────── OperatingModel ──────────── */
// Three big numerals reflecting the self-funded story. No cards, no borders —
// just brutal type on a clean surface.
function OperatingModel({ onNavigate }) {
  const blocks = [
    { stat: "2,000+",   label: "Units shipped",         body: "All without external capital. Self-funded since 2019, reinvesting every penny into the platform." },
    { stat: "3",        label: "Factories",             body: "Bedfordshire HQ. Wrocław. Wellington, Florida. Engineered and built in-house, by the group." },
    { stat: "100%",     label: "Engineer-led",          body: "Owner-operated. Every decision made with a technical vision. No committee, no handoff." },
  ];
  return (
    <section style={{
      padding: "120px 36px",
      background: "var(--bg)",
      borderBottom: "1px solid var(--line)",
    }}>
      <div style={{ maxWidth: 1480, margin: "0 auto" }}>
        <div style={{
          display: "grid", gridTemplateColumns: "1fr 1.6fr",
          gap: 80, marginBottom: 80, alignItems: "end",
        }}>
          <Eyebrow>The operating model</Eyebrow>
          <h2 style={{
            fontFamily: "var(--font-display)", fontWeight: 700,
            // Capped at 60px (was 84px) — at the old ceiling the longest
            // line, "Owner-operated.", measured wider than its own column
            // at desktop widths (1203px in an 861px column at 1600px
            // viewport), forcing the browser to additionally wrap at the
            // internal hyphens and turning the intended clean 3-line
            // heading into a broken-looking 5-line one. Measured against
            // the real column width at 1280/1440/1600px viewports and
            // reduced so every phrase fits on its own single line with
            // margin to spare.
            fontSize: "clamp(28px, 3.8vw, 60px)", lineHeight: 1.05,
            letterSpacing: "-0.005em", textTransform: "uppercase",
            margin: 0, color: "var(--fg)", maxWidth: 900,
          }}>
            Self-funded.<br />Engineer-led.<br />Owner-operated.
          </h2>
        </div>

        <div style={{
          display: "grid", gridTemplateColumns: "repeat(3, 1fr)",
          gap: 0,
          borderTop: "1px solid var(--line)",
        }}>
          {blocks.map((b, i) => (
            <div key={i} style={{
              padding: "44px 36px 4px",
              borderRight: i < 2 ? "1px solid var(--line)" : "none",
            }}>
              <div style={{
                fontFamily: "var(--font-display)", fontWeight: 700,
                fontSize: "clamp(56px, 8vw, 112px)", lineHeight: 0.9,
                letterSpacing: "-0.02em", color: "var(--fg)",
                marginBottom: 22,
              }}>{b.stat}</div>
              <div style={{
                fontFamily: "var(--font-body)", fontSize: 11,
                letterSpacing: "0.22em", textTransform: "uppercase",
                color: "var(--fg-dim)", fontWeight: 500, marginBottom: 16,
              }}>{b.label}</div>
              <p style={{
                fontFamily: "var(--font-body)", fontSize: 15,
                lineHeight: 1.55, color: "var(--fg-soft)",
                margin: 0, maxWidth: 360,
              }}>{b.body}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ──────────── PartnerCallout ──────────── */
function PartnerCallout({ onNavigate }) {
  return (
    <section style={{
      padding: "120px 36px",
      background: "var(--surface)",
      borderBottom: "1px solid var(--line)",
    }}>
      <div style={{
        maxWidth: 1480, margin: "0 auto",
        display: "grid", gridTemplateColumns: "1.3fr 1fr",
        gap: 80, alignItems: "center",
      }}>
        <div>
          <Eyebrow style={{ marginBottom: 28 }}>The partner channel</Eyebrow>
          <h2 style={{
            fontFamily: "var(--font-display)", fontWeight: 700,
            fontSize: "clamp(36px, 4.8vw, 64px)", lineHeight: 1.02,
            letterSpacing: "-0.005em", textTransform: "uppercase",
            margin: "0 0 24px", color: "var(--fg)", maxWidth: 800,
          }}>
            Solo sells exclusively through approved partners.
          </h2>
          <p style={{
            fontFamily: "var(--font-body)", fontSize: 17,
            lineHeight: 1.55, color: "var(--fg-soft)",
            margin: 0, maxWidth: 620,
          }}>
            Gold and Platinum partners across North America; exclusive partner regions across the UK and EU. We protect your margin, protect your leads, and back you with the field support of a UK manufacturer that ships every week.
          </p>
        </div>
        <div style={{ display: "flex", flexDirection: "column", gap: 14, alignItems: "flex-start" }}>
          <Button primary onClick={() => onNavigate("partners", { subject: "Join the partner programme" })}>
            Join the partner programme →
          </Button>
          <Button onClick={() => onNavigate("partners")}>
            See partner tiers
          </Button>
        </div>
      </div>
    </section>
  );
}

/* ──────────── FinalBigCTA ──────────── */
function FinalBigCTA({ onNavigate }) {
  return (
    <section style={{
      padding: "140px 36px",
      background: "#000", color: "#fff",
      borderBottom: "1px solid var(--line)",
    }}>
      <div style={{ maxWidth: 1480, margin: "0 auto" }}>
        <div style={{
          fontFamily: "var(--font-body)", fontSize: 12,
          letterSpacing: "0.32em", textTransform: "uppercase",
          color: "rgba(255,255,255,0.5)", fontWeight: 500,
          marginBottom: 40,
        }}>Ready to deploy</div>
        <h2 style={{
          fontFamily: "var(--font-display)", fontWeight: 700,
          fontSize: "clamp(56px, 9vw, 160px)", lineHeight: 0.88,
          letterSpacing: "-0.012em", textTransform: "uppercase",
          margin: "0 0 56px", color: "#fff",
        }}>
          Build a tower.<br />Ship the platform.
        </h2>
        <div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
          <button
            onClick={() => onNavigate("builder")}
            style={{
              background: "#fff", color: "#000", border: "1px solid #fff",
              padding: "20px 32px", cursor: "pointer",
              fontFamily: "var(--font-body)", fontSize: 13, fontWeight: 500,
              letterSpacing: "0.22em", textTransform: "uppercase",
            }}>Build a tower →</button>
          <button
            onClick={() => onNavigate("contact", { subject: "Request a demo" })}
            style={{
              background: "transparent", color: "#fff",
              border: "1px solid rgba(255,255,255,0.4)",
              padding: "20px 32px", cursor: "pointer",
              fontFamily: "var(--font-body)", fontSize: 13, fontWeight: 500,
              letterSpacing: "0.22em", textTransform: "uppercase",
            }}>Request a demo</button>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { HomePage });
