/* === JitterFree — Tweaks integration ===
   Reads TWEAK_DEFAULTS from window, applies axis values as data-attributes on
   <html>, and renders the floating TweaksPanel. Each tweak is a "mode" that
   reshapes many properties at once via tweaks-styles.css. */

(function mountTweaks() {
  const { useEffect } = React;

  function TweaksApp() {
    const [t, setTweak] = window.useTweaks(window.TWEAK_DEFAULTS);

    useEffect(() => {
      const r = document.documentElement;
      r.dataset.mood = t.mood;
      r.dataset.material = t.material;
      r.dataset.rhythm = t.rhythm;
    }, [t.mood, t.material, t.rhythm]);

    return (
      <window.TweaksPanel title="Tweaks">
        <window.TweakSection label="Mood" />
        <window.TweakSelect
          label="Palette"
          value={t.mood}
          options={[
            { value: "cobalt",   label: "Cobalt — clean white + electric blue" },
            { value: "studio",   label: "Studio — dark mode workshop" },
            { value: "sunburst", label: "Sunburst — warm cream + terra" },
            { value: "graphite", label: "Graphite — engineering mono" },
          ]}
          onChange={(v) => setTweak("mood", v)}
        />

        <window.TweakSection label="Material" />
        <window.TweakRadio
          label="Surface"
          value={t.material}
          options={["refined", "tactile", "edged"]}
          onChange={(v) => setTweak("material", v)}
        />

        <window.TweakSection label="Rhythm" />
        <window.TweakRadio
          label="Type"
          value={t.rhythm}
          options={["editorial", "console", "display"]}
          onChange={(v) => setTweak("rhythm", v)}
        />
      </window.TweaksPanel>
    );
  }

  // Mount into its own root so it doesn't fight the main App's render tree.
  const mount = document.createElement("div");
  mount.id = "tweaks-root";
  document.body.appendChild(mount);
  const root = ReactDOM.createRoot(mount);
  root.render(<TweaksApp />);
})();
