/**
 * @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 { AswTextFieldDialog } from './textfield-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/button";
import * as i4 from "@angular/material/icon";
import * as i5 from "@angular/common";
import * as i6 from "@angular/material/input";
import * as i7 from "@angular/forms";
import * as i8 from "@angular/material/tooltip";
export class AswTextField {
    constructor(dialog) {
        this.dialog = dialog;
        this.constants = Constants;
        /**
         * TextField control
         */
        this.control = null;
        this.isPreviewTemplate = false;
        this.textFieldUpdateEvent = new EventEmitter();
        this.textFieldDeleteEvent = new EventEmitter();
        this.aswModelChange = new EventEmitter();
        this.duplicateControl = new EventEmitter();
    }
    deleteTextFieldDialog(control, controlIndex) {
        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.textFieldDeleteEvent.emit(controlIndex);
            }
        });
    }
    editTextFieldDialog(control, controlIndex) {
        const dialogRef = this.dialog.open(AswTextFieldDialog, {
            disableClose: true,
            width: '744px',
            data: control
        });
        dialogRef.afterClosed().subscribe(result => {
            if (result !== undefined) {
                this.textFieldUpdateEvent.emit({ control: result, index: controlIndex });
            }
        });
    }
    onChange(control) {
        this.aswModelChange.emit(control);
    }
    duplicateTextFieldControl(control) {
        this.duplicateControl.emit(control);
    }
}
AswTextField.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.4", ngImport: i0, type: AswTextField, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
AswTextField.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.4", type: AswTextField, selector: "asw-textfield", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { textFieldUpdateEvent: "textFieldUpdateEvent", textFieldDeleteEvent: "textFieldDeleteEvent", aswModelChange: "aswModelChange", duplicateControl: "duplicateControl" }, 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 {{control.customClass}}\">\r\n        <mat-label>{{control.label}}</mat-label>\r\n        <input matInput type=\"text\"\r\n                        [id]=\"control.id\"\r\n                        pattern=\"{{control.pattern}}\"\r\n                        [placeholder]=\"control.label\"\r\n                        [(ngModel)]=\"control.value\"                    \r\n                        #input=\"ngModel\"\r\n                        (change)=\"onChange(control)\"\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 class=\"asw-mat-error\" *ngIf=\"input?.errors?.pattern\">\r\n                {{control.customErrorMsg}}\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-icon-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Duplicate\" \r\n                        [matTooltipPosition]=\"'below'\" \r\n                        (click)=\"duplicateTextFieldControl(control)\">\r\n                    <mat-icon>content_copy</mat-icon>\r\n                </button>\r\n                <button mat-icon-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Edit\" \r\n                        [matTooltipPosition]=\"'below'\" \r\n                        (click)=\"editTextFieldDialog(control, controlIndex)\">\r\n                    <mat-icon>edit</mat-icon>\r\n                </button>\r\n                <button mat-icon-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Delete\" \r\n                        [matTooltipPosition]=\"'below'\" \r\n                        (click)=\"deleteTextFieldDialog(control, controlIndex)\">\r\n                    <mat-icon>delete</mat-icon>\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.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], directives: [{ type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i6.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: i7.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: i7.PatternValidator, selector: "[pattern][formControlName],[pattern][formControl],[pattern][ngModel]", inputs: ["pattern"] }, { 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: i8.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i7.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { type: i7.MinLengthValidator, selector: "[minlength][formControlName],[minlength][formControl],[minlength][ngModel]", inputs: ["minlength"] }, { type: i7.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: AswTextField, decorators: [{
            type: Component,
            args: [{ selector: 'asw-textfield', 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 {{control.customClass}}\">\r\n        <mat-label>{{control.label}}</mat-label>\r\n        <input matInput type=\"text\"\r\n                        [id]=\"control.id\"\r\n                        pattern=\"{{control.pattern}}\"\r\n                        [placeholder]=\"control.label\"\r\n                        [(ngModel)]=\"control.value\"                    \r\n                        #input=\"ngModel\"\r\n                        (change)=\"onChange(control)\"\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 class=\"asw-mat-error\" *ngIf=\"input?.errors?.pattern\">\r\n                {{control.customErrorMsg}}\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-icon-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Duplicate\" \r\n                        [matTooltipPosition]=\"'below'\" \r\n                        (click)=\"duplicateTextFieldControl(control)\">\r\n                    <mat-icon>content_copy</mat-icon>\r\n                </button>\r\n                <button mat-icon-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Edit\" \r\n                        [matTooltipPosition]=\"'below'\" \r\n                        (click)=\"editTextFieldDialog(control, controlIndex)\">\r\n                    <mat-icon>edit</mat-icon>\r\n                </button>\r\n                <button mat-icon-button \r\n                        type=\"button\" \r\n                        matTooltip=\"Delete\" \r\n                        [matTooltipPosition]=\"'below'\" \r\n                        (click)=\"deleteTextFieldDialog(control, controlIndex)\">\r\n                    <mat-icon>delete</mat-icon>\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
            }], textFieldUpdateEvent: [{
                type: Output
            }], textFieldDeleteEvent: [{
                type: Output
            }], aswModelChange: [{
                type: Output
            }], duplicateControl: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 