{"version":3,"file":"InternalGTProvider.mjs","names":[],"sources":["../../src/context/InternalGTProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, type ReactNode } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport type { Dictionary, Translation } from 'gt-i18n/types';\nimport type { Locale, Hash } from 'gt-i18n/internal/types';\nimport { getGTContext } from './context';\nimport type {\n  OnMissingDictionaryEntry,\n  OnMissingDictionaryObj,\n  OnMissingTranslation,\n} from '../hooks/utils/missing-translation';\n\nexport type InternalGTProviderProps = {\n  children?: ReactNode;\n  // For streaming translations to server\n  translations: Record<Locale, Record<Hash, Translation>>;\n  dictionaries?: Record<Locale, Dictionary>;\n  locale: string;\n  region: string | undefined;\n  enableI18n: boolean;\n  setLocale: (locale: string) => void;\n  setRegion: (region: string | undefined) => void;\n  setEnableI18n: (enabled: boolean) => void;\n  i18nStore: I18nStore;\n  // Custom override missing translation behavior for dev hot reload\n  onMissingTranslation?: OnMissingTranslation;\n  onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n  onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\n// ===== Component ===== //\nconst GTContext = getGTContext();\n/**\n * - Shared provider logic btwn client and server providers\n * - This is not userfacing, it should be wrapped in a userfacing provider with runtime-specific logic\n * - Locale and translations (and dictionaries if applicable) are required\n *\n * TODO: selectively filter to only pass new translations to client for dev hot reload\n * TODO: rename parent directory to \"/provider\" (separate PR)\n */\nexport function InternalGTProvider({\n  children,\n  translations,\n  dictionaries,\n  locale,\n  region,\n  enableI18n,\n  setLocale,\n  setRegion,\n  setEnableI18n,\n  i18nStore,\n  onMissingTranslation,\n  onMissingDictionaryEntry,\n  onMissingDictionaryObj,\n}: InternalGTProviderProps) {\n  const value = useMemo(\n    () => ({\n      translationsSnapshot: translations,\n      dictionariesSnapshot: dictionaries ?? {},\n      i18nStore,\n      locale,\n      region,\n      enableI18n,\n      setLocale,\n      setRegion,\n      setEnableI18n,\n      onMissingTranslation,\n      onMissingDictionaryEntry,\n      onMissingDictionaryObj,\n    }),\n    [\n      translations,\n      dictionaries,\n      i18nStore,\n      locale,\n      region,\n      enableI18n,\n      setLocale,\n      setRegion,\n      setEnableI18n,\n      onMissingTranslation,\n      onMissingDictionaryEntry,\n      onMissingDictionaryObj,\n    ]\n  );\n\n  // Update cache with data from server, do not emit events\n  useEffect(() => {\n    i18nStore.updateTranslations(translations);\n    i18nStore.updateDictionaries(dictionaries ?? {});\n  }, [translations, dictionaries, i18nStore]);\n\n  return <GTContext.Provider value={value}>{children}</GTContext.Provider>;\n}\n"],"mappings":"oIA8BA,MAAM,EAAY,GAAc,CAShC,SAAgB,EAAmB,CACjC,WACA,eACA,eACA,SACA,SACA,aACA,YACA,YACA,gBACA,YACA,uBACA,2BACA,0BAC0B,CAC1B,IAAM,EAAQ,OACL,CACL,qBAAsB,EACtB,qBAAsB,GAAgB,EAAE,CACxC,YACA,SACA,SACA,aACA,YACA,YACA,gBACA,uBACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAQD,OALA,MAAgB,CACd,EAAU,mBAAmB,EAAa,CAC1C,EAAU,mBAAmB,GAAgB,EAAE,CAAC,EAC/C,CAAC,EAAc,EAAc,EAAU,CAAC,CAEpC,EAAC,EAAU,SAAX,CAA2B,QAAQ,WAA8B,CAAA"}