"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.alignAttributes = void 0;
Object.defineProperty(exports, "calculateSnapPoints", {
  enumerable: true,
  get: function get() {
    return _calculateSnapPoints.calculateSnapPoints;
  }
});
Object.defineProperty(exports, "floatingLayouts", {
  enumerable: true,
  get: function get() {
    return _floatingLayouts.floatingLayouts;
  }
});
Object.defineProperty(exports, "isRichMediaInsideOfBlockNode", {
  enumerable: true,
  get: function get() {
    return _isRichMediaInsideOfBlockNode.isRichMediaInsideOfBlockNode;
  }
});
Object.defineProperty(exports, "nonWrappedLayouts", {
  enumerable: true,
  get: function get() {
    return _nonWrappedLayouts.nonWrappedLayouts;
  }
});
Object.defineProperty(exports, "shouldAddDefaultWrappedWidth", {
  enumerable: true,
  get: function get() {
    return _shouldAddDefaultWrappedWidth.shouldAddDefaultWrappedWidth;
  }
});
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _wrappedLayouts = require("../ui/MediaSingle/wrappedLayouts");
var _nonWrappedLayouts = require("./nonWrappedLayouts");
var _shouldAddDefaultWrappedWidth = require("./shouldAddDefaultWrappedWidth");
var _floatingLayouts = require("./floatingLayouts");
var _isRichMediaInsideOfBlockNode = require("./isRichMediaInsideOfBlockNode");
var _calculateSnapPoints = require("./calculateSnapPoints");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var alignAttributes = exports.alignAttributes = function alignAttributes(layout, oldAttrs) {
  var gridSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 12;
  var originalWidth = arguments.length > 3 ? arguments[3] : undefined;
  var lineLength = arguments.length > 4 ? arguments[4] : undefined;
  var width = oldAttrs.width;
  var oldLayout = oldAttrs.layout;
  var oldLayoutIsNonWrapped = _nonWrappedLayouts.nonWrappedLayouts.indexOf(oldLayout) > -1;
  var newLayoutIsNonWrapped = _nonWrappedLayouts.nonWrappedLayouts.indexOf(layout) > -1;
  var newLayoutIsWrapped = _wrappedLayouts.wrappedLayouts.indexOf(layout) > -1;
  var oldLayoutIsWrapped = _wrappedLayouts.wrappedLayouts.indexOf(oldLayout) > -1;
  if (oldLayoutIsNonWrapped && (0, _shouldAddDefaultWrappedWidth.shouldAddDefaultWrappedWidth)(layout, originalWidth, lineLength)) {
    // 'full-width' or 'wide' or 'center' -> 'wrap-left' or 'wrap-right' or 'align-end' or 'align-start'
    if (!width || width >= 100 || oldLayout !== 'center' // == 'full-width' or 'wide'
    ) {
      width = 50;
    }
  } else if (layout !== oldLayout && ['full-width', 'wide'].indexOf(oldLayout) > -1) {
    // 'full-width' -> 'center' or 'wide'
    // 'wide' -> 'center' or 'full-width'
    // unset width
    width = undefined;
  } else if (width) {
    var cols = Math.round(width / 100 * gridSize);
    var targetCols = cols;
    if (oldLayoutIsWrapped && newLayoutIsNonWrapped) {
      // wrap -> center needs to align to even grid
      targetCols = Math.floor(targetCols / 2) * 2;
      width = undefined;
    } else if (oldLayoutIsNonWrapped && newLayoutIsWrapped) {
      // Can be here only if
      // 'full-width' or 'wide' or 'center' -> 'wrap-left' or 'wrap-right' or 'align-end' or 'align-start'
      // AND
      // !originalWidth || !lineLength || small image
      // AND
      // width defined!

      // cannot resize to full column width, and cannot resize to 1 column
      if (cols <= 1) {
        targetCols = 2;
      } else if (cols >= gridSize) {
        targetCols = 10;
      }
    }
    if (targetCols !== cols) {
      width = targetCols / gridSize * 100;
    }
  }
  return _objectSpread(_objectSpread({}, oldAttrs), {}, {
    layout: layout,
    width: width
  });
};
// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export