"use strict";var e=require("@babel/runtime/helpers/asyncToGenerator"),r=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),n=require("@babel/runtime/regenerator"),u=require("react"),i=require("lodash"),a=require("./utils.js"),s=require("./dataResolvers.js"),c=require("../../../../utils/devcenter.js"),o=require("./constants.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=l(e),p=l(r),d=l(t),v=l(n);function h(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 b(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?h(Object(t),!0).forEach((function(r){p.default(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):h(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}module.exports=function(e){var r=e.apps,t=e.dashboardAssetId,n=u.useState({}),l=d.default(n,2),p=l[0],h=l[1],g=u.useRef(),A=u.useRef(),y=u.useRef({}),O=u.useRef({wellsById:{},rigsById:{},fracFleetsById:{},interventionUnitsById:{},deprecatedAssetData:{}}),j=r.reduce((function(e,r){var t=i.get(r,["app","ui_settings","multi_rig"]);return c.isDevCenterApp(r)&&!t&&e.push(b(b({},r),{},{appHash:a.getAppHash(r)})),e}),[]),E=function(e){return h((function(r){return i.mapValues(r,(function(r){var t=e[r.id]||{};return b(b(b({},r),t),{},{isLoading:!1})}))}))},S=function(e){O.current=i.merge(O.current,e)};u.useEffect((function(){var e=Object.values(p);if(j.length||e.length)if(j.length<e.length){var r=i.keyBy(j,"id"),n=e.find((function(e){return!r[e.id]})).id;h((function(e){return i.omit(e,n)}))}else{var u=j.filter((function(e){return!p[e.id]||p[e.id].appHash!==e.appHash}));h((function(e){return b(b({},e),a.getInitialAppsDataState(u))})),s.resolveAppsData({apps:j,dashboardAssetId:t,cache:O,updateCache:S}).then(E)}}),[String(j.map((function(e){return e.appHash}))),t]),y.current={apps:j,dashboardAssetId:t,cache:O,updateCache:S},u.useEffect((function(){return g.current=setInterval((function(){s.resolveAppsData(b(b({},y.current),{},{requests:[o.APPS_DATA_REQUESTS.FRAC_FLEET_WELLS,o.APPS_DATA_REQUESTS.PAD_WELLS]})).then(E)}),3e5),function(){return clearInterval(g.current)}}),[]);var m=j.some(a.isAppNeedingInterventionUnitWellRefresh);return u.useEffect((function(){if(m)return A.current=setInterval(f.default(v.default.mark((function e(){var r,t,n;return v.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=y.current.apps,t=new Set(r.filter(a.isAppNeedingInterventionUnitWellRefresh).map((function(e){return e.id}))),e.next=4,s.resolveAppsData(b(b({},y.current),{},{requests:[o.APPS_DATA_REQUESTS.INTERVENTION_UNIT_WELLS]}));case 4:n=e.sent,h((function(e){var r=Object.entries(e);return r.some((function(e){var r,u,i=d.default(e,2),a=i[0],s=i[1];if(!t.has(a))return!1;var c=n[a];return!!c&&(null===(r=c.well)||void 0===r?void 0:r.id)!==(null===(u=s.well)||void 0===u?void 0:u.id)}))?r.reduce((function(e,r){var u,i,a=d.default(r,2),s=a[0],c=a[1];if(!t.has(s))return e[s]=c,e;var o=n[s];return o&&(null===(u=o.well)||void 0===u?void 0:u.id)!==(null===(i=c.well)||void 0===i?void 0:i.id)?(e[s]=b(b(b({},c),o),{},{isLoading:!1}),e):(e[s]=c,e)}),{}):e}));case 6:case"end":return e.stop()}}),e)}))),3e5),function(){return clearInterval(A.current)}}),[m]),p};
//# sourceMappingURL=useAppsData.js.map
