import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, TemplateRef, input, Directive, viewChild, contentChild, contentChildren, computed, ChangeDetectorRef, ElementRef, booleanAttribute, model, output, signal, isSignal, DestroyRef, effect, untracked, ChangeDetectionStrategy, Component } from '@angular/core';
import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
import * as i2 from '@angular/forms';
import { NgForm, FormGroup, FormControl, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i5 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i3 from '@angular/material/input';
import { MatInput, MatInputModule } from '@angular/material/input';
import * as i7 from '@angular/material/progress-spinner';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import * as i6 from '@angular/material/select';
import { MatSelectModule } from '@angular/material/select';
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 { Utilities, StringUtilities, ArrayUtilities } from '@sdcorejs/angular/utilities/extensions';
import { timer, combineLatest } from 'rxjs';
import { tap, map, startWith, debounce, switchMap } from 'rxjs/operators';

class SdSelectFooterActionDirective {
    templateRef = inject((TemplateRef));
    when = input('always', ...(ngDevMode ? [{ debugName: "when" }] : /* istanbul ignore next */ []));
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdSelectFooterActionDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.17", type: SdSelectFooterActionDirective, isStandalone: true, selector: "ng-template[sdSelectFooterAction]", inputs: { when: { classPropertyName: "when", publicName: "when", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdSelectFooterActionDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: 'ng-template[sdSelectFooterAction]',
                    standalone: true,
                }]
        }], propDecorators: { when: [{ type: i0.Input, args: [{ isSignal: true, alias: "when", required: false }] }] } });

