teodor-new-chat-ui 3.0.165 → 3.0.166
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 +4 -3
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2734,14 +2734,15 @@ function vx(e, t) {
|
|
|
2734
2734
|
case "seed": {
|
|
2735
2735
|
const r = Hs(t.payload.messages), o = {
|
|
2736
2736
|
...e,
|
|
2737
|
-
messages:
|
|
2738
|
-
//
|
|
2737
|
+
messages: r,
|
|
2738
|
+
// REPLACE with incoming messages (don't merge with existing)
|
|
2739
2739
|
assemblingId: null
|
|
2740
2740
|
// Clear any streaming state on seed
|
|
2741
2741
|
};
|
|
2742
|
-
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:", {
|
|
2742
|
+
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):", {
|
|
2743
2743
|
incomingCount: t.payload.messages.length,
|
|
2744
2744
|
sanitizedCount: r.length,
|
|
2745
|
+
previousCount: e.messages.length,
|
|
2745
2746
|
checkpointId: o.lastCheckpointId
|
|
2746
2747
|
}), o;
|
|
2747
2748
|
}
|
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=Rn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&uo.assertOptions(r,{silentJSONParsing:Jt.transitional(Jt.boolean),forcedJSONParsing:Jt.transitional(Jt.boolean),clarifyTimeoutError:Jt.transitional(Jt.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:uo.assertOptions(o,{encode:Jt.function,serialize:Jt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),uo.assertOptions(n,{baseUrl:Jt.spelling("baseURL"),withXsrfToken:Jt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=St.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(b){typeof b.runWhen=="function"&&b.runWhen(n)===!1||(c=c&&b.synchronous,a.unshift(b.fulfilled,b.rejected))});const u=[];this.interceptors.response.forEach(function(b){u.push(b.fulfilled,b.rejected)});let d,f=0,p;if(!c){const w=[kl.bind(this),void 0];for(w.unshift(...a),w.push(...u),p=w.length,d=Promise.resolve(n);f<p;)d=d.then(w[f++],w[f++]);return d}p=a.length;let m=n;for(;f<p;){const w=a[f++],b=a[f++];try{m=w(m)}catch(g){b.call(this,g);break}}try{d=kl.call(this,m)}catch(w){return Promise.reject(w)}for(f=0,p=u.length;f<p;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Rn(this.defaults,t);const n=pl(t.baseURL,t.url,t.allowAbsoluteUrls);return sl(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){_n.prototype[t]=function(n,r){return this.request(Rn(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Rn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}_n.prototype[t]=n(),_n.prototype[t+"Form"]=n(!0)});let fg=class Hp{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 Jn(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 Hp(function(o){t=o}),cancel:t}}};function hg(e){return function(n){return e.apply(null,n)}}function pg(e){return R.isObject(e)&&e.isAxiosError===!0}const Vs={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Vs).forEach(([e,t])=>{Vs[t]=e});function Nl(e){const t=new _n(e),n=Wa(_n.prototype.request,t);return R.extend(n,_n.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Nl(Rn(e,o))},n}const tt=Nl(yr);tt.Axios=_n,tt.CanceledError=Jn,tt.CancelToken=fg,tt.isCancel=ul,tt.VERSION=El,tt.toFormData=so,tt.AxiosError=Ie,tt.Cancel=tt.CanceledError,tt.all=function(t){return Promise.all(t)},tt.spread=hg,tt.isAxiosError=pg,tt.mergeConfig=Rn,tt.AxiosHeaders=St,tt.formToJSON=e=>ll(R.isHTMLForm(e)?new FormData(e):e),tt.getAdapter=Tl.getAdapter,tt.HttpStatusCode=Vs,tt.default=tt;const{Axios:RT,AxiosError:_T,CanceledError:PT,isCancel:OT,CancelToken:MT,VERSION:DT,all:LT,Cancel:$T,isAxiosError:FT,spread:zT,toFormData:BT,AxiosHeaders:HT,HttpStatusCode:UT,formToJSON:WT,getAdapter:VT,mergeConfig:KT}=tt,jl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ks=jl?jl.replace(/\/+$/,""):void 0;!Ks&&typeof window<"u"&&console.warn("API base URL is not configured. The API client will need to be configured via apiConfig prop or window.__API_BASE_URL__.");let fo=null;const qs=new Set;function Al(){return fo}function Gs(e){fo=e,qs.forEach(t=>t(e))}function Rl(e){return qs.add(e),()=>qs.delete(e)}const Ot=tt.create({...Ks?{baseURL:Ks}:{},timeout:3e4,withCredentials:!0});Ot.interceptors.request.use(e=>(fo&&(e.headers.Authorization=`Bearer ${fo}`),e)),Ot.interceptors.response.use(e=>e,e=>Promise.reject(e));async function It(e,t){return Ot.defaults.baseURL?(await Ot.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function _l(e,t,n){return Ot.defaults.baseURL?(await Ot.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Pl(e,t,n){return Ot.defaults.baseURL?(await Ot.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ol(e,t){return Ot.defaults.baseURL?(await Ot.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Mt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Ml{get baseUrl(){const t=Ot.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(Ot.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Gs(t.authToken)}getAuthToken(){return Al()}setAuthToken(t){Gs(t)}onTokenChange(t){return Rl(t)}async listThreads(){const t=await It("/chat/threads"),n=Mt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await _l("/chat/threads",t?{title:t}:void 0);return Mt(r)}async updateThread(t,n){const r=await Pl(`/chat/threads/${t}`,{title:n});return Mt(r)}async deleteThread(t){const n=await Ol(`/chat/threads/${t}`);return Mt(n)}async threadInfo(t){const n=await It(`/chat/threads/${t}/info`);return Mt(n)}async listAgents(){const t=await It("/chat/agents"),n=Mt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await It(`/chat/agents/${t}`);return Mt(n)}async getAgentSchema(t){const n=await It(`/chat/agents/${t}/schema`);return Mt(n)}async getMessages(t){const n=await It(`/chat/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return Mt(n)}async getState(t){const n=await It(`/chat/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Mt(n)}async getStateHistory(t){const n=await It(`/chat/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Mt(n)}async listCheckpoints(t){const n=await It(`/chat/threads/${t}/checkpoints`,{params:{thread_id:t}});return Mt(n)}}const mn=new Ml;function Dl(e={}){const t=e.baseUrl??"/api/chat",n=e.streamPath??"/runs/stream",[r,o]=C.useState(e.token??null),s=C.useRef(e.headers??{}),[i,a]=C.useState(!1),[c,u]=C.useState(null),[d,f]=C.useState(""),[p,m]=C.useState(null),[w,b]=C.useState(0),[g,x]=C.useState(!1),v=C.useRef(null),y=C.useRef(!0),E=C.useRef(0),S=C.useCallback(j=>{o(j)},[]),T=C.useCallback(()=>{var j;(j=v.current)==null||j.abort(),v.current=null,a(!1),x(!1)},[]),I=C.useCallback(()=>{f(""),m(null),u(null)},[]),N=C.useCallback((j,O,A)=>{v.current&&(v.current.abort(),v.current=null),a(!0),u(null),e.autoAppendAssistant!==!1&&f("");const F=new AbortController;return v.current=F,(async()=>{var J,K,oe,W,M,X,Z,he;const H=(()=>{var $;try{return typeof window<"u"&&(($=window.localStorage)==null?void 0:$.getItem("chat-debug"))==="1"}catch{return!1}})(),D=$=>{var G;try{const ee=JSON.parse(JSON.stringify($));return(G=ee==null?void 0:ee.payload)!=null&&G.files_info&&Array.isArray(ee.payload.files_info)&&(ee.payload.files_info=ee.payload.files_info.map(pe=>({...pe,data:pe!=null&&pe.data?`<base64 ${String(pe.data).length} chars>`:pe==null?void 0:pe.data}))),ee}catch{return $}};try{let $={};try{if(r)$={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ae=window.__AUTH_TOKEN__,et=((J=window.localStorage)==null?void 0:J.getItem("authToken"))||null;let qe=null;try{const ut=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");ut&&(qe=((oe=JSON.parse(ut))==null?void 0:oe.apiKey)||null)}catch{}const ct=Ae||et||qe||null;ct&&($={Authorization:`Bearer ${ct}`})}}catch{}H&&console.debug("[use-chat] POST",t+n,D(j));const G=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...$,...s.current},body:JSON.stringify(j),signal:F.signal});if(!G.ok||!G.body){const Ee=await G.text().catch(()=>"");throw H&&console.debug("[use-chat] non-OK response",G.status,Ee==null?void 0:Ee.slice(0,500)),new Error(`stream ${G.status}${Ee?": "+Ee:""}`)}x(!0);const ee=G.body.getReader(),pe=new TextDecoder;let z="",_=[],Y=E.current,Q=null;const de=()=>{if(_.length){const Ee=_.join("");_=[],y.current&&f(Ae=>Ae+Ee)}Q=null},ne=()=>{typeof window<"u"&&Q==null&&(Q=requestAnimationFrame(de))};let _e=Date.now();const Pe=setInterval(()=>{var Ee;if(Date.now()-_e>2e4){const Ae="Stream idle timeout";u(Ae),F.abort(),(Ee=A==null?void 0:A.onError)==null||Ee.call(A,Ae)}},5e3),Ue=1024*1024;try{const Ee=G.headers.get("X-Thread-Id")||G.headers.get("x-thread-id"),Ae=G.headers.get("X-Thread-Created")||G.headers.get("x-thread-created"),et=Ee??null,qe=String(Ae??"").toLowerCase()==="true";for((W=A==null?void 0:A.onOpen)==null||W.call(A,{threadId:et,created:qe});;){const{value:ct,done:ut}=await ee.read();if(ut)break;z+=pe.decode(ct,{stream:!0}),z.length>Ue&&(z="",console.warn("Stream buffer reset: exceeded 1MB"));let ve;for(;(ve=z.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const Fe=z.slice(0,ve);z=z.slice(ve+2);const Ge=gg(Fe);if(!Ge)continue;let P;try{P=JSON.parse(Ge)}catch{H&&console.debug("[use-chat] malformed SSE:",Ge.slice(0,200));continue}const U=mg(P)?P.data:P;_e=Date.now(),O==null||O(U);const ue=U.seq;if(ue!==void 0){if(ue<=Y)continue;Y>0&&ue>Y+1&&((M=A==null?void 0:A.onGap)==null||M.call(A,{from:Y,to:ue})),Y=ue,E.current=ue,b(ue)}if(U.type==="token"&&e.autoAppendAssistant!==!1)_.push(U.content),ne();else if(U.type==="message_delta"){const be=U.delta.filter(le=>le.type==="text").map(le=>le.text).join("");be&&e.autoAppendAssistant!==!1&&(_.push(be),ne())}else Q!==null&&cancelAnimationFrame(Q),de(),U.type==="checkpoint"?m(U.checkpointId):U.type==="error"&&u(U.message)}}de()}catch(Ee){if(Ee.name!=="AbortError"){const Ae=Ee.message||String(Ee);u(Ae),(X=A==null?void 0:A.onError)==null||X.call(A,Ae)}}finally{try{await ee.cancel()}catch{}finally{(Z=ee.releaseLock)==null||Z.call(ee)}Q!==null&&typeof window<"u"&&window.cancelAnimationFrame(Q),clearInterval(Pe),a(!1),x(!1),v.current=null}}catch($){if($.name!=="AbortError"){const G=$.message||String($);u(G),(he=A==null?void 0:A.onError)==null||he.call(A,G)}}finally{a(!1),x(!1),v.current=null}})(),{close:()=>F.abort()}},[t,n,r,e.autoAppendAssistant]);return C.useEffect(()=>()=>{var j;y.current=!1,(j=v.current)==null||j.abort()},[]),{isStreaming:i,error:c,assistantText:d,lastCheckpointId:p,lastSeq:w,connected:g,stream:N,stop:T,clear:I,setToken:S}}function mg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function gg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
38
|
-
`)}const xg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function bg(e,t){var n;switch(t.type){case"reset":return{messages:Ys(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};case"seed":{const r=Ys(t.payload.messages),o={...e,messages:[...r,...e.messages],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:",{incomingCount:t.payload.messages.length,sanitizedCount:r.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;if(e.assemblingId){const o=e.messages.findIndex(s=>s.id===e.assemblingId);if(o!==-1)return{...e,messages:[...e.messages.slice(0,o),r,...e.messages.slice(o)]}}return{...e,messages:[...e.messages,r]}}case"event":return $l(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>$l(o,s),e):e}default:return e}}function Ll(e=[]){const[t,n]=C.useReducer(bg,{...xg,messages:e}),r=C.useRef([]),o=C.useRef(null),s=C.useRef(null),i=C.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=C.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),c=C.useCallback(d=>{r.current.push(d),a()},[a]);C.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=C.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:c}),[c]);return{state:t,dispatch:n,...u}}function $l(e,t){var n;if(t.type==="message_start"&&t.role==="assistant"){const r=t.id,o=Cg(t.model),s={id:r,role:"assistant",name:o||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:r,messages:[...e.messages,s]}}if(t.type==="token"){const r=e.assemblingId??Xs(e.messages);return r?{...e,messages:wg(e.messages,r,t.content)}:e}if(t.type==="message_delta"){const r=e.assemblingId??Xs(e.messages);return r?{...e,messages:Fl(e.messages,r,t.delta)}:e}if(t.type==="message_end"){const r=e.assemblingId??Xs(e.messages);if(!r)return{...e,assemblingId:null};const o=e.messages,s=o.findIndex(i=>i.id===r&&i.role==="assistant");if(s>=0&&!((n=o[s].content)==null?void 0:n.some(c=>{var u;return(c==null?void 0:c.type)==="text"&&((u=c.text)==null?void 0:u.trim())}))){const c=[...o.slice(0,s),...o.slice(s+1)];return{...e,assemblingId:null,messages:c}}return e}if(t.type==="tool_start"){const r=`tool-${t.id}`,o={type:"tool_call",id:t.id,name:t.name,args:t.args},s={id:r,role:"tool",name:t.name,createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],toolIndex:{...e.toolIndex,[t.id]:r}}}if(t.type==="tool_result"){const r=e.toolIndex[t.id]??`tool-${t.id}`,o={type:"tool_result",toolCallId:t.id,output:t.output,error:t.error},s=e.messages.find(c=>c.id===r),i={id:r,role:"tool",content:[o],createdAt:new Date().toISOString()},a=s?Fl(e.messages,r,[o]):[...e.messages,i];return{...e,messages:a}}if(t.type==="checkpoint"){const r=t.checkpointNs??e.lastCheckpointNs??null,o=Sg(e.messages,t.checkpointId,r);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:r,messages:o}}if(t.type==="branch"){const r=t.checkpointId??e.lastCheckpointId,o=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:r??null,lastCheckpointNs:o??null}}if(t.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,r]}}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 vg(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 wg(e,t,n){return e.map(r=>{if(r.id!==t)return r;const o=r.content.slice(),s=o[o.length-1];return s&&s.type==="text"?s.text+=n:o.push({type:"text",text:n}),{...r,content:o}})}function Fl(e,t,n){return e.map(r=>r.id===t?{...r,content:yg(r.content,n)}:r)}function yg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Sg(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 vg(e,r,s)}return e}function Cg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Tg(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 kg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Eg(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await kg(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const zl=C.createContext(null);function Cr({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null,autoLoadInitial:s=!0,enableFileAgentRouting:i=!1,fileAgentId:a="invoice_reader"}){const c=mn;C.useEffect(()=>{t&&c.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[c,t]);const{isStreaming:u,error:d,stream:f,stop:p,setToken:m}=Dl({baseUrl:c.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/runs/stream"}),[w,b]=C.useState(()=>typeof c.getAuthToken=="function"?c.getAuthToken():null);C.useEffect(()=>{m(typeof c.getAuthToken=="function"?c.getAuthToken():null);const P=c.onTokenChange(U=>{b(U),m(U)});return()=>{P()}},[c,m]);const g=C.useCallback(P=>{c.setAuthToken(P)},[c]),{state:x,seed:v,prepend:y,pushUser:E,onEvent:S,reset:T}=Ll(),I=20,[N,j]=C.useState(!1),[O,A]=C.useState(!1),[F,H]=C.useState(null),[D,J]=C.useState(void 0),[K,oe]=C.useState(void 0),W=C.useRef(!1),M=C.useRef([]),X=C.useCallback(P=>{P.cursor!==void 0&&H(P.cursor),P.hasMore!==void 0&&j(P.hasMore),P.checkpointId!==void 0&&J(P.checkpointId),P.checkpointNs!==void 0&&oe(P.checkpointNs)},[]),Z=C.useCallback((P,U)=>new Promise((ue,be)=>{const le=async()=>{if(W.current){console.warn(`[ChatProvider] Operation "${U}" queued - another operation in progress`),M.current.push(le);return}W.current=!0;try{console.log(`[ChatProvider] Executing operation: ${U}`),await P(),ue()}catch(Be){console.error(`[ChatProvider] Operation "${U}" failed:`,Be),be(Be)}finally{W.current=!1;const Be=M.current.shift();Be&&Be().catch(()=>{})}};W.current?(M.current.push(le),console.log(`[ChatProvider] Queued operation: ${U}`)):le().catch(Be=>{be(Be)})}),[]),he=C.useCallback((P,U)=>{const ue=Array.isArray(P==null?void 0:P.messages)?P.messages:[];U==="replace"?(console.log("[ChatProvider] Replacing messages, count:",ue.length),v(ue,{checkpointId:(P==null?void 0:P.checkpointId)??null,checkpointNs:(P==null?void 0:P.checkpointNs)??null})):U==="prepend"&&ue.length?(console.log("[ChatProvider] Calling prepend with",ue.length,"messages"),y(ue)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),H((P==null?void 0:P.nextCursor)??null),j(!!(P!=null&&P.hasMore)),J(be=>(P==null?void 0:P.checkpointId)??be??void 0),oe(be=>(P==null?void 0:P.checkpointNs)??be??void 0)},[v,y]),[$,G]=C.useState([]),[ee,pe]=C.useState(null),z=C.useCallback(async()=>{const P=await c.listThreads();G(P)},[c]),[_,Y]=C.useState(!1),Q=C.useCallback(async P=>{const U=(P==null?void 0:P.maxAttempts)??5,ue=(P==null?void 0:P.baseDelayMs)??500,be=(P==null?void 0:P.timeoutMs)??2e3;if(!c.baseUrl)return!1;const le=c.baseUrl.replace(/\/+$/,""),Be=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],at=async xt=>{try{const _t=new AbortController,ft=setTimeout(()=>_t.abort(),be),Pt=await fetch(xt,{method:"GET",signal:_t.signal});return clearTimeout(ft),Pt.ok}catch{return!1}},hn=async xt=>{try{const _t=new AbortController,ft=setTimeout(()=>_t.abort(),be),Pt=await fetch(xt,{method:"HEAD",signal:_t.signal});return clearTimeout(ft),Pt.ok}catch{return!1}};for(let xt=0;xt<U;xt++){console.debug(`[ChatProvider] health-check attempt ${xt+1}/${U}`);for(const ft of Be){let Pt=ft;le.endsWith("/api")&&ft.startsWith("/api")&&(Pt=ft.replace(/^\/api/,"")||"/");const jn=Pt==="/"?le+"/":le+Pt;if(console.debug(`[ChatProvider] checking ${jn}`),await at(jn)||ft==="/"&&await hn(le+"/"))return Y(!0),!0}const _t=ue*Math.pow(2,xt);await new Promise(ft=>setTimeout(ft,_t))}return Y(!1),!1},[c.baseUrl]);C.useEffect(()=>{let P=!0;if(!c.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const U=await Q();if(!P)return;U?z().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{P=!1}},[z,c.baseUrl,Q]),C.useEffect(()=>{r==null||r(ee)},[ee,r]);const de=C.useRef(null);C.useEffect(()=>{if(o&&s){if(!c.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!_){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}de.current!==o&&(de.current=o,Pe(o).catch(()=>{}))}},[o,s,c.baseUrl,_]);const ne=C.useRef(null),_e=C.useRef(null),Pe=C.useCallback(async(P,U,ue)=>{await Z(async()=>{if(!c.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(ne.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${ne.current}) is loading`);return}_e.current!==null&&_e.current!==P&&(console.log(`[ChatProvider] Thread switch detected: ${_e.current} -> ${P}`),T([])),ne.current=P,_e.current=P;try{X({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),pe(P);const le=await c.getMessages({threadId:P,checkpointId:U,checkpointNs:ue,limit:I}),Be=Array.isArray(le==null?void 0:le.messages)?le.messages:[];console.log("[ChatProvider] Loading thread with",Be.length,"messages"),v(Be,{checkpointId:(le==null?void 0:le.checkpointId)??null,checkpointNs:(le==null?void 0:le.checkpointNs)??null}),H((le==null?void 0:le.nextCursor)??null),j(!!(le!=null&&le.hasMore)),J(at=>(le==null?void 0:le.checkpointId)??at??void 0),oe(at=>(le==null?void 0:le.checkpointNs)??at??void 0)}finally{ne.current=null}},`loadThread-${P}`)},[c,Z,X,v]),Ue=C.useCallback(async P=>{const U=await c.listCheckpoints(P);return Tg(U,P)},[c]),Ee=C.useCallback(async(P,U)=>{await Z(async()=>{if(!ee)throw new Error("No active thread");X({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0});const ue=await c.getMessages({threadId:ee,checkpointId:P,checkpointNs:U??void 0,limit:I});he(ue,"replace")},`navigateToCheckpoint-${P}`)},[c,ee,he,Z,X]),Ae=C.useCallback(async()=>{if(!ee)throw new Error("No active thread");await Pe(ee)},[ee,Pe]),et=C.useRef(!1);C.useEffect(()=>{const P=et.current;et.current=u,P&&!u&&ee&&Z(async()=>{try{await z()}catch(U){console.warn("[ChatProvider] Post-streaming thread refresh failed:",U)}},"postStreamingRefresh")},[u,ee,c,he,z,Z]);const qe=C.useCallback(async P=>{const U=await c.createThread(P);return await z(),await Pe(U.threadId),U.threadId},[c,z,Pe]),ct=C.useCallback(async P=>{await c.deleteThread(P),await z(),ee===P&&(pe(null),T([]),j(!1),H(null),J(void 0),oe(void 0))},[c,z,ee,T]),ut=C.useCallback(async(P,U)=>{await c.updateThread(P,U),await z()},[c,z]),ve=C.useCallback(async(P,U)=>{await Z(async()=>{var qn;const ue=(U==null?void 0:U.attachments)||[],{contentParts:be,filesInfo:le}=await Eg(c,ue,t==null?void 0:t.uploadPath),Be=[];P&&P.trim()&&Be.push({type:"text",text:P.trim()});const at={id:((qn=crypto.randomUUID)==null?void 0:qn.call(crypto))||`user-${Date.now()}`,role:"user",content:Be,createdAt:new Date().toISOString(),checkpointId:(U==null?void 0:U.checkpointId)??x.lastCheckpointId??void 0,checkpointNs:(U==null?void 0:U.checkpointNs)??x.lastCheckpointNs??void 0};E(at);const hn={...at,content:Be},xt={...(U==null?void 0:U.payloadExtras)??{}},_t=!!xt.edit,ft=xt.originalMessageId,Pt=typeof ft=="string"?ft:void 0,jn=ue&&ue.length>0,Kn={...ee?{threadId:ee}:{},payload:{messages:[hn],files_info:le,...i&&jn&&a?{active_agent:a}:{},...xt},checkpointId:(U==null?void 0:U.checkpointId)??x.lastCheckpointId??void 0,checkpointNs:(U==null?void 0:U.checkpointNs)??x.lastCheckpointNs??void 0,nodeFilter:U==null?void 0:U.nodeFilter,config:U==null?void 0:U.config,edit:_t,originalMessageId:Pt};f(Kn,re=>S(re),{onError:re=>console.warn("stream error",re),onOpen:({threadId:re,created:me})=>{!ee&&re&&(pe(re),me&&z().catch(()=>{}))}})},"send")},[ee,E,f,S,x.lastCheckpointId,x.lastCheckpointNs,c,t==null?void 0:t.uploadPath,z,pe,i,a,Z]),Fe=C.useCallback(async P=>{if(!ee)throw new Error("No active thread");if(O||!N)return;const U=F;if(U){A(!0);try{const ue=await c.getMessages({threadId:ee,checkpointId:D,checkpointNs:K,limit:(P==null?void 0:P.limit)??I,beforeId:U});he(ue,"prepend")}finally{A(!1)}}},[c,ee,D,K,F,N,O,he,I]),Ge={baseUrl:c.baseUrl,token:w,setToken:g,api:c,threads:$,currentThreadId:ee,setCurrentThreadId:pe,messages:x.messages,isStreaming:u,error:d,lastCheckpointId:x.lastCheckpointId,lastCheckpointNs:x.lastCheckpointNs,streamingAssistantId:x.assemblingId,hasMoreHistory:N,isLoadingHistory:O,loadOlderMessages:Fe,historyPageSize:I,listCheckpoints:Ue,navigateToCheckpoint:Ee,returnToLatest:Ae,refreshThreads:z,createThread:qe,deleteThread:ct,renameThread:ut,loadThread:Pe,send:ve,stop:p};return l.jsx(zl.Provider,{value:Ge,children:e})}function ho(){const e=C.useContext(zl);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function L(...e){return Wp.twMerge(Up.clsx(e))}const Ig=mr.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"}}),ze=h.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Et.Slot:"button";return l.jsx(i,{className:L(Ig({variant:t,size:n,className:e})),ref:s,...o})});ze.displayName="Button";const Bl=h.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:L("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}));Bl.displayName="Textarea";function Ng({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[p,m]=C.useState(e),[w,b]=C.useTransition(),g=C.useRef(null);C.useEffect(()=>{m(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=C.useCallback(()=>{const N=g.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);C.useEffect(()=>{x()},[x]);const v=C.useCallback(async N=>{N&&N.preventDefault();const j=(p??"").trim();!j&&!f||b(()=>{try{const O=i(j);O&&typeof O.then=="function"?O.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[p,i,f]),y=C.useCallback(N=>{m(N.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=C.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),v()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[v,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return l.jsx("form",{onSubmit:N=>void v(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Bl,{ref:g,value:p,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(ze,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(se.Square,{size:16})}):l.jsx(ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!p.trim()&&!f||w,children:l.jsx(se.Send,{size:16})})})]})})}const jg=C.memo(Ng),po=0,gn=1,Zn=2,Hl=4;function Ul(e){return()=>e}function Ag(e){e()}function Wl(e,t){return n=>e(t(n))}function Vl(e,t){return()=>e(t)}function Rg(e,t){return n=>e(t,n)}function Js(e){return e!==void 0}function _g(...e){return()=>{e.map(Ag)}}function Qn(){}function mo(e,t){return t(e),e}function Pg(e,t){return t(e)}function Je(...e){return e}function He(e,t){return e(gn,t)}function Ne(e,t){e(po,t)}function Zs(e){e(Zn)}function nt(e){return e(Hl)}function fe(e,t){return He(e,Rg(t,po))}function Ut(e,t){const n=e(gn,r=>{n(),t(r)});return n}function Kl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function ql(e,t){return e===t}function Ze(e=ql){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ye(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>Wl(t,e)}function Zt(e){return t=>()=>{t(e)}}function B(e,...t){const n=Og(...t);return(r,o)=>{switch(r){case Zn:Zs(e);return;case gn:return He(e,n(o))}}}function Qt(e,t){return n=>r=>{n(t=e(t,r))}}function Pn(e){return t=>n=>{e>0?e--:t(n)}}function un(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function je(...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);He(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Og(...e){return t=>e.reduceRight(Pg,t)}function Mg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case gn:return s?n===s?void 0:(r(),n=s,t=He(e,s),t):(r(),Qn);case Zn:r(),n=null;return}}}function q(e){let t=e;const n=Me();return(r,o)=>{switch(r){case po:t=o;break;case gn:{o(t);break}case Hl:return t}return n(r,o)}}function pt(e,t){return mo(q(t),n=>fe(e,n))}function Me(){const e=[];return(t,n)=>{switch(t){case po:e.slice().forEach(r=>{r(n)});return;case Zn:e.splice(0,e.length);return;case gn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Nt(e){return mo(Me(),t=>fe(e,t))}function $e(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Dg(),singleton:n}}const Dg=()=>Symbol();function Lg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function ot(...e){const t=Me(),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);He(s,c=>{n[i]=c,r=r|a,r===o&&Ne(t,n)})}),function(s,i){switch(s){case Zn:{Zs(t);return}case gn:return r===o&&i(n),He(t,i)}}}function we(e,t=ql){return B(e,Ze(t))}function Qs(...e){return function(t,n){switch(t){case Zn:return;case gn:return _g(...e.map(r=>He(r,n)))}}}var Ct=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ct||{});const $g={0:"debug",3:"error",1:"log",2:"warn"},Fg=()=>typeof globalThis>"u"?window:globalThis,xn=$e(()=>{const e=q(3);return{log:q((t,n,r=1)=>{var o;const s=(o=Fg().VIRTUOSO_LOG_LEVEL)!=null?o:nt(e);r>=s&&console[$g[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function On(e,t,n){return ei(e,t,n).callbackRef}function ei(e,t,n){const r=C.useRef(null);let o=i=>{};const s=C.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function zg(e,t,n,r,o,s,i,a,c){const u=C.useCallback(d=>{const f=Bg(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const m=p.lastElementChild.dataset.viewportType==="window";let w;m&&(w=p.ownerDocument.defaultView);const b=i?a?i.scrollLeft:i.scrollTop:m?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:m?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:m?a?w.innerWidth:w.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(b,0),viewportHeight:x}),s==null||s(a?Gl("column-gap",getComputedStyle(d).columnGap,o):Gl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ei(u,n,c)}function Bg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ct.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Gl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ct.WARN),t==="normal"?0:parseInt(t??"0",10)}function Yl(e,t,n){const r=C.useRef(null),o=C.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,p;if(t){const m=t.getBoundingClientRect(),w=u.top-m.top;p=m.height-Math.max(0,w),f=w+t.scrollTop}else{const m=i.current.ownerDocument.defaultView;p=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ei(o,!0,n),a=C.useCallback(()=>{o(i.current)},[o,i]);return C.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const bt=$e(()=>{const e=Me(),t=Me(),n=q(0),r=Me(),o=q(0),s=Me(),i=Me(),a=q(0),c=q(0),u=q(0),d=q(0),f=Me(),p=Me(),m=q(!1),w=q(!1),b=q(!1);return fe(B(e,ae(({scrollTop:g})=>g)),t),fe(B(e,ae(({scrollHeight:g})=>g)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:b,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Tr={lvl:0};function Xl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ve(e){return e===Tr}function kr(e,t){if(!Ve(e))return t===e.k?e.v:t<e.k?kr(e.l,t):kr(e.r,t)}function Wt(e,t,n="k"){if(Ve(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Wt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Wt(e.l,t,n)}function jt(e,t,n){return Ve(e)?Ql(t,n,1):t===e.k?it(e,{k:t,v:n}):t<e.k?ec(it(e,{l:jt(e.l,t,n)})):ec(it(e,{r:jt(e.r,t,n)}))}function er(){return Tr}function go(e,t,n){if(Ve(e))return[];const r=Wt(e,t)[0];return Hg(ni(e,r,n))}function ti(e,t){if(Ve(e))return Tr;const{k:n,l:r,r:o}=e;if(t===n){if(Ve(r))return o;if(Ve(o))return r;{const[s,i]=Zl(r);return xo(it(e,{k:s,l:Jl(r),v:i}))}}else return t<n?xo(it(e,{l:ti(r,t)})):xo(it(e,{r:ti(o,t)}))}function Mn(e){return Ve(e)?[]:[...Mn(e.l),{k:e.k,v:e.v},...Mn(e.r)]}function ni(e,t,n){if(Ve(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ni(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ni(s,t,n))),a}function xo(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(ri(t))return tc(it(e,{lvl:n-1}));if(!Ve(t)&&!Ve(t.r))return it(t.r,{l:it(t,{r:t.r.l}),lvl:n,r:it(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ri(e))return oi(it(e,{lvl:n-1}));if(!Ve(r)&&!Ve(r.l)){const o=r.l,s=ri(o)?r.lvl-1:r.lvl;return it(o,{l:it(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oi(it(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function it(e,t){return Ql(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 Jl(e){return Ve(e.r)?e.l:xo(it(e,{r:Jl(e.r)}))}function ri(e){return Ve(e)||e.lvl>e.r.lvl}function Zl(e){return Ve(e.r)?[e.k,e.v]:Zl(e.r)}function Ql(e,t,n,r=Tr,o=Tr){return{k:e,l:r,lvl:n,r:o,v:t}}function ec(e){return oi(tc(e))}function tc(e){const{l:t}=e;return!Ve(t)&&t.lvl===e.lvl?it(t,{r:it(e,{l:t.r})}):e}function oi(e){const{lvl:t,r:n}=e;return!Ve(n)&&!Ve(n.r)&&n.lvl===t&&n.r.lvl===t?it(n,{l:it(e,{r:n.l}),lvl:t+1}):e}function Hg(e){return Xl(e,({k:t,v:n})=>({index:t,value:n}))}function nc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Er(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const si=$e(()=>({recalcInProgress:q(!1)}),[],{singleton:!0});function rc(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 Ug(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 vo(e){return!Ve(e.groupOffsetTree)}function ii({index:e},t){return t===e?0:t<e?-1:1}function Wg(){return{groupIndices:[],groupOffsetTree:er(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:er()}}function Vg(e,t){let n=Ve(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ve(e)){e=jt(e,0,s);continue}const a=go(e,i-1,o+1);if(a.some(Zg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:p}of a)c?(o>=f||s===p)&&(e=ti(e,f)):(u=p!==s,c=!0),d>o&&o>=f&&p!==s&&(e=jt(e,o+1,p));u&&(e=jt(e,i,s))}return[e,n]}function Kg(e){return typeof e.groupIndex<"u"}function qg({offset:e},t){return t===e?0:t<e?-1:1}function Ir(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=rc(t,e,ii),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function oc(e,t){if(!vo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function sc(e,t,n){if(Kg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=oc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Gg(e,t,n,r=0){return r>0&&(t=Math.max(t,rc(e,r,ii).offset)),Xl(Ug(e,t,n,qg),Jg)}function Yg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ct.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ve(s)&&t.length===2){const p=t[0].size,m=t[1].size;i=n.reduce((w,b)=>jt(jt(w,b,p),b+1,m),i)}else[i,a]=Vg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ai(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,m)=>jt(p,m,Ir(m,f,o)),er()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Xg(e){return Mn(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 ic(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 ai(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=bo(o,t-1,ii),a=o[c].offset;const u=Wt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Wt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of go(n,t,1/0)){const f=u-s,p=f*i+a+f*r;o.push({index:u,offset:p,size:d}),s=u,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Jg(e){return{index:e.index,value:e}}function Zg(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 Qg={offsetHeight:"height",offsetWidth:"width"},en=$e(([{log:e},{recalcInProgress:t}])=>{const n=Me(),r=Me(),o=pt(r,0),s=Me(),i=Me(),a=q(0),c=q([]),u=q(void 0),d=q(void 0),f=q((S,T)=>bn(S,Qg[T])),p=q(void 0),m=q(0),w=Wg(),b=pt(B(n,je(c,e,m),Qt(Yg,w),Ze()),w),g=pt(B(c,Ze(),Qt((S,T)=>({current:T,prev:S.current}),{current:[],prev:[]}),ae(({prev:S})=>S)),[]);fe(B(c,ye(S=>S.length>0),je(b,m),ae(([S,T,I])=>{const N=S.reduce((j,O,A)=>jt(j,O,Ir(O,T.offsetTree,I)||A),er());return{...T,groupIndices:S,groupOffsetTree:N}})),b),fe(B(r,je(b),ye(([S,{lastIndex:T}])=>S<T),ae(([S,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:S}])),n),fe(u,d);const x=pt(B(u,ae(S=>S===void 0)),!0);fe(B(d,ye(S=>S!==void 0&&Ve(nt(b).sizeTree)),ae(S=>[{endIndex:0,size:S,startIndex:0}])),n);const v=Nt(B(n,je(b),Qt(({sizes:S},[T,I])=>({changed:I!==S,sizes:I}),{changed:!1,sizes:w}),ae(S=>S.changed)));He(B(a,Qt((S,T)=>({diff:S.prev-T,prev:T}),{diff:0,prev:0}),ae(S=>S.diff)),S=>{const{groupIndices:T}=nt(b);if(S>0)Ne(t,!0),Ne(s,S+ic(S,T));else if(S<0){const I=nt(g);I.length>0&&(S-=ic(-S,I)),Ne(i,S)}}),He(B(a,je(e)),([S,T])=>{S<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},Ct.ERROR)});const y=Nt(s);fe(B(s,je(b),ae(([S,T])=>{const I=T.groupIndices.length>0,N=[],j=T.lastSize;if(I){const O=kr(T.sizeTree,0);let A=0,F=0;for(;A<S;){const D=T.groupIndices[F],J=T.groupIndices.length===F+1?1/0:T.groupIndices[F+1]-D-1;N.push({endIndex:D,size:O,startIndex:D}),N.push({endIndex:D+1+J-1,size:j,startIndex:D+1}),F++,A+=J+1}const H=Mn(T.sizeTree);return A!==S&&H.shift(),H.reduce((D,{k:J,v:K})=>{let oe=D.ranges;return D.prevSize!==0&&(oe=[...D.ranges,{endIndex:J+S-1,size:D.prevSize,startIndex:D.prevIndex}]),{prevIndex:J+S,prevSize:K,ranges:oe}},{prevIndex:S,prevSize:0,ranges:N}).ranges}return Mn(T.sizeTree).reduce((O,{k:A,v:F})=>({prevIndex:A+S,prevSize:F,ranges:[...O.ranges,{endIndex:A+S-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=Nt(B(i,je(b,m),ae(([S,{offsetTree:T},I])=>{const N=-S;return Ir(N,T,I)})));return fe(B(i,je(b,m),ae(([S,T,I])=>{if(T.groupIndices.length>0){if(Ve(T.sizeTree))return T;let N=er();const j=nt(g);let O=0,A=0,F=0;for(;O<-S;){F=j[A];const H=j[A+1]-F-1;A++,O+=H+1}if(N=Mn(T.sizeTree).reduce((H,{k:D,v:J})=>jt(H,Math.max(0,D+S),J),N),O!==-S){const H=kr(T.sizeTree,F);N=jt(N,0,H);const D=Wt(T.sizeTree,-S+1)[1];N=jt(N,1,D)}return{...T,sizeTree:N,...ai(T.offsetTree,0,N,I)}}else{const N=Mn(T.sizeTree).reduce((j,{k:O,v:A})=>jt(j,Math.max(0,O+S),A),er());return{...T,sizeTree:N,...ai(T.offsetTree,0,N,I)}}})),b),{beforeUnshiftWith:y,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:m,groupIndices:c,itemSize:f,listRefresh:v,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Je(xn,si),{singleton:!0});function ex(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const ac=$e(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Me(),i=Me(),a=Nt(B(s,ae(ex)));return fe(B(a,ae(c=>c.totalCount)),n),fe(B(a,ae(c=>c.groupIndices)),e),fe(B(ot(o,t,r),ye(([c,u])=>vo(u)),ae(([c,u,d])=>Wt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),Ze(),ae(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Je(en,bt)),vn=$e(([{log:e}])=>{const t=q(!1),n=Nt(B(t,ye(r=>r),Ze()));return He(t,r=>{r&&nt(e)("props updated",{},Ct.DEBUG)}),{didMount:n,propsReady:t}},Je(xn),{singleton:!0}),tx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function lc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!tx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Nr=$e(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const m=Me(),w=Me(),b=q(0);let g=null,x=null,v=null;function y(){g&&(g(),g=null),v&&(v(),v=null),x&&(clearTimeout(x),x=null),Ne(c,!1)}return fe(B(m,je(n,f,r,b,a,i,p),je(e,s,o),ae(([[E,S,T,I,N,j,O,A],F,H,D])=>{const J=lc(E),{align:K,behavior:oe,offset:W}=J,M=I-1,X=sc(J,S,M);let Z=Ir(X,S.offsetTree,F)+j;K==="end"?(Z+=H+Wt(S.sizeTree,X)[1]-T+D,X===M&&(Z+=O)):K==="center"?Z+=(H+Wt(S.sizeTree,X)[1]-T+D)/2:Z-=N,W&&(Z+=W);const he=$=>{y(),$?(A("retrying to scroll to",{location:E},Ct.DEBUG),Ne(m,E)):(Ne(w,!0),A("list did not change, scroll successful",{},Ct.DEBUG))};if(y(),oe==="smooth"){let $=!1;v=He(t,G=>{$=$||G}),g=Ut(d,()=>{he($)})}else g=Ut(B(t,nx(150)),he);return x=setTimeout(()=>{y()},1200),Ne(c,!0),A("scrolling from index to",{behavior:oe,index:X,top:Z},Ct.DEBUG),{behavior:oe,top:Z}})),u),{scrollTargetReached:w,scrollToIndex:m,topListHeight:b}},Je(en,bt,xn),{singleton:!0});function nx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function li(e,t){e==0?t():requestAnimationFrame(()=>{li(e-1,t)})}function ci(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const jr=$e(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=q(!0),c=q(0),u=q(!0);return fe(B(i,je(c),ye(([d,f])=>!!f),Zt(!1)),a),fe(B(i,je(c),ye(([d,f])=>!!f),Zt(!1)),u),He(B(ot(t,i),je(a,n,e,u),ye(([[,d],f,{sizeTree:p},m,w])=>d&&(!Ve(p)||Js(m))&&!f&&!w),je(c)),([,d])=>{Ut(o,()=>{Ne(u,!0)}),li(4,()=>{Ut(r,()=>{Ne(a,!0)}),Ne(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Je(en,bt,Nr,vn),{singleton:!0});function cc(e,t){return Math.abs(e-t)<1.01}const Ar="up",Rr="down",rx="none",ox={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},sx=0,_r=$e(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=q(!1),a=q(!0),c=Me(),u=Me(),d=q(4),f=q(sx),p=pt(B(Qs(B(we(o),Pn(1),Zt(!0)),B(we(o),Pn(1),Zt(!1),Kl(100))),Ze()),!1),m=pt(B(Qs(B(n,Zt(!0)),B(n,Zt(!1),Kl(200))),Ze()),!1);fe(B(ot(we(o),we(f)),ae(([v,y])=>v<=y),Ze()),a),fe(B(a,un(50)),u);const w=Nt(B(ot(r,we(s),we(t),we(e),we(d)),Qt((v,[{scrollHeight:y,scrollTop:E},S,T,I,N])=>{const j=E+S-y>-N,O={scrollHeight:y,scrollTop:E,viewportHeight:S};if(j){let F,H;return E>v.state.scrollTop?(F="SCROLLED_DOWN",H=v.state.scrollTop-E):(F="SIZE_DECREASED",H=v.state.scrollTop-E||v.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:H,state:O}}let A;return O.scrollHeight>v.state.scrollHeight?A="SIZE_INCREASED":S<v.state.viewportHeight?A="VIEWPORT_HEIGHT_DECREASING":E<v.state.scrollTop?A="SCROLLING_UPWARDS":A="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:A,state:O}},ox),Ze((v,y)=>v&&v.atBottom===y.atBottom))),b=pt(B(r,Qt((v,{scrollHeight:y,scrollTop:E,viewportHeight:S})=>{if(cc(v.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const T=y-(E+S)<1;return v.scrollTop!==E&&T?{changed:!0,jump:v.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ye(v=>v.changed),ae(v=>v.jump)),0);fe(B(w,ae(v=>v.atBottom)),i),fe(B(i,un(50)),c);const g=q(Rr);fe(B(r,ae(({scrollTop:v})=>v),Ze(),Qt((v,y)=>nt(m)?{direction:v.direction,prevScrollTop:y}:{direction:y<v.prevScrollTop?Ar:Rr,prevScrollTop:y},{direction:Rr,prevScrollTop:0}),ae(v=>v.direction)),g),fe(B(r,un(50),Zt(rx)),g);const x=q(0);return fe(B(p,ye(v=>!v),Zt(0)),x),fe(B(o,un(100),je(p),ye(([v,y])=>!!y),Qt(([v,y],[E])=>[y,E],[0,0]),ae(([v,y])=>y-v)),x),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:b,scrollDirection:g,scrollVelocity:x}},Je(bt)),wo="top",yo="bottom",uc="none";function dc(e,t,n){return typeof e=="number"?n===Ar&&t===wo||n===Rr&&t===yo?e:0:n===Ar?t===wo?e.main:e.reverse:t===yo?e.main:e.reverse}function fc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ui=$e(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Me(),i=q(0),a=q(0),c=q(0),u=pt(B(ot(we(r),we(o),we(n),we(s,Er),we(c),we(i),we(t),we(e),we(a)),ae(([d,f,p,[m,w],b,g,x,v,y])=>{const E=d-v,S=g+x,T=Math.max(p-E,0);let I=uc;const N=fc(y,wo),j=fc(y,yo);return m-=v,m+=p+x,w+=p+x,w-=v,m>d+S-N&&(I=Ar),w<d-T+f+j&&(I=Rr),I!==uc?[Math.max(E-p-dc(b,wo,I)-N,0),E-T-x+f+dc(b,yo,I)+j]:null}),ye(d=>d!=null),Ze(Er)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Je(bt),{singleton:!0});function ix(e,t,n){if(vo(t)){const r=oc(e,t);return[{index:Wt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const di={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function So(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const b=e[e.length-1];d=b.offset+b.size}const f=n-i,p=a+f*c+(f-1)*r,m=u,w=p-d;return{bottom:d,firstItemIndex:s,items:pc(e,o,s),offsetBottom:w,offsetTop:u,top:m,topItems:pc(t,o,s),topListHeight:t.reduce((b,g)=>g.size+b,0),totalCount:n}}function hc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,c=ci(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return So(u,[],a,o,n,r)}function pc(e,t,n){if(e.length===0)return[];if(!vo(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=go(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Dn=$e(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:m},{recalcInProgress:w}])=>{const b=q([]),g=q(0),x=Me();fe(s.topItemsIndexes,b);const v=pt(B(ot(m,w,we(c,Er),we(o),we(r),we(u),d,we(b),we(t),we(n),e),ye(([T,I,,N,,,,,,,j])=>{const O=j&&j.length!==N;return T&&!I&&!O}),ae(([,,[T,I],N,j,O,A,F,H,D,J])=>{const K=j,{offsetTree:oe,sizeTree:W}=K,M=nt(g);if(N===0)return{...di,totalCount:N};if(T===0&&I===0)return M===0?{...di,totalCount:N}:hc(M,O,j,H,D,J||[]);if(Ve(W))return M>0?null:So(ix(ci(O,N),K,J),[],N,D,K,H);const X=[];if(F.length>0){const ee=F[0],pe=F[F.length-1];let z=0;for(const _ of go(W,ee,pe)){const Y=_.value,Q=Math.max(_.start,ee),de=Math.min(_.end,pe);for(let ne=Q;ne<=de;ne++)X.push({data:J==null?void 0:J[ne],index:ne,offset:z,size:Y}),z+=Y}}if(!A)return So([],X,N,D,K,H);const Z=F.length>0?F[F.length-1]+1:0,he=Gg(oe,T,I,Z);if(he.length===0)return null;const $=N-1,G=mo([],ee=>{for(const pe of he){const z=pe.value;let _=z.offset,Y=pe.start;const Q=z.size;if(z.offset<T){Y+=Math.floor((T-z.offset+D)/(Q+D));const ne=Y-pe.start;_+=ne*Q+ne*D}Y<Z&&(_+=(Z-Y)*Q,Y=Z);const de=Math.min(pe.end,$);for(let ne=Y;ne<=de&&!(_>=I);ne++)ee.push({data:J==null?void 0:J[ne],index:ne,offset:_,size:Q}),_+=Q+D}});return So(G,X,N,D,K,H)}),ye(T=>T!==null),Ze()),di);fe(B(e,ye(Js),ae(T=>T==null?void 0:T.length)),o),fe(B(v,ae(T=>T.topListHeight)),f),fe(f,a),fe(B(v,ae(T=>[T.top,T.bottom])),i),fe(B(v,ae(T=>T.items)),x);const y=Nt(B(v,ye(({items:T})=>T.length>0),je(o,e),ye(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ae(([,T,I])=>[T-1,I]),Ze(Er),ae(([T])=>T))),E=Nt(B(v,un(200),ye(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ae(({items:T})=>T[0].index),Ze())),S=Nt(B(v,ye(({items:T})=>T.length>0),ae(({items:T})=>{let I=0,N=T.length-1;for(;T[I].type==="group"&&I<N;)I++;for(;T[N].type==="group"&&N>I;)N--;return{endIndex:T[N].index,startIndex:T[I].index}}),Ze(nc)));return{endReached:y,initialItemCount:g,itemsRendered:x,listState:v,rangeChanged:S,startReached:E,topItemsIndexes:b,...p}},Je(en,ac,ui,jr,Nr,_r,vn,si),{singleton:!0}),mc=$e(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Me(),i=pt(B(ot(n,e,r,t,o),ae(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return fe(we(i),s),{totalListHeight:i,totalListHeightChanged:s}},Je(bt,Dn),{singleton:!0}),ax=$e(([{viewportHeight:e},{totalListHeight:t}])=>{const n=q(!1),r=pt(B(ot(n,e,t),ye(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),un(0),Ze()),0);return{alignToBottom:n,paddingTopAddition:r}},Je(bt,mc),{singleton:!0}),gc=$e(()=>({context:q(null)})),lx=({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,xc=$e(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=Me();return fe(B(d,je(t,c,n,s,o,r,a),je(e),ae(([[f,p,m,w,b,g,x,v],y])=>{const{align:E,behavior:S,calculateViewLocation:T=lx,done:I,...N}=f,j=sc(f,p,w-1),O=Ir(j,p.offsetTree,y)+b+g,A=O+Wt(p.sizeTree,j)[1],F=v+g,H=v+m-x,D=T({itemBottom:A,itemTop:O,locationParams:{align:E,behavior:S,...N},viewportBottom:H,viewportTop:F});return D?I&&Ut(B(i,ye(J=>!J),Pn(nt(i)?1:2)),I):I&&I(),D}),ye(f=>f!==null)),u),{scrollIntoView:d}},Je(en,bt,Nr,Dn,xn),{singleton:!0});function bc(e){return e?e==="smooth"?"smooth":"auto":!1}const cx=(e,t)=>typeof e=="function"?bc(e(t)):t&&bc(e),ux=$e(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:m}])=>{const w=q(!1),b=Me();let g=null;function x(S){Ne(i,{align:"end",behavior:S,index:"LAST"})}He(B(ot(B(we(t),Pn(1)),c),je(we(w),s,a,f),ae(([[S,T],I,N,j,O])=>{let A=T&&j,F="auto";return A&&(F=cx(I,N||O),A=A&&!!F),{followOutputBehavior:F,shouldFollow:A,totalCount:S}}),ye(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:T})=>{g&&(g(),g=null),nt(n)?requestAnimationFrame(()=>{nt(d)("following output to ",{totalCount:T},Ct.DEBUG),x(S)}):g=Ut(e,()=>{nt(d)("following output to ",{totalCount:T},Ct.DEBUG),x(S),g=null})});function v(S){const T=Ut(o,I=>{S&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(nt(d)("scrolling to bottom due to increased size",{},Ct.DEBUG),x("auto"))});setTimeout(T,100)}He(B(ot(we(w),t,u),ye(([S,,T])=>S&&T),Qt(({value:S},[,T])=>({refreshed:S===T,value:T}),{refreshed:!1,value:0}),ye(({refreshed:S})=>S),je(w,t)),([,S])=>{nt(a)&&v(S!==!1)}),He(b,()=>{v(nt(w)!==!1)}),He(ot(we(w),o),([S,T])=>{S&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=q(null),E=Me();return fe(Qs(B(we(r),ae(S=>{var T;return(T=S==null?void 0:S.length)!=null?T:0})),B(we(t))),E),He(B(ot(B(E,Pn(1)),c),je(we(y),a,f,p),ae(([[S,T],I,N,j,O])=>T&&N&&(I==null?void 0:I({context:O,totalCount:S,scrollingInProgress:j}))),ye(S=>!!S),un(0)),S=>{g&&(g(),g=null),nt(n)?requestAnimationFrame(()=>{nt(d)("scrolling into view",{}),Ne(m,S)}):g=Ut(e,()=>{nt(d)("scrolling into view",{}),Ne(m,S),g=null})}),{autoscrollToBottom:b,followOutput:w,scrollIntoViewOnChange:y}},Je(en,_r,Nr,jr,vn,xn,bt,gc,xc)),dx=$e(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(B(a,je(s),ye(([,c])=>c!==0),je(o,r,t,n,e),ae(([[,c],u,d,f,p,m=[]])=>hc(c,u,d,f,p,m))),i),{}),Je(en,jr,Dn,vn),{singleton:!0}),fx=$e(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=q(0);return He(B(e,je(r),ye(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{Ut(B(n,Pn(1),ye(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ne(t,o)})})}),{initialScrollTop:r}},Je(vn,bt,Dn),{singleton:!0}),vc=$e(([{scrollVelocity:e}])=>{const t=q(!1),n=Me(),r=q(!1);return fe(B(e,je(r,t,n),ye(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),Ze()),t),He(B(ot(t,e,n),je(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Je(_r),{singleton:!0}),fi=$e(([{scrollContainerState:e,scrollTo:t}])=>{const n=Me(),r=Me(),o=Me(),s=q(!1),i=q(void 0);return fe(B(ot(n,r),ae(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),fe(B(t,je(r),ae(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Je(bt)),hx=$e(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=Me(),d=q(void 0),f=q(null),p=q(null);return fe(a,f),fe(c,p),He(B(u,je(t,r,i,f,p,n)),([m,w,b,g,x,v,y])=>{const E=Xg(w.sizeTree);g&&x!==null&&v!==null&&(b=x.scrollTop-v.offsetTop),b-=y,m({ranges:E,scrollTop:b})}),fe(B(d,ye(Js),ae(px)),o),fe(B(s,je(d),ye(([,m])=>m!==void 0),Ze(),ae(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:d}},Je(en,bt,jr,vn,fi));function px(e){return{align:"start",index:0,offset:e.scrollTop}}const mx=$e(([{topItemsIndexes:e}])=>{const t=q(0);return fe(B(t,ye(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Je(Dn));function wc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const gx=wc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),xx=$e(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:p},{log:m},{recalcInProgress:w}])=>{const b=Nt(B(c,je(i),Qt(([,x,v,y],[{bottom:E,items:S,offsetBottom:T,totalCount:I},N])=>{const j=E+T;let O=0;return v===I&&x.length>0&&S.length>0&&(S[0].originalIndex===0&&x[0].originalIndex===0||(O=j-y,O!==0&&(O+=N))),[O,S,I,j]},[0,[],0,0]),ye(([x])=>x!==0),je(r,a,n,o,m,w),ye(([,x,v,y,,,E])=>!E&&!y&&x!==0&&v===Ar),ae(([[x],,,,,v])=>(v("Upward scrolling compensation",{amount:x},Ct.DEBUG),x))));function g(x){x>0?(Ne(t,{behavior:"auto",top:-x}),Ne(e,0)):(Ne(e,0),Ne(t,{behavior:"auto",top:-x}))}return He(B(b,je(e,s)),([x,v,y])=>{y&&gx()?Ne(e,v-x):g(-x)}),He(B(ot(pt(s,!1),e,w),ye(([x,v,y])=>!x&&!y&&v!==0),ae(([x,v])=>v),un(1)),g),fe(B(f,ae(x=>({top:-x}))),t),He(B(u,je(p,d),ae(([x,{groupIndices:v,lastSize:y,sizeTree:E},S])=>{function T(I){return I*(y+S)}if(v.length===0)return T(x);{let I=0;const N=kr(E,0);let j=0,O=0;for(;j<x;){j++,I+=N;let A=v.length===O+1?1/0:v[O+1]-v[O]-1;j+A>x&&(I-=N,A=x-j+1),j+=A,I+=T(A),O++}return I}})),x=>{Ne(e,x),requestAnimationFrame(()=>{Ne(t,{top:x}),requestAnimationFrame(()=>{Ne(e,0),Ne(w,!1)})})}),{deviation:e}},Je(bt,_r,Dn,en,xn,si)),bx=$e(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Je(ui,dx,vn,vc,mc,fx,ax,fi,xc,xn,gc)),yc=$e(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:w},b,g,x,{listState:v,topItemsIndexes:y,...E},{scrollToIndex:S},T,{topItemCount:I},{groupCounts:N},j])=>(fe(E.rangeChanged,j.scrollSeekRangeChanged),fe(B(j.windowViewportRect,ae(O=>O.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:v,scrollToIndex:S,statefulTotalCount:u,trackItemSizes:f,...E,...j,...b,sizes:c,...g}),Je(en,jr,bt,hx,ux,Dn,Nr,xx,mx,ac,bx));function vx(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Co=typeof document<"u"?C.useLayoutEffect:C.useEffect;function Sc(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=C.createContext({});function c(g,x){g.propsReady&&Ne(g.propsReady,!1);for(const v of r){const y=g[t.required[v]];Ne(y,x[v])}for(const v of o)if(v in x){const y=g[t.optional[v]];Ne(y,x[v])}g.propsReady&&Ne(g.propsReady,!0)}function u(g){return s.reduce((x,v)=>(x[v]=y=>{const E=g[t.methods[v]];Ne(E,y)},x),{})}function d(g){return i.reduce((x,v)=>(x[v]=Mg(g[t.events[v]]),x),{})}const f=C.forwardRef((g,x)=>{const{children:v,...y}=g,[E]=C.useState(()=>mo(Lg(e),I=>{c(I,y)})),[S]=C.useState(Vl(d,E));Co(()=>{for(const I of i)I in y&&He(S[I],y[I]);return()=>{Object.values(S).map(Zs)}},[y,S,E]),Co(()=>{c(E,y)}),C.useImperativeHandle(x,Ul(u(E)));const T=n;return l.jsx(a.Provider,{value:E,children:n?l.jsx(T,{...vx([...r,...o,...i],y),children:v}):v})}),p=g=>{const x=C.useContext(a);return C.useCallback(v=>{Ne(x[g],v)},[x,g])},m=g=>{const x=C.useContext(a)[g],v=C.useCallback(y=>He(x,y),[x]);return C.useSyncExternalStore(v,()=>nt(x),()=>nt(x))},w=g=>{const x=C.useContext(a)[g],[v,y]=C.useState(Vl(nt,x));return Co(()=>He(x,E=>{E!==v&&y(Ul(E))}),[x,v]),v},b=C.version.startsWith("18")?m:w;return{Component:f,useEmitter:(g,x)=>{const v=C.useContext(a)[g];Co(()=>He(v,x),[x,v])},useEmitterValue:b,usePublisher:p}}const Cc=C.createContext(void 0),Tc=C.createContext(void 0),kc=typeof document<"u"?C.useLayoutEffect:C.useEffect;function hi(e){return"self"in e}function wx(e){return"body"in e}function Ec(e,t,n,r=Qn,o,s){const i=C.useRef(null),a=C.useRef(null),c=C.useRef(null),u=C.useCallback(p=>{let m,w,b;const g=p.target;if(wx(g)||hi(g)){const v=hi(g)?g:g.defaultView;b=s?v.scrollX:v.scrollY,m=s?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,w=s?v.innerWidth:v.innerHeight}else b=s?g.scrollLeft:g.scrollTop,m=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:m,scrollTop:Math.max(b,0),viewportHeight:w})};p.suppressFlushSync?x():Ps.flushSync(x),a.current!==null&&(b===a.current||b<=0||b===m-w)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);C.useEffect(()=>{const p=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",u,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(p){const m=i.current;if(!m||(s?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const w=p.behavior==="smooth";let b,g,x;hi(m)?(g=Math.max(bn(m.document.documentElement,s?"width":"height"),s?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),b=s?m.innerWidth:m.innerHeight,x=s?window.scrollX:window.scrollY):(g=m[s?"scrollWidth":"scrollHeight"],b=bn(m,s?"width":"height"),x=m[s?"scrollLeft":"scrollTop"]);const v=g-b;if(p.top=Math.ceil(Math.max(Math.min(v,p.top),0)),cc(b,g)||p.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:b}),w&&t(!0);return}w?(a.current=p.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),m.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const pi="-webkit-sticky",Ic="sticky",mi=wc(()=>{if(typeof document>"u")return Ic;const e=document.createElement("div");return e.style.position=pi,e.style.position===pi?pi:Ic});function gi(e){return e}const yx=$e(()=>{const e=q(a=>`Item ${a}`),t=q(a=>`Group ${a}`),n=q({}),r=q(gi),o=q("div"),s=q(Qn),i=(a,c=null)=>pt(B(n,ae(u=>u[a]),Ze()),c);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),Sx=$e(([e,t])=>({...e,...t}),Je(yc,yx)),Cx=({height:e})=>l.jsx("div",{style:{height:e}}),Tx={overflowAnchor:"none",position:mi(),zIndex:1},Nc={overflowAnchor:"none"},kx={...Nc,display:"inline-block",height:"100%"},jc=C.memo(function({showTopList:e=!1}){const t=ke("listState"),n=Dt("sizeRanges"),r=ke("useWindowScroll"),o=ke("customScrollParent"),s=Dt("windowScrollContainerState"),i=Dt("scrollContainerState"),a=o||r?s:i,c=ke("itemContent"),u=ke("context"),d=ke("groupContent"),f=ke("trackItemSizes"),p=ke("itemSize"),m=ke("log"),w=Dt("gap"),b=ke("horizontalDirection"),{callbackRef:g}=zg(n,p,f,e?Qn:a,m,w,o,b,ke("skipAnimationFrameInResizeObserver")),[x,v]=C.useState(0);xi("deviation",D=>{x!==D&&v(D)});const y=ke("EmptyPlaceholder"),E=ke("ScrollSeekPlaceholder")||Cx,S=ke("ListComponent"),T=ke("ItemComponent"),I=ke("GroupComponent"),N=ke("computeItemKey"),j=ke("isSeeking"),O=ke("groupIndices").length>0,A=ke("alignToBottom"),F=ke("initialItemFinalLocationReached"),H=e?{}:{boxSizing:"border-box",...b?{display:"inline-block",height:"100%",marginLeft:x!==0?x:A?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:A?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?l.jsx(y,{...mt(y,u)}):l.jsx(S,{...mt(S,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:H,children:(e?t.topItems:t.items).map(D=>{const J=D.originalIndex,K=N(J+t.firstItemIndex,D.data,u);return j?C.createElement(E,{...mt(E,u),height:D.size,index:D.index,key:K,type:D.type||"item",...D.type==="group"?{}:{groupIndex:D.groupIndex}}):D.type==="group"?C.createElement(I,{...mt(I,u),"data-index":J,"data-item-index":D.index,"data-known-size":D.size,key:K,style:Tx},d(D.index,u)):C.createElement(T,{...mt(T,u),...jx(T,D.data),"data-index":J,"data-item-group-index":D.groupIndex,"data-item-index":D.index,"data-known-size":D.size,key:K,style:b?kx:Nc},O?c(D.index,D.groupIndex,D.data,u):c(D.index,D.data,u))})})}),Ex={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Ix={outline:"none",overflowX:"auto",position:"relative"},To=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Nx={position:mi(),top:0,width:"100%",zIndex:1};function mt(e,t){if(typeof e!="string")return{context:t}}function jx(e,t){return{item:typeof e=="string"?void 0:t}}const Ax=C.memo(function(){const e=ke("HeaderComponent"),t=Dt("headerHeight"),n=ke("HeaderFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,ke("skipAnimationFrameInResizeObserver")),o=ke("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Rx=C.memo(function(){const e=ke("FooterComponent"),t=Dt("footerHeight"),n=ke("HeaderFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,ke("skipAnimationFrameInResizeObserver")),o=ke("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null});function Ac({useEmitter:e,useEmitterValue:t,usePublisher:n}){return C.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:m,scrollToCallback:w}=Ec(a,u,c,d,void 0,f);return e("scrollTo",w),e("scrollBy",p),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?Ix:Ex,...o},tabIndex:0,...i,...mt(c,s),children:r})})}function Rc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return C.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),m=C.useRef(null),w=t("scrollerRef"),{scrollByCallback:b,scrollerRef:g,scrollToCallback:x}=Ec(a,u,c,w,p);return kc(()=>{var v;return g.current=p||((v=m.current)==null?void 0:v.ownerDocument.defaultView),()=>{g.current=null}},[g,p]),e("windowScrollTo",x),e("scrollBy",b),l.jsx(c,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...mt(c,s),children:r})})}const _x=({children:e})=>{const t=C.useContext(Cc),n=Dt("viewportHeight"),r=Dt("fixedItemHeight"),o=ke("alignToBottom"),s=ke("horizontalDirection"),i=C.useMemo(()=>Wl(n,c=>bn(c,s?"width":"height")),[n,s]),a=On(i,!0,ke("skipAnimationFrameInResizeObserver"));return C.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:To(o),children:e})},Px=({children:e})=>{const t=C.useContext(Cc),n=Dt("windowViewportRect"),r=Dt("fixedItemHeight"),o=ke("customScrollParent"),s=Yl(n,o,ke("skipAnimationFrameInResizeObserver")),i=ke("alignToBottom");return C.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:To(i),children:e})},Ox=({children:e})=>{const t=ke("TopItemListComponent")||"div",n=ke("headerHeight"),r={...Nx,marginTop:`${n}px`},o=ke("context");return l.jsx(t,{style:r,...mt(t,o),children:e})},Mx=C.memo(function(e){const t=ke("useWindowScroll"),n=ke("topItemsIndexes").length>0,r=ke("customScrollParent"),o=ke("context");return l.jsxs(r||t?$x:Lx,{...e,context:o,children:[n&&l.jsx(Ox,{children:l.jsx(jc,{showTopList:!0})}),l.jsxs(r||t?Px:_x,{children:[l.jsx(Ax,{}),l.jsx(jc,{}),l.jsx(Rx,{})]})]})}),{Component:Dx,useEmitter:xi,useEmitterValue:ke,usePublisher:Dt}=Sc(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"}},Mx),Lx=Ac({useEmitter:xi,useEmitterValue:ke,usePublisher:Dt}),$x=Rc({useEmitter:xi,useEmitterValue:ke,usePublisher:Dt}),Fx=Dx;Je(yc,$e(()=>{const e=q(u=>l.jsxs("td",{children:["Item $",u]})),t=q(null),n=q(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=q(null),o=q(null),s=q({}),i=q(gi),a=q(Qn),c=(u,d=null)=>pt(B(s,ae(f=>f[u]),Ze()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),mi();const _c={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},zx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Pc,floor:ko,max:Pr,min:bi,round:Oc}=Math;function Mc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Bx(e){return{...zx,items:e}}function Eo(e,t){return e&&e.width===t.width&&e.height===t.height}function Hx(e,t){return e&&e.column===t.column&&e.row===t.row}const Ux=$e(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},p,m,{didMount:w,propsReady:b},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E},S])=>{const T=q(0),I=q(0),N=q(_c),j=q({height:0,width:0}),O=q({height:0,width:0}),A=Me(),F=Me(),H=q(0),D=q(null),J=q({column:0,row:0}),K=Me(),oe=Me(),W=q(!1),M=q(0),X=q(!0),Z=q(!1),he=q(!1);He(B(w,je(M),ye(([_,Y])=>!!Y)),()=>{Ne(X,!1)}),He(B(ot(w,X,O,j,M,Z),ye(([_,Y,Q,de,,ne])=>_&&!Y&&Q.height!==0&&de.height!==0&&!ne)),([,,,,_])=>{Ne(Z,!0),li(1,()=>{Ne(A,_)}),Ut(B(u),()=>{Ne(t,[0,0]),Ne(X,!0)})}),fe(B(oe,ye(_=>_!=null&&_.scrollTop>0),Zt(0)),I),He(B(w,je(oe),ye(([,_])=>_!=null)),([,_])=>{_&&(Ne(j,_.viewport),Ne(O,_.item),Ne(J,_.gap),_.scrollTop>0&&(Ne(W,!0),Ut(B(u,Pn(1)),Y=>{Ne(W,!1)}),Ne(c,{top:_.scrollTop})))}),fe(B(j,ae(({height:_})=>_)),f),fe(B(ot(we(j,Eo),we(O,Eo),we(J,(_,Y)=>_&&_.column===Y.column&&_.row===Y.row),we(u)),ae(([_,Y,Q,de])=>({gap:Q,item:Y,scrollTop:de,viewport:_}))),K),fe(B(ot(we(T),r,we(J,Hx),we(O,Eo),we(j,Eo),we(D),we(I),we(W),we(X),we(M)),ye(([,,,,,,,_])=>!_),ae(([_,[Y,Q],de,ne,_e,Pe,Ue,,Ee,Ae])=>{const{column:et,row:qe}=de,{height:ct,width:ut}=ne,{width:ve}=_e;if(Ue===0&&(_===0||ve===0))return _c;if(ut===0){const at=ci(Ae,_),hn=at+Math.max(Ue-1,0);return Bx(Mc(at,hn,Pe))}const Fe=Dc(ve,ut,et);let Ge,P;Ee?Y===0&&Q===0&&Ue>0?(Ge=0,P=Ue-1):(Ge=Fe*ko((Y+qe)/(ct+qe)),P=Fe*Pc((Q+qe)/(ct+qe))-1,P=bi(_-1,Pr(P,Fe-1)),Ge=bi(P,Pr(0,Ge))):(Ge=0,P=-1);const U=Mc(Ge,P,Pe),{bottom:ue,top:be}=Lc(_e,de,ne,U),le=Pc(_/Fe),Be=le*ct+(le-1)*qe-ue;return{bottom:ue,itemHeight:ct,items:U,itemWidth:ut,offsetBottom:Be,offsetTop:be,top:be}})),N),fe(B(D,ye(_=>_!==null),ae(_=>_.length)),T),fe(B(ot(j,O,N,J),ye(([_,Y,{items:Q}])=>Q.length>0&&Y.height!==0&&_.height!==0),ae(([_,Y,{items:Q},de])=>{const{bottom:ne,top:_e}=Lc(_,de,Y,Q);return[_e,ne]}),Ze(Er)),t);const $=q(!1);fe(B(u,je($),ae(([_,Y])=>Y||_!==0)),$);const G=Nt(B(ot(N,T),ye(([{items:_}])=>_.length>0),je($),ye(([[_,Y],Q])=>{const de=_.items[_.items.length-1].index===Y-1;return(Q||_.bottom>0&&_.itemHeight>0&&_.offsetBottom===0&&_.items.length===Y)&&de}),ae(([[,_]])=>_-1),Ze())),ee=Nt(B(we(N),ye(({items:_})=>_.length>0&&_[0].index===0),Zt(0),Ze())),pe=Nt(B(we(N),je(W),ye(([{items:_},Y])=>_.length>0&&!Y),ae(([{items:_}])=>({endIndex:_[_.length-1].index,startIndex:_[0].index})),Ze(nc),un(0)));fe(pe,m.scrollSeekRangeChanged),fe(B(A,je(j,O,T,J),ae(([_,Y,Q,de,ne])=>{const _e=lc(_),{align:Pe,behavior:Ue,offset:Ee}=_e;let Ae=_e.index;Ae==="LAST"&&(Ae=de-1),Ae=Pr(0,Ae,bi(de-1,Ae));let et=vi(Y,ne,Q,Ae);return Pe==="end"?et=Oc(et-Y.height+Q.height):Pe==="center"&&(et=Oc(et-Y.height/2+Q.height/2)),Ee&&(et+=Ee),{behavior:Ue,top:et}})),c);const z=pt(B(N,ae(_=>_.offsetBottom+_.bottom)),0);return fe(B(E,ae(_=>({height:_.visibleHeight,width:_.visibleWidth}))),j),{customScrollParent:g,data:D,deviation:H,footerHeight:o,gap:J,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:O,overscan:n,restoreStateFrom:oe,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:c,scrollToIndex:A,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E,...m,gridState:N,horizontalDirection:he,initialTopMostItemIndex:M,totalListHeight:z,...p,endReached:G,propsReady:b,rangeChanged:pe,startReached:ee,stateChanged:K,stateRestoreInProgress:W,...S}},Je(ui,bt,_r,vc,vn,fi,xn));function Dc(e,t,n){return Pr(1,ko((e+n)/(ko(t)+n)))}function Lc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=vi(e,t,n,r[0].index);return{bottom:vi(e,t,n,r[r.length-1].index)+o,top:s}}function vi(e,t,n,r){const o=Dc(e.width,n.width,t.column),s=ko(r/o),i=s*n.height+Pr(0,s-1)*t.row;return i>0?i+t.row:i}const Wx=$e(()=>{const e=q(f=>`Item ${f}`),t=q({}),n=q(null),r=q("virtuoso-grid-item"),o=q("virtuoso-grid-list"),s=q(gi),i=q("div"),a=q(Qn),c=(f,p=null)=>pt(B(t,ae(m=>m[f]),Ze()),p),u=q(!1),d=q(!1);return fe(we(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Vx=$e(([e,t])=>({...e,...t}),Je(Ux,Wx)),Kx=C.memo(function(){const e=Qe("gridState"),t=Qe("listClassName"),n=Qe("itemClassName"),r=Qe("itemContent"),o=Qe("computeItemKey"),s=Qe("isSeeking"),i=Lt("scrollHeight"),a=Qe("ItemComponent"),c=Qe("ListComponent"),u=Qe("ScrollSeekPlaceholder"),d=Qe("context"),f=Lt("itemDimensions"),p=Lt("gap"),m=Qe("log"),w=Qe("stateRestoreInProgress"),b=Lt("reportReadyState"),g=On(C.useMemo(()=>x=>{const v=x.parentElement.parentElement.scrollHeight;i(v);const y=x.firstChild;if(y){const{height:E,width:S}=y.getBoundingClientRect();f({height:E,width:S})}p({column:Fc("column-gap",getComputedStyle(x).columnGap,m),row:Fc("row-gap",getComputedStyle(x).rowGap,m)})},[i,f,p,m]),!0,!1);return kc(()=>{e.itemHeight>0&&e.itemWidth>0&&b(!0)},[e]),w?null:l.jsx(c,{className:t,ref:g,...mt(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const v=o(x.index,x.data,d);return s?l.jsx(u,{...mt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},v):C.createElement(a,{...mt(a,d),className:n,"data-index":x.index,key:v},r(x.index,x.data,d))})})}),qx=C.memo(function(){const e=Qe("HeaderComponent"),t=Lt("headerHeight"),n=Qe("headerFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=Qe("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Gx=C.memo(function(){const e=Qe("FooterComponent"),t=Lt("footerHeight"),n=Qe("headerFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=Qe("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Yx=({children:e})=>{const t=C.useContext(Tc),n=Lt("itemDimensions"),r=Lt("viewportDimensions"),o=On(C.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return C.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:To(!1),children:e})},Xx=({children:e})=>{const t=C.useContext(Tc),n=Lt("windowViewportRect"),r=Lt("itemDimensions"),o=Qe("customScrollParent"),s=Yl(n,o,!1);return C.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:To(!1),children:e})},Jx=C.memo(function({...e}){const t=Qe("useWindowScroll"),n=Qe("customScrollParent"),r=n||t?Qx:Zx,o=n||t?Xx:Yx,s=Qe("context");return l.jsx(r,{...e,...mt(r,s),children:l.jsxs(o,{children:[l.jsx(qx,{}),l.jsx(Kx,{}),l.jsx(Gx,{})]})})}),{useEmitter:$c,useEmitterValue:Qe,usePublisher:Lt}=Sc(Vx,{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"}},Jx),Zx=Ac({useEmitter:$c,useEmitterValue:Qe,usePublisher:Lt}),Qx=Rc({useEmitter:$c,useEmitterValue:Qe,usePublisher:Lt});function Fc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ct.WARN),t==="normal"?0:parseInt(t??"0",10)}const eb=mr.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 zc({className:e,variant:t,...n}){return l.jsx("div",{className:L(eb({variant:t}),e),...n})}function te(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 tb(e,t){const n=h.createContext(t),r=s=>{const{children:i,...a}=s,c=h.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=h.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 Vt(e,t=[]){let n=[];function r(s,i){const a=h.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:p,children:m,...w}=f,b=((x=p==null?void 0:p[e])==null?void 0:x[c])||a,g=h.useMemo(()=>w,Object.values(w));return l.jsx(b.Provider,{value:g,children:m})};u.displayName=s+"Provider";function d(f,p){var b;const m=((b=p==null?void 0:p[e])==null?void 0:b[c])||a,w=h.useContext(m);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=>h.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return h.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,nb(o,...t)]}function nb(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return h.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var lt=globalThis!=null&&globalThis.document?h.useLayoutEffect:()=>{},rb=h[" useInsertionEffect ".trim().toString()]||lt;function wn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ob({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=h.useRef(e!==void 0);h.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=h.useCallback(d=>{var f;if(a){const p=sb(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[c,u]}function ob({defaultProp:e,onChange:t}){const[n,r]=h.useState(e),o=h.useRef(n),s=h.useRef(t);return rb(()=>{s.current=t},[t]),h.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sb(e){return typeof e=="function"}function Bc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function wi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Bc(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():Bc(e[o],null)}}}}function Re(...e){return h.useCallback(wi(...e),e)}var ib=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=ib.reduce((e,t)=>{const n=Et.createSlot(`Primitive.${t}`),r=h.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Hc(e,t){e&&eo.flushSync(()=>e.dispatchEvent(t))}function ab(e,t){return h.useReducer((n,r)=>t[n][r]??n,e)}var Tt=e=>{const{present:t,children:n}=e,r=lb(t),o=typeof n=="function"?n({present:r.isPresent}):h.Children.only(n),s=Re(r.ref,cb(o));return typeof n=="function"||r.isPresent?h.cloneElement(o,{ref:s}):null};Tt.displayName="Presence";function lb(e){const[t,n]=h.useState(),r=h.useRef(null),o=h.useRef(e),s=h.useRef("none"),i=e?"mounted":"unmounted",[a,c]=ab(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return h.useEffect(()=>{const u=Io(r.current);s.current=a==="mounted"?u:"none"},[a]),lt(()=>{const u=r.current,d=o.current;if(d!==e){const p=s.current,m=Io(u);e?c("MOUNT"):m==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),lt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=m=>{const b=Io(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&b&&(c("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},p=m=>{m.target===t&&(s.current=Io(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:h.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Io(e){return(e==null?void 0:e.animationName)||"none"}function cb(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 ub=h[" useId ".trim().toString()]||(()=>{}),db=0;function Kt(e){const[t,n]=h.useState(ub());return lt(()=>{n(r=>r??String(db++))},[e]),e||(t?`radix-${t}`:"")}var No="Collapsible",[fb,GT]=Vt(No),[hb,yi]=fb(No),Uc=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=wn({prop:r,defaultProp:o??!1,onChange:i,caller:No});return l.jsx(hb,{scope:n,disabled:s,contentId:Kt(),open:c,onOpenToggle:h.useCallback(()=>u(d=>!d),[u]),children:l.jsx(Se.div,{"data-state":Ci(c),"data-disabled":s?"":void 0,...a,ref:t})})});Uc.displayName=No;var Wc="CollapsibleTrigger",Vc=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=yi(Wc,n);return l.jsx(Se.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ci(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:te(e.onClick,o.onOpenToggle)})});Vc.displayName=Wc;var Si="CollapsibleContent",pb=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yi(Si,e.__scopeCollapsible);return l.jsx(Tt,{present:n||o.open,children:({present:s})=>l.jsx(mb,{...r,ref:t,present:s})})});pb.displayName=Si;var mb=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=yi(Si,n),[a,c]=h.useState(r),u=h.useRef(null),d=Re(t,u),f=h.useRef(0),p=f.current,m=h.useRef(0),w=m.current,b=i.open||a,g=h.useRef(b),x=h.useRef(void 0);return h.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),lt(()=>{const v=u.current;if(v){x.current=x.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const y=v.getBoundingClientRect();f.current=y.height,m.current=y.width,g.current||(v.style.transitionDuration=x.current.transitionDuration,v.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(Se.div,{"data-state":Ci(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!b,...s,ref:d,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:b&&o})});function Ci(e){return e?"open":"closed"}var gb=Uc;const Kc=gb,qc=Vc;function Gc(){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 Ln=Gc();function xb(e){Ln=e}const Yc=/[&<>"']/,bb=new RegExp(Yc.source,"g"),Xc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,vb=new RegExp(Xc.source,"g"),wb={"&":"&","<":"<",">":">",'"':""","'":"'"},Jc=e=>wb[e];function gt(e,t){if(t){if(Yc.test(e))return e.replace(bb,Jc)}else if(Xc.test(e))return e.replace(vb,Jc);return e}const yb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zc(e){return e.replace(yb,(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 Sb=/(^|[^\[])\^/g;function Ke(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Sb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Cb=/[^\w:]/g,Tb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qc(e,t,n){if(e){let r;try{r=decodeURIComponent(Zc(n)).replace(Cb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Tb.test(n)&&(n=Nb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const jo={},kb=/^[^:]+:\/*[^/]*$/,Eb=/^([^:]+:)[\s\S]*$/,Ib=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Nb(e,t){jo[" "+e]||(kb.test(e)?jo[" "+e]=e+"/":jo[" "+e]=Ro(e,"/",!0)),e=jo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Eb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Ib,"$1")+t:e+t}const Ao={exec:function(){}};function eu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ro(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 jb(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 Ab(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 tu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function nu(e,t,n,r){const o=t.href,s=t.title?gt(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:gt(i)}}function Rb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
38
|
+
`)}const xg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function bg(e,t){var n;switch(t.type){case"reset":return{messages:Ys(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};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;if(e.assemblingId){const o=e.messages.findIndex(s=>s.id===e.assemblingId);if(o!==-1)return{...e,messages:[...e.messages.slice(0,o),r,...e.messages.slice(o)]}}return{...e,messages:[...e.messages,r]}}case"event":return $l(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>$l(o,s),e):e}default:return e}}function Ll(e=[]){const[t,n]=C.useReducer(bg,{...xg,messages:e}),r=C.useRef([]),o=C.useRef(null),s=C.useRef(null),i=C.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=C.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),c=C.useCallback(d=>{r.current.push(d),a()},[a]);C.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=C.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:c}),[c]);return{state:t,dispatch:n,...u}}function $l(e,t){var n;if(t.type==="message_start"&&t.role==="assistant"){const r=t.id,o=Cg(t.model),s={id:r,role:"assistant",name:o||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:r,messages:[...e.messages,s]}}if(t.type==="token"){const r=e.assemblingId??Xs(e.messages);return r?{...e,messages:wg(e.messages,r,t.content)}:e}if(t.type==="message_delta"){const r=e.assemblingId??Xs(e.messages);return r?{...e,messages:Fl(e.messages,r,t.delta)}:e}if(t.type==="message_end"){const r=e.assemblingId??Xs(e.messages);if(!r)return{...e,assemblingId:null};const o=e.messages,s=o.findIndex(i=>i.id===r&&i.role==="assistant");if(s>=0&&!((n=o[s].content)==null?void 0:n.some(c=>{var u;return(c==null?void 0:c.type)==="text"&&((u=c.text)==null?void 0:u.trim())}))){const c=[...o.slice(0,s),...o.slice(s+1)];return{...e,assemblingId:null,messages:c}}return e}if(t.type==="tool_start"){const r=`tool-${t.id}`,o={type:"tool_call",id:t.id,name:t.name,args:t.args},s={id:r,role:"tool",name:t.name,createdAt:new Date().toISOString(),content:[o]};return{...e,messages:[...e.messages,s],toolIndex:{...e.toolIndex,[t.id]:r}}}if(t.type==="tool_result"){const r=e.toolIndex[t.id]??`tool-${t.id}`,o={type:"tool_result",toolCallId:t.id,output:t.output,error:t.error},s=e.messages.find(c=>c.id===r),i={id:r,role:"tool",content:[o],createdAt:new Date().toISOString()},a=s?Fl(e.messages,r,[o]):[...e.messages,i];return{...e,messages:a}}if(t.type==="checkpoint"){const r=t.checkpointNs??e.lastCheckpointNs??null,o=Sg(e.messages,t.checkpointId,r);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:r,messages:o}}if(t.type==="branch"){const r=t.checkpointId??e.lastCheckpointId,o=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:r??null,lastCheckpointNs:o??null}}if(t.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,r]}}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 vg(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 wg(e,t,n){return e.map(r=>{if(r.id!==t)return r;const o=r.content.slice(),s=o[o.length-1];return s&&s.type==="text"?s.text+=n:o.push({type:"text",text:n}),{...r,content:o}})}function Fl(e,t,n){return e.map(r=>r.id===t?{...r,content:yg(r.content,n)}:r)}function yg(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Sg(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 vg(e,r,s)}return e}function Cg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Tg(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 kg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Eg(e,t=[],n,r,o,s){const i=[],a=[];for(const c of t)try{const u=await kg(c);a.push({filename:c.name,data:u,mime_type:c.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const zl=C.createContext(null);function Cr({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null,autoLoadInitial:s=!0,enableFileAgentRouting:i=!1,fileAgentId:a="invoice_reader"}){const c=mn;C.useEffect(()=>{t&&c.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[c,t]);const{isStreaming:u,error:d,stream:f,stop:p,setToken:m}=Dl({baseUrl:c.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/runs/stream"}),[w,b]=C.useState(()=>typeof c.getAuthToken=="function"?c.getAuthToken():null);C.useEffect(()=>{m(typeof c.getAuthToken=="function"?c.getAuthToken():null);const P=c.onTokenChange(U=>{b(U),m(U)});return()=>{P()}},[c,m]);const g=C.useCallback(P=>{c.setAuthToken(P)},[c]),{state:x,seed:v,prepend:y,pushUser:E,onEvent:S,reset:T}=Ll(),I=20,[N,j]=C.useState(!1),[O,A]=C.useState(!1),[F,H]=C.useState(null),[D,J]=C.useState(void 0),[K,oe]=C.useState(void 0),W=C.useRef(!1),M=C.useRef([]),X=C.useCallback(P=>{P.cursor!==void 0&&H(P.cursor),P.hasMore!==void 0&&j(P.hasMore),P.checkpointId!==void 0&&J(P.checkpointId),P.checkpointNs!==void 0&&oe(P.checkpointNs)},[]),Z=C.useCallback((P,U)=>new Promise((ue,be)=>{const le=async()=>{if(W.current){console.warn(`[ChatProvider] Operation "${U}" queued - another operation in progress`),M.current.push(le);return}W.current=!0;try{console.log(`[ChatProvider] Executing operation: ${U}`),await P(),ue()}catch(Be){console.error(`[ChatProvider] Operation "${U}" failed:`,Be),be(Be)}finally{W.current=!1;const Be=M.current.shift();Be&&Be().catch(()=>{})}};W.current?(M.current.push(le),console.log(`[ChatProvider] Queued operation: ${U}`)):le().catch(Be=>{be(Be)})}),[]),he=C.useCallback((P,U)=>{const ue=Array.isArray(P==null?void 0:P.messages)?P.messages:[];U==="replace"?(console.log("[ChatProvider] Replacing messages, count:",ue.length),v(ue,{checkpointId:(P==null?void 0:P.checkpointId)??null,checkpointNs:(P==null?void 0:P.checkpointNs)??null})):U==="prepend"&&ue.length?(console.log("[ChatProvider] Calling prepend with",ue.length,"messages"),y(ue)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),H((P==null?void 0:P.nextCursor)??null),j(!!(P!=null&&P.hasMore)),J(be=>(P==null?void 0:P.checkpointId)??be??void 0),oe(be=>(P==null?void 0:P.checkpointNs)??be??void 0)},[v,y]),[$,G]=C.useState([]),[ee,pe]=C.useState(null),z=C.useCallback(async()=>{const P=await c.listThreads();G(P)},[c]),[_,Y]=C.useState(!1),Q=C.useCallback(async P=>{const U=(P==null?void 0:P.maxAttempts)??5,ue=(P==null?void 0:P.baseDelayMs)??500,be=(P==null?void 0:P.timeoutMs)??2e3;if(!c.baseUrl)return!1;const le=c.baseUrl.replace(/\/+$/,""),Be=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],at=async xt=>{try{const _t=new AbortController,ft=setTimeout(()=>_t.abort(),be),Pt=await fetch(xt,{method:"GET",signal:_t.signal});return clearTimeout(ft),Pt.ok}catch{return!1}},hn=async xt=>{try{const _t=new AbortController,ft=setTimeout(()=>_t.abort(),be),Pt=await fetch(xt,{method:"HEAD",signal:_t.signal});return clearTimeout(ft),Pt.ok}catch{return!1}};for(let xt=0;xt<U;xt++){console.debug(`[ChatProvider] health-check attempt ${xt+1}/${U}`);for(const ft of Be){let Pt=ft;le.endsWith("/api")&&ft.startsWith("/api")&&(Pt=ft.replace(/^\/api/,"")||"/");const jn=Pt==="/"?le+"/":le+Pt;if(console.debug(`[ChatProvider] checking ${jn}`),await at(jn)||ft==="/"&&await hn(le+"/"))return Y(!0),!0}const _t=ue*Math.pow(2,xt);await new Promise(ft=>setTimeout(ft,_t))}return Y(!1),!1},[c.baseUrl]);C.useEffect(()=>{let P=!0;if(!c.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const U=await Q();if(!P)return;U?z().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{P=!1}},[z,c.baseUrl,Q]),C.useEffect(()=>{r==null||r(ee)},[ee,r]);const de=C.useRef(null);C.useEffect(()=>{if(o&&s){if(!c.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!_){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}de.current!==o&&(de.current=o,Pe(o).catch(()=>{}))}},[o,s,c.baseUrl,_]);const ne=C.useRef(null),_e=C.useRef(null),Pe=C.useCallback(async(P,U,ue)=>{await Z(async()=>{if(!c.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(ne.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${ne.current}) is loading`);return}_e.current!==null&&_e.current!==P&&(console.log(`[ChatProvider] Thread switch detected: ${_e.current} -> ${P}`),T([])),ne.current=P,_e.current=P;try{X({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),pe(P);const le=await c.getMessages({threadId:P,checkpointId:U,checkpointNs:ue,limit:I}),Be=Array.isArray(le==null?void 0:le.messages)?le.messages:[];console.log("[ChatProvider] Loading thread with",Be.length,"messages"),v(Be,{checkpointId:(le==null?void 0:le.checkpointId)??null,checkpointNs:(le==null?void 0:le.checkpointNs)??null}),H((le==null?void 0:le.nextCursor)??null),j(!!(le!=null&&le.hasMore)),J(at=>(le==null?void 0:le.checkpointId)??at??void 0),oe(at=>(le==null?void 0:le.checkpointNs)??at??void 0)}finally{ne.current=null}},`loadThread-${P}`)},[c,Z,X,v]),Ue=C.useCallback(async P=>{const U=await c.listCheckpoints(P);return Tg(U,P)},[c]),Ee=C.useCallback(async(P,U)=>{await Z(async()=>{if(!ee)throw new Error("No active thread");X({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0});const ue=await c.getMessages({threadId:ee,checkpointId:P,checkpointNs:U??void 0,limit:I});he(ue,"replace")},`navigateToCheckpoint-${P}`)},[c,ee,he,Z,X]),Ae=C.useCallback(async()=>{if(!ee)throw new Error("No active thread");await Pe(ee)},[ee,Pe]),et=C.useRef(!1);C.useEffect(()=>{const P=et.current;et.current=u,P&&!u&&ee&&Z(async()=>{try{await z()}catch(U){console.warn("[ChatProvider] Post-streaming thread refresh failed:",U)}},"postStreamingRefresh")},[u,ee,c,he,z,Z]);const qe=C.useCallback(async P=>{const U=await c.createThread(P);return await z(),await Pe(U.threadId),U.threadId},[c,z,Pe]),ct=C.useCallback(async P=>{await c.deleteThread(P),await z(),ee===P&&(pe(null),T([]),j(!1),H(null),J(void 0),oe(void 0))},[c,z,ee,T]),ut=C.useCallback(async(P,U)=>{await c.updateThread(P,U),await z()},[c,z]),ve=C.useCallback(async(P,U)=>{await Z(async()=>{var qn;const ue=(U==null?void 0:U.attachments)||[],{contentParts:be,filesInfo:le}=await Eg(c,ue,t==null?void 0:t.uploadPath),Be=[];P&&P.trim()&&Be.push({type:"text",text:P.trim()});const at={id:((qn=crypto.randomUUID)==null?void 0:qn.call(crypto))||`user-${Date.now()}`,role:"user",content:Be,createdAt:new Date().toISOString(),checkpointId:(U==null?void 0:U.checkpointId)??x.lastCheckpointId??void 0,checkpointNs:(U==null?void 0:U.checkpointNs)??x.lastCheckpointNs??void 0};E(at);const hn={...at,content:Be},xt={...(U==null?void 0:U.payloadExtras)??{}},_t=!!xt.edit,ft=xt.originalMessageId,Pt=typeof ft=="string"?ft:void 0,jn=ue&&ue.length>0,Kn={...ee?{threadId:ee}:{},payload:{messages:[hn],files_info:le,...i&&jn&&a?{active_agent:a}:{},...xt},checkpointId:(U==null?void 0:U.checkpointId)??x.lastCheckpointId??void 0,checkpointNs:(U==null?void 0:U.checkpointNs)??x.lastCheckpointNs??void 0,nodeFilter:U==null?void 0:U.nodeFilter,config:U==null?void 0:U.config,edit:_t,originalMessageId:Pt};f(Kn,re=>S(re),{onError:re=>console.warn("stream error",re),onOpen:({threadId:re,created:me})=>{!ee&&re&&(pe(re),me&&z().catch(()=>{}))}})},"send")},[ee,E,f,S,x.lastCheckpointId,x.lastCheckpointNs,c,t==null?void 0:t.uploadPath,z,pe,i,a,Z]),Fe=C.useCallback(async P=>{if(!ee)throw new Error("No active thread");if(O||!N)return;const U=F;if(U){A(!0);try{const ue=await c.getMessages({threadId:ee,checkpointId:D,checkpointNs:K,limit:(P==null?void 0:P.limit)??I,beforeId:U});he(ue,"prepend")}finally{A(!1)}}},[c,ee,D,K,F,N,O,he,I]),Ge={baseUrl:c.baseUrl,token:w,setToken:g,api:c,threads:$,currentThreadId:ee,setCurrentThreadId:pe,messages:x.messages,isStreaming:u,error:d,lastCheckpointId:x.lastCheckpointId,lastCheckpointNs:x.lastCheckpointNs,streamingAssistantId:x.assemblingId,hasMoreHistory:N,isLoadingHistory:O,loadOlderMessages:Fe,historyPageSize:I,listCheckpoints:Ue,navigateToCheckpoint:Ee,returnToLatest:Ae,refreshThreads:z,createThread:qe,deleteThread:ct,renameThread:ut,loadThread:Pe,send:ve,stop:p};return l.jsx(zl.Provider,{value:Ge,children:e})}function ho(){const e=C.useContext(zl);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function L(...e){return Wp.twMerge(Up.clsx(e))}const Ig=mr.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"}}),ze=h.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Et.Slot:"button";return l.jsx(i,{className:L(Ig({variant:t,size:n,className:e})),ref:s,...o})});ze.displayName="Button";const Bl=h.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:L("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}));Bl.displayName="Textarea";function Ng({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:c,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[p,m]=C.useState(e),[w,b]=C.useTransition(),g=C.useRef(null);C.useEffect(()=>{m(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=C.useCallback(()=>{const N=g.current;N&&(N.style.height="auto",N.style.height=`${N.scrollHeight}px`)},[]);C.useEffect(()=>{x()},[x]);const v=C.useCallback(async N=>{N&&N.preventDefault();const j=(p??"").trim();!j&&!f||b(()=>{try{const O=i(j);O&&typeof O.then=="function"?O.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[p,i,f]),y=C.useCallback(N=>{m(N.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=C.useCallback(N=>{N.key==="Enter"&&!N.shiftKey?(N.preventDefault(),v()):N.key==="Escape"&&t&&(N.preventDefault(),a==null||a())},[v,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return l.jsx("form",{onSubmit:N=>void v(N),className:`w-full ${u}`,children:l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsx("div",{className:"flex-1",children:l.jsx(Bl,{ref:g,value:p,onChange:y,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),l.jsx("div",{children:r?l.jsx(ze,{type:"button",onClick:()=>{c==null||c()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!c,children:l.jsx(se.Square,{size:16})}):l.jsx(ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!p.trim()&&!f||w,children:l.jsx(se.Send,{size:16})})})]})})}const jg=C.memo(Ng),po=0,gn=1,Zn=2,Hl=4;function Ul(e){return()=>e}function Ag(e){e()}function Wl(e,t){return n=>e(t(n))}function Vl(e,t){return()=>e(t)}function Rg(e,t){return n=>e(t,n)}function Js(e){return e!==void 0}function _g(...e){return()=>{e.map(Ag)}}function Qn(){}function mo(e,t){return t(e),e}function Pg(e,t){return t(e)}function Je(...e){return e}function He(e,t){return e(gn,t)}function Ne(e,t){e(po,t)}function Zs(e){e(Zn)}function nt(e){return e(Hl)}function fe(e,t){return He(e,Rg(t,po))}function Ut(e,t){const n=e(gn,r=>{n(),t(r)});return n}function Kl(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function ql(e,t){return e===t}function Ze(e=ql){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ye(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>Wl(t,e)}function Zt(e){return t=>()=>{t(e)}}function B(e,...t){const n=Og(...t);return(r,o)=>{switch(r){case Zn:Zs(e);return;case gn:return He(e,n(o))}}}function Qt(e,t){return n=>r=>{n(t=e(t,r))}}function Pn(e){return t=>n=>{e>0?e--:t(n)}}function un(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function je(...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);He(s,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Og(...e){return t=>e.reduceRight(Pg,t)}function Mg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case gn:return s?n===s?void 0:(r(),n=s,t=He(e,s),t):(r(),Qn);case Zn:r(),n=null;return}}}function q(e){let t=e;const n=Me();return(r,o)=>{switch(r){case po:t=o;break;case gn:{o(t);break}case Hl:return t}return n(r,o)}}function pt(e,t){return mo(q(t),n=>fe(e,n))}function Me(){const e=[];return(t,n)=>{switch(t){case po:e.slice().forEach(r=>{r(n)});return;case Zn:e.splice(0,e.length);return;case gn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Nt(e){return mo(Me(),t=>fe(e,t))}function $e(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Dg(),singleton:n}}const Dg=()=>Symbol();function Lg(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function ot(...e){const t=Me(),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);He(s,c=>{n[i]=c,r=r|a,r===o&&Ne(t,n)})}),function(s,i){switch(s){case Zn:{Zs(t);return}case gn:return r===o&&i(n),He(t,i)}}}function we(e,t=ql){return B(e,Ze(t))}function Qs(...e){return function(t,n){switch(t){case Zn:return;case gn:return _g(...e.map(r=>He(r,n)))}}}var Ct=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ct||{});const $g={0:"debug",3:"error",1:"log",2:"warn"},Fg=()=>typeof globalThis>"u"?window:globalThis,xn=$e(()=>{const e=q(3);return{log:q((t,n,r=1)=>{var o;const s=(o=Fg().VIRTUOSO_LOG_LEVEL)!=null?o:nt(e);r>=s&&console[$g[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function On(e,t,n){return ei(e,t,n).callbackRef}function ei(e,t,n){const r=C.useRef(null);let o=i=>{};const s=C.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function zg(e,t,n,r,o,s,i,a,c){const u=C.useCallback(d=>{const f=Bg(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const m=p.lastElementChild.dataset.viewportType==="window";let w;m&&(w=p.ownerDocument.defaultView);const b=i?a?i.scrollLeft:i.scrollTop:m?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:m?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:m?a?w.innerWidth:w.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(b,0),viewportHeight:x}),s==null||s(a?Gl("column-gap",getComputedStyle(d).columnGap,o):Gl("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ei(u,n,c)}function Bg(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ct.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==c-1?s.push({endIndex:c,size:d,startIndex:c}):s[s.length-1].endIndex++}return s}function Gl(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ct.WARN),t==="normal"?0:parseInt(t??"0",10)}function Yl(e,t,n){const r=C.useRef(null),o=C.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),d=u.width;let f,p;if(t){const m=t.getBoundingClientRect(),w=u.top-m.top;p=m.height-Math.max(0,w),f=w+t.scrollTop}else{const m=i.current.ownerDocument.defaultView;p=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ei(o,!0,n),a=C.useCallback(()=>{o(i.current)},[o,i]);return C.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const bt=$e(()=>{const e=Me(),t=Me(),n=q(0),r=Me(),o=q(0),s=Me(),i=Me(),a=q(0),c=q(0),u=q(0),d=q(0),f=Me(),p=Me(),m=q(!1),w=q(!1),b=q(!1);return fe(B(e,ae(({scrollTop:g})=>g)),t),fe(B(e,ae(({scrollHeight:g})=>g)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:b,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Tr={lvl:0};function Xl(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ve(e){return e===Tr}function kr(e,t){if(!Ve(e))return t===e.k?e.v:t<e.k?kr(e.l,t):kr(e.r,t)}function Wt(e,t,n="k"){if(Ve(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Wt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Wt(e.l,t,n)}function jt(e,t,n){return Ve(e)?Ql(t,n,1):t===e.k?it(e,{k:t,v:n}):t<e.k?ec(it(e,{l:jt(e.l,t,n)})):ec(it(e,{r:jt(e.r,t,n)}))}function er(){return Tr}function go(e,t,n){if(Ve(e))return[];const r=Wt(e,t)[0];return Hg(ni(e,r,n))}function ti(e,t){if(Ve(e))return Tr;const{k:n,l:r,r:o}=e;if(t===n){if(Ve(r))return o;if(Ve(o))return r;{const[s,i]=Zl(r);return xo(it(e,{k:s,l:Jl(r),v:i}))}}else return t<n?xo(it(e,{l:ti(r,t)})):xo(it(e,{r:ti(o,t)}))}function Mn(e){return Ve(e)?[]:[...Mn(e.l),{k:e.k,v:e.v},...Mn(e.r)]}function ni(e,t,n){if(Ve(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ni(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ni(s,t,n))),a}function xo(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(ri(t))return tc(it(e,{lvl:n-1}));if(!Ve(t)&&!Ve(t.r))return it(t.r,{l:it(t,{r:t.r.l}),lvl:n,r:it(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ri(e))return oi(it(e,{lvl:n-1}));if(!Ve(r)&&!Ve(r.l)){const o=r.l,s=ri(o)?r.lvl-1:r.lvl;return it(o,{l:it(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oi(it(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function it(e,t){return Ql(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 Jl(e){return Ve(e.r)?e.l:xo(it(e,{r:Jl(e.r)}))}function ri(e){return Ve(e)||e.lvl>e.r.lvl}function Zl(e){return Ve(e.r)?[e.k,e.v]:Zl(e.r)}function Ql(e,t,n,r=Tr,o=Tr){return{k:e,l:r,lvl:n,r:o,v:t}}function ec(e){return oi(tc(e))}function tc(e){const{l:t}=e;return!Ve(t)&&t.lvl===e.lvl?it(t,{r:it(e,{l:t.r})}):e}function oi(e){const{lvl:t,r:n}=e;return!Ve(n)&&!Ve(n.r)&&n.lvl===t&&n.r.lvl===t?it(n,{l:it(e,{r:n.l}),lvl:t+1}):e}function Hg(e){return Xl(e,({k:t,v:n})=>({index:t,value:n}))}function nc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Er(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const si=$e(()=>({recalcInProgress:q(!1)}),[],{singleton:!0});function rc(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 Ug(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 vo(e){return!Ve(e.groupOffsetTree)}function ii({index:e},t){return t===e?0:t<e?-1:1}function Wg(){return{groupIndices:[],groupOffsetTree:er(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:er()}}function Vg(e,t){let n=Ve(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ve(e)){e=jt(e,0,s);continue}const a=go(e,i-1,o+1);if(a.some(Zg(r)))continue;let c=!1,u=!1;for(const{end:d,start:f,value:p}of a)c?(o>=f||s===p)&&(e=ti(e,f)):(u=p!==s,c=!0),d>o&&o>=f&&p!==s&&(e=jt(e,o+1,p));u&&(e=jt(e,i,s))}return[e,n]}function Kg(e){return typeof e.groupIndex<"u"}function qg({offset:e},t){return t===e?0:t<e?-1:1}function Ir(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=rc(t,e,ii),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function oc(e,t){if(!vo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function sc(e,t,n){if(Kg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=oc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Gg(e,t,n,r=0){return r>0&&(t=Math.max(t,rc(e,r,ii).offset)),Xl(Ug(e,t,n,qg),Jg)}function Yg(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ct.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ve(s)&&t.length===2){const p=t[0].size,m=t[1].size;i=n.reduce((w,b)=>jt(jt(w,b,p),b+1,m),i)}else[i,a]=Vg(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f}=ai(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,m)=>jt(p,m,Ir(m,f,o)),er()),lastIndex:c,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Xg(e){return Mn(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 ic(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 ai(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=bo(o,t-1,ii),a=o[c].offset;const u=Wt(n,t-1);s=u[0],i=u[1],o.length&&o[c].size===Wt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:d}of go(n,t,1/0)){const f=u-s,p=f*i+a+f*r;o.push({index:u,offset:p,size:d}),s=u,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Jg(e){return{index:e.index,value:e}}function Zg(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 Qg={offsetHeight:"height",offsetWidth:"width"},en=$e(([{log:e},{recalcInProgress:t}])=>{const n=Me(),r=Me(),o=pt(r,0),s=Me(),i=Me(),a=q(0),c=q([]),u=q(void 0),d=q(void 0),f=q((S,T)=>bn(S,Qg[T])),p=q(void 0),m=q(0),w=Wg(),b=pt(B(n,je(c,e,m),Qt(Yg,w),Ze()),w),g=pt(B(c,Ze(),Qt((S,T)=>({current:T,prev:S.current}),{current:[],prev:[]}),ae(({prev:S})=>S)),[]);fe(B(c,ye(S=>S.length>0),je(b,m),ae(([S,T,I])=>{const N=S.reduce((j,O,A)=>jt(j,O,Ir(O,T.offsetTree,I)||A),er());return{...T,groupIndices:S,groupOffsetTree:N}})),b),fe(B(r,je(b),ye(([S,{lastIndex:T}])=>S<T),ae(([S,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:S}])),n),fe(u,d);const x=pt(B(u,ae(S=>S===void 0)),!0);fe(B(d,ye(S=>S!==void 0&&Ve(nt(b).sizeTree)),ae(S=>[{endIndex:0,size:S,startIndex:0}])),n);const v=Nt(B(n,je(b),Qt(({sizes:S},[T,I])=>({changed:I!==S,sizes:I}),{changed:!1,sizes:w}),ae(S=>S.changed)));He(B(a,Qt((S,T)=>({diff:S.prev-T,prev:T}),{diff:0,prev:0}),ae(S=>S.diff)),S=>{const{groupIndices:T}=nt(b);if(S>0)Ne(t,!0),Ne(s,S+ic(S,T));else if(S<0){const I=nt(g);I.length>0&&(S-=ic(-S,I)),Ne(i,S)}}),He(B(a,je(e)),([S,T])=>{S<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},Ct.ERROR)});const y=Nt(s);fe(B(s,je(b),ae(([S,T])=>{const I=T.groupIndices.length>0,N=[],j=T.lastSize;if(I){const O=kr(T.sizeTree,0);let A=0,F=0;for(;A<S;){const D=T.groupIndices[F],J=T.groupIndices.length===F+1?1/0:T.groupIndices[F+1]-D-1;N.push({endIndex:D,size:O,startIndex:D}),N.push({endIndex:D+1+J-1,size:j,startIndex:D+1}),F++,A+=J+1}const H=Mn(T.sizeTree);return A!==S&&H.shift(),H.reduce((D,{k:J,v:K})=>{let oe=D.ranges;return D.prevSize!==0&&(oe=[...D.ranges,{endIndex:J+S-1,size:D.prevSize,startIndex:D.prevIndex}]),{prevIndex:J+S,prevSize:K,ranges:oe}},{prevIndex:S,prevSize:0,ranges:N}).ranges}return Mn(T.sizeTree).reduce((O,{k:A,v:F})=>({prevIndex:A+S,prevSize:F,ranges:[...O.ranges,{endIndex:A+S-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=Nt(B(i,je(b,m),ae(([S,{offsetTree:T},I])=>{const N=-S;return Ir(N,T,I)})));return fe(B(i,je(b,m),ae(([S,T,I])=>{if(T.groupIndices.length>0){if(Ve(T.sizeTree))return T;let N=er();const j=nt(g);let O=0,A=0,F=0;for(;O<-S;){F=j[A];const H=j[A+1]-F-1;A++,O+=H+1}if(N=Mn(T.sizeTree).reduce((H,{k:D,v:J})=>jt(H,Math.max(0,D+S),J),N),O!==-S){const H=kr(T.sizeTree,F);N=jt(N,0,H);const D=Wt(T.sizeTree,-S+1)[1];N=jt(N,1,D)}return{...T,sizeTree:N,...ai(T.offsetTree,0,N,I)}}else{const N=Mn(T.sizeTree).reduce((j,{k:O,v:A})=>jt(j,Math.max(0,O+S),A),er());return{...T,sizeTree:N,...ai(T.offsetTree,0,N,I)}}})),b),{beforeUnshiftWith:y,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:m,groupIndices:c,itemSize:f,listRefresh:v,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},Je(xn,si),{singleton:!0});function ex(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const ac=$e(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Me(),i=Me(),a=Nt(B(s,ae(ex)));return fe(B(a,ae(c=>c.totalCount)),n),fe(B(a,ae(c=>c.groupIndices)),e),fe(B(ot(o,t,r),ye(([c,u])=>vo(u)),ae(([c,u,d])=>Wt(u.groupOffsetTree,Math.max(c-d,0),"v")[0]),Ze(),ae(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Je(en,bt)),vn=$e(([{log:e}])=>{const t=q(!1),n=Nt(B(t,ye(r=>r),Ze()));return He(t,r=>{r&&nt(e)("props updated",{},Ct.DEBUG)}),{didMount:n,propsReady:t}},Je(xn),{singleton:!0}),tx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function lc(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!tx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Nr=$e(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const m=Me(),w=Me(),b=q(0);let g=null,x=null,v=null;function y(){g&&(g(),g=null),v&&(v(),v=null),x&&(clearTimeout(x),x=null),Ne(c,!1)}return fe(B(m,je(n,f,r,b,a,i,p),je(e,s,o),ae(([[E,S,T,I,N,j,O,A],F,H,D])=>{const J=lc(E),{align:K,behavior:oe,offset:W}=J,M=I-1,X=sc(J,S,M);let Z=Ir(X,S.offsetTree,F)+j;K==="end"?(Z+=H+Wt(S.sizeTree,X)[1]-T+D,X===M&&(Z+=O)):K==="center"?Z+=(H+Wt(S.sizeTree,X)[1]-T+D)/2:Z-=N,W&&(Z+=W);const he=$=>{y(),$?(A("retrying to scroll to",{location:E},Ct.DEBUG),Ne(m,E)):(Ne(w,!0),A("list did not change, scroll successful",{},Ct.DEBUG))};if(y(),oe==="smooth"){let $=!1;v=He(t,G=>{$=$||G}),g=Ut(d,()=>{he($)})}else g=Ut(B(t,nx(150)),he);return x=setTimeout(()=>{y()},1200),Ne(c,!0),A("scrolling from index to",{behavior:oe,index:X,top:Z},Ct.DEBUG),{behavior:oe,top:Z}})),u),{scrollTargetReached:w,scrollToIndex:m,topListHeight:b}},Je(en,bt,xn),{singleton:!0});function nx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function li(e,t){e==0?t():requestAnimationFrame(()=>{li(e-1,t)})}function ci(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const jr=$e(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=q(!0),c=q(0),u=q(!0);return fe(B(i,je(c),ye(([d,f])=>!!f),Zt(!1)),a),fe(B(i,je(c),ye(([d,f])=>!!f),Zt(!1)),u),He(B(ot(t,i),je(a,n,e,u),ye(([[,d],f,{sizeTree:p},m,w])=>d&&(!Ve(p)||Js(m))&&!f&&!w),je(c)),([,d])=>{Ut(o,()=>{Ne(u,!0)}),li(4,()=>{Ut(r,()=>{Ne(a,!0)}),Ne(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Je(en,bt,Nr,vn),{singleton:!0});function cc(e,t){return Math.abs(e-t)<1.01}const Ar="up",Rr="down",rx="none",ox={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},sx=0,_r=$e(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=q(!1),a=q(!0),c=Me(),u=Me(),d=q(4),f=q(sx),p=pt(B(Qs(B(we(o),Pn(1),Zt(!0)),B(we(o),Pn(1),Zt(!1),Kl(100))),Ze()),!1),m=pt(B(Qs(B(n,Zt(!0)),B(n,Zt(!1),Kl(200))),Ze()),!1);fe(B(ot(we(o),we(f)),ae(([v,y])=>v<=y),Ze()),a),fe(B(a,un(50)),u);const w=Nt(B(ot(r,we(s),we(t),we(e),we(d)),Qt((v,[{scrollHeight:y,scrollTop:E},S,T,I,N])=>{const j=E+S-y>-N,O={scrollHeight:y,scrollTop:E,viewportHeight:S};if(j){let F,H;return E>v.state.scrollTop?(F="SCROLLED_DOWN",H=v.state.scrollTop-E):(F="SIZE_DECREASED",H=v.state.scrollTop-E||v.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:H,state:O}}let A;return O.scrollHeight>v.state.scrollHeight?A="SIZE_INCREASED":S<v.state.viewportHeight?A="VIEWPORT_HEIGHT_DECREASING":E<v.state.scrollTop?A="SCROLLING_UPWARDS":A="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:A,state:O}},ox),Ze((v,y)=>v&&v.atBottom===y.atBottom))),b=pt(B(r,Qt((v,{scrollHeight:y,scrollTop:E,viewportHeight:S})=>{if(cc(v.scrollHeight,y))return{changed:!1,jump:0,scrollHeight:y,scrollTop:E};{const T=y-(E+S)<1;return v.scrollTop!==E&&T?{changed:!0,jump:v.scrollTop-E,scrollHeight:y,scrollTop:E}:{changed:!0,jump:0,scrollHeight:y,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ye(v=>v.changed),ae(v=>v.jump)),0);fe(B(w,ae(v=>v.atBottom)),i),fe(B(i,un(50)),c);const g=q(Rr);fe(B(r,ae(({scrollTop:v})=>v),Ze(),Qt((v,y)=>nt(m)?{direction:v.direction,prevScrollTop:y}:{direction:y<v.prevScrollTop?Ar:Rr,prevScrollTop:y},{direction:Rr,prevScrollTop:0}),ae(v=>v.direction)),g),fe(B(r,un(50),Zt(rx)),g);const x=q(0);return fe(B(p,ye(v=>!v),Zt(0)),x),fe(B(o,un(100),je(p),ye(([v,y])=>!!y),Qt(([v,y],[E])=>[y,E],[0,0]),ae(([v,y])=>y-v)),x),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:b,scrollDirection:g,scrollVelocity:x}},Je(bt)),wo="top",yo="bottom",uc="none";function dc(e,t,n){return typeof e=="number"?n===Ar&&t===wo||n===Rr&&t===yo?e:0:n===Ar?t===wo?e.main:e.reverse:t===yo?e.main:e.reverse}function fc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ui=$e(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Me(),i=q(0),a=q(0),c=q(0),u=pt(B(ot(we(r),we(o),we(n),we(s,Er),we(c),we(i),we(t),we(e),we(a)),ae(([d,f,p,[m,w],b,g,x,v,y])=>{const E=d-v,S=g+x,T=Math.max(p-E,0);let I=uc;const N=fc(y,wo),j=fc(y,yo);return m-=v,m+=p+x,w+=p+x,w-=v,m>d+S-N&&(I=Ar),w<d-T+f+j&&(I=Rr),I!==uc?[Math.max(E-p-dc(b,wo,I)-N,0),E-T-x+f+dc(b,yo,I)+j]:null}),ye(d=>d!=null),Ze(Er)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:u}},Je(bt),{singleton:!0});function ix(e,t,n){if(vo(t)){const r=oc(e,t);return[{index:Wt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const di={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function So(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const b=e[e.length-1];d=b.offset+b.size}const f=n-i,p=a+f*c+(f-1)*r,m=u,w=p-d;return{bottom:d,firstItemIndex:s,items:pc(e,o,s),offsetBottom:w,offsetTop:u,top:m,topItems:pc(t,o,s),topListHeight:t.reduce((b,g)=>g.size+b,0),totalCount:n}}function hc(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,c=ci(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return So(u,[],a,o,n,r)}function pc(e,t,n){if(e.length===0)return[];if(!vo(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=go(t.groupOffsetTree,r,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:c,type:"group"}:d={groupIndex:c,index:u.index-(c+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Dn=$e(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:m},{recalcInProgress:w}])=>{const b=q([]),g=q(0),x=Me();fe(s.topItemsIndexes,b);const v=pt(B(ot(m,w,we(c,Er),we(o),we(r),we(u),d,we(b),we(t),we(n),e),ye(([T,I,,N,,,,,,,j])=>{const O=j&&j.length!==N;return T&&!I&&!O}),ae(([,,[T,I],N,j,O,A,F,H,D,J])=>{const K=j,{offsetTree:oe,sizeTree:W}=K,M=nt(g);if(N===0)return{...di,totalCount:N};if(T===0&&I===0)return M===0?{...di,totalCount:N}:hc(M,O,j,H,D,J||[]);if(Ve(W))return M>0?null:So(ix(ci(O,N),K,J),[],N,D,K,H);const X=[];if(F.length>0){const ee=F[0],pe=F[F.length-1];let z=0;for(const _ of go(W,ee,pe)){const Y=_.value,Q=Math.max(_.start,ee),de=Math.min(_.end,pe);for(let ne=Q;ne<=de;ne++)X.push({data:J==null?void 0:J[ne],index:ne,offset:z,size:Y}),z+=Y}}if(!A)return So([],X,N,D,K,H);const Z=F.length>0?F[F.length-1]+1:0,he=Gg(oe,T,I,Z);if(he.length===0)return null;const $=N-1,G=mo([],ee=>{for(const pe of he){const z=pe.value;let _=z.offset,Y=pe.start;const Q=z.size;if(z.offset<T){Y+=Math.floor((T-z.offset+D)/(Q+D));const ne=Y-pe.start;_+=ne*Q+ne*D}Y<Z&&(_+=(Z-Y)*Q,Y=Z);const de=Math.min(pe.end,$);for(let ne=Y;ne<=de&&!(_>=I);ne++)ee.push({data:J==null?void 0:J[ne],index:ne,offset:_,size:Q}),_+=Q+D}});return So(G,X,N,D,K,H)}),ye(T=>T!==null),Ze()),di);fe(B(e,ye(Js),ae(T=>T==null?void 0:T.length)),o),fe(B(v,ae(T=>T.topListHeight)),f),fe(f,a),fe(B(v,ae(T=>[T.top,T.bottom])),i),fe(B(v,ae(T=>T.items)),x);const y=Nt(B(v,ye(({items:T})=>T.length>0),je(o,e),ye(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ae(([,T,I])=>[T-1,I]),Ze(Er),ae(([T])=>T))),E=Nt(B(v,un(200),ye(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ae(({items:T})=>T[0].index),Ze())),S=Nt(B(v,ye(({items:T})=>T.length>0),ae(({items:T})=>{let I=0,N=T.length-1;for(;T[I].type==="group"&&I<N;)I++;for(;T[N].type==="group"&&N>I;)N--;return{endIndex:T[N].index,startIndex:T[I].index}}),Ze(nc)));return{endReached:y,initialItemCount:g,itemsRendered:x,listState:v,rangeChanged:S,startReached:E,topItemsIndexes:b,...p}},Je(en,ac,ui,jr,Nr,_r,vn,si),{singleton:!0}),mc=$e(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Me(),i=pt(B(ot(n,e,r,t,o),ae(([a,c,u,d,f])=>a+c+u+d+f.offsetBottom+f.bottom)),0);return fe(we(i),s),{totalListHeight:i,totalListHeightChanged:s}},Je(bt,Dn),{singleton:!0}),ax=$e(([{viewportHeight:e},{totalListHeight:t}])=>{const n=q(!1),r=pt(B(ot(n,e,t),ye(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),un(0),Ze()),0);return{alignToBottom:n,paddingTopAddition:r}},Je(bt,mc),{singleton:!0}),gc=$e(()=>({context:q(null)})),lx=({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,xc=$e(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const d=Me();return fe(B(d,je(t,c,n,s,o,r,a),je(e),ae(([[f,p,m,w,b,g,x,v],y])=>{const{align:E,behavior:S,calculateViewLocation:T=lx,done:I,...N}=f,j=sc(f,p,w-1),O=Ir(j,p.offsetTree,y)+b+g,A=O+Wt(p.sizeTree,j)[1],F=v+g,H=v+m-x,D=T({itemBottom:A,itemTop:O,locationParams:{align:E,behavior:S,...N},viewportBottom:H,viewportTop:F});return D?I&&Ut(B(i,ye(J=>!J),Pn(nt(i)?1:2)),I):I&&I(),D}),ye(f=>f!==null)),u),{scrollIntoView:d}},Je(en,bt,Nr,Dn,xn),{singleton:!0});function bc(e){return e?e==="smooth"?"smooth":"auto":!1}const cx=(e,t)=>typeof e=="function"?bc(e(t)):t&&bc(e),ux=$e(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:m}])=>{const w=q(!1),b=Me();let g=null;function x(S){Ne(i,{align:"end",behavior:S,index:"LAST"})}He(B(ot(B(we(t),Pn(1)),c),je(we(w),s,a,f),ae(([[S,T],I,N,j,O])=>{let A=T&&j,F="auto";return A&&(F=cx(I,N||O),A=A&&!!F),{followOutputBehavior:F,shouldFollow:A,totalCount:S}}),ye(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:T})=>{g&&(g(),g=null),nt(n)?requestAnimationFrame(()=>{nt(d)("following output to ",{totalCount:T},Ct.DEBUG),x(S)}):g=Ut(e,()=>{nt(d)("following output to ",{totalCount:T},Ct.DEBUG),x(S),g=null})});function v(S){const T=Ut(o,I=>{S&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(nt(d)("scrolling to bottom due to increased size",{},Ct.DEBUG),x("auto"))});setTimeout(T,100)}He(B(ot(we(w),t,u),ye(([S,,T])=>S&&T),Qt(({value:S},[,T])=>({refreshed:S===T,value:T}),{refreshed:!1,value:0}),ye(({refreshed:S})=>S),je(w,t)),([,S])=>{nt(a)&&v(S!==!1)}),He(b,()=>{v(nt(w)!==!1)}),He(ot(we(w),o),([S,T])=>{S&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const y=q(null),E=Me();return fe(Qs(B(we(r),ae(S=>{var T;return(T=S==null?void 0:S.length)!=null?T:0})),B(we(t))),E),He(B(ot(B(E,Pn(1)),c),je(we(y),a,f,p),ae(([[S,T],I,N,j,O])=>T&&N&&(I==null?void 0:I({context:O,totalCount:S,scrollingInProgress:j}))),ye(S=>!!S),un(0)),S=>{g&&(g(),g=null),nt(n)?requestAnimationFrame(()=>{nt(d)("scrolling into view",{}),Ne(m,S)}):g=Ut(e,()=>{nt(d)("scrolling into view",{}),Ne(m,S),g=null})}),{autoscrollToBottom:b,followOutput:w,scrollIntoViewOnChange:y}},Je(en,_r,Nr,jr,vn,xn,bt,gc,xc)),dx=$e(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(B(a,je(s),ye(([,c])=>c!==0),je(o,r,t,n,e),ae(([[,c],u,d,f,p,m=[]])=>hc(c,u,d,f,p,m))),i),{}),Je(en,jr,Dn,vn),{singleton:!0}),fx=$e(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=q(0);return He(B(e,je(r),ye(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{Ut(B(n,Pn(1),ye(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Ne(t,o)})})}),{initialScrollTop:r}},Je(vn,bt,Dn),{singleton:!0}),vc=$e(([{scrollVelocity:e}])=>{const t=q(!1),n=Me(),r=q(!1);return fe(B(e,je(r,t,n),ye(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:c,exit:u}=s;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),Ze()),t),He(B(ot(t,e,n),je(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Je(_r),{singleton:!0}),fi=$e(([{scrollContainerState:e,scrollTo:t}])=>{const n=Me(),r=Me(),o=Me(),s=q(!1),i=q(void 0);return fe(B(ot(n,r),ae(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,c-d),viewportHeight:u}))),e),fe(B(t,je(r),ae(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Je(bt)),hx=$e(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=Me(),d=q(void 0),f=q(null),p=q(null);return fe(a,f),fe(c,p),He(B(u,je(t,r,i,f,p,n)),([m,w,b,g,x,v,y])=>{const E=Xg(w.sizeTree);g&&x!==null&&v!==null&&(b=x.scrollTop-v.offsetTop),b-=y,m({ranges:E,scrollTop:b})}),fe(B(d,ye(Js),ae(px)),o),fe(B(s,je(d),ye(([,m])=>m!==void 0),Ze(),ae(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:d}},Je(en,bt,jr,vn,fi));function px(e){return{align:"start",index:0,offset:e.scrollTop}}const mx=$e(([{topItemsIndexes:e}])=>{const t=q(0);return fe(B(t,ye(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Je(Dn));function wc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const gx=wc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),xx=$e(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:p},{log:m},{recalcInProgress:w}])=>{const b=Nt(B(c,je(i),Qt(([,x,v,y],[{bottom:E,items:S,offsetBottom:T,totalCount:I},N])=>{const j=E+T;let O=0;return v===I&&x.length>0&&S.length>0&&(S[0].originalIndex===0&&x[0].originalIndex===0||(O=j-y,O!==0&&(O+=N))),[O,S,I,j]},[0,[],0,0]),ye(([x])=>x!==0),je(r,a,n,o,m,w),ye(([,x,v,y,,,E])=>!E&&!y&&x!==0&&v===Ar),ae(([[x],,,,,v])=>(v("Upward scrolling compensation",{amount:x},Ct.DEBUG),x))));function g(x){x>0?(Ne(t,{behavior:"auto",top:-x}),Ne(e,0)):(Ne(e,0),Ne(t,{behavior:"auto",top:-x}))}return He(B(b,je(e,s)),([x,v,y])=>{y&&gx()?Ne(e,v-x):g(-x)}),He(B(ot(pt(s,!1),e,w),ye(([x,v,y])=>!x&&!y&&v!==0),ae(([x,v])=>v),un(1)),g),fe(B(f,ae(x=>({top:-x}))),t),He(B(u,je(p,d),ae(([x,{groupIndices:v,lastSize:y,sizeTree:E},S])=>{function T(I){return I*(y+S)}if(v.length===0)return T(x);{let I=0;const N=kr(E,0);let j=0,O=0;for(;j<x;){j++,I+=N;let A=v.length===O+1?1/0:v[O+1]-v[O]-1;j+A>x&&(I-=N,A=x-j+1),j+=A,I+=T(A),O++}return I}})),x=>{Ne(e,x),requestAnimationFrame(()=>{Ne(t,{top:x}),requestAnimationFrame(()=>{Ne(e,0),Ne(w,!1)})})}),{deviation:e}},Je(bt,_r,Dn,en,xn,si)),bx=$e(([e,t,n,r,o,s,i,a,c,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...u,...d}),Je(ui,dx,vn,vc,mc,fx,ax,fi,xc,xn,gc)),yc=$e(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:w},b,g,x,{listState:v,topItemsIndexes:y,...E},{scrollToIndex:S},T,{topItemCount:I},{groupCounts:N},j])=>(fe(E.rangeChanged,j.scrollSeekRangeChanged),fe(B(j.windowViewportRect,ae(O=>O.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:y,totalCount:d,...x,groupIndices:s,itemSize:i,listState:v,scrollToIndex:S,statefulTotalCount:u,trackItemSizes:f,...E,...j,...b,sizes:c,...g}),Je(en,jr,bt,hx,ux,Dn,Nr,xx,mx,ac,bx));function vx(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Co=typeof document<"u"?C.useLayoutEffect:C.useEffect;function Sc(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=C.createContext({});function c(g,x){g.propsReady&&Ne(g.propsReady,!1);for(const v of r){const y=g[t.required[v]];Ne(y,x[v])}for(const v of o)if(v in x){const y=g[t.optional[v]];Ne(y,x[v])}g.propsReady&&Ne(g.propsReady,!0)}function u(g){return s.reduce((x,v)=>(x[v]=y=>{const E=g[t.methods[v]];Ne(E,y)},x),{})}function d(g){return i.reduce((x,v)=>(x[v]=Mg(g[t.events[v]]),x),{})}const f=C.forwardRef((g,x)=>{const{children:v,...y}=g,[E]=C.useState(()=>mo(Lg(e),I=>{c(I,y)})),[S]=C.useState(Vl(d,E));Co(()=>{for(const I of i)I in y&&He(S[I],y[I]);return()=>{Object.values(S).map(Zs)}},[y,S,E]),Co(()=>{c(E,y)}),C.useImperativeHandle(x,Ul(u(E)));const T=n;return l.jsx(a.Provider,{value:E,children:n?l.jsx(T,{...vx([...r,...o,...i],y),children:v}):v})}),p=g=>{const x=C.useContext(a);return C.useCallback(v=>{Ne(x[g],v)},[x,g])},m=g=>{const x=C.useContext(a)[g],v=C.useCallback(y=>He(x,y),[x]);return C.useSyncExternalStore(v,()=>nt(x),()=>nt(x))},w=g=>{const x=C.useContext(a)[g],[v,y]=C.useState(Vl(nt,x));return Co(()=>He(x,E=>{E!==v&&y(Ul(E))}),[x,v]),v},b=C.version.startsWith("18")?m:w;return{Component:f,useEmitter:(g,x)=>{const v=C.useContext(a)[g];Co(()=>He(v,x),[x,v])},useEmitterValue:b,usePublisher:p}}const Cc=C.createContext(void 0),Tc=C.createContext(void 0),kc=typeof document<"u"?C.useLayoutEffect:C.useEffect;function hi(e){return"self"in e}function wx(e){return"body"in e}function Ec(e,t,n,r=Qn,o,s){const i=C.useRef(null),a=C.useRef(null),c=C.useRef(null),u=C.useCallback(p=>{let m,w,b;const g=p.target;if(wx(g)||hi(g)){const v=hi(g)?g:g.defaultView;b=s?v.scrollX:v.scrollY,m=s?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,w=s?v.innerWidth:v.innerHeight}else b=s?g.scrollLeft:g.scrollTop,m=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:m,scrollTop:Math.max(b,0),viewportHeight:w})};p.suppressFlushSync?x():Ps.flushSync(x),a.current!==null&&(b===a.current||b<=0||b===m-w)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);C.useEffect(()=>{const p=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",u,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(p){const m=i.current;if(!m||(s?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const w=p.behavior==="smooth";let b,g,x;hi(m)?(g=Math.max(bn(m.document.documentElement,s?"width":"height"),s?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),b=s?m.innerWidth:m.innerHeight,x=s?window.scrollX:window.scrollY):(g=m[s?"scrollWidth":"scrollHeight"],b=bn(m,s?"width":"height"),x=m[s?"scrollLeft":"scrollTop"]);const v=g-b;if(p.top=Math.ceil(Math.max(Math.min(v,p.top),0)),cc(b,g)||p.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:b}),w&&t(!0);return}w?(a.current=p.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),m.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const pi="-webkit-sticky",Ic="sticky",mi=wc(()=>{if(typeof document>"u")return Ic;const e=document.createElement("div");return e.style.position=pi,e.style.position===pi?pi:Ic});function gi(e){return e}const yx=$e(()=>{const e=q(a=>`Item ${a}`),t=q(a=>`Group ${a}`),n=q({}),r=q(gi),o=q("div"),s=q(Qn),i=(a,c=null)=>pt(B(n,ae(u=>u[a]),Ze()),c);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),Sx=$e(([e,t])=>({...e,...t}),Je(yc,yx)),Cx=({height:e})=>l.jsx("div",{style:{height:e}}),Tx={overflowAnchor:"none",position:mi(),zIndex:1},Nc={overflowAnchor:"none"},kx={...Nc,display:"inline-block",height:"100%"},jc=C.memo(function({showTopList:e=!1}){const t=ke("listState"),n=Dt("sizeRanges"),r=ke("useWindowScroll"),o=ke("customScrollParent"),s=Dt("windowScrollContainerState"),i=Dt("scrollContainerState"),a=o||r?s:i,c=ke("itemContent"),u=ke("context"),d=ke("groupContent"),f=ke("trackItemSizes"),p=ke("itemSize"),m=ke("log"),w=Dt("gap"),b=ke("horizontalDirection"),{callbackRef:g}=zg(n,p,f,e?Qn:a,m,w,o,b,ke("skipAnimationFrameInResizeObserver")),[x,v]=C.useState(0);xi("deviation",D=>{x!==D&&v(D)});const y=ke("EmptyPlaceholder"),E=ke("ScrollSeekPlaceholder")||Cx,S=ke("ListComponent"),T=ke("ItemComponent"),I=ke("GroupComponent"),N=ke("computeItemKey"),j=ke("isSeeking"),O=ke("groupIndices").length>0,A=ke("alignToBottom"),F=ke("initialItemFinalLocationReached"),H=e?{}:{boxSizing:"border-box",...b?{display:"inline-block",height:"100%",marginLeft:x!==0?x:A?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:A?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&y?l.jsx(y,{...mt(y,u)}):l.jsx(S,{...mt(S,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:H,children:(e?t.topItems:t.items).map(D=>{const J=D.originalIndex,K=N(J+t.firstItemIndex,D.data,u);return j?C.createElement(E,{...mt(E,u),height:D.size,index:D.index,key:K,type:D.type||"item",...D.type==="group"?{}:{groupIndex:D.groupIndex}}):D.type==="group"?C.createElement(I,{...mt(I,u),"data-index":J,"data-item-index":D.index,"data-known-size":D.size,key:K,style:Tx},d(D.index,u)):C.createElement(T,{...mt(T,u),...jx(T,D.data),"data-index":J,"data-item-group-index":D.groupIndex,"data-item-index":D.index,"data-known-size":D.size,key:K,style:b?kx:Nc},O?c(D.index,D.groupIndex,D.data,u):c(D.index,D.data,u))})})}),Ex={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Ix={outline:"none",overflowX:"auto",position:"relative"},To=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Nx={position:mi(),top:0,width:"100%",zIndex:1};function mt(e,t){if(typeof e!="string")return{context:t}}function jx(e,t){return{item:typeof e=="string"?void 0:t}}const Ax=C.memo(function(){const e=ke("HeaderComponent"),t=Dt("headerHeight"),n=ke("HeaderFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,ke("skipAnimationFrameInResizeObserver")),o=ke("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Rx=C.memo(function(){const e=ke("FooterComponent"),t=Dt("footerHeight"),n=ke("HeaderFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,ke("skipAnimationFrameInResizeObserver")),o=ke("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null});function Ac({useEmitter:e,useEmitterValue:t,usePublisher:n}){return C.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:m,scrollToCallback:w}=Ec(a,u,c,d,void 0,f);return e("scrollTo",w),e("scrollBy",p),l.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?Ix:Ex,...o},tabIndex:0,...i,...mt(c,s),children:r})})}function Rc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return C.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),m=C.useRef(null),w=t("scrollerRef"),{scrollByCallback:b,scrollerRef:g,scrollToCallback:x}=Ec(a,u,c,w,p);return kc(()=>{var v;return g.current=p||((v=m.current)==null?void 0:v.ownerDocument.defaultView),()=>{g.current=null}},[g,p]),e("windowScrollTo",x),e("scrollBy",b),l.jsx(c,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...mt(c,s),children:r})})}const _x=({children:e})=>{const t=C.useContext(Cc),n=Dt("viewportHeight"),r=Dt("fixedItemHeight"),o=ke("alignToBottom"),s=ke("horizontalDirection"),i=C.useMemo(()=>Wl(n,c=>bn(c,s?"width":"height")),[n,s]),a=On(i,!0,ke("skipAnimationFrameInResizeObserver"));return C.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),l.jsx("div",{"data-viewport-type":"element",ref:a,style:To(o),children:e})},Px=({children:e})=>{const t=C.useContext(Cc),n=Dt("windowViewportRect"),r=Dt("fixedItemHeight"),o=ke("customScrollParent"),s=Yl(n,o,ke("skipAnimationFrameInResizeObserver")),i=ke("alignToBottom");return C.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),l.jsx("div",{"data-viewport-type":"window",ref:s,style:To(i),children:e})},Ox=({children:e})=>{const t=ke("TopItemListComponent")||"div",n=ke("headerHeight"),r={...Nx,marginTop:`${n}px`},o=ke("context");return l.jsx(t,{style:r,...mt(t,o),children:e})},Mx=C.memo(function(e){const t=ke("useWindowScroll"),n=ke("topItemsIndexes").length>0,r=ke("customScrollParent"),o=ke("context");return l.jsxs(r||t?$x:Lx,{...e,context:o,children:[n&&l.jsx(Ox,{children:l.jsx(jc,{showTopList:!0})}),l.jsxs(r||t?Px:_x,{children:[l.jsx(Ax,{}),l.jsx(jc,{}),l.jsx(Rx,{})]})]})}),{Component:Dx,useEmitter:xi,useEmitterValue:ke,usePublisher:Dt}=Sc(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"}},Mx),Lx=Ac({useEmitter:xi,useEmitterValue:ke,usePublisher:Dt}),$x=Rc({useEmitter:xi,useEmitterValue:ke,usePublisher:Dt}),Fx=Dx;Je(yc,$e(()=>{const e=q(u=>l.jsxs("td",{children:["Item $",u]})),t=q(null),n=q(u=>l.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=q(null),o=q(null),s=q({}),i=q(gi),a=q(Qn),c=(u,d=null)=>pt(B(s,ae(f=>f[u]),Ze()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),mi();const _c={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},zx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Pc,floor:ko,max:Pr,min:bi,round:Oc}=Math;function Mc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Bx(e){return{...zx,items:e}}function Eo(e,t){return e&&e.width===t.width&&e.height===t.height}function Hx(e,t){return e&&e.column===t.column&&e.row===t.row}const Ux=$e(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},p,m,{didMount:w,propsReady:b},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E},S])=>{const T=q(0),I=q(0),N=q(_c),j=q({height:0,width:0}),O=q({height:0,width:0}),A=Me(),F=Me(),H=q(0),D=q(null),J=q({column:0,row:0}),K=Me(),oe=Me(),W=q(!1),M=q(0),X=q(!0),Z=q(!1),he=q(!1);He(B(w,je(M),ye(([_,Y])=>!!Y)),()=>{Ne(X,!1)}),He(B(ot(w,X,O,j,M,Z),ye(([_,Y,Q,de,,ne])=>_&&!Y&&Q.height!==0&&de.height!==0&&!ne)),([,,,,_])=>{Ne(Z,!0),li(1,()=>{Ne(A,_)}),Ut(B(u),()=>{Ne(t,[0,0]),Ne(X,!0)})}),fe(B(oe,ye(_=>_!=null&&_.scrollTop>0),Zt(0)),I),He(B(w,je(oe),ye(([,_])=>_!=null)),([,_])=>{_&&(Ne(j,_.viewport),Ne(O,_.item),Ne(J,_.gap),_.scrollTop>0&&(Ne(W,!0),Ut(B(u,Pn(1)),Y=>{Ne(W,!1)}),Ne(c,{top:_.scrollTop})))}),fe(B(j,ae(({height:_})=>_)),f),fe(B(ot(we(j,Eo),we(O,Eo),we(J,(_,Y)=>_&&_.column===Y.column&&_.row===Y.row),we(u)),ae(([_,Y,Q,de])=>({gap:Q,item:Y,scrollTop:de,viewport:_}))),K),fe(B(ot(we(T),r,we(J,Hx),we(O,Eo),we(j,Eo),we(D),we(I),we(W),we(X),we(M)),ye(([,,,,,,,_])=>!_),ae(([_,[Y,Q],de,ne,_e,Pe,Ue,,Ee,Ae])=>{const{column:et,row:qe}=de,{height:ct,width:ut}=ne,{width:ve}=_e;if(Ue===0&&(_===0||ve===0))return _c;if(ut===0){const at=ci(Ae,_),hn=at+Math.max(Ue-1,0);return Bx(Mc(at,hn,Pe))}const Fe=Dc(ve,ut,et);let Ge,P;Ee?Y===0&&Q===0&&Ue>0?(Ge=0,P=Ue-1):(Ge=Fe*ko((Y+qe)/(ct+qe)),P=Fe*Pc((Q+qe)/(ct+qe))-1,P=bi(_-1,Pr(P,Fe-1)),Ge=bi(P,Pr(0,Ge))):(Ge=0,P=-1);const U=Mc(Ge,P,Pe),{bottom:ue,top:be}=Lc(_e,de,ne,U),le=Pc(_/Fe),Be=le*ct+(le-1)*qe-ue;return{bottom:ue,itemHeight:ct,items:U,itemWidth:ut,offsetBottom:Be,offsetTop:be,top:be}})),N),fe(B(D,ye(_=>_!==null),ae(_=>_.length)),T),fe(B(ot(j,O,N,J),ye(([_,Y,{items:Q}])=>Q.length>0&&Y.height!==0&&_.height!==0),ae(([_,Y,{items:Q},de])=>{const{bottom:ne,top:_e}=Lc(_,de,Y,Q);return[_e,ne]}),Ze(Er)),t);const $=q(!1);fe(B(u,je($),ae(([_,Y])=>Y||_!==0)),$);const G=Nt(B(ot(N,T),ye(([{items:_}])=>_.length>0),je($),ye(([[_,Y],Q])=>{const de=_.items[_.items.length-1].index===Y-1;return(Q||_.bottom>0&&_.itemHeight>0&&_.offsetBottom===0&&_.items.length===Y)&&de}),ae(([[,_]])=>_-1),Ze())),ee=Nt(B(we(N),ye(({items:_})=>_.length>0&&_[0].index===0),Zt(0),Ze())),pe=Nt(B(we(N),je(W),ye(([{items:_},Y])=>_.length>0&&!Y),ae(([{items:_}])=>({endIndex:_[_.length-1].index,startIndex:_[0].index})),Ze(nc),un(0)));fe(pe,m.scrollSeekRangeChanged),fe(B(A,je(j,O,T,J),ae(([_,Y,Q,de,ne])=>{const _e=lc(_),{align:Pe,behavior:Ue,offset:Ee}=_e;let Ae=_e.index;Ae==="LAST"&&(Ae=de-1),Ae=Pr(0,Ae,bi(de-1,Ae));let et=vi(Y,ne,Q,Ae);return Pe==="end"?et=Oc(et-Y.height+Q.height):Pe==="center"&&(et=Oc(et-Y.height/2+Q.height/2)),Ee&&(et+=Ee),{behavior:Ue,top:et}})),c);const z=pt(B(N,ae(_=>_.offsetBottom+_.bottom)),0);return fe(B(E,ae(_=>({height:_.visibleHeight,width:_.visibleWidth}))),j),{customScrollParent:g,data:D,deviation:H,footerHeight:o,gap:J,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:O,overscan:n,restoreStateFrom:oe,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:c,scrollToIndex:A,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:v,windowScrollTo:y,windowViewportRect:E,...m,gridState:N,horizontalDirection:he,initialTopMostItemIndex:M,totalListHeight:z,...p,endReached:G,propsReady:b,rangeChanged:pe,startReached:ee,stateChanged:K,stateRestoreInProgress:W,...S}},Je(ui,bt,_r,vc,vn,fi,xn));function Dc(e,t,n){return Pr(1,ko((e+n)/(ko(t)+n)))}function Lc(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=vi(e,t,n,r[0].index);return{bottom:vi(e,t,n,r[r.length-1].index)+o,top:s}}function vi(e,t,n,r){const o=Dc(e.width,n.width,t.column),s=ko(r/o),i=s*n.height+Pr(0,s-1)*t.row;return i>0?i+t.row:i}const Wx=$e(()=>{const e=q(f=>`Item ${f}`),t=q({}),n=q(null),r=q("virtuoso-grid-item"),o=q("virtuoso-grid-list"),s=q(gi),i=q("div"),a=q(Qn),c=(f,p=null)=>pt(B(t,ae(m=>m[f]),Ze()),p),u=q(!1),d=q(!1);return fe(we(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Vx=$e(([e,t])=>({...e,...t}),Je(Ux,Wx)),Kx=C.memo(function(){const e=Qe("gridState"),t=Qe("listClassName"),n=Qe("itemClassName"),r=Qe("itemContent"),o=Qe("computeItemKey"),s=Qe("isSeeking"),i=Lt("scrollHeight"),a=Qe("ItemComponent"),c=Qe("ListComponent"),u=Qe("ScrollSeekPlaceholder"),d=Qe("context"),f=Lt("itemDimensions"),p=Lt("gap"),m=Qe("log"),w=Qe("stateRestoreInProgress"),b=Lt("reportReadyState"),g=On(C.useMemo(()=>x=>{const v=x.parentElement.parentElement.scrollHeight;i(v);const y=x.firstChild;if(y){const{height:E,width:S}=y.getBoundingClientRect();f({height:E,width:S})}p({column:Fc("column-gap",getComputedStyle(x).columnGap,m),row:Fc("row-gap",getComputedStyle(x).rowGap,m)})},[i,f,p,m]),!0,!1);return kc(()=>{e.itemHeight>0&&e.itemWidth>0&&b(!0)},[e]),w?null:l.jsx(c,{className:t,ref:g,...mt(c,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const v=o(x.index,x.data,d);return s?l.jsx(u,{...mt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},v):C.createElement(a,{...mt(a,d),className:n,"data-index":x.index,key:v},r(x.index,x.data,d))})})}),qx=C.memo(function(){const e=Qe("HeaderComponent"),t=Lt("headerHeight"),n=Qe("headerFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=Qe("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Gx=C.memo(function(){const e=Qe("FooterComponent"),t=Lt("footerHeight"),n=Qe("headerFooterTag"),r=On(C.useMemo(()=>s=>{t(bn(s,"height"))},[t]),!0,!1),o=Qe("context");return e?l.jsx(n,{ref:r,children:l.jsx(e,{...mt(e,o)})}):null}),Yx=({children:e})=>{const t=C.useContext(Tc),n=Lt("itemDimensions"),r=Lt("viewportDimensions"),o=On(C.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return C.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),l.jsx("div",{ref:o,style:To(!1),children:e})},Xx=({children:e})=>{const t=C.useContext(Tc),n=Lt("windowViewportRect"),r=Lt("itemDimensions"),o=Qe("customScrollParent"),s=Yl(n,o,!1);return C.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),l.jsx("div",{ref:s,style:To(!1),children:e})},Jx=C.memo(function({...e}){const t=Qe("useWindowScroll"),n=Qe("customScrollParent"),r=n||t?Qx:Zx,o=n||t?Xx:Yx,s=Qe("context");return l.jsx(r,{...e,...mt(r,s),children:l.jsxs(o,{children:[l.jsx(qx,{}),l.jsx(Kx,{}),l.jsx(Gx,{})]})})}),{useEmitter:$c,useEmitterValue:Qe,usePublisher:Lt}=Sc(Vx,{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"}},Jx),Zx=Ac({useEmitter:$c,useEmitterValue:Qe,usePublisher:Lt}),Qx=Rc({useEmitter:$c,useEmitterValue:Qe,usePublisher:Lt});function Fc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ct.WARN),t==="normal"?0:parseInt(t??"0",10)}const eb=mr.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 zc({className:e,variant:t,...n}){return l.jsx("div",{className:L(eb({variant:t}),e),...n})}function te(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 tb(e,t){const n=h.createContext(t),r=s=>{const{children:i,...a}=s,c=h.useMemo(()=>a,Object.values(a));return l.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=h.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 Vt(e,t=[]){let n=[];function r(s,i){const a=h.createContext(i),c=n.length;n=[...n,i];const u=f=>{var x;const{scope:p,children:m,...w}=f,b=((x=p==null?void 0:p[e])==null?void 0:x[c])||a,g=h.useMemo(()=>w,Object.values(w));return l.jsx(b.Provider,{value:g,children:m})};u.displayName=s+"Provider";function d(f,p){var b;const m=((b=p==null?void 0:p[e])==null?void 0:b[c])||a,w=h.useContext(m);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=>h.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return h.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,nb(o,...t)]}function nb(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:c,scopeName:u})=>{const f=c(s)[`__scope${u}`];return{...a,...f}},{});return h.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var lt=globalThis!=null&&globalThis.document?h.useLayoutEffect:()=>{},rb=h[" useInsertionEffect ".trim().toString()]||lt;function wn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ob({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const d=h.useRef(e!==void 0);h.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=h.useCallback(d=>{var f;if(a){const p=sb(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[c,u]}function ob({defaultProp:e,onChange:t}){const[n,r]=h.useState(e),o=h.useRef(n),s=h.useRef(t);return rb(()=>{s.current=t},[t]),h.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function sb(e){return typeof e=="function"}function Bc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function wi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Bc(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():Bc(e[o],null)}}}}function Re(...e){return h.useCallback(wi(...e),e)}var ib=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=ib.reduce((e,t)=>{const n=Et.createSlot(`Primitive.${t}`),r=h.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),l.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Hc(e,t){e&&eo.flushSync(()=>e.dispatchEvent(t))}function ab(e,t){return h.useReducer((n,r)=>t[n][r]??n,e)}var Tt=e=>{const{present:t,children:n}=e,r=lb(t),o=typeof n=="function"?n({present:r.isPresent}):h.Children.only(n),s=Re(r.ref,cb(o));return typeof n=="function"||r.isPresent?h.cloneElement(o,{ref:s}):null};Tt.displayName="Presence";function lb(e){const[t,n]=h.useState(),r=h.useRef(null),o=h.useRef(e),s=h.useRef("none"),i=e?"mounted":"unmounted",[a,c]=ab(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return h.useEffect(()=>{const u=Io(r.current);s.current=a==="mounted"?u:"none"},[a]),lt(()=>{const u=r.current,d=o.current;if(d!==e){const p=s.current,m=Io(u);e?c("MOUNT"):m==="none"||(u==null?void 0:u.display)==="none"?c("UNMOUNT"):c(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),lt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=m=>{const b=Io(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&b&&(c("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},p=m=>{m.target===t&&(s.current=Io(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:h.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Io(e){return(e==null?void 0:e.animationName)||"none"}function cb(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 ub=h[" useId ".trim().toString()]||(()=>{}),db=0;function Kt(e){const[t,n]=h.useState(ub());return lt(()=>{n(r=>r??String(db++))},[e]),e||(t?`radix-${t}`:"")}var No="Collapsible",[fb,GT]=Vt(No),[hb,yi]=fb(No),Uc=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,u]=wn({prop:r,defaultProp:o??!1,onChange:i,caller:No});return l.jsx(hb,{scope:n,disabled:s,contentId:Kt(),open:c,onOpenToggle:h.useCallback(()=>u(d=>!d),[u]),children:l.jsx(Se.div,{"data-state":Ci(c),"data-disabled":s?"":void 0,...a,ref:t})})});Uc.displayName=No;var Wc="CollapsibleTrigger",Vc=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=yi(Wc,n);return l.jsx(Se.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ci(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:te(e.onClick,o.onOpenToggle)})});Vc.displayName=Wc;var Si="CollapsibleContent",pb=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yi(Si,e.__scopeCollapsible);return l.jsx(Tt,{present:n||o.open,children:({present:s})=>l.jsx(mb,{...r,ref:t,present:s})})});pb.displayName=Si;var mb=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=yi(Si,n),[a,c]=h.useState(r),u=h.useRef(null),d=Re(t,u),f=h.useRef(0),p=f.current,m=h.useRef(0),w=m.current,b=i.open||a,g=h.useRef(b),x=h.useRef(void 0);return h.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),lt(()=>{const v=u.current;if(v){x.current=x.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const y=v.getBoundingClientRect();f.current=y.height,m.current=y.width,g.current||(v.style.transitionDuration=x.current.transitionDuration,v.style.animationName=x.current.animationName),c(r)}},[i.open,r]),l.jsx(Se.div,{"data-state":Ci(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!b,...s,ref:d,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:b&&o})});function Ci(e){return e?"open":"closed"}var gb=Uc;const Kc=gb,qc=Vc;function Gc(){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 Ln=Gc();function xb(e){Ln=e}const Yc=/[&<>"']/,bb=new RegExp(Yc.source,"g"),Xc=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,vb=new RegExp(Xc.source,"g"),wb={"&":"&","<":"<",">":">",'"':""","'":"'"},Jc=e=>wb[e];function gt(e,t){if(t){if(Yc.test(e))return e.replace(bb,Jc)}else if(Xc.test(e))return e.replace(vb,Jc);return e}const yb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zc(e){return e.replace(yb,(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 Sb=/(^|[^\[])\^/g;function Ke(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Sb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Cb=/[^\w:]/g,Tb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qc(e,t,n){if(e){let r;try{r=decodeURIComponent(Zc(n)).replace(Cb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Tb.test(n)&&(n=Nb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const jo={},kb=/^[^:]+:\/*[^/]*$/,Eb=/^([^:]+:)[\s\S]*$/,Ib=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Nb(e,t){jo[" "+e]||(kb.test(e)?jo[" "+e]=e+"/":jo[" "+e]=Ro(e,"/",!0)),e=jo[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Eb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Ib,"$1")+t:e+t}const Ao={exec:function(){}};function eu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,u=i;for(;--u>=0&&a[u]==="\\";)c=!c;return c?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ro(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 jb(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 Ab(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 tu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function nu(e,t,n,r){const o=t.href,s=t.title?gt(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:gt(i)}}function Rb(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 Ti{constructor(t){this.options=t||Ln}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:Ro(r,`
|
|
41
41
|
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Rb(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=Ro(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,c,u,d,f,p,m,w,b=n[1].trim();const g=b.length>1,x={type:"list",raw:"",ordered:g,start:g?+b.slice(0,-1):"",loose:!1,items:[]};b=g?`\\d{1,9}\\${b.slice(-1)}`:`\\${b}`,this.options.pedantic&&(b=g?b:"[*+-]");const v=new RegExp(`^( {0,3}${b})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=v.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
package/package.json
CHANGED