/**
 * @license
 * Copyright ASW (A Software World) All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file
 */
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { AswConfirmDialog } from '@asoftwareworld/form-builder/form-control/confirm-dialog';
import { Constants } from '@asoftwareworld/form-builder/form-control/core';
import { AswButtonDialog } from './button-dialog';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "@angular/material/button";
import * as i3 from "@angular/common";
import * as i4 from "@angular/material/tooltip";
export class AswButton {
    constructor(dialog) {
        this.dialog = dialog;
        this.constants = Constants;
        /**
         * Button control
         */
        this.control = null;
        this.isPreviewTemplate = false;
        this.buttonUpdateEvent = new EventEmitter();
        this.buttonDeleteEvent = new EventEmitter();
    }
    /**
     * Delete button control based on control index
     * @param control button control items
     * @param controlIndex button control index
     */
    deleteButtonDialog(control, controlIndex) {
        const dialogRef = this.dialog.open(AswConfirmDialog, {
            width: '350px',
            data: { name: control.name, message: this.constants.messages.waringMessage }
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.buttonDeleteEvent.emit(controlIndex);
            }
        });
    }
    editButtonDialog(control, controlIndex) {
        const dialogRef = this.dialog.open(AswButtonDialog, {
            disableClose: true,
            width: '744px',
            data: control
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.buttonUpdateEvent.emit({ control: result, index: controlIndex });
            }
        });
    }
}
AswButton.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswButton, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
AswButton.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: AswButton, selector: "asw-button", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { buttonUpdateEvent: "buttonUpdateEvent", buttonDeleteEvent: "buttonDeleteEvent" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n    <ng-container [ngSwitch]=\"control.style\">\r\n        <ng-container *ngSwitchCase=\"'mat-button'\">\r\n            <button mat-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n        <ng-container *ngSwitchCase=\"'mat-raised-button'\">\r\n            <button mat-raised-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n        <ng-container *ngSwitchCase=\"'mat-stroked-button'\">\r\n            <button mat-stroked-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n        <ng-container *ngSwitchCase=\"'mat-flat-button'\">\r\n            <button mat-flat-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [title]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    [title]=\"control.tooltip\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n    </ng-container>\r\n    <ng-template [ngIf]=\"isPreviewTemplate\">\r\n        <div class=\"row\">\r\n            <div class=\"col-md-12\">\r\n                <button type=\"button\" \r\n                        matTooltip=\"Edit button\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editButtonDialog(control, controlIndex)\"\r\n                        class=\"btn btn-sm btn-just-icon btn-outline-success mr-2 mb-1\">\r\n                    <i class=\"material-icons\">edit</i>\r\n                </button>\r\n                <button type=\"button\" \r\n                        matTooltip=\"Remove button\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteButtonDialog(control, controlIndex)\"\r\n                        class=\"btn btn-sm btn-just-icon btn-outline-danger mb-1\">\r\n                    <i class=\"material-icons\">close</i>\r\n                </button>\r\n            </div>\r\n        </div>\r\n    </ng-template>    \r\n</ng-container>", components: [{ type: i2.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { type: i3.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { type: i4.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswButton, decorators: [{
            type: Component,
            args: [{ selector: 'asw-button', template: "<ng-container *ngIf=\"control as control\">\r\n    <ng-container [ngSwitch]=\"control.style\">\r\n        <ng-container *ngSwitchCase=\"'mat-button'\">\r\n            <button mat-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n        <ng-container *ngSwitchCase=\"'mat-raised-button'\">\r\n            <button mat-raised-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n        <ng-container *ngSwitchCase=\"'mat-stroked-button'\">\r\n            <button mat-stroked-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n        <ng-container *ngSwitchCase=\"'mat-flat-button'\">\r\n            <button mat-flat-button \r\n                    [color]=\"control.color\"\r\n                    [type]=\"control.type\"\r\n                    [title]=\"control.tooltip\"\r\n                    [name]=\"control.name\"\r\n                    [title]=\"control.tooltip\"\r\n                    >{{control.label}}</button>\r\n        </ng-container>\r\n    </ng-container>\r\n    <ng-template [ngIf]=\"isPreviewTemplate\">\r\n        <div class=\"row\">\r\n            <div class=\"col-md-12\">\r\n                <button type=\"button\" \r\n                        matTooltip=\"Edit button\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editButtonDialog(control, controlIndex)\"\r\n                        class=\"btn btn-sm btn-just-icon btn-outline-success mr-2 mb-1\">\r\n                    <i class=\"material-icons\">edit</i>\r\n                </button>\r\n                <button type=\"button\" \r\n                        matTooltip=\"Remove button\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteButtonDialog(control, controlIndex)\"\r\n                        class=\"btn btn-sm btn-just-icon btn-outline-danger mb-1\">\r\n                    <i class=\"material-icons\">close</i>\r\n                </button>\r\n            </div>\r\n        </div>\r\n    </ng-template>    \r\n</ng-container>" }]
        }], ctorParameters: function () { return [{ type: i1.MatDialog }]; }, propDecorators: { control: [{
                type: Input
            }], controlIndex: [{
                type: Input
            }], isPreviewTemplate: [{
                type: Input
            }], buttonUpdateEvent: [{
                type: Output
            }], buttonDeleteEvent: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 