// app.jsx — root component, Tweaks panel, scroll-rise observer.

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "track": "a",
  "display": "serif",
  "headline": "finance",
  "density": "regular"
}/*EDITMODE-END*/;

function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);

  // Apply tweaks to <body> data-attrs so CSS variables flip.
  React.useEffect(() => {
    document.body.setAttribute('data-track', t.track);
    document.body.setAttribute('data-display', t.display);
    document.body.setAttribute('data-density', t.density);
  }, [t.track, t.display, t.density]);

  // Fade-and-rise on scroll.
  React.useEffect(() => {
    const els = document.querySelectorAll('.rise:not(.in)');
    if (!('IntersectionObserver' in window)) {
      els.forEach(el => el.classList.add('in'));
      return;
    }
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          io.unobserve(e.target);
        }
      });
    }, { threshold: 0.08, rootMargin: '0px 0px -40px 0px' });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, []);

  return (
    <>
      <Nav />
      <Hero headlineKey={t.headline} />
      <TrustedBy />
      <ProblemSection />
      <HowItWorks />
      <FeatureGrid />
      <Roadmap />
      <Compliance />
      <CaseStudy />
      <Pricing />
      <FAQ />
      <FinalCTA />
      <Footer />

      <TweaksPanel title="Tweaks">
        <TweakSection label="Aesthetic" />
        <TweakRadio
          label="Color track"
          value={t.track}
          options={[
            { value: 'a', label: 'Med.' },
            { value: 'b', label: 'Civic' },
          ]}
          onChange={(v) => setTweak('track', v)}
        />
        <TweakRadio
          label="Headings"
          value={t.display}
          options={[
            { value: 'serif', label: 'Serif' },
            { value: 'sans',  label: 'Sans' },
          ]}
          onChange={(v) => setTweak('display', v)}
        />
        <TweakRadio
          label="Density"
          value={t.density}
          options={[
            { value: 'compact', label: 'Compact' },
            { value: 'regular', label: 'Regular' },
          ]}
          onChange={(v) => setTweak('density', v)}
        />

        <TweakSection label="Hero" />
        <TweakSelect
          label="Headline"
          value={t.headline}
          options={[
            { value: 'finance', label: 'Council finance, without the spreadsheets.' },
            { value: 'excel',   label: 'Stop processing invoices in Excel.' },
            { value: 'skeda',   label: 'The Skeda tal-Ħlasijiet, generated for you.' },
          ]}
          onChange={(v) => setTweak('headline', v)}
        />
      </TweaksPanel>
    </>
  );
}

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