'use strict';

exports.__esModule = true;

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _instance = require('./instance');

var _instance2 = _interopRequireDefault(_instance);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function Context(_ref) {
  var _ref$locale = _ref.locale,
      locale = _ref$locale === undefined ? {} : _ref$locale,
      language = _ref.language,
      portal = _ref.portal,
      children = _ref.children;

  // 根据语言名称获取locale数据
  function initLocale() {
    var languageLocale = null;
    var result = require('./../locale/' + language + '.js');
    if (!result) {
      console.error('seedsui\u4E2D, ' + language + '\u8BED\u8A00\u5305\u4E0D\u5B58\u5728');
      locale = null;
      return;
    }
    // 防止没有用babel-plugin-add-module-exports自动加上default
    if (result.default) languageLocale = result.default;
    locale = _extends({}, languageLocale, locale);
  }
  // 获取locale数据
  if (language) {
    // 其次读取locale
    initLocale();
  }
  localStorage.setItem('_seedsui_locale', JSON.stringify(locale));
  return _react2.default.createElement(
    _instance2.default.Provider,
    {
      value: {
        locale: locale,
        language: language,
        portal: portal
      }
    },
    children
  );
}

exports.default = Context;
module.exports = exports['default'];