"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 dedent_exports = {};
__export(dedent_exports, {
  dedent: () => dedent
});
module.exports = __toCommonJS(dedent_exports);
var import_slate = require("slate");
var import_indent = require("./indent");
var import_getSelectedListItems = require("./utils/getSelectedListItems");
var import_filterForSubtreeRoots = require("./utils/filterForSubtreeRoots");
var import_editor = require("../utils/editor");
function dedentPath(editor, listItemPath) {
  const parentList = import_editor.EditorUtils.getFirstAncestorList(editor, listItemPath);
  const listItemContainingParentList = import_editor.EditorUtils.getFirstAncestorListItem(editor, listItemPath);
  if (!parentList || !listItemContainingParentList)
    return;
  const [parentListNode, parentListPath] = parentList;
  const [_, listItemContainingParentListPath] = listItemContainingParentList;
  const listItemPosition = listItemPath[listItemPath.length - 1];
  const previousSiblings = parentListNode.children.slice(0, listItemPosition);
  const nextSiblings = parentListNode.children.slice(listItemPosition + 1);
  import_slate.Editor.withoutNormalizing(editor, () => {
    nextSiblings.forEach(() => {
      const nextSiblingPath = [...parentListPath, listItemPosition + 1];
      (0, import_indent.indentPath)(editor, nextSiblingPath);
    });
    import_slate.Transforms.moveNodes(editor, {
      at: listItemPath,
      to: import_slate.Path.next(listItemContainingParentListPath)
    });
    if (previousSiblings.length === 0) {
      import_slate.Transforms.removeNodes(editor, { at: parentListPath });
    }
  });
}
function dedent(editor) {
  if (!editor.selection)
    return;
  const listItems = (0, import_getSelectedListItems.getSelectedListItems)(editor);
  const subRoots = (0, import_filterForSubtreeRoots.filterForSubtreeRoots)(listItems);
  const refs = subRoots.map(([_, path]) => import_slate.Editor.pathRef(editor, path));
  refs.forEach((ref) => {
    if (ref.current) {
      dedentPath(editor, ref.current);
    }
    ref.unref();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  dedent
});
//# sourceMappingURL=dedent.js.map