/**
 * @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 { MatDialog } from '@angular/material/dialog';
import { CSSFrameworkEnum } from '@asoftwareworld/form-builder-pro/api';
import { Constants, Icons } from '@asoftwareworld/form-builder-pro/common';
import { AswConfirmDialog } from '@asoftwareworld/form-builder-pro/form-control/confirm-dialog';
import { AswButtonDialog } from './button-dialog';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "@angular/common";
import * as i3 from "@angular/material/button";
import * as i4 from "@angular/material/tooltip";
import * as i5 from "@asoftwareworld/form-builder-pro/core";
import * as i6 from "@asoftwareworld/form-builder-pro/common";
export class AswButton {
    dialog;
    constants = Constants;
    icons = Icons;
    /**
     * Button control
     */
    control = null;
    CSSFramework = CSSFrameworkEnum.Material;
    isPreviewTemplate = false;
    propertyPersonalization = [];
    buttonClickEvent = new EventEmitter();
    buttonUpdateEvent = new EventEmitter();
    buttonDeleteEvent = new EventEmitter();
    duplicateControl = new EventEmitter();
    constructor(dialog) {
        this.dialog = dialog;
    }
    /**
     * Delete button control based on control index
     * @param control button control items
     * @param controlIndex button control index
     */
    deleteButtonDialog(control) {
        const dialogRef = this.dialog.open(AswConfirmDialog, {
            width: '350px',
            data: { name: control.controlType, message: this.constants.messages.waringMessage }
        });
        dialogRef.afterClosed().subscribe((result) => {
            if (result !== undefined) {
                this.buttonDeleteEvent.emit(control);
            }
        });
    }
    editButtonDialog(control) {
        const dialogRef = this.dialog.open(AswButtonDialog, {
            width: '50%',
            disableClose: true,
            data: { control, CSSFramework: this.CSSFramework, propertyPersonalization: this.propertyPersonalization }
        });
        dialogRef.afterClosed().subscribe((result) => {
            if (result !== undefined) {
                this.buttonUpdateEvent.emit(result);
            }
        });
    }
    buttonClick(type) {
        this.buttonClickEvent.emit(type);
    }
    duplicateButtonControl(control) {
        this.duplicateControl.emit(control);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: AswButton, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: AswButton, selector: "asw-button", inputs: { control: "control", CSSFramework: "CSSFramework", isPreviewTemplate: "isPreviewTemplate", propertyPersonalization: "propertyPersonalization" }, outputs: { buttonClickEvent: "buttonClickEvent", buttonUpdateEvent: "buttonUpdateEvent", buttonDeleteEvent: "buttonDeleteEvent", duplicateControl: "duplicateControl" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n    <ng-container *ngIf=\"CSSFramework === 'material'; else bootstrap\">\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\"\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\"\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\"\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\">\r\n                    {{control.label}}\r\n                </button>\r\n            </ng-container>\r\n        </ng-container>\r\n    </ng-container>\r\n    <ng-template #bootstrap>\r\n        <button [id]=\"control.id\"\r\n            [class]=\"control.customClass\"\r\n            [type]=\"control.type\"\r\n            [matTooltip]=\"control.tooltip\"\r\n            (click)=\"buttonClick(control.type)\"\r\n            class=\"asw-button asw-button-{{control.color}}\">{{control.label}}\r\n        </button>\r\n    </ng-template>\r\n    <div class=\"asw-row\" *ngIf=\"isPreviewTemplate\">\r\n        <div class=\"asw-col-md-12\" align=\"right\">\r\n            <button type=\"button\"\r\n                    mat-icon-button \r\n                    matTooltip=\"{{'FormControl.Duplicate' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"duplicateButtonControl(control)\">\r\n                <div [innerHTML]=\"icons.contentCopy | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Edit' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"editButtonDialog(control)\">\r\n                <div [innerHTML]=\"icons.edit | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"deleteButtonDialog(control)\">\r\n                <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n            </button>\r\n        </div>\r\n    </div>\r\n</ng-container>", dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i2.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "component", type: i3.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i3.MatIconButton, selector: "button[mat-icon-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "directive", type: i4.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "pipe", type: i5.AswTranslatePipe, name: "aswTranslate" }, { kind: "pipe", type: i6.AswSafeHtmlPipe, name: "aswSafeHtml" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: AswButton, decorators: [{
            type: Component,
            args: [{ selector: 'asw-button', template: "<ng-container *ngIf=\"control as control\">\r\n    <ng-container *ngIf=\"CSSFramework === 'material'; else bootstrap\">\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\"\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\"\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\"\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                        [id]=\"control.id\"\r\n                        [class]=\"control.customClass\"\r\n                        [type]=\"control.type\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        (click)=\"buttonClick(control.type)\">\r\n                    {{control.label}}\r\n                </button>\r\n            </ng-container>\r\n        </ng-container>\r\n    </ng-container>\r\n    <ng-template #bootstrap>\r\n        <button [id]=\"control.id\"\r\n            [class]=\"control.customClass\"\r\n            [type]=\"control.type\"\r\n            [matTooltip]=\"control.tooltip\"\r\n            (click)=\"buttonClick(control.type)\"\r\n            class=\"asw-button asw-button-{{control.color}}\">{{control.label}}\r\n        </button>\r\n    </ng-template>\r\n    <div class=\"asw-row\" *ngIf=\"isPreviewTemplate\">\r\n        <div class=\"asw-col-md-12\" align=\"right\">\r\n            <button type=\"button\"\r\n                    mat-icon-button \r\n                    matTooltip=\"{{'FormControl.Duplicate' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"duplicateButtonControl(control)\">\r\n                <div [innerHTML]=\"icons.contentCopy | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Edit' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"editButtonDialog(control)\">\r\n                <div [innerHTML]=\"icons.edit | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"deleteButtonDialog(control)\">\r\n                <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n            </button>\r\n        </div>\r\n    </div>\r\n</ng-container>" }]
        }], ctorParameters: function () { return [{ type: i1.MatDialog }]; }, propDecorators: { control: [{
                type: Input
            }], CSSFramework: [{
                type: Input
            }], isPreviewTemplate: [{
                type: Input
            }], propertyPersonalization: [{
                type: Input
            }], buttonClickEvent: [{
                type: Output
            }], buttonUpdateEvent: [{
                type: Output
            }], buttonDeleteEvent: [{
                type: Output
            }], duplicateControl: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 