/**
 * @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 { AswDatepickerDialog } from './datepicker-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/datepicker";
import * as i4 from "@angular/common";
import * as i5 from "@angular/material/input";
import * as i6 from "@angular/forms";
import * as i7 from "@angular/material/tooltip";
export class AswDatepicker {
    constructor(dialog) {
        this.dialog = dialog;
        this.constants = Constants;
        /**
         * Datepicker control
         */
        this.control = null;
        this.isPreviewTemplate = false;
        this.datepickerUpdateEvent = new EventEmitter();
        this.datepickerDeleteEvent = new EventEmitter();
    }
    /**
     * Delete datepicker control based on control index
     * @param control datepicker control items
     * @param controlIndex datepicker control index
     */
    deleteDatepickerDialog(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.datepickerDeleteEvent.emit(controlIndex);
            }
        });
    }
    editDatepickerDialog(control, controlIndex) {
        const dialogRef = this.dialog.open(AswDatepickerDialog, {
            disableClose: true,
            width: '744px',
            data: control
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.datepickerUpdateEvent.emit({ control: result, index: controlIndex });
            }
        });
    }
}
AswDatepicker.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswDatepicker, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
AswDatepicker.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.4", type: AswDatepicker, selector: "asw-datepicker", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { datepickerUpdateEvent: "datepickerUpdateEvent", datepickerDeleteEvent: "datepickerDeleteEvent" }, 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        <input matInput [matDatepicker]=\"picker\" \r\n                        #input=\"ngModel\"\r\n                        [(ngModel)]=\"control.value\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        [placeholder]=\"control.label\" \r\n                        [required]=\"control.isRequired\">\r\n        <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n        <mat-datepicker #picker></mat-datepicker>\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    <div class=\"row\" *ngIf=\"isPreviewTemplate\">\r\n        <div class=\"col-md-12\">\r\n            <button mat-raised-button \r\n                    type=\"button\" \r\n                    matTooltip=\"Edit datepicker control\" \r\n                    [matTooltipPosition]=\"'above'\" \r\n                    (click)=\"editDatepickerDialog(control, controlIndex)\"\r\n                    class=\"asw-btn btn btn-sm btn-just-icon 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 datepicker control\" \r\n                    [matTooltipPosition]=\"'above'\" \r\n                    (click)=\"deleteDatepickerDialog(control, controlIndex)\"\r\n                    class=\"asw-btn btn btn-sm btn-just-icon 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-container>", components: [{ type: i2.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { type: i3.MatDatepickerToggle, selector: "mat-datepicker-toggle", inputs: ["for", "tabIndex", "aria-label", "disabled", "disableRipple"], exportAs: ["matDatepickerToggle"] }, { type: i3.MatDatepicker, selector: "mat-datepicker", exportAs: ["matDatepicker"] }], directives: [{ type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { type: i3.MatDatepickerInput, selector: "input[matDatepicker]", inputs: ["matDatepicker", "min", "max", "matDatepickerFilter"], exportAs: ["matDatepickerInput"] }, { type: i6.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { 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: i7.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i6.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { type: i2.MatSuffix, selector: "[matSuffix]" }, { type: i2.MatError, selector: "mat-error", inputs: ["id"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswDatepicker, decorators: [{
            type: Component,
            args: [{ selector: 'asw-datepicker', 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        <input matInput [matDatepicker]=\"picker\" \r\n                        #input=\"ngModel\"\r\n                        [(ngModel)]=\"control.value\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        [placeholder]=\"control.label\" \r\n                        [required]=\"control.isRequired\">\r\n        <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n        <mat-datepicker #picker></mat-datepicker>\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    <div class=\"row\" *ngIf=\"isPreviewTemplate\">\r\n        <div class=\"col-md-12\">\r\n            <button mat-raised-button \r\n                    type=\"button\" \r\n                    matTooltip=\"Edit datepicker control\" \r\n                    [matTooltipPosition]=\"'above'\" \r\n                    (click)=\"editDatepickerDialog(control, controlIndex)\"\r\n                    class=\"asw-btn btn btn-sm btn-just-icon 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 datepicker control\" \r\n                    [matTooltipPosition]=\"'above'\" \r\n                    (click)=\"deleteDatepickerDialog(control, controlIndex)\"\r\n                    class=\"asw-btn btn btn-sm btn-just-icon 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-container>" }]
        }], ctorParameters: function () { return [{ type: i1.MatDialog }]; }, propDecorators: { control: [{
                type: Input
            }], controlIndex: [{
                type: Input
            }], isPreviewTemplate: [{
                type: Input
            }], datepickerUpdateEvent: [{
                type: Output
            }], datepickerDeleteEvent: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 