import r from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/slicedToArray";import n from"@babel/runtime/regenerator";import{useState as o,useEffect as c,useMemo as i}from"react";import{debounce as u,groupBy as a,every as p,flatten as s,toPairs as f}from"lodash";import{fetchAllAssets as l}from"../utils/apiCalls.js";function m(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 b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?m(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}var y=u((function(r){r()}),500);function O(u,m,O,h,j){var v=o([]),d=t(v,2),w=d[0],P=d[1],g=o(!1),k=t(g,2),x=k[0],D=k[1],C=o({}),T=t(C,2),A=T[0],E=T[1];return c((function(){function t(){return(t=e(n.mark((function e(){var t,o;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,l(u,m,O,h);case 3:t=e.sent,o=s(f(A).filter((function(r){return+r[0]<+O})).map((function(r){return r[1]}))).concat(t),P(o),E((function(e){return b(b({},e),{},r({searchKey:u,assetType:m},O,t))})),D(!1),e.next=14;break;case 10:e.prev=10,e.t0=e.catch(0),console.error(e.t0),D(!1);case 14:case"end":return e.stop()}}),e,null,[[0,10]])})))).apply(this,arguments)}D(!0),y((function(){return t.apply(this,arguments)}))}),[u,m,O,h]),[x,i((function(){var r=w.map((function(r){return b(b({},r),{},{checked:j.includes(r.redirectAssetId)})})).filter((function(r){return(!m||r.type===m)&&function(r,e){var t=(e||"").split(" ");return p(t,(function(e){return r.toLowerCase().includes(e||"")}))}(r.name,(u||"").toLowerCase())}));return Object.entries(a(r,"type"))}),[u,w,m,j])]}export{O as useAssetsData};
