/* Warrior Shadow — chrome + shared helpers + Section 01 (Hero). */
(function () {
  window.WS = window.WS || {};

  /* ---- Scroll reveal hook -------------------------------------- */
  function useReveal() {
    React.useEffect(() => {
      const els = document.querySelectorAll('.thea-reveal');
      if (!('IntersectionObserver' in window)) {
        els.forEach((el) => el.classList.add('is-in'));
        return;
      }
      const io = new IntersectionObserver(
        (entries) => {
          entries.forEach((e) => {
            if (e.isIntersecting) {
              e.target.classList.add('is-in');
              io.unobserve(e.target);
            }
          });
        },
        { rootMargin: '0px 0px -12% 0px', threshold: 0.08 }
      );
      els.forEach((el) => io.observe(el));
      return () => io.disconnect();
    }, []);
  }
  window.WS.useReveal = useReveal;

  /* ---- Image placeholder (user-fillable slot) ------------------ */
  /* A labelled, hairline-framed drop target in the brand's texture
     idiom. The user drags real architecture/water/stone photography
     in later; until then it reads as an honest, clinical placeholder. */
  function ImageSlot({ id, label, caption, height, fit = 'cover', tint = 'stone', style }) {
    const tints = {
      stone:  'linear-gradient(150deg, #1b1c1e 0%, #131416 55%, #0d0e10 100%)',
      water:  'linear-gradient(160deg, #14181c 0%, #0f1316 50%, #0a0c0e 100%)',
      oxblood:'linear-gradient(150deg, #1d130d 0%, #150f0b 55%, #0c0908 100%)',
    };
    return (
      <figure
        style={{
          position: 'relative', margin: 0, height: height || 320,
          border: '1px solid var(--line)', background: tints[tint] || tints.stone,
          overflow: 'hidden', ...style,
        }}
      >
        {/* texture wash + grain */}
        <div aria-hidden="true" style={{
          position: 'absolute', inset: 0,
          background: 'radial-gradient(120% 120% at 80% 0%, rgba(197,160,89,0.10), transparent 55%)',
          pointerEvents: 'none', zIndex: 1,
        }} />
        <div aria-hidden="true" className="thea-grain" style={{ position: 'absolute', inset: 0, opacity: 0.5, zIndex: 1 }} />
        {/* the fillable slot */}
        <image-slot
          id={id}
          fit={fit}
          shape="rect"
          placeholder=" "
          style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', zIndex: 2 }}
        ></image-slot>
        {/* label overlay */}
        <figcaption style={{
          position: 'absolute', left: 0, bottom: 0, right: 0, zIndex: 3,
          padding: '14px 16px', display: 'flex', flexDirection: 'column', gap: 6,
          pointerEvents: 'none',
          background: 'linear-gradient(0deg, rgba(10,11,12,0.78), transparent)',
        }}>
          <span style={{
            fontFamily: 'var(--font-mono)', fontSize: '10px', letterSpacing: '0.14em',
            textTransform: 'uppercase', color: 'var(--brass)',
          }}>[ {label} ]</span>
          {caption && (
            <span style={{
              fontFamily: 'var(--font-mono)', fontSize: '10px', letterSpacing: '0.06em',
              textTransform: 'uppercase', color: 'var(--ash-light)', maxWidth: '46ch',
              lineHeight: 1.6, opacity: 0.78,
            }}>{caption}</span>
          )}
        </figcaption>
      </figure>
    );
  }
  window.WS.ImageSlot = ImageSlot;

  /* ---- Navigation --------------------------------------------- */
  function SiteHeader({ onApply }) {
    return (
      <header style={{
        position: 'fixed', top: 0, left: 0, right: 0, zIndex: 40,
        background: 'rgba(10,11,12,0.66)', backdropFilter: 'blur(16px)',
        WebkitBackdropFilter: 'blur(16px)',
        borderBottom: '1px solid var(--hairline-on-dark)',
      }}>
        <div className="thea-container" style={{
          display: 'flex', alignItems: 'center', justifyContent: 'space-between', height: '72px',
        }}>
          <a href="#top" style={{
            fontFamily: 'var(--font-display)', fontSize: '18px', letterSpacing: '0.04em',
            color: 'var(--brass)', textDecoration: 'none',
          }}>THEA.</a>
          <a href="#apply" className="thea-hover-fade thea-focus" style={{
            fontFamily: 'var(--font-mono)', fontSize: '10px', letterSpacing: '0.1em',
            textTransform: 'uppercase', color: 'var(--ash-light)', textDecoration: 'none',
            border: '1px solid var(--hairline-on-dark)', padding: '10px 18px',
          }}
          onClick={(e) => { e.preventDefault(); onApply(); }}>[ Apply for the Container ]</a>
        </div>
      </header>
    );
  }
  window.WS.SiteHeader = SiteHeader;

  /* ---- Section 01 — The Hero ---------------------------------- */
  function Hero({ onApply }) {
    const { Button } = window.TheaCorridorsShadowDesignSystem_46741f;
    return (
      <section id="top" className="on-void" style={{
        position: 'relative', minHeight: '100vh', display: 'flex',
        flexDirection: 'column', justifyContent: 'flex-end',
        background: 'var(--void)', overflow: 'hidden',
        borderBottom: '1px solid var(--hairline-on-dark)',
      }}>
        {/* full-viewport hero image — fillable, dark so text pops */}
        <image-slot
          id="ws-hero-bg"
          fit="cover"
          shape="rect"
          placeholder=" "
          style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', zIndex: 0, opacity: 0.4 }}
        ></image-slot>
        <div aria-hidden="true" style={{
          position: 'absolute', inset: 0, zIndex: 1,
          background:
            'radial-gradient(90% 120% at 82% -8%, rgba(197,160,89,0.16), transparent 48%),' +
            'linear-gradient(178deg, rgba(10,11,12,0.30) 0%, rgba(10,11,12,0.55) 55%, var(--void) 100%)',
        }} />
        <div aria-hidden="true" className="thea-grain" style={{ position: 'absolute', inset: 0, opacity: 0.45, zIndex: 1 }} />

        {/* placeholder marker for the hero image, top-right */}
        <div style={{
          position: 'absolute', top: 96, right: 'max(32px, calc((100vw - 1440px)/2 + 32px))', zIndex: 2,
          fontFamily: 'var(--font-mono)', fontSize: '10px', letterSpacing: '0.14em',
          textTransform: 'uppercase', color: 'var(--ash-light)', opacity: 0.7, textAlign: 'right',
          maxWidth: '30ch', lineHeight: 1.7, pointerEvents: 'none',
        }}>
          [ Image Insert 01 — Hero Background ]<br />
          <span style={{ opacity: 0.7 }}>Brutalist concrete interior · a single warm geometric beam · gritty, silent, no figures</span>
        </div>

        <div className="thea-container thea-corridor" style={{
          position: 'relative', zIndex: 2, display: 'grid',
          gridTemplateColumns: 'repeat(12, 1fr)', alignItems: 'end',
          paddingBottom: 'var(--space-28)', paddingTop: 'var(--space-36)',
        }}>
          <div className="thea-reveal" style={{
            gridColumn: '1 / span 7', display: 'flex', flexDirection: 'column', gap: 'var(--space-8)',
          }}>
            <span style={{
              fontFamily: 'var(--font-mono)', fontSize: '12px', letterSpacing: '0.14em',
              textTransform: 'uppercase', color: 'var(--brass)',
            }}>01 / The Warrior Shadow</span>
            <h1 className="t-display" style={{ fontSize: 'clamp(46px, 7vw, 88px)', margin: 0, color: 'var(--sanctuary)' }}>
              You have mastered the external world.<br />
              <span className="t-serif-italic" style={{ fontSize: 'inherit', color: 'var(--brass-wash)' }}>Now, put down the armor.</span>
            </h1>
            <p className="t-body" style={{ color: 'var(--text-muted)', maxWidth: '52ch', fontSize: 'var(--text-18)' }}>
              A private, architectural container for the outwardly victorious and inwardly
              exhausted man. Healing the wounded masculine through the profound mechanics of the shadow.
            </p>
            <div style={{ marginTop: 'var(--space-4)' }}>
              <Button variant="primary" trailing="↗" onClick={onApply}>Enter the Corridor</Button>
            </div>
          </div>
        </div>
      </section>
    );
  }
  window.WS.Hero = Hero;
})();
