import * as i0 from '@angular/core';
import { inject, ChangeDetectorRef, forwardRef, ElementRef, Component, ViewChild, Input, NgModule } from '@angular/core';
import * as i1 from '@angular/forms';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { KeyFilter } from 'primeng/keyfilter';
import { NgStyle } from '@angular/common';
import { SpeechRecognitionComponent } from '@seniorsistemas/angular-components/speech-recognition';

/**
 * @description Componente de área de texto com suporte a reconhecimento de voz,
 * filtro de teclas, comprimento máximo e integração com `ControlValueAccessor`.
 * Renderiza condicionalmente o componente `SpeechRecognitionComponent` quando
 * a flag `speechRecognition` está ativa.
 *
 * @example
 * ```html
 * <s-textarea
 *   formControlName="descricao"
 *   [rows]="6"
 *   [maxLength]="500"
 *   placeholder="Digite aqui..." />
 * ```
 *
 * @category Inputs
 */
class TextAreaComponent {
    cdr = inject(ChangeDetectorRef);
    onChange = () => { };
    onTouched = () => { };
    disabled = false;
    value = '';
    _textAreaElement;
    get textAreaElement() {
        return this._textAreaElement;
    }
    set textAreaElement(value) {
        this._textAreaElement = value;
        setTimeout(() => {
            this.renderTextArea = true;
            this.cdr.detectChanges();
        });
    }
    /** @description Identificador do elemento `<textarea>` no DOM. @default 'textarea-{random}' */
    inputId = `textarea-${Math.random()}`;
    /** @description Número de linhas visíveis no textarea. @default 5 */
    rows = 5;
    /** @description Habilita o botão de reconhecimento de voz. @default false */
    speechRecognition = false;
    /** @description Filtro de teclas aceitas, usando padrão ou expressão regular. */
    keyFilter;
    /** @description Quando `true`, mantém o contexto ao reiniciar o reconhecimento de voz. @default false */
    keepContext = false;
    /** @description Placeholder exibido durante o reconhecimento de voz. @default '' */
    speechRecognitionPlaceholder = '';
    /** @description Número máximo de caracteres aceitos. @default null (ilimitado) */
    maxLength = null;
    /** @description Texto exibido quando o campo está vazio. */
    placeholder;
    _inputStyle = {
        resize: 'vertical',
    };
    /** @description Estilos inline aplicados ao elemento `<textarea>` interno. @default `{ resize: 'vertical' }` */
    get inputStyle() {
        return this._inputStyle;
    }
    set inputStyle(value) {
        this._inputStyle = {
            ...value,
            ...this._inputStyle,
        };
    }
    /** @description Coloca o textarea em modo somente leitura. @default false */
    readOnly = false;
    renderTextArea = false;
    writeValue(obj) {
        this.value = obj;
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(isDisabled) {
        this.disabled = isDisabled;
    }
    setValue(value) {
        if (this.disabled) {
            return;
        }
        this.value = value.toString();
        this.writeValue(this.value);
        this.onChange(this.value);
        this.onTouched(this.value);
    }
    handleRecognizedText(recognizedText) {
        this.setValue(recognizedText);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: TextAreaComponent, isStandalone: true, selector: "s-textarea", inputs: { inputId: "inputId", rows: "rows", speechRecognition: "speechRecognition", keyFilter: "keyFilter", keepContext: "keepContext", speechRecognitionPlaceholder: "speechRecognitionPlaceholder", maxLength: "maxLength", placeholder: "placeholder", inputStyle: "inputStyle", readOnly: "readOnly" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => TextAreaComponent),
                multi: true,
            },
        ], viewQueries: [{ propertyName: "textAreaElement", first: true, predicate: ["textArea"], descendants: true, read: ElementRef }], ngImport: i0, template: "@if (keyFilter) {\r\n    <textarea\r\n        #textArea\r\n        class=\"textarea\"\r\n        [pKeyFilter]=\"keyFilter\"\r\n        [id]=\"inputId\"\r\n        [rows]=\"rows\"\r\n        [ngModel]=\"value\"\r\n        (ngModelChange)=\"setValue($event)\"\r\n        [disabled]=\"disabled\"\r\n        [ngStyle]=\"inputStyle\"\r\n        [readOnly]=\"readOnly\"\r\n        [maxlength]=\"maxLength\"\r\n        [placeholder]=\"placeholder ? placeholder : ''\"\r\n    ></textarea>\r\n}\r\n\r\n@if (!keyFilter) {\r\n    <textarea\r\n        #textArea\r\n        class=\"textarea\"\r\n        [id]=\"inputId\"\r\n        [rows]=\"rows\"\r\n        [(ngModel)]=\"value\"\r\n        [disabled]=\"disabled\"\r\n        [ngStyle]=\"inputStyle\"\r\n        [readOnly]=\"readOnly\"\r\n        [maxlength]=\"maxLength\"\r\n        [placeholder]=\"placeholder ? placeholder : ''\"\r\n        (ngModelChange)=\"setValue($event)\"\r\n    ></textarea>\r\n}\r\n\r\n@if (speechRecognition && renderTextArea) {\r\n    <s-speech-recognition\r\n        [textAreaElement]=\"textAreaElement.nativeElement\"\r\n        [keepContext]=\"keepContext\"\r\n        [speechRecognitionPlaceholder]=\"speechRecognitionPlaceholder\"\r\n        (recognizedText)=\"handleRecognizedText($event)\"\r\n    >\r\n    </s-speech-recognition>\r\n}\r\n", styles: [".textarea{border-radius:3px;border:1px solid #c1c1cc;background:#fff;width:100%;max-width:100%;min-height:4em;min-width:10em;outline:none;padding:8px;display:block}.textarea:disabled{opacity:.5}.textarea:focus{transition:border-color .2s ease-out;border:1px solid #428bca}:host.ng-invalid.ng-dirty .textarea{border-color:#c13018}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.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: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: KeyFilter, selector: "[pKeyFilter]", inputs: ["pValidateOnly", "pKeyFilter"], outputs: ["ngModelChange"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: SpeechRecognitionComponent, selector: "s-speech-recognition", inputs: ["textAreaElement", "keepContext", "speechRecognitionPlaceholder"], outputs: ["recognizedText"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-textarea', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => TextAreaComponent),
                            multi: true,
                        },
                    ], standalone: true, imports: [FormsModule, KeyFilter, NgStyle, SpeechRecognitionComponent], template: "@if (keyFilter) {\r\n    <textarea\r\n        #textArea\r\n        class=\"textarea\"\r\n        [pKeyFilter]=\"keyFilter\"\r\n        [id]=\"inputId\"\r\n        [rows]=\"rows\"\r\n        [ngModel]=\"value\"\r\n        (ngModelChange)=\"setValue($event)\"\r\n        [disabled]=\"disabled\"\r\n        [ngStyle]=\"inputStyle\"\r\n        [readOnly]=\"readOnly\"\r\n        [maxlength]=\"maxLength\"\r\n        [placeholder]=\"placeholder ? placeholder : ''\"\r\n    ></textarea>\r\n}\r\n\r\n@if (!keyFilter) {\r\n    <textarea\r\n        #textArea\r\n        class=\"textarea\"\r\n        [id]=\"inputId\"\r\n        [rows]=\"rows\"\r\n        [(ngModel)]=\"value\"\r\n        [disabled]=\"disabled\"\r\n        [ngStyle]=\"inputStyle\"\r\n        [readOnly]=\"readOnly\"\r\n        [maxlength]=\"maxLength\"\r\n        [placeholder]=\"placeholder ? placeholder : ''\"\r\n        (ngModelChange)=\"setValue($event)\"\r\n    ></textarea>\r\n}\r\n\r\n@if (speechRecognition && renderTextArea) {\r\n    <s-speech-recognition\r\n        [textAreaElement]=\"textAreaElement.nativeElement\"\r\n        [keepContext]=\"keepContext\"\r\n        [speechRecognitionPlaceholder]=\"speechRecognitionPlaceholder\"\r\n        (recognizedText)=\"handleRecognizedText($event)\"\r\n    >\r\n    </s-speech-recognition>\r\n}\r\n", styles: [".textarea{border-radius:3px;border:1px solid #c1c1cc;background:#fff;width:100%;max-width:100%;min-height:4em;min-width:10em;outline:none;padding:8px;display:block}.textarea:disabled{opacity:.5}.textarea:focus{transition:border-color .2s ease-out;border:1px solid #428bca}:host.ng-invalid.ng-dirty .textarea{border-color:#c13018}\n"] }]
        }], propDecorators: { textAreaElement: [{
                type: ViewChild,
                args: ['textArea', { read: ElementRef }]
            }], inputId: [{
                type: Input
            }], rows: [{
                type: Input
            }], speechRecognition: [{
                type: Input
            }], keyFilter: [{
                type: Input
            }], keepContext: [{
                type: Input
            }], speechRecognitionPlaceholder: [{
                type: Input
            }], maxLength: [{
                type: Input
            }], placeholder: [{
                type: Input
            }], inputStyle: [{
                type: Input
            }], readOnly: [{
                type: Input
            }] } });

class TextAreaModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: TextAreaModule, imports: [TextAreaComponent], exports: [TextAreaComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaModule, imports: [TextAreaComponent] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [TextAreaComponent],
                    exports: [TextAreaComponent],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { TextAreaComponent, TextAreaModule };
//# sourceMappingURL=seniorsistemas-angular-components-text-area.mjs.map
