var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _class, _temp;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

import { Component } from 'react';
import PropTypes from 'prop-types';

var ConfigProvider = (_temp = _class = function (_Component) {
  _inherits(ConfigProvider, _Component);

  function ConfigProvider() {
    _classCallCheck(this, ConfigProvider);

    return _possibleConstructorReturn(this, _Component.apply(this, arguments));
  }

  ConfigProvider.prototype.getChildContext = function getChildContext() {
    var _props = this.props,
        locale = _props.locale,
        language = _props.language,
        portal = _props.portal,
        onChange = _props.onChange;

    if (language) {
      var defaultLocale = null;
      switch (language) {
        case 'zh_CN':
          {
            defaultLocale = require('./../locale/zh_CN.js');
            // 防止没有用babel-plugin-add-module-exports自动加上default
            if (defaultLocale.default) defaultLocale = defaultLocale.default;
            locale = _extends({}, defaultLocale, locale);
            break;
          }
        case 'en_US':
          {
            defaultLocale = require('./../locale/en_US.js');
            // 防止没有用babel-plugin-add-module-exports自动加上default
            if (defaultLocale.default) defaultLocale = defaultLocale.default;
            locale = _extends({}, defaultLocale, locale);
            break;
          }
      }
    }
    // 如果有locale的话, 则放入内存中, 开放给getLocaleValue使用
    if (locale) {
      localStorage.setItem('_seedsui_locale', JSON.stringify(locale));
    }
    return {
      locale: locale,
      language: language,
      portal: portal,
      onChange: onChange
    };
  };

  ConfigProvider.prototype.render = function render() {
    return this.props.children;
  };

  return ConfigProvider;
}(Component), _class.childContextTypes = {
  locale: PropTypes.object,
  language: PropTypes.string,
  portal: PropTypes.object,
  onChange: PropTypes.func
}, _temp);
export { ConfigProvider as default };
ConfigProvider.propTypes = process.env.NODE_ENV !== "production" ? {
  locale: PropTypes.object,
  language: PropTypes.string,
  portal: PropTypes.object,
  onChange: PropTypes.func,
  children: PropTypes.any
} : {};