/**
 * @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 { AswSelectDialog } from './select-dialog';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "@angular/material/form-field";
import * as i3 from "@angular/material/select";
import * as i4 from "@angular/material/core";
import * as i5 from "@angular/common";
import * as i6 from "@angular/material/tooltip";
import * as i7 from "@angular/forms";
export class AswSelect {
    constructor(dialog) {
        this.dialog = dialog;
        this.constants = Constants;
        /**
         * Select control
         */
        this.control = null;
        this.isPreviewTemplate = false;
        this.selectUpdateEvent = new EventEmitter();
        this.selectDeleteEvent = new EventEmitter();
    }
    deleteSelectDialog(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.selectDeleteEvent.emit(controlIndex);
            }
        });
    }
    editSelectDialog(control, controlIndex) {
        control.options.forEach(element => {
            element.isChecked = control.value === element.key ? true : false;
        });
        const dialogRef = this.dialog.open(AswSelectDialog, {
            disableClose: true,
            width: '744px',
            data: control
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.selectUpdateEvent.emit({ control: result, index: controlIndex });
            }
        });
    }
}
AswSelect.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswSelect, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
AswSelect.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.4", type: AswSelect, selector: "asw-select", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { selectUpdateEvent: "selectUpdateEvent", selectDeleteEvent: "selectDeleteEvent" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n    <mat-form-field [appearance]=\"control.style\" class=\"asw-mat-form-field\">\r\n        <mat-label>{{control.label}}</mat-label>\r\n        <mat-select [placeholder]=\"control.label\" \r\n            [matTooltip]=\"control.tooltip\"\r\n            [(ngModel)]=\"control.value\"                    \r\n            #input=\"ngModel\"\r\n            [required]=\"control.isRequired\">\r\n            <mat-option *ngFor=\"let option of control.options\" [value]=\"option.key\">\r\n                {{ option.value }}\r\n            </mat-option>\r\n        </mat-select>\r\n        <mat-error class=\"asw-mat-error\" *ngIf=\"input.invalid && (input.dirty || input.touched)\">\r\n            <mat-error class=\"asw-mat-error\" *ngIf=\"input?.errors?.required\">\r\n                {{control.label}} is required\r\n            </mat-error>\r\n        </mat-error>\r\n    </mat-form-field>\r\n    <ng-template [ngIf]=\"isPreviewTemplate\">\r\n        <div class=\"row\">\r\n            <div class=\"col-md-12\">\r\n                <button mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Edit select control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editSelectDialog(control, controlIndex)\"\r\n                        class=\"asw-btn btn btn-just-icon btn-sm btn-outline-success mr-2 me-2 mb-1\">\r\n                    <i class=\"material-icons asw-material-icon\">edit</i>\r\n                </button>\r\n                <button mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Remove select control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteSelectDialog(control, controlIndex)\"\r\n                        class=\"asw-btn btn btn-just-icon btn-sm btn-outline-danger mb-1\">\r\n                    <i class=\"material-icons asw-material-icon\">close</i>\r\n                </button>\r\n            </div>                                            \r\n        </div>\r\n    </ng-template>    \r\n</ng-container>", components: [{ type: i2.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { type: i3.MatSelect, selector: "mat-select", inputs: ["disabled", "disableRipple", "tabIndex"], exportAs: ["matSelect"] }, { type: i4.MatOption, selector: "mat-option", exportAs: ["matOption"] }], directives: [{ type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i6.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i7.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i7.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: i7.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.MatError, selector: "mat-error", inputs: ["id"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswSelect, decorators: [{
            type: Component,
            args: [{ selector: 'asw-select', template: "<ng-container *ngIf=\"control as control\">\r\n    <mat-form-field [appearance]=\"control.style\" class=\"asw-mat-form-field\">\r\n        <mat-label>{{control.label}}</mat-label>\r\n        <mat-select [placeholder]=\"control.label\" \r\n            [matTooltip]=\"control.tooltip\"\r\n            [(ngModel)]=\"control.value\"                    \r\n            #input=\"ngModel\"\r\n            [required]=\"control.isRequired\">\r\n            <mat-option *ngFor=\"let option of control.options\" [value]=\"option.key\">\r\n                {{ option.value }}\r\n            </mat-option>\r\n        </mat-select>\r\n        <mat-error class=\"asw-mat-error\" *ngIf=\"input.invalid && (input.dirty || input.touched)\">\r\n            <mat-error class=\"asw-mat-error\" *ngIf=\"input?.errors?.required\">\r\n                {{control.label}} is required\r\n            </mat-error>\r\n        </mat-error>\r\n    </mat-form-field>\r\n    <ng-template [ngIf]=\"isPreviewTemplate\">\r\n        <div class=\"row\">\r\n            <div class=\"col-md-12\">\r\n                <button mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Edit select control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editSelectDialog(control, controlIndex)\"\r\n                        class=\"asw-btn btn btn-just-icon btn-sm btn-outline-success mr-2 me-2 mb-1\">\r\n                    <i class=\"material-icons asw-material-icon\">edit</i>\r\n                </button>\r\n                <button mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Remove select control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteSelectDialog(control, controlIndex)\"\r\n                        class=\"asw-btn btn btn-just-icon btn-sm btn-outline-danger mb-1\">\r\n                    <i class=\"material-icons asw-material-icon\">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
            }], selectUpdateEvent: [{
                type: Output
            }], selectDeleteEvent: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 