import * as _shival99_angular_virtual from '@shival99/angular-virtual';
import * as _angular_core from '@angular/core';
import { TemplateRef, Signal, OnInit, ElementRef } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { ZIcon } from '@shival99/z-ui/components/z-icon';
import { ZPopoverPosition, ZPopoverControl } from '@shival99/z-ui/components/z-popover';
import { ZAsyncOptionsConfig, ZEvent } from '@shival99/z-ui/utils';
import { ClassValue } from 'clsx';
import * as class_variance_authority_types from 'class-variance-authority/types';
import { VariantProps } from 'class-variance-authority';

declare class ZAutocompleteOptionDirective<T = unknown> {
    readonly templateRef: TemplateRef<any>;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<ZAutocompleteOptionDirective<any>, never>;
    static ɵdir: _angular_core.ɵɵDirectiveDeclaration<ZAutocompleteOptionDirective<any>, "[z-autocomplete-option], [zAutocompleteOption]", never, {}, {}, never, never, true, never>;
}

interface ZAutocompleteOption<T = unknown> {
    label: string;
    value: T;
    disabled?: boolean;
    description?: string;
    icon?: ZIcon;
}
interface ZAutocompleteConfig<T = unknown> {
    /** Số ký tự tối thiểu trước khi bắt đầu search hoặc gọi async.load. */
    minLength: number;
    /** Thời gian chờ sau khi người dùng ngừng nhập rồi mới phát zOnSearch/call async.load, tính bằng mili giây. */
    debounceTime: number;
    /** Giới hạn số option hiển thị sau khi filter; đặt 0 để không giới hạn. */
    maxDisplayed: number;
    /** Bật highlight phần text khớp với keyword trong label của option. */
    highlightMatch: boolean;
    /** i18n key hoặc text hiển thị khi đã nhập keyword nhưng không có kết quả. */
    emptyMessage: string;
    /** i18n key hoặc text hiển thị khi chưa có dữ liệu ban đầu. */
    noDataMessage: string;
    /** Tự đóng dropdown sau khi chọn option. */
    closeOnSelect: boolean;
    /** Chiều cao mặc định của một option, dùng cho virtual scroll và layout dropdown. */
    optionHeight: number;
    /** Chiều cao tối đa của dropdown, tính bằng pixel. */
    dropdownMaxHeight: number;
    /** Bỏ filter local khi options đã được xử lý từ server qua zOnSearch. */
    serverSearch: boolean;
    /** Config để component tự search, load-more, loading và append options. */
    async?: ZAsyncOptionsConfig<ZAutocompleteOption<T>>;
}
declare const Z_AUTOCOMPLETE_DEFAULT_CONFIG: Omit<ZAutocompleteConfig, 'async'>;
type ZAutocompleteSize = 'sm' | 'default' | 'lg';
type ZAutocompleteType = 'default' | 'address_bar';
interface ZAutocompleteState {
    focused: boolean;
    touched: boolean;
    dirty: boolean;
    disabled: boolean;
    readonly: boolean;
    open: boolean;
}
interface ZAutocompleteCommitEvent {
    value: string;
    source: 'enter' | 'blur';
}
interface ZAutocompleteLoadMoreEvent {
    currentCount: number;
    scrollTop: number;
}
interface ZAutocompleteOptionContext<T = unknown> {
    $implicit: ZAutocompleteOption<T>;
    active: boolean;
}
interface ZAutocompleteControl<T = unknown> {
    focus: () => void;
    blur: () => void;
    clear: () => void;
    reset: () => void;
    open: () => void;
    close: () => void;
    setValue: (value: string) => void;
    value: Signal<string>;
    selectedOption: Signal<ZAutocompleteOption<T> | null>;
    /**
     * @deprecated Use individual event outputs (zOnFocus, zOnBlur, etc.) instead.
     * Will be removed in a future version.
     */
    state: Signal<ZAutocompleteState>;
}
type ZAutocompleteOptionTemplate<T = unknown> = TemplateRef<ZAutocompleteOptionContext<T>>;

