"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.movedListItemDown = void 0;
var _slate = require("slate");
var _core = require("../../../core");
var _constant = require("../constant");
const movedListItemDown = (editor, _ref) => {
  let {
    list,
    listItem
  } = _ref;
  let moved = false;
  const [listNode] = list;
  const [, listItemPath] = listItem;
  let previousListItemPath = null;
  try {
    previousListItemPath = _slate.Path.previous(listItemPath);
  } catch (e) {
    return;
  }
  const previousSiblingItem = _slate.Editor.node(editor, previousListItemPath);
  if (previousSiblingItem) {
    const [previousNode, previousPath] = previousSiblingItem;
    const subList = previousNode.children.find(n => {
      return _constant.LIST_TYPES.includes(n.type);
    });
    const newPath = previousPath.concat(subList ? [1, subList.children.length] : [1]);
    _slate.Editor.withoutNormalizing(editor, () => {
      if (!subList) {
        // Insert a list child element
        const list = (0, _core.generateElement)(listNode.type, {
          childrenOrText: []
        });
        _slate.Transforms.wrapNodes(editor, list, {
          at: listItemPath
        });
      }
      _slate.Transforms.moveNodes(editor, {
        at: listItemPath,
        to: newPath
      });
      moved = true;
    });
  }
  return moved;
};
exports.movedListItemDown = movedListItemDown;