import{a as l,b as w}from"./chunk-AJ7ODGYR.js";import{J as a,Sa as p,be as d,g as o,na as m,ta as c}from"./chunk-WL5U2YIT.js";import{e as h}from"./chunk-ADEKKGI2.js";var u,f=h(()=>{u=(function(s){return s[s.Global=0]="Global",s[s.Local=1]="Local",s})(u||{})});var i,k=h(()=>{i=(function(s){return s[s.begin=0]="begin",s[s.progress=1]="progress",s[s.finish=2]="finish",s})(i||{})});var O,R=h(()=>{p();m();f();w();k();d();O=(()=>{let r=class r{constructor(){this.receivers=[],this.workList=[],this.subject=new o,this.requestStatusChange=new o,this.poolStatusChange=new o,this.poolsRequestStarter=[],this.workingPools=[],this.pools=[],this._mode=u.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(a(e=>e.name===t)):this.requestStatusChange}poolStatus(t){return t?this.poolStatusChange.pipe(a(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(l.dvlsUrl,""),n=this.workList.find(g=>g.url===e);this.workList.splice(this.workList.indexOf(n),1),t.name=n?.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 n={name:t,requestNameList:e,workingRequest:[],finishedRequest:[],status:{name:t,error:!1,status:i.finish},takeUntil:()=>{}};return n.takeUntil=this.takeUntil.bind(this,n),this.pools.push(n),this.poolsRequestStarter.push(e[0]),n}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))}};r.\u0275fac=function(e){return new(e||r)},r.\u0275prov=c({token:r,factory:r.\u0275fac,providedIn:"root"});let s=r;return s})()});export{i as a,k as b,u as c,f as d,O as e,R as f};
