teodor-new-chat-ui 4.1.24 → 4.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -3489,7 +3489,7 @@ function wx({
3489
3489
  }
3490
3490
  };
3491
3491
  return te.current = window.setTimeout(() => {
3492
- Cl(_);
3492
+ Cl(_), te.current = null;
3493
3493
  }, To), () => {
3494
3494
  te.current !== null && (window.clearTimeout(te.current), te.current = null);
3495
3495
  };
package/dist/index.umd.js CHANGED
@@ -30,7 +30,7 @@ Check the top-level render call using <`+X+">.")}return F}}function se(S,F){{if(
30
30
  `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=On(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&po.assertOptions(r,{silentJSONParsing:Yt.transitional(Yt.boolean),forcedJSONParsing:Yt.transitional(Yt.boolean),clarifyTimeoutError:Yt.transitional(Yt.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:po.assertOptions(o,{encode:Yt.function,serialize:Yt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),po.assertOptions(n,{baseUrl:Yt.spelling("baseURL"),withXsrfToken:Yt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=kt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(l=l&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});const u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,f=0,h;if(!l){const w=[El.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],v=a[f++];try{p=w(p)}catch(g){v.call(this,g);break}}try{d=El.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=On(this.defaults,t);const n=ml(t.baseURL,t.url,t.allowAbsoluteUrls);return il(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Mn.prototype[t]=function(n,r){return this.request(On(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(On(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Mn.prototype[t]=n(),Mn.prototype[t+"Form"]=n(!0)});let Qm=class Ap{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new rr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Ap(function(o){t=o}),cancel:t}}};function eg(e){return function(n){return e.apply(null,n)}}function tg(e){return O.isObject(e)&&e.isAxiosError===!0}const Vs={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Vs).forEach(([e,t])=>{Vs[t]=e});function Al(e){const t=new Mn(e),n=Va(Mn.prototype.request,t);return O.extend(n,Mn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Al(On(e,o))},n}const lt=Al(Ar);lt.Axios=Mn,lt.CanceledError=rr,lt.CancelToken=Qm,lt.isCancel=dl,lt.VERSION=Il,lt.toFormData=lo,lt.AxiosError=Pe,lt.Cancel=lt.CanceledError,lt.all=function(t){return Promise.all(t)},lt.spread=eg,lt.isAxiosError=tg,lt.mergeConfig=On,lt.AxiosHeaders=kt,lt.formToJSON=e=>cl(O.isHTMLForm(e)?new FormData(e):e),lt.getAdapter=kl.getAdapter,lt.HttpStatusCode=Vs,lt.default=lt;const{Axios:jC,AxiosError:RC,CanceledError:PC,isCancel:OC,CancelToken:MC,VERSION:DC,all:LC,Cancel:$C,isAxiosError:FC,spread:BC,toFormData:zC,AxiosHeaders:HC,HttpStatusCode:UC,formToJSON:WC,getAdapter:VC,mergeConfig:KC}=lt,_l=typeof window<"u"?window.__API_BASE_URL__:void 0,jl=_l?ln(_l):void 0;function ln(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let mo=null;const Ks=new Set;function Rl(){return mo}function qs(e){mo=e,Ks.forEach(t=>t(e))}function Pl(e){return Ks.add(e),()=>Ks.delete(e)}const Mt=lt.create({...jl?{baseURL:jl}:{},timeout:3e4,withCredentials:!0});Mt.interceptors.request.use(e=>(mo&&(e.headers.Authorization=`Bearer ${mo}`),e)),Mt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Nt(e,t){return Mt.defaults.baseURL?(await Mt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Gs(e,t,n){return Mt.defaults.baseURL?(await Mt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ol(e,t,n){return Mt.defaults.baseURL?(await Mt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ml(e,t){return Mt.defaults.baseURL?(await Mt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function At(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Dl{get baseUrl(){const t=Mt.defaults.baseURL;return t?ln(String(t)):""}updateConfig(t){t.baseUrl&&(Mt.defaults.baseURL=ln(String(t.baseUrl))),t.authToken!==void 0&&qs(t.authToken)}getAuthToken(){return Rl()}setAuthToken(t){qs(t)}onTokenChange(t){return Pl(t)}async listThreads(){const t=await Nt("/threads"),n=At(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Gs("/threads",t?{title:t}:void 0);return At(r)}async updateThread(t,n){const r=await Ol(`/threads/${t}`,{title:n});return At(r)}async deleteThread(t){const n=await Ml(`/threads/${t}`);return At(n)}async threadInfo(t){const n=await Nt(`/threads/${t}/info`);return At(n)}async listAgents(){const t=await Nt("/agents"),n=At(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Nt(`/agents/${t}`);return At(n)}async getAgentSchema(t){const n=await Nt(`/agents/${t}/schema`);return At(n)}async getMessages(t){const n=await Nt(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return At(n)}async getState(t){const n=await Nt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async getStateHistory(t){const n=await Nt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async listCheckpoints(t){const n=await Nt(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return At(n)}async resume(t){const n=await Gs("/runs/resume",{thread_id:t.threadId,value:t.value});return At(n)}}const mn=new Dl,Ll=y.createContext(null);function ng({children:e,apiConfig:t}){const n=mn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(Ll.Provider,{value:r,children:e})}function Ys(){const e=y.useContext(Ll);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function rg(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function og(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function sg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await og(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}function ig(e){return e.type!=="thread_info"&&e.type!=="token"}const ag={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function lg(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Xs(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Xs(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Xs(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Fl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Fl(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function $l(e=[]){const[t,n]=y.useReducer(lg,{...ag,messages:e}),r=y.useRef([]),o=y.useRef(null),s=y.useRef(null),i=y.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=y.useCallback(d=>{r.current.push(d),a()},[a]);y.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Fl(e,t){var n,r;if(t.type==="message_start"&&t.role==="assistant"){const o=t.id,s=pg(t.model);if(e.messages.some(l=>l.id===o))return{...e,assemblingId:o};const a={id:o,role:"assistant",name:s||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:o,messages:[...e.messages,a]}}if(t.type==="message_delta"){const o=e.assemblingId??Js(e.messages);return o?{...e,messages:Zs(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Js(e.messages);if(!o)return{...e,assemblingId:null};const s=e.messages,i=s.findIndex(a=>a.id===o&&a.role==="assistant");if(i>=0&&!((n=s[i].content)==null?void 0:n.some(u=>{var d;return(u==null?void 0:u.type)==="text"&&((d=u.text)==null?void 0:d.trim())}))){const u=[...s.slice(0,i),...s.slice(i+1)];return{...e,assemblingId:null,messages:u}}return e}if(t.type==="tool_start"){const o=t.id??t.call_id,s=t.name??t.tool??"tool";if(!o)return e;const i=`tool-${o}`,a={type:"tool_call",id:o,name:s,args:t.args};if(e.messages.find(d=>d.id===i))return{...e,toolIndex:{...e.toolIndex,[o]:i}};const u={id:i,role:"tool",name:s,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,u],toolIndex:{...e.toolIndex,[o]:i}}}if(t.type==="tool_end"){const o=t.id??t.call_id;if(!o)return e;const s=e.toolIndex[o]??`tool-${o}`,i={type:"tool_end",toolCallId:o,output:t.output,error:t.error},a=e.messages.find(d=>d.id===s),l={id:s,role:"tool",name:t.name??((r=e.messages.find(d=>d.id===s))==null?void 0:r.name),content:[i],createdAt:new Date().toISOString()},u=a?Zs(e.messages,s,[i]):[...e.messages,l];return{...e,messages:u,toolIndex:{...e.toolIndex,[o]:s}}}if(t.type==="checkpoint"){const o=t.checkpointNs??e.lastCheckpointNs??null,s=hg(e.messages,t.checkpointId,o);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:o,messages:s}}if(t.type==="branch"){const o=t.checkpointId??e.lastCheckpointId,s=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:o??null,lastCheckpointNs:s??null}}if(t.type==="error"){const o={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,o]}}if(t.type==="interrupt"){const o=e.assemblingId??Js(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Zs(e.messages,o,[s]),pendingInterrupt:{id:t.id,value:t.value}};const i={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[s]};return{...e,messages:[...e.messages,i],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Xs(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function cg(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Js(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function ug(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Zs(e,t,n){return ug(e,t,r=>({...r,content:dg(r.content,n)}))}function dg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){const i=o,a=i.text??"";if(!a){i.text=s;continue}if(s.startsWith(a)){i.text=s;continue}if(a.includes(s))continue;const l=fg(a,s);l?i.text=a+l:i.text=a+s}else n.push({type:"text",text:s})}else n.push(r);return n}function fg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function hg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return cg(e,r,s)}return e}function pg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Bl(e={}){const t=y.useMemo(()=>ln(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=y.useState(e.token??null),s=y.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=y.useState(!1),[u,d]=y.useState(null),[f,h]=y.useState(""),[p,w]=y.useState(null),[v,g]=y.useState(0),[x,b]=y.useState(!1),C=y.useRef(null),E=y.useRef(!0),T=y.useRef(0),k=y.useCallback(P=>{o(P)},[]),I=y.useCallback(()=>{var P;(P=C.current)==null||P.abort(),C.current=null,l(!1),b(!1),T.current=0,g(0)},[]),A=y.useCallback(()=>{h(""),w(null),d(null)},[]),j=y.useCallback((P,L,$)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const H=new AbortController;return C.current=H,(async()=>{var K,W,G,B,_,q,Q,xe;const M=ue=>{var ne;try{const _e=JSON.parse(JSON.stringify(ue));return(ne=_e==null?void 0:_e.payload)!=null&&ne.files_info&&Array.isArray(_e.payload.files_info)&&(_e.payload.files_info=_e.payload.files_info.map(Ce=>({...Ce,data:Ce!=null&&Ce.data?`<base64 ${String(Ce.data).length} chars>`:Ce==null?void 0:Ce.data}))),_e}catch{return ue}};try{let ue={};try{if(r)ue={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Me=window.__AUTH_TOKEN__,tt=((K=window.localStorage)==null?void 0:K.getItem("authToken"))||null;let He=null;try{const ht=(W=window.localStorage)==null?void 0:W.getItem("chat-settings");ht&&(He=((G=JSON.parse(ht))==null?void 0:G.apiKey)||null)}catch{}const Xe=Me||tt||He||null;Xe&&(ue={Authorization:`Bearer ${Xe}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const ne=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...ue,...s.current},body:JSON.stringify(P),signal:H.signal,credentials:i});if(!ne.ok||!ne.body){const Te=await ne.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",ne.status,Te==null?void 0:Te.slice(0,500)),new Error(`stream ${ne.status}${Te?": "+Te:""}`)}b(!0);const _e=ne.body.getReader(),Ce=new TextDecoder;let V="",D=[];T.current=0,g(0);let J=0,U=null;const he=()=>{if(D.length){const Te=D.join("");D=[],E.current&&h(Me=>Me+Te)}U=null},ce=()=>{typeof window<"u"&&U==null&&(U=requestAnimationFrame(he))};let ze=Date.now();const Ye=setInterval(()=>{var Te;if(Date.now()-ze>6e4){const Me="Stream idle timeout";d(Me),H.abort(),(Te=$==null?void 0:$.onError)==null||Te.call($,Me)}},5e3),Ge=1024*1024;try{const Te=ne.headers.get("X-Thread-Id")||ne.headers.get("x-thread-id"),Me=ne.headers.get("X-Thread-Created")||ne.headers.get("x-thread-created"),tt=Te??null,He=String(Me??"").toLowerCase()==="true";for((B=$==null?void 0:$.onOpen)==null||B.call($,{threadId:tt,created:He});;){const{value:Xe,done:ht}=await _e.read();if(ht)break;V+=Ce.decode(Xe,{stream:!0}),V.length>Ge&&(V="",console.warn("Stream buffer reset: exceeded 1MB"));let re;for(;(re=V.indexOf(`
31
31
 
32
32
  `))>=0;){const te=V.slice(0,re);V=V.slice(re+2);const ge=gg(te);if(!ge)continue;let Ee;try{Ee=JSON.parse(ge)}catch{console.debug("[use-chat] malformed SSE:",ge.slice(0,200));continue}const ye=mg(Ee)?Ee.data:Ee;ze=Date.now();const Re=ye.seq;if(Re!==void 0){if(Re<=J){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Re,lastProcessedSeq:J,type:ye.type});continue}J>0&&Re>J+1&&((_=$==null?void 0:$.onGap)==null||_.call($,{from:J,to:Re})),J=Re,T.current=Re,g(Re)}if(L==null||L(ye),ye.type==="token"&&e.autoAppendAssistant!==!1)D.push(ye.content),ce();else if(ye.type==="message_delta"){const Je=ye.delta.filter(We=>We.type==="text").map(We=>We.text).join("");Je&&e.autoAppendAssistant!==!1&&(D.push(Je),ce())}else ye.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(U!==null&&cancelAnimationFrame(U),he(),ye.type==="checkpoint"?w(ye.checkpointId):ye.type==="error"&&d(ye.message))}}he()}catch(Te){if(Te.name!=="AbortError"){const Me=Te.message||String(Te);d(Me),(q=$==null?void 0:$.onError)==null||q.call($,Me)}}finally{try{await _e.cancel()}catch{}finally{(Q=_e.releaseLock)==null||Q.call(_e)}U!==null&&typeof window<"u"&&window.cancelAnimationFrame(U),clearInterval(Ye),l(!1),b(!1),C.current=null,T.current=0,g(0)}}catch(ue){if(ue.name!=="AbortError"){const ne=ue.message||String(ue);d(ne),(xe=$==null?void 0:$.onError)==null||xe.call($,ne)}}finally{l(!1),b(!1),C.current=null,T.current=0,g(0)}})(),{close:()=>H.abort()}},[t,n,r,e.autoAppendAssistant]);return y.useEffect(()=>()=>{var P;E.current=!1,(P=C.current)==null||P.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:v,connected:x,stream:j,stop:I,clear:A,setToken:k}}function mg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function gg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
33
- `)}function xg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=y.useRef(null),i=y.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(ig(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Bl({baseUrl:e,token:null}),h=y.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return y.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const zl=y.createContext(null),Hl=y.createContext(null),Ul=y.createContext(null),vg=y.createContext(!1),wg=20,bg="cachedThreads",yg="v1",go=300,Qs=200;function Wl(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,go)}function or(){return typeof window<"u"&&typeof window.localStorage<"u"}function ei(e){if(!or())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Vl(e,t){if(or())try{window.localStorage.setItem(e,t)}catch{}}function ti(e){if(or())try{window.localStorage.removeItem(e)}catch{}}function Sg(){const e=ei(bg);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Cg(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function ni(e,t){return`cachedThreads:v1:${e}:${Cg(t||"anon")}`}function Tg(e){const t=ei(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function ri(e,t){try{Vl(e,JSON.stringify(t))}catch{}}function Kl(e){const t=Tg(e);if(t.length>0)return t;const n=Sg();if(n.length>0)try{ri(e,n.slice(0,Qs))}catch{}return n}function oi(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function si(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function kg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Ys(),d=y.useMemo(()=>ln(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${yg}:${f}:`,[f]),p=y.useCallback(N=>`${h}${N}`,[h]),w=y.useCallback(N=>{if(!N||typeof N!="object")return null;const R=N;return typeof R.threadId!="string"||!Array.isArray(R.messages)?null:{threadId:R.threadId,messages:R.messages,hasMore:!!R.hasMore,nextCursor:R.nextCursor??null,checkpointId:R.checkpointId??null,checkpointNs:R.checkpointNs??null}},[]),v=y.useCallback(N=>{const R=ei(p(N));if(!R)return null;try{const Z=JSON.parse(R);return w(Z)}catch{return null}},[p,w]),g=y.useCallback((N,R=100)=>{const Z={...N,messages:Array.isArray(N.messages)?N.messages.slice(-R):[]};try{Vl(p(N.threadId),JSON.stringify(Z))}catch{}},[p]),x=y.useCallback(N=>{ti(p(N))},[p]),b=y.useCallback(()=>{if(or())try{const N=h;for(let R=0;R<window.localStorage.length;R++){const Z=window.localStorage.key(R);Z&&Z.startsWith(N)&&window.localStorage.removeItem(Z)}}catch{}},[h]),[C,E]=y.useState(()=>{var N;return ni(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[T,k]=y.useState(()=>{var R;const N=Kl(ni(f,(R=l.getAuthToken)==null?void 0:R.call(l)));return oi(N)}),I=y.useMemo(()=>si(T),[T]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[$,H]=y.useState(!1),[M,K]=y.useState(!1),[W,G]=y.useState(!1),[B,_]=y.useState(null),[q,Q]=y.useState(void 0),[xe,ue]=y.useState(void 0),{state:ne,seed:_e,prepend:Ce,pushUser:V,onEvent:D,reset:J}=$l(),U=y.useRef(A);y.useEffect(()=>{U.current=A},[A]);const he=y.useRef(!1),ce=y.useRef([]),ze=y.useRef(null),Ye=y.useRef(null),Ge=y.useRef(new Map),Te=y.useRef(A),Me=y.useRef(!1),tt=y.useRef(null),He=y.useCallback((N,R)=>new Promise((Z,pe)=>{const fe=async()=>{he.current=!0;try{await N(),Z()}catch(S){pe(S)}finally{he.current=!1;const S=ce.current.shift();S&&S().catch(()=>{})}};he.current?ce.current.push(fe):fe().catch(S=>{pe(S)})}),[]),Xe=y.useCallback(async()=>{const N=I.length>0;N||L(!0);try{const R=await l.listThreads();y.startTransition(()=>{k(Z=>{const pe=F=>F.map(X=>`${X.threadId}:${X.updatedAt??""}:${X.messageCount??""}`).join("|"),fe=si(Z);return pe(fe)===pe(R)?Z:oi(R)})})}catch(R){i==null||i(String(R)),console.error("[ChatSessionProvider] Failed to refresh threads:",R)}finally{N||L(!1)}},[l,i,I.length]),ht=y.useRef(!1),re=y.useRef(null),te=y.useRef(null),ge=y.useRef(""),Ee=y.useCallback((N,R)=>{if(!or())return;te.current!==null&&(window.clearTimeout(te.current),te.current=null);const Z=N.map(fe=>`${fe.threadId}:${fe.updatedAt??""}:${fe.messageCount??""}`).join("|");if(N.length===0){try{ti(C)}catch{}ge.current="";return}if(Z===ge.current)return;const pe=()=>{try{const fe=N.slice(0,Qs);ri(C,fe),ge.current=Z}catch{}finally{te.current=null}};if(R!=null&&R.immediate){pe();return}te.current=window.setTimeout(()=>{Wl(pe)},go)},[C]),ye=y.useCallback((N,R,Z)=>{const pe=Array.isArray(N==null?void 0:N.messages)?N.messages:[],fe=Z??(N==null?void 0:N.threadId)??U.current;if(R==="replace"){if(fe){const S={threadId:fe,messages:pe.slice(),hasMore:!!(N!=null&&N.hasMore),nextCursor:(N==null?void 0:N.nextCursor)??null,checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null};Ge.current.set(fe,S),Te.current=fe}_e(pe,{checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null})}else if(R==="prepend"&&pe.length&&fe){const S=Ge.current.get(fe),F=(S==null?void 0:S.messages)??[],X=new Set,de=[...pe,...F].filter(Ke=>{const De=Ke==null?void 0:Ke.id;return De?X.has(De)?!1:(X.add(De),!0):!0}),Ne={threadId:fe,messages:de,hasMore:(N==null?void 0:N.hasMore)??(S==null?void 0:S.hasMore)??!1,nextCursor:(N==null?void 0:N.nextCursor)??(S==null?void 0:S.nextCursor)??null,checkpointId:(S==null?void 0:S.checkpointId)??(N==null?void 0:N.checkpointId)??null,checkpointNs:(S==null?void 0:S.checkpointNs)??(N==null?void 0:N.checkpointNs)??null};Ge.current.set(fe,Ne),Ce(pe)}else R==="prepend"&&pe.length&&Ce(pe);R==="replace"?(_((N==null?void 0:N.nextCursor)??null),K(!!(N!=null&&N.hasMore)),Q((N==null?void 0:N.checkpointId)??void 0),ue((N==null?void 0:N.checkpointNs)??void 0)):(_(S=>(N==null?void 0:N.nextCursor)??S??null),K(S=>(N==null?void 0:N.hasMore)!==void 0?!!(N!=null&&N.hasMore):S),Q(S=>(N==null?void 0:N.checkpointId)??S??void 0),ue(S=>(N==null?void 0:N.checkpointNs)??S??void 0))},[Ce,_e]),Re=y.useCallback(N=>{_e(N.messages,{checkpointId:N.checkpointId,checkpointNs:N.checkpointNs}),_(N.nextCursor),K(N.hasMore),Q(N.checkpointId??void 0),ue(N.checkpointNs??void 0),Te.current=N.threadId},[_e]),Je=y.useCallback(N=>{N&&(Ge.current.delete(N),x(N),Te.current===N&&(Te.current=null))},[x]),We=y.useCallback(()=>{const N=U.current;N&&Je(N),J([]),K(!1),G(!1),_(null),Q(void 0),ue(void 0)},[Je,J]),it=y.useCallback(({from:N,to:R})=>{const Z=U.current;Z&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${R}) for thread ${Z}`)},[]),It=y.useCallback(N=>{const R=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:R,title:N.title,created:N.created,currentThreads:I.length});const Z={threadId:R,title:N.title||`Thread ${R.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};U.current!==R&&(!U.current&&ne.messages.length<=1&&(Ye.current=R),j(R)),y.startTransition(()=>{k(pe=>{const fe=pe.byId[R];return fe?fe.title===Z.title&&fe.updatedAt===Z.updatedAt&&fe.messageCount===Z.messageCount?pe:{byId:{...pe.byId,[R]:Z},order:pe.order}:{byId:{...pe.byId,[R]:Z},order:[R,...pe.order]}})})},[ne.messages.length]),{startStream:fn,stop:wr,isStreaming:Nn,error:Jn,setAuthToken:hn}=xg({baseUrl:d,onThreadInfo:It,onMessageEvent:D,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:it});y.useEffect(()=>{ht.current=Nn},[Nn]),y.useEffect(()=>{if(!or())return;te.current!==null&&(window.clearTimeout(te.current),te.current=null);const N=I.map(Z=>`${Z.threadId}:${Z.updatedAt??""}:${Z.messageCount??""}`).join("|");if(I.length===0){try{ti(C)}catch{}ge.current="";return}if(N===ge.current)return;const R=()=>{try{const Z=I.slice(0,Qs);ri(C,Z),ge.current=N}catch{}finally{te.current=null}};return te.current=window.setTimeout(()=>{Wl(R)},go),()=>{te.current!==null&&(window.clearTimeout(te.current),te.current=null)}},[I,Ee]),y.useEffect(()=>{var pe;const N=l.getAuthToken();hn(N);const R=fe=>{const S=ni(f,fe);tt.current!==S&&(tt.current=S,Me.current=!1),E(S);const F=Kl(S);y.startTransition(()=>{k(oi(F))}),Me.current||(Me.current=!0,Xe().catch(()=>{}))};R(N);const Z=(pe=l.onTokenChange)==null?void 0:pe.call(l,fe=>{hn(fe),b(),R(fe)});return()=>{Z==null||Z()}},[l,f,hn,b,Xe]);const br=y.useCallback(async N=>{const R=`temp-${Date.now()}`,Z={threadId:R,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(pe=>({byId:{...pe.byId,[R]:Z},order:[R,...pe.order]})),j(R);try{const pe=await l.createThread(N),fe=typeof pe=="string"?pe:pe.threadId;return k(S=>{const F=S.byId[R];if(!F)return S;const X={...S.byId};delete X[R],X[fe]={...F,threadId:fe};const de=S.order.map(Ne=>Ne===R?fe:Ne);return{byId:X,order:de}}),j(fe),setTimeout(()=>Xe(),10),fe}catch(pe){throw k(fe=>{if(!fe.byId[R])return fe;const S={...fe.byId};delete S[R];const F=fe.order.filter(X=>X!==R);return{byId:S,order:F}}),j(null),pe}},[l,Xe]),An=y.useCallback(async N=>{await l.deleteThread(N);let R=null;k(Z=>{if(!Z.byId[N])return Z;const pe={...Z.byId};delete pe[N];const fe=Z.order.filter(F=>F!==N),S={byId:pe,order:fe};return R=si(S),S}),R&&Ee(R,{immediate:!0}),Je(N),U.current===N&&(Ye.current=N,j(null),U.current=null,Te.current=null,We()),await Xe()},[l,We,Je,Xe,Ee]),Zn=y.useCallback(async(N,R)=>{try{await l.updateThread(N,R),k(Z=>{const pe=Z.byId[N];return pe?{byId:{...Z.byId,[N]:{...pe,title:R}},order:Z.order}:Z})}catch(Z){throw await Xe(),Z}},[l,Xe]),xt=y.useCallback(async(N,R,Z,pe=!1)=>{await He(async()=>{if(Ye.current===N&&!pe){Ye.current=null;return}if(ze.current===N&&!pe)return;j(de=>de===N?de:N),U.current=N;const fe=!pe&&!R&&!Z;let S=!1;if(fe){const de=Ge.current.get(N);if(de)Re(de),S=!0;else{const Ne=v(N);Ne&&(Ge.current.set(N,Ne),Re(Ne),S=!0)}}const F=pe||!S||!!R||!!Z,X=async de=>{de&&H(!0),ze.current=N;try{const Ne=await l.getMessages({threadId:N,checkpointId:R,checkpointNs:Z});ye(Ne,"replace",N)}catch(Ne){throw(!S||pe||de)&&(i==null||i(String(Ne))),Ne}finally{ze.current=null,de&&H(!1)}};F?await X(!0):fe&&S&&X(!1).catch(de=>{console.warn("[ChatSessionProvider] Background refresh failed:",de)})},`loadThread-${N}`)},[l,Re,ye,He,i]),_n=y.useCallback(async()=>{await He(async()=>{const N=U.current;N&&Je(N),Ye.current=null,j(null),U.current=null,Te.current=null,We(),Q(void 0),ue(void 0);try{localStorage.removeItem("lastThreadId")}catch(R){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",R)}},"clearCurrentThread")},[We,Je,He]),jn=y.useCallback(async N=>{const R=await l.listCheckpoints(N);return rg(R,N)},[l]),Qn=y.useCallback(async(N,R)=>{if(!U.current)throw new Error("No active thread");await xt(U.current,N,R??void 0,!0)},[xt]),yr=y.useCallback(async()=>{if(!U.current)throw new Error("No active thread");await xt(U.current,void 0,void 0,!0)},[xt]),er=y.useCallback(async N=>{if(!U.current)throw new Error("No active thread");if(W||!M)return;const R=B;if(R){G(!0);try{const Z=U.current,pe=await l.getMessages({threadId:Z,checkpointId:q,checkpointNs:xe,limit:(N==null?void 0:N.limit)??wg,beforeId:R});ye(pe,"prepend",Z??void 0)}finally{G(!1)}}},[l,ye,M,q,xe,B,W]),Sr=y.useCallback(async(N,R)=>{var $e;const Z=U.current;!Z&&!(R!=null&&R.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const pe=(R==null?void 0:R.attachments)||[],{contentParts:fe,filesInfo:S}=await sg(l,pe),F=[...fe];N&&N.trim()&&F.push({type:"text",text:N.trim()});const X={id:(($e=crypto.randomUUID)==null?void 0:$e.call(crypto))||`user-${Date.now()}`,role:"user",content:F,createdAt:new Date().toISOString(),checkpointId:(R==null?void 0:R.checkpointId)??ne.lastCheckpointId??void 0,checkpointNs:(R==null?void 0:R.checkpointNs)??ne.lastCheckpointNs??void 0};V(X);const de={...X,content:F},Ne={...(R==null?void 0:R.payloadExtras)??{}},Ke=pe.length>0,De={...Z?{threadId:Z}:{},payload:{messages:[de],files_info:S,...o&&Ke&&s?{active_agent:s}:{},...Ne},checkpointId:(R==null?void 0:R.checkpointId)??ne.lastCheckpointId??void 0,checkpointNs:(R==null?void 0:R.checkpointNs)??ne.lastCheckpointNs??void 0,nodeFilter:R==null?void 0:R.nodeFilter,config:R==null?void 0:R.config};fn(De,{onError:ut=>{console.warn("[ChatSessionProvider] Stream error:",ut)},onOpen:({threadId:ut,created:at})=>{!U.current&&ut&&(ne.messages.length<=1&&(Ye.current=ut),j(ut))},onGap:it})},[l,o,s,it,ne.lastCheckpointId,ne.lastCheckpointNs,ne.messages.length,V,fn]),se=y.useCallback(async(N,R,Z)=>{const pe=U.current;if(!pe)throw new Error("No active thread to handle interrupt");try{const fe=R?Z??!0:!1;await l.resume({threadId:pe,value:fe})}catch(fe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,fe),fe}},[l]);y.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[A,a]),y.useEffect(()=>((async()=>{try{if(Xe().catch(R=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",R),i==null||i(String(R))}),!r&&!t)try{const R=localStorage.getItem("lastThreadId");R&&(j(R),n&&await xt(R))}catch(R){console.warn("[ChatSessionProvider] Failed to restore last thread:",R)}else t&&n&&await xt(t)}catch(R){console.error("[ChatSessionProvider] Initialization failed:",R),i==null||i(String(R))}})(),()=>{}),[]),y.useEffect(()=>{const N=U.current;if(!N||Te.current!==N)return;const R={threadId:N,messages:ne.messages.slice(),hasMore:M,nextCursor:B,checkpointId:ne.lastCheckpointId??null,checkpointNs:ne.lastCheckpointNs??null},Z=Ge.current.get(N);(!Z||Z.messages.length!==R.messages.length||Z.messages.some((fe,S)=>{var F;return(fe==null?void 0:fe.id)!==((F=R.messages[S])==null?void 0:F.id)})||(Z==null?void 0:Z.hasMore)!==R.hasMore||(Z==null?void 0:Z.nextCursor)!==R.nextCursor||(Z==null?void 0:Z.checkpointId)!==R.checkpointId||(Z==null?void 0:Z.checkpointNs)!==R.checkpointNs)&&(Ge.current.set(N,R),re.current&&window.clearTimeout(re.current),re.current=window.setTimeout(()=>{try{g(R,100)}catch(fe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",fe)}},go))},[M,B,ne.lastCheckpointId,ne.lastCheckpointNs,ne.messages]);const be=y.useMemo(()=>({threads:I,currentThreadId:A,isLoadingThreads:P,isLoadingThread:$,setCurrentThreadId:j,createThread:br,deleteThread:An,renameThread:Zn,refreshThreads:Xe,loadThread:xt,clearCurrentThread:_n,listCheckpoints:jn,navigateToCheckpoint:Qn,returnToLatest:yr}),[_n,br,A,An,$,P,jn,xt,Qn,Xe,Zn,yr,I]),Fe=y.useMemo(()=>({messages:ne.messages,assemblingId:ne.assemblingId,lastUserMessage:null,hasMoreHistory:M,isLoadingHistory:W,send:Sr,stop:wr,loadOlderMessages:er,clearMessages:We,handleInterrupt:se}),[We,se,M,W,er,ne.assemblingId,ne.messages,Sr,wr]),nt=y.useMemo(()=>({isStreaming:Nn,error:Jn,streamingAssistantId:ne.assemblingId,lastCheckpointId:ne.lastCheckpointId??null,lastCheckpointNs:ne.lastCheckpointNs??null}),[Nn,ne.assemblingId,ne.lastCheckpointId,ne.lastCheckpointNs,Jn]);return c.jsx(vg.Provider,{value:!0,children:c.jsx(Ul.Provider,{value:nt,children:c.jsx(zl.Provider,{value:be,children:c.jsx(Hl.Provider,{value:Fe,children:e})})})})}function xo(){const e=y.useContext(zl);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ii(){const e=y.useContext(Hl);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function ql(){const e=y.useContext(Ul);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function vo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(ng,{apiConfig:t,children:c.jsx(kg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function ee(...e){return jp.twMerge(_p.clsx(e))}const Eg=no.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ve=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Rn.Slot:"button";return c.jsx(i,{className:ee(Eg({variant:t,size:n,className:e})),ref:s,...o})});Ve.displayName="Button";const Gl=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:ee("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Gl.displayName="Textarea";function Ig({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=y.useState(e),[w,v]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);y.useEffect(()=>{x()},[x]);const b=y.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||v(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),C=y.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Gl,{ref:g,value:h,onChange:C,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ve,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(oe.Square,{size:16})}):c.jsx(Ve,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(oe.Send,{size:16})})})]})})}const Ng=y.memo(Ig),wo=0,gn=1,sr=2,Yl=4;function Xl(e){return()=>e}function Ag(e){e()}function Jl(e,t){return n=>e(t(n))}function Zl(e,t){return()=>e(t)}function _g(e,t){return n=>e(t,n)}function ai(e){return e!==void 0}function jg(...e){return()=>{e.map(Ag)}}function ir(){}function bo(e,t){return t(e),e}function Rg(e,t){return t(e)}function rt(...e){return e}function Ze(e,t){return e(gn,t)}function Oe(e,t){e(wo,t)}function li(e){e(sr)}function ct(e){return e(Yl)}function me(e,t){return Ze(e,_g(t,wo))}function Ut(e,t){const n=e(gn,r=>{n(),t(r)});return n}function Ql(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function ec(e,t){return e===t}function ot(e=ec){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ie(e){return t=>Jl(t,e)}function Xt(e){return t=>()=>{t(e)}}function z(e,...t){const n=Pg(...t);return(r,o)=>{switch(r){case sr:li(e);return;case gn:return Ze(e,n(o))}}}function Jt(e,t){return n=>r=>{n(t=e(t,r))}}function Dn(e){return t=>n=>{e>0?e--:t(n)}}function cn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Le(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ze(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Pg(...e){return t=>e.reduceRight(Rg,t)}function Og(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case gn:return s?n===s?void 0:(r(),n=s,t=Ze(e,s),t):(r(),ir);case sr:r(),n=null;return}}}function Y(e){let t=e;const n=Ue();return(r,o)=>{switch(r){case wo:t=o;break;case gn:{o(t);break}case Yl:return t}return n(r,o)}}function wt(e,t){return bo(Y(t),n=>me(e,n))}function Ue(){const e=[];return(t,n)=>{switch(t){case wo:e.slice().forEach(r=>{r(n)});return;case sr:e.splice(0,e.length);return;case gn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function _t(e){return bo(Ue(),t=>me(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Mg(),singleton:n}}const Mg=()=>Symbol();function Dg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function ft(...e){const t=Ue(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Oe(t,n)})}),function(s,i){switch(s){case sr:{li(t);return}case gn:return r===o&&i(n),Ze(t,i)}}}function Se(e,t=ec){return z(e,ot(t))}function ci(...e){return function(t,n){switch(t){case sr:return;case gn:return jg(...e.map(r=>Ze(r,n)))}}}var Et=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Et||{});const Lg={0:"debug",3:"error",1:"log",2:"warn"},$g=()=>typeof globalThis>"u"?window:globalThis,xn=qe(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=$g().VIRTUOSO_LOG_LEVEL)!=null?o:ct(e);r>=s&&console[Lg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Ln(e,t,n){return ui(e,t,n).callbackRef}function ui(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Fg(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=Bg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?tc("column-gap",getComputedStyle(d).columnGap,o):tc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ui(u,n,l)}function Bg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Et.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function tc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}function nc(e,t,n){const r=y.useRef(null),o=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ui(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const St=qe(()=>{const e=Ue(),t=Ue(),n=Y(0),r=Ue(),o=Y(0),s=Ue(),i=Ue(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=Ue(),h=Ue(),p=Y(!1),w=Y(!1),v=Y(!1);return me(z(e,ie(({scrollTop:g})=>g)),t),me(z(e,ie(({scrollHeight:g})=>g)),i),me(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),jr={lvl:0};function rc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Qe(e){return e===jr}function Rr(e,t){if(!Qe(e))return t===e.k?e.v:t<e.k?Rr(e.l,t):Rr(e.r,t)}function Wt(e,t,n="k"){if(Qe(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Wt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Wt(e.l,t,n)}function jt(e,t,n){return Qe(e)?ic(t,n,1):t===e.k?pt(e,{k:t,v:n}):t<e.k?ac(pt(e,{l:jt(e.l,t,n)})):ac(pt(e,{r:jt(e.r,t,n)}))}function ar(){return jr}function yo(e,t,n){if(Qe(e))return[];const r=Wt(e,t)[0];return zg(fi(e,r,n))}function di(e,t){if(Qe(e))return jr;const{k:n,l:r,r:o}=e;if(t===n){if(Qe(r))return o;if(Qe(o))return r;{const[s,i]=sc(r);return So(pt(e,{k:s,l:oc(r),v:i}))}}else return t<n?So(pt(e,{l:di(r,t)})):So(pt(e,{r:di(o,t)}))}function $n(e){return Qe(e)?[]:[...$n(e.l),{k:e.k,v:e.v},...$n(e.r)]}function fi(e,t,n){if(Qe(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(fi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(fi(s,t,n))),a}function So(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(hi(t))return lc(pt(e,{lvl:n-1}));if(!Qe(t)&&!Qe(t.r))return pt(t.r,{l:pt(t,{r:t.r.l}),lvl:n,r:pt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(hi(e))return pi(pt(e,{lvl:n-1}));if(!Qe(r)&&!Qe(r.l)){const o=r.l,s=hi(o)?r.lvl-1:r.lvl;return pt(o,{l:pt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:pi(pt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function pt(e,t){return ic(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function oc(e){return Qe(e.r)?e.l:So(pt(e,{r:oc(e.r)}))}function hi(e){return Qe(e)||e.lvl>e.r.lvl}function sc(e){return Qe(e.r)?[e.k,e.v]:sc(e.r)}function ic(e,t,n,r=jr,o=jr){return{k:e,l:r,lvl:n,r:o,v:t}}function ac(e){return pi(lc(e))}function lc(e){const{l:t}=e;return!Qe(t)&&t.lvl===e.lvl?pt(t,{r:pt(e,{l:t.r})}):e}function pi(e){const{lvl:t,r:n}=e;return!Qe(n)&&!Qe(n.r)&&n.lvl===t&&n.r.lvl===t?pt(n,{l:pt(e,{r:n.l}),lvl:t+1}):e}function zg(e){return rc(e,({k:t,v:n})=>({index:t,value:n}))}function cc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Pr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const mi=qe(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function uc(e,t,n){return e[Co(e,t,n)]}function Co(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function Hg(e,t,n,r){const o=Co(e,t,r),s=Co(e,n,r,o);return e.slice(o,s+1)}function vn(e,t){return Math.round(e.getBoundingClientRect()[t])}function To(e){return!Qe(e.groupOffsetTree)}function gi({index:e},t){return t===e?0:t<e?-1:1}function Ug(){return{groupIndices:[],groupOffsetTree:ar(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ar()}}function Wg(e,t){let n=Qe(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Qe(e)){e=jt(e,0,s);continue}const a=yo(e,i-1,o+1);if(a.some(Jg(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=di(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=jt(e,o+1,h));u&&(e=jt(e,i,s))}return[e,n]}function Vg(e){return typeof e.groupIndex<"u"}function Kg({offset:e},t){return t===e?0:t<e?-1:1}function Or(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=uc(t,e,gi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function dc(e,t){if(!To(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function fc(e,t,n){if(Vg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=dc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function qg(e,t,n,r=0){return r>0&&(t=Math.max(t,uc(e,r,gi).offset)),rc(Hg(e,t,n,Kg),Xg)}function Gg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Et.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Qe(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>jt(jt(w,v,h),v+1,p),i)}else[i,a]=Wg(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=xi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>jt(h,p,Or(p,f,o)),ar()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Yg(e){return $n(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function hc(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function xi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Co(o,t-1,gi),a=o[l].offset;const u=Wt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Wt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of yo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Xg(e){return{index:e.index,value:e}}function Jg(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const Zg={offsetHeight:"height",offsetWidth:"width"},Zt=qe(([{log:e},{recalcInProgress:t}])=>{const n=Ue(),r=Ue(),o=wt(r,0),s=Ue(),i=Ue(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((T,k)=>vn(T,Zg[k])),h=Y(void 0),p=Y(0),w=Ug(),v=wt(z(n,Le(l,e,p),Jt(Gg,w),ot()),w),g=wt(z(l,ot(),Jt((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),ie(({prev:T})=>T)),[]);me(z(l,ke(T=>T.length>0),Le(v,p),ie(([T,k,I])=>{const A=T.reduce((j,P,L)=>jt(j,P,Or(P,k.offsetTree,I)||L),ar());return{...k,groupIndices:T,groupOffsetTree:A}})),v),me(z(r,Le(v),ke(([T,{lastIndex:k}])=>T<k),ie(([T,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:T}])),n),me(u,d);const x=wt(z(u,ie(T=>T===void 0)),!0);me(z(d,ke(T=>T!==void 0&&Qe(ct(v).sizeTree)),ie(T=>[{endIndex:0,size:T,startIndex:0}])),n);const b=_t(z(n,Le(v),Jt(({sizes:T},[k,I])=>({changed:I!==T,sizes:I}),{changed:!1,sizes:w}),ie(T=>T.changed)));Ze(z(a,Jt((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),ie(T=>T.diff)),T=>{const{groupIndices:k}=ct(v);if(T>0)Oe(t,!0),Oe(s,T+hc(T,k));else if(T<0){const I=ct(g);I.length>0&&(T-=hc(-T,I)),Oe(i,T)}}),Ze(z(a,Le(e)),([T,k])=>{T<0&&k("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Et.ERROR)});const C=_t(s);me(z(s,Le(v),ie(([T,k])=>{const I=k.groupIndices.length>0,A=[],j=k.lastSize;if(I){const P=Rr(k.sizeTree,0);let L=0,$=0;for(;L<T;){const M=k.groupIndices[$],K=k.groupIndices.length===$+1?1/0:k.groupIndices[$+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+K-1,size:j,startIndex:M+1}),$++,L+=K+1}const H=$n(k.sizeTree);return L!==T&&H.shift(),H.reduce((M,{k:K,v:W})=>{let G=M.ranges;return M.prevSize!==0&&(G=[...M.ranges,{endIndex:K+T-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:K+T,prevSize:W,ranges:G}},{prevIndex:T,prevSize:0,ranges:A}).ranges}return $n(k.sizeTree).reduce((P,{k:L,v:$})=>({prevIndex:L+T,prevSize:$,ranges:[...P.ranges,{endIndex:L+T-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=_t(z(i,Le(v,p),ie(([T,{offsetTree:k},I])=>{const A=-T;return Or(A,k,I)})));return me(z(i,Le(v,p),ie(([T,k,I])=>{if(k.groupIndices.length>0){if(Qe(k.sizeTree))return k;let A=ar();const j=ct(g);let P=0,L=0,$=0;for(;P<-T;){$=j[L];const H=j[L+1]-$-1;L++,P+=H+1}if(A=$n(k.sizeTree).reduce((H,{k:M,v:K})=>jt(H,Math.max(0,M+T),K),A),P!==-T){const H=Rr(k.sizeTree,$);A=jt(A,0,H);const M=Wt(k.sizeTree,-T+1)[1];A=jt(A,1,M)}return{...k,sizeTree:A,...xi(k.offsetTree,0,A,I)}}else{const A=$n(k.sizeTree).reduce((j,{k:P,v:L})=>jt(j,Math.max(0,P+T),L),ar());return{...k,sizeTree:A,...xi(k.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},rt(xn,mi),{singleton:!0});function Qg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const pc=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ue(),i=Ue(),a=_t(z(s,ie(Qg)));return me(z(a,ie(l=>l.totalCount)),n),me(z(a,ie(l=>l.groupIndices)),e),me(z(ft(o,t,r),ke(([l,u])=>To(u)),ie(([l,u,d])=>Wt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ot(),ie(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},rt(Zt,St)),wn=qe(([{log:e}])=>{const t=Y(!1),n=_t(z(t,ke(r=>r),ot()));return Ze(t,r=>{r&&ct(e)("props updated",{},Et.DEBUG)}),{didMount:n,propsReady:t}},rt(xn),{singleton:!0}),ex=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function mc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ex)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Mr=qe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ue(),w=Ue(),v=Y(0);let g=null,x=null,b=null;function C(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Oe(l,!1)}return me(z(p,Le(n,f,r,v,a,i,h),Le(e,s,o),ie(([[E,T,k,I,A,j,P,L],$,H,M])=>{const K=mc(E),{align:W,behavior:G,offset:B}=K,_=I-1,q=fc(K,T,_);let Q=Or(q,T.offsetTree,$)+j;W==="end"?(Q+=H+Wt(T.sizeTree,q)[1]-k+M,q===_&&(Q+=P)):W==="center"?Q+=(H+Wt(T.sizeTree,q)[1]-k+M)/2:Q-=A,B&&(Q+=B);const xe=ue=>{C(),ue?(L("retrying to scroll to",{location:E},Et.DEBUG),Oe(p,E)):(Oe(w,!0),L("list did not change, scroll successful",{},Et.DEBUG))};if(C(),G==="smooth"){let ue=!1;b=Ze(t,ne=>{ue=ue||ne}),g=Ut(d,()=>{xe(ue)})}else g=Ut(z(t,tx(150)),xe);return x=setTimeout(()=>{C()},1200),Oe(l,!0),L("scrolling from index to",{behavior:G,index:q,top:Q},Et.DEBUG),{behavior:G,top:Q}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},rt(Zt,St,xn),{singleton:!0});function tx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function vi(e,t){e==0?t():requestAnimationFrame(()=>{vi(e-1,t)})}function wi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Dr=qe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),u=Y(!0);return me(z(i,Le(l),ke(([d,f])=>!!f),Xt(!1)),a),me(z(i,Le(l),ke(([d,f])=>!!f),Xt(!1)),u),Ze(z(ft(t,i),Le(a,n,e,u),ke(([[,d],f,{sizeTree:h},p,w])=>d&&(!Qe(h)||ai(p))&&!f&&!w),Le(l)),([,d])=>{Ut(o,()=>{Oe(u,!0)}),vi(4,()=>{Ut(r,()=>{Oe(a,!0)}),Oe(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},rt(Zt,St,Mr,wn),{singleton:!0});function gc(e,t){return Math.abs(e-t)<1.01}const Lr="up",$r="down",nx="none",rx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},ox=0,Fr=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=Ue(),u=Ue(),d=Y(4),f=Y(ox),h=wt(z(ci(z(Se(o),Dn(1),Xt(!0)),z(Se(o),Dn(1),Xt(!1),Ql(100))),ot()),!1),p=wt(z(ci(z(n,Xt(!0)),z(n,Xt(!1),Ql(200))),ot()),!1);me(z(ft(Se(o),Se(f)),ie(([b,C])=>b<=C),ot()),a),me(z(a,cn(50)),u);const w=_t(z(ft(r,Se(s),Se(t),Se(e),Se(d)),Jt((b,[{scrollHeight:C,scrollTop:E},T,k,I,A])=>{const j=E+T-C>-A,P={scrollHeight:C,scrollTop:E,viewportHeight:T};if(j){let $,H;return E>b.state.scrollTop?($="SCROLLED_DOWN",H=b.state.scrollTop-E):($="SIZE_DECREASED",H=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:H,state:P}}let L;return P.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":T<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:P}},rx),ot((b,C)=>b&&b.atBottom===C.atBottom))),v=wt(z(r,Jt((b,{scrollHeight:C,scrollTop:E,viewportHeight:T})=>{if(gc(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:E};{const k=C-(E+T)<1;return b.scrollTop!==E&&k?{changed:!0,jump:b.scrollTop-E,scrollHeight:C,scrollTop:E}:{changed:!0,jump:0,scrollHeight:C,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),ie(b=>b.jump)),0);me(z(w,ie(b=>b.atBottom)),i),me(z(i,cn(50)),l);const g=Y($r);me(z(r,ie(({scrollTop:b})=>b),ot(),Jt((b,C)=>ct(p)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?Lr:$r,prevScrollTop:C},{direction:$r,prevScrollTop:0}),ie(b=>b.direction)),g),me(z(r,cn(50),Xt(nx)),g);const x=Y(0);return me(z(h,ke(b=>!b),Xt(0)),x),me(z(o,cn(100),Le(h),ke(([b,C])=>!!C),Jt(([b,C],[E])=>[C,E],[0,0]),ie(([b,C])=>C-b)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},rt(St)),ko="top",Eo="bottom",xc="none";function vc(e,t,n){return typeof e=="number"?n===Lr&&t===ko||n===$r&&t===Eo?e:0:n===Lr?t===ko?e.main:e.reverse:t===Eo?e.main:e.reverse}function wc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const bi=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ue(),i=Y(0),a=Y(0),l=Y(0),u=wt(z(ft(Se(r),Se(o),Se(n),Se(s,Pr),Se(l),Se(i),Se(t),Se(e),Se(a)),ie(([d,f,h,[p,w],v,g,x,b,C])=>{const E=d-b,T=g+x,k=Math.max(h-E,0);let I=xc;const A=wc(C,ko),j=wc(C,Eo);return p-=b,p+=h+x,w+=h+x,w-=b,p>d+T-A&&(I=Lr),w<d-k+f+j&&(I=$r),I!==xc?[Math.max(E-h-vc(v,ko,I)-A,0),E-k-x+f+vc(v,Eo,I)+j]:null}),ke(d=>d!=null),ot(Pr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},rt(St),{singleton:!0});function sx(e,t,n){if(To(t)){const r=dc(e,t);return[{index:Wt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const yi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Io(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:yc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:yc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function bc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=wi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Io(u,[],a,o,n,r)}function yc(e,t,n){if(e.length===0)return[];if(!To(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=yo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Fn=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=Y([]),g=Y(0),x=Ue();me(s.topItemsIndexes,v);const b=wt(z(ft(p,w,Se(l,Pr),Se(o),Se(r),Se(u),d,Se(v),Se(t),Se(n),e),ke(([k,I,,A,,,,,,,j])=>{const P=j&&j.length!==A;return k&&!I&&!P}),ie(([,,[k,I],A,j,P,L,$,H,M,K])=>{const W=j,{offsetTree:G,sizeTree:B}=W,_=ct(g);if(A===0)return{...yi,totalCount:A};if(k===0&&I===0)return _===0?{...yi,totalCount:A}:bc(_,P,j,H,M,K||[]);if(Qe(B))return _>0?null:Io(sx(wi(P,A),W,K),[],A,M,W,H);const q=[];if($.length>0){const _e=$[0],Ce=$[$.length-1];let V=0;for(const D of yo(B,_e,Ce)){const J=D.value,U=Math.max(D.start,_e),he=Math.min(D.end,Ce);for(let ce=U;ce<=he;ce++)q.push({data:K==null?void 0:K[ce],index:ce,offset:V,size:J}),V+=J}}if(!L)return Io([],q,A,M,W,H);const Q=$.length>0?$[$.length-1]+1:0,xe=qg(G,k,I,Q);if(xe.length===0)return null;const ue=A-1,ne=bo([],_e=>{for(const Ce of xe){const V=Ce.value;let D=V.offset,J=Ce.start;const U=V.size;if(V.offset<k){J+=Math.floor((k-V.offset+M)/(U+M));const ce=J-Ce.start;D+=ce*U+ce*M}J<Q&&(D+=(Q-J)*U,J=Q);const he=Math.min(Ce.end,ue);for(let ce=J;ce<=he&&!(D>=I);ce++)_e.push({data:K==null?void 0:K[ce],index:ce,offset:D,size:U}),D+=U+M}});return Io(ne,q,A,M,W,H)}),ke(k=>k!==null),ot()),yi);me(z(e,ke(ai),ie(k=>k==null?void 0:k.length)),o),me(z(b,ie(k=>k.topListHeight)),f),me(f,a),me(z(b,ie(k=>[k.top,k.bottom])),i),me(z(b,ie(k=>k.items)),x);const C=_t(z(b,ke(({items:k})=>k.length>0),Le(o,e),ke(([{items:k},I])=>k[k.length-1].originalIndex===I-1),ie(([,k,I])=>[k-1,I]),ot(Pr),ie(([k])=>k))),E=_t(z(b,cn(200),ke(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),ie(({items:k})=>k[0].index),ot())),T=_t(z(b,ke(({items:k})=>k.length>0),ie(({items:k})=>{let I=0,A=k.length-1;for(;k[I].type==="group"&&I<A;)I++;for(;k[A].type==="group"&&A>I;)A--;return{endIndex:k[A].index,startIndex:k[I].index}}),ot(cc)));return{endReached:C,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:T,startReached:E,topItemsIndexes:v,...h}},rt(Zt,pc,bi,Dr,Mr,Fr,wn,mi),{singleton:!0}),Sc=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ue(),i=wt(z(ft(n,e,r,t,o),ie(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return me(Se(i),s),{totalListHeight:i,totalListHeightChanged:s}},rt(St,Fn),{singleton:!0}),ix=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=wt(z(ft(n,e,t),ke(([o])=>o),ie(([,o,s])=>Math.max(0,o-s)),cn(0),ot()),0);return{alignToBottom:n,paddingTopAddition:r}},rt(St,Sc),{singleton:!0}),Cc=qe(()=>({context:Y(null)})),ax=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,Tc=qe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ue();return me(z(d,Le(t,l,n,s,o,r,a),Le(e),ie(([[f,h,p,w,v,g,x,b],C])=>{const{align:E,behavior:T,calculateViewLocation:k=ax,done:I,...A}=f,j=fc(f,h,w-1),P=Or(j,h.offsetTree,C)+v+g,L=P+Wt(h.sizeTree,j)[1],$=b+g,H=b+p-x,M=k({itemBottom:L,itemTop:P,locationParams:{align:E,behavior:T,...A},viewportBottom:H,viewportTop:$});return M?I&&Ut(z(i,ke(K=>!K),Dn(ct(i)?1:2)),I):I&&I(),M}),ke(f=>f!==null)),u),{scrollIntoView:d}},rt(Zt,St,Mr,Fn,xn),{singleton:!0});function kc(e){return e?e==="smooth"?"smooth":"auto":!1}const lx=(e,t)=>typeof e=="function"?kc(e(t)):t&&kc(e),cx=qe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=Y(!1),v=Ue();let g=null;function x(T){Oe(i,{align:"end",behavior:T,index:"LAST"})}Ze(z(ft(z(Se(t),Dn(1)),l),Le(Se(w),s,a,f),ie(([[T,k],I,A,j,P])=>{let L=k&&j,$="auto";return L&&($=lx(I,A||P),L=L&&!!$),{followOutputBehavior:$,shouldFollow:L,totalCount:T}}),ke(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:k})=>{g&&(g(),g=null),ct(n)?requestAnimationFrame(()=>{ct(d)("following output to ",{totalCount:k},Et.DEBUG),x(T)}):g=Ut(e,()=>{ct(d)("following output to ",{totalCount:k},Et.DEBUG),x(T),g=null})});function b(T){const k=Ut(o,I=>{T&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ct(d)("scrolling to bottom due to increased size",{},Et.DEBUG),x("auto"))});setTimeout(k,100)}Ze(z(ft(Se(w),t,u),ke(([T,,k])=>T&&k),Jt(({value:T},[,k])=>({refreshed:T===k,value:k}),{refreshed:!1,value:0}),ke(({refreshed:T})=>T),Le(w,t)),([,T])=>{ct(a)&&b(T!==!1)}),Ze(v,()=>{b(ct(w)!==!1)}),Ze(ft(Se(w),o),([T,k])=>{T&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=Y(null),E=Ue();return me(ci(z(Se(r),ie(T=>{var k;return(k=T==null?void 0:T.length)!=null?k:0})),z(Se(t))),E),Ze(z(ft(z(E,Dn(1)),l),Le(Se(C),a,f,h),ie(([[T,k],I,A,j,P])=>k&&A&&(I==null?void 0:I({context:P,totalCount:T,scrollingInProgress:j}))),ke(T=>!!T),cn(0)),T=>{g&&(g(),g=null),ct(n)?requestAnimationFrame(()=>{ct(d)("scrolling into view",{}),Oe(p,T)}):g=Ut(e,()=>{ct(d)("scrolling into view",{}),Oe(p,T),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:C}},rt(Zt,Fr,Mr,Dr,wn,xn,St,Cc,Tc)),ux=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(me(z(a,Le(s),ke(([,l])=>l!==0),Le(o,r,t,n,e),ie(([[,l],u,d,f,h,p=[]])=>bc(l,u,d,f,h,p))),i),{}),rt(Zt,Dr,Fn,wn),{singleton:!0}),dx=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Ze(z(e,Le(r),ke(([,o])=>o!==0),ie(([,o])=>({top:o}))),o=>{Ut(z(n,Dn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Oe(t,o)})})}),{initialScrollTop:r}},rt(wn,St,Fn),{singleton:!0}),Ec=qe(([{scrollVelocity:e}])=>{const t=Y(!1),n=Ue(),r=Y(!1);return me(z(e,Le(r,t,n),ke(([o,s])=>!!s),ie(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),ot()),t),Ze(z(ft(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},rt(Fr),{singleton:!0}),Si=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ue(),r=Ue(),o=Ue(),s=Y(!1),i=Y(void 0);return me(z(ft(n,r),ie(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),me(z(t,Le(r),ie(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},rt(St)),fx=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ue(),d=Y(void 0),f=Y(null),h=Y(null);return me(a,f),me(l,h),Ze(z(u,Le(t,r,i,f,h,n)),([p,w,v,g,x,b,C])=>{const E=Yg(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=C,p({ranges:E,scrollTop:v})}),me(z(d,ke(ai),ie(hx)),o),me(z(s,Le(d),ke(([,p])=>p!==void 0),ot(),ie(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},rt(Zt,St,Dr,wn,Si));function hx(e){return{align:"start",index:0,offset:e.scrollTop}}const px=qe(([{topItemsIndexes:e}])=>{const t=Y(0);return me(z(t,ke(n=>n>=0),ie(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},rt(Fn));function Ic(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const mx=Ic(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),gx=qe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=_t(z(l,Le(i),Jt(([,x,b,C],[{bottom:E,items:T,offsetBottom:k,totalCount:I},A])=>{const j=E+k;let P=0;return b===I&&x.length>0&&T.length>0&&(T[0].originalIndex===0&&x[0].originalIndex===0||(P=j-C,P!==0&&(P+=A))),[P,T,I,j]},[0,[],0,0]),ke(([x])=>x!==0),Le(r,a,n,o,p,w),ke(([,x,b,C,,,E])=>!E&&!C&&x!==0&&b===Lr),ie(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Et.DEBUG),x))));function g(x){x>0?(Oe(t,{behavior:"auto",top:-x}),Oe(e,0)):(Oe(e,0),Oe(t,{behavior:"auto",top:-x}))}return Ze(z(v,Le(e,s)),([x,b,C])=>{C&&mx()?Oe(e,b-x):g(-x)}),Ze(z(ft(wt(s,!1),e,w),ke(([x,b,C])=>!x&&!C&&b!==0),ie(([x,b])=>b),cn(1)),g),me(z(f,ie(x=>({top:-x}))),t),Ze(z(u,Le(h,d),ie(([x,{groupIndices:b,lastSize:C,sizeTree:E},T])=>{function k(I){return I*(C+T)}if(b.length===0)return k(x);{let I=0;const A=Rr(E,0);let j=0,P=0;for(;j<x;){j++,I+=A;let L=b.length===P+1?1/0:b[P+1]-b[P]-1;j+L>x&&(I-=A,L=x-j+1),j+=L,I+=k(L),P++}return I}})),x=>{Oe(e,x),requestAnimationFrame(()=>{Oe(t,{top:x}),requestAnimationFrame(()=>{Oe(e,0),Oe(w,!1)})})}),{deviation:e}},rt(St,Fr,Fn,Zt,xn,mi)),xx=qe(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),rt(bi,ux,wn,Ec,Sc,dx,ix,Si,Tc,xn,Cc)),Nc=qe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:C,...E},{scrollToIndex:T},k,{topItemCount:I},{groupCounts:A},j])=>(me(E.rangeChanged,j.scrollSeekRangeChanged),me(z(j.windowViewportRect,ie(P=>P.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:T,statefulTotalCount:u,trackItemSizes:f,...E,...j,...v,sizes:l,...g}),rt(Zt,Dr,St,fx,cx,Fn,Mr,gx,px,pc,xx));function vx(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const No=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Ac(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=y.createContext({});function l(g,x){g.propsReady&&Oe(g.propsReady,!1);for(const b of r){const C=g[t.required[b]];Oe(C,x[b])}for(const b of o)if(b in x){const C=g[t.optional[b]];Oe(C,x[b])}g.propsReady&&Oe(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=C=>{const E=g[t.methods[b]];Oe(E,C)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=Og(g[t.events[b]]),x),{})}const f=y.forwardRef((g,x)=>{const{children:b,...C}=g,[E]=y.useState(()=>bo(Dg(e),I=>{l(I,C)})),[T]=y.useState(Zl(d,E));No(()=>{for(const I of i)I in C&&Ze(T[I],C[I]);return()=>{Object.values(T).map(li)}},[C,T,E]),No(()=>{l(E,C)}),y.useImperativeHandle(x,Xl(u(E)));const k=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(k,{...vx([...r,...o,...i],C),children:b}):b})}),h=g=>{const x=y.useContext(a);return y.useCallback(b=>{Oe(x[g],b)},[x,g])},p=g=>{const x=y.useContext(a)[g],b=y.useCallback(C=>Ze(x,C),[x]);return y.useSyncExternalStore(b,()=>ct(x),()=>ct(x))},w=g=>{const x=y.useContext(a)[g],[b,C]=y.useState(Zl(ct,x));return No(()=>Ze(x,E=>{E!==b&&C(Xl(E))}),[x,b]),b},v=y.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const b=y.useContext(a)[g];No(()=>Ze(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const _c=y.createContext(void 0),jc=y.createContext(void 0),Rc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Ci(e){return"self"in e}function wx(e){return"body"in e}function Pc(e,t,n,r=ir,o,s){const i=y.useRef(null),a=y.useRef(null),l=y.useRef(null),u=y.useCallback(h=>{let p,w,v;const g=h.target;if(wx(g)||Ci(g)){const b=Ci(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Ps.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;Ci(p)?(g=Math.max(vn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=vn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),gc(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ti="-webkit-sticky",Oc="sticky",ki=Ic(()=>{if(typeof document>"u")return Oc;const e=document.createElement("div");return e.style.position=Ti,e.style.position===Ti?Ti:Oc});function Ei(e){return e}const bx=qe(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(Ei),o=Y("div"),s=Y(ir),i=(a,l=null)=>wt(z(n,ie(u=>u[a]),ot()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),yx=qe(([e,t])=>({...e,...t}),rt(Nc,bx)),Sx=({height:e})=>c.jsx("div",{style:{height:e}}),Cx={overflowAnchor:"none",position:ki(),zIndex:1},Mc={overflowAnchor:"none"},Tx={...Mc,display:"inline-block",height:"100%"},Dc=y.memo(function({showTopList:e=!1}){const t=je("listState"),n=Dt("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=Dt("windowScrollContainerState"),i=Dt("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),u=je("context"),d=je("groupContent"),f=je("trackItemSizes"),h=je("itemSize"),p=je("log"),w=Dt("gap"),v=je("horizontalDirection"),{callbackRef:g}=Fg(n,h,f,e?ir:a,p,w,o,v,je("skipAnimationFrameInResizeObserver")),[x,b]=y.useState(0);Ii("deviation",M=>{x!==M&&b(M)});const C=je("EmptyPlaceholder"),E=je("ScrollSeekPlaceholder")||Sx,T=je("ListComponent"),k=je("ItemComponent"),I=je("GroupComponent"),A=je("computeItemKey"),j=je("isSeeking"),P=je("groupIndices").length>0,L=je("alignToBottom"),$=je("initialItemFinalLocationReached"),H=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?c.jsx(C,{...bt(C,u)}):c.jsx(T,{...bt(T,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:H,children:(e?t.topItems:t.items).map(M=>{const K=M.originalIndex,W=A(K+t.firstItemIndex,M.data,u);return j?y.createElement(E,{...bt(E,u),height:M.size,index:M.index,key:W,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(I,{...bt(I,u),"data-index":K,"data-item-index":M.index,"data-known-size":M.size,key:W,style:Cx},d(M.index,u)):y.createElement(k,{...bt(k,u),...Nx(k,M.data),"data-index":K,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:W,style:v?Tx:Mc},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),kx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Ex={outline:"none",overflowX:"auto",position:"relative"},Ao=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Ix={position:ki(),top:0,width:"100%",zIndex:1};function bt(e,t){if(typeof e!="string")return{context:t}}function Nx(e,t){return{item:typeof e=="string"?void 0:t}}const Ax=y.memo(function(){const e=je("HeaderComponent"),t=Dt("headerHeight"),n=je("HeaderFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null}),_x=y.memo(function(){const e=je("FooterComponent"),t=Dt("footerHeight"),n=je("HeaderFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null});function Lc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Pc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Ex:kx,...o},tabIndex:0,...i,...bt(l,s),children:r})})}function $c({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Pc(a,u,l,w,h);return Rc(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...bt(l,s),children:r})})}const jx=({children:e})=>{const t=y.useContext(_c),n=Dt("viewportHeight"),r=Dt("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=y.useMemo(()=>Jl(n,l=>vn(l,s?"width":"height")),[n,s]),a=Ln(i,!0,je("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Ao(o),children:e})},Rx=({children:e})=>{const t=y.useContext(_c),n=Dt("windowViewportRect"),r=Dt("fixedItemHeight"),o=je("customScrollParent"),s=nc(n,o,je("skipAnimationFrameInResizeObserver")),i=je("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Ao(i),children:e})},Px=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...Ix,marginTop:`${n}px`},o=je("context");return c.jsx(t,{style:r,...bt(t,o),children:e})},Ox=y.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return c.jsxs(r||t?Lx:Dx,{...e,context:o,children:[n&&c.jsx(Px,{children:c.jsx(Dc,{showTopList:!0})}),c.jsxs(r||t?Rx:jx,{children:[c.jsx(Ax,{}),c.jsx(Dc,{}),c.jsx(_x,{})]})]})}),{Component:Mx,useEmitter:Ii,useEmitterValue:je,usePublisher:Dt}=Ac(yx,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},Ox),Dx=Lc({useEmitter:Ii,useEmitterValue:je,usePublisher:Dt}),Lx=$c({useEmitter:Ii,useEmitterValue:je,usePublisher:Dt}),$x=Mx;rt(Nc,qe(()=>{const e=Y(u=>c.jsxs("td",{children:["Item $",u]})),t=Y(null),n=Y(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=Y(null),o=Y(null),s=Y({}),i=Y(Ei),a=Y(ir),l=(u,d=null)=>wt(z(s,ie(f=>f[u]),ot()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),ki();const Fc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Fx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Bc,floor:_o,max:Br,min:Ni,round:zc}=Math;function Hc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Bx(e){return{...Fx,items:e}}function jo(e,t){return e&&e.width===t.width&&e.height===t.height}function zx(e,t){return e&&e.column===t.column&&e.row===t.row}const Hx=qe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:E},T])=>{const k=Y(0),I=Y(0),A=Y(Fc),j=Y({height:0,width:0}),P=Y({height:0,width:0}),L=Ue(),$=Ue(),H=Y(0),M=Y(null),K=Y({column:0,row:0}),W=Ue(),G=Ue(),B=Y(!1),_=Y(0),q=Y(!0),Q=Y(!1),xe=Y(!1);Ze(z(w,Le(_),ke(([D,J])=>!!J)),()=>{Oe(q,!1)}),Ze(z(ft(w,q,P,j,_,Q),ke(([D,J,U,he,,ce])=>D&&!J&&U.height!==0&&he.height!==0&&!ce)),([,,,,D])=>{Oe(Q,!0),vi(1,()=>{Oe(L,D)}),Ut(z(u),()=>{Oe(t,[0,0]),Oe(q,!0)})}),me(z(G,ke(D=>D!=null&&D.scrollTop>0),Xt(0)),I),Ze(z(w,Le(G),ke(([,D])=>D!=null)),([,D])=>{D&&(Oe(j,D.viewport),Oe(P,D.item),Oe(K,D.gap),D.scrollTop>0&&(Oe(B,!0),Ut(z(u,Dn(1)),J=>{Oe(B,!1)}),Oe(l,{top:D.scrollTop})))}),me(z(j,ie(({height:D})=>D)),f),me(z(ft(Se(j,jo),Se(P,jo),Se(K,(D,J)=>D&&D.column===J.column&&D.row===J.row),Se(u)),ie(([D,J,U,he])=>({gap:U,item:J,scrollTop:he,viewport:D}))),W),me(z(ft(Se(k),r,Se(K,zx),Se(P,jo),Se(j,jo),Se(M),Se(I),Se(B),Se(q),Se(_)),ke(([,,,,,,,D])=>!D),ie(([D,[J,U],he,ce,ze,Ye,Ge,,Te,Me])=>{const{column:tt,row:He}=he,{height:Xe,width:ht}=ce,{width:re}=ze;if(Ge===0&&(D===0||re===0))return Fc;if(ht===0){const It=wi(Me,D),fn=It+Math.max(Ge-1,0);return Bx(Hc(It,fn,Ye))}const te=Uc(re,ht,tt);let ge,Ee;Te?J===0&&U===0&&Ge>0?(ge=0,Ee=Ge-1):(ge=te*_o((J+He)/(Xe+He)),Ee=te*Bc((U+He)/(Xe+He))-1,Ee=Ni(D-1,Br(Ee,te-1)),ge=Ni(Ee,Br(0,ge))):(ge=0,Ee=-1);const ye=Hc(ge,Ee,Ye),{bottom:Re,top:Je}=Wc(ze,he,ce,ye),We=Bc(D/te),it=We*Xe+(We-1)*He-Re;return{bottom:Re,itemHeight:Xe,items:ye,itemWidth:ht,offsetBottom:it,offsetTop:Je,top:Je}})),A),me(z(M,ke(D=>D!==null),ie(D=>D.length)),k),me(z(ft(j,P,A,K),ke(([D,J,{items:U}])=>U.length>0&&J.height!==0&&D.height!==0),ie(([D,J,{items:U},he])=>{const{bottom:ce,top:ze}=Wc(D,he,J,U);return[ze,ce]}),ot(Pr)),t);const ue=Y(!1);me(z(u,Le(ue),ie(([D,J])=>J||D!==0)),ue);const ne=_t(z(ft(A,k),ke(([{items:D}])=>D.length>0),Le(ue),ke(([[D,J],U])=>{const he=D.items[D.items.length-1].index===J-1;return(U||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===J)&&he}),ie(([[,D]])=>D-1),ot())),_e=_t(z(Se(A),ke(({items:D})=>D.length>0&&D[0].index===0),Xt(0),ot())),Ce=_t(z(Se(A),Le(B),ke(([{items:D},J])=>D.length>0&&!J),ie(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ot(cc),cn(0)));me(Ce,p.scrollSeekRangeChanged),me(z(L,Le(j,P,k,K),ie(([D,J,U,he,ce])=>{const ze=mc(D),{align:Ye,behavior:Ge,offset:Te}=ze;let Me=ze.index;Me==="LAST"&&(Me=he-1),Me=Br(0,Me,Ni(he-1,Me));let tt=Ai(J,ce,U,Me);return Ye==="end"?tt=zc(tt-J.height+U.height):Ye==="center"&&(tt=zc(tt-J.height/2+U.height/2)),Te&&(tt+=Te),{behavior:Ge,top:tt}})),l);const V=wt(z(A,ie(D=>D.offsetBottom+D.bottom)),0);return me(z(E,ie(D=>({height:D.visibleHeight,width:D.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:H,footerHeight:o,gap:K,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:P,overscan:n,restoreStateFrom:G,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:E,...p,gridState:A,horizontalDirection:xe,initialTopMostItemIndex:_,totalListHeight:V,...h,endReached:ne,propsReady:v,rangeChanged:Ce,startReached:_e,stateChanged:W,stateRestoreInProgress:B,...T}},rt(bi,St,Fr,Ec,wn,Si,xn));function Uc(e,t,n){return Br(1,_o((e+n)/(_o(t)+n)))}function Wc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ai(e,t,n,r[0].index);return{bottom:Ai(e,t,n,r[r.length-1].index)+o,top:s}}function Ai(e,t,n,r){const o=Uc(e.width,n.width,t.column),s=_o(r/o),i=s*n.height+Br(0,s-1)*t.row;return i>0?i+t.row:i}const Ux=qe(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(Ei),i=Y("div"),a=Y(ir),l=(f,h=null)=>wt(z(t,ie(p=>p[f]),ot()),h),u=Y(!1),d=Y(!1);return me(Se(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Wx=qe(([e,t])=>({...e,...t}),rt(Hx,Ux)),Vx=y.memo(function(){const e=st("gridState"),t=st("listClassName"),n=st("itemClassName"),r=st("itemContent"),o=st("computeItemKey"),s=st("isSeeking"),i=Lt("scrollHeight"),a=st("ItemComponent"),l=st("ListComponent"),u=st("ScrollSeekPlaceholder"),d=st("context"),f=Lt("itemDimensions"),h=Lt("gap"),p=st("log"),w=st("stateRestoreInProgress"),v=Lt("reportReadyState"),g=Ln(y.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const C=x.firstChild;if(C){const{height:E,width:T}=C.getBoundingClientRect();f({height:E,width:T})}h({column:Kc("column-gap",getComputedStyle(x).columnGap,p),row:Kc("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Rc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...bt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?c.jsx(u,{...bt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):y.createElement(a,{...bt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),Kx=y.memo(function(){const e=st("HeaderComponent"),t=Lt("headerHeight"),n=st("headerFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,!1),o=st("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null}),qx=y.memo(function(){const e=st("FooterComponent"),t=Lt("footerHeight"),n=st("headerFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,!1),o=st("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null}),Gx=({children:e})=>{const t=y.useContext(jc),n=Lt("itemDimensions"),r=Lt("viewportDimensions"),o=Ln(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Ao(!1),children:e})},Yx=({children:e})=>{const t=y.useContext(jc),n=Lt("windowViewportRect"),r=Lt("itemDimensions"),o=st("customScrollParent"),s=nc(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Ao(!1),children:e})},Xx=y.memo(function({...e}){const t=st("useWindowScroll"),n=st("customScrollParent"),r=n||t?Zx:Jx,o=n||t?Yx:Gx,s=st("context");return c.jsx(r,{...e,...bt(r,s),children:c.jsxs(o,{children:[c.jsx(Kx,{}),c.jsx(Vx,{}),c.jsx(qx,{})]})})}),{useEmitter:Vc,useEmitterValue:st,usePublisher:Lt}=Ac(Wx,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Xx),Jx=Lc({useEmitter:Vc,useEmitterValue:st,usePublisher:Lt}),Zx=$c({useEmitter:Vc,useEmitterValue:st,usePublisher:Lt});function Kc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}const Qx=no.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function _i({className:e,variant:t,...n}){return c.jsx("div",{className:ee(Qx({variant:t}),e),...n})}function le(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function ev(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Qt(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,tv(o,...t)]}function tv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var mt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},nv=m[" useInsertionEffect ".trim().toString()]||mt;function Bn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=rv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=ov(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function rv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return nv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ov(e){return typeof e=="function"}function qc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ji(...e){return t=>{let n=!1;const r=e.map(o=>{const s=qc(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():qc(e[o],null)}}}}function Be(...e){return m.useCallback(ji(...e),e)}var sv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ie=sv.reduce((e,t)=>{const n=Rn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Gc(e,t){e&&ro.flushSync(()=>e.dispatchEvent(t))}function iv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Rt=e=>{const{present:t,children:n}=e,r=av(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Be(r.ref,lv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Rt.displayName="Presence";function av(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=iv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Ro(r.current);s.current=a==="mounted"?u:"none"},[a]),mt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Ro(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),mt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=Ro(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Ro(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Ro(e){return(e==null?void 0:e.animationName)||"none"}function lv(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var cv=m[" useId ".trim().toString()]||(()=>{}),uv=0;function en(e){const[t,n]=m.useState(cv());return mt(()=>{n(r=>r??String(uv++))},[e]),e||(t?`radix-${t}`:"")}var Po="Collapsible",[dv,GC]=Qt(Po),[fv,Ri]=dv(Po),Yc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Bn({prop:r,defaultProp:o??!1,onChange:i,caller:Po});return c.jsx(fv,{scope:n,disabled:s,contentId:en(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ie.div,{"data-state":Oi(l),"data-disabled":s?"":void 0,...a,ref:t})})});Yc.displayName=Po;var Xc="CollapsibleTrigger",Jc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Ri(Xc,n);return c.jsx(Ie.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Oi(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:le(e.onClick,o.onOpenToggle)})});Jc.displayName=Xc;var Pi="CollapsibleContent",hv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ri(Pi,e.__scopeCollapsible);return c.jsx(Rt,{present:n||o.open,children:({present:s})=>c.jsx(pv,{...r,ref:t,present:s})})});hv.displayName=Pi;var pv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Ri(Pi,n),[a,l]=m.useState(r),u=m.useRef(null),d=Be(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),mt(()=>{const b=u.current;if(b){x.current=x.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const C=b.getBoundingClientRect();f.current=C.height,p.current=C.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Ie.div,{"data-state":Oi(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function Oi(e){return e?"open":"closed"}var mv=Yc;const Zc=mv,Qc=Jc,zr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));zr.displayName="Card";const Hr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex flex-col space-y-1.5 p-6",e),...t}));Hr.displayName="CardHeader";const Ur=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:ee("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ur.displayName="CardTitle";const eu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));eu.displayName="CardDescription";const Oo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("p-6 pt-0",e),...t}));Oo.displayName="CardContent";const tu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex items-center p-6 pt-0",e),...t}));tu.displayName="CardFooter";function nu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let zn=nu();function gv(e){zn=e}const ru=/[&<>"']/,xv=new RegExp(ru.source,"g"),ou=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,vv=new RegExp(ou.source,"g"),wv={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},su=e=>wv[e];function yt(e,t){if(t){if(ru.test(e))return e.replace(xv,su)}else if(ou.test(e))return e.replace(vv,su);return e}const bv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function iu(e){return e.replace(bv,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const yv=/(^|[^\[])\^/g;function et(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(yv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Sv=/[^\w:]/g,Cv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function au(e,t,n){if(e){let r;try{r=decodeURIComponent(iu(n)).replace(Sv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Cv.test(n)&&(n=Iv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Mo={},Tv=/^[^:]+:\/*[^/]*$/,kv=/^([^:]+:)[\s\S]*$/,Ev=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Iv(e,t){Mo[" "+e]||(Tv.test(e)?Mo[" "+e]=e+"/":Mo[" "+e]=Lo(e,"/",!0)),e=Mo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(kv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Ev,"$1")+t:e+t}const Do={exec:function(){}};function lu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Lo(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function Nv(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function Av(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function cu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function uu(e,t,n,r){const o=t.href,s=t.title?yt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:yt(i)}}function _v(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
33
+ `)}function xg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=y.useRef(null),i=y.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(ig(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Bl({baseUrl:e,token:null}),h=y.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return y.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const zl=y.createContext(null),Hl=y.createContext(null),Ul=y.createContext(null),vg=y.createContext(!1),wg=20,bg="cachedThreads",yg="v1",go=300,Qs=200;function Wl(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,go)}function or(){return typeof window<"u"&&typeof window.localStorage<"u"}function ei(e){if(!or())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Vl(e,t){if(or())try{window.localStorage.setItem(e,t)}catch{}}function ti(e){if(or())try{window.localStorage.removeItem(e)}catch{}}function Sg(){const e=ei(bg);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Cg(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function ni(e,t){return`cachedThreads:v1:${e}:${Cg(t||"anon")}`}function Tg(e){const t=ei(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function ri(e,t){try{Vl(e,JSON.stringify(t))}catch{}}function Kl(e){const t=Tg(e);if(t.length>0)return t;const n=Sg();if(n.length>0)try{ri(e,n.slice(0,Qs))}catch{}return n}function oi(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function si(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function kg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Ys(),d=y.useMemo(()=>ln(u),[u]),f=y.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=y.useMemo(()=>`threadPayload:${yg}:${f}:`,[f]),p=y.useCallback(N=>`${h}${N}`,[h]),w=y.useCallback(N=>{if(!N||typeof N!="object")return null;const R=N;return typeof R.threadId!="string"||!Array.isArray(R.messages)?null:{threadId:R.threadId,messages:R.messages,hasMore:!!R.hasMore,nextCursor:R.nextCursor??null,checkpointId:R.checkpointId??null,checkpointNs:R.checkpointNs??null}},[]),v=y.useCallback(N=>{const R=ei(p(N));if(!R)return null;try{const Z=JSON.parse(R);return w(Z)}catch{return null}},[p,w]),g=y.useCallback((N,R=100)=>{const Z={...N,messages:Array.isArray(N.messages)?N.messages.slice(-R):[]};try{Vl(p(N.threadId),JSON.stringify(Z))}catch{}},[p]),x=y.useCallback(N=>{ti(p(N))},[p]),b=y.useCallback(()=>{if(or())try{const N=h;for(let R=0;R<window.localStorage.length;R++){const Z=window.localStorage.key(R);Z&&Z.startsWith(N)&&window.localStorage.removeItem(Z)}}catch{}},[h]),[C,E]=y.useState(()=>{var N;return ni(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[T,k]=y.useState(()=>{var R;const N=Kl(ni(f,(R=l.getAuthToken)==null?void 0:R.call(l)));return oi(N)}),I=y.useMemo(()=>si(T),[T]),[A,j]=y.useState(t),[P,L]=y.useState(!1),[$,H]=y.useState(!1),[M,K]=y.useState(!1),[W,G]=y.useState(!1),[B,_]=y.useState(null),[q,Q]=y.useState(void 0),[xe,ue]=y.useState(void 0),{state:ne,seed:_e,prepend:Ce,pushUser:V,onEvent:D,reset:J}=$l(),U=y.useRef(A);y.useEffect(()=>{U.current=A},[A]);const he=y.useRef(!1),ce=y.useRef([]),ze=y.useRef(null),Ye=y.useRef(null),Ge=y.useRef(new Map),Te=y.useRef(A),Me=y.useRef(!1),tt=y.useRef(null),He=y.useCallback((N,R)=>new Promise((Z,pe)=>{const fe=async()=>{he.current=!0;try{await N(),Z()}catch(S){pe(S)}finally{he.current=!1;const S=ce.current.shift();S&&S().catch(()=>{})}};he.current?ce.current.push(fe):fe().catch(S=>{pe(S)})}),[]),Xe=y.useCallback(async()=>{const N=I.length>0;N||L(!0);try{const R=await l.listThreads();y.startTransition(()=>{k(Z=>{const pe=F=>F.map(X=>`${X.threadId}:${X.updatedAt??""}:${X.messageCount??""}`).join("|"),fe=si(Z);return pe(fe)===pe(R)?Z:oi(R)})})}catch(R){i==null||i(String(R)),console.error("[ChatSessionProvider] Failed to refresh threads:",R)}finally{N||L(!1)}},[l,i,I.length]),ht=y.useRef(!1),re=y.useRef(null),te=y.useRef(null),ge=y.useRef(""),Ee=y.useCallback((N,R)=>{if(!or())return;te.current!==null&&(window.clearTimeout(te.current),te.current=null);const Z=N.map(fe=>`${fe.threadId}:${fe.updatedAt??""}:${fe.messageCount??""}`).join("|");if(N.length===0){try{ti(C)}catch{}ge.current="";return}if(Z===ge.current)return;const pe=()=>{try{const fe=N.slice(0,Qs);ri(C,fe),ge.current=Z}catch{}finally{te.current=null}};if(R!=null&&R.immediate){pe();return}te.current=window.setTimeout(()=>{Wl(pe)},go)},[C]),ye=y.useCallback((N,R,Z)=>{const pe=Array.isArray(N==null?void 0:N.messages)?N.messages:[],fe=Z??(N==null?void 0:N.threadId)??U.current;if(R==="replace"){if(fe){const S={threadId:fe,messages:pe.slice(),hasMore:!!(N!=null&&N.hasMore),nextCursor:(N==null?void 0:N.nextCursor)??null,checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null};Ge.current.set(fe,S),Te.current=fe}_e(pe,{checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null})}else if(R==="prepend"&&pe.length&&fe){const S=Ge.current.get(fe),F=(S==null?void 0:S.messages)??[],X=new Set,de=[...pe,...F].filter(Ke=>{const De=Ke==null?void 0:Ke.id;return De?X.has(De)?!1:(X.add(De),!0):!0}),Ne={threadId:fe,messages:de,hasMore:(N==null?void 0:N.hasMore)??(S==null?void 0:S.hasMore)??!1,nextCursor:(N==null?void 0:N.nextCursor)??(S==null?void 0:S.nextCursor)??null,checkpointId:(S==null?void 0:S.checkpointId)??(N==null?void 0:N.checkpointId)??null,checkpointNs:(S==null?void 0:S.checkpointNs)??(N==null?void 0:N.checkpointNs)??null};Ge.current.set(fe,Ne),Ce(pe)}else R==="prepend"&&pe.length&&Ce(pe);R==="replace"?(_((N==null?void 0:N.nextCursor)??null),K(!!(N!=null&&N.hasMore)),Q((N==null?void 0:N.checkpointId)??void 0),ue((N==null?void 0:N.checkpointNs)??void 0)):(_(S=>(N==null?void 0:N.nextCursor)??S??null),K(S=>(N==null?void 0:N.hasMore)!==void 0?!!(N!=null&&N.hasMore):S),Q(S=>(N==null?void 0:N.checkpointId)??S??void 0),ue(S=>(N==null?void 0:N.checkpointNs)??S??void 0))},[Ce,_e]),Re=y.useCallback(N=>{_e(N.messages,{checkpointId:N.checkpointId,checkpointNs:N.checkpointNs}),_(N.nextCursor),K(N.hasMore),Q(N.checkpointId??void 0),ue(N.checkpointNs??void 0),Te.current=N.threadId},[_e]),Je=y.useCallback(N=>{N&&(Ge.current.delete(N),x(N),Te.current===N&&(Te.current=null))},[x]),We=y.useCallback(()=>{const N=U.current;N&&Je(N),J([]),K(!1),G(!1),_(null),Q(void 0),ue(void 0)},[Je,J]),it=y.useCallback(({from:N,to:R})=>{const Z=U.current;Z&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${R}) for thread ${Z}`)},[]),It=y.useCallback(N=>{const R=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:R,title:N.title,created:N.created,currentThreads:I.length});const Z={threadId:R,title:N.title||`Thread ${R.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};U.current!==R&&(!U.current&&ne.messages.length<=1&&(Ye.current=R),j(R)),y.startTransition(()=>{k(pe=>{const fe=pe.byId[R];return fe?fe.title===Z.title&&fe.updatedAt===Z.updatedAt&&fe.messageCount===Z.messageCount?pe:{byId:{...pe.byId,[R]:Z},order:pe.order}:{byId:{...pe.byId,[R]:Z},order:[R,...pe.order]}})})},[ne.messages.length]),{startStream:fn,stop:wr,isStreaming:Nn,error:Jn,setAuthToken:hn}=xg({baseUrl:d,onThreadInfo:It,onMessageEvent:D,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:it});y.useEffect(()=>{ht.current=Nn},[Nn]),y.useEffect(()=>{if(!or())return;te.current!==null&&(window.clearTimeout(te.current),te.current=null);const N=I.map(Z=>`${Z.threadId}:${Z.updatedAt??""}:${Z.messageCount??""}`).join("|");if(I.length===0){try{ti(C)}catch{}ge.current="";return}if(N===ge.current)return;const R=()=>{try{const Z=I.slice(0,Qs);ri(C,Z),ge.current=N}catch{}finally{te.current=null}};return te.current=window.setTimeout(()=>{Wl(R),te.current=null},go),()=>{te.current!==null&&(window.clearTimeout(te.current),te.current=null)}},[I,Ee]),y.useEffect(()=>{var pe;const N=l.getAuthToken();hn(N);const R=fe=>{const S=ni(f,fe);tt.current!==S&&(tt.current=S,Me.current=!1),E(S);const F=Kl(S);y.startTransition(()=>{k(oi(F))}),Me.current||(Me.current=!0,Xe().catch(()=>{}))};R(N);const Z=(pe=l.onTokenChange)==null?void 0:pe.call(l,fe=>{hn(fe),b(),R(fe)});return()=>{Z==null||Z()}},[l,f,hn,b,Xe]);const br=y.useCallback(async N=>{const R=`temp-${Date.now()}`,Z={threadId:R,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(pe=>({byId:{...pe.byId,[R]:Z},order:[R,...pe.order]})),j(R);try{const pe=await l.createThread(N),fe=typeof pe=="string"?pe:pe.threadId;return k(S=>{const F=S.byId[R];if(!F)return S;const X={...S.byId};delete X[R],X[fe]={...F,threadId:fe};const de=S.order.map(Ne=>Ne===R?fe:Ne);return{byId:X,order:de}}),j(fe),setTimeout(()=>Xe(),10),fe}catch(pe){throw k(fe=>{if(!fe.byId[R])return fe;const S={...fe.byId};delete S[R];const F=fe.order.filter(X=>X!==R);return{byId:S,order:F}}),j(null),pe}},[l,Xe]),An=y.useCallback(async N=>{await l.deleteThread(N);let R=null;k(Z=>{if(!Z.byId[N])return Z;const pe={...Z.byId};delete pe[N];const fe=Z.order.filter(F=>F!==N),S={byId:pe,order:fe};return R=si(S),S}),R&&Ee(R,{immediate:!0}),Je(N),U.current===N&&(Ye.current=N,j(null),U.current=null,Te.current=null,We()),await Xe()},[l,We,Je,Xe,Ee]),Zn=y.useCallback(async(N,R)=>{try{await l.updateThread(N,R),k(Z=>{const pe=Z.byId[N];return pe?{byId:{...Z.byId,[N]:{...pe,title:R}},order:Z.order}:Z})}catch(Z){throw await Xe(),Z}},[l,Xe]),xt=y.useCallback(async(N,R,Z,pe=!1)=>{await He(async()=>{if(Ye.current===N&&!pe){Ye.current=null;return}if(ze.current===N&&!pe)return;j(de=>de===N?de:N),U.current=N;const fe=!pe&&!R&&!Z;let S=!1;if(fe){const de=Ge.current.get(N);if(de)Re(de),S=!0;else{const Ne=v(N);Ne&&(Ge.current.set(N,Ne),Re(Ne),S=!0)}}const F=pe||!S||!!R||!!Z,X=async de=>{de&&H(!0),ze.current=N;try{const Ne=await l.getMessages({threadId:N,checkpointId:R,checkpointNs:Z});ye(Ne,"replace",N)}catch(Ne){throw(!S||pe||de)&&(i==null||i(String(Ne))),Ne}finally{ze.current=null,de&&H(!1)}};F?await X(!0):fe&&S&&X(!1).catch(de=>{console.warn("[ChatSessionProvider] Background refresh failed:",de)})},`loadThread-${N}`)},[l,Re,ye,He,i]),_n=y.useCallback(async()=>{await He(async()=>{const N=U.current;N&&Je(N),Ye.current=null,j(null),U.current=null,Te.current=null,We(),Q(void 0),ue(void 0);try{localStorage.removeItem("lastThreadId")}catch(R){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",R)}},"clearCurrentThread")},[We,Je,He]),jn=y.useCallback(async N=>{const R=await l.listCheckpoints(N);return rg(R,N)},[l]),Qn=y.useCallback(async(N,R)=>{if(!U.current)throw new Error("No active thread");await xt(U.current,N,R??void 0,!0)},[xt]),yr=y.useCallback(async()=>{if(!U.current)throw new Error("No active thread");await xt(U.current,void 0,void 0,!0)},[xt]),er=y.useCallback(async N=>{if(!U.current)throw new Error("No active thread");if(W||!M)return;const R=B;if(R){G(!0);try{const Z=U.current,pe=await l.getMessages({threadId:Z,checkpointId:q,checkpointNs:xe,limit:(N==null?void 0:N.limit)??wg,beforeId:R});ye(pe,"prepend",Z??void 0)}finally{G(!1)}}},[l,ye,M,q,xe,B,W]),Sr=y.useCallback(async(N,R)=>{var $e;const Z=U.current;!Z&&!(R!=null&&R.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const pe=(R==null?void 0:R.attachments)||[],{contentParts:fe,filesInfo:S}=await sg(l,pe),F=[...fe];N&&N.trim()&&F.push({type:"text",text:N.trim()});const X={id:(($e=crypto.randomUUID)==null?void 0:$e.call(crypto))||`user-${Date.now()}`,role:"user",content:F,createdAt:new Date().toISOString(),checkpointId:(R==null?void 0:R.checkpointId)??ne.lastCheckpointId??void 0,checkpointNs:(R==null?void 0:R.checkpointNs)??ne.lastCheckpointNs??void 0};V(X);const de={...X,content:F},Ne={...(R==null?void 0:R.payloadExtras)??{}},Ke=pe.length>0,De={...Z?{threadId:Z}:{},payload:{messages:[de],files_info:S,...o&&Ke&&s?{active_agent:s}:{},...Ne},checkpointId:(R==null?void 0:R.checkpointId)??ne.lastCheckpointId??void 0,checkpointNs:(R==null?void 0:R.checkpointNs)??ne.lastCheckpointNs??void 0,nodeFilter:R==null?void 0:R.nodeFilter,config:R==null?void 0:R.config};fn(De,{onError:ut=>{console.warn("[ChatSessionProvider] Stream error:",ut)},onOpen:({threadId:ut,created:at})=>{!U.current&&ut&&(ne.messages.length<=1&&(Ye.current=ut),j(ut))},onGap:it})},[l,o,s,it,ne.lastCheckpointId,ne.lastCheckpointNs,ne.messages.length,V,fn]),se=y.useCallback(async(N,R,Z)=>{const pe=U.current;if(!pe)throw new Error("No active thread to handle interrupt");try{const fe=R?Z??!0:!1;await l.resume({threadId:pe,value:fe})}catch(fe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,fe),fe}},[l]);y.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[A,a]),y.useEffect(()=>((async()=>{try{if(Xe().catch(R=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",R),i==null||i(String(R))}),!r&&!t)try{const R=localStorage.getItem("lastThreadId");R&&(j(R),n&&await xt(R))}catch(R){console.warn("[ChatSessionProvider] Failed to restore last thread:",R)}else t&&n&&await xt(t)}catch(R){console.error("[ChatSessionProvider] Initialization failed:",R),i==null||i(String(R))}})(),()=>{}),[]),y.useEffect(()=>{const N=U.current;if(!N||Te.current!==N)return;const R={threadId:N,messages:ne.messages.slice(),hasMore:M,nextCursor:B,checkpointId:ne.lastCheckpointId??null,checkpointNs:ne.lastCheckpointNs??null},Z=Ge.current.get(N);(!Z||Z.messages.length!==R.messages.length||Z.messages.some((fe,S)=>{var F;return(fe==null?void 0:fe.id)!==((F=R.messages[S])==null?void 0:F.id)})||(Z==null?void 0:Z.hasMore)!==R.hasMore||(Z==null?void 0:Z.nextCursor)!==R.nextCursor||(Z==null?void 0:Z.checkpointId)!==R.checkpointId||(Z==null?void 0:Z.checkpointNs)!==R.checkpointNs)&&(Ge.current.set(N,R),re.current&&window.clearTimeout(re.current),re.current=window.setTimeout(()=>{try{g(R,100)}catch(fe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",fe)}},go))},[M,B,ne.lastCheckpointId,ne.lastCheckpointNs,ne.messages]);const be=y.useMemo(()=>({threads:I,currentThreadId:A,isLoadingThreads:P,isLoadingThread:$,setCurrentThreadId:j,createThread:br,deleteThread:An,renameThread:Zn,refreshThreads:Xe,loadThread:xt,clearCurrentThread:_n,listCheckpoints:jn,navigateToCheckpoint:Qn,returnToLatest:yr}),[_n,br,A,An,$,P,jn,xt,Qn,Xe,Zn,yr,I]),Fe=y.useMemo(()=>({messages:ne.messages,assemblingId:ne.assemblingId,lastUserMessage:null,hasMoreHistory:M,isLoadingHistory:W,send:Sr,stop:wr,loadOlderMessages:er,clearMessages:We,handleInterrupt:se}),[We,se,M,W,er,ne.assemblingId,ne.messages,Sr,wr]),nt=y.useMemo(()=>({isStreaming:Nn,error:Jn,streamingAssistantId:ne.assemblingId,lastCheckpointId:ne.lastCheckpointId??null,lastCheckpointNs:ne.lastCheckpointNs??null}),[Nn,ne.assemblingId,ne.lastCheckpointId,ne.lastCheckpointNs,Jn]);return c.jsx(vg.Provider,{value:!0,children:c.jsx(Ul.Provider,{value:nt,children:c.jsx(zl.Provider,{value:be,children:c.jsx(Hl.Provider,{value:Fe,children:e})})})})}function xo(){const e=y.useContext(zl);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ii(){const e=y.useContext(Hl);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function ql(){const e=y.useContext(Ul);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function vo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(ng,{apiConfig:t,children:c.jsx(kg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function ee(...e){return jp.twMerge(_p.clsx(e))}const Eg=no.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ve=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Rn.Slot:"button";return c.jsx(i,{className:ee(Eg({variant:t,size:n,className:e})),ref:s,...o})});Ve.displayName="Button";const Gl=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:ee("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Gl.displayName="Textarea";function Ig({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=y.useState(e),[w,v]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=y.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);y.useEffect(()=>{x()},[x]);const b=y.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||v(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),C=y.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=y.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Gl,{ref:g,value:h,onChange:C,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ve,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(oe.Square,{size:16})}):c.jsx(Ve,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(oe.Send,{size:16})})})]})})}const Ng=y.memo(Ig),wo=0,gn=1,sr=2,Yl=4;function Xl(e){return()=>e}function Ag(e){e()}function Jl(e,t){return n=>e(t(n))}function Zl(e,t){return()=>e(t)}function _g(e,t){return n=>e(t,n)}function ai(e){return e!==void 0}function jg(...e){return()=>{e.map(Ag)}}function ir(){}function bo(e,t){return t(e),e}function Rg(e,t){return t(e)}function rt(...e){return e}function Ze(e,t){return e(gn,t)}function Oe(e,t){e(wo,t)}function li(e){e(sr)}function ct(e){return e(Yl)}function me(e,t){return Ze(e,_g(t,wo))}function Ut(e,t){const n=e(gn,r=>{n(),t(r)});return n}function Ql(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function ec(e,t){return e===t}function ot(e=ec){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ie(e){return t=>Jl(t,e)}function Xt(e){return t=>()=>{t(e)}}function z(e,...t){const n=Pg(...t);return(r,o)=>{switch(r){case sr:li(e);return;case gn:return Ze(e,n(o))}}}function Jt(e,t){return n=>r=>{n(t=e(t,r))}}function Dn(e){return t=>n=>{e>0?e--:t(n)}}function cn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Le(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ze(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Pg(...e){return t=>e.reduceRight(Rg,t)}function Og(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case gn:return s?n===s?void 0:(r(),n=s,t=Ze(e,s),t):(r(),ir);case sr:r(),n=null;return}}}function Y(e){let t=e;const n=Ue();return(r,o)=>{switch(r){case wo:t=o;break;case gn:{o(t);break}case Yl:return t}return n(r,o)}}function wt(e,t){return bo(Y(t),n=>me(e,n))}function Ue(){const e=[];return(t,n)=>{switch(t){case wo:e.slice().forEach(r=>{r(n)});return;case sr:e.splice(0,e.length);return;case gn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function _t(e){return bo(Ue(),t=>me(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Mg(),singleton:n}}const Mg=()=>Symbol();function Dg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function ft(...e){const t=Ue(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Oe(t,n)})}),function(s,i){switch(s){case sr:{li(t);return}case gn:return r===o&&i(n),Ze(t,i)}}}function Se(e,t=ec){return z(e,ot(t))}function ci(...e){return function(t,n){switch(t){case sr:return;case gn:return jg(...e.map(r=>Ze(r,n)))}}}var Et=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Et||{});const Lg={0:"debug",3:"error",1:"log",2:"warn"},$g=()=>typeof globalThis>"u"?window:globalThis,xn=qe(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=$g().VIRTUOSO_LOG_LEVEL)!=null?o:ct(e);r>=s&&console[Lg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Ln(e,t,n){return ui(e,t,n).callbackRef}function ui(e,t,n){const r=y.useRef(null);let o=i=>{};const s=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Fg(e,t,n,r,o,s,i,a,l){const u=y.useCallback(d=>{const f=Bg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?tc("column-gap",getComputedStyle(d).columnGap,o):tc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ui(u,n,l)}function Bg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Et.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function tc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}function nc(e,t,n){const r=y.useRef(null),o=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ui(o,!0,n),a=y.useCallback(()=>{o(i.current)},[o,i]);return y.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const St=qe(()=>{const e=Ue(),t=Ue(),n=Y(0),r=Ue(),o=Y(0),s=Ue(),i=Ue(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=Ue(),h=Ue(),p=Y(!1),w=Y(!1),v=Y(!1);return me(z(e,ie(({scrollTop:g})=>g)),t),me(z(e,ie(({scrollHeight:g})=>g)),i),me(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),jr={lvl:0};function rc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Qe(e){return e===jr}function Rr(e,t){if(!Qe(e))return t===e.k?e.v:t<e.k?Rr(e.l,t):Rr(e.r,t)}function Wt(e,t,n="k"){if(Qe(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Wt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Wt(e.l,t,n)}function jt(e,t,n){return Qe(e)?ic(t,n,1):t===e.k?pt(e,{k:t,v:n}):t<e.k?ac(pt(e,{l:jt(e.l,t,n)})):ac(pt(e,{r:jt(e.r,t,n)}))}function ar(){return jr}function yo(e,t,n){if(Qe(e))return[];const r=Wt(e,t)[0];return zg(fi(e,r,n))}function di(e,t){if(Qe(e))return jr;const{k:n,l:r,r:o}=e;if(t===n){if(Qe(r))return o;if(Qe(o))return r;{const[s,i]=sc(r);return So(pt(e,{k:s,l:oc(r),v:i}))}}else return t<n?So(pt(e,{l:di(r,t)})):So(pt(e,{r:di(o,t)}))}function $n(e){return Qe(e)?[]:[...$n(e.l),{k:e.k,v:e.v},...$n(e.r)]}function fi(e,t,n){if(Qe(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(fi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(fi(s,t,n))),a}function So(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(hi(t))return lc(pt(e,{lvl:n-1}));if(!Qe(t)&&!Qe(t.r))return pt(t.r,{l:pt(t,{r:t.r.l}),lvl:n,r:pt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(hi(e))return pi(pt(e,{lvl:n-1}));if(!Qe(r)&&!Qe(r.l)){const o=r.l,s=hi(o)?r.lvl-1:r.lvl;return pt(o,{l:pt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:pi(pt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function pt(e,t){return ic(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function oc(e){return Qe(e.r)?e.l:So(pt(e,{r:oc(e.r)}))}function hi(e){return Qe(e)||e.lvl>e.r.lvl}function sc(e){return Qe(e.r)?[e.k,e.v]:sc(e.r)}function ic(e,t,n,r=jr,o=jr){return{k:e,l:r,lvl:n,r:o,v:t}}function ac(e){return pi(lc(e))}function lc(e){const{l:t}=e;return!Qe(t)&&t.lvl===e.lvl?pt(t,{r:pt(e,{l:t.r})}):e}function pi(e){const{lvl:t,r:n}=e;return!Qe(n)&&!Qe(n.r)&&n.lvl===t&&n.r.lvl===t?pt(n,{l:pt(e,{r:n.l}),lvl:t+1}):e}function zg(e){return rc(e,({k:t,v:n})=>({index:t,value:n}))}function cc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Pr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const mi=qe(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function uc(e,t,n){return e[Co(e,t,n)]}function Co(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function Hg(e,t,n,r){const o=Co(e,t,r),s=Co(e,n,r,o);return e.slice(o,s+1)}function vn(e,t){return Math.round(e.getBoundingClientRect()[t])}function To(e){return!Qe(e.groupOffsetTree)}function gi({index:e},t){return t===e?0:t<e?-1:1}function Ug(){return{groupIndices:[],groupOffsetTree:ar(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ar()}}function Wg(e,t){let n=Qe(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Qe(e)){e=jt(e,0,s);continue}const a=yo(e,i-1,o+1);if(a.some(Jg(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=di(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=jt(e,o+1,h));u&&(e=jt(e,i,s))}return[e,n]}function Vg(e){return typeof e.groupIndex<"u"}function Kg({offset:e},t){return t===e?0:t<e?-1:1}function Or(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=uc(t,e,gi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function dc(e,t){if(!To(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function fc(e,t,n){if(Vg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=dc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function qg(e,t,n,r=0){return r>0&&(t=Math.max(t,uc(e,r,gi).offset)),rc(Hg(e,t,n,Kg),Xg)}function Gg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Et.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Qe(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>jt(jt(w,v,h),v+1,p),i)}else[i,a]=Wg(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=xi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>jt(h,p,Or(p,f,o)),ar()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Yg(e){return $n(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function hc(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function xi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Co(o,t-1,gi),a=o[l].offset;const u=Wt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Wt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of yo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Xg(e){return{index:e.index,value:e}}function Jg(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const Zg={offsetHeight:"height",offsetWidth:"width"},Zt=qe(([{log:e},{recalcInProgress:t}])=>{const n=Ue(),r=Ue(),o=wt(r,0),s=Ue(),i=Ue(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((T,k)=>vn(T,Zg[k])),h=Y(void 0),p=Y(0),w=Ug(),v=wt(z(n,Le(l,e,p),Jt(Gg,w),ot()),w),g=wt(z(l,ot(),Jt((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),ie(({prev:T})=>T)),[]);me(z(l,ke(T=>T.length>0),Le(v,p),ie(([T,k,I])=>{const A=T.reduce((j,P,L)=>jt(j,P,Or(P,k.offsetTree,I)||L),ar());return{...k,groupIndices:T,groupOffsetTree:A}})),v),me(z(r,Le(v),ke(([T,{lastIndex:k}])=>T<k),ie(([T,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:T}])),n),me(u,d);const x=wt(z(u,ie(T=>T===void 0)),!0);me(z(d,ke(T=>T!==void 0&&Qe(ct(v).sizeTree)),ie(T=>[{endIndex:0,size:T,startIndex:0}])),n);const b=_t(z(n,Le(v),Jt(({sizes:T},[k,I])=>({changed:I!==T,sizes:I}),{changed:!1,sizes:w}),ie(T=>T.changed)));Ze(z(a,Jt((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),ie(T=>T.diff)),T=>{const{groupIndices:k}=ct(v);if(T>0)Oe(t,!0),Oe(s,T+hc(T,k));else if(T<0){const I=ct(g);I.length>0&&(T-=hc(-T,I)),Oe(i,T)}}),Ze(z(a,Le(e)),([T,k])=>{T<0&&k("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Et.ERROR)});const C=_t(s);me(z(s,Le(v),ie(([T,k])=>{const I=k.groupIndices.length>0,A=[],j=k.lastSize;if(I){const P=Rr(k.sizeTree,0);let L=0,$=0;for(;L<T;){const M=k.groupIndices[$],K=k.groupIndices.length===$+1?1/0:k.groupIndices[$+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+K-1,size:j,startIndex:M+1}),$++,L+=K+1}const H=$n(k.sizeTree);return L!==T&&H.shift(),H.reduce((M,{k:K,v:W})=>{let G=M.ranges;return M.prevSize!==0&&(G=[...M.ranges,{endIndex:K+T-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:K+T,prevSize:W,ranges:G}},{prevIndex:T,prevSize:0,ranges:A}).ranges}return $n(k.sizeTree).reduce((P,{k:L,v:$})=>({prevIndex:L+T,prevSize:$,ranges:[...P.ranges,{endIndex:L+T-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=_t(z(i,Le(v,p),ie(([T,{offsetTree:k},I])=>{const A=-T;return Or(A,k,I)})));return me(z(i,Le(v,p),ie(([T,k,I])=>{if(k.groupIndices.length>0){if(Qe(k.sizeTree))return k;let A=ar();const j=ct(g);let P=0,L=0,$=0;for(;P<-T;){$=j[L];const H=j[L+1]-$-1;L++,P+=H+1}if(A=$n(k.sizeTree).reduce((H,{k:M,v:K})=>jt(H,Math.max(0,M+T),K),A),P!==-T){const H=Rr(k.sizeTree,$);A=jt(A,0,H);const M=Wt(k.sizeTree,-T+1)[1];A=jt(A,1,M)}return{...k,sizeTree:A,...xi(k.offsetTree,0,A,I)}}else{const A=$n(k.sizeTree).reduce((j,{k:P,v:L})=>jt(j,Math.max(0,P+T),L),ar());return{...k,sizeTree:A,...xi(k.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},rt(xn,mi),{singleton:!0});function Qg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const pc=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ue(),i=Ue(),a=_t(z(s,ie(Qg)));return me(z(a,ie(l=>l.totalCount)),n),me(z(a,ie(l=>l.groupIndices)),e),me(z(ft(o,t,r),ke(([l,u])=>To(u)),ie(([l,u,d])=>Wt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ot(),ie(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},rt(Zt,St)),wn=qe(([{log:e}])=>{const t=Y(!1),n=_t(z(t,ke(r=>r),ot()));return Ze(t,r=>{r&&ct(e)("props updated",{},Et.DEBUG)}),{didMount:n,propsReady:t}},rt(xn),{singleton:!0}),ex=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function mc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ex)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Mr=qe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ue(),w=Ue(),v=Y(0);let g=null,x=null,b=null;function C(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Oe(l,!1)}return me(z(p,Le(n,f,r,v,a,i,h),Le(e,s,o),ie(([[E,T,k,I,A,j,P,L],$,H,M])=>{const K=mc(E),{align:W,behavior:G,offset:B}=K,_=I-1,q=fc(K,T,_);let Q=Or(q,T.offsetTree,$)+j;W==="end"?(Q+=H+Wt(T.sizeTree,q)[1]-k+M,q===_&&(Q+=P)):W==="center"?Q+=(H+Wt(T.sizeTree,q)[1]-k+M)/2:Q-=A,B&&(Q+=B);const xe=ue=>{C(),ue?(L("retrying to scroll to",{location:E},Et.DEBUG),Oe(p,E)):(Oe(w,!0),L("list did not change, scroll successful",{},Et.DEBUG))};if(C(),G==="smooth"){let ue=!1;b=Ze(t,ne=>{ue=ue||ne}),g=Ut(d,()=>{xe(ue)})}else g=Ut(z(t,tx(150)),xe);return x=setTimeout(()=>{C()},1200),Oe(l,!0),L("scrolling from index to",{behavior:G,index:q,top:Q},Et.DEBUG),{behavior:G,top:Q}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},rt(Zt,St,xn),{singleton:!0});function tx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function vi(e,t){e==0?t():requestAnimationFrame(()=>{vi(e-1,t)})}function wi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Dr=qe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),u=Y(!0);return me(z(i,Le(l),ke(([d,f])=>!!f),Xt(!1)),a),me(z(i,Le(l),ke(([d,f])=>!!f),Xt(!1)),u),Ze(z(ft(t,i),Le(a,n,e,u),ke(([[,d],f,{sizeTree:h},p,w])=>d&&(!Qe(h)||ai(p))&&!f&&!w),Le(l)),([,d])=>{Ut(o,()=>{Oe(u,!0)}),vi(4,()=>{Ut(r,()=>{Oe(a,!0)}),Oe(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},rt(Zt,St,Mr,wn),{singleton:!0});function gc(e,t){return Math.abs(e-t)<1.01}const Lr="up",$r="down",nx="none",rx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},ox=0,Fr=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=Ue(),u=Ue(),d=Y(4),f=Y(ox),h=wt(z(ci(z(Se(o),Dn(1),Xt(!0)),z(Se(o),Dn(1),Xt(!1),Ql(100))),ot()),!1),p=wt(z(ci(z(n,Xt(!0)),z(n,Xt(!1),Ql(200))),ot()),!1);me(z(ft(Se(o),Se(f)),ie(([b,C])=>b<=C),ot()),a),me(z(a,cn(50)),u);const w=_t(z(ft(r,Se(s),Se(t),Se(e),Se(d)),Jt((b,[{scrollHeight:C,scrollTop:E},T,k,I,A])=>{const j=E+T-C>-A,P={scrollHeight:C,scrollTop:E,viewportHeight:T};if(j){let $,H;return E>b.state.scrollTop?($="SCROLLED_DOWN",H=b.state.scrollTop-E):($="SIZE_DECREASED",H=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:$,scrollTopDelta:H,state:P}}let L;return P.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":T<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:P}},rx),ot((b,C)=>b&&b.atBottom===C.atBottom))),v=wt(z(r,Jt((b,{scrollHeight:C,scrollTop:E,viewportHeight:T})=>{if(gc(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:E};{const k=C-(E+T)<1;return b.scrollTop!==E&&k?{changed:!0,jump:b.scrollTop-E,scrollHeight:C,scrollTop:E}:{changed:!0,jump:0,scrollHeight:C,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),ie(b=>b.jump)),0);me(z(w,ie(b=>b.atBottom)),i),me(z(i,cn(50)),l);const g=Y($r);me(z(r,ie(({scrollTop:b})=>b),ot(),Jt((b,C)=>ct(p)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?Lr:$r,prevScrollTop:C},{direction:$r,prevScrollTop:0}),ie(b=>b.direction)),g),me(z(r,cn(50),Xt(nx)),g);const x=Y(0);return me(z(h,ke(b=>!b),Xt(0)),x),me(z(o,cn(100),Le(h),ke(([b,C])=>!!C),Jt(([b,C],[E])=>[C,E],[0,0]),ie(([b,C])=>C-b)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},rt(St)),ko="top",Eo="bottom",xc="none";function vc(e,t,n){return typeof e=="number"?n===Lr&&t===ko||n===$r&&t===Eo?e:0:n===Lr?t===ko?e.main:e.reverse:t===Eo?e.main:e.reverse}function wc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const bi=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ue(),i=Y(0),a=Y(0),l=Y(0),u=wt(z(ft(Se(r),Se(o),Se(n),Se(s,Pr),Se(l),Se(i),Se(t),Se(e),Se(a)),ie(([d,f,h,[p,w],v,g,x,b,C])=>{const E=d-b,T=g+x,k=Math.max(h-E,0);let I=xc;const A=wc(C,ko),j=wc(C,Eo);return p-=b,p+=h+x,w+=h+x,w-=b,p>d+T-A&&(I=Lr),w<d-k+f+j&&(I=$r),I!==xc?[Math.max(E-h-vc(v,ko,I)-A,0),E-k-x+f+vc(v,Eo,I)+j]:null}),ke(d=>d!=null),ot(Pr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},rt(St),{singleton:!0});function sx(e,t,n){if(To(t)){const r=dc(e,t);return[{index:Wt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const yi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Io(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:yc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:yc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function bc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=wi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Io(u,[],a,o,n,r)}function yc(e,t,n){if(e.length===0)return[];if(!To(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=yo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Fn=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=Y([]),g=Y(0),x=Ue();me(s.topItemsIndexes,v);const b=wt(z(ft(p,w,Se(l,Pr),Se(o),Se(r),Se(u),d,Se(v),Se(t),Se(n),e),ke(([k,I,,A,,,,,,,j])=>{const P=j&&j.length!==A;return k&&!I&&!P}),ie(([,,[k,I],A,j,P,L,$,H,M,K])=>{const W=j,{offsetTree:G,sizeTree:B}=W,_=ct(g);if(A===0)return{...yi,totalCount:A};if(k===0&&I===0)return _===0?{...yi,totalCount:A}:bc(_,P,j,H,M,K||[]);if(Qe(B))return _>0?null:Io(sx(wi(P,A),W,K),[],A,M,W,H);const q=[];if($.length>0){const _e=$[0],Ce=$[$.length-1];let V=0;for(const D of yo(B,_e,Ce)){const J=D.value,U=Math.max(D.start,_e),he=Math.min(D.end,Ce);for(let ce=U;ce<=he;ce++)q.push({data:K==null?void 0:K[ce],index:ce,offset:V,size:J}),V+=J}}if(!L)return Io([],q,A,M,W,H);const Q=$.length>0?$[$.length-1]+1:0,xe=qg(G,k,I,Q);if(xe.length===0)return null;const ue=A-1,ne=bo([],_e=>{for(const Ce of xe){const V=Ce.value;let D=V.offset,J=Ce.start;const U=V.size;if(V.offset<k){J+=Math.floor((k-V.offset+M)/(U+M));const ce=J-Ce.start;D+=ce*U+ce*M}J<Q&&(D+=(Q-J)*U,J=Q);const he=Math.min(Ce.end,ue);for(let ce=J;ce<=he&&!(D>=I);ce++)_e.push({data:K==null?void 0:K[ce],index:ce,offset:D,size:U}),D+=U+M}});return Io(ne,q,A,M,W,H)}),ke(k=>k!==null),ot()),yi);me(z(e,ke(ai),ie(k=>k==null?void 0:k.length)),o),me(z(b,ie(k=>k.topListHeight)),f),me(f,a),me(z(b,ie(k=>[k.top,k.bottom])),i),me(z(b,ie(k=>k.items)),x);const C=_t(z(b,ke(({items:k})=>k.length>0),Le(o,e),ke(([{items:k},I])=>k[k.length-1].originalIndex===I-1),ie(([,k,I])=>[k-1,I]),ot(Pr),ie(([k])=>k))),E=_t(z(b,cn(200),ke(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),ie(({items:k})=>k[0].index),ot())),T=_t(z(b,ke(({items:k})=>k.length>0),ie(({items:k})=>{let I=0,A=k.length-1;for(;k[I].type==="group"&&I<A;)I++;for(;k[A].type==="group"&&A>I;)A--;return{endIndex:k[A].index,startIndex:k[I].index}}),ot(cc)));return{endReached:C,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:T,startReached:E,topItemsIndexes:v,...h}},rt(Zt,pc,bi,Dr,Mr,Fr,wn,mi),{singleton:!0}),Sc=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ue(),i=wt(z(ft(n,e,r,t,o),ie(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return me(Se(i),s),{totalListHeight:i,totalListHeightChanged:s}},rt(St,Fn),{singleton:!0}),ix=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=wt(z(ft(n,e,t),ke(([o])=>o),ie(([,o,s])=>Math.max(0,o-s)),cn(0),ot()),0);return{alignToBottom:n,paddingTopAddition:r}},rt(St,Sc),{singleton:!0}),Cc=qe(()=>({context:Y(null)})),ax=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,Tc=qe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ue();return me(z(d,Le(t,l,n,s,o,r,a),Le(e),ie(([[f,h,p,w,v,g,x,b],C])=>{const{align:E,behavior:T,calculateViewLocation:k=ax,done:I,...A}=f,j=fc(f,h,w-1),P=Or(j,h.offsetTree,C)+v+g,L=P+Wt(h.sizeTree,j)[1],$=b+g,H=b+p-x,M=k({itemBottom:L,itemTop:P,locationParams:{align:E,behavior:T,...A},viewportBottom:H,viewportTop:$});return M?I&&Ut(z(i,ke(K=>!K),Dn(ct(i)?1:2)),I):I&&I(),M}),ke(f=>f!==null)),u),{scrollIntoView:d}},rt(Zt,St,Mr,Fn,xn),{singleton:!0});function kc(e){return e?e==="smooth"?"smooth":"auto":!1}const lx=(e,t)=>typeof e=="function"?kc(e(t)):t&&kc(e),cx=qe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=Y(!1),v=Ue();let g=null;function x(T){Oe(i,{align:"end",behavior:T,index:"LAST"})}Ze(z(ft(z(Se(t),Dn(1)),l),Le(Se(w),s,a,f),ie(([[T,k],I,A,j,P])=>{let L=k&&j,$="auto";return L&&($=lx(I,A||P),L=L&&!!$),{followOutputBehavior:$,shouldFollow:L,totalCount:T}}),ke(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:k})=>{g&&(g(),g=null),ct(n)?requestAnimationFrame(()=>{ct(d)("following output to ",{totalCount:k},Et.DEBUG),x(T)}):g=Ut(e,()=>{ct(d)("following output to ",{totalCount:k},Et.DEBUG),x(T),g=null})});function b(T){const k=Ut(o,I=>{T&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(ct(d)("scrolling to bottom due to increased size",{},Et.DEBUG),x("auto"))});setTimeout(k,100)}Ze(z(ft(Se(w),t,u),ke(([T,,k])=>T&&k),Jt(({value:T},[,k])=>({refreshed:T===k,value:k}),{refreshed:!1,value:0}),ke(({refreshed:T})=>T),Le(w,t)),([,T])=>{ct(a)&&b(T!==!1)}),Ze(v,()=>{b(ct(w)!==!1)}),Ze(ft(Se(w),o),([T,k])=>{T&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=Y(null),E=Ue();return me(ci(z(Se(r),ie(T=>{var k;return(k=T==null?void 0:T.length)!=null?k:0})),z(Se(t))),E),Ze(z(ft(z(E,Dn(1)),l),Le(Se(C),a,f,h),ie(([[T,k],I,A,j,P])=>k&&A&&(I==null?void 0:I({context:P,totalCount:T,scrollingInProgress:j}))),ke(T=>!!T),cn(0)),T=>{g&&(g(),g=null),ct(n)?requestAnimationFrame(()=>{ct(d)("scrolling into view",{}),Oe(p,T)}):g=Ut(e,()=>{ct(d)("scrolling into view",{}),Oe(p,T),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:C}},rt(Zt,Fr,Mr,Dr,wn,xn,St,Cc,Tc)),ux=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(me(z(a,Le(s),ke(([,l])=>l!==0),Le(o,r,t,n,e),ie(([[,l],u,d,f,h,p=[]])=>bc(l,u,d,f,h,p))),i),{}),rt(Zt,Dr,Fn,wn),{singleton:!0}),dx=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Ze(z(e,Le(r),ke(([,o])=>o!==0),ie(([,o])=>({top:o}))),o=>{Ut(z(n,Dn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Oe(t,o)})})}),{initialScrollTop:r}},rt(wn,St,Fn),{singleton:!0}),Ec=qe(([{scrollVelocity:e}])=>{const t=Y(!1),n=Ue(),r=Y(!1);return me(z(e,Le(r,t,n),ke(([o,s])=>!!s),ie(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),ot()),t),Ze(z(ft(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},rt(Fr),{singleton:!0}),Si=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ue(),r=Ue(),o=Ue(),s=Y(!1),i=Y(void 0);return me(z(ft(n,r),ie(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),me(z(t,Le(r),ie(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},rt(St)),fx=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ue(),d=Y(void 0),f=Y(null),h=Y(null);return me(a,f),me(l,h),Ze(z(u,Le(t,r,i,f,h,n)),([p,w,v,g,x,b,C])=>{const E=Yg(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=C,p({ranges:E,scrollTop:v})}),me(z(d,ke(ai),ie(hx)),o),me(z(s,Le(d),ke(([,p])=>p!==void 0),ot(),ie(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},rt(Zt,St,Dr,wn,Si));function hx(e){return{align:"start",index:0,offset:e.scrollTop}}const px=qe(([{topItemsIndexes:e}])=>{const t=Y(0);return me(z(t,ke(n=>n>=0),ie(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},rt(Fn));function Ic(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const mx=Ic(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),gx=qe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=_t(z(l,Le(i),Jt(([,x,b,C],[{bottom:E,items:T,offsetBottom:k,totalCount:I},A])=>{const j=E+k;let P=0;return b===I&&x.length>0&&T.length>0&&(T[0].originalIndex===0&&x[0].originalIndex===0||(P=j-C,P!==0&&(P+=A))),[P,T,I,j]},[0,[],0,0]),ke(([x])=>x!==0),Le(r,a,n,o,p,w),ke(([,x,b,C,,,E])=>!E&&!C&&x!==0&&b===Lr),ie(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Et.DEBUG),x))));function g(x){x>0?(Oe(t,{behavior:"auto",top:-x}),Oe(e,0)):(Oe(e,0),Oe(t,{behavior:"auto",top:-x}))}return Ze(z(v,Le(e,s)),([x,b,C])=>{C&&mx()?Oe(e,b-x):g(-x)}),Ze(z(ft(wt(s,!1),e,w),ke(([x,b,C])=>!x&&!C&&b!==0),ie(([x,b])=>b),cn(1)),g),me(z(f,ie(x=>({top:-x}))),t),Ze(z(u,Le(h,d),ie(([x,{groupIndices:b,lastSize:C,sizeTree:E},T])=>{function k(I){return I*(C+T)}if(b.length===0)return k(x);{let I=0;const A=Rr(E,0);let j=0,P=0;for(;j<x;){j++,I+=A;let L=b.length===P+1?1/0:b[P+1]-b[P]-1;j+L>x&&(I-=A,L=x-j+1),j+=L,I+=k(L),P++}return I}})),x=>{Oe(e,x),requestAnimationFrame(()=>{Oe(t,{top:x}),requestAnimationFrame(()=>{Oe(e,0),Oe(w,!1)})})}),{deviation:e}},rt(St,Fr,Fn,Zt,xn,mi)),xx=qe(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),rt(bi,ux,wn,Ec,Sc,dx,ix,Si,Tc,xn,Cc)),Nc=qe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:C,...E},{scrollToIndex:T},k,{topItemCount:I},{groupCounts:A},j])=>(me(E.rangeChanged,j.scrollSeekRangeChanged),me(z(j.windowViewportRect,ie(P=>P.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:T,statefulTotalCount:u,trackItemSizes:f,...E,...j,...v,sizes:l,...g}),rt(Zt,Dr,St,fx,cx,Fn,Mr,gx,px,pc,xx));function vx(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const No=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Ac(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=y.createContext({});function l(g,x){g.propsReady&&Oe(g.propsReady,!1);for(const b of r){const C=g[t.required[b]];Oe(C,x[b])}for(const b of o)if(b in x){const C=g[t.optional[b]];Oe(C,x[b])}g.propsReady&&Oe(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=C=>{const E=g[t.methods[b]];Oe(E,C)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=Og(g[t.events[b]]),x),{})}const f=y.forwardRef((g,x)=>{const{children:b,...C}=g,[E]=y.useState(()=>bo(Dg(e),I=>{l(I,C)})),[T]=y.useState(Zl(d,E));No(()=>{for(const I of i)I in C&&Ze(T[I],C[I]);return()=>{Object.values(T).map(li)}},[C,T,E]),No(()=>{l(E,C)}),y.useImperativeHandle(x,Xl(u(E)));const k=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(k,{...vx([...r,...o,...i],C),children:b}):b})}),h=g=>{const x=y.useContext(a);return y.useCallback(b=>{Oe(x[g],b)},[x,g])},p=g=>{const x=y.useContext(a)[g],b=y.useCallback(C=>Ze(x,C),[x]);return y.useSyncExternalStore(b,()=>ct(x),()=>ct(x))},w=g=>{const x=y.useContext(a)[g],[b,C]=y.useState(Zl(ct,x));return No(()=>Ze(x,E=>{E!==b&&C(Xl(E))}),[x,b]),b},v=y.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const b=y.useContext(a)[g];No(()=>Ze(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const _c=y.createContext(void 0),jc=y.createContext(void 0),Rc=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Ci(e){return"self"in e}function wx(e){return"body"in e}function Pc(e,t,n,r=ir,o,s){const i=y.useRef(null),a=y.useRef(null),l=y.useRef(null),u=y.useCallback(h=>{let p,w,v;const g=h.target;if(wx(g)||Ci(g)){const b=Ci(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Ps.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);y.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;Ci(p)?(g=Math.max(vn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=vn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),gc(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ti="-webkit-sticky",Oc="sticky",ki=Ic(()=>{if(typeof document>"u")return Oc;const e=document.createElement("div");return e.style.position=Ti,e.style.position===Ti?Ti:Oc});function Ei(e){return e}const bx=qe(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(Ei),o=Y("div"),s=Y(ir),i=(a,l=null)=>wt(z(n,ie(u=>u[a]),ot()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),yx=qe(([e,t])=>({...e,...t}),rt(Nc,bx)),Sx=({height:e})=>c.jsx("div",{style:{height:e}}),Cx={overflowAnchor:"none",position:ki(),zIndex:1},Mc={overflowAnchor:"none"},Tx={...Mc,display:"inline-block",height:"100%"},Dc=y.memo(function({showTopList:e=!1}){const t=je("listState"),n=Dt("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=Dt("windowScrollContainerState"),i=Dt("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),u=je("context"),d=je("groupContent"),f=je("trackItemSizes"),h=je("itemSize"),p=je("log"),w=Dt("gap"),v=je("horizontalDirection"),{callbackRef:g}=Fg(n,h,f,e?ir:a,p,w,o,v,je("skipAnimationFrameInResizeObserver")),[x,b]=y.useState(0);Ii("deviation",M=>{x!==M&&b(M)});const C=je("EmptyPlaceholder"),E=je("ScrollSeekPlaceholder")||Sx,T=je("ListComponent"),k=je("ItemComponent"),I=je("GroupComponent"),A=je("computeItemKey"),j=je("isSeeking"),P=je("groupIndices").length>0,L=je("alignToBottom"),$=je("initialItemFinalLocationReached"),H=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...$?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?c.jsx(C,{...bt(C,u)}):c.jsx(T,{...bt(T,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:H,children:(e?t.topItems:t.items).map(M=>{const K=M.originalIndex,W=A(K+t.firstItemIndex,M.data,u);return j?y.createElement(E,{...bt(E,u),height:M.size,index:M.index,key:W,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?y.createElement(I,{...bt(I,u),"data-index":K,"data-item-index":M.index,"data-known-size":M.size,key:W,style:Cx},d(M.index,u)):y.createElement(k,{...bt(k,u),...Nx(k,M.data),"data-index":K,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:W,style:v?Tx:Mc},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),kx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Ex={outline:"none",overflowX:"auto",position:"relative"},Ao=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Ix={position:ki(),top:0,width:"100%",zIndex:1};function bt(e,t){if(typeof e!="string")return{context:t}}function Nx(e,t){return{item:typeof e=="string"?void 0:t}}const Ax=y.memo(function(){const e=je("HeaderComponent"),t=Dt("headerHeight"),n=je("HeaderFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null}),_x=y.memo(function(){const e=je("FooterComponent"),t=Dt("footerHeight"),n=je("HeaderFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null});function Lc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Pc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Ex:kx,...o},tabIndex:0,...i,...bt(l,s),children:r})})}function $c({useEmitter:e,useEmitterValue:t,usePublisher:n}){return y.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=y.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Pc(a,u,l,w,h);return Rc(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...bt(l,s),children:r})})}const jx=({children:e})=>{const t=y.useContext(_c),n=Dt("viewportHeight"),r=Dt("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=y.useMemo(()=>Jl(n,l=>vn(l,s?"width":"height")),[n,s]),a=Ln(i,!0,je("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Ao(o),children:e})},Rx=({children:e})=>{const t=y.useContext(_c),n=Dt("windowViewportRect"),r=Dt("fixedItemHeight"),o=je("customScrollParent"),s=nc(n,o,je("skipAnimationFrameInResizeObserver")),i=je("alignToBottom");return y.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Ao(i),children:e})},Px=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...Ix,marginTop:`${n}px`},o=je("context");return c.jsx(t,{style:r,...bt(t,o),children:e})},Ox=y.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return c.jsxs(r||t?Lx:Dx,{...e,context:o,children:[n&&c.jsx(Px,{children:c.jsx(Dc,{showTopList:!0})}),c.jsxs(r||t?Rx:jx,{children:[c.jsx(Ax,{}),c.jsx(Dc,{}),c.jsx(_x,{})]})]})}),{Component:Mx,useEmitter:Ii,useEmitterValue:je,usePublisher:Dt}=Ac(yx,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},Ox),Dx=Lc({useEmitter:Ii,useEmitterValue:je,usePublisher:Dt}),Lx=$c({useEmitter:Ii,useEmitterValue:je,usePublisher:Dt}),$x=Mx;rt(Nc,qe(()=>{const e=Y(u=>c.jsxs("td",{children:["Item $",u]})),t=Y(null),n=Y(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=Y(null),o=Y(null),s=Y({}),i=Y(Ei),a=Y(ir),l=(u,d=null)=>wt(z(s,ie(f=>f[u]),ot()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),ki();const Fc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Fx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Bc,floor:_o,max:Br,min:Ni,round:zc}=Math;function Hc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Bx(e){return{...Fx,items:e}}function jo(e,t){return e&&e.width===t.width&&e.height===t.height}function zx(e,t){return e&&e.column===t.column&&e.row===t.row}const Hx=qe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:E},T])=>{const k=Y(0),I=Y(0),A=Y(Fc),j=Y({height:0,width:0}),P=Y({height:0,width:0}),L=Ue(),$=Ue(),H=Y(0),M=Y(null),K=Y({column:0,row:0}),W=Ue(),G=Ue(),B=Y(!1),_=Y(0),q=Y(!0),Q=Y(!1),xe=Y(!1);Ze(z(w,Le(_),ke(([D,J])=>!!J)),()=>{Oe(q,!1)}),Ze(z(ft(w,q,P,j,_,Q),ke(([D,J,U,he,,ce])=>D&&!J&&U.height!==0&&he.height!==0&&!ce)),([,,,,D])=>{Oe(Q,!0),vi(1,()=>{Oe(L,D)}),Ut(z(u),()=>{Oe(t,[0,0]),Oe(q,!0)})}),me(z(G,ke(D=>D!=null&&D.scrollTop>0),Xt(0)),I),Ze(z(w,Le(G),ke(([,D])=>D!=null)),([,D])=>{D&&(Oe(j,D.viewport),Oe(P,D.item),Oe(K,D.gap),D.scrollTop>0&&(Oe(B,!0),Ut(z(u,Dn(1)),J=>{Oe(B,!1)}),Oe(l,{top:D.scrollTop})))}),me(z(j,ie(({height:D})=>D)),f),me(z(ft(Se(j,jo),Se(P,jo),Se(K,(D,J)=>D&&D.column===J.column&&D.row===J.row),Se(u)),ie(([D,J,U,he])=>({gap:U,item:J,scrollTop:he,viewport:D}))),W),me(z(ft(Se(k),r,Se(K,zx),Se(P,jo),Se(j,jo),Se(M),Se(I),Se(B),Se(q),Se(_)),ke(([,,,,,,,D])=>!D),ie(([D,[J,U],he,ce,ze,Ye,Ge,,Te,Me])=>{const{column:tt,row:He}=he,{height:Xe,width:ht}=ce,{width:re}=ze;if(Ge===0&&(D===0||re===0))return Fc;if(ht===0){const It=wi(Me,D),fn=It+Math.max(Ge-1,0);return Bx(Hc(It,fn,Ye))}const te=Uc(re,ht,tt);let ge,Ee;Te?J===0&&U===0&&Ge>0?(ge=0,Ee=Ge-1):(ge=te*_o((J+He)/(Xe+He)),Ee=te*Bc((U+He)/(Xe+He))-1,Ee=Ni(D-1,Br(Ee,te-1)),ge=Ni(Ee,Br(0,ge))):(ge=0,Ee=-1);const ye=Hc(ge,Ee,Ye),{bottom:Re,top:Je}=Wc(ze,he,ce,ye),We=Bc(D/te),it=We*Xe+(We-1)*He-Re;return{bottom:Re,itemHeight:Xe,items:ye,itemWidth:ht,offsetBottom:it,offsetTop:Je,top:Je}})),A),me(z(M,ke(D=>D!==null),ie(D=>D.length)),k),me(z(ft(j,P,A,K),ke(([D,J,{items:U}])=>U.length>0&&J.height!==0&&D.height!==0),ie(([D,J,{items:U},he])=>{const{bottom:ce,top:ze}=Wc(D,he,J,U);return[ze,ce]}),ot(Pr)),t);const ue=Y(!1);me(z(u,Le(ue),ie(([D,J])=>J||D!==0)),ue);const ne=_t(z(ft(A,k),ke(([{items:D}])=>D.length>0),Le(ue),ke(([[D,J],U])=>{const he=D.items[D.items.length-1].index===J-1;return(U||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===J)&&he}),ie(([[,D]])=>D-1),ot())),_e=_t(z(Se(A),ke(({items:D})=>D.length>0&&D[0].index===0),Xt(0),ot())),Ce=_t(z(Se(A),Le(B),ke(([{items:D},J])=>D.length>0&&!J),ie(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ot(cc),cn(0)));me(Ce,p.scrollSeekRangeChanged),me(z(L,Le(j,P,k,K),ie(([D,J,U,he,ce])=>{const ze=mc(D),{align:Ye,behavior:Ge,offset:Te}=ze;let Me=ze.index;Me==="LAST"&&(Me=he-1),Me=Br(0,Me,Ni(he-1,Me));let tt=Ai(J,ce,U,Me);return Ye==="end"?tt=zc(tt-J.height+U.height):Ye==="center"&&(tt=zc(tt-J.height/2+U.height/2)),Te&&(tt+=Te),{behavior:Ge,top:tt}})),l);const V=wt(z(A,ie(D=>D.offsetBottom+D.bottom)),0);return me(z(E,ie(D=>({height:D.visibleHeight,width:D.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:H,footerHeight:o,gap:K,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:P,overscan:n,restoreStateFrom:G,scrollBy:i,scrollContainerState:a,scrollHeight:$,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:E,...p,gridState:A,horizontalDirection:xe,initialTopMostItemIndex:_,totalListHeight:V,...h,endReached:ne,propsReady:v,rangeChanged:Ce,startReached:_e,stateChanged:W,stateRestoreInProgress:B,...T}},rt(bi,St,Fr,Ec,wn,Si,xn));function Uc(e,t,n){return Br(1,_o((e+n)/(_o(t)+n)))}function Wc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ai(e,t,n,r[0].index);return{bottom:Ai(e,t,n,r[r.length-1].index)+o,top:s}}function Ai(e,t,n,r){const o=Uc(e.width,n.width,t.column),s=_o(r/o),i=s*n.height+Br(0,s-1)*t.row;return i>0?i+t.row:i}const Ux=qe(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(Ei),i=Y("div"),a=Y(ir),l=(f,h=null)=>wt(z(t,ie(p=>p[f]),ot()),h),u=Y(!1),d=Y(!1);return me(Se(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Wx=qe(([e,t])=>({...e,...t}),rt(Hx,Ux)),Vx=y.memo(function(){const e=st("gridState"),t=st("listClassName"),n=st("itemClassName"),r=st("itemContent"),o=st("computeItemKey"),s=st("isSeeking"),i=Lt("scrollHeight"),a=st("ItemComponent"),l=st("ListComponent"),u=st("ScrollSeekPlaceholder"),d=st("context"),f=Lt("itemDimensions"),h=Lt("gap"),p=st("log"),w=st("stateRestoreInProgress"),v=Lt("reportReadyState"),g=Ln(y.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const C=x.firstChild;if(C){const{height:E,width:T}=C.getBoundingClientRect();f({height:E,width:T})}h({column:Kc("column-gap",getComputedStyle(x).columnGap,p),row:Kc("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Rc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...bt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?c.jsx(u,{...bt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):y.createElement(a,{...bt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),Kx=y.memo(function(){const e=st("HeaderComponent"),t=Lt("headerHeight"),n=st("headerFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,!1),o=st("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null}),qx=y.memo(function(){const e=st("FooterComponent"),t=Lt("footerHeight"),n=st("headerFooterTag"),r=Ln(y.useMemo(()=>s=>{t(vn(s,"height"))},[t]),!0,!1),o=st("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...bt(e,o)})}):null}),Gx=({children:e})=>{const t=y.useContext(jc),n=Lt("itemDimensions"),r=Lt("viewportDimensions"),o=Ln(y.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Ao(!1),children:e})},Yx=({children:e})=>{const t=y.useContext(jc),n=Lt("windowViewportRect"),r=Lt("itemDimensions"),o=st("customScrollParent"),s=nc(n,o,!1);return y.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Ao(!1),children:e})},Xx=y.memo(function({...e}){const t=st("useWindowScroll"),n=st("customScrollParent"),r=n||t?Zx:Jx,o=n||t?Yx:Gx,s=st("context");return c.jsx(r,{...e,...bt(r,s),children:c.jsxs(o,{children:[c.jsx(Kx,{}),c.jsx(Vx,{}),c.jsx(qx,{})]})})}),{useEmitter:Vc,useEmitterValue:st,usePublisher:Lt}=Ac(Wx,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Xx),Jx=Lc({useEmitter:Vc,useEmitterValue:st,usePublisher:Lt}),Zx=$c({useEmitter:Vc,useEmitterValue:st,usePublisher:Lt});function Kc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}const Qx=no.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function _i({className:e,variant:t,...n}){return c.jsx("div",{className:ee(Qx({variant:t}),e),...n})}function le(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function ev(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Qt(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,tv(o,...t)]}function tv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var mt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},nv=m[" useInsertionEffect ".trim().toString()]||mt;function Bn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=rv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=ov(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function rv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return nv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ov(e){return typeof e=="function"}function qc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ji(...e){return t=>{let n=!1;const r=e.map(o=>{const s=qc(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():qc(e[o],null)}}}}function Be(...e){return m.useCallback(ji(...e),e)}var sv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ie=sv.reduce((e,t)=>{const n=Rn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Gc(e,t){e&&ro.flushSync(()=>e.dispatchEvent(t))}function iv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Rt=e=>{const{present:t,children:n}=e,r=av(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Be(r.ref,lv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Rt.displayName="Presence";function av(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=iv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Ro(r.current);s.current=a==="mounted"?u:"none"},[a]),mt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Ro(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),mt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=Ro(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Ro(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Ro(e){return(e==null?void 0:e.animationName)||"none"}function lv(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var cv=m[" useId ".trim().toString()]||(()=>{}),uv=0;function en(e){const[t,n]=m.useState(cv());return mt(()=>{n(r=>r??String(uv++))},[e]),e||(t?`radix-${t}`:"")}var Po="Collapsible",[dv,GC]=Qt(Po),[fv,Ri]=dv(Po),Yc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Bn({prop:r,defaultProp:o??!1,onChange:i,caller:Po});return c.jsx(fv,{scope:n,disabled:s,contentId:en(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ie.div,{"data-state":Oi(l),"data-disabled":s?"":void 0,...a,ref:t})})});Yc.displayName=Po;var Xc="CollapsibleTrigger",Jc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Ri(Xc,n);return c.jsx(Ie.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Oi(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:le(e.onClick,o.onOpenToggle)})});Jc.displayName=Xc;var Pi="CollapsibleContent",hv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ri(Pi,e.__scopeCollapsible);return c.jsx(Rt,{present:n||o.open,children:({present:s})=>c.jsx(pv,{...r,ref:t,present:s})})});hv.displayName=Pi;var pv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Ri(Pi,n),[a,l]=m.useState(r),u=m.useRef(null),d=Be(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),mt(()=>{const b=u.current;if(b){x.current=x.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const C=b.getBoundingClientRect();f.current=C.height,p.current=C.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Ie.div,{"data-state":Oi(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function Oi(e){return e?"open":"closed"}var mv=Yc;const Zc=mv,Qc=Jc,zr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));zr.displayName="Card";const Hr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex flex-col space-y-1.5 p-6",e),...t}));Hr.displayName="CardHeader";const Ur=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:ee("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ur.displayName="CardTitle";const eu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));eu.displayName="CardDescription";const Oo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("p-6 pt-0",e),...t}));Oo.displayName="CardContent";const tu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex items-center p-6 pt-0",e),...t}));tu.displayName="CardFooter";function nu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let zn=nu();function gv(e){zn=e}const ru=/[&<>"']/,xv=new RegExp(ru.source,"g"),ou=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,vv=new RegExp(ou.source,"g"),wv={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},su=e=>wv[e];function yt(e,t){if(t){if(ru.test(e))return e.replace(xv,su)}else if(ou.test(e))return e.replace(vv,su);return e}const bv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function iu(e){return e.replace(bv,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const yv=/(^|[^\[])\^/g;function et(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(yv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Sv=/[^\w:]/g,Cv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function au(e,t,n){if(e){let r;try{r=decodeURIComponent(iu(n)).replace(Sv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Cv.test(n)&&(n=Iv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Mo={},Tv=/^[^:]+:\/*[^/]*$/,kv=/^([^:]+:)[\s\S]*$/,Ev=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Iv(e,t){Mo[" "+e]||(Tv.test(e)?Mo[" "+e]=e+"/":Mo[" "+e]=Lo(e,"/",!0)),e=Mo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(kv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Ev,"$1")+t:e+t}const Do={exec:function(){}};function lu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Lo(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function Nv(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function Av(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function cu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function uu(e,t,n,r){const o=t.href,s=t.title?yt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:yt(i)}}function _v(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
34
34
  `).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
35
35
  `)}class Mi{constructor(t){this.options=t||zn}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Lo(r,`
36
36
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=_v(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=Lo(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,w,v=n[1].trim();const g=v.length>1,x={type:"list",raw:"",ordered:g,start:g?+v.slice(0,-1):"",loose:!1,items:[]};v=g?`\\d{1,9}\\${v.slice(-1)}`:`\\${v}`,this.options.pedantic&&(v=g?v:"[*+-]");const b=new RegExp(`^( {0,3}${v})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "4.1.24",
3
+ "version": "4.1.25",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",