"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _elementTypes = require("../../../constants/element-types");
var _helpers = require("../helpers");
var _constants = require("../../../constants");
var _dropdownMenuItem = _interopRequireDefault(require("../../../commons/dropdown-menu-item"));
const menuConfig = _constants.MENUS_CONFIG_MAP[_elementTypes.CODE_BLOCK];
const CodeBlockMenu = _ref => {
  let {
    readonly,
    editor,
    toggle
  } = _ref;
  // eslint-disable-next-line react-hooks/exhaustive-deps
  const isActive = (0, _react.useMemo)(() => (0, _helpers.isInCodeBlock)(editor), [editor.selection]);
  const onMousedown = (0, _react.useCallback)(e => {
    e.preventDefault();
    isActive ? (0, _helpers.unwrapCodeBlock)(editor) : (0, _helpers.transformToCodeBlock)(editor);
    toggle && toggle();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [isActive]);
  return /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
    disabled: readonly,
    menuConfig: menuConfig,
    className: "pr-2",
    onClick: onMousedown
  });
};
var _default = exports.default = CodeBlockMenu;