/* @jsx React.createElement */
/* Hero — Direction C: a Standing Order bulletin pinned to the dark canvas.
   First-load opening sequence (gated by sessionStorage; honors reduced-motion):
     t=0    bulletin enters (translateY + fade)
     t=120  left tape pins, then damped wobble
     t=200  right tape pins, then damped wobble
     t=320  header rule draws left→right
     t=420  block labels cascade in (01 → 02 → 03), digits scramble briefly
     t=520  reading-list arrows reveal in order
     t=720  signature stamp slams in (scale + rotation + ink-bleed)
     ~1100  page is silent.
   No looping motion. */

const { useState: useStateH, useEffect: useEffectH } = React;

const READING_LIST = [
  {
    n: '01',
    cat: 'ON COMMAND',
    title: 'Mission command in five sentences. Then in fifty.',
    why: "If you read one thing first. The shape of an order that survives plan collapse.",
    href: '#doctrine',
  },
  {
    n: '02',
    cat: 'ON OPS',
    title: 'Logistics is leadership.',
    why: "Why your wing keeps stalling on the ramp, and what fixes it before the op.",
    href: '#doctrine',
  },
  {
    n: '03',
    cat: 'ON LEARNING',
    title: "AARs that don\u2019t lie to themselves.",
    why: "A four-question structure. Replaces the confessional theater most after-actions become.",
    href: '#doctrine',
  },
];

/** Returns true once, on first paint of a session. Skips when the user prefers
 *  reduced motion. Persisted via sessionStorage so refreshes don't re-trigger,
 *  but a fresh tab/visit will. */
function useHeroOpening() {
  const [opening, setOpening] = useStateH(false);
  useEffectH(() => {
    const reduced = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (reduced) return;
    let played = false;
    try { played = sessionStorage.getItem('vc.heroPlayed') === '1'; } catch (e) {}
    if (played) return;
    // Defer one frame so the .is-opening class application triggers the
    // CSS keyframes (avoids a missed paint).
    const raf = requestAnimationFrame(() => setOpening(true));
    try { sessionStorage.setItem('vc.heroPlayed', '1'); } catch (e) {}
    // Drop the class once the sequence ends so future state changes don't
    // re-animate elements (and `transform`s clear back to defaults).
    const timeout = setTimeout(() => setOpening(false), 1400);
    return () => { cancelAnimationFrame(raf); clearTimeout(timeout); };
  }, []);
  return opening;
}

/* Block label — cascades in during opening. Digits scramble briefly. */
function BulletinNLbl({ n, label, idx, opening }) {
  return (
    <div className="vc-bulletin__nlbl" style={{'--bulletin-i': idx}}>
      <span>
        {opening ? <Scramble value={n} /> : n}
      </span>
      <span dangerouslySetInnerHTML={{__html: label}} />
    </div>
  );
}

