"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/helpers/toConsumableArray"),t=require("@babel/runtime/helpers/asyncToGenerator"),n=require("@babel/runtime/helpers/slicedToArray"),u=require("@babel/runtime/regenerator"),a=require("react"),c=require("lodash");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(e),i=o(r),f=o(t),l=o(n),p=o(u);function b(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function d(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?b(Object(t),!0).forEach((function(r){s.default(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):b(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}exports.useInfiniteScroll=function(e){var r=e.loadData,t=e.filters,n=e.getParams,u=e.perPage,o=void 0===u?100:u,s=a.useRef(),b=a.useState([]),O=l.default(b,2),y=O[0],v=O[1],h=a.useState(!1),g=l.default(h,2),m=g[0],j=g[1],P=a.useRef(!1),w=a.useRef(!1),x=a.useRef(0),R=a.useRef(!1),q=a.useState(null),E=l.default(q,2),k=E[0],D=E[1],S=a.useRef(null),C=a.useCallback(function(){var e=f.default(p.default.mark((function e(t){var n;return p.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return j(!0),w.current=!0,e.next=4,r(t);case 4:n=e.sent,c.isEqual(t,s.current)&&(P.current=n.length>=o,v((function(e){return[].concat(i.default(e),i.default(n))})),j(!1),w.current=!1);case 6:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}(),[o,r]),A=a.useCallback(f.default(p.default.mark((function e(){var r;return p.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!w.current&&P.current){e.next=2;break}return e.abrupt("return");case 2:return x.current+=1,r=n(d(d({},t),{},{page:x.current,perPage:o})),s.current=r,e.next=7,C(r);case 7:if(!R.current){e.next=10;break}return e.next=10,A();case 10:case"end":return e.stop()}}),e)}))),[n,t,o,C]);return a.useEffect((function(){var e=new IntersectionObserver((function(e){e.forEach((function(e){e.target===k&&(R.current=e.intersectionRatio>0,R.current&&A())}))}),{threshold:1,root:S.current});return k&&e.observe(k),function(){e.disconnect()}}),[A,k]),a.useEffect((function(){v([]),w.current=!1,P.current=!0,x.current=0,k&&A()}),[A,k]),{data:y,setData:v,isLoading:m,loadMoreElementRef:D,containerElementRef:S}};
//# sourceMappingURL=useInfiniteScroll.js.map
