// Home hero — full-bleed photographic background with overlaid headline,
// intro paragraph, two CTAs, and a 4-stat strip along the bottom.
//
// Background: a slow crossfade slideshow cycling through 4 hero scenes —
// Construction at dusk · Substation/BESS at blue hour · Motorway at night ·
// Studio product hero. Each scene is visible for ~8 seconds with a soft
// ~1.5-second crossfade between. Total cycle: 32 seconds.
//
// A horizontal gradient darkens the left side so the headline reads
// cleanly across all four scenes; a vertical gradient grounds the bottom
// for the stat strip.

/* ──────────── HomeHUDHero — the hero block ──────────── */
function HomeHUDHero({ onNavigate }) {
  return (
    <section style={{
      position: "relative",
      background: "#000",
      color: "#fff",
      minHeight: "calc(100vh - 88px)",
      // Generous top/bottom padding so headline and HUD breathe even on tall screens.
      padding: "60px 36px 80px",
      overflow: "hidden",
      borderBottom: "1px solid rgba(255,255,255,0.1)",
    }}>
      {/* Animation keyframes — 4-scene crossfade slideshow.
            Each scene visible 100% for ~6.5s, then crossfades over ~1.5s
            to the next. Total cycle: 32s (8s per scene).
            Layers are offset by 8s each so they crossfade in sequence.

            Cycle anatomy for each scene (32s = 100%):
               0% — fade in starts (from previous scene)
               5% — fully visible
              25% — still fully visible (end of "hold")
              30% — faded out
              100% — stays at 0 until cycle restart

            Slot 1: 0–32%  visible       (peak 0–25%)
            Slot 2: 25–57% visible       (peak 25–50%)
            Slot 3: 50–82% visible       (peak 50–75%)
            Slot 4: 75–100% + 0–7%       (peak 75–100% wrapping to 0–5%) */}
      <style>{`
        @keyframes solo-bg-slot-1 {
          0%, 25%   { opacity: 1; }
          30%, 95%  { opacity: 0; }
          100%      { opacity: 1; }
        }
        @keyframes solo-bg-slot-2 {
          0%, 20%   { opacity: 0; }
          25%, 50%  { opacity: 1; }
          55%, 100% { opacity: 0; }
        }
        @keyframes solo-bg-slot-3 {
          0%, 45%   { opacity: 0; }
          50%, 75%  { opacity: 1; }
          80%, 100% { opacity: 0; }
        }
        @keyframes solo-bg-slot-4 {
          0%, 70%   { opacity: 0; }
          75%, 100% { opacity: 1; }
        }
      `}</style>

      {/* ── Background slideshow ──
          Four hero scenes layered on top of each other, each fading in
          and out in sequence. Total cycle: 32 seconds, 8 seconds per scene.
          All four images are sized to cover the hero box and centred so
          the tower stays roughly in the middle of the frame on each.

          To swap scene order or change durations: edit the array below
          and the corresponding keyframes above. */}
      {[
        { src: "assets/hero-construction-dusk.png", anim: "solo-bg-slot-1" },
        { src: "assets/hero-substation-bess.png",   anim: "solo-bg-slot-2" },
        { src: "assets/hero-motorway-night.png",    anim: "solo-bg-slot-3" },
        { src: "assets/hero-studio-product.png",    anim: "solo-bg-slot-4" },
      ].map((layer, i) => (
        <div key={layer.src} aria-hidden style={{
          position: "absolute", inset: 0,
          backgroundImage: `url("${layer.src}")`,
          backgroundSize: "cover",
          backgroundPosition: "center center",
          backgroundRepeat: "no-repeat",
          animation: `${layer.anim} 32s ease-in-out infinite`,
          willChange: "opacity",
          zIndex: 0,
        }} />
      ))}

      {/* Gradient overlay — darkens the left side so the headline reads
          cleanly. Keeps the right side (where the tower lives) more visible.
          Sits above all photo layers (z=0 crowd frames, z=1 dim pulse) and
          below the page content (z=3). */}
      <div aria-hidden style={{
        position: "absolute", inset: 0,
        background:
          "linear-gradient(90deg, rgba(0,0,0,0.78) 0%, rgba(0,0,0,0.5) 45%, rgba(0,0,0,0.25) 70%, rgba(0,0,0,0.45) 100%), " +
          "linear-gradient(180deg, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,0.5) 100%)",
        zIndex: 2,
      }} />

      {/* ── Decorative cross-hairs at the four corners ── */}
      <CornerMarks />

      <div style={{
        // zIndex 3 so the content sits above the LED-pulse overlay (z=2)
        position: "relative", zIndex: 3,
        maxWidth: 1480, margin: "0 auto",
        height: "100%",
        display: "grid",
        // 2 rows: content / stat strip
        gridTemplateRows: "1fr auto",
        gap: 40,
      }}>
        {/* ── Headline column ── */}
        <div style={{
          position: "relative",
          display: "flex",
          alignItems: "center",
        }}>
          <div style={{
            maxWidth: 760, zIndex: 3,
          }}>
            <h1 style={{
              fontFamily: "var(--font-display)", fontWeight: 700,
              // Capped at 84px (was 100px, originally 112px) — Michroma
              // only ships a 400 (regular) static weight, so requesting
              // 700 forces every browser to synthesize a faux-bold.
              // Different browsers widen glyphs by different amounts when
              // doing this. Measured directly against this column's real
              // 760px width: at 100px font-size the single word
              // "REDEFINED" alone rendered ~798px wide — wider than the
              // column — guaranteeing a mid-word break ("REDEFINE"/"D")
              // regardless of any wrap/hyphen CSS. 84px keeps every word
              // in "We redefined" / "mobile security." comfortably under
              // the column width with margin to spare.
              fontSize: "clamp(44px, 5.8vw, 84px)", lineHeight: 0.94,
              letterSpacing: "-0.01em", textTransform: "uppercase",
              margin: "0 0 24px", color: "#fff",
              // Subtle text-shadow keeps the massive headline crisp against
              // the festival photo's bright stage lights and crowd silhouettes.
              textShadow: "0 2px 12px rgba(0,0,0,0.4)",
              // Belt-and-suspenders, matching the pattern used elsewhere on
              // the site (pages.jsx, partner-pages.jsx): if a break is ever
              // unavoidable, prefer a clean word-boundary wrap over a
              // mid-glyph split. NOTE: deliberately no soft hyphens (&shy;)
              // here — tested and confirmed they backfire with
              // overflow-wrap: break-word, causing the browser to
              // opportunistically split "mobile security." mid-word
              // ("mobile securi" / "ty.") even when a clean whole-word wrap
              // ("MOBILE" / "SECURITY.") was available and used without them.
              maxWidth: "100%", overflowWrap: "break-word",
              wordBreak: "normal", hyphens: "manual",
            }}>
              We redefined<br />mobile security.
            </h1>
            <p style={{
              fontFamily: "var(--font-body)", fontSize: 19,
              lineHeight: 1.4,
              // Brighter than before so it reads against the festival photo
              color: "rgba(255,255,255,0.85)",
              // Tiny text shadow for legibility against busy photo areas
              textShadow: "0 1px 2px rgba(0,0,0,0.4)",
              maxWidth: 560, margin: "0 0 36px",
            }}>
              Secure beyond limits. Solo designs, manufactures and supports the platform behind 2,000+ rapidly-deployable security units across the UK, Europe, North America and the GCC.
            </p>
            <div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
              <HudButton primary onClick={() => onNavigate("builder")}>Build a tower →</HudButton>
            </div>

            {/* ── Product quick-list ──
                SEO: puts real, crawlable product names + links directly
                under the H1 (this is the primary heading on the page a
                search engine associates with the site's core keywords),
                reinforcing the "mobile CCTV tower" topical relevance right
                at the top instead of relying solely on deeper pages.
                Also serves as a fast, above-the-fold way for a visitor to
                jump straight to a specific product. Excludes comingSoon,
                accessory (RS1/RS2/Volt Box) and legacy products — this is
                the live tower + SSU range only, matching the mega-menu's
                primary grouping. */}
            <nav aria-label="Product range" style={{ marginTop: 28 }}>
              <div style={{
                fontFamily: "var(--font-body)", fontSize: 11,
                letterSpacing: "0.22em", textTransform: "uppercase",
                color: "rgba(255,255,255,0.55)", marginBottom: 12,
              }}>The range</div>
              <ul style={{
                display: "flex", flexWrap: "wrap", gap: "10px 22px",
                listStyle: "none", margin: 0, padding: 0,
              }}>
                {window.SOLO_DATA.products
                  .filter(p => !p.comingSoon && !p.isAccessory && !p.isLegacy)
                  .map(p => (
                    <li key={p.id}>
                      <a
                        href={`/?page=product-detail&id=${p.id}`}
                        onClick={(e) => { e.preventDefault(); onNavigate("product-detail", p.id); }}
                        style={{
                          fontFamily: "var(--font-body)", fontSize: 15, fontWeight: 500,
                          color: "#fff", textDecoration: "none",
                          borderBottom: "1px solid rgba(255,255,255,0.35)",
                          paddingBottom: 2,
                          textShadow: "0 1px 2px rgba(0,0,0,0.4)",
                        }}
                      >{p.name}</a>
                    </li>
                  ))}
              </ul>
            </nav>
          </div>

        </div>

        {/* ── Bottom row: signature stat strip ──
            Vertical row list, not a 4-col grid — "Since 2019" wrapped to
            2 lines while its siblings stayed single-line, misaligning
            every label across the row. */}
        <div style={{ paddingTop: 8 }}>
          <StatRow dark stats={[
            ["2,000+",   "Units shipped"],
            ["3",        "Factories"],
            ["4",        "Regions"],
            ["Since 2019", "Self-funded growth"],
          ]} />
        </div>
      </div>
    </section>
  );
}

