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