import{__assign as t}from'./../../../ext-esm/tslib/tslib.es6.js';import{useState as e,useRef as i,useLayoutEffect as r}from"react";import{socketClient as a}from"../../../clients/index.js";import n from"./useWellStreamsData.js";import{initialDataFetcher as o}from"../utils/initialDataFetcher.js";var s={provider:"corva",collection:"completion.wits",event:"",params:{fields:"timestamp,collection,asset_id",limit:1,sort:"{ timestamp: -1 }"}},m={provider:"corva",collection:"wireline.wits",event:"",params:{fields:"timestamp,collection,asset_id,data.state",limit:1,sort:"{ timestamp: -1 }"}};function c(c){var l=c.currentWellId,u=c.isStatusShown,p=c.withSubscription,f=e({timestamp:0}),d=f[0],v=f[1],h=e({timestamp:0}),b=h[0],w=h[1],S=i([]),D=n({isStatusShown:u,currentWellId:l,wirelineData:d,fracData:b}),j=function(e){var i=e.data[0]||{},r=i.collection,a=i.timestamp,n=i.data,o=i.stage_number;a&&(r===m.collection?v((function(e){return t(t({},e),{timestamp:a,stageNumber:o,data:n})})):r===s.collection&&w((function(e){return t(t({},e),{timestamp:a})})))},_=function(e,i){var r=t(t({},i),{assetId:e}),n=a.subscribe(r,{onDataReceive:j});S.current.push(n)};return r((function(){if(l){var t=o(s),e=o(m),i=[t(l),e(l)];return p&&(_(l,s),_(l,m)),Promise.all(i).then((function(t){t.forEach((function(t){j({data:t})}))})),function(){S.current.forEach((function(t){return t()})),S.current=[],v({timestamp:0}),w({timestamp:0})}}}),[l]),D}export{c as useWellStreamActivityTypeSubscription};
