import React from "react"; import { Option } from "../choicefield"; import { SelectProps } from "./select"; export type UseSelectStateProps = { /** Either a static array or an async loader. */ options: SelectProps["options"]; /** Controlled selected value(s). Values are the source of truth. */ value: Option["value"] | Option | Array | null; /** Enable multi-select behavior. */ multiple: boolean; /** If true, perform an initial empty-query fetch on mount/open. */ fetchOnMount?: boolean; /** Minimum characters before non-empty async queries fire. */ minSearchChars?: number; /** Debounce in ms for the query used with loadOptions and local filtering. */ searchDebounceMs?: number; /** Blur callback, receives a native-like FocusEvent dispatched on a hidden . */ onChange?: (e: React.ChangeEvent) => void; }; type HiddenSelectValue = string | string[]; export type UseSelectStateResult = { state: { /** True while an async fetch is in flight. */ isLoading: boolean; /** Dropdown open state. */ isOpen: boolean; /** Current options in view, from static or async source. */ options: Option[]; /** Current search input value. */ search: string; /** Selected values (strings). */ selectedValues: string[]; }; actions: { /** Clear all selections and dispatch change. */ clear: () => void; /** Dispatch a blur event to the hidden select. */ handleBlur: (evt: React.FocusEvent) => void; /** Commit a selection by option index or clear when index is null. Dispatches a change event. */ handleChange: (evt: React.UIEvent, index: number | null) => void; /** Remove one value (multi only) and dispatch change. No-op in single mode. */ removeValue: (val: string) => void; /** Control open state. */ setIsOpen: React.Dispatch>; /** Set search input value. */ setSearch: React.Dispatch>; }; meta: { /** Map from option value (or label fallback) to its first index. */ getIndex: (v: string) => number | undefined; /** Map from option value (or label fallback) to its label. */ getLabel: (v: string) => string; }; hiddenSelectProps: { /** Whether multiple selection is enabled. */ multiple: boolean; /** Ref to the hidden native select element. */ ref: React.RefObject; /** Current hidden select value(s). */ value: HiddenSelectValue; }; }; /** * Select state and behaviors. * * Values are the source of truth. Indices are derived for UI navigation and styling. * Supports static and async options, debounced searching, and native-like events. */ export declare function useSelectState({ options, value, multiple, fetchOnMount, minSearchChars, searchDebounceMs, onBlur, onChange, }: UseSelectStateProps): UseSelectStateResult; export {};