// Soulforce Arts — Your Body Is Your Instrument page app
const { useState: useStateA, useEffect: useEffectA } = React;

function YbyiHeader({ onCTA, onOpenMenu, scrolled }) {
  const links = [
    { href: '/', label: 'Home' },
    { href: '/studio', label: 'The Studio' },
    { 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">
          <button className="btn sm" onClick={() => onCTA('course')}>Get the course</button>
          <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 YbyiDrawer({ open, onClose, onCTA }) {
  return (
    <div className={`mob-drawer ${open ? 'open' : ''}`}>
      <a href="/" onClick={onClose}>Home</a>
      <a href="/studio" onClick={onClose}>The Studio</a>
      <a href="/book" onClick={onClose}>The Book</a>
      <a href="/about" onClick={onClose}>About</a>
      <div className="ctas">
        <button className="btn" onClick={() => { onClose(); onCTA('course'); }}>Get the course — $149</button>
        <a className="btn outline" href="/pwp" onClick={onClose}>Perform Without Pain</a>
      </div>
    </div>
  );
}

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

function YbyiApp() {
  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);
  }, []);

  // Stripe Payment Links. Each link's success URL (set in Stripe) points to the
  // matching delivery page: course -> /ybiyi/watch, coursePlus -> /ybiyi/watch-plus.
  const STRIPE_LINKS = {
    course: 'https://buy.stripe.com/00waEY7SheBS3qmeUcgMw0h',
    coursePlus: 'https://buy.stripe.com/7sYbJ2goN0L22midQ8gMw0i',
  };
  const openCTA = (kind) => {
    const url = STRIPE_LINKS[kind];
    if (url) window.location.href = url;
  };

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

      <main id="top" className="page">
        <YbyiHero onCTA={openCTA} />
        <BigIdea />
        <Different />
        <WhatLearn />
        <WhoFor />
        <FromJoseph />
        <Quotes />
        <Enroll onCTA={openCTA} />
        <Guarantee />
        <Upsell />
        <Faq />
        <FinalCTA onCTA={openCTA} />
      </main>

      <YbyiFooter />

      {modal === 'course' && (
        <CheckoutModal onClose={() => setModal(null)}
          eyebrow="Lifetime access" title="Your Body Is Your Instrument"
          item="Ten self-paced video lessons" sub="Lifetime access · 14-day refund" price="$149"
          cta="Get the course — $149"
          fine="Secure checkout. Lifetime access. 14-day, no-questions money-back guarantee." />
      )}
      {modal === 'coursePlus' && (
        <CheckoutModal onClose={() => setModal(null)}
          eyebrow="Course + private lesson" title="Course + a Private Lesson"
          item="Ten lessons + one 1:1 session" sub="$299 value · lifetime access" price="$199"
          cta="Get the course + a lesson — $199"
          fine="Secure checkout. The course is covered by the 14-day guarantee; the private lesson is non-refundable." />
      )}

      <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(<YbyiApp />);
