import { NextIntlClientProvider } from "next-intl";
import { getMessages } from "next-intl/server";
import { messagesWith } from "@/lib/messages";

/**
 * The legal documents are the only pages that render the `legalPages`
 * namespace, and at 48KB it is the largest in the file. The locale layout
 * leaves it out so no other route carries it; this provider adds it back for
 * the six documents that actually need it.
 *
 * A nested provider replaces the messages it inherits rather than merging, so
 * this passes the full set.
 */
export default async function PublicLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const messages = await getMessages();

  return (
    <NextIntlClientProvider messages={messagesWith(messages, ["legalPages"])}>
      {children}
    </NextIntlClientProvider>
  );
}
