{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","internationalization","useDictionary","useLoadDynamic"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n  DeclaredLocales,\n  LocalesValues,\n  StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n  const T extends Dictionary,\n  const L extends LocalesValues = DeclaredLocales,\n>(\n  dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n  key: string,\n  locale?: L,\n  fallbackLocale?: DeclaredLocales\n) => {\n  const localeTarget =\n    locale ??\n    getServerContext<LocalesValues>(IntlayerServerContext) ??\n    fallbackLocale ??\n    internationalization.defaultLocale;\n\n  const dictionary = useLoadDynamic<T>(\n    `${String(key)}.${localeTarget}`,\n    (dictionaryPromise as any)[localeTarget]?.()\n  );\n\n  return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAa,wBAIX,mBACA,KACA,QACA,mBACG;CACH,MAAM,eACJ,UACAA,8CAAgCC,4DAAsB,IACtD,kBACAC,4CAAqB;AAOvB,QAAOC,2CALYC,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBACjB,kBAA0B,iBAAiB,CAGT,EAAE,aAAkB"}