"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.transformListStructure = void 0;
var _isBulletOrOrderedList = require("./isBulletOrOrderedList");
var _isTaskList = require("./isTaskList");
var _listTransforms = require("./list-transforms");
var _listUtils = require("./list-utils");
/**
 * Transform list structure between different list types
 */
var transformListStructure = exports.transformListStructure = function transformListStructure(context) {
  var tr = context.tr,
    sourceNode = context.sourceNode,
    sourcePos = context.sourcePos,
    targetNodeType = context.targetNodeType;
  var nodes = tr.doc.type.schema.nodes;
  var unsupportedContent = [];
  var onhandleUnsupportedContent = function onhandleUnsupportedContent(content) {
    unsupportedContent.push(content);
  };
  try {
    var listNode = {
      node: sourceNode,
      pos: sourcePos
    };
    var sourceList = listNode.node,
      listPos = listNode.pos;
    // const { taskList, listItem, taskItem, paragraph } = nodes;

    var isSourceBulletOrOrdered = (0, _isBulletOrOrderedList.isBulletOrOrderedList)(sourceList.type);
    var isTargetTask = (0, _isTaskList.isTaskList)(targetNodeType);
    var isSourceTask = (0, _isTaskList.isTaskList)(sourceList.type);
    var isTargetBulletOrOrdered = (0, _isBulletOrOrderedList.isBulletOrOrderedList)(targetNodeType);
    var supportedListTypes = (0, _listUtils.getSupportedListTypesSet)(nodes);
    var newList = (0, _listTransforms.transformListRecursively)({
      isSourceBulletOrOrdered: isSourceBulletOrOrdered,
      isSourceTask: isSourceTask,
      isTargetBulletOrOrdered: isTargetBulletOrOrdered,
      isTargetTask: isTargetTask,
      listNode: sourceList,
      schema: tr.doc.type.schema,
      supportedListTypes: supportedListTypes,
      targetNodeType: targetNodeType
    }, onhandleUnsupportedContent);
    tr.replaceWith(listPos, listPos + sourceList.nodeSize, [newList].concat(unsupportedContent));
    return tr;
  } catch (_unused) {
    return tr;
  }
};