/**
 * @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 { AswTextboxDialog } from './textbox-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/common";
import * as i4 from "@angular/material/input";
import * as i5 from "@angular/forms";
import * as i6 from "@angular/material/tooltip";
export class AswTextbox {
    constructor(dialog) {
        this.dialog = dialog;
        this.constants = Constants;
        /**
         * Textbox control
         */
        this.control = null;
        this.isPreviewTemplate = false;
        this.textboxUpdateEvent = new EventEmitter();
        this.textboxDeleteEvent = new EventEmitter();
    }
    deleteTextboxDialog(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.textboxDeleteEvent.emit(controlIndex);
            }
        });
    }
    editTextboxDialog(control, controlIndex) {
        const dialogRef = this.dialog.open(AswTextboxDialog, {
            disableClose: true,
            width: '744px',
            data: control
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.textboxUpdateEvent.emit({ control: result, index: controlIndex });
            }
        });
    }
}
AswTextbox.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswTextbox, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
AswTextbox.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.4", type: AswTextbox, selector: "asw-textbox", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { textboxUpdateEvent: "textboxUpdateEvent", textboxDeleteEvent: "textboxDeleteEvent" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n    <mat-form-field hintLabel=\"Max {{control.maxlength}} characters\" [appearance]=\"control.style\" class=\"asw-mat-form-field\">\r\n        <mat-label>{{control.label}}</mat-label>\r\n        <input matInput type=\"text\"\r\n                        name=\"control.name\"\r\n                        [placeholder]=\"control.label\"\r\n                        [(ngModel)]=\"control.value\"                    \r\n                        #input=\"ngModel\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        [maxlength]=\"control.maxlength\"\r\n                        [minlength]=\"control.minlength\"\r\n                        [required]=\"control.isRequired\">\r\n        <mat-hint align=\"end\">{{input.value?.length || 0}}/{{control.maxlength}}</mat-hint>\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 class=\"asw-mat-error\" *ngIf=\"input?.errors?.minlength\">\r\n                Sorry, {{control.label}} must be at least {{control.minlength}} characters long.\r\n            </mat-error>\r\n        </mat-error>\r\n    </mat-form-field>\r\n    <ng-template [ngIf]=\"isPreviewTemplate\">\r\n        <div class=\"row mb-2\">\r\n            <div class=\"col-md-12\">\r\n                <button mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Edit textbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editTextboxDialog(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 textbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteTextboxDialog(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"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i4.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: i5.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: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i5.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: i6.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i5.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { type: i5.MinLengthValidator, selector: "[minlength][formControlName],[minlength][formControl],[minlength][ngModel]", inputs: ["minlength"] }, { type: i5.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { type: i2.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { type: i2.MatError, selector: "mat-error", inputs: ["id"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswTextbox, decorators: [{
            type: Component,
            args: [{ selector: 'asw-textbox', template: "<ng-container *ngIf=\"control as control\">\r\n    <mat-form-field hintLabel=\"Max {{control.maxlength}} characters\" [appearance]=\"control.style\" class=\"asw-mat-form-field\">\r\n        <mat-label>{{control.label}}</mat-label>\r\n        <input matInput type=\"text\"\r\n                        name=\"control.name\"\r\n                        [placeholder]=\"control.label\"\r\n                        [(ngModel)]=\"control.value\"                    \r\n                        #input=\"ngModel\"\r\n                        [matTooltip]=\"control.tooltip\"\r\n                        [maxlength]=\"control.maxlength\"\r\n                        [minlength]=\"control.minlength\"\r\n                        [required]=\"control.isRequired\">\r\n        <mat-hint align=\"end\">{{input.value?.length || 0}}/{{control.maxlength}}</mat-hint>\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 class=\"asw-mat-error\" *ngIf=\"input?.errors?.minlength\">\r\n                Sorry, {{control.label}} must be at least {{control.minlength}} characters long.\r\n            </mat-error>\r\n        </mat-error>\r\n    </mat-form-field>\r\n    <ng-template [ngIf]=\"isPreviewTemplate\">\r\n        <div class=\"row mb-2\">\r\n            <div class=\"col-md-12\">\r\n                <button mat-raised-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Edit textbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"editTextboxDialog(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 textbox control\" \r\n                        [matTooltipPosition]=\"'above'\" \r\n                        (click)=\"deleteTextboxDialog(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
            }], textboxUpdateEvent: [{
                type: Output
            }], textboxDeleteEvent: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 