// 22K hi-fi — Header + Hero (full-bleed cinematic reel).

function Header({ scrolled, theme, base = "" }) {
  const dark = theme === "dark";
  const fg = scrolled ? dark ? "var(--text)" : "var(--ink)" : "#fff";
  return (
    <header
      className="r-header"
      style={{
        position: "fixed",
        top: 0, left: 0, right: 0,
        zIndex: 50,
        display: "flex",
        alignItems: "center",
        justifyContent: "space-between",
        padding: scrolled ? "16px 36px" : "26px 36px",
        background: scrolled ? dark ? "rgba(10,10,10,.85)" : "rgba(244,241,234,.92)" : "transparent",
        backdropFilter: scrolled ? "blur(18px) saturate(140%)" : "none",
        borderBottom: scrolled ? "1px solid var(--line)" : "none",
        transition: "all .4s cubic-bezier(.2,.7,.2,1)",
        color: fg
      }}>
      
      <a href={base || "#top"} style={{ display: "flex", alignItems: "center" }}>
        <Wordmark22K size={24} color={fg} />
      </a>
      <nav style={{ display: "flex", alignItems: "center", gap: 36 }}>
        {[
        ["Trabalhos", "#trabalhos"],
        ["Sobre", "#sobre"],
        ["Contato", "#contato"]].
        map(([label, href]) =>
        <a
          key={label}
          href={base + href}
          className="mono r-hide-sm"
          style={{
            color: fg, fontSize: 11, letterSpacing: "0.14em",
            fontFamily: "'Helvetica Neue', Helvetica, sans-serif", fontWeight: 500
          }}>
          
            {label}
          </a>
        )}
        <a
          href={base + "#contato"}
          className="mono"
          style={{
            padding: "11px 18px",
            border: `1px solid ${fg}`,
            color: fg,
            fontSize: 11, letterSpacing: "0.14em",
            fontFamily: "'Helvetica Neue', Helvetica, sans-serif", fontWeight: 600,
            transition: "all .25s"
          }}>
          
          Agende agora
        </a>
      </nav>
    </header>);

}

// Vimeo reel — cycles through the 22K films in the hero background.
const VIMEO_REEL = [
  { id: 1199265366, h: "5378d5ecb8" },
  { id: 1199263586, h: "bf87c8aac9" },
  { id: 1199252213, h: "f4ad10db46" },
  { id: 1199252212, h: "d0d975c58d" },
  { id: 1199252211, h: "c31c91889f" },
  { id: 1199252210, h: "1417628739" },
  { id: 1199247097 },
  { id: 1199247096 },
  { id: 1199259582, h: "a6cc0b56e9" },
  { id: 1199259581, h: "7b72de52d7" },
];

function Hero({ variant = "bottom-split" }) {
  const [playing, setPlaying] = React.useState(true);
  const [clock, setClock] = React.useState("");
  const videoRef = React.useRef(null);

  React.useEffect(() => {
    const v = videoRef.current;
    if (v) { v.muted = true; const p = v.play(); if (p && p.catch) p.catch(() => {}); }
    const tick = () => setClock(new Date().toLocaleTimeString("pt-BR", {
      timeZone: "America/Sao_Paulo", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false
    }));
    tick();
    const id = setInterval(tick, 1000);
    return () => clearInterval(id);
  }, []);

  const togglePlay = () => {
    const v = videoRef.current;
    setPlaying((prev) => {
      const np = !prev;
      if (v) { np ? v.play().catch(() => {}) : v.pause(); }
      return np;
    });
  };

  return (
    <section
      id="top"
      style={{
        position: "relative",
        height: "100vh",
        minHeight: 720,
        background: "#000",
        overflow: "hidden",
        color: "#fff"
      }}>

      {/* full-bleed hero reel — local video (autoplay, muted, loop) */}
      <video
        ref={videoRef}
        autoPlay
        muted
        loop
        playsInline
        preload="auto"
        src="assets/hero-reel.mp4"
        style={{
          position: "absolute", inset: 0,
          width: "100%", height: "100%",
          objectFit: "cover",
          filter: "brightness(.7) contrast(1.05)"
        }} />

      {/* film grain over the video */}
      <div className="grain" style={{ position: "absolute", inset: 0, pointerEvents: "none" }} />

      {/* legibility gradient — top + bottom */}
      <div
        style={{
          position: "absolute", inset: 0,
          background:
          "linear-gradient(180deg, rgba(0,0,0,.6) 0%, rgba(0,0,0,0) 18%, rgba(0,0,0,0) 55%, rgba(0,0,0,.85) 100%)",
          pointerEvents: "none"
        }} />
      

      {/* top-right timecode */}
      <div
        className="mono"
        style={{
          position: "absolute", top: 110, right: 36,
          color: "rgba(255,255,255,.7)", fontSize: 11,
          display: "flex", flexDirection: "column", gap: 8, alignItems: "flex-end",
          lineHeight: 1.4
        }}>
        
        <span>Rio de Janeiro · BR</span>
        <span>{clock}</span>
      </div>

      {/* center play */}
      <button
        onClick={togglePlay}
        style={{
          position: "absolute", top: "50%", left: "50%", transform: "translate(-50%,-50%)",
          width: 96, height: 96, borderRadius: "50%",
          border: "1px solid rgba(255,255,255,.5)", background: "rgba(0,0,0,.18)",
          backdropFilter: "blur(8px)", color: "#fff", fontSize: 18,
          display: "flex", alignItems: "center", justifyContent: "center",
          transition: "all .3s"
        }}
        onMouseEnter={(e) => {e.currentTarget.style.borderColor = "#fff";e.currentTarget.style.transform = "translate(-50%,-50%) scale(1.06)";}}
        onMouseLeave={(e) => {e.currentTarget.style.borderColor = "rgba(255,255,255,.5)";e.currentTarget.style.transform = "translate(-50%,-50%)";}}
        aria-label={playing ? "Pausar reel" : "Tocar reel"}>
        
        {playing ?
        <svg width="18" height="20" viewBox="0 0 18 20" fill="currentColor"><rect x="0" y="0" width="6" height="20" /><rect x="12" y="0" width="6" height="20" /></svg> :

        <svg width="18" height="20" viewBox="0 0 18 20" fill="currentColor"><polygon points="0,0 18,10 0,20" /></svg>
        }
      </button>

      {/* bottom-right CTAs */}
      <div
        className="r-hero-cta"
        style={{
          position: "absolute", bottom: 96, right: 36,
          display: "flex", alignItems: "center", gap: 28
        }}>
        
        <a href="#trabalhos"><GhostBtn dark>Ver portfólio</GhostBtn></a>
        <PrimaryBtn dark onClick={() => { window.location.hash = "#contato"; }}>Agende agora</PrimaryBtn>
      </div>

      {/* scroll cue */}
      <div
        className="mono"
        style={{
          position: "absolute", bottom: 28, left: "50%", transform: "translateX(-50%)",
          color: "rgba(255,255,255,.55)", fontSize: 10,
          display: "flex", alignItems: "center", gap: 10
        }}>
        
        <span>Role</span>
        <span style={{ width: 1, height: 28, background: "rgba(255,255,255,.35)" }} />
      </div>
    </section>);

}

Object.assign(window, { Header, Hero });