import r from"@babel/runtime/helpers/toConsumableArray";import t from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/slicedToArray";import n from"@babel/runtime/regenerator";import{useState as o,useRef as s,useEffect as i,useCallback as c}from"react";import{debounce as u,groupBy as a}from"lodash";import"@babel/runtime/helpers/defineProperty";import"uuid";import"lodash/set";import"lodash/get";import"lodash/unset";import"moment";import"../../../../../../clients/jsonApi/index.js";import"../../../../../../clients/subscriptions/constants.js";import"../../../../../../clients/subscriptions.v1.js";import"../../../../../../clients/subscriptions/subscriptions-client.factory.js";import"../../../../../../clients/api/apiCore.js";import"../../../../../../clients/constants.js";import"../../../../../../clients/sso/auth0.js";import"../../../../../../clients/sso/oauth2.js";import"../../../../../../clients/api/rateLimiter.js";import{fetchAllAssets as p}from"../../../../api/assets/fetchAllAssets.js";import{ROWS_PER_PAGE as m}from"../../../../constants.js";import{MAX_EMPTY_PAGES as l}from"./useAssetsData.utils.js";var f=function(f,h,b){var j=o(1),v=e(j,2),d=v[0],g=v[1],y=o([]),A=e(y,2),x=A[0],k=A[1],w=o(!1),C=e(w,2),D=C[0],F=C[1],M=o(!1),T=e(M,2),G=T[0],L=T[1],O=s(u((function(r){return r()}),500)),P=s(!1),q=s(0),z=s(0),B=s(0),E=s(!1),H=function(r){L(r),P.current=r},I=function(){E.current=!0,g((function(r){return r+1}))};i((function(){var r=O.current;return function(){return r.cancel()}}),[]),i((function(){k([]),H(!1),g(1),q.current=0,z.current=0,B.current=0,E.current=!1}),[f,h]),i((function(){var e=!1,o=function(){var o=t(n.mark((function t(){var o,s;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,p(f,h,d,b);case 3:if(o=t.sent,!e){t.next=6;break}return t.abrupt("return");case 6:s=h?o.length>=m:Object.values(a(o,"type")).some((function(r){return r.length>=m})),H(s),k((function(t){return 1===d?o:[].concat(r(t),r(o))})),F(!1),t.next=16;break;case 12:t.prev=12,t.t0=t.catch(0),console.error(t.t0),e||F(!1);case 16:case"end":return t.stop()}}),t,null,[[0,12]])})));return function(){return o.apply(this,arguments)}}();return F(!0),E.current?(E.current=!1,O.current.cancel(),o()):O.current(o),function(){e=!0}}),[f,h,d,b]);var J=c((function(r){var t=x.length!==q.current;if(q.current=x.length,t){if(r>z.current)return z.current=r,void(B.current=0);z.current=r,B.current>=l||P.current&&(B.current+=1,I())}}),[x.length]),K=c((function(r){!G||D||r||(B.current=0,I())}),[G,D]);return{assetsData:x,isFetching:D,hasMore:G,loadMore:K,maybeAutoFetch:J}};export{f as useAssetsFetch};
//# sourceMappingURL=useAssetsFetch.js.map
