import{a as c,b as p}from"./chunk-ZSHAELBT.js";import{J as h,Sd as d,g as n,na as g,oa as m,ta as u}from"./chunk-XJKQ67XR.js";import{e as o}from"./chunk-SZAW6ZBW.js";var a,l=o(()=>{a=function(s){return s[s.Global=0]="Global",s[s.Local=1]="Local",s}(a||{})});var i,f=o(()=>{i=function(s){return s[s.begin=0]="begin",s[s.progress=1]="progress",s[s.finish=2]="finish",s}(i||{})});var L,w=o(()=>{m();g();l();p();f();d();L=(()=>{class s{constructor(){this.receivers=[],this.workList=[],this.subject=new n,this.requestStatusChange=new n,this.poolStatusChange=new n,this.poolsRequestStarter=[],this.workingPools=[],this.pools=[],this._mode=a.Local,this.workCounter=0}get mode(){return this._mode}set mode(t){this.clear(),this._mode=t}isWorking(){return this.subject}requestStatus(t){return t?this.requestStatusChange.pipe(h(e=>e.name===t)):this.requestStatusChange}poolStatus(t){return t?this.poolStatusChange.pipe(h(e=>e.name===t)):this.poolStatusChange}clear(t=!1){this.workCounter=0,t&&(this.receivers=[],this.workList=[],this.poolsRequestStarter=[],this.workingPools=[],this.pools=[]),this.pushValue()}addWork(t){t&&(this.workList.push(t),this.requestStatusChange.next(t),this.checkPoolStartStatus(t)),this.workCounter++,this.pushValue()}removeWork(t){if(t){let e=t.url.replace(c.dvlsUrl,""),r=this.workList.find(k=>k.url===e);this.workList.splice(this.workList.indexOf(r),1),t.name=r?.name,this.requestStatusChange.next(t),this.checkPoolEndStatus(t)}this.workCounter>0&&this.workCounter--,this.pushValue()}addReceiver(t){this.receivers.push(t)}removeReceiver(t){let e=this.receivers.indexOf(t);e>-1&&this.receivers.splice(e,1)}addPool(t,e){let r={name:t,requestNameList:e,workingRequest:[],finishedRequest:[],status:{name:t,error:!1,status:i.finish},takeUntil:()=>{}};return r.takeUntil=this.takeUntil.bind(this,r),this.pools.push(r),this.poolsRequestStarter.push(e[0]),r}removePool(t){this.poolsRequestStarter.splice(this.poolsRequestStarter.indexOf(t.requestNameList[0]),1),this.pools.splice(this.pools.indexOf(t),1)}takeUntil(t,e){e.subscribe(()=>{this.removePool(t)})}pushValue(){let t={isLoading:this.workCounter>0,receiver:this.getCurrentReceiver(),mode:this._mode};this.subject.next(t)}getCurrentReceiver(){let t=null;return this.receivers.length!==0&&(t=this.receivers[this.receivers.length-1]),t}checkPoolStartStatus(t){this.checkPoolStarting(t),this.checkPoolStartedRequestStatus(t)}checkPoolStarting(t){let e=this.poolsRequestStarter.indexOf(t.name);e>-1&&(this.pools[e].workingRequest.push(t.name),this.pools[e].status.status=i.begin,this.workingPools.push(this.pools[e]),this.poolStatusChange.next(this.pools[e].status))}checkPoolStartedRequestStatus(t){this.workingPools.filter(e=>e.requestNameList.indexOf(t.name)>-1&&e.finishedRequest.indexOf(t.name)<0).forEach(e=>{e.status.status=i.progress,e.status.currentRequestStatus=i.begin,e.status.currentRequestName=t.name,e.status.currentRequestError=!1,this.poolStatusChange.next(e.status),e.workingRequest.push(t.name)})}checkPoolEndStatus(t){this.workingPools.filter(e=>e.workingRequest.indexOf(t.name)>-1).forEach(e=>{e.workingRequest=e.workingRequest.splice(e.workingRequest.indexOf(t.name),1),e.finishedRequest.push(t.name),e.status.error=e.status.error?!0:t.error,e.status.currentRequestStatus=i.finish,e.status.currentRequestName=t.name,e.status.currentRequestError=t.error,this.poolStatusChange.next(e.status),this.checkPoolStatus(e)})}checkPoolStatus(t){(t.requestNameList.length===t.finishedRequest.length||t.status.error)&&(t.workingRequest=[],t.finishedRequest=[],t.status.status=i.finish,this.workingPools.splice(this.workingPools.indexOf(t),1),this.poolStatusChange.next(t.status))}static{this.\u0275fac=function(e){return new(e||s)}}static{this.\u0275prov=u({token:s,factory:s.\u0275fac,providedIn:"root"})}}return s})()});export{i as a,f as b,a as c,l as d,L as e,w as f};
