import { useMemo, useCallback } from 'react';
import { getTabIndex, shouldSubmitViaKeyDown } from '../use-non-native-button-attrs';
export function useListboxAttrs() {
  const getOptionAttrs = useCallback(({
    tabIndex,
    size,
    position,
    onClick,
    onKeyDown,
    isDisabled = false,
    isSelected = false
  }) => ({
    role: 'option',
    'aria-disabled': isDisabled,
    'aria-selected': isSelected,
    'aria-setsize': size,
    'aria-posinset': position,
    tabIndex: getTabIndex(isDisabled, tabIndex),
    onKeyDown(e) {
      if (shouldSubmitViaKeyDown(e) && !isDisabled) {
        onKeyDown?.(e);
      }
    },
    onClick(e) {
      if (!isDisabled) {
        onClick?.(e);
      }
    }
  }), []);
  return useMemo(() => ({
    role: 'listbox',
    getOptionAttrs
  }), []);
}