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