/* Créapeiron maison — app shell: compose sections, reveal-on-scroll, nav. */
function MaisonApp() {
  const scrollTo = React.useCallback((id) => {
    const el = id === 'top' ? document.body : document.getElementById(id);
    if (!el) return;
    const y = id === 'top' ? 0 : el.getBoundingClientRect().top + window.scrollY - 60;
    window.scrollTo({ top: y, behavior: 'smooth' });
  }, []);

  React.useEffect(() => {
    const els = document.querySelectorAll('[data-reveal]');
    const reveal = (el) => el.setAttribute('data-shown', '');
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) { reveal(e.target); io.unobserve(e.target); }
      });
    }, { threshold: 0.12, rootMargin: '0px 0px -8% 0px' });
    els.forEach((el) => io.observe(el));
    // Safety: anything already on-screen at mount reveals immediately, so
    // content is never left stuck at opacity 0 if the observer is slow.
    requestAnimationFrame(() => {
      els.forEach((el) => {
        const r = el.getBoundingClientRect();
        if (r.top < window.innerHeight && r.bottom > 0) { reveal(el); io.unobserve(el); }
      });
    });
    return () => io.disconnect();
  }, []);

  return (
    <React.Fragment>
      <MaisonNav onNavigate={scrollTo} />
      <main>
        <Hero onNavigate={scrollTo} />
        <Manifesto />
        <Craftsmanship />
        <Mechanism />
        <Specs />
        <Collection onNavigate={scrollTo} />
        <TheCase onNavigate={scrollTo} />
        <Philosophy />
        <Gallery />
        <Collectors onNavigate={scrollTo} />
        <DealerMap />
        <Concierge />
      </main>
      <MaisonFooter />
    </React.Fragment>
  );
}

// Mount ONLY in the real page context — never when this file is evaluated as
// part of the compiled _ds_bundle.js (where the namespace isn't ready and #root
// must not be claimed twice). index.html sets __MAISON_PAGE__ after the bundle.
if (window.__MAISON_PAGE__ && !window.__maisonMounted) {
  window.__maisonMounted = true;
  ReactDOM.createRoot(document.getElementById('root')).render(<MaisonApp />);
}
