/* GALLOS MEDIA — App root */

function App() {
  // El home siempre marca "Inicio" en el nav. Proyectos y Contacto son
  // rutas propias (/proyectos y /contacto), así que NO usamos scroll-spy:
  // antes Contacto se "auto-seleccionaba" al llegar al fondo de la página.
  const activeSection = 'inicio';

  // Al llegar con un #hash desde otra página, baja a la sección.
  // (el contenido se monta tras compilar con Babel, por eso el navegador
  //  no alcanza a hacer el scroll nativo y se queda en el inicio)
  React.useEffect(() => {
    const id = decodeURIComponent(window.location.hash.slice(1));
    if (!id) return;
    const t = setTimeout(() => {
      const el = document.getElementById(id);
      if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
    }, 180);
    return () => clearTimeout(t);
  }, []);

  // Reveal on scroll
  React.useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    const io = new IntersectionObserver(entries => {
      entries.forEach(e => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          io.unobserve(e.target);
        }
      });
    }, { rootMargin: '0px 0px -10% 0px', threshold: 0.05 });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  });

  return (
    <>
      <SiteNav active={activeSection} />
      <main>
        <Hero />
        <Proyectos />
        <Contacto />
      </main>
      <Footer />
    </>
  );
}

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