import createFluidScroller from "./fluid-scroller";
import createJumpScroller from "./jump-scroller";

const autoScroller = ({ scrollDroppable, scrollWindow, move }) => {
  const fluidScroller = createFluidScroller({
    scrollWindow,
    scrollDroppable
  });
  const jumpScroll = createJumpScroller({
    move,
    scrollWindow,
    scrollDroppable
  });
  const scroll = (state) => {
    // Only allowing auto scrolling in the DRAGGING phase
    if (state.phase !== "DRAGGING") {
      return;
    }
    if (state.movementMode === "FLUID") {
      fluidScroller.scroll(state);
      return;
    }
    if (!state.scrollJumpRequest) {
      return;
    }
    jumpScroll(state);
  };
  const scroller = {
    scroll,
    start: fluidScroller.start,
    stop: fluidScroller.stop
  };
  return scroller;
};

export default autoScroller;
