"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useScroll = useScroll;
var _react = require("react");
function useScroll(tableRef, bottomEndScrollOffset, onScrollEnd, isLoading) {
  const {
    scrollHeight,
    scrollTop,
    clientHeight
  } = tableRef.current || {};
  const elementPresent = scrollHeight && scrollTop && clientHeight;
  const isScrollToEnd = elementPresent && scrollHeight - scrollTop - clientHeight < bottomEndScrollOffset;
  const notEnoughForScroll = scrollHeight === clientHeight;
  (0, _react.useEffect)(() => {
    if (isScrollToEnd || notEnoughForScroll) {
      onScrollEnd();
    }
  }, [scrollHeight, scrollTop, clientHeight]);
  (0, _react.useEffect)(() => {
    if (!isLoading && (isScrollToEnd || notEnoughForScroll)) {
      onScrollEnd();
    }
  }, [isLoading]);
}