// tweaks-controller.jsx — Pipewerk feel controls
// Three expressive knobs that reshape the whole site:
//   atmosphere — Daylight (warm paper, current) / Twilight (dusky earthen) / Workshop (full dark)
//   voice      — Quiet (editorial) / Confident (current) / Loud (declarative)
//   markShape  — Anchored (pipe attached) / Detached (gap pipe) / Free (no pipe)

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "atmosphere": "daylight",
  "voice": "confident",
  "markShape": "anchored"
}/*EDITMODE-END*/;

// Context so PWMark instances deep in the tree can read markShape without prop drilling
window.PWTweaksContext = React.createContext({ markShape: "anchored" });

function PipewerkTweaks({ children }) {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);

  // Apply atmosphere + voice as data-attributes on <html> so CSS picks them up
  React.useEffect(() => {
    document.documentElement.setAttribute("data-atmosphere", t.atmosphere);
    document.documentElement.setAttribute("data-voice", t.voice);
  }, [t.atmosphere, t.voice]);

  return (
    <PWTweaksContext.Provider value={{ markShape: t.markShape }}>
      {children}
      <TweaksPanel title="Tweaks">
        <TweakSection label="Atmosphere" />
        <TweakRadio
          label="Mood"
          value={t.atmosphere}
          options={["daylight", "twilight", "workshop"]}
          onChange={(v) => setTweak("atmosphere", v)}
        />
        <TweakSection label="Voice" />
        <TweakRadio
          label="Tone"
          value={t.voice}
          options={["quiet", "confident", "loud"]}
          onChange={(v) => setTweak("voice", v)}
        />
        <TweakSection label="Mark" />
        <TweakRadio
          label="Pipe"
          value={t.markShape}
          options={["anchored", "detached", "free"]}
          onChange={(v) => setTweak("markShape", v)}
        />
      </TweaksPanel>
    </PWTweaksContext.Provider>
  );
}

Object.assign(window, { PipewerkTweaks });
