/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { Component, Output, EventEmitter } from '@angular/core';
import { FormConstants, PrivateConstants } from './constants';
import { PrivateDynamicFromService } from './services';
var DynamicFormControllerComponent = /** @class */ (function () {
    function DynamicFormControllerComponent(_privateDynamicFromService) {
        var _this = this;
        this._privateDynamicFromService = _privateDynamicFromService;
        this.submitEvent = new EventEmitter();
        this.fields = [];
        this.formConstants = FormConstants;
        this.privateConstants = PrivateConstants;
        this.validateForm = false;
        this._privateDynamicFromService.getFormFields().subscribe((/**
         * @param {?} resp
         * @return {?}
         */
        function (resp) {
            if (resp && resp.fieldSet && resp.fieldSet.length) {
                _this.fields = resp.fieldSet;
                _this._privateDynamicFromService.updateFields(_this.fields).subscribe((/**
                 * @param {?} resp
                 * @return {?}
                 */
                function (resp) {
                    _this.orderForm = resp;
                }));
            }
        }));
        this._privateDynamicFromService.clickEvent().subscribe((/**
         * @param {?} resp
         * @return {?}
         */
        function (resp) {
            if (resp && resp.attrObj) {
                _this.clickEvent(resp.attrObj);
            }
        }));
    }
    /**
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () { };
    Object.defineProperty(DynamicFormControllerComponent.prototype, "rowFormList", {
        get: /**
         * @return {?}
         */
        function () {
            return this.orderForm.get('rowForm')['controls'];
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @param {?} field
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.clickEvent = /**
     * @param {?} field
     * @return {?}
     */
    function (field) {
        if (field.returnValue &&
            !this.handleReadonlyAttr(field)) {
            this.responseFormat(field);
        }
        else if (field.validateForm &&
            this.orderForm.valid &&
            !this.handleReadonlyAttr(field)) {
            this.responseFormat(field);
        }
        else if (field.validateForm &&
            !this.handleReadonlyAttr(field)) {
            this.validateForm = true;
            this._privateDynamicFromService.updateValidateForm(this.validateForm);
        }
        else if (field.resetForm &&
            !this.handleReadonlyAttr(field)) {
            this.orderForm.reset();
        }
        else if (field.returnFormObject) {
            this.submitEvent.emit({
                fieldName: field.name,
                formData: this.orderForm
            });
        }
    };
    /**
     * @param {?} field
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.responseFormat = /**
     * @param {?} field
     * @return {?}
     */
    function (field) {
        var _this = this;
        if (this.formatFields()) {
            setTimeout((/**
             * @return {?}
             */
            function () {
                _this.submitEvent.emit({
                    fieldName: field.name,
                    formData: _this.orderForm.value.rowForm
                });
            }), this.formConstants.responseTime);
        }
    };
    /**
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.formatFields = /**
     * @return {?}
     */
    function () {
        var _this = this;
        this.fields.forEach((/**
         * @param {?} rF
         * @param {?} rfKey
         * @return {?}
         */
        function (rF, rfKey) {
            rF.fields.forEach((/**
             * @param {?} cF
             * @param {?} cfKey
             * @return {?}
             */
            function (cF, cfKey) {
                if (cF.type === _this.formConstants.fieldType.checkBox) {
                    /** @type {?} */
                    var selectedValue_1 = _this.orderForm.value.rowForm[rfKey][cF.name];
                    Object.keys(selectedValue_1).forEach((/**
                     * @param {?} sKey
                     * @return {?}
                     */
                    function (sKey) {
                        if (selectedValue_1 &&
                            sKey &&
                            selectedValue_1[sKey] &&
                            selectedValue_1[sKey].length &&
                            typeof selectedValue_1[sKey] === "object") {
                            _this.orderForm.value.rowForm[rfKey][cF.name] = [];
                            selectedValue_1[sKey].forEach((/**
                             * @param {?} selectCheckbox
                             * @param {?} selectCheckboxKey
                             * @return {?}
                             */
                            function (selectCheckbox, selectCheckboxKey) {
                                if (selectCheckbox) {
                                    _this.orderForm.value.rowForm[rfKey][cF.name].push(cF.otherOptions[selectCheckboxKey].value);
                                }
                            }));
                        }
                    }));
                }
            }));
        }));
        return true;
    };
    /**
     * @param {?} attrObj
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.handleReadonlyAttr = /**
     * @param {?} attrObj
     * @return {?}
     */
    function (attrObj) {
        return this._privateDynamicFromService.handleReadonlyAttr(attrObj);
    };
    /**
     * @param {?} field
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.checkDisplayAttr = /**
     * @param {?} field
     * @return {?}
     */
    function (field) {
        return this._privateDynamicFromService.checkDisplayAttr(field);
    };
    /**
     * @param {?} rowField
     * @return {?}
     */
    DynamicFormControllerComponent.prototype.calculateClass = /**
     * @param {?} rowField
     * @return {?}
     */
    function (rowField) {
        return this._privateDynamicFromService.calculateClass(rowField);
    };
    DynamicFormControllerComponent.decorators = [
        { type: Component, args: [{
                    selector: 'dynamic-form-controller',
                    template: "<form class=\"form-content\" [formGroup]=\"orderForm\" *ngIf=\"fields && fields.length\">\n    <div formArrayName=\"rowForm\" [id]=\"fields[i].id\" *ngFor=\"let item of rowFormList; let i = index;\">\n        <div class=\"form-label\" *ngIf=\"fields[i].label\">{{fields[i].label}}</div>\n        <div class=\"row {{fields[i].class}}\" [formGroupName]=\"i\">\n            <ng-container *ngFor=\"let field of fields[i].fields; let j = index\">\n                <textbox-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.textBox && checkDisplayAttr(field)\"\n                    [i]=\"i\" [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></textbox-controll>\n\n                <image-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.image && checkDisplayAttr(field)\" [i]=\"i\"\n                    [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></image-controll>\n\n                <password-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.password && checkDisplayAttr(field)\"\n                    [i]=\"i\" [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></password-controll>\n\n                <number-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.number && checkDisplayAttr(field)\"\n                    [i]=\"i\" [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></number-controll>\n\n                <files-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.files && checkDisplayAttr(field)\" [i]=\"i\" [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></files-controll>\n\n                <dropdown-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.selectOption && checkDisplayAttr(field)\" [i]=\"i\" [j]=\"j\" [field]=\"field\" [formControlName]=\"field.name\" [rowField]=\"fields[i]\"></dropdown-controll>\n\n                <datetextbox-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.dateTextBox && checkDisplayAttr(field)\" [i]=\"i\" [j]=\"j\" [field]=\"field\" [parentFormGroup]=\"item\" [formControlName]=\"field.name\" [rowField]=\"fields[i]\"></datetextbox-controll>\n\n                <textarea-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.textArea && checkDisplayAttr(field)\"\n                    [i]=\"i\" [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></textarea-controll>\n\n                <radio-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.radio && checkDisplayAttr(field)\" [i]=\"i\" [j]=\"j\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></radio-controll>\n\n                <checkbox-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.checkBox && checkDisplayAttr(field)\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\" (clickEvent)=\"clickEvent($event)\"></checkbox-controll>\n\n                <timetextbox-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.timeTextBox && checkDisplayAttr(field)\" [i]=\"i\" [j]=\"j\" [formControlName]=\"field.name\" [parentFormGroup]=\"item\" [field]=\"field\" [rowField]=\"fields[i]\"></timetextbox-controll>\n\n                <button-controll class=\"{{calculateClass(fields[i])}}\" *ngIf=\"field.type === formConstants.fieldType.button && checkDisplayAttr(field)\"\n                    [i]=\"i\" [j]=\"j\" (clickEvent)=\"clickEvent($event)\" [field]=\"field\" [rowField]=\"fields[i]\">\n                </button-controll>\n            </ng-container>\n\n            <div class=\"col-md-12 divider\" *ngIf=\"fields[i].divider\"></div>\n        </div>\n    </div>\n</form>",
                    styles: ["@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css);@import url(https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css);.readonly-text-color{color:#8a8989!important}.divider{clear:both;border-top:1px solid rgba(0,0,0,.1);margin:10px 0}"]
                }] }
    ];
    /** @nocollapse */
    DynamicFormControllerComponent.ctorParameters = function () { return [
        { type: PrivateDynamicFromService }
    ]; };
    DynamicFormControllerComponent.propDecorators = {
        submitEvent: [{ type: Output }]
    };
    return DynamicFormControllerComponent;
}());
export { DynamicFormControllerComponent };
if (false) {
    /** @type {?} */
    DynamicFormControllerComponent.prototype.submitEvent;
    /** @type {?} */
    DynamicFormControllerComponent.prototype.subscription;
    /** @type {?} */
    DynamicFormControllerComponent.prototype.fields;
    /** @type {?} */
    DynamicFormControllerComponent.prototype.formConstants;
    /** @type {?} */
    DynamicFormControllerComponent.prototype.privateConstants;
    /** @type {?} */
    DynamicFormControllerComponent.prototype.orderForm;
    /** @type {?} */
    DynamicFormControllerComponent.prototype.validateForm;
    /**
     * @type {?}
     * @private
     */
    DynamicFormControllerComponent.prototype._privateDynamicFromService;
}
//# sourceMappingURL=data:application/json;base64, 