import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { DepEdgeGroups } from '../../../component/constants';
export var getGroupsAroundNode = function getGroupsAroundNode(moduleNode, importedNodes) {
  var _groups;

  var groups = (_groups = {}, _defineProperty(_groups, DepEdgeGroups.TOP_LEFT, []), _defineProperty(_groups, DepEdgeGroups.TOP_RIGHT, []), _defineProperty(_groups, DepEdgeGroups.BOTTOM_LEFT, []), _defineProperty(_groups, DepEdgeGroups.BOTTOM_RIGHT, []), _groups);
  var _ref = [moduleNode.y, moduleNode.x],
      mX = _ref[0],
      mY = _ref[1];
  importedNodes.sort(function (a, b) {
    var aDiff = Math.abs(mY - a.x); // swap coordinates

    var bDiff = Math.abs(mY - b.x); // swap coordinates

    if (aDiff < bDiff) {
      return -1;
    }

    if (aDiff > bDiff) {
      return 1;
    }

    return 0;
  }).forEach(function (importedNode) {
    var _ref2 = [importedNode.y, importedNode.x],
        iX = _ref2[0],
        iY = _ref2[1];

    if (iY < mY) {
      if (iX < mX) {
        groups[DepEdgeGroups.TOP_LEFT].push(importedNode);
      } else {
        groups[DepEdgeGroups.TOP_RIGHT].push(importedNode);
      }
    } else {
      if (iX < mX) {
        groups[DepEdgeGroups.BOTTOM_LEFT].push(importedNode);
      } else {
        groups[DepEdgeGroups.BOTTOM_RIGHT].push(importedNode);
      }
    }
  });
  return groups;
};
export var checkIsEdgeSelected = function checkIsEdgeSelected(selectedEdge, target, source) {
  if (selectedEdge.target && selectedEdge.sources.length > 1) {
    return selectedEdge.target === target;
  }

  if (!source) {
    return selectedEdge.target === target;
  }

  return selectedEdge.target === target && selectedEdge.sources[0] === source;
};