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, EventEmitter, signal, effect, untracked, Output, ChangeDetectionStrategy, Component } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import * as i2 from '@angular/forms';
import { NgForm, FormGroup, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
import * as i5 from '@angular/material/autocomplete';
import { MatAutocompleteTrigger, MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i6 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i3 from '@angular/material/input';
import { MatInputModule } from '@angular/material/input';
import * as i7 from '@angular/material/progress-spinner';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import * as i4 from '@angular/material/tooltip';
import { MatTooltipModule } from '@angular/material/tooltip';
import { SdView } from '@sdcorejs/angular/components/view';
import { SdItemDefDefDirective, SdViewDefDirective } from '@sdcorejs/angular/forms/directives';
import { SdLabel } from '@sdcorejs/angular/forms/label';
import { SD_FORM_CONFIGURATION, sdFormControlState, sdViewedTransform, sdViewedInline, SdFormControl, HandleSdCustomValidator, SdInlineErrorValidator } from '@sdcorejs/angular/forms/models';
import { I18nService } from '@sdcorejs/angular/i18n';
import { sdIsEmpty, sdSerializeDataValue } from '@sdcorejs/angular/utilities/data-state';
import { ArrayUtilities } from '@sdcorejs/angular/utilities/extensions';
import { Utilities } from '@sdcorejs/utils/fns';
import { Subscription, combineLatest, timer, of, defer, from } from 'rxjs';
import { tap, map, startWith, debounce, switchMap, catchError } from 'rxjs/operators';
import * as uuid from 'uuid';

/* eslint-disable @angular-eslint/component-class-suffix */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @angular-eslint/no-input-rename */
class SdAutocompleteErrotStateMatcher {
    formControl;
    constructor(formControl) {
        this.formControl = formControl;
    }
    isErrorState(control, form) {
        const isSubmitted = form && form.submitted;
        return !!(this.formControl?.invalid && (this.formControl?.dirty || this.formControl?.touched || isSubmitted));
    }
}
class SdAutocomplete {
    id = `I${uuid.v4()}`;
    // ==========================================
    // 1. SIGNAL QUERIES
    // ==========================================
    inputRef = viewChild('input', ...(ngDevMode ? [{ debugName: "inputRef" }] : /* istanbul ignore next */ []));
    autocompleteTrigger = viewChild(MatAutocompleteTrigger, ...(ngDevMode ? [{ debugName: "autocompleteTrigger" }] : /* istanbul ignore next */ []));
    sdLabelTemplate = contentChild('sdLabel', ...(ngDevMode ? [{ debugName: "sdLabelTemplate" }] : /* istanbul ignore next */ []));
    sdValueTemplate = contentChild('sdValue', ...(ngDevMode ? [{ debugName: "sdValueTemplate" }] : /* istanbul ignore next */ []));
    itemDef = contentChild(SdItemDefDefDirective, ...(ngDevMode ? [{ debugName: "itemDef" }] : /* istanbul ignore next */ []));
    sdViewDef = contentChild(SdViewDefDirective, ...(ngDevMode ? [{ debugName: "sdViewDef" }] : /* istanbul ignore next */ []));
    // ==========================================
    // 2. INJECTS
    // ==========================================
    ref = inject(ChangeDetectorRef);
    formConfig = inject(SD_FORM_CONFIGURATION, { optional: true });
    #i18n = inject(I18nService);
    // ==========================================
    // 3. SIGNAL INPUTS & MODEL
    // ==========================================
    autoIdInput = input(undefined, { ...(ngDevMode ? { debugName: "autoIdInput" } : /* istanbul ignore next */ {}), alias: 'autoId' });
    autoId = computed(() => (this.autoIdInput() ? `forms-autocomplete-${this.autoIdInput()}` : undefined), ...(ngDevMode ? [{ debugName: "autoId" }] : /* istanbul ignore next */ []));
    // E2E data-* attributes
    #state = sdFormControlState(computed(() => this.formControl));
    dataDisabled = computed(() => (this.#state().disabled ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataDisabled" }] : /* istanbul ignore next */ []));
    dataInvalid = computed(() => (this.#state().invalid ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataInvalid" }] : /* istanbul ignore next */ []));
    dataEmpty = computed(() => (sdIsEmpty(this.#state().value) ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataEmpty" }] : /* istanbul ignore next */ []));
    dataValue = computed(() => sdSerializeDataValue(this.#state().value), ...(ngDevMode ? [{ debugName: "dataValue" }] : /* istanbul ignore next */ []));
    dataLoading = computed(() => (this.loading() ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataLoading" }] : /* istanbul ignore next */ []));
    dataRequired = computed(() => (this.required() ? 'true' : 'false'), ...(ngDevMode ? [{ debugName: "dataRequired" }] : /* istanbul ignore next */ []));
    dataErrorMessage = computed(() => {
        void this.#state();
        const msg = this.errorMessage();
        return msg && msg.length > 0 ? msg : null;
    }, ...(ngDevMode ? [{ debugName: "dataErrorMessage" }] : /* istanbul ignore next */ []));
    name = input(uuid.v4(), ...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
    size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
    // Ghi (TransformT): any (để không bị lỗi typing khi cha truyền vào)
    form = input(undefined, { ...(ngDevMode ? { debugName: "form" } : /* istanbul ignore next */ {}), 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(...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ []));
    helperText = input(...(ngDevMode ? [undefined, { debugName: "helperText" }] : /* istanbul ignore next */ []));
    placeholder = input(...(ngDevMode ? [undefined, { debugName: "placeholder" }] : /* istanbul ignore next */ []));
    valueField = input(...(ngDevMode ? [undefined, { debugName: "valueField" }] : /* istanbul ignore next */ []));
    displayField = input(...(ngDevMode ? [undefined, { debugName: "displayField" }] : /* istanbul ignore next */ []));
    disabledField = input('', ...(ngDevMode ? [{ debugName: "disabledField" }] : /* istanbul ignore next */ []));
    limit = input(100, ...(ngDevMode ? [{ debugName: "limit" }] : /* istanbul ignore next */ []));
    cacheChecksum = input(...(ngDevMode ? [undefined, { debugName: "cacheChecksum" }] : /* istanbul ignore next */ []));
    hyperlink = input(...(ngDevMode ? [undefined, { debugName: "hyperlink" }] : /* istanbul ignore next */ []));
    items = input(...(ngDevMode ? [undefined, { debugName: "items" }] : /* istanbul ignore next */ []));
    hideInlineError = input(false, { ...(ngDevMode ? { debugName: "hideInlineError" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    addable = input(false, { ...(ngDevMode ? { debugName: "addable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    /** Display mode: `false` edit · `true` static view · `'inline'` view + click-to-edit (autocomplete panel). */
    viewed = input(false, { ...(ngDevMode ? { debugName: "viewed" } : /* istanbul ignore next */ {}), transform: sdViewedTransform });
    /** In `viewed='inline'`, show a hover clear-× on the text face. Set `false` when the host owns removal (chips). */
    clearable = input(true, { ...(ngDevMode ? { debugName: "clearable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    // Tri-state `viewed` — shared primitive. In `'inline'` the autocomplete editor is always mounted
    // (chrome hidden via CSS); the sd-view text face opens the panel on click.
    #viewedState = sdViewedInline(this.viewed, () => this.open(), this.disabled);
    /** `true` when `viewed === 'inline'`. */
    isInline = this.#viewedState.isInline;
    /** `true` when `viewed === true` (static view, no editor). */
    isViewed = this.#viewedState.isViewed;
    /** Open the autocomplete panel from the inline text face. No-op unless `viewed='inline'`. */
    enterInlineEdit = () => this.#viewedState.enterInlineEdit();
    /** View display template: `sdViewDef` overrides the projected `#sdValue` (unified). */
    viewTemplate = computed(() => this.sdViewDef()?.templateRef ?? this.sdValueTemplate(), ...(ngDevMode ? [{ debugName: "viewTemplate" }] : /* istanbul ignore next */ []));
    validator = input(...(ngDevMode ? [undefined, { debugName: "validator" }] : /* istanbul ignore next */ []));
    inlineError = input(...(ngDevMode ? [undefined, { debugName: "inlineError" }] : /* istanbul ignore next */ []));
    /**
     * 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.autocomplete.required');
        if (errors['customValidator'])
            return errors['customValidator'];
        if (errors['inlineError'])
            return this.inlineError();
        return undefined;
    }, ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
    appearanceInput = input(undefined, { ...(ngDevMode ? { debugName: "appearanceInput" } : /* istanbul ignore next */ {}), alias: 'appearance' });
    appearance = computed(() => this.appearanceInput() ?? this.formConfig?.appearance ?? 'outline', ...(ngDevMode ? [{ debugName: "appearance" }] : /* istanbul ignore next */ []));
    valueModel = model(undefined, { ...(ngDevMode ? { debugName: "valueModel" } : /* istanbul ignore next */ {}), alias: 'model' });
    // ==========================================
    // 4. SIGNAL OUTPUTS
    // ==========================================
    sdChange = output();
    sdSelection = output();
    sdAdd = new EventEmitter();
    // ==========================================
    // 5. INTERNAL STATE & STREAMS
    // ==========================================
    loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
    isFocused = false;
    isTyping = signal(false, ...(ngDevMode ? [{ debugName: "isTyping" }] : /* istanbul ignore next */ []));
    inputControl = new SdFormControl();
    formControl = new SdFormControl();
    matcher = new SdAutocompleteErrotStateMatcher(this.formControl);
    #cache = {};
    #item = {};
    #subscription = new Subscription();
    // RXJS STREAMS
    #items$ = toObservable(this.items);
    #valueModel$ = toObservable(this.valueModel);
    // PUBLIC SIGNALS (Render View)
    filteredItems = signal([], ...(ngDevMode ? [{ debugName: "filteredItems" }] : /* istanbul ignore next */ []));
    selected = signal(null, ...(ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []));
    display = signal('', ...(ngDevMode ? [{ debugName: "display" }] : /* istanbul ignore next */ []));
    controlPlaceHolder = signal('', ...(ngDevMode ? [{ debugName: "controlPlaceHolder" }] : /* istanbul ignore next */ []));
    normalizedValue = computed(() => this.valueModel(), ...(ngDevMode ? [{ debugName: "normalizedValue" }] : /* istanbul ignore next */ []));
    // ==========================================
    // [NEW]: Hàm đọc thuộc tính lồng nhau (a.b.c)
    // ==========================================
    getNestedValue = (obj, path) => {
        if (!path || obj == null)
            return obj;
        const keys = path.split('.');
        let result = obj;
        for (const key of keys) {
            if (result == null)
                return undefined;
            result = result[key];
        }
        return result;
    };
    constructor() {
        effect(() => {
            const val = this.normalizedValue();
            untracked(() => {
                if (this.formControl.value !== val) {
                    this.formControl.setValue(val, { emitEvent: false });
                }
            });
        });
        effect(() => {
            if (this.disabled()) {
                this.inputControl.disable({ emitEvent: false });
                this.formControl.disable({ emitEvent: false });
            }
            else {
                this.inputControl.enable({ emitEvent: false });
                this.formControl.enable({ emitEvent: false });
            }
        });
        effect(() => {
            const req = this.required();
            const val = this.validator();
            const inl = this.inlineError();
            untracked(() => this.#updateValidator(req, val, inl));
        });
    }
    ngOnInit() {
        this.#subscription.add(this.formControl.valueChanges.subscribe(val => {
            if (this.valueModel() !== val) {
                this.valueModel.set(val);
            }
        }));
        this.#subscription.add(this.inputControl.touchChanges.subscribe(() => {
            this.formControl.markAsTouched();
            this.ref.markForCheck();
        }));
        this.#subscription.add(this.formControl.sdChanges.subscribe(() => this.ref.markForCheck()));
        this.#subscription.add(this.inputControl.sdChanges.subscribe(() => this.ref.markForCheck()));
        this.#subscription.add(this.inputControl.valueChanges.subscribe(() => this.isTyping.set(true)));
        const cleanItems$ = this.#items$.pipe(tap(() => {
            this.#cache = {};
        }), map(items => {
            if (!items)
                return [];
            if (Array.isArray(items))
                return items.filter(e => e !== null && e !== undefined);
            return items;
        }));
        const filteredItems$ = combineLatest([
            cleanItems$,
            this.inputControl.valueChanges.pipe(startWith(''), debounce(() => timer(typeof this.items() === 'function' ? 500 : 0))),
        ]).pipe(tap(() => this.isTyping.set(false)), switchMap(([items, searchText]) => {
            const sText = searchText || '';
            if (typeof items !== 'function') {
                // [UPDATED]: Hỗ trợ search lồng nhau (nested) local
                const filtered = items.filter((e) => {
                    const v = String(this.getNestedValue(e, this.valueField()) || '').toLowerCase();
                    const d = String(this.getNestedValue(e, this.displayField()) || '').toLowerCase();
                    const q = sText.toLowerCase();
                    return v.includes(q) || d.includes(q);
                });
                return of(ArrayUtilities.paging(filtered, this.limit()));
            }
            const key = Utilities.hash({
                checksum: this.cacheChecksum() || null,
                searchText: sText,
            });
            if (this.#cache[key] !== undefined) {
                return of(this.#cache[key]);
            }
            this.loading.set(true);
            let obs;
            const func = items({ type: 'SEARCH', searchText: sText });
            if (func instanceof Promise)
                obs = defer(() => from(func));
            else
                obs = func;
            return obs.pipe(map(data => {
                this.#cache[key] = data || [];
                // [UPDATED]: Lưu cache #item theo nested value
                (this.#cache[key] || []).forEach((e) => {
                    const valKey = this.getNestedValue(e, this.valueField());
                    if (valKey != null) {
                        this.#item[valKey] = e;
                    }
                });
                return this.#cache[key];
            }), catchError(() => of([])));
        }), tap(() => this.loading.set(false)));
        const selected$ = combineLatest([cleanItems$, this.#valueModel$]).pipe(switchMap(([items, val]) => {
            const vField = this.valueField();
            const dField = this.displayField();
            if (!vField)
                return of(val);
            if (val || val === 0) {
                if (typeof items === 'function') {
                    if (this.#item[val])
                        return of(this.#item[val]);
                    this.loading.set(true);
                    let obs;
                    const func = items({ type: 'VALUE', value: val });
                    if (func instanceof Promise)
                        obs = defer(() => from(func));
                    else
                        obs = func;
                    return obs.pipe(map(data => {
                        // [UPDATED]: Lưu cache #item theo nested value
                        (data || []).forEach((e) => {
                            const valKey = this.getNestedValue(e, vField);
                            if (valKey != null) {
                                this.#item[valKey] = e;
                            }
                        });
                        return this.#item[val] || { [vField]: val, [dField]: val };
                    }), catchError(() => of({ [vField]: val, [dField]: val })));
                }
                // [UPDATED]: Tìm local theo nested field
                return of(items.find((e) => this.getNestedValue(e, vField) === val));
            }
            return of('');
        }), tap(() => this.loading.set(false)));
        const controlPlaceHolder$ = selected$.pipe(map((item) => {
            // [UPDATED]: Đọc PlaceHolder bằng getNestedValue
            const dispVal = this.getNestedValue(item, this.displayField());
            return dispVal ?? item ?? this.placeholder() ?? (this.appearance() ? this.label() : '');
        }));
        const display$ = selected$.pipe(map((item) => {
            // [UPDATED]: Đọc Display bằng getNestedValue
            const dField = this.displayField();
            if (dField && typeof item === 'object' && !!item) {
                return this.getNestedValue(item, dField) ?? '';
            }
            if (typeof item === 'string' || typeof item === 'number') {
                return item.toString();
            }
            return '';
        }));
        this.#subscription.add(filteredItems$.subscribe(val => {
            this.filteredItems.set(val || []);
            this.ref.markForCheck();
        }));
        this.#subscription.add(selected$.subscribe(val => {
            this.selected.set(val);
            this.ref.markForCheck();
        }));
        this.#subscription.add(controlPlaceHolder$.subscribe(val => {
            this.controlPlaceHolder.set(val || '');
            this.ref.markForCheck();
        }));
        this.#subscription.add(display$.subscribe(val => {
            this.display.set(val || '');
            this.ref.markForCheck();
        }));
    }
    ngAfterViewInit() {
        const formGroup = this.form();
        formGroup?.addControl(this.name(), this.formControl);
    }
    ngOnDestroy() {
        this.#subscription.unsubscribe();
        const formGroup = this.form();
        formGroup?.removeControl(this.name());
        this.#cache = {};
        this.#item = {};
    }
    onSelect = (item) => {
        if (!item)
            return;
        const vField = this.valueField();
        const dField = this.displayField();
        // why: KHÔNG dùng { emitEvent: false } khi mirror giá trị chọn sang formControl. formControl
        // mang async [validator] (HandleSdCustomValidator). Nếu chặn event thì khi async resolve,
        // setErrors cũng im → #state (sdFormControlState) không tick → errorMessage không recompute →
        // message lỗi không hiện/không clear. Để event lan ra: formControl.valueChanges có subscriber
        // set valueModel (guard `!==`), và onSelect set lại valueModel cùng giá trị (no-op) → không lặp.
        if (typeof item === 'string' || typeof item === 'number') {
            if (this.formControl.value !== item) {
                this.formControl.setValue(item);
                this.valueModel.set(item);
                this.sdChange.emit(item);
                this.sdSelection.emit({ values: [item], selectedItems: [item], value: item, selectedItem: item });
            }
        }
        else if (vField && dField) {
            // [UPDATED]: Lấy giá trị val = getNestedValue(item, vField)
            const val = this.getNestedValue(item, vField) ?? null;
            if (this.formControl.value !== val) {
                this.formControl.setValue(val);
                this.valueModel.set(val);
                this.sdChange.emit(val);
                this.sdSelection.emit({ values: [val], selectedItems: [item], value: val, selectedItem: item });
            }
        }
        this.inputControl.setValue('', { emitEvent: false });
    };
    onFocus = () => {
        this.isFocused = true;
        this.filteredItems.set([]);
        if (typeof this.items() === 'function') {
            this.loading.set(true);
        }
        this.inputControl.setValue('', { emitEvent: true });
    };
    onBlur = () => {
        this.isFocused = false;
        this.inputControl.setValue('', { emitEvent: false });
    };
    onClick = () => {
        if (this.sdViewDef()?.templateRef) {
            if (!this.formControl.disabled && !this.isFocused) {
                this.focus();
            }
        }
    };
    blur = () => {
        this.inputRef()?.nativeElement?.blur();
    };
    focus = () => {
        this.isFocused = true;
        setTimeout(() => {
            this.autocompleteTrigger()?.openPanel();
            this.inputRef()?.nativeElement?.focus();
        }, 100);
    };
    /** Open the autocomplete panel programmatically (anchors to the field input). Used by inline mode. */
    open = () => {
        if (this.formControl.disabled)
            return;
        this.focus();
    };
    clear = ($event) => {
        $event?.stopPropagation();
        this.filteredItems.set([]);
        this.inputControl?.setValue('');
        if (this.valueModel()) {
            this.formControl.setValue(null, { emitEvent: false });
            this.valueModel.set(null);
            this.sdChange.emit(null);
            this.sdSelection.emit({ values: [null], selectedItems: [], value: null, selectedItem: null });
        }
    };
    onAdd = ($event) => {
        $event.stopPropagation();
        $event?.preventDefault();
        this.sdAdd.emit();
    };
    reValidate = () => {
        this.inputControl.updateValueAndValidity({ emitEvent: true });
    };
    #updateValidator = (req, val, inl) => {
        const validators = [];
        const asyncValidators = [];
        if (req)
            validators.push(Validators.required);
        if (val)
            asyncValidators.push(HandleSdCustomValidator(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 });
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdAutocomplete, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.17", type: SdAutocomplete, isStandalone: true, selector: "sd-autocomplete", 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 }, valueField: { classPropertyName: "valueField", publicName: "valueField", isSignal: true, isRequired: false, transformFunction: null }, displayField: { classPropertyName: "displayField", publicName: "displayField", isSignal: true, isRequired: false, transformFunction: null }, disabledField: { classPropertyName: "disabledField", publicName: "disabledField", isSignal: true, isRequired: false, transformFunction: null }, limit: { classPropertyName: "limit", publicName: "limit", isSignal: true, isRequired: false, transformFunction: null }, cacheChecksum: { classPropertyName: "cacheChecksum", publicName: "cacheChecksum", isSignal: true, isRequired: false, transformFunction: null }, hyperlink: { classPropertyName: "hyperlink", publicName: "hyperlink", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, addable: { classPropertyName: "addable", publicName: "addable", 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 }, clearable: { classPropertyName: "clearable", publicName: "clearable", 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 }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange", sdSelection: "sdSelection", sdAdd: "sdAdd" }, host: { properties: { "class.sd-has-label": "!!label()", "class.sd-viewed": "isViewed() || isInline()", "class.sd-bare": "isInline()" } }, queries: [{ propertyName: "sdLabelTemplate", first: true, predicate: ["sdLabel"], descendants: true, isSignal: true }, { propertyName: "sdValueTemplate", first: true, predicate: ["sdValue"], descendants: true, isSignal: true }, { propertyName: "itemDef", first: true, predicate: SdItemDefDefDirective, descendants: true, isSignal: true }, { propertyName: "sdViewDef", first: true, predicate: SdViewDefDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["input"], descendants: true, isSignal: true }, { propertyName: "autocompleteTrigger", first: true, predicate: MatAutocompleteTrigger, descendants: true, isSignal: true }], ngImport: i0, template: "@let lbl = label();\n@let app = appearance();\n@let hideErr = hideInlineError();\n@let errMsg = errorMessage();\n@let hText = helperText();\n@let req = required();\n@let dField = displayField();\n@let disField = disabledField();\n@let iDefTpl = itemDef()?.templateRef;\n@let isLoad = loading();\n@let nVal = $any(normalizedValue());\n@let _isInline = isInline();\n@let _bare = _isInline;\n@let _hasValue = nVal !== undefined && nVal !== null && nVal !== '';\n\n@if (isViewed()) {\n  <sd-view\n    [label]=\"lbl\"\n    [labelTemplate]=\"sdLabelTemplate()\"\n    [value]=\"nVal\"\n    [display]=\"display()\"\n    [hyperlink]=\"hyperlink()\"\n    [valueTemplate]=\"viewTemplate()\">\n  </sd-view>\n} @else {\n  @if (_isInline) {\n    <!-- why: inline \u2014 sd-view l\u00E0 \"m\u1EB7t\" + trigger; autocomplete editor render \u1EA9n (.sd-inline-editor) ch\u1EC9 \u0111\u1EC3 m\u1EDF panel. -->\n    <span class=\"sd-inline-view\" role=\"button\" tabindex=\"0\" (click)=\"enterInlineEdit()\" (keydown.enter)=\"enterInlineEdit()\">\n      <sd-view\n        [label]=\"lbl\"\n        [labelTemplate]=\"sdLabelTemplate()\"\n        [value]=\"nVal\"\n        [display]=\"display()\"\n        [hyperlink]=\"hyperlink()\"\n        [valueTemplate]=\"viewTemplate()\">\n      </sd-view>\n      @if (clearable() && _hasValue && !req && !formControl.disabled) {\n        <button type=\"button\" class=\"sd-inline-clear\" (click)=\"clear($event)\" title=\"X\u00F3a\" aria-label=\"X\u00F3a\">\n          <mat-icon>close</mat-icon>\n        </button>\n      }\n    </span>\n  }\n\n  @if (!app) {\n    <ng-content select=\"[sdLabel]\">\n      @if (lbl) {\n        <sd-label [label]=\"lbl\" [required]=\"req\"></sd-label>\n      }\n    </ng-content>\n  }\n\n  <div\n    class=\"d-flex align-items-center\"\n    [class.sd-inline-editor]=\"_isInline\"\n    [class.c-focused]=\"isFocused\"\n    [class.c-disabled]=\"formControl.disabled\"\n    (click)=\"onClick()\"\n    aria-hidden=\"true\">\n      <mat-form-field\n        [class.sd-md]=\"size() === 'md'\"\n        [class.sd-sm]=\"size() === 'sm'\"\n        [class.hide-inline-error]=\"hideErr\"\n        [floatLabel]=\"nVal ? 'always' : 'auto'\"\n        [appearance]=\"app || 'outline'\">\n        @if (app && lbl) {\n          <mat-label style=\"display: inline-block\">\n            <div style=\"display: flex; align-items: center; gap: 4px\">\n              <span>{{ lbl }}</span>\n              @if (hText) {\n                <mat-icon [matTooltip]=\"hText\" matTooltipPosition=\"below\">info_outline</mat-icon>\n              }\n            </div>\n          </mat-label>\n        }\n\n        <input\n          [id]=\"id\"\n          [formControl]=\"inputControl\"\n          [placeholder]=\"controlPlaceHolder() || ''\"\n          [class.c-selected]=\"nVal\"\n          [matAutocomplete]=\"auto\"\n          (focus)=\"onFocus()\"\n          (blur)=\"onBlur()\"\n          matInput\n          [autocomplete]=\"id\"\n          autocorrect=\"off\"\n          [errorStateMatcher]=\"matcher\"\n          [required]=\"req\"\n          #input\n          #autocompleteTrigger=\"matAutocompleteTrigger\"\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-loading]=\"dataLoading()\"\n          [attr.data-required]=\"dataRequired()\"\n          [attr.data-error-message]=\"dataErrorMessage()\"\n          aria-hidden=\"true\" />\n\n        @if (!isLoad && nVal && !inputControl.disabled && !_bare) {\n          <button type=\"button\" class=\"sd-clear-btn\" matSuffix (click)=\"clear($event)\" title=\"X\u00F3a\" aria-label=\"X\u00F3a\">\n            <mat-icon>close</mat-icon>\n          </button>\n        } @else if (isLoad) {\n          <mat-spinner [diameter]=\"20\" matSuffix></mat-spinner>\n        } @else {\n          <mat-icon class=\"cursor-pointer sd-suffix-icon\" matSuffix>search</mat-icon>\n        }\n\n        <mat-autocomplete #auto=\"matAutocomplete\" (optionSelected)=\"onSelect($event.option.value)\" class=\"sd-autocomplete-panel\">\n          @let itemsList = filteredItems();\n\n          @if (itemsList?.length) {\n            @for (item of itemsList; track $index) {\n              <mat-option\n                [value]=\"item\"\n                matTooltipPosition=\"above\"\n                [matTooltip]=\"dField ? getNestedValue(item, dField) : item\"\n                [disabled]=\"disField ? getNestedValue(item, disField) : false\">\n                @if (iDefTpl) {\n                  <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                } @else {\n                  {{ dField ? getNestedValue(item, dField) : item }}\n                }\n              </mat-option>\n            }\n          } @else if (!itemsList?.length && inputControl.value && !isTyping() && !isLoad) {}\n\n          @if (addable() && sdAdd.observed) {\n            <mat-option class=\"sd__option--add\" (keyup.Space)=\"$event.stopPropagation()\" disabled=\"true\">\n              <div (click)=\"onAdd($event)\">\n                <mat-icon class=\"mr-1\">add</mat-icon>\n                {{ 'New item' }}\n              </div>\n            </mat-option>\n          }\n        </mat-autocomplete>\n\n        @if (hideErr && errMsg && formControl.touched) {\n          <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"errMsg\" matTooltipPosition=\"above\"> error </mat-icon>\n        }\n\n        @if (!hideErr && errMsg && formControl.touched) {\n          <mat-error>{{ errMsg }}</mat-error>\n        }\n      </mat-form-field>\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}:host(.sd-bare){position:relative}.sd-inline-view{cursor:pointer;display:inline-flex;align-items:center;width:100%;padding:1px 6px;border-radius:4px;background-color:#0000000a;transition:background-color .15s ease}.sd-inline-view:hover{background-color:#00000014}.sd-inline-view .sd-inline-clear{display:none;align-items:center;margin-left:4px;padding:0;border:0;background:transparent;cursor:pointer;line-height:0;color:var(--sd-text-secondary, #6b7280);transition:color .15s ease}.sd-inline-view .sd-inline-clear mat-icon{font-size:16px;width:16px;height:16px}.sd-inline-view .sd-inline-clear:hover{color:var(--sd-error, #b32626)}.sd-inline-view:hover .sd-inline-clear{display:inline-flex}.sd-inline-editor{position:absolute;inset:0;opacity:0;pointer-events:none}.sd-inline-editor ::ng-deep *{pointer-events:none!important}:host{display:block}:host(.sd-has-label){padding-top:4px}:host(.sd-viewed){padding-top:0}: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.c-selected::placeholder{color:#000;opacity:1}:host ::ng-deep .mat-mdc-form-field input.c-selected:-ms-input-placeholder{color:#000}:host ::ng-deep .mat-mdc-form-field input.c-selected::-ms-input-placeholder{color:#000}: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 input.mat-mdc-input-element:disabled.c-selected::placeholder{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field input.mat-mdc-input-element:disabled.c-selected:-ms-input-placeholder{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field input.mat-mdc-input-element:disabled.c-selected::-ms-input-placeholder{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}:host ::ng-deep .mat-mdc-form-field:hover .icon-copy{opacity:1}:host ::ng-deep .mat-mdc-form-field .icon-copy{cursor:pointer;width:.9em;height:.9em;fill:#00000080;transition:opacity .2s linear;opacity:0}::ng-deep .sd-autocomplete-panel .mat-mdc-option{min-height:36px!important;padding:8px 12px!important}::ng-deep .sd-autocomplete-panel .mdc-list-item__primary-text{font-size:14px!important;line-height:normal}::ng-deep .sd-autocomplete-panel .mat-pseudo-checkbox{transform:scale(.7);margin-right:8px!important}::ng-deep .sd-autocomplete-panel .mat-pseudo-checkbox-minimal{transform:scale(.7);transform-origin:center right}.sd__option--add{position:sticky;bottom:0;background-color:#fff;z-index:10;color:#000000de;cursor:pointer!important}.c-loading-icon{position:absolute;right:5px;top:5px}\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: MatInputModule }, { kind: "directive", type: i3.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: "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: MatTooltipModule }, { kind: "directive", type: i4.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "ngmodule", type: MatAutocompleteModule }, { kind: "component", type: i5.MatAutocomplete, selector: "mat-autocomplete", inputs: ["aria-label", "aria-labelledby", "displayWith", "autoActiveFirstOption", "autoSelectActiveOption", "requireSelection", "panelWidth", "disableRipple", "class", "hideSingleSelectionIndicator"], outputs: ["optionSelected", "opened", "closed", "optionActivated"], exportAs: ["matAutocomplete"] }, { kind: "component", type: i5.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "directive", type: i5.MatAutocompleteTrigger, selector: "input[matAutocomplete], textarea[matAutocomplete]", inputs: ["matAutocomplete", "matAutocompletePosition", "matAutocompleteConnectedTo", "autocomplete", "matAutocompleteDisabled"], exportAs: ["matAutocompleteTrigger"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i6.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatProgressSpinnerModule }, { kind: "component", type: i7.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "mode", "value", "diameter", "strokeWidth"], exportAs: ["matProgressSpinner"] }, { 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", "selectedItems"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdAutocomplete, decorators: [{
            type: Component,
            args: [{ selector: 'sd-autocomplete', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, host: { '[class.sd-has-label]': '!!label()', '[class.sd-viewed]': 'isViewed() || isInline()', '[class.sd-bare]': 'isInline()' }, imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        MatInputModule,
                        MatTooltipModule,
                        MatFormFieldModule,
                        MatAutocompleteModule,
                        MatIconModule,
                        MatProgressSpinnerModule,
                        SdLabel,
                        SdView,
                    ], template: "@let lbl = label();\n@let app = appearance();\n@let hideErr = hideInlineError();\n@let errMsg = errorMessage();\n@let hText = helperText();\n@let req = required();\n@let dField = displayField();\n@let disField = disabledField();\n@let iDefTpl = itemDef()?.templateRef;\n@let isLoad = loading();\n@let nVal = $any(normalizedValue());\n@let _isInline = isInline();\n@let _bare = _isInline;\n@let _hasValue = nVal !== undefined && nVal !== null && nVal !== '';\n\n@if (isViewed()) {\n  <sd-view\n    [label]=\"lbl\"\n    [labelTemplate]=\"sdLabelTemplate()\"\n    [value]=\"nVal\"\n    [display]=\"display()\"\n    [hyperlink]=\"hyperlink()\"\n    [valueTemplate]=\"viewTemplate()\">\n  </sd-view>\n} @else {\n  @if (_isInline) {\n    <!-- why: inline \u2014 sd-view l\u00E0 \"m\u1EB7t\" + trigger; autocomplete editor render \u1EA9n (.sd-inline-editor) ch\u1EC9 \u0111\u1EC3 m\u1EDF panel. -->\n    <span class=\"sd-inline-view\" role=\"button\" tabindex=\"0\" (click)=\"enterInlineEdit()\" (keydown.enter)=\"enterInlineEdit()\">\n      <sd-view\n        [label]=\"lbl\"\n        [labelTemplate]=\"sdLabelTemplate()\"\n        [value]=\"nVal\"\n        [display]=\"display()\"\n        [hyperlink]=\"hyperlink()\"\n        [valueTemplate]=\"viewTemplate()\">\n      </sd-view>\n      @if (clearable() && _hasValue && !req && !formControl.disabled) {\n        <button type=\"button\" class=\"sd-inline-clear\" (click)=\"clear($event)\" title=\"X\u00F3a\" aria-label=\"X\u00F3a\">\n          <mat-icon>close</mat-icon>\n        </button>\n      }\n    </span>\n  }\n\n  @if (!app) {\n    <ng-content select=\"[sdLabel]\">\n      @if (lbl) {\n        <sd-label [label]=\"lbl\" [required]=\"req\"></sd-label>\n      }\n    </ng-content>\n  }\n\n  <div\n    class=\"d-flex align-items-center\"\n    [class.sd-inline-editor]=\"_isInline\"\n    [class.c-focused]=\"isFocused\"\n    [class.c-disabled]=\"formControl.disabled\"\n    (click)=\"onClick()\"\n    aria-hidden=\"true\">\n      <mat-form-field\n        [class.sd-md]=\"size() === 'md'\"\n        [class.sd-sm]=\"size() === 'sm'\"\n        [class.hide-inline-error]=\"hideErr\"\n        [floatLabel]=\"nVal ? 'always' : 'auto'\"\n        [appearance]=\"app || 'outline'\">\n        @if (app && lbl) {\n          <mat-label style=\"display: inline-block\">\n            <div style=\"display: flex; align-items: center; gap: 4px\">\n              <span>{{ lbl }}</span>\n              @if (hText) {\n                <mat-icon [matTooltip]=\"hText\" matTooltipPosition=\"below\">info_outline</mat-icon>\n              }\n            </div>\n          </mat-label>\n        }\n\n        <input\n          [id]=\"id\"\n          [formControl]=\"inputControl\"\n          [placeholder]=\"controlPlaceHolder() || ''\"\n          [class.c-selected]=\"nVal\"\n          [matAutocomplete]=\"auto\"\n          (focus)=\"onFocus()\"\n          (blur)=\"onBlur()\"\n          matInput\n          [autocomplete]=\"id\"\n          autocorrect=\"off\"\n          [errorStateMatcher]=\"matcher\"\n          [required]=\"req\"\n          #input\n          #autocompleteTrigger=\"matAutocompleteTrigger\"\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-loading]=\"dataLoading()\"\n          [attr.data-required]=\"dataRequired()\"\n          [attr.data-error-message]=\"dataErrorMessage()\"\n          aria-hidden=\"true\" />\n\n        @if (!isLoad && nVal && !inputControl.disabled && !_bare) {\n          <button type=\"button\" class=\"sd-clear-btn\" matSuffix (click)=\"clear($event)\" title=\"X\u00F3a\" aria-label=\"X\u00F3a\">\n            <mat-icon>close</mat-icon>\n          </button>\n        } @else if (isLoad) {\n          <mat-spinner [diameter]=\"20\" matSuffix></mat-spinner>\n        } @else {\n          <mat-icon class=\"cursor-pointer sd-suffix-icon\" matSuffix>search</mat-icon>\n        }\n\n        <mat-autocomplete #auto=\"matAutocomplete\" (optionSelected)=\"onSelect($event.option.value)\" class=\"sd-autocomplete-panel\">\n          @let itemsList = filteredItems();\n\n          @if (itemsList?.length) {\n            @for (item of itemsList; track $index) {\n              <mat-option\n                [value]=\"item\"\n                matTooltipPosition=\"above\"\n                [matTooltip]=\"dField ? getNestedValue(item, dField) : item\"\n                [disabled]=\"disField ? getNestedValue(item, disField) : false\">\n                @if (iDefTpl) {\n                  <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                } @else {\n                  {{ dField ? getNestedValue(item, dField) : item }}\n                }\n              </mat-option>\n            }\n          } @else if (!itemsList?.length && inputControl.value && !isTyping() && !isLoad) {}\n\n          @if (addable() && sdAdd.observed) {\n            <mat-option class=\"sd__option--add\" (keyup.Space)=\"$event.stopPropagation()\" disabled=\"true\">\n              <div (click)=\"onAdd($event)\">\n                <mat-icon class=\"mr-1\">add</mat-icon>\n                {{ 'New item' }}\n              </div>\n            </mat-option>\n          }\n        </mat-autocomplete>\n\n        @if (hideErr && errMsg && formControl.touched) {\n          <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"errMsg\" matTooltipPosition=\"above\"> error </mat-icon>\n        }\n\n        @if (!hideErr && errMsg && formControl.touched) {\n          <mat-error>{{ errMsg }}</mat-error>\n        }\n      </mat-form-field>\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}:host(.sd-bare){position:relative}.sd-inline-view{cursor:pointer;display:inline-flex;align-items:center;width:100%;padding:1px 6px;border-radius:4px;background-color:#0000000a;transition:background-color .15s ease}.sd-inline-view:hover{background-color:#00000014}.sd-inline-view .sd-inline-clear{display:none;align-items:center;margin-left:4px;padding:0;border:0;background:transparent;cursor:pointer;line-height:0;color:var(--sd-text-secondary, #6b7280);transition:color .15s ease}.sd-inline-view .sd-inline-clear mat-icon{font-size:16px;width:16px;height:16px}.sd-inline-view .sd-inline-clear:hover{color:var(--sd-error, #b32626)}.sd-inline-view:hover .sd-inline-clear{display:inline-flex}.sd-inline-editor{position:absolute;inset:0;opacity:0;pointer-events:none}.sd-inline-editor ::ng-deep *{pointer-events:none!important}:host{display:block}:host(.sd-has-label){padding-top:4px}:host(.sd-viewed){padding-top:0}: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.c-selected::placeholder{color:#000;opacity:1}:host ::ng-deep .mat-mdc-form-field input.c-selected:-ms-input-placeholder{color:#000}:host ::ng-deep .mat-mdc-form-field input.c-selected::-ms-input-placeholder{color:#000}: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 input.mat-mdc-input-element:disabled.c-selected::placeholder{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field input.mat-mdc-input-element:disabled.c-selected:-ms-input-placeholder{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field input.mat-mdc-input-element:disabled.c-selected::-ms-input-placeholder{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}:host ::ng-deep .mat-mdc-form-field:hover .icon-copy{opacity:1}:host ::ng-deep .mat-mdc-form-field .icon-copy{cursor:pointer;width:.9em;height:.9em;fill:#00000080;transition:opacity .2s linear;opacity:0}::ng-deep .sd-autocomplete-panel .mat-mdc-option{min-height:36px!important;padding:8px 12px!important}::ng-deep .sd-autocomplete-panel .mdc-list-item__primary-text{font-size:14px!important;line-height:normal}::ng-deep .sd-autocomplete-panel .mat-pseudo-checkbox{transform:scale(.7);margin-right:8px!important}::ng-deep .sd-autocomplete-panel .mat-pseudo-checkbox-minimal{transform:scale(.7);transform-origin:center right}.sd__option--add{position:sticky;bottom:0;background-color:#fff;z-index:10;color:#000000de;cursor:pointer!important}.c-loading-icon{position:absolute;right:5px;top:5px}\n"] }]
        }], ctorParameters: () => [], propDecorators: { inputRef: [{ type: i0.ViewChild, args: ['input', { isSignal: true }] }], autocompleteTrigger: [{ type: i0.ViewChild, args: [i0.forwardRef(() => MatAutocompleteTrigger), { isSignal: true }] }], sdLabelTemplate: [{ type: i0.ContentChild, args: ['sdLabel', { isSignal: true }] }], sdValueTemplate: [{ type: i0.ContentChild, args: ['sdValue', { isSignal: true }] }], itemDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdItemDefDefDirective), { isSignal: true }] }], sdViewDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdViewDefDirective), { 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 }] }], valueField: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueField", required: false }] }], displayField: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayField", required: false }] }], disabledField: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabledField", required: false }] }], limit: [{ type: i0.Input, args: [{ isSignal: true, alias: "limit", required: false }] }], cacheChecksum: [{ type: i0.Input, args: [{ isSignal: true, alias: "cacheChecksum", required: false }] }], hyperlink: [{ type: i0.Input, args: [{ isSignal: true, alias: "hyperlink", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], hideInlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideInlineError", required: false }] }], addable: [{ type: i0.Input, args: [{ isSignal: true, alias: "addable", 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 }] }], clearable: [{ type: i0.Input, args: [{ isSignal: true, alias: "clearable", 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 }] }], valueModel: [{ type: i0.Input, args: [{ isSignal: true, alias: "model", required: false }] }, { type: i0.Output, args: ["modelChange"] }], sdChange: [{ type: i0.Output, args: ["sdChange"] }], sdSelection: [{ type: i0.Output, args: ["sdSelection"] }], sdAdd: [{
                type: Output
            }] } });

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

export { SdAutocomplete };
//# sourceMappingURL=sdcorejs-angular-forms-autocomplete.mjs.map
