// ── Hero — Imersão Mundo China · editorial, locked to viewport.
// The hero composite already contains Soong on stage with the
// Shanghai skyline + world-trade arc, so we use it as the single
// full-bleed background and overlay only the editorial copy + washes.

function useCountdown(targetIso) {
  const target = React.useMemo(() => new Date(targetIso).getTime(), [targetIso]);
  const [now, setNow] = React.useState(() => Date.now());
  React.useEffect(() => {
    const t = setInterval(() => setNow(Date.now()), 1000 * 60); // minute tick
    return () => clearInterval(t);
  }, []);
  let diff = Math.max(0, target - now);
  const d = Math.floor(diff / 86400000); diff -= d * 86400000;
  const h = Math.floor(diff / 3600000);  diff -= h * 3600000;
  const m = Math.floor(diff / 60000);
  return { d, h, m, isPast: now >= target };
}

function Hero({ onCta }) {
  const cd = useCountdown("2026-06-24T09:00:00-03:00");
  return (
    <header
      className="pf-hero"
      style={{
        position: "relative",
        minHeight: "min(100svh, 1080px)",
        overflow: "hidden",
        background: "var(--abyss)",
        display: "grid",
        gridTemplateRows: "auto 1fr auto",
      }}
    >
      {/* hero background — Shanghai skyline + stage */}
      <div
        className="pf-hero-bg"
        style={{
          backgroundImage: "url(assets/hero-stage-bg.jpg)",
        }}
      />

      {/* Stage light/glow behind the expert */}
      <div className="pf-hero-expert-glow" />

      {/* Centered Expert Image */}
      <div className="pf-hero-expert-container">
        <img
          src="assets/soong-expert-center.png"
          alt="Soong"
          className="pf-hero-expert-img"
        />
      </div>

      {/* gradient washes — strong on the left so the copy column stays
          legible over the world-map artwork, plus top/bottom + vignette
          + grain + bottom fade into the page. */}
      <div style={{ position: "absolute", inset: 0, zIndex: 1, background: "linear-gradient(90deg, rgba(3,5,13,0.92) 0%, rgba(3,5,13,0.78) 22%, rgba(3,5,13,0.40) 40%, rgba(3,5,13,0.05) 58%, transparent 72%)" }} />
      <div style={{ position: "absolute", inset: 0, zIndex: 1, background: "linear-gradient(180deg, rgba(3,5,13,0.55) 0%, transparent 16%, transparent 52%, rgba(6,9,18,0.40) 74%, rgba(6,9,18,0.85) 92%, var(--void) 100%)" }} />
      <div style={{ position: "absolute", inset: 0, zIndex: 1, boxShadow: "inset 0 0 160px 30px rgba(3,5,13,0.45)" }} />
      <div className="pf-grain" style={{ position: "absolute", inset: 0, zIndex: 1, opacity: 0.04, mixBlendMode: "overlay", pointerEvents: "none" }} />
      <div aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: "180px", zIndex: 1, background: "linear-gradient(180deg, transparent 0%, rgba(6,9,18,0.5) 40%, rgba(3,5,13,0.92) 80%, var(--void) 100%)", pointerEvents: "none" }} />

      {/* ── TOP ROW: top-right stat ────────────────────── */}
      <div className="pf-hero-top" style={{ position: "relative", zIndex: 3, padding: "20px clamp(20px,3.5vw,44px) 0", display: "flex", justifyContent: "flex-end", alignItems: "flex-start", gap: "24px" }}>
        <Reveal delay={0.08}>
          <div className="pf-hero-stat" style={{ textAlign: "right", maxWidth: "250px", textShadow: "0 2px 14px rgba(3,5,13,0.85)" }}>
            <div style={{ fontFamily: "var(--f-serif)", fontWeight: 400, fontSize: "clamp(1.05rem,1.6vw,1.55rem)", color: "var(--txt-white)", letterSpacing: "-0.01em", lineHeight: 1 }}>
              +R$ 100 milhões
            </div>
            <div style={{ fontFamily: "var(--f-body)", fontSize: ".68rem", color: "var(--txt-soft)", lineHeight: 1.5, marginTop: "6px" }}>
              importados direto da China por quem conduz a imersão.
            </div>
          </div>
        </Reveal>
      </div>

      {/* ── MIDDLE: wordmark / headline / body — left column ─ */}
      <div className="pf-hero-mid" style={{ position: "relative", zIndex: 3, padding: "0 clamp(20px,3.5vw,44px)", maxWidth: "600px", alignSelf: "center", display: "flex", flexDirection: "column", justifyContent: "center" }}>
        <Reveal delay={0.1}>
          <div style={{ marginBottom: "22px", display: "flex", flexDirection: "column", gap: "0px" }}>
            <div style={{ fontFamily: "var(--f-serif)", fontStyle: "italic", fontWeight: 400, fontSize: "clamp(1.7rem,3.4vw,2.9rem)", lineHeight: 0.98, letterSpacing: "-0.02em", color: "var(--txt-white)", textShadow: "0 4px 24px rgba(3,5,13,0.95), 0 2px 8px rgba(3,5,13,0.85)" }}>
              Imersão
            </div>
            <div style={{ fontFamily: "var(--f-serif)", fontStyle: "italic", fontWeight: 400, fontSize: "clamp(2.6rem,5.4vw,4.8rem)", lineHeight: 0.95, letterSpacing: "-0.025em", color: "var(--go-4)", textShadow: "0 2px 22px rgba(var(--go-rgb),0.45), 0 6px 28px rgba(3,5,13,0.92)" }}>
              Mundo China<span style={{ color: "var(--go-3)" }}>.</span>
            </div>
          </div>
        </Reveal>
        <Reveal delay={0.2}>
          <h1 style={{ fontFamily: "var(--f-serif)", fontWeight: 400, fontStyle: "normal", fontSize: "clamp(1.2rem,2.2vw,2.05rem)", lineHeight: 1.14, letterSpacing: "-0.012em", color: "var(--txt-white)", margin: "0 0 16px", textShadow: "0 4px 24px rgba(3,5,13,0.97), 0 2px 8px rgba(3,5,13,0.85)" }}>
            Pare de comprar caro de quem<br />
            <span className="pf-glow-text" style={{ fontStyle: "italic" }}>compra antes de você.</span>
          </h1>
        </Reveal>
        <Reveal delay={0.28}>
          <p style={{ fontFamily: "var(--f-body)", fontSize: "clamp(.88rem,.95vw,.98rem)", lineHeight: 1.62, color: "var(--txt-soft)", maxWidth: "480px", margin: 0, textShadow: "0 2px 10px rgba(3,5,13,0.85)" }}>
            Dois dias presenciais em Alphaville, com <strong style={{ color: "var(--txt-white)", fontWeight: 600 }}>Soong</strong>, para entender o caminho de negociar direto na fonte, enxergar fornecedores por trás dos intermediários e se preparar para a maior feira de fornecedores do mundo, em outubro.
          </p>
        </Reveal>

        {/* MOBILE-ONLY inline CTA — visible only on phones */}
        <Reveal delay={0.34}>
          <div className="pf-hero-cta-inline" style={{ display: "none", marginTop: "26px", flexDirection: "column", alignItems: "flex-start", gap: "10px" }}>
            <Button variant="primary" size="md" onClick={onCta} shimmer>Garantir minha vaga →</Button>
            <div style={{ display: "inline-flex", alignItems: "center", gap: "8px", fontFamily: "var(--f-mono)", fontSize: ".62rem", letterSpacing: ".06em", color: "var(--txt-soft)", textShadow: "0 2px 10px rgba(3,5,13,0.9)" }}>
              <span style={{ width: "7px", height: "7px", borderRadius: "50%", background: "var(--go-4)", animation: "pfPulse 1.4s ease-in-out infinite" }} />
              Vagas limitadas ao espaço físico
            </div>
          </div>
        </Reveal>
      </div>

      {/* ── CENTERED CTA — anchored bottom-center of hero (desktop) ───── */}
      <div className="pf-hero-cta" style={{ position: "absolute", left: "50%", bottom: "clamp(110px,16vh,160px)", transform: "translateX(-50%)", zIndex: 4, display: "flex", flexDirection: "column", alignItems: "center", gap: "12px", textAlign: "center" }}>
        <Reveal delay={0.36}>
          <Button variant="primary" size="md" onClick={onCta} shimmer>Garantir minha vaga em Alphaville →</Button>
        </Reveal>
        <Reveal delay={0.42}>
          <div style={{ display: "inline-flex", alignItems: "center", gap: "8px", fontFamily: "var(--f-mono)", fontSize: ".64rem", letterSpacing: ".06em", color: "var(--txt-soft)", textShadow: "0 2px 10px rgba(3,5,13,0.9)" }}>
            <span style={{ width: "7px", height: "7px", borderRadius: "50%", background: "var(--go-4)", animation: "pfPulse 1.4s ease-in-out infinite" }} />
            Encontro presencial · vagas limitadas
          </div>
        </Reveal>
      </div>

      {/* ── BOTTOM ROW: bio · event stat + countdown ──────────────────────── */}
      <div className="pf-hero-bot" style={{ position: "relative", zIndex: 3, padding: "0 clamp(20px,3.5vw,44px) clamp(18px,3vh,28px)", display: "flex", justifyContent: "space-between", alignItems: "flex-end", gap: "32px" }}>
        <Reveal delay={0.44}>
          <div style={{ maxWidth: "320px", textShadow: "0 2px 12px rgba(3,5,13,0.85)" }}>
            <div style={{ fontFamily: "var(--f-mono)", fontSize: ".64rem", fontWeight: 500, letterSpacing: ".22em", textTransform: "uppercase", color: "var(--go-3)", marginBottom: "10px" }}>
              Quem conduz
            </div>
            <p style={{ fontFamily: "var(--f-body)", fontSize: ".76rem", lineHeight: 1.55, color: "var(--txt-soft)", margin: 0 }}>
              Soong vive na China e conhece o mercado por dentro. A ponte real entre o empresário brasileiro e a China dos negócios: fornecedores, fábricas e negociação na fonte.
            </p>
          </div>
        </Reveal>
        <Reveal delay={0.5}>
          <div style={{ textAlign: "right", maxWidth: "260px", textShadow: "0 2px 14px rgba(3,5,13,0.9)" }}>
            <div style={{ fontFamily: "var(--f-serif)", fontWeight: 400, fontSize: "clamp(1.2rem,1.9vw,1.75rem)", color: "var(--txt-white)", letterSpacing: "-0.01em", lineHeight: 1 }}>
              24 · 25 Junho
            </div>
            <div style={{ fontFamily: "var(--f-body)", fontSize: ".7rem", color: "var(--txt-soft)", lineHeight: 1.5, marginTop: "6px" }}>
              2026 · Alphaville · com Soong.
            </div>
            {!cd.isPast && (
              <div style={{ marginTop: "10px", display: "inline-flex", alignItems: "center", gap: "8px", padding: "5px 10px", borderRadius: "99px", border: "1px solid rgba(var(--go-rgb),0.35)", background: "rgba(var(--go-rgb),0.06)", fontFamily: "var(--f-mono)", fontSize: ".6rem", letterSpacing: ".14em", textTransform: "uppercase", color: "var(--go-4)" }}>
                <span style={{ width: "6px", height: "6px", borderRadius: "50%", background: "var(--go-4)", animation: "pfPulse 1.4s ease-in-out infinite" }} />
                Faltam {cd.d}d {cd.h}h
              </div>
            )}
          </div>
        </Reveal>
      </div>

      <style>{`
        /* ─── Hero Background ─── */
        .pf-hero-bg {
          position: absolute;
          inset: 0;
          z-index: 0;
          background-position: center 36%; /* shifted vertically to center the stage and skyline */
          background-size: cover;
          background-repeat: no-repeat;
          transition: all 0.3s ease;
        }

        /* ─── Expert Image and Glow ─── */
        .pf-hero-expert-glow {
          position: absolute;
          left: 50%;
          bottom: 8%;
          transform: translate(-50%, 0);
          width: 600px;
          height: 600px;
          background: radial-gradient(circle, rgba(var(--go-rgb), 0.35) 0%, rgba(3,5,13,0) 70%);
          z-index: 1;
          pointer-events: none;
          filter: blur(40px);
          opacity: 0.85;
        }

        .pf-hero-expert-container {
          position: absolute;
          left: 50%;
          bottom: -110px; /* moved down to sit lower and crop feet */
          transform: translateX(-50%);
          z-index: 2;
          height: 84vh;
          max-height: 840px;
          display: flex;
          align-items: flex-end;
          justify-content: center;
          pointer-events: none;
          transition: all 0.3s ease;
        }

        .pf-hero-expert-img {
          height: 100%;
          width: auto;
          object-fit: contain;
          filter: drop-shadow(0 15px 30px rgba(0,0,0,0.85)) 
                  drop-shadow(0 0 35px rgba(var(--go-rgb), 0.25));
        }

        /* ─── Mobile hero — full-bleed composite + stacked copy ───── */
        @media (max-width: 760px) {
          .pf-hero {
            min-height: 100svh !important;
            padding-bottom: 16px;
          }
          .pf-hero-bg {
            background-position: center 30% !important;
            background-size: cover !important;
          }
          /* On mobile, lift the whole frame so copy reads over the
             busy stage image: stronger top + bottom darkening. */
          .pf-hero > div[style*="linear-gradient(90deg"] {
            background: linear-gradient(180deg, rgba(3,5,13,0.85) 0%, rgba(3,5,13,0.50) 30%, rgba(3,5,13,0.40) 52%, rgba(3,5,13,0.80) 86%, var(--void) 100%) !important;
          }

          .pf-hero-top  { padding: 18px 20px 0 !important; }
          .pf-hero-mid  { padding: 18px 20px 8px !important; max-width: 100% !important; }
          .pf-hero-mid p { max-width: 85% !important; }
          .pf-hero-stat { max-width: 220px; }

          /* desktop center CTA → hide; inline CTA in copy column → show */
          .pf-hero-cta { display: none !important; }
          .pf-hero-cta-inline { display: flex !important; }

          /* Bottom row on mobile: keep date + countdown, drop bio (it's
             repeated in body copy) and left-align full-width. */
          .pf-hero-bot {
            display: flex !important;
            flex-direction: column !important;
            align-items: flex-start !important;
            gap: 6px !important;
            padding: 14px 20px 18px !important;
          }
          .pf-hero-bot > .pf-reveal:first-child { display: none !important; }
          .pf-hero-bot > .pf-reveal:last-child > div {
            text-align: left !important;
            max-width: 100% !important;
          }

          /* Responsive expert on mobile */
          .pf-hero-expert-glow {
            left: auto !important;
            right: -20px !important;
            transform: none !important;
            width: 280px;
            height: 280px;
            bottom: 5%;
          }

          .pf-hero-expert-container {
            left: auto !important;
            right: -15px !important; /* pull slightly off-screen to frame him nicely on the right edge */
            transform: none !important;
            height: 48vh !important; /* slightly smaller to avoid face collision with main text */
            bottom: -50px !important; /* sit lower to keep head clear of CTA */
            opacity: 0.95;
          }
        }
      `}</style>
    </header>
  );
}

window.Hero = Hero;
