/* eslint-disable @angular-eslint/no-output-on-prefix */
import { Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation, } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { BaseFieldComponent } from '../base-field-component';
import { InputMask } from 'primeng/inputmask';
import * as i0 from "@angular/core";
import * as i1 from "@seniorsistemas/angular-components/button";
import * as i2 from "@angular/common";
import * as i3 from "@angular/forms";
import * as i4 from "primeng/inputmask";
import * as i5 from "primeng/inputtext";
import * as i6 from "primeng/keyfilter";
import * as i7 from "@seniorsistemas/angular-components/tooltip";
import * as i8 from "../../../components/field-label/field-label.component";
export class TextFieldComponent extends BaseFieldComponent {
    changeDetectorRef;
    field;
    formControl;
    onInput = new EventEmitter();
    onFocus = new EventEmitter();
    onComplete = new EventEmitter();
    inputRef = null;
    ngUnsubscribe = new Subject();
    constructor(changeDetectorRef) {
        super();
        this.changeDetectorRef = changeDetectorRef;
    }
    ngOnInit() {
        this.onFocus.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (this.field.onFocus)
                this.field.onFocus(event);
        });
        this.onInput.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (this.field.onInput)
                this.field.onInput(event);
        });
        this.onComplete.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (this.field.onComplete)
                this.field.onComplete(event);
        });
    }
    ngAfterViewInit() {
        this.changeDetectorRef.detectChanges();
    }
    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
    getCharacterPattern() {
        return typeof this.field.characterPattern === 'function'
            ? this.field.characterPattern()
            : this.field.characterPattern;
    }
    getUnmask() {
        return typeof this.field.unmask === 'function' ? this.field.unmask() : this.field.unmask;
    }
    get inputElement() {
        if (this.inputRef instanceof InputMask) {
            return this.inputRef?.inputViewChild?.nativeElement;
        }
        else {
            return this.inputRef?.nativeElement;
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextFieldComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: TextFieldComponent, selector: "ng-component", inputs: { field: "field", formControl: "formControl" }, outputs: { onInput: "onInput", onFocus: "onFocus", onComplete: "onComplete" }, viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["inputRef"], descendants: true }], usesInheritance: true, ngImport: i0, template: "@if (inputElement) {\n    <s-field-label\n        [field]=\"field\"\n        [fieldContainerRef]=\"inputElement\"\n    />\n}\n\n@if (field.mask) {\n    <p-inputMask\n        #inputRef\n        [type]=\"field.inputType || 'text'\"\n        [inputId]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [mask]=\"isFunction(field.mask) ? field.mask() : field.mask\"\n        [characterPattern]=\"getCharacterPattern()\"\n        [unmask]=\"getUnmask()\"\n        [placeholder]=\"field.placeholder\"\n        slotChar=\"_\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [showDelay]=\"500\"\n        styleClass=\"mousetrap\"\n        (onBlur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (onFocus)=\"onFocus.next($event)\"\n        (onComplete)=\"onComplete.next($event)\"\n        (onInput)=\"onInput.next($event)\"\n        [formControl]=\"formControl\"\n        [readonly]=\"field.readonly ? field.readonly() : false\"\n        [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n\n    >\n    </p-inputMask>\n} @else {\n    <div class=\"ui-inputgroup\">\n        @if (field.leftAddon) {\n            @if (field.leftAddon.callback) {\n                <span class=\"addon-button addon-button--left\">\n                    <s-button\n                        [label]=\"field.leftAddon.label\"\n                        [iconClass]=\"field.leftAddon.icon\"\n                        [priority]=\"field.leftAddon.priority\"\n                        [disabled]=\"fieldPropertyIsDisabled(field.leftAddon)\"\n                        (clicked)=\"field.leftAddon.callback()\"\n                    >\n                    </s-button>\n                </span>\n            }\n            @if (!field.leftAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.leftAddon.label) {\n                        <span>{{ field.leftAddon.label }}</span>\n                    } @else if (!field.leftAddon.label) {\n                        <span [ngClass]=\"field.leftAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n\n        <ng-container *ngTemplateOutlet=\"field.keyFilter ? inputKeyFilter : input\"></ng-container>\n\n        @if (field.rightAddon) {\n            @if (field.rightAddon.callback) {\n                <s-button\n                    [label]=\"field.rightAddon.label\"\n                    [iconClass]=\"field.rightAddon.icon\"\n                    [priority]=\"field.rightAddon.priority\"\n                    [disabled]=\"fieldPropertyIsDisabled(field.rightAddon)\"\n                    (clicked)=\"field.rightAddon.callback()\"\n                >\n                </s-button>\n            } @else if (field.rightAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.rightAddon.label) {\n                        <span>{{ field.rightAddon.label }}</span>\n                    } @else if (!field.rightAddon.label) {\n                        <span [ngClass]=\"field.rightAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n    </div>\n}\n<ng-template #input>\n    <input\n        #inputRef\n        [type]=\"field.inputType || 'text'\"\n        [id]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [placeholder]=\"field.placeholder\"\n        [showDelay]=\"500\"\n        [maxLength]=\"field.maxLength\"\n        pInputText\n        [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n        [ngClass]=\"'mousetrap'\"\n        (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (input)=\"onInput.next($event)\"\n        [formControl]=\"formControl\"\n        [ngStyle]=\"field.style\"\n        [readOnly]=\"field.readonly ? field.readonly() : false\"\n    />\n</ng-template>\n<ng-template #inputKeyFilter>\n    <input\n        #inputText\n        [type]=\"field.inputType || 'text'\"\n        [id]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [placeholder]=\"field.placeholder\"\n        [showDelay]=\"500\"\n        [maxLength]=\"field.maxLength\"\n        pInputText\n        [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n        [ngClass]=\"'mousetrap'\"\n        (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (input)=\"onInput.next($event)\"\n        [pKeyFilter]=\"field.keyFilter\"\n        [formControl]=\"formControl\"\n        [ngStyle]=\"field.style\"\n        [readOnly]=\"field.readonly ? field.readonly() : false\"\n    />\n</ng-template>\n", styles: ["s-text-field.ng-dirty.ng-invalid .ui-inputtext{border-color:#c13018}s-text-field.ng-dirty.ng-invalid .ui-inputtext:hover{border-color:highlight(#c13018)}.addon-button{border:1px solid #c1c1cc}.addon-button s-button button,.addon-button s-button .s-button-with-text{height:100%;min-width:40px}.addon-button--left{border-radius:5px 0 0 5px;border-right:none}.addon-button--left s-button button{border-bottom-right-radius:0;border-top-right-radius:0}.addon-button--right{border-left:none;border-radius:0 5px 5px 0}.addon-button--right s-button button{border-bottom-left-radius:0;border-top-left-radius:0}\n"], dependencies: [{ kind: "component", type: i1.ButtonComponent, selector: "s-button", inputs: ["id", "label", "tooltip", "tooltipPosition", "iconClass", "rightIconClass", "caret", "styleClass", "baseZIndex", "disabled", "auxiliary", "type", "priority", "menuOptions", "size", "slide", "animation", "badge", "iconColor"], outputs: ["clicked"] }, { kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "component", type: i4.InputMask, selector: "p-inputmask, p-inputMask, p-input-mask", inputs: ["type", "slotChar", "autoClear", "showClear", "style", "inputId", "styleClass", "placeholder", "size", "maxlength", "tabindex", "title", "variant", "ariaLabel", "ariaLabelledBy", "ariaRequired", "disabled", "readonly", "unmask", "name", "required", "characterPattern", "autofocus", "autoFocus", "autocomplete", "keepBuffer", "mask"], outputs: ["onComplete", "onFocus", "onBlur", "onInput", "onKeydown", "onClear"] }, { kind: "directive", type: i5.InputText, selector: "[pInputText]", inputs: ["variant", "fluid", "pSize"] }, { kind: "directive", type: i6.KeyFilter, selector: "[pKeyFilter]", inputs: ["pValidateOnly", "pKeyFilter"], outputs: ["ngModelChange"] }, { kind: "directive", type: i3.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i7.TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "component", type: i8.FieldLabelComponent, selector: "s-field-label", inputs: ["field", "fieldContainerRef"] }], encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextFieldComponent, decorators: [{
            type: Component,
            args: [{ encapsulation: ViewEncapsulation.None, template: "@if (inputElement) {\n    <s-field-label\n        [field]=\"field\"\n        [fieldContainerRef]=\"inputElement\"\n    />\n}\n\n@if (field.mask) {\n    <p-inputMask\n        #inputRef\n        [type]=\"field.inputType || 'text'\"\n        [inputId]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [mask]=\"isFunction(field.mask) ? field.mask() : field.mask\"\n        [characterPattern]=\"getCharacterPattern()\"\n        [unmask]=\"getUnmask()\"\n        [placeholder]=\"field.placeholder\"\n        slotChar=\"_\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [showDelay]=\"500\"\n        styleClass=\"mousetrap\"\n        (onBlur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (onFocus)=\"onFocus.next($event)\"\n        (onComplete)=\"onComplete.next($event)\"\n        (onInput)=\"onInput.next($event)\"\n        [formControl]=\"formControl\"\n        [readonly]=\"field.readonly ? field.readonly() : false\"\n        [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n\n    >\n    </p-inputMask>\n} @else {\n    <div class=\"ui-inputgroup\">\n        @if (field.leftAddon) {\n            @if (field.leftAddon.callback) {\n                <span class=\"addon-button addon-button--left\">\n                    <s-button\n                        [label]=\"field.leftAddon.label\"\n                        [iconClass]=\"field.leftAddon.icon\"\n                        [priority]=\"field.leftAddon.priority\"\n                        [disabled]=\"fieldPropertyIsDisabled(field.leftAddon)\"\n                        (clicked)=\"field.leftAddon.callback()\"\n                    >\n                    </s-button>\n                </span>\n            }\n            @if (!field.leftAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.leftAddon.label) {\n                        <span>{{ field.leftAddon.label }}</span>\n                    } @else if (!field.leftAddon.label) {\n                        <span [ngClass]=\"field.leftAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n\n        <ng-container *ngTemplateOutlet=\"field.keyFilter ? inputKeyFilter : input\"></ng-container>\n\n        @if (field.rightAddon) {\n            @if (field.rightAddon.callback) {\n                <s-button\n                    [label]=\"field.rightAddon.label\"\n                    [iconClass]=\"field.rightAddon.icon\"\n                    [priority]=\"field.rightAddon.priority\"\n                    [disabled]=\"fieldPropertyIsDisabled(field.rightAddon)\"\n                    (clicked)=\"field.rightAddon.callback()\"\n                >\n                </s-button>\n            } @else if (field.rightAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.rightAddon.label) {\n                        <span>{{ field.rightAddon.label }}</span>\n                    } @else if (!field.rightAddon.label) {\n                        <span [ngClass]=\"field.rightAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n    </div>\n}\n<ng-template #input>\n    <input\n        #inputRef\n        [type]=\"field.inputType || 'text'\"\n        [id]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [placeholder]=\"field.placeholder\"\n        [showDelay]=\"500\"\n        [maxLength]=\"field.maxLength\"\n        pInputText\n        [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n        [ngClass]=\"'mousetrap'\"\n        (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (input)=\"onInput.next($event)\"\n        [formControl]=\"formControl\"\n        [ngStyle]=\"field.style\"\n        [readOnly]=\"field.readonly ? field.readonly() : false\"\n    />\n</ng-template>\n<ng-template #inputKeyFilter>\n    <input\n        #inputText\n        [type]=\"field.inputType || 'text'\"\n        [id]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [placeholder]=\"field.placeholder\"\n        [showDelay]=\"500\"\n        [maxLength]=\"field.maxLength\"\n        pInputText\n        [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n        [ngClass]=\"'mousetrap'\"\n        (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (input)=\"onInput.next($event)\"\n        [pKeyFilter]=\"field.keyFilter\"\n        [formControl]=\"formControl\"\n        [ngStyle]=\"field.style\"\n        [readOnly]=\"field.readonly ? field.readonly() : false\"\n    />\n</ng-template>\n", styles: ["s-text-field.ng-dirty.ng-invalid .ui-inputtext{border-color:#c13018}s-text-field.ng-dirty.ng-invalid .ui-inputtext:hover{border-color:highlight(#c13018)}.addon-button{border:1px solid #c1c1cc}.addon-button s-button button,.addon-button s-button .s-button-with-text{height:100%;min-width:40px}.addon-button--left{border-radius:5px 0 0 5px;border-right:none}.addon-button--left s-button button{border-bottom-right-radius:0;border-top-right-radius:0}.addon-button--right{border-left:none;border-radius:0 5px 5px 0}.addon-button--right s-button button{border-bottom-left-radius:0;border-top-left-radius:0}\n"] }]
        }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { field: [{
                type: Input,
                args: [{ required: true }]
            }], formControl: [{
                type: Input,
                args: [{ required: true }]
            }], onInput: [{
                type: Output
            }], onFocus: [{
                type: Output
            }], onComplete: [{
                type: Output
            }], inputRef: [{
                type: ViewChild,
                args: ['inputRef']
            }] } });
//# sourceMappingURL=data:application/json;base64, 