"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var lift_list_item_with_multiple_empty_paragraphs_exports = {};
__export(lift_list_item_with_multiple_empty_paragraphs_exports, {
  liftEmptyListItemWithMultipleEmptyParagraphs: () => liftEmptyListItemWithMultipleEmptyParagraphs
});
module.exports = __toCommonJS(lift_list_item_with_multiple_empty_paragraphs_exports);
var import_ricos_types = require("./../ricos-types/index.js");
var import_tiptap = require("./../tiptap/index.js");
var import_transform = require("./../tiptap/pm/transform.js");
const liftEmptyListItemWithMultipleEmptyParagraphs = (state, dispatch) => {
  if (!dispatch) {
    console.error("dispatch is not defined");
    return false;
  }
  const currListItem = (0, import_tiptap.findParentNodeClosestToPos)(
    state.selection.$from,
    (node) => node.type.name === import_ricos_types.Node_Type.LIST_ITEM
  );
  if (!currListItem) {
    return false;
  }
  if (currListItem.node.content.childCount < 2) {
    return false;
  }
  const currParagraph = (0, import_tiptap.findParentNodeClosestToPos)(
    state.selection.$from,
    (node) => node.type.name === import_ricos_types.Node_Type.PARAGRAPH
  );
  if (!currParagraph) {
    return false;
  }
  if (currListItem.node.firstChild?.attrs.id !== currParagraph.node.attrs.id) {
    return false;
  }
  let allEmptyParagraphs = true;
  currListItem.node.forEach((node) => {
    if (node.type.name !== import_ricos_types.Node_Type.PARAGRAPH || node.content.childCount !== 0) {
      allEmptyParagraphs = false;
    }
  });
  if (!allEmptyParagraphs) {
    return false;
  }
  const parentListNode = (0, import_tiptap.findParentNodeClosestToPos)(
    state.selection.$from,
    (node) => node.type.name === import_ricos_types.Node_Type.BULLETED_LIST || node.type.name === import_ricos_types.Node_Type.CHECKBOX_LIST || node.type.name === import_ricos_types.Node_Type.ORDERED_LIST
  );
  if (!parentListNode) {
    return false;
  }
  if (parentListNode.node.lastChild?.attrs.id !== currListItem.node.attrs.id) {
    return false;
  }
  const tr = state.tr;
  tr.delete(currListItem.pos + 3, currListItem.pos + currListItem.node.nodeSize - 1);
  const { $cursor } = tr.selection;
  if (!$cursor || $cursor.parent.content.size) {
    return false;
  }
  const range = $cursor?.blockRange();
  if (!range || range.parent.type.name !== import_ricos_types.Node_Type.LIST_ITEM) {
    return false;
  }
  const target = (0, import_transform.liftTarget)(range);
  if (target === null) {
    return false;
  }
  dispatch(tr.lift(range, target).scrollIntoView());
  return true;
};
//# sourceMappingURL=lift-list-item-with-multiple-empty-paragraphs.js.map
