// App — mount root, read query params for variant/intent
const App = () => {
  const params = new URLSearchParams(window.location.search);
  const variantKey = ["a", "b", "c"].includes(params.get("v")) ? params.get("v") : "a";
  const intentParam = params.get("intent");
  const intent = intentParam === "live" || intentParam === "invest" || intentParam === "both" ? intentParam : "";

  lfUseEffect(() => {
    track("page_view", {
      variant: variantKey,
      intent_utm: intent || "(none)",
      page_path: window.location.pathname,
    });
    track("variant_assigned", { h1_variant: variantKey });
    try { document.cookie = `__cl_v=${variantKey};path=/;max-age=2592000;samesite=lax`; } catch {}
  }, []);

  lfUseEffect(() => {
    const fired = new Set();
    const onScroll = () => {
      const h = document.documentElement;
      const pct = (h.scrollTop / (h.scrollHeight - h.clientHeight)) * 100;
      [50, 75, 100].forEach(t => {
        if (pct >= t && !fired.has(t)) {
          fired.add(t);
          track(`scroll_${t}`);
        }
      });
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  const HasBeachConcept = typeof BeachConceptSection !== "undefined";

  return (
    <>
      <SiteHeader />
      <main>
        <HeroSection variantKey={variantKey} intent={intent} />
        <TrustBar />
        <ManifestoSection intent={intent} />
        {HasBeachConcept && <BeachConceptSection />}
        <AmenitiesGallerySection />
        <FloorPlansSection />
        <LocationSection />
        <FAQSection />
        <FinalCtaSection />
      </main>
      <SiteFooter />
      <StickyMobileBar />
      <ConsentBanner />
      <ExitIntentModal />
    </>
  );
};

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