"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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __validation = typescript_angular_utilities_1.services.validation;
var __array = typescript_angular_utilities_1.services.array;
var form_1 = require("../form/form");
var componentValidator_service_1 = require("../../services/componentValidator/componentValidator.service");
var ValidationGroupComponent = (function () {
    function ValidationGroupComponent(rlForm, componentValidator, arrayUtility) {
        this.arrayUtility = arrayUtility;
        this.groupValidator = componentValidator;
        this.validationControl = new forms_1.FormControl('', null, this.groupValidator.validate.bind(this.groupValidator));
        this.formGroup = new forms_1.FormGroup({ validation: this.validationControl });
        if (rlForm) {
            rlForm.form.addControl('', this.formGroup);
        }
    }
    ValidationGroupComponent.prototype.ngOnInit = function () {
        var validators = [];
        if (this.validator) {
            validators = validators.concat(this.arrayUtility.arrayify(this.validator));
        }
        if (this.validators) {
            validators = validators.concat(this.arrayUtility.arrayify(this.validators));
        }
        this.groupValidator.initValidator(validators, this.validationControl.valueChanges, this.validationControl);
    };
    ValidationGroupComponent.prototype.ngAfterViewInit = function () {
        this.validationControl.updateValueAndValidity(this.model || undefined);
    };
    ValidationGroupComponent.prototype.ngOnChanges = function (changes) {
        if (changes.model) {
            this.validationControl.updateValueAndValidity(changes.model.currentValue);
        }
    };
    ValidationGroupComponent.prototype.checkValidity = function () {
        this.validationControl.updateValueAndValidity(this.model);
    };
    return ValidationGroupComponent;
}());
__decorate([
    core_1.Input(),
    __metadata("design:type", Object)
], ValidationGroupComponent.prototype, "validator", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Array)
], ValidationGroupComponent.prototype, "validators", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Object)
], ValidationGroupComponent.prototype, "model", void 0);
ValidationGroupComponent = __decorate([
    core_1.Component({
        selector: 'rlValidationGroup',
        template: require('./validationGroup.html'),
        providers: [componentValidator_service_1.ComponentValidator],
    }),
    __param(0, core_1.Optional()),
    __metadata("design:paramtypes", [form_1.FormComponent,
        componentValidator_service_1.ComponentValidator, __array.ArrayUtility])
], ValidationGroupComponent);
exports.ValidationGroupComponent = ValidationGroupComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbkdyb3VwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidmFsaWRhdGlvbkdyb3VwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7QUFBQSxzQ0FBMkc7QUFDM0csd0NBQXdEO0FBRXhELDZFQUF3RDtBQUN4RCxJQUFPLFlBQVksR0FBRyx1Q0FBUSxDQUFDLFVBQVUsQ0FBQztBQUMxQyxJQUFPLE9BQU8sR0FBRyx1Q0FBUSxDQUFDLEtBQUssQ0FBQztBQUVoQyxxQ0FBNkM7QUFDN0MsMkdBQWtHO0FBWWxHLElBQWEsd0JBQXdCO0lBVXBDLGtDQUF3QixNQUFxQixFQUN6QyxrQkFBc0MsRUFDdEMsWUFBa0M7UUFDckMsSUFBSSxDQUFDLFlBQVksR0FBRyxZQUFZLENBQUM7UUFDakMsSUFBSSxDQUFDLGNBQWMsR0FBRyxrQkFBa0IsQ0FBQztRQUN6QyxJQUFJLENBQUMsaUJBQW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