"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = require("react");

var _index = require("./index");

var LocaleReceiver = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(LocaleReceiver, _Component);

  var _super = (0, _createSuper2["default"])(LocaleReceiver);

  function LocaleReceiver() {
    (0, _classCallCheck2["default"])(this, LocaleReceiver);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(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 (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, 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 _index.LocaleContext;
    }
  }]);
  return LocaleReceiver;
}(_react.Component);

exports["default"] = LocaleReceiver;
//# sourceMappingURL=LocaleReceiver.js.map
