import { Dispatch, MouseEvent, SetStateAction } from 'react'; import { SelectValue } from '../Select/typings'; export interface UseAutoCompleteBaseValueControl { disabledOptionsFilter: boolean; getOptionsFilterQuery?: (searchText: string) => string | undefined; onChange?(newOptions: SelectValue[] | SelectValue | null): any; onClear?(e: MouseEvent): void; onClose?(): void; onSearch?(input: string): any; options: SelectValue[]; } export type UseAutoCompleteMultipleValueControl = UseAutoCompleteBaseValueControl & { defaultValue?: SelectValue[]; mode: 'multiple'; onChange?(newOptions: SelectValue[]): any; value?: SelectValue[]; }; export type UseAutoCompleteSingleValueControl = UseAutoCompleteBaseValueControl & { defaultValue?: SelectValue; mode: 'single'; onChange?(newOption: SelectValue | null): any; value?: SelectValue | null; }; export type UseAutoCompleteValueControl = UseAutoCompleteMultipleValueControl | UseAutoCompleteSingleValueControl; export interface AutoCompleteBaseValueControl { focused: boolean; onClear(e: MouseEvent): void; onFocus: (f: boolean) => void; options: SelectValue[]; searchText: string; selectedOptions: SelectValue[]; setSearchText: Dispatch>; unselectedOptions: SelectValue[]; } export type AutoCompleteMultipleValueControl = AutoCompleteBaseValueControl & { onChange: (v: SelectValue | null) => SelectValue[]; value: SelectValue[]; }; export type AutoCompleteSingleValueControl = AutoCompleteBaseValueControl & { onChange: (v: SelectValue | null) => SelectValue | null; value: SelectValue | null; }; /** * 管理 AutoComplete 搜尋文字與選取值的受控狀態 Hook。 * * 根據 `mode` 支援單選(`single`)與多選(`multiple`),並內建選項過濾邏輯、 * 焦點狀態追蹤以及清除功能,回傳完整的操作介面供 AutoComplete 元件使用。 * * @example * ```tsx * import { useAutoCompleteValueControl } from '@mezzanine-ui/react'; * * const control = useAutoCompleteValueControl({ * mode: 'single', * options: [{ id: '1', name: 'Option A' }], * disabledOptionsFilter: false, * onChange: (option) => console.log(option), * }); * ``` * * @see {@link AutoComplete} 搭配的元件 */ export declare const useAutoCompleteValueControl: (props: UseAutoCompleteValueControl) => AutoCompleteMultipleValueControl | AutoCompleteSingleValueControl;