"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.joinListItemForward = void 0;

var _commands = require("../../../../utils/commands");

var _joinListItemsForward = require("../actions/join-list-items-forward");

var joinListItemForward = function joinListItemForward(state, dispatch) {
  var tr = state.tr,
      $head = state.selection.$head;
  var walkNode = (0, _commands.walkNextNode)($head);

  if (!(0, _commands.isEmptySelectionAtEnd)(state)) {
    return false;
  }

  var scenarios = (0, _joinListItemsForward.calcJoinListScenario)(walkNode, $head);

  if (!scenarios) {
    return false;
  }

  var action = scenarios;
  var result = action({
    tr: tr,
    $next: walkNode.$pos,
    $head: $head
  });

  if (!result) {
    return false;
  }

  if (dispatch) {
    dispatch(tr);
  }

  return true;
};

exports.joinListItemForward = joinListItemForward;