"use strict";

exports.__esModule = true;
exports.withInfiniteScroll = exports.getOnScroll = exports.default = void 0;
var _recompose = require("recompose");
var _utils = require("../utils");
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var getOnScroll = exports.getOnScroll = function getOnScroll(_, _ref) {
  var _ref$onScroll = _ref.onScroll,
    onScroll = _ref$onScroll === void 0 ? function () {} : _ref$onScroll,
    scrollLoader = _ref.scrollLoader,
    _ref$loadTrigger = _ref.loadTrigger,
    loadTrigger = _ref$loadTrigger === void 0 ? 200 : _ref$loadTrigger,
    _ref$length = _ref.length,
    length = _ref$length === void 0 ? 0 : _ref$length,
    _ref$latestPage = _ref.latestPage,
    latestPage = _ref$latestPage === void 0 ? 1 : _ref$latestPage,
    _ref$pageLength = _ref.pageLength,
    pageLength = _ref$pageLength === void 0 ? 20 : _ref$pageLength;
  var scrollCheck = (0, _utils.debounce)(function (event) {
    if (
    // Are we scrolled far enough?
    event.target.scrollHeight - (event.target.scrollTop + event.target.offsetHeight) < loadTrigger &&
    // Are we already loading?
    length === latestPage * pageLength) {
      scrollLoader(latestPage + 1);
    }
  }, 200, true);
  return function (event) {
    scrollCheck(event);
    onScroll(event);
    return {
      scrollTop: event.target.scrollTop
    };
  };
};
var withInfiniteScroll = exports.withInfiniteScroll = (0, _recompose.withStateHandlers)(function (_ref2) {
  var _ref2$initialScrollTo = _ref2.initialScrollTop,
    initialScrollTop = _ref2$initialScrollTo === void 0 ? 0 : _ref2$initialScrollTo;
  return {
    scrollTop: initialScrollTop,
    virtual: true
  };
}, {
  onScroll: getOnScroll
});
var _default = withInfiniteScroll;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(getOnScroll, "getOnScroll", "/home/vsts/work/1/s/src/hocs/withInfiniteScroll.js");
  reactHotLoader.register(withInfiniteScroll, "withInfiniteScroll", "/home/vsts/work/1/s/src/hocs/withInfiniteScroll.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/hocs/withInfiniteScroll.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(getOnScroll, "getOnScroll", "/home/vsts/work/1/s/src/hocs/withInfiniteScroll.js");
  reactHotLoader.register(withInfiniteScroll, "withInfiniteScroll", "/home/vsts/work/1/s/src/hocs/withInfiniteScroll.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/hocs/withInfiniteScroll.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();