import { negate, origin } from "./position";
import didStartAfterCritical from "./did-start-after-critical";

const getCombinedItemDisplacement = ({ displaced, afterCritical, combineWith, displacedBy }) => {
  const isDisplaced = Boolean(displaced.visible[combineWith] || displaced.invisible[combineWith]);
  if (didStartAfterCritical(combineWith, afterCritical)) {
    return isDisplaced ? origin : negate(displacedBy.point);
  }
  return isDisplaced ? displacedBy.point : origin;
};

export default getCombinedItemDisplacement;