/* ──────────── Small bits ──────────── */
function CornerMarks() {
  // Four small L-shaped marks at the corners of the hero block — adds the
  // operator-console framing without taking attention.
  const arm = 24;
  const off = 22;
  // Split props: style-related keys go into `style`, HTML attributes
  // (e.g. data-om-id injected by the design tool) go on the element
  // itself. Prevents React "Unsupported style property" warnings.
  const styleKeys = new Set(["top", "right", "bottom", "left", "width", "height"]);
  const Stroke = (props) => {
    const styleProps = {};
    const domProps = {};
    for (const [k, v] of Object.entries(props)) {
      if (styleKeys.has(k)) styleProps[k] = v;
      else domProps[k] = v;
    }
    return (
      <span
        {...domProps}
        style={{
          position: "absolute",
          background: "rgba(255,255,255,0.3)",
          ...styleProps,
        }}
      />
    );
  };
  return (
    <div aria-hidden style={{ position: "absolute", inset: 0, pointerEvents: "none", zIndex: 1 }}>
      {/* top-left */}
      <Stroke top={off} left={off} width={arm} height={1} />
      <Stroke top={off} left={off} width={1}   height={arm} />
      {/* top-right */}
      <Stroke top={off} right={off} width={arm} height={1} />
      <Stroke top={off} right={off} width={1}   height={arm} />
      {/* bottom-left */}
      <Stroke bottom={off} left={off} width={arm} height={1} />
      <Stroke bottom={off} left={off} width={1}   height={arm} />
      {/* bottom-right */}
      <Stroke bottom={off} right={off} width={arm} height={1} />
      <Stroke bottom={off} right={off} width={1}   height={arm} />
    </div>
  );
}

