import React from 'react';
import { useTreeNodeNavigation } from '../hooks';
import { getKeyActionFnMenu } from '../hooks/use-tree-navigation/utils';
import { MENU_ROLE } from './types';
import DropdownItemTitle from './dropdown-item-title';
import DropdownItemTooltip from './dropdown-item-tooltip';
import { BUTTON_TYPES } from '../button';
import { jsx as _jsx } from "react/jsx-runtime";
const DropdownItemButton = ({
  option,
  onClick,
  onMouseLeave = () => {},
  onMouseEnter = () => {},
  onCloseDropdown = () => {},
  isMultiLevelHandler
}) => {
  const {
    testId,
    disabled
  } = option;
  const {
    treeItemAttrs,
    ref: setRefCallback,
    node
  } = useTreeNodeNavigation({
    id: option.privateKey || option.key,
    getKeyActionFn: getKeyActionFnMenu,
    onCustomButtonKeyDown: button => {
      return onCloseDropdown(String(button));
    },
    onToggleSelected: isSelected => {
      if (isSelected) {
        onClick?.(option);
      }
    },
    ignoreKeys: null
  });
  return /*#__PURE__*/_jsx(DropdownItemTooltip, {
    option: option,
    children: /*#__PURE__*/_jsx("button", {
      ref: setRefCallback,
      role: MENU_ROLE.MENUITEM,
      "test-id": testId,
      onClick: onClick,
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave,
      disabled: disabled,
      type: BUTTON_TYPES.BUTTON,
      onKeyDown: treeItemAttrs.onKeyDown,
      "aria-haspopup": isMultiLevelHandler,
      ...(isMultiLevelHandler && {
        'aria-expanded': node.isExpanded
      }),
      children: /*#__PURE__*/_jsx(DropdownItemTitle, {
        option: option,
        isMultiLevelHandler: isMultiLevelHandler
      })
    })
  });
};
export default DropdownItemButton;