function HeroBulletin() {
  const opening = useHeroOpening();
  return (
    <section className="vc-hero vc-hero--bulletin">
      <div className="vc-hero__grid" />
      <div className="vc-bracket vc-bracket--tl" />
      <div className="vc-bracket vc-bracket--tr" />
      <div className="vc-bracket vc-bracket--bl" />
      <div className="vc-bracket vc-bracket--br" />

      <div className="vc-hero__inner vc-hero__inner--bulletin">

        {/* Top eyebrow stays on the dark canvas — channel identity, single line */}
        <div className="vc-hero__chrome">
          <div className="vc-eyebrow">
            <span style={{color:'var(--c-signal)'}}>VOLUNTEER&nbsp;C2</span>
            &nbsp;&middot;&nbsp;EST.&nbsp;2026
            &nbsp;&middot;&nbsp;CMD&nbsp;&amp;&nbsp;CONTROL
          </div>
        </div>

        {/* Show signature line — italic serif deck, sits between the eyebrow chrome
            and the bulletin paper. Functions as the masthead tagline; pairs with
            the bulletin's THESIS h1 to complete a deck-into-H1 hammer. */}
        <p className="vc-hero__deck">For the wall, not the feed.</p>

        {/* The bulletin itself — a single paper sheet pinned to the wall */}
        <article className={"vc-bulletin" + (opening ? " is-opening" : "")} aria-label="Standing Order">
          <span className="vc-bulletin__tape vc-bulletin__tape--l" aria-hidden="true" />
          <span className="vc-bulletin__tape vc-bulletin__tape--r" aria-hidden="true" />

          {/* Document header band */}
          <header className="vc-bulletin__head">
            <div className="vc-bulletin__doc">
              <span className="vc-bulletin__kind">STANDING&nbsp;ORDER</span>
              <span className="vc-bulletin__sep">/</span>
              <span className="vc-bulletin__no">VC&middot;26&middot;001</span>
            </div>
            <div className="vc-bulletin__doc vc-bulletin__doc--right">
              <span className="vc-bulletin__lbl">ENTERED&nbsp;INTO&nbsp;FORCE</span>
              <span className="vc-bulletin__val">14&nbsp;OCT&nbsp;2026</span>
              <span className="vc-bulletin__sep">/</span>
              <span className="vc-bulletin__lbl">PUBLIC&nbsp;RELEASE</span>
            </div>
          </header>

          <div className="vc-bulletin__rule" aria-hidden="true" />

          {/* Block 01 — THESIS */}
          <section className="vc-bulletin__block">
            <BulletinNLbl n="01" label="THESIS" idx={0} opening={opening} />
            <h1 className="vc-bulletin__thesis">
              A working library of organizational doctrine &mdash; mission command, ISR, logistics, OPSEC, AARs &mdash; framed through the fleets and conflicts of <em>Star&nbsp;Citizen</em> and translated back to the work you do on Monday.
            </h1>
          </section>

          {/* Block 02 — WHO THIS IS FOR */}
          <section className="vc-bulletin__block">
            <BulletinNLbl n="02" label="WHO&nbsp;THIS&nbsp;IS&nbsp;FOR" idx={1} opening={opening} />
            <ul className="vc-bulletin__who">
              <li><span className="vc-bulletin__who-glyph">&rsaquo;</span><span>Volunteer commanders running fleets, raids, ops, or any unpaid org with shared risk and shared comms.</span></li>
              <li><span className="vc-bulletin__who-glyph">&rsaquo;</span><span>Working leaders who want vocabulary for the part of the job nobody trained them for.</span></li>
              <li><span className="vc-bulletin__who-glyph">&rsaquo;</span><span>Anyone who has ever watched a plan survive contact, and wondered why theirs did not.</span></li>
            </ul>
          </section>

          {/* Block 03 — WHAT TO READ FIRST */}
          <section className="vc-bulletin__block">
            <BulletinNLbl n="03" label="WHAT&nbsp;TO&nbsp;READ&nbsp;FIRST" idx={2} opening={opening} />
            <ol className="vc-bulletin__list">
              {READING_LIST.map((item, i) => (
                <li key={item.n} className="vc-bulletin__item" style={{'--list-i': i}}>
                  <a className="vc-bulletin__item-link" href={item.href}>
                    <span className="vc-bulletin__item-n">{item.n}</span>
                    <span className="vc-bulletin__item-body">
                      <span className="vc-bulletin__item-cat">{item.cat}</span>
                      <span className="vc-bulletin__item-title">{item.title}</span>
                      <span className="vc-bulletin__item-why">{item.why}</span>
                    </span>
                    <span className="vc-bulletin__item-go" aria-hidden="true">READ&nbsp;&rarr;</span>
                  </a>
                </li>
              ))}
            </ol>
          </section>

          <div className="vc-bulletin__rule" aria-hidden="true" />

          {/* Signature block */}
          <footer className="vc-bulletin__sig">
            <div className="vc-bulletin__sig-l">
              <div className="vc-bulletin__sig-cs">CALLSIGN&nbsp;&mdash;&nbsp;VC2</div>
              <div className="vc-bulletin__sig-by">SIGNED FOR THE CHANNEL</div>
            </div>
            <div className="vc-bulletin__sig-r">
              <div className="vc-bulletin__sig-stamp" aria-hidden="true">
                <span className="vc-bulletin__sig-stamp-top">FOR&nbsp;THE</span>
                <span className="vc-bulletin__sig-stamp-mid">WALL</span>
                <span className="vc-bulletin__sig-stamp-bot">VC2</span>
              </div>
            </div>
          </footer>
        </article>
      </div>
    </section>
  );
}

function Hero() { return <HeroBulletin />; }
window.Hero = Hero;
