/**
 * @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 { COMMA, ENTER } from '@angular/cdk/keycodes';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { CSSFrameworkEnum } from '@asoftwareworld/form-builder-pro/api';
import { Constants, Icons } from '@asoftwareworld/form-builder-pro/common';
import { AswConfirmDialog } from '@asoftwareworld/form-builder-pro/form-control/confirm-dialog';
import { AswTextDialog } from '@asoftwareworld/form-builder-pro/form-control/shared';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "@angular/common";
import * as i3 from "@angular/material/button";
import * as i4 from "@angular/material/form-field";
import * as i5 from "@angular/material/tooltip";
import * as i6 from "@angular/material/chips";
import * as i7 from "@angular/material/icon";
import * as i8 from "@asoftwareworld/form-builder-pro/core";
import * as i9 from "@asoftwareworld/form-builder-pro/common";
export class AswTags {
    dialog;
    addOnBlur = true;
    constants = Constants;
    icons = Icons;
    separatorKeysCodes = [ENTER, COMMA];
    /**
     * tags control
     */
    control;
    propertyPersonalization = [];
    isPreviewTemplate = false;
    CSSFramework = CSSFrameworkEnum.Material;
    patterns = [];
    tagsUpdateEvent = new EventEmitter();
    tagsDeleteEvent = new EventEmitter();
    selectionChange = new EventEmitter();
    duplicateControl = new EventEmitter();
    constructor(dialog) {
        this.dialog = dialog;
    }
    addTags(event) {
        const value = (event.value || '').trim();
        // Add our fruit
        if (value) {
            this.control.value.push(value);
        }
        // Clear the input value
        event?.chipInput?.clear();
    }
    removeTags(value) {
        const index = this.control.value.indexOf(value);
        if (index >= 0) {
            this.control.value.splice(index, 1);
        }
    }
    /**
     * Delete tags control based on control index
     * @param control tags control items
     */
    deleteTagsDialog(control) {
        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.tagsDeleteEvent.emit(control);
            }
        });
    }
    editTagsDialog(control) {
        const dialogRef = this.dialog.open(AswTextDialog, {
            width: '80%',
            disableClose: true,
            data: { control, CSSFramework: this.CSSFramework, propertyPersonalization: this.propertyPersonalization }
        });
        dialogRef.afterClosed().subscribe((result) => {
            if (result !== undefined) {
                this.tagsUpdateEvent.emit(result);
            }
        });
    }
    duplicateTagsControl(control) {
        this.duplicateControl.emit(control);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: AswTags, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: AswTags, selector: "asw-tags", inputs: { control: "control", propertyPersonalization: "propertyPersonalization", isPreviewTemplate: "isPreviewTemplate", CSSFramework: "CSSFramework", patterns: "patterns" }, outputs: { tagsUpdateEvent: "tagsUpdateEvent", tagsDeleteEvent: "tagsDeleteEvent", selectionChange: "selectionChange", duplicateControl: "duplicateControl" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n    <ng-container *ngIf=\"CSSFramework === 'material'; else bootstrap\">\r\n        <mat-form-field [appearance]=\"control.style\" class=\"asw-width-100 {{control.customClass}}\">\r\n            <mat-label>{{control.label}}</mat-label>\r\n            <mat-chip-grid #tagList aria-label=\"Fruit selection\">\r\n                <mat-chip-row\r\n                    *ngFor=\"let v of control.value\"\r\n                    (removed)=\"removeTags(v)\">\r\n                    {{v}}\r\n                    <button matChipRemove>\r\n                        <mat-icon>cancel</mat-icon>\r\n                    </button>\r\n                </mat-chip-row>\r\n                <input\r\n                    [placeholder]=\"control.label\"\r\n                    [id]=\"control.id\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [required]=\"control.isRequired\"\r\n                    [disabled]=\"control.isDisabled ? true : false\"\r\n                    [matChipInputFor]=\"tagList\"\r\n                    [matChipInputAddOnBlur]=\"addOnBlur\"\r\n                    [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n                    (matChipInputTokenEnd)=\"addTags($event)\">\r\n            </mat-chip-grid>\r\n            <!-- <mat-error *ngIf=\"inputTags.invalid && (inputTags.dirty || inputTags.touched)\">\r\n                <mat-error *ngIf=\"inputTags?.errors?.required\">\r\n                    {{control.label}} {{'FormControl.IsRequired' | aswTranslate}}\r\n                </mat-error>\r\n            </mat-error> -->\r\n        </mat-form-field>\r\n    </ng-container>\r\n    <ng-template #bootstrap>\r\n        <div class=\"asw-mb-3\">\r\n            <label for=\"{{control.id}}\" \r\n            class=\"asw-input-label \"\r\n            [class.asw-invalid-label]=\"control.isRequired\">{{control.label}}</label>\r\n            <mat-chip-grid #tagList aria-label=\"Fruit selection\">\r\n                <mat-chip-row\r\n                    *ngFor=\"let v of control.value\"\r\n                    (removed)=\"removeTags(v)\">\r\n                    {{v}}\r\n                    <button matChipRemove>\r\n                        <mat-icon>cancel</mat-icon>\r\n                    </button>\r\n                </mat-chip-row>\r\n                <input\r\n                    [placeholder]=\"control.label\"\r\n                    [id]=\"control.id\"\r\n                    class=\"asw-input-control\" \r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [required]=\"control.isRequired\"\r\n                    [disabled]=\"control.isDisabled ? true : false\"\r\n                    [matChipInputFor]=\"tagList\"\r\n                    [matChipInputAddOnBlur]=\"addOnBlur\"\r\n                    [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n                    (matChipInputTokenEnd)=\"addTags($event)\">\r\n            </mat-chip-grid>\r\n            <!-- <mat-error *ngIf=\"inputTags.invalid && (inputTags.dirty || inputTags.touched)\">\r\n                <mat-error *ngIf=\"inputTags?.errors?.required\">\r\n                    {{control.label}} {{'FormControl.IsRequired' | aswTranslate}}\r\n                </mat-error>\r\n            </mat-error> -->\r\n        </div>\r\n    </ng-template>\r\n    <div class=\"asw-row\" *ngIf=\"isPreviewTemplate\">\r\n        <div class=\"asw-col-md-12\" align=\"right\">\r\n            <button mat-icon-button\r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Duplicate' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\"\r\n                    (click)=\"duplicateTagsControl(control)\">\r\n                <div [innerHTML]=\"icons.contentCopy | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Edit' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"editTagsDialog(control)\">\r\n                <div [innerHTML]=\"icons.edit | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"deleteTagsDialog(control)\">\r\n                <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n            </button>\r\n        </div>\r\n    </div>\r\n</ng-container>", dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.MatIconButton, selector: "button[mat-icon-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i4.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i4.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "component", type: i6.MatChipGrid, selector: "mat-chip-grid", inputs: ["tabIndex", "disabled", "placeholder", "required", "value", "errorStateMatcher"], outputs: ["change", "valueChange"] }, { kind: "directive", type: i6.MatChipInput, selector: "input[matChipInputFor]", inputs: ["matChipInputFor", "matChipInputAddOnBlur", "matChipInputSeparatorKeyCodes", "placeholder", "id", "disabled"], outputs: ["matChipInputTokenEnd"], exportAs: ["matChipInput", "matChipInputFor"] }, { kind: "directive", type: i6.MatChipRemove, selector: "[matChipRemove]" }, { kind: "component", type: i6.MatChipRow, selector: "mat-chip-row, [mat-chip-row], mat-basic-chip-row, [mat-basic-chip-row]", inputs: ["color", "disabled", "disableRipple", "tabIndex", "editable"], outputs: ["edited"] }, { kind: "component", type: i7.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "pipe", type: i8.AswTranslatePipe, name: "aswTranslate" }, { kind: "pipe", type: i9.AswSafeHtmlPipe, name: "aswSafeHtml" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: AswTags, decorators: [{
            type: Component,
            args: [{ selector: 'asw-tags', template: "<ng-container *ngIf=\"control as control\">\r\n    <ng-container *ngIf=\"CSSFramework === 'material'; else bootstrap\">\r\n        <mat-form-field [appearance]=\"control.style\" class=\"asw-width-100 {{control.customClass}}\">\r\n            <mat-label>{{control.label}}</mat-label>\r\n            <mat-chip-grid #tagList aria-label=\"Fruit selection\">\r\n                <mat-chip-row\r\n                    *ngFor=\"let v of control.value\"\r\n                    (removed)=\"removeTags(v)\">\r\n                    {{v}}\r\n                    <button matChipRemove>\r\n                        <mat-icon>cancel</mat-icon>\r\n                    </button>\r\n                </mat-chip-row>\r\n                <input\r\n                    [placeholder]=\"control.label\"\r\n                    [id]=\"control.id\"\r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [required]=\"control.isRequired\"\r\n                    [disabled]=\"control.isDisabled ? true : false\"\r\n                    [matChipInputFor]=\"tagList\"\r\n                    [matChipInputAddOnBlur]=\"addOnBlur\"\r\n                    [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n                    (matChipInputTokenEnd)=\"addTags($event)\">\r\n            </mat-chip-grid>\r\n            <!-- <mat-error *ngIf=\"inputTags.invalid && (inputTags.dirty || inputTags.touched)\">\r\n                <mat-error *ngIf=\"inputTags?.errors?.required\">\r\n                    {{control.label}} {{'FormControl.IsRequired' | aswTranslate}}\r\n                </mat-error>\r\n            </mat-error> -->\r\n        </mat-form-field>\r\n    </ng-container>\r\n    <ng-template #bootstrap>\r\n        <div class=\"asw-mb-3\">\r\n            <label for=\"{{control.id}}\" \r\n            class=\"asw-input-label \"\r\n            [class.asw-invalid-label]=\"control.isRequired\">{{control.label}}</label>\r\n            <mat-chip-grid #tagList aria-label=\"Fruit selection\">\r\n                <mat-chip-row\r\n                    *ngFor=\"let v of control.value\"\r\n                    (removed)=\"removeTags(v)\">\r\n                    {{v}}\r\n                    <button matChipRemove>\r\n                        <mat-icon>cancel</mat-icon>\r\n                    </button>\r\n                </mat-chip-row>\r\n                <input\r\n                    [placeholder]=\"control.label\"\r\n                    [id]=\"control.id\"\r\n                    class=\"asw-input-control\" \r\n                    [matTooltip]=\"control.tooltip\"\r\n                    [required]=\"control.isRequired\"\r\n                    [disabled]=\"control.isDisabled ? true : false\"\r\n                    [matChipInputFor]=\"tagList\"\r\n                    [matChipInputAddOnBlur]=\"addOnBlur\"\r\n                    [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n                    (matChipInputTokenEnd)=\"addTags($event)\">\r\n            </mat-chip-grid>\r\n            <!-- <mat-error *ngIf=\"inputTags.invalid && (inputTags.dirty || inputTags.touched)\">\r\n                <mat-error *ngIf=\"inputTags?.errors?.required\">\r\n                    {{control.label}} {{'FormControl.IsRequired' | aswTranslate}}\r\n                </mat-error>\r\n            </mat-error> -->\r\n        </div>\r\n    </ng-template>\r\n    <div class=\"asw-row\" *ngIf=\"isPreviewTemplate\">\r\n        <div class=\"asw-col-md-12\" align=\"right\">\r\n            <button mat-icon-button\r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Duplicate' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\"\r\n                    (click)=\"duplicateTagsControl(control)\">\r\n                <div [innerHTML]=\"icons.contentCopy | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Edit' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"editTagsDialog(control)\">\r\n                <div [innerHTML]=\"icons.edit | aswSafeHtml\"></div>\r\n            </button>\r\n            <button mat-icon-button \r\n                    type=\"button\" \r\n                    matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n                    [matTooltipPosition]=\"'below'\" \r\n                    (click)=\"deleteTagsDialog(control)\">\r\n                <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n            </button>\r\n        </div>\r\n    </div>\r\n</ng-container>" }]
        }], ctorParameters: function () { return [{ type: i1.MatDialog }]; }, propDecorators: { control: [{
                type: Input
            }], propertyPersonalization: [{
                type: Input
            }], isPreviewTemplate: [{
                type: Input
            }], CSSFramework: [{
                type: Input
            }], patterns: [{
                type: Input
            }], tagsUpdateEvent: [{
                type: Output
            }], tagsDeleteEvent: [{
                type: Output
            }], selectionChange: [{
                type: Output
            }], duplicateControl: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 