import{ca as u,g as l}from"./chunk-42LKD4JQ.js";import{a}from"./chunk-2AVGQ2MQ.js";var f=(()=>{class i{constructor(){this.filesSubject=new l([]),this.files$=this.filesSubject.asObservable()}createTask(t,e){let s=this.generateId(),r={id:s,name:t,size:e??null,receivedBytes:0,progress:0,status:"pending",error:null,startedAt:Date.now(),abortController:null};return this.filesSubject.next([...this.filesSubject.getValue(),r]),s}attachAbortController(t,e){this.update(t,{abortController:e,status:"starting"})}setTotalSize(t,e){e&&e>0&&this.update(t,{size:e})}onChunk(t,e){let s=this.get(t);if(!s)return;let r=(s.receivedBytes||0)+e,o=s.size??0,n=s.progress;o>0&&(n=Math.min(100,Math.round(r/o*100))),this.update(t,{receivedBytes:r,progress:n,status:"downloading"})}complete(t){this.update(t,{progress:100,status:"completed"}),setTimeout(()=>this.remove(t),5e3)}fail(t,e){this.update(t,{status:"failed",error:String(e)})}cancelFile(t){let e=this.get(t);if(e)if(e.status==="downloading"||e.status==="pending"){this.update(t,{status:"canceling"});try{e.abortController?.abort()}catch{}this.update(t,{status:"canceled"}),setTimeout(()=>this.remove(t),2e3)}else this.remove(t)}hasFiles(){return this.filesSubject.getValue().length>0}get(t){return this.filesSubject.getValue().find(e=>e.id===t)}update(t,e){let s=this.filesSubject.getValue(),r=s.findIndex(c=>c.id===t);if(r===-1)return;let o=a(a({},s[r]),e),n=[...s];n[r]=o,this.filesSubject.next(n)}remove(t){let e=this.filesSubject.getValue();this.filesSubject.next(e.filter(s=>s.id!==t))}generateId(){return"dl_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36)}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=u({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{f as a};
