/* VOLZAR — app shell & routing */
function App() {
  const [page, setPage] = useState("home");
  const [product, setProductState] = useState("akm");
  const pending = useRef(null);

  function go(p, section, productSlug) {
    if (productSlug) setProductState(productSlug);
    if (p && p !== page) {
      pending.current = section || "__top";
      setPage(p);
    } else if (section) {
      scrollToId(section);
    } else {
      window.scrollTo({ top: 0, behavior: "smooth" });
    }
  }

  useEffect(() => {
    const t = pending.current;
    pending.current = null;
    if (t === "__top" || !t) {
      window.scrollTo(0, 0);
    } else {
      requestAnimationFrame(() => requestAnimationFrame(() => scrollToId(t)));
    }
  }, [page]);

  useReveal(page);

  const PAGES = { home: HomePage, catalog: CatalogPage, product: ProductPage, industry: IndustryPage, chemical: ChemicalPage, energy: EnergyPage, mining: MiningPage, water: WaterPage, service: ServicePage, about: AboutPage, contacts: ContactsPage };
  const Current = PAGES[page] || HomePage;

  return (
    <NavCtx.Provider value={{ page, go, product }}>
      <UtilityBar />
      <Header />
      <Current />
      <Footer />
    </NavCtx.Provider>
  );
}

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