"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useListboxAttrs = useListboxAttrs;
var _react = require("react");
var _useNonNativeButtonAttrs = require("../use-non-native-button-attrs");
function useListboxAttrs() {
  const getOptionAttrs = (0, _react.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: (0, _useNonNativeButtonAttrs.getTabIndex)(isDisabled, tabIndex),
    onKeyDown(e) {
      if ((0, _useNonNativeButtonAttrs.shouldSubmitViaKeyDown)(e) && !isDisabled) {
        onKeyDown?.(e);
      }
    },
    onClick(e) {
      if (!isDisabled) {
        onClick?.(e);
      }
    }
  }), []);
  return (0, _react.useMemo)(() => ({
    role: 'listbox',
    getOptionAttrs
  }), []);
}