const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "accent": "neon",
  "bg": "default"
}/*EDITMODE-END*/;

// Permite que o HTML inicialize a variante via <body data-bg="..."> ou
// querystring ?bg=light. Isso deixa o index-white.html abrir já no branco
// sem precisar de duplicação de bundle.
const INITIAL_TWEAKS = (() => {
  const out = { ...TWEAK_DEFAULTS };
  if (typeof document !== 'undefined') {
    const bodyBg = document.body && document.body.getAttribute('data-bg');
    if (bodyBg) out.bg = bodyBg;
  }
  if (typeof window !== 'undefined') {
    const params = new URLSearchParams(window.location.search);
    const qsBg = params.get('bg');
    if (qsBg) out.bg = qsBg;
    const qsAccent = params.get('accent');
    if (qsAccent) out.accent = qsAccent;
  }
  return out;
})();

const App = () => {
  const [tweaks, setTweak] = useTweaks(INITIAL_TWEAKS);

  React.useEffect(() => {
    const map = { neon: '', emerald: 'emerald', lime: 'lime', cyan: 'cyan' };
    if (tweaks.accent && map[tweaks.accent]) document.body.setAttribute('data-theme', map[tweaks.accent]);
    else document.body.removeAttribute('data-theme');

    if (tweaks.bg && tweaks.bg !== 'default') document.body.setAttribute('data-bg', tweaks.bg);
    else document.body.removeAttribute('data-bg');
  }, [tweaks.accent, tweaks.bg]);

  // Reveal-on-scroll
  React.useEffect(() => {
    const obs = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('in'); });
    }, { threshold: 0.15 });
    document.querySelectorAll('.reveal').forEach(el => obs.observe(el));
    return () => obs.disconnect();
  }, []);

  return (
    <>
      {/* Ordem v3 (wireframe combinando os benchmarks):
          Hero → TrustBar → IntegraStrip → VejaConversa (NOVO show-don't-tell) →
          FunnelDifferentials (4 IAs em grid) → AntesDepois → Testimonials →
          VendedorHumanoVsIA → IAvsChatbot (números) → ComoFunciona3Passos →
          UseCases → TrustStrip → FAQ → RiskReversalCard → CTAFinal → Footer
          Intercala comparativos (AntesDepois/Vendedor/IAvsChatbot) com prova
          social e mockup pra quebrar o ritmo de "tabela atrás de tabela".
          Fora da rotação: Problem, HowItWorks, Features, Integrations,
          SeloSeguranca, HeroVSL (substituído pelo mockup animado). */}
      <Hero/>
      <TrustBar/>
      <VejaConversa/>
      <FunnelDifferentials/>
      <IntegraStrip/>
      <AntesDepois/>
      <ResultadosReais/>
      <Testimonials/>
      <VendedorHumanoVsIA/>
      <IAvsChatbot/>
      <ComoFunciona3Passos/>
      <TrustStrip/>
      <FAQ/>
      <Footer/>

      <DemoFormModal/>

      <TweaksPanel title="Tweaks">
        <TweakSection title="Cor de destaque">
          <TweakRadio
            value={tweaks.accent}
            onChange={v => setTweak('accent', v)}
            options={[
              { value: 'neon', label: 'Neon' },
              { value: 'emerald', label: 'Emerald' },
              { value: 'lime', label: 'Lime' },
              { value: 'cyan', label: 'Cyan' },
            ]}
          />
        </TweakSection>
        <TweakSection title="Fundo">
          <TweakRadio
            value={tweaks.bg}
            onChange={v => setTweak('bg', v)}
            options={[
              { value: 'default', label: 'Padrão' },
              { value: 'deepblack', label: 'Deep black' },
              { value: 'forest', label: 'Forest' },
              { value: 'light', label: 'Branco' },
            ]}
          />
        </TweakSection>
      </TweaksPanel>
    </>
  );
};

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