import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/slicedToArray";import t from"@babel/runtime/regenerator";import{useState as n,useRef as o,useCallback as a,useMemo as p,useEffect as s}from"react";import{debounce as i}from"lodash";import"../../../../AppCommonsProvider/AppCommonsProvider.js";import{useAppCommons as m}from"../../../../AppCommonsProvider/AppCommonsContext.js";import{isCorrectAssetType as c}from"./constants.js";import{loadAssets as u}from"./loadAssets.js";var f=function(f,l,d){var v=m().appKey,h=n(""),b=e(h,2),g=b[0],y=b[1],x=n(!1),A=e(x,2),C=A[0],P=A[1],j=n([]),k=e(j,2),T=k[0],w=k[1],S=o(!0),V=o(g),_=a(function(){var e=r(t.mark((function r(e,n,o){var a;return t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(P(!!e.trim()||!!o),V.current=e,(e.trim()||o)&&c(f)){r.next=6;break}return w([]),P(!1),r.abrupt("return");case 6:return r.prev=6,r.next=9,u({assetType:f,parentId:o,searchString:e,page:n,perPage:50,parentType:d,additionalParams:"rig"!==f&&"frac_fleet"!==f||!v?void 0:{app_key:v}});case 9:a=r.sent,e===V.current&&(w(a),a.length<50&&(S.current=!1),P(!1)),r.next=17;break;case 13:r.prev=13,r.t0=r.catch(6),console.error(r.t0),P(!1);case 17:case"end":return r.stop()}}),r,null,[[6,13]])})));return function(r,t,n){return e.apply(this,arguments)}}(),[f,d,v]),G=p((function(){return i(_,500)}),[_]),I=g.trim();return s((function(){G(I,1,l)}),[G,I,l]),{searchValue:g,setSearchValue:y,isLoading:C,results:T}};export{f as useLoadAssets};
//# sourceMappingURL=useLoadAssets.js.map
