"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/asyncToGenerator"),r=require("@babel/runtime/helpers/slicedToArray"),n=require("@babel/runtime/regenerator"),u=require("react"),c=require("lodash"),a=require("../utils/apiCalls.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(e),i=o(t),f=o(r),l=o(n);function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){s.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var d=c.debounce((function(e){e()}),500);exports.useAssetsData=function(e,t,r,n,o){var p=u.useState([]),y=f.default(p,2),O=y[0],v=y[1],h=u.useState(!1),j=f.default(h,2),m=j[0],P=j[1],w=u.useState({}),g=f.default(w,2),q=g[0],x=g[1];return u.useEffect((function(){function u(){return(u=i.default(l.default.mark((function u(){var o,i;return l.default.wrap((function(u){for(;;)switch(u.prev=u.next){case 0:return u.prev=0,u.next=3,a.fetchAllAssets(e,t,r,n);case 3:o=u.sent,i=c.flatten(c.toPairs(q).filter((function(e){return+e[0]<+r})).map((function(e){return e[1]}))).concat(o),v(i),x((function(n){return b(b({},n),{},s.default({searchKey:e,assetType:t},r,o))})),P(!1),u.next=14;break;case 10:u.prev=10,u.t0=u.catch(0),console.error(u.t0),P(!1);case 14:case"end":return u.stop()}}),u,null,[[0,10]])})))).apply(this,arguments)}P(!0),d((function(){return u.apply(this,arguments)}))}),[e,t,r,n]),[m,u.useMemo((function(){var r=O.map((function(e){return b(b({},e),{},{checked:o.includes(e.redirectAssetId)})})).filter((function(r){return(!t||r.type===t)&&function(e,t){var r=(t||"").split(" ");return c.every(r,(function(t){return e.toLowerCase().includes(t||"")}))}(r.name,(e||"").toLowerCase())}));return Object.entries(c.groupBy(r,"type"))}),[e,O,t,o])]};
