{"version":3,"file":"IntlayerServerProvider.cjs","names":["internationalization","createServerContext","registerAmbientLocaleResolver","getServerContext"],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { registerAmbientLocaleResolver } from '@intlayer/core/interpreter';\nimport type {\n  LocalesValues,\n  ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n  createServerContext<LocalesValues>(defaultLocale);\n\n// Lets a bare `getIntlayer` / `getDictionary` rendered on the server resolve to\n// the locale seeded by `IntlayerServerProvider` / `setLocale`. Read from the\n// store rather than `getServerContext`, whose default locale would shadow the\n// other resolvers.\nregisterAmbientLocaleResolver(() => IntlayerServerContext._storage()?.value);\n\n/**\n * Context that stores the ambient variant on the server side.\n *\n * Kept separate from {@link IntlayerServerContext} so the locale context keeps\n * its plain `LocalesValues` shape for the packages already reading it.\n */\nexport const IntlayerServerVariantContext =\n  createServerContext<ProviderVariant>(undefined);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\n/**\n * Seeds the request-scoped server context locale imperatively — the equivalent\n * of mounting {@link IntlayerServerProvider} without wrapping the tree.\n *\n * Useful in pages that must stay statically rendered while no ambient\n * request-derived locale source is static-safe (Next.js < 16):\n *\n * ```tsx\n * const Page = async ({ params }) => {\n *   const { locale } = await params;\n *   setLocale(locale);\n *   return <PageContent />;\n * };\n * ```\n */\nexport const setLocale = (locale: LocalesValues): void => {\n  IntlayerServerContext._storage().value = locale;\n};\n\n/**\n * Seeds the request-scoped ambient variant imperatively — the equivalent of\n * the `variant` prop of {@link IntlayerServerProvider} without wrapping the\n * tree. See that prop for the accepted shapes.\n */\nexport const setVariant = (variant: ProviderVariant): void => {\n  IntlayerServerVariantContext._storage().value = variant;\n};\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n  locale?: LocalesValues;\n  /**\n   * Ambient variant applied to every dictionary read below this provider — for\n   * a dimension resolved once per request (tenant, school type, plan tier…).\n   *\n   * Accepts a name (`'school1'`), an ordered preference chain\n   * (`['school1', 'default']`), or a per-key map\n   * (`{ key1: 'school1', default: 'base' }`). A call-site selector wins.\n   */\n  variant?: ProviderVariant;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n  children,\n  locale = defaultLocale,\n  variant,\n}) => (\n  <IntlayerServerContext.Provider value={locale}>\n    <IntlayerServerVariantContext.Provider value={variant}>\n      {children}\n    </IntlayerServerVariantContext.Provider>\n  </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;AASA,MAAM,EAAE,kBAAkBA,+CAAwB,CAAC;;;;AAKnD,MAAa,wBACXC,iDAAmC,aAAa;IAMlDC,gEAAoC,sBAAsB,SAAS,CAAC,EAAE,KAAK;;;;;;;AAQ3E,MAAa,+BACXD,iDAAqC,MAAS;;;;AAKhD,MAAa,oBAAoBE,8CAAiB,qBAAqB;;;;AAKvE,MAAa,SAASA,8CAAiB,qBAAqB;;;;;;;;;;;;;;;;AAiB5D,MAAa,aAAa,WAAgC;CACxD,sBAAsB,SAAS,CAAC,CAAC,QAAQ;AAC3C;;;;;;AAOA,MAAa,cAAc,YAAmC;CAC5D,6BAA6B,SAAS,CAAC,CAAC,QAAQ;AAClD;;;;AAkBA,MAAa,0BAA2D,EACtE,UACA,SAAS,eACT,cAEA,2CAAC,sBAAsB,UAAvB;CAAgC,OAAO;WACrC,2CAAC,6BAA6B,UAA9B;EAAuC,OAAO;EAC3C;CACoC;AACT"}