// App shell

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "heroVariant": "empower"
}/*EDITMODE-END*/;

const App = () => {
  const [active, setActive] = React.useState('home');
  const [tweaks, setTweak] = useTweaks(TWEAK_DEFAULTS);

  const onNav = (id) => {
    setActive(id);
    const el = document.getElementById(id);
    if (el) el.scrollIntoView ? el.scrollIntoView({behavior:'smooth', block:'start'}) : window.scrollTo({top: el.offsetTop-72, behavior:'smooth'});
  };

  // Track active section as user scrolls
  React.useEffect(() => {
    const ids = ['home','industries','how','audit','contact'];
    const onScroll = () => {
      const y = window.scrollY + 120;
      let cur = 'home';
      for (const id of ids) {
        const el = document.getElementById(id);
        if (el && el.offsetTop <= y) cur = id;
      }
      setActive(cur);
    };
    window.addEventListener('scroll', onScroll, {passive:true});
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  return (
    <>
      <Header activeSection={active} onNav={onNav}/>
      <main>
        <Hero onNav={onNav} variantKey={tweaks.heroVariant}/>
        <Problem/>
        <HowItWorks/>
        <Industries/>
        <About/>
        <Faqs onNav={onNav}/>
        <AuditForm/>
        <Contact/>
      </main>
      <Footer onNav={onNav}/>

      <TweaksPanel title="Tweaks">
        <TweakSection title="Hero copy" subtitle="Three alternate hero openings.">
          <TweakRadio
            label="Variant"
            value={tweaks.heroVariant}
            onChange={(v)=>setTweak('heroVariant', v)}
            options={[
              { value: 'empower', label: 'Best day' },
              { value: 'partner', label: 'Alongside' },
              { value: 'unlock',  label: 'Unlock hours' },
            ]}
          />
          <div className="text-xs leading-relaxed opacity-70 mt-2">
            <div><b>Best day</b> leads with the hours your team gets back.</div>
            <div className="mt-1"><b>Alongside</b> presents AI as working with your team.</div>
            <div className="mt-1"><b>Unlock hours</b> leads with the hours your business already loses.</div>
          </div>
        </TweakSection>
      </TweaksPanel>
    </>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App/>);
