{"version":3,"file":"useIntlayer.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryArgument","getDictionarySelectorCacheKey","useMemo","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport {\n  getDictionarySelectorCacheKey,\n  resolveDictionaryArgument,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n  DeclaredLocales,\n  DictionaryKeys,\n  DictionarySelectorForKey,\n  LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: ['black-friday', 'promo'] }` — ordered preference chain\n * - `locale` composes with any selector and overrides the context locale\n *\n * `locale` and `variant` both fall back to the surrounding `IntlayerProvider`\n * when the call does not pin them.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The dictionary content for the resolved entry and locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n *   const content = useIntlayer('my-dictionary-key');\n *   const faq2 = useIntlayer('faq', { item: 2 });\n *\n *   return <div>{content.myField.value}</div>;\n * };\n * ```\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) => {\n  const { locale: currentLocale, variant: contextVariant } =\n    useContext(IntlayerClientContext) ?? {};\n\n  // Layers the provider's locale and variant under the call-site argument.\n  // Selectors disabled project-wide (build-time flag) ⇒ the argument can only\n  // be a locale, so the merge is dead code and is dropped by the bundler.\n  const argument =\n    process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n      ? resolveDictionaryArgument({\n          localeOrSelector,\n          contextLocale: currentLocale,\n          contextVariant,\n          dictionaryKey: key as string,\n        })\n      : (localeOrSelector ?? currentLocale);\n\n  // Stable identity of the resolved argument for memoization — a provider\n  // variant is often a fresh object literal on every render, so the dependency\n  // has to be its serialization, never its reference.\n  const argumentIdentity =\n    process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n    typeof argument === 'object' &&\n    argument !== null\n      ? `${argument.locale ?? ''}|${getDictionarySelectorCacheKey(argument)}`\n      : argument;\n\n  return useMemo(\n    () => getIntlayer<T, A>(key, argument as A),\n    [key, argumentIdentity]\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,eAIX,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,uBACtCA,kBAAWC,qDAAqB,KAAK,CAAC;CAKxC,MAAM,WACJ,QAAQ,IAAI,iCAAiC,cACzCC,gEAA0B;EACxB;EACA,eAAe;EACf;EACA,eAAe;CACjB,CAAC,IACA,oBAAoB;CAK3B,MAAM,mBACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,aAAa,YACpB,aAAa,OACT,GAAG,SAAS,UAAU,GAAG,OAAGC,oEAA8B,QAAQ,MAClE;CAEN,WAAOC,qBACCC,gCAAkB,KAAK,QAAa,GAC1C,CAAC,KAAK,gBAAgB,CACxB;AACF"}