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