import { Path, Node, Editor, Transforms } from "slate";
import { ContemberEditor } from "../../../../ContemberEditor/index.js";
import { indentListItem } from "./indentListItem.js";
import { isListElement } from "../ListElement.js";
import { isListItemElement } from "../ListItemElement.js";
const dedentListItem = (editor, listItem, listItemPath) => {
  const parentListPath = Path.parent(listItemPath);
  const parentListElement = Node.get(editor, parentListPath);
  const parentListChildrenCount = parentListElement.children.length;
  const subsequentListItemCount = parentListChildrenCount - listItemPath[listItemPath.length - 1] - 1;
  if (!isListElement(parentListElement) || parentListPath.length <= 1) {
    return false;
  }
  const parentListItemPath = Path.parent(parentListPath);
  const parentListItemElement = Node.get(editor, parentListItemPath);
  if (!isListItemElement(parentListItemElement)) {
    return false;
  }
  const grandParentListPath = Path.parent(parentListItemPath);
  const grandParentListElement = Node.get(editor, grandParentListPath);
  if (!isListElement(grandParentListElement)) {
    return false;
  }
  const parentListElementSpecifics = ContemberEditor.elementToSpecifics(parentListElement);
  const parentAndGrandParentAreCompatible = ContemberEditor.isElementType(grandParentListElement, parentListElement.type, parentListElementSpecifics);
  if (parentAndGrandParentAreCompatible) {
    const newListItemPath = Path.next(parentListItemPath);
    Editor.withoutNormalizing(editor, () => {
      if (subsequentListItemCount) {
        const nextSiblingPath = Path.next(listItemPath);
        for (let i = 0; i < subsequentListItemCount; i++) {
          const nextListItem = Node.get(editor, nextSiblingPath);
          indentListItem(editor, nextListItem, nextSiblingPath);
        }
      }
      Transforms.moveNodes(editor, {
        at: listItemPath,
        to: newListItemPath
      });
      if (parentListChildrenCount === 1) {
        Transforms.removeNodes(editor, {
          at: parentListPath
        });
      }
    });
    return true;
  }
  return false;
};
export { dedentListItem };
//# sourceMappingURL=dedentListItem.js.map
