/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

import React, { useRef } from 'react';
import { useNodeRelationships, Visibility } from '../../shared/hooks/use_node_relationships.hook';
import { t } from '../../shared/i18n/t';
import { useOnClickOutside } from '../../shared/hooks/use_on_click_outside.hook';
import { MenuItem } from './menu_item';
import { useContextMenuActions } from './use_context_menu_actions.hook';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const ContextMenu = _ref => {
  let nodeId = _ref.nodeId,
    onClose = _ref.onClose;
  const menuRef = useRef(null);
  const _useNodeRelationships = useNodeRelationships(),
    hasOutgoingEdges = _useNodeRelationships.hasOutgoingEdges;

  // closes menu if user clicks outside of the node
  useOnClickOutside(menuRef, onClose);
  const _useContextMenuAction = useContextMenuActions(nodeId, onClose),
    onExpandChildren = _useContextMenuAction.onExpandChildren,
    onCollapseDescendants = _useContextMenuAction.onCollapseDescendants;
  return /*#__PURE__*/_jsxs("ul", {
    ref: menuRef,
    className: "osd:absolute osd:z-9999 osd:overflow-visible osd:bg-white osd:border osd:border-gray-200 osd:rounded osd:shadow-md osd:w-60",
    children: [/*#__PURE__*/_jsx(MenuItem, {
      label: t('contextMenu.expandDependencies'),
      isDisabled: !hasOutgoingEdges(nodeId, Visibility.Hidden),
      onClick: onExpandChildren
    }), /*#__PURE__*/_jsx(MenuItem, {
      label: t('contextMenu.collapseDependencies'),
      isDisabled: !hasOutgoingEdges(nodeId, Visibility.Visible),
      onClick: onCollapseDescendants
    })]
  });
};
// eslint-disable-next-line import/no-default-export
export default ContextMenu;