/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { Component, Input, ChangeDetectorRef } from '@angular/core';
import { ControlContainer, NgForm, FormControl } from '@angular/forms';
import { FVAbstractControl } from '../../../shared/abstract-control.component';
import { ProcessService } from '../../../../services/process.service';
import { ValidationService } from '../../../../services/validation.service';
var FVControlsValidatorComponent = /** @class */ (function (_super) {
    tslib_1.__extends(FVControlsValidatorComponent, _super);
    function FVControlsValidatorComponent(process, validator, ref) {
        var _this = _super.call(this, process) || this;
        _this.process = process;
        _this.validator = validator;
        _this.ref = ref;
        _this.errors = [];
        return _this;
    }
    /**
     * @return {?}
     */
    FVControlsValidatorComponent.prototype.ngAfterViewInit = /**
     * @return {?}
     */
    function () {
        this.subscriptions.push(this.process.onAnyUpdate.subscribe(this.checkForErrors.bind(this)));
        this.subscriptions.push(this.group.valueChanges.subscribe(this.checkForErrors.bind(this)));
        this.validator.onUpdate(this.checkForErrors.bind(this));
        this.checkForErrors();
        this.ref.detectChanges();
    };
    /**
     * @return {?}
     */
    FVControlsValidatorComponent.prototype.checkForErrors = /**
     * @return {?}
     */
    function () {
        var _this = this;
        /** @type {?} */
        var oldErrors = this.process.get("validator-" + this.task.taskId) || {};
        /** @type {?} */
        var control = this.formControl;
        if (!control.invalid || !this.group.dirty) {
            this.errors = [];
            delete oldErrors[this.control.key];
            return;
        }
        oldErrors[this.control.key] = this.tabIndex;
        this.process.set("validator-" + this.task.taskId, oldErrors);
        if (control.errors) {
            this.validator.scanForControlErrors(control.errors).then(function (errors) {
                _this.errors = errors;
            });
        }
        else {
            this.warn('Found error but not error type, throwing unknown!');
            this.validator.unkownError(false).then(function (error) {
                _this.errors = [error];
            });
        }
    };
    /**
     * @return {?}
     */
    FVControlsValidatorComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        _super.prototype.OnDestroy.call(this, this.ref);
    };
    FVControlsValidatorComponent.decorators = [
        { type: Component, args: [{
                    selector: 'fv-controls-validator',
                    template: "<div *ngFor=\"let err of errors\">\n  <span class=\"error-block\">{{ err | ltranslate }}</span>\n</div>",
                    viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
                    styles: [".col{display:inline-flex;flex-basis:0;flex-grow:1;max-width:100%;min-width:50%}.col fv-form-tab{padding:0 5px;display:block;width:100%}.col fv-form-tab .controls-row{margin:0;padding:0}.col fv-form-tab div{max-width:100%}.columns-0,.columns-1{width:100%;min-width:100%;max-width:100%}.columns-2{width:50%;min-width:50%;max-width:50%}.columns-3{width:33.33%;max-width:33.33%;min-width:33.33%}.columns-4{width:25%;max-width:25%;min-width:25%}.controlBox .input-group{display:inline-flex;width:100%;margin-top:5px}.controlBox>.input-group>button:not(.input-group-addon),.controlBox>.input-group>input,.controlBox>.input-group>select{height:40px!important;width:100%;padding:10px}.controlBox .input-group button.input-group-addon{position:relative;width:35px;height:40px}.controlBox .input-group span.controlName{color:red}.controlBox .input-group button.input-group-addon i{position:absolute;top:10px;bottom:0;left:0;right:0}.has-text-centered,.table,.table thead th{text-align:center}.gridForm{width:100%;padding:0;margin:0 0 10px}.gridForm .input-group>.form-control{max-width:50%;border-radius:unset;margin-right:10px;min-width:80px;min-height:45px}.gridForm .input-group>.addon{background:0 0;border:none;color:#36c}.grid-table tbody>tr>td{vertical-align:middle}.modal-dialog>.modal-content{max-height:100vh}.modal-content>.modal-body{max-height:85vh;overflow-y:auto}.modal-content fv-navigator{width:100%;display:block;position:relative;height:50px}.modal-content fv-navigator .docked-buttons{width:auto}.modal-content fv-navigator .btn-col:not(.bottom){max-width:unset;padding:6px!important}span.required{color:red}form:not(.ng-untouched) .ng-invalid{border:1px solid red},form:not(.ng-untouched) .ng-invalid.input-group-addon{border-left:none!important}span.error-block{color:red}@media screen and (max-width:426px){.columns-2,.columns-3,.columns-4{width:100%;max-width:100%;min-width:100%}}.tree:last-of-type(.accordion){margin:0}select:disabled{background:#eee}navigator-bot,navigator-top{display:flex}fv-menu-folder:last-of-type>accordion:last-of-type{margin:0;padding:0}.button-group>button:not(:last-child):not(:first-child){margin-left:0!important;padding-left:0!important;margin-right:0!important;padding-right:0!important}.fv_container,.fv_container>*,navigator-after,navigator-before{all:inherit!important;padding:0!important}.lookup-form .gridInputs{width:100%}.lookup-form .gridInputs select{width:40%}.lookup-form .gridInputs input{width:60%}.lookup-form .gridInputs,.lookup-form .gridInputs input,.lookup-form .gridInputs select{max-width:100%}.noMarginY{margin-top:0!important;margin-bottom:0!important}.placeholder,ng-select input:-moz-placeholder,ng-select input:-ms-input-placeholder,ng-select input:-webkit-input-placeholder,ng-select input:placeholder{color:#a9a9a9}select-dropdown div.options{text-align:left}.modal-dialog .modal-header .pull-right span{font-size:inherit!important}"]
                }] }
    ];
    /** @nocollapse */
    FVControlsValidatorComponent.ctorParameters = function () { return [
        { type: ProcessService },
        { type: ValidationService },
        { type: ChangeDetectorRef }
    ]; };
    FVControlsValidatorComponent.propDecorators = {
        formControl: [{ type: Input, args: ['FVFormControl',] }]
    };
    return FVControlsValidatorComponent;
}(FVAbstractControl));
export { FVControlsValidatorComponent };
if (false) {
    /** @type {?} */
    FVControlsValidatorComponent.prototype.errors;
    /** @type {?} */
    FVControlsValidatorComponent.prototype.formControl;
    /** @type {?} */
    FVControlsValidatorComponent.prototype.process;
    /** @type {?} */
    FVControlsValidatorComponent.prototype.validator;
    /** @type {?} */
    FVControlsValidatorComponent.prototype.ref;
}

//# sourceMappingURL=data:application/json;base64, 