"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ruRUIntl = exports.ptBRIntl = exports.msMYIntl = exports.koKRIntl = exports.jaJPIntl = exports.itITIntl = exports.intlMapKeys = exports.intlMap = exports.idIDIntl = exports.frFRIntl = exports.faIRIntl = exports.esESIntl = exports.enUSIntl = exports.default = exports.deDEIntl = exports.createIntl = exports.arEGIntl = exports.ConfigProviderWrap = exports.ConfigProvider = exports.ConfigConsumer = void 0;
exports.useIntl = useIntl;
exports.zhTWIntl = exports.zhCNIntl = exports.viVNIntl = void 0;
require("core-js/modules/es.regexp.exec.js");
require("core-js/modules/es.string.replace.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireWildcard(require("react"));
var _warning = require("rc-util/es/warning");
var _configProvider = _interopRequireDefault(require("../config-provider"));
var _ar_EG = _interopRequireDefault(require("./locale/ar_EG"));
var _zh_CN = _interopRequireDefault(require("./locale/zh_CN"));
var _en_US = _interopRequireDefault(require("./locale/en_US"));
var _vi_VN = _interopRequireDefault(require("./locale/vi_VN"));
var _it_IT = _interopRequireDefault(require("./locale/it_IT"));
var _es_ES = _interopRequireDefault(require("./locale/es_ES"));
var _ja_JP = _interopRequireDefault(require("./locale/ja_JP"));
var _ru_RU = _interopRequireDefault(require("./locale/ru_RU"));
var _ms_MY = _interopRequireDefault(require("./locale/ms_MY"));
var _zh_TW = _interopRequireDefault(require("./locale/zh_TW"));
var _fr_FR = _interopRequireDefault(require("./locale/fr_FR"));
var _pt_BR = _interopRequireDefault(require("./locale/pt_BR"));
var _ko_KR = _interopRequireDefault(require("./locale/ko_KR"));
var _id_ID = _interopRequireDefault(require("./locale/id_ID"));
var _de_DE = _interopRequireDefault(require("./locale/de_DE"));
var _fa_IR = _interopRequireDefault(require("./locale/fa_IR"));
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
 * 支持 Map 和 Object
 *
 * @name ValueEnum 的类型
 */

/** Render 第二个参数，里面包含了一些常用的参数 */

function get(source, path, defaultValue) {
  // a[3].b -> a.3.b
  const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.');
  let result = source;
  let message = defaultValue;
  // eslint-disable-next-line no-restricted-syntax
  for (const p of paths) {
    message = Object(result)[p];
    result = Object(result)[p];
    if (message === undefined) {
      return defaultValue;
    }
  }
  return message;
}

/**
 * 创建一个操作函数
 *
 * @param locale
 * @param localeMap
 */
const createIntl = (locale, localeMap) => ({
  getMessage: (id, defaultMessage) => get(localeMap, id, defaultMessage) || defaultMessage,
  locale
});
exports.createIntl = createIntl;
const arEGIntl = createIntl('ar_EG', _ar_EG.default);
exports.arEGIntl = arEGIntl;
const zhCNIntl = createIntl('zh_CN', _zh_CN.default);
exports.zhCNIntl = zhCNIntl;
const enUSIntl = createIntl('en_US', _en_US.default);
exports.enUSIntl = enUSIntl;
const viVNIntl = createIntl('vi_VN', _vi_VN.default);
exports.viVNIntl = viVNIntl;
const itITIntl = createIntl('it_IT', _it_IT.default);
exports.itITIntl = itITIntl;
const jaJPIntl = createIntl('ja_JP', _ja_JP.default);
exports.jaJPIntl = jaJPIntl;
const esESIntl = createIntl('es_ES', _es_ES.default);
exports.esESIntl = esESIntl;
const ruRUIntl = createIntl('ru_RU', _ru_RU.default);
exports.ruRUIntl = ruRUIntl;
const msMYIntl = createIntl('ms_MY', _ms_MY.default);
exports.msMYIntl = msMYIntl;
const zhTWIntl = createIntl('zh_TW', _zh_TW.default);
exports.zhTWIntl = zhTWIntl;
const frFRIntl = createIntl('fr_FR', _fr_FR.default);
exports.frFRIntl = frFRIntl;
const ptBRIntl = createIntl('pt_BR', _pt_BR.default);
exports.ptBRIntl = ptBRIntl;
const koKRIntl = createIntl('ko_KR', _ko_KR.default);
exports.koKRIntl = koKRIntl;
const idIDIntl = createIntl('id_ID', _id_ID.default);
exports.idIDIntl = idIDIntl;
const deDEIntl = createIntl('de_DE', _de_DE.default);
exports.deDEIntl = deDEIntl;
const faIRIntl = createIntl('fa_IR', _fa_IR.default);
exports.faIRIntl = faIRIntl;
const intlMap = {
  'ar-EG': arEGIntl,
  'zh-CN': zhCNIntl,
  'en-US': enUSIntl,
  'vi-VN': viVNIntl,
  'it-IT': itITIntl,
  'ja-JP': jaJPIntl,
  'es-ES': esESIntl,
  'ru-RU': ruRUIntl,
  'ms-MY': msMYIntl,
  'zh-TW': zhTWIntl,
  'fr-FR': frFRIntl,
  'pt-BR': ptBRIntl,
  'ko-KR': koKRIntl,
  'id-ID': idIDIntl,
  'de-DE': deDEIntl,
  'fa-IR': faIRIntl
};
exports.intlMap = intlMap;
const intlMapKeys = Object.keys(intlMap);
exports.intlMapKeys = intlMapKeys;
const ConfigContext = /*#__PURE__*/_react.default.createContext({
  intl: {
    ...zhCNIntl,
    locale: 'default'
  },
  valueTypeMap: {}
});
const {
  Consumer: ConfigConsumer,
  Provider: ConfigProvider
} = ConfigContext;

/**
 * 根据 antd 的 key 来找到的 locale 插件的 key
 *
 * @param localeKey
 */
exports.ConfigProvider = ConfigProvider;
exports.ConfigConsumer = ConfigConsumer;
const findIntlKeyByAntdLocaleKey = localeKey => {
  if (!localeKey) {
    return 'zh-CN';
  }
  const localeName = localeKey.toLocaleLowerCase();
  return intlMapKeys.find(intlKey => {
    const LowerCaseKey = intlKey.toLocaleLowerCase();
    return LowerCaseKey.includes(localeName);
  }) || 'zh-CN';
};

/**
 * 如果没有配置 locale，这里组件会根据 antd 的 key 来自动选择
 *
 * @param param0
 */
const ConfigProviderWrap = ({
  children
}) => {
  const {
    locale
  } = (0, _react.useContext)(_configProvider.default.ConfigContext);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ConfigConsumer, {
    children: value => {
      var _value$intl;
      const localeName = locale === null || locale === void 0 ? void 0 : locale.locale;
      const key = findIntlKeyByAntdLocaleKey(localeName);
      // antd 的 key 存在的时候以 antd 的为主
      const intl = localeName && ((_value$intl = value.intl) === null || _value$intl === void 0 ? void 0 : _value$intl.locale) === 'default' ? intlMap[key] : value.intl || intlMap[key];
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(ConfigProvider, {
        value: {
          ...value,
          intl: intl || zhCNIntl
        },
        children: children
      });
    }
  });
};
exports.ConfigProviderWrap = ConfigProviderWrap;
function useIntl() {
  const context = (0, _react.useContext)(ConfigContext);
  (0, _warning.noteOnce)(!!context.intl, `
为了提升兼容性
<IntlProvider value={zhCNIntl}/>
需要修改为:
<ConfigProvider
  value={{
    intl: zhCNIntl,
  }}
/>
我们将会在下个版本中删除它
    `);
  (0, _warning.noteOnce)(!!context.intl, `
To improve compatibility
  <IntlProvider value={zhCNIntl}/>
Need to be modified to:
  <ConfigProvider
    value={{
      intl: zhCNIntl,
    }}
  />
We will remove it in the next version
    `);
  if (!context.intl) {
    return context || zhCNIntl;
  }
  return context.intl || zhCNIntl;
}
var _default = ConfigContext;
exports.default = _default;