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