"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getMaxWidthForNestedNode = void 0;
var _floatingLayouts = require("../utils/floatingLayouts");
var _isRichMediaInsideOfBlockNode = require("../utils/isRichMediaInsideOfBlockNode");
/**
 * Get parent width for a nested media single node
 * @param view Editor view
 * @param pos node position
 */
var getMaxWidthForNestedNode = exports.getMaxWidthForNestedNode = function getMaxWidthForNestedNode(view, pos) {
  if (typeof pos !== 'number') {
    return null;
  }
  if ((0, _isRichMediaInsideOfBlockNode.isRichMediaInsideOfBlockNode)(view, pos)) {
    var $pos = view.state.doc.resolve(pos);
    var domNode = view.nodeDOM($pos.pos);
    if ($pos.nodeAfter && _floatingLayouts.floatingLayouts.indexOf($pos.nodeAfter.attrs.layout) > -1 && domNode && domNode.parentElement) {
      return domNode.parentElement.offsetWidth;
    }
    if (domNode instanceof HTMLElement) {
      return domNode.offsetWidth;
    }
  }
  return null;
};