// СУ 47 — Main composition.

const { useEffect: useEffectA, useRef: useRefA } = React;

function App() {
  const rootRef = useRefA(null);

  // Anonymous visit beacon — once per browser session. The server stores only a
  // salted hash of ip+UA per day (no cookie, no raw IP), powering DAU/WAU/MAU in
  // the owner panel. sendBeacon so it never delays the page; sessionStorage so a
  // reload within the same visit isn't counted twice on the client side too.
  useEffectA(() => {
    try {
      if (sessionStorage.getItem('su47_hit')) return;
      sessionStorage.setItem('su47_hit', '1');
    } catch { /* private mode — fall through, server dedupes by day anyway */ }
    try {
      if (navigator.sendBeacon) navigator.sendBeacon('/api/hit');
      else fetch('/api/hit', { method: 'POST', keepalive: true });
    } catch { /* offline — ignore */ }
  }, []);

  useEffectA(() => {
    // Progressive enhancement: content is fully visible by default. We only opt
    // into the hidden-then-reveal animation once JS is running AND motion is OK,
    // so headless renderers / background tabs never ship blank sections.
    const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (reduce || !('IntersectionObserver' in window)) return;

    document.documentElement.classList.add('reveal-ready');
    const io = new IntersectionObserver((entries, obs) => {
      entries.forEach(e => {
        if (e.isIntersecting) { e.target.classList.add('reveal--in'); obs.unobserve(e.target); }
      });
    }, { threshold: 0.12, rootMargin: '0px 0px -8% 0px' });

    const els = rootRef.current ? rootRef.current.querySelectorAll('.reveal') : [];
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, []);

  return (
    <div ref={rootRef}>
      <Nav />
      <main id="main">
        <Hero />
        <About />
        <Prices />
        <Order />
        <Reviews />
        <FAQ />
        <Contacts />
      </main>
      <Footer />
      <StickyCall />
      <EditBridge />
    </div>
  );
}

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