/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { Component, Input } from '@angular/core';
import { FormArray, FormGroup } from '@angular/forms';
import { EntityRelation } from '../../entity';
var AttributeTableComponent = /** @class */ (function () {
    function AttributeTableComponent() {
        this.isDetailModalShown = false;
        this.isErrorModalShown = false;
    }
    /**
     * @return {?}
     */
    AttributeTableComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    Object.defineProperty(AttributeTableComponent.prototype, "displayDetailModal", {
        get: /**
         * @return {?}
         */
        function () { return this.isDetailModalShown ? 'block' : 'none'; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AttributeTableComponent.prototype, "displayErrorModal", {
        get: /**
         * @return {?}
         */
        function () { return this.isErrorModalShown ? 'block' : 'none'; },
        enumerable: true,
        configurable: true
    });
    /**
     * @param {?} index
     * @return {?}
     */
    AttributeTableComponent.prototype.openDetailModal = /**
     * @param {?} index
     * @return {?}
     */
    function (index) {
        this.currentFormGroup = this.formArray.at(index);
        this.isDetailModalShown = true;
    };
    /**
     * @return {?}
     */
    AttributeTableComponent.prototype.closeDetailModal = /**
     * @return {?}
     */
    function () {
        if (!this.readonly && this.currentFormGroup.dirty) {
            this.currentFormGroup.setValue(this.currentFormGroup.value); // Or the value won't be updated.
        }
        this.isDetailModalShown = false;
    };
    /**
     * @param {?} errorTitle
     * @param {?} errorDescription
     * @return {?}
     */
    AttributeTableComponent.prototype.openErrorModal = /**
     * @param {?} errorTitle
     * @param {?} errorDescription
     * @return {?}
     */
    function (errorTitle, errorDescription) {
        this.errorTitle = errorTitle;
        this.errorDescription = errorDescription;
        this.isErrorModalShown = true;
    };
    /**
     * @return {?}
     */
    AttributeTableComponent.prototype.closeErrorModal = /**
     * @return {?}
     */
    function () {
        this.isErrorModalShown = false;
    };
    /**
     * @param {?=} index
     * @return {?}
     */
    AttributeTableComponent.prototype.deleteRelationInstance = /**
     * @param {?=} index
     * @return {?}
     */
    function (index) {
        if (index === void 0) { index = 0; }
        switch (this.entityRelation.CARDINALITY) {
            case '[0..n]':
                this.formArray.removeAt(index);
                this.formArray.markAsDirty();
                if (this.formArray.length === 0) {
                    this.entityRelation.EMPTY = true;
                }
                break;
            case '[1..n]':
                if (this.formArray.length === 1) {
                    this.openErrorModal('Deletion Fail', 'The relation requires at lease one entry!');
                }
                else {
                    this.formArray.removeAt(index);
                    this.formArray.markAsDirty();
                }
        }
    };
    AttributeTableComponent.decorators = [
        { type: Component, args: [{
                    selector: 'dk-app-attribute-table',
                    template: "<table class=\"table table-bordered table-sm relation-table\" [formGroup]=\"parentFormGroup\">\n  <thead class=\"thead-light\">\n  <tr>\n    <th scope=\"col\">\n      Action\n    </th>\n    <th scope=\"col\" *ngFor=\"let attributeControl of attributeControls\">\n      {{attributeControl.label}}<strong *ngIf=\"attributeControl.primaryKey\" class=\"primaryKey\">*</strong>\n    </th>\n  </tr>\n  </thead>\n\n  <tbody [formArrayName]=\"entityRelation.RELATION_ID\">\n    <tr *ngFor=\"let formGroup of formArray.controls; let i = index\">\n      <td class=\"actions\">\n        <button class=\"btn btn-sm\" type=\"button\" (click)=\"openDetailModal(i)\" title=\"Detail\">\n          <span *ngIf=\"readonly\" class=\"fas fa-search\"></span>\n          <span *ngIf=\"!readonly\" class=\"fas fa-pen\"></span>\n        </button>\n        <button class=\"btn btn-sm\" type=\"button\" [disabled]=\"readonly\" (click)=\"deleteRelationInstance(i)\" title=\"Delete\">\n          <span class=\"far fa-trash-alt\"></span>\n        </button>\n      </td>\n      <td *ngFor=\"let attributeControl of attributeControls\">\n        <dk-app-attribute [attributeControl]=\"attributeControl\" [formGroup]=\"formGroup\" [readonly]=\"readonly\">\n\n        </dk-app-attribute>\n      </td>\n    </tr>\n  </tbody>\n</table>\n\n<div *ngIf=\"currentFormGroup\" class=\"modal fade dk-modal-open\" [ngClass]=\"{'show': isDetailModalShown}\"\n     [ngStyle]=\"{'display': displayDetailModal}\" id=\"detailModal\" tabindex=\"-1\" role=\"dialog\">\n  <div class=\"modal-dialog modal-lg\" role=\"document\">\n    <div class=\"modal-content\">\n      <div class=\"modal-header\">\n        <h5 class=\"modal-title\" id=\"detail\">Line Detail</h5>\n        <button type=\"button\" class=\"close\" (click)=\"closeDetailModal()\">\n          <span aria-hidden=\"true\">&times;</span>\n        </button>\n      </div>\n      <div class=\"modal-body\">\n        <dk-app-attribute-form *ngFor=\"let attributeControl of attributeControls\" [readonly]=\"readonly\"\n                            [attributeControl]=\"attributeControl\" [formGroup]=\"currentFormGroup\">\n        </dk-app-attribute-form>\n      </div>\n      <div class=\"modal-footer\">\n        <button type=\"button\" class=\"btn btn-sm btn-primary\" (click)=\"closeDetailModal()\">OK</button>\n      </div>\n    </div>\n  </div>\n</div>\n\n<div class=\"modal fade\" [ngClass]=\"{'show': isErrorModalShown}\"\n     [ngStyle]=\"{'display': displayErrorModal}\" id=\"errorModal\" tabindex=\"-1\" role=\"dialog\">\n  <div class=\"modal-dialog\" role=\"document\">\n    <div class=\"modal-content\">\n      <div class=\"modal-header\">\n        <h5 class=\"modal-title\" id=\"error\">{{errorTitle}}</h5>\n        <button type=\"button\" class=\"close\" (click)=\"closeErrorModal()\">\n          <span aria-hidden=\"true\">&times;</span>\n        </button>\n      </div>\n      <div class=\"modal-body\">\n        <p>{{errorDescription}}</p>\n      </div>\n      <div class=\"modal-footer\">\n        <button type=\"button\" class=\"btn btn-sm btn-primary\" (click)=\"closeErrorModal()\">OK</button>\n      </div>\n    </div>\n  </div>\n</div>\n\n",
                    styles: [".primaryKey{color:red}.relation-table{display:block;overflow-x:auto;white-space:nowrap;border:none}.actions{width:5rem;min-width:5rem;max-width:6rem}.dk-modal-open{overflow:auto}"]
                }] }
    ];
    /** @nocollapse */
    AttributeTableComponent.ctorParameters = function () { return []; };
    AttributeTableComponent.propDecorators = {
        attributeControls: [{ type: Input }],
        formArray: [{ type: Input }],
        parentFormGroup: [{ type: Input }],
        entityRelation: [{ type: Input }],
        readonly: [{ type: Input }]
    };
    return AttributeTableComponent;
}());
export { AttributeTableComponent };
if (false) {
    /** @type {?} */
    AttributeTableComponent.prototype.isDetailModalShown;
    /** @type {?} */
    AttributeTableComponent.prototype.currentFormGroup;
    /** @type {?} */
    AttributeTableComponent.prototype.isErrorModalShown;
    /** @type {?} */
    AttributeTableComponent.prototype.errorTitle;
    /** @type {?} */
    AttributeTableComponent.prototype.errorDescription;
    /** @type {?} */
    AttributeTableComponent.prototype.attributeControls;
    /** @type {?} */
    AttributeTableComponent.prototype.formArray;
    /** @type {?} */
    AttributeTableComponent.prototype.parentFormGroup;
    /** @type {?} */
    AttributeTableComponent.prototype.entityRelation;
    /** @type {?} */
    AttributeTableComponent.prototype.readonly;
}
//# sourceMappingURL=data:application/json;base64, 