function Pulse({ on = true, small }) {
  const s = small ? 5 : 6;
  return (
    <span style={{
      position: "relative", width: s, height: s,
      display: "inline-block",
    }}>
      <span style={{
        position: "absolute", inset: 0,
        background: on ? "#fff" : "rgba(255,255,255,0.4)",
        borderRadius: "50%",
      }} />
      {on && (
        <span style={{
          position: "absolute", inset: 0,
          background: "rgba(255,255,255,0.5)",
          borderRadius: "50%",
          animation: "solo-hud-pulse 1.6s cubic-bezier(0,0,0.2,1) infinite",
        }} />
      )}
      <style>{`
        @keyframes solo-hud-pulse {
          0%   { transform: scale(1);   opacity: 0.7; }
          70%  { transform: scale(2.6); opacity: 0;   }
          100% { transform: scale(2.6); opacity: 0;   }
        }
      `}</style>
    </span>
  );
}

// Dark-theme button styled to match the HUD aesthetic.
function HudButton({ primary, onClick, children }) {
  const [hover, setHover] = useState(false);
  const filled = primary && !hover;
  const hoverFilled = primary && hover;
  return (
    <button
      onClick={onClick}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        background: primary
          ? (hover ? "rgba(255,255,255,0.85)" : "#fff")
          : (hover ? "rgba(255,255,255,0.08)" : "transparent"),
        color: primary ? "#000" : "#fff",
        border: `1px solid ${primary ? "#fff" : "rgba(255,255,255,0.4)"}`,
        padding: "16px 26px",
        cursor: "pointer",
        fontFamily: "var(--font-body)",
        fontSize: 13, fontWeight: 500,
        letterSpacing: "0.2em", textTransform: "uppercase",
        transition: "background 140ms",
      }}>
      {children}
    </button>
  );
}

Object.assign(window, { HomeHUDHero });
