// Marmar Halim — app entry & router
const { useState: useStateA, useEffect: useEffectA } = React;

function App() {
  const [route, setRoute] = useStateA("home");
  const [product, setProduct] = useStateA(null);
  const [toastMsg, setToastMsg] = useStateA("");

  const go = (r) => {
    setRoute(r);
    window.scrollTo({ top: 0, behavior: "instant" });
  };
  const openProduct = (p) => {
    setProduct(p);
    setRoute("product");
    window.scrollTo({ top: 0, behavior: "instant" });
  };
  const showToast = (m) => {
    setToastMsg(m);
    setTimeout(() => setToastMsg(""), 2400);
  };

  const overlay = route === "home";

  let page;
  switch (route) {
    case "home":         page = <window.Home go={go} openProduct={openProduct} />; break;
    case "collections":  page = <window.Collections go={go} />; break;
    case "shop":         page = <window.Shop go={go} openProduct={openProduct} />; break;
    case "product":      page = product ? <window.ProductDetail p={product} go={go} openProduct={openProduct} toast={showToast} /> : <window.Shop go={go} openProduct={openProduct} />; break;
    case "bridal":       page = <window.Bridal go={go} />; break;
    case "couture":      page = <window.Couture go={go} />; break;
    case "modest":       page = <window.Modest go={go} openProduct={openProduct} />; break;
    case "designer":     page = <window.Designer go={go} />; break;
    case "appointments": page = <window.Appointments go={go} toast={showToast} />; break;
    case "contact":      page = <window.Contact go={go} />; break;
    case "stockists":    page = <window.Stockists go={go} />; break;
    case "faqs":         page = <window.FAQs go={go} />; break;
    default:             page = <window.Home go={go} openProduct={openProduct} />;
  }

  return (
    <>
      <window.Announce />
      <window.Nav route={route} go={go} overlay={overlay} />
      <main>{page}</main>
      <window.Footer go={go} />
      <window.WhatsAppFab />
      <window.MobileBar go={go} />
      <window.Toast msg={toastMsg} />
    </>
  );
}

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