// app.jsx — boots the combined single-page Motomelli site. Picks the page
// component for the current clean path and renders it inside the right chrome.
// Must load LAST (after every component module and router.jsx).

const ROUTES = {
  "/":        () => <HomeV1 />,                                              // self-chromed (Hero + Footer)
  "/compare": () => <PageShell right="social"><ComparePage /></PageShell>,
  "/about":   () => <PageShell current="about"><AboutPage /></PageShell>,
  "/contact": () => <PageShell current="contact"><ContactPage /></PageShell>,
  "/hoodies": () => <PageShell current="hoodies"><HoodiesStore /></PageShell>,
  "/privacy": () => <PageShell><PrivacyPage /></PageShell>,
  "/terms":   () => <PageShell><TermsPage /></PageShell>,
  "/cookies": () => <PageShell><CookiesPage /></PageShell>,
  "/product": () => <ProductPage />,                                         // self-chromed
};

const NotFound = () => (
  <>
    <TopBar />
    <main className="mm-section" style={{ textAlign: "center", padding: "120px 24px" }}>
      <span className="mm-mono" style={{ color: "var(--mm-light-accent)" }}>404</span>
      <h1 style={{ fontFamily: "var(--mm-font-display)", fontWeight: 700, fontSize: "clamp(34px,5vw,64px)", margin: "12px 0 18px", color: "var(--mm-light-text)" }}>
        Page not found.
      </h1>
      <p style={{ color: "var(--mm-light-dim)", marginBottom: 28 }}>
        That page doesn't exist (or moved). Let's get you back on the road.
      </p>
      <a href="/" className="mm-bigbtn" style={{ color: "#fff", background: "var(--mm-light-accent)", borderColor: "var(--mm-light-accent)" }}>
        Back home <span aria-hidden>→</span>
      </a>
    </main>
    <Footer />
  </>
);

// Routes whose body keeps the dark base background from styles.css. Every
// other (secondary) page used `<body style="background: light">` before, so we
// apply that light background for them.
const DARK_BODY_ROUTES = new Set(["/", "/product"]);

const App = () => {
  const route = window.useRoute();

  // On first paint, honour an incoming hash (e.g. deep link to /#mm-sizecmp).
  React.useEffect(() => {
    if (window.location.hash) window.mmScrollToHash(window.location.hash);
  }, []);

  // Match the per-page body background the standalone pages used to set inline.
  React.useEffect(() => {
    document.body.style.background =
      DARK_BODY_ROUTES.has(route.path) ? "" : "var(--mm-light-bg)";
  }, [route.path]);

  const render = ROUTES[route.path];
  return render ? render() : <NotFound />;
};

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