/* eslint-disable @angular-eslint/no-input-rename */
/* eslint-disable @typescript-eslint/no-explicit-any */
class SdSelect {
    id = `I${Utilities.generateUuid()}`;
    // ==========================================
    // 1. SIGNAL QUERIES & INJECTS
    // ==========================================
    matInputRef = viewChild(MatInput, ...(ngDevMode ? [{ debugName: "matInputRef" }] : /* istanbul ignore next */ []));
    selectRef = viewChild('select', ...(ngDevMode ? [{ debugName: "selectRef" }] : /* istanbul ignore next */ []));
    sdLabelTemplate = contentChild('sdLabel', ...(ngDevMode ? [{ debugName: "sdLabelTemplate" }] : /* istanbul ignore next */ []));
    sdValueTemplate = contentChild('sdValue', ...(ngDevMode ? [{ debugName: "sdValueTemplate" }] : /* istanbul ignore next */ []));
    /**
     * Custom render for the SELECTED value shown in the editable trigger (`<mat-select-trigger>`).
     * Distinct from `#sdValue`/`sdViewDef` which only drive the read-only `viewed`/`inline` face.
     * Context: `{ $implicit, item, items: selectedItems(), display, multiple }` — `item`/`$implicit`
     * is the single selected item object (single mode) or the selected-item array (multiple mode).
     * Falls back to the plain `display` text when not projected, so existing usages are unaffected.
     */
    sdSelectedTemplate = contentChild('sdSelected', ...(ngDevMode ? [{ debugName: "sdSelectedTemplate" }] : /* istanbul ignore next */ []));
    itemDef = contentChild(SdItemDefDefDirective, ...(ngDevMode ? [{ debugName: "itemDef" }] : /* istanbul ignore next */ []));
    sdViewDef = contentChild(SdViewDefDirective, ...(ngDevMode ? [{ debugName: "sdViewDef" }] : /* istanbul ignore next */ []));
    footerActions = contentChildren(SdSelectFooterActionDirective, ...(ngDevMode ? [{ debugName: "footerActions" }] : /* istanbul ignore next */ []));
    /**
     * View display template. `sdViewDef` is now just a custom override of the view rendering —
     * it replaces the projected `#sdValue` template when present (fed into `<sd-view>`'s
     * `valueTemplate`), so there is ONE rendering path. No more `.sd-view` class / focus-swap;
     * click-to-edit is governed by `viewed='inline'`.
     */
    viewTemplate = computed(() => this.sdViewDef()?.templateRef ?? this.sdValueTemplate(), ...(ngDevMode ? [{ debugName: "viewTemplate" }] : /* istanbul ignore next */ []));
    #ref = inject(ChangeDetectorRef);
    #formConfiguration = inject(SD_FORM_CONFIGURATION, { optional: true });
    #el = inject(ElementRef);
    #i18n = inject(I18nService);
    // ==========================================
    // 2. SIGNAL INPUTS & MODEL
    // ==========================================
    autoIdInput = input(undefined, { ...(ngDevMode ? { debugName: "autoIdInput" } : /* istanbul ignore next */ {}), alias: 'autoId' });
    autoId = computed(() => (this.autoIdInput() ? `forms-select-${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(Utilities.generateUuid(), ...(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.required(...(ngDevMode ? [{ debugName: "valueField" }] : /* istanbul ignore next */ []));
    displayField = input.required(...(ngDevMode ? [{ debugName: "displayField" }] : /* istanbul ignore next */ []));
    disabledField = input('', ...(ngDevMode ? [{ debugName: "disabledField" }] : /* istanbul ignore next */ []));
    cacheChecksum = input(...(ngDevMode ? [undefined, { debugName: "cacheChecksum" }] : /* istanbul ignore next */ []));
    limit = input(50, ...(ngDevMode ? [{ debugName: "limit" }] : /* istanbul ignore next */ []));
    hyperlink = input(...(ngDevMode ? [undefined, { debugName: "hyperlink" }] : /* istanbul ignore next */ []));
    minWidthPanel = input('auto', { ...(ngDevMode ? { debugName: "minWidthPanel" } : /* istanbul ignore next */ {}), transform: value => value ?? 'auto' });
    hideInlineError = input(false, { ...(ngDevMode ? { debugName: "hideInlineError" } : /* 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 (bare editor). */
    viewed = input(false, { ...(ngDevMode ? { debugName: "viewed" } : /* istanbul ignore next */ {}), transform: sdViewedTransform });
    multiple = input(false, { ...(ngDevMode ? { debugName: "multiple" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    /**
     * Whether the `viewed='inline'` text face shows a hover clear-× to empty the value.
     * Default `true`. Set `false` where the HOST owns removal (e.g. `<sd-query-bar>` chips,
     * whose own `×` removes the whole filter) so the chip isn't cluttered with two ×.
     */
    clearable = input(true, { ...(ngDevMode ? { debugName: "clearable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    // Tri-state `viewed` (isViewed / isInline) — shared primitive. In `'inline'` the editor is
    // always rendered (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'` — editor mounted but chrome hidden; sd-view text is the trigger face. */
    isInline = this.#viewedState.isInline;
    /** `true` when `viewed === true` — static read-only view, no editor mounted. */
    isViewed = this.#viewedState.isViewed;
    /** Open the picker from the inline text face. No-op unless `viewed='inline'`. */
    enterInlineEdit = () => this.#viewedState.enterInlineEdit();
    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.select.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.#formConfiguration?.appearance ?? 'outline', ...(ngDevMode ? [{ debugName: "appearance" }] : /* istanbul ignore next */ []));
    floatLabel = input('auto', ...(ngDevMode ? [{ debugName: "floatLabel" }] : /* istanbul ignore next */ []));
    // Mở rộng kiểu dữ liệu cho phép nhận Signal từ bên ngoài truyền vào
    items = input(...(ngDevMode ? [undefined, { debugName: "items" }] : /* istanbul ignore next */ []));
    valueModel = model(undefined, { ...(ngDevMode ? { debugName: "valueModel" } : /* istanbul ignore next */ {}), alias: 'model' });
    // ==========================================
    // 3. SIGNAL OUTPUTS
    // ==========================================
    sdChange = output();
    sdSelection = output();
    // ==========================================
    // 4. INTERNAL STATE & STREAMS
    // ==========================================
    formControl = new SdFormControl();
    inputControl = new FormControl('');
    loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
    focused = signal(false, ...(ngDevMode ? [{ debugName: "focused" }] : /* istanbul ignore next */ []));
    allSelected = false;
    #cache = {};
    #allItem = {};
    #searchRequestId = 0;
    #hashedValue;
    // [NÂNG CẤP]: Xử lý Unwrap (Mở hộp) Signal lồng nhau nếu có
    actualItems = computed(() => {
        const rawItems = this.items();
        // Nếu cha truyền vào một biến Signal, ta cần gọi rawItems() để lấy mảng thật
        if (isSignal(rawItems)) {
            return rawItems();
        }
        return rawItems;
    }, ...(ngDevMode ? [{ debugName: "actualItems" }] : /* istanbul ignore next */ []));
    // Thay vì toObservable(this.items), ta observe cái actualItems đã được unwrap
    #items$ = toObservable(this.actualItems);
    #valueModel$ = toObservable(this.valueModel);
    filteredItems = signal([], ...(ngDevMode ? [{ debugName: "filteredItems" }] : /* istanbul ignore next */ []));
    selectedItems = signal([], ...(ngDevMode ? [{ debugName: "selectedItems" }] : /* istanbul ignore next */ []));
    display = signal('', ...(ngDevMode ? [{ debugName: "display" }] : /* istanbul ignore next */ []));
    calculatedPanelWidth = signal('auto', ...(ngDevMode ? [{ debugName: "calculatedPanelWidth" }] : /* istanbul ignore next */ []));
    searchText = signal('', ...(ngDevMode ? [{ debugName: "searchText" }] : /* istanbul ignore next */ []));
    footerActionContext = computed(() => ({ searchText: this.searchText() }), ...(ngDevMode ? [{ debugName: "footerActionContext" }] : /* istanbul ignore next */ []));
    visibleFooterActions = computed(() => this.footerActions().filter(action => this.shouldRenderFooterAction(action)), ...(ngDevMode ? [{ debugName: "visibleFooterActions" }] : /* istanbul ignore next */ []));
    normalizedValue = computed(() => {
        const val = this.valueModel();
        if (this.multiple() && val !== undefined && val !== null && !Array.isArray(val)) {
            return [val];
        }
        return val;
    }, ...(ngDevMode ? [{ debugName: "normalizedValue" }] : /* istanbul ignore next */ []));
    filtered = computed(() => {
        const data = this.actualItems();
        if (typeof data === 'function')
            return true;
        if (Array.isArray(data))
            return data.filter(e => e != null).length > 10;
        return false;
    }, ...(ngDevMode ? [{ debugName: "filtered" }] : /* istanbul ignore next */ []));
    delayTime = computed(() => (typeof this.actualItems() === 'function' ? 500 : 0), ...(ngDevMode ? [{ debugName: "delayTime" }] : /* istanbul ignore next */ []));
    // ==========================================
    // 5. GETTER & HELPERS
    // ==========================================
    itemValue = (item) => {
        const path = this.valueField();
        if (!path || item == null)
            return item;
        return Utilities.getNestedValue(item, path);
    };
    itemDisplay = (item) => {
        const path = this.displayField();
        if (!path || item == null)
            return String(item ?? '');
        return String(Utilities.getNestedValue(item, path) ?? '');
    };
    itemDisabled = (item) => {
        const path = this.disabledField();
        if (!path || item == null)
            return false;
        return Boolean(Utilities.getNestedValue(item, path));
    };
    shouldRenderFooterAction(action) {
        const when = action.when();
        if (when === 'always')
            return true;
        if (when === 'empty')
            return this.searchText().length > 0 && this.filteredItems().length === 0;
        if (when === 'has-result')
            return this.filteredItems().length > 0;
        return false;
    }
    setNestedValue = (obj, path, value) => {
        if (!path)
            return;
        const keys = path.split('.');
        let current = obj;
        for (let i = 0; i < keys.length - 1; i++) {
            if (!current[keys[i]])
                current[keys[i]] = {};
            current = current[keys[i]];
        }
        current[keys[keys.length - 1]] = value;
    };
    #addToDict = (dataList) => {
        if (!this.valueField())
            return;
        dataList.forEach(e => {
            const k = this.itemValue(e);
            if (k != null)
                this.#allItem[String(k)] = e;
        });
    };
    tooltip = computed(() => {
        const items = this.selectedItems();
        if (!items || !items.length)
            return '';
        const vF = this.valueField();
        return items.map(item => (vF ? `• ${this.itemValue(item)} - ${this.itemDisplay(item)}` : `• ${item}`)).join('\n');
    }, ...(ngDevMode ? [{ debugName: "tooltip" }] : /* istanbul ignore next */ []));
    updatePanelWidth = () => {
        let minWInput = this.minWidthPanel();
        // why: inline mode — trigger là text hẹp (.sd-inline-view), panel tối thiểu 200px cho dễ đọc options.
        if (this.isInline() && (!minWInput || minWInput === 'auto'))
            minWInput = '200px';
        if (!minWInput || minWInput === 'auto') {
            this.calculatedPanelWidth.set('auto');
            return;
        }
        const minWStr = String(minWInput).trim().toLowerCase();
        if (!minWStr.endsWith('px') && isNaN(Number(minWStr))) {
            this.calculatedPanelWidth.set(minWInput);
            return;
        }
        const hostWidth = this.#el.nativeElement.getBoundingClientRect().width;
        const minW = parseFloat(minWStr);
        if (hostWidth >= minW) {
            this.calculatedPanelWidth.set('auto');
        }
        else {
            this.calculatedPanelWidth.set(minWInput);
        }
    };
    #destroyRef = inject(DestroyRef);
    constructor() {
        effect(() => {
            const val = this.normalizedValue();
            untracked(() => {
                const current = this.formControl.value;
                const isDiff = Array.isArray(val) && Array.isArray(current) ? JSON.stringify(val) !== JSON.stringify(current) : val !== current;
                if (isDiff) {
                    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 val = this.validator();
            const inl = this.inlineError();
            untracked(() => this.#updateValidator(req, val, inl));
        });
        // ==========================================
        // EFFECT: QUẢN LÝ FORM GROUP & CONTROL
        // ==========================================
        effect(onCleanup => {
            // 1. Lấy giá trị mới nhất của form và name
            const formGroup = this.form();
            const controlName = this.name();
            if (formGroup && controlName) {
                // 2. Thêm control vào form
                formGroup.addControl(controlName, this.formControl);
                // 3. Đăng ký hàm dọn dẹp (Cleanup)
                onCleanup(() => {
                    // Hàm này sẽ tự động chạy trong 2 trường hợp:
                    // - Khi Component bị Destroy (thay thế ngOnDestroy)
                    // - Khi form() hoặc name() thay đổi giá trị (nó sẽ gỡ control cũ ra trước khi add cái mới vào)
                    formGroup.removeControl(controlName);
                });
            }
        });
    }
    ngOnInit() {
        this.formControl.valueChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(val => {
            const currentModel = this.valueModel();
            const isDiff = Array.isArray(val) && Array.isArray(currentModel) ? JSON.stringify(val) !== JSON.stringify(currentModel) : val !== currentModel;
            if (isDiff) {
                this.valueModel.set(val);
            }
        });
        this.formControl.sdChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#ref.markForCheck());
        const cleanItems$ = this.#items$.pipe(tap(() => {
            this.#cache = {};
            this.inputControl.setValue('');
        }), map(items => {
            if (!items)
                return [];
            if (Array.isArray(items))
                return items.filter(e => e !== null && e !== undefined);
            return items;
        }));
        const search$ = this.inputControl.valueChanges.pipe(startWith(''), tap(searchText => this.searchText.set(searchText?.toString() || '')), tap(() => {
            if (typeof this.actualItems() === 'function' && this.focused()) {
                this.loading.set(true);
                this.#ref.markForCheck();
            }
        }), debounce(() => timer(this.delayTime())));
        const allItems$ = combineLatest([cleanItems$, search$, this.#valueModel$]).pipe(switchMap(async ([items, searchText]) => {
            const sText = searchText || '';
            const formValue = this.valueModel();
            const vField = this.valueField();
            if (typeof items === 'function') {
                return await this.#loadItems(sText, items);
            }
            this.#addToDict(items);
            const isArray = Array.isArray(formValue);
            const hasFields = !!vField && !!this.displayField();
            const filteredList = items.filter(item => {
                const value = hasFields ? this.itemValue(item) : item;
                const display = hasFields ? this.itemDisplay(item) : item;
                if (StringUtilities.aliasIncludes(value, sText) || StringUtilities.aliasIncludes(display, sText))
                    return true;
                if (isArray)
                    return formValue.some((e) => e === value);
                return formValue === value;
            });
            // Khi filtered mode bật và multiple=true, luôn đẩy item đã chọn lên trên
            // để user dễ nhìn thấy selection hiện tại, kể cả dataset chưa vượt limit.
            const shouldPinSelectedFirst = this.filtered() && this.multiple() && isArray;
            if (!shouldPinSelectedFirst && items.length <= this.limit())
                return filteredList;
            return filteredList.sort((current, next) => {
                const value1 = hasFields ? this.itemValue(current) : current;
                const value2 = hasFields ? this.itemValue(next) : next;
                let flag1 = 0;
                let flag2 = 0;
                if (isArray) {
                    flag1 = formValue.some((e) => e === value1) ? 1 : 0;
                    flag2 = formValue.some((e) => e === value2) ? 1 : 0;
                    return flag2 - flag1;
                }
                flag1 = formValue === value1 ? 1 : 0;
                flag2 = formValue === value2 ? 1 : 0;
                return flag2 - flag1;
            });
        }), tap(() => {
            this.loading.set(false);
            this.#ref.markForCheck();
        }));
        const selectedItems$ = combineLatest([cleanItems$, this.#valueModel$]).pipe(switchMap(async ([items, val]) => {
            const vField = this.valueField();
            const dField = this.displayField();
            if (val === undefined || val === null || val === '')
                return [];
            const values = Array.isArray(val) ? val : [val];
            if (!vField)
                return values;
            if (typeof items === 'function') {
                return await this.#loadSelectedItems(val, items);
            }
            return values.map(value => {
                return (items?.find(item => this.itemValue(item) === value) || {
                    [vField]: value,
                    [dField]: value,
                });
            });
        }));
        const filteredItems$ = allItems$.pipe(map(allItems => {
            const limit = this.limit();
            const val = this.valueModel();
            if (!this.multiple() || !Array.isArray(val) || val.length === 0) {
                return ArrayUtilities.paging(allItems, limit);
            }
            // multiple mode: keep ALL selected items (for checkmarks) + limit unselected items
            // why: if selected.length >= limit, paging would show only selected items → user can't pick new ones
            const vField = this.valueField();
            const selectedSet = new Set(val.map(String));
            const selected = [];
            const unselected = [];
            for (const item of allItems) {
                const itemVal = vField ? String(this.itemValue(item) ?? '') : String(item ?? '');
                if (selectedSet.has(itemVal)) {
                    selected.push(item);
                }
                else {
                    unselected.push(item);
                }
            }
            return [...selected, ...ArrayUtilities.paging(unselected, limit)];
        }));
        const display$ = selectedItems$.pipe(map(items => items?.map(item => (this.displayField() ? this.itemDisplay(item) : item))?.join(', ') || ''));
        filteredItems$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(val => {
            this.filteredItems.set(val || []);
            this.#ref.markForCheck();
        });
        selectedItems$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(val => {
            this.selectedItems.set(val || []);
            this.#ref.markForCheck();
        });
        display$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(val => {
            this.display.set(val || '');
            this.#ref.markForCheck();
        });
    }
    #updateValidator = (req, val, inl) => {
        this.formControl.clearValidators();
        this.formControl.clearAsyncValidators();
        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 });
    };
    #loadSelectedItems = async (value, items) => {
        if (value === undefined || value === null || value === '')
            return [];
        const values = Array.isArray(value) ? value : [value];
        const vField = this.valueField();
        const dField = this.displayField();
        if (!vField && !dField)
            return values;
        if (values.some(val => this.#allItem[val?.toString()] === undefined)) {
            const results = await items({ type: 'VALUE', value }).catch(() => []);
            this.#addToDict(results);
            const objValue = {};
            values.forEach(val => {
                const dummy = {};
                this.setNestedValue(dummy, vField, val);
                if (dField)
                    this.setNestedValue(dummy, dField, val);
                objValue[String(val)] = dummy;
            });
            this.#allItem = { ...objValue, ...this.#allItem };
        }
        return values.map(val => {
            if (this.#allItem[val?.toString()])
                return this.#allItem[val?.toString()];
            const dummy = {};
            this.setNestedValue(dummy, vField, val);
            if (dField)
                this.setNestedValue(dummy, dField, val);
            return dummy;
        });
    };
    #loadItems = async (searchText, items) => {
        searchText = searchText?.toString() || '';
        const key = Utilities.hash({ checksum: this.cacheChecksum() || null, searchText });
        this.#searchRequestId++;
        const currentRequestId = this.#searchRequestId;
        if (this.#cache[key] === undefined && this.focused()) {
            const results = await items({ type: 'SEARCH', searchText }).catch(() => []);
            if (currentRequestId !== this.#searchRequestId)
                return [];
            this.#addToDict(results);
            const mapObj = new Map();
            results.forEach(e => {
                const k = this.itemValue(e);
                if (k != null && !mapObj.has(k))
                    mapObj.set(k, e);
            });
            this.#cache[key] = Array.from(mapObj.values());
        }
        const selectedItems = await this.#loadSelectedItems(this.valueModel(), items);
        if (currentRequestId !== this.#searchRequestId)
            return [];
        const finalMap = new Map();
        [...selectedItems, ...(this.#cache[key] || [])].forEach(e => {
            const k = this.itemValue(e);
            if (k != null && !finalMap.has(k))
                finalMap.set(k, e);
        });
        return Array.from(finalMap.values());
    };
    onSelectionChange = (change) => {
        this.allSelected = !this.selectRef()?.options.some(e => !e.selected);
        const value = change?.value ?? '';
        if (this.multiple()) {
            this.formControl.setValue(value || [], { emitEvent: false });
            this.#onChange(value || []);
        }
        else {
            this.inputControl.setValue('');
            this.formControl.setValue(value, { emitEvent: false });
            this.#onChange(value);
        }
    };
    reValidate = () => {
        this.formControl.updateValueAndValidity({ emitEvent: true });
    };
    // Chỉ cập nhật model binding, KHÔNG emit event.
    // sdChange + sdSelection sẽ chỉ được emit khi panel đóng (onOpenedChange).
    #onChange = async (value) => {
        this.valueModel.set(value);
    };
    clear = ($event) => {
        $event?.stopPropagation();
        if (this.multiple()) {
            this.formControl.setValue([]);
            this.valueModel.set([]);
            this.sdChange.emit([]);
            this.sdSelection.emit({ multiple: true, values: [], selectedItems: [], value: undefined, selectedItem: undefined });
        }
        else {
            this.formControl.setValue(null);
            this.valueModel.set(null);
            this.sdChange.emit(null);
            this.sdSelection.emit({ multiple: false, values: [], selectedItems: [], value: null, selectedItem: null });
        }
    };
    onClick = () => {
        this.updatePanelWidth();
        if (this.sdViewDef()?.templateRef) {
            if (!this.formControl.disabled && !this.focused())
                this.focus();
        }
    };
    focus = () => {
        this.focused.set(true);
        this.updatePanelWidth();
        setTimeout(() => {
            this.selectRef()?.focus();
            this.selectRef()?.open();
        }, 100);
    };
    /** Open the select panel programmatically (anchors to the mat-select trigger). */
    open = () => {
        if (this.formControl.disabled)
            return;
        // why: signal write từ updatePanelWidth() chưa qua CD trong cùng tick → mat-select
        // sẽ đọc [panelWidth] cũ và panel co lại theo bare trigger. Gán trực tiếp panelWidth
        // lên mat-select instance để open() thấy giá trị mới ngay, không phải chờ CD.
        this.updatePanelWidth();
        const ref = this.selectRef();
        if (!ref)
            return;
        ref.panelWidth = this.calculatedPanelWidth();
        ref.open();
    };
    onOpenedChange = (isOpened) => {
        if (isOpened) {
            this.focused.set(true);
            setTimeout(() => {
                const input = this.matInputRef();
                if (input) {
                    input.value = '';
                    input.focus();
                }
            }, 100);
            this.#hashedValue = Utilities.hash({ value: this.formControl.value });
            this.inputControl.setValue('');
        }
        else {
            this.focused.set(false);
            const hashedValue = Utilities.hash({ value: this.formControl.value });
            if (this.#hashedValue !== hashedValue) {
                this.sdChange.emit(this.formControl.value);
                if (this.multiple()) {
                    this.sdSelection.emit({
                        multiple: true,
                        values: this.formControl.value,
                        selectedItems: this.formControl.value?.map((val) => this.#allItem[val?.toString()]) || [],
                    });
                }
                else {
                    this.sdSelection.emit({
                        multiple: false,
                        values: [this.formControl.value],
                        selectedItems: [this.#allItem[this.formControl.value?.toString()]],
                        value: this.formControl.value,
                        selectedItem: this.#allItem[this.formControl.value?.toString()],
                    });
                }
            }
            this.#hashedValue = undefined;
        }
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdSelect, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.17", type: SdSelect, isStandalone: true, selector: "sd-select", 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: true, transformFunction: null }, displayField: { classPropertyName: "displayField", publicName: "displayField", isSignal: true, isRequired: true, transformFunction: null }, disabledField: { classPropertyName: "disabledField", publicName: "disabledField", isSignal: true, isRequired: false, transformFunction: null }, cacheChecksum: { classPropertyName: "cacheChecksum", publicName: "cacheChecksum", isSignal: true, isRequired: false, transformFunction: null }, limit: { classPropertyName: "limit", publicName: "limit", isSignal: true, isRequired: false, transformFunction: null }, hyperlink: { classPropertyName: "hyperlink", publicName: "hyperlink", isSignal: true, isRequired: false, transformFunction: null }, minWidthPanel: { classPropertyName: "minWidthPanel", publicName: "minWidthPanel", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, viewed: { classPropertyName: "viewed", publicName: "viewed", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", 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 }, floatLabel: { classPropertyName: "floatLabel", publicName: "floatLabel", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange", sdSelection: "sdSelection" }, host: { properties: { "class.sd-bare": "isInline()", "class.sd-viewed": "isViewed() || isInline()", "class.sd-has-label": "!!label()" } }, queries: [{ propertyName: "sdLabelTemplate", first: true, predicate: ["sdLabel"], descendants: true, isSignal: true }, { propertyName: "sdValueTemplate", first: true, predicate: ["sdValue"], descendants: true, isSignal: true }, { propertyName: "sdSelectedTemplate", first: true, predicate: ["sdSelected"], descendants: true, isSignal: true }, { propertyName: "itemDef", first: true, predicate: SdItemDefDefDirective, descendants: true, isSignal: true }, { propertyName: "sdViewDef", first: true, predicate: SdViewDefDirective, descendants: true, isSignal: true }, { propertyName: "footerActions", predicate: SdSelectFooterActionDirective, isSignal: true }], viewQueries: [{ propertyName: "matInputRef", first: true, predicate: MatInput, descendants: true, isSignal: true }, { propertyName: "selectRef", first: true, predicate: ["select"], descendants: true, isSignal: true }], ngImport: i0, template: "@let _label = label();\n@let _appearance = appearance();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage();\n@let _helperText = helperText();\n@let _multiple = multiple();\n@let _required = required();\n@let _normalizedValue = $any(normalizedValue());\n@let _focused = $any(focused());\n@let _isInline = isInline();\n@let _bare = _isInline;\n@let _hasValue = _multiple ? !!_normalizedValue?.length : _normalizedValue !== undefined && _normalizedValue !== null;\n@let _display = display();\n@let _size = size();\n@let _floatLabel = floatLabel();\n@let _valueField = valueField();\n@let _displayField = displayField();\n\n@if (isViewed()) {\n  <sd-view\n    [label]=\"_label\"\n    [labelTemplate]=\"sdLabelTemplate()\"\n    [value]=\"_normalizedValue\"\n    [display]=\"_display\"\n    [hyperlink]=\"hyperlink()\"\n    [valueTemplate]=\"viewTemplate()\"\n    [selectedItems]=\"selectedItems()\">\n  </sd-view>\n} @else {\n  @if (_isInline) {\n    <!-- why: inline \u2014 sd-view text l\u00E0 \"m\u1EB7t\" + trigger; editor v\u1EABn render b\u00EAn d\u01B0\u1EDBi (chrome \u1EA9n qua\n         .sd-inline-editor) \u0111\u1EC3 m\u1EDF panel. Text gi\u1EEF nguy\u00EAn, ch\u1EC9 \u0111\u1ED5i khi commit gi\u00E1 tr\u1ECB m\u1EDBi. -->\n    <span class=\"sd-inline-view\" role=\"button\" tabindex=\"0\" (click)=\"enterInlineEdit()\" (keydown.enter)=\"enterInlineEdit()\">\n      <sd-view\n        [label]=\"_label\"\n        [labelTemplate]=\"sdLabelTemplate()\"\n        [value]=\"_normalizedValue\"\n        [display]=\"_display\"\n        [hyperlink]=\"hyperlink()\"\n        [valueTemplate]=\"viewTemplate()\"\n        [selectedItems]=\"selectedItems()\">\n      </sd-view>\n\n      <!-- why: clear-\u00D7 ch\u1EC9 hi\u1EC7n khi hover (CSS), \u0111\u1EB7t CU\u1ED0I face + clear($event) stopPropagation \u2192\n           xo\u00E1 gi\u00E1 tr\u1ECB m\u00E0 KH\u00D4NG m\u1EDF panel; tr\u00E1nh bug c\u0169 (\u00D7 s\u00E1t trigger b\u1ECB b\u1EA5m nh\u1EA7m l\u00FAc \u0111\u00F3ng panel). -->\n      @if (clearable() && _hasValue && !_required && !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 (!_appearance) {\n    <ng-content select=\"[sdLabel]\">\n      @if (_label) {\n        <sd-label [label]=\"_label\" [required]=\"_required\"></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]=\"_focused\"\n    [class.c-disabled]=\"formControl.disabled\"\n    (click)=\"onClick()\"\n    (mouseenter)=\"updatePanelWidth()\"\n    (focusin)=\"updatePanelWidth()\"\n    aria-hidden=\"true\">\n      @if (_multiple) {\n        <mat-form-field\n          [class.sd-md]=\"_size === 'md'\"\n          [class.sd-sm]=\"_size === 'sm'\"\n          [class.hide-inline-error]=\"_hideInlineError\"\n          [appearance]=\"_appearance!\"\n          [floatLabel]=\"_floatLabel\">\n          @if (_appearance && _label) {\n            <mat-label style=\"display: inline-block\">\n              <div style=\"display: flex; align-items: center; gap: 4px\">\n                <span>{{ _label }}</span>\n                @if (_helperText) {\n                  <mat-icon [matTooltip]=\"_helperText\" matTooltipPosition=\"below\">info_outline</mat-icon>\n                }\n              </div>\n            </mat-label>\n          }\n\n          <mat-select\n            #select\n            multiple\n            [formControl]=\"formControl\"\n            [placeholder]=\"placeholder() || _label || ''\"\n            (selectionChange)=\"onSelectionChange($event)\"\n            disableOptionCentering=\"true\"\n            [panelWidth]=\"calculatedPanelWidth()\"\n            [panelClass]=\"['sd-select-panel', 'sd-multiple']\"\n            [class.sd-selected]=\"!_required && _normalizedValue?.length\"\n            [required]=\"_required\"\n            (openedChange)=\"onOpenedChange($event)\"\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            matTooltipClass=\"sd-multiline-tooltip\"\n            [matTooltipDisabled]=\"!formControl.disabled || !_normalizedValue?.length\"\n            [matTooltip]=\"tooltip() || ''\">\n            <mat-select-trigger>\n              @if (sdSelectedTemplate(); as _selTpl) {\n                <ng-container\n                  *ngTemplateOutlet=\"_selTpl; context: { $implicit: selectedItems(), item: selectedItems(), items: selectedItems(), display: _display, multiple: true }\">\n                </ng-container>\n              } @else {\n                <div class=\"sd-trigger-text\" [matTooltip]=\"_display || ''\" matTooltipPosition=\"above\">\n                  {{ _display }}\n                </div>\n              }\n            </mat-select-trigger>\n\n            @if (filtered()) {\n              <div class=\"c-filter-input-container\">\n                <div class=\"filter-input-wrapper\">\n                  <mat-icon>search</mat-icon>\n                  <input\n                    [formControl]=\"inputControl\"\n                    aria-hidden=\"true\"\n                    matInput\n                    autocomplete=\"off\"\n                    class=\"c-search-input\"\n                    (keydown)=\"$event.stopPropagation()\" />\n                </div>\n              </div>\n            }\n\n            @let asyncItems = filteredItems();\n            @if (asyncItems) {\n              @if (!asyncItems.length && !loading()) {\n                <mat-option class=\"sd-empty\" disabled>\n                  <img class=\"sd-image-data-empty\" alt=\"empty-image\" style=\"width: 95px\" />\n                </mat-option>\n              } @else {\n                @let iDefTpl = itemDef()?.templateRef;\n                @if (_valueField && _displayField) {\n                  @for (item of asyncItems; track itemValue(item)) {\n                    <mat-option [value]=\"itemValue(item)\" [disabled]=\"itemDisabled(item)\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ itemDisplay(item) }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                } @else if (!_valueField && !_displayField) {\n                  @for (item of asyncItems; track item) {\n                    <mat-option [value]=\"item\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ item }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                }\n              }\n            }\n\n            @if (loading()) {\n              <mat-option disabled class=\"sd-loading-option\">\n                <mat-spinner diameter=\"24\"></mat-spinner>\n              </mat-option>\n            }\n\n            @let renderedFooterActions = visibleFooterActions();\n            @if (renderedFooterActions.length) {\n              <div class=\"sd-select-footer-actions\">\n                @for (action of renderedFooterActions; track action) {\n                  <ng-container *ngTemplateOutlet=\"action.templateRef; context: footerActionContext()\"> </ng-container>\n                }\n              </div>\n            }\n          </mat-select>\n\n          @if (_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\"> error </mat-icon>\n          }\n\n          @if (!_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-error>{{ _errorMessage }}</mat-error>\n          }\n\n          @if (_normalizedValue?.length && !_required && !formControl.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 {\n            <mat-icon class=\"cursor-pointer sd-suffix-icon\" matSuffix>keyboard_arrow_down</mat-icon>\n          }\n        </mat-form-field>\n      } @else {\n        <mat-form-field\n          [class.sd-md]=\"_size === 'md'\"\n          [class.sd-sm]=\"_size === 'sm'\"\n          [class.hide-inline-error]=\"_hideInlineError\"\n          [appearance]=\"_appearance!\"\n          [floatLabel]=\"_floatLabel\">\n          @if (_appearance && _label) {\n            <mat-label style=\"display: inline-block\">\n              <div style=\"display: flex; align-items: center; gap: 4px\">\n                <span>{{ _label }}</span>\n                @if (_helperText) {\n                  <mat-icon [matTooltip]=\"_helperText\" matTooltipPosition=\"below\">info_outline</mat-icon>\n                }\n              </div>\n            </mat-label>\n          }\n\n          <mat-select\n            #select\n            [formControl]=\"formControl\"\n            [placeholder]=\"placeholder() || _label || ''\"\n            (selectionChange)=\"onSelectionChange($event)\"\n            disableOptionCentering=\"true\"\n            [panelWidth]=\"calculatedPanelWidth()\"\n            [panelClass]=\"'sd-select-panel'\"\n            [class.sd-selected]=\"!_required && _normalizedValue !== undefined && _normalizedValue !== null\"\n            [required]=\"_required\"\n            (openedChange)=\"onOpenedChange($event)\"\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            matTooltipClass=\"sd-multiline-tooltip\"\n            [matTooltipDisabled]=\"!formControl.disabled || !_normalizedValue?.length\"\n            [matTooltip]=\"tooltip() || ''\">\n            <mat-select-trigger>\n              @if (sdSelectedTemplate(); as _selTpl) {\n                <ng-container\n                  *ngTemplateOutlet=\"_selTpl; context: { $implicit: selectedItems()[0], item: selectedItems()[0], items: selectedItems(), display: _display, multiple: false }\">\n                </ng-container>\n              } @else {\n                {{ _display }}\n              }\n            </mat-select-trigger>\n\n            @if (filtered()) {\n              <div class=\"c-filter-input-container\">\n                <div class=\"filter-input-wrapper\">\n                  <mat-icon>search</mat-icon>\n                  <input\n                    [formControl]=\"inputControl\"\n                    aria-hidden=\"true\"\n                    matInput\n                    autocomplete=\"off\"\n                    class=\"c-search-input\"\n                    (keydown)=\"$event.stopPropagation()\" />\n                </div>\n              </div>\n            }\n\n            @let asyncItems = filteredItems();\n            @if (asyncItems) {\n              @if (!asyncItems.length && !loading()) {\n                <mat-option class=\"sd-empty\" disabled>\n                  <img class=\"sd-image-data-empty\" alt=\"empty-image\" style=\"width: 95px\" />\n                </mat-option>\n              } @else {\n                @let iDefTpl = itemDef()?.templateRef;\n\n                @if (_valueField && _displayField) {\n                  @for (item of asyncItems; track itemValue(item)) {\n                    <mat-option [value]=\"itemValue(item)\" [disabled]=\"itemDisabled(item)\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ itemDisplay(item) }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                } @else if (!_valueField && !_displayField) {\n                  @for (item of asyncItems; track item) {\n                    <mat-option [value]=\"item\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ item }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                }\n              }\n            }\n\n            @if (loading()) {\n              <mat-option disabled class=\"sd-loading-option\">\n                <mat-spinner diameter=\"24\"></mat-spinner>\n              </mat-option>\n            }\n\n            @let renderedFooterActions = visibleFooterActions();\n            @if (renderedFooterActions.length) {\n              <div class=\"sd-select-footer-actions\">\n                @for (action of renderedFooterActions; track action) {\n                  <ng-container *ngTemplateOutlet=\"action.templateRef; context: footerActionContext()\"> </ng-container>\n                }\n              </div>\n            }\n          </mat-select>\n\n          @if (_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\"> error </mat-icon>\n          }\n\n          @if (!_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-error>{{ _errorMessage }}</mat-error>\n          }\n\n          @if (_normalizedValue !== undefined && _normalizedValue !== null && !_required && !formControl.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 {\n            <mat-icon class=\"cursor-pointer sd-suffix-icon\" matSuffix>keyboard_arrow_down</mat-icon>\n          }\n        </mat-form-field>\n      }\n  </div>\n}\n", styles: ["@charset \"UTF-8\";.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{display:block;max-width:100%}:host(.sd-has-label){padding-top:4px}:host(.sd-viewed){padding-top:0}::ng-deep .sd-loading-option .mat-pseudo-checkbox{display:none!important}::ng-deep .sd-loading-option .mdc-list-item__primary-text{width:100%;display:flex;justify-content:center;align-items:center}::ng-deep .sd-loading-option{min-height:50px!important}.sd-trigger-text{display:block;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host ::ng-deep .mat-mdc-select-value{max-width:100%;overflow:hidden;width:0;min-width:100%}:host ::ng-deep .sd-selected .mat-mdc-select-arrow{display:none}:host ::ng-deep .mat-mdc-select-arrow{display:none!important}:host ::ng-deep .custom-arrow{pointer-events:none;position:absolute;right:1rem;top:50%;transform:translateY(-50%);display:flex;align-items:center}: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 mat-select.mat-mdc-select-disabled .mat-mdc-select-value{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}::ng-deep .sd-select-panel .mat-mdc-option.sd-empty .mat-pseudo-checkbox{display:none}::ng-deep .sd-select-panel .mat-mdc-option{min-height:36px!important;padding:8px 12px!important}::ng-deep .sd-select-panel .c-filter-input-container{position:sticky;top:0;background-color:#fff;box-shadow:0 1px #f2f2f2;padding:8px;margin-bottom:8px;z-index:1000}::ng-deep .sd-select-panel .c-filter-input-container .filter-input-wrapper{display:flex;align-items:center;padding:4px 8px;border:1px solid var(--sd-black200);border-radius:4px;background-color:#fff}::ng-deep .sd-select-panel .c-filter-input-container .filter-input-wrapper .mat-icon{color:#dadada}::ng-deep .sd-select-panel .c-filter-input-container .filter-input-wrapper .c-search-input{background-color:#fff;border:none;outline:none;flex:1;padding:4px}::ng-deep .sd-select-panel .sd-select-footer-actions{position:sticky;bottom:0;z-index:1000;display:flex;flex-direction:column;gap:4px;border-top:1px solid #f2f2f2;background-color:#fff}::ng-deep .sd-multiline-tooltip{white-space:pre-line}::ng-deep .mat-mdc-select-panel.sd-select-panel{padding:0}::ng-deep .mat-mdc-select-panel.sd-select-panel .mat-mdc-option.mdc-list-item--disabled.sd-empty .mdc-list-item__primary-text{opacity:.8;width:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:16px}::ng-deep .sd-select-panel .mat-pseudo-checkbox-minimal{transform:scale(.7);transform-origin:center right}::ng-deep .sd-select-panel.sd-multiple .mat-pseudo-checkbox{transform:scale(.75);margin-right:8px!important}::ng-deep .sd-select-panel.sd-multiple .mdc-list-item__primary-text{font-size:14px;white-space:normal}::ng-deep .mat-mdc-select-panel.sd-select-panel{max-width:90vw!important}::ng-deep .mat-mdc-select-panel.sd-select-panel .mat-mdc-option .mdc-list-item__primary-text{white-space:normal;word-break:break-word;line-height:1.4}:host(.sd-bare){display:inline-flex;align-items:center}: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(.sd-bare) ::ng-deep .mat-mdc-form-field{width:auto}:host(.sd-bare) ::ng-deep .mat-mdc-text-field-wrapper{padding:0;background:transparent}:host(.sd-bare) ::ng-deep .mat-mdc-form-field-flex{padding:0;align-items:center}:host(.sd-bare) ::ng-deep .mdc-notched-outline{display:none}:host(.sd-bare) ::ng-deep .mat-mdc-form-field-subscript-wrapper{display:none}:host(.sd-bare) ::ng-deep .mat-mdc-form-field-infix{padding:0;min-height:0;width:auto;border:0;display:inline-flex;align-items:center}:host(.sd-bare) ::ng-deep .mat-mdc-select-arrow-wrapper{display:none}\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: MatIconModule }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatSelectModule }, { kind: "component", type: i6.MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth", "canSelectNullableOptions"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "directive", type: i6.MatSelectTrigger, selector: "mat-select-trigger" }, { kind: "component", type: i6.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "ngmodule", type: MatCheckboxModule }, { 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: SdSelect, decorators: [{
            type: Component,
            args: [{ selector: 'sd-select', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, host: { '[class.sd-bare]': 'isInline()', '[class.sd-viewed]': 'isViewed() || isInline()', '[class.sd-has-label]': '!!label()' }, imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        MatInputModule,
                        MatTooltipModule,
                        MatFormFieldModule,
                        MatIconModule,
                        MatSelectModule,
                        MatCheckboxModule,
                        MatProgressSpinnerModule,
                        SdLabel,
                        SdView,
                        SdSelectFooterActionDirective,
                    ], template: "@let _label = label();\n@let _appearance = appearance();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage();\n@let _helperText = helperText();\n@let _multiple = multiple();\n@let _required = required();\n@let _normalizedValue = $any(normalizedValue());\n@let _focused = $any(focused());\n@let _isInline = isInline();\n@let _bare = _isInline;\n@let _hasValue = _multiple ? !!_normalizedValue?.length : _normalizedValue !== undefined && _normalizedValue !== null;\n@let _display = display();\n@let _size = size();\n@let _floatLabel = floatLabel();\n@let _valueField = valueField();\n@let _displayField = displayField();\n\n@if (isViewed()) {\n  <sd-view\n    [label]=\"_label\"\n    [labelTemplate]=\"sdLabelTemplate()\"\n    [value]=\"_normalizedValue\"\n    [display]=\"_display\"\n    [hyperlink]=\"hyperlink()\"\n    [valueTemplate]=\"viewTemplate()\"\n    [selectedItems]=\"selectedItems()\">\n  </sd-view>\n} @else {\n  @if (_isInline) {\n    <!-- why: inline \u2014 sd-view text l\u00E0 \"m\u1EB7t\" + trigger; editor v\u1EABn render b\u00EAn d\u01B0\u1EDBi (chrome \u1EA9n qua\n         .sd-inline-editor) \u0111\u1EC3 m\u1EDF panel. Text gi\u1EEF nguy\u00EAn, ch\u1EC9 \u0111\u1ED5i khi commit gi\u00E1 tr\u1ECB m\u1EDBi. -->\n    <span class=\"sd-inline-view\" role=\"button\" tabindex=\"0\" (click)=\"enterInlineEdit()\" (keydown.enter)=\"enterInlineEdit()\">\n      <sd-view\n        [label]=\"_label\"\n        [labelTemplate]=\"sdLabelTemplate()\"\n        [value]=\"_normalizedValue\"\n        [display]=\"_display\"\n        [hyperlink]=\"hyperlink()\"\n        [valueTemplate]=\"viewTemplate()\"\n        [selectedItems]=\"selectedItems()\">\n      </sd-view>\n\n      <!-- why: clear-\u00D7 ch\u1EC9 hi\u1EC7n khi hover (CSS), \u0111\u1EB7t CU\u1ED0I face + clear($event) stopPropagation \u2192\n           xo\u00E1 gi\u00E1 tr\u1ECB m\u00E0 KH\u00D4NG m\u1EDF panel; tr\u00E1nh bug c\u0169 (\u00D7 s\u00E1t trigger b\u1ECB b\u1EA5m nh\u1EA7m l\u00FAc \u0111\u00F3ng panel). -->\n      @if (clearable() && _hasValue && !_required && !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 (!_appearance) {\n    <ng-content select=\"[sdLabel]\">\n      @if (_label) {\n        <sd-label [label]=\"_label\" [required]=\"_required\"></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]=\"_focused\"\n    [class.c-disabled]=\"formControl.disabled\"\n    (click)=\"onClick()\"\n    (mouseenter)=\"updatePanelWidth()\"\n    (focusin)=\"updatePanelWidth()\"\n    aria-hidden=\"true\">\n      @if (_multiple) {\n        <mat-form-field\n          [class.sd-md]=\"_size === 'md'\"\n          [class.sd-sm]=\"_size === 'sm'\"\n          [class.hide-inline-error]=\"_hideInlineError\"\n          [appearance]=\"_appearance!\"\n          [floatLabel]=\"_floatLabel\">\n          @if (_appearance && _label) {\n            <mat-label style=\"display: inline-block\">\n              <div style=\"display: flex; align-items: center; gap: 4px\">\n                <span>{{ _label }}</span>\n                @if (_helperText) {\n                  <mat-icon [matTooltip]=\"_helperText\" matTooltipPosition=\"below\">info_outline</mat-icon>\n                }\n              </div>\n            </mat-label>\n          }\n\n          <mat-select\n            #select\n            multiple\n            [formControl]=\"formControl\"\n            [placeholder]=\"placeholder() || _label || ''\"\n            (selectionChange)=\"onSelectionChange($event)\"\n            disableOptionCentering=\"true\"\n            [panelWidth]=\"calculatedPanelWidth()\"\n            [panelClass]=\"['sd-select-panel', 'sd-multiple']\"\n            [class.sd-selected]=\"!_required && _normalizedValue?.length\"\n            [required]=\"_required\"\n            (openedChange)=\"onOpenedChange($event)\"\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            matTooltipClass=\"sd-multiline-tooltip\"\n            [matTooltipDisabled]=\"!formControl.disabled || !_normalizedValue?.length\"\n            [matTooltip]=\"tooltip() || ''\">\n            <mat-select-trigger>\n              @if (sdSelectedTemplate(); as _selTpl) {\n                <ng-container\n                  *ngTemplateOutlet=\"_selTpl; context: { $implicit: selectedItems(), item: selectedItems(), items: selectedItems(), display: _display, multiple: true }\">\n                </ng-container>\n              } @else {\n                <div class=\"sd-trigger-text\" [matTooltip]=\"_display || ''\" matTooltipPosition=\"above\">\n                  {{ _display }}\n                </div>\n              }\n            </mat-select-trigger>\n\n            @if (filtered()) {\n              <div class=\"c-filter-input-container\">\n                <div class=\"filter-input-wrapper\">\n                  <mat-icon>search</mat-icon>\n                  <input\n                    [formControl]=\"inputControl\"\n                    aria-hidden=\"true\"\n                    matInput\n                    autocomplete=\"off\"\n                    class=\"c-search-input\"\n                    (keydown)=\"$event.stopPropagation()\" />\n                </div>\n              </div>\n            }\n\n            @let asyncItems = filteredItems();\n            @if (asyncItems) {\n              @if (!asyncItems.length && !loading()) {\n                <mat-option class=\"sd-empty\" disabled>\n                  <img class=\"sd-image-data-empty\" alt=\"empty-image\" style=\"width: 95px\" />\n                </mat-option>\n              } @else {\n                @let iDefTpl = itemDef()?.templateRef;\n                @if (_valueField && _displayField) {\n                  @for (item of asyncItems; track itemValue(item)) {\n                    <mat-option [value]=\"itemValue(item)\" [disabled]=\"itemDisabled(item)\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ itemDisplay(item) }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                } @else if (!_valueField && !_displayField) {\n                  @for (item of asyncItems; track item) {\n                    <mat-option [value]=\"item\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ item }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                }\n              }\n            }\n\n            @if (loading()) {\n              <mat-option disabled class=\"sd-loading-option\">\n                <mat-spinner diameter=\"24\"></mat-spinner>\n              </mat-option>\n            }\n\n            @let renderedFooterActions = visibleFooterActions();\n            @if (renderedFooterActions.length) {\n              <div class=\"sd-select-footer-actions\">\n                @for (action of renderedFooterActions; track action) {\n                  <ng-container *ngTemplateOutlet=\"action.templateRef; context: footerActionContext()\"> </ng-container>\n                }\n              </div>\n            }\n          </mat-select>\n\n          @if (_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\"> error </mat-icon>\n          }\n\n          @if (!_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-error>{{ _errorMessage }}</mat-error>\n          }\n\n          @if (_normalizedValue?.length && !_required && !formControl.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 {\n            <mat-icon class=\"cursor-pointer sd-suffix-icon\" matSuffix>keyboard_arrow_down</mat-icon>\n          }\n        </mat-form-field>\n      } @else {\n        <mat-form-field\n          [class.sd-md]=\"_size === 'md'\"\n          [class.sd-sm]=\"_size === 'sm'\"\n          [class.hide-inline-error]=\"_hideInlineError\"\n          [appearance]=\"_appearance!\"\n          [floatLabel]=\"_floatLabel\">\n          @if (_appearance && _label) {\n            <mat-label style=\"display: inline-block\">\n              <div style=\"display: flex; align-items: center; gap: 4px\">\n                <span>{{ _label }}</span>\n                @if (_helperText) {\n                  <mat-icon [matTooltip]=\"_helperText\" matTooltipPosition=\"below\">info_outline</mat-icon>\n                }\n              </div>\n            </mat-label>\n          }\n\n          <mat-select\n            #select\n            [formControl]=\"formControl\"\n            [placeholder]=\"placeholder() || _label || ''\"\n            (selectionChange)=\"onSelectionChange($event)\"\n            disableOptionCentering=\"true\"\n            [panelWidth]=\"calculatedPanelWidth()\"\n            [panelClass]=\"'sd-select-panel'\"\n            [class.sd-selected]=\"!_required && _normalizedValue !== undefined && _normalizedValue !== null\"\n            [required]=\"_required\"\n            (openedChange)=\"onOpenedChange($event)\"\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            matTooltipClass=\"sd-multiline-tooltip\"\n            [matTooltipDisabled]=\"!formControl.disabled || !_normalizedValue?.length\"\n            [matTooltip]=\"tooltip() || ''\">\n            <mat-select-trigger>\n              @if (sdSelectedTemplate(); as _selTpl) {\n                <ng-container\n                  *ngTemplateOutlet=\"_selTpl; context: { $implicit: selectedItems()[0], item: selectedItems()[0], items: selectedItems(), display: _display, multiple: false }\">\n                </ng-container>\n              } @else {\n                {{ _display }}\n              }\n            </mat-select-trigger>\n\n            @if (filtered()) {\n              <div class=\"c-filter-input-container\">\n                <div class=\"filter-input-wrapper\">\n                  <mat-icon>search</mat-icon>\n                  <input\n                    [formControl]=\"inputControl\"\n                    aria-hidden=\"true\"\n                    matInput\n                    autocomplete=\"off\"\n                    class=\"c-search-input\"\n                    (keydown)=\"$event.stopPropagation()\" />\n                </div>\n              </div>\n            }\n\n            @let asyncItems = filteredItems();\n            @if (asyncItems) {\n              @if (!asyncItems.length && !loading()) {\n                <mat-option class=\"sd-empty\" disabled>\n                  <img class=\"sd-image-data-empty\" alt=\"empty-image\" style=\"width: 95px\" />\n                </mat-option>\n              } @else {\n                @let iDefTpl = itemDef()?.templateRef;\n\n                @if (_valueField && _displayField) {\n                  @for (item of asyncItems; track itemValue(item)) {\n                    <mat-option [value]=\"itemValue(item)\" [disabled]=\"itemDisabled(item)\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ itemDisplay(item) }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                } @else if (!_valueField && !_displayField) {\n                  @for (item of asyncItems; track item) {\n                    <mat-option [value]=\"item\">\n                      <div>\n                        @if (iDefTpl) {\n                          <ng-container *ngTemplateOutlet=\"iDefTpl ?? null; context: { item: item }\"> </ng-container>\n                        } @else {\n                          {{ item }}\n                        }\n                      </div>\n                    </mat-option>\n                  }\n                }\n              }\n            }\n\n            @if (loading()) {\n              <mat-option disabled class=\"sd-loading-option\">\n                <mat-spinner diameter=\"24\"></mat-spinner>\n              </mat-option>\n            }\n\n            @let renderedFooterActions = visibleFooterActions();\n            @if (renderedFooterActions.length) {\n              <div class=\"sd-select-footer-actions\">\n                @for (action of renderedFooterActions; track action) {\n                  <ng-container *ngTemplateOutlet=\"action.templateRef; context: footerActionContext()\"> </ng-container>\n                }\n              </div>\n            }\n          </mat-select>\n\n          @if (_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-icon matSuffix class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\"> error </mat-icon>\n          }\n\n          @if (!_hideInlineError && _errorMessage && formControl.touched) {\n            <mat-error>{{ _errorMessage }}</mat-error>\n          }\n\n          @if (_normalizedValue !== undefined && _normalizedValue !== null && !_required && !formControl.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 {\n            <mat-icon class=\"cursor-pointer sd-suffix-icon\" matSuffix>keyboard_arrow_down</mat-icon>\n          }\n        </mat-form-field>\n      }\n  </div>\n}\n", styles: ["@charset \"UTF-8\";.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{display:block;max-width:100%}:host(.sd-has-label){padding-top:4px}:host(.sd-viewed){padding-top:0}::ng-deep .sd-loading-option .mat-pseudo-checkbox{display:none!important}::ng-deep .sd-loading-option .mdc-list-item__primary-text{width:100%;display:flex;justify-content:center;align-items:center}::ng-deep .sd-loading-option{min-height:50px!important}.sd-trigger-text{display:block;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host ::ng-deep .mat-mdc-select-value{max-width:100%;overflow:hidden;width:0;min-width:100%}:host ::ng-deep .sd-selected .mat-mdc-select-arrow{display:none}:host ::ng-deep .mat-mdc-select-arrow{display:none!important}:host ::ng-deep .custom-arrow{pointer-events:none;position:absolute;right:1rem;top:50%;transform:translateY(-50%);display:flex;align-items:center}: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 mat-select.mat-mdc-select-disabled .mat-mdc-select-value{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}::ng-deep .sd-select-panel .mat-mdc-option.sd-empty .mat-pseudo-checkbox{display:none}::ng-deep .sd-select-panel .mat-mdc-option{min-height:36px!important;padding:8px 12px!important}::ng-deep .sd-select-panel .c-filter-input-container{position:sticky;top:0;background-color:#fff;box-shadow:0 1px #f2f2f2;padding:8px;margin-bottom:8px;z-index:1000}::ng-deep .sd-select-panel .c-filter-input-container .filter-input-wrapper{display:flex;align-items:center;padding:4px 8px;border:1px solid var(--sd-black200);border-radius:4px;background-color:#fff}::ng-deep .sd-select-panel .c-filter-input-container .filter-input-wrapper .mat-icon{color:#dadada}::ng-deep .sd-select-panel .c-filter-input-container .filter-input-wrapper .c-search-input{background-color:#fff;border:none;outline:none;flex:1;padding:4px}::ng-deep .sd-select-panel .sd-select-footer-actions{position:sticky;bottom:0;z-index:1000;display:flex;flex-direction:column;gap:4px;border-top:1px solid #f2f2f2;background-color:#fff}::ng-deep .sd-multiline-tooltip{white-space:pre-line}::ng-deep .mat-mdc-select-panel.sd-select-panel{padding:0}::ng-deep .mat-mdc-select-panel.sd-select-panel .mat-mdc-option.mdc-list-item--disabled.sd-empty .mdc-list-item__primary-text{opacity:.8;width:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:16px}::ng-deep .sd-select-panel .mat-pseudo-checkbox-minimal{transform:scale(.7);transform-origin:center right}::ng-deep .sd-select-panel.sd-multiple .mat-pseudo-checkbox{transform:scale(.75);margin-right:8px!important}::ng-deep .sd-select-panel.sd-multiple .mdc-list-item__primary-text{font-size:14px;white-space:normal}::ng-deep .mat-mdc-select-panel.sd-select-panel{max-width:90vw!important}::ng-deep .mat-mdc-select-panel.sd-select-panel .mat-mdc-option .mdc-list-item__primary-text{white-space:normal;word-break:break-word;line-height:1.4}:host(.sd-bare){display:inline-flex;align-items:center}: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(.sd-bare) ::ng-deep .mat-mdc-form-field{width:auto}:host(.sd-bare) ::ng-deep .mat-mdc-text-field-wrapper{padding:0;background:transparent}:host(.sd-bare) ::ng-deep .mat-mdc-form-field-flex{padding:0;align-items:center}:host(.sd-bare) ::ng-deep .mdc-notched-outline{display:none}:host(.sd-bare) ::ng-deep .mat-mdc-form-field-subscript-wrapper{display:none}:host(.sd-bare) ::ng-deep .mat-mdc-form-field-infix{padding:0;min-height:0;width:auto;border:0;display:inline-flex;align-items:center}:host(.sd-bare) ::ng-deep .mat-mdc-select-arrow-wrapper{display:none}\n"] }]
        }], ctorParameters: () => [], propDecorators: { matInputRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => MatInput), { isSignal: true }] }], selectRef: [{ type: i0.ViewChild, args: ['select', { isSignal: true }] }], sdLabelTemplate: [{ type: i0.ContentChild, args: ['sdLabel', { isSignal: true }] }], sdValueTemplate: [{ type: i0.ContentChild, args: ['sdValue', { isSignal: true }] }], sdSelectedTemplate: [{ type: i0.ContentChild, args: ['sdSelected', { isSignal: true }] }], itemDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdItemDefDefDirective), { isSignal: true }] }], sdViewDef: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SdViewDefDirective), { isSignal: true }] }], footerActions: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => SdSelectFooterActionDirective), { 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: true }] }], displayField: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayField", required: true }] }], disabledField: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabledField", required: false }] }], cacheChecksum: [{ type: i0.Input, args: [{ isSignal: true, alias: "cacheChecksum", required: false }] }], limit: [{ type: i0.Input, args: [{ isSignal: true, alias: "limit", required: false }] }], hyperlink: [{ type: i0.Input, args: [{ isSignal: true, alias: "hyperlink", required: false }] }], minWidthPanel: [{ type: i0.Input, args: [{ isSignal: true, alias: "minWidthPanel", required: false }] }], hideInlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideInlineError", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], viewed: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewed", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", 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 }] }], floatLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "floatLabel", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", 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"] }] } });

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

export { SdSelect, SdSelectFooterActionDirective };
//# sourceMappingURL=sdcorejs-angular-forms-select.mjs.map
