export interface ScrollPositionParams {
  scrollHeight: number;
  clientHeight: number;
  scrollTop: number;
}

export interface ScrollPosition extends ScrollPositionParams {}

export class ScrollPosition {
  scrollHeight: number;
  clientHeight: number;
  scrollTop: number;

  constructor(params: ScrollPositionParams) {
    this.scrollHeight = params.scrollHeight;
    this.clientHeight = params.clientHeight;
    this.scrollTop = params.scrollTop;
  }

  isScrollDown(other: ScrollPosition) {
    return this.scrollTop >= other.scrollTop;
  }

  // private reachedBottom(prev: ScrollPosition, offset: number = 0) {
  //   const { scrollHeight } = this;
  //
  //   return this.reachedTo(prev, scrollHeight, offset);
  // }

  reachingTo(prev: ScrollPosition, bottomX: number, offsetPX: number = 0) {
    return this.isScrollDown(prev) && this.reachedTo(bottomX, offsetPX);
  }

  reachedTo(bottomX: number, offsetPX: number = 0) {
    const { clientHeight, scrollTop } = this;

    return scrollTop + clientHeight + offsetPX > bottomX;
  }
}
