/**
 * 对外暴露用于注入全局配置属性的Context.Provider
 */
import React from 'react';
import assign from 'lodash/assign';
import ConfigContext from './ConfigContext';
import defaultConfig from './defaultConfig';
import localeCacher, { getLangMsg as getLang, getCompLangMsg as getCompLang } from '../locale/index';

var ConfigProvider = function ConfigProvider(props) {
  // 处理当前语言
  var value = props.value;
  var localeConfig = value && value.localeConfig;
  var locale = {
    getLangMsg: function getLangMsg(componentName, labelName, params) {
      if (localeConfig && localeConfig.customGetLangMsg) {
        return localeConfig.customGetLangMsg(componentName, labelName, params);
      }

      return getLang(componentName, labelName, params);
    },
    getCompLangMsg: function getCompLangMsg(compLangMsgParams) {
      return getCompLang(compLangMsgParams, localeConfig === null || localeConfig === void 0 ? void 0 : localeConfig.customGetLangMsg);
    }
  };

  if (localeConfig) {
    localeCacher.setLocalesData(localeConfig.locale, localeConfig.localeData);
  } // 处理组件默认属性


  var providerValue = assign({}, defaultConfig, value, {
    locale: locale
  });
  return /*#__PURE__*/React.createElement(ConfigContext.Provider, {
    value: providerValue
  }, props.children);
};

export default ConfigProvider;