import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/slicedToArray";import{useState as r,useRef as i,useLayoutEffect as n}from"react";import{initialDataFetcher as o}from"../utils/initialDataFetcher.js";import a from"./useWellStreamsData.js";import{socketClient as c}from"../../../clients/index.js";function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function m(e){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?s(Object(i),!0).forEach((function(r){t(e,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var l={provider:"corva",collection:"completion.wits",event:"",params:{fields:"timestamp,collection,asset_id",limit:1,sort:"{ timestamp: -1 }"}},p={provider:"corva",collection:"wireline.wits",event:"",params:{fields:"timestamp,collection,asset_id,data.state",limit:1,sort:"{ timestamp: -1 }"}};function u(t){var s=t.currentWellId,u=t.isStatusShown,f=t.withSubscription,b=r({timestamp:0}),d=e(b,2),v=d[0],O=d[1],h=r({timestamp:0}),j=e(h,2),w=j[0],y=j[1],P=i([]),g=a({isStatusShown:u,currentWellId:s,wirelineData:v,fracData:w}),D=function(t){var e=t.data[0]||{},r=e.collection,i=e.timestamp,n=e.data,o=e.stage_number;if(!i)return O({timestamp:0}),void y({timestamp:0});r===p.collection?O((function(t){return m(m({},t),{},{timestamp:i,stageNumber:o,data:n})})):r===l.collection&&y((function(t){return m(m({},t),{},{timestamp:i})}))},S=function(t,e){var r={provider:e.provider,collection:e.collection,event:e.event,params:e.params,assetId:t},i=c.subscribe(r,{onDataReceive:D});P.current.push(i)};return n((function(){if(s){var t=o(l),e=o(p),r=[t(s),e(s)];return f&&(S(s,l),S(s,p)),Promise.all(r).then((function(t){t.forEach((function(t){t&&D({data:t})}))})),function(){P.current.forEach((function(t){return t()})),P.current=[],O({timestamp:0}),y({timestamp:0})}}}),[s]),g}export{u as useWellStreamActivityTypeSubscription};
//# sourceMappingURL=useWellStreamActivityTypeSubscription.js.map
