import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import { Component } from 'react';
import { LocaleContext } from './index';

var LocaleReceiver = /*#__PURE__*/function (_Component) {
  _inherits(LocaleReceiver, _Component);

  var _super = _createSuper(LocaleReceiver);

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

    return _super.apply(this, arguments);
  }

  _createClass(LocaleReceiver, [{
    key: "getLocale",
    value: function getLocale() {
      var _this$props = this.props,
          componentName = _this$props.componentName,
          defaultLocale = _this$props.defaultLocale;
      var c7nLocale = this.context.c7nLocale;
      var localeFromContext = c7nLocale && c7nLocale[componentName];
      return _objectSpread(_objectSpread({}, typeof defaultLocale === 'function' ? defaultLocale() : defaultLocale), localeFromContext || {});
    }
  }, {
    key: "getLocaleCode",
    value: function getLocaleCode() {
      var c7nLocale = this.context.c7nLocale;
      var localeCode = c7nLocale && c7nLocale.locale; // Had use LocaleProvide but didn't set locale

      if (c7nLocale && c7nLocale.exist && !localeCode) {
        return 'en-us';
      }

      return localeCode;
    }
  }, {
    key: "render",
    value: function render() {
      var children = this.props.children;
      return children(this.getLocale(), this.getLocaleCode());
    }
  }], [{
    key: "contextType",
    get: function get() {
      return LocaleContext;
    }
  }]);

  return LocaleReceiver;
}(Component);

export { LocaleReceiver as default };
//# sourceMappingURL=LocaleReceiver.js.map
