/* Tweaks bridge — live-tunes the section-navigation feel.
   The panel only appears when "Tweaks" is toggled on in the toolbar.
   It mutates window.__nuriaMotion in place, which site.js reads live, so
   changes take effect on the very next scroll — handy for demoing options. */

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "transitionMs": 1150,
  "holdMs": 1750,
  "pauseToRead": true,
  "effort": 60
}/*EDITMODE-END*/;

function applyMotion(t){
  const m = window.__nuriaMotion || (window.__nuriaMotion = {});
  m.duration = t.transitionMs;
  m.hold = t.holdMs;
  m.pauseToRead = t.pauseToRead;
  m.effort = t.effort;
}

function TweaksApp(){
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  React.useEffect(()=>{ applyMotion(t); }, [t]);
  return (
    <TweaksPanel title="Motion & scroll">
      <TweakSection label="Transitions" />
      <TweakSlider label="Transition length" value={t.transitionMs}
                   min={600} max={1900} step={50} unit="ms"
                   onChange={(v)=>setTweak('transitionMs', v)} />
      <TweakSlider label="Hold after landing" value={t.holdMs}
                   min={800} max={2800} step={50} unit="ms"
                   onChange={(v)=>setTweak('holdMs', v)} />

      <TweakSection label="Scrolling" />
      <TweakToggle label="Finish reading before advancing" value={t.pauseToRead}
                   onChange={(v)=>setTweak('pauseToRead', v)} />
      <TweakSlider label="Scroll effort to advance" value={t.effort}
                   min={24} max={160} step={4}
                   onChange={(v)=>setTweak('effort', v)} />
    </TweaksPanel>
  );
}

(function mountTweaks(){
  const el = document.getElementById('tweaks-root');
  if(!el || !window.ReactDOM) return;
  // sync persisted values into the engine immediately, before the panel is opened
  applyMotion(TWEAK_DEFAULTS);
  ReactDOM.createRoot(el).render(<TweaksApp />);
})();
