/* ═══════════════════════════════════════════════════════════════
   DRAFTED — Tweaks island
   A tiny React app that only renders the Tweaks panel and writes
   the chosen values onto <html> (data-* attributes) + the hero
   headline. The page itself stays vanilla HTML/CSS/JS.
   ═══════════════════════════════════════════════════════════════ */

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "accent": "#4F6BED",
  "bg": "cool",
  "motion": "full",
  "headline": "tagline"
}/*EDITMODE-END*/;

const ACCENT_MAP = { "#4F6BED": "icy", "#6B7385": "silver", "#18181B": "mono" };

const HEADLINES = {
  tagline: 'Your LinkedIn posts.<br />Your voice. <span class="ink-accent">Drafted.</span>',
  outcome: 'Turn quiet profile visits into<br /><span class="ink-accent">warm inbound leads.</span>',
  problem: 'Stop staring at<br />the <span class="ink-accent">blank page.</span>',
  authority: 'Show up every week.<br /><span class="ink-accent">In your exact voice.</span>',
};

function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);

  React.useEffect(() => {
    const root = document.documentElement;
    root.dataset.accent = ACCENT_MAP[t.accent] || "icy";
    root.dataset.bg = t.bg;
    root.dataset.motion = t.motion;
  }, [t.accent, t.bg, t.motion]);

  React.useEffect(() => {
    const h = document.getElementById("hero-headline");
    if (h) h.innerHTML = HEADLINES[t.headline] || HEADLINES.tagline;
  }, [t.headline]);

  return (
    <TweaksPanel title="Tweaks">
      <TweakSection label="Identity" />
      <TweakColor
        label="Accent"
        value={t.accent}
        options={["#4F6BED", "#6B7385", "#18181B"]}
        onChange={(v) => setTweak("accent", v)}
      />
      <TweakRadio
        label="Background"
        value={t.bg}
        options={[
          { value: "cool", label: "Cool" },
          { value: "pure", label: "Pure" },
          { value: "warm", label: "Warm" },
        ]}
        onChange={(v) => setTweak("bg", v)}
      />

      <TweakSection label="Hero headline" />
      <TweakSelect
        label="Variant"
        value={t.headline}
        options={[
          { value: "tagline", label: "Your voice. Drafted." },
          { value: "outcome", label: "Warm inbound leads" },
          { value: "problem", label: "Stop staring at the blank page" },
          { value: "authority", label: "Show up every week" },
        ]}
        onChange={(v) => setTweak("headline", v)}
      />

      <TweakSection label="Motion" />
      <TweakRadio
        label="Intensity"
        value={t.motion}
        options={[
          { value: "full", label: "Full" },
          { value: "calm", label: "Calm" },
        ]}
        onChange={(v) => setTweak("motion", v)}
      />
    </TweaksPanel>
  );
}

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