/* eslint-disable @angular-eslint/no-output-on-prefix */
import { ChangeDetectorRef, Component, EventEmitter, inject, input, Output, ViewChild, ViewEncapsulation, } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { InputMaskDirective } from '@seniorsistemas/angular-components/input-mask';
import { FormFieldUtilsService } from '../../../services/form-field-utils.service';
import { FieldLabelComponent } from '../../../components/field-label/field-label.component';
import { TooltipModule } from '@seniorsistemas/angular-components/tooltip';
import { ButtonComponent } from '@seniorsistemas/angular-components/button';
import { NgClass, NgStyle, NgTemplateOutlet } from '@angular/common';
import { KeyFilterModule } from 'primeng/keyfilter';
import { InputText } from 'primeng/inputtext';
import * as i0 from "@angular/core";
import * as i1 from "@seniorsistemas/angular-components/tooltip";
import * as i2 from "@angular/forms";
import * as i3 from "primeng/keyfilter";
export class TextFieldComponent {
    changeDetectorRef = inject(ChangeDetectorRef);
    field = input.required();
    formControl = input.required();
    fieldUtils = inject(FormFieldUtilsService);
    onInput = new EventEmitter();
    onFocus = new EventEmitter();
    onComplete = new EventEmitter();
    inputRef = null;
    ngUnsubscribe = new Subject();
    ngOnInit() {
        this.fieldUtils.switchEmptyStringToNull(this.formControl(), this.ngUnsubscribe);
        const field = this.field();
        this.onFocus.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (field.onFocus) {
                field.onFocus(event);
            }
        });
        this.onInput.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (field.onInput) {
                field.onInput(event);
            }
        });
        this.onComplete.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (field.onComplete) {
                field.onComplete(event);
            }
        });
    }
    ngAfterViewInit() {
        this.changeDetectorRef.detectChanges();
    }
    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
    get inputElement() {
        return this.inputRef?.nativeElement;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: TextFieldComponent, isStandalone: true, selector: "ng-component", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: true, transformFunction: null }, formControl: { classPropertyName: "formControl", publicName: "formControl", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { onInput: "onInput", onFocus: "onFocus", onComplete: "onComplete" }, viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["inputRef"], descendants: true }], ngImport: i0, template: "@let _field = field();\n\n@if (inputElement) {\n    <s-field-label\n        [field]=\"_field\"\n        [fieldContainerRef]=\"inputElement\"\n    />\n}\n\n@if (_field.mask) {\n    <input\n        #inputRef\n        pInputText\n        class=\"input-text mousetrap\"\n        [sInputMask]=\"fieldUtils.getFieldPropertyMask(_field.mask)\"\n        [characterPattern]=\"fieldUtils.getFieldProperty(_field.characterPattern ?? '[A-Za-z]')\"\n        [unmask]=\"fieldUtils.getFieldProperty(_field.unmask ?? false)\"\n        slotChar=\"_\"\n        [type]=\"_field.inputType || 'text'\"\n        [id]=\"_field.id || _field.name\"\n        [name]=\"_field.name\"\n        [placeholder]=\"_field.placeholder ?? ''\"\n        [sTooltip]=\"_field.tooltip\"\n        tooltipPosition=\"top\"\n        [showDelay]=\"500\"\n        [autocomplete]=\"_field.browserAutocomplete ? 'on' : 'off'\"\n        [readOnly]=\"_field.readonly ? _field.readonly() : false\"\n        [formControl]=\"formControl()\"\n        (blur)=\"_field.onBlur ? _field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (maskComplete)=\"onComplete.next($event)\"\n        (input)=\"onInput.next($event)\"\n    />\n} @else {\n    <div class=\"text-field\">\n        @if (_field.leftAddon) {\n            <div class=\"button-left\">\n                <ng-container *ngTemplateOutlet=\"addonRender; context: { button: _field.leftAddon }\"></ng-container>\n            </div>\n        }\n\n        <ng-container *ngTemplateOutlet=\"_field.keyFilter ? inputKeyFilter : input\"></ng-container>\n\n        @if (_field.rightAddon) {\n            <div class=\"button-right\">\n                <ng-container *ngTemplateOutlet=\"addonRender; context: { button: _field.rightAddon }\"></ng-container>\n            </div>\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 ?? 9999999\"\n        pInputText\n        class=\"input-text\"\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 ?? 9999999\"\n        pInputText\n        [autocomplete]=\"_field.browserAutocomplete ? 'on' : 'off'\"\n        class=\"input-text\"\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\n<ng-template\n    #addonRender\n    let-button=\"button\"\n>\n    <s-button\n        [label]=\"button.label\"\n        [priority]=\"button.priority ?? 'default'\"\n        [iconClass]=\"button.icon\"\n        [disabled]=\"fieldUtils.fieldPropertyIsDisabled(button.leftAddon)\"\n        [auxiliary]=\"false\"\n        (clicked)=\"button.callback?.()\"\n    />\n</ng-template>\n\n", styles: ["s-text-field.ng-dirty.ng-invalid .p-inputtext{border-color:#c13018}s-text-field.ng-dirty.ng-invalid .p-inputtext:hover{border-color:highlight(#c13018)}.text-field{display:flex;width:100%}.text-field .input-text{width:auto;flex-grow:1}.text-field:has(.button-left) .input-text{border-top-left-radius:0;border-bottom-left-radius:0}.text-field:has(.button-left) .button-left button{border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}.text-field:has(input:focus) .button-left button{border-color:#428bca!important}.text-field:has(input.ng-invalid.ng-dirty) .button-left button{border-color:#c13018!important}.text-field:has(.button-right) .input-text{border-top-right-radius:0;border-bottom-right-radius:0}.text-field:has(.button-right) .button-right button{border-top-left-radius:0;border-bottom-left-radius:0;border-left:none}.text-field:has(input:focus) .button-right button{border-color:#428bca!important}.text-field:has(input.ng-invalid.ng-dirty) .button-right button{border-color:#c13018!important}\n"], dependencies: [{ kind: "component", type: FieldLabelComponent, selector: "s-field-label", inputs: ["field", "fieldContainerRef"] }, { kind: "directive", type: InputMaskDirective, selector: "input[sInputMask]", inputs: ["sInputMask", "slotChar", "unmask", "characterPattern", "autoClear"], outputs: ["maskComplete"] }, { kind: "ngmodule", type: TooltipModule }, { kind: "directive", type: i1.TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "component", type: ButtonComponent, selector: "s-button", inputs: ["id", "label", "tooltip", "tooltipPosition", "iconClass", "rightIconClass", "caret", "styleClass", "baseZIndex", "disabled", "auxiliary", "type", "priority", "menuOptions", "size", "slide", "animation", "badge", "iconColor", "menuAriaLabel", "ariaLabel"], outputs: ["clicked"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.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: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "ngmodule", type: KeyFilterModule }, { kind: "directive", type: i3.KeyFilter, selector: "[pKeyFilter]", inputs: ["pValidateOnly", "pKeyFilter"], outputs: ["ngModelChange"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: InputText, selector: "[pInputText]", inputs: ["variant", "fluid", "pSize"] }], 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, standalone: true, imports: [
                        FieldLabelComponent,
                        InputMaskDirective,
                        TooltipModule,
                        ButtonComponent,
                        ReactiveFormsModule,
                        NgClass,
                        KeyFilterModule,
                        NgStyle,
                        NgTemplateOutlet,
                        InputText,
                    ], template: "@let _field = field();\n\n@if (inputElement) {\n    <s-field-label\n        [field]=\"_field\"\n        [fieldContainerRef]=\"inputElement\"\n    />\n}\n\n@if (_field.mask) {\n    <input\n        #inputRef\n        pInputText\n        class=\"input-text mousetrap\"\n        [sInputMask]=\"fieldUtils.getFieldPropertyMask(_field.mask)\"\n        [characterPattern]=\"fieldUtils.getFieldProperty(_field.characterPattern ?? '[A-Za-z]')\"\n        [unmask]=\"fieldUtils.getFieldProperty(_field.unmask ?? false)\"\n        slotChar=\"_\"\n        [type]=\"_field.inputType || 'text'\"\n        [id]=\"_field.id || _field.name\"\n        [name]=\"_field.name\"\n        [placeholder]=\"_field.placeholder ?? ''\"\n        [sTooltip]=\"_field.tooltip\"\n        tooltipPosition=\"top\"\n        [showDelay]=\"500\"\n        [autocomplete]=\"_field.browserAutocomplete ? 'on' : 'off'\"\n        [readOnly]=\"_field.readonly ? _field.readonly() : false\"\n        [formControl]=\"formControl()\"\n        (blur)=\"_field.onBlur ? _field.onBlur($event) : null\"\n        (focus)=\"onFocus.next($event)\"\n        (maskComplete)=\"onComplete.next($event)\"\n        (input)=\"onInput.next($event)\"\n    />\n} @else {\n    <div class=\"text-field\">\n        @if (_field.leftAddon) {\n            <div class=\"button-left\">\n                <ng-container *ngTemplateOutlet=\"addonRender; context: { button: _field.leftAddon }\"></ng-container>\n            </div>\n        }\n\n        <ng-container *ngTemplateOutlet=\"_field.keyFilter ? inputKeyFilter : input\"></ng-container>\n\n        @if (_field.rightAddon) {\n            <div class=\"button-right\">\n                <ng-container *ngTemplateOutlet=\"addonRender; context: { button: _field.rightAddon }\"></ng-container>\n            </div>\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 ?? 9999999\"\n        pInputText\n        class=\"input-text\"\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 ?? 9999999\"\n        pInputText\n        [autocomplete]=\"_field.browserAutocomplete ? 'on' : 'off'\"\n        class=\"input-text\"\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\n<ng-template\n    #addonRender\n    let-button=\"button\"\n>\n    <s-button\n        [label]=\"button.label\"\n        [priority]=\"button.priority ?? 'default'\"\n        [iconClass]=\"button.icon\"\n        [disabled]=\"fieldUtils.fieldPropertyIsDisabled(button.leftAddon)\"\n        [auxiliary]=\"false\"\n        (clicked)=\"button.callback?.()\"\n    />\n</ng-template>\n\n", styles: ["s-text-field.ng-dirty.ng-invalid .p-inputtext{border-color:#c13018}s-text-field.ng-dirty.ng-invalid .p-inputtext:hover{border-color:highlight(#c13018)}.text-field{display:flex;width:100%}.text-field .input-text{width:auto;flex-grow:1}.text-field:has(.button-left) .input-text{border-top-left-radius:0;border-bottom-left-radius:0}.text-field:has(.button-left) .button-left button{border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}.text-field:has(input:focus) .button-left button{border-color:#428bca!important}.text-field:has(input.ng-invalid.ng-dirty) .button-left button{border-color:#c13018!important}.text-field:has(.button-right) .input-text{border-top-right-radius:0;border-bottom-right-radius:0}.text-field:has(.button-right) .button-right button{border-top-left-radius:0;border-bottom-left-radius:0;border-left:none}.text-field:has(input:focus) .button-right button{border-color:#428bca!important}.text-field:has(input.ng-invalid.ng-dirty) .button-right button{border-color:#c13018!important}\n"] }]
        }], propDecorators: { onInput: [{
                type: Output
            }], onFocus: [{
                type: Output
            }], onComplete: [{
                type: Output
            }], inputRef: [{
                type: ViewChild,
                args: ['inputRef']
            }] } });
//# sourceMappingURL=data:application/json;base64, 