"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.moveListItemsToList = void 0;
var _slate = require("slate");
var _core = require("../../../core");
var _constant = require("../constant");
const moveListItemsToList = (editor, _ref) => {
  let {
    fromList,
    fromListItem,
    fromStartIndex,
    to: _to,
    toList,
    toListIndex = null,
    deleteFromList = true
  } = _ref;
  let fromListPath = null;
  let moved = false;
  _slate.Editor.withoutNormalizing(editor, () => {
    if (fromListItem) {
      const fromListItemSubList = (0, _core.findDescendant)(editor, {
        at: fromListItem[1],
        match: {
          type: _constant.LIST_TYPES
        }
      });
      if (!fromListItemSubList) return;
      fromListPath = fromListItemSubList === null || fromListItemSubList === void 0 ? void 0 : fromListItemSubList[1];
    } else if (fromList) {
      fromListPath = fromList[1];
    } else {
      return;
    }
    let to = null;
    if (_to) to = _to;
    if (toList) {
      if (toListIndex !== null) {
        to = toList[1].concat([toListIndex]);
      } else {
        const lastChildPath = (0, _core.getLastChildPath)(toList);
        to = _slate.Path.next(lastChildPath);
      }
    }
    if (!to) return;
    moved = (0, _core.moveChildren)(editor, {
      at: fromListPath,
      to,
      fromStartIndex
    });

    // Remove the empty list
    if (deleteFromList) {
      _slate.Transforms.delete(editor, {
        at: fromListPath
      });
    }
  });
  return moved;
};
exports.moveListItemsToList = moveListItemsToList;