// Hero — aurora bg, restrained big-serif claim, live console panel as the
// only "data" element. Less clutter than the wireframe.
const { useState: useStateH, useEffect: useEffectH, useRef: useRefH } = React;

function useTyping(lines, { onDone } = {}) {
  // Plays a sequence of lines with a tiny per-char delay.
  const [shown, setShown] = useStateH([]); // array of {text, cls}
  useEffectH(() => {
    let cancelled = false;
    let acc = [];
    (async () => {
      for (let i = 0; i < lines.length; i++) {
        const l = lines[i];
        const pre = l.pre || '';
        const text = l.text;
        // initial line entry — typewriter chars
        for (let c = 1; c <= text.length; c++) {
          if (cancelled) return;
          acc = [...acc.slice(0, i), { ...l, text: text.slice(0, c) }];
          setShown([...acc]);
          await new Promise(r => setTimeout(r, l.fast ? 6 : 14));
        }
        await new Promise(r => setTimeout(r, l.pause || 220));
      }
      onDone && onDone();
    })();
    return () => { cancelled = true; };
  }, []);
  return shown;
}

const ATTACK_LINES = [
  { text: '[14:32:01]  watching · 6 honeytokens armed across prd-eu', cls:'line-dim', fast:true },
  { text: '[14:33:02]  ⚠  TRIP   aws-iam · prd-04   ← 185.220.101.47', cls:'line-warn', pause: 400 },
  { text: '              enrich  VT · AbuseIPDB · Shodan · MITRE  …', cls:'line-dim', fast:true },
  { text: '              actor   inferred · autonomous-agent  (conf 0.94)', cls:'line-aurora', pause: 350 },
  { text: '              signals timing-σ 38ms · typos 0% · path-optimality 0.97', cls:'line-dim', fast:true },
  { text: '[14:33:11]  ⚡ CONTAIN  iam:revoke ✓   cf:block ✓   siem:ingest ✓', cls:'line-ok', pause: 400 },
  { text: '              dossier nis2-art.23 → /reports/2026-05-12-VTZ-7714.pdf', cls:'line-dim', fast:true },
  { text: '[14:33:12]  ✓ contained · 11s   ─  attacker: agent · framework langgraph-llama', cls:'line-aurora', pause: 800 },
  { text: '[14:34:18]  watching · 6 honeytokens armed', cls:'line-dim', fast:true },
];

function HeroConsole() {
  const lines = useTyping(ATTACK_LINES);
  const bodyRef = useRefH(null);
  useEffectH(() => {
    if (bodyRef.current) bodyRef.current.scrollTop = bodyRef.current.scrollHeight;
  }, [lines]);

  return (
    <div className="console" style={{width:'100%', minHeight:300}}>
      <div className="console-head">
        <span className="traffic"/>
        <span className="traffic"/>
        <span className="traffic"/>
        <span style={{marginLeft:14}}>vantuz · live feed · tenant eu-prod-04</span>
        <span style={{marginLeft:'auto', display:'inline-flex', alignItems:'center', gap:6}}>
          <span className="live-dot"/> LIVE
        </span>
      </div>
      <div className="console-body" ref={bodyRef} style={{minHeight:230}}>
        {lines.map((l, i) => (
          <div key={i} className={l.cls || ''}>{l.text}<span style={{opacity: i === lines.length-1 ? 1 : 0}} className="line-aurora">▮</span></div>
        ))}
      </div>
    </div>
  );
}

