{"version":3,"file":"dictionaries.cjs","names":[],"sources":["../../../src/i18n-store/utils/dictionaries.ts"],"sourcesContent":["import { getDictionaryEntry, isDictionaryValue } from 'gt-i18n/internal';\nimport type { Locale } from 'gt-i18n/internal/types';\nimport type { Dictionary, DictionaryObject } from 'gt-i18n/types';\nimport type {\n  DictionaryEntrySnapshot,\n  DictionaryLookup,\n  DictionaryObjectSnapshot,\n} from '../storeTypes';\n\nexport function lookupDictionaryEntry(\n  dictionariesSnapshot: Record<Locale, Dictionary> | undefined,\n  lookup: DictionaryLookup\n): DictionaryEntrySnapshot {\n  return getDictionaryEntry(\n    lookupDictionaryValue(dictionariesSnapshot, lookup)\n  );\n}\n\nexport function lookupDictionaryObject(\n  dictionariesSnapshot: Record<Locale, Dictionary> | undefined,\n  lookup: DictionaryLookup\n): DictionaryObjectSnapshot {\n  return lookupDictionaryValue(dictionariesSnapshot, lookup);\n}\n\nfunction lookupDictionaryValue(\n  dictionariesSnapshot: Record<Locale, Dictionary> | undefined,\n  { locale, id }: DictionaryLookup\n): DictionaryObjectSnapshot {\n  const dictionary = dictionariesSnapshot?.[locale];\n  if (!dictionary) return undefined;\n  if (!id) return dictionary;\n\n  let current: DictionaryObject | undefined = dictionary;\n  for (const segment of id.split('.')) {\n    if (!isSafeDictionaryPathSegment(segment)) return undefined;\n    if (!isDictionaryValue(current)) return undefined;\n    if (!Object.prototype.hasOwnProperty.call(current, segment)) {\n      return undefined;\n    }\n    current = current[segment];\n  }\n  return current;\n}\n\nfunction isSafeDictionaryPathSegment(segment: string): boolean {\n  return (\n    segment !== '__proto__' &&\n    segment !== 'constructor' &&\n    segment !== 'prototype'\n  );\n}\n"],"mappings":"kFASA,SAAgB,EACd,EACA,EACyB,CACzB,OAAA,EAAA,EAAA,oBACE,EAAsB,EAAsB,EAAO,CACpD,CAGH,SAAgB,EACd,EACA,EAC0B,CAC1B,OAAO,EAAsB,EAAsB,EAAO,CAG5D,SAAS,EACP,EACA,CAAE,SAAQ,MACgB,CAC1B,IAAM,EAAa,IAAuB,GAC1C,GAAI,CAAC,EAAY,OACjB,GAAI,CAAC,EAAI,OAAO,EAEhB,IAAI,EAAwC,EAC5C,IAAK,IAAM,KAAW,EAAG,MAAM,IAAI,CAAE,CAGnC,GAFI,CAAC,EAA4B,EAAQ,EACrC,EAAA,EAAA,EAAA,mBAAmB,EAAQ,EAC3B,CAAC,OAAO,UAAU,eAAe,KAAK,EAAS,EAAQ,CACzD,OAEF,EAAU,EAAQ,GAEpB,OAAO,EAGT,SAAS,EAA4B,EAA0B,CAC7D,OACE,IAAY,aACZ,IAAY,eACZ,IAAY"}