"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _hooks = require("../hooks");
var _utils = require("../hooks/use-tree-navigation/utils");
var _types = require("./types");
var _dropdownItemTitle = _interopRequireDefault(require("./dropdown-item-title"));
var _dropdownItemTooltip = _interopRequireDefault(require("./dropdown-item-tooltip"));
var _button = require("../button");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const DropdownItemButton = ({
  option,
  onClick,
  onMouseLeave = () => {},
  onMouseEnter = () => {},
  onCloseDropdown = () => {},
  isMultiLevelHandler
}) => {
  const {
    testId,
    disabled
  } = option;
  const {
    treeItemAttrs,
    ref: setRefCallback,
    node
  } = (0, _hooks.useTreeNodeNavigation)({
    id: option.privateKey || option.key,
    getKeyActionFn: _utils.getKeyActionFnMenu,
    onCustomButtonKeyDown: button => {
      return onCloseDropdown(String(button));
    },
    onToggleSelected: isSelected => {
      if (isSelected) {
        onClick?.(option);
      }
    },
    ignoreKeys: null
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItemTooltip.default, {
    option: option,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
      ref: setRefCallback,
      role: _types.MENU_ROLE.MENUITEM,
      "test-id": testId,
      onClick: onClick,
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave,
      disabled: disabled,
      type: _button.BUTTON_TYPES.BUTTON,
      onKeyDown: treeItemAttrs.onKeyDown,
      "aria-haspopup": isMultiLevelHandler,
      ...(isMultiLevelHandler && {
        'aria-expanded': node.isExpanded
      }),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItemTitle.default, {
        option: option,
        isMultiLevelHandler: isMultiLevelHandler
      })
    })
  });
};
var _default = exports.default = DropdownItemButton;