"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 indent_exports = {};
__export(indent_exports, {
  indent: () => indent,
  indentPath: () => indentPath
});
module.exports = __toCommonJS(indent_exports);
var import_slate = require("slate");
var import_controls = require("@makeswift/controls");
var import_element = require("../utils/element");
var import_constants = require("./constants");
var import_filterForSubtreeRoots = require("./utils/filterForSubtreeRoots");
var import_getSelectedListItems = require("./utils/getSelectedListItems");
function indentPath(editor, path) {
  const parent = import_slate.Node.parent(editor, path);
  if (!path || !import_slate.Path.hasPrevious(path) || !import_controls.Slate.isList(parent))
    return;
  const previosPath = import_slate.Path.previous(path);
  const previousChildListPath = [...previosPath, import_constants.LIST_ITEM_LIST_POSITION];
  const previousHasChildList = import_slate.Node.has(editor, previousChildListPath);
  import_slate.Editor.withoutNormalizing(editor, () => {
    if (!previousHasChildList) {
      import_slate.Transforms.insertNodes(editor, import_element.ElementUtils.createList(parent.type), {
        at: previousChildListPath
      });
    }
    const previousChildList = import_slate.Node.get(editor, previousChildListPath);
    if (import_controls.Slate.isList(previousChildList)) {
      const index = previousHasChildList ? previousChildList.children.length : 0;
      import_slate.Transforms.moveNodes(editor, {
        at: path,
        to: [...previousChildListPath, index]
      });
    }
  });
}
function indent(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) {
      indentPath(editor, ref.current);
    }
    ref.unref();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  indent,
  indentPath
});
//# sourceMappingURL=indent.js.map