{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n  DeclaredLocales,\n  DictionaryKeys,\n  DictionarySelectorForKey,\n  LocalesValues,\n  ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport {\n  IntlayerServerContext,\n  IntlayerServerVariantContext,\n} from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, optionally with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n  const T extends DictionaryKeys,\n  const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n  key: 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 getIntlayer<T, A>(\n      key,\n      resolveDictionaryArgument({\n        localeOrSelector,\n        contextLocale,\n        contextVariant,\n        dictionaryKey: key as string,\n      }) as A\n    );\n  }\n\n  const localeTarget = (localeOrSelector ?? contextLocale) as A;\n\n  return getIntlayer<T, A>(key, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,eAIX,KACA,kBACA,mBACG;CACH,MAAM,gBACJ,iBAAgC,qBAAqB,KAAK;CAE5D,IAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,iBAAiB,iBACrB,4BACF;EAEA,OAAO,YACL,KACA,0BAA0B;GACxB;GACA;GACA;GACA,eAAe;EACjB,CAAC,CACH;CACF;CAIA,OAAO,YAAkB,KAFH,oBAAoB,aAEA;AAC5C"}