"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.locale = locale;var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _constants = require("./constants");
var _LocaleContext = require("./LocaleContext");



function locale(controlName, localeHelper) {
  return function (constructor) {var _Class;
    var LocaleDecorator = (_Class = /*#__PURE__*/function (_constructor) {function LocaleDecorator() {var _this;for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}_this = _constructor.call.apply(_constructor, [this].concat(args)) || this;_this.


        controlName = controlName;_this.
        localeHelper = localeHelper;return _this;}(0, _inheritsLoose2.default)(LocaleDecorator, _constructor);return (0, _createClass2.default)(LocaleDecorator, [{ key: "locale", get:

        function get() {var _this$context$locale;
          var localeFromContext = (_this$context$locale = this.context.locale) == null ? void 0 : _this$context$locale[this.controlName];
          return Object.assign({}, this.localeHelper.get(this.context.langCode), localeFromContext);
        }, set:

        function set(l) {

          // TODO альтернативная транспиляция декораторов ломает тесты
        } }, { key: "langCode", get: function get() {var _this$context$langCod;
          return (_this$context$langCod = this.context.langCode) != null ? _this$context$langCod : _constants.defaultLangCode;
        } }]);}(constructor), _Class.contextType = _LocaleContext.LocaleContext, _Class);

    var nameDescriptor = Object.getOwnPropertyDescriptor(LocaleDecorator, 'name');
    if (!nameDescriptor || nameDescriptor.configurable) {
      Object.defineProperty(LocaleDecorator, 'name', { value: constructor.name });
    }
    return LocaleDecorator;
  };
}