// tweaks-app.jsx — Bella Alma Ranch
// Mounts only the Tweaks panel; applies values to the static page via
// <body> data-attributes and CSS custom properties.

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "hero": "lowerleft",
  "plan": "vertical",
  "crop": "grid",
  "headline": "spectral",
  "accent": "#BE9A57",
  "motion": true
}/*EDITMODE-END*/;

// accent hex -> matching deeper shade for --accent-deep
const ACCENT_DEEP = {
  "#BE9A57": "#9F7E3B", // dusty gold
  "#7E8C68": "#5E6B4A", // sage
  "#B07551": "#8E5839", // clay
};

function applyTweaks(t) {
  const b = document.body;
  b.dataset.hero = t.hero;
  b.dataset.plan = t.plan;
  b.dataset.crop = t.crop;
  b.dataset.headline = t.headline;
  b.dataset.motion = t.motion ? "on" : "off";
  const root = document.documentElement.style;
  root.setProperty("--accent", t.accent);
  root.setProperty("--accent-deep", ACCENT_DEEP[t.accent] || t.accent);
}

function TweaksApp() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  React.useEffect(() => { applyTweaks(t); }, [t]);

  return (
    <TweaksPanel title="Tweaks">
      <TweakSection label="Layout" />
      <TweakRadio
        label="Hero"
        value={t.hero}
        options={[
          { value: "lowerleft", label: "Lower-left" },
          { value: "centered", label: "Centered" },
          { value: "split", label: "Split" },
        ]}
        onChange={(v) => setTweak("hero", v)}
      />
      <TweakRadio
        label="Timeline"
        value={t.plan}
        options={[
          { value: "vertical", label: "Vertical" },
          { value: "horizontal", label: "Horizontal" },
          { value: "cards", label: "Cards" },
        ]}
        onChange={(v) => setTweak("plan", v)}
      />
      <TweakRadio
        label="The Crop"
        value={t.crop}
        options={[
          { value: "grid", label: "Grid" },
          { value: "list", label: "List" },
        ]}
        onChange={(v) => setTweak("crop", v)}
      />

      <TweakSection label="Look" />
      <TweakColor
        label="Accent"
        value={t.accent}
        options={["#BE9A57", "#7E8C68", "#B07551"]}
        onChange={(v) => setTweak("accent", v)}
      />
      <TweakSelect
        label="Headline font"
        value={t.headline}
        options={[
          { value: "spectral", label: "Spectral (serif)" },
          { value: "zilla", label: "Zilla Slab" },
          { value: "newsreader", label: "Newsreader" },
        ]}
        onChange={(v) => setTweak("headline", v)}
      />

      <TweakSection label="Motion" />
      <TweakToggle
        label="Scroll fades"
        value={t.motion}
        onChange={(v) => setTweak("motion", v)}
      />
    </TweaksPanel>
  );
}

// Apply persisted defaults immediately (before React mounts) to avoid a flash.
applyTweaks(TWEAK_DEFAULTS);

const __bar_tweakRoot = document.createElement("div");
document.body.appendChild(__bar_tweakRoot);
ReactDOM.createRoot(__bar_tweakRoot).render(<TweaksApp />);