declare class ZAutocompleteComponent<T = unknown> implements OnInit, ControlValueAccessor {
    private readonly _injector;
    private readonly _destroyRef;
    private readonly _query$;
    protected readonly triggerRef: _angular_core.Signal<ElementRef<HTMLDivElement> | undefined>;
    protected readonly inputRef: _angular_core.Signal<ElementRef<HTMLInputElement> | undefined>;
    protected readonly dropdownTpl: _angular_core.Signal<TemplateRef<unknown> | undefined>;
    protected readonly virtualScrollRef: _angular_core.Signal<ElementRef<HTMLDivElement> | undefined>;
    protected readonly optionsContainerRef: _angular_core.Signal<ElementRef<HTMLDivElement> | undefined>;
    protected readonly loadMoreSentinelRef: _angular_core.Signal<ElementRef<HTMLDivElement> | undefined>;
    protected readonly virtualOptionElements: _angular_core.Signal<readonly ElementRef<HTMLDivElement>[]>;
    protected readonly customOptionDirective: _angular_core.Signal<ZAutocompleteOptionDirective<any> | undefined>;
    readonly class: _angular_core.InputSignal<ClassValue>;
    readonly zOptions: _angular_core.InputSignal<ZAutocompleteOption<T>[]>;
    readonly zConfig: _angular_core.InputSignal<Partial<ZAutocompleteConfig<T>>>;
    readonly zSize: _angular_core.InputSignal<ZAutocompleteSize>;
    readonly zType: _angular_core.InputSignal<ZAutocompleteType>;
    readonly zLabel: _angular_core.InputSignal<string>;
    readonly zLabelClass: _angular_core.InputSignal<string>;
    readonly zPlaceholder: _angular_core.InputSignal<string>;
    readonly zDisabled: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zReadonly: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zLoading: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zRequired: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zPrefix: _angular_core.InputSignal<"" | ZIcon>;
    readonly zSuffix: _angular_core.InputSignal<"" | ZIcon>;
    readonly zAllowClear: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zVirtualScroll: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zDynamicSize: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zOptionHeight: _angular_core.InputSignal<number>;
    readonly zHeightExpand: _angular_core.InputSignal<number>;
    readonly zMaxVisible: _angular_core.InputSignal<number | null>;
    readonly zResetOnSelect: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zEmptyText: _angular_core.InputSignal<string>;
    readonly zEmptyIcon: _angular_core.InputSignal<ZIcon>;
    readonly zNoDataText: _angular_core.InputSignal<string>;
    readonly zNoDataIcon: _angular_core.InputSignal<ZIcon>;
    readonly zAllowCustomValue: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zDebounceTime: _angular_core.InputSignal<number>;
    readonly zLoadingMore: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zEnableLoadMore: _angular_core.InputSignalWithTransform<boolean, string | boolean>;
    readonly zScrollDistance: _angular_core.InputSignal<number>;
    readonly zKey: _angular_core.InputSignal<string>;
    readonly zOptionTemplate: _angular_core.InputSignal<ZAutocompleteOptionTemplate<T> | null>;
    readonly zOnSearch: _angular_core.OutputEmitterRef<string>;
    readonly zOnLoadMore: _angular_core.OutputEmitterRef<ZAutocompleteLoadMoreEvent>;
    readonly zOnSelect: _angular_core.OutputEmitterRef<ZAutocompleteOption<T>>;
    readonly zOnEnter: _angular_core.OutputEmitterRef<string>;
    readonly zOnCommit: _angular_core.OutputEmitterRef<ZAutocompleteCommitEvent>;
    readonly zValueChange: _angular_core.OutputEmitterRef<string>;
    readonly zOnBlur: _angular_core.OutputEmitterRef<FocusEvent>;
    readonly zOnFocus: _angular_core.OutputEmitterRef<FocusEvent>;
    readonly zControl: _angular_core.OutputEmitterRef<ZAutocompleteControl<T>>;
    readonly zEvent: _angular_core.OutputEmitterRef<ZEvent>;
    private readonly _value;
    private readonly _disabled;
    private readonly _formControl;
    private readonly _popoverControl;
    private readonly _selectedOption;
    private readonly _asyncOptions;
    private readonly _asyncKeyword;
    private readonly _asyncPage;
    private readonly _asyncHasMore;
    private readonly _asyncLoading;
    private readonly _asyncLoadingMore;
    protected readonly uiState: _angular_core.WritableSignal<{
        isOpen: boolean;
        isFocused: boolean;
        touched: boolean;
        dirty: boolean;
    }>;
    protected readonly actualPosition: _angular_core.WritableSignal<ZPopoverPosition>;
    protected readonly autocompleteId: string;
    protected readonly dropdownId: string;
    protected readonly inputValue: _angular_core.WritableSignal<string>;
    protected readonly debouncedQuery: _angular_core.WritableSignal<string>;
    protected readonly searchQuery: _angular_core.WritableSignal<string>;
    protected readonly activeIndex: _angular_core.WritableSignal<number>;
    protected readonly dropdownWidth: _angular_core.WritableSignal<number>;
    private readonly _pendingSearch;
    private _localLoadingTimeout;
    private _loadMoreObserver;
    private _virtualScrollListener;
    private _asyncLoadSubscription;
    private _asyncRequestId;
    private _lastFilteredOptionsLength;
    private _shouldScrollActiveOption;
    /** Stores input value before keyboard navigation for ESC revert */
    private _valueBeforeNavigation;
    protected readonly virtualizer: _shival99_angular_virtual.AngularVirtualizer<HTMLDivElement, Element>;
    private readonly _measureVirtualItems;
    protected readonly config: _angular_core.Signal<ZAutocompleteConfig<T>>;
    protected readonly hasAsyncOptions: _angular_core.Signal<boolean>;
    protected readonly sourceOptions: _angular_core.Signal<ZAutocompleteOption<T>[]>;
    protected readonly isLoading: _angular_core.Signal<boolean>;
    protected readonly isLoadingMore: _angular_core.Signal<boolean>;
    protected readonly canLoadMore: _angular_core.Signal<boolean>;
    protected readonly isDisabled: _angular_core.Signal<boolean>;
    protected readonly isReadonly: _angular_core.Signal<boolean>;
    protected readonly isInteractionDisabled: _angular_core.Signal<boolean>;
    protected readonly effectiveOptionHeight: _angular_core.Signal<number>;
    protected readonly effectiveHeightExpand: _angular_core.Signal<number>;
    protected readonly effectiveEmptyText: _angular_core.Signal<string>;
    protected readonly effectiveNoDataText: _angular_core.Signal<string>;
    protected readonly effectiveDebounceTime: _angular_core.Signal<number>;
    protected readonly effectiveOptionTemplate: _angular_core.Signal<TemplateRef<any> | null>;
    protected readonly hasCustomOptionTemplate: _angular_core.Signal<boolean>;
    protected readonly highlightQuery: _angular_core.Signal<string>;
    /**
     * Local-mode loading state after debounce to avoid quick flicker.
     * Server mode relies only on zLoading from parent.
     */
    protected readonly isLoadingState: _angular_core.Signal<boolean>;
    protected readonly isPositionTop: _angular_core.Signal<boolean>;
    protected readonly shouldUseVirtualScroll: _angular_core.Signal<boolean>;
    protected readonly filteredOptions: _angular_core.Signal<ZAutocompleteOption<T>[]>;
    protected readonly optionViews: _angular_core.Signal<{
        option: ZAutocompleteOption<T>;
        index: number;
        trackKey: string;
    }[]>;
    protected readonly hasValue: _angular_core.Signal<boolean>;
    protected readonly currentStatus: _angular_core.Signal<"default" | "disabled" | "readonly" | "open">;
    protected readonly inputClasses: _angular_core.Signal<string>;
    readonly state: _angular_core.Signal<ZAutocompleteState>;
    private _onChange;
    private _onTouched;
    private _ngControl;
    private _isNavigationFilling;
    constructor();
    ngOnInit(): void;
    writeValue(value: string): void;
    registerOnChange(fn: (value: string) => void): void;
    registerOnTouched(fn: () => void): void;
    setDisabledState(isDisabled: boolean): void;
    protected onInput(event: Event): void;
    protected onFocus(event: FocusEvent): void;
    protected onInputClick(): void;
    protected onBlur(event: FocusEvent): void;
    protected onKeydown(event: KeyboardEvent): void;
    private _handleEnterKey;
    private _fillInputFromActiveOption;
    private _revertToValueBeforeNavigation;
    private _resetInput;
    protected onPopoverControl(control: ZPopoverControl): void;
    protected onPopoverShow(): void;
    protected onPopoverHideStart(): void;
    protected onPopoverHideEnd(): void;
    protected onPositionChange(position: ZPopoverPosition): void;
    protected selectOption(option: ZAutocompleteOption<T>): void;
    protected clearInput(event: MouseEvent): void;
    protected getOptionClasses(option: ZAutocompleteOption<T>, index: number): string;
    protected trackByValue: (index: number, option: ZAutocompleteOption<T>) => unknown;
    focus(): void;
    blur(): void;
    clear(): void;
    reset(): void;
    open(): void;
    close(): void;
    setValue(value: string): void;
    private _openPanel;
    private _closePanel;
    private _setupDebounce;
    private _loadAsyncOptionsOnFocus;
    private _loadAsyncOptions;
    private _handleAsyncOptionsError;
    private _getAsyncOptionsScrollTop;
    private _restoreAsyncOptionsScrollTop;
    private _resetAsyncOptions;
    private _clearLocalLoadingTimer;
    private _setupLoadMoreObserver;
    private _cleanupLoadMoreObserver;
    private _setupVirtualScrollLoadMore;
    private _cleanupVirtualScrollListener;
    private _handleLoadMore;
    private _emitControl;
    private _getOptionKey;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<ZAutocompleteComponent<any>, never>;
    static ɵcmp: _angular_core.ɵɵComponentDeclaration<ZAutocompleteComponent<any>, "z-autocomplete", ["zAutocomplete"], { "class": { "alias": "class"; "required": false; "isSignal": true; }; "zOptions": { "alias": "zOptions"; "required": false; "isSignal": true; }; "zConfig": { "alias": "zConfig"; "required": false; "isSignal": true; }; "zSize": { "alias": "zSize"; "required": false; "isSignal": true; }; "zType": { "alias": "zType"; "required": false; "isSignal": true; }; "zLabel": { "alias": "zLabel"; "required": false; "isSignal": true; }; "zLabelClass": { "alias": "zLabelClass"; "required": false; "isSignal": true; }; "zPlaceholder": { "alias": "zPlaceholder"; "required": false; "isSignal": true; }; "zDisabled": { "alias": "zDisabled"; "required": false; "isSignal": true; }; "zReadonly": { "alias": "zReadonly"; "required": false; "isSignal": true; }; "zLoading": { "alias": "zLoading"; "required": false; "isSignal": true; }; "zRequired": { "alias": "zRequired"; "required": false; "isSignal": true; }; "zPrefix": { "alias": "zPrefix"; "required": false; "isSignal": true; }; "zSuffix": { "alias": "zSuffix"; "required": false; "isSignal": true; }; "zAllowClear": { "alias": "zAllowClear"; "required": false; "isSignal": true; }; "zVirtualScroll": { "alias": "zVirtualScroll"; "required": false; "isSignal": true; }; "zDynamicSize": { "alias": "zDynamicSize"; "required": false; "isSignal": true; }; "zOptionHeight": { "alias": "zOptionHeight"; "required": false; "isSignal": true; }; "zHeightExpand": { "alias": "zHeightExpand"; "required": false; "isSignal": true; }; "zMaxVisible": { "alias": "zMaxVisible"; "required": false; "isSignal": true; }; "zResetOnSelect": { "alias": "zResetOnSelect"; "required": false; "isSignal": true; }; "zEmptyText": { "alias": "zEmptyText"; "required": false; "isSignal": true; }; "zEmptyIcon": { "alias": "zEmptyIcon"; "required": false; "isSignal": true; }; "zNoDataText": { "alias": "zNoDataText"; "required": false; "isSignal": true; }; "zNoDataIcon": { "alias": "zNoDataIcon"; "required": false; "isSignal": true; }; "zAllowCustomValue": { "alias": "zAllowCustomValue"; "required": false; "isSignal": true; }; "zDebounceTime": { "alias": "zDebounceTime"; "required": false; "isSignal": true; }; "zLoadingMore": { "alias": "zLoadingMore"; "required": false; "isSignal": true; }; "zEnableLoadMore": { "alias": "zEnableLoadMore"; "required": false; "isSignal": true; }; "zScrollDistance": { "alias": "zScrollDistance"; "required": false; "isSignal": true; }; "zKey": { "alias": "zKey"; "required": false; "isSignal": true; }; "zOptionTemplate": { "alias": "zOptionTemplate"; "required": false; "isSignal": true; }; }, { "zOnSearch": "zOnSearch"; "zOnLoadMore": "zOnLoadMore"; "zOnSelect": "zOnSelect"; "zOnEnter": "zOnEnter"; "zOnCommit": "zOnCommit"; "zValueChange": "zValueChange"; "zOnBlur": "zOnBlur"; "zOnFocus": "zOnFocus"; "zControl": "zControl"; "zEvent": "zEvent"; }, ["customOptionDirective"], never, true, never>;
}

