"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isListNested = exports.hasListChild = exports.getListItemEntry = void 0;
var _slate = require("slate");
var _elementTypes = require("../../../constants/element-types");
var _constant = require("../constant");
const getListItemEntry = function (editor) {
  let {
    at = editor.selection
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  let _at = null;
  if (_slate.Range.isRange(at) && !_slate.Range.isCollapsed(at)) {
    _at = at.focus.path;
  } else if (_slate.Range.isRange(at)) {
    _at = at.anchor.path;
  } else {
    _at = at;
  }
  if (_at) {
    const node = _slate.Node.get(editor, _at);
    if (node) {
      const listItem = _slate.Editor.above(editor, {
        at: _at,
        match: n => _slate.Element.isElement(n) && n.type === _elementTypes.LIST_ITEM
      });
      if (listItem) {
        const list = _slate.Editor.parent(editor, listItem[1]);
        return {
          list,
          listItem
        };
      }
    }
  }
  return null;
};
exports.getListItemEntry = getListItemEntry;
const hasListChild = node => {
  return node.children.some(n => {
    return _slate.Element.isElement(n) && _constant.LIST_TYPES.includes(n.type);
  });
};
exports.hasListChild = hasListChild;
const isListNested = (editor, listPath) => {
  var _Editor$parent;
  const listParentNode = (_Editor$parent = _slate.Editor.parent(editor, listPath)) === null || _Editor$parent === void 0 ? void 0 : _Editor$parent[0];
  return (listParentNode === null || listParentNode === void 0 ? void 0 : listParentNode.type) === _elementTypes.LIST_ITEM;
};
exports.isListNested = isListNested;