"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require("@angular/core");
var lodash_1 = require("lodash");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __validation = typescript_angular_utilities_1.services.validation;
var ComponentValidator = (function () {
    function ComponentValidator(validationService) {
        this.validator = validationService.buildObservableValidator();
    }
    ComponentValidator.prototype.initValidator = function (validators, value$, control) {
        var _this = this;
        lodash_1.each(validators, function (customValidator) {
            _this.validator.registerValidationHandler(customValidator);
        });
        this.value$ = value$;
        this.error$.subscribe(function (error) { return control.rlErrorMessage = error; });
    };
    Object.defineProperty(ComponentValidator.prototype, "error$", {
        get: function () {
            return this.validator.validate(this.value$);
        },
        enumerable: true,
        configurable: true
    });
    ComponentValidator.prototype.validate = function (control) {
        return this.validator.validate(control.valueChanges).map(function (validation) {
            if (validation) {
                return { validationError: validation };
            }
            return null;
        });
    };
    return ComponentValidator;
}());
ComponentValidator = __decorate([
    core_1.Injectable(),
    __metadata("design:paramtypes", [__validation.ValidationService])
], ComponentValidator);
exports.ComponentValidator = ComponentValidator;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcG9uZW50VmFsaWRhdG9yLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjb21wb25lbnRWYWxpZGF0b3Iuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcH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