import { akEditorBreakoutPadding } from '@atlaskit/editor-shared-styles';
import { calcPxFromColumns } from '../ui/MediaSingle/calcPxFromColumns';
export function calculateSnapPoints(_ref) {
  var $pos = _ref.$pos,
    akEditorWideLayoutWidth = _ref.akEditorWideLayoutWidth,
    allowBreakoutSnapPoints = _ref.allowBreakoutSnapPoints,
    containerWidth = _ref.containerWidth,
    gridSize = _ref.gridSize,
    gridWidth = _ref.gridWidth,
    insideInlineLike = _ref.insideInlineLike,
    insideLayout = _ref.insideLayout,
    isVideoFile = _ref.isVideoFile,
    lineLength = _ref.lineLength,
    offsetLeft = _ref.offsetLeft,
    wrappedLayout = _ref.wrappedLayout;
  var snapTargets = [];
  for (var i = 0; i < gridWidth; i++) {
    var pxFromColumns = calcPxFromColumns(i, lineLength, gridWidth);
    snapTargets.push(insideLayout ? pxFromColumns : pxFromColumns - offsetLeft);
  }
  // full width
  snapTargets.push(lineLength - offsetLeft);
  var columns = wrappedLayout || insideInlineLike ? 1 : 2;
  var minimumWidth = calcPxFromColumns(columns, lineLength, gridSize);
  var snapPoints = snapTargets.filter(function (width) {
    return width >= minimumWidth;
  });
  if (!$pos) {
    return snapPoints;
  }
  snapPoints = isVideoFile ? snapPoints.filter(function (width) {
    return width > 320;
  }) : snapPoints;
  var isTopLevel = $pos.parent.type.name === 'doc';
  if (isTopLevel && allowBreakoutSnapPoints) {
    snapPoints.push(akEditorWideLayoutWidth);
    var fullWidthPoint = containerWidth - akEditorBreakoutPadding;
    if (fullWidthPoint > akEditorWideLayoutWidth) {
      snapPoints.push(fullWidthPoint);
    }
  }

  // EDM-1107: Ensure new snapPoints are sorted with existing points
  snapPoints = snapPoints.sort(function (a, b) {
    return a - b;
  });
  return snapPoints;
}