{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n  Dictionary,\n  DictionarySelectorForGroup,\n  QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n  DeclaredLocales,\n  LocalesValues,\n  ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport {\n  IntlayerServerContext,\n  IntlayerServerVariantContext,\n} from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary (or qualified\n * dictionary group) and return the content\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the server context\n */\nexport const useDictionary = <\n  const T extends Dictionary | QualifiedDictionaryGroup,\n  const A extends LocalesValues | DictionarySelectorForGroup<T> =\n    DeclaredLocales,\n>(\n  dictionary: T,\n  localeOrSelector?: A,\n  fallbackLocale?: DeclaredLocales\n) => {\n  const contextLocale =\n    getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n  if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n    const contextVariant = getServerContext<ProviderVariant>(\n      IntlayerServerVariantContext\n    );\n\n    return getDictionary<T, A>(\n      dictionary,\n      resolveDictionaryArgument({\n        localeOrSelector,\n        contextLocale,\n        contextVariant,\n        dictionaryKey: dictionary.key,\n      }) as A\n    );\n  }\n\n  const localeTarget = (localeOrSelector ?? contextLocale) as A;\n\n  return getDictionary<T, A>(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAa,iBAKX,YACA,kBACA,mBACG;CACH,MAAM,gBACJ,iBAAgC,qBAAqB,KAAK;CAE5D,IAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,iBAAiB,iBACrB,4BACF;EAEA,OAAO,cACL,YACA,0BAA0B;GACxB;GACA;GACA;GACA,eAAe,WAAW;EAC5B,CAAC,CACH;CACF;CAIA,OAAO,cAAoB,YAFL,oBAAoB,aAES;AACrD"}