import { CC_NODE_TYPE } from '../../constants';
export var calculateLayoutProps = function calculateLayoutProps(list) {
  var padding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 120;

  if (!list) {
    return {
      width: 0,
      height: 0
    };
  }

  var minX = 0,
      minY = 0,
      maxX = 0,
      maxY = 0;
  var ccAlightPoint = 0;
  var maxCcWidth = 0;
  list.each(function (node) {
    var _ref = [node.y, node.x],
        x = _ref[0],
        y = _ref[1];
    var _ref2 = [node.ySize, node.xSize],
        xSize = _ref2[0],
        ySize = _ref2[1]; // calc cc vertical line

    if (node.data.type === CC_NODE_TYPE) {
      if (xSize > maxCcWidth) {
        maxCcWidth = xSize;
      }
    } else {
      if (x + xSize > ccAlightPoint) {
        ccAlightPoint = x + xSize;
      }
    }

    if (x < minX) {
      minX = x;
    }

    if (y < minY) {
      minY = y;
    }

    if (x + xSize > maxX) {
      maxX = x + xSize;
    }

    if (y + ySize > maxY) {
      maxY = y + ySize;
    }
  });
  var yShift = Math.abs(Math.round(minY)) + 20;
  var height = Math.round(Math.abs(maxY) + Math.abs(yShift)) + 5;
  var width = Math.round(Math.abs(maxX + maxCcWidth) + Math.abs(minX) + 2 * padding);
  return {
    xShift: padding / 4,
    width: width,
    height: height,
    yShift: yShift,
    ccAlightPoint: ccAlightPoint
  };
};
export var buildShiftToPoint = function buildShiftToPoint(shift) {
  return function (x, y) {
    return {
      x: Math.round(shift.x + x),
      y: Math.round(shift.y + y)
    };
  };
};