import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { viewChild, contentChild, inject, ChangeDetectorRef, input, computed, booleanAttribute, model, output, effect, untracked, Component } from '@angular/core';
import * as i2 from '@angular/forms';
import { NgForm, FormGroup, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
import * as i3 from '@angular/material/form-field';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i5 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i4 from '@angular/material/input';
import { MatInputModule } from '@angular/material/input';
import * as i6 from '@angular/material/tooltip';
import { MatTooltipModule } from '@angular/material/tooltip';
import { SdViewDefDirective, SdLabelDefDirective, SdSuffixDefDirective } from '@sdcorejs/angular/forms/directives';
import { SD_FORM_CONFIGURATION, sdFormControlState, sdViewedTransform, sdViewedInline, SdFormControl, SdInlineErrorValidator } from '@sdcorejs/angular/forms/models';
import { sdIsEmpty, sdSerializeDataValue } from '@sdcorejs/angular/utilities/data-state';
import { NumberUtilities } from '@sdcorejs/angular/utilities/extensions';
import { Subscription } from 'rxjs';
import * as uuid from 'uuid';
import { SdLabel } from '@sdcorejs/angular/forms/label';
import { I18nService, TranslatePipe } from '@sdcorejs/angular/i18n';
import { SdEmptyPipe } from '@sdcorejs/angular/pipes';

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @angular-eslint/no-input-rename */
class SdTextarea {
    id = `I${uuid.v4()}`;
    // ==========================================
    // 1. SIGNAL QUERIES
    // ==========================================
    textareaRef = viewChild('textarea', ...(ngDevMode ? [{ debugName: "textareaRef" }] : []));
    sdViewDef = contentChild(SdViewDefDirective, ...(ngDevMode ? [{ debugName: "sdViewDef" }] : []));
    sdLabelDef = contentChild(SdLabelDefDirective, ...(ngDevMode ? [{ debugName: "sdLabelDef" }] : []));
    sdSuffixDef = contentChild(SdSuffixDefDirective, ...(ngDevMode ? [{ debugName: "sdSuffixDef" }] : []));
    // ==========================================
    // 2. INJECTS
    // ==========================================
    #ref = inject(ChangeDetectorRef);
    #formConfiguration = inject(SD_FORM_CONFIGURATION, { optional: true });
    #i18n = inject(I18nService);
    // ==========================================
    // 3. SIGNAL INPUTS & MODEL
    // ==========================================
    autoIdInput = input(undefined, ...(ngDevMode ? [{ debugName: "autoIdInput", alias: 'autoId' }] : [{ alias: 'autoId' }]));
    autoId = computed(() => this.autoIdInput() ? `forms-textarea-${this.autoIdInput()}` : undefined, ...(ngDevMode ? [{ debugName: "autoId" }] : []));
    #state = sdFormControlState(computed(() => this.formControl));
    dataDisabled = computed(() => (this.#state().disabled ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataDisabled" }] : []));
    dataInvalid = computed(() => (this.#state().invalid ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataInvalid" }] : []));
    dataEmpty = computed(() => (sdIsEmpty(this.#state().value) ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataEmpty" }] : []));
    dataValue = computed(() => sdSerializeDataValue(this.#state().value), ...(ngDevMode ? [{ debugName: "dataValue" }] : []));
    dataRequired = computed(() => (this.required() ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataRequired" }] : []));
    dataMaxLength = computed(() => {
        const v = this.maxlength();
        return v == null ? null : String(v);
    }, ...(ngDevMode ? [{ debugName: "dataMaxLength" }] : []));
    dataPattern = computed(() => {
        const v = this.pattern();
        return v == null || v === '' ? null : String(v);
    }, ...(ngDevMode ? [{ debugName: "dataPattern" }] : []));
    dataErrorMessage = computed(() => {
        void this.#state();
        const msg = this.errorMessage();
        return msg && msg.length > 0 ? msg : null;
    }, ...(ngDevMode ? [{ debugName: "dataErrorMessage" }] : []));
    name = input(uuid.v4(), ...(ngDevMode ? [{ debugName: "name" }] : []));
    size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : []));
    // Ghi (TransformT): any (để không bị lỗi typing khi cha truyền vào)
    form = input(undefined, ...(ngDevMode ? [{ debugName: "form", transform: (val) => {
                if (!val)
                    return undefined;
                // Nếu cha truyền vào NgForm (template-driven) -> Bóc lấy FormGroup bên trong
                if (val instanceof NgForm)
                    return val.form;
                // Nếu cha truyền sẵn FormGroup (reactive) -> Lấy luôn
                if (val instanceof FormGroup)
                    return val;
                // Fallback an toàn phòng trường hợp cha truyền 1 object chứa form
                if (val?.form instanceof FormGroup)
                    return val.form;
                return undefined;
            } }] : [{
            transform: (val) => {
                if (!val)
                    return undefined;
                // Nếu cha truyền vào NgForm (template-driven) -> Bóc lấy FormGroup bên trong
                if (val instanceof NgForm)
                    return val.form;
                // Nếu cha truyền sẵn FormGroup (reactive) -> Lấy luôn
                if (val instanceof FormGroup)
                    return val;
                // Fallback an toàn phòng trường hợp cha truyền 1 object chứa form
                if (val?.form instanceof FormGroup)
                    return val.form;
                return undefined;
            },
        }]));
    label = input(undefined, ...(ngDevMode ? [{ debugName: "label", transform: (v) => v ?? undefined }] : [{
            transform: (v) => v ?? undefined,
        }]));
    helperText = input(undefined, ...(ngDevMode ? [{ debugName: "helperText", transform: (v) => v ?? undefined }] : [{
            transform: (v) => v ?? undefined,
        }]));
    placeholder = input(undefined, ...(ngDevMode ? [{ debugName: "placeholder", transform: (v) => v ?? undefined }] : [{
            transform: (v) => v ?? undefined,
        }]));
    rows = input(5, ...(ngDevMode ? [{ debugName: "rows" }] : []));
    hideInlineError = input(false, ...(ngDevMode ? [{ debugName: "hideInlineError", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
    required = input(false, ...(ngDevMode ? [{ debugName: "required", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
    disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
    /** Display mode: `false` edit · `true` static view · `'inline'` borderless inline-edit (textarea reads like text). */
    viewed = input(false, ...(ngDevMode ? [{ debugName: "viewed", transform: sdViewedTransform }] : [{ transform: sdViewedTransform }]));
    autoHeight = input(false, ...(ngDevMode ? [{ debugName: "autoHeight", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
    // Tri-state `viewed` — shared primitive. No panel; in `'inline'` the textarea renders borderless.
    // why: disabled 'inline' falls back to static view (cannot edit a disabled control).
    #viewedState = sdViewedInline(this.viewed, () => this.textareaRef()?.nativeElement?.focus(), this.disabled);
    /** `true` when `viewed === 'inline'`. */
    isInline = this.#viewedState.isInline;
    /** `true` when `viewed === true` (static view, no editor). */
    isViewed = this.#viewedState.isViewed;
    /** Focus the inline textarea. No-op unless `viewed='inline'`. */
    enterInlineEdit = () => this.#viewedState.enterInlineEdit();
    maxlength = input(null, ...(ngDevMode ? [{ debugName: "maxlength", transform: (v) => (v != null && NumberUtilities.isPositiveInteger(Number(v))) ? Number(v) : null }] : [{
            transform: (v) => (v != null && NumberUtilities.isPositiveInteger(Number(v))) ? Number(v) : null
        }]));
    pattern = input(undefined, ...(ngDevMode ? [{ debugName: "pattern", transform: (v) => v ?? undefined }] : [{
            transform: (v) => v ?? undefined,
        }]));
    validator = input(...(ngDevMode ? [undefined, { debugName: "validator" }] : []));
    inlineError = input(undefined, ...(ngDevMode ? [{ debugName: "inlineError", transform: (v) => v ?? undefined }] : [{
            transform: (v) => v ?? undefined,
        }]));
    /**
     * Tổng hợp error message để hiển thị trong tooltip khi hideInlineError = true.
     */
    errorMessage = computed(() => {
        void this.#state();
        const errors = this.formControl.errors;
        if (!errors)
            return undefined;
        if (errors['required'])
            return this.#i18n.t('core.form.textarea.required');
        if (errors['maxlength'])
            return this.#i18n.t('core.form.textarea.maxlength', { max: this.maxlength() ?? '' });
        if (errors['pattern'])
            return this.#i18n.t('core.form.textarea.invalid-pattern');
        if (errors['customValidator'])
            return errors['customValidator'];
        if (errors['inlineError'])
            return this.inlineError();
        return undefined;
    }, ...(ngDevMode ? [{ debugName: "errorMessage" }] : []));
    appearanceInput = input(undefined, ...(ngDevMode ? [{ debugName: "appearanceInput", alias: 'appearance' }] : [{ alias: 'appearance' }]));
    appearance = computed(() => this.appearanceInput() ?? this.#formConfiguration?.appearance ?? 'outline', ...(ngDevMode ? [{ debugName: "appearance" }] : []));
    floatLabel = input('auto', ...(ngDevMode ? [{ debugName: "floatLabel" }] : []));
    valueModel = model(undefined, ...(ngDevMode ? [{ debugName: "valueModel", alias: 'model' }] : [{ alias: 'model' }]));
    // ==========================================
    // 4. SIGNAL OUTPUTS
    // ==========================================
    sdChange = output();
    // ==========================================
    // 5. INTERNAL STATE & STREAMS
    // ==========================================
    formControl = new SdFormControl();
    #subscription = new Subscription();
    isFocused = false;
    constructor() {
        // EFFECT 1: Sync model thay đổi từ bên ngoài
        effect(() => {
            const val = this.valueModel();
            untracked(() => {
                if (this.formControl.value !== val) {
                    this.formControl.setValue(val, { emitEvent: false });
                    // [IMPROVE] Cập nhật chiều cao khi value đổi từ bên ngoài
                    if (this.autoHeight())
                        this.#adjustHeight();
                }
            });
        });
        // EFFECT 2: Sync Disable
        effect(() => {
            if (this.disabled())
                this.formControl.disable({ emitEvent: false });
            else
                this.formControl.enable({ emitEvent: false });
        });
        // EFFECT 3: Update Validators
        effect(() => {
            const req = this.required();
            const maxLen = this.maxlength();
            const pat = this.pattern();
            const val = this.validator();
            const inl = this.inlineError();
            untracked(() => this.#updateValidator(req, maxLen, pat, val, inl));
        });
    }
    ngOnInit() {
        this.#subscription.add(this.formControl.sdChanges.subscribe(() => this.#ref.markForCheck()));
        this.#subscription.add(this.formControl.valueChanges.subscribe(this.#onChange));
        const formGroup = this.form();
        formGroup?.addControl(this.name(), this.formControl);
    }
    ngAfterViewInit() {
        if (this.autoHeight()) {
            setTimeout(() => this.#adjustHeight(), 0);
        }
    }
    ngOnDestroy() {
        const formGroup = this.form();
        formGroup?.removeControl(this.name());
        this.#subscription.unsubscribe();
    }
    // Hàm private tính toán chiều cao mượt mà
    #adjustHeight() {
        const el = this.textareaRef()?.nativeElement;
        if (el) {
            el.style.height = 'auto';
            el.style.overflowY = 'hidden';
            el.style.height = `${el.scrollHeight}px`;
        }
    }
    onFocus = () => {
        this.isFocused = true;
    };
    onBlur = () => {
        this.isFocused = false;
        const val = (this.formControl.value ?? '').toString();
        if (val.length > val.trim().length) {
            this.formControl.setValue(val.trim());
        }
    };
    onClick = () => {
        if (this.sdViewDef()?.templateRef) {
            if (!this.formControl.disabled && !this.isFocused) {
                this.focus();
            }
        }
    };
    blur = () => {
        this.textareaRef()?.nativeElement?.blur();
    };
    focus = () => {
        this.isFocused = true;
        setTimeout(() => {
            this.textareaRef()?.nativeElement?.focus();
        }, 100);
    };
    #onChange = (value) => {
        if (this.autoHeight()) {
            this.#adjustHeight();
        }
        this.valueModel.set(value);
        this.sdChange.emit(value);
    };
    #updateValidator = (req, maxLen, pat, val, inl) => {
        this.formControl.clearValidators();
        this.formControl.clearAsyncValidators();
        const validators = [];
        const asyncValidators = [];
        if (req)
            validators.push(Validators.required);
        if (maxLen != null)
            validators.push(Validators.maxLength(maxLen));
        if (pat)
            validators.push(Validators.pattern(pat));
        if (val)
            asyncValidators.push(this.#customValidator(val));
        if (inl)
            validators.push(SdInlineErrorValidator);
        this.formControl.setValidators(validators.length ? validators : null);
        this.formControl.setAsyncValidators(asyncValidators.length ? asyncValidators : null);
        this.formControl.updateValueAndValidity({ emitEvent: false });
    };
    getCurrentLength = () => {
        return (this.formControl.value ?? '').toString().length;
    };
    isMaxlengthExceeded = () => {
        const max = this.maxlength();
        return !!(max && max > 0 && this.getCurrentLength() > max);
    };
    #customValidator = (func) => {
        return async (c) => {
            const value = c.value || null;
            if (func && typeof func === 'function') {
                const result = func(value);
                if (result instanceof Promise) {
                    const message = await result;
                    if (message)
                        return { customValidator: message };
                    return null;
                }
                if (result)
                    return { customValidator: result };
                return null;
            }
            return null;
        };
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.24", ngImport: i0, type: SdTextarea, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.24", type: SdTextarea, isStandalone: true, selector: "sd-textarea", inputs: { autoIdInput: { classPropertyName: "autoIdInput", publicName: "autoId", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, form: { classPropertyName: "form", publicName: "form", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, helperText: { classPropertyName: "helperText", publicName: "helperText", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, rows: { classPropertyName: "rows", publicName: "rows", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, viewed: { classPropertyName: "viewed", publicName: "viewed", isSignal: true, isRequired: false, transformFunction: null }, autoHeight: { classPropertyName: "autoHeight", publicName: "autoHeight", isSignal: true, isRequired: false, transformFunction: null }, maxlength: { classPropertyName: "maxlength", publicName: "maxlength", isSignal: true, isRequired: false, transformFunction: null }, pattern: { classPropertyName: "pattern", publicName: "pattern", isSignal: true, isRequired: false, transformFunction: null }, validator: { classPropertyName: "validator", publicName: "validator", isSignal: true, isRequired: false, transformFunction: null }, inlineError: { classPropertyName: "inlineError", publicName: "inlineError", isSignal: true, isRequired: false, transformFunction: null }, appearanceInput: { classPropertyName: "appearanceInput", publicName: "appearance", isSignal: true, isRequired: false, transformFunction: null }, floatLabel: { classPropertyName: "floatLabel", publicName: "floatLabel", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange" }, host: { properties: { "class.sd-has-label": "!!label()", "class.sd-viewed": "isViewed() || isInline()" } }, queries: [{ propertyName: "sdViewDef", first: true, predicate: SdViewDefDirective, descendants: true, isSignal: true }, { propertyName: "sdLabelDef", first: true, predicate: SdLabelDefDirective, descendants: true, isSignal: true }, { propertyName: "sdSuffixDef", first: true, predicate: SdSuffixDefDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "textareaRef", first: true, predicate: ["textarea"], descendants: true, isSignal: true }], ngImport: i0, template: "@let _label = label();\n@let _appearance = appearance();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage();\n@let _labelDef = sdLabelDef();\n@let _helperText = helperText();\n@let _required = required();\n@let _maxLength = maxlength();\n@let _isInline = isInline();\n\n@if (isViewed()) {\n  @if (_labelDef?.templateRef) {\n    <ng-container *ngTemplateOutlet=\"_labelDef!.templateRef\"> </ng-container>\n  } @else if (_label) {\n    <div class=\"T14R text-black400\">{{ _label }}</div>\n  }\n  <div class=\"T14M\">{{ formControl.value | sdEmpty }}</div>\n} @else {\n  @if (!_appearance && _labelDef?.templateRef) {\n    <ng-container *ngTemplateOutlet=\"_labelDef!.templateRef\"> </ng-container>\n  }\n  @if (!_appearance && _label && !_labelDef?.templateRef) {\n    <sd-label [label]=\"_label\" [required]=\"_required\"></sd-label>\n  }\n\n  <div\n    class=\"d-flex align-items-center sd-textarea-container\"\n    [class.c-focused]=\"isFocused\"\n    [class.c-disabled]=\"formControl.disabled\"\n    (click)=\"onClick()\"\n    aria-hidden=\"true\">\n      <div class=\"sd-textarea-field-wrap\" [class.sd-inline-textarea]=\"_isInline\">\n        <mat-form-field\n          [class.sd-md]=\"size() === 'md'\"\n          [class.sd-sm]=\"size() === 'sm'\"\n          [class.hide-inline-error]=\"_hideInlineError\"\n          [appearance]=\"_appearance!\"\n          [floatLabel]=\"floatLabel()\">\n          @if (_appearance && _label) {\n            <mat-label style=\"display: inline-block\">\n              <div style=\"display: flex; align-items: center; gap: 4px\">\n                <span>{{ _label }}</span>\n                @if (_helperText) {\n                  <mat-icon [matTooltip]=\"_helperText\" matTooltipPosition=\"above\">info_outline</mat-icon>\n                }\n              </div>\n            </mat-label>\n          }\n\n          <textarea\n            matInput\n            [placeholder]=\"placeholder() || _label || ''\"\n            [formControl]=\"formControl\"\n            [required]=\"_required\"\n            autocomplete=\"off\"\n            (focus)=\"onFocus()\"\n            (blur)=\"onBlur()\"\n            [rows]=\"rows()\"\n            [attr.data-autoId]=\"autoId()\"\n            [attr.data-disabled]=\"dataDisabled()\"\n            [attr.data-invalid]=\"dataInvalid()\"\n            [attr.data-empty]=\"dataEmpty()\"\n            [attr.data-value]=\"dataValue()\"\n            [attr.data-required]=\"dataRequired()\"\n            [attr.data-maxlength]=\"dataMaxLength()\"\n            [attr.data-pattern]=\"dataPattern()\"\n            [attr.data-error-message]=\"dataErrorMessage()\"\n            spellcheck=\"false\"\n            #textarea>\n          </textarea>\n\n          @if (_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\"> error </mat-icon>\n          }\n\n          @if (!_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-error>{{ _errorMessage }}</mat-error>\n          }\n\n          @if (sdSuffixDef()?.templateRef; as suffixRef) {\n            <ng-container matSuffix>\n              <ng-container *ngTemplateOutlet=\"suffixRef\"></ng-container>\n            </ng-container>\n          }\n          <!-- <ng-container matSuffix>\n            <ng-content select=\"[sdSuffix]\"></ng-content>\n          </ng-container> -->\n        </mat-form-field>\n\n        @if (_maxLength !== null && !_hideInlineError && !formControl.disabled) {\n          <div\n            class=\"sd-maxlength-counter\"\n            [class.sd-maxlength-counter--visible]=\"isFocused\"\n            [class.sd-maxlength-counter--exceeded]=\"isMaxlengthExceeded()\"\n            [attr.title]=\"isMaxlengthExceeded() ? ('core.form.textarea.exceeded' | translate) : null\">\n            {{ getCurrentLength() }}/{{ _maxLength }}\n          </div>\n        }\n      </div>\n  </div>\n}\n", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}.sd-inline-textarea{cursor:text;border-radius:4px;background-color:#0000000a;transition:background-color .15s ease}.sd-inline-textarea:hover{background-color:#00000014}.sd-inline-textarea:focus-within{background-color:#0000000f;box-shadow:inset 0 0 0 1px var(--sd-primary, #1f6feb)}.sd-inline-textarea ::ng-deep .mat-mdc-text-field-wrapper{padding:0 6px;background:transparent}.sd-inline-textarea ::ng-deep .mat-mdc-form-field-flex{padding:0}.sd-inline-textarea ::ng-deep .mdc-notched-outline{display:none}.sd-inline-textarea ::ng-deep .mat-mdc-form-field-subscript-wrapper{display:none}.sd-inline-textarea ::ng-deep .mat-mdc-form-field-infix{padding:4px 0;min-height:0;border:0}:host{display:block}:host(.sd-has-label){padding-top:4px}:host(.sd-viewed){padding-top:0}:host ::ng-deep textarea.mat-mdc-input-element{resize:none}:host ::ng-deep .mat-mdc-form-field.mat-form-field-appearance-outline .mdc-text-field--disabled{background:var(--sd-black100)}:host ::ng-deep .mat-mdc-form-field textarea.mat-mdc-input-element:disabled{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}.sd-textarea-field-wrap{position:relative;flex:1;min-width:0}.sd-maxlength-counter{position:absolute;right:4px;top:calc(100% - 16px);opacity:0;font-size:10px;line-height:1.1;color:#00000061;pointer-events:none;transition:opacity .12s ease;z-index:1}.sd-maxlength-counter--exceeded{color:var(--sd-error);font-weight:600}:host ::ng-deep .sd-textarea-container.c-focused .sd-maxlength-counter,:host ::ng-deep .sd-textarea-container:hover .sd-maxlength-counter,:host ::ng-deep .sd-textarea-container .sd-maxlength-counter.sd-maxlength-counter--visible{opacity:1}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: FormsModule }, { 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.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i3.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i3.MatLabel, selector: "mat-label" }, { kind: "directive", type: i3.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i3.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i4.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "directive", type: i6.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: SdLabel, selector: "sd-label", inputs: ["label", "description", "required", "helperText"] }, { kind: "pipe", type: SdEmptyPipe, name: "sdEmpty" }, { kind: "pipe", type: TranslatePipe, name: "translate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.24", ngImport: i0, type: SdTextarea, decorators: [{
            type: Component,
            args: [{ selector: 'sd-textarea', standalone: true, host: { '[class.sd-has-label]': '!!label()', '[class.sd-viewed]': 'isViewed() || isInline()' }, imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        MatFormFieldModule,
                        MatInputModule,
                        MatIconModule,
                        MatTooltipModule,
                        SdLabel,
                        SdEmptyPipe,
                        TranslatePipe,
                    ], template: "@let _label = label();\n@let _appearance = appearance();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage();\n@let _labelDef = sdLabelDef();\n@let _helperText = helperText();\n@let _required = required();\n@let _maxLength = maxlength();\n@let _isInline = isInline();\n\n@if (isViewed()) {\n  @if (_labelDef?.templateRef) {\n    <ng-container *ngTemplateOutlet=\"_labelDef!.templateRef\"> </ng-container>\n  } @else if (_label) {\n    <div class=\"T14R text-black400\">{{ _label }}</div>\n  }\n  <div class=\"T14M\">{{ formControl.value | sdEmpty }}</div>\n} @else {\n  @if (!_appearance && _labelDef?.templateRef) {\n    <ng-container *ngTemplateOutlet=\"_labelDef!.templateRef\"> </ng-container>\n  }\n  @if (!_appearance && _label && !_labelDef?.templateRef) {\n    <sd-label [label]=\"_label\" [required]=\"_required\"></sd-label>\n  }\n\n  <div\n    class=\"d-flex align-items-center sd-textarea-container\"\n    [class.c-focused]=\"isFocused\"\n    [class.c-disabled]=\"formControl.disabled\"\n    (click)=\"onClick()\"\n    aria-hidden=\"true\">\n      <div class=\"sd-textarea-field-wrap\" [class.sd-inline-textarea]=\"_isInline\">\n        <mat-form-field\n          [class.sd-md]=\"size() === 'md'\"\n          [class.sd-sm]=\"size() === 'sm'\"\n          [class.hide-inline-error]=\"_hideInlineError\"\n          [appearance]=\"_appearance!\"\n          [floatLabel]=\"floatLabel()\">\n          @if (_appearance && _label) {\n            <mat-label style=\"display: inline-block\">\n              <div style=\"display: flex; align-items: center; gap: 4px\">\n                <span>{{ _label }}</span>\n                @if (_helperText) {\n                  <mat-icon [matTooltip]=\"_helperText\" matTooltipPosition=\"above\">info_outline</mat-icon>\n                }\n              </div>\n            </mat-label>\n          }\n\n          <textarea\n            matInput\n            [placeholder]=\"placeholder() || _label || ''\"\n            [formControl]=\"formControl\"\n            [required]=\"_required\"\n            autocomplete=\"off\"\n            (focus)=\"onFocus()\"\n            (blur)=\"onBlur()\"\n            [rows]=\"rows()\"\n            [attr.data-autoId]=\"autoId()\"\n            [attr.data-disabled]=\"dataDisabled()\"\n            [attr.data-invalid]=\"dataInvalid()\"\n            [attr.data-empty]=\"dataEmpty()\"\n            [attr.data-value]=\"dataValue()\"\n            [attr.data-required]=\"dataRequired()\"\n            [attr.data-maxlength]=\"dataMaxLength()\"\n            [attr.data-pattern]=\"dataPattern()\"\n            [attr.data-error-message]=\"dataErrorMessage()\"\n            spellcheck=\"false\"\n            #textarea>\n          </textarea>\n\n          @if (_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\"> error </mat-icon>\n          }\n\n          @if (!_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-error>{{ _errorMessage }}</mat-error>\n          }\n\n          @if (sdSuffixDef()?.templateRef; as suffixRef) {\n            <ng-container matSuffix>\n              <ng-container *ngTemplateOutlet=\"suffixRef\"></ng-container>\n            </ng-container>\n          }\n          <!-- <ng-container matSuffix>\n            <ng-content select=\"[sdSuffix]\"></ng-content>\n          </ng-container> -->\n        </mat-form-field>\n\n        @if (_maxLength !== null && !_hideInlineError && !formControl.disabled) {\n          <div\n            class=\"sd-maxlength-counter\"\n            [class.sd-maxlength-counter--visible]=\"isFocused\"\n            [class.sd-maxlength-counter--exceeded]=\"isMaxlengthExceeded()\"\n            [attr.title]=\"isMaxlengthExceeded() ? ('core.form.textarea.exceeded' | translate) : null\">\n            {{ getCurrentLength() }}/{{ _maxLength }}\n          </div>\n        }\n      </div>\n  </div>\n}\n", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}.sd-inline-textarea{cursor:text;border-radius:4px;background-color:#0000000a;transition:background-color .15s ease}.sd-inline-textarea:hover{background-color:#00000014}.sd-inline-textarea:focus-within{background-color:#0000000f;box-shadow:inset 0 0 0 1px var(--sd-primary, #1f6feb)}.sd-inline-textarea ::ng-deep .mat-mdc-text-field-wrapper{padding:0 6px;background:transparent}.sd-inline-textarea ::ng-deep .mat-mdc-form-field-flex{padding:0}.sd-inline-textarea ::ng-deep .mdc-notched-outline{display:none}.sd-inline-textarea ::ng-deep .mat-mdc-form-field-subscript-wrapper{display:none}.sd-inline-textarea ::ng-deep .mat-mdc-form-field-infix{padding:4px 0;min-height:0;border:0}:host{display:block}:host(.sd-has-label){padding-top:4px}:host(.sd-viewed){padding-top:0}:host ::ng-deep textarea.mat-mdc-input-element{resize:none}:host ::ng-deep .mat-mdc-form-field.mat-form-field-appearance-outline .mdc-text-field--disabled{background:var(--sd-black100)}:host ::ng-deep .mat-mdc-form-field textarea.mat-mdc-input-element:disabled{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}.sd-textarea-field-wrap{position:relative;flex:1;min-width:0}.sd-maxlength-counter{position:absolute;right:4px;top:calc(100% - 16px);opacity:0;font-size:10px;line-height:1.1;color:#00000061;pointer-events:none;transition:opacity .12s ease;z-index:1}.sd-maxlength-counter--exceeded{color:var(--sd-error);font-weight:600}:host ::ng-deep .sd-textarea-container.c-focused .sd-maxlength-counter,:host ::ng-deep .sd-textarea-container:hover .sd-maxlength-counter,:host ::ng-deep .sd-textarea-container .sd-maxlength-counter.sd-maxlength-counter--visible{opacity:1}\n"] }]
        }], ctorParameters: () => [], propDecorators: { textareaRef: [{ type: i0.ViewChild, args: ['textarea', { isSignal: true }] }], sdViewDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdViewDefDirective), { isSignal: true }] }], sdLabelDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdLabelDefDirective), { isSignal: true }] }], sdSuffixDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdSuffixDefDirective), { isSignal: true }] }], autoIdInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoId", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], form: [{ type: i0.Input, args: [{ isSignal: true, alias: "form", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], helperText: [{ type: i0.Input, args: [{ isSignal: true, alias: "helperText", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], rows: [{ type: i0.Input, args: [{ isSignal: true, alias: "rows", required: false }] }], hideInlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideInlineError", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], viewed: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewed", required: false }] }], autoHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoHeight", required: false }] }], maxlength: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxlength", required: false }] }], pattern: [{ type: i0.Input, args: [{ isSignal: true, alias: "pattern", required: false }] }], validator: [{ type: i0.Input, args: [{ isSignal: true, alias: "validator", required: false }] }], inlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "inlineError", required: false }] }], appearanceInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "appearance", required: false }] }], floatLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "floatLabel", required: false }] }], valueModel: [{ type: i0.Input, args: [{ isSignal: true, alias: "model", required: false }] }, { type: i0.Output, args: ["modelChange"] }], sdChange: [{ type: i0.Output, args: ["sdChange"] }] } });

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

export { SdTextarea };
//# sourceMappingURL=sdcorejs-angular-forms-textarea.mjs.map
