// Polycode marketing — tweak wiring.
//
// Three expressive controls that reshape feel:
//   palette  ember | ink | oceanic   — accent colour system
//   voice    editorial | receipts    — how headings carry themselves
//   hero     cinematic | quiet       — what dominates the hero
//
// Applies as data-* attributes on <html>, picked up by CSS overrides at the
// bottom of site.css. JSX changes are intentionally minimal so direct-edit
// of the source markup keeps working in either state.

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "palette": "ember",
  "voice": "editorial",
  "hero": "cinematic"
}/*EDITMODE-END*/;

function applyTweaks(t) {
  const r = document.documentElement;
  r.setAttribute('data-palette', t.palette);
  r.setAttribute('data-voice', t.voice);
  r.setAttribute('data-hero', t.hero);
}
// Apply defaults synchronously so the first paint matches the persisted state.
applyTweaks(TWEAK_DEFAULTS);

function PolycodeTweaks() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  React.useEffect(() => { applyTweaks(t); }, [t.palette, t.voice, t.hero]);
  return (
    <TweaksPanel title="Tweaks">
      <TweakSection label="Palette">
        <TweakColor
          label="Accent system"
          value={t.palette === 'ember'   ? ['#C55A1F', '#2B5CE6', '#F6F4EF']
               : t.palette === 'ink'     ? ['#1C1915', '#3F3A30', '#F6F4EF']
               :                           ['#2B5CE6', '#1F4FCC', '#EAF1FF']}
          options={[
            ['#C55A1F', '#2B5CE6', '#F6F4EF'],   // ember (default)
            ['#1C1915', '#3F3A30', '#F6F4EF'],   // ink
            ['#2B5CE6', '#1F4FCC', '#EAF1FF'],   // oceanic
          ]}
          onChange={(arr) => {
            const which = arr[0] === '#C55A1F' ? 'ember' : arr[0] === '#1C1915' ? 'ink' : 'oceanic';
            setTweak('palette', which);
          }}
        />
      </TweakSection>

      <TweakSection label="Voice">
        <TweakRadio label="Headline style" value={t.voice}
          options={[
            { value: 'editorial', label: 'Editorial' },
            { value: 'receipts',  label: 'Receipts'  },
          ]}
          onChange={(v) => setTweak('voice', v)} />
      </TweakSection>

      <TweakSection label="Hero rhythm">
        <TweakRadio label="What leads" value={t.hero}
          options={[
            { value: 'cinematic', label: 'Cinematic' },
            { value: 'quiet',     label: 'Quiet'     },
          ]}
          onChange={(v) => setTweak('hero', v)} />
      </TweakSection>
    </TweaksPanel>
  );
}

window.PolycodeTweaks = PolycodeTweaks;
