/* Ava Solutions — products page root.
   Reuses TopTicker, Footer (components.jsx) and the Toros chat (chat.jsx). */

function ProductsApp() {
  const [isChatOpen, setIsChatOpen] = React.useState(false);
  const closeChat = React.useCallback(() => {
    window.avaTrack?.('chat_close', { page: 'products' });
    setIsChatOpen(false);
  }, []);
  const openChat = React.useCallback((entrypoint) => {
    window.avaTrack?.('chat_open', { entrypoint: typeof entrypoint === 'string' ? entrypoint : 'floating_cta', page: 'products' });
    setIsChatOpen(true);
  }, []);
  // Once, after mount: honour an incoming #hash (e.g. #nogis-solutions from the
  // shared footer on index.html) — the target only exists post-render, so the
  // browser's own fragment jump is too early and lands at the top.
  React.useEffect(() => {
    const el = window.location.hash && document.getElementById(window.location.hash.slice(1));
    if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
  }, []);
  return (
    <LangProvider>
      <Grain />
      <TopTicker active={0} />
      <FloatingChatCta onOpen={openChat} />
      <WebChatDrawer isOpen={isChatOpen} onClose={closeChat} />
      <main><ProductsPage onDiscuss={() => openChat('product_header')} /></main>
      <Footer />
    </LangProvider>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<ProductsApp />);
