/* PLASTIFY · variant App router — picks Home from window[`Home${VAR}`] */
/* global React, ReactDOM */

function PlastifyApp({ variantKey }) {
  const router = window.usePlastifyRouter();
  const { clean, top, parts } = router;
  React.useEffect(() => {
    if (window.lucide) window.lucide.createIcons();
  });

  let page;
  let dataLabel;
  if (top === "" || clean === "/" || top === "home") {
    const HomeComp = window[`Home${variantKey}`] || window.HomeA1;
    page = <HomeComp />;
    dataLabel = "Acasă";
  } else if (top === "materiale") {
    page = <window.MaterialePage />;
    dataLabel = "Materiale";
  } else if (top === "produs") {
    page = <window.ProdusPage slug={parts[1]} />;
    dataLabel = "Produs";
  } else if (top === "cere-oferta") {
    const m = clean.match(/produs=([^&]+)/);
    page = <window.CereOfertaPage prefillSlug={m ? m[1] : null} />;
    dataLabel = "Cere ofertă";
  } else if (top === "contact") {
    page = <window.ContactPage />;
    dataLabel = "Contact";
  } else if (top === "legale") {
    const sec = parts[1] || "termeni";
    page = <window.LegalePage section={sec} />;
    dataLabel = "Legale";
  } else {
    page = <window.NotFoundPage />;
    dataLabel = "404";
  }

  return (
    <div data-variant={variantKey}>
      <window.SiteHeader tone="dark" route={router.route} />
      <main>{page}</main>
      <window.SiteFooter />
      <window.FloatingCta />
    </div>
  );
}

window.PlastifyApp = PlastifyApp;