declare const zAutocompleteInputVariants: (props?: ({
    zSize?: "sm" | "default" | "lg" | null | undefined;
    zStatus?: "default" | "open" | "error" | "disabled" | "readonly" | null | undefined;
} & class_variance_authority_types.ClassProp) | undefined) => string;
type ZAutocompleteInputVariants = VariantProps<typeof zAutocompleteInputVariants>;
declare const zAutocompleteOptionVariants: (props?: ({
    active?: boolean | null | undefined;
    disabled?: boolean | null | undefined;
} & class_variance_authority_types.ClassProp) | undefined) => string;
type ZAutocompleteOptionVariants = VariantProps<typeof zAutocompleteOptionVariants>;

export { ZAutocompleteComponent, ZAutocompleteOptionDirective, Z_AUTOCOMPLETE_DEFAULT_CONFIG, zAutocompleteInputVariants, zAutocompleteOptionVariants };
export type { ZAutocompleteCommitEvent, ZAutocompleteConfig, ZAutocompleteControl, ZAutocompleteInputVariants, ZAutocompleteLoadMoreEvent, ZAutocompleteOption, ZAutocompleteOptionContext, ZAutocompleteOptionTemplate, ZAutocompleteOptionVariants, ZAutocompleteSize, ZAutocompleteState, ZAutocompleteType };
