import { Divider, Menu, MenuItem, useTheme } from '@material-ui/core';
import React from 'react';
import { useLocalization } from "../hooks/index.js";
export const ContextMenu = props => {
  const theme = useTheme();
  const localization = useLocalization();

  const handleClose = () => {
    props.setOpen(false);
    props.setMousePosition({
      x: null,
      y: null
    });
  };

  return /*#__PURE__*/React.createElement(Menu, {
    open: props.open,
    anchorReference: "anchorPosition",
    anchorPosition: props.mousePosition.y !== null && props.mousePosition.x !== null ? {
      top: props.mousePosition.y,
      left: props.mousePosition.x
    } : undefined,
    transitionDuration: {
      enter: theme.transitions.duration.enteringScreen,
      exit: 0
    },
    BackdropProps: {
      onClick: () => {
        handleClose();
      },
      onContextMenu: ev => ev.preventDefault()
    }
  }, props.editor.can().deleteTable() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().deleteTable().run();
      handleClose();
    }
  }, localization.contextMenu.deleteTable), /*#__PURE__*/React.createElement(Divider, {
    variant: "middle"
  }), props.editor.can().addRowBefore() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addRowBefore().run();
      handleClose();
    }
  }, localization.contextMenu.addRowAbove), props.editor.can().addRowAfter() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addRowAfter().run();
      handleClose();
    }
  }, localization.contextMenu.addRowBelow), /*#__PURE__*/React.createElement(Divider, {
    variant: "middle"
  }), props.editor.can().addColumnBefore() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addColumnBefore().run();
      handleClose();
    }
  }, localization.contextMenu.addColBefore), props.editor.can().addColumnAfter() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addColumnAfter().run();
      handleClose();
    }
  }, localization.contextMenu.addColAfter), /*#__PURE__*/React.createElement(Divider, {
    variant: "middle"
  }), props.editor.can().deleteRow() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().deleteRow().run();
      handleClose();
    }
  }, localization.contextMenu.deleteRow), props.editor.can().deleteColumn() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().deleteColumn().run();
      handleClose();
    }
  }, localization.contextMenu.deleteCol), /*#__PURE__*/React.createElement(Divider, {
    variant: "middle"
  }), props.editor.can().toggleHeaderRow() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().toggleHeaderRow().run();
      handleClose();
    }
  }, localization.contextMenu.toggleHeaderRow), props.editor.can().toggleHeaderColumn() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().toggleHeaderColumn().run();
      handleClose();
    }
  }, localization.contextMenu.toggleHeaderCol), (props.editor.can().mergeCells() || props.editor.can().splitCell()) && /*#__PURE__*/React.createElement(Divider, {
    variant: "middle"
  }), props.editor.can().mergeCells() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().mergeCells().run();
      handleClose();
    }
  }, localization.contextMenu.mergeCells), props.editor.can().splitCell() && /*#__PURE__*/React.createElement(MenuItem, {
    onClick: () => {
      props.editor.chain().focus().splitCell().run();
      handleClose();
    }
  }, localization.contextMenu.splitCell));
};
//# sourceMappingURL=context-menu.js.map