"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ContextMenu = void 0;

var _core = require("@material-ui/core");

var _react = _interopRequireDefault(require("react"));

var _hooks = require("../hooks");

const ContextMenu = props => {
  const theme = (0, _core.useTheme)();
  const localization = (0, _hooks.useLocalization)();

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

  return /*#__PURE__*/_react.default.createElement(_core.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.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().deleteTable().run();
      handleClose();
    }
  }, localization.contextMenu.deleteTable), /*#__PURE__*/_react.default.createElement(_core.Divider, {
    variant: "middle"
  }), props.editor.can().addRowBefore() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addRowBefore().run();
      handleClose();
    }
  }, localization.contextMenu.addRowAbove), props.editor.can().addRowAfter() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addRowAfter().run();
      handleClose();
    }
  }, localization.contextMenu.addRowBelow), /*#__PURE__*/_react.default.createElement(_core.Divider, {
    variant: "middle"
  }), props.editor.can().addColumnBefore() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addColumnBefore().run();
      handleClose();
    }
  }, localization.contextMenu.addColBefore), props.editor.can().addColumnAfter() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().addColumnAfter().run();
      handleClose();
    }
  }, localization.contextMenu.addColAfter), /*#__PURE__*/_react.default.createElement(_core.Divider, {
    variant: "middle"
  }), props.editor.can().deleteRow() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().deleteRow().run();
      handleClose();
    }
  }, localization.contextMenu.deleteRow), props.editor.can().deleteColumn() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().deleteColumn().run();
      handleClose();
    }
  }, localization.contextMenu.deleteCol), /*#__PURE__*/_react.default.createElement(_core.Divider, {
    variant: "middle"
  }), props.editor.can().toggleHeaderRow() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().toggleHeaderRow().run();
      handleClose();
    }
  }, localization.contextMenu.toggleHeaderRow), props.editor.can().toggleHeaderColumn() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().toggleHeaderColumn().run();
      handleClose();
    }
  }, localization.contextMenu.toggleHeaderCol), (props.editor.can().mergeCells() || props.editor.can().splitCell()) && /*#__PURE__*/_react.default.createElement(_core.Divider, {
    variant: "middle"
  }), props.editor.can().mergeCells() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().mergeCells().run();
      handleClose();
    }
  }, localization.contextMenu.mergeCells), props.editor.can().splitCell() && /*#__PURE__*/_react.default.createElement(_core.MenuItem, {
    onClick: () => {
      props.editor.chain().focus().splitCell().run();
      handleClose();
    }
  }, localization.contextMenu.splitCell));
};

exports.ContextMenu = ContextMenu;
//# sourceMappingURL=context-menu.js.map