// Root app — wires sections + tweaks panel

const DEFAULTS = /*EDITMODE-BEGIN*/{
  "direction": "dark-techy",
  "accentHue": 195,
  "density": "comfy",
  "heroVariant": "workflow",
  "showLogos": true,
  "monoLabels": true,
  "buttonHover": "lift",
  "logoBadge": "navy"
}/*EDITMODE-END*/;

const App = () => {
  const [values, setTweak] = useTweaks(DEFAULTS);
  const [legalOpen, setLegalOpen] = React.useState(false);
  const [privacyOpen, setPrivacyOpen] = React.useState(false);

  // Apply theme
  React.useEffect(() => {
    const map = {
      'dark-techy': 'dark',
      'light-editorial': 'light',
      'hybrid-narrative': 'hybrid'
    };
    document.body.dataset.theme = map[values.direction] || 'dark';
    document.body.dataset.density = values.density || 'comfy';
    document.body.dataset.hover = values.buttonHover || 'lift';
    document.body.dataset.badge = values.logoBadge || 'navy';

    // Accent hue
    const h = Number.isFinite(values.accentHue) ? values.accentHue : 195;
    document.documentElement.style.setProperty('--cyan', `oklch(0.82 0.17 ${h})`);
    document.documentElement.style.setProperty('--blue', `oklch(0.62 0.2 ${(h + 30) % 360})`);
  }, [values]);

  // Scroll reveal
  React.useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('in'); });
    }, { threshold: 0.15 });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, [values.direction]);

  return (
    <>
      <Nav />
      <main>
        <Hero />
        {values.showLogos && <LogoStrip />}
        <Services />
        <Process />
        <About />
        <CTA />
      </main>
      <Footer onOpenLegal={() => setLegalOpen(true)} onOpenPrivacy={() => setPrivacyOpen(true)} />
      <LegalModal open={legalOpen} kind="legal" onClose={() => setLegalOpen(false)} />
      <LegalModal open={privacyOpen} kind="privacy" onClose={() => setPrivacyOpen(false)} />
      <ConsentManager onOpenPrivacy={() => setPrivacyOpen(true)} />
      <FAQModal />

      {/* TweaksPanel gère lui-même sa visibilité via le protocole hôte */}
      <TweaksPanel>
          <TweakSection label="Direction visuelle">
            <TweakRadio
              label="Variante"
              value={values.direction}
              onChange={(v) => setTweak('direction', v)}
              options={[
                { value: 'dark-techy', label: 'A · Dark techy (control panel)' },
                { value: 'light-editorial', label: 'B · Clair éditorial' },
                { value: 'hybrid-narrative', label: 'C · Hybride narratif' }
              ]}
            />
          </TweakSection>

          <TweakSection label="Palette">
            <TweakSlider
              label="Teinte accent"
              min={0} max={360} step={1}
              value={values.accentHue}
              onChange={(v) => setTweak('accentHue', v)}
              unit="°"
            />
          </TweakSection>

          <TweakSection label="Composition">
            <TweakSelect
              label="Densité"
              value={values.density}
              onChange={(v) => setTweak('density', v)}
              options={[
                { value: 'cozy', label: 'Compacte' },
                { value: 'comfy', label: 'Confortable' },
                { value: 'spacious', label: 'Aérée' }
              ]}
            />
            <TweakToggle
              label="Afficher stack partenaires"
              value={values.showLogos}
              onChange={(v) => setTweak('showLogos', v)}
            />
          </TweakSection>

          <TweakSection label="Logo — badge">
            <TweakRadio
              label="Style du fond"
              value={values.logoBadge}
              onChange={(v) => setTweak('logoBadge', v)}
              options={[
                { value: 'navy', label: 'Navy (dégradé)' },
                { value: 'cyan', label: 'Cyan (dégradé)' },
                { value: 'white', label: 'Blanc' }
              ]}
            />
          </TweakSection>

          <TweakSection label="Interactions — boutons">
            <TweakRadio
              label="Effet au survol"
              value={values.buttonHover}
              onChange={(v) => setTweak('buttonHover', v)}
              options={[
                { value: 'lift', label: 'Lift (ombre + translation)' },
                { value: 'swap', label: 'Swap (inversion des couleurs)' },
                { value: 'glow', label: 'Glow (halo cyan)' },
                { value: 'underline', label: 'Soulignement' },
                { value: 'none', label: 'Aucun (opacité légère)' }
              ]}
            />
          </TweakSection>
      </TweaksPanel>
    </>
  );
};

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
