var _excluded = ["children"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { createI18njs } from '@procore/core-i18n-js';
import * as R from 'ramda';
import React from 'react';
import deDE from '../_locales/de-DE.json';
import enAU from '../_locales/en-AU.json';
import enCA from '../_locales/en-CA.json';
import enGB from '../_locales/en-GB.json';
import en from '../_locales/en.json';
import esES from '../_locales/es-ES.json';
import es from '../_locales/es.json';
import frCA from '../_locales/fr-CA.json';
import frFR from '../_locales/fr-FR.json';
import isIS from '../_locales/is-IS.json';
import jaJP from '../_locales/ja-JP.json';
import plPL from '../_locales/pl-PL.json';
import pseudo from '../_locales/pseudo.json';
import ptBR from '../_locales/pt-BR.json';
import thTH from '../_locales/th-TH.json';
import zhSG from '../_locales/zh-SG.json';
import { OVERWRITE_LOCALE_MAP } from './getI18nProviderLocale';

/**
 * @deprecated this type will no longer be supported from core-i18n-js,
 * to have a type safe Locale use TmsSupportedLocale or AllLocales from [Globalization toolkit](https://github.com/procore/globalization-toolkit)
 * @deprecatedSince 12.10.0
 */

/* Set up i18n-js */
export var coreTranslations = {
  'de-DE': deDE,
  en: en,
  'en-AU': enAU,
  'en-CA': enCA,
  'en-GB': enGB,
  es: es,
  'es-ES': esES,
  'fr-CA': frCA,
  'fr-FR': frFR,
  'is-IS': isIS,
  'ja-JP': jaJP,
  pseudo: pseudo,
  'pt-BR': ptBR,
  'th-TH': thTH,
  'zh-SG': zhSG,
  'pl-PL': plPL
};
function getValidLocale(_ref) {
  var locale = _ref.locale,
    translations = _ref.translations;
  return locale;
}
var FALLBACK_LOCALE_MAP = {
  'es-ES': 'es',
  'fr-FR': 'fr-CA'
};
function getTranslationFallbacks(locale) {
  if (locale === 'en') {
    return ['en'];
  }
  if (OVERWRITE_LOCALE_MAP[locale]) {
    return [OVERWRITE_LOCALE_MAP[locale], 'en'];
  }
  if (FALLBACK_LOCALE_MAP[locale]) {
    return [locale, FALLBACK_LOCALE_MAP[locale], 'en'];
  }
  return [locale, 'en'];
}
function setTranslationFallbacks(_ref2) {
  var I18n = _ref2.I18n,
    locale = _ref2.locale;
  I18n.locales[locale] = function () {
    return getTranslationFallbacks(locale);
  };
  return I18n;
}
export function useI18n(_ref3) {
  var _locale = _ref3.locale,
    _ref3$translations = _ref3.translations,
    _translations = _ref3$translations === void 0 ? {} : _ref3$translations;
  var translations = R.mergeDeepLeft(_translations, coreTranslations);
  var locale = getValidLocale({
    locale: _locale,
    translations: translations
  });
  var I18n = createI18njs({
    locale: locale,
    translations: translations
  });
  return setTranslationFallbacks({
    I18n: I18n,
    locale: locale || 'en'
  });
}
export var I18nContext = /*#__PURE__*/React.createContext(createI18njs({
  locale: 'en',
  translations: coreTranslations // inject our translations
}));

export function I18nProvider(_ref4) {
  var children = _ref4.children,
    props = _objectWithoutProperties(_ref4, _excluded);
  return /*#__PURE__*/React.createElement(I18nContext.Provider, {
    value: useI18n(props)
  }, children);
}
export function useI18nContext() {
  var ctx = React.useContext(I18nContext);
  if (!ctx) {
    // TODO investigate a way to do warnings that won't annoy people
    // we probably need to introduce a build system to have nice dev warnings
    // console.warn()
  }
  return ctx;
}
//# sourceMappingURL=I18n.js.map