// Minimal stand-in for the design tool's tweaks panel (not included in handoff export).
// Provides useTweaks/TweaksPanel/TweakSection/TweakRadio/TweakColor/TweakToggle
// so app.jsx runs standalone. Not part of the production design intent.
const { useState: useStateTweaks } = React;

function useTweaks(defaults) {
  const [tweaks, setTweaks] = useStateTweaks(defaults);
  const setTweak = (key, value) => setTweaks((t) => ({ ...t, [key]: value }));
  return [tweaks, setTweak];
}

function TweaksPanel({ title, children }) {
  const [open, setOpen] = useStateTweaks(false);
  return (
    <div className="no-print" style={{ position: 'fixed', bottom: 16, right: 16, zIndex: 40, fontFamily: 'Inter, system-ui, sans-serif' }}>
      <button
        onClick={() => setOpen((o) => !o)}
        style={{
          padding: '6px 12px', borderRadius: 8, border: '1px solid var(--line-2)',
          background: 'var(--surface)', color: 'var(--ink-2)', cursor: 'pointer', fontSize: 12, boxShadow: 'var(--shadow-sm)',
        }}
      >
        {title || 'Tweaks'}
      </button>
      {open && (
        <div style={{
          marginTop: 8, padding: 12, borderRadius: 12, border: '1px solid var(--line-2)',
          background: 'var(--surface)', boxShadow: 'var(--shadow)', width: 260, maxHeight: 400, overflow: 'auto',
        }}>
          {children}
        </div>
      )}
    </div>
  );
}

function TweakSection({ label, children }) {
  return (
    <div style={{ marginBottom: 12 }}>
      <div style={{ fontSize: 11, fontWeight: 600, opacity: 0.6, marginBottom: 6 }}>{label}</div>
      {children}
    </div>
  );
}

function TweakRadio({ label, value, options, onChange }) {
  return (
    <div style={{ marginBottom: 8, fontSize: 12 }}>
      <div style={{ marginBottom: 4 }}>{label}</div>
      {options.map((o) => (
        <label key={o.value} style={{ display: 'block', cursor: 'pointer' }}>
          <input
            type="radio"
            checked={value === o.value}
            onChange={() => onChange(o.value)}
            style={{ marginRight: 6 }}
          />
          {o.label}
        </label>
      ))}
    </div>
  );
}

function TweakColor({ label, value, options, onChange }) {
  return (
    <div style={{ marginBottom: 8, fontSize: 12 }}>
      <div style={{ marginBottom: 4 }}>{label}</div>
      <div style={{ display: 'flex', gap: 6 }}>
        {options.map((c) => (
          <button
            key={c}
            onClick={() => onChange(c)}
            style={{
              width: 22, height: 22, borderRadius: '50%', background: c, cursor: 'pointer',
              border: value === c ? '2px solid #000' : '1px solid #ccc',
            }}
          />
        ))}
      </div>
    </div>
  );
}

function TweakToggle({ label, value, onChange }) {
  return (
    <label style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, cursor: 'pointer' }}>
      <input type="checkbox" checked={!!value} onChange={(e) => onChange(e.target.checked)} />
      {label}
    </label>
  );
}
