teodor-new-chat-ui 3.0.196 → 3.0.197

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
@@ -2761,12 +2761,7 @@ function Lg(e, t) {
2761
2761
  }
2762
2762
  case "user_message": {
2763
2763
  const o = t.payload.message;
2764
- if (e.assemblingId) {
2765
- const s = e.messages.findIndex((i) => i.id === e.assemblingId);
2766
- if (s !== -1)
2767
- return { ...e, messages: [...e.messages.slice(0, s), o, ...e.messages.slice(s)] };
2768
- }
2769
- return { ...e, messages: [...e.messages, o] };
2764
+ return e.messages.some((s) => s.id === o.id) ? e : { ...e, messages: [...e.messages, o] };
2770
2765
  }
2771
2766
  case "event":
2772
2767
  return pl(e, t.payload.ev);
@@ -2803,7 +2798,10 @@ function $g(e = []) {
2803
2798
  function pl(e, t) {
2804
2799
  var n;
2805
2800
  if (t.type === "message_start" && t.role === "assistant") {
2806
- const r = t.id, o = Ug(t.model), s = {
2801
+ const r = t.id, o = Ug(t.model);
2802
+ if (e.messages.some((a) => a.id === r))
2803
+ return { ...e, assemblingId: r };
2804
+ const i = {
2807
2805
  id: r,
2808
2806
  role: "assistant",
2809
2807
  name: o || void 0,
@@ -2811,7 +2809,7 @@ function pl(e, t) {
2811
2809
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2812
2810
  content: []
2813
2811
  };
2814
- return { ...e, assemblingId: r, messages: [...e.messages, s] };
2812
+ return { ...e, assemblingId: r, messages: [...e.messages, i] };
2815
2813
  }
2816
2814
  if (t.type === "message_delta") {
2817
2815
  const r = e.assemblingId ?? Us(e.messages);
@@ -2831,7 +2829,13 @@ function pl(e, t) {
2831
2829
  return e;
2832
2830
  }
2833
2831
  if (t.type === "tool_start") {
2834
- const r = `tool-${t.id}`, o = { type: "tool_call", id: t.id, name: t.name, args: t.args }, s = {
2832
+ const r = `tool-${t.id}`, o = { type: "tool_call", id: t.id, name: t.name, args: t.args };
2833
+ if (e.messages.find((a) => a.id === r))
2834
+ return {
2835
+ ...e,
2836
+ toolIndex: { ...e.toolIndex, [t.id]: r }
2837
+ };
2838
+ const i = {
2835
2839
  id: r,
2836
2840
  role: "tool",
2837
2841
  name: t.name,
@@ -2840,7 +2844,7 @@ function pl(e, t) {
2840
2844
  };
2841
2845
  return {
2842
2846
  ...e,
2843
- messages: [...e.messages, s],
2847
+ messages: [...e.messages, i],
2844
2848
  toolIndex: { ...e.toolIndex, [t.id]: r }
2845
2849
  };
2846
2850
  }
package/dist/index.umd.js CHANGED
@@ -35,7 +35,7 @@ React keys must be passed directly to JSX without using spread:
35
35
  `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Dn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&mo.assertOptions(r,{silentJSONParsing:en.transitional(en.boolean),forcedJSONParsing:en.transitional(en.boolean),clarifyTimeoutError:en.transitional(en.boolean)},!1),o!=null&&(_.isFunction(o)?n.paramsSerializer={serialize:o}:mo.assertOptions(o,{encode:en.function,serialize:en.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),mo.assertOptions(n,{baseUrl:en.spelling("baseURL"),withXsrfToken:en.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&_.merge(s.common,s[n.method]);s&&_.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=At.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(b){typeof b.runWhen=="function"&&b.runWhen(n)===!1||(c=c&&b.synchronous,a.unshift(b.fulfilled,b.rejected))});const u=[];this.interceptors.response.forEach(function(b){u.push(b.fulfilled,b.rejected)});let d,f=0,h;if(!c){const w=[wl.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 g=n;for(;f<h;){const w=a[f++],b=a[f++];try{g=w(g)}catch(m){b.call(this,m);break}}try{d=wl.call(this,g)}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=Dn(this.defaults,t);const n=cl(t.baseURL,t.url,t.allowAbsoluteUrls);return el(n,t.params,t.paramsSerializer)}};_.forEach(["delete","get","head","options"],function(t){Ln.prototype[t]=function(n,r){return this.request(Dn(r||{},{method:t,url:n,data:(r||{}).data}))}}),_.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Dn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Ln.prototype[t]=n(),Ln.prototype[t+"Form"]=n(!0)});let Dm=class fp{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 ir(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 fp(function(o){t=o}),cancel:t}}};function Lm(e){return function(n){return e.apply(null,n)}}function $m(e){return _.isObject(e)&&e.isAxiosError===!0}const qs={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(qs).forEach(([e,t])=>{qs[t]=e});function Cl(e){const t=new Ln(e),n=Fa(Ln.prototype.request,t);return _.extend(n,Ln.prototype,t,{allOwnKeys:!0}),_.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(Dn(e,o))},n}const ot=Cl(Ar);ot.Axios=Ln,ot.CanceledError=ir,ot.CancelToken=Dm,ot.isCancel=sl,ot.VERSION=yl,ot.toFormData=co,ot.AxiosError=Ie,ot.Cancel=ot.CanceledError,ot.all=function(t){return Promise.all(t)},ot.spread=Lm,ot.isAxiosError=$m,ot.mergeConfig=Dn,ot.AxiosHeaders=At,ot.formToJSON=e=>rl(_.isHTMLForm(e)?new FormData(e):e),ot.getAdapter=bl.getAdapter,ot.HttpStatusCode=qs,ot.default=ot;const{Axios:iC,AxiosError:aC,CanceledError:lC,isCancel:cC,CancelToken:uC,VERSION:dC,all:fC,Cancel:hC,isAxiosError:pC,spread:mC,toFormData:gC,AxiosHeaders:xC,HttpStatusCode:vC,formToJSON:bC,getAdapter:wC,mergeConfig:yC}=ot,kl=typeof window<"u"?window.__API_BASE_URL__:void 0,Tl=kl?kl.replace(/\/+$/,""):void 0;let go=null;const Ks=new Set;function El(){return go}function Gs(e){go=e,Ks.forEach(t=>t(e))}function Il(e){return Ks.add(e),()=>Ks.delete(e)}const Ft=ot.create({...Tl?{baseURL:Tl}:{},timeout:3e4,withCredentials:!0});Ft.interceptors.request.use(e=>(go&&(e.headers.Authorization=`Bearer ${go}`),e)),Ft.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Rt(e,t){return Ft.defaults.baseURL?(await Ft.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ys(e,t,n){return Ft.defaults.baseURL?(await Ft.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nl(e,t,n){return Ft.defaults.baseURL?(await Ft.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t){return Ft.defaults.baseURL?(await Ft.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Pt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class jl{get baseUrl(){const t=Ft.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(Ft.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Gs(t.authToken)}getAuthToken(){return El()}setAuthToken(t){Gs(t)}onTokenChange(t){return Il(t)}async listThreads(){const t=await Rt("/chat/threads"),n=Pt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ys("/chat/threads",t?{title:t}:void 0);return Pt(r)}async updateThread(t,n){const r=await Nl(`/chat/threads/${t}`,{title:n});return Pt(r)}async deleteThread(t){const n=await Al(`/chat/threads/${t}`);return Pt(n)}async threadInfo(t){const n=await Rt(`/chat/threads/${t}/info`);return Pt(n)}async listAgents(){const t=await Rt("/chat/agents"),n=Pt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Rt(`/chat/agents/${t}`);return Pt(n)}async getAgentSchema(t){const n=await Rt(`/chat/agents/${t}/schema`);return Pt(n)}async getMessages(t){const n=await Rt(`/chat/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 Pt(n)}async getState(t){const n=await Rt(`/chat/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Pt(n)}async getStateHistory(t){const n=await Rt(`/chat/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Pt(n)}async listCheckpoints(t){const n=await Rt(`/chat/threads/${t}/checkpoints`,{params:{thread_id:t}});return Pt(n)}async resume(t){const n=await Ys("/chat/runs/resume",{thread_id:t.threadId,value:t.value});return Pt(n)}}const wn=new jl;function _l(e={}){const t=e.baseUrl??"/api/chat",n=e.streamPath??"/runs/stream",[r,o]=S.useState(e.token??null),s=S.useRef(e.headers??{}),[i,a]=S.useState(!1),[c,u]=S.useState(null),[d,f]=S.useState(""),[h,g]=S.useState(null),[w,b]=S.useState(0),[m,x]=S.useState(!1),v=S.useRef(null),y=S.useRef(!0),E=S.useRef(0),C=S.useCallback(A=>{o(A)},[]),k=S.useCallback(()=>{var A;(A=v.current)==null||A.abort(),v.current=null,a(!1),x(!1)},[]),I=S.useCallback(()=>{f(""),g(null),u(null)},[]),N=S.useCallback((A,R,j)=>{v.current&&(v.current.abort(),v.current=null),a(!0),u(null),e.autoAppendAssistant!==!1&&f("");const B=new AbortController;return v.current=B,(async()=>{var P,Y,W,q,F,D,ue,X;const V=ae=>{var $;try{const Z=JSON.parse(JSON.stringify(ae));return($=Z==null?void 0:Z.payload)!=null&&$.files_info&&Array.isArray(Z.payload.files_info)&&(Z.payload.files_info=Z.payload.files_info.map(Ne=>({...Ne,data:Ne!=null&&Ne.data?`<base64 ${String(Ne.data).length} chars>`:Ne==null?void 0:Ne.data}))),Z}catch{return ae}};try{let ae={};try{if(r)ae={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const je=window.__AUTH_TOKEN__,He=((P=window.localStorage)==null?void 0:P.getItem("authToken"))||null;let Ue=null;try{const it=(Y=window.localStorage)==null?void 0:Y.getItem("chat-settings");it&&(Ue=((W=JSON.parse(it))==null?void 0:W.apiKey)||null)}catch{}const We=je||He||Ue||null;We&&(ae={Authorization:`Bearer ${We}`})}}catch{}console.debug("[use-chat] POST",t+n,V(A));const $=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...ae,...s.current},body:JSON.stringify(A),signal:B.signal});if(!$.ok||!$.body){const Ce=await $.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",$.status,Ce==null?void 0:Ce.slice(0,500)),new Error(`stream ${$.status}${Ce?": "+Ce:""}`)}x(!0);const Z=$.body.getReader(),Ne=new TextDecoder;let be="",M=[],O=E.current,z=null;const ee=()=>{if(M.length){const Ce=M.join("");M=[],y.current&&f(je=>je+Ce)}z=null},de=()=>{typeof window<"u"&&z==null&&(z=requestAnimationFrame(ee))};let le=Date.now();const Fe=setInterval(()=>{var Ce;if(Date.now()-le>2e4){const je="Stream idle timeout";u(je),B.abort(),(Ce=j==null?void 0:j.onError)==null||Ce.call(j,je)}},5e3),Ge=1024*1024;try{const Ce=$.headers.get("X-Thread-Id")||$.headers.get("x-thread-id"),je=$.headers.get("X-Thread-Created")||$.headers.get("x-thread-created"),He=Ce??null,Ue=String(je??"").toLowerCase()==="true";for((q=j==null?void 0:j.onOpen)==null||q.call(j,{threadId:He,created:Ue});;){const{value:We,done:it}=await Z.read();if(it)break;be+=Ne.decode(We,{stream:!0}),be.length>Ge&&(be="",console.warn("Stream buffer reset: exceeded 1MB"));let nt;for(;(nt=be.indexOf(`
36
36
 
37
37
  `))>=0;){const Tt=be.slice(0,nt);be=be.slice(nt+2);const gt=zm(Tt);if(!gt)continue;let rt;try{rt=JSON.parse(gt)}catch{console.debug("[use-chat] malformed SSE:",gt.slice(0,200));continue}const Ve=Fm(rt)?rt.data:rt;le=Date.now(),R==null||R(Ve);const Q=Ve.seq;if(Q!==void 0){if(Q<=O)continue;O>0&&Q>O+1&&((F=j==null?void 0:j.onGap)==null||F.call(j,{from:O,to:Q})),O=Q,E.current=Q,b(Q)}if(Ve.type==="token"&&e.autoAppendAssistant!==!1)M.push(Ve.content),de();else if(Ve.type==="message_delta"){const ne=Ve.delta.filter(xe=>xe.type==="text").map(xe=>xe.text).join("");ne&&e.autoAppendAssistant!==!1&&(M.push(ne),de())}else z!==null&&cancelAnimationFrame(z),ee(),Ve.type==="checkpoint"?g(Ve.checkpointId):Ve.type==="error"&&u(Ve.message)}}ee()}catch(Ce){if(Ce.name!=="AbortError"){const je=Ce.message||String(Ce);u(je),(D=j==null?void 0:j.onError)==null||D.call(j,je)}}finally{try{await Z.cancel()}catch{}finally{(ue=Z.releaseLock)==null||ue.call(Z)}z!==null&&typeof window<"u"&&window.cancelAnimationFrame(z),clearInterval(Fe),a(!1),x(!1),v.current=null}}catch(ae){if(ae.name!=="AbortError"){const $=ae.message||String(ae);u($),(X=j==null?void 0:j.onError)==null||X.call(j,$)}}finally{a(!1),x(!1),v.current=null}})(),{close:()=>B.abort()}},[t,n,r,e.autoAppendAssistant]);return S.useEffect(()=>()=>{var A;y.current=!1,(A=v.current)==null||A.abort()},[]),{isStreaming:i,error:c,assistantText:d,lastCheckpointId:h,lastSeq:w,connected:m,stream:N,stop:k,clear:I,setToken:C}}function Fm(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function zm(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(`
38
- `)}const Bm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Hm(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 o=Xs(t.payload.messages),s={...e,messages:o,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(s.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(s.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:o.length,previousCount:e.messages.length,checkpointId:s.lastCheckpointId}),s}case"prepend":{const o=Xs(t.payload.messages);if(!o.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const s=new Set(e.messages.map(a=>a.id)),i=o.filter(a=>!s.has(a.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:i.length,duplicates:o.length-i.length,finalTotal:i.length+e.messages.length}),i.length?{...e,messages:[...i,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const o=t.payload.message;if(e.assemblingId){const s=e.messages.findIndex(i=>i.id===e.assemblingId);if(s!==-1)return{...e,messages:[...e.messages.slice(0,s),o,...e.messages.slice(s)]}}return{...e,messages:[...e.messages,o]}}case"event":return Pl(e,t.payload.ev);case"batch":{const{events:o}=t.payload;return o.length?o.reduce((s,i)=>Pl(s,i),e):e}default:return e}}function Rl(e=[]){const[t,n]=S.useReducer(Hm,{...Bm,messages:e}),r=S.useRef([]),o=S.useRef(null),s=S.useRef(null),i=S.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=S.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]),c=S.useCallback(d=>{r.current.push(d),a()},[a]);S.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=S.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:c}),[c]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n;if(t.type==="message_start"&&t.role==="assistant"){const r=t.id,o=Km(t.model),s={id:r,role:"assistant",name:o||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:r,messages:[...e.messages,s]}}if(t.type==="message_delta"){const r=e.assemblingId??Js(e.messages);return r?{...e,messages:Zs(e.messages,r,t.delta)}:e}if(t.type==="message_end"){const r=e.assemblingId??Js(e.messages);if(!r)return{...e,assemblingId:null};const o=e.messages,s=o.findIndex(i=>i.id===r&&i.role==="assistant");if(s>=0&&!((n=o[s].content)==null?void 0:n.some(c=>{var u;return(c==null?void 0:c.type)==="text"&&((u=c.text)==null?void 0:u.trim())}))){const c=[...o.slice(0,s),...o.slice(s+1)];return{...e,assemblingId:null,messages:c}}return e}if(t.type==="tool_start"){const r=`tool-${t.id}`,o={type:"tool_call",id:t.id,name:t.name,args:t.args},s={id:r,role:"tool",name:t.name,createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],toolIndex:{...e.toolIndex,[t.id]:r}}}if(t.type==="tool_result"){const r=e.toolIndex[t.id]??`tool-${t.id}`,o={type:"tool_result",toolCallId:t.id,output:t.output,error:t.error},s=e.messages.find(c=>c.id===r),i={id:r,role:"tool",content:[o],createdAt:new Date().toISOString()},a=s?Zs(e.messages,r,[o]):[...e.messages,i];return{...e,messages:a}}if(t.type==="checkpoint"){const r=t.checkpointNs??e.lastCheckpointNs??null,o=qm(e.messages,t.checkpointId,r);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:r,messages:o}}if(t.type==="branch"){const r=t.checkpointId??e.lastCheckpointId,o=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:r??null,lastCheckpointNs:o??null}}if(t.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,r]}}if(t.type==="interrupt"){const r=e.assemblingId??Js(e.messages),o={type:"interrupt",value:t.value};if(r)return{...e,assemblingId:null,messages:Zs(e.messages,r,[o]),pendingInterrupt:{id:t.id,value:t.value}};const s={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],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 Um(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 Wm(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 Wm(e,t,r=>({...r,content:Vm(r.content,n)}))}function Vm(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function qm(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 Um(e,r,s)}return e}function Km(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Gm(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 Ym(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 c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Xm(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await Ym(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Ol=S.createContext(null);function xo({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null,autoLoadInitial:s=!0,disableAutoRestore:i=!1,enableFileAgentRouting:a=!1,fileAgentId:c="invoice_reader"}){const u=wn;S.useEffect(()=>{t&&u.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[u,t]);const{isStreaming:d,error:f,stream:h,stop:g,setToken:w}=_l({baseUrl:u.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/runs/stream"}),[b,m]=S.useState(()=>typeof u.getAuthToken=="function"?u.getAuthToken():null);S.useEffect(()=>{w(typeof u.getAuthToken=="function"?u.getAuthToken():null);const L=u.onTokenChange(G=>{m(G),w(G)});return()=>{L()}},[u,w]);const x=S.useCallback(L=>{u.setAuthToken(L)},[u]),{state:v,seed:y,prepend:E,pushUser:C,onEvent:k,reset:I}=Rl(),N=20,[A,R]=S.useState(!1),[j,B]=S.useState(!1),[V,P]=S.useState(null),[Y,W]=S.useState(void 0),[q,F]=S.useState(void 0),D=S.useRef(!1),ue=S.useRef([]),X=S.useRef(null),ae=S.useCallback(L=>{L.cursor!==void 0&&P(L.cursor),L.hasMore!==void 0&&R(L.hasMore),L.checkpointId!==void 0&&W(L.checkpointId),L.checkpointNs!==void 0&&F(L.checkpointNs)},[]),$=S.useCallback((L,G)=>new Promise((ye,ze)=>{const he=async()=>{if(D.current){console.warn(`[ChatProvider] Operation "${G}" queued - another operation in progress`),ue.current.push(he);return}D.current=!0;try{console.log(`[ChatProvider] Executing operation: ${G}`),await L(),ye()}catch(Le){console.error(`[ChatProvider] Operation "${G}" failed:`,Le),ze(Le)}finally{D.current=!1;const Le=ue.current.shift();Le&&Le().catch(()=>{})}};D.current?(ue.current.push(he),console.log(`[ChatProvider] Queued operation: ${G}`)):he().catch(Le=>{ze(Le)})}),[]),Z=S.useCallback((L,G)=>{const ye=Array.isArray(L==null?void 0:L.messages)?L.messages:[];G==="replace"?(console.log("[ChatProvider] Replacing messages, count:",ye.length),y(ye,{checkpointId:(L==null?void 0:L.checkpointId)??null,checkpointNs:(L==null?void 0:L.checkpointNs)??null})):G==="prepend"&&ye.length?(console.log("[ChatProvider] Calling prepend with",ye.length,"messages"),E(ye)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),P((L==null?void 0:L.nextCursor)??null),R(!!(L!=null&&L.hasMore)),W(ze=>(L==null?void 0:L.checkpointId)??ze??void 0),F(ze=>(L==null?void 0:L.checkpointNs)??ze??void 0)},[y,E]),[Ne,be]=S.useState([]),[M,O]=S.useState(null),z=S.useCallback(async()=>{const L=await u.listThreads();be(L)},[u]),[ee,de]=S.useState(!1),le=S.useCallback(async L=>{const G=(L==null?void 0:L.maxAttempts)??5,ye=(L==null?void 0:L.baseDelayMs)??500,ze=(L==null?void 0:L.timeoutMs)??2e3;if(!u.baseUrl)return!1;const he=u.baseUrl.replace(/\/+$/,""),Le=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],ct=async yt=>{try{const Et=new AbortController,ht=setTimeout(()=>Et.abort(),ze),pt=await fetch(yt,{method:"GET",signal:Et.signal});return clearTimeout(ht),pt.ok}catch{return!1}},Pn=async yt=>{try{const Et=new AbortController,ht=setTimeout(()=>Et.abort(),ze),pt=await fetch(yt,{method:"HEAD",signal:Et.signal});return clearTimeout(ht),pt.ok}catch{return!1}};for(let yt=0;yt<G;yt++){console.debug(`[ChatProvider] health-check attempt ${yt+1}/${G}`);for(const ht of Le){let pt=ht;he.endsWith("/api")&&ht.startsWith("/api")&&(pt=ht.replace(/^\/api/,"")||"/");const hn=pt==="/"?he+"/":he+pt;if(console.debug(`[ChatProvider] checking ${hn}`),await ct(hn)||ht==="/"&&await Pn(he+"/"))return de(!0),!0}const Et=ye*Math.pow(2,yt);await new Promise(ht=>setTimeout(ht,Et))}return de(!1),!1},[u.baseUrl]);S.useEffect(()=>{let L=!0;if(!u.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const G=await le();if(!L)return;G?z().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{L=!1}},[z,u.baseUrl,le]),S.useEffect(()=>{r==null||r(M)},[M,r]);const Fe=S.useRef(null);S.useEffect(()=>{if(o&&s){if(!u.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!ee){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}Fe.current!==o&&(Fe.current=o,je(o).catch(()=>{}))}},[o,s,u.baseUrl,ee]);const Ge=S.useRef(null),Ce=S.useRef(null),je=S.useCallback(async(L,G,ye)=>{await $(async()=>{if(X.current===L){console.log(`[ChatProvider] Skipping auto-load for thread ${L} - suppressed after clear`),X.current=null;return}if(!u.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(Ge.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${Ge.current}) is loading`);return}Ce.current!==null&&Ce.current!==L&&(console.log(`[ChatProvider] Thread switch detected: ${Ce.current} -> ${L}`),I([])),Ge.current=L,Ce.current=L;try{ae({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),O(L);const he=await u.getMessages({threadId:L,checkpointId:G,checkpointNs:ye,limit:N}),Le=Array.isArray(he==null?void 0:he.messages)?he.messages:[];console.log("[ChatProvider] Loading thread with",Le.length,"messages"),y(Le,{checkpointId:(he==null?void 0:he.checkpointId)??null,checkpointNs:(he==null?void 0:he.checkpointNs)??null}),P((he==null?void 0:he.nextCursor)??null),R(!!(he!=null&&he.hasMore)),W(ct=>(he==null?void 0:he.checkpointId)??ct??void 0),F(ct=>(he==null?void 0:he.checkpointNs)??ct??void 0)}finally{Ge.current=null}},`loadThread-${L}`)},[u,$,ae,y]),He=S.useCallback(async L=>{const G=await u.listCheckpoints(L);return Gm(G,L)},[u]),Ue=S.useCallback(async(L,G)=>{await $(async()=>{if(!M)throw new Error("No active thread");ae({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0});const ye=await u.getMessages({threadId:M,checkpointId:L,checkpointNs:G??void 0,limit:N});Z(ye,"replace")},`navigateToCheckpoint-${L}`)},[u,M,Z,$,ae]),We=S.useCallback(async()=>{if(!M)throw new Error("No active thread");await je(M)},[M,je]),it=S.useRef(!1);S.useEffect(()=>{const L=it.current;it.current=d,L&&!d&&M&&$(async()=>{try{await z()}catch(G){console.warn("[ChatProvider] Post-streaming thread refresh failed:",G)}},"postStreamingRefresh")},[d,M,u,Z,z,$]);const nt=S.useCallback(async()=>{console.log("[ChatProvider] 🔄 clearCurrentThread called"),console.log("[ChatProvider] 📊 Before clear - currentThreadId:",M),console.log("[ChatProvider] 📊 Before clear - messages count:",v.messages.length),M&&(X.current=M,console.log(`[ChatProvider] 🚫 Suppressing next auto-load for thread: ${M}`)),await $(()=>(console.log("[ChatProvider] 🚀 Executing atomic clear operation"),O(null),I([]),ae({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),typeof window<"u"&&localStorage.removeItem("currentThreadId"),console.log("[ChatProvider] ✅ Atomic clear operation completed"),Promise.resolve()),"clearCurrentThread"),console.log("[ChatProvider] 📊 After clear - currentThreadId should be null")},[I,ae,M,v.messages.length,$]),Tt=S.useCallback(async L=>{nt();const G=await u.createThread(L);return await z(),await je(G.threadId),G.threadId},[u,z,je,nt]),gt=S.useCallback(async L=>{await u.deleteThread(L),await z(),M===L&&(O(null),I([]),R(!1),P(null),W(void 0),F(void 0))},[u,z,M,I]),rt=S.useCallback(async(L,G)=>{await u.updateThread(L,G),await z()},[u,z]),Ve=S.useCallback(async(L,G)=>{var nr;const ye=(G==null?void 0:G.attachments)||[],{contentParts:ze,filesInfo:he}=await Xm(u,ye,t==null?void 0:t.uploadPath),Le=[];L&&L.trim()&&Le.push({type:"text",text:L.trim()});const ct={id:((nr=crypto.randomUUID)==null?void 0:nr.call(crypto))||`user-${Date.now()}`,role:"user",content:Le,createdAt:new Date().toISOString(),checkpointId:(G==null?void 0:G.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(G==null?void 0:G.checkpointNs)??v.lastCheckpointNs??void 0};C(ct);const Pn={...ct,content:Le},yt={...(G==null?void 0:G.payloadExtras)??{}},Et=!!yt.edit,ht=yt.originalMessageId,pt=typeof ht=="string"?ht:void 0,hn=ye&&ye.length>0,tr={...M?{threadId:M}:{},payload:{messages:[Pn],files_info:he,...a&&hn&&c?{active_agent:c}:{},...yt},checkpointId:(G==null?void 0:G.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(G==null?void 0:G.checkpointNs)??v.lastCheckpointNs??void 0,nodeFilter:G==null?void 0:G.nodeFilter,config:G==null?void 0:G.config,edit:Et,originalMessageId:pt};h(tr,St=>{if(St.type==="thread_info"&&St.threadId){const pn=St.threadId,te=!!St.created,pe=!!St.ready;if(M!==pn){const Re=!M&&v.messages.length<=1;Re&&(X.current=pn),O(pn),(pe||te||Re)&&z().catch(()=>{})}else(pe||te)&&z().catch(()=>{})}k(St)},{onError:St=>console.warn("stream error",St),onOpen:({threadId:St,created:pn})=>{if(!M&&St){const te=v.messages.length<=1;te&&(X.current=St),O(St),(pn||te)&&z().catch(()=>{})}}})},[M,C,h,k,v.lastCheckpointId,v.lastCheckpointNs,u,t==null?void 0:t.uploadPath,z,O,a,c,v.messages.length]),Q=S.useCallback(async L=>{if(!M)throw new Error("No active thread");if(j||!A)return;const G=V;if(G){B(!0);try{const ye=await u.getMessages({threadId:M,checkpointId:Y,checkpointNs:q,limit:(L==null?void 0:L.limit)??N,beforeId:G});Z(ye,"prepend")}finally{B(!1)}}},[u,M,Y,q,V,A,j,Z,N]),ne=S.useCallback(async(L,G,ye)=>{if(!M)throw new Error("No active thread to handle interrupt");try{console.log(`[ChatProvider] Handling interrupt ${L}: ${G?"approved":"rejected"}`);const ze=G?ye:{rejected:!0,interruptId:L};await u.resume({threadId:M,value:ze}),console.log(`[ChatProvider] Interrupt ${L} handled successfully`)}catch(ze){throw console.error(`[ChatProvider] Failed to handle interrupt ${L}:`,ze),ze}},[u,M]),xe={baseUrl:u.baseUrl,token:b,setToken:x,api:u,threads:Ne,currentThreadId:M,setCurrentThreadId:O,messages:v.messages,isStreaming:d,error:f,lastCheckpointId:v.lastCheckpointId,lastCheckpointNs:v.lastCheckpointNs,streamingAssistantId:v.assemblingId,hasMoreHistory:A,isLoadingHistory:j,loadOlderMessages:Q,historyPageSize:N,listCheckpoints:He,navigateToCheckpoint:Ue,returnToLatest:We,refreshThreads:z,createThread:Tt,deleteThread:gt,renameThread:rt,loadThread:je,clearCurrentThread:nt,send:Ve,stop:g,handleInterrupt:ne};return l.jsx(Ol.Provider,{value:xe,children:e})}function _r(){const e=S.useContext(Ol);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function J(...e){return pp.twMerge(hp.clsx(e))}const Jm=ro.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"}}),Pe=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?On.Slot:"button";return l.jsx(i,{className:J(Jm({variant:t,size:n,className:e})),ref:s,...o})});Pe.displayName="Button";const Ml=p.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:J("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}));Ml.displayName="Textarea";function Zm({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,g]=S.useState(e),[w,b]=S.useTransition(),m=S.useRef(null);S.useEffect(()=>{g(e??""),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const N=m.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const v=S.useCallback(async N=>{N&&N.preventDefault();const A=(h??"").trim();!A&&!f||b(()=>{try{const R=i(A);R&&typeof R.then=="function"?R.then(()=>{g(""),m.current&&(m.current.style.height="auto")}).catch(()=>{}):(g(""),m.current&&(m.current.style.height="auto"))}catch{}})},[h,i,f]),y=S.useCallback(N=>{g(N.target.value),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[]),E=S.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),v()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[v,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 l.jsx("form",{onSubmit:N=>void v(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Ml,{ref:m,value:h,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(Pe,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(se.Square,{size:16})}):l.jsx(Pe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:l.jsx(se.Send,{size:16})})})]})})}const Qm=S.memo(Zm),vo=0,yn=1,ar=2,Dl=4;function Ll(e){return()=>e}function eg(e){e()}function $l(e,t){return n=>e(t(n))}function Fl(e,t){return()=>e(t)}function tg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function ng(...e){return()=>{e.map(eg)}}function lr(){}function bo(e,t){return t(e),e}function rg(e,t){return t(e)}function Ze(...e){return e}function qe(e,t){return e(yn,t)}function Ae(e,t){e(vo,t)}function ei(e){e(ar)}function st(e){return e(Dl)}function fe(e,t){return qe(e,tg(t,vo))}function Gt(e,t){const n=e(yn,r=>{n(),t(r)});return n}function zl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Bl(e,t){return e===t}function Qe(e=Bl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function we(e){return t=>n=>{e(n)&&t(n)}}function oe(e){return t=>$l(t,e)}function tn(e){return t=>()=>{t(e)}}function H(e,...t){const n=og(...t);return(r,o)=>{switch(r){case ar:ei(e);return;case yn:return qe(e,n(o))}}}function nn(e,t){return n=>r=>{n(t=e(t,r))}}function $n(e){return t=>n=>{e>0?e--:t(n)}}function gn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function _e(...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);qe(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function og(...e){return t=>e.reduceRight(rg,t)}function sg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case yn:return s?n===s?void 0:(r(),n=s,t=qe(e,s),t):(r(),lr);case ar:r(),n=null;return}}}function K(e){let t=e;const n=De();return(r,o)=>{switch(r){case vo:t=o;break;case yn:{o(t);break}case Dl:return t}return n(r,o)}}function vt(e,t){return bo(K(t),n=>fe(e,n))}function De(){const e=[];return(t,n)=>{switch(t){case vo:e.slice().forEach(r=>{r(n)});return;case ar:e.splice(0,e.length);return;case yn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ot(e){return bo(De(),t=>fe(e,t))}function Be(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:ig(),singleton:n}}const ig=()=>Symbol();function ag(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(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function lt(...e){const t=De(),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);qe(s,c=>{n[i]=c,r=r|a,r===o&&Ae(t,n)})}),function(s,i){switch(s){case ar:{ei(t);return}case yn:return r===o&&i(n),qe(t,i)}}}function ve(e,t=Bl){return H(e,Qe(t))}function ti(...e){return function(t,n){switch(t){case ar:return;case yn:return ng(...e.map(r=>qe(r,n)))}}}var jt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(jt||{});const lg={0:"debug",3:"error",1:"log",2:"warn"},cg=()=>typeof globalThis>"u"?window:globalThis,Sn=Be(()=>{const e=K(3);return{log:K((t,n,r=1)=>{var o;const s=(o=cg().VIRTUOSO_LOG_LEVEL)!=null?o:st(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 Fn(e,t,n){return ni(e,t,n).callbackRef}function ni(e,t,n){const r=S.useRef(null);let o=i=>{};const s=S.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};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 ug(e,t,n,r,o,s,i,a,c){const u=S.useCallback(d=>{const f=dg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const g=h.lastElementChild.dataset.viewportType==="window";let w;g&&(w=h.ownerDocument.defaultView);const b=i?a?i.scrollLeft:i.scrollTop:g?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,m=i?a?i.scrollWidth:i.scrollHeight:g?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:g?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:m,scrollTop:Math.max(b,0),viewportHeight:x}),s==null||s(a?Hl("column-gap",getComputedStyle(d).columnGap,o):Hl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,c)}function dg(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 c=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},jt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Hl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,jt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ul(e,t,n){const r=S.useRef(null),o=S.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,h;if(t){const g=t.getBoundingClientRect(),w=u.top-g.top;h=g.height-Math.max(0,w),f=w+t.scrollTop}else{const g=i.current.ownerDocument.defaultView;h=g.innerHeight-Math.max(0,u.top),f=u.top+g.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var c;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=(c=i.current)==null?void 0:c.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 Ct=Be(()=>{const e=De(),t=De(),n=K(0),r=De(),o=K(0),s=De(),i=De(),a=K(0),c=K(0),u=K(0),d=K(0),f=De(),h=De(),g=K(!1),w=K(!1),b=K(!1);return fe(H(e,oe(({scrollTop:m})=>m)),t),fe(H(e,oe(({scrollHeight:m})=>m)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:g,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:b,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Rr={lvl:0};function Wl(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:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ye(e){return e===Rr}function Pr(e,t){if(!Ye(e))return t===e.k?e.v:t<e.k?Pr(e.l,t):Pr(e.r,t)}function Yt(e,t,n="k"){if(Ye(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Yt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Yt(e.l,t,n)}function Mt(e,t,n){return Ye(e)?Kl(t,n,1):t===e.k?dt(e,{k:t,v:n}):t<e.k?Gl(dt(e,{l:Mt(e.l,t,n)})):Gl(dt(e,{r:Mt(e.r,t,n)}))}function cr(){return Rr}function wo(e,t,n){if(Ye(e))return[];const r=Yt(e,t)[0];return fg(oi(e,r,n))}function ri(e,t){if(Ye(e))return Rr;const{k:n,l:r,r:o}=e;if(t===n){if(Ye(r))return o;if(Ye(o))return r;{const[s,i]=ql(r);return yo(dt(e,{k:s,l:Vl(r),v:i}))}}else return t<n?yo(dt(e,{l:ri(r,t)})):yo(dt(e,{r:ri(o,t)}))}function zn(e){return Ye(e)?[]:[...zn(e.l),{k:e.k,v:e.v},...zn(e.r)]}function oi(e,t,n){if(Ye(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oi(s,t,n))),a}function yo(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(si(t))return Yl(dt(e,{lvl:n-1}));if(!Ye(t)&&!Ye(t.r))return dt(t.r,{l:dt(t,{r:t.r.l}),lvl:n,r:dt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(dt(e,{lvl:n-1}));if(!Ye(r)&&!Ye(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return dt(o,{l:dt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(dt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function dt(e,t){return Kl(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 Vl(e){return Ye(e.r)?e.l:yo(dt(e,{r:Vl(e.r)}))}function si(e){return Ye(e)||e.lvl>e.r.lvl}function ql(e){return Ye(e.r)?[e.k,e.v]:ql(e.r)}function Kl(e,t,n,r=Rr,o=Rr){return{k:e,l:r,lvl:n,r:o,v:t}}function Gl(e){return ii(Yl(e))}function Yl(e){const{l:t}=e;return!Ye(t)&&t.lvl===e.lvl?dt(t,{r:dt(e,{l:t.r})}):e}function ii(e){const{lvl:t,r:n}=e;return!Ye(n)&&!Ye(n.r)&&n.lvl===t&&n.r.lvl===t?dt(n,{l:dt(e,{r:n.l}),lvl:t+1}):e}function fg(e){return Wl(e,({k:t,v:n})=>({index:t,value:n}))}function Xl(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Or(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=Be(()=>({recalcInProgress:K(!1)}),[],{singleton:!0});function Jl(e,t,n){return e[So(e,t,n)]}function So(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=So(e,t,r),s=So(e,n,r,o);return e.slice(o,s+1)}function Cn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Co(e){return!Ye(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function pg(){return{groupIndices:[],groupOffsetTree:cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:cr()}}function mg(e,t){let n=Ye(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ye(e)){e=Mt(e,0,s);continue}const a=wo(e,i-1,o+1);if(a.some(Sg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=Mt(e,o+1,h));u&&(e=Mt(e,i,s))}return[e,n]}function gg(e){return typeof e.groupIndex<"u"}function xg({offset:e},t){return t===e?0:t<e?-1:1}function Mr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Jl(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Zl(e,t){if(!Co(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ql(e,t,n){if(gg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Zl(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function vg(e,t,n,r=0){return r>0&&(t=Math.max(t,Jl(e,r,li).offset)),Wl(hg(e,t,n,xg),yg)}function bg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,jt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ye(s)&&t.length===2){const h=t[0].size,g=t[1].size;i=n.reduce((w,b)=>Mt(Mt(w,b,h),b+1,g),i)}else[i,a]=mg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,g)=>Mt(h,g,Mr(g,f,o)),cr()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function wg(e){return zn(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 ec(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 ci(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=So(o,t-1,li),a=o[c].offset;const u=Yt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Yt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of wo(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 yg(e){return{index:e.index,value:e}}function Sg(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 Cg={offsetHeight:"height",offsetWidth:"width"},rn=Be(([{log:e},{recalcInProgress:t}])=>{const n=De(),r=De(),o=vt(r,0),s=De(),i=De(),a=K(0),c=K([]),u=K(void 0),d=K(void 0),f=K((C,k)=>Cn(C,Cg[k])),h=K(void 0),g=K(0),w=pg(),b=vt(H(n,_e(c,e,g),nn(bg,w),Qe()),w),m=vt(H(c,Qe(),nn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),oe(({prev:C})=>C)),[]);fe(H(c,we(C=>C.length>0),_e(b,g),oe(([C,k,I])=>{const N=C.reduce((A,R,j)=>Mt(A,R,Mr(R,k.offsetTree,I)||j),cr());return{...k,groupIndices:C,groupOffsetTree:N}})),b),fe(H(r,_e(b),we(([C,{lastIndex:k}])=>C<k),oe(([C,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:C}])),n),fe(u,d);const x=vt(H(u,oe(C=>C===void 0)),!0);fe(H(d,we(C=>C!==void 0&&Ye(st(b).sizeTree)),oe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const v=Ot(H(n,_e(b),nn(({sizes:C},[k,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),oe(C=>C.changed)));qe(H(a,nn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),oe(C=>C.diff)),C=>{const{groupIndices:k}=st(b);if(C>0)Ae(t,!0),Ae(s,C+ec(C,k));else if(C<0){const I=st(m);I.length>0&&(C-=ec(-C,I)),Ae(i,C)}}),qe(H(a,_e(e)),([C,k])=>{C<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},jt.ERROR)});const y=Ot(s);fe(H(s,_e(b),oe(([C,k])=>{const I=k.groupIndices.length>0,N=[],A=k.lastSize;if(I){const R=Pr(k.sizeTree,0);let j=0,B=0;for(;j<C;){const P=k.groupIndices[B],Y=k.groupIndices.length===B+1?1/0:k.groupIndices[B+1]-P-1;N.push({endIndex:P,size:R,startIndex:P}),N.push({endIndex:P+1+Y-1,size:A,startIndex:P+1}),B++,j+=Y+1}const V=zn(k.sizeTree);return j!==C&&V.shift(),V.reduce((P,{k:Y,v:W})=>{let q=P.ranges;return P.prevSize!==0&&(q=[...P.ranges,{endIndex:Y+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:Y+C,prevSize:W,ranges:q}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return zn(k.sizeTree).reduce((R,{k:j,v:B})=>({prevIndex:j+C,prevSize:B,ranges:[...R.ranges,{endIndex:j+C-1,size:R.prevSize,startIndex:R.prevIndex}]}),{prevIndex:0,prevSize:A,ranges:[]}).ranges})),n);const E=Ot(H(i,_e(b,g),oe(([C,{offsetTree:k},I])=>{const N=-C;return Mr(N,k,I)})));return fe(H(i,_e(b,g),oe(([C,k,I])=>{if(k.groupIndices.length>0){if(Ye(k.sizeTree))return k;let N=cr();const A=st(m);let R=0,j=0,B=0;for(;R<-C;){B=A[j];const V=A[j+1]-B-1;j++,R+=V+1}if(N=zn(k.sizeTree).reduce((V,{k:P,v:Y})=>Mt(V,Math.max(0,P+C),Y),N),R!==-C){const V=Pr(k.sizeTree,B);N=Mt(N,0,V);const P=Yt(k.sizeTree,-C+1)[1];N=Mt(N,1,P)}return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}else{const N=zn(k.sizeTree).reduce((A,{k:R,v:j})=>Mt(A,Math.max(0,R+C),j),cr());return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}})),b),{beforeUnshiftWith:y,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:g,groupIndices:c,itemSize:f,listRefresh:v,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Ze(Sn,ai),{singleton:!0});function kg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const tc=Be(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=De(),i=De(),a=Ot(H(s,oe(kg)));return fe(H(a,oe(c=>c.totalCount)),n),fe(H(a,oe(c=>c.groupIndices)),e),fe(H(lt(o,t,r),we(([c,u])=>Co(u)),oe(([c,u,d])=>Yt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),Qe(),oe(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Ze(rn,Ct)),kn=Be(([{log:e}])=>{const t=K(!1),n=Ot(H(t,we(r=>r),Qe()));return qe(t,r=>{r&&st(e)("props updated",{},jt.DEBUG)}),{didMount:n,propsReady:t}},Ze(Sn),{singleton:!0}),Tg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function nc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Tg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Dr=Be(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const g=De(),w=De(),b=K(0);let m=null,x=null,v=null;function y(){m&&(m(),m=null),v&&(v(),v=null),x&&(clearTimeout(x),x=null),Ae(c,!1)}return fe(H(g,_e(n,f,r,b,a,i,h),_e(e,s,o),oe(([[E,C,k,I,N,A,R,j],B,V,P])=>{const Y=nc(E),{align:W,behavior:q,offset:F}=Y,D=I-1,ue=Ql(Y,C,D);let X=Mr(ue,C.offsetTree,B)+A;W==="end"?(X+=V+Yt(C.sizeTree,ue)[1]-k+P,ue===D&&(X+=R)):W==="center"?X+=(V+Yt(C.sizeTree,ue)[1]-k+P)/2:X-=N,F&&(X+=F);const ae=$=>{y(),$?(j("retrying to scroll to",{location:E},jt.DEBUG),Ae(g,E)):(Ae(w,!0),j("list did not change, scroll successful",{},jt.DEBUG))};if(y(),q==="smooth"){let $=!1;v=qe(t,Z=>{$=$||Z}),m=Gt(d,()=>{ae($)})}else m=Gt(H(t,Eg(150)),ae);return x=setTimeout(()=>{y()},1200),Ae(c,!0),j("scrolling from index to",{behavior:q,index:ue,top:X},jt.DEBUG),{behavior:q,top:X}})),u),{scrollTargetReached:w,scrollToIndex:g,topListHeight:b}},Ze(rn,Ct,Sn),{singleton:!0});function Eg(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ui(e,t){e==0?t():requestAnimationFrame(()=>{ui(e-1,t)})}function di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Lr=Be(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=K(!0),c=K(0),u=K(!0);return fe(H(i,_e(c),we(([d,f])=>!!f),tn(!1)),a),fe(H(i,_e(c),we(([d,f])=>!!f),tn(!1)),u),qe(H(lt(t,i),_e(a,n,e,u),we(([[,d],f,{sizeTree:h},g,w])=>d&&(!Ye(h)||Qs(g))&&!f&&!w),_e(c)),([,d])=>{Gt(o,()=>{Ae(u,!0)}),ui(4,()=>{Gt(r,()=>{Ae(a,!0)}),Ae(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Ze(rn,Ct,Dr,kn),{singleton:!0});function rc(e,t){return Math.abs(e-t)<1.01}const $r="up",Fr="down",Ig="none",Ng={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ag=0,zr=Be(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=K(!1),a=K(!0),c=De(),u=De(),d=K(4),f=K(Ag),h=vt(H(ti(H(ve(o),$n(1),tn(!0)),H(ve(o),$n(1),tn(!1),zl(100))),Qe()),!1),g=vt(H(ti(H(n,tn(!0)),H(n,tn(!1),zl(200))),Qe()),!1);fe(H(lt(ve(o),ve(f)),oe(([v,y])=>v<=y),Qe()),a),fe(H(a,gn(50)),u);const w=Ot(H(lt(r,ve(s),ve(t),ve(e),ve(d)),nn((v,[{scrollHeight:y,scrollTop:E},C,k,I,N])=>{const A=E+C-y>-N,R={scrollHeight:y,scrollTop:E,viewportHeight:C};if(A){let B,V;return E>v.state.scrollTop?(B="SCROLLED_DOWN",V=v.state.scrollTop-E):(B="SIZE_DECREASED",V=v.state.scrollTop-E||v.scrollTopDelta),{atBottom:!0,atBottomBecause:B,scrollTopDelta:V,state:R}}let j;return R.scrollHeight>v.state.scrollHeight?j="SIZE_INCREASED":C<v.state.viewportHeight?j="VIEWPORT_HEIGHT_DECREASING":E<v.state.scrollTop?j="SCROLLING_UPWARDS":j="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:j,state:R}},Ng),Qe((v,y)=>v&&v.atBottom===y.atBottom))),b=vt(H(r,nn((v,{scrollHeight:y,scrollTop:E,viewportHeight:C})=>{if(rc(v.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const k=y-(E+C)<1;return v.scrollTop!==E&&k?{changed:!0,jump:v.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(v=>v.changed),oe(v=>v.jump)),0);fe(H(w,oe(v=>v.atBottom)),i),fe(H(i,gn(50)),c);const m=K(Fr);fe(H(r,oe(({scrollTop:v})=>v),Qe(),nn((v,y)=>st(g)?{direction:v.direction,prevScrollTop:y}:{direction:y<v.prevScrollTop?$r:Fr,prevScrollTop:y},{direction:Fr,prevScrollTop:0}),oe(v=>v.direction)),m),fe(H(r,gn(50),tn(Ig)),m);const x=K(0);return fe(H(h,we(v=>!v),tn(0)),x),fe(H(o,gn(100),_e(h),we(([v,y])=>!!y),nn(([v,y],[E])=>[y,E],[0,0]),oe(([v,y])=>y-v)),x),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:b,scrollDirection:m,scrollVelocity:x}},Ze(Ct)),ko="top",To="bottom",oc="none";function sc(e,t,n){return typeof e=="number"?n===$r&&t===ko||n===Fr&&t===To?e:0:n===$r?t===ko?e.main:e.reverse:t===To?e.main:e.reverse}function ic(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=Be(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=De(),i=K(0),a=K(0),c=K(0),u=vt(H(lt(ve(r),ve(o),ve(n),ve(s,Or),ve(c),ve(i),ve(t),ve(e),ve(a)),oe(([d,f,h,[g,w],b,m,x,v,y])=>{const E=d-v,C=m+x,k=Math.max(h-E,0);let I=oc;const N=ic(y,ko),A=ic(y,To);return g-=v,g+=h+x,w+=h+x,w-=v,g>d+C-N&&(I=$r),w<d-k+f+A&&(I=Fr),I!==oc?[Math.max(E-h-sc(b,ko,I)-N,0),E-k-x+f+sc(b,To,I)+A]:null}),we(d=>d!=null),Qe(Or)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Ze(Ct),{singleton:!0});function jg(e,t,n){if(Co(t)){const r=Zl(e,t);return[{index:Yt(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 hi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Eo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const b=e[e.length-1];d=b.offset+b.size}const f=n-i,h=a+f*c+(f-1)*r,g=u,w=h-d;return{bottom:d,firstItemIndex:s,items:lc(e,o,s),offsetBottom:w,offsetTop:u,top:g,topItems:lc(t,o,s),topListHeight:t.reduce((b,m)=>m.size+b,0),totalCount:n}}function ac(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,c=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return Eo(u,[],a,o,n,r)}function lc(e,t,n){if(e.length===0)return[];if(!Co(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=wo(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Bn=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:g},{recalcInProgress:w}])=>{const b=K([]),m=K(0),x=De();fe(s.topItemsIndexes,b);const v=vt(H(lt(g,w,ve(c,Or),ve(o),ve(r),ve(u),d,ve(b),ve(t),ve(n),e),we(([k,I,,N,,,,,,,A])=>{const R=A&&A.length!==N;return k&&!I&&!R}),oe(([,,[k,I],N,A,R,j,B,V,P,Y])=>{const W=A,{offsetTree:q,sizeTree:F}=W,D=st(m);if(N===0)return{...hi,totalCount:N};if(k===0&&I===0)return D===0?{...hi,totalCount:N}:ac(D,R,A,V,P,Y||[]);if(Ye(F))return D>0?null:Eo(jg(di(R,N),W,Y),[],N,P,W,V);const ue=[];if(B.length>0){const Ne=B[0],be=B[B.length-1];let M=0;for(const O of wo(F,Ne,be)){const z=O.value,ee=Math.max(O.start,Ne),de=Math.min(O.end,be);for(let le=ee;le<=de;le++)ue.push({data:Y==null?void 0:Y[le],index:le,offset:M,size:z}),M+=z}}if(!j)return Eo([],ue,N,P,W,V);const X=B.length>0?B[B.length-1]+1:0,ae=vg(q,k,I,X);if(ae.length===0)return null;const $=N-1,Z=bo([],Ne=>{for(const be of ae){const M=be.value;let O=M.offset,z=be.start;const ee=M.size;if(M.offset<k){z+=Math.floor((k-M.offset+P)/(ee+P));const le=z-be.start;O+=le*ee+le*P}z<X&&(O+=(X-z)*ee,z=X);const de=Math.min(be.end,$);for(let le=z;le<=de&&!(O>=I);le++)Ne.push({data:Y==null?void 0:Y[le],index:le,offset:O,size:ee}),O+=ee+P}});return Eo(Z,ue,N,P,W,V)}),we(k=>k!==null),Qe()),hi);fe(H(e,we(Qs),oe(k=>k==null?void 0:k.length)),o),fe(H(v,oe(k=>k.topListHeight)),f),fe(f,a),fe(H(v,oe(k=>[k.top,k.bottom])),i),fe(H(v,oe(k=>k.items)),x);const y=Ot(H(v,we(({items:k})=>k.length>0),_e(o,e),we(([{items:k},I])=>k[k.length-1].originalIndex===I-1),oe(([,k,I])=>[k-1,I]),Qe(Or),oe(([k])=>k))),E=Ot(H(v,gn(200),we(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),oe(({items:k})=>k[0].index),Qe())),C=Ot(H(v,we(({items:k})=>k.length>0),oe(({items:k})=>{let I=0,N=k.length-1;for(;k[I].type==="group"&&I<N;)I++;for(;k[N].type==="group"&&N>I;)N--;return{endIndex:k[N].index,startIndex:k[I].index}}),Qe(Xl)));return{endReached:y,initialItemCount:m,itemsRendered:x,listState:v,rangeChanged:C,startReached:E,topItemsIndexes:b,...h}},Ze(rn,tc,fi,Lr,Dr,zr,kn,ai),{singleton:!0}),cc=Be(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=De(),i=vt(H(lt(n,e,r,t,o),oe(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return fe(ve(i),s),{totalListHeight:i,totalListHeightChanged:s}},Ze(Ct,Bn),{singleton:!0}),_g=Be(([{viewportHeight:e},{totalListHeight:t}])=>{const n=K(!1),r=vt(H(lt(n,e,t),we(([o])=>o),oe(([,o,s])=>Math.max(0,o-s)),gn(0),Qe()),0);return{alignToBottom:n,paddingTopAddition:r}},Ze(Ct,cc),{singleton:!0}),uc=Be(()=>({context:K(null)})),Rg=({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,dc=Be(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=De();return fe(H(d,_e(t,c,n,s,o,r,a),_e(e),oe(([[f,h,g,w,b,m,x,v],y])=>{const{align:E,behavior:C,calculateViewLocation:k=Rg,done:I,...N}=f,A=Ql(f,h,w-1),R=Mr(A,h.offsetTree,y)+b+m,j=R+Yt(h.sizeTree,A)[1],B=v+m,V=v+g-x,P=k({itemBottom:j,itemTop:R,locationParams:{align:E,behavior:C,...N},viewportBottom:V,viewportTop:B});return P?I&&Gt(H(i,we(Y=>!Y),$n(st(i)?1:2)),I):I&&I(),P}),we(f=>f!==null)),u),{scrollIntoView:d}},Ze(rn,Ct,Dr,Bn,Sn),{singleton:!0});function fc(e){return e?e==="smooth"?"smooth":"auto":!1}const Pg=(e,t)=>typeof e=="function"?fc(e(t)):t&&fc(e),Og=Be(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:g}])=>{const w=K(!1),b=De();let m=null;function x(C){Ae(i,{align:"end",behavior:C,index:"LAST"})}qe(H(lt(H(ve(t),$n(1)),c),_e(ve(w),s,a,f),oe(([[C,k],I,N,A,R])=>{let j=k&&A,B="auto";return j&&(B=Pg(I,N||R),j=j&&!!B),{followOutputBehavior:B,shouldFollow:j,totalCount:C}}),we(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{m&&(m(),m=null),st(n)?requestAnimationFrame(()=>{st(d)("following output to ",{totalCount:k},jt.DEBUG),x(C)}):m=Gt(e,()=>{st(d)("following output to ",{totalCount:k},jt.DEBUG),x(C),m=null})});function v(C){const k=Gt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!m&&(st(d)("scrolling to bottom due to increased size",{},jt.DEBUG),x("auto"))});setTimeout(k,100)}qe(H(lt(ve(w),t,u),we(([C,,k])=>C&&k),nn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),we(({refreshed:C})=>C),_e(w,t)),([,C])=>{st(a)&&v(C!==!1)}),qe(b,()=>{v(st(w)!==!1)}),qe(lt(ve(w),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=K(null),E=De();return fe(ti(H(ve(r),oe(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),H(ve(t))),E),qe(H(lt(H(E,$n(1)),c),_e(ve(y),a,f,h),oe(([[C,k],I,N,A,R])=>k&&N&&(I==null?void 0:I({context:R,totalCount:C,scrollingInProgress:A}))),we(C=>!!C),gn(0)),C=>{m&&(m(),m=null),st(n)?requestAnimationFrame(()=>{st(d)("scrolling into view",{}),Ae(g,C)}):m=Gt(e,()=>{st(d)("scrolling into view",{}),Ae(g,C),m=null})}),{autoscrollToBottom:b,followOutput:w,scrollIntoViewOnChange:y}},Ze(rn,zr,Dr,Lr,kn,Sn,Ct,uc,dc)),Mg=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(H(a,_e(s),we(([,c])=>c!==0),_e(o,r,t,n,e),oe(([[,c],u,d,f,h,g=[]])=>ac(c,u,d,f,h,g))),i),{}),Ze(rn,Lr,Bn,kn),{singleton:!0}),Dg=Be(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=K(0);return qe(H(e,_e(r),we(([,o])=>o!==0),oe(([,o])=>({top:o}))),o=>{Gt(H(n,$n(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(t,o)})})}),{initialScrollTop:r}},Ze(kn,Ct,Bn),{singleton:!0}),hc=Be(([{scrollVelocity:e}])=>{const t=K(!1),n=De(),r=K(!1);return fe(H(e,_e(r,t,n),we(([o,s])=>!!s),oe(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),Qe()),t),qe(H(lt(t,e,n),_e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Ze(zr),{singleton:!0}),pi=Be(([{scrollContainerState:e,scrollTo:t}])=>{const n=De(),r=De(),o=De(),s=K(!1),i=K(void 0);return fe(H(lt(n,r),oe(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),fe(H(t,_e(r),oe(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Ze(Ct)),Lg=Be(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=De(),d=K(void 0),f=K(null),h=K(null);return fe(a,f),fe(c,h),qe(H(u,_e(t,r,i,f,h,n)),([g,w,b,m,x,v,y])=>{const E=wg(w.sizeTree);m&&x!==null&&v!==null&&(b=x.scrollTop-v.offsetTop),b-=y,g({ranges:E,scrollTop:b})}),fe(H(d,we(Qs),oe($g)),o),fe(H(s,_e(d),we(([,g])=>g!==void 0),Qe(),oe(([,g])=>g.ranges)),e),{getState:u,restoreStateFrom:d}},Ze(rn,Ct,Lr,kn,pi));function $g(e){return{align:"start",index:0,offset:e.scrollTop}}const Fg=Be(([{topItemsIndexes:e}])=>{const t=K(0);return fe(H(t,we(n=>n>=0),oe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Ze(Bn));function pc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const zg=pc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Bg=Be(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:g},{recalcInProgress:w}])=>{const b=Ot(H(c,_e(i),nn(([,x,v,y],[{bottom:E,items:C,offsetBottom:k,totalCount:I},N])=>{const A=E+k;let R=0;return v===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(R=A-y,R!==0&&(R+=N))),[R,C,I,A]},[0,[],0,0]),we(([x])=>x!==0),_e(r,a,n,o,g,w),we(([,x,v,y,,,E])=>!E&&!y&&x!==0&&v===$r),oe(([[x],,,,,v])=>(v("Upward scrolling compensation",{amount:x},jt.DEBUG),x))));function m(x){x>0?(Ae(t,{behavior:"auto",top:-x}),Ae(e,0)):(Ae(e,0),Ae(t,{behavior:"auto",top:-x}))}return qe(H(b,_e(e,s)),([x,v,y])=>{y&&zg()?Ae(e,v-x):m(-x)}),qe(H(lt(vt(s,!1),e,w),we(([x,v,y])=>!x&&!y&&v!==0),oe(([x,v])=>v),gn(1)),m),fe(H(f,oe(x=>({top:-x}))),t),qe(H(u,_e(h,d),oe(([x,{groupIndices:v,lastSize:y,sizeTree:E},C])=>{function k(I){return I*(y+C)}if(v.length===0)return k(x);{let I=0;const N=Pr(E,0);let A=0,R=0;for(;A<x;){A++,I+=N;let j=v.length===R+1?1/0:v[R+1]-v[R]-1;A+j>x&&(I-=N,j=x-A+1),A+=j,I+=k(j),R++}return I}})),x=>{Ae(e,x),requestAnimationFrame(()=>{Ae(t,{top:x}),requestAnimationFrame(()=>{Ae(e,0),Ae(w,!1)})})}),{deviation:e}},Ze(Ct,zr,Bn,rn,Sn,ai)),Hg=Be(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Ze(fi,Mg,kn,hc,cc,Dg,_g,pi,dc,Sn,uc)),mc=Be(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:g,scrolledToInitialItem:w},b,m,x,{listState:v,topItemsIndexes:y,...E},{scrollToIndex:C},k,{topItemCount:I},{groupCounts:N},A])=>(fe(E.rangeChanged,A.scrollSeekRangeChanged),fe(H(A.windowViewportRect,oe(R=>R.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:g,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:v,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...A,...b,sizes:c,...m}),Ze(rn,Lr,Ct,Lg,Og,Bn,Dr,Bg,Fg,tc,Hg));function Ug(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 Io=typeof document<"u"?S.useLayoutEffect:S.useEffect;function gc(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=S.createContext({});function c(m,x){m.propsReady&&Ae(m.propsReady,!1);for(const v of r){const y=m[t.required[v]];Ae(y,x[v])}for(const v of o)if(v in x){const y=m[t.optional[v]];Ae(y,x[v])}m.propsReady&&Ae(m.propsReady,!0)}function u(m){return s.reduce((x,v)=>(x[v]=y=>{const E=m[t.methods[v]];Ae(E,y)},x),{})}function d(m){return i.reduce((x,v)=>(x[v]=sg(m[t.events[v]]),x),{})}const f=S.forwardRef((m,x)=>{const{children:v,...y}=m,[E]=S.useState(()=>bo(ag(e),I=>{c(I,y)})),[C]=S.useState(Fl(d,E));Io(()=>{for(const I of i)I in y&&qe(C[I],y[I]);return()=>{Object.values(C).map(ei)}},[y,C,E]),Io(()=>{c(E,y)}),S.useImperativeHandle(x,Ll(u(E)));const k=n;return l.jsx(a.Provider,{value:E,children:n?l.jsx(k,{...Ug([...r,...o,...i],y),children:v}):v})}),h=m=>{const x=S.useContext(a);return S.useCallback(v=>{Ae(x[m],v)},[x,m])},g=m=>{const x=S.useContext(a)[m],v=S.useCallback(y=>qe(x,y),[x]);return S.useSyncExternalStore(v,()=>st(x),()=>st(x))},w=m=>{const x=S.useContext(a)[m],[v,y]=S.useState(Fl(st,x));return Io(()=>qe(x,E=>{E!==v&&y(Ll(E))}),[x,v]),v},b=S.version.startsWith("18")?g:w;return{Component:f,useEmitter:(m,x)=>{const v=S.useContext(a)[m];Io(()=>qe(v,x),[x,v])},useEmitterValue:b,usePublisher:h}}const xc=S.createContext(void 0),vc=S.createContext(void 0),bc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function mi(e){return"self"in e}function Wg(e){return"body"in e}function wc(e,t,n,r=lr,o,s){const i=S.useRef(null),a=S.useRef(null),c=S.useRef(null),u=S.useCallback(h=>{let g,w,b;const m=h.target;if(Wg(m)||mi(m)){const v=mi(m)?m:m.defaultView;b=s?v.scrollX:v.scrollY,g=s?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,w=s?v.innerWidth:v.innerHeight}else b=s?m.scrollLeft:m.scrollTop,g=s?m.scrollWidth:m.scrollHeight,w=s?m.offsetWidth:m.offsetHeight;const x=()=>{e({scrollHeight:g,scrollTop:Math.max(b,0),viewportHeight:w})};h.suppressFlushSync?x():Os.flushSync(x),a.current!==null&&(b===a.current||b<=0||b===g-w)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);S.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 g=i.current;if(!g||(s?"offsetWidth"in g&&g.offsetWidth===0:"offsetHeight"in g&&g.offsetHeight===0))return;const w=h.behavior==="smooth";let b,m,x;mi(g)?(m=Math.max(Cn(g.document.documentElement,s?"width":"height"),s?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight),b=s?g.innerWidth:g.innerHeight,x=s?window.scrollX:window.scrollY):(m=g[s?"scrollWidth":"scrollHeight"],b=Cn(g,s?"width":"height"),x=g[s?"scrollLeft":"scrollTop"]);const v=m-b;if(h.top=Math.ceil(Math.max(Math.min(v,h.top),0)),rc(b,m)||h.top===x){e({scrollHeight:m,scrollTop:x,viewportHeight:b}),w&&t(!0);return}w?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),g.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 gi="-webkit-sticky",yc="sticky",xi=pc(()=>{if(typeof document>"u")return yc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:yc});function vi(e){return e}const Vg=Be(()=>{const e=K(a=>`Item ${a}`),t=K(a=>`Group ${a}`),n=K({}),r=K(vi),o=K("div"),s=K(lr),i=(a,c=null)=>vt(H(n,oe(u=>u[a]),Qe()),c);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")}}),qg=Be(([e,t])=>({...e,...t}),Ze(mc,Vg)),Kg=({height:e})=>l.jsx("div",{style:{height:e}}),Gg={overflowAnchor:"none",position:xi(),zIndex:1},Sc={overflowAnchor:"none"},Yg={...Sc,display:"inline-block",height:"100%"},Cc=S.memo(function({showTopList:e=!1}){const t=Te("listState"),n=zt("sizeRanges"),r=Te("useWindowScroll"),o=Te("customScrollParent"),s=zt("windowScrollContainerState"),i=zt("scrollContainerState"),a=o||r?s:i,c=Te("itemContent"),u=Te("context"),d=Te("groupContent"),f=Te("trackItemSizes"),h=Te("itemSize"),g=Te("log"),w=zt("gap"),b=Te("horizontalDirection"),{callbackRef:m}=ug(n,h,f,e?lr:a,g,w,o,b,Te("skipAnimationFrameInResizeObserver")),[x,v]=S.useState(0);bi("deviation",P=>{x!==P&&v(P)});const y=Te("EmptyPlaceholder"),E=Te("ScrollSeekPlaceholder")||Kg,C=Te("ListComponent"),k=Te("ItemComponent"),I=Te("GroupComponent"),N=Te("computeItemKey"),A=Te("isSeeking"),R=Te("groupIndices").length>0,j=Te("alignToBottom"),B=Te("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...b?{display:"inline-block",height:"100%",marginLeft:x!==0?x:j?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:j?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...B?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?l.jsx(y,{...bt(y,u)}):l.jsx(C,{...bt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:m,style:V,children:(e?t.topItems:t.items).map(P=>{const Y=P.originalIndex,W=N(Y+t.firstItemIndex,P.data,u);return A?S.createElement(E,{...bt(E,u),height:P.size,index:P.index,key:W,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?S.createElement(I,{...bt(I,u),"data-index":Y,"data-item-index":P.index,"data-known-size":P.size,key:W,style:Gg},d(P.index,u)):S.createElement(k,{...bt(k,u),...Qg(k,P.data),"data-index":Y,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:W,style:b?Yg:Sc},R?c(P.index,P.groupIndex,P.data,u):c(P.index,P.data,u))})})}),Xg={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Jg={outline:"none",overflowX:"auto",position:"relative"},No=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Zg={position:xi(),top:0,width:"100%",zIndex:1};function bt(e,t){if(typeof e!="string")return{context:t}}function Qg(e,t){return{item:typeof e=="string"?void 0:t}}const ex=S.memo(function(){const e=Te("HeaderComponent"),t=zt("headerHeight"),n=Te("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null}),tx=S.memo(function(){const e=Te("FooterComponent"),t=zt("footerHeight"),n=Te("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null});function kc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:g,scrollToCallback:w}=wc(a,u,c,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:g,style:{...f?Jg:Xg,...o},tabIndex:0,...i,...bt(c,s),children:r})})}function Tc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),g=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:b,scrollerRef:m,scrollToCallback:x}=wc(a,u,c,w,h);return bc(()=>{var v;return m.current=h||((v=g.current)==null?void 0:v.ownerDocument.defaultView),()=>{m.current=null}},[m,h]),e("windowScrollTo",x),e("scrollBy",b),l.jsx(c,{ref:g,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...bt(c,s),children:r})})}const nx=({children:e})=>{const t=S.useContext(xc),n=zt("viewportHeight"),r=zt("fixedItemHeight"),o=Te("alignToBottom"),s=Te("horizontalDirection"),i=S.useMemo(()=>$l(n,c=>Cn(c,s?"width":"height")),[n,s]),a=Fn(i,!0,Te("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:No(o),children:e})},rx=({children:e})=>{const t=S.useContext(xc),n=zt("windowViewportRect"),r=zt("fixedItemHeight"),o=Te("customScrollParent"),s=Ul(n,o,Te("skipAnimationFrameInResizeObserver")),i=Te("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:No(i),children:e})},ox=({children:e})=>{const t=Te("TopItemListComponent")||"div",n=Te("headerHeight"),r={...Zg,marginTop:`${n}px`},o=Te("context");return l.jsx(t,{style:r,...bt(t,o),children:e})},sx=S.memo(function(e){const t=Te("useWindowScroll"),n=Te("topItemsIndexes").length>0,r=Te("customScrollParent"),o=Te("context");return l.jsxs(r||t?lx:ax,{...e,context:o,children:[n&&l.jsx(ox,{children:l.jsx(Cc,{showTopList:!0})}),l.jsxs(r||t?rx:nx,{children:[l.jsx(ex,{}),l.jsx(Cc,{}),l.jsx(tx,{})]})]})}),{Component:ix,useEmitter:bi,useEmitterValue:Te,usePublisher:zt}=gc(qg,{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"}},sx),ax=kc({useEmitter:bi,useEmitterValue:Te,usePublisher:zt}),lx=Tc({useEmitter:bi,useEmitterValue:Te,usePublisher:zt}),cx=ix;Ze(mc,Be(()=>{const e=K(u=>l.jsxs("td",{children:["Item $",u]})),t=K(null),n=K(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=K(null),o=K(null),s=K({}),i=K(vi),a=K(lr),c=(u,d=null)=>vt(H(s,oe(f=>f[u]),Qe()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),xi();const Ec={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},ux={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ic,floor:Ao,max:Br,min:wi,round:Nc}=Math;function Ac(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function dx(e){return{...ux,items:e}}function jo(e,t){return e&&e.width===t.width&&e.height===t.height}function fx(e,t){return e&&e.column===t.column&&e.row===t.row}const hx=Be(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,g,{didMount:w,propsReady:b},{customScrollParent:m,useWindowScroll:x,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E},C])=>{const k=K(0),I=K(0),N=K(Ec),A=K({height:0,width:0}),R=K({height:0,width:0}),j=De(),B=De(),V=K(0),P=K(null),Y=K({column:0,row:0}),W=De(),q=De(),F=K(!1),D=K(0),ue=K(!0),X=K(!1),ae=K(!1);qe(H(w,_e(D),we(([O,z])=>!!z)),()=>{Ae(ue,!1)}),qe(H(lt(w,ue,R,A,D,X),we(([O,z,ee,de,,le])=>O&&!z&&ee.height!==0&&de.height!==0&&!le)),([,,,,O])=>{Ae(X,!0),ui(1,()=>{Ae(j,O)}),Gt(H(u),()=>{Ae(t,[0,0]),Ae(ue,!0)})}),fe(H(q,we(O=>O!=null&&O.scrollTop>0),tn(0)),I),qe(H(w,_e(q),we(([,O])=>O!=null)),([,O])=>{O&&(Ae(A,O.viewport),Ae(R,O.item),Ae(Y,O.gap),O.scrollTop>0&&(Ae(F,!0),Gt(H(u,$n(1)),z=>{Ae(F,!1)}),Ae(c,{top:O.scrollTop})))}),fe(H(A,oe(({height:O})=>O)),f),fe(H(lt(ve(A,jo),ve(R,jo),ve(Y,(O,z)=>O&&O.column===z.column&&O.row===z.row),ve(u)),oe(([O,z,ee,de])=>({gap:ee,item:z,scrollTop:de,viewport:O}))),W),fe(H(lt(ve(k),r,ve(Y,fx),ve(R,jo),ve(A,jo),ve(P),ve(I),ve(F),ve(ue),ve(D)),we(([,,,,,,,O])=>!O),oe(([O,[z,ee],de,le,Fe,Ge,Ce,,je,He])=>{const{column:Ue,row:We}=de,{height:it,width:nt}=le,{width:Tt}=Fe;if(Ce===0&&(O===0||Tt===0))return Ec;if(nt===0){const ye=di(He,O),ze=ye+Math.max(Ce-1,0);return dx(Ac(ye,ze,Ge))}const gt=jc(Tt,nt,Ue);let rt,Ve;je?z===0&&ee===0&&Ce>0?(rt=0,Ve=Ce-1):(rt=gt*Ao((z+We)/(it+We)),Ve=gt*Ic((ee+We)/(it+We))-1,Ve=wi(O-1,Br(Ve,gt-1)),rt=wi(Ve,Br(0,rt))):(rt=0,Ve=-1);const Q=Ac(rt,Ve,Ge),{bottom:ne,top:xe}=_c(Fe,de,le,Q),L=Ic(O/gt),G=L*it+(L-1)*We-ne;return{bottom:ne,itemHeight:it,items:Q,itemWidth:nt,offsetBottom:G,offsetTop:xe,top:xe}})),N),fe(H(P,we(O=>O!==null),oe(O=>O.length)),k),fe(H(lt(A,R,N,Y),we(([O,z,{items:ee}])=>ee.length>0&&z.height!==0&&O.height!==0),oe(([O,z,{items:ee},de])=>{const{bottom:le,top:Fe}=_c(O,de,z,ee);return[Fe,le]}),Qe(Or)),t);const $=K(!1);fe(H(u,_e($),oe(([O,z])=>z||O!==0)),$);const Z=Ot(H(lt(N,k),we(([{items:O}])=>O.length>0),_e($),we(([[O,z],ee])=>{const de=O.items[O.items.length-1].index===z-1;return(ee||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===z)&&de}),oe(([[,O]])=>O-1),Qe())),Ne=Ot(H(ve(N),we(({items:O})=>O.length>0&&O[0].index===0),tn(0),Qe())),be=Ot(H(ve(N),_e(F),we(([{items:O},z])=>O.length>0&&!z),oe(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),Qe(Xl),gn(0)));fe(be,g.scrollSeekRangeChanged),fe(H(j,_e(A,R,k,Y),oe(([O,z,ee,de,le])=>{const Fe=nc(O),{align:Ge,behavior:Ce,offset:je}=Fe;let He=Fe.index;He==="LAST"&&(He=de-1),He=Br(0,He,wi(de-1,He));let Ue=yi(z,le,ee,He);return Ge==="end"?Ue=Nc(Ue-z.height+ee.height):Ge==="center"&&(Ue=Nc(Ue-z.height/2+ee.height/2)),je&&(Ue+=je),{behavior:Ce,top:Ue}})),c);const M=vt(H(N,oe(O=>O.offsetBottom+O.bottom)),0);return fe(H(E,oe(O=>({height:O.visibleHeight,width:O.visibleWidth}))),A),{customScrollParent:m,data:P,deviation:V,footerHeight:o,gap:Y,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:R,overscan:n,restoreStateFrom:q,scrollBy:i,scrollContainerState:a,scrollHeight:B,scrollTo:c,scrollToIndex:j,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:A,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E,...g,gridState:N,horizontalDirection:ae,initialTopMostItemIndex:D,totalListHeight:M,...h,endReached:Z,propsReady:b,rangeChanged:be,startReached:Ne,stateChanged:W,stateRestoreInProgress:F,...C}},Ze(fi,Ct,zr,hc,kn,pi,Sn));function jc(e,t,n){return Br(1,Ao((e+n)/(Ao(t)+n)))}function _c(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=yi(e,t,n,r[0].index);return{bottom:yi(e,t,n,r[r.length-1].index)+o,top:s}}function yi(e,t,n,r){const o=jc(e.width,n.width,t.column),s=Ao(r/o),i=s*n.height+Br(0,s-1)*t.row;return i>0?i+t.row:i}const px=Be(()=>{const e=K(f=>`Item ${f}`),t=K({}),n=K(null),r=K("virtuoso-grid-item"),o=K("virtuoso-grid-list"),s=K(vi),i=K("div"),a=K(lr),c=(f,h=null)=>vt(H(t,oe(g=>g[f]),Qe()),h),u=K(!1),d=K(!1);return fe(ve(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),mx=Be(([e,t])=>({...e,...t}),Ze(hx,px)),gx=S.memo(function(){const e=et("gridState"),t=et("listClassName"),n=et("itemClassName"),r=et("itemContent"),o=et("computeItemKey"),s=et("isSeeking"),i=Bt("scrollHeight"),a=et("ItemComponent"),c=et("ListComponent"),u=et("ScrollSeekPlaceholder"),d=et("context"),f=Bt("itemDimensions"),h=Bt("gap"),g=et("log"),w=et("stateRestoreInProgress"),b=Bt("reportReadyState"),m=Fn(S.useMemo(()=>x=>{const v=x.parentElement.parentElement.scrollHeight;i(v);const y=x.firstChild;if(y){const{height:E,width:C}=y.getBoundingClientRect();f({height:E,width:C})}h({column:Pc("column-gap",getComputedStyle(x).columnGap,g),row:Pc("row-gap",getComputedStyle(x).rowGap,g)})},[i,f,h,g]),!0,!1);return bc(()=>{e.itemHeight>0&&e.itemWidth>0&&b(!0)},[e]),w?null:l.jsx(c,{className:t,ref:m,...bt(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const v=o(x.index,x.data,d);return s?l.jsx(u,{...bt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},v):S.createElement(a,{...bt(a,d),className:n,"data-index":x.index,key:v},r(x.index,x.data,d))})})}),xx=S.memo(function(){const e=et("HeaderComponent"),t=Bt("headerHeight"),n=et("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,!1),o=et("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null}),vx=S.memo(function(){const e=et("FooterComponent"),t=Bt("footerHeight"),n=et("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,!1),o=et("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null}),bx=({children:e})=>{const t=S.useContext(vc),n=Bt("itemDimensions"),r=Bt("viewportDimensions"),o=Fn(S.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return S.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:No(!1),children:e})},wx=({children:e})=>{const t=S.useContext(vc),n=Bt("windowViewportRect"),r=Bt("itemDimensions"),o=et("customScrollParent"),s=Ul(n,o,!1);return S.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:No(!1),children:e})},yx=S.memo(function({...e}){const t=et("useWindowScroll"),n=et("customScrollParent"),r=n||t?Cx:Sx,o=n||t?wx:bx,s=et("context");return l.jsx(r,{...e,...bt(r,s),children:l.jsxs(o,{children:[l.jsx(xx,{}),l.jsx(gx,{}),l.jsx(vx,{})]})})}),{useEmitter:Rc,useEmitterValue:et,usePublisher:Bt}=gc(mx,{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"}},yx),Sx=kc({useEmitter:Rc,useEmitterValue:et,usePublisher:Bt}),Cx=Tc({useEmitter:Rc,useEmitterValue:et,usePublisher:Bt});function Pc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,jt.WARN),t==="normal"?0:parseInt(t??"0",10)}const kx=ro.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 Si({className:e,variant:t,...n}){return l.jsx("div",{className:J(kx({variant:t}),e),...n})}function ce(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 Tx(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,c=p.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=p.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 on(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:g,...w}=f,b=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,m=p.useMemo(()=>w,Object.values(w));return l.jsx(b.Provider,{value:m,children:g})};u.displayName=s+"Provider";function d(f,h){var b;const g=((b=h==null?void 0:h[e])==null?void 0:b[c])||a,w=p.useContext(g);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=>p.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,Ex(o,...t)]}function Ex(...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:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ft=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},Ix=p[" useInsertionEffect ".trim().toString()]||ft;function Hn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Nx({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=p.useRef(e!==void 0);p.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=p.useCallback(d=>{var f;if(a){const h=Ax(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[c,u]}function Nx({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Ix(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Ax(e){return typeof e=="function"}function Oc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ci(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Oc(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():Oc(e[o],null)}}}}function Oe(...e){return p.useCallback(Ci(...e),e)}var jx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=jx.reduce((e,t)=>{const n=On.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Mc(e,t){e&&oo.flushSync(()=>e.dispatchEvent(t))}function _x(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var Dt=e=>{const{present:t,children:n}=e,r=Rx(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Oe(r.ref,Px(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};Dt.displayName="Presence";function Rx(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=_x(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=_o(r.current);s.current=a==="mounted"?u:"none"},[a]),ft(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,g=_o(u);e?c("MOUNT"):g==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),ft(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=g=>{const b=_o(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(c("ANIMATION_END"),!o.current)){const m=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=m)})}},h=g=>{g.target===t&&(s.current=_o(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 c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function _o(e){return(e==null?void 0:e.animationName)||"none"}function Px(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 Ox=p[" useId ".trim().toString()]||(()=>{}),Mx=0;function sn(e){const[t,n]=p.useState(Ox());return ft(()=>{n(r=>r??String(Mx++))},[e]),e||(t?`radix-${t}`:"")}var Ro="Collapsible",[Dx,CC]=on(Ro),[Lx,ki]=Dx(Ro),Dc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Hn({prop:r,defaultProp:o??!1,onChange:i,caller:Ro});return l.jsx(Lx,{scope:n,disabled:s,contentId:sn(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(Se.div,{"data-state":Ei(c),"data-disabled":s?"":void 0,...a,ref:t})})});Dc.displayName=Ro;var Lc="CollapsibleTrigger",$c=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ki(Lc,n);return l.jsx(Se.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ei(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ce(e.onClick,o.onOpenToggle)})});$c.displayName=Lc;var Ti="CollapsibleContent",$x=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ki(Ti,e.__scopeCollapsible);return l.jsx(Dt,{present:n||o.open,children:({present:s})=>l.jsx(Fx,{...r,ref:t,present:s})})});$x.displayName=Ti;var Fx=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ki(Ti,n),[a,c]=p.useState(r),u=p.useRef(null),d=Oe(t,u),f=p.useRef(0),h=f.current,g=p.useRef(0),w=g.current,b=i.open||a,m=p.useRef(b),x=p.useRef(void 0);return p.useEffect(()=>{const v=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(v)},[]),ft(()=>{const v=u.current;if(v){x.current=x.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const y=v.getBoundingClientRect();f.current=y.height,g.current=y.width,m.current||(v.style.transitionDuration=x.current.transitionDuration,v.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(Se.div,{"data-state":Ei(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!b,...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:b&&o})});function Ei(e){return e?"open":"closed"}var zx=Dc;const Fc=zx,zc=$c,Un=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Un.displayName="Card";const Wn=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("flex flex-col space-y-1.5 p-6",e),...t}));Wn.displayName="CardHeader";const ur=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:J("text-2xl font-semibold leading-none tracking-tight",e),...t}));ur.displayName="CardTitle";const Hr=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:J("text-sm text-muted-foreground",e),...t}));Hr.displayName="CardDescription";const Ur=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("p-6 pt-0",e),...t}));Ur.displayName="CardContent";const Po=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("flex items-center p-6 pt-0",e),...t}));Po.displayName="CardFooter";function Bc(){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 Vn=Bc();function Bx(e){Vn=e}const Hc=/[&<>"']/,Hx=new RegExp(Hc.source,"g"),Uc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Ux=new RegExp(Uc.source,"g"),Wx={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Wc=e=>Wx[e];function wt(e,t){if(t){if(Hc.test(e))return e.replace(Hx,Wc)}else if(Uc.test(e))return e.replace(Ux,Wc);return e}const Vx=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Vc(e){return e.replace(Vx,(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 qx=/(^|[^\[])\^/g;function Xe(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(qx,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Kx=/[^\w:]/g,Gx=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function qc(e,t,n){if(e){let r;try{r=decodeURIComponent(Vc(n)).replace(Kx,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Gx.test(n)&&(n=Zx(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Oo={},Yx=/^[^:]+:\/*[^/]*$/,Xx=/^([^:]+:)[\s\S]*$/,Jx=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Zx(e,t){Oo[" "+e]||(Yx.test(e)?Oo[" "+e]=e+"/":Oo[" "+e]=Do(e,"/",!0)),e=Oo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Xx,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Jx,"$1")+t:e+t}const Mo={exec:function(){}};function Kc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),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 Do(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 Qx(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 ev(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 Gc(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Yc(e,t,n,r){const o=t.href,s=t.title?wt(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:wt(i)}}function tv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
38
+ `)}const Bm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Hm(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 o=Xs(t.payload.messages),s={...e,messages:o,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(s.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(s.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:o.length,previousCount:e.messages.length,checkpointId:s.lastCheckpointId}),s}case"prepend":{const o=Xs(t.payload.messages);if(!o.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const s=new Set(e.messages.map(a=>a.id)),i=o.filter(a=>!s.has(a.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:i.length,duplicates:o.length-i.length,finalTotal:i.length+e.messages.length}),i.length?{...e,messages:[...i,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const o=t.payload.message;return e.messages.some(s=>s.id===o.id)?e:{...e,messages:[...e.messages,o]}}case"event":return Pl(e,t.payload.ev);case"batch":{const{events:o}=t.payload;return o.length?o.reduce((s,i)=>Pl(s,i),e):e}default:return e}}function Rl(e=[]){const[t,n]=S.useReducer(Hm,{...Bm,messages:e}),r=S.useRef([]),o=S.useRef(null),s=S.useRef(null),i=S.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=S.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]),c=S.useCallback(d=>{r.current.push(d),a()},[a]);S.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=S.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:c}),[c]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n;if(t.type==="message_start"&&t.role==="assistant"){const r=t.id,o=Km(t.model);if(e.messages.some(a=>a.id===r))return{...e,assemblingId:r};const i={id:r,role:"assistant",name:o||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:r,messages:[...e.messages,i]}}if(t.type==="message_delta"){const r=e.assemblingId??Js(e.messages);return r?{...e,messages:Zs(e.messages,r,t.delta)}:e}if(t.type==="message_end"){const r=e.assemblingId??Js(e.messages);if(!r)return{...e,assemblingId:null};const o=e.messages,s=o.findIndex(i=>i.id===r&&i.role==="assistant");if(s>=0&&!((n=o[s].content)==null?void 0:n.some(c=>{var u;return(c==null?void 0:c.type)==="text"&&((u=c.text)==null?void 0:u.trim())}))){const c=[...o.slice(0,s),...o.slice(s+1)];return{...e,assemblingId:null,messages:c}}return e}if(t.type==="tool_start"){const r=`tool-${t.id}`,o={type:"tool_call",id:t.id,name:t.name,args:t.args};if(e.messages.find(a=>a.id===r))return{...e,toolIndex:{...e.toolIndex,[t.id]:r}};const i={id:r,role:"tool",name:t.name,createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,i],toolIndex:{...e.toolIndex,[t.id]:r}}}if(t.type==="tool_result"){const r=e.toolIndex[t.id]??`tool-${t.id}`,o={type:"tool_result",toolCallId:t.id,output:t.output,error:t.error},s=e.messages.find(c=>c.id===r),i={id:r,role:"tool",content:[o],createdAt:new Date().toISOString()},a=s?Zs(e.messages,r,[o]):[...e.messages,i];return{...e,messages:a}}if(t.type==="checkpoint"){const r=t.checkpointNs??e.lastCheckpointNs??null,o=qm(e.messages,t.checkpointId,r);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:r,messages:o}}if(t.type==="branch"){const r=t.checkpointId??e.lastCheckpointId,o=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:r??null,lastCheckpointNs:o??null}}if(t.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,r]}}if(t.type==="interrupt"){const r=e.assemblingId??Js(e.messages),o={type:"interrupt",value:t.value};if(r)return{...e,assemblingId:null,messages:Zs(e.messages,r,[o]),pendingInterrupt:{id:t.id,value:t.value}};const s={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],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 Um(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 Wm(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 Wm(e,t,r=>({...r,content:Vm(r.content,n)}))}function Vm(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function qm(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 Um(e,r,s)}return e}function Km(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Gm(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 Ym(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 c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Xm(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await Ym(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Ol=S.createContext(null);function xo({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null,autoLoadInitial:s=!0,disableAutoRestore:i=!1,enableFileAgentRouting:a=!1,fileAgentId:c="invoice_reader"}){const u=wn;S.useEffect(()=>{t&&u.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[u,t]);const{isStreaming:d,error:f,stream:h,stop:g,setToken:w}=_l({baseUrl:u.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/runs/stream"}),[b,m]=S.useState(()=>typeof u.getAuthToken=="function"?u.getAuthToken():null);S.useEffect(()=>{w(typeof u.getAuthToken=="function"?u.getAuthToken():null);const L=u.onTokenChange(G=>{m(G),w(G)});return()=>{L()}},[u,w]);const x=S.useCallback(L=>{u.setAuthToken(L)},[u]),{state:v,seed:y,prepend:E,pushUser:C,onEvent:k,reset:I}=Rl(),N=20,[A,R]=S.useState(!1),[j,B]=S.useState(!1),[V,P]=S.useState(null),[Y,W]=S.useState(void 0),[q,F]=S.useState(void 0),D=S.useRef(!1),ue=S.useRef([]),X=S.useRef(null),ae=S.useCallback(L=>{L.cursor!==void 0&&P(L.cursor),L.hasMore!==void 0&&R(L.hasMore),L.checkpointId!==void 0&&W(L.checkpointId),L.checkpointNs!==void 0&&F(L.checkpointNs)},[]),$=S.useCallback((L,G)=>new Promise((ye,ze)=>{const he=async()=>{if(D.current){console.warn(`[ChatProvider] Operation "${G}" queued - another operation in progress`),ue.current.push(he);return}D.current=!0;try{console.log(`[ChatProvider] Executing operation: ${G}`),await L(),ye()}catch(Le){console.error(`[ChatProvider] Operation "${G}" failed:`,Le),ze(Le)}finally{D.current=!1;const Le=ue.current.shift();Le&&Le().catch(()=>{})}};D.current?(ue.current.push(he),console.log(`[ChatProvider] Queued operation: ${G}`)):he().catch(Le=>{ze(Le)})}),[]),Z=S.useCallback((L,G)=>{const ye=Array.isArray(L==null?void 0:L.messages)?L.messages:[];G==="replace"?(console.log("[ChatProvider] Replacing messages, count:",ye.length),y(ye,{checkpointId:(L==null?void 0:L.checkpointId)??null,checkpointNs:(L==null?void 0:L.checkpointNs)??null})):G==="prepend"&&ye.length?(console.log("[ChatProvider] Calling prepend with",ye.length,"messages"),E(ye)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),P((L==null?void 0:L.nextCursor)??null),R(!!(L!=null&&L.hasMore)),W(ze=>(L==null?void 0:L.checkpointId)??ze??void 0),F(ze=>(L==null?void 0:L.checkpointNs)??ze??void 0)},[y,E]),[Ne,be]=S.useState([]),[M,O]=S.useState(null),z=S.useCallback(async()=>{const L=await u.listThreads();be(L)},[u]),[ee,de]=S.useState(!1),le=S.useCallback(async L=>{const G=(L==null?void 0:L.maxAttempts)??5,ye=(L==null?void 0:L.baseDelayMs)??500,ze=(L==null?void 0:L.timeoutMs)??2e3;if(!u.baseUrl)return!1;const he=u.baseUrl.replace(/\/+$/,""),Le=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],ct=async yt=>{try{const Et=new AbortController,ht=setTimeout(()=>Et.abort(),ze),pt=await fetch(yt,{method:"GET",signal:Et.signal});return clearTimeout(ht),pt.ok}catch{return!1}},Pn=async yt=>{try{const Et=new AbortController,ht=setTimeout(()=>Et.abort(),ze),pt=await fetch(yt,{method:"HEAD",signal:Et.signal});return clearTimeout(ht),pt.ok}catch{return!1}};for(let yt=0;yt<G;yt++){console.debug(`[ChatProvider] health-check attempt ${yt+1}/${G}`);for(const ht of Le){let pt=ht;he.endsWith("/api")&&ht.startsWith("/api")&&(pt=ht.replace(/^\/api/,"")||"/");const hn=pt==="/"?he+"/":he+pt;if(console.debug(`[ChatProvider] checking ${hn}`),await ct(hn)||ht==="/"&&await Pn(he+"/"))return de(!0),!0}const Et=ye*Math.pow(2,yt);await new Promise(ht=>setTimeout(ht,Et))}return de(!1),!1},[u.baseUrl]);S.useEffect(()=>{let L=!0;if(!u.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const G=await le();if(!L)return;G?z().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{L=!1}},[z,u.baseUrl,le]),S.useEffect(()=>{r==null||r(M)},[M,r]);const Fe=S.useRef(null);S.useEffect(()=>{if(o&&s){if(!u.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!ee){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}Fe.current!==o&&(Fe.current=o,je(o).catch(()=>{}))}},[o,s,u.baseUrl,ee]);const Ge=S.useRef(null),Ce=S.useRef(null),je=S.useCallback(async(L,G,ye)=>{await $(async()=>{if(X.current===L){console.log(`[ChatProvider] Skipping auto-load for thread ${L} - suppressed after clear`),X.current=null;return}if(!u.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(Ge.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${Ge.current}) is loading`);return}Ce.current!==null&&Ce.current!==L&&(console.log(`[ChatProvider] Thread switch detected: ${Ce.current} -> ${L}`),I([])),Ge.current=L,Ce.current=L;try{ae({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),O(L);const he=await u.getMessages({threadId:L,checkpointId:G,checkpointNs:ye,limit:N}),Le=Array.isArray(he==null?void 0:he.messages)?he.messages:[];console.log("[ChatProvider] Loading thread with",Le.length,"messages"),y(Le,{checkpointId:(he==null?void 0:he.checkpointId)??null,checkpointNs:(he==null?void 0:he.checkpointNs)??null}),P((he==null?void 0:he.nextCursor)??null),R(!!(he!=null&&he.hasMore)),W(ct=>(he==null?void 0:he.checkpointId)??ct??void 0),F(ct=>(he==null?void 0:he.checkpointNs)??ct??void 0)}finally{Ge.current=null}},`loadThread-${L}`)},[u,$,ae,y]),He=S.useCallback(async L=>{const G=await u.listCheckpoints(L);return Gm(G,L)},[u]),Ue=S.useCallback(async(L,G)=>{await $(async()=>{if(!M)throw new Error("No active thread");ae({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0});const ye=await u.getMessages({threadId:M,checkpointId:L,checkpointNs:G??void 0,limit:N});Z(ye,"replace")},`navigateToCheckpoint-${L}`)},[u,M,Z,$,ae]),We=S.useCallback(async()=>{if(!M)throw new Error("No active thread");await je(M)},[M,je]),it=S.useRef(!1);S.useEffect(()=>{const L=it.current;it.current=d,L&&!d&&M&&$(async()=>{try{await z()}catch(G){console.warn("[ChatProvider] Post-streaming thread refresh failed:",G)}},"postStreamingRefresh")},[d,M,u,Z,z,$]);const nt=S.useCallback(async()=>{console.log("[ChatProvider] 🔄 clearCurrentThread called"),console.log("[ChatProvider] 📊 Before clear - currentThreadId:",M),console.log("[ChatProvider] 📊 Before clear - messages count:",v.messages.length),M&&(X.current=M,console.log(`[ChatProvider] 🚫 Suppressing next auto-load for thread: ${M}`)),await $(()=>(console.log("[ChatProvider] 🚀 Executing atomic clear operation"),O(null),I([]),ae({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),typeof window<"u"&&localStorage.removeItem("currentThreadId"),console.log("[ChatProvider] ✅ Atomic clear operation completed"),Promise.resolve()),"clearCurrentThread"),console.log("[ChatProvider] 📊 After clear - currentThreadId should be null")},[I,ae,M,v.messages.length,$]),Tt=S.useCallback(async L=>{nt();const G=await u.createThread(L);return await z(),await je(G.threadId),G.threadId},[u,z,je,nt]),gt=S.useCallback(async L=>{await u.deleteThread(L),await z(),M===L&&(O(null),I([]),R(!1),P(null),W(void 0),F(void 0))},[u,z,M,I]),rt=S.useCallback(async(L,G)=>{await u.updateThread(L,G),await z()},[u,z]),Ve=S.useCallback(async(L,G)=>{var nr;const ye=(G==null?void 0:G.attachments)||[],{contentParts:ze,filesInfo:he}=await Xm(u,ye,t==null?void 0:t.uploadPath),Le=[];L&&L.trim()&&Le.push({type:"text",text:L.trim()});const ct={id:((nr=crypto.randomUUID)==null?void 0:nr.call(crypto))||`user-${Date.now()}`,role:"user",content:Le,createdAt:new Date().toISOString(),checkpointId:(G==null?void 0:G.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(G==null?void 0:G.checkpointNs)??v.lastCheckpointNs??void 0};C(ct);const Pn={...ct,content:Le},yt={...(G==null?void 0:G.payloadExtras)??{}},Et=!!yt.edit,ht=yt.originalMessageId,pt=typeof ht=="string"?ht:void 0,hn=ye&&ye.length>0,tr={...M?{threadId:M}:{},payload:{messages:[Pn],files_info:he,...a&&hn&&c?{active_agent:c}:{},...yt},checkpointId:(G==null?void 0:G.checkpointId)??v.lastCheckpointId??void 0,checkpointNs:(G==null?void 0:G.checkpointNs)??v.lastCheckpointNs??void 0,nodeFilter:G==null?void 0:G.nodeFilter,config:G==null?void 0:G.config,edit:Et,originalMessageId:pt};h(tr,St=>{if(St.type==="thread_info"&&St.threadId){const pn=St.threadId,te=!!St.created,pe=!!St.ready;if(M!==pn){const Re=!M&&v.messages.length<=1;Re&&(X.current=pn),O(pn),(pe||te||Re)&&z().catch(()=>{})}else(pe||te)&&z().catch(()=>{})}k(St)},{onError:St=>console.warn("stream error",St),onOpen:({threadId:St,created:pn})=>{if(!M&&St){const te=v.messages.length<=1;te&&(X.current=St),O(St),(pn||te)&&z().catch(()=>{})}}})},[M,C,h,k,v.lastCheckpointId,v.lastCheckpointNs,u,t==null?void 0:t.uploadPath,z,O,a,c,v.messages.length]),Q=S.useCallback(async L=>{if(!M)throw new Error("No active thread");if(j||!A)return;const G=V;if(G){B(!0);try{const ye=await u.getMessages({threadId:M,checkpointId:Y,checkpointNs:q,limit:(L==null?void 0:L.limit)??N,beforeId:G});Z(ye,"prepend")}finally{B(!1)}}},[u,M,Y,q,V,A,j,Z,N]),ne=S.useCallback(async(L,G,ye)=>{if(!M)throw new Error("No active thread to handle interrupt");try{console.log(`[ChatProvider] Handling interrupt ${L}: ${G?"approved":"rejected"}`);const ze=G?ye:{rejected:!0,interruptId:L};await u.resume({threadId:M,value:ze}),console.log(`[ChatProvider] Interrupt ${L} handled successfully`)}catch(ze){throw console.error(`[ChatProvider] Failed to handle interrupt ${L}:`,ze),ze}},[u,M]),xe={baseUrl:u.baseUrl,token:b,setToken:x,api:u,threads:Ne,currentThreadId:M,setCurrentThreadId:O,messages:v.messages,isStreaming:d,error:f,lastCheckpointId:v.lastCheckpointId,lastCheckpointNs:v.lastCheckpointNs,streamingAssistantId:v.assemblingId,hasMoreHistory:A,isLoadingHistory:j,loadOlderMessages:Q,historyPageSize:N,listCheckpoints:He,navigateToCheckpoint:Ue,returnToLatest:We,refreshThreads:z,createThread:Tt,deleteThread:gt,renameThread:rt,loadThread:je,clearCurrentThread:nt,send:Ve,stop:g,handleInterrupt:ne};return l.jsx(Ol.Provider,{value:xe,children:e})}function _r(){const e=S.useContext(Ol);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function J(...e){return pp.twMerge(hp.clsx(e))}const Jm=ro.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"}}),Pe=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?On.Slot:"button";return l.jsx(i,{className:J(Jm({variant:t,size:n,className:e})),ref:s,...o})});Pe.displayName="Button";const Ml=p.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:J("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}));Ml.displayName="Textarea";function Zm({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,g]=S.useState(e),[w,b]=S.useTransition(),m=S.useRef(null);S.useEffect(()=>{g(e??""),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const N=m.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const v=S.useCallback(async N=>{N&&N.preventDefault();const A=(h??"").trim();!A&&!f||b(()=>{try{const R=i(A);R&&typeof R.then=="function"?R.then(()=>{g(""),m.current&&(m.current.style.height="auto")}).catch(()=>{}):(g(""),m.current&&(m.current.style.height="auto"))}catch{}})},[h,i,f]),y=S.useCallback(N=>{g(N.target.value),m.current&&(m.current.style.height="auto",m.current.style.height=`${m.current.scrollHeight}px`)},[]),E=S.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),v()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[v,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 l.jsx("form",{onSubmit:N=>void v(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Ml,{ref:m,value:h,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(Pe,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(se.Square,{size:16})}):l.jsx(Pe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:l.jsx(se.Send,{size:16})})})]})})}const Qm=S.memo(Zm),vo=0,yn=1,ar=2,Dl=4;function Ll(e){return()=>e}function eg(e){e()}function $l(e,t){return n=>e(t(n))}function Fl(e,t){return()=>e(t)}function tg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function ng(...e){return()=>{e.map(eg)}}function lr(){}function bo(e,t){return t(e),e}function rg(e,t){return t(e)}function Ze(...e){return e}function qe(e,t){return e(yn,t)}function Ae(e,t){e(vo,t)}function ei(e){e(ar)}function st(e){return e(Dl)}function fe(e,t){return qe(e,tg(t,vo))}function Gt(e,t){const n=e(yn,r=>{n(),t(r)});return n}function zl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Bl(e,t){return e===t}function Qe(e=Bl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function we(e){return t=>n=>{e(n)&&t(n)}}function oe(e){return t=>$l(t,e)}function tn(e){return t=>()=>{t(e)}}function H(e,...t){const n=og(...t);return(r,o)=>{switch(r){case ar:ei(e);return;case yn:return qe(e,n(o))}}}function nn(e,t){return n=>r=>{n(t=e(t,r))}}function $n(e){return t=>n=>{e>0?e--:t(n)}}function gn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function _e(...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);qe(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function og(...e){return t=>e.reduceRight(rg,t)}function sg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case yn:return s?n===s?void 0:(r(),n=s,t=qe(e,s),t):(r(),lr);case ar:r(),n=null;return}}}function K(e){let t=e;const n=De();return(r,o)=>{switch(r){case vo:t=o;break;case yn:{o(t);break}case Dl:return t}return n(r,o)}}function vt(e,t){return bo(K(t),n=>fe(e,n))}function De(){const e=[];return(t,n)=>{switch(t){case vo:e.slice().forEach(r=>{r(n)});return;case ar:e.splice(0,e.length);return;case yn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ot(e){return bo(De(),t=>fe(e,t))}function Be(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:ig(),singleton:n}}const ig=()=>Symbol();function ag(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(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function lt(...e){const t=De(),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);qe(s,c=>{n[i]=c,r=r|a,r===o&&Ae(t,n)})}),function(s,i){switch(s){case ar:{ei(t);return}case yn:return r===o&&i(n),qe(t,i)}}}function ve(e,t=Bl){return H(e,Qe(t))}function ti(...e){return function(t,n){switch(t){case ar:return;case yn:return ng(...e.map(r=>qe(r,n)))}}}var jt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(jt||{});const lg={0:"debug",3:"error",1:"log",2:"warn"},cg=()=>typeof globalThis>"u"?window:globalThis,Sn=Be(()=>{const e=K(3);return{log:K((t,n,r=1)=>{var o;const s=(o=cg().VIRTUOSO_LOG_LEVEL)!=null?o:st(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 Fn(e,t,n){return ni(e,t,n).callbackRef}function ni(e,t,n){const r=S.useRef(null);let o=i=>{};const s=S.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};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 ug(e,t,n,r,o,s,i,a,c){const u=S.useCallback(d=>{const f=dg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const g=h.lastElementChild.dataset.viewportType==="window";let w;g&&(w=h.ownerDocument.defaultView);const b=i?a?i.scrollLeft:i.scrollTop:g?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,m=i?a?i.scrollWidth:i.scrollHeight:g?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:g?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:m,scrollTop:Math.max(b,0),viewportHeight:x}),s==null||s(a?Hl("column-gap",getComputedStyle(d).columnGap,o):Hl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,c)}function dg(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 c=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},jt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Hl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,jt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ul(e,t,n){const r=S.useRef(null),o=S.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,h;if(t){const g=t.getBoundingClientRect(),w=u.top-g.top;h=g.height-Math.max(0,w),f=w+t.scrollTop}else{const g=i.current.ownerDocument.defaultView;h=g.innerHeight-Math.max(0,u.top),f=u.top+g.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var c;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=(c=i.current)==null?void 0:c.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 Ct=Be(()=>{const e=De(),t=De(),n=K(0),r=De(),o=K(0),s=De(),i=De(),a=K(0),c=K(0),u=K(0),d=K(0),f=De(),h=De(),g=K(!1),w=K(!1),b=K(!1);return fe(H(e,oe(({scrollTop:m})=>m)),t),fe(H(e,oe(({scrollHeight:m})=>m)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:g,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:b,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Rr={lvl:0};function Wl(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:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ye(e){return e===Rr}function Pr(e,t){if(!Ye(e))return t===e.k?e.v:t<e.k?Pr(e.l,t):Pr(e.r,t)}function Yt(e,t,n="k"){if(Ye(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Yt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Yt(e.l,t,n)}function Mt(e,t,n){return Ye(e)?Kl(t,n,1):t===e.k?dt(e,{k:t,v:n}):t<e.k?Gl(dt(e,{l:Mt(e.l,t,n)})):Gl(dt(e,{r:Mt(e.r,t,n)}))}function cr(){return Rr}function wo(e,t,n){if(Ye(e))return[];const r=Yt(e,t)[0];return fg(oi(e,r,n))}function ri(e,t){if(Ye(e))return Rr;const{k:n,l:r,r:o}=e;if(t===n){if(Ye(r))return o;if(Ye(o))return r;{const[s,i]=ql(r);return yo(dt(e,{k:s,l:Vl(r),v:i}))}}else return t<n?yo(dt(e,{l:ri(r,t)})):yo(dt(e,{r:ri(o,t)}))}function zn(e){return Ye(e)?[]:[...zn(e.l),{k:e.k,v:e.v},...zn(e.r)]}function oi(e,t,n){if(Ye(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oi(s,t,n))),a}function yo(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(si(t))return Yl(dt(e,{lvl:n-1}));if(!Ye(t)&&!Ye(t.r))return dt(t.r,{l:dt(t,{r:t.r.l}),lvl:n,r:dt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(dt(e,{lvl:n-1}));if(!Ye(r)&&!Ye(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return dt(o,{l:dt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(dt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function dt(e,t){return Kl(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 Vl(e){return Ye(e.r)?e.l:yo(dt(e,{r:Vl(e.r)}))}function si(e){return Ye(e)||e.lvl>e.r.lvl}function ql(e){return Ye(e.r)?[e.k,e.v]:ql(e.r)}function Kl(e,t,n,r=Rr,o=Rr){return{k:e,l:r,lvl:n,r:o,v:t}}function Gl(e){return ii(Yl(e))}function Yl(e){const{l:t}=e;return!Ye(t)&&t.lvl===e.lvl?dt(t,{r:dt(e,{l:t.r})}):e}function ii(e){const{lvl:t,r:n}=e;return!Ye(n)&&!Ye(n.r)&&n.lvl===t&&n.r.lvl===t?dt(n,{l:dt(e,{r:n.l}),lvl:t+1}):e}function fg(e){return Wl(e,({k:t,v:n})=>({index:t,value:n}))}function Xl(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Or(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=Be(()=>({recalcInProgress:K(!1)}),[],{singleton:!0});function Jl(e,t,n){return e[So(e,t,n)]}function So(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=So(e,t,r),s=So(e,n,r,o);return e.slice(o,s+1)}function Cn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Co(e){return!Ye(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function pg(){return{groupIndices:[],groupOffsetTree:cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:cr()}}function mg(e,t){let n=Ye(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ye(e)){e=Mt(e,0,s);continue}const a=wo(e,i-1,o+1);if(a.some(Sg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:h}of a)c?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,c=!0),d>o&&o>=f&&h!==s&&(e=Mt(e,o+1,h));u&&(e=Mt(e,i,s))}return[e,n]}function gg(e){return typeof e.groupIndex<"u"}function xg({offset:e},t){return t===e?0:t<e?-1:1}function Mr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Jl(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Zl(e,t){if(!Co(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ql(e,t,n){if(gg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Zl(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function vg(e,t,n,r=0){return r>0&&(t=Math.max(t,Jl(e,r,li).offset)),Wl(hg(e,t,n,xg),yg)}function bg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,jt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ye(s)&&t.length===2){const h=t[0].size,g=t[1].size;i=n.reduce((w,b)=>Mt(Mt(w,b,h),b+1,g),i)}else[i,a]=mg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,g)=>Mt(h,g,Mr(g,f,o)),cr()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function wg(e){return zn(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 ec(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 ci(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=So(o,t-1,li),a=o[c].offset;const u=Yt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Yt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of wo(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 yg(e){return{index:e.index,value:e}}function Sg(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 Cg={offsetHeight:"height",offsetWidth:"width"},rn=Be(([{log:e},{recalcInProgress:t}])=>{const n=De(),r=De(),o=vt(r,0),s=De(),i=De(),a=K(0),c=K([]),u=K(void 0),d=K(void 0),f=K((C,k)=>Cn(C,Cg[k])),h=K(void 0),g=K(0),w=pg(),b=vt(H(n,_e(c,e,g),nn(bg,w),Qe()),w),m=vt(H(c,Qe(),nn((C,k)=>({current:k,prev:C.current}),{current:[],prev:[]}),oe(({prev:C})=>C)),[]);fe(H(c,we(C=>C.length>0),_e(b,g),oe(([C,k,I])=>{const N=C.reduce((A,R,j)=>Mt(A,R,Mr(R,k.offsetTree,I)||j),cr());return{...k,groupIndices:C,groupOffsetTree:N}})),b),fe(H(r,_e(b),we(([C,{lastIndex:k}])=>C<k),oe(([C,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:C}])),n),fe(u,d);const x=vt(H(u,oe(C=>C===void 0)),!0);fe(H(d,we(C=>C!==void 0&&Ye(st(b).sizeTree)),oe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const v=Ot(H(n,_e(b),nn(({sizes:C},[k,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),oe(C=>C.changed)));qe(H(a,nn((C,k)=>({diff:C.prev-k,prev:k}),{diff:0,prev:0}),oe(C=>C.diff)),C=>{const{groupIndices:k}=st(b);if(C>0)Ae(t,!0),Ae(s,C+ec(C,k));else if(C<0){const I=st(m);I.length>0&&(C-=ec(-C,I)),Ae(i,C)}}),qe(H(a,_e(e)),([C,k])=>{C<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},jt.ERROR)});const y=Ot(s);fe(H(s,_e(b),oe(([C,k])=>{const I=k.groupIndices.length>0,N=[],A=k.lastSize;if(I){const R=Pr(k.sizeTree,0);let j=0,B=0;for(;j<C;){const P=k.groupIndices[B],Y=k.groupIndices.length===B+1?1/0:k.groupIndices[B+1]-P-1;N.push({endIndex:P,size:R,startIndex:P}),N.push({endIndex:P+1+Y-1,size:A,startIndex:P+1}),B++,j+=Y+1}const V=zn(k.sizeTree);return j!==C&&V.shift(),V.reduce((P,{k:Y,v:W})=>{let q=P.ranges;return P.prevSize!==0&&(q=[...P.ranges,{endIndex:Y+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:Y+C,prevSize:W,ranges:q}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return zn(k.sizeTree).reduce((R,{k:j,v:B})=>({prevIndex:j+C,prevSize:B,ranges:[...R.ranges,{endIndex:j+C-1,size:R.prevSize,startIndex:R.prevIndex}]}),{prevIndex:0,prevSize:A,ranges:[]}).ranges})),n);const E=Ot(H(i,_e(b,g),oe(([C,{offsetTree:k},I])=>{const N=-C;return Mr(N,k,I)})));return fe(H(i,_e(b,g),oe(([C,k,I])=>{if(k.groupIndices.length>0){if(Ye(k.sizeTree))return k;let N=cr();const A=st(m);let R=0,j=0,B=0;for(;R<-C;){B=A[j];const V=A[j+1]-B-1;j++,R+=V+1}if(N=zn(k.sizeTree).reduce((V,{k:P,v:Y})=>Mt(V,Math.max(0,P+C),Y),N),R!==-C){const V=Pr(k.sizeTree,B);N=Mt(N,0,V);const P=Yt(k.sizeTree,-C+1)[1];N=Mt(N,1,P)}return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}else{const N=zn(k.sizeTree).reduce((A,{k:R,v:j})=>Mt(A,Math.max(0,R+C),j),cr());return{...k,sizeTree:N,...ci(k.offsetTree,0,N,I)}}})),b),{beforeUnshiftWith:y,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:g,groupIndices:c,itemSize:f,listRefresh:v,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Ze(Sn,ai),{singleton:!0});function kg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const tc=Be(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=De(),i=De(),a=Ot(H(s,oe(kg)));return fe(H(a,oe(c=>c.totalCount)),n),fe(H(a,oe(c=>c.groupIndices)),e),fe(H(lt(o,t,r),we(([c,u])=>Co(u)),oe(([c,u,d])=>Yt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),Qe(),oe(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Ze(rn,Ct)),kn=Be(([{log:e}])=>{const t=K(!1),n=Ot(H(t,we(r=>r),Qe()));return qe(t,r=>{r&&st(e)("props updated",{},jt.DEBUG)}),{didMount:n,propsReady:t}},Ze(Sn),{singleton:!0}),Tg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function nc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Tg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Dr=Be(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const g=De(),w=De(),b=K(0);let m=null,x=null,v=null;function y(){m&&(m(),m=null),v&&(v(),v=null),x&&(clearTimeout(x),x=null),Ae(c,!1)}return fe(H(g,_e(n,f,r,b,a,i,h),_e(e,s,o),oe(([[E,C,k,I,N,A,R,j],B,V,P])=>{const Y=nc(E),{align:W,behavior:q,offset:F}=Y,D=I-1,ue=Ql(Y,C,D);let X=Mr(ue,C.offsetTree,B)+A;W==="end"?(X+=V+Yt(C.sizeTree,ue)[1]-k+P,ue===D&&(X+=R)):W==="center"?X+=(V+Yt(C.sizeTree,ue)[1]-k+P)/2:X-=N,F&&(X+=F);const ae=$=>{y(),$?(j("retrying to scroll to",{location:E},jt.DEBUG),Ae(g,E)):(Ae(w,!0),j("list did not change, scroll successful",{},jt.DEBUG))};if(y(),q==="smooth"){let $=!1;v=qe(t,Z=>{$=$||Z}),m=Gt(d,()=>{ae($)})}else m=Gt(H(t,Eg(150)),ae);return x=setTimeout(()=>{y()},1200),Ae(c,!0),j("scrolling from index to",{behavior:q,index:ue,top:X},jt.DEBUG),{behavior:q,top:X}})),u),{scrollTargetReached:w,scrollToIndex:g,topListHeight:b}},Ze(rn,Ct,Sn),{singleton:!0});function Eg(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ui(e,t){e==0?t():requestAnimationFrame(()=>{ui(e-1,t)})}function di(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Lr=Be(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=K(!0),c=K(0),u=K(!0);return fe(H(i,_e(c),we(([d,f])=>!!f),tn(!1)),a),fe(H(i,_e(c),we(([d,f])=>!!f),tn(!1)),u),qe(H(lt(t,i),_e(a,n,e,u),we(([[,d],f,{sizeTree:h},g,w])=>d&&(!Ye(h)||Qs(g))&&!f&&!w),_e(c)),([,d])=>{Gt(o,()=>{Ae(u,!0)}),ui(4,()=>{Gt(r,()=>{Ae(a,!0)}),Ae(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Ze(rn,Ct,Dr,kn),{singleton:!0});function rc(e,t){return Math.abs(e-t)<1.01}const $r="up",Fr="down",Ig="none",Ng={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ag=0,zr=Be(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=K(!1),a=K(!0),c=De(),u=De(),d=K(4),f=K(Ag),h=vt(H(ti(H(ve(o),$n(1),tn(!0)),H(ve(o),$n(1),tn(!1),zl(100))),Qe()),!1),g=vt(H(ti(H(n,tn(!0)),H(n,tn(!1),zl(200))),Qe()),!1);fe(H(lt(ve(o),ve(f)),oe(([v,y])=>v<=y),Qe()),a),fe(H(a,gn(50)),u);const w=Ot(H(lt(r,ve(s),ve(t),ve(e),ve(d)),nn((v,[{scrollHeight:y,scrollTop:E},C,k,I,N])=>{const A=E+C-y>-N,R={scrollHeight:y,scrollTop:E,viewportHeight:C};if(A){let B,V;return E>v.state.scrollTop?(B="SCROLLED_DOWN",V=v.state.scrollTop-E):(B="SIZE_DECREASED",V=v.state.scrollTop-E||v.scrollTopDelta),{atBottom:!0,atBottomBecause:B,scrollTopDelta:V,state:R}}let j;return R.scrollHeight>v.state.scrollHeight?j="SIZE_INCREASED":C<v.state.viewportHeight?j="VIEWPORT_HEIGHT_DECREASING":E<v.state.scrollTop?j="SCROLLING_UPWARDS":j="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:j,state:R}},Ng),Qe((v,y)=>v&&v.atBottom===y.atBottom))),b=vt(H(r,nn((v,{scrollHeight:y,scrollTop:E,viewportHeight:C})=>{if(rc(v.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const k=y-(E+C)<1;return v.scrollTop!==E&&k?{changed:!0,jump:v.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(v=>v.changed),oe(v=>v.jump)),0);fe(H(w,oe(v=>v.atBottom)),i),fe(H(i,gn(50)),c);const m=K(Fr);fe(H(r,oe(({scrollTop:v})=>v),Qe(),nn((v,y)=>st(g)?{direction:v.direction,prevScrollTop:y}:{direction:y<v.prevScrollTop?$r:Fr,prevScrollTop:y},{direction:Fr,prevScrollTop:0}),oe(v=>v.direction)),m),fe(H(r,gn(50),tn(Ig)),m);const x=K(0);return fe(H(h,we(v=>!v),tn(0)),x),fe(H(o,gn(100),_e(h),we(([v,y])=>!!y),nn(([v,y],[E])=>[y,E],[0,0]),oe(([v,y])=>y-v)),x),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:b,scrollDirection:m,scrollVelocity:x}},Ze(Ct)),ko="top",To="bottom",oc="none";function sc(e,t,n){return typeof e=="number"?n===$r&&t===ko||n===Fr&&t===To?e:0:n===$r?t===ko?e.main:e.reverse:t===To?e.main:e.reverse}function ic(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=Be(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=De(),i=K(0),a=K(0),c=K(0),u=vt(H(lt(ve(r),ve(o),ve(n),ve(s,Or),ve(c),ve(i),ve(t),ve(e),ve(a)),oe(([d,f,h,[g,w],b,m,x,v,y])=>{const E=d-v,C=m+x,k=Math.max(h-E,0);let I=oc;const N=ic(y,ko),A=ic(y,To);return g-=v,g+=h+x,w+=h+x,w-=v,g>d+C-N&&(I=$r),w<d-k+f+A&&(I=Fr),I!==oc?[Math.max(E-h-sc(b,ko,I)-N,0),E-k-x+f+sc(b,To,I)+A]:null}),we(d=>d!=null),Qe(Or)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Ze(Ct),{singleton:!0});function jg(e,t,n){if(Co(t)){const r=Zl(e,t);return[{index:Yt(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 hi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Eo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const b=e[e.length-1];d=b.offset+b.size}const f=n-i,h=a+f*c+(f-1)*r,g=u,w=h-d;return{bottom:d,firstItemIndex:s,items:lc(e,o,s),offsetBottom:w,offsetTop:u,top:g,topItems:lc(t,o,s),topListHeight:t.reduce((b,m)=>m.size+b,0),totalCount:n}}function ac(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,c=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return Eo(u,[],a,o,n,r)}function lc(e,t,n){if(e.length===0)return[];if(!Co(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=wo(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Bn=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:g},{recalcInProgress:w}])=>{const b=K([]),m=K(0),x=De();fe(s.topItemsIndexes,b);const v=vt(H(lt(g,w,ve(c,Or),ve(o),ve(r),ve(u),d,ve(b),ve(t),ve(n),e),we(([k,I,,N,,,,,,,A])=>{const R=A&&A.length!==N;return k&&!I&&!R}),oe(([,,[k,I],N,A,R,j,B,V,P,Y])=>{const W=A,{offsetTree:q,sizeTree:F}=W,D=st(m);if(N===0)return{...hi,totalCount:N};if(k===0&&I===0)return D===0?{...hi,totalCount:N}:ac(D,R,A,V,P,Y||[]);if(Ye(F))return D>0?null:Eo(jg(di(R,N),W,Y),[],N,P,W,V);const ue=[];if(B.length>0){const Ne=B[0],be=B[B.length-1];let M=0;for(const O of wo(F,Ne,be)){const z=O.value,ee=Math.max(O.start,Ne),de=Math.min(O.end,be);for(let le=ee;le<=de;le++)ue.push({data:Y==null?void 0:Y[le],index:le,offset:M,size:z}),M+=z}}if(!j)return Eo([],ue,N,P,W,V);const X=B.length>0?B[B.length-1]+1:0,ae=vg(q,k,I,X);if(ae.length===0)return null;const $=N-1,Z=bo([],Ne=>{for(const be of ae){const M=be.value;let O=M.offset,z=be.start;const ee=M.size;if(M.offset<k){z+=Math.floor((k-M.offset+P)/(ee+P));const le=z-be.start;O+=le*ee+le*P}z<X&&(O+=(X-z)*ee,z=X);const de=Math.min(be.end,$);for(let le=z;le<=de&&!(O>=I);le++)Ne.push({data:Y==null?void 0:Y[le],index:le,offset:O,size:ee}),O+=ee+P}});return Eo(Z,ue,N,P,W,V)}),we(k=>k!==null),Qe()),hi);fe(H(e,we(Qs),oe(k=>k==null?void 0:k.length)),o),fe(H(v,oe(k=>k.topListHeight)),f),fe(f,a),fe(H(v,oe(k=>[k.top,k.bottom])),i),fe(H(v,oe(k=>k.items)),x);const y=Ot(H(v,we(({items:k})=>k.length>0),_e(o,e),we(([{items:k},I])=>k[k.length-1].originalIndex===I-1),oe(([,k,I])=>[k-1,I]),Qe(Or),oe(([k])=>k))),E=Ot(H(v,gn(200),we(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),oe(({items:k})=>k[0].index),Qe())),C=Ot(H(v,we(({items:k})=>k.length>0),oe(({items:k})=>{let I=0,N=k.length-1;for(;k[I].type==="group"&&I<N;)I++;for(;k[N].type==="group"&&N>I;)N--;return{endIndex:k[N].index,startIndex:k[I].index}}),Qe(Xl)));return{endReached:y,initialItemCount:m,itemsRendered:x,listState:v,rangeChanged:C,startReached:E,topItemsIndexes:b,...h}},Ze(rn,tc,fi,Lr,Dr,zr,kn,ai),{singleton:!0}),cc=Be(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=De(),i=vt(H(lt(n,e,r,t,o),oe(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return fe(ve(i),s),{totalListHeight:i,totalListHeightChanged:s}},Ze(Ct,Bn),{singleton:!0}),_g=Be(([{viewportHeight:e},{totalListHeight:t}])=>{const n=K(!1),r=vt(H(lt(n,e,t),we(([o])=>o),oe(([,o,s])=>Math.max(0,o-s)),gn(0),Qe()),0);return{alignToBottom:n,paddingTopAddition:r}},Ze(Ct,cc),{singleton:!0}),uc=Be(()=>({context:K(null)})),Rg=({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,dc=Be(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=De();return fe(H(d,_e(t,c,n,s,o,r,a),_e(e),oe(([[f,h,g,w,b,m,x,v],y])=>{const{align:E,behavior:C,calculateViewLocation:k=Rg,done:I,...N}=f,A=Ql(f,h,w-1),R=Mr(A,h.offsetTree,y)+b+m,j=R+Yt(h.sizeTree,A)[1],B=v+m,V=v+g-x,P=k({itemBottom:j,itemTop:R,locationParams:{align:E,behavior:C,...N},viewportBottom:V,viewportTop:B});return P?I&&Gt(H(i,we(Y=>!Y),$n(st(i)?1:2)),I):I&&I(),P}),we(f=>f!==null)),u),{scrollIntoView:d}},Ze(rn,Ct,Dr,Bn,Sn),{singleton:!0});function fc(e){return e?e==="smooth"?"smooth":"auto":!1}const Pg=(e,t)=>typeof e=="function"?fc(e(t)):t&&fc(e),Og=Be(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:g}])=>{const w=K(!1),b=De();let m=null;function x(C){Ae(i,{align:"end",behavior:C,index:"LAST"})}qe(H(lt(H(ve(t),$n(1)),c),_e(ve(w),s,a,f),oe(([[C,k],I,N,A,R])=>{let j=k&&A,B="auto";return j&&(B=Pg(I,N||R),j=j&&!!B),{followOutputBehavior:B,shouldFollow:j,totalCount:C}}),we(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:k})=>{m&&(m(),m=null),st(n)?requestAnimationFrame(()=>{st(d)("following output to ",{totalCount:k},jt.DEBUG),x(C)}):m=Gt(e,()=>{st(d)("following output to ",{totalCount:k},jt.DEBUG),x(C),m=null})});function v(C){const k=Gt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!m&&(st(d)("scrolling to bottom due to increased size",{},jt.DEBUG),x("auto"))});setTimeout(k,100)}qe(H(lt(ve(w),t,u),we(([C,,k])=>C&&k),nn(({value:C},[,k])=>({refreshed:C===k,value:k}),{refreshed:!1,value:0}),we(({refreshed:C})=>C),_e(w,t)),([,C])=>{st(a)&&v(C!==!1)}),qe(b,()=>{v(st(w)!==!1)}),qe(lt(ve(w),o),([C,k])=>{C&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=K(null),E=De();return fe(ti(H(ve(r),oe(C=>{var k;return(k=C==null?void 0:C.length)!=null?k:0})),H(ve(t))),E),qe(H(lt(H(E,$n(1)),c),_e(ve(y),a,f,h),oe(([[C,k],I,N,A,R])=>k&&N&&(I==null?void 0:I({context:R,totalCount:C,scrollingInProgress:A}))),we(C=>!!C),gn(0)),C=>{m&&(m(),m=null),st(n)?requestAnimationFrame(()=>{st(d)("scrolling into view",{}),Ae(g,C)}):m=Gt(e,()=>{st(d)("scrolling into view",{}),Ae(g,C),m=null})}),{autoscrollToBottom:b,followOutput:w,scrollIntoViewOnChange:y}},Ze(rn,zr,Dr,Lr,kn,Sn,Ct,uc,dc)),Mg=Be(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(H(a,_e(s),we(([,c])=>c!==0),_e(o,r,t,n,e),oe(([[,c],u,d,f,h,g=[]])=>ac(c,u,d,f,h,g))),i),{}),Ze(rn,Lr,Bn,kn),{singleton:!0}),Dg=Be(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=K(0);return qe(H(e,_e(r),we(([,o])=>o!==0),oe(([,o])=>({top:o}))),o=>{Gt(H(n,$n(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(t,o)})})}),{initialScrollTop:r}},Ze(kn,Ct,Bn),{singleton:!0}),hc=Be(([{scrollVelocity:e}])=>{const t=K(!1),n=De(),r=K(!1);return fe(H(e,_e(r,t,n),we(([o,s])=>!!s),oe(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),Qe()),t),qe(H(lt(t,e,n),_e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Ze(zr),{singleton:!0}),pi=Be(([{scrollContainerState:e,scrollTo:t}])=>{const n=De(),r=De(),o=De(),s=K(!1),i=K(void 0);return fe(H(lt(n,r),oe(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),fe(H(t,_e(r),oe(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Ze(Ct)),Lg=Be(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=De(),d=K(void 0),f=K(null),h=K(null);return fe(a,f),fe(c,h),qe(H(u,_e(t,r,i,f,h,n)),([g,w,b,m,x,v,y])=>{const E=wg(w.sizeTree);m&&x!==null&&v!==null&&(b=x.scrollTop-v.offsetTop),b-=y,g({ranges:E,scrollTop:b})}),fe(H(d,we(Qs),oe($g)),o),fe(H(s,_e(d),we(([,g])=>g!==void 0),Qe(),oe(([,g])=>g.ranges)),e),{getState:u,restoreStateFrom:d}},Ze(rn,Ct,Lr,kn,pi));function $g(e){return{align:"start",index:0,offset:e.scrollTop}}const Fg=Be(([{topItemsIndexes:e}])=>{const t=K(0);return fe(H(t,we(n=>n>=0),oe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Ze(Bn));function pc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const zg=pc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Bg=Be(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:g},{recalcInProgress:w}])=>{const b=Ot(H(c,_e(i),nn(([,x,v,y],[{bottom:E,items:C,offsetBottom:k,totalCount:I},N])=>{const A=E+k;let R=0;return v===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(R=A-y,R!==0&&(R+=N))),[R,C,I,A]},[0,[],0,0]),we(([x])=>x!==0),_e(r,a,n,o,g,w),we(([,x,v,y,,,E])=>!E&&!y&&x!==0&&v===$r),oe(([[x],,,,,v])=>(v("Upward scrolling compensation",{amount:x},jt.DEBUG),x))));function m(x){x>0?(Ae(t,{behavior:"auto",top:-x}),Ae(e,0)):(Ae(e,0),Ae(t,{behavior:"auto",top:-x}))}return qe(H(b,_e(e,s)),([x,v,y])=>{y&&zg()?Ae(e,v-x):m(-x)}),qe(H(lt(vt(s,!1),e,w),we(([x,v,y])=>!x&&!y&&v!==0),oe(([x,v])=>v),gn(1)),m),fe(H(f,oe(x=>({top:-x}))),t),qe(H(u,_e(h,d),oe(([x,{groupIndices:v,lastSize:y,sizeTree:E},C])=>{function k(I){return I*(y+C)}if(v.length===0)return k(x);{let I=0;const N=Pr(E,0);let A=0,R=0;for(;A<x;){A++,I+=N;let j=v.length===R+1?1/0:v[R+1]-v[R]-1;A+j>x&&(I-=N,j=x-A+1),A+=j,I+=k(j),R++}return I}})),x=>{Ae(e,x),requestAnimationFrame(()=>{Ae(t,{top:x}),requestAnimationFrame(()=>{Ae(e,0),Ae(w,!1)})})}),{deviation:e}},Ze(Ct,zr,Bn,rn,Sn,ai)),Hg=Be(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Ze(fi,Mg,kn,hc,cc,Dg,_g,pi,dc,Sn,uc)),mc=Be(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:g,scrolledToInitialItem:w},b,m,x,{listState:v,topItemsIndexes:y,...E},{scrollToIndex:C},k,{topItemCount:I},{groupCounts:N},A])=>(fe(E.rangeChanged,A.scrollSeekRangeChanged),fe(H(A.windowViewportRect,oe(R=>R.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:g,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:v,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...A,...b,sizes:c,...m}),Ze(rn,Lr,Ct,Lg,Og,Bn,Dr,Bg,Fg,tc,Hg));function Ug(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 Io=typeof document<"u"?S.useLayoutEffect:S.useEffect;function gc(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=S.createContext({});function c(m,x){m.propsReady&&Ae(m.propsReady,!1);for(const v of r){const y=m[t.required[v]];Ae(y,x[v])}for(const v of o)if(v in x){const y=m[t.optional[v]];Ae(y,x[v])}m.propsReady&&Ae(m.propsReady,!0)}function u(m){return s.reduce((x,v)=>(x[v]=y=>{const E=m[t.methods[v]];Ae(E,y)},x),{})}function d(m){return i.reduce((x,v)=>(x[v]=sg(m[t.events[v]]),x),{})}const f=S.forwardRef((m,x)=>{const{children:v,...y}=m,[E]=S.useState(()=>bo(ag(e),I=>{c(I,y)})),[C]=S.useState(Fl(d,E));Io(()=>{for(const I of i)I in y&&qe(C[I],y[I]);return()=>{Object.values(C).map(ei)}},[y,C,E]),Io(()=>{c(E,y)}),S.useImperativeHandle(x,Ll(u(E)));const k=n;return l.jsx(a.Provider,{value:E,children:n?l.jsx(k,{...Ug([...r,...o,...i],y),children:v}):v})}),h=m=>{const x=S.useContext(a);return S.useCallback(v=>{Ae(x[m],v)},[x,m])},g=m=>{const x=S.useContext(a)[m],v=S.useCallback(y=>qe(x,y),[x]);return S.useSyncExternalStore(v,()=>st(x),()=>st(x))},w=m=>{const x=S.useContext(a)[m],[v,y]=S.useState(Fl(st,x));return Io(()=>qe(x,E=>{E!==v&&y(Ll(E))}),[x,v]),v},b=S.version.startsWith("18")?g:w;return{Component:f,useEmitter:(m,x)=>{const v=S.useContext(a)[m];Io(()=>qe(v,x),[x,v])},useEmitterValue:b,usePublisher:h}}const xc=S.createContext(void 0),vc=S.createContext(void 0),bc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function mi(e){return"self"in e}function Wg(e){return"body"in e}function wc(e,t,n,r=lr,o,s){const i=S.useRef(null),a=S.useRef(null),c=S.useRef(null),u=S.useCallback(h=>{let g,w,b;const m=h.target;if(Wg(m)||mi(m)){const v=mi(m)?m:m.defaultView;b=s?v.scrollX:v.scrollY,g=s?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,w=s?v.innerWidth:v.innerHeight}else b=s?m.scrollLeft:m.scrollTop,g=s?m.scrollWidth:m.scrollHeight,w=s?m.offsetWidth:m.offsetHeight;const x=()=>{e({scrollHeight:g,scrollTop:Math.max(b,0),viewportHeight:w})};h.suppressFlushSync?x():Os.flushSync(x),a.current!==null&&(b===a.current||b<=0||b===g-w)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);S.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 g=i.current;if(!g||(s?"offsetWidth"in g&&g.offsetWidth===0:"offsetHeight"in g&&g.offsetHeight===0))return;const w=h.behavior==="smooth";let b,m,x;mi(g)?(m=Math.max(Cn(g.document.documentElement,s?"width":"height"),s?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight),b=s?g.innerWidth:g.innerHeight,x=s?window.scrollX:window.scrollY):(m=g[s?"scrollWidth":"scrollHeight"],b=Cn(g,s?"width":"height"),x=g[s?"scrollLeft":"scrollTop"]);const v=m-b;if(h.top=Math.ceil(Math.max(Math.min(v,h.top),0)),rc(b,m)||h.top===x){e({scrollHeight:m,scrollTop:x,viewportHeight:b}),w&&t(!0);return}w?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),g.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 gi="-webkit-sticky",yc="sticky",xi=pc(()=>{if(typeof document>"u")return yc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:yc});function vi(e){return e}const Vg=Be(()=>{const e=K(a=>`Item ${a}`),t=K(a=>`Group ${a}`),n=K({}),r=K(vi),o=K("div"),s=K(lr),i=(a,c=null)=>vt(H(n,oe(u=>u[a]),Qe()),c);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")}}),qg=Be(([e,t])=>({...e,...t}),Ze(mc,Vg)),Kg=({height:e})=>l.jsx("div",{style:{height:e}}),Gg={overflowAnchor:"none",position:xi(),zIndex:1},Sc={overflowAnchor:"none"},Yg={...Sc,display:"inline-block",height:"100%"},Cc=S.memo(function({showTopList:e=!1}){const t=Te("listState"),n=zt("sizeRanges"),r=Te("useWindowScroll"),o=Te("customScrollParent"),s=zt("windowScrollContainerState"),i=zt("scrollContainerState"),a=o||r?s:i,c=Te("itemContent"),u=Te("context"),d=Te("groupContent"),f=Te("trackItemSizes"),h=Te("itemSize"),g=Te("log"),w=zt("gap"),b=Te("horizontalDirection"),{callbackRef:m}=ug(n,h,f,e?lr:a,g,w,o,b,Te("skipAnimationFrameInResizeObserver")),[x,v]=S.useState(0);bi("deviation",P=>{x!==P&&v(P)});const y=Te("EmptyPlaceholder"),E=Te("ScrollSeekPlaceholder")||Kg,C=Te("ListComponent"),k=Te("ItemComponent"),I=Te("GroupComponent"),N=Te("computeItemKey"),A=Te("isSeeking"),R=Te("groupIndices").length>0,j=Te("alignToBottom"),B=Te("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...b?{display:"inline-block",height:"100%",marginLeft:x!==0?x:j?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:j?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...B?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?l.jsx(y,{...bt(y,u)}):l.jsx(C,{...bt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:m,style:V,children:(e?t.topItems:t.items).map(P=>{const Y=P.originalIndex,W=N(Y+t.firstItemIndex,P.data,u);return A?S.createElement(E,{...bt(E,u),height:P.size,index:P.index,key:W,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?S.createElement(I,{...bt(I,u),"data-index":Y,"data-item-index":P.index,"data-known-size":P.size,key:W,style:Gg},d(P.index,u)):S.createElement(k,{...bt(k,u),...Qg(k,P.data),"data-index":Y,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:W,style:b?Yg:Sc},R?c(P.index,P.groupIndex,P.data,u):c(P.index,P.data,u))})})}),Xg={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Jg={outline:"none",overflowX:"auto",position:"relative"},No=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Zg={position:xi(),top:0,width:"100%",zIndex:1};function bt(e,t){if(typeof e!="string")return{context:t}}function Qg(e,t){return{item:typeof e=="string"?void 0:t}}const ex=S.memo(function(){const e=Te("HeaderComponent"),t=zt("headerHeight"),n=Te("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null}),tx=S.memo(function(){const e=Te("FooterComponent"),t=zt("footerHeight"),n=Te("HeaderFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null});function kc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:g,scrollToCallback:w}=wc(a,u,c,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:g,style:{...f?Jg:Xg,...o},tabIndex:0,...i,...bt(c,s),children:r})})}function Tc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),g=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:b,scrollerRef:m,scrollToCallback:x}=wc(a,u,c,w,h);return bc(()=>{var v;return m.current=h||((v=g.current)==null?void 0:v.ownerDocument.defaultView),()=>{m.current=null}},[m,h]),e("windowScrollTo",x),e("scrollBy",b),l.jsx(c,{ref:g,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...bt(c,s),children:r})})}const nx=({children:e})=>{const t=S.useContext(xc),n=zt("viewportHeight"),r=zt("fixedItemHeight"),o=Te("alignToBottom"),s=Te("horizontalDirection"),i=S.useMemo(()=>$l(n,c=>Cn(c,s?"width":"height")),[n,s]),a=Fn(i,!0,Te("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:No(o),children:e})},rx=({children:e})=>{const t=S.useContext(xc),n=zt("windowViewportRect"),r=zt("fixedItemHeight"),o=Te("customScrollParent"),s=Ul(n,o,Te("skipAnimationFrameInResizeObserver")),i=Te("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:No(i),children:e})},ox=({children:e})=>{const t=Te("TopItemListComponent")||"div",n=Te("headerHeight"),r={...Zg,marginTop:`${n}px`},o=Te("context");return l.jsx(t,{style:r,...bt(t,o),children:e})},sx=S.memo(function(e){const t=Te("useWindowScroll"),n=Te("topItemsIndexes").length>0,r=Te("customScrollParent"),o=Te("context");return l.jsxs(r||t?lx:ax,{...e,context:o,children:[n&&l.jsx(ox,{children:l.jsx(Cc,{showTopList:!0})}),l.jsxs(r||t?rx:nx,{children:[l.jsx(ex,{}),l.jsx(Cc,{}),l.jsx(tx,{})]})]})}),{Component:ix,useEmitter:bi,useEmitterValue:Te,usePublisher:zt}=gc(qg,{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"}},sx),ax=kc({useEmitter:bi,useEmitterValue:Te,usePublisher:zt}),lx=Tc({useEmitter:bi,useEmitterValue:Te,usePublisher:zt}),cx=ix;Ze(mc,Be(()=>{const e=K(u=>l.jsxs("td",{children:["Item $",u]})),t=K(null),n=K(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=K(null),o=K(null),s=K({}),i=K(vi),a=K(lr),c=(u,d=null)=>vt(H(s,oe(f=>f[u]),Qe()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),xi();const Ec={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},ux={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ic,floor:Ao,max:Br,min:wi,round:Nc}=Math;function Ac(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function dx(e){return{...ux,items:e}}function jo(e,t){return e&&e.width===t.width&&e.height===t.height}function fx(e,t){return e&&e.column===t.column&&e.row===t.row}const hx=Be(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,g,{didMount:w,propsReady:b},{customScrollParent:m,useWindowScroll:x,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E},C])=>{const k=K(0),I=K(0),N=K(Ec),A=K({height:0,width:0}),R=K({height:0,width:0}),j=De(),B=De(),V=K(0),P=K(null),Y=K({column:0,row:0}),W=De(),q=De(),F=K(!1),D=K(0),ue=K(!0),X=K(!1),ae=K(!1);qe(H(w,_e(D),we(([O,z])=>!!z)),()=>{Ae(ue,!1)}),qe(H(lt(w,ue,R,A,D,X),we(([O,z,ee,de,,le])=>O&&!z&&ee.height!==0&&de.height!==0&&!le)),([,,,,O])=>{Ae(X,!0),ui(1,()=>{Ae(j,O)}),Gt(H(u),()=>{Ae(t,[0,0]),Ae(ue,!0)})}),fe(H(q,we(O=>O!=null&&O.scrollTop>0),tn(0)),I),qe(H(w,_e(q),we(([,O])=>O!=null)),([,O])=>{O&&(Ae(A,O.viewport),Ae(R,O.item),Ae(Y,O.gap),O.scrollTop>0&&(Ae(F,!0),Gt(H(u,$n(1)),z=>{Ae(F,!1)}),Ae(c,{top:O.scrollTop})))}),fe(H(A,oe(({height:O})=>O)),f),fe(H(lt(ve(A,jo),ve(R,jo),ve(Y,(O,z)=>O&&O.column===z.column&&O.row===z.row),ve(u)),oe(([O,z,ee,de])=>({gap:ee,item:z,scrollTop:de,viewport:O}))),W),fe(H(lt(ve(k),r,ve(Y,fx),ve(R,jo),ve(A,jo),ve(P),ve(I),ve(F),ve(ue),ve(D)),we(([,,,,,,,O])=>!O),oe(([O,[z,ee],de,le,Fe,Ge,Ce,,je,He])=>{const{column:Ue,row:We}=de,{height:it,width:nt}=le,{width:Tt}=Fe;if(Ce===0&&(O===0||Tt===0))return Ec;if(nt===0){const ye=di(He,O),ze=ye+Math.max(Ce-1,0);return dx(Ac(ye,ze,Ge))}const gt=jc(Tt,nt,Ue);let rt,Ve;je?z===0&&ee===0&&Ce>0?(rt=0,Ve=Ce-1):(rt=gt*Ao((z+We)/(it+We)),Ve=gt*Ic((ee+We)/(it+We))-1,Ve=wi(O-1,Br(Ve,gt-1)),rt=wi(Ve,Br(0,rt))):(rt=0,Ve=-1);const Q=Ac(rt,Ve,Ge),{bottom:ne,top:xe}=_c(Fe,de,le,Q),L=Ic(O/gt),G=L*it+(L-1)*We-ne;return{bottom:ne,itemHeight:it,items:Q,itemWidth:nt,offsetBottom:G,offsetTop:xe,top:xe}})),N),fe(H(P,we(O=>O!==null),oe(O=>O.length)),k),fe(H(lt(A,R,N,Y),we(([O,z,{items:ee}])=>ee.length>0&&z.height!==0&&O.height!==0),oe(([O,z,{items:ee},de])=>{const{bottom:le,top:Fe}=_c(O,de,z,ee);return[Fe,le]}),Qe(Or)),t);const $=K(!1);fe(H(u,_e($),oe(([O,z])=>z||O!==0)),$);const Z=Ot(H(lt(N,k),we(([{items:O}])=>O.length>0),_e($),we(([[O,z],ee])=>{const de=O.items[O.items.length-1].index===z-1;return(ee||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===z)&&de}),oe(([[,O]])=>O-1),Qe())),Ne=Ot(H(ve(N),we(({items:O})=>O.length>0&&O[0].index===0),tn(0),Qe())),be=Ot(H(ve(N),_e(F),we(([{items:O},z])=>O.length>0&&!z),oe(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),Qe(Xl),gn(0)));fe(be,g.scrollSeekRangeChanged),fe(H(j,_e(A,R,k,Y),oe(([O,z,ee,de,le])=>{const Fe=nc(O),{align:Ge,behavior:Ce,offset:je}=Fe;let He=Fe.index;He==="LAST"&&(He=de-1),He=Br(0,He,wi(de-1,He));let Ue=yi(z,le,ee,He);return Ge==="end"?Ue=Nc(Ue-z.height+ee.height):Ge==="center"&&(Ue=Nc(Ue-z.height/2+ee.height/2)),je&&(Ue+=je),{behavior:Ce,top:Ue}})),c);const M=vt(H(N,oe(O=>O.offsetBottom+O.bottom)),0);return fe(H(E,oe(O=>({height:O.visibleHeight,width:O.visibleWidth}))),A),{customScrollParent:m,data:P,deviation:V,footerHeight:o,gap:Y,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:R,overscan:n,restoreStateFrom:q,scrollBy:i,scrollContainerState:a,scrollHeight:B,scrollTo:c,scrollToIndex:j,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:A,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E,...g,gridState:N,horizontalDirection:ae,initialTopMostItemIndex:D,totalListHeight:M,...h,endReached:Z,propsReady:b,rangeChanged:be,startReached:Ne,stateChanged:W,stateRestoreInProgress:F,...C}},Ze(fi,Ct,zr,hc,kn,pi,Sn));function jc(e,t,n){return Br(1,Ao((e+n)/(Ao(t)+n)))}function _c(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=yi(e,t,n,r[0].index);return{bottom:yi(e,t,n,r[r.length-1].index)+o,top:s}}function yi(e,t,n,r){const o=jc(e.width,n.width,t.column),s=Ao(r/o),i=s*n.height+Br(0,s-1)*t.row;return i>0?i+t.row:i}const px=Be(()=>{const e=K(f=>`Item ${f}`),t=K({}),n=K(null),r=K("virtuoso-grid-item"),o=K("virtuoso-grid-list"),s=K(vi),i=K("div"),a=K(lr),c=(f,h=null)=>vt(H(t,oe(g=>g[f]),Qe()),h),u=K(!1),d=K(!1);return fe(ve(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),mx=Be(([e,t])=>({...e,...t}),Ze(hx,px)),gx=S.memo(function(){const e=et("gridState"),t=et("listClassName"),n=et("itemClassName"),r=et("itemContent"),o=et("computeItemKey"),s=et("isSeeking"),i=Bt("scrollHeight"),a=et("ItemComponent"),c=et("ListComponent"),u=et("ScrollSeekPlaceholder"),d=et("context"),f=Bt("itemDimensions"),h=Bt("gap"),g=et("log"),w=et("stateRestoreInProgress"),b=Bt("reportReadyState"),m=Fn(S.useMemo(()=>x=>{const v=x.parentElement.parentElement.scrollHeight;i(v);const y=x.firstChild;if(y){const{height:E,width:C}=y.getBoundingClientRect();f({height:E,width:C})}h({column:Pc("column-gap",getComputedStyle(x).columnGap,g),row:Pc("row-gap",getComputedStyle(x).rowGap,g)})},[i,f,h,g]),!0,!1);return bc(()=>{e.itemHeight>0&&e.itemWidth>0&&b(!0)},[e]),w?null:l.jsx(c,{className:t,ref:m,...bt(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const v=o(x.index,x.data,d);return s?l.jsx(u,{...bt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},v):S.createElement(a,{...bt(a,d),className:n,"data-index":x.index,key:v},r(x.index,x.data,d))})})}),xx=S.memo(function(){const e=et("HeaderComponent"),t=Bt("headerHeight"),n=et("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,!1),o=et("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null}),vx=S.memo(function(){const e=et("FooterComponent"),t=Bt("footerHeight"),n=et("headerFooterTag"),r=Fn(S.useMemo(()=>s=>{t(Cn(s,"height"))},[t]),!0,!1),o=et("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...bt(e,o)})}):null}),bx=({children:e})=>{const t=S.useContext(vc),n=Bt("itemDimensions"),r=Bt("viewportDimensions"),o=Fn(S.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return S.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:No(!1),children:e})},wx=({children:e})=>{const t=S.useContext(vc),n=Bt("windowViewportRect"),r=Bt("itemDimensions"),o=et("customScrollParent"),s=Ul(n,o,!1);return S.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:No(!1),children:e})},yx=S.memo(function({...e}){const t=et("useWindowScroll"),n=et("customScrollParent"),r=n||t?Cx:Sx,o=n||t?wx:bx,s=et("context");return l.jsx(r,{...e,...bt(r,s),children:l.jsxs(o,{children:[l.jsx(xx,{}),l.jsx(gx,{}),l.jsx(vx,{})]})})}),{useEmitter:Rc,useEmitterValue:et,usePublisher:Bt}=gc(mx,{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"}},yx),Sx=kc({useEmitter:Rc,useEmitterValue:et,usePublisher:Bt}),Cx=Tc({useEmitter:Rc,useEmitterValue:et,usePublisher:Bt});function Pc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,jt.WARN),t==="normal"?0:parseInt(t??"0",10)}const kx=ro.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 Si({className:e,variant:t,...n}){return l.jsx("div",{className:J(kx({variant:t}),e),...n})}function ce(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 Tx(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,c=p.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=p.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 on(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:g,...w}=f,b=((x=h==null?void 0:h[e])==null?void 0:x[c])||a,m=p.useMemo(()=>w,Object.values(w));return l.jsx(b.Provider,{value:m,children:g})};u.displayName=s+"Provider";function d(f,h){var b;const g=((b=h==null?void 0:h[e])==null?void 0:b[c])||a,w=p.useContext(g);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=>p.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,Ex(o,...t)]}function Ex(...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:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ft=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},Ix=p[" useInsertionEffect ".trim().toString()]||ft;function Hn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Nx({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=p.useRef(e!==void 0);p.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=p.useCallback(d=>{var f;if(a){const h=Ax(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[c,u]}function Nx({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return Ix(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Ax(e){return typeof e=="function"}function Oc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ci(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Oc(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():Oc(e[o],null)}}}}function Oe(...e){return p.useCallback(Ci(...e),e)}var jx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=jx.reduce((e,t)=>{const n=On.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Mc(e,t){e&&oo.flushSync(()=>e.dispatchEvent(t))}function _x(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var Dt=e=>{const{present:t,children:n}=e,r=Rx(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Oe(r.ref,Px(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};Dt.displayName="Presence";function Rx(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,c]=_x(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const u=_o(r.current);s.current=a==="mounted"?u:"none"},[a]),ft(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,g=_o(u);e?c("MOUNT"):g==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&h!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),ft(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=g=>{const b=_o(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(c("ANIMATION_END"),!o.current)){const m=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=m)})}},h=g=>{g.target===t&&(s.current=_o(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 c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function _o(e){return(e==null?void 0:e.animationName)||"none"}function Px(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 Ox=p[" useId ".trim().toString()]||(()=>{}),Mx=0;function sn(e){const[t,n]=p.useState(Ox());return ft(()=>{n(r=>r??String(Mx++))},[e]),e||(t?`radix-${t}`:"")}var Ro="Collapsible",[Dx,CC]=on(Ro),[Lx,ki]=Dx(Ro),Dc=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=Hn({prop:r,defaultProp:o??!1,onChange:i,caller:Ro});return l.jsx(Lx,{scope:n,disabled:s,contentId:sn(),open:c,onOpenToggle:p.useCallback(()=>u(d=>!d),[u]),children:l.jsx(Se.div,{"data-state":Ei(c),"data-disabled":s?"":void 0,...a,ref:t})})});Dc.displayName=Ro;var Lc="CollapsibleTrigger",$c=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ki(Lc,n);return l.jsx(Se.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ei(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ce(e.onClick,o.onOpenToggle)})});$c.displayName=Lc;var Ti="CollapsibleContent",$x=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ki(Ti,e.__scopeCollapsible);return l.jsx(Dt,{present:n||o.open,children:({present:s})=>l.jsx(Fx,{...r,ref:t,present:s})})});$x.displayName=Ti;var Fx=p.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ki(Ti,n),[a,c]=p.useState(r),u=p.useRef(null),d=Oe(t,u),f=p.useRef(0),h=f.current,g=p.useRef(0),w=g.current,b=i.open||a,m=p.useRef(b),x=p.useRef(void 0);return p.useEffect(()=>{const v=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(v)},[]),ft(()=>{const v=u.current;if(v){x.current=x.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const y=v.getBoundingClientRect();f.current=y.height,g.current=y.width,m.current||(v.style.transitionDuration=x.current.transitionDuration,v.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(Se.div,{"data-state":Ei(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!b,...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:b&&o})});function Ei(e){return e?"open":"closed"}var zx=Dc;const Fc=zx,zc=$c,Un=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Un.displayName="Card";const Wn=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("flex flex-col space-y-1.5 p-6",e),...t}));Wn.displayName="CardHeader";const ur=p.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:J("text-2xl font-semibold leading-none tracking-tight",e),...t}));ur.displayName="CardTitle";const Hr=p.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:J("text-sm text-muted-foreground",e),...t}));Hr.displayName="CardDescription";const Ur=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("p-6 pt-0",e),...t}));Ur.displayName="CardContent";const Po=p.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:J("flex items-center p-6 pt-0",e),...t}));Po.displayName="CardFooter";function Bc(){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 Vn=Bc();function Bx(e){Vn=e}const Hc=/[&<>"']/,Hx=new RegExp(Hc.source,"g"),Uc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Ux=new RegExp(Uc.source,"g"),Wx={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Wc=e=>Wx[e];function wt(e,t){if(t){if(Hc.test(e))return e.replace(Hx,Wc)}else if(Uc.test(e))return e.replace(Ux,Wc);return e}const Vx=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Vc(e){return e.replace(Vx,(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 qx=/(^|[^\[])\^/g;function Xe(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(qx,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Kx=/[^\w:]/g,Gx=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function qc(e,t,n){if(e){let r;try{r=decodeURIComponent(Vc(n)).replace(Kx,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Gx.test(n)&&(n=Zx(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Oo={},Yx=/^[^:]+:\/*[^/]*$/,Xx=/^([^:]+:)[\s\S]*$/,Jx=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Zx(e,t){Oo[" "+e]||(Yx.test(e)?Oo[" "+e]=e+"/":Oo[" "+e]=Do(e,"/",!0)),e=Oo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Xx,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Jx,"$1")+t:e+t}const Mo={exec:function(){}};function Kc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),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 Do(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 Qx(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 ev(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 Gc(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Yc(e,t,n,r){const o=t.href,s=t.title?wt(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:wt(i)}}function tv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
39
39
  `).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(`
40
40
  `)}class Ii{constructor(t){this.options=t||Vn}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:Do(r,`
41
41
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=tv(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=Do(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,c,u,d,f,h,g,w,b=n[1].trim();const m=b.length>1,x={type:"list",raw:"",ordered:m,start:m?+b.slice(0,-1):"",loose:!1,items:[]};b=m?`\\d{1,9}\\${b.slice(-1)}`:`\\${b}`,this.options.pedantic&&(b=m?b:"[*+-]");const v=new RegExp(`^( {0,3}${b})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=v.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": "3.0.196",
3
+ "version": "3.0.197",
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",