// MandateWorks — main app
// Composes sections + wires Tweaks panel for density / type / motion.

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "density": "comfortable",
  "typeset": "serif-display",
  "motion": "subtle",
  "mode": "editorial"
}/*EDITMODE-END*/;

const App = () => {
  const [t, setTweak] = window.useTweaks(TWEAK_DEFAULTS);

  // apply tweaks to <html>
  React.useEffect(() => {
    const root = document.documentElement;
    root.dataset.density = t.density === "comfortable" ? "" : t.density;
    root.dataset.typeset = t.typeset;
    root.dataset.motion = t.motion;
    root.dataset.mode = t.mode === "editorial" ? "" : t.mode;
  }, [t.density, t.typeset, t.motion, t.mode]);

  // reveal-on-scroll
  React.useEffect(() => {
    if (t.motion === "off") {
      document.querySelectorAll(".reveal").forEach(el => el.classList.add("in"));
      return;
    }
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) e.target.classList.add("in"); });
    }, {threshold: 0.08, rootMargin: "0px 0px -10% 0px"});
    document.querySelectorAll(".reveal").forEach(el => io.observe(el));
    return () => io.disconnect();
  }, [t.motion]);

  const {TweaksPanel, TweakSection, TweakRadio} = window;

  return (
    <>
      <Nav />
      <Ticker />
      <Hero />
      <Pull />
      <Platforms />
      <Stack />
      <Audience />
      <Insights />
      <FAQ />
      <Waitlist />
      <Footer />

      <TweaksPanel title="Tweaks">
        <TweakSection label="Mode" />
        <TweakRadio
          label="Surface"
          value={t.mode}
          onChange={(v) => setTweak("mode", v)}
          options={["editorial", "command"]}
        />
        <TweakSection label="Layout" />
        <TweakRadio
          label="Density"
          value={t.density}
          onChange={(v) => setTweak("density", v)}
          options={["compact", "comfortable", "airy"]}
        />
        <TweakSection label="Typography" />
        <TweakRadio
          label="Pairing"
          value={t.typeset}
          onChange={(v) => setTweak("typeset", v)}
          options={["serif-display", "all-sans"]}
        />
        <TweakSection label="Motion" />
        <TweakRadio
          label="Intensity"
          value={t.motion}
          onChange={(v) => setTweak("motion", v)}
          options={["off", "subtle", "rich"]}
        />
      </TweaksPanel>
    </>
  );
};

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
