var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
    if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
    return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
};
import { defaultLangCode } from './constants.js';
import { LocaleContext } from './LocaleContext.js';
export function locale(controlName, localeHelper) {
    return function (constructor) {
        var _a;
        var LocaleDecorator = (_a = /** @class */ (function (_super) {
                __extends(class_1, _super);
                function class_1() {
                    var _this = _super !== null && _super.apply(this, arguments) || this;
                    _this.controlName = controlName;
                    _this.localeHelper = localeHelper;
                    return _this;
                }
                Object.defineProperty(class_1.prototype, "locale", {
                    get: function () {
                        var _b;
                        var localeFromContext = (_b = this.context.locale) === null || _b === void 0 ? void 0 : _b[this.controlName];
                        return Object.assign({}, this.localeHelper.get(this.context.langCode), localeFromContext);
                    },
                    set: function (l) {
                        // TODO альтернативная транспиляция декораторов ломает тесты
                    },
                    enumerable: false,
                    configurable: true
                });
                Object.defineProperty(class_1.prototype, "langCode", {
                    get: function () {
                        var _b;
                        return (_b = this.context.langCode) !== null && _b !== void 0 ? _b : defaultLangCode;
                    },
                    enumerable: false,
                    configurable: true
                });
                return class_1;
            }(constructor)),
            __setFunctionName(_a, "LocaleDecorator"),
            _a.contextType = LocaleContext,
            _a);
        var nameDescriptor = Object.getOwnPropertyDescriptor(LocaleDecorator, 'name');
        if (!nameDescriptor || nameDescriptor.configurable) {
            Object.defineProperty(LocaleDecorator, 'name', { value: constructor.name });
        }
        return LocaleDecorator;
    };
}
//# sourceMappingURL=decorators.js.map