// Soulforce Arts — For Music Teachers page app
const { useState: useStateA, useEffect: useEffectA } = React;

function TeachHeader({ onCTA, onOpenMenu, scrolled }) {
  const links = [
    { href: '/', label: 'Home' },
    { href: '/tensionreset', label: 'Free Lab' },
    { href: '/pwp', label: 'Perform Without Pain' },
    { href: '/book', label: 'The Book' },
    { href: '/about', label: 'About' },
  ];
  return (
    <header className={`header ${scrolled ? 'scrolled' : ''}`}>
      <a className="brand" href="/" aria-label="Soulforce Arts Institute — Home">
        <img src="assets/logo-gold-wide-light.png" alt="Soulforce Arts Institute" />
      </a>
      <div className="header-right">
        <nav aria-label="Primary">{links.map((l) => <a key={l.label} href={l.href}>{l.label}</a>)}</nav>
        <div className="cta-row">
          <a className="btn sm" href="/pwp"><span className="cta-lg">Join the waiting list</span><span className="cta-sm">Waitlist</span></a>
          <button className="menu-toggle" onClick={onOpenMenu} aria-label="Menu">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M3 7h18M3 12h18M3 17h18" /></svg>
          </button>
        </div>
      </div>
    </header>
  );
}

function TeachDrawer({ open, onClose, onCTA }) {
  return (
    <div className={`mob-drawer ${open ? 'open' : ''}`}>
      <button className="drawer-close" onClick={onClose} aria-label="Close menu">×</button>
      <a href="/" onClick={onClose}>Home</a>
      <a href="/tensionreset" onClick={onClose}>Free Lab</a>
      <a href="/pwp" onClick={onClose}>Perform Without Pain</a>
      <a href="/book" onClick={onClose}>The Book</a>
      <a href="/about" onClick={onClose}>About</a>
      <div className="ctas">
        <a className="btn" href="/pwp">Join the waiting list</a>
        <button className="btn outline" onClick={() => { onClose(); onCTA('group'); }}>Bring this to my association</button>
      </div>
    </div>
  );
}

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "ensoIntensity": "subtle",
  "density": "regular"
}/*EDITMODE-END*/;

function TeachApp() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const [modal, setModal] = useStateA(null);
  const [menuOpen, setMenuOpen] = useStateA(false);
  const [scrolled, setScrolled] = useStateA(false);

  useEffectA(() => {
    document.body.classList.toggle('enso-off', t.ensoIntensity === 'off');
    document.body.classList.toggle('enso-subtle', t.ensoIntensity === 'subtle');
    document.body.classList.toggle('enso-prominent', t.ensoIntensity === 'prominent');
    document.body.classList.remove('density-compact', 'density-comfy');
    if (t.density === 'compact') document.body.classList.add('density-compact');
    if (t.density === 'comfy') document.body.classList.add('density-comfy');
  }, [t.ensoIntensity, t.density]);

  useEffectA(() => {
    const onScroll = () => setScrolled(window.scrollY > 60);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const openCTA = (kind) => setModal(kind);

  return (
    <>
      <TeachHeader onCTA={openCTA} onOpenMenu={() => setMenuOpen(true)} scrolled={scrolled} />
      <TeachDrawer open={menuOpen} onClose={() => setMenuOpen(false)} onCTA={openCTA} />

      <main id="top" className="page">
        <TeachHero onCTA={openCTA} />
        <Problem />
        <Reframe />
        <WalkAway />
        <TwoWaysIn />
        <ForGroup onCTA={openCTA} />
        <FromJoseph />
        <TeacherQuote />
        <HowItWorks onCTA={openCTA} />
        <Faq />
        <FinalCTA onCTA={openCTA} />
      </main>

      <TeachFooter />

      {modal === 'waitlist' && <WaitlistModal onClose={() => setModal(null)} />}
      {modal === 'group' && <GroupModal onClose={() => setModal(null)} />}

      <TweaksPanel title="Tweaks">
        <TweakSection label="Enso" />
        <TweakRadio label="Intensity" value={t.ensoIntensity} options={['off', 'subtle', 'prominent']} onChange={(v) => setTweak('ensoIntensity', v)} />
        <TweakSection label="Page rhythm" />
        <TweakRadio label="Whitespace" value={t.density} options={['compact', 'regular', 'comfy']} onChange={(v) => setTweak('density', v)} />
      </TweaksPanel>
    </>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<TeachApp />);
