/* Ava Solutions — home page root.
   Bilingual layer (EN/RU) lives in i18n.jsx; chat (Toros) + analytics in chat.jsx;
   shared TopTicker/Footer/ProductsTeaser in components.jsx.

   Section → file map (file numbers no longer match section order):
     01 #top        Hero        page1.jsx        (Page1)
        (proofbar)  Proof-bar   page-proofbar    (ProofBar, unnumbered)
     02 #foundation Foundation  page-foundation  (PageFoundation)
     03 #approach   Approach    page-approach    (PageApproach)
     04 #how        How we work page4.jsx        (Page4)
     05 #ownership  Ownership   page-ownership   (PageOwnership)
     06 #philosophy Philosophy  page2.jsx        (Page2)
        #work       Before/after page3.jsx        (PageWork, unnumbered)
        #cases      Case studies page-cases       (Cases, unnumbered)
        #products-teaser        components.jsx   (ProductsTeaser, unnumbered)
     07 #contact    Contact     page5.jsx        (Page5) + Footer */

function App() {
  const [active, setActive] = React.useState(1);
  const [isChatOpen, setIsChatOpen] = React.useState(false);
  React.useEffect(() => {
    const sections = [
      { id: 'top', n: 1 }, { id: 'foundation', n: 2 }, { id: 'approach', n: 3 }, { id: 'how', n: 4 },
      { id: 'ownership', n: 5 }, { id: 'philosophy', n: 6 }, { id: 'contact', n: 7 },
    ];
    const onScroll = () => {
      const y = window.scrollY + window.innerHeight * 0.35;
      let cur = 1;
      for (const s of sections) { const el = document.getElementById(s.id); if (el && el.offsetTop <= y) cur = s.n; }
      setActive(cur);
    };
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  const closeChat = React.useCallback(() => {
    window.avaTrack?.('chat_close', {});
    setIsChatOpen(false);
  }, []);
  const openChat = React.useCallback(() => {
    window.avaTrack?.('chat_open', { entrypoint: 'floating_cta' });
    setIsChatOpen(true);
  }, []);
  return (
    <LangProvider>
      <DocMeta />
      <TopTicker active={active} />
      <FloatingChatCta onOpen={openChat} />
      <WebChatDrawer isOpen={isChatOpen} onClose={closeChat} />
      <main>
        <Page1 />
        <ProofBar />
        <PageFoundation />
        <PageApproach />
        <Page4 />
        <PageOwnership />
        <Page2 />
        <PageWork />
        <Cases />
        <MidCta />
        <ProductsTeaser />
        <Page5 />
      </main>
    </LangProvider>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
