/* Site shell: Navbar + current screen + Footer. Each page sets window.CURRENT_PAGE
   ("home" | "terms" | "privacy") before this loads. Links are real hrefs so each
   page is a genuine, crawlable URL. */
const DS = window.DuologueDesignSystem_a613c9;
const CUR = window.CURRENT_PAGE || "home";
const onHome = CUR === "home";

/* Root-relative, clean (extension-less) URLs — these resolve directly on the live
   site with no redirect, and keep the current host (www). */
const anchor = frag => "/#" + frag;

const navLinks = [
  { id: "how", label: "How it works", href: anchor("how-it-works") },
  { id: "customers", label: "Customers", href: anchor("testimonials") },
  { id: "faqs", label: "FAQs", href: anchor("faq") },
  { id: "terms", label: "Terms", href: "/terms" },
  { id: "privacy", label: "Privacy", href: "/privacy" }
];

const Screen = CUR === "terms" ? window.TermsScreen : CUR === "privacy" ? window.PrivacyScreen : CUR === "404" ? window.NotFoundScreen : window.HomeScreen;

function Site() {
  return <>
    <DS.Navbar
      links={navLinks}
      active={CUR === "terms" ? "terms" : CUR === "privacy" ? "privacy" : null}
      homeHref="/"
      ctaSecondary="Sign in" ctaSecondaryHref="https://try.duologue.co/signin"
      ctaPrimary="Try now" ctaPrimaryHref="https://try.duologue.co/signup" />
    <main><Screen /></main>
    <DS.Footer
      wordmark="duologue"
      statement="Account-native inbox for sales teams."
      newsletter="One real objection, broken with account context, every Tuesday."
      columns={[
        { title: "Product", links: [
          { label: "How it works", href: anchor("how-it-works") },
          { label: "Customers", href: anchor("testimonials") },
          { label: "FAQs", href: anchor("faq") },
          { label: "Book a demo", href: "https://try.duologue.co/chat" },
          { label: "Sign up", href: "https://try.duologue.co/signup" }
        ] },
        { title: "Company", links: [
          { label: "Terms", href: "/terms" },
          { label: "Privacy", href: "/privacy" }
        ] }
      ]}
      legal={[{ label: "Privacy", href: "/privacy" }, { label: "Terms", href: "/terms" }, "Security"]} />
  </>;
}

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

/* Honour an incoming #hash on the home page (e.g. arriving from a Terms/Privacy
   link). Retry until the app has rendered the target section into the DOM. */
if (onHome && window.location.hash) {
  const id = window.location.hash.slice(1);
  let tries = 0;
  const tryScroll = () => {
    const el = document.getElementById(id);
    if (el) el.scrollIntoView({ block: "start" });
    else if (tries++ < 40) setTimeout(tryScroll, 50);
  };
  setTimeout(tryScroll, 0);
}
