import { createRoot } from "react-dom/client";
import App from "./App";
import { paymentsConfigured } from "./lib/payments";
import { initializeAnalytics } from "./lib/analytics";

/* No <StrictMode>: it double-runs effects in development, which would make
   the migrated pages' legacy scripts initialise twice (double map loads,
   duplicate listeners). Remove this note if the legacy bridge ever goes. */

/* Card payments live (spec 07): legacy shop.js checks this flag - when set,
   the cart drawer's Checkout button sends chargeable reports to the native
   /checkout page instead of the interim email-order flow. */
if (paymentsConfigured()) {
  (window as unknown as Record<string, unknown>).LS_CHECKOUT_PATH = "/checkout";
}

/* Development deploys must never be indexed (spec 07 §7). */
if (import.meta.env.VITE_SITE_ENV === "development") {
  const robots = document.createElement("meta");
  robots.name = "robots";
  robots.content = "noindex,nofollow";
  document.head.appendChild(robots);
}

initializeAnalytics();

const rootEl = document.getElementById("root");
if (!rootEl) throw new Error("#root missing from index.html");
createRoot(rootEl).render(<App />);
