"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isExpandCollapsed = exports.getNextNodeExpandPos = exports.expandedState = void 0;
var _utils = require("@atlaskit/editor-prosemirror/utils");
// Used to store the state of the new single player expand node
var expandedState = exports.expandedState = new WeakMap();

// used to determine if the expand is expanded or collapsed
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var isExpandCollapsed = exports.isExpandCollapsed = function isExpandCollapsed(node) {
  var _expandedState$get;
  // @ts-ignore - TS2869 TypeScript 5.9.2 upgrade
  return (_expandedState$get = !expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false;
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var getNextNodeExpandPos = exports.getNextNodeExpandPos = function getNextNodeExpandPos(editorView, selection) {
  var parentNode = (0, _utils.findParentNodeOfType)([editorView.state.schema.nodes.listItem, editorView.state.schema.nodes.heading, editorView.state.schema.nodes.blockquote, editorView.state.schema.nodes.taskItem, editorView.state.schema.nodes.mediaSingle])(selection);
  var tableRowNode = (0, _utils.findParentNodeOfType)([editorView.state.schema.nodes.tableRow])(selection);
  if (tableRowNode) {
    parentNode = tableRowNode;
  }
  if (!parentNode) {
    var paragraphNode = (0, _utils.findParentNodeOfType)([editorView.state.schema.nodes.paragraph])(selection);
    if (!paragraphNode) {
      return;
    }
    parentNode = paragraphNode;
  }
  if (!parentNode) {
    return undefined;
  }
  var endPosOffset = parentNode && ['taskItem', 'listItem', 'tableRow'].includes(parentNode.node.type.name) ? 1 : 0;
  var endOfTextblockPos = parentNode.start + parentNode.node.content.size + endPosOffset + 1;
  if (endOfTextblockPos > editorView.state.doc.content.size) {
    return undefined;
  }
  var $endOfTextblockPos = editorView.state.doc.resolve(endOfTextblockPos);
  if ($endOfTextblockPos !== null && $endOfTextblockPos !== void 0 && $endOfTextblockPos.nodeAfter && ['expand', 'nestedExpand'].includes($endOfTextblockPos.nodeAfter.type.name)) {
    return endOfTextblockPos + 1;
  }
  return undefined;
};