import { Component, Input, EventEmitter, Output } from '@angular/core';
import { DefaultCreateSaveCancel } from '../../../lib/create-save-cancel-default';
import * as i0 from "@angular/core";
import * as i1 from "../../../../icon/icon.component";
import * as i2 from "@angular/forms";
import * as i3 from "../../../../button/button.directive";
import * as i4 from "../../../../popover/popover.component";
import * as i5 from "@angular/common";
import * as i6 from "@ngx-translate/core";
export class TbodySaveCancelComponent extends DefaultCreateSaveCancel {
    constructor() {
        super();
        this.editSave = new EventEmitter();
        this.editCancel = new EventEmitter();
    }
    ngOnChanges() {
        // ===========================================
        // Call DefaultCreateSaveCancel "ngOnChanges()" life cycle hook
        // ===========================================
        super.ngOnChanges();
        this.saveButtonContent = this.grid.getSetting('edit.saveButtonContent');
        this.cancelButtonContent = this.grid.getSetting('edit.cancelButtonContent');
    }
    onSave(event) {
        event.preventDefault();
        event.stopPropagation();
        if (!this.grid.getSetting('edit.confirmSave')) {
            // As it will be saved immediately, send to the instalation the Edited Data to be, i.e., API call saved @ BD:
            this.editSave.emit({
                data: Object.assign({}, this.row.data),
                newData: this.row.getNewData(),
            });
            this.editingFormGroup.reset();
        }
        // Save data @ grid, checking if it needs an "editConfirm" or not:
        this.grid.save(this.row, this.editConfirm);
    }
    onCancelEdit(event) {
        event.preventDefault();
        event.stopPropagation();
        this.row.isInEditing = false;
        this.editingFormGroup.reset();
        this.editCancel.emit();
    }
}
TbodySaveCancelComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: TbodySaveCancelComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
TbodySaveCancelComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: TbodySaveCancelComponent, selector: "ng2-st-tbody-save-cancel", inputs: { grid: "grid", row: "row", editConfirm: "editConfirm" }, outputs: { editSave: "editSave", editCancel: "editCancel" }, usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
        <div class="form-editor-submit" [formGroup]="editingFormGroup">
            <button
                type="submit"
                class="slds-m-right--x-small uno-smart-table-action uno-smart-table-action-edit-save text-uppercase"
                unoButton
                unoType="green"
                unoSize="x-small"
                (click)="onSave($event)"
                [disabled]="!editingFormGroup.valid"
                [title]="saveButtonContent | translate"

                uno-popover-trigger
                [unoPopover]="formErrorsTemplate"
                [unoPopoverOpen]="openValidatorPopover"

                unoPopoverPlacement="leftBottom"
                unoPopoverNubbin="right-top"
                unoPopoverSize="small"
                unoPopoverTooltip="true"
                [unoPopoverTheme]="grid.getSetting('popoverTheme') || 'info'">
                    {{ saveButtonContent | translate }}
            </button>

            <uno-icon
                id="close"
                icon="close"
                size="x-small"
                class="uno-smart-table-action uno-smart-table-action-edit-cancel"
                [title]="cancelButtonContent | translate"
                (click)="onCancelEdit($event)">
            </uno-icon>

        </div>

        <!-- The "editingFormGroup" ALL Controller's Input Validator errors: -->
        <ng-template #formErrorsTemplate>
            <div class="form-errors-content-container">
                <!--Following errors where found on editing:-->
                <div *ngFor="let cell of grid.dataSet.columns" class="slds-m-top--x-small">
                    <div *ngIf="editingFormGroup.get(cell.id)?.errors">

                        <b style="color:red;">{{ cell.id }}</b> is invalid!
                        <!-- Has error {{ editingFormGroup.get(cell.id).errors | json}}! -->

                        <div *ngFor="let errors of errorsData">
                            <div *ngIf="errors.input === cell.id">
                                <div *ngFor="let strError of errors.translated" translate>
                                    {{ strError }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </ng-template>
    `, isInline: true, components: [{ type: i1.IconComponent, selector: "uno-icon", inputs: ["svgType", "icon", "withOpacity", "color", "size", "customColor"] }], directives: [{ type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i2.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i3.ButtonDirective, selector: "[unoButton]", inputs: ["unoType", "unoSize"] }, { type: i4.PopoverTriggerDirective, selector: "[uno-popover-trigger]", inputs: ["unoPopover", "unoPopoverHeader", "unoPopoverFooter", "unoPopoverTemplate", "unoPopoverTemplateData", "hasEdit", "hasDelete", "infoTitle", "infoCreatedBy", "infoModifiedBy", "infoDate", "unoPopoverPlacement", "unoPopoverTheme", "unoPopoverNubbin", "unoPopoverSize", "unoPopoverTooltip", "unoPopoverDelay", "unoPopoverInteractive", "unoPopoverOpen"], outputs: ["unoPopoverToggled", "unoPopoverTemplateEvent"], exportAs: ["unoPopoverTrigger"] }, { type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i6.TranslateDirective, selector: "[translate],[ngx-translate]", inputs: ["translate", "translateParams"] }], pipes: { "translate": i6.TranslatePipe } });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: TbodySaveCancelComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'ng2-st-tbody-save-cancel',
                    template: `
        <div class="form-editor-submit" [formGroup]="editingFormGroup">
            <button
                type="submit"
                class="slds-m-right--x-small uno-smart-table-action uno-smart-table-action-edit-save text-uppercase"
                unoButton
                unoType="green"
                unoSize="x-small"
                (click)="onSave($event)"
                [disabled]="!editingFormGroup.valid"
                [title]="saveButtonContent | translate"

                uno-popover-trigger
                [unoPopover]="formErrorsTemplate"
                [unoPopoverOpen]="openValidatorPopover"

                unoPopoverPlacement="leftBottom"
                unoPopoverNubbin="right-top"
                unoPopoverSize="small"
                unoPopoverTooltip="true"
                [unoPopoverTheme]="grid.getSetting('popoverTheme') || 'info'">
                    {{ saveButtonContent | translate }}
            </button>

            <uno-icon
                id="close"
                icon="close"
                size="x-small"
                class="uno-smart-table-action uno-smart-table-action-edit-cancel"
                [title]="cancelButtonContent | translate"
                (click)="onCancelEdit($event)">
            </uno-icon>

        </div>

        <!-- The "editingFormGroup" ALL Controller's Input Validator errors: -->
        <ng-template #formErrorsTemplate>
            <div class="form-errors-content-container">
                <!--Following errors where found on editing:-->
                <div *ngFor="let cell of grid.dataSet.columns" class="slds-m-top--x-small">
                    <div *ngIf="editingFormGroup.get(cell.id)?.errors">

                        <b style="color:red;">{{ cell.id }}</b> is invalid!
                        <!-- Has error {{ editingFormGroup.get(cell.id).errors | json}}! -->

                        <div *ngFor="let errors of errorsData">
                            <div *ngIf="errors.input === cell.id">
                                <div *ngFor="let strError of errors.translated" translate>
                                    {{ strError }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </ng-template>
    `
                }]
        }], ctorParameters: function () { return []; }, propDecorators: { grid: [{
                type: Input
            }], row: [{
                type: Input
            }], editConfirm: [{
                type: Input
            }], editSave: [{
                type: Output
            }], editCancel: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 