/* Samantha Seitz Interiors — page bootstrap.
   Each entry HTML sets window.__PAGE__; this renders that page's sections.
   Navigation is real per-URL links (full page loads) — best for SEO. */
const { Header, Hero, CaseTease, Consultation, Services, Process, Portfolio, Inquiry, Footer } = window;
const { About, FAQ, Journal, Privacy, PostWhatARoomShouldSay } = window;

function App() {
  const page = (window.__PAGE__ || "home").toLowerCase();
  const params = new URLSearchParams(window.location.search);
  const preselect = params.get("svc") || null;

  // Book CTA -> real navigation, carrying the chosen service as a query param.
  const handleInquire = (svc) => {
    const url = new URL("book/", document.baseURI);
    if (svc) url.searchParams.set("svc", svc);
    window.location.href = url.toString();
  };

  // Journal posts live at journal/<slug>/ and keep "Journal" lit in the nav.
  const isJournalPost = page.indexOf("journal-") === 0;
  const activeLabel = page === "home" ? ""
    : isJournalPost ? "Journal"
    : page.charAt(0).toUpperCase() + page.slice(1);

  return (
    <React.Fragment>
      <Header activePage={activeLabel} />

      <main id="main-content" tabIndex="-1">
      {page === "book" && <Inquiry preselect={preselect} />}

      {page === "home" && (
        <React.Fragment>
          <Hero onInquire={handleInquire} />
          <CaseTease />
          <Inquiry preselect={preselect} />
        </React.Fragment>
      )}

      {page === "about" && <About />}

      {page === "services" && (
        <React.Fragment>
          <Consultation />
          <Services onInquire={handleInquire} />
        </React.Fragment>
      )}

      {page === "process" && (
        <React.Fragment>
          <Process />
          <FAQ />
        </React.Fragment>
      )}

      {page === "portfolio" && <Portfolio />}

      {page === "journal" && <Journal />}

      {page === "privacy" && <Privacy />}

      {page === "journal-what-a-room-should-say" && <PostWhatARoomShouldSay />}
      </main>

      <Footer />
    </React.Fragment>
  );
}

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