import { useCallback, useState } from "react";
import { useSelectNavigation } from "./use-select-navigation.js";
export function useSelectState(props) {
    const [value, setValue] = useState(props.defaultValue);
    const navigation = useSelectNavigation({
        visibleOptionCount: props.visibleOptionCount,
        options: props.options,
        initialFocusValue: props.defaultValue,
        onFocus: props.onFocus,
        focusValue: props.focusValue,
    });
    const selectFocusedOption = useCallback(() => {
        if (navigation.focusedValue === undefined)
            return;
        setValue(navigation.focusedValue);
        props.onChange?.(navigation.focusedValue);
    }, [navigation.focusedValue, props]);
    return {
        ...navigation,
        value,
        selectFocusedOption,
        onChange: props.onChange,
        onCancel: props.onCancel,
        isInInput: false,
    };
}
