import { useMemo } from 'react';
export function getTabIndex(isDisabled = false, tabIndex = 0) {
  if (isDisabled) {
    return -1;
  }
  return tabIndex;
}
export function shouldSubmitViaKeyDown(e) {
  return e.key === ' ' || e.key === 'Enter';
}
export function getNonNativeButtonAttrs({
  onKeyDown,
  onClick,
  tabIndex,
  isDisabled = false
}) {
  return {
    tabIndex: getTabIndex(isDisabled, tabIndex),
    role: 'button',
    'aria-disabled': isDisabled,
    onKeyDown(e) {
      if (shouldSubmitViaKeyDown(e) && !isDisabled) {
        onKeyDown?.(e);
      }
    },
    onClick(e) {
      if (!isDisabled) {
        onClick?.(e);
      }
    }
  };
}
export function useNonNativeButtonAttrs({
  onKeyDown,
  onClick,
  tabIndex,
  isDisabled = false
}) {
  const attrs = useMemo(() => getNonNativeButtonAttrs({
    isDisabled,
    tabIndex,
    onClick,
    onKeyDown
  }), [isDisabled, tabIndex, onClick, onKeyDown]);
  return attrs;
}