import { Suspense, type ReactNode } from "react";

import LeisureVendorAssets from "@/components/layout/LeisureVendorAssets";
import LayoverDrawerHost from "@/components/flights/layover/LayoverDrawerHost";
import { RequestApprovalHost } from "@/components/employee-requests/RequestApprovalHost";

/**
 * Stylesheet scope for the search-results pages.
 *
 * The SRP components are copied verbatim from leisure-ui and written in
 * Bootstrap 5 markup, so this route loads Bootstrap plus leisure-ui's vendored
 * sheets. <LeisureVendorAssets/> owns that — and the several ways it bites —
 * because /flight-request (LEIS-961) needs exactly the same bundle and the two
 * layouts must not drift apart. Read its doc comment before changing anything
 * about the cascade here.
 *
 * <LayoverDrawerHost/> is mounted here rather than in the root layout, which is
 * where leisure-ui keeps it: the "Know your layover" link only exists on the
 * flights SRP, and the drawer it opens is ported Bootstrap markup that needs
 * these same stylesheets. Without it the link set the open key and nothing
 * rendered — the drawer simply never appeared.
 *
 * <RequestApprovalHost/> is mounted here, once, for the same reason: it owns the
 * single E4 request overlay that all four "Request approval" surfaces open, and
 * those surfaces are spread across the one-way, round-trip and multi-city
 * clients. Putting it in any one of them would mean three copies and three
 * dialogs. It renders nothing until a request is started.
 *
 * It is wrapped in <Suspense> because it reads `bookingFor` with
 * useSearchParams(), which opts its whole subtree out of static prerendering
 * unless a boundary exists. The two SRP pages set `dynamic = "force-dynamic"`
 * and so were unaffected, but the retired /srp/flights/round-trip and
 * /multi-city redirects do not — they are plain server components Next tries to
 * prerender, and with no boundary here `npm run build` failed on them with
 * "useSearchParams() should be wrapped in a suspense boundary", taking the
 * whole build down. A null fallback is the honest one: the host renders nothing
 * until a request is actually started.
 */
export default function SrpLayout({ children }: { children: ReactNode }) {
  return (
    <>
      <LeisureVendorAssets />
      {children}
      <LayoverDrawerHost />
      <Suspense fallback={null}>
        <RequestApprovalHost />
      </Suspense>
    </>
  );
}
