/*
 * 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 } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const ContextMenu = _ref => {
  let {
    nodeId,
    onClose
  } = _ref;
  const menuRef = useRef(null);
  const {
    hasOutgoingEdges
  } = useNodeRelationships();

  // closes menu if user clicks outside of the node
  useOnClickOutside(menuRef, onClose);
  const {
    onExpandChildren,
    onCollapseDescendants
  } = useContextMenuActions(nodeId, onClose);
  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;