import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import memoizeOne from 'memoize-one';
import { isVerticalPosition } from './utils';
export var getGuidelineSnaps = memoizeOne(function (guidelines, editorWidth) {
  var layout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'center';
  var offset = editorWidth / 2;
  var getPositionX = function getPositionX(position) {
    return isVerticalPosition(position) ? position.x : 0;
  };
  var calcXSnaps = function calcXSnaps(guidelineReference) {
    var snapsWidth = guidelineReference.filter(function (g) {
      return g.width > 0;
    }).map(function (g) {
      return g.width;
    });
    var uniqueSnapWidth = _toConsumableArray(new Set(snapsWidth));
    return snapsWidth.length ? uniqueSnapWidth : undefined;
  };
  var guidelinesSnapsReference = guidelines.map(function (guideline) {
    var positionX = getPositionX(guideline.position);
    if (['align-end', 'wrap-right'].includes(layout)) {
      return {
        guidelineKey: guideline.key,
        width: offset - positionX
      };
    } else if (['align-start', 'wrap-left'].includes(layout)) {
      return {
        guidelineKey: guideline.key,
        width: positionX + offset
      };
    }
    return {
      guidelineKey: guideline.key,
      width: Math.abs(positionX) * 2
    };
  });
  return {
    guidelineReference: guidelinesSnapsReference,
    snaps: {
      x: calcXSnaps(guidelinesSnapsReference)
    }
  };
});