/**
 * @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 { AswCheckboxDialog } from './checkbox-dialog';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "@angular/material/checkbox";
import * as i3 from "@angular/common";
import * as i4 from "@angular/material/form-field";
import * as i5 from "@angular/material/tooltip";
import * as i6 from "@angular/forms";
export class AswCheckbox {
    constructor(dialog) {
        this.dialog = dialog;
        this.constants = Constants;
        this.control = null;
        this.isPreviewTemplate = false;
        this.checkboxUpdateEvent = new EventEmitter();
        this.checkboxDeleteEvent = new EventEmitter();
    }
    deleteCheckboxDialog(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.checkboxDeleteEvent.emit(controlIndex);
            }
        });
    }
    editCheckboxDialog(control, controlIndex) {
        const dialogRef = this.dialog.open(AswCheckboxDialog, {
            disableClose: true,
            width: '744px',
            data: control
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.checkboxUpdateEvent.emit({ control: result, index: controlIndex });
            }
        });
    }
}
AswCheckbox.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswCheckbox, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
AswCheckbox.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: AswCheckbox, selector: "asw-checkbox", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { checkboxUpdateEvent: "checkboxUpdateEvent", checkboxDeleteEvent: "checkboxDeleteEvent" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n    <mat-label>{{control.label}}</mat-label>\r\n    <div *ngFor=\"let option of control.options\">\r\n        <mat-checkbox color=\"primary\" \r\n                    [name]=\"control.name\"\r\n                    [matTooltip]=\"option.value\"\r\n                    [(ngModel)]=\"option.isChecked\"\r\n                    [required]=\"control.isRequired\">\r\n            {{option.value}}\r\n        </mat-checkbox>\r\n    </div>\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 checkbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editCheckboxDialog(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 mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Remove checkbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteCheckboxDialog(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>\r\n", components: [{ type: i2.MatCheckbox, selector: "mat-checkbox", inputs: ["disableRipple", "color", "tabIndex", "aria-label", "aria-labelledby", "aria-describedby", "id", "required", "labelPosition", "name", "value", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4.MatLabel, selector: "mat-label" }, { type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.MatCheckboxRequiredValidator, selector: "mat-checkbox[required][formControlName],             mat-checkbox[required][formControl], mat-checkbox[required][ngModel]" }, { type: i5.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i6.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i6.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: i6.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswCheckbox, decorators: [{
            type: Component,
            args: [{ selector: 'asw-checkbox', template: "<ng-container *ngIf=\"control as control\">\r\n    <mat-label>{{control.label}}</mat-label>\r\n    <div *ngFor=\"let option of control.options\">\r\n        <mat-checkbox color=\"primary\" \r\n                    [name]=\"control.name\"\r\n                    [matTooltip]=\"option.value\"\r\n                    [(ngModel)]=\"option.isChecked\"\r\n                    [required]=\"control.isRequired\">\r\n            {{option.value}}\r\n        </mat-checkbox>\r\n    </div>\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 checkbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editCheckboxDialog(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 mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Remove checkbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteCheckboxDialog(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>\r\n" }]
        }], ctorParameters: function () { return [{ type: i1.MatDialog }]; }, propDecorators: { control: [{
                type: Input
            }], controlIndex: [{
                type: Input
            }], isPreviewTemplate: [{
                type: Input
            }], checkboxUpdateEvent: [{
                type: Output
            }], checkboxDeleteEvent: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 