/* Main App — assembles all sections */

function App() {
  const [scrolled, setScrolled] = React.useState(false);

  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 60);
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  // Intersection Observer for reveal animations
  React.useEffect(() => {
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          entry.target.classList.add('visible');
        }
      });
    }, { threshold: 0.05, rootMargin: '0px 0px -20px 0px' });

    // Wait for DOM to be fully populated, then observe
    const raf = requestAnimationFrame(() => {
      document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
    });

    // Fallback: force all visible after 1.2s in case observer doesn't fire
    const fallback = setTimeout(() => {
      document.querySelectorAll('.reveal:not(.visible)').forEach(el => {
        el.classList.add('visible');
      });
    }, 1200);

    return () => {
      cancelAnimationFrame(raf);
      clearTimeout(fallback);
      observer.disconnect();
    };
  }, []);

  return React.createElement(React.Fragment, null,
    React.createElement(Header, { scrolled }),
    React.createElement(Hero),
    React.createElement(Dores),
    React.createElement(Resultados),
    React.createElement(Procedimentos),
    React.createElement(Sobre),
    React.createElement(SobrePaula),
    React.createElement(Depoimentos),
    React.createElement(FAQ),
    React.createElement(Clinica),
    React.createElement(CTAFinal),
    React.createElement(Footer),
    React.createElement(WhatsAppButton)
  );
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(React.createElement(App));
