import{p as E,k as F,m as L,f as M,q as A}from"./i18n-Dnhn5Rxr.js";import{R as C,u as P,v as R,y as T,x as q,t as S,a as k,T as V,W as $,w as d,V as W,Y as I}from"./index-DWyDLubb.js";import{T as Y}from"./StreamingBar.svelte_svelte_type_style_lang-Y9omZ2gK.js";import{s as b}from"./index-CglBvmLb.js";var j=$('<div class="toast-item svelte-1qhecvt"><!></div>'),B=$('<div class="toast-wrap svelte-1qhecvt"></div>');function N(x,s){C(s,!0);const r=()=>A(c,"$top",o),[o,l]=L();let _=E(s,"messages",19,()=>[]);const c=b(0,{stiffness:.4,damping:.5});let u=P(R([]));T(()=>{g(_())}),T(()=>{q(u,f(_()),!0)});function f(e){const t=new Map;return e.forEach(n=>{const a=n.type;t.has(a)||t.set(a,{type:n.type,messages:[],expanded:!0}),t.get(a).messages.push(n)}),Array.from(t.values())}function g(e){e.length>0&&"parentIFrame"in window&&window.parentIFrame?.getPageInfo(t=>{t.scrollTop<t.offsetTop?c.set(0):c.set(t.scrollTop-t.offsetTop)})}function h(e){q(u,d(u).map(t=>t.type===e?{...t,expanded:!t.expanded}:t),!0)}var p=B();F(p,21,()=>d(u),e=>e.type,(e,t)=>{var n=j(),a=W(n);Y(a,{get type(){return d(t).type},get messages(){return d(t).messages},get expanded(){return d(t).expanded},ontoggle:()=>h(d(t).type),onclose:v=>s.on_close(v)}),I(n),k(e,n)}),I(p),S(()=>M(p,`--toast-top: ${r()??""}px;`)),k(x,p),V(),l()}class O{current={};fn_outputs={};fn_inputs={};pending_outputs=new Map;fn_status={};show_progress={};register(s,r,o,l){this.fn_outputs[s]=r,this.fn_inputs[s]=o,this.show_progress[s]=l}clear(s){s in this.current&&(this.current[s]={})}update(s){this.resolve_args(s).forEach(({id:o,queue_position:l,queue_size:_,eta:c,status:u,message:f,progress:g,stream_state:h,time_limit:p,type:e,used_cache:t,cache_duration:n,avg_time:a})=>{this.current[o]={queue:s.queue||!1,queue_size:_,queue_position:l,eta:c,stream_state:h,message:f,progress:g||void 0,status:u,fn_index:s.fn_index,time_limit:p,type:e,show_progress:this.show_progress[s.fn_index],used_cache:t,cache_duration:n,avg_time:a}})}set_status(s,r){this.current[s].status=r}resolve_args(s){const{fn_index:r,status:o,size:l=void 0,position:_=null,eta:c=null,message:u=null,stream_state:f=null,time_limit:g=null,progress_data:h=null,used_cache:p=null,cache_duration:e=null,avg_time:t=null}=s,n=this.fn_outputs[r],a=this.fn_status[r],v=this.fn_inputs[r];return n.concat(v).map(i=>{let m;const y=this.pending_outputs.get(i)||0;if(a==="pending"&&o!=="pending"){let w=y-1;this.pending_outputs.set(i,w<0?0:w),m=w>0?"pending":o}else a==="pending"&&o==="pending"?m="pending":a!=="pending"&&o==="pending"?(m="pending",this.pending_outputs.set(i,y+1)):m=o;const z=v.includes(i)&&f?"input":n.includes(i)?"output":"skip";return{id:i,queue_position:_,queue_size:l,eta:c,status:m,message:u,progress:h,stream_state:f,time_limit:g,type:z,used_cache:p,cache_duration:e,avg_time:t}}).filter(i=>i.type!=="skip")}}export{O as L,N as T};
