import { Suspense } from "react";

import Header from "@/components/layout/Header";
import FooterSection from "@/components/layout/FooterSection";
import ScrollToTop from "@/components/shared/ScrollToTop";
import NotificationSync from "@/components/shared/NotificationSync";
import OrganizerTypeSync from "@/components/shared/OrganizerTypeSync";

export default function MainLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <div className="min-h-screen flex flex-col">
      <NotificationSync />
      <OrganizerTypeSync />
      <Header />
      <main className="main-section flex-1">
        <ScrollToTop />
        {children}
      </main>
      {/*
        The footer's admin-editable content is fetched inside `FooterSection`,
        behind this boundary, so it is the only thing that waits for it. This
        layout used to `await fetchHomeCms()` itself, which blocked `children`
        — the whole page — on a request nothing above the fold needs.

        `fallback={null}`: the footer is below the fold on every route in this
        group, and `flex-1` on `<main>` already holds the page to full height,
        so there is nothing to reserve space for and no jump to avoid.
      */}
      <Suspense fallback={null}>
        <FooterSection />
      </Suspense>
    </div>
  );
}