function Hero({ tweaks }) {
  return (
    <section data-screen-label="01 Hero" className="bg-aurora fade-bottom" style={{position:'relative', minHeight:'100vh'}}>
      {/* Looping cinematic background — generated procedurally with a WebGL shader.
         Original work, fully owned by this project. */}
      <div className="hero-video-wrap" aria-hidden="true">
        <Aurora intensity={1.1} variant={tweaks.aurora} />
        <div className="hero-video-tint"/>
      </div>
      <div className="grid-fine" style={{position:'absolute', inset:0, opacity:.35, pointerEvents:'none', zIndex:1}}/>

      <div className="wrap" style={{position:'relative', zIndex:2, paddingTop:170, paddingBottom:80}}>
        <div className="hero-grid" style={{display:'grid', gridTemplateColumns:'minmax(0,1.15fr) minmax(0,1fr)', gap:56, alignItems:'center', minHeight:'72vh'}}>
          {/* LEFT — claim */}
          <div>
            <div className="chip" style={{marginBottom:28}}>
              <span className="live-dot"/> AI-NATIVE DECEPTION · EU · NIS2-READY
            </div>

            <h1 className="display" style={{fontSize:'clamp(54px, 6.6vw, 104px)', margin:0, color:'#fff', fontWeight:700, lineHeight:1, letterSpacing:'-.035em'}}>
              The next intruder<br/>
              on your network<br/>
              <span style={{color:'#fff'}}>won't be human.</span>
            </h1>

            <p style={{fontSize:18, lineHeight:1.55, color:'var(--txt-2)', maxWidth:540, marginTop:34, marginBottom:36}}>
              Vantuz seeds your infrastructure with honeytokens indistinguishable from production secrets. The instant an <span style={{color:'#fff'}}>autonomous agent</span> — or a human — trips one, our AI investigation pipeline detects, classifies and contains it in under sixty seconds.
            </p>

            <div style={{display:'flex', gap:12, marginBottom:32, flexWrap:'wrap'}}>
              <a href="https://app.vantuz.co/login" className="btn btn-lg btn-white">Start free <span aria-hidden>→</span></a>
              <a href="/platform" className="btn btn-lg btn-outline-white">See a trap fire</a>
            </div>

            <div style={{display:'flex', gap:36, paddingTop:28, flexWrap:'wrap'}}>
              {[
                ['11s', 'median contain'],
                ['100%', 'alert precision'],
                ['EU', 'data residency'],
              ].map(([k,v], i) => (
                <div key={i}>
                  <div className="display" style={{fontSize:38, lineHeight:1, color:'#fff', fontWeight:700, letterSpacing:'-.03em'}}>{k}</div>
                  <div className="mono" style={{fontSize:11, color:'var(--txt-3)', letterSpacing:'.15em', textTransform:'uppercase', marginTop:6}}>{v}</div>
                </div>
              ))}
            </div>
          </div>

          {/* RIGHT — live console */}
          <div style={{position:'relative'}}>
            {/* soft glow behind console */}
            <div style={{position:'absolute', inset:'-40px', background:'radial-gradient(circle, var(--aurora-glow), transparent 60%)', filter:'blur(40px)', opacity:.6, pointerEvents:'none'}}/>
            <div style={{position:'relative'}}>
              <HeroConsole/>
              {/* floating mini-card */}
              <div className="card hero-mini-card" style={{
                position:'absolute', right:-24, bottom:-30, padding:14,
                background:'rgba(15,15,28,.85)', backdropFilter:'blur(20px)',
                width:240
              }}>
                <div className="mono" style={{fontSize:10, letterSpacing:'.2em', color:'var(--aurora-2)'}}>● ACTOR PROFILE</div>
                <div className="display" style={{fontSize:22, lineHeight:1.15, marginTop:6, color:'#fff', fontWeight:600, letterSpacing:'-.02em'}}>Autonomous agent</div>
                <div style={{fontSize:12, color:'var(--txt-3)', marginTop:4}}>185.220.101.47 · NL · TOR-exit</div>
                <div style={{display:'flex', gap:6, marginTop:10, fontSize:11}} className="mono">
                  <span style={{color:'var(--signal-bad)'}}>● risk 0.97</span>
                  <span style={{color:'var(--txt-3)'}}>·</span>
                  <span style={{color:'var(--signal-ok)'}}>contained 11s</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      {/* logo strip — sits OVER the bottom fade, so it reads as the bridge into the dark next section */}
      <div style={{position:'relative', zIndex:4, borderTop:'1px solid var(--ink-line)', borderBottom:'1px solid var(--ink-line)', background:'rgba(5,6,8,.75)', backdropFilter:'blur(14px)'}}>
        <div className="wrap" style={{padding:'22px var(--gutter)', display:'flex', alignItems:'center', gap:48}}>
          <div className="mono" style={{fontSize:10, letterSpacing:'.22em', color:'var(--txt-3)', textTransform:'uppercase', flex:'0 0 auto'}}>// trusted across</div>
          <div className="marquee" style={{flex:1}}>
            <div className="marquee-track" style={{fontFamily:'var(--f-display)', fontWeight:500, fontSize:20, color:'var(--txt-2)', letterSpacing:'-.01em'}}>
              {[...Array(2)].map((_,k) => (
                <React.Fragment key={k}>
                  <span>Fintech · NL</span><span style={{color:'var(--txt-4)'}}>◇</span>
                  <span>HealthTech · DE</span><span style={{color:'var(--txt-4)'}}>◇</span>
                  <span>LegalTech · FR</span><span style={{color:'var(--txt-4)'}}>◇</span>
                  <span>AI Lab · UK</span><span style={{color:'var(--txt-4)'}}>◇</span>
                  <span>Insurance · ES</span><span style={{color:'var(--txt-4)'}}>◇</span>
                  <span>SaaS · IE</span><span style={{color:'var(--txt-4)'}}>◇</span>
                  <span>Bank · LU</span><span style={{color:'var(--txt-4)'}}>◇</span>
                </React.Fragment>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

window.Hero = Hero;
