"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 outdent_list_exports = {};
__export(outdent_list_exports, {
  outdentList: () => outdentList
});
module.exports = __toCommonJS(outdent_list_exports);
var import_v1 = require("./../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_commons = require("./commons.js");
var import_indent_list = require("./indent-list.js");
var import_lift_list_item_nodes = require("./lift-list-item-nodes.js");
const outdentList = () => ({ tr }) => {
  const { smallestIndentation } = (0, import_commons.getIndentationsInSelection)(tr);
  if (smallestIndentation === 0) {
    return false;
  }
  return liftListItem(tr);
};
const liftListItem = (tr) => {
  const parentList = (0, import_commons.findParentList)(tr.selection.$from);
  if (!parentList) {
    return false;
  }
  const multipleListsInSelection = tr.selection.to > parentList.pos + parentList.node.nodeSize;
  if (multipleListsInSelection) {
    (0, import_commons.changeIndentationOfEveryListSeparately)(tr, liftChildrenOfList);
    return true;
  }
  liftChildrenOfList(tr, parentList);
  return true;
};
const liftChildrenOfList = (tr, parentList) => {
  const selectedListItems = (0, import_commons.getListItemsInSelection)(tr, parentList);
  const areListItemsLiftedSemantically = (0, import_lift_list_item_nodes.lifListItemNodes)(tr, selectedListItems, parentList);
  if (!areListItemsLiftedSemantically) {
    const notSelectedSiblingListItems = getNotSelectedSiblingListItems(tr, parentList);
    (0, import_commons.changeIndentationOfNotSelectedNodes)(tr, notSelectedSiblingListItems, import_indent_list.sinkListItemNodes);
  }
  const notSelectedDescendantListItems = (0, import_commons.getNotSelectedDescendantListItems)(tr, selectedListItems);
  (0, import_commons.changeIndentationOfNotSelectedNodes)(tr, notSelectedDescendantListItems, import_indent_list.sinkListItemNodes);
  return selectedListItems;
};
const getNotSelectedSiblingListItems = (tr, parentList) => {
  const notSelectedSiblingListItems = [];
  parentList.node.descendants((childNode, childPos) => {
    const childPosInDoc = childPos + parentList.pos + 1;
    if (childNode.type.name !== import_v1.Node_Type.LIST_ITEM || childPosInDoc < tr.selection.to) {
      return false;
    }
    notSelectedSiblingListItems.push({ node: childNode, pos: childPosInDoc });
  });
  return notSelectedSiblingListItems;
};
//# sourceMappingURL=outdent-list.js.map
