teodor-new-chat-ui 4.1.4 → 4.1.5
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 +5 -7
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3194,13 +3194,11 @@ function ox({
|
|
|
3194
3194
|
g(!1);
|
|
3195
3195
|
}
|
|
3196
3196
|
}, [l, i]), be = Be(async () => {
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
}
|
|
3203
|
-
}, 100);
|
|
3197
|
+
try {
|
|
3198
|
+
await fe();
|
|
3199
|
+
} catch (B) {
|
|
3200
|
+
console.error("[ChatSessionProvider] Failed to refresh threads after stream:", B);
|
|
3201
|
+
}
|
|
3204
3202
|
}, [fe]), H = ut(!1), P = Be(
|
|
3205
3203
|
(B, ee) => {
|
|
3206
3204
|
const Ie = Array.isArray(B == null ? void 0 : B.messages) ? B.messages : [];
|
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=Pn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&fo.assertOptions(r,{silentJSONParsing:Xt.transitional(Xt.boolean),forcedJSONParsing:Xt.transitional(Xt.boolean),clarifyTimeoutError:Xt.transitional(Xt.boolean)},!1),o!=null&&(_.isFunction(o)?n.paramsSerializer={serialize:o}:fo.assertOptions(o,{encode:Xt.function,serialize:Xt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),fo.assertOptions(n,{baseUrl:Xt.spelling("baseURL"),withXsrfToken:Xt.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=Tt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(l=l&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});const u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,f=0,h;if(!l){const w=[bl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],v=a[f++];try{p=w(p)}catch(g){v.call(this,g);break}}try{d=bl.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Pn(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){On.prototype[t]=function(n,r){return this.request(Pn(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(Pn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}On.prototype[t]=n(),On.prototype[t+"Form"]=n(!0)});let Hm=class vp{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new rr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new vp(function(o){t=o}),cancel:t}}};function Um(e){return function(n){return e.apply(null,n)}}function Wm(e){return _.isObject(e)&&e.isAxiosError===!0}const Ws={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(Ws).forEach(([e,t])=>{Ws[t]=e});function Cl(e){const t=new On(e),n=$a(On.prototype.request,t);return _.extend(n,On.prototype,t,{allOwnKeys:!0}),_.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cl(Pn(e,o))},n}const it=Cl(kr);it.Axios=On,it.CanceledError=rr,it.CancelToken=Hm,it.isCancel=sl,it.VERSION=yl,it.toFormData=io,it.AxiosError=Ne,it.Cancel=it.CanceledError,it.all=function(t){return Promise.all(t)},it.spread=Um,it.isAxiosError=Wm,it.mergeConfig=Pn,it.AxiosHeaders=Tt,it.formToJSON=e=>rl(_.isHTMLForm(e)?new FormData(e):e),it.getAdapter=wl.getAdapter,it.HttpStatusCode=Ws,it.default=it;const{Axios:xC,AxiosError:vC,CanceledError:wC,isCancel:bC,CancelToken:yC,VERSION:SC,all:CC,Cancel:TC,isAxiosError:kC,spread:EC,toFormData:IC,AxiosHeaders:NC,HttpStatusCode:AC,formToJSON:jC,getAdapter:_C,mergeConfig:RC}=it,Tl=typeof window<"u"?window.__API_BASE_URL__:void 0,kl=Tl?dn(Tl):void 0;function dn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ho=null;const Vs=new Set;function El(){return ho}function Ks(e){ho=e,Vs.forEach(t=>t(e))}function Il(e){return Vs.add(e),()=>Vs.delete(e)}const Dt=it.create({...kl?{baseURL:kl}:{},timeout:3e4,withCredentials:!0});Dt.interceptors.request.use(e=>(ho&&(e.headers.Authorization=`Bearer ${ho}`),e)),Dt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Nt(e,t){return Dt.defaults.baseURL?(await Dt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function qs(e,t,n){return Dt.defaults.baseURL?(await Dt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nl(e,t,n){return Dt.defaults.baseURL?(await Dt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Al(e,t){return Dt.defaults.baseURL?(await Dt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function At(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class jl{get baseUrl(){const t=Dt.defaults.baseURL;return t?dn(String(t)):""}updateConfig(t){t.baseUrl&&(Dt.defaults.baseURL=dn(String(t.baseUrl))),t.authToken!==void 0&&Ks(t.authToken)}getAuthToken(){return El()}setAuthToken(t){Ks(t)}onTokenChange(t){return Il(t)}async listThreads(){const t=await Nt("/threads"),n=At(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await qs("/threads",t?{title:t}:void 0);return At(r)}async updateThread(t,n){const r=await Nl(`/threads/${t}`,{title:n});return At(r)}async deleteThread(t){const n=await Al(`/threads/${t}`);return At(n)}async threadInfo(t){const n=await Nt(`/threads/${t}/info`);return At(n)}async listAgents(){const t=await Nt("/agents"),n=At(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Nt(`/agents/${t}`);return At(n)}async getAgentSchema(t){const n=await Nt(`/agents/${t}/schema`);return At(n)}async getMessages(t){const n=await Nt(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return At(n)}async getState(t){const n=await Nt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async getStateHistory(t){const n=await Nt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async listCheckpoints(t){const n=await Nt(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return At(n)}async resume(t){const n=await qs("/runs/resume",{thread_id:t.threadId,value:t.value});return At(n)}}const xn=new jl,_l=S.createContext(null);function Vm({children:e,apiConfig:t}){const n=xn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(_l.Provider,{value:r,children:e})}function Gs(){const e=S.useContext(_l);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function Km(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 qm(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Gm(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await qm(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}function Ym(e){return e.type!=="thread_info"&&e.type!=="token"}const Xm={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Jm(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:Ys(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ys(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ys(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Pl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pl(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Rl(e=[]){const[t,n]=S.useReducer(Jm,{...Xm,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]),l=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:l}),[l]);return{state:t,dispatch:n,...u}}function Pl(e,t){var n,r;if(t.type==="message_start"&&t.role==="assistant"){const o=t.id,s=rg(t.model);if(e.messages.some(l=>l.id===o))return{...e,assemblingId:o};const a={id:o,role:"assistant",name:s||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:o,messages:[...e.messages,a]}}if(t.type==="message_delta"){const o=e.assemblingId??Xs(e.messages);return o?{...e,messages:Js(e.messages,o,t.delta)}:e}if(t.type==="message_end"){const o=e.assemblingId??Xs(e.messages);if(!o)return{...e,assemblingId:null};const s=e.messages,i=s.findIndex(a=>a.id===o&&a.role==="assistant");if(i>=0&&!((n=s[i].content)==null?void 0:n.some(u=>{var d;return(u==null?void 0:u.type)==="text"&&((d=u.text)==null?void 0:d.trim())}))){const u=[...s.slice(0,i),...s.slice(i+1)];return{...e,assemblingId:null,messages:u}}return e}if(t.type==="tool_start"){const o=t.id??t.call_id,s=t.name??t.tool??"tool";if(!o)return e;const i=`tool-${o}`,a={type:"tool_call",id:o,name:s,args:t.args};if(e.messages.find(d=>d.id===i))return{...e,toolIndex:{...e.toolIndex,[o]:i}};const u={id:i,role:"tool",name:s,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,u],toolIndex:{...e.toolIndex,[o]:i}}}if(t.type==="tool_end"){const o=t.id??t.call_id;if(!o)return e;const s=e.toolIndex[o]??`tool-${o}`,i={type:"tool_end",toolCallId:o,output:t.output,error:t.error},a=e.messages.find(d=>d.id===s),l={id:s,role:"tool",name:t.name??((r=e.messages.find(d=>d.id===s))==null?void 0:r.name),content:[i],createdAt:new Date().toISOString()},u=a?Js(e.messages,s,[i]):[...e.messages,l];return{...e,messages:u,toolIndex:{...e.toolIndex,[o]:s}}}if(t.type==="checkpoint"){const o=t.checkpointNs??e.lastCheckpointNs??null,s=ng(e.messages,t.checkpointId,o);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:o,messages:s}}if(t.type==="branch"){const o=t.checkpointId??e.lastCheckpointId,s=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:o??null,lastCheckpointNs:s??null}}if(t.type==="error"){const o={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,o]}}if(t.type==="interrupt"){const o=e.assemblingId??Xs(e.messages),s={type:"interrupt",value:t.value};if(o)return{...e,assemblingId:null,messages:Js(e.messages,o,[s]),pendingInterrupt:{id:t.id,value:t.value}};const i={id:`interrupt-${t.id}`,role:"system",createdAt:new Date().toISOString(),content:[s]};return{...e,messages:[...e.messages,i],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ys(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 Zm(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xs(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Qm(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 Js(e,t,n){return Qm(e,t,r=>({...r,content:eg(r.content,n)}))}function eg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){const i=o,a=i.text??"";if(!a){i.text=s;continue}if(s.startsWith(a)){i.text=s;continue}if(a.startsWith(s)){i.text=s;continue}const l=tg(a,s);l?i.text=a+l:s.length!==a.length&&(i.text=s)}else n.push({type:"text",text:s})}else n.push(r);return n}function tg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function ng(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 Zm(e,r,s)}return e}function rg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Ol(e={}){const t=S.useMemo(()=>dn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=S.useState(e.token??null),s=S.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=S.useState(!1),[u,d]=S.useState(null),[f,h]=S.useState(""),[p,w]=S.useState(null),[v,g]=S.useState(0),[x,b]=S.useState(!1),y=S.useRef(null),E=S.useRef(!0),C=S.useRef(0),T=S.useCallback(j=>{o(j)},[]),I=S.useCallback(()=>{var j;(j=y.current)==null||j.abort(),y.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=S.useCallback(()=>{h(""),w(null),d(null)},[]),R=S.useCallback((j,M,D)=>{y.current&&(y.current.abort(),y.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const L=new AbortController;return y.current=L,(async()=>{var V,U,G,F,N,W,Y,de;const P=se=>{var pe;try{const me=JSON.parse(JSON.stringify(se));return(pe=me==null?void 0:me.payload)!=null&&pe.files_info&&Array.isArray(me.payload.files_info)&&(me.payload.files_info=me.payload.files_info.map(ye=>({...ye,data:ye!=null&&ye.data?`<base64 ${String(ye.data).length} chars>`:ye==null?void 0:ye.data}))),me}catch{return se}};try{let se={};try{if(r)se={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Pe=window.__AUTH_TOKEN__,Qe=((V=window.localStorage)==null?void 0:V.getItem("authToken"))||null;let $e=null;try{const lt=(U=window.localStorage)==null?void 0:U.getItem("chat-settings");lt&&($e=((G=JSON.parse(lt))==null?void 0:G.apiKey)||null)}catch{}const qe=Pe||Qe||$e||null;qe&&(se={Authorization:`Bearer ${qe}`})}}catch{}console.debug("[use-chat] POST",t+n,P(j));const pe=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...se,...s.current},body:JSON.stringify(j),signal:L.signal,credentials:i});if(!pe.ok||!pe.body){const Ee=await pe.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",pe.status,Ee==null?void 0:Ee.slice(0,500)),new Error(`stream ${pe.status}${Ee?": "+Ee:""}`)}b(!0);const me=pe.body.getReader(),ye=new TextDecoder;let H="",O=[];C.current=0,g(0);let K=0,J=null;const ce=()=>{if(O.length){const Ee=O.join("");O=[],E.current&&h(Pe=>Pe+Ee)}J=null},ie=()=>{typeof window<"u"&&J==null&&(J=requestAnimationFrame(ce))};let Le=Date.now();const We=setInterval(()=>{var Ee;if(Date.now()-Le>6e4){const Pe="Stream idle timeout";d(Pe),L.abort(),(Ee=D==null?void 0:D.onError)==null||Ee.call(D,Pe)}},5e3),Ze=1024*1024;try{const Ee=pe.headers.get("X-Thread-Id")||pe.headers.get("x-thread-id"),Pe=pe.headers.get("X-Thread-Created")||pe.headers.get("x-thread-created"),Qe=Ee??null,$e=String(Pe??"").toLowerCase()==="true";for((F=D==null?void 0:D.onOpen)==null||F.call(D,{threadId:Qe,created:$e});;){const{value:qe,done:lt}=await me.read();if(lt)break;H+=ye.decode(qe,{stream:!0}),H.length>Ze&&(H="",console.warn("Stream buffer reset: exceeded 1MB"));let Z;for(;(Z=H.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const le=H.slice(0,Z);H=H.slice(Z+2);const ge=sg(le);if(!ge)continue;let Ce;try{Ce=JSON.parse(ge)}catch{console.debug("[use-chat] malformed SSE:",ge.slice(0,200));continue}const we=og(Ce)?Ce.data:Ce;Le=Date.now();const Ae=we.seq;if(Ae!==void 0){if(Ae<=K){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ae,lastProcessedSeq:K,type:we.type});continue}K>0&&Ae>K+1&&((N=D==null?void 0:D.onGap)==null||N.call(D,{from:K,to:Ae})),K=Ae,C.current=Ae,g(Ae)}if(M==null||M(we),we.type==="token"&&e.autoAppendAssistant!==!1)O.push(we.content),ie();else if(we.type==="message_delta"){const et=we.delta.filter(Ve=>Ve.type==="text").map(Ve=>Ve.text).join("");et&&e.autoAppendAssistant!==!1&&(O.push(et),ie())}else we.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(J!==null&&cancelAnimationFrame(J),ce(),we.type==="checkpoint"?w(we.checkpointId):we.type==="error"&&d(we.message))}}ce()}catch(Ee){if(Ee.name!=="AbortError"){const Pe=Ee.message||String(Ee);d(Pe),(W=D==null?void 0:D.onError)==null||W.call(D,Pe)}}finally{try{await me.cancel()}catch{}finally{(Y=me.releaseLock)==null||Y.call(me)}J!==null&&typeof window<"u"&&window.cancelAnimationFrame(J),clearInterval(We),l(!1),b(!1),y.current=null,C.current=0,g(0)}}catch(se){if(se.name!=="AbortError"){const pe=se.message||String(se);d(pe),(de=D==null?void 0:D.onError)==null||de.call(D,pe)}}finally{l(!1),b(!1),y.current=null,C.current=0,g(0)}})(),{close:()=>L.abort()}},[t,n,r,e.autoAppendAssistant]);return S.useEffect(()=>()=>{var j;E.current=!1,(j=y.current)==null||j.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:v,connected:x,stream:R,stop:I,clear:A,setToken:T}}function og(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function sg(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
|
-
`)}function ig({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=S.useRef(null),i=S.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){t(p);return}if(Ym(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Ol({baseUrl:e,token:null}),h=S.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return S.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Ml=S.createContext(null),Dl=S.createContext(null),Ll=S.createContext(null),ag=S.createContext(!1),lg=20;function cg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Gs(),d=S.useMemo(()=>dn(u),[u]),[f,h]=S.useState([]),[p,w]=S.useState(t),[v,g]=S.useState(!1),[x,b]=S.useState(!1),[y,E]=S.useState(!1),[C,T]=S.useState(!1),[I,A]=S.useState(null),[R,j]=S.useState(void 0),[M,D]=S.useState(void 0),{state:L,seed:P,prepend:V,pushUser:U,onEvent:G,reset:F}=Rl(),N=S.useRef(p);S.useEffect(()=>{N.current=p},[p]);const W=S.useRef(!1),Y=S.useRef([]),de=S.useRef(null),se=S.useRef(null),pe=S.useCallback((B,ne)=>new Promise((je,rt)=>{const Ge=async()=>{W.current=!0;try{await B(),je()}catch(Et){rt(Et)}finally{W.current=!1;const Et=Y.current.shift();Et&&Et().catch(()=>{})}};W.current?Y.current.push(Ge):Ge().catch(Et=>{rt(Et)})}),[]),me=S.useCallback(async()=>{g(!0);try{const B=await l.listThreads();h(B)}catch(B){i==null||i(String(B)),console.error("[ChatSessionProvider] Failed to refresh threads:",B)}finally{g(!1)}},[l,i]),ye=S.useCallback(async()=>{setTimeout(async()=>{try{await me()}catch(B){console.error("[ChatSessionProvider] Failed to refresh threads after stream:",B)}},100)},[me]),H=S.useRef(!1),O=S.useCallback((B,ne)=>{const je=Array.isArray(B==null?void 0:B.messages)?B.messages:[];ne==="replace"?P(je,{checkpointId:(B==null?void 0:B.checkpointId)??null,checkpointNs:(B==null?void 0:B.checkpointNs)??null}):ne==="prepend"&&je.length&&V(je),A((B==null?void 0:B.nextCursor)??null),E(!!(B!=null&&B.hasMore)),j(rt=>(B==null?void 0:B.checkpointId)??rt??void 0),D(rt=>(B==null?void 0:B.checkpointNs)??rt??void 0)},[V,P]),K=S.useCallback(()=>{F([]),E(!1),T(!1),A(null),j(void 0),D(void 0)},[F]),J=S.useCallback(({from:B,to:ne})=>{const je=N.current;je&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${B} -> ${ne}) for thread ${je}`)},[]),ce=S.useCallback(B=>{const ne=B.threadId;if(B.created,B.ready,N.current!==ne){!N.current&&L.messages.length<=1&&(se.current=ne),w(ne);return}},[]),{startStream:ie,stop:Le,isStreaming:We,error:Ze,setAuthToken:Ee}=ig({baseUrl:d,onThreadInfo:ce,onMessageEvent:G,onUnhandledEvent:B=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${B.type}`,B)},onSequenceGap:J});S.useEffect(()=>{H.current=We,We||ye()},[ye,We]),S.useEffect(()=>{var je;const B=l.getAuthToken();Ee(B);const ne=(je=l.onTokenChange)==null?void 0:je.call(l,rt=>{Ee(rt)});return()=>{ne==null||ne()}},[l,Ee]);const Pe=S.useCallback(async B=>{const ne=await l.createThread(B),je=typeof ne=="string"?ne:ne.threadId;return await me(),w(je),je},[l,me]),Qe=S.useCallback(async B=>{await l.deleteThread(B),N.current===B&&(se.current=B,w(null),K()),await me()},[l,K,me]),$e=S.useCallback(async(B,ne)=>{try{await l.updateThread(B,ne),h(je=>je.map(rt=>rt.threadId===B?{...rt,title:ne}:rt))}catch(je){throw await me(),je}},[l,me]),qe=S.useCallback(async(B,ne,je,rt=!1)=>{await pe(async()=>{if(se.current===B&&!rt){se.current=null;return}if(!(de.current===B&&!rt)){w(Ge=>Ge===B?Ge:B),de.current=B,b(!0);try{const Ge=await l.getMessages({threadId:B,checkpointId:ne,checkpointNs:je});O(Ge,"replace"),j((Ge==null?void 0:Ge.checkpointId)??void 0),D((Ge==null?void 0:Ge.checkpointNs)??void 0)}catch(Ge){throw i==null||i(String(Ge)),Ge}finally{de.current=null,b(!1)}}},`loadThread-${B}`)},[l,O,pe,i]),lt=S.useCallback(async()=>{await pe(async()=>{N.current&&(se.current=N.current),w(null),K(),j(void 0),D(void 0);try{localStorage.removeItem("lastThreadId")}catch(B){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",B)}},"clearCurrentThread")},[K,pe]),Z=S.useCallback(async B=>{const ne=await l.listCheckpoints(B);return Km(ne,B)},[l]),le=S.useCallback(async(B,ne)=>{if(!N.current)throw new Error("No active thread");await qe(N.current,B,ne??void 0,!0)},[qe]),ge=S.useCallback(async()=>{if(!N.current)throw new Error("No active thread");await qe(N.current,void 0,void 0,!0)},[qe]),Ce=S.useCallback(async B=>{if(!N.current)throw new Error("No active thread");if(C||!y)return;const ne=I;if(ne){T(!0);try{const je=await l.getMessages({threadId:N.current,checkpointId:R,checkpointNs:M,limit:(B==null?void 0:B.limit)??lg,beforeId:ne});O(je,"prepend")}finally{T(!1)}}},[l,O,y,R,M,I,C]),we=S.useCallback(async(B,ne)=>{var Qn;const je=N.current;!je&&!(ne!=null&&ne.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const rt=(ne==null?void 0:ne.attachments)||[],{contentParts:Ge,filesInfo:Et}=await Gm(l,rt),Xn=[...Ge];B&&B.trim()&&Xn.push({type:"text",text:B.trim()});const jn={id:((Qn=crypto.randomUUID)==null?void 0:Qn.call(crypto))||`user-${Date.now()}`,role:"user",content:Xn,createdAt:new Date().toISOString(),checkpointId:(ne==null?void 0:ne.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ne==null?void 0:ne.checkpointNs)??L.lastCheckpointNs??void 0};U(jn);const vr={...jn,content:Xn},cn={...(ne==null?void 0:ne.payloadExtras)??{}},Jn=rt.length>0,Zn={...je?{threadId:je}:{},payload:{messages:[vr],files_info:Et,...o&&Jn&&s?{active_agent:s}:{},...cn},checkpointId:(ne==null?void 0:ne.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ne==null?void 0:ne.checkpointNs)??L.lastCheckpointNs??void 0,nodeFilter:ne==null?void 0:ne.nodeFilter,config:ne==null?void 0:ne.config};ie(Zn,{onError:mn=>{console.warn("[ChatSessionProvider] Stream error:",mn)},onOpen:({threadId:mn,created:Zr})=>{!N.current&&mn&&(L.messages.length<=1&&(se.current=mn),w(mn))},onGap:J})},[l,o,s,J,L.lastCheckpointId,L.lastCheckpointNs,L.messages.length,U,ie]),Ae=S.useCallback(async(B,ne,je)=>{const rt=N.current;if(!rt)throw new Error("No active thread to handle interrupt");try{const Ge=ne?je??!0:!1;await l.resume({threadId:rt,value:Ge})}catch(Ge){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${B}:`,Ge),Ge}},[l]);S.useEffect(()=>{if(a==null||a(p),p)try{localStorage.setItem("lastThreadId",p)}catch(B){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",B)}},[p,a]),S.useEffect(()=>{let B=!0;return(async()=>{try{if(await me(),!B)return;if(!r&&!t)try{const je=localStorage.getItem("lastThreadId");je&&(w(je),n&&await qe(je))}catch(je){console.warn("[ChatSessionProvider] Failed to restore last thread:",je)}else t&&n&&await qe(t)}catch(je){console.error("[ChatSessionProvider] Initialization failed:",je),i==null||i(String(je))}})(),()=>{B=!1}},[]);const et=S.useMemo(()=>({threads:f,currentThreadId:p,isLoadingThreads:v,isLoadingThread:x,setCurrentThreadId:w,createThread:Pe,deleteThread:Qe,renameThread:$e,refreshThreads:me,loadThread:qe,clearCurrentThread:lt,listCheckpoints:Z,navigateToCheckpoint:le,returnToLatest:ge}),[lt,Pe,p,Qe,x,v,Z,qe,le,me,$e,ge,f]),Ve=S.useMemo(()=>({messages:L.messages,assemblingId:L.assemblingId,lastUserMessage:null,hasMoreHistory:y,isLoadingHistory:C,send:we,stop:Le,loadOlderMessages:Ce,clearMessages:K,handleInterrupt:Ae}),[K,Ae,y,C,Ce,L.assemblingId,L.messages,we,Le]),ct=S.useMemo(()=>({isStreaming:We,error:Ze,streamingAssistantId:L.assemblingId,lastCheckpointId:L.lastCheckpointId??null,lastCheckpointNs:L.lastCheckpointNs??null}),[We,L.assemblingId,L.lastCheckpointId,L.lastCheckpointNs,Ze]);return c.jsx(ag.Provider,{value:!0,children:c.jsx(Ll.Provider,{value:ct,children:c.jsx(Ml.Provider,{value:et,children:c.jsx(Dl.Provider,{value:Ve,children:e})})})})}function po(){const e=S.useContext(Ml);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Zs(){const e=S.useContext(Dl);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function Fl(){const e=S.useContext(Ll);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function mo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Vm,{apiConfig:t,children:c.jsx(cg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function X(...e){return bp.twMerge(wp.clsx(e))}const ug=eo.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"}}),Be=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?_n.Slot:"button";return c.jsx(i,{className:X(ug({variant:t,size:n,className:e})),ref:s,...o})});Be.displayName="Button";const $l=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:X("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}));$l.displayName="Textarea";function dg({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=S.useState(e),[w,v]=S.useTransition(),g=S.useRef(null);S.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const b=S.useCallback(async A=>{A&&A.preventDefault();const R=(h??"").trim();!R&&!f||v(()=>{try{const j=i(R);j&&typeof j.then=="function"?j.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),y=S.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=S.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx($l,{ref:g,value:h,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Be,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(Q.Square,{size:16})}):c.jsx(Be,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(Q.Send,{size:16})})})]})})}const fg=S.memo(dg),go=0,vn=1,or=2,zl=4;function Bl(e){return()=>e}function hg(e){e()}function Hl(e,t){return n=>e(t(n))}function Ul(e,t){return()=>e(t)}function pg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function mg(...e){return()=>{e.map(hg)}}function sr(){}function xo(e,t){return t(e),e}function gg(e,t){return t(e)}function tt(...e){return e}function Ue(e,t){return e(vn,t)}function _e(e,t){e(go,t)}function ei(e){e(or)}function at(e){return e(zl)}function ue(e,t){return Ue(e,pg(t,go))}function Wt(e,t){const n=e(vn,r=>{n(),t(r)});return n}function Wl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Vl(e,t){return e===t}function nt(e=Vl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function be(e){return t=>n=>{e(n)&&t(n)}}function te(e){return t=>Hl(t,e)}function Jt(e){return t=>()=>{t(e)}}function $(e,...t){const n=xg(...t);return(r,o)=>{switch(r){case or:ei(e);return;case vn:return Ue(e,n(o))}}}function Zt(e,t){return n=>r=>{n(t=e(t,r))}}function Mn(e){return t=>n=>{e>0?e--:t(n)}}function fn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Re(...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);Ue(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function xg(...e){return t=>e.reduceRight(gg,t)}function vg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case vn:return s?n===s?void 0:(r(),n=s,t=Ue(e,s),t):(r(),sr);case or:r(),n=null;return}}}function q(e){let t=e;const n=De();return(r,o)=>{switch(r){case go:t=o;break;case vn:{o(t);break}case zl:return t}return n(r,o)}}function xt(e,t){return xo(q(t),n=>ue(e,n))}function De(){const e=[];return(t,n)=>{switch(t){case go:e.slice().forEach(r=>{r(n)});return;case or:e.splice(0,e.length);return;case vn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function jt(e){return xo(De(),t=>ue(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:wg(),singleton:n}}const wg=()=>Symbol();function bg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function dt(...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);Ue(s,l=>{n[i]=l,r=r|a,r===o&&_e(t,n)})}),function(s,i){switch(s){case or:{ei(t);return}case vn:return r===o&&i(n),Ue(t,i)}}}function ve(e,t=Vl){return $(e,nt(t))}function ti(...e){return function(t,n){switch(t){case or:return;case vn:return mg(...e.map(r=>Ue(r,n)))}}}var kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(kt||{});const yg={0:"debug",3:"error",1:"log",2:"warn"},Sg=()=>typeof globalThis>"u"?window:globalThis,wn=He(()=>{const e=q(3);return{log:q((t,n,r=1)=>{var o;const s=(o=Sg().VIRTUOSO_LOG_LEVEL)!=null?o:at(e);r>=s&&console[yg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Dn(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 l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Cg(e,t,n,r,o,s,i,a,l){const u=S.useCallback(d=>{const f=Tg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Kl("column-gap",getComputedStyle(d).columnGap,o):Kl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,l)}function Tg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},kt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Kl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ql(e,t,n){const r=S.useRef(null),o=S.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const bt=He(()=>{const e=De(),t=De(),n=q(0),r=De(),o=q(0),s=De(),i=De(),a=q(0),l=q(0),u=q(0),d=q(0),f=De(),h=De(),p=q(!1),w=q(!1),v=q(!1);return ue($(e,te(({scrollTop:g})=>g)),t),ue($(e,te(({scrollHeight:g})=>g)),i),ue(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Ir={lvl:0};function Gl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Ye(e){return e===Ir}function Nr(e,t){if(!Ye(e))return t===e.k?e.v:t<e.k?Nr(e.l,t):Nr(e.r,t)}function Vt(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=Vt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Vt(e.l,t,n)}function _t(e,t,n){return Ye(e)?Jl(t,n,1):t===e.k?ht(e,{k:t,v:n}):t<e.k?Zl(ht(e,{l:_t(e.l,t,n)})):Zl(ht(e,{r:_t(e.r,t,n)}))}function ir(){return Ir}function vo(e,t,n){if(Ye(e))return[];const r=Vt(e,t)[0];return kg(oi(e,r,n))}function ri(e,t){if(Ye(e))return Ir;const{k:n,l:r,r:o}=e;if(t===n){if(Ye(r))return o;if(Ye(o))return r;{const[s,i]=Xl(r);return wo(ht(e,{k:s,l:Yl(r),v:i}))}}else return t<n?wo(ht(e,{l:ri(r,t)})):wo(ht(e,{r:ri(o,t)}))}function Ln(e){return Ye(e)?[]:[...Ln(e.l),{k:e.k,v:e.v},...Ln(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 wo(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 Ql(ht(e,{lvl:n-1}));if(!Ye(t)&&!Ye(t.r))return ht(t.r,{l:ht(t,{r:t.r.l}),lvl:n,r:ht(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(ht(e,{lvl:n-1}));if(!Ye(r)&&!Ye(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return ht(o,{l:ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ht(e,t){return Jl(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 Yl(e){return Ye(e.r)?e.l:wo(ht(e,{r:Yl(e.r)}))}function si(e){return Ye(e)||e.lvl>e.r.lvl}function Xl(e){return Ye(e.r)?[e.k,e.v]:Xl(e.r)}function Jl(e,t,n,r=Ir,o=Ir){return{k:e,l:r,lvl:n,r:o,v:t}}function Zl(e){return ii(Ql(e))}function Ql(e){const{l:t}=e;return!Ye(t)&&t.lvl===e.lvl?ht(t,{r:ht(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?ht(n,{l:ht(e,{r:n.l}),lvl:t+1}):e}function kg(e){return Gl(e,({k:t,v:n})=>({index:t,value:n}))}function ec(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Ar(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=He(()=>({recalcInProgress:q(!1)}),[],{singleton:!0});function tc(e,t,n){return e[bo(e,t,n)]}function bo(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 Eg(e,t,n,r){const o=bo(e,t,r),s=bo(e,n,r,o);return e.slice(o,s+1)}function bn(e,t){return Math.round(e.getBoundingClientRect()[t])}function yo(e){return!Ye(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function Ig(){return{groupIndices:[],groupOffsetTree:ir(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ir()}}function Ng(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=_t(e,0,s);continue}const a=vo(e,i-1,o+1);if(a.some(Mg(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=_t(e,o+1,h));u&&(e=_t(e,i,s))}return[e,n]}function Ag(e){return typeof e.groupIndex<"u"}function jg({offset:e},t){return t===e?0:t<e?-1:1}function jr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=tc(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function nc(e,t){if(!yo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function rc(e,t,n){if(Ag(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=nc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function _g(e,t,n,r=0){return r>0&&(t=Math.max(t,tc(e,r,li).offset)),Gl(Eg(e,t,n,jg),Og)}function Rg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ye(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>_t(_t(w,v,h),v+1,p),i)}else[i,a]=Ng(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>_t(h,p,jr(p,f,o)),ir()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Pg(e){return Ln(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 oc(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,l=0;if(t!==0){l=bo(o,t-1,li),a=o[l].offset;const u=Vt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Vt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of vo(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 Og(e){return{index:e.index,value:e}}function Mg(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 Dg={offsetHeight:"height",offsetWidth:"width"},Qt=He(([{log:e},{recalcInProgress:t}])=>{const n=De(),r=De(),o=xt(r,0),s=De(),i=De(),a=q(0),l=q([]),u=q(void 0),d=q(void 0),f=q((C,T)=>bn(C,Dg[T])),h=q(void 0),p=q(0),w=Ig(),v=xt($(n,Re(l,e,p),Zt(Rg,w),nt()),w),g=xt($(l,nt(),Zt((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),te(({prev:C})=>C)),[]);ue($(l,be(C=>C.length>0),Re(v,p),te(([C,T,I])=>{const A=C.reduce((R,j,M)=>_t(R,j,jr(j,T.offsetTree,I)||M),ir());return{...T,groupIndices:C,groupOffsetTree:A}})),v),ue($(r,Re(v),be(([C,{lastIndex:T}])=>C<T),te(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),ue(u,d);const x=xt($(u,te(C=>C===void 0)),!0);ue($(d,be(C=>C!==void 0&&Ye(at(v).sizeTree)),te(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=jt($(n,Re(v),Zt(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),te(C=>C.changed)));Ue($(a,Zt((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),te(C=>C.diff)),C=>{const{groupIndices:T}=at(v);if(C>0)_e(t,!0),_e(s,C+oc(C,T));else if(C<0){const I=at(g);I.length>0&&(C-=oc(-C,I)),_e(i,C)}}),Ue($(a,Re(e)),([C,T])=>{C<0&&T("`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},kt.ERROR)});const y=jt(s);ue($(s,Re(v),te(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const j=Nr(T.sizeTree,0);let M=0,D=0;for(;M<C;){const P=T.groupIndices[D],V=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-P-1;A.push({endIndex:P,size:j,startIndex:P}),A.push({endIndex:P+1+V-1,size:R,startIndex:P+1}),D++,M+=V+1}const L=Ln(T.sizeTree);return M!==C&&L.shift(),L.reduce((P,{k:V,v:U})=>{let G=P.ranges;return P.prevSize!==0&&(G=[...P.ranges,{endIndex:V+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:V+C,prevSize:U,ranges:G}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Ln(T.sizeTree).reduce((j,{k:M,v:D})=>({prevIndex:M+C,prevSize:D,ranges:[...j.ranges,{endIndex:M+C-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const E=jt($(i,Re(v,p),te(([C,{offsetTree:T},I])=>{const A=-C;return jr(A,T,I)})));return ue($(i,Re(v,p),te(([C,T,I])=>{if(T.groupIndices.length>0){if(Ye(T.sizeTree))return T;let A=ir();const R=at(g);let j=0,M=0,D=0;for(;j<-C;){D=R[M];const L=R[M+1]-D-1;M++,j+=L+1}if(A=Ln(T.sizeTree).reduce((L,{k:P,v:V})=>_t(L,Math.max(0,P+C),V),A),j!==-C){const L=Nr(T.sizeTree,D);A=_t(A,0,L);const P=Vt(T.sizeTree,-C+1)[1];A=_t(A,1,P)}return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}else{const A=Ln(T.sizeTree).reduce((R,{k:j,v:M})=>_t(R,Math.max(0,j+C),M),ir());return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:y,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},tt(wn,ai),{singleton:!0});function Lg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const sc=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=De(),i=De(),a=jt($(s,te(Lg)));return ue($(a,te(l=>l.totalCount)),n),ue($(a,te(l=>l.groupIndices)),e),ue($(dt(o,t,r),be(([l,u])=>yo(u)),te(([l,u,d])=>Vt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),nt(),te(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},tt(Qt,bt)),yn=He(([{log:e}])=>{const t=q(!1),n=jt($(t,be(r=>r),nt()));return Ue(t,r=>{r&&at(e)("props updated",{},kt.DEBUG)}),{didMount:n,propsReady:t}},tt(wn),{singleton:!0}),Fg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function ic(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Fg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const _r=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=De(),w=De(),v=q(0);let g=null,x=null,b=null;function y(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),_e(l,!1)}return ue($(p,Re(n,f,r,v,a,i,h),Re(e,s,o),te(([[E,C,T,I,A,R,j,M],D,L,P])=>{const V=ic(E),{align:U,behavior:G,offset:F}=V,N=I-1,W=rc(V,C,N);let Y=jr(W,C.offsetTree,D)+R;U==="end"?(Y+=L+Vt(C.sizeTree,W)[1]-T+P,W===N&&(Y+=j)):U==="center"?Y+=(L+Vt(C.sizeTree,W)[1]-T+P)/2:Y-=A,F&&(Y+=F);const de=se=>{y(),se?(M("retrying to scroll to",{location:E},kt.DEBUG),_e(p,E)):(_e(w,!0),M("list did not change, scroll successful",{},kt.DEBUG))};if(y(),G==="smooth"){let se=!1;b=Ue(t,pe=>{se=se||pe}),g=Wt(d,()=>{de(se)})}else g=Wt($(t,$g(150)),de);return x=setTimeout(()=>{y()},1200),_e(l,!0),M("scrolling from index to",{behavior:G,index:W,top:Y},kt.DEBUG),{behavior:G,top:Y}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},tt(Qt,bt,wn),{singleton:!0});function $g(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 Rr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=q(!0),l=q(0),u=q(!0);return ue($(i,Re(l),be(([d,f])=>!!f),Jt(!1)),a),ue($(i,Re(l),be(([d,f])=>!!f),Jt(!1)),u),Ue($(dt(t,i),Re(a,n,e,u),be(([[,d],f,{sizeTree:h},p,w])=>d&&(!Ye(h)||Qs(p))&&!f&&!w),Re(l)),([,d])=>{Wt(o,()=>{_e(u,!0)}),ui(4,()=>{Wt(r,()=>{_e(a,!0)}),_e(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},tt(Qt,bt,_r,yn),{singleton:!0});function ac(e,t){return Math.abs(e-t)<1.01}const Pr="up",Or="down",zg="none",Bg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Hg=0,Mr=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=q(!1),a=q(!0),l=De(),u=De(),d=q(4),f=q(Hg),h=xt($(ti($(ve(o),Mn(1),Jt(!0)),$(ve(o),Mn(1),Jt(!1),Wl(100))),nt()),!1),p=xt($(ti($(n,Jt(!0)),$(n,Jt(!1),Wl(200))),nt()),!1);ue($(dt(ve(o),ve(f)),te(([b,y])=>b<=y),nt()),a),ue($(a,fn(50)),u);const w=jt($(dt(r,ve(s),ve(t),ve(e),ve(d)),Zt((b,[{scrollHeight:y,scrollTop:E},C,T,I,A])=>{const R=E+C-y>-A,j={scrollHeight:y,scrollTop:E,viewportHeight:C};if(R){let D,L;return E>b.state.scrollTop?(D="SCROLLED_DOWN",L=b.state.scrollTop-E):(D="SIZE_DECREASED",L=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:L,state:j}}let M;return j.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:j}},Bg),nt((b,y)=>b&&b.atBottom===y.atBottom))),v=xt($(r,Zt((b,{scrollHeight:y,scrollTop:E,viewportHeight:C})=>{if(ac(b.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const T=y-(E+C)<1;return b.scrollTop!==E&&T?{changed:!0,jump:b.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),be(b=>b.changed),te(b=>b.jump)),0);ue($(w,te(b=>b.atBottom)),i),ue($(i,fn(50)),l);const g=q(Or);ue($(r,te(({scrollTop:b})=>b),nt(),Zt((b,y)=>at(p)?{direction:b.direction,prevScrollTop:y}:{direction:y<b.prevScrollTop?Pr:Or,prevScrollTop:y},{direction:Or,prevScrollTop:0}),te(b=>b.direction)),g),ue($(r,fn(50),Jt(zg)),g);const x=q(0);return ue($(h,be(b=>!b),Jt(0)),x),ue($(o,fn(100),Re(h),be(([b,y])=>!!y),Zt(([b,y],[E])=>[y,E],[0,0]),te(([b,y])=>y-b)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},tt(bt)),So="top",Co="bottom",lc="none";function cc(e,t,n){return typeof e=="number"?n===Pr&&t===So||n===Or&&t===Co?e:0:n===Pr?t===So?e.main:e.reverse:t===Co?e.main:e.reverse}function uc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=De(),i=q(0),a=q(0),l=q(0),u=xt($(dt(ve(r),ve(o),ve(n),ve(s,Ar),ve(l),ve(i),ve(t),ve(e),ve(a)),te(([d,f,h,[p,w],v,g,x,b,y])=>{const E=d-b,C=g+x,T=Math.max(h-E,0);let I=lc;const A=uc(y,So),R=uc(y,Co);return p-=b,p+=h+x,w+=h+x,w-=b,p>d+C-A&&(I=Pr),w<d-T+f+R&&(I=Or),I!==lc?[Math.max(E-h-cc(v,So,I)-A,0),E-T-x+f+cc(v,Co,I)+R]:null}),be(d=>d!=null),nt(Ar)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},tt(bt),{singleton:!0});function Ug(e,t,n){if(yo(t)){const r=nc(e,t);return[{index:Vt(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 To(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:fc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:fc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function dc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return To(u,[],a,o,n,r)}function fc(e,t,n){if(e.length===0)return[];if(!yo(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=vo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Fn=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=q([]),g=q(0),x=De();ue(s.topItemsIndexes,v);const b=xt($(dt(p,w,ve(l,Ar),ve(o),ve(r),ve(u),d,ve(v),ve(t),ve(n),e),be(([T,I,,A,,,,,,,R])=>{const j=R&&R.length!==A;return T&&!I&&!j}),te(([,,[T,I],A,R,j,M,D,L,P,V])=>{const U=R,{offsetTree:G,sizeTree:F}=U,N=at(g);if(A===0)return{...hi,totalCount:A};if(T===0&&I===0)return N===0?{...hi,totalCount:A}:dc(N,j,R,L,P,V||[]);if(Ye(F))return N>0?null:To(Ug(di(j,A),U,V),[],A,P,U,L);const W=[];if(D.length>0){const me=D[0],ye=D[D.length-1];let H=0;for(const O of vo(F,me,ye)){const K=O.value,J=Math.max(O.start,me),ce=Math.min(O.end,ye);for(let ie=J;ie<=ce;ie++)W.push({data:V==null?void 0:V[ie],index:ie,offset:H,size:K}),H+=K}}if(!M)return To([],W,A,P,U,L);const Y=D.length>0?D[D.length-1]+1:0,de=_g(G,T,I,Y);if(de.length===0)return null;const se=A-1,pe=xo([],me=>{for(const ye of de){const H=ye.value;let O=H.offset,K=ye.start;const J=H.size;if(H.offset<T){K+=Math.floor((T-H.offset+P)/(J+P));const ie=K-ye.start;O+=ie*J+ie*P}K<Y&&(O+=(Y-K)*J,K=Y);const ce=Math.min(ye.end,se);for(let ie=K;ie<=ce&&!(O>=I);ie++)me.push({data:V==null?void 0:V[ie],index:ie,offset:O,size:J}),O+=J+P}});return To(pe,W,A,P,U,L)}),be(T=>T!==null),nt()),hi);ue($(e,be(Qs),te(T=>T==null?void 0:T.length)),o),ue($(b,te(T=>T.topListHeight)),f),ue(f,a),ue($(b,te(T=>[T.top,T.bottom])),i),ue($(b,te(T=>T.items)),x);const y=jt($(b,be(({items:T})=>T.length>0),Re(o,e),be(([{items:T},I])=>T[T.length-1].originalIndex===I-1),te(([,T,I])=>[T-1,I]),nt(Ar),te(([T])=>T))),E=jt($(b,fn(200),be(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),te(({items:T})=>T[0].index),nt())),C=jt($(b,be(({items:T})=>T.length>0),te(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),nt(ec)));return{endReached:y,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:C,startReached:E,topItemsIndexes:v,...h}},tt(Qt,sc,fi,Rr,_r,Mr,yn,ai),{singleton:!0}),hc=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=De(),i=xt($(dt(n,e,r,t,o),te(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ue(ve(i),s),{totalListHeight:i,totalListHeightChanged:s}},tt(bt,Fn),{singleton:!0}),Wg=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=q(!1),r=xt($(dt(n,e,t),be(([o])=>o),te(([,o,s])=>Math.max(0,o-s)),fn(0),nt()),0);return{alignToBottom:n,paddingTopAddition:r}},tt(bt,hc),{singleton:!0}),pc=He(()=>({context:q(null)})),Vg=({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,mc=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=De();return ue($(d,Re(t,l,n,s,o,r,a),Re(e),te(([[f,h,p,w,v,g,x,b],y])=>{const{align:E,behavior:C,calculateViewLocation:T=Vg,done:I,...A}=f,R=rc(f,h,w-1),j=jr(R,h.offsetTree,y)+v+g,M=j+Vt(h.sizeTree,R)[1],D=b+g,L=b+p-x,P=T({itemBottom:M,itemTop:j,locationParams:{align:E,behavior:C,...A},viewportBottom:L,viewportTop:D});return P?I&&Wt($(i,be(V=>!V),Mn(at(i)?1:2)),I):I&&I(),P}),be(f=>f!==null)),u),{scrollIntoView:d}},tt(Qt,bt,_r,Fn,wn),{singleton:!0});function gc(e){return e?e==="smooth"?"smooth":"auto":!1}const Kg=(e,t)=>typeof e=="function"?gc(e(t)):t&&gc(e),qg=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=q(!1),v=De();let g=null;function x(C){_e(i,{align:"end",behavior:C,index:"LAST"})}Ue($(dt($(ve(t),Mn(1)),l),Re(ve(w),s,a,f),te(([[C,T],I,A,R,j])=>{let M=T&&R,D="auto";return M&&(D=Kg(I,A||j),M=M&&!!D),{followOutputBehavior:D,shouldFollow:M,totalCount:C}}),be(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C)}):g=Wt(e,()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C),g=null})});function b(C){const T=Wt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(at(d)("scrolling to bottom due to increased size",{},kt.DEBUG),x("auto"))});setTimeout(T,100)}Ue($(dt(ve(w),t,u),be(([C,,T])=>C&&T),Zt(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),be(({refreshed:C})=>C),Re(w,t)),([,C])=>{at(a)&&b(C!==!1)}),Ue(v,()=>{b(at(w)!==!1)}),Ue(dt(ve(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=q(null),E=De();return ue(ti($(ve(r),te(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),$(ve(t))),E),Ue($(dt($(E,Mn(1)),l),Re(ve(y),a,f,h),te(([[C,T],I,A,R,j])=>T&&A&&(I==null?void 0:I({context:j,totalCount:C,scrollingInProgress:R}))),be(C=>!!C),fn(0)),C=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("scrolling into view",{}),_e(p,C)}):g=Wt(e,()=>{at(d)("scrolling into view",{}),_e(p,C),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:y}},tt(Qt,Mr,_r,Rr,yn,wn,bt,pc,mc)),Gg=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ue($(a,Re(s),be(([,l])=>l!==0),Re(o,r,t,n,e),te(([[,l],u,d,f,h,p=[]])=>dc(l,u,d,f,h,p))),i),{}),tt(Qt,Rr,Fn,yn),{singleton:!0}),Yg=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=q(0);return Ue($(e,Re(r),be(([,o])=>o!==0),te(([,o])=>({top:o}))),o=>{Wt($(n,Mn(1),be(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{_e(t,o)})})}),{initialScrollTop:r}},tt(yn,bt,Fn),{singleton:!0}),xc=He(([{scrollVelocity:e}])=>{const t=q(!1),n=De(),r=q(!1);return ue($(e,Re(r,t,n),be(([o,s])=>!!s),te(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),nt()),t),Ue($(dt(t,e,n),Re(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},tt(Mr),{singleton:!0}),pi=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=De(),r=De(),o=De(),s=q(!1),i=q(void 0);return ue($(dt(n,r),te(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ue($(t,Re(r),te(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},tt(bt)),Xg=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=De(),d=q(void 0),f=q(null),h=q(null);return ue(a,f),ue(l,h),Ue($(u,Re(t,r,i,f,h,n)),([p,w,v,g,x,b,y])=>{const E=Pg(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=y,p({ranges:E,scrollTop:v})}),ue($(d,be(Qs),te(Jg)),o),ue($(s,Re(d),be(([,p])=>p!==void 0),nt(),te(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},tt(Qt,bt,Rr,yn,pi));function Jg(e){return{align:"start",index:0,offset:e.scrollTop}}const Zg=He(([{topItemsIndexes:e}])=>{const t=q(0);return ue($(t,be(n=>n>=0),te(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},tt(Fn));function vc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Qg=vc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),ex=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=jt($(l,Re(i),Zt(([,x,b,y],[{bottom:E,items:C,offsetBottom:T,totalCount:I},A])=>{const R=E+T;let j=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(j=R-y,j!==0&&(j+=A))),[j,C,I,R]},[0,[],0,0]),be(([x])=>x!==0),Re(r,a,n,o,p,w),be(([,x,b,y,,,E])=>!E&&!y&&x!==0&&b===Pr),te(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},kt.DEBUG),x))));function g(x){x>0?(_e(t,{behavior:"auto",top:-x}),_e(e,0)):(_e(e,0),_e(t,{behavior:"auto",top:-x}))}return Ue($(v,Re(e,s)),([x,b,y])=>{y&&Qg()?_e(e,b-x):g(-x)}),Ue($(dt(xt(s,!1),e,w),be(([x,b,y])=>!x&&!y&&b!==0),te(([x,b])=>b),fn(1)),g),ue($(f,te(x=>({top:-x}))),t),Ue($(u,Re(h,d),te(([x,{groupIndices:b,lastSize:y,sizeTree:E},C])=>{function T(I){return I*(y+C)}if(b.length===0)return T(x);{let I=0;const A=Nr(E,0);let R=0,j=0;for(;R<x;){R++,I+=A;let M=b.length===j+1?1/0:b[j+1]-b[j]-1;R+M>x&&(I-=A,M=x-R+1),R+=M,I+=T(M),j++}return I}})),x=>{_e(e,x),requestAnimationFrame(()=>{_e(t,{top:x}),requestAnimationFrame(()=>{_e(e,0),_e(w,!1)})})}),{deviation:e}},tt(bt,Mr,Fn,Qt,wn,ai)),tx=He(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),tt(fi,Gg,yn,xc,hc,Yg,Wg,pi,mc,wn,pc)),wc=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:y,...E},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(ue(E.rangeChanged,R.scrollSeekRangeChanged),ue($(R.windowViewportRect,te(j=>j.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...R,...v,sizes:l,...g}),tt(Qt,Rr,bt,Xg,qg,Fn,_r,ex,Zg,sc,tx));function nx(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 ko=typeof document<"u"?S.useLayoutEffect:S.useEffect;function bc(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 l(g,x){g.propsReady&&_e(g.propsReady,!1);for(const b of r){const y=g[t.required[b]];_e(y,x[b])}for(const b of o)if(b in x){const y=g[t.optional[b]];_e(y,x[b])}g.propsReady&&_e(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=y=>{const E=g[t.methods[b]];_e(E,y)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=vg(g[t.events[b]]),x),{})}const f=S.forwardRef((g,x)=>{const{children:b,...y}=g,[E]=S.useState(()=>xo(bg(e),I=>{l(I,y)})),[C]=S.useState(Ul(d,E));ko(()=>{for(const I of i)I in y&&Ue(C[I],y[I]);return()=>{Object.values(C).map(ei)}},[y,C,E]),ko(()=>{l(E,y)}),S.useImperativeHandle(x,Bl(u(E)));const T=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(T,{...nx([...r,...o,...i],y),children:b}):b})}),h=g=>{const x=S.useContext(a);return S.useCallback(b=>{_e(x[g],b)},[x,g])},p=g=>{const x=S.useContext(a)[g],b=S.useCallback(y=>Ue(x,y),[x]);return S.useSyncExternalStore(b,()=>at(x),()=>at(x))},w=g=>{const x=S.useContext(a)[g],[b,y]=S.useState(Ul(at,x));return ko(()=>Ue(x,E=>{E!==b&&y(Bl(E))}),[x,b]),b},v=S.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const b=S.useContext(a)[g];ko(()=>Ue(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const yc=S.createContext(void 0),Sc=S.createContext(void 0),Cc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function mi(e){return"self"in e}function rx(e){return"body"in e}function Tc(e,t,n,r=sr,o,s){const i=S.useRef(null),a=S.useRef(null),l=S.useRef(null),u=S.useCallback(h=>{let p,w,v;const g=h.target;if(rx(g)||mi(g)){const b=mi(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Rs.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);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 p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;mi(p)?(g=Math.max(bn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=bn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),ac(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const gi="-webkit-sticky",kc="sticky",xi=vc(()=>{if(typeof document>"u")return kc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:kc});function vi(e){return e}const ox=He(()=>{const e=q(a=>`Item ${a}`),t=q(a=>`Group ${a}`),n=q({}),r=q(vi),o=q("div"),s=q(sr),i=(a,l=null)=>xt($(n,te(u=>u[a]),nt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),sx=He(([e,t])=>({...e,...t}),tt(wc,ox)),ix=({height:e})=>c.jsx("div",{style:{height:e}}),ax={overflowAnchor:"none",position:xi(),zIndex:1},Ec={overflowAnchor:"none"},lx={...Ec,display:"inline-block",height:"100%"},Ic=S.memo(function({showTopList:e=!1}){const t=Ie("listState"),n=Lt("sizeRanges"),r=Ie("useWindowScroll"),o=Ie("customScrollParent"),s=Lt("windowScrollContainerState"),i=Lt("scrollContainerState"),a=o||r?s:i,l=Ie("itemContent"),u=Ie("context"),d=Ie("groupContent"),f=Ie("trackItemSizes"),h=Ie("itemSize"),p=Ie("log"),w=Lt("gap"),v=Ie("horizontalDirection"),{callbackRef:g}=Cg(n,h,f,e?sr:a,p,w,o,v,Ie("skipAnimationFrameInResizeObserver")),[x,b]=S.useState(0);wi("deviation",P=>{x!==P&&b(P)});const y=Ie("EmptyPlaceholder"),E=Ie("ScrollSeekPlaceholder")||ix,C=Ie("ListComponent"),T=Ie("ItemComponent"),I=Ie("GroupComponent"),A=Ie("computeItemKey"),R=Ie("isSeeking"),j=Ie("groupIndices").length>0,M=Ie("alignToBottom"),D=Ie("initialItemFinalLocationReached"),L=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?c.jsx(y,{...vt(y,u)}):c.jsx(C,{...vt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:L,children:(e?t.topItems:t.items).map(P=>{const V=P.originalIndex,U=A(V+t.firstItemIndex,P.data,u);return R?S.createElement(E,{...vt(E,u),height:P.size,index:P.index,key:U,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?S.createElement(I,{...vt(I,u),"data-index":V,"data-item-index":P.index,"data-known-size":P.size,key:U,style:ax},d(P.index,u)):S.createElement(T,{...vt(T,u),...fx(T,P.data),"data-index":V,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:U,style:v?lx:Ec},j?l(P.index,P.groupIndex,P.data,u):l(P.index,P.data,u))})})}),cx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ux={outline:"none",overflowX:"auto",position:"relative"},Eo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),dx={position:xi(),top:0,width:"100%",zIndex:1};function vt(e,t){if(typeof e!="string")return{context:t}}function fx(e,t){return{item:typeof e=="string"?void 0:t}}const hx=S.memo(function(){const e=Ie("HeaderComponent"),t=Lt("headerHeight"),n=Ie("HeaderFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,Ie("skipAnimationFrameInResizeObserver")),o=Ie("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),px=S.memo(function(){const e=Ie("FooterComponent"),t=Lt("footerHeight"),n=Ie("HeaderFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,Ie("skipAnimationFrameInResizeObserver")),o=Ie("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null});function Nc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Tc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?ux:cx,...o},tabIndex:0,...i,...vt(l,s),children:r})})}function Ac({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Tc(a,u,l,w,h);return Cc(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...vt(l,s),children:r})})}const mx=({children:e})=>{const t=S.useContext(yc),n=Lt("viewportHeight"),r=Lt("fixedItemHeight"),o=Ie("alignToBottom"),s=Ie("horizontalDirection"),i=S.useMemo(()=>Hl(n,l=>bn(l,s?"width":"height")),[n,s]),a=Dn(i,!0,Ie("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Eo(o),children:e})},gx=({children:e})=>{const t=S.useContext(yc),n=Lt("windowViewportRect"),r=Lt("fixedItemHeight"),o=Ie("customScrollParent"),s=ql(n,o,Ie("skipAnimationFrameInResizeObserver")),i=Ie("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Eo(i),children:e})},xx=({children:e})=>{const t=Ie("TopItemListComponent")||"div",n=Ie("headerHeight"),r={...dx,marginTop:`${n}px`},o=Ie("context");return c.jsx(t,{style:r,...vt(t,o),children:e})},vx=S.memo(function(e){const t=Ie("useWindowScroll"),n=Ie("topItemsIndexes").length>0,r=Ie("customScrollParent"),o=Ie("context");return c.jsxs(r||t?yx:bx,{...e,context:o,children:[n&&c.jsx(xx,{children:c.jsx(Ic,{showTopList:!0})}),c.jsxs(r||t?gx:mx,{children:[c.jsx(hx,{}),c.jsx(Ic,{}),c.jsx(px,{})]})]})}),{Component:wx,useEmitter:wi,useEmitterValue:Ie,usePublisher:Lt}=bc(sx,{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"}},vx),bx=Nc({useEmitter:wi,useEmitterValue:Ie,usePublisher:Lt}),yx=Ac({useEmitter:wi,useEmitterValue:Ie,usePublisher:Lt}),Sx=wx;tt(wc,He(()=>{const e=q(u=>c.jsxs("td",{children:["Item $",u]})),t=q(null),n=q(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=q(null),o=q(null),s=q({}),i=q(vi),a=q(sr),l=(u,d=null)=>xt($(s,te(f=>f[u]),nt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xi();const jc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Cx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:_c,floor:Io,max:Dr,min:bi,round:Rc}=Math;function Pc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Tx(e){return{...Cx,items:e}}function No(e,t){return e&&e.width===t.width&&e.height===t.height}function kx(e,t){return e&&e.column===t.column&&e.row===t.row}const Ex=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E},C])=>{const T=q(0),I=q(0),A=q(jc),R=q({height:0,width:0}),j=q({height:0,width:0}),M=De(),D=De(),L=q(0),P=q(null),V=q({column:0,row:0}),U=De(),G=De(),F=q(!1),N=q(0),W=q(!0),Y=q(!1),de=q(!1);Ue($(w,Re(N),be(([O,K])=>!!K)),()=>{_e(W,!1)}),Ue($(dt(w,W,j,R,N,Y),be(([O,K,J,ce,,ie])=>O&&!K&&J.height!==0&&ce.height!==0&&!ie)),([,,,,O])=>{_e(Y,!0),ui(1,()=>{_e(M,O)}),Wt($(u),()=>{_e(t,[0,0]),_e(W,!0)})}),ue($(G,be(O=>O!=null&&O.scrollTop>0),Jt(0)),I),Ue($(w,Re(G),be(([,O])=>O!=null)),([,O])=>{O&&(_e(R,O.viewport),_e(j,O.item),_e(V,O.gap),O.scrollTop>0&&(_e(F,!0),Wt($(u,Mn(1)),K=>{_e(F,!1)}),_e(l,{top:O.scrollTop})))}),ue($(R,te(({height:O})=>O)),f),ue($(dt(ve(R,No),ve(j,No),ve(V,(O,K)=>O&&O.column===K.column&&O.row===K.row),ve(u)),te(([O,K,J,ce])=>({gap:J,item:K,scrollTop:ce,viewport:O}))),U),ue($(dt(ve(T),r,ve(V,kx),ve(j,No),ve(R,No),ve(P),ve(I),ve(F),ve(W),ve(N)),be(([,,,,,,,O])=>!O),te(([O,[K,J],ce,ie,Le,We,Ze,,Ee,Pe])=>{const{column:Qe,row:$e}=ce,{height:qe,width:lt}=ie,{width:Z}=Le;if(Ze===0&&(O===0||Z===0))return jc;if(lt===0){const B=di(Pe,O),ne=B+Math.max(Ze-1,0);return Tx(Pc(B,ne,We))}const le=Oc(Z,lt,Qe);let ge,Ce;Ee?K===0&&J===0&&Ze>0?(ge=0,Ce=Ze-1):(ge=le*Io((K+$e)/(qe+$e)),Ce=le*_c((J+$e)/(qe+$e))-1,Ce=bi(O-1,Dr(Ce,le-1)),ge=bi(Ce,Dr(0,ge))):(ge=0,Ce=-1);const we=Pc(ge,Ce,We),{bottom:Ae,top:et}=Mc(Le,ce,ie,we),Ve=_c(O/le),ct=Ve*qe+(Ve-1)*$e-Ae;return{bottom:Ae,itemHeight:qe,items:we,itemWidth:lt,offsetBottom:ct,offsetTop:et,top:et}})),A),ue($(P,be(O=>O!==null),te(O=>O.length)),T),ue($(dt(R,j,A,V),be(([O,K,{items:J}])=>J.length>0&&K.height!==0&&O.height!==0),te(([O,K,{items:J},ce])=>{const{bottom:ie,top:Le}=Mc(O,ce,K,J);return[Le,ie]}),nt(Ar)),t);const se=q(!1);ue($(u,Re(se),te(([O,K])=>K||O!==0)),se);const pe=jt($(dt(A,T),be(([{items:O}])=>O.length>0),Re(se),be(([[O,K],J])=>{const ce=O.items[O.items.length-1].index===K-1;return(J||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===K)&&ce}),te(([[,O]])=>O-1),nt())),me=jt($(ve(A),be(({items:O})=>O.length>0&&O[0].index===0),Jt(0),nt())),ye=jt($(ve(A),Re(F),be(([{items:O},K])=>O.length>0&&!K),te(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),nt(ec),fn(0)));ue(ye,p.scrollSeekRangeChanged),ue($(M,Re(R,j,T,V),te(([O,K,J,ce,ie])=>{const Le=ic(O),{align:We,behavior:Ze,offset:Ee}=Le;let Pe=Le.index;Pe==="LAST"&&(Pe=ce-1),Pe=Dr(0,Pe,bi(ce-1,Pe));let Qe=yi(K,ie,J,Pe);return We==="end"?Qe=Rc(Qe-K.height+J.height):We==="center"&&(Qe=Rc(Qe-K.height/2+J.height/2)),Ee&&(Qe+=Ee),{behavior:Ze,top:Qe}})),l);const H=xt($(A,te(O=>O.offsetBottom+O.bottom)),0);return ue($(E,te(O=>({height:O.visibleHeight,width:O.visibleWidth}))),R),{customScrollParent:g,data:P,deviation:L,footerHeight:o,gap:V,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:G,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:M,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E,...p,gridState:A,horizontalDirection:de,initialTopMostItemIndex:N,totalListHeight:H,...h,endReached:pe,propsReady:v,rangeChanged:ye,startReached:me,stateChanged:U,stateRestoreInProgress:F,...C}},tt(fi,bt,Mr,xc,yn,pi,wn));function Oc(e,t,n){return Dr(1,Io((e+n)/(Io(t)+n)))}function Mc(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=Oc(e.width,n.width,t.column),s=Io(r/o),i=s*n.height+Dr(0,s-1)*t.row;return i>0?i+t.row:i}const Ix=He(()=>{const e=q(f=>`Item ${f}`),t=q({}),n=q(null),r=q("virtuoso-grid-item"),o=q("virtuoso-grid-list"),s=q(vi),i=q("div"),a=q(sr),l=(f,h=null)=>xt($(t,te(p=>p[f]),nt()),h),u=q(!1),d=q(!1);return ue(ve(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Nx=He(([e,t])=>({...e,...t}),tt(Ex,Ix)),Ax=S.memo(function(){const e=ot("gridState"),t=ot("listClassName"),n=ot("itemClassName"),r=ot("itemContent"),o=ot("computeItemKey"),s=ot("isSeeking"),i=Ft("scrollHeight"),a=ot("ItemComponent"),l=ot("ListComponent"),u=ot("ScrollSeekPlaceholder"),d=ot("context"),f=Ft("itemDimensions"),h=Ft("gap"),p=ot("log"),w=ot("stateRestoreInProgress"),v=Ft("reportReadyState"),g=Dn(S.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const y=x.firstChild;if(y){const{height:E,width:C}=y.getBoundingClientRect();f({height:E,width:C})}h({column:Lc("column-gap",getComputedStyle(x).columnGap,p),row:Lc("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Cc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...vt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?c.jsx(u,{...vt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):S.createElement(a,{...vt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),jx=S.memo(function(){const e=ot("HeaderComponent"),t=Ft("headerHeight"),n=ot("headerFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=ot("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),_x=S.memo(function(){const e=ot("FooterComponent"),t=Ft("footerHeight"),n=ot("headerFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=ot("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),Rx=({children:e})=>{const t=S.useContext(Sc),n=Ft("itemDimensions"),r=Ft("viewportDimensions"),o=Dn(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]),c.jsx("div",{ref:o,style:Eo(!1),children:e})},Px=({children:e})=>{const t=S.useContext(Sc),n=Ft("windowViewportRect"),r=Ft("itemDimensions"),o=ot("customScrollParent"),s=ql(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]),c.jsx("div",{ref:s,style:Eo(!1),children:e})},Ox=S.memo(function({...e}){const t=ot("useWindowScroll"),n=ot("customScrollParent"),r=n||t?Dx:Mx,o=n||t?Px:Rx,s=ot("context");return c.jsx(r,{...e,...vt(r,s),children:c.jsxs(o,{children:[c.jsx(jx,{}),c.jsx(Ax,{}),c.jsx(_x,{})]})})}),{useEmitter:Dc,useEmitterValue:ot,usePublisher:Ft}=bc(Nx,{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"}},Ox),Mx=Nc({useEmitter:Dc,useEmitterValue:ot,usePublisher:Ft}),Dx=Ac({useEmitter:Dc,useEmitterValue:ot,usePublisher:Ft});function Lc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Lx=eo.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 c.jsx("div",{className:X(Lx({variant:t}),e),...n})}function oe(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 Fx(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function en(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,$x(o,...t)]}function $x(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var pt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},zx=m[" useInsertionEffect ".trim().toString()]||pt;function $n({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Bx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=Hx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Bx({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return zx(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Hx(e){return typeof e=="function"}function Fc(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=Fc(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():Fc(e[o],null)}}}}function Oe(...e){return m.useCallback(Ci(...e),e)}var Ux=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=Ux.reduce((e,t)=>{const n=_n.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function $c(e,t){e&&to.flushSync(()=>e.dispatchEvent(t))}function Wx(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Rt=e=>{const{present:t,children:n}=e,r=Vx(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Oe(r.ref,Kx(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Rt.displayName="Presence";function Vx(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wx(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Ao(r.current);s.current=a==="mounted"?u:"none"},[a]),pt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Ao(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),pt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=Ao(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Ao(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Ao(e){return(e==null?void 0:e.animationName)||"none"}function Kx(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 qx=m[" useId ".trim().toString()]||(()=>{}),Gx=0;function tn(e){const[t,n]=m.useState(qx());return pt(()=>{n(r=>r??String(Gx++))},[e]),e||(t?`radix-${t}`:"")}var jo="Collapsible",[Yx,OC]=en(jo),[Xx,Ti]=Yx(jo),zc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=$n({prop:r,defaultProp:o??!1,onChange:i,caller:jo});return c.jsx(Xx,{scope:n,disabled:s,contentId:tn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Se.div,{"data-state":Ei(l),"data-disabled":s?"":void 0,...a,ref:t})})});zc.displayName=jo;var Bc="CollapsibleTrigger",Hc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Ti(Bc,n);return c.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:oe(e.onClick,o.onOpenToggle)})});Hc.displayName=Bc;var ki="CollapsibleContent",Jx=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ti(ki,e.__scopeCollapsible);return c.jsx(Rt,{present:n||o.open,children:({present:s})=>c.jsx(Zx,{...r,ref:t,present:s})})});Jx.displayName=ki;var Zx=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Ti(ki,n),[a,l]=m.useState(r),u=m.useRef(null),d=Oe(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),pt(()=>{const b=u.current;if(b){x.current=x.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const y=b.getBoundingClientRect();f.current=y.height,p.current=y.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Se.div,{"data-state":Ei(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function Ei(e){return e?"open":"closed"}var Qx=zc;const Uc=Qx,Wc=Hc,Lr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Lr.displayName="Card";const Fr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex flex-col space-y-1.5 p-6",e),...t}));Fr.displayName="CardHeader";const $r=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:X("text-2xl font-semibold leading-none tracking-tight",e),...t}));$r.displayName="CardTitle";const Vc=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:X("text-sm text-muted-foreground",e),...t}));Vc.displayName="CardDescription";const _o=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("p-6 pt-0",e),...t}));_o.displayName="CardContent";const Kc=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex items-center p-6 pt-0",e),...t}));Kc.displayName="CardFooter";function qc(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let zn=qc();function ev(e){zn=e}const Gc=/[&<>"']/,tv=new RegExp(Gc.source,"g"),Yc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,nv=new RegExp(Yc.source,"g"),rv={"&":"&","<":"<",">":">",'"':""","'":"'"},Xc=e=>rv[e];function wt(e,t){if(t){if(Gc.test(e))return e.replace(tv,Xc)}else if(Yc.test(e))return e.replace(nv,Xc);return e}const ov=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Jc(e){return e.replace(ov,(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 sv=/(^|[^\[])\^/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(sv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const iv=/[^\w:]/g,av=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Zc(e,t,n){if(e){let r;try{r=decodeURIComponent(Jc(n)).replace(iv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!av.test(n)&&(n=dv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ro={},lv=/^[^:]+:\/*[^/]*$/,cv=/^([^:]+:)[\s\S]*$/,uv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function dv(e,t){Ro[" "+e]||(lv.test(e)?Ro[" "+e]=e+"/":Ro[" "+e]=Oo(e,"/",!0)),e=Ro[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(cv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(uv,"$1")+t:e+t}const Po={exec:function(){}};function Qc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Oo(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 fv(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 hv(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 eu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function tu(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 pv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
38
|
+
`)}function ig({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=S.useRef(null),i=S.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){t(p);return}if(Ym(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Ol({baseUrl:e,token:null}),h=S.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return S.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Ml=S.createContext(null),Dl=S.createContext(null),Ll=S.createContext(null),ag=S.createContext(!1),lg=20;function cg({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Gs(),d=S.useMemo(()=>dn(u),[u]),[f,h]=S.useState([]),[p,w]=S.useState(t),[v,g]=S.useState(!1),[x,b]=S.useState(!1),[y,E]=S.useState(!1),[C,T]=S.useState(!1),[I,A]=S.useState(null),[R,j]=S.useState(void 0),[M,D]=S.useState(void 0),{state:L,seed:P,prepend:V,pushUser:U,onEvent:G,reset:F}=Rl(),N=S.useRef(p);S.useEffect(()=>{N.current=p},[p]);const W=S.useRef(!1),Y=S.useRef([]),de=S.useRef(null),se=S.useRef(null),pe=S.useCallback((B,ne)=>new Promise((je,rt)=>{const Ge=async()=>{W.current=!0;try{await B(),je()}catch(Et){rt(Et)}finally{W.current=!1;const Et=Y.current.shift();Et&&Et().catch(()=>{})}};W.current?Y.current.push(Ge):Ge().catch(Et=>{rt(Et)})}),[]),me=S.useCallback(async()=>{g(!0);try{const B=await l.listThreads();h(B)}catch(B){i==null||i(String(B)),console.error("[ChatSessionProvider] Failed to refresh threads:",B)}finally{g(!1)}},[l,i]),ye=S.useCallback(async()=>{try{await me()}catch(B){console.error("[ChatSessionProvider] Failed to refresh threads after stream:",B)}},[me]),H=S.useRef(!1),O=S.useCallback((B,ne)=>{const je=Array.isArray(B==null?void 0:B.messages)?B.messages:[];ne==="replace"?P(je,{checkpointId:(B==null?void 0:B.checkpointId)??null,checkpointNs:(B==null?void 0:B.checkpointNs)??null}):ne==="prepend"&&je.length&&V(je),A((B==null?void 0:B.nextCursor)??null),E(!!(B!=null&&B.hasMore)),j(rt=>(B==null?void 0:B.checkpointId)??rt??void 0),D(rt=>(B==null?void 0:B.checkpointNs)??rt??void 0)},[V,P]),K=S.useCallback(()=>{F([]),E(!1),T(!1),A(null),j(void 0),D(void 0)},[F]),J=S.useCallback(({from:B,to:ne})=>{const je=N.current;je&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${B} -> ${ne}) for thread ${je}`)},[]),ce=S.useCallback(B=>{const ne=B.threadId;if(B.created,B.ready,N.current!==ne){!N.current&&L.messages.length<=1&&(se.current=ne),w(ne);return}},[]),{startStream:ie,stop:Le,isStreaming:We,error:Ze,setAuthToken:Ee}=ig({baseUrl:d,onThreadInfo:ce,onMessageEvent:G,onUnhandledEvent:B=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${B.type}`,B)},onSequenceGap:J});S.useEffect(()=>{H.current=We,We||ye()},[ye,We]),S.useEffect(()=>{var je;const B=l.getAuthToken();Ee(B);const ne=(je=l.onTokenChange)==null?void 0:je.call(l,rt=>{Ee(rt)});return()=>{ne==null||ne()}},[l,Ee]);const Pe=S.useCallback(async B=>{const ne=await l.createThread(B),je=typeof ne=="string"?ne:ne.threadId;return await me(),w(je),je},[l,me]),Qe=S.useCallback(async B=>{await l.deleteThread(B),N.current===B&&(se.current=B,w(null),K()),await me()},[l,K,me]),$e=S.useCallback(async(B,ne)=>{try{await l.updateThread(B,ne),h(je=>je.map(rt=>rt.threadId===B?{...rt,title:ne}:rt))}catch(je){throw await me(),je}},[l,me]),qe=S.useCallback(async(B,ne,je,rt=!1)=>{await pe(async()=>{if(se.current===B&&!rt){se.current=null;return}if(!(de.current===B&&!rt)){w(Ge=>Ge===B?Ge:B),de.current=B,b(!0);try{const Ge=await l.getMessages({threadId:B,checkpointId:ne,checkpointNs:je});O(Ge,"replace"),j((Ge==null?void 0:Ge.checkpointId)??void 0),D((Ge==null?void 0:Ge.checkpointNs)??void 0)}catch(Ge){throw i==null||i(String(Ge)),Ge}finally{de.current=null,b(!1)}}},`loadThread-${B}`)},[l,O,pe,i]),lt=S.useCallback(async()=>{await pe(async()=>{N.current&&(se.current=N.current),w(null),K(),j(void 0),D(void 0);try{localStorage.removeItem("lastThreadId")}catch(B){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",B)}},"clearCurrentThread")},[K,pe]),Z=S.useCallback(async B=>{const ne=await l.listCheckpoints(B);return Km(ne,B)},[l]),le=S.useCallback(async(B,ne)=>{if(!N.current)throw new Error("No active thread");await qe(N.current,B,ne??void 0,!0)},[qe]),ge=S.useCallback(async()=>{if(!N.current)throw new Error("No active thread");await qe(N.current,void 0,void 0,!0)},[qe]),Ce=S.useCallback(async B=>{if(!N.current)throw new Error("No active thread");if(C||!y)return;const ne=I;if(ne){T(!0);try{const je=await l.getMessages({threadId:N.current,checkpointId:R,checkpointNs:M,limit:(B==null?void 0:B.limit)??lg,beforeId:ne});O(je,"prepend")}finally{T(!1)}}},[l,O,y,R,M,I,C]),we=S.useCallback(async(B,ne)=>{var Qn;const je=N.current;!je&&!(ne!=null&&ne.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const rt=(ne==null?void 0:ne.attachments)||[],{contentParts:Ge,filesInfo:Et}=await Gm(l,rt),Xn=[...Ge];B&&B.trim()&&Xn.push({type:"text",text:B.trim()});const jn={id:((Qn=crypto.randomUUID)==null?void 0:Qn.call(crypto))||`user-${Date.now()}`,role:"user",content:Xn,createdAt:new Date().toISOString(),checkpointId:(ne==null?void 0:ne.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ne==null?void 0:ne.checkpointNs)??L.lastCheckpointNs??void 0};U(jn);const vr={...jn,content:Xn},cn={...(ne==null?void 0:ne.payloadExtras)??{}},Jn=rt.length>0,Zn={...je?{threadId:je}:{},payload:{messages:[vr],files_info:Et,...o&&Jn&&s?{active_agent:s}:{},...cn},checkpointId:(ne==null?void 0:ne.checkpointId)??L.lastCheckpointId??void 0,checkpointNs:(ne==null?void 0:ne.checkpointNs)??L.lastCheckpointNs??void 0,nodeFilter:ne==null?void 0:ne.nodeFilter,config:ne==null?void 0:ne.config};ie(Zn,{onError:mn=>{console.warn("[ChatSessionProvider] Stream error:",mn)},onOpen:({threadId:mn,created:Zr})=>{!N.current&&mn&&(L.messages.length<=1&&(se.current=mn),w(mn))},onGap:J})},[l,o,s,J,L.lastCheckpointId,L.lastCheckpointNs,L.messages.length,U,ie]),Ae=S.useCallback(async(B,ne,je)=>{const rt=N.current;if(!rt)throw new Error("No active thread to handle interrupt");try{const Ge=ne?je??!0:!1;await l.resume({threadId:rt,value:Ge})}catch(Ge){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${B}:`,Ge),Ge}},[l]);S.useEffect(()=>{if(a==null||a(p),p)try{localStorage.setItem("lastThreadId",p)}catch(B){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",B)}},[p,a]),S.useEffect(()=>{let B=!0;return(async()=>{try{if(await me(),!B)return;if(!r&&!t)try{const je=localStorage.getItem("lastThreadId");je&&(w(je),n&&await qe(je))}catch(je){console.warn("[ChatSessionProvider] Failed to restore last thread:",je)}else t&&n&&await qe(t)}catch(je){console.error("[ChatSessionProvider] Initialization failed:",je),i==null||i(String(je))}})(),()=>{B=!1}},[]);const et=S.useMemo(()=>({threads:f,currentThreadId:p,isLoadingThreads:v,isLoadingThread:x,setCurrentThreadId:w,createThread:Pe,deleteThread:Qe,renameThread:$e,refreshThreads:me,loadThread:qe,clearCurrentThread:lt,listCheckpoints:Z,navigateToCheckpoint:le,returnToLatest:ge}),[lt,Pe,p,Qe,x,v,Z,qe,le,me,$e,ge,f]),Ve=S.useMemo(()=>({messages:L.messages,assemblingId:L.assemblingId,lastUserMessage:null,hasMoreHistory:y,isLoadingHistory:C,send:we,stop:Le,loadOlderMessages:Ce,clearMessages:K,handleInterrupt:Ae}),[K,Ae,y,C,Ce,L.assemblingId,L.messages,we,Le]),ct=S.useMemo(()=>({isStreaming:We,error:Ze,streamingAssistantId:L.assemblingId,lastCheckpointId:L.lastCheckpointId??null,lastCheckpointNs:L.lastCheckpointNs??null}),[We,L.assemblingId,L.lastCheckpointId,L.lastCheckpointNs,Ze]);return c.jsx(ag.Provider,{value:!0,children:c.jsx(Ll.Provider,{value:ct,children:c.jsx(Ml.Provider,{value:et,children:c.jsx(Dl.Provider,{value:Ve,children:e})})})})}function po(){const e=S.useContext(Ml);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Zs(){const e=S.useContext(Dl);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function Fl(){const e=S.useContext(Ll);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function mo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Vm,{apiConfig:t,children:c.jsx(cg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function X(...e){return bp.twMerge(wp.clsx(e))}const ug=eo.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"}}),Be=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?_n.Slot:"button";return c.jsx(i,{className:X(ug({variant:t,size:n,className:e})),ref:s,...o})});Be.displayName="Button";const $l=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:X("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}));$l.displayName="Textarea";function dg({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=S.useState(e),[w,v]=S.useTransition(),g=S.useRef(null);S.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const b=S.useCallback(async A=>{A&&A.preventDefault();const R=(h??"").trim();!R&&!f||v(()=>{try{const j=i(R);j&&typeof j.then=="function"?j.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),y=S.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=S.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx($l,{ref:g,value:h,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Be,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(Q.Square,{size:16})}):c.jsx(Be,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(Q.Send,{size:16})})})]})})}const fg=S.memo(dg),go=0,vn=1,or=2,zl=4;function Bl(e){return()=>e}function hg(e){e()}function Hl(e,t){return n=>e(t(n))}function Ul(e,t){return()=>e(t)}function pg(e,t){return n=>e(t,n)}function Qs(e){return e!==void 0}function mg(...e){return()=>{e.map(hg)}}function sr(){}function xo(e,t){return t(e),e}function gg(e,t){return t(e)}function tt(...e){return e}function Ue(e,t){return e(vn,t)}function _e(e,t){e(go,t)}function ei(e){e(or)}function at(e){return e(zl)}function ue(e,t){return Ue(e,pg(t,go))}function Wt(e,t){const n=e(vn,r=>{n(),t(r)});return n}function Wl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Vl(e,t){return e===t}function nt(e=Vl){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function be(e){return t=>n=>{e(n)&&t(n)}}function te(e){return t=>Hl(t,e)}function Jt(e){return t=>()=>{t(e)}}function $(e,...t){const n=xg(...t);return(r,o)=>{switch(r){case or:ei(e);return;case vn:return Ue(e,n(o))}}}function Zt(e,t){return n=>r=>{n(t=e(t,r))}}function Mn(e){return t=>n=>{e>0?e--:t(n)}}function fn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Re(...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);Ue(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function xg(...e){return t=>e.reduceRight(gg,t)}function vg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case vn:return s?n===s?void 0:(r(),n=s,t=Ue(e,s),t):(r(),sr);case or:r(),n=null;return}}}function q(e){let t=e;const n=De();return(r,o)=>{switch(r){case go:t=o;break;case vn:{o(t);break}case zl:return t}return n(r,o)}}function xt(e,t){return xo(q(t),n=>ue(e,n))}function De(){const e=[];return(t,n)=>{switch(t){case go:e.slice().forEach(r=>{r(n)});return;case or:e.splice(0,e.length);return;case vn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function jt(e){return xo(De(),t=>ue(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:wg(),singleton:n}}const wg=()=>Symbol();function bg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function dt(...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);Ue(s,l=>{n[i]=l,r=r|a,r===o&&_e(t,n)})}),function(s,i){switch(s){case or:{ei(t);return}case vn:return r===o&&i(n),Ue(t,i)}}}function ve(e,t=Vl){return $(e,nt(t))}function ti(...e){return function(t,n){switch(t){case or:return;case vn:return mg(...e.map(r=>Ue(r,n)))}}}var kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(kt||{});const yg={0:"debug",3:"error",1:"log",2:"warn"},Sg=()=>typeof globalThis>"u"?window:globalThis,wn=He(()=>{const e=q(3);return{log:q((t,n,r=1)=>{var o;const s=(o=Sg().VIRTUOSO_LOG_LEVEL)!=null?o:at(e);r>=s&&console[yg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Dn(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 l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Cg(e,t,n,r,o,s,i,a,l){const u=S.useCallback(d=>{const f=Tg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?Kl("column-gap",getComputedStyle(d).columnGap,o):Kl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ni(u,n,l)}function Tg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},kt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Kl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ql(e,t,n){const r=S.useRef(null),o=S.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ni(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const bt=He(()=>{const e=De(),t=De(),n=q(0),r=De(),o=q(0),s=De(),i=De(),a=q(0),l=q(0),u=q(0),d=q(0),f=De(),h=De(),p=q(!1),w=q(!1),v=q(!1);return ue($(e,te(({scrollTop:g})=>g)),t),ue($(e,te(({scrollHeight:g})=>g)),i),ue(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Ir={lvl:0};function Gl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Ye(e){return e===Ir}function Nr(e,t){if(!Ye(e))return t===e.k?e.v:t<e.k?Nr(e.l,t):Nr(e.r,t)}function Vt(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=Vt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Vt(e.l,t,n)}function _t(e,t,n){return Ye(e)?Jl(t,n,1):t===e.k?ht(e,{k:t,v:n}):t<e.k?Zl(ht(e,{l:_t(e.l,t,n)})):Zl(ht(e,{r:_t(e.r,t,n)}))}function ir(){return Ir}function vo(e,t,n){if(Ye(e))return[];const r=Vt(e,t)[0];return kg(oi(e,r,n))}function ri(e,t){if(Ye(e))return Ir;const{k:n,l:r,r:o}=e;if(t===n){if(Ye(r))return o;if(Ye(o))return r;{const[s,i]=Xl(r);return wo(ht(e,{k:s,l:Yl(r),v:i}))}}else return t<n?wo(ht(e,{l:ri(r,t)})):wo(ht(e,{r:ri(o,t)}))}function Ln(e){return Ye(e)?[]:[...Ln(e.l),{k:e.k,v:e.v},...Ln(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 wo(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 Ql(ht(e,{lvl:n-1}));if(!Ye(t)&&!Ye(t.r))return ht(t.r,{l:ht(t,{r:t.r.l}),lvl:n,r:ht(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(si(e))return ii(ht(e,{lvl:n-1}));if(!Ye(r)&&!Ye(r.l)){const o=r.l,s=si(o)?r.lvl-1:r.lvl;return ht(o,{l:ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ii(ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ht(e,t){return Jl(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 Yl(e){return Ye(e.r)?e.l:wo(ht(e,{r:Yl(e.r)}))}function si(e){return Ye(e)||e.lvl>e.r.lvl}function Xl(e){return Ye(e.r)?[e.k,e.v]:Xl(e.r)}function Jl(e,t,n,r=Ir,o=Ir){return{k:e,l:r,lvl:n,r:o,v:t}}function Zl(e){return ii(Ql(e))}function Ql(e){const{l:t}=e;return!Ye(t)&&t.lvl===e.lvl?ht(t,{r:ht(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?ht(n,{l:ht(e,{r:n.l}),lvl:t+1}):e}function kg(e){return Gl(e,({k:t,v:n})=>({index:t,value:n}))}function ec(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Ar(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ai=He(()=>({recalcInProgress:q(!1)}),[],{singleton:!0});function tc(e,t,n){return e[bo(e,t,n)]}function bo(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 Eg(e,t,n,r){const o=bo(e,t,r),s=bo(e,n,r,o);return e.slice(o,s+1)}function bn(e,t){return Math.round(e.getBoundingClientRect()[t])}function yo(e){return!Ye(e.groupOffsetTree)}function li({index:e},t){return t===e?0:t<e?-1:1}function Ig(){return{groupIndices:[],groupOffsetTree:ir(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:ir()}}function Ng(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=_t(e,0,s);continue}const a=vo(e,i-1,o+1);if(a.some(Mg(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ri(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=_t(e,o+1,h));u&&(e=_t(e,i,s))}return[e,n]}function Ag(e){return typeof e.groupIndex<"u"}function jg({offset:e},t){return t===e?0:t<e?-1:1}function jr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=tc(t,e,li),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function nc(e,t){if(!yo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function rc(e,t,n){if(Ag(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=nc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function _g(e,t,n,r=0){return r>0&&(t=Math.max(t,tc(e,r,li).offset)),Gl(Eg(e,t,n,jg),Og)}function Rg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ye(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>_t(_t(w,v,h),v+1,p),i)}else[i,a]=Ng(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=ci(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>_t(h,p,jr(p,f,o)),ir()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Pg(e){return Ln(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 oc(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,l=0;if(t!==0){l=bo(o,t-1,li),a=o[l].offset;const u=Vt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Vt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of vo(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 Og(e){return{index:e.index,value:e}}function Mg(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 Dg={offsetHeight:"height",offsetWidth:"width"},Qt=He(([{log:e},{recalcInProgress:t}])=>{const n=De(),r=De(),o=xt(r,0),s=De(),i=De(),a=q(0),l=q([]),u=q(void 0),d=q(void 0),f=q((C,T)=>bn(C,Dg[T])),h=q(void 0),p=q(0),w=Ig(),v=xt($(n,Re(l,e,p),Zt(Rg,w),nt()),w),g=xt($(l,nt(),Zt((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),te(({prev:C})=>C)),[]);ue($(l,be(C=>C.length>0),Re(v,p),te(([C,T,I])=>{const A=C.reduce((R,j,M)=>_t(R,j,jr(j,T.offsetTree,I)||M),ir());return{...T,groupIndices:C,groupOffsetTree:A}})),v),ue($(r,Re(v),be(([C,{lastIndex:T}])=>C<T),te(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),ue(u,d);const x=xt($(u,te(C=>C===void 0)),!0);ue($(d,be(C=>C!==void 0&&Ye(at(v).sizeTree)),te(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=jt($(n,Re(v),Zt(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:w}),te(C=>C.changed)));Ue($(a,Zt((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),te(C=>C.diff)),C=>{const{groupIndices:T}=at(v);if(C>0)_e(t,!0),_e(s,C+oc(C,T));else if(C<0){const I=at(g);I.length>0&&(C-=oc(-C,I)),_e(i,C)}}),Ue($(a,Re(e)),([C,T])=>{C<0&&T("`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},kt.ERROR)});const y=jt(s);ue($(s,Re(v),te(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const j=Nr(T.sizeTree,0);let M=0,D=0;for(;M<C;){const P=T.groupIndices[D],V=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-P-1;A.push({endIndex:P,size:j,startIndex:P}),A.push({endIndex:P+1+V-1,size:R,startIndex:P+1}),D++,M+=V+1}const L=Ln(T.sizeTree);return M!==C&&L.shift(),L.reduce((P,{k:V,v:U})=>{let G=P.ranges;return P.prevSize!==0&&(G=[...P.ranges,{endIndex:V+C-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:V+C,prevSize:U,ranges:G}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Ln(T.sizeTree).reduce((j,{k:M,v:D})=>({prevIndex:M+C,prevSize:D,ranges:[...j.ranges,{endIndex:M+C-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const E=jt($(i,Re(v,p),te(([C,{offsetTree:T},I])=>{const A=-C;return jr(A,T,I)})));return ue($(i,Re(v,p),te(([C,T,I])=>{if(T.groupIndices.length>0){if(Ye(T.sizeTree))return T;let A=ir();const R=at(g);let j=0,M=0,D=0;for(;j<-C;){D=R[M];const L=R[M+1]-D-1;M++,j+=L+1}if(A=Ln(T.sizeTree).reduce((L,{k:P,v:V})=>_t(L,Math.max(0,P+C),V),A),j!==-C){const L=Nr(T.sizeTree,D);A=_t(A,0,L);const P=Vt(T.sizeTree,-C+1)[1];A=_t(A,1,P)}return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}else{const A=Ln(T.sizeTree).reduce((R,{k:j,v:M})=>_t(R,Math.max(0,j+C),M),ir());return{...T,sizeTree:A,...ci(T.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:y,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},tt(wn,ai),{singleton:!0});function Lg(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const sc=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=De(),i=De(),a=jt($(s,te(Lg)));return ue($(a,te(l=>l.totalCount)),n),ue($(a,te(l=>l.groupIndices)),e),ue($(dt(o,t,r),be(([l,u])=>yo(u)),te(([l,u,d])=>Vt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),nt(),te(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},tt(Qt,bt)),yn=He(([{log:e}])=>{const t=q(!1),n=jt($(t,be(r=>r),nt()));return Ue(t,r=>{r&&at(e)("props updated",{},kt.DEBUG)}),{didMount:n,propsReady:t}},tt(wn),{singleton:!0}),Fg=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function ic(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Fg)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const _r=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=De(),w=De(),v=q(0);let g=null,x=null,b=null;function y(){g&&(g(),g=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),_e(l,!1)}return ue($(p,Re(n,f,r,v,a,i,h),Re(e,s,o),te(([[E,C,T,I,A,R,j,M],D,L,P])=>{const V=ic(E),{align:U,behavior:G,offset:F}=V,N=I-1,W=rc(V,C,N);let Y=jr(W,C.offsetTree,D)+R;U==="end"?(Y+=L+Vt(C.sizeTree,W)[1]-T+P,W===N&&(Y+=j)):U==="center"?Y+=(L+Vt(C.sizeTree,W)[1]-T+P)/2:Y-=A,F&&(Y+=F);const de=se=>{y(),se?(M("retrying to scroll to",{location:E},kt.DEBUG),_e(p,E)):(_e(w,!0),M("list did not change, scroll successful",{},kt.DEBUG))};if(y(),G==="smooth"){let se=!1;b=Ue(t,pe=>{se=se||pe}),g=Wt(d,()=>{de(se)})}else g=Wt($(t,$g(150)),de);return x=setTimeout(()=>{y()},1200),_e(l,!0),M("scrolling from index to",{behavior:G,index:W,top:Y},kt.DEBUG),{behavior:G,top:Y}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},tt(Qt,bt,wn),{singleton:!0});function $g(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 Rr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=q(!0),l=q(0),u=q(!0);return ue($(i,Re(l),be(([d,f])=>!!f),Jt(!1)),a),ue($(i,Re(l),be(([d,f])=>!!f),Jt(!1)),u),Ue($(dt(t,i),Re(a,n,e,u),be(([[,d],f,{sizeTree:h},p,w])=>d&&(!Ye(h)||Qs(p))&&!f&&!w),Re(l)),([,d])=>{Wt(o,()=>{_e(u,!0)}),ui(4,()=>{Wt(r,()=>{_e(a,!0)}),_e(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},tt(Qt,bt,_r,yn),{singleton:!0});function ac(e,t){return Math.abs(e-t)<1.01}const Pr="up",Or="down",zg="none",Bg={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Hg=0,Mr=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=q(!1),a=q(!0),l=De(),u=De(),d=q(4),f=q(Hg),h=xt($(ti($(ve(o),Mn(1),Jt(!0)),$(ve(o),Mn(1),Jt(!1),Wl(100))),nt()),!1),p=xt($(ti($(n,Jt(!0)),$(n,Jt(!1),Wl(200))),nt()),!1);ue($(dt(ve(o),ve(f)),te(([b,y])=>b<=y),nt()),a),ue($(a,fn(50)),u);const w=jt($(dt(r,ve(s),ve(t),ve(e),ve(d)),Zt((b,[{scrollHeight:y,scrollTop:E},C,T,I,A])=>{const R=E+C-y>-A,j={scrollHeight:y,scrollTop:E,viewportHeight:C};if(R){let D,L;return E>b.state.scrollTop?(D="SCROLLED_DOWN",L=b.state.scrollTop-E):(D="SIZE_DECREASED",L=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:L,state:j}}let M;return j.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:j}},Bg),nt((b,y)=>b&&b.atBottom===y.atBottom))),v=xt($(r,Zt((b,{scrollHeight:y,scrollTop:E,viewportHeight:C})=>{if(ac(b.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const T=y-(E+C)<1;return b.scrollTop!==E&&T?{changed:!0,jump:b.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),be(b=>b.changed),te(b=>b.jump)),0);ue($(w,te(b=>b.atBottom)),i),ue($(i,fn(50)),l);const g=q(Or);ue($(r,te(({scrollTop:b})=>b),nt(),Zt((b,y)=>at(p)?{direction:b.direction,prevScrollTop:y}:{direction:y<b.prevScrollTop?Pr:Or,prevScrollTop:y},{direction:Or,prevScrollTop:0}),te(b=>b.direction)),g),ue($(r,fn(50),Jt(zg)),g);const x=q(0);return ue($(h,be(b=>!b),Jt(0)),x),ue($(o,fn(100),Re(h),be(([b,y])=>!!y),Zt(([b,y],[E])=>[y,E],[0,0]),te(([b,y])=>y-b)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},tt(bt)),So="top",Co="bottom",lc="none";function cc(e,t,n){return typeof e=="number"?n===Pr&&t===So||n===Or&&t===Co?e:0:n===Pr?t===So?e.main:e.reverse:t===Co?e.main:e.reverse}function uc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fi=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=De(),i=q(0),a=q(0),l=q(0),u=xt($(dt(ve(r),ve(o),ve(n),ve(s,Ar),ve(l),ve(i),ve(t),ve(e),ve(a)),te(([d,f,h,[p,w],v,g,x,b,y])=>{const E=d-b,C=g+x,T=Math.max(h-E,0);let I=lc;const A=uc(y,So),R=uc(y,Co);return p-=b,p+=h+x,w+=h+x,w-=b,p>d+C-A&&(I=Pr),w<d-T+f+R&&(I=Or),I!==lc?[Math.max(E-h-cc(v,So,I)-A,0),E-T-x+f+cc(v,Co,I)+R]:null}),be(d=>d!=null),nt(Ar)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},tt(bt),{singleton:!0});function Ug(e,t,n){if(yo(t)){const r=nc(e,t);return[{index:Vt(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 To(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:fc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:fc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function dc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=di(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return To(u,[],a,o,n,r)}function fc(e,t,n){if(e.length===0)return[];if(!yo(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=vo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Fn=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=q([]),g=q(0),x=De();ue(s.topItemsIndexes,v);const b=xt($(dt(p,w,ve(l,Ar),ve(o),ve(r),ve(u),d,ve(v),ve(t),ve(n),e),be(([T,I,,A,,,,,,,R])=>{const j=R&&R.length!==A;return T&&!I&&!j}),te(([,,[T,I],A,R,j,M,D,L,P,V])=>{const U=R,{offsetTree:G,sizeTree:F}=U,N=at(g);if(A===0)return{...hi,totalCount:A};if(T===0&&I===0)return N===0?{...hi,totalCount:A}:dc(N,j,R,L,P,V||[]);if(Ye(F))return N>0?null:To(Ug(di(j,A),U,V),[],A,P,U,L);const W=[];if(D.length>0){const me=D[0],ye=D[D.length-1];let H=0;for(const O of vo(F,me,ye)){const K=O.value,J=Math.max(O.start,me),ce=Math.min(O.end,ye);for(let ie=J;ie<=ce;ie++)W.push({data:V==null?void 0:V[ie],index:ie,offset:H,size:K}),H+=K}}if(!M)return To([],W,A,P,U,L);const Y=D.length>0?D[D.length-1]+1:0,de=_g(G,T,I,Y);if(de.length===0)return null;const se=A-1,pe=xo([],me=>{for(const ye of de){const H=ye.value;let O=H.offset,K=ye.start;const J=H.size;if(H.offset<T){K+=Math.floor((T-H.offset+P)/(J+P));const ie=K-ye.start;O+=ie*J+ie*P}K<Y&&(O+=(Y-K)*J,K=Y);const ce=Math.min(ye.end,se);for(let ie=K;ie<=ce&&!(O>=I);ie++)me.push({data:V==null?void 0:V[ie],index:ie,offset:O,size:J}),O+=J+P}});return To(pe,W,A,P,U,L)}),be(T=>T!==null),nt()),hi);ue($(e,be(Qs),te(T=>T==null?void 0:T.length)),o),ue($(b,te(T=>T.topListHeight)),f),ue(f,a),ue($(b,te(T=>[T.top,T.bottom])),i),ue($(b,te(T=>T.items)),x);const y=jt($(b,be(({items:T})=>T.length>0),Re(o,e),be(([{items:T},I])=>T[T.length-1].originalIndex===I-1),te(([,T,I])=>[T-1,I]),nt(Ar),te(([T])=>T))),E=jt($(b,fn(200),be(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),te(({items:T})=>T[0].index),nt())),C=jt($(b,be(({items:T})=>T.length>0),te(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),nt(ec)));return{endReached:y,initialItemCount:g,itemsRendered:x,listState:b,rangeChanged:C,startReached:E,topItemsIndexes:v,...h}},tt(Qt,sc,fi,Rr,_r,Mr,yn,ai),{singleton:!0}),hc=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=De(),i=xt($(dt(n,e,r,t,o),te(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ue(ve(i),s),{totalListHeight:i,totalListHeightChanged:s}},tt(bt,Fn),{singleton:!0}),Wg=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=q(!1),r=xt($(dt(n,e,t),be(([o])=>o),te(([,o,s])=>Math.max(0,o-s)),fn(0),nt()),0);return{alignToBottom:n,paddingTopAddition:r}},tt(bt,hc),{singleton:!0}),pc=He(()=>({context:q(null)})),Vg=({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,mc=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=De();return ue($(d,Re(t,l,n,s,o,r,a),Re(e),te(([[f,h,p,w,v,g,x,b],y])=>{const{align:E,behavior:C,calculateViewLocation:T=Vg,done:I,...A}=f,R=rc(f,h,w-1),j=jr(R,h.offsetTree,y)+v+g,M=j+Vt(h.sizeTree,R)[1],D=b+g,L=b+p-x,P=T({itemBottom:M,itemTop:j,locationParams:{align:E,behavior:C,...A},viewportBottom:L,viewportTop:D});return P?I&&Wt($(i,be(V=>!V),Mn(at(i)?1:2)),I):I&&I(),P}),be(f=>f!==null)),u),{scrollIntoView:d}},tt(Qt,bt,_r,Fn,wn),{singleton:!0});function gc(e){return e?e==="smooth"?"smooth":"auto":!1}const Kg=(e,t)=>typeof e=="function"?gc(e(t)):t&&gc(e),qg=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=q(!1),v=De();let g=null;function x(C){_e(i,{align:"end",behavior:C,index:"LAST"})}Ue($(dt($(ve(t),Mn(1)),l),Re(ve(w),s,a,f),te(([[C,T],I,A,R,j])=>{let M=T&&R,D="auto";return M&&(D=Kg(I,A||j),M=M&&!!D),{followOutputBehavior:D,shouldFollow:M,totalCount:C}}),be(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C)}):g=Wt(e,()=>{at(d)("following output to ",{totalCount:T},kt.DEBUG),x(C),g=null})});function b(C){const T=Wt(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(at(d)("scrolling to bottom due to increased size",{},kt.DEBUG),x("auto"))});setTimeout(T,100)}Ue($(dt(ve(w),t,u),be(([C,,T])=>C&&T),Zt(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),be(({refreshed:C})=>C),Re(w,t)),([,C])=>{at(a)&&b(C!==!1)}),Ue(v,()=>{b(at(w)!==!1)}),Ue(dt(ve(w),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=q(null),E=De();return ue(ti($(ve(r),te(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),$(ve(t))),E),Ue($(dt($(E,Mn(1)),l),Re(ve(y),a,f,h),te(([[C,T],I,A,R,j])=>T&&A&&(I==null?void 0:I({context:j,totalCount:C,scrollingInProgress:R}))),be(C=>!!C),fn(0)),C=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("scrolling into view",{}),_e(p,C)}):g=Wt(e,()=>{at(d)("scrolling into view",{}),_e(p,C),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:y}},tt(Qt,Mr,_r,Rr,yn,wn,bt,pc,mc)),Gg=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ue($(a,Re(s),be(([,l])=>l!==0),Re(o,r,t,n,e),te(([[,l],u,d,f,h,p=[]])=>dc(l,u,d,f,h,p))),i),{}),tt(Qt,Rr,Fn,yn),{singleton:!0}),Yg=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=q(0);return Ue($(e,Re(r),be(([,o])=>o!==0),te(([,o])=>({top:o}))),o=>{Wt($(n,Mn(1),be(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{_e(t,o)})})}),{initialScrollTop:r}},tt(yn,bt,Fn),{singleton:!0}),xc=He(([{scrollVelocity:e}])=>{const t=q(!1),n=De(),r=q(!1);return ue($(e,Re(r,t,n),be(([o,s])=>!!s),te(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),nt()),t),Ue($(dt(t,e,n),Re(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},tt(Mr),{singleton:!0}),pi=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=De(),r=De(),o=De(),s=q(!1),i=q(void 0);return ue($(dt(n,r),te(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ue($(t,Re(r),te(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},tt(bt)),Xg=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=De(),d=q(void 0),f=q(null),h=q(null);return ue(a,f),ue(l,h),Ue($(u,Re(t,r,i,f,h,n)),([p,w,v,g,x,b,y])=>{const E=Pg(w.sizeTree);g&&x!==null&&b!==null&&(v=x.scrollTop-b.offsetTop),v-=y,p({ranges:E,scrollTop:v})}),ue($(d,be(Qs),te(Jg)),o),ue($(s,Re(d),be(([,p])=>p!==void 0),nt(),te(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},tt(Qt,bt,Rr,yn,pi));function Jg(e){return{align:"start",index:0,offset:e.scrollTop}}const Zg=He(([{topItemsIndexes:e}])=>{const t=q(0);return ue($(t,be(n=>n>=0),te(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},tt(Fn));function vc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Qg=vc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),ex=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=jt($(l,Re(i),Zt(([,x,b,y],[{bottom:E,items:C,offsetBottom:T,totalCount:I},A])=>{const R=E+T;let j=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(j=R-y,j!==0&&(j+=A))),[j,C,I,R]},[0,[],0,0]),be(([x])=>x!==0),Re(r,a,n,o,p,w),be(([,x,b,y,,,E])=>!E&&!y&&x!==0&&b===Pr),te(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},kt.DEBUG),x))));function g(x){x>0?(_e(t,{behavior:"auto",top:-x}),_e(e,0)):(_e(e,0),_e(t,{behavior:"auto",top:-x}))}return Ue($(v,Re(e,s)),([x,b,y])=>{y&&Qg()?_e(e,b-x):g(-x)}),Ue($(dt(xt(s,!1),e,w),be(([x,b,y])=>!x&&!y&&b!==0),te(([x,b])=>b),fn(1)),g),ue($(f,te(x=>({top:-x}))),t),Ue($(u,Re(h,d),te(([x,{groupIndices:b,lastSize:y,sizeTree:E},C])=>{function T(I){return I*(y+C)}if(b.length===0)return T(x);{let I=0;const A=Nr(E,0);let R=0,j=0;for(;R<x;){R++,I+=A;let M=b.length===j+1?1/0:b[j+1]-b[j]-1;R+M>x&&(I-=A,M=x-R+1),R+=M,I+=T(M),j++}return I}})),x=>{_e(e,x),requestAnimationFrame(()=>{_e(t,{top:x}),requestAnimationFrame(()=>{_e(e,0),_e(w,!1)})})}),{deviation:e}},tt(bt,Mr,Fn,Qt,wn,ai)),tx=He(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),tt(fi,Gg,yn,xc,hc,Yg,Wg,pi,mc,wn,pc)),wc=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:b,topItemsIndexes:y,...E},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(ue(E.rangeChanged,R.scrollSeekRangeChanged),ue($(R.windowViewportRect,te(j=>j.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...E,...R,...v,sizes:l,...g}),tt(Qt,Rr,bt,Xg,qg,Fn,_r,ex,Zg,sc,tx));function nx(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 ko=typeof document<"u"?S.useLayoutEffect:S.useEffect;function bc(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 l(g,x){g.propsReady&&_e(g.propsReady,!1);for(const b of r){const y=g[t.required[b]];_e(y,x[b])}for(const b of o)if(b in x){const y=g[t.optional[b]];_e(y,x[b])}g.propsReady&&_e(g.propsReady,!0)}function u(g){return s.reduce((x,b)=>(x[b]=y=>{const E=g[t.methods[b]];_e(E,y)},x),{})}function d(g){return i.reduce((x,b)=>(x[b]=vg(g[t.events[b]]),x),{})}const f=S.forwardRef((g,x)=>{const{children:b,...y}=g,[E]=S.useState(()=>xo(bg(e),I=>{l(I,y)})),[C]=S.useState(Ul(d,E));ko(()=>{for(const I of i)I in y&&Ue(C[I],y[I]);return()=>{Object.values(C).map(ei)}},[y,C,E]),ko(()=>{l(E,y)}),S.useImperativeHandle(x,Bl(u(E)));const T=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(T,{...nx([...r,...o,...i],y),children:b}):b})}),h=g=>{const x=S.useContext(a);return S.useCallback(b=>{_e(x[g],b)},[x,g])},p=g=>{const x=S.useContext(a)[g],b=S.useCallback(y=>Ue(x,y),[x]);return S.useSyncExternalStore(b,()=>at(x),()=>at(x))},w=g=>{const x=S.useContext(a)[g],[b,y]=S.useState(Ul(at,x));return ko(()=>Ue(x,E=>{E!==b&&y(Bl(E))}),[x,b]),b},v=S.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const b=S.useContext(a)[g];ko(()=>Ue(b,x),[x,b])},useEmitterValue:v,usePublisher:h}}const yc=S.createContext(void 0),Sc=S.createContext(void 0),Cc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function mi(e){return"self"in e}function rx(e){return"body"in e}function Tc(e,t,n,r=sr,o,s){const i=S.useRef(null),a=S.useRef(null),l=S.useRef(null),u=S.useCallback(h=>{let p,w,v;const g=h.target;if(rx(g)||mi(g)){const b=mi(g)?g:g.defaultView;v=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,w=s?b.innerWidth:b.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Rs.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);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 p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;mi(p)?(g=Math.max(bn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=bn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=g-v;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),ac(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const gi="-webkit-sticky",kc="sticky",xi=vc(()=>{if(typeof document>"u")return kc;const e=document.createElement("div");return e.style.position=gi,e.style.position===gi?gi:kc});function vi(e){return e}const ox=He(()=>{const e=q(a=>`Item ${a}`),t=q(a=>`Group ${a}`),n=q({}),r=q(vi),o=q("div"),s=q(sr),i=(a,l=null)=>xt($(n,te(u=>u[a]),nt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),sx=He(([e,t])=>({...e,...t}),tt(wc,ox)),ix=({height:e})=>c.jsx("div",{style:{height:e}}),ax={overflowAnchor:"none",position:xi(),zIndex:1},Ec={overflowAnchor:"none"},lx={...Ec,display:"inline-block",height:"100%"},Ic=S.memo(function({showTopList:e=!1}){const t=Ie("listState"),n=Lt("sizeRanges"),r=Ie("useWindowScroll"),o=Ie("customScrollParent"),s=Lt("windowScrollContainerState"),i=Lt("scrollContainerState"),a=o||r?s:i,l=Ie("itemContent"),u=Ie("context"),d=Ie("groupContent"),f=Ie("trackItemSizes"),h=Ie("itemSize"),p=Ie("log"),w=Lt("gap"),v=Ie("horizontalDirection"),{callbackRef:g}=Cg(n,h,f,e?sr:a,p,w,o,v,Ie("skipAnimationFrameInResizeObserver")),[x,b]=S.useState(0);wi("deviation",P=>{x!==P&&b(P)});const y=Ie("EmptyPlaceholder"),E=Ie("ScrollSeekPlaceholder")||ix,C=Ie("ListComponent"),T=Ie("ItemComponent"),I=Ie("GroupComponent"),A=Ie("computeItemKey"),R=Ie("isSeeking"),j=Ie("groupIndices").length>0,M=Ie("alignToBottom"),D=Ie("initialItemFinalLocationReached"),L=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?c.jsx(y,{...vt(y,u)}):c.jsx(C,{...vt(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:L,children:(e?t.topItems:t.items).map(P=>{const V=P.originalIndex,U=A(V+t.firstItemIndex,P.data,u);return R?S.createElement(E,{...vt(E,u),height:P.size,index:P.index,key:U,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?S.createElement(I,{...vt(I,u),"data-index":V,"data-item-index":P.index,"data-known-size":P.size,key:U,style:ax},d(P.index,u)):S.createElement(T,{...vt(T,u),...fx(T,P.data),"data-index":V,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:U,style:v?lx:Ec},j?l(P.index,P.groupIndex,P.data,u):l(P.index,P.data,u))})})}),cx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ux={outline:"none",overflowX:"auto",position:"relative"},Eo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),dx={position:xi(),top:0,width:"100%",zIndex:1};function vt(e,t){if(typeof e!="string")return{context:t}}function fx(e,t){return{item:typeof e=="string"?void 0:t}}const hx=S.memo(function(){const e=Ie("HeaderComponent"),t=Lt("headerHeight"),n=Ie("HeaderFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,Ie("skipAnimationFrameInResizeObserver")),o=Ie("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),px=S.memo(function(){const e=Ie("FooterComponent"),t=Lt("footerHeight"),n=Ie("HeaderFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,Ie("skipAnimationFrameInResizeObserver")),o=Ie("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null});function Nc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Tc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?ux:cx,...o},tabIndex:0,...i,...vt(l,s),children:r})})}function Ac({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Tc(a,u,l,w,h);return Cc(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...vt(l,s),children:r})})}const mx=({children:e})=>{const t=S.useContext(yc),n=Lt("viewportHeight"),r=Lt("fixedItemHeight"),o=Ie("alignToBottom"),s=Ie("horizontalDirection"),i=S.useMemo(()=>Hl(n,l=>bn(l,s?"width":"height")),[n,s]),a=Dn(i,!0,Ie("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Eo(o),children:e})},gx=({children:e})=>{const t=S.useContext(yc),n=Lt("windowViewportRect"),r=Lt("fixedItemHeight"),o=Ie("customScrollParent"),s=ql(n,o,Ie("skipAnimationFrameInResizeObserver")),i=Ie("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Eo(i),children:e})},xx=({children:e})=>{const t=Ie("TopItemListComponent")||"div",n=Ie("headerHeight"),r={...dx,marginTop:`${n}px`},o=Ie("context");return c.jsx(t,{style:r,...vt(t,o),children:e})},vx=S.memo(function(e){const t=Ie("useWindowScroll"),n=Ie("topItemsIndexes").length>0,r=Ie("customScrollParent"),o=Ie("context");return c.jsxs(r||t?yx:bx,{...e,context:o,children:[n&&c.jsx(xx,{children:c.jsx(Ic,{showTopList:!0})}),c.jsxs(r||t?gx:mx,{children:[c.jsx(hx,{}),c.jsx(Ic,{}),c.jsx(px,{})]})]})}),{Component:wx,useEmitter:wi,useEmitterValue:Ie,usePublisher:Lt}=bc(sx,{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"}},vx),bx=Nc({useEmitter:wi,useEmitterValue:Ie,usePublisher:Lt}),yx=Ac({useEmitter:wi,useEmitterValue:Ie,usePublisher:Lt}),Sx=wx;tt(wc,He(()=>{const e=q(u=>c.jsxs("td",{children:["Item $",u]})),t=q(null),n=q(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=q(null),o=q(null),s=q({}),i=q(vi),a=q(sr),l=(u,d=null)=>xt($(s,te(f=>f[u]),nt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xi();const jc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Cx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:_c,floor:Io,max:Dr,min:bi,round:Rc}=Math;function Pc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Tx(e){return{...Cx,items:e}}function No(e,t){return e&&e.width===t.width&&e.height===t.height}function kx(e,t){return e&&e.column===t.column&&e.row===t.row}const Ex=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E},C])=>{const T=q(0),I=q(0),A=q(jc),R=q({height:0,width:0}),j=q({height:0,width:0}),M=De(),D=De(),L=q(0),P=q(null),V=q({column:0,row:0}),U=De(),G=De(),F=q(!1),N=q(0),W=q(!0),Y=q(!1),de=q(!1);Ue($(w,Re(N),be(([O,K])=>!!K)),()=>{_e(W,!1)}),Ue($(dt(w,W,j,R,N,Y),be(([O,K,J,ce,,ie])=>O&&!K&&J.height!==0&&ce.height!==0&&!ie)),([,,,,O])=>{_e(Y,!0),ui(1,()=>{_e(M,O)}),Wt($(u),()=>{_e(t,[0,0]),_e(W,!0)})}),ue($(G,be(O=>O!=null&&O.scrollTop>0),Jt(0)),I),Ue($(w,Re(G),be(([,O])=>O!=null)),([,O])=>{O&&(_e(R,O.viewport),_e(j,O.item),_e(V,O.gap),O.scrollTop>0&&(_e(F,!0),Wt($(u,Mn(1)),K=>{_e(F,!1)}),_e(l,{top:O.scrollTop})))}),ue($(R,te(({height:O})=>O)),f),ue($(dt(ve(R,No),ve(j,No),ve(V,(O,K)=>O&&O.column===K.column&&O.row===K.row),ve(u)),te(([O,K,J,ce])=>({gap:J,item:K,scrollTop:ce,viewport:O}))),U),ue($(dt(ve(T),r,ve(V,kx),ve(j,No),ve(R,No),ve(P),ve(I),ve(F),ve(W),ve(N)),be(([,,,,,,,O])=>!O),te(([O,[K,J],ce,ie,Le,We,Ze,,Ee,Pe])=>{const{column:Qe,row:$e}=ce,{height:qe,width:lt}=ie,{width:Z}=Le;if(Ze===0&&(O===0||Z===0))return jc;if(lt===0){const B=di(Pe,O),ne=B+Math.max(Ze-1,0);return Tx(Pc(B,ne,We))}const le=Oc(Z,lt,Qe);let ge,Ce;Ee?K===0&&J===0&&Ze>0?(ge=0,Ce=Ze-1):(ge=le*Io((K+$e)/(qe+$e)),Ce=le*_c((J+$e)/(qe+$e))-1,Ce=bi(O-1,Dr(Ce,le-1)),ge=bi(Ce,Dr(0,ge))):(ge=0,Ce=-1);const we=Pc(ge,Ce,We),{bottom:Ae,top:et}=Mc(Le,ce,ie,we),Ve=_c(O/le),ct=Ve*qe+(Ve-1)*$e-Ae;return{bottom:Ae,itemHeight:qe,items:we,itemWidth:lt,offsetBottom:ct,offsetTop:et,top:et}})),A),ue($(P,be(O=>O!==null),te(O=>O.length)),T),ue($(dt(R,j,A,V),be(([O,K,{items:J}])=>J.length>0&&K.height!==0&&O.height!==0),te(([O,K,{items:J},ce])=>{const{bottom:ie,top:Le}=Mc(O,ce,K,J);return[Le,ie]}),nt(Ar)),t);const se=q(!1);ue($(u,Re(se),te(([O,K])=>K||O!==0)),se);const pe=jt($(dt(A,T),be(([{items:O}])=>O.length>0),Re(se),be(([[O,K],J])=>{const ce=O.items[O.items.length-1].index===K-1;return(J||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===K)&&ce}),te(([[,O]])=>O-1),nt())),me=jt($(ve(A),be(({items:O})=>O.length>0&&O[0].index===0),Jt(0),nt())),ye=jt($(ve(A),Re(F),be(([{items:O},K])=>O.length>0&&!K),te(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),nt(ec),fn(0)));ue(ye,p.scrollSeekRangeChanged),ue($(M,Re(R,j,T,V),te(([O,K,J,ce,ie])=>{const Le=ic(O),{align:We,behavior:Ze,offset:Ee}=Le;let Pe=Le.index;Pe==="LAST"&&(Pe=ce-1),Pe=Dr(0,Pe,bi(ce-1,Pe));let Qe=yi(K,ie,J,Pe);return We==="end"?Qe=Rc(Qe-K.height+J.height):We==="center"&&(Qe=Rc(Qe-K.height/2+J.height/2)),Ee&&(Qe+=Ee),{behavior:Ze,top:Qe}})),l);const H=xt($(A,te(O=>O.offsetBottom+O.bottom)),0);return ue($(E,te(O=>({height:O.visibleHeight,width:O.visibleWidth}))),R),{customScrollParent:g,data:P,deviation:L,footerHeight:o,gap:V,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:G,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:M,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:y,windowViewportRect:E,...p,gridState:A,horizontalDirection:de,initialTopMostItemIndex:N,totalListHeight:H,...h,endReached:pe,propsReady:v,rangeChanged:ye,startReached:me,stateChanged:U,stateRestoreInProgress:F,...C}},tt(fi,bt,Mr,xc,yn,pi,wn));function Oc(e,t,n){return Dr(1,Io((e+n)/(Io(t)+n)))}function Mc(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=Oc(e.width,n.width,t.column),s=Io(r/o),i=s*n.height+Dr(0,s-1)*t.row;return i>0?i+t.row:i}const Ix=He(()=>{const e=q(f=>`Item ${f}`),t=q({}),n=q(null),r=q("virtuoso-grid-item"),o=q("virtuoso-grid-list"),s=q(vi),i=q("div"),a=q(sr),l=(f,h=null)=>xt($(t,te(p=>p[f]),nt()),h),u=q(!1),d=q(!1);return ue(ve(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Nx=He(([e,t])=>({...e,...t}),tt(Ex,Ix)),Ax=S.memo(function(){const e=ot("gridState"),t=ot("listClassName"),n=ot("itemClassName"),r=ot("itemContent"),o=ot("computeItemKey"),s=ot("isSeeking"),i=Ft("scrollHeight"),a=ot("ItemComponent"),l=ot("ListComponent"),u=ot("ScrollSeekPlaceholder"),d=ot("context"),f=Ft("itemDimensions"),h=Ft("gap"),p=ot("log"),w=ot("stateRestoreInProgress"),v=Ft("reportReadyState"),g=Dn(S.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const y=x.firstChild;if(y){const{height:E,width:C}=y.getBoundingClientRect();f({height:E,width:C})}h({column:Lc("column-gap",getComputedStyle(x).columnGap,p),row:Lc("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Cc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...vt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?c.jsx(u,{...vt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):S.createElement(a,{...vt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),jx=S.memo(function(){const e=ot("HeaderComponent"),t=Ft("headerHeight"),n=ot("headerFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=ot("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),_x=S.memo(function(){const e=ot("FooterComponent"),t=Ft("footerHeight"),n=ot("headerFooterTag"),r=Dn(S.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=ot("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),Rx=({children:e})=>{const t=S.useContext(Sc),n=Ft("itemDimensions"),r=Ft("viewportDimensions"),o=Dn(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]),c.jsx("div",{ref:o,style:Eo(!1),children:e})},Px=({children:e})=>{const t=S.useContext(Sc),n=Ft("windowViewportRect"),r=Ft("itemDimensions"),o=ot("customScrollParent"),s=ql(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]),c.jsx("div",{ref:s,style:Eo(!1),children:e})},Ox=S.memo(function({...e}){const t=ot("useWindowScroll"),n=ot("customScrollParent"),r=n||t?Dx:Mx,o=n||t?Px:Rx,s=ot("context");return c.jsx(r,{...e,...vt(r,s),children:c.jsxs(o,{children:[c.jsx(jx,{}),c.jsx(Ax,{}),c.jsx(_x,{})]})})}),{useEmitter:Dc,useEmitterValue:ot,usePublisher:Ft}=bc(Nx,{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"}},Ox),Mx=Nc({useEmitter:Dc,useEmitterValue:ot,usePublisher:Ft}),Dx=Ac({useEmitter:Dc,useEmitterValue:ot,usePublisher:Ft});function Lc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}const Lx=eo.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 c.jsx("div",{className:X(Lx({variant:t}),e),...n})}function oe(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 Fx(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function en(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,$x(o,...t)]}function $x(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var pt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},zx=m[" useInsertionEffect ".trim().toString()]||pt;function $n({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Bx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=Hx(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function Bx({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return zx(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Hx(e){return typeof e=="function"}function Fc(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=Fc(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():Fc(e[o],null)}}}}function Oe(...e){return m.useCallback(Ci(...e),e)}var Ux=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=Ux.reduce((e,t)=>{const n=_n.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function $c(e,t){e&&to.flushSync(()=>e.dispatchEvent(t))}function Wx(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Rt=e=>{const{present:t,children:n}=e,r=Vx(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Oe(r.ref,Kx(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Rt.displayName="Presence";function Vx(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wx(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Ao(r.current);s.current=a==="mounted"?u:"none"},[a]),pt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Ao(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),pt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=Ao(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Ao(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Ao(e){return(e==null?void 0:e.animationName)||"none"}function Kx(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 qx=m[" useId ".trim().toString()]||(()=>{}),Gx=0;function tn(e){const[t,n]=m.useState(qx());return pt(()=>{n(r=>r??String(Gx++))},[e]),e||(t?`radix-${t}`:"")}var jo="Collapsible",[Yx,OC]=en(jo),[Xx,Ti]=Yx(jo),zc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=$n({prop:r,defaultProp:o??!1,onChange:i,caller:jo});return c.jsx(Xx,{scope:n,disabled:s,contentId:tn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Se.div,{"data-state":Ei(l),"data-disabled":s?"":void 0,...a,ref:t})})});zc.displayName=jo;var Bc="CollapsibleTrigger",Hc=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Ti(Bc,n);return c.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:oe(e.onClick,o.onOpenToggle)})});Hc.displayName=Bc;var ki="CollapsibleContent",Jx=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ti(ki,e.__scopeCollapsible);return c.jsx(Rt,{present:n||o.open,children:({present:s})=>c.jsx(Zx,{...r,ref:t,present:s})})});Jx.displayName=ki;var Zx=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Ti(ki,n),[a,l]=m.useState(r),u=m.useRef(null),d=Oe(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),pt(()=>{const b=u.current;if(b){x.current=x.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const y=b.getBoundingClientRect();f.current=y.height,p.current=y.width,g.current||(b.style.transitionDuration=x.current.transitionDuration,b.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Se.div,{"data-state":Ei(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function Ei(e){return e?"open":"closed"}var Qx=zc;const Uc=Qx,Wc=Hc,Lr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Lr.displayName="Card";const Fr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex flex-col space-y-1.5 p-6",e),...t}));Fr.displayName="CardHeader";const $r=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:X("text-2xl font-semibold leading-none tracking-tight",e),...t}));$r.displayName="CardTitle";const Vc=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:X("text-sm text-muted-foreground",e),...t}));Vc.displayName="CardDescription";const _o=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("p-6 pt-0",e),...t}));_o.displayName="CardContent";const Kc=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:X("flex items-center p-6 pt-0",e),...t}));Kc.displayName="CardFooter";function qc(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let zn=qc();function ev(e){zn=e}const Gc=/[&<>"']/,tv=new RegExp(Gc.source,"g"),Yc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,nv=new RegExp(Yc.source,"g"),rv={"&":"&","<":"<",">":">",'"':""","'":"'"},Xc=e=>rv[e];function wt(e,t){if(t){if(Gc.test(e))return e.replace(tv,Xc)}else if(Yc.test(e))return e.replace(nv,Xc);return e}const ov=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Jc(e){return e.replace(ov,(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 sv=/(^|[^\[])\^/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(sv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const iv=/[^\w:]/g,av=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Zc(e,t,n){if(e){let r;try{r=decodeURIComponent(Jc(n)).replace(iv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!av.test(n)&&(n=dv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ro={},lv=/^[^:]+:\/*[^/]*$/,cv=/^([^:]+:)[\s\S]*$/,uv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function dv(e,t){Ro[" "+e]||(lv.test(e)?Ro[" "+e]=e+"/":Ro[" "+e]=Oo(e,"/",!0)),e=Ro[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(cv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(uv,"$1")+t:e+t}const Po={exec:function(){}};function Qc(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Oo(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 fv(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 hv(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 eu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function tu(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 pv(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||zn}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Oo(r,`
|
|
41
41
|
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=pv(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=Oo(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,w,v=n[1].trim();const g=v.length>1,x={type:"list",raw:"",ordered:g,start:g?+v.slice(0,-1):"",loose:!1,items:[]};v=g?`\\d{1,9}\\${v.slice(-1)}`:`\\${v}`,this.options.pedantic&&(v=g?v:"[*+-]");const b=new RegExp(`^( {0,3}${v})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
package/package.json
CHANGED