"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
function useOutsideClickHandler(ref, handler) {
  React.useEffect(() => {
    function handleClickOutside(event) {
      if (ref.current && !ref.current.contains(event.target) && (!(event.target instanceof Element) || !event.target.className.includes("ant-dropdown"))) {
        handler(event);
      }
    }
    document.addEventListener("mousedown", handleClickOutside);
    return () => {
      document.removeEventListener("mousedown", handleClickOutside);
    };
  }, [ref, handler]);
}
function ContextMenu({
  cell,
  rowData,
  link,
  onClose,
  onComplete,
  open,
  renderContextMenuComponent,
  x,
  y
}) {
  const containerRef = React.useRef(null);
  useOutsideClickHandler(containerRef, onClose);
  const handleComplete = React.useCallback(
    (action, id, data) => {
      onComplete == null ? void 0 : onComplete(action, id, data);
      onClose();
    },
    [onClose, onComplete]
  );
  const handleVisibleChange = React.useCallback(() => onClose(), [onClose]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      ref: containerRef,
      style: {
        left: x,
        position: "fixed",
        top: y,
        zIndex: 10
      },
      children: renderContextMenuComponent == null ? void 0 : renderContextMenuComponent({
        cell,
        link,
        onClose,
        onComplete: handleComplete,
        onVisibleChange: handleVisibleChange,
        open,
        rowData
      })
    }
  );
}
exports.ContextMenu = ContextMenu;
