import { IntlProvider } from 'react-intl';
import en from '../i18n/en.json.mjs';
import { DirectionProvider } from './direction/DirectionProvider.mjs';
import { LanguageProvider } from './language/LanguageProvider.mjs';
import { jsx } from 'react/jsx-runtime';
import { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common/locale/index.mjs';

function Provider({
  i18n,
  children
}) {
  const {
    locale,
    messages,
    defaultRichTextElements
  } = i18n;
  const adjustedLocale = adjustLocale(locale);
  let intlConfig;
  if (adjustedLocale === null) {
    // eslint-disable-next-line no-console
    console.warn(`Unsupported locale value was provided: '${locale}', defaulting to '${DEFAULT_LOCALE}'`);
    intlConfig = {
      locale: DEFAULT_LOCALE,
      messages: {
        ...en,
        ...messages
      }
    };
  } else {
    intlConfig = {
      locale: adjustedLocale,
      messages
    };
  }
  return /*#__PURE__*/jsx(DirectionProvider, {
    direction: getDirectionFromLocale(locale),
    children: /*#__PURE__*/jsx(LanguageProvider, {
      locale: locale,
      children: /*#__PURE__*/jsx(IntlProvider, {
        defaultLocale: DEFAULT_LOCALE,
        locale: intlConfig.locale,
        messages: intlConfig.messages,
        defaultRichTextElements: defaultRichTextElements,
        children: children
      })
    })
  });
}

export { Provider as default };
//# sourceMappingURL=Provider.mjs.map
