import * as i0 from '@angular/core';
import { inject, ChangeDetectorRef, forwardRef, ElementRef, Component, ViewChild, Input, NgModule } from '@angular/core';
import * as i2 from '@angular/forms';
import { NG_VALUE_ACCESSOR, FormsModule, ReactiveFormsModule } from '@angular/forms';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@seniorsistemas/angular-components/speech-recognition';
import { SpeechRecognitionModule } from '@seniorsistemas/angular-components/speech-recognition';
import * as i4 from 'primeng/keyfilter';
import { KeyFilterModule } from 'primeng/keyfilter';

/**
 * @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: "14.0.0", version: "18.2.14", type: TextAreaComponent, 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: "<textarea\n    *ngIf=\"keyFilter\"\n    #textArea\n    class=\"textarea\"\n    [pKeyFilter]=\"keyFilter\"\n    [id]=\"inputId\"\n    [rows]=\"rows\"\n    [ngModel]=\"value\"\n    (ngModelChange)=\"setValue($event)\"\n    [disabled]=\"disabled\"\n    [ngStyle]=\"inputStyle\"\n    [readOnly]=\"readOnly\"\n    [maxlength]=\"maxLength\"\n    [placeholder]=\"placeholder ? placeholder : ''\"\n></textarea>\n\n<textarea\n    *ngIf=\"!keyFilter\"\n    #textArea\n    class=\"textarea\"\n    [id]=\"inputId\"\n    [rows]=\"rows\"\n    [(ngModel)]=\"value\"\n    [disabled]=\"disabled\"\n    [ngStyle]=\"inputStyle\"\n    [readOnly]=\"readOnly\"\n    [maxlength]=\"maxLength\"\n    [placeholder]=\"placeholder ? placeholder : ''\"\n    (ngModelChange)=\"setValue($event)\"\n></textarea>\n\n<s-speech-recognition\n    *ngIf=\"speechRecognition && renderTextArea\"\n    [textAreaElement]=\"textAreaElement.nativeElement\"\n    [keepContext]=\"keepContext\"\n    [speechRecognitionPlaceholder]=\"speechRecognitionPlaceholder\"\n    (recognizedText)=\"handleRecognizedText($event)\"\n>\n</s-speech-recognition>\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: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { 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.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i3.SpeechRecognitionComponent, selector: "s-speech-recognition", inputs: ["textAreaElement", "keepContext", "speechRecognitionPlaceholder"], outputs: ["recognizedText"] }, { kind: "directive", type: i4.KeyFilter, selector: "[pKeyFilter]", inputs: ["pValidateOnly", "pKeyFilter"], outputs: ["ngModelChange"] }] });
}
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,
                        },
                    ], template: "<textarea\n    *ngIf=\"keyFilter\"\n    #textArea\n    class=\"textarea\"\n    [pKeyFilter]=\"keyFilter\"\n    [id]=\"inputId\"\n    [rows]=\"rows\"\n    [ngModel]=\"value\"\n    (ngModelChange)=\"setValue($event)\"\n    [disabled]=\"disabled\"\n    [ngStyle]=\"inputStyle\"\n    [readOnly]=\"readOnly\"\n    [maxlength]=\"maxLength\"\n    [placeholder]=\"placeholder ? placeholder : ''\"\n></textarea>\n\n<textarea\n    *ngIf=\"!keyFilter\"\n    #textArea\n    class=\"textarea\"\n    [id]=\"inputId\"\n    [rows]=\"rows\"\n    [(ngModel)]=\"value\"\n    [disabled]=\"disabled\"\n    [ngStyle]=\"inputStyle\"\n    [readOnly]=\"readOnly\"\n    [maxlength]=\"maxLength\"\n    [placeholder]=\"placeholder ? placeholder : ''\"\n    (ngModelChange)=\"setValue($event)\"\n></textarea>\n\n<s-speech-recognition\n    *ngIf=\"speechRecognition && renderTextArea\"\n    [textAreaElement]=\"textAreaElement.nativeElement\"\n    [keepContext]=\"keepContext\"\n    [speechRecognitionPlaceholder]=\"speechRecognitionPlaceholder\"\n    (recognizedText)=\"handleRecognizedText($event)\"\n>\n</s-speech-recognition>\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, declarations: [TextAreaComponent], imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            SpeechRecognitionModule,
            KeyFilterModule], exports: [TextAreaComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaModule, imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            SpeechRecognitionModule,
            KeyFilterModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: TextAreaModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [TextAreaComponent],
                    imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        SpeechRecognitionModule,
                        KeyFilterModule
                    ],
                    exports: [TextAreaComponent]
                }]
        }] });

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

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