"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _throttle = _interopRequireDefault(require("lodash/throttle"));

var _react = require("react");

var _events = _interopRequireDefault(require("../utils/events"));

var useScroll = function useScroll(_ref) {
  var container = _ref.container,
      onScroll = _ref.onScroll,
      _ref$wait = _ref.wait,
      wait = _ref$wait === void 0 ? 200 : _ref$wait;
  (0, _react.useEffect)(function () {
    var handler = (0, _throttle.default)(function (event) {
      // console.log(`[${Date.now()}] handler`);
      typeof onScroll === 'function' && onScroll(event);
    }, wait);

    if (container.current) {
      _events.default.on(container.current, 'scroll', handler);
    }

    return function () {
      if (container.current) {
        _events.default.off(container.current, 'scroll', handler);
      }
    };
  }, [container]);
};

var _default = useScroll;
exports.default = _default;