import getDisplacementGroups from "../get-displacement-groups";

function getDraggables(ids, draggables) {
  return ids.map((id) => draggables[id]);
}

const recompute = ({ impact, viewport, draggables, destination, forceShouldAnimate }) => {
  const last = impact.displaced;
  const afterDragging = getDraggables(last.all, draggables);
  const displaced = getDisplacementGroups({
    afterDragging,
    destination,
    displacedBy: impact.displacedBy,
    viewport: viewport.frame,
    forceShouldAnimate,
    last
  });
  return {
    ...impact,
    displaced
  };
};

export default recompute;
