import r from"@babel/runtime/helpers/toConsumableArray";import e from"@babel/runtime/helpers/slicedToArray";import t from"@babel/runtime/helpers/defineProperty";import n from"@babel/runtime/helpers/asyncToGenerator";import a from"@babel/runtime/regenerator";import{useQuery as o}from"@tanstack/react-query";import i from"moment";import{useMemo as c,useState as u,useEffect as s}from"react";import{getQueryKey as p,PADS_URL as l,baseQuery as f,removeViewerAndPDAssets as m,deserializePads as b}from"../constants.js";import{corvaAPI as d}from"../../../clients/index.js";import"../../../utils/index.js";import{mapPad as v}from"./mapPad.js";import{showErrorNotification as g}from"../../../utils/notificationToasts.js";function y(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 h(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?y(Object(n),!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}var w=function(t){var y,w=t.companyId,O=c((function(){return p("nonActivePads",w)}),[w]),j=o({queryKey:O,queryFn:(y=n(a.mark((function r(e){var t,n;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=e.signal,r.next=3,d.get(l,h(h({},f),{},{company:Number(w),current:!1,page:1}),{signal:t});case 3:return n=r.sent,r.abrupt("return",n);case 5:case"end":return r.stop()}}),r)}))),function(r){return y.apply(this,arguments)}),initialData:{data:[],included:[]},select:function(r){var e=m(r.data);return b(e,r.included).map((function(r){return v(r)}))},refetchInterval:i.duration(10,"minutes").asMilliseconds(),enabled:!!w}),k=j.data,x=j.isLoading,P=u([]),A=e(P,2),D=A[0],I=A[1],q=u(!0),E=e(q,2),N=E[0],T=E[1];return s((function(){var e=function(){var e=n(a.mark((function e(t){var n,o;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:I([]),T(!0),e.prev=2,n=2,o=a.mark((function e(){var o,i,c,u,s,p;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=h(h({},f),{},{current:!1,page:n,company:Number(w)}),e.next=3,d.get(l,i,{signal:t});case 3:if(c=e.sent,n+=1,null!=c&&null!==(o=c.data)&&void 0!==o&&o.length){e.next=7;break}return e.abrupt("return","break");case 7:if(u=m(c.data),s=b(u,c.included),p=s.map((function(r){return v(r)})),I((function(e){return[].concat(r(e),r(p))})),!(c.data.length<(null==f?void 0:f.per_page))){e.next=13;break}return e.abrupt("return","break");case 13:case"end":return e.stop()}}),e)}));case 5:if(t.aborted){e.next=12;break}return e.delegateYield(o(),"t0",7);case 7:if("break"!==e.t0){e.next=10;break}return e.abrupt("break",12);case 10:e.next=5;break;case 12:if(!t.aborted){e.next=15;break}return T(!1),e.abrupt("return");case 15:e.next=20;break;case 17:e.prev=17,e.t1=e.catch(2),g("Error fetching non-active pads");case 20:return e.prev=20,T(!1),e.finish(20);case 23:case"end":return e.stop()}}),e,null,[[2,17,20,23]])})));return function(r){return e.apply(this,arguments)}}(),t=new AbortController;e(t.signal);var o=window.setInterval((function(){e(t.signal)}),i.duration(10,"minutes").asMilliseconds());return function(){T(!1),t.abort(),window.clearInterval(o)}}),[w]),{nonActivePads:c((function(){return[].concat(r(k||[]),r(D||[]))}),[k,D]),isNonActivePadsLoading:x||N}};export{w as useNonActivePads};
//# sourceMappingURL=useNonActivePads.js.map
