"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "calcColumnsFromPx", {
  enumerable: true,
  get: function get() {
    return _calcColumnsFromPx.calcColumnsFromPx;
  }
});
exports.calcMediaPxWidth = void 0;
Object.defineProperty(exports, "calcPctFromPx", {
  enumerable: true,
  get: function get() {
    return _calcPctFromPx.calcPctFromPx;
  }
});
exports.calcPctWidth = void 0;
Object.defineProperty(exports, "calcPxFromColumns", {
  enumerable: true,
  get: function get() {
    return _calcPxFromColumns.calcPxFromColumns;
  }
});
Object.defineProperty(exports, "calcPxFromPct", {
  enumerable: true,
  get: function get() {
    return _calcPxFromPct.calcPxFromPct;
  }
});
exports.snapToGrid = exports.layoutSupportsWidth = void 0;
Object.defineProperty(exports, "wrappedLayouts", {
  enumerable: true,
  get: function get() {
    return _wrappedLayouts.wrappedLayouts;
  }
});
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var _calcColumnsFromPx = require("./calcColumnsFromPx");
var _calcPxFromColumns = require("./calcPxFromColumns");
var _calcPxFromPct = require("./calcPxFromPct");
var _wrappedLayouts = require("./wrappedLayouts");
var _calcPctFromPx = require("./calcPctFromPx");
var validWidthModes = ['center', 'wrap-left', 'wrap-right', 'align-start', 'align-end'];
var layoutSupportsWidth = exports.layoutSupportsWidth = function layoutSupportsWidth(layout) {
  return validWidthModes.indexOf(layout) > -1;
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var calcPctWidth = exports.calcPctWidth = function calcPctWidth(containerWidth, pctWidth, origWidth, origHeight) {
  return pctWidth && origWidth && origHeight && Math.ceil((0, _calcPxFromPct.calcPxFromPct)(pctWidth / 100, containerWidth.lineLength || containerWidth.width));
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var calcMediaPxWidth = exports.calcMediaPxWidth = function calcMediaPxWidth(opts) {
  var origWidth = opts.origWidth,
    origHeight = opts.origHeight,
    layout = opts.layout,
    pctWidth = opts.pctWidth,
    containerWidth = opts.containerWidth,
    resizedPctWidth = opts.resizedPctWidth;
  var width = containerWidth.width,
    lineLength = containerWidth.lineLength;
  var calculatedPctWidth = calcPctWidth(containerWidth, pctWidth, origWidth, origHeight);
  var calculatedResizedPctWidth = calcPctWidth(containerWidth, resizedPctWidth, origWidth, origHeight);
  if (layout === 'wide') {
    if (lineLength) {
      var wideWidth = Math.ceil(lineLength * _editorSharedStyles.breakoutWideScaleRatio);
      return wideWidth > width ? lineLength : wideWidth;
    }
  } else if (layout === 'full-width') {
    return width - _editorSharedStyles.akEditorBreakoutPadding;
  } else if (calculatedPctWidth) {
    // Ignored via go/ees005
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    if (_wrappedLayouts.wrappedLayouts.indexOf(layout) > -1) {
      if (calculatedResizedPctWidth) {
        // Ignored via go/ees005
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        if (resizedPctWidth < 50) {
          return calculatedResizedPctWidth;
        }
        return calculatedPctWidth;
      }
      return calculatedPctWidth;
    }
    if (calculatedResizedPctWidth) {
      return calculatedResizedPctWidth;
    }
    return calculatedPctWidth;
  } else if (layout === 'center') {
    if (calculatedResizedPctWidth) {
      return calculatedResizedPctWidth;
    }
    return Math.min(origWidth, lineLength || width);
  } else if (layout && _wrappedLayouts.wrappedLayouts.indexOf(layout) !== -1) {
    // when layout is wrap-left, wrap-right, align-start, align-end
    // but no pctWidth is defined
    return Math.min((0, _calcPxFromPct.calcPxFromPct)(0.5, lineLength || width), origWidth);
  }
  return origWidth;
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var snapToGrid = exports.snapToGrid = function snapToGrid(gridWidth, width, height, lineLength, gridSize) {
  var pxWidth = (0, _calcPxFromPct.calcPxFromPct)(gridWidth / 100, lineLength);
  var columnSpan = Math.round((0, _calcColumnsFromPx.calcColumnsFromPx)(pxWidth, lineLength, gridSize));
  var alignedWidth = (0, _calcPxFromColumns.calcPxFromColumns)(columnSpan, lineLength, gridSize);
  return {
    height: height / width * alignedWidth,
    width: alignedWidth
  };
};
// 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