"use strict";

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

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

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

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

var _tslib = require("tslib");

var _mobx = require("mobx");

var _moment = _interopRequireDefault(require("moment"));

var _defaultTo = _interopRequireDefault(require("lodash/defaultTo"));

var _locale = _interopRequireDefault(require("./locale"));

var _supports = _interopRequireDefault(require("./supports"));

var _utils = require("../utils");

var _mobxHelper = require("../mobx-helper");

function setMomentLocale(locale) {
  _moment["default"].locale((0, _utils.normalizeLanguage)(locale ? locale.lang : _locale["default"].lang));
}

var LocaleContext = /*#__PURE__*/function () {
  function LocaleContext() {
    var _this = this;

    (0, _classCallCheck2["default"])(this, LocaleContext);
    (0, _mobx.runInAction)(function () {
      _this.locale = _locale["default"];
      _this.supports = _supports["default"];
    });
  }

  (0, _createClass2["default"])(LocaleContext, [{
    key: "setLocale",
    value: function setLocale(locale) {
      setMomentLocale(locale);
      this.locale = locale;
    }
  }, {
    key: "setNumberFormatLanguage",
    value: function setNumberFormatLanguage(numberFormatLanguage) {
      this.numberFormatLanguage = numberFormatLanguage;
    }
  }, {
    key: "setSupports",
    value: function setSupports(supports) {
      this.supports = supports;
    }
  }, {
    key: "getCmp",
    value: function getCmp(component) {
      return (0, _mobxHelper.mobxGet)(this.locale, component);
    }
  }, {
    key: "get",
    value: function get(component, key, defaults) {
      var componentString = String(component);
      var cmp = (0, _mobxHelper.mobxGet)(this.locale, componentString) || defaults && (0, _mobxHelper.mobxGet)(defaults, componentString);

      if (key) {
        return (0, _defaultTo["default"])(cmp && (0, _mobxHelper.mobxGet)(cmp, String(key)), "".concat(componentString, ".").concat(key));
      }

      return componentString;
    }
  }]);
  return LocaleContext;
}();

exports.LocaleContext = LocaleContext;
(0, _tslib.__decorate)([_mobx.observable], LocaleContext.prototype, "locale", void 0);
(0, _tslib.__decorate)([_mobx.observable], LocaleContext.prototype, "numberFormatLanguage", void 0);
(0, _tslib.__decorate)([_mobx.observable], LocaleContext.prototype, "supports", void 0);
(0, _tslib.__decorate)([_mobx.action], LocaleContext.prototype, "setLocale", null);
(0, _tslib.__decorate)([_mobx.action], LocaleContext.prototype, "setNumberFormatLanguage", null);
(0, _tslib.__decorate)([_mobx.action], LocaleContext.prototype, "setSupports", null);

var _default = new LocaleContext();

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