{"version":3,"file":"useIntlayer.mjs","names":["useIntlayerBase"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n  DeclaredLocales,\n  DictionaryKeys,\n} from '@intlayer/types/module_augmentation';\nimport React from 'react';\nimport { useIntlayer as useIntlayerBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\nconst getCachedLocale =\n  typeof React.cache === 'function' ? React.cache(getLocale) : getLocale;\n\nexport const safeUseLocale = (): Locale | undefined => {\n  // getLocale returns a Promise based on your TS error\n  const localeData = getCachedLocale() as Promise<Locale> | Locale;\n\n  if (localeData instanceof Promise) {\n    if (typeof React.use === 'function') {\n      return React.use(localeData); // Safely unwraps in React 19+\n    }\n\n    // React < 19 cannot synchronously unwrap Promises in hooks.\n    // Return undefined to trigger the localeTarget fallback.\n    return undefined;\n  }\n\n  return localeData;\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n  T extends DictionaryKeys,\n  L extends DeclaredLocales = DeclaredLocales,\n>(\n  key: T,\n  locale?: L\n): ReturnType<typeof useIntlayerBase<T, L>> => {\n  const storedLocale = safeUseLocale();\n\n  return useIntlayerBase<T, L>(key, locale, storedLocale);\n};\n"],"mappings":";;;;;AASA,MAAM,kBACJ,OAAO,MAAM,UAAU,aAAa,MAAM,MAAM,SAAS,IAAI;AAE/D,MAAa,sBAA0C;CAErD,MAAM,aAAa,gBAAgB;CAEnC,IAAI,sBAAsB,SAAS;EACjC,IAAI,OAAO,MAAM,QAAQ,YACvB,OAAO,MAAM,IAAI,UAAU;EAK7B;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,eAIX,KACA,WAC6C;CAG7C,OAAOA,cAAsB,KAAK,QAFb,cAEgC,CAAC;AACxD"}