{"version":3,"file":"configProvider.mjs","names":[],"sources":["../../../../package/common/configProvider/configProvider.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from 'react';\nimport type { ComponentDefaults, ConfigProviderProps } from './configProvider.types';\nimport type { Presentation } from '../configProvider/presentation.types';\nimport { validLocale } from './validLocale';\n\nexport const ConfigContext = createContext<ComponentDefaults | null>(null);\n\n/**\n * One setting for every component that can present as a bottom sheet, kept separate from\n * `defaultProps` so that turning sheets on (or off) app-wide is a single switch rather than one\n * entry per component key — the components that can do it are unrelated to each other, and a\n * consumer who missed one would get sheets in half their app.\n */\nexport const PresentationContext = createContext<Presentation | undefined>(undefined);\n\nexport const NavigateContext = createContext<ConfigProviderProps['navigate']>(undefined);\n\nexport const LocaleContext = createContext<string | undefined>(undefined);\n\n/**\n * Shallow-merge two default maps per component key, so nested ConfigProviders\n * compose: an inner provider's `Input` defaults extend (and override on\n * conflict) the outer provider's `Input` defaults rather than replacing them.\n */\nfunction mergeDefaults(parent: ComponentDefaults | null, own: ComponentDefaults | undefined): ComponentDefaults {\n  if (!parent) return own ?? {};\n  if (!own) return parent;\n\n  const merged: Record<string, object> = { ...parent };\n  for (const key in own) {\n    merged[key] = {\n      ...(parent as Record<string, object>)[key],\n      ...(own as Record<string, object>)[key],\n    };\n  }\n  return merged as ComponentDefaults;\n}\n\nfunction ConfigProvider({ children, defaultProps, presentation, navigate, locale }: ConfigProviderProps) {\n  const parent = useContext(ConfigContext);\n  const value = useMemo(() => mergeDefaults(parent, defaultProps), [parent, defaultProps]);\n\n  // A nested provider that doesn't set `presentation` keeps the outer one's, the same way\n  // `defaultProps` compose.\n  const inheritedPresentation = useContext(PresentationContext);\n  const presentationValue = presentation ?? inheritedPresentation;\n  const inheritedNavigate = useContext(NavigateContext);\n  const inheritedLocale = useContext(LocaleContext);\n\n  return (\n    <ConfigContext.Provider value={value}>\n      <PresentationContext.Provider value={presentationValue}>\n        <NavigateContext.Provider value={navigate ?? inheritedNavigate}>\n          <LocaleContext.Provider value={validLocale(locale, 'ConfigProvider') ?? inheritedLocale}>\n            {children}\n          </LocaleContext.Provider>\n        </NavigateContext.Provider>\n      </PresentationContext.Provider>\n    </ConfigContext.Provider>\n  );\n}\n\nexport default ConfigProvider;\n"],"mappings":"wKAKA,IAAa,EAAgB,EAAwC,IAAI,EAQ5D,EAAsB,EAAwC,IAAA,EAAS,EAEvE,EAAkB,EAA+C,IAAA,EAAS,EAE1E,EAAgB,EAAkC,IAAA,EAAS,EAOxE,SAAS,EAAc,EAAkC,EAAuD,CAC9G,GAAI,CAAC,EAAQ,OAAO,GAAO,CAAC,EAC5B,GAAI,CAAC,EAAK,OAAO,EAEjB,IAAM,EAAiC,CAAE,GAAG,CAAO,EACnD,IAAK,IAAM,KAAO,EAChB,EAAO,GAAO,CACZ,GAAI,EAAkC,GACtC,GAAI,EAA+B,EACrC,EAEF,OAAO,CACT,CAEA,SAAS,EAAe,CAAE,WAAU,eAAc,eAAc,WAAU,UAA+B,CACvG,IAAM,EAAS,EAAW,CAAa,EACjC,EAAQ,MAAc,EAAc,EAAQ,CAAY,EAAG,CAAC,EAAQ,CAAY,CAAC,EAIjF,EAAwB,EAAW,CAAmB,EACtD,EAAoB,GAAgB,EACpC,EAAoB,EAAW,CAAe,EAC9C,EAAkB,EAAW,CAAa,EAEhD,OACE,EAAC,EAAc,SAAf,CAA+B,QAC7B,SAAA,EAAC,EAAoB,SAArB,CAA8B,MAAO,EACnC,SAAA,EAAC,EAAgB,SAAjB,CAA0B,MAAO,GAAY,EAC3C,SAAA,EAAC,EAAc,SAAf,CAAwB,MAAO,EAAY,EAAQ,gBAAgB,GAAK,EACrE,UACqB,CAAA,CACA,CAAA,CACE,CAAA,CACR,CAAA,CAE5B"}