import type { Messages } from "next-intl";

/**
 * The subset of `messages/<locale>.json` that has to reach the browser.
 *
 * `NextIntlClientProvider` mounted without a `messages` prop inherits the *whole*
 * message catalogue from the request config and serialises it into the RSC
 * payload of every page — ~42 KB of JSON per document, of which the client
 * actually reads a few hundred bytes. Server Components are unaffected: they
 * resolve `useTranslations` / `getTranslations` against the request config, not
 * against this provider.
 *
 * Rule for this list: one entry per namespace **declared** by a
 * `useTranslations(...)` call that runs in a Client Component. Declared, not
 * used — a component can only read keys below its own namespace, so shipping the
 * whole declared namespace keeps the scoping stable when that component gains a
 * key. Anything finer would break at runtime (a missing message only surfaces as
 * a console error and the key path rendered in place of the text), never at
 * build time.
 *
 * Keep in sync when a Client Component starts or stops calling
 * `useTranslations`:
 *
 *     grep -rl "use client" src | xargs grep -n "useTranslations("
 *
 * Note that a module without `"use client"` still counts as client code when it
 * is imported from a Client Component (`JrPostCard` below, pulled in by
 * `BlogIndexView`).
 */
export function pickClientMessages(messages: Messages) {
  return {
    /** `blog/BlogSubNav`, `production/ProcessSteps` */
    Common: messages.Common,
    /** `app/[locale]/error`, `app/[locale]/[category]/[slug]/error` */
    Error: messages.Error,
    /** `LanguageSelect` */
    LocaleSwitcher: messages.LocaleSwitcher,
    /** `blog/BlogIndexView`, `blog/BlogSubNav`, `blog/JrPostCard`, plus `blog/ExploredBadge` and `blog/ShareButtons` under `.article` */
    BlogPage: messages.BlogPage,
    // `GalleryPage` and `IndexPage.gallery` used to be here for the two sliders
    // `Crossfade` replaced. Crossfade takes every string as a prop, so both
    // namespaces are now read on the server only — no client entry.
    ContactUsPage: {
      /** `contact/ContactForm` */
      form: messages.ContactUsPage.form,
    },
    ProductionProcessPage: {
      /** `production/ProcessSteps` */
      methodology: messages.ProductionProcessPage.methodology,
    },
  };
}
