import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { viewChild, contentChild, input, computed, inject, ChangeDetectorRef, booleanAttribute, model, output, EventEmitter, effect, untracked, Output, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i2 from '@angular/forms';
import { NgForm, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
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 { SdView } from '@sd-angular/core/components/view';
import { SdSuffixDefDirective, SdViewDefDirective } from '@sd-angular/core/forms/directives';
import { SdLabel } from '@sd-angular/core/forms/label';
import { SD_FORM_CONFIGURATION, SdFormControl, HandleSdCustomValidator } from '@sd-angular/core/forms/models';
import { SdPatternCommons } from '@sd-angular/core/utilities/models';
import { Subscription } from 'rxjs';
import * as uuid from 'uuid';

class SdInput {
    id = `I${uuid.v4()}`;
    // ==========================================
    // 1. SIGNAL QUERIES (Thay thế @ViewChild / @ContentChild)
    // ==========================================
    control = viewChild('control');
    sdLabelTemplate = contentChild('sdLabel');
    sdValueTemplate = contentChild('sdValue');
    sdSuffixDef = contentChild(SdSuffixDefDirective);
    sdViewDef = contentChild(SdViewDefDirective);
    // ==========================================
    // 2. SIGNAL INPUTS & MODEL
    // ==========================================
    autoIdInput = input(undefined, { alias: 'autoId' });
    autoId = computed(() => (this.autoIdInput() ? `forms-input-${this.autoIdInput()}` : undefined));
    name = input(uuid.v4());
    // ==========================================
    // 3. INJECT (Thay thế Constructor DI)
    // ==========================================
    #ref = inject(ChangeDetectorRef);
    #formConfig = inject(SD_FORM_CONFIGURATION, { optional: true });
    appearanceInput = input(undefined, { alias: 'appearance' });
    appearance = computed(() => this.appearanceInput() ?? this.#formConfig?.appearance ?? 'outline');
    size = input('md');
    // Chấp nhận mọi loại Form cha truyền xuống (FormGroup<{}>, FormGroup<any>, NgForm...)
    form = input();
    label = input();
    helperText = input();
    placeholder = input();
    type = input('text');
    hideInlineError = input(false, { transform: booleanAttribute });
    blurOnEnter = input(false, { transform: booleanAttribute });
    required = input(false, { transform: booleanAttribute });
    readonly = input(false, { transform: booleanAttribute });
    disabled = input(false, { transform: booleanAttribute });
    viewed = input(false, { transform: booleanAttribute });
    minlength = input(undefined, { transform: v => (v == null ? undefined : Number(v)) });
    maxlength = input(undefined, { transform: v => (v == null ? undefined : Number(v)) });
    pattern = input();
    patternErrorMessage = input();
    resolvedPattern = computed(() => {
        const val = this.pattern();
        const patternObj = SdPatternCommons.find(e => e.type === val);
        return patternObj ? patternObj.regex : (val ?? undefined);
    });
    resolvedPatternErrorMsg = computed(() => {
        const val = this.pattern();
        const patternObj = SdPatternCommons.find(e => e.type === val);
        return this.patternErrorMessage() ?? (patternObj ? patternObj.errorMessage : undefined);
    });
    validator = input();
    inlineError = input();
    hyperlink = input();
    tooltip = input();
    valueModel = model(undefined, { alias: 'model' });
    // ==========================================
    // 4. SIGNAL OUTPUTS (Thay thế @Output)
    // ==========================================
    sdChange = output();
    sdFocus = output(); // Đổi sang void vì không truyền data
    sdBlur = output();
    keyupEnter = output();
    // 🚨 GIỮ LẠI EVENT_EMITTER DUY NHẤT VÌ CẦN CHECK OBSERVERED
    sdFocusForceBlur = new EventEmitter();
    formControl = new SdFormControl();
    #subscription = new Subscription();
    isFocused = false;
    constructor() {
        effect(() => {
            const val = this.valueModel();
            untracked(() => {
                if (this.formControl.value !== val) {
                    this.formControl.setValue(val, { emitEvent: false });
                }
            });
        });
        effect(() => {
            if (this.disabled()) {
                this.formControl.disable({ emitEvent: false });
            }
            else {
                this.formControl.enable({ emitEvent: false });
            }
        });
        effect(() => {
            const req = this.required();
            const min = this.minlength();
            const max = this.maxlength();
            const pat = this.resolvedPattern();
            const inl = this.inlineError();
            const val = this.validator();
            untracked(() => {
                this.#updateValidator(req, min, max, pat, inl, val);
            });
        });
    }
    ngOnInit() {
        this.#subscription.add(this.formControl.sdChanges.subscribe(() => {
            this.#ref.markForCheck();
        }));
    }
    ngAfterViewInit() {
        this.#subscription.add(this.formControl.valueChanges.subscribe(this.#onChange));
        const formGroup = this.form() instanceof NgForm ? this.form().form : this.form();
        formGroup?.addControl(this.name(), this.formControl);
        this.#ref.detectChanges();
    }
    ngOnDestroy() {
        const formGroup = this.form() instanceof NgForm ? this.form().form : this.form();
        formGroup?.removeControl(this.name());
        this.#subscription.unsubscribe();
    }
    reValidate = () => {
        this.formControl.updateValueAndValidity();
    };
    #updateValidator = (req, min, max, pat, inl, val) => {
        const validators = [];
        const asyncValidators = [];
        if (req)
            validators.push(Validators.required);
        if (min && min > 0)
            validators.push(Validators.minLength(min));
        if (max && max > 0)
            validators.push(Validators.maxLength(max));
        if (pat)
            validators.push(Validators.pattern(pat));
        if (inl)
            validators.push(this.customInlineErrorValidator());
        if (val)
            asyncValidators.push(HandleSdCustomValidator(val));
        this.formControl.setValidators(validators.length ? validators : null);
        this.formControl.setAsyncValidators(asyncValidators.length ? asyncValidators : null);
        this.formControl.updateValueAndValidity({ emitEvent: false });
    };
    customInlineErrorValidator() {
        return () => ({ inlineError: true });
    }
    #onChange = () => {
        this.valueModel.set(this.formControl.value);
        this.sdChange.emit(this.formControl.value);
    };
    onKeyupEnter = () => {
        const val = (this.formControl.value ?? '').toString();
        if (val.length > val.trim().length) {
            this.formControl.setValue(val.trim());
        }
        this.keyupEnter.emit(this.formControl.value);
        if (this.blurOnEnter()) {
            this.blur();
        }
    };
    onFocus = () => {
        this.isFocused = true;
        this.sdFocus.emit(); // Gọi .emit() y hệt như cũ
        if (this.sdFocusForceBlur.observed) {
            this.blur();
            this.sdFocusForceBlur.emit();
        }
    };
    onBlur = () => {
        this.isFocused = false;
        const val = (this.formControl.value ?? '').toString();
        if (val.length > val.trim().length) {
            this.formControl.setValue(val.trim());
        }
        this.sdBlur.emit(this.formControl.value);
    };
    onClick = () => {
        // 🚨 GỌI SIGNAL: Phải thêm () vào sdViewDef
        if (this.sdViewDef()?.templateRef) {
            if (!this.formControl.disabled && !this.isFocused) {
                this.focus();
            }
        }
    };
    blur = () => {
        this.isFocused = false;
        // 🚨 GỌI SIGNAL: Phải thêm () vào control
        this.control()?.nativeElement?.blur();
    };
    focus = () => {
        this.isFocused = true;
        setTimeout(() => {
            // 🚨 GỌI SIGNAL: Phải thêm () vào control
            this.control()?.nativeElement?.focus();
        }, 100);
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdInput, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.17", type: SdInput, isStandalone: true, selector: "sd-input", inputs: { autoIdInput: { classPropertyName: "autoIdInput", publicName: "autoId", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, appearanceInput: { classPropertyName: "appearanceInput", publicName: "appearance", 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 }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, blurOnEnter: { classPropertyName: "blurOnEnter", publicName: "blurOnEnter", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", 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 }, minlength: { classPropertyName: "minlength", publicName: "minlength", 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 }, patternErrorMessage: { classPropertyName: "patternErrorMessage", publicName: "patternErrorMessage", 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 }, hyperlink: { classPropertyName: "hyperlink", publicName: "hyperlink", isSignal: true, isRequired: false, transformFunction: null }, tooltip: { classPropertyName: "tooltip", publicName: "tooltip", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange", sdFocus: "sdFocus", sdBlur: "sdBlur", keyupEnter: "keyupEnter", sdFocusForceBlur: "sdFocusForceBlur" }, queries: [{ propertyName: "sdLabelTemplate", first: true, predicate: ["sdLabel"], descendants: true, isSignal: true }, { propertyName: "sdValueTemplate", first: true, predicate: ["sdValue"], descendants: true, isSignal: true }, { propertyName: "sdSuffixDef", first: true, predicate: SdSuffixDefDirective, descendants: true, isSignal: true }, { propertyName: "sdViewDef", first: true, predicate: SdViewDefDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "control", first: true, predicate: ["control"], descendants: true, isSignal: true }], ngImport: i0, template: "@let lbl = label();\r\n@let app = appearance();\r\n@let hideErr = hideInlineError();\r\n@let viewDef = sdViewDef();\r\n@let hText = helperText();\r\n@let ttip = tooltip();\r\n@let maxLen = maxlength();\r\n@let req = required();\r\n\r\n@if (viewed()) {\r\n  <sd-view\r\n    [label]=\"lbl\"\r\n    [labelTemplate]=\"sdLabelTemplate()\"\r\n    [value]=\"formControl.value\"\r\n    [display]=\"formControl.value\"\r\n    [hyperlink]=\"hyperlink()\"\r\n    [valueTemplate]=\"sdValueTemplate()\">\r\n  </sd-view>\r\n} @else {\r\n  @if (!app) {\r\n    <ng-content select=\"[sdLabel]\">\r\n      @if (lbl) {\r\n        <sd-label [label]=\"lbl\" [required]=\"req\"></sd-label>\r\n      }\r\n    </ng-content>\r\n  }\r\n\r\n  <div\r\n    class=\"d-flex align-items-center\"\r\n    [class.sd-view]=\"!!viewDef?.templateRef\"\r\n    [class.c-focused]=\"isFocused\"\r\n    [class.c-disabled]=\"formControl.disabled\"\r\n    (click)=\"onClick()\"\r\n    aria-hidden=\"true\">\r\n    \r\n    @if (viewDef?.templateRef && !isFocused) {\r\n      <ng-container *ngTemplateOutlet=\"viewDef!.templateRef; context: { value: formControl.value }\"> </ng-container>\r\n    } @else {\r\n      <mat-form-field\r\n        [class.sd-md]=\"size() === 'md'\"\r\n        [class.sd-sm]=\"size() === 'sm'\"\r\n        [class.hide-inline-error]=\"hideErr\"\r\n        [class.sd-form-tooltip]=\"!!ttip\"\r\n        [appearance]=\"app!\">\r\n        \r\n        @if (app && lbl) {\r\n          <mat-label style=\"display: inline-block\">\r\n            <div style=\"display: flex; align-items: center; gap: 4px\">\r\n              <span>{{ lbl }}</span>\r\n              @if (hText) {\r\n                <mat-icon [matTooltip]=\"hText\" matTooltipPosition=\"below\">info_outline</mat-icon>\r\n              }\r\n            </div>\r\n          </mat-label>\r\n        }\r\n        \r\n        <input\r\n          aria-hidden=\"true\"\r\n          [id]=\"id\"\r\n          [formControl]=\"formControl\"\r\n          [type]=\"type()\"\r\n          #control\r\n          matInput\r\n          [placeholder]=\"placeholder() || lbl || ''\"\r\n          (keyup.enter)=\"onKeyupEnter()\"\r\n          (focus)=\"onFocus()\"\r\n          (blur)=\"onBlur()\"\r\n          [required]=\"req\"\r\n          [readonly]=\"readonly()\"\r\n          [autocomplete]=\"id\"\r\n          autocorrect=\"off\"\r\n          [step]=\"1\"\r\n          [attr.data-autoId]=\"autoId()\" />\r\n\r\n        @if (maxLen && !formControl.disabled) {\r\n          <span matSuffix>{{ formControl.value?.length || 0 }}/{{ maxLen }}</span>\r\n        }\r\n\r\n        @if (sdSuffixDef()?.templateRef; as suffixRef) {\r\n          <ng-container matSuffix>\r\n            <ng-container *ngTemplateOutlet=\"suffixRef\"></ng-container>\r\n          </ng-container>\r\n        }\r\n\r\n        @if (formControl.errors?.['required']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Vui l\u00F2ng nh\u1EADp th\u00F4ng tin' }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['maxlength']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'S\u1ED1 k\u00FD t\u1EF1 t\u1ED1i \u0111a: ' }} {{ maxLen }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['pattern']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ resolvedPatternErrorMsg() || '\u0110\u1ECBnh d\u1EA1ng kh\u00F4ng h\u1EE3p l\u1EC7' }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['customValidator']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ formControl.errors?.['customValidator'] }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['inlineError']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ inlineError() }}\r\n            }\r\n          </mat-error>\r\n        }\r\n      </mat-form-field>\r\n      \r\n      @if (ttip) {\r\n        <div class=\"sd-tooltip\">\r\n          <mat-icon (click)=\"sdTooltip.toggle()\" [matTooltip]=\"formControl.value || ttip\" matSuffix #sdTooltip=\"matTooltip\">info</mat-icon>\r\n        </div>\r\n      }\r\n    }\r\n  </div>\r\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}:host ::ng-deep .mat-mdc-form-field.sd-form-tooltip{width:calc(100% - 30px)}:host ::ng-deep .mat-mdc-form-field.mat-form-field-appearance-outline.mat-form-field-disabled .mat-mdc-text-field-wrapper{background:var(--sd-black100)}:host ::ng-deep .mat-mdc-form-field input.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-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}.sd-tooltip{display:inline-block;text-align:center;margin:auto;width:30px}:host{padding-top:5px;display:block}.sd-md:hover .btn-copy{visibility:visible}\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: "ngmodule", type: MatButtonModule }, { kind: "component", type: SdLabel, selector: "sd-label", inputs: ["label", "description", "required", "helperText"] }, { kind: "component", type: SdView, selector: "sd-view", inputs: ["label", "value", "display", "hyperlink", "labelTemplate", "valueTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdInput, decorators: [{
            type: Component,
            args: [{ selector: 'sd-input', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        MatFormFieldModule,
                        MatInputModule,
                        MatIconModule,
                        MatTooltipModule,
                        MatButtonModule,
                        SdLabel,
                        SdView,
                    ], template: "@let lbl = label();\r\n@let app = appearance();\r\n@let hideErr = hideInlineError();\r\n@let viewDef = sdViewDef();\r\n@let hText = helperText();\r\n@let ttip = tooltip();\r\n@let maxLen = maxlength();\r\n@let req = required();\r\n\r\n@if (viewed()) {\r\n  <sd-view\r\n    [label]=\"lbl\"\r\n    [labelTemplate]=\"sdLabelTemplate()\"\r\n    [value]=\"formControl.value\"\r\n    [display]=\"formControl.value\"\r\n    [hyperlink]=\"hyperlink()\"\r\n    [valueTemplate]=\"sdValueTemplate()\">\r\n  </sd-view>\r\n} @else {\r\n  @if (!app) {\r\n    <ng-content select=\"[sdLabel]\">\r\n      @if (lbl) {\r\n        <sd-label [label]=\"lbl\" [required]=\"req\"></sd-label>\r\n      }\r\n    </ng-content>\r\n  }\r\n\r\n  <div\r\n    class=\"d-flex align-items-center\"\r\n    [class.sd-view]=\"!!viewDef?.templateRef\"\r\n    [class.c-focused]=\"isFocused\"\r\n    [class.c-disabled]=\"formControl.disabled\"\r\n    (click)=\"onClick()\"\r\n    aria-hidden=\"true\">\r\n    \r\n    @if (viewDef?.templateRef && !isFocused) {\r\n      <ng-container *ngTemplateOutlet=\"viewDef!.templateRef; context: { value: formControl.value }\"> </ng-container>\r\n    } @else {\r\n      <mat-form-field\r\n        [class.sd-md]=\"size() === 'md'\"\r\n        [class.sd-sm]=\"size() === 'sm'\"\r\n        [class.hide-inline-error]=\"hideErr\"\r\n        [class.sd-form-tooltip]=\"!!ttip\"\r\n        [appearance]=\"app!\">\r\n        \r\n        @if (app && lbl) {\r\n          <mat-label style=\"display: inline-block\">\r\n            <div style=\"display: flex; align-items: center; gap: 4px\">\r\n              <span>{{ lbl }}</span>\r\n              @if (hText) {\r\n                <mat-icon [matTooltip]=\"hText\" matTooltipPosition=\"below\">info_outline</mat-icon>\r\n              }\r\n            </div>\r\n          </mat-label>\r\n        }\r\n        \r\n        <input\r\n          aria-hidden=\"true\"\r\n          [id]=\"id\"\r\n          [formControl]=\"formControl\"\r\n          [type]=\"type()\"\r\n          #control\r\n          matInput\r\n          [placeholder]=\"placeholder() || lbl || ''\"\r\n          (keyup.enter)=\"onKeyupEnter()\"\r\n          (focus)=\"onFocus()\"\r\n          (blur)=\"onBlur()\"\r\n          [required]=\"req\"\r\n          [readonly]=\"readonly()\"\r\n          [autocomplete]=\"id\"\r\n          autocorrect=\"off\"\r\n          [step]=\"1\"\r\n          [attr.data-autoId]=\"autoId()\" />\r\n\r\n        @if (maxLen && !formControl.disabled) {\r\n          <span matSuffix>{{ formControl.value?.length || 0 }}/{{ maxLen }}</span>\r\n        }\r\n\r\n        @if (sdSuffixDef()?.templateRef; as suffixRef) {\r\n          <ng-container matSuffix>\r\n            <ng-container *ngTemplateOutlet=\"suffixRef\"></ng-container>\r\n          </ng-container>\r\n        }\r\n\r\n        @if (formControl.errors?.['required']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Vui l\u00F2ng nh\u1EADp th\u00F4ng tin' }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['maxlength']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'S\u1ED1 k\u00FD t\u1EF1 t\u1ED1i \u0111a: ' }} {{ maxLen }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['pattern']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ resolvedPatternErrorMsg() || '\u0110\u1ECBnh d\u1EA1ng kh\u00F4ng h\u1EE3p l\u1EC7' }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['customValidator']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ formControl.errors?.['customValidator'] }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['inlineError']) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ inlineError() }}\r\n            }\r\n          </mat-error>\r\n        }\r\n      </mat-form-field>\r\n      \r\n      @if (ttip) {\r\n        <div class=\"sd-tooltip\">\r\n          <mat-icon (click)=\"sdTooltip.toggle()\" [matTooltip]=\"formControl.value || ttip\" matSuffix #sdTooltip=\"matTooltip\">info</mat-icon>\r\n        </div>\r\n      }\r\n    }\r\n  </div>\r\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}:host ::ng-deep .mat-mdc-form-field.sd-form-tooltip{width:calc(100% - 30px)}:host ::ng-deep .mat-mdc-form-field.mat-form-field-appearance-outline.mat-form-field-disabled .mat-mdc-text-field-wrapper{background:var(--sd-black100)}:host ::ng-deep .mat-mdc-form-field input.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-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}.sd-tooltip{display:inline-block;text-align:center;margin:auto;width:30px}:host{padding-top:5px;display:block}.sd-md:hover .btn-copy{visibility:visible}\n"] }]
        }], ctorParameters: () => [], propDecorators: { sdFocusForceBlur: [{
                type: Output
            }] } });
function backendErrorValidator(backendErrorMessage) {
    return (control) => {
        const value = control.value;
        if (value === backendErrorMessage) {
            return { backendError: true };
        }
        return null;
    };
}

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

export { SdInput, backendErrorValidator };
//# sourceMappingURL=sd-angular-core-forms-input.mjs.map
