// Owithu — main app + hash router
const { useState: useStateA, useEffect: useEffectA } = React;

function App() {
  const [route, setRoute] = useStateA(() => normalizeHash(window.location.hash));
  const [modal, setModal] = useStateA(null);

  useEffectA(() => {
    const onHash = () => setRoute(normalizeHash(window.location.hash));
    window.addEventListener('hashchange', onHash);
    return () => window.removeEventListener('hashchange', onHash);
  }, []);

  function normalizeHash(h) {
    if (!h || h === '#' || h === '#/') return '/';
    let r = h.replace(/^#/, '');
    // strip query
    const q = r.indexOf('?');
    if (q >= 0) r = r.slice(0, q);
    return r;
  }

  let page;
  if (route === '/') page = <HomePage onOpenCollection={setModal} />;
  else if (route === '/restaurante') page = <IndustryPage id="restaurante" onOpenCollection={setModal} />;
  else if (route === '/cafenele') page = <IndustryPage id="cafenele" onOpenCollection={setModal} />;
  else if (route === '/hoteluri') page = <IndustryPage id="hoteluri" onOpenCollection={setModal} />;
  else if (route === '/colectii') page = <CollectionsPage onOpenCollection={setModal} />;
  else if (route === '/oferta') page = <RFQPage />;
  else if (route === '/despre') page = <AboutPage />;
  else page = <HomePage onOpenCollection={setModal} />;

  // Tag screen for inline-comment context
  const screenLabel = {
    '/': '01 Home',
    '/restaurante': '02 Restaurante',
    '/cafenele': '03 Cafenele',
    '/hoteluri': '04 Hoteluri',
    '/colectii': '05 Colecții',
    '/oferta': '06 Cerere ofertă',
    '/despre': '07 Despre'
  }[route] || '01 Home';

  return (
    <div data-screen-label={screenLabel}>
      <Nav route={route} />
      {page}
      <Footer />
      {modal && <CollectionModal c={modal} onClose={() => setModal(null)} />}
    </div>
  );
}

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