"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 _constants = require("../../../constants");
var _elementTypes = require("../../../constants/element-types");
var _menuItem = _interopRequireDefault(require("../../../commons/menu/menu-item"));
var _helper = require("../helper");
var _helper2 = require("../../paragraph/helper");
var _core = require("../../../core");
const menuConfig = _constants.MENUS_CONFIG_MAP[_elementTypes.CHECK_LIST_ITEM];
const CheckListMenu = _ref => {
  let {
    editor,
    readonly,
    className,
    isRichEditor
  } = _ref;
  // eslint-disable-next-line react-hooks/exhaustive-deps
  const isDisabled = (0, _react.useMemo)(() => (0, _helper.isMenuDisabled)(editor, readonly), [editor.selection, readonly]);
  const isActive = !!(0, _core.getSelectedNodeByType)(editor, _elementTypes.CHECK_LIST_ITEM);
  const onMouseDown = (0, _react.useCallback)(e => {
    e.preventDefault();
    isActive ? (0, _helper2.transformToParagraph)(editor) : (0, _helper.transformToCheckList)(editor);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [isActive]);
  return /*#__PURE__*/_react.default.createElement(_menuItem.default, Object.assign({
    isRichEditor: isRichEditor,
    className: className,
    disabled: isDisabled,
    isActive: isActive,
    onMouseDown: onMouseDown
  }, menuConfig));
};
var _default = exports.default = CheckListMenu;