"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _dropdownItemTitle = _interopRequireDefault(require("./dropdown-item-title"));
var _types = require("./types");
var _hooks = require("../hooks");
var _utils = require("../hooks/use-tree-navigation/utils");
var _dropdownItemTooltip = _interopRequireDefault(require("./dropdown-item-tooltip"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const DropdownItemLink = ({
  option,
  onClick = () => {},
  onMouseLeave = () => {},
  onMouseEnter = () => {},
  onCloseDropdown = () => {},
  LinkComponent: PropsLinkComponent
}) => {
  const {
    disabled,
    link,
    testId,
    isExternal,
    LinkComponent: OptionLinkComponent
  } = option;
  const LinkComponent = OptionLinkComponent || PropsLinkComponent;
  const {
    treeItemAttrs,
    ref: setRefCallback
  } = (0, _hooks.useTreeNodeNavigation)({
    id: option.privateKey || option.key,
    getKeyActionFn: _utils.getKeyActionFnMenu,
    onCustomButtonKeyDown: () => onCloseDropdown(),
    onToggleSelected: onClick,
    ignoreKeys: null,
    preventDefault: false
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItemTooltip.default, {
    option: option,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkComponent, {
      className: "drop-link",
      ref: setRefCallback,
      rel: "noopener noreferrer",
      "test-id": testId,
      onClick: onClick,
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave,
      onKeyDown: treeItemAttrs.onKeyDown,
      onBlur: treeItemAttrs.onBlur,
      onFocus: treeItemAttrs.onFocus,
      target: isExternal ? '_blank' : undefined,
      href: disabled ? undefined : link,
      role: _types.MENU_ROLE.MENUITEM,
      option: option,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownItemTitle.default, {
        option: option
      })
    })
  });
};
var _default = exports.default = DropdownItemLink;