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