teodor-new-chat-ui 3.0.152 → 3.0.153
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 +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3104,7 +3104,7 @@ function bo({ children: e, apiConfig: t, onError: n, onThreadChange: r, initialT
|
|
|
3104
3104
|
console.warn(`[ChatProvider] Thread load cancelled - another thread (${se.current}) is loading`);
|
|
3105
3105
|
return;
|
|
3106
3106
|
}
|
|
3107
|
-
Ie.current !== null && Ie.current !== L && (console.log(`[ChatProvider] Thread switch detected: ${Ie.current} -> ${L}`),
|
|
3107
|
+
Ie.current !== null && Ie.current !== L && (console.log(`[ChatProvider] Thread switch detected: ${Ie.current} -> ${L}`), C([])), se.current = L, Ie.current = L;
|
|
3108
3108
|
try {
|
|
3109
3109
|
J({
|
|
3110
3110
|
cursor: null,
|
package/dist/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
35
35
|
`+i):r.stack=i}catch{}}throw r}}_request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=Fn(this.defaults,n);const{transitional:r,paramsSerializer:a,headers:i}=n;r!==void 0&&Oa.assertOptions(r,{silentJSONParsing:tn.transitional(tn.boolean),forcedJSONParsing:tn.transitional(tn.boolean),clarifyTimeoutError:tn.transitional(tn.boolean)},!1),a!=null&&(G.isFunction(a)?n.paramsSerializer={serialize:a}:Oa.assertOptions(a,{encode:tn.function,serialize:tn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Oa.assertOptions(n,{baseUrl:tn.spelling("baseURL"),withXsrfToken:tn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=i&&G.merge(i.common,i[n.method]);i&&G.forEach(["delete","get","head","post","put","patch","common"],E=>{delete i[E]}),n.headers=It.concat(o,i);const s=[];let l=!0;this.interceptors.request.forEach(function(f){typeof f.runWhen=="function"&&f.runWhen(n)===!1||(l=l&&f.synchronous,s.unshift(f.fulfilled,f.rejected))});const c=[];this.interceptors.response.forEach(function(f){c.push(f.fulfilled,f.rejected)});let d,_=0,p;if(!l){const E=[U_.bind(this),void 0];for(E.unshift(...s),E.push(...c),p=E.length,d=Promise.resolve(n);_<p;)d=d.then(E[_++],E[_++]);return d}p=s.length;let m=n;for(;_<p;){const E=s[_++],f=s[_++];try{m=E(m)}catch(g){f.call(this,g);break}}try{d=U_.call(this,m)}catch(E){return Promise.reject(E)}for(_=0,p=c.length;_<p;)d=d.then(c[_++],c[_++]);return d}getUri(e){e=Fn(this.defaults,e);const n=O_(e.baseURL,e.url,e.allowAbsoluteUrls);return f_(n,e.params,e.paramsSerializer)}};G.forEach(["delete","get","head","options"],function(e){Bn.prototype[e]=function(n,r){return this.request(Fn(r||{},{method:e,url:n,data:(r||{}).data}))}}),G.forEach(["post","put","patch"],function(e){function n(r){return function(i,o,s){return this.request(Fn(s||{},{method:e,headers:r?{"Content-Type":"multipart/form-data"}:{},url:i,data:o}))}}Bn.prototype[e]=n(),Bn.prototype[e+"Form"]=n(!0)});let Av=class aR{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(i){n=i});const r=this;this.promise.then(a=>{if(!r._listeners)return;let i=r._listeners.length;for(;i-- >0;)r._listeners[i](a);r._listeners=null}),this.promise.then=a=>{let i;const o=new Promise(s=>{r.subscribe(s),i=s}).then(a);return o.cancel=function(){r.unsubscribe(i)},o},e(function(i,o,s){r.reason||(r.reason=new ir(i,o,s),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const e=new AbortController,n=r=>{e.abort(r)};return this.subscribe(n),e.signal.unsubscribe=()=>this.unsubscribe(n),e.signal}static source(){let e;return{token:new aR(function(a){e=a}),cancel:e}}};function xv(t){return function(n){return t.apply(null,n)}}function Dv(t){return G.isObject(t)&&t.isAxiosError===!0}const Eo={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(Eo).forEach(([t,e])=>{Eo[e]=t});function G_(t){const e=new Bn(t),n=n_(Bn.prototype.request,e);return G.extend(n,Bn.prototype,e,{allOwnKeys:!0}),G.extend(n,e,null,{allOwnKeys:!0}),n.create=function(a){return G_(Fn(t,a))},n}const st=G_(Mr);st.Axios=Bn,st.CanceledError=ir,st.CancelToken=Av,st.isCancel=C_,st.VERSION=F_,st.toFormData=ha,st.AxiosError=Ue,st.Cancel=st.CanceledError,st.all=function(e){return Promise.all(e)},st.spread=xv,st.isAxiosError=Dv,st.mergeConfig=Fn,st.AxiosHeaders=It,st.formToJSON=t=>T_(G.isHTMLForm(t)?new FormData(t):t),st.getAdapter=k_.getAdapter,st.HttpStatusCode=Eo,st.default=st;const{Axios:k0,AxiosError:U0,CanceledError:F0,isCancel:B0,CancelToken:G0,VERSION:Y0,all:H0,Cancel:q0,isAxiosError:V0,spread:z0,toFormData:$0,AxiosHeaders:W0,HttpStatusCode:K0,formToJSON:Q0,getAdapter:j0,mergeConfig:X0}=st,Y_=typeof window<"u"?window.__API_BASE_URL__:void 0,fo=Y_?Y_.replace(/\/+$/,""):void 0;!fo&&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 ya=null;const So=new Set;function H_(){return ya}function bo(t){ya=t,So.forEach(e=>e(t))}function q_(t){return So.add(t),()=>So.delete(t)}const Ut=st.create({...fo?{baseURL:fo}:{},timeout:3e4,withCredentials:!0});Ut.interceptors.request.use(t=>(ya&&(t.headers.Authorization=`Bearer ${ya}`),t)),Ut.interceptors.response.use(t=>t,t=>Promise.reject(t));async function Ft(t,e){return Ut.defaults.baseURL?(await Ut.get(t,e)).data:Promise.reject(new Error("API base URL is not configured"))}async function V_(t,e,n){return Ut.defaults.baseURL?(await Ut.post(t,e,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function z_(t,e,n){return Ut.defaults.baseURL?(await Ut.put(t,e,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $_(t,e){return Ut.defaults.baseURL?(await Ut.delete(t,e)).data:Promise.reject(new Error("API base URL is not configured"))}function Bt(t){return t&&typeof t=="object"&&"data"in t?t.data:t}class Ia{get baseUrl(){const e=Ut.defaults.baseURL||"";return String(e).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(e){e.baseUrl&&(Ut.defaults.baseURL=String(e.baseUrl).replace(/\/+$/g,"")),e.authToken!==void 0&&bo(e.authToken)}getAuthToken(){return H_()}setAuthToken(e){bo(e)}onTokenChange(e){return q_(e)}async listThreads(){const e=await Ft("/chat/threads"),n=Bt(e);return(n==null?void 0:n.items)??(e==null?void 0:e.items)??[]}async createThread(e){const r=await V_("/chat/threads",e?{title:e}:void 0);return Bt(r)}async updateThread(e,n){const r=await z_(`/chat/threads/${e}`,{title:n});return Bt(r)}async deleteThread(e){const n=await $_(`/chat/threads/${e}`);return Bt(n)}async threadInfo(e){const n=await Ft(`/chat/threads/${e}/info`);return Bt(n)}async listAgents(){const e=await Ft("/chat/agents"),n=Bt(e);return(n==null?void 0:n.items)??[]}async getAgent(e){const n=await Ft(`/chat/agents/${e}`);return Bt(n)}async getAgentSchema(e){const n=await Ft(`/chat/agents/${e}/schema`);return Bt(n)}async getMessages(e){const n=await Ft(`/chat/threads/${e.threadId}/messages`,{params:{thread_id:e.threadId,checkpoint_id:e.checkpointId,checkpoint_ns:e.checkpointNs,limit:e.limit,before_id:e.beforeId??void 0}});return Bt(n)}async getState(e){const n=await Ft(`/chat/threads/${e.threadId}/state`,{params:{thread_id:e.threadId,checkpoint_id:e.checkpointId,checkpoint_ns:e.checkpointNs}});return Bt(n)}async getStateHistory(e){const n=await Ft(`/chat/threads/${e.threadId}/state/history`,{params:{thread_id:e.threadId,checkpoint_id:e.checkpointId,checkpoint_ns:e.checkpointNs}});return Bt(n)}async listCheckpoints(e){const n=await Ft(`/chat/threads/${e}/checkpoints`,{params:{thread_id:e}});return Bt(n)}}const gn=new Ia;function W_(t={}){const e=t.baseUrl??"/api/chat",n=t.streamPath??"/runs/stream",[r,a]=y.useState(t.token??null),i=y.useRef(t.headers??{}),[o,s]=y.useState(!1),[l,c]=y.useState(null),[d,_]=y.useState(""),[p,m]=y.useState(null),[E,f]=y.useState(0),[g,S]=y.useState(!1),b=y.useRef(null),h=y.useRef(0),v=y.useCallback(O=>{a(O)},[]),C=y.useCallback(()=>{var O;(O=b.current)==null||O.abort(),b.current=null,s(!1)},[]),R=y.useCallback(()=>{_(""),m(null),c(null)},[]),N=y.useCallback((O,I,x)=>{b.current&&(b.current.abort(),b.current=null),s(!0),c(null),t.autoAppendAssistant!==!1&&_("");const M=new AbortController;return b.current=M,(async()=>{var U,W,D,B,L,k,Q;const Y=(()=>{var $;try{return typeof window<"u"&&(($=window.localStorage)==null?void 0:$.getItem("chat-debug"))==="1"}catch{return!1}})(),z=$=>{var J;try{const q=JSON.parse(JSON.stringify($));return(J=q==null?void 0:q.payload)!=null&&J.files_info&&Array.isArray(q.payload.files_info)&&(q.payload.files_info=q.payload.files_info.map(X=>({...X,data:X!=null&&X.data?`<base64 ${String(X.data).length} chars>`:X==null?void 0:X.data}))),q}catch{return $}};try{let $={};try{if(r)$={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const ye=window.__AUTH_TOKEN__,fe=((U=window.localStorage)==null?void 0:U.getItem("authToken"))||null;let Le=null;try{const he=(W=window.localStorage)==null?void 0:W.getItem("chat-settings");he&&(Le=((D=JSON.parse(he))==null?void 0:D.apiKey)||null)}catch{}const ce=ye||fe||Le||null;ce&&($={Authorization:`Bearer ${ce}`})}}catch{}Y&&console.debug("[use-chat] POST",e+n,z(O));const J=await fetch(e+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...$,...i.current},body:JSON.stringify(O),signal:M.signal});if(!J.ok||!J.body){const be=await J.text().catch(()=>"");throw Y&&console.debug("[use-chat] non-OK response",J.status,be==null?void 0:be.slice(0,500)),new Error(`stream ${J.status}${be?": "+be:""}`)}S(!0);let q=J.body.getReader(),X=new TextDecoder,re="",le="",H=h.current,P=null;const j=()=>{le&&(_(be=>be+le),le=""),P=null},ne=()=>{P==null&&(P=requestAnimationFrame(j))};let oe=Date.now();const ie=setInterval(()=>{var be;if(Date.now()-oe>2e4){const ye="Stream idle timeout";c(ye),M.abort(),(be=x==null?void 0:x.onError)==null||be.call(x,ye)}},5e3),Oe=1024*1024;try{const be=J.headers.get("X-Thread-Id")||J.headers.get("x-thread-id"),ye=J.headers.get("X-Thread-Created")||J.headers.get("x-thread-created"),fe=be??null,Le=String(ye??"").toLowerCase()==="true";for((B=x==null?void 0:x.onOpen)==null||B.call(x,{threadId:fe,created:Le});;){const{value:ce,done:he}=await q.read();if(he)break;re+=X.decode(ce,{stream:!0}),re.length>Oe&&(re="",console.warn("Stream buffer reset: exceeded 1MB"));let Re;for(;(Re=re.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const Ce=re.slice(0,Re);re=re.slice(Re+2);const We=Mv(Ce);if(!We)continue;let ze;try{ze=JSON.parse(We)}catch{Y&&console.debug("[use-chat] malformed SSE:",We.slice(0,200));continue}const Ke=wv(ze)?ze.data:ze;oe=Date.now(),I==null||I(Ke);const V=Ke.seq;if(V!==void 0){if(V<=H)continue;H>0&&V>H+1&&((L=x==null?void 0:x.onGap)==null||L.call(x,{from:H,to:V})),H=V,h.current=V,f(V)}if(Ke.type==="token"&&t.autoAppendAssistant!==!1)le+=Ke.content,ne();else if(Ke.type==="message_delta"){const F=Ke.delta.filter(te=>te.type==="text").map(te=>te.text).join("");F&&t.autoAppendAssistant!==!1&&(le+=F,ne())}else P!==null&&cancelAnimationFrame(P),j(),Ke.type==="checkpoint"?m(Ke.checkpointId):Ke.type==="error"&&c(Ke.message)}}j()}catch(be){if(be.name!=="AbortError"){const ye=be.message||String(be);c(ye),(k=x==null?void 0:x.onError)==null||k.call(x,ye)}}finally{q.cancel(),q.releaseLock&&q.releaseLock(),P!==null&&cancelAnimationFrame(P),clearInterval(ie),s(!1),S(!1),b.current=null}}catch($){if($.name!=="AbortError"){const J=$.message||String($);c(J),(Q=x==null?void 0:x.onError)==null||Q.call(x,J)}}finally{s(!1),S(!1),b.current=null}})(),{close:()=>M.abort()}},[e,r,t.autoAppendAssistant]);return y.useEffect(()=>()=>{var O;return(O=b.current)==null?void 0:O.abort()},[]),{isStreaming:o,error:l,assistantText:d,lastCheckpointId:p,lastSeq:E,connected:g,stream:N,stop:C,clear:R,setToken:v}}function wv(t){return!!t&&typeof t=="object"&&t.protocolVersion==="v1"&&"data"in t}function Mv(t){const e=t.split(/\r?\n/),n=[];for(const r of e)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const a=r.slice(5);n.push(a.startsWith(" ")?a.slice(1):a)}return n.length===0?null:n.join(`
|
|
38
|
-
`)}const Lv={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Pv(t,e){var n;switch(e.type){case"reset":return{messages:To(((n=e.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};case"seed":{const r=To(e.payload.messages),a={...t,messages:[...r,...t.messages],assemblingId:null};return Object.prototype.hasOwnProperty.call(e.payload,"checkpointId")&&(a.lastCheckpointId=e.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(e.payload,"checkpointNs")&&(a.lastCheckpointNs=e.payload.checkpointNs??null),console.log("[MessageReducer] seed action:",{incomingCount:e.payload.messages.length,sanitizedCount:r.length,checkpointId:a.lastCheckpointId}),a}case"prepend":{const r=To(e.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),t;const a=new Set(t.messages.map(o=>o.id)),i=r.filter(o=>!a.has(o.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:i.length,duplicates:r.length-i.length,finalTotal:i.length+t.messages.length}),i.length?{...t,messages:[...i,...t.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),t)}case"user_message":{const r=e.payload.message;if(t.assemblingId){const a=t.messages.findIndex(i=>i.id===t.assemblingId);if(a!==-1)return{...t,messages:[...t.messages.slice(0,a),r,...t.messages.slice(a)]}}return{...t,messages:[...t.messages,r]}}case"event":return Q_(t,e.payload.ev);case"batch":{const{events:r}=e.payload;return r.length?r.reduce((a,i)=>Q_(a,i),t):t}default:return t}}function K_(t=[]){const[e,n]=y.useReducer(Pv,{...Lv,messages:t}),r=y.useRef([]),a=y.useRef(null),i=y.useRef(null),o=y.useCallback(()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),a.current=null,i.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),s=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?a.current===null&&(a.current=window.requestAnimationFrame(()=>o())):i.current===null&&(i.current=setTimeout(o,8))},[o]),l=y.useCallback(d=>{r.current.push(d),s()},[s]);y.useEffect(()=>()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),r.current=[]},[]);const c=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,_)=>n({type:"seed",payload:{messages:d,..._??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:e,dispatch:n,...c}}function Q_(t,e){var n;if(e.type==="message_start"&&e.role==="assistant"){const r=e.id,a=Gv(e.model),i={id:r,role:"assistant",name:a||void 0,model:e.model,createdAt:new Date().toISOString(),content:[]};return{...t,assemblingId:r,messages:[...t.messages,i]}}if(e.type==="token"){const r=t.assemblingId??ho(t.messages);return r?{...t,messages:Uv(t.messages,r,e.content)}:t}if(e.type==="message_delta"){const r=t.assemblingId??ho(t.messages);return r?{...t,messages:j_(t.messages,r,e.delta)}:t}if(e.type==="message_end"){const r=t.assemblingId??ho(t.messages);if(!r)return{...t,assemblingId:null};const a=t.messages,i=a.findIndex(o=>o.id===r&&o.role==="assistant");if(i>=0&&!((n=a[i].content)==null?void 0:n.some(l=>{var c;return(l==null?void 0:l.type)==="text"&&((c=l.text)==null?void 0:c.trim())}))){const l=[...a.slice(0,i),...a.slice(i+1)];return{...t,assemblingId:null,messages:l}}return t}if(e.type==="tool_start"){const r=`tool-${e.id}`,a={type:"tool_call",id:e.id,name:e.name,args:e.args},i={id:r,role:"tool",name:e.name,createdAt:new Date().toISOString(),content:[a]};return{...t,messages:[...t.messages,i],toolIndex:{...t.toolIndex,[e.id]:r}}}if(e.type==="tool_result"){const r=t.toolIndex[e.id]??`tool-${e.id}`,a={type:"tool_result",toolCallId:e.id,output:e.output,error:e.error},i=t.messages.find(l=>l.id===r),o={id:r,role:"tool",content:[a],createdAt:new Date().toISOString()},s=i?j_(t.messages,r,[a]):[...t.messages,o];return{...t,messages:s}}if(e.type==="checkpoint"){const r=e.checkpointNs??t.lastCheckpointNs??null,a=Bv(t.messages,e.checkpointId,r);return{...t,lastCheckpointId:e.checkpointId,lastCheckpointNs:r,messages:a}}if(e.type==="branch"){const r=e.checkpointId??t.lastCheckpointId,a=e.checkpointNs??t.lastCheckpointNs;return{...t,lastBranch:e,lastCheckpointId:r??null,lastCheckpointNs:a??null}}if(e.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${e.message}`}],createdAt:new Date().toISOString()};return{...t,messages:[...t.messages,r]}}return t}function To(t){return t.filter(e=>{if(e.role!=="assistant")return!0;const n=(e.content||[]).some(a=>{var i;return a&&a.type==="text"&&((i=a.text)==null?void 0:i.trim())}),r=(e.content||[]).some(a=>a&&a.type==="image_url");return!!(n||r)})}function kv(t,e,n){return e<0||e>=t.length?t:[...t.slice(0,e),n,...t.slice(e+1)]}function ho(t){for(let e=t.length-1;e>=0;e--)if(t[e].role==="assistant")return t[e].id;return null}function Uv(t,e,n){return t.map(r=>{if(r.id!==e)return r;const a=r.content.slice(),i=a[a.length-1];return i&&i.type==="text"?i.text+=n:a.push({type:"text",text:n}),{...r,content:a}})}function j_(t,e,n){return t.map(r=>r.id===e?{...r,content:Fv(r.content,n)}:r)}function Fv(t,e){const n=t.slice();for(const r of e)if(r.type==="text"){const a=n[n.length-1];(a==null?void 0:a.type)==="text"?a.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Bv(t,e,n){for(let r=t.length-1;r>=0;r--)if(t[r].role==="assistant"){const i={...t[r],checkpointId:e,checkpointNs:n??void 0};return kv(t,r,i)}return t}function Gv(t){if(!t)return null;const e=t.split("/");return e[e.length-1]||null}function Yv(t,e){const n=t==null?void 0:t.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],a=o=>o&&typeof o=="object"&&typeof o.checkpointId=="string"&&typeof o.createdAt=="string",i=r.filter(a).map(o=>({checkpointId:o.checkpointId,checkpointNs:o.checkpointNs??"",createdAt:o.createdAt,messagesLen:o.messagesLen??0,preview:o.preview??"",role:o.role??null,parentId:o.parentId??null,editedMessageId:o.editedMessageId??null,branchLabel:o.branchLabel??null,lastMessageId:o.lastMessageId??null,hasMessages:typeof o.hasMessages=="boolean"?o.hasMessages:void 0}));return{threadId:(t==null?void 0:t.threadId)??e??null,checkpoints:i}}async function Hv(t){return await new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{try{const a=r.result,i=new Uint8Array(a);let o="";const s=i.byteLength;for(let l=0;l<s;l++)o+=String.fromCharCode(i[l]);e(btoa(o))}catch(a){n(a)}},r.onerror=a=>n(a),r.readAsArrayBuffer(t)})}async function qv(t,e=[],n,r,a,i){const o=[],s=[];for(const l of e)try{const c=await Hv(l);s.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:o,filesInfo:s}}const X_=y.createContext(null);function Pr({children:t,apiConfig:e,onError:n,onThreadChange:r,initialThreadId:a=null,autoLoadInitial:i=!0,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader"}){const l=gn;y.useEffect(()=>{e&&l.updateConfig({baseUrl:e.baseUrl,authToken:e.apiKey})},[l,e]);const{isStreaming:c,error:d,stream:_,stop:p,setToken:m}=W_({baseUrl:l.baseUrl,token:null,headers:e==null?void 0:e.headers,streamPath:"/chat/runs/stream"}),[E,f]=y.useState(()=>typeof l.getAuthToken=="function"?l.getAuthToken():null);y.useEffect(()=>{m(typeof l.getAuthToken=="function"?l.getAuthToken():null);const V=l.onTokenChange(F=>{f(F),m(F)});return()=>{V()}},[l,m]);const g=y.useCallback(V=>{l.setAuthToken(V)},[l]),{state:S,seed:b,prepend:h,pushUser:v,onEvent:C,reset:R}=K_(),N=20,[O,I]=y.useState(!1),[x,M]=y.useState(!1),[Y,z]=y.useState(null),[U,W]=y.useState(void 0),[D,B]=y.useState(void 0),L=y.useRef(!1),k=y.useRef([]),Q=y.useCallback(V=>{V.cursor!==void 0&&z(V.cursor),V.hasMore!==void 0&&I(V.hasMore),V.checkpointId!==void 0&&W(V.checkpointId),V.checkpointNs!==void 0&&B(V.checkpointNs)},[]),$=y.useCallback((V,F)=>new Promise((te,Se)=>{const se=async()=>{if(L.current){console.warn(`[ChatProvider] Operation "${F}" queued - another operation in progress`),k.current.push(se);return}L.current=!0;try{console.log(`[ChatProvider] Executing operation: ${F}`),await V(),te()}catch(we){console.error(`[ChatProvider] Operation "${F}" failed:`,we),Se(we)}finally{L.current=!1;const we=k.current.shift();we&&we().catch(()=>{})}};L.current?(k.current.push(se),console.log(`[ChatProvider] Queued operation: ${F}`)):se().catch(we=>{Se(we)})}),[]),J=y.useCallback((V,F)=>{const te=Array.isArray(V==null?void 0:V.messages)?V.messages:[];F==="replace"?(console.log("[ChatProvider] Replacing messages, count:",te.length),b(te,{checkpointId:(V==null?void 0:V.checkpointId)??null,checkpointNs:(V==null?void 0:V.checkpointNs)??null})):F==="prepend"&&te.length?(console.log("[ChatProvider] Calling prepend with",te.length,"messages"),h(te)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),z((V==null?void 0:V.nextCursor)??null),I(!!(V!=null&&V.hasMore)),W(Se=>(V==null?void 0:V.checkpointId)??Se??void 0),B(Se=>(V==null?void 0:V.checkpointNs)??Se??void 0)},[b,h]),[q,X]=y.useState([]),[re,le]=y.useState(null),H=y.useCallback(async()=>{const V=await l.listThreads();X(V)},[l]),[P,j]=y.useState(!1),ne=y.useCallback(async V=>{const F=(V==null?void 0:V.maxAttempts)??5,te=(V==null?void 0:V.baseDelayMs)??500,Se=(V==null?void 0:V.timeoutMs)??2e3;if(!l.baseUrl)return!1;const se=l.baseUrl.replace(/\/+$/,""),we=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],Ze=async ct=>{try{const Tt=new AbortController,_t=setTimeout(()=>Tt.abort(),Se),ht=await fetch(ct,{method:"GET",signal:Tt.signal});return clearTimeout(_t),ht.ok}catch{return!1}},Nt=async ct=>{try{const Tt=new AbortController,_t=setTimeout(()=>Tt.abort(),Se),ht=await fetch(ct,{method:"HEAD",signal:Tt.signal});return clearTimeout(_t),ht.ok}catch{return!1}};for(let ct=0;ct<F;ct++){console.debug(`[ChatProvider] health-check attempt ${ct+1}/${F}`);for(const _t of we){let ht=_t;se.endsWith("/api")&&_t.startsWith("/api")&&(ht=_t.replace(/^\/api/,"")||"/");const en=ht==="/"?se+"/":se+ht;if(console.debug(`[ChatProvider] checking ${en}`),await Ze(en)||_t==="/"&&await Nt(se+"/"))return j(!0),!0}const Tt=te*Math.pow(2,ct);await new Promise(_t=>setTimeout(_t,Tt))}return j(!1),!1},[l.baseUrl]);y.useEffect(()=>{let V=!0;if(!l.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const F=await ne();if(!V)return;F?H().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{V=!1}},[H,l.baseUrl,ne]),y.useEffect(()=>{r==null||r(re)},[re,r]);const oe=y.useRef(null);y.useEffect(()=>{if(a&&i){if(!l.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!P){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}oe.current!==a&&(oe.current=a,be(a).catch(()=>{}))}},[a,i,l.baseUrl,P]);const ie=y.useRef(null),Oe=y.useRef(null),be=y.useCallback(async(V,F,te)=>{await $(async()=>{if(!l.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(ie.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${ie.current}) is loading`);return}Oe.current!==null&&Oe.current!==V&&(console.log(`[ChatProvider] Thread switch detected: ${Oe.current} -> ${V}`),b([],{checkpointId:null,checkpointNs:null})),ie.current=V,Oe.current=V;try{Q({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),le(V);const se=await l.getMessages({threadId:V,checkpointId:F,checkpointNs:te,limit:N}),we=Array.isArray(se==null?void 0:se.messages)?se.messages:[];console.log("[ChatProvider] Loading thread with",we.length,"messages"),b(we,{checkpointId:(se==null?void 0:se.checkpointId)??null,checkpointNs:(se==null?void 0:se.checkpointNs)??null}),z((se==null?void 0:se.nextCursor)??null),I(!!(se!=null&&se.hasMore)),W(Ze=>(se==null?void 0:se.checkpointId)??Ze??void 0),B(Ze=>(se==null?void 0:se.checkpointNs)??Ze??void 0)}finally{ie.current=null}},`loadThread-${V}`)},[l,$,Q,b]),ye=y.useCallback(async V=>{const F=await l.listCheckpoints(V);return Yv(F,V)},[l]),fe=y.useCallback(async(V,F)=>{await $(async()=>{if(!re)throw new Error("No active thread");Q({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0});const te=await l.getMessages({threadId:re,checkpointId:V,checkpointNs:F??void 0,limit:N});J(te,"replace")},`navigateToCheckpoint-${V}`)},[l,re,J,$,Q]),Le=y.useCallback(async()=>{if(!re)throw new Error("No active thread");await be(re)},[re,be]),ce=y.useRef(!1);y.useEffect(()=>{const V=ce.current;ce.current=c,V&&!c&&re&&$(async()=>{try{await H()}catch(F){console.warn("[ChatProvider] Post-streaming thread refresh failed:",F)}},"postStreamingRefresh")},[c,re,l,J,H,$]);const he=y.useCallback(async V=>{const F=await l.createThread(V);return await H(),await be(F.threadId),F.threadId},[l,H,be]),Re=y.useCallback(async V=>{await l.deleteThread(V),await H(),re===V&&(le(null),R([]),I(!1),z(null),W(void 0),B(void 0))},[l,H,re,R]),Ce=y.useCallback(async(V,F)=>{await l.updateThread(V,F),await H()},[l,H]),We=y.useCallback(async(V,F)=>{await $(async()=>{var pn;const te=(F==null?void 0:F.attachments)||[],{contentParts:Se,filesInfo:se}=await qv(l,te,e==null?void 0:e.uploadPath),we=[];V&&V.trim()&&we.push({type:"text",text:V.trim()});const Ze={id:((pn=crypto.randomUUID)==null?void 0:pn.call(crypto))||`user-${Date.now()}`,role:"user",content:we,createdAt:new Date().toISOString(),checkpointId:(F==null?void 0:F.checkpointId)??S.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??S.lastCheckpointNs??void 0};v(Ze);const Nt={...Ze,content:we},ct={...(F==null?void 0:F.payloadExtras)??{}},Tt=!!ct.edit,_t=ct.originalMessageId,ht=typeof _t=="string"?_t:void 0,en=te&&te.length>0,_n={...re?{threadId:re}:{},payload:{messages:[Nt],files_info:se,...o&&en&&s?{active_agent:s}:{},...ct},checkpointId:(F==null?void 0:F.checkpointId)??S.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??S.lastCheckpointNs??void 0,nodeFilter:F==null?void 0:F.nodeFilter,config:F==null?void 0:F.config,edit:Tt,originalMessageId:ht};_(_n,ke=>C(ke),{onError:ke=>console.warn("stream error",ke),onOpen:({threadId:ke,created:ue})=>{!re&&ke&&(le(ke),ue&&H().catch(()=>{}))}})},"send")},[re,v,_,C,S.lastCheckpointId,S.lastCheckpointNs,l,e==null?void 0:e.uploadPath,H,le,o,s,$]),ze=y.useCallback(async V=>{if(!re)throw new Error("No active thread");if(x||!O)return;const F=Y;if(F){M(!0);try{const te=await l.getMessages({threadId:re,checkpointId:U,checkpointNs:D,limit:(V==null?void 0:V.limit)??N,beforeId:F});J(te,"prepend")}finally{M(!1)}}},[l,re,U,D,Y,O,x,J,N]),Ke={baseUrl:l.baseUrl,token:E,setToken:g,api:l,threads:q,currentThreadId:re,setCurrentThreadId:le,messages:S.messages,isStreaming:c,error:d,lastCheckpointId:S.lastCheckpointId,lastCheckpointNs:S.lastCheckpointNs,streamingAssistantId:S.assemblingId,hasMoreHistory:O,isLoadingHistory:x,loadOlderMessages:ze,historyPageSize:N,listCheckpoints:ye,navigateToCheckpoint:fe,returnToLatest:Le,refreshThreads:H,createThread:he,deleteThread:Re,renameThread:Ce,loadThread:be,send:We,stop:p};return u.jsx(X_.Provider,{value:Ke,children:t})}function Aa(){const t=y.useContext(X_);if(!t)throw new Error("useChat must be used within ChatProvider");return t}function K(...t){return oR.twMerge(iR.clsx(t))}const Vv=yr.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"}}),Qe=T.forwardRef(({className:t,variant:e,size:n,asChild:r=!1,...a},i)=>{const o=r?Dt.Slot:"button";return u.jsx(o,{className:K(Vv({variant:e,size:n,className:t})),ref:i,...a})});Qe.displayName="Button";const Z_=T.forwardRef(({className:t,...e},n)=>u.jsx("textarea",{className:K("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",t),ref:n,...e}));Z_.displayName="Textarea";function zv({initialValue:t="",editingMessageId:e=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:a=!1,maxLength:i=2e4,onSend:o,onCancelEdit:s,onStop:l,className:c="",textareaClassName:d="",allowEmptySend:_=!1}){const[p,m]=y.useState(t),[E,f]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(t??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[t,e]);const S=y.useCallback(()=>{const O=g.current;O&&(O.style.height="auto",O.style.height=`${O.scrollHeight}px`)},[]);y.useEffect(()=>{S()},[S]);const b=y.useCallback(async O=>{O&&O.preventDefault();const I=(p??"").trim();!I&&!_||f(()=>{try{const x=o(I);x&&typeof x.then=="function"?x.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[p,o,_]),h=y.useCallback(O=>{m(O.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),v=y.useCallback(O=>{O.key==="Enter"&&!O.shiftKey?(O.preventDefault(),b()):O.key==="Escape"&&e&&(O.preventDefault(),s==null||s())},[b,e,s]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${e?"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 u.jsx("form",{onSubmit:O=>void b(O),className:`w-full ${c}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(Z_,{ref:g,value:p,onChange:h,onKeyDown:v,placeholder:e?"Edit your message...":n,className:N,disabled:a,maxLength:i,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Qe,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:a||!l,children:u.jsx(pe.Square,{size:16})}):u.jsx(Qe,{type:"submit",size:"icon",className:"shrink-0",title:e?"Save changes":"Send message",disabled:a||!p.trim()&&!_||E,children:u.jsx(pe.Send,{size:16})})})]})})}const $v=y.memo(zv),xa=0,Cn=1,or=2,J_=4;function ep(t){return()=>t}function Wv(t){t()}function tp(t,e){return n=>t(e(n))}function np(t,e){return()=>t(e)}function Kv(t,e){return n=>t(e,n)}function Co(t){return t!==void 0}function Qv(...t){return()=>{t.map(Wv)}}function sr(){}function Da(t,e){return e(t),t}function jv(t,e){return e(t)}function nt(...t){return t}function Xe(t,e){return t(Cn,e)}function Fe(t,e){t(xa,e)}function Ro(t){t(or)}function lt(t){return t(J_)}function Te(t,e){return Xe(t,Kv(e,xa))}function $t(t,e){const n=t(Cn,r=>{n(),e(r)});return n}function rp(t){let e,n;return r=>a=>{e=a,n&&clearTimeout(n),n=setTimeout(()=>{r(e)},t)}}function ap(t,e){return t===e}function rt(t=ap){let e;return n=>r=>{t(e,r)||(e=r,n(r))}}function xe(t){return e=>n=>{t(n)&&e(n)}}function me(t){return e=>tp(e,t)}function nn(t){return e=>()=>{e(t)}}function Z(t,...e){const n=Xv(...e);return(r,a)=>{switch(r){case or:Ro(t);return;case Cn:return Xe(t,n(a))}}}function rn(t,e){return n=>r=>{n(e=t(e,r))}}function Gn(t){return e=>n=>{t>0?t--:e(n)}}function En(t){let e=null,n;return r=>a=>{e=a,!n&&(n=setTimeout(()=>{n=void 0,r(e)},t))}}function Be(...t){const e=new Array(t.length);let n=0,r=null;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);Xe(i,l=>{const c=n;n=n|s,e[o]=l,c!==a&&n===a&&r&&(r(),r=null)})}),i=>o=>{const s=()=>{i([o].concat(e))};n===a?s():r=s}}function Xv(...t){return e=>t.reduceRight(jv,e)}function Zv(t){let e,n;const r=()=>e==null?void 0:e();return function(a,i){switch(a){case Cn:return i?n===i?void 0:(r(),n=i,e=Xe(t,i),e):(r(),sr);case or:r(),n=null;return}}}function ae(t){let e=t;const n=qe();return(r,a)=>{switch(r){case xa:e=a;break;case Cn:{a(e);break}case J_:return e}return n(r,a)}}function ft(t,e){return Da(ae(e),n=>Te(t,n))}function qe(){const t=[];return(e,n)=>{switch(e){case xa:t.slice().forEach(r=>{r(n)});return;case or:t.splice(0,t.length);return;case Cn:return t.push(n),()=>{const r=t.indexOf(n);r>-1&&t.splice(r,1)}}}}function wt(t){return Da(qe(),e=>Te(t,e))}function $e(t,e=[],{singleton:n}={singleton:!0}){return{constructor:t,dependencies:e,id:Jv(),singleton:n}}const Jv=()=>Symbol();function eN(t){const e=new Map,n=({constructor:r,dependencies:a,id:i,singleton:o})=>{if(o&&e.has(i))return e.get(i);const s=r(a.map(l=>n(l)));return o&&e.set(i,s),s};return n(t)}function ut(...t){const e=qe(),n=new Array(t.length);let r=0;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);Xe(i,l=>{n[o]=l,r=r|s,r===a&&Fe(e,n)})}),function(i,o){switch(i){case or:{Ro(e);return}case Cn:return r===a&&o(n),Xe(e,o)}}}function Ae(t,e=ap){return Z(t,rt(e))}function vo(...t){return function(e,n){switch(e){case or:return;case Cn:return Qv(...t.map(r=>Xe(r,n)))}}}var At=(t=>(t[t.DEBUG=0]="DEBUG",t[t.INFO=1]="INFO",t[t.WARN=2]="WARN",t[t.ERROR=3]="ERROR",t))(At||{});const tN={0:"debug",3:"error",1:"log",2:"warn"},nN=()=>typeof globalThis>"u"?window:globalThis,Rn=$e(()=>{const t=ae(3);return{log:ae((e,n,r=1)=>{var a;const i=(a=nN().VIRTUOSO_LOG_LEVEL)!=null?a:lt(t);r>=i&&console[tN[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",e,n)}),logLevel:t}},[],{singleton:!0});function Yn(t,e,n){return No(t,e,n).callbackRef}function No(t,e,n){const r=y.useRef(null);let a=o=>{};const i=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(o=>{const s=()=>{const l=o[0].target;l.offsetParent!==null&&t(l)};n?s():requestAnimationFrame(s)}):null,[t,n]);return a=o=>{o&&e?(i==null||i.observe(o),r.current=o):(r.current&&(i==null||i.unobserve(r.current)),r.current=null)},{callbackRef:a,ref:r}}function rN(t,e,n,r,a,i,o,s,l){const c=y.useCallback(d=>{const _=aN(d.children,e,s?"offsetWidth":"offsetHeight",a);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const m=p.lastElementChild.dataset.viewportType==="window";let E;m&&(E=p.ownerDocument.defaultView);const f=o?s?o.scrollLeft:o.scrollTop:m?s?E.scrollX||E.document.documentElement.scrollLeft:E.scrollY||E.document.documentElement.scrollTop:s?p.scrollLeft:p.scrollTop,g=o?s?o.scrollWidth:o.scrollHeight:m?s?E.document.documentElement.scrollWidth:E.document.documentElement.scrollHeight:s?p.scrollWidth:p.scrollHeight,S=o?s?o.offsetWidth:o.offsetHeight:m?s?E.innerWidth:E.innerHeight:s?p.offsetWidth:p.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(f,0),viewportHeight:S}),i==null||i(s?ip("column-gap",getComputedStyle(d).columnGap,a):ip("row-gap",getComputedStyle(d).rowGap,a)),_!==null&&t(_)},[t,e,a,i,o,r,s]);return No(c,n,l)}function aN(t,e,n,r){const a=t.length;if(a===0)return null;const i=[];for(let o=0;o<a;o++){const s=t.item(o);if(s.dataset.index===void 0)continue;const l=parseInt(s.dataset.index),c=parseFloat(s.dataset.knownSize),d=e(s,n);if(d===0&&r("Zero-sized element, this should not happen",{child:s},At.ERROR),d===c)continue;const _=i[i.length-1];i.length===0||_.size!==d||_.endIndex!==l-1?i.push({endIndex:l,size:d,startIndex:l}):i[i.length-1].endIndex++}return i}function ip(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,At.WARN),e==="normal"?0:parseInt(e??"0",10)}function op(t,e,n){const r=y.useRef(null),a=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let _,p;if(e){const m=e.getBoundingClientRect(),E=c.top-m.top;p=m.height-Math.max(0,E),_=E+e.scrollTop}else{const m=o.current.ownerDocument.defaultView;p=m.innerHeight-Math.max(0,c.top),_=c.top+m.scrollY}r.current={offsetTop:_,visibleHeight:p,visibleWidth:d},t(r.current)},[t,e]),{callbackRef:i,ref:o}=No(a,!0,n),s=y.useCallback(()=>{a(o.current)},[a,o]);return y.useEffect(()=>{var l;if(e){e.addEventListener("scroll",s);const c=new ResizeObserver(()=>{requestAnimationFrame(s)});return c.observe(e),()=>{e.removeEventListener("scroll",s),c.unobserve(e)}}else{const c=(l=o.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",s),c==null||c.addEventListener("resize",s),()=>{c==null||c.removeEventListener("scroll",s),c==null||c.removeEventListener("resize",s)}}},[s,e,o]),i}const Rt=$e(()=>{const t=qe(),e=qe(),n=ae(0),r=qe(),a=ae(0),i=qe(),o=qe(),s=ae(0),l=ae(0),c=ae(0),d=ae(0),_=qe(),p=qe(),m=ae(!1),E=ae(!1),f=ae(!1);return Te(Z(t,me(({scrollTop:g})=>g)),e),Te(Z(t,me(({scrollHeight:g})=>g)),o),Te(e,a),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:s,horizontalDirection:E,scrollBy:p,scrollContainerState:t,scrollHeight:o,scrollingInProgress:m,scrollTo:_,scrollTop:e,skipAnimationFrameInResizeObserver:f,smoothScrollTargetReached:r,statefulScrollTop:a,viewportHeight:i}},[],{singleton:!0}),kr={lvl:0};function sp(t,e){const n=t.length;if(n===0)return[];let{index:r,value:a}=e(t[0]);const i=[];for(let o=1;o<n;o++){const{index:s,value:l}=e(t[o]);i.push({end:s-1,start:r,value:a}),r=s,a=l}return i.push({end:1/0,start:r,value:a}),i}function et(t){return t===kr}function Ur(t,e){if(!et(t))return e===t.k?t.v:e<t.k?Ur(t.l,e):Ur(t.r,e)}function Wt(t,e,n="k"){if(et(t))return[-1/0,void 0];if(Number(t[n])===e)return[t.k,t.v];if(Number(t[n])<e){const r=Wt(t.r,e,n);return r[0]===-1/0?[t.k,t.v]:r}return Wt(t.l,e,n)}function Mt(t,e,n){return et(t)?dp(e,n,1):e===t.k?pt(t,{k:e,v:n}):e<t.k?up(pt(t,{l:Mt(t.l,e,n)})):up(pt(t,{r:Mt(t.r,e,n)}))}function lr(){return kr}function wa(t,e,n){if(et(t))return[];const r=Wt(t,e)[0];return iN(yo(t,r,n))}function Oo(t,e){if(et(t))return kr;const{k:n,l:r,r:a}=t;if(e===n){if(et(r))return a;if(et(a))return r;{const[i,o]=cp(r);return Ma(pt(t,{k:i,l:lp(r),v:o}))}}else return e<n?Ma(pt(t,{l:Oo(r,e)})):Ma(pt(t,{r:Oo(a,e)}))}function Hn(t){return et(t)?[]:[...Hn(t.l),{k:t.k,v:t.v},...Hn(t.r)]}function yo(t,e,n){if(et(t))return[];const{k:r,l:a,r:i,v:o}=t;let s=[];return r>e&&(s=s.concat(yo(a,e,n))),r>=e&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(yo(i,e,n))),s}function Ma(t){const{l:e,lvl:n,r}=t;if(r.lvl>=n-1&&e.lvl>=n-1)return t;if(n>r.lvl+1){if(Io(e))return _p(pt(t,{lvl:n-1}));if(!et(e)&&!et(e.r))return pt(e.r,{l:pt(e,{r:e.r.l}),lvl:n,r:pt(t,{l:e.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Io(t))return Ao(pt(t,{lvl:n-1}));if(!et(r)&&!et(r.l)){const a=r.l,i=Io(a)?r.lvl-1:r.lvl;return pt(a,{l:pt(t,{lvl:n-1,r:a.l}),lvl:a.lvl+1,r:Ao(pt(r,{l:a.r,lvl:i}))})}else throw new Error("Unexpected empty nodes")}}function pt(t,e){return dp(e.k!==void 0?e.k:t.k,e.v!==void 0?e.v:t.v,e.lvl!==void 0?e.lvl:t.lvl,e.l!==void 0?e.l:t.l,e.r!==void 0?e.r:t.r)}function lp(t){return et(t.r)?t.l:Ma(pt(t,{r:lp(t.r)}))}function Io(t){return et(t)||t.lvl>t.r.lvl}function cp(t){return et(t.r)?[t.k,t.v]:cp(t.r)}function dp(t,e,n,r=kr,a=kr){return{k:t,l:r,lvl:n,r:a,v:e}}function up(t){return Ao(_p(t))}function _p(t){const{l:e}=t;return!et(e)&&e.lvl===t.lvl?pt(e,{r:pt(t,{l:e.r})}):t}function Ao(t){const{lvl:e,r:n}=t;return!et(n)&&!et(n.r)&&n.lvl===e&&n.r.lvl===e?pt(n,{l:pt(t,{r:n.l}),lvl:e+1}):t}function iN(t){return sp(t,({k:e,v:n})=>({index:e,value:n}))}function pp(t,e){return!!(t&&t.startIndex===e.startIndex&&t.endIndex===e.endIndex)}function Fr(t,e){return!!(t&&t[0]===e[0]&&t[1]===e[1])}const xo=$e(()=>({recalcInProgress:ae(!1)}),[],{singleton:!0});function mp(t,e,n){return t[La(t,e,n)]}function La(t,e,n,r=0){let a=t.length-1;for(;r<=a;){const i=Math.floor((r+a)/2),o=t[i],s=n(o,e);if(s===0)return i;if(s===-1){if(a-r<2)return i-1;a=i-1}else{if(a===r)return i;r=i+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${e}`)}function oN(t,e,n,r){const a=La(t,e,r),i=La(t,n,r,a);return t.slice(a,i+1)}function vn(t,e){return Math.round(t.getBoundingClientRect()[e])}function Pa(t){return!et(t.groupOffsetTree)}function Do({index:t},e){return e===t?0:e<t?-1:1}function sN(){return{groupIndices:[],groupOffsetTree:lr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:lr()}}function lN(t,e){let n=et(t)?0:1/0;for(const r of e){const{endIndex:a,size:i,startIndex:o}=r;if(n=Math.min(n,o),et(t)){t=Mt(t,0,i);continue}const s=wa(t,o-1,a+1);if(s.some(gN(r)))continue;let l=!1,c=!1;for(const{end:d,start:_,value:p}of s)l?(a>=_||i===p)&&(t=Oo(t,_)):(c=p!==i,l=!0),d>a&&a>=_&&p!==i&&(t=Mt(t,a+1,p));c&&(t=Mt(t,o,i))}return[t,n]}function cN(t){return typeof t.groupIndex<"u"}function dN({offset:t},e){return e===t?0:e<t?-1:1}function Br(t,e,n){if(e.length===0)return 0;const{index:r,offset:a,size:i}=mp(e,t,Do),o=t-r,s=i*o+(o-1)*n+a;return s>0?s+n:s}function gp(t,e){if(!Pa(e))return t;let n=0;for(;e.groupIndices[n]<=t+n;)n++;return t+n}function Ep(t,e,n){if(cN(t))return e.groupIndices[t.groupIndex]+1;{const r=t.index==="LAST"?n:t.index;let a=gp(r,e);return a=Math.max(0,a,Math.min(n,a)),a}}function uN(t,e,n,r=0){return r>0&&(e=Math.max(e,mp(t,r,Do).offset)),sp(oN(t,e,n,dN),mN)}function _N(t,[e,n,r,a]){e.length>0&&r("received item sizes",e,At.DEBUG);const i=t.sizeTree;let o=i,s=0;if(n.length>0&&et(i)&&e.length===2){const p=e[0].size,m=e[1].size;o=n.reduce((E,f)=>Mt(Mt(E,f,p),f+1,m),o)}else[o,s]=lN(o,e);if(o===i)return t;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_}=wo(t.offsetTree,s,o,a);return{groupIndices:n,groupOffsetTree:n.reduce((p,m)=>Mt(p,m,Br(m,_,a)),lr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_,sizeTree:o}}function pN(t){return Hn(t).map(({k:e,v:n},r,a)=>{const i=a[r+1];return{endIndex:i?i.k-1:1/0,size:n,startIndex:e}})}function fp(t,e){let n=0,r=0;for(;n<t;)n+=e[r+1]-e[r]-1,r++;return r-(n===t?0:1)}function wo(t,e,n,r){let a=t,i=0,o=0,s=0,l=0;if(e!==0){l=La(a,e-1,Do),s=a[l].offset;const c=Wt(n,e-1);i=c[0],o=c[1],a.length&&a[l].size===Wt(n,e)[1]&&(l-=1),a=a.slice(0,l+1)}else a=[];for(const{start:c,value:d}of wa(n,e,1/0)){const _=c-i,p=_*o+s+_*r;a.push({index:c,offset:p,size:d}),i=c,s=p,o=d}return{lastIndex:i,lastOffset:s,lastSize:o,offsetTree:a}}function mN(t){return{index:t.index,value:t}}function gN(t){const{endIndex:e,size:n,startIndex:r}=t;return a=>a.start===r&&(a.end===e||a.end===1/0)&&a.value===n}const EN={offsetHeight:"height",offsetWidth:"width"},an=$e(([{log:t},{recalcInProgress:e}])=>{const n=qe(),r=qe(),a=ft(r,0),i=qe(),o=qe(),s=ae(0),l=ae([]),c=ae(void 0),d=ae(void 0),_=ae((C,R)=>vn(C,EN[R])),p=ae(void 0),m=ae(0),E=sN(),f=ft(Z(n,Be(l,t,m),rn(_N,E),rt()),E),g=ft(Z(l,rt(),rn((C,R)=>({current:R,prev:C.current}),{current:[],prev:[]}),me(({prev:C})=>C)),[]);Te(Z(l,xe(C=>C.length>0),Be(f,m),me(([C,R,N])=>{const O=C.reduce((I,x,M)=>Mt(I,x,Br(x,R.offsetTree,N)||M),lr());return{...R,groupIndices:C,groupOffsetTree:O}})),f),Te(Z(r,Be(f),xe(([C,{lastIndex:R}])=>C<R),me(([C,{lastIndex:R,lastSize:N}])=>[{endIndex:R,size:N,startIndex:C}])),n),Te(c,d);const S=ft(Z(c,me(C=>C===void 0)),!0);Te(Z(d,xe(C=>C!==void 0&&et(lt(f).sizeTree)),me(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=wt(Z(n,Be(f),rn(({sizes:C},[R,N])=>({changed:N!==C,sizes:N}),{changed:!1,sizes:E}),me(C=>C.changed)));Xe(Z(s,rn((C,R)=>({diff:C.prev-R,prev:R}),{diff:0,prev:0}),me(C=>C.diff)),C=>{const{groupIndices:R}=lt(f);if(C>0)Fe(e,!0),Fe(i,C+fp(C,R));else if(C<0){const N=lt(g);N.length>0&&(C-=fp(-C,N)),Fe(o,C)}}),Xe(Z(s,Be(t)),([C,R])=>{C<0&&R("`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:s},At.ERROR)});const h=wt(i);Te(Z(i,Be(f),me(([C,R])=>{const N=R.groupIndices.length>0,O=[],I=R.lastSize;if(N){const x=Ur(R.sizeTree,0);let M=0,Y=0;for(;M<C;){const U=R.groupIndices[Y],W=R.groupIndices.length===Y+1?1/0:R.groupIndices[Y+1]-U-1;O.push({endIndex:U,size:x,startIndex:U}),O.push({endIndex:U+1+W-1,size:I,startIndex:U+1}),Y++,M+=W+1}const z=Hn(R.sizeTree);return M!==C&&z.shift(),z.reduce((U,{k:W,v:D})=>{let B=U.ranges;return U.prevSize!==0&&(B=[...U.ranges,{endIndex:W+C-1,size:U.prevSize,startIndex:U.prevIndex}]),{prevIndex:W+C,prevSize:D,ranges:B}},{prevIndex:C,prevSize:0,ranges:O}).ranges}return Hn(R.sizeTree).reduce((x,{k:M,v:Y})=>({prevIndex:M+C,prevSize:Y,ranges:[...x.ranges,{endIndex:M+C-1,size:x.prevSize,startIndex:x.prevIndex}]}),{prevIndex:0,prevSize:I,ranges:[]}).ranges})),n);const v=wt(Z(o,Be(f,m),me(([C,{offsetTree:R},N])=>{const O=-C;return Br(O,R,N)})));return Te(Z(o,Be(f,m),me(([C,R,N])=>{if(R.groupIndices.length>0){if(et(R.sizeTree))return R;let O=lr();const I=lt(g);let x=0,M=0,Y=0;for(;x<-C;){Y=I[M];const z=I[M+1]-Y-1;M++,x+=z+1}if(O=Hn(R.sizeTree).reduce((z,{k:U,v:W})=>Mt(z,Math.max(0,U+C),W),O),x!==-C){const z=Ur(R.sizeTree,Y);O=Mt(O,0,z);const U=Wt(R.sizeTree,-C+1)[1];O=Mt(O,1,U)}return{...R,sizeTree:O,...wo(R.offsetTree,0,O,N)}}else{const O=Hn(R.sizeTree).reduce((I,{k:x,v:M})=>Mt(I,Math.max(0,x+C),M),lr());return{...R,sizeTree:O,...wo(R.offsetTree,0,O,N)}}})),f),{beforeUnshiftWith:h,data:p,defaultItemSize:d,firstItemIndex:s,fixedItemSize:c,gap:m,groupIndices:l,itemSize:_,listRefresh:b,shiftWith:o,shiftWithOffset:v,sizeRanges:n,sizes:f,statefulTotalCount:a,totalCount:r,trackItemSizes:S,unshiftWith:i}},nt(Rn,xo),{singleton:!0});function fN(t){return t.reduce((e,n)=>(e.groupIndices.push(e.totalCount),e.totalCount+=n+1,e),{groupIndices:[],totalCount:0})}const Sp=$e(([{groupIndices:t,sizes:e,totalCount:n},{headerHeight:r,scrollTop:a}])=>{const i=qe(),o=qe(),s=wt(Z(i,me(fN)));return Te(Z(s,me(l=>l.totalCount)),n),Te(Z(s,me(l=>l.groupIndices)),t),Te(Z(ut(a,e,r),xe(([l,c])=>Pa(c)),me(([l,c,d])=>Wt(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),rt(),me(l=>[l])),o),{groupCounts:i,topItemsIndexes:o}},nt(an,Rt)),Nn=$e(([{log:t}])=>{const e=ae(!1),n=wt(Z(e,xe(r=>r),rt()));return Xe(e,r=>{r&<(t)("props updated",{},At.DEBUG)}),{didMount:n,propsReady:e}},nt(Rn),{singleton:!0}),SN=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function bp(t){const e=typeof t=="number"?{index:t}:t;return e.align||(e.align="start"),(!e.behavior||!SN)&&(e.behavior="auto"),e.offset||(e.offset=0),e}const Gr=$e(([{gap:t,listRefresh:e,sizes:n,totalCount:r},{fixedFooterHeight:a,fixedHeaderHeight:i,footerHeight:o,headerHeight:s,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:_},{log:p}])=>{const m=qe(),E=qe(),f=ae(0);let g=null,S=null,b=null;function h(){g&&(g(),g=null),b&&(b(),b=null),S&&(clearTimeout(S),S=null),Fe(l,!1)}return Te(Z(m,Be(n,_,r,f,s,o,p),Be(t,i,a),me(([[v,C,R,N,O,I,x,M],Y,z,U])=>{const W=bp(v),{align:D,behavior:B,offset:L}=W,k=N-1,Q=Ep(W,C,k);let $=Br(Q,C.offsetTree,Y)+I;D==="end"?($+=z+Wt(C.sizeTree,Q)[1]-R+U,Q===k&&($+=x)):D==="center"?$+=(z+Wt(C.sizeTree,Q)[1]-R+U)/2:$-=O,L&&($+=L);const J=q=>{h(),q?(M("retrying to scroll to",{location:v},At.DEBUG),Fe(m,v)):(Fe(E,!0),M("list did not change, scroll successful",{},At.DEBUG))};if(h(),B==="smooth"){let q=!1;b=Xe(e,X=>{q=q||X}),g=$t(d,()=>{J(q)})}else g=$t(Z(e,bN(150)),J);return S=setTimeout(()=>{h()},1200),Fe(l,!0),M("scrolling from index to",{behavior:B,index:Q,top:$},At.DEBUG),{behavior:B,top:$}})),c),{scrollTargetReached:E,scrollToIndex:m,topListHeight:f}},nt(an,Rt,Rn),{singleton:!0});function bN(t){return e=>{const n=setTimeout(()=>{e(!1)},t);return r=>{r&&(e(!0),clearTimeout(n))}}}function Mo(t,e){t==0?e():requestAnimationFrame(()=>{Mo(t-1,e)})}function Lo(t,e){const n=e-1;return typeof t=="number"?t:t.index==="LAST"?n:t.index}const Yr=$e(([{defaultItemSize:t,listRefresh:e,sizes:n},{scrollTop:r},{scrollTargetReached:a,scrollToIndex:i},{didMount:o}])=>{const s=ae(!0),l=ae(0),c=ae(!0);return Te(Z(o,Be(l),xe(([d,_])=>!!_),nn(!1)),s),Te(Z(o,Be(l),xe(([d,_])=>!!_),nn(!1)),c),Xe(Z(ut(e,o),Be(s,n,t,c),xe(([[,d],_,{sizeTree:p},m,E])=>d&&(!et(p)||Co(m))&&!_&&!E),Be(l)),([,d])=>{$t(a,()=>{Fe(c,!0)}),Mo(4,()=>{$t(r,()=>{Fe(s,!0)}),Fe(i,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:s}},nt(an,Rt,Gr,Nn),{singleton:!0});function Tp(t,e){return Math.abs(t-e)<1.01}const Hr="up",qr="down",TN="none",hN={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},CN=0,Vr=$e(([{footerHeight:t,headerHeight:e,scrollBy:n,scrollContainerState:r,scrollTop:a,viewportHeight:i}])=>{const o=ae(!1),s=ae(!0),l=qe(),c=qe(),d=ae(4),_=ae(CN),p=ft(Z(vo(Z(Ae(a),Gn(1),nn(!0)),Z(Ae(a),Gn(1),nn(!1),rp(100))),rt()),!1),m=ft(Z(vo(Z(n,nn(!0)),Z(n,nn(!1),rp(200))),rt()),!1);Te(Z(ut(Ae(a),Ae(_)),me(([b,h])=>b<=h),rt()),s),Te(Z(s,En(50)),c);const E=wt(Z(ut(r,Ae(i),Ae(e),Ae(t),Ae(d)),rn((b,[{scrollHeight:h,scrollTop:v},C,R,N,O])=>{const I=v+C-h>-O,x={scrollHeight:h,scrollTop:v,viewportHeight:C};if(I){let Y,z;return v>b.state.scrollTop?(Y="SCROLLED_DOWN",z=b.state.scrollTop-v):(Y="SIZE_DECREASED",z=b.state.scrollTop-v||b.scrollTopDelta),{atBottom:!0,atBottomBecause:Y,scrollTopDelta:z,state:x}}let M;return x.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":v<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:x}},hN),rt((b,h)=>b&&b.atBottom===h.atBottom))),f=ft(Z(r,rn((b,{scrollHeight:h,scrollTop:v,viewportHeight:C})=>{if(Tp(b.scrollHeight,h))return{changed:!1,jump:0,scrollHeight:h,scrollTop:v};{const R=h-(v+C)<1;return b.scrollTop!==v&&R?{changed:!0,jump:b.scrollTop-v,scrollHeight:h,scrollTop:v}:{changed:!0,jump:0,scrollHeight:h,scrollTop:v}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),xe(b=>b.changed),me(b=>b.jump)),0);Te(Z(E,me(b=>b.atBottom)),o),Te(Z(o,En(50)),l);const g=ae(qr);Te(Z(r,me(({scrollTop:b})=>b),rt(),rn((b,h)=>lt(m)?{direction:b.direction,prevScrollTop:h}:{direction:h<b.prevScrollTop?Hr:qr,prevScrollTop:h},{direction:qr,prevScrollTop:0}),me(b=>b.direction)),g),Te(Z(r,En(50),nn(TN)),g);const S=ae(0);return Te(Z(p,xe(b=>!b),nn(0)),S),Te(Z(a,En(100),Be(p),xe(([b,h])=>!!h),rn(([b,h],[v])=>[h,v],[0,0]),me(([b,h])=>h-b)),S),{atBottomState:E,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:_,isAtBottom:o,isAtTop:s,isScrolling:p,lastJumpDueToItemResize:f,scrollDirection:g,scrollVelocity:S}},nt(Rt)),ka="top",Ua="bottom",hp="none";function Cp(t,e,n){return typeof t=="number"?n===Hr&&e===ka||n===qr&&e===Ua?t:0:n===Hr?e===ka?t.main:t.reverse:e===Ua?t.main:t.reverse}function Rp(t,e){var n;return typeof t=="number"?t:(n=t[e])!=null?n:0}const Po=$e(([{deviation:t,fixedHeaderHeight:e,headerHeight:n,scrollTop:r,viewportHeight:a}])=>{const i=qe(),o=ae(0),s=ae(0),l=ae(0),c=ft(Z(ut(Ae(r),Ae(a),Ae(n),Ae(i,Fr),Ae(l),Ae(o),Ae(e),Ae(t),Ae(s)),me(([d,_,p,[m,E],f,g,S,b,h])=>{const v=d-b,C=g+S,R=Math.max(p-v,0);let N=hp;const O=Rp(h,ka),I=Rp(h,Ua);return m-=b,m+=p+S,E+=p+S,E-=b,m>d+C-O&&(N=Hr),E<d-R+_+I&&(N=qr),N!==hp?[Math.max(v-p-Cp(f,ka,N)-O,0),v-R-S+_+Cp(f,Ua,N)+I]:null}),xe(d=>d!=null),rt(Fr)),[0,0]);return{increaseViewportBy:s,listBoundary:i,overscan:l,topListHeight:o,visibleRange:c}},nt(Rt),{singleton:!0});function RN(t,e,n){if(Pa(e)){const r=gp(t,e);return[{index:Wt(e.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:t,offset:0,size:0}]}const ko={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Fa(t,e,n,r,a,i){const{lastIndex:o,lastOffset:s,lastSize:l}=a;let c=0,d=0;if(t.length>0){c=t[0].offset;const f=t[t.length-1];d=f.offset+f.size}const _=n-o,p=s+_*l+(_-1)*r,m=c,E=p-d;return{bottom:d,firstItemIndex:i,items:Np(t,a,i),offsetBottom:E,offsetTop:c,top:m,topItems:Np(e,a,i),topListHeight:e.reduce((f,g)=>g.size+f,0),totalCount:n}}function vp(t,e,n,r,a,i){let o=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-o>=t)break;o++}const s=t+o,l=Lo(e,s),c=Array.from({length:s}).map((d,_)=>({data:i[_+l],index:_+l,offset:0,size:0}));return Fa(c,[],s,a,n,r)}function Np(t,e,n){if(t.length===0)return[];if(!Pa(e))return t.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=t[0].index,a=t[t.length-1].index,i=[],o=wa(e.groupOffsetTree,r,a);let s,l=0;for(const c of t){(!s||s.end<c.index)&&(s=o.shift(),l=e.groupIndices.indexOf(s.start));let d;c.index===s.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},i.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return i}const qn=$e(([{data:t,firstItemIndex:e,gap:n,sizes:r,totalCount:a},i,{listBoundary:o,topListHeight:s,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:_},p,{didMount:m},{recalcInProgress:E}])=>{const f=ae([]),g=ae(0),S=qe();Te(i.topItemsIndexes,f);const b=ft(Z(ut(m,E,Ae(l,Fr),Ae(a),Ae(r),Ae(c),d,Ae(f),Ae(e),Ae(n),t),xe(([R,N,,O,,,,,,,I])=>{const x=I&&I.length!==O;return R&&!N&&!x}),me(([,,[R,N],O,I,x,M,Y,z,U,W])=>{const D=I,{offsetTree:B,sizeTree:L}=D,k=lt(g);if(O===0)return{...ko,totalCount:O};if(R===0&&N===0)return k===0?{...ko,totalCount:O}:vp(k,x,I,z,U,W||[]);if(et(L))return k>0?null:Fa(RN(Lo(x,O),D,W),[],O,U,D,z);const Q=[];if(Y.length>0){const re=Y[0],le=Y[Y.length-1];let H=0;for(const P of wa(L,re,le)){const j=P.value,ne=Math.max(P.start,re),oe=Math.min(P.end,le);for(let ie=ne;ie<=oe;ie++)Q.push({data:W==null?void 0:W[ie],index:ie,offset:H,size:j}),H+=j}}if(!M)return Fa([],Q,O,U,D,z);const $=Y.length>0?Y[Y.length-1]+1:0,J=uN(B,R,N,$);if(J.length===0)return null;const q=O-1,X=Da([],re=>{for(const le of J){const H=le.value;let P=H.offset,j=le.start;const ne=H.size;if(H.offset<R){j+=Math.floor((R-H.offset+U)/(ne+U));const ie=j-le.start;P+=ie*ne+ie*U}j<$&&(P+=($-j)*ne,j=$);const oe=Math.min(le.end,q);for(let ie=j;ie<=oe&&!(P>=N);ie++)re.push({data:W==null?void 0:W[ie],index:ie,offset:P,size:ne}),P+=ne+U}});return Fa(X,Q,O,U,D,z)}),xe(R=>R!==null),rt()),ko);Te(Z(t,xe(Co),me(R=>R==null?void 0:R.length)),a),Te(Z(b,me(R=>R.topListHeight)),_),Te(_,s),Te(Z(b,me(R=>[R.top,R.bottom])),o),Te(Z(b,me(R=>R.items)),S);const h=wt(Z(b,xe(({items:R})=>R.length>0),Be(a,t),xe(([{items:R},N])=>R[R.length-1].originalIndex===N-1),me(([,R,N])=>[R-1,N]),rt(Fr),me(([R])=>R))),v=wt(Z(b,En(200),xe(({items:R,topItems:N})=>R.length>0&&R[0].originalIndex===N.length),me(({items:R})=>R[0].index),rt())),C=wt(Z(b,xe(({items:R})=>R.length>0),me(({items:R})=>{let N=0,O=R.length-1;for(;R[N].type==="group"&&N<O;)N++;for(;R[O].type==="group"&&O>N;)O--;return{endIndex:R[O].index,startIndex:R[N].index}}),rt(pp)));return{endReached:h,initialItemCount:g,itemsRendered:S,listState:b,rangeChanged:C,startReached:v,topItemsIndexes:f,...p}},nt(an,Sp,Po,Yr,Gr,Vr,Nn,xo),{singleton:!0}),Op=$e(([{fixedFooterHeight:t,fixedHeaderHeight:e,footerHeight:n,headerHeight:r},{listState:a}])=>{const i=qe(),o=ft(Z(ut(n,t,r,e,a),me(([s,l,c,d,_])=>s+l+c+d+_.offsetBottom+_.bottom)),0);return Te(Ae(o),i),{totalListHeight:o,totalListHeightChanged:i}},nt(Rt,qn),{singleton:!0}),vN=$e(([{viewportHeight:t},{totalListHeight:e}])=>{const n=ae(!1),r=ft(Z(ut(n,t,e),xe(([a])=>a),me(([,a,i])=>Math.max(0,a-i)),En(0),rt()),0);return{alignToBottom:n,paddingTopAddition:r}},nt(Rt,Op),{singleton:!0}),yp=$e(()=>({context:ae(null)})),NN=({itemBottom:t,itemTop:e,locationParams:{align:n,behavior:r,...a},viewportBottom:i,viewportTop:o})=>e<o?{...a,align:n??"start",behavior:r}:t>i?{...a,align:n??"end",behavior:r}:null,Ip=$e(([{gap:t,sizes:e,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:a,headerHeight:i,scrollingInProgress:o,scrollTop:s,viewportHeight:l},{scrollToIndex:c}])=>{const d=qe();return Te(Z(d,Be(e,l,n,i,a,r,s),Be(t),me(([[_,p,m,E,f,g,S,b],h])=>{const{align:v,behavior:C,calculateViewLocation:R=NN,done:N,...O}=_,I=Ep(_,p,E-1),x=Br(I,p.offsetTree,h)+f+g,M=x+Wt(p.sizeTree,I)[1],Y=b+g,z=b+m-S,U=R({itemBottom:M,itemTop:x,locationParams:{align:v,behavior:C,...O},viewportBottom:z,viewportTop:Y});return U?N&&$t(Z(o,xe(W=>!W),Gn(lt(o)?1:2)),N):N&&N(),U}),xe(_=>_!==null)),c),{scrollIntoView:d}},nt(an,Rt,Gr,qn,Rn),{singleton:!0});function Ap(t){return t?t==="smooth"?"smooth":"auto":!1}const ON=(t,e)=>typeof t=="function"?Ap(t(e)):e&&Ap(t),yN=$e(([{listRefresh:t,totalCount:e,fixedItemSize:n,data:r},{atBottomState:a,isAtBottom:i},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:_},{context:p},{scrollIntoView:m}])=>{const E=ae(!1),f=qe();let g=null;function S(C){Fe(o,{align:"end",behavior:C,index:"LAST"})}Xe(Z(ut(Z(Ae(e),Gn(1)),l),Be(Ae(E),i,s,_),me(([[C,R],N,O,I,x])=>{let M=R&&I,Y="auto";return M&&(Y=ON(N,O||x),M=M&&!!Y),{followOutputBehavior:Y,shouldFollow:M,totalCount:C}}),xe(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:R})=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("following output to ",{totalCount:R},At.DEBUG),S(C)}):g=$t(t,()=>{lt(d)("following output to ",{totalCount:R},At.DEBUG),S(C),g=null})});function b(C){const R=$t(a,N=>{C&&!N.atBottom&&N.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(lt(d)("scrolling to bottom due to increased size",{},At.DEBUG),S("auto"))});setTimeout(R,100)}Xe(Z(ut(Ae(E),e,c),xe(([C,,R])=>C&&R),rn(({value:C},[,R])=>({refreshed:C===R,value:R}),{refreshed:!1,value:0}),xe(({refreshed:C})=>C),Be(E,e)),([,C])=>{lt(s)&&b(C!==!1)}),Xe(f,()=>{b(lt(E)!==!1)}),Xe(ut(Ae(E),a),([C,R])=>{C&&!R.atBottom&&R.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&S("auto")});const h=ae(null),v=qe();return Te(vo(Z(Ae(r),me(C=>{var R;return(R=C==null?void 0:C.length)!=null?R:0})),Z(Ae(e))),v),Xe(Z(ut(Z(v,Gn(1)),l),Be(Ae(h),s,_,p),me(([[C,R],N,O,I,x])=>R&&O&&(N==null?void 0:N({context:x,totalCount:C,scrollingInProgress:I}))),xe(C=>!!C),En(0)),C=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("scrolling into view",{}),Fe(m,C)}):g=$t(t,()=>{lt(d)("scrolling into view",{}),Fe(m,C),g=null})}),{autoscrollToBottom:f,followOutput:E,scrollIntoViewOnChange:h}},nt(an,Vr,Gr,Yr,Nn,Rn,Rt,yp,Ip)),IN=$e(([{data:t,firstItemIndex:e,gap:n,sizes:r},{initialTopMostItemIndex:a},{initialItemCount:i,listState:o},{didMount:s}])=>(Te(Z(s,Be(i),xe(([,l])=>l!==0),Be(a,r,e,n,t),me(([[,l],c,d,_,p,m=[]])=>vp(l,c,d,_,p,m))),o),{}),nt(an,Yr,qn,Nn),{singleton:!0}),AN=$e(([{didMount:t},{scrollTo:e},{listState:n}])=>{const r=ae(0);return Xe(Z(t,Be(r),xe(([,a])=>a!==0),me(([,a])=>({top:a}))),a=>{$t(Z(n,Gn(1),xe(i=>i.items.length>1)),()=>{requestAnimationFrame(()=>{Fe(e,a)})})}),{initialScrollTop:r}},nt(Nn,Rt,qn),{singleton:!0}),xp=$e(([{scrollVelocity:t}])=>{const e=ae(!1),n=qe(),r=ae(!1);return Te(Z(t,Be(r,e,n),xe(([a,i])=>!!i),me(([a,i,o,s])=>{const{enter:l,exit:c}=i;if(o){if(c(a,s))return!1}else if(l(a,s))return!0;return o}),rt()),e),Xe(Z(ut(e,t,n),Be(r)),([[a,i,o],s])=>{a&&s&&s.change&&s.change(i,o)}),{isSeeking:e,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:t}},nt(Vr),{singleton:!0}),Uo=$e(([{scrollContainerState:t,scrollTo:e}])=>{const n=qe(),r=qe(),a=qe(),i=ae(!1),o=ae(void 0);return Te(Z(ut(n,r),me(([{scrollHeight:s,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:s,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),Te(Z(e,Be(r),me(([s,{offsetTop:l}])=>({...s,top:s.top+l}))),a),{customScrollParent:o,useWindowScroll:i,windowScrollContainerState:n,windowScrollTo:a,windowViewportRect:r}},nt(Rt)),xN=$e(([{sizeRanges:t,sizes:e},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:a},{didMount:i},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:l}])=>{const c=qe(),d=ae(void 0),_=ae(null),p=ae(null);return Te(s,_),Te(l,p),Xe(Z(c,Be(e,r,o,_,p,n)),([m,E,f,g,S,b,h])=>{const v=pN(E.sizeTree);g&&S!==null&&b!==null&&(f=S.scrollTop-b.offsetTop),f-=h,m({ranges:v,scrollTop:f})}),Te(Z(d,xe(Co),me(DN)),a),Te(Z(i,Be(d),xe(([,m])=>m!==void 0),rt(),me(([,m])=>m.ranges)),t),{getState:c,restoreStateFrom:d}},nt(an,Rt,Yr,Nn,Uo));function DN(t){return{align:"start",index:0,offset:t.scrollTop}}const wN=$e(([{topItemsIndexes:t}])=>{const e=ae(0);return Te(Z(e,xe(n=>n>=0),me(n=>Array.from({length:n}).map((r,a)=>a))),t),{topItemCount:e}},nt(qn));function Dp(t){let e=!1,n;return()=>(e||(e=!0,n=t()),n)}const MN=Dp(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),LN=$e(([{deviation:t,scrollBy:e,scrollingInProgress:n,scrollTop:r},{isAtBottom:a,isScrolling:i,lastJumpDueToItemResize:o,scrollDirection:s},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:_,sizes:p},{log:m},{recalcInProgress:E}])=>{const f=wt(Z(l,Be(o),rn(([,S,b,h],[{bottom:v,items:C,offsetBottom:R,totalCount:N},O])=>{const I=v+R;let x=0;return b===N&&S.length>0&&C.length>0&&(C[0].originalIndex===0&&S[0].originalIndex===0||(x=I-h,x!==0&&(x+=O))),[x,C,N,I]},[0,[],0,0]),xe(([S])=>S!==0),Be(r,s,n,a,m,E),xe(([,S,b,h,,,v])=>!v&&!h&&S!==0&&b===Hr),me(([[S],,,,,b])=>(b("Upward scrolling compensation",{amount:S},At.DEBUG),S))));function g(S){S>0?(Fe(e,{behavior:"auto",top:-S}),Fe(t,0)):(Fe(t,0),Fe(e,{behavior:"auto",top:-S}))}return Xe(Z(f,Be(t,i)),([S,b,h])=>{h&&MN()?Fe(t,b-S):g(-S)}),Xe(Z(ut(ft(i,!1),t,E),xe(([S,b,h])=>!S&&!h&&b!==0),me(([S,b])=>b),En(1)),g),Te(Z(_,me(S=>({top:-S}))),e),Xe(Z(c,Be(p,d),me(([S,{groupIndices:b,lastSize:h,sizeTree:v},C])=>{function R(N){return N*(h+C)}if(b.length===0)return R(S);{let N=0;const O=Ur(v,0);let I=0,x=0;for(;I<S;){I++,N+=O;let M=b.length===x+1?1/0:b[x+1]-b[x]-1;I+M>S&&(N-=O,M=S-I+1),I+=M,N+=R(M),x++}return N}})),S=>{Fe(t,S),requestAnimationFrame(()=>{Fe(e,{top:S}),requestAnimationFrame(()=>{Fe(t,0),Fe(E,!1)})})}),{deviation:t}},nt(Rt,Vr,qn,an,Rn,xo)),PN=$e(([t,e,n,r,a,i,o,s,l,c,d])=>({...t,...e,...n,...r,...a,...i,...o,...s,...l,...c,...d}),nt(Po,IN,Nn,xp,Op,AN,vN,Uo,Ip,Rn,yp)),wp=$e(([{data:t,defaultItemSize:e,firstItemIndex:n,fixedItemSize:r,gap:a,groupIndices:i,itemSize:o,sizeRanges:s,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:_},{initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E},f,g,S,{listState:b,topItemsIndexes:h,...v},{scrollToIndex:C},R,{topItemCount:N},{groupCounts:O},I])=>(Te(v.rangeChanged,I.scrollSeekRangeChanged),Te(Z(I.windowViewportRect,me(x=>x.visibleHeight)),f.viewportHeight),{data:t,defaultItemHeight:e,firstItemIndex:n,fixedItemHeight:r,gap:a,groupCounts:O,initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E,sizeRanges:s,topItemCount:N,topItemsIndexes:h,totalCount:d,...S,groupIndices:i,itemSize:o,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:_,...v,...I,...f,sizes:l,...g}),nt(an,Yr,Rt,xN,yN,qn,Gr,LN,wN,Sp,PN));function kN(t,e){const n={},r={};let a=0;const i=t.length;for(;a<i;)r[t[a]]=1,a+=1;for(const o in e)Object.hasOwn(r,o)||(n[o]=e[o]);return n}const Ba=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Mp(t,e,n){const r=Object.keys(e.required||{}),a=Object.keys(e.optional||{}),i=Object.keys(e.methods||{}),o=Object.keys(e.events||{}),s=y.createContext({});function l(g,S){g.propsReady&&Fe(g.propsReady,!1);for(const b of r){const h=g[e.required[b]];Fe(h,S[b])}for(const b of a)if(b in S){const h=g[e.optional[b]];Fe(h,S[b])}g.propsReady&&Fe(g.propsReady,!0)}function c(g){return i.reduce((S,b)=>(S[b]=h=>{const v=g[e.methods[b]];Fe(v,h)},S),{})}function d(g){return o.reduce((S,b)=>(S[b]=Zv(g[e.events[b]]),S),{})}const _=y.forwardRef((g,S)=>{const{children:b,...h}=g,[v]=y.useState(()=>Da(eN(t),N=>{l(N,h)})),[C]=y.useState(np(d,v));Ba(()=>{for(const N of o)N in h&&Xe(C[N],h[N]);return()=>{Object.values(C).map(Ro)}},[h,C,v]),Ba(()=>{l(v,h)}),y.useImperativeHandle(S,ep(c(v)));const R=n;return u.jsx(s.Provider,{value:v,children:n?u.jsx(R,{...kN([...r,...a,...o],h),children:b}):b})}),p=g=>{const S=y.useContext(s);return y.useCallback(b=>{Fe(S[g],b)},[S,g])},m=g=>{const S=y.useContext(s)[g],b=y.useCallback(h=>Xe(S,h),[S]);return y.useSyncExternalStore(b,()=>lt(S),()=>lt(S))},E=g=>{const S=y.useContext(s)[g],[b,h]=y.useState(np(lt,S));return Ba(()=>Xe(S,v=>{v!==b&&h(ep(v))}),[S,b]),b},f=y.version.startsWith("18")?m:E;return{Component:_,useEmitter:(g,S)=>{const b=y.useContext(s)[g];Ba(()=>Xe(b,S),[S,b])},useEmitterValue:f,usePublisher:p}}const Lp=y.createContext(void 0),Pp=y.createContext(void 0),kp=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Fo(t){return"self"in t}function UN(t){return"body"in t}function Up(t,e,n,r=sr,a,i){const o=y.useRef(null),s=y.useRef(null),l=y.useRef(null),c=y.useCallback(p=>{let m,E,f;const g=p.target;if(UN(g)||Fo(g)){const b=Fo(g)?g:g.defaultView;f=i?b.scrollX:b.scrollY,m=i?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,E=i?b.innerWidth:b.innerHeight}else f=i?g.scrollLeft:g.scrollTop,m=i?g.scrollWidth:g.scrollHeight,E=i?g.offsetWidth:g.offsetHeight;const S=()=>{t({scrollHeight:m,scrollTop:Math.max(f,0),viewportHeight:E})};p.suppressFlushSync?S():no.flushSync(S),s.current!==null&&(f===s.current||f<=0||f===m-E)&&(s.current=null,e(!0),l.current&&(clearTimeout(l.current),l.current=null))},[t,e,i]);y.useEffect(()=>{const p=a||o.current;return r(a||o.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[o,c,n,r,a]);function d(p){const m=o.current;if(!m||(i?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const E=p.behavior==="smooth";let f,g,S;Fo(m)?(g=Math.max(vn(m.document.documentElement,i?"width":"height"),i?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),f=i?m.innerWidth:m.innerHeight,S=i?window.scrollX:window.scrollY):(g=m[i?"scrollWidth":"scrollHeight"],f=vn(m,i?"width":"height"),S=m[i?"scrollLeft":"scrollTop"]);const b=g-f;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Tp(f,g)||p.top===S){t({scrollHeight:g,scrollTop:S,viewportHeight:f}),E&&e(!0);return}E?(s.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,s.current=null,e(!0)},1e3)):s.current=null,i&&(p={behavior:p.behavior,left:p.top}),m.scrollTo(p)}function _(p){i&&(p={behavior:p.behavior,left:p.top}),o.current.scrollBy(p)}return{scrollByCallback:_,scrollerRef:o,scrollToCallback:d}}const Bo="-webkit-sticky",Fp="sticky",Go=Dp(()=>{if(typeof document>"u")return Fp;const t=document.createElement("div");return t.style.position=Bo,t.style.position===Bo?Bo:Fp});function Yo(t){return t}const FN=$e(()=>{const t=ae(s=>`Item ${s}`),e=ae(s=>`Group ${s}`),n=ae({}),r=ae(Yo),a=ae("div"),i=ae(sr),o=(s,l=null)=>ft(Z(n,me(c=>c[s]),rt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:o("EmptyPlaceholder"),FooterComponent:o("Footer"),GroupComponent:o("Group","div"),groupContent:e,HeaderComponent:o("Header"),HeaderFooterTag:a,ItemComponent:o("Item","div"),itemContent:t,ListComponent:o("List","div"),ScrollerComponent:o("Scroller","div"),scrollerRef:i,ScrollSeekPlaceholder:o("ScrollSeekPlaceholder"),TopItemListComponent:o("TopItemList")}}),BN=$e(([t,e])=>({...t,...e}),nt(wp,FN)),GN=({height:t})=>u.jsx("div",{style:{height:t}}),YN={overflowAnchor:"none",position:Go(),zIndex:1},Bp={overflowAnchor:"none"},HN={...Bp,display:"inline-block",height:"100%"},Gp=y.memo(function({showTopList:t=!1}){const e=Pe("listState"),n=Gt("sizeRanges"),r=Pe("useWindowScroll"),a=Pe("customScrollParent"),i=Gt("windowScrollContainerState"),o=Gt("scrollContainerState"),s=a||r?i:o,l=Pe("itemContent"),c=Pe("context"),d=Pe("groupContent"),_=Pe("trackItemSizes"),p=Pe("itemSize"),m=Pe("log"),E=Gt("gap"),f=Pe("horizontalDirection"),{callbackRef:g}=rN(n,p,_,t?sr:s,m,E,a,f,Pe("skipAnimationFrameInResizeObserver")),[S,b]=y.useState(0);Ho("deviation",U=>{S!==U&&b(U)});const h=Pe("EmptyPlaceholder"),v=Pe("ScrollSeekPlaceholder")||GN,C=Pe("ListComponent"),R=Pe("ItemComponent"),N=Pe("GroupComponent"),O=Pe("computeItemKey"),I=Pe("isSeeking"),x=Pe("groupIndices").length>0,M=Pe("alignToBottom"),Y=Pe("initialItemFinalLocationReached"),z=t?{}:{boxSizing:"border-box",...f?{display:"inline-block",height:"100%",marginLeft:S!==0?S:M?"auto":0,paddingLeft:e.offsetTop,paddingRight:e.offsetBottom,whiteSpace:"nowrap"}:{marginTop:S!==0?S:M?"auto":0,paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},...Y?{}:{visibility:"hidden"}};return!t&&e.totalCount===0&&h?u.jsx(h,{...St(h,c)}):u.jsx(C,{...St(C,c),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:z,children:(t?e.topItems:e.items).map(U=>{const W=U.originalIndex,D=O(W+e.firstItemIndex,U.data,c);return I?y.createElement(v,{...St(v,c),height:U.size,index:U.index,key:D,type:U.type||"item",...U.type==="group"?{}:{groupIndex:U.groupIndex}}):U.type==="group"?y.createElement(N,{...St(N,c),"data-index":W,"data-item-index":U.index,"data-known-size":U.size,key:D,style:YN},d(U.index,c)):y.createElement(R,{...St(R,c),...$N(R,U.data),"data-index":W,"data-item-group-index":U.groupIndex,"data-item-index":U.index,"data-known-size":U.size,key:D,style:f?HN:Bp},x?l(U.index,U.groupIndex,U.data,c):l(U.index,U.data,c))})})}),qN={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},VN={outline:"none",overflowX:"auto",position:"relative"},Ga=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:{}}),zN={position:Go(),top:0,width:"100%",zIndex:1};function St(t,e){if(typeof t!="string")return{context:e}}function $N(t,e){return{item:typeof t=="string"?void 0:e}}const WN=y.memo(function(){const t=Pe("HeaderComponent"),e=Gt("headerHeight"),n=Pe("HeaderFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,Pe("skipAnimationFrameInResizeObserver")),a=Pe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null}),KN=y.memo(function(){const t=Pe("FooterComponent"),e=Gt("footerHeight"),n=Pe("HeaderFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,Pe("skipAnimationFrameInResizeObserver")),a=Pe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null});function Yp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("scrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("scrollerRef"),_=e("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:m,scrollToCallback:E}=Up(s,c,l,d,void 0,_);return t("scrollTo",E),t("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{..._?VN:qN,...a},tabIndex:0,...o,...St(l,i),children:r})})}function Hp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("windowScrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("totalListHeight"),_=e("deviation"),p=e("customScrollParent"),m=y.useRef(null),E=e("scrollerRef"),{scrollByCallback:f,scrollerRef:g,scrollToCallback:S}=Up(s,c,l,E,p);return kp(()=>{var b;return g.current=p||((b=m.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,p]),t("windowScrollTo",S),t("scrollBy",f),u.jsx(l,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...a,...d!==0?{height:d+_}:{}},...o,...St(l,i),children:r})})}const QN=({children:t})=>{const e=y.useContext(Lp),n=Gt("viewportHeight"),r=Gt("fixedItemHeight"),a=Pe("alignToBottom"),i=Pe("horizontalDirection"),o=y.useMemo(()=>tp(n,l=>vn(l,i?"width":"height")),[n,i]),s=Yn(o,!0,Pe("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{e&&(n(e.viewportHeight),r(e.itemHeight))},[e,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:s,style:Ga(a),children:t})},jN=({children:t})=>{const e=y.useContext(Lp),n=Gt("windowViewportRect"),r=Gt("fixedItemHeight"),a=Pe("customScrollParent"),i=op(n,a,Pe("skipAnimationFrameInResizeObserver")),o=Pe("alignToBottom");return y.useEffect(()=>{e&&(r(e.itemHeight),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:100}))},[e,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:i,style:Ga(o),children:t})},XN=({children:t})=>{const e=Pe("TopItemListComponent")||"div",n=Pe("headerHeight"),r={...zN,marginTop:`${n}px`},a=Pe("context");return u.jsx(e,{style:r,...St(e,a),children:t})},ZN=y.memo(function(t){const e=Pe("useWindowScroll"),n=Pe("topItemsIndexes").length>0,r=Pe("customScrollParent"),a=Pe("context");return u.jsxs(r||e?tO:eO,{...t,context:a,children:[n&&u.jsx(XN,{children:u.jsx(Gp,{showTopList:!0})}),u.jsxs(r||e?jN:QN,{children:[u.jsx(WN,{}),u.jsx(Gp,{}),u.jsx(KN,{})]})]})}),{Component:JN,useEmitter:Ho,useEmitterValue:Pe,usePublisher:Gt}=Mp(BN,{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"}},ZN),eO=Yp({useEmitter:Ho,useEmitterValue:Pe,usePublisher:Gt}),tO=Hp({useEmitter:Ho,useEmitterValue:Pe,usePublisher:Gt}),nO=JN;nt(wp,$e(()=>{const t=ae(c=>u.jsxs("td",{children:["Item $",c]})),e=ae(null),n=ae(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ae(null),a=ae(null),i=ae({}),o=ae(Yo),s=ae(sr),l=(c,d=null)=>ft(Z(i,me(_=>_[c]),rt()),d);return{components:i,computeItemKey:o,context:e,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:a,fixedHeaderContent:r,itemContent:t,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Go();const qp={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},rO={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Vp,floor:Ya,max:zr,min:qo,round:zp}=Math;function $p(t,e,n){return Array.from({length:e-t+1}).map((r,a)=>({data:n===null?null:n[a+t],index:a+t}))}function aO(t){return{...rO,items:t}}function Ha(t,e){return t&&t.width===e.width&&t.height===e.height}function iO(t,e){return t&&t.column===e.column&&t.row===e.row}const oO=$e(([{increaseViewportBy:t,listBoundary:e,overscan:n,visibleRange:r},{footerHeight:a,headerHeight:i,scrollBy:o,scrollContainerState:s,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:_},p,m,{didMount:E,propsReady:f},{customScrollParent:g,useWindowScroll:S,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:v},C])=>{const R=ae(0),N=ae(0),O=ae(qp),I=ae({height:0,width:0}),x=ae({height:0,width:0}),M=qe(),Y=qe(),z=ae(0),U=ae(null),W=ae({column:0,row:0}),D=qe(),B=qe(),L=ae(!1),k=ae(0),Q=ae(!0),$=ae(!1),J=ae(!1);Xe(Z(E,Be(k),xe(([P,j])=>!!j)),()=>{Fe(Q,!1)}),Xe(Z(ut(E,Q,x,I,k,$),xe(([P,j,ne,oe,,ie])=>P&&!j&&ne.height!==0&&oe.height!==0&&!ie)),([,,,,P])=>{Fe($,!0),Mo(1,()=>{Fe(M,P)}),$t(Z(c),()=>{Fe(e,[0,0]),Fe(Q,!0)})}),Te(Z(B,xe(P=>P!=null&&P.scrollTop>0),nn(0)),N),Xe(Z(E,Be(B),xe(([,P])=>P!=null)),([,P])=>{P&&(Fe(I,P.viewport),Fe(x,P.item),Fe(W,P.gap),P.scrollTop>0&&(Fe(L,!0),$t(Z(c,Gn(1)),j=>{Fe(L,!1)}),Fe(l,{top:P.scrollTop})))}),Te(Z(I,me(({height:P})=>P)),_),Te(Z(ut(Ae(I,Ha),Ae(x,Ha),Ae(W,(P,j)=>P&&P.column===j.column&&P.row===j.row),Ae(c)),me(([P,j,ne,oe])=>({gap:ne,item:j,scrollTop:oe,viewport:P}))),D),Te(Z(ut(Ae(R),r,Ae(W,iO),Ae(x,Ha),Ae(I,Ha),Ae(U),Ae(N),Ae(L),Ae(Q),Ae(k)),xe(([,,,,,,,P])=>!P),me(([P,[j,ne],oe,ie,Oe,be,ye,,fe,Le])=>{const{column:ce,row:he}=oe,{height:Re,width:Ce}=ie,{width:We}=Oe;if(ye===0&&(P===0||We===0))return qp;if(Ce===0){const Ze=Lo(Le,P),Nt=Ze+Math.max(ye-1,0);return aO($p(Ze,Nt,be))}const ze=Wp(We,Ce,ce);let Ke,V;fe?j===0&&ne===0&&ye>0?(Ke=0,V=ye-1):(Ke=ze*Ya((j+he)/(Re+he)),V=ze*Vp((ne+he)/(Re+he))-1,V=qo(P-1,zr(V,ze-1)),Ke=qo(V,zr(0,Ke))):(Ke=0,V=-1);const F=$p(Ke,V,be),{bottom:te,top:Se}=Kp(Oe,oe,ie,F),se=Vp(P/ze),we=se*Re+(se-1)*he-te;return{bottom:te,itemHeight:Re,items:F,itemWidth:Ce,offsetBottom:we,offsetTop:Se,top:Se}})),O),Te(Z(U,xe(P=>P!==null),me(P=>P.length)),R),Te(Z(ut(I,x,O,W),xe(([P,j,{items:ne}])=>ne.length>0&&j.height!==0&&P.height!==0),me(([P,j,{items:ne},oe])=>{const{bottom:ie,top:Oe}=Kp(P,oe,j,ne);return[Oe,ie]}),rt(Fr)),e);const q=ae(!1);Te(Z(c,Be(q),me(([P,j])=>j||P!==0)),q);const X=wt(Z(ut(O,R),xe(([{items:P}])=>P.length>0),Be(q),xe(([[P,j],ne])=>{const oe=P.items[P.items.length-1].index===j-1;return(ne||P.bottom>0&&P.itemHeight>0&&P.offsetBottom===0&&P.items.length===j)&&oe}),me(([[,P]])=>P-1),rt())),re=wt(Z(Ae(O),xe(({items:P})=>P.length>0&&P[0].index===0),nn(0),rt())),le=wt(Z(Ae(O),Be(L),xe(([{items:P},j])=>P.length>0&&!j),me(([{items:P}])=>({endIndex:P[P.length-1].index,startIndex:P[0].index})),rt(pp),En(0)));Te(le,m.scrollSeekRangeChanged),Te(Z(M,Be(I,x,R,W),me(([P,j,ne,oe,ie])=>{const Oe=bp(P),{align:be,behavior:ye,offset:fe}=Oe;let Le=Oe.index;Le==="LAST"&&(Le=oe-1),Le=zr(0,Le,qo(oe-1,Le));let ce=Vo(j,ie,ne,Le);return be==="end"?ce=zp(ce-j.height+ne.height):be==="center"&&(ce=zp(ce-j.height/2+ne.height/2)),fe&&(ce+=fe),{behavior:ye,top:ce}})),l);const H=ft(Z(O,me(P=>P.offsetBottom+P.bottom)),0);return Te(Z(v,me(P=>({height:P.visibleHeight,width:P.visibleWidth}))),I),{customScrollParent:g,data:U,deviation:z,footerHeight:a,gap:W,headerHeight:i,increaseViewportBy:t,initialItemCount:N,itemDimensions:x,overscan:n,restoreStateFrom:B,scrollBy:o,scrollContainerState:s,scrollHeight:Y,scrollTo:l,scrollToIndex:M,scrollTop:c,smoothScrollTargetReached:d,totalCount:R,useWindowScroll:S,viewportDimensions:I,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:v,...m,gridState:O,horizontalDirection:J,initialTopMostItemIndex:k,totalListHeight:H,...p,endReached:X,propsReady:f,rangeChanged:le,startReached:re,stateChanged:D,stateRestoreInProgress:L,...C}},nt(Po,Rt,Vr,xp,Nn,Uo,Rn));function Wp(t,e,n){return zr(1,Ya((t+n)/(Ya(e)+n)))}function Kp(t,e,n,r){const{height:a}=n;if(a===void 0||r.length===0)return{bottom:0,top:0};const i=Vo(t,e,n,r[0].index);return{bottom:Vo(t,e,n,r[r.length-1].index)+a,top:i}}function Vo(t,e,n,r){const a=Wp(t.width,n.width,e.column),i=Ya(r/a),o=i*n.height+zr(0,i-1)*e.row;return o>0?o+e.row:o}const sO=$e(()=>{const t=ae(_=>`Item ${_}`),e=ae({}),n=ae(null),r=ae("virtuoso-grid-item"),a=ae("virtuoso-grid-list"),i=ae(Yo),o=ae("div"),s=ae(sr),l=(_,p=null)=>ft(Z(e,me(m=>m[_]),rt()),p),c=ae(!1),d=ae(!1);return Te(Ae(d),c),{components:e,computeItemKey:i,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:o,itemClassName:r,ItemComponent:l("Item","div"),itemContent:t,listClassName:a,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),lO=$e(([t,e])=>({...t,...e}),nt(oO,sO)),cO=y.memo(function(){const t=at("gridState"),e=at("listClassName"),n=at("itemClassName"),r=at("itemContent"),a=at("computeItemKey"),i=at("isSeeking"),o=Yt("scrollHeight"),s=at("ItemComponent"),l=at("ListComponent"),c=at("ScrollSeekPlaceholder"),d=at("context"),_=Yt("itemDimensions"),p=Yt("gap"),m=at("log"),E=at("stateRestoreInProgress"),f=Yt("reportReadyState"),g=Yn(y.useMemo(()=>S=>{const b=S.parentElement.parentElement.scrollHeight;o(b);const h=S.firstChild;if(h){const{height:v,width:C}=h.getBoundingClientRect();_({height:v,width:C})}p({column:jp("column-gap",getComputedStyle(S).columnGap,m),row:jp("row-gap",getComputedStyle(S).rowGap,m)})},[o,_,p,m]),!0,!1);return kp(()=>{t.itemHeight>0&&t.itemWidth>0&&f(!0)},[t]),E?null:u.jsx(l,{className:e,ref:g,...St(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(S=>{const b=a(S.index,S.data,d);return i?u.jsx(c,{...St(c,d),height:t.itemHeight,index:S.index,width:t.itemWidth},b):y.createElement(s,{...St(s,d),className:n,"data-index":S.index,key:b},r(S.index,S.data,d))})})}),dO=y.memo(function(){const t=at("HeaderComponent"),e=Yt("headerHeight"),n=at("headerFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,!1),a=at("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null}),uO=y.memo(function(){const t=at("FooterComponent"),e=Yt("footerHeight"),n=at("headerFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,!1),a=at("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null}),_O=({children:t})=>{const e=y.useContext(Pp),n=Yt("itemDimensions"),r=Yt("viewportDimensions"),a=Yn(y.useMemo(()=>i=>{r(i.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{e&&(r({height:e.viewportHeight,width:e.viewportWidth}),n({height:e.itemHeight,width:e.itemWidth}))},[e,r,n]),u.jsx("div",{ref:a,style:Ga(!1),children:t})},pO=({children:t})=>{const e=y.useContext(Pp),n=Yt("windowViewportRect"),r=Yt("itemDimensions"),a=at("customScrollParent"),i=op(n,a,!1);return y.useEffect(()=>{e&&(r({height:e.itemHeight,width:e.itemWidth}),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:e.viewportWidth}))},[e,n,r]),u.jsx("div",{ref:i,style:Ga(!1),children:t})},mO=y.memo(function({...t}){const e=at("useWindowScroll"),n=at("customScrollParent"),r=n||e?EO:gO,a=n||e?pO:_O,i=at("context");return u.jsx(r,{...t,...St(r,i),children:u.jsxs(a,{children:[u.jsx(dO,{}),u.jsx(cO,{}),u.jsx(uO,{})]})})}),{useEmitter:Qp,useEmitterValue:at,usePublisher:Yt}=Mp(lO,{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"}},mO),gO=Yp({useEmitter:Qp,useEmitterValue:at,usePublisher:Yt}),EO=Hp({useEmitter:Qp,useEmitterValue:at,usePublisher:Yt});function jp(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,At.WARN),e==="normal"?0:parseInt(e??"0",10)}const fO=yr.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 Xp({className:t,variant:e,...n}){return u.jsx("div",{className:K(fO({variant:e}),t),...n})}function de(t,e,{checkForDefaultPrevented:n=!0}={}){return function(a){if(t==null||t(a),n===!1||!a.defaultPrevented)return e==null?void 0:e(a)}}function SO(t,e){const n=T.createContext(e),r=i=>{const{children:o,...s}=i,l=T.useMemo(()=>s,Object.values(s));return u.jsx(n.Provider,{value:l,children:o})};r.displayName=t+"Provider";function a(i){const o=T.useContext(n);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${i}\` must be used within \`${t}\``)}return[r,a]}function Kt(t,e=[]){let n=[];function r(i,o){const s=T.createContext(o),l=n.length;n=[...n,o];const c=_=>{var S;const{scope:p,children:m,...E}=_,f=((S=p==null?void 0:p[t])==null?void 0:S[l])||s,g=T.useMemo(()=>E,Object.values(E));return u.jsx(f.Provider,{value:g,children:m})};c.displayName=i+"Provider";function d(_,p){var f;const m=((f=p==null?void 0:p[t])==null?void 0:f[l])||s,E=T.useContext(m);if(E)return E;if(o!==void 0)return o;throw new Error(`\`${_}\` must be used within \`${i}\``)}return[c,d]}const a=()=>{const i=n.map(o=>T.createContext(o));return function(s){const l=(s==null?void 0:s[t])||i;return T.useMemo(()=>({[`__scope${t}`]:{...s,[t]:l}}),[s,l])}};return a.scopeName=t,[r,bO(a,...e)]}function bO(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(i){const o=r.reduce((s,{useScope:l,scopeName:c})=>{const _=l(i)[`__scope${c}`];return{...s,..._}},{});return T.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return n.scopeName=e.scopeName,n}var mt=globalThis!=null&&globalThis.document?T.useLayoutEffect:()=>{},TO=T[" useInsertionEffect ".trim().toString()]||mt;function On({prop:t,defaultProp:e,onChange:n=()=>{},caller:r}){const[a,i,o]=hO({defaultProp:e,onChange:n}),s=t!==void 0,l=s?t:a;{const d=T.useRef(t!==void 0);T.useEffect(()=>{const _=d.current;_!==s&&console.warn(`${r} is changing from ${_?"controlled":"uncontrolled"} to ${s?"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=s},[s,r])}const c=T.useCallback(d=>{var _;if(s){const p=CO(d)?d(t):d;p!==t&&((_=o.current)==null||_.call(o,p))}else i(d)},[s,t,i,o]);return[l,c]}function hO({defaultProp:t,onChange:e}){const[n,r]=T.useState(t),a=T.useRef(n),i=T.useRef(e);return TO(()=>{i.current=e},[e]),T.useEffect(()=>{var o;a.current!==n&&((o=i.current)==null||o.call(i,n),a.current=n)},[n,a]),[n,r,i]}function CO(t){return typeof t=="function"}function Zp(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function zo(...t){return e=>{let n=!1;const r=t.map(a=>{const i=Zp(a,e);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():Zp(t[a],null)}}}}function Ge(...t){return T.useCallback(zo(...t),t)}var RO=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],De=RO.reduce((t,e)=>{const n=Dt.createSlot(`Primitive.${e}`),r=T.forwardRef((a,i)=>{const{asChild:o,...s}=a,l=o?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...s,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function Jp(t,e){t&&Ea.flushSync(()=>t.dispatchEvent(e))}function vO(t,e){return T.useReducer((n,r)=>e[n][r]??n,t)}var xt=t=>{const{present:e,children:n}=t,r=NO(e),a=typeof n=="function"?n({present:r.isPresent}):T.Children.only(n),i=Ge(r.ref,OO(a));return typeof n=="function"||r.isPresent?T.cloneElement(a,{ref:i}):null};xt.displayName="Presence";function NO(t){const[e,n]=T.useState(),r=T.useRef(null),a=T.useRef(t),i=T.useRef("none"),o=t?"mounted":"unmounted",[s,l]=vO(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return T.useEffect(()=>{const c=qa(r.current);i.current=s==="mounted"?c:"none"},[s]),mt(()=>{const c=r.current,d=a.current;if(d!==t){const p=i.current,m=qa(c);t?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),a.current=t}},[t,l]),mt(()=>{if(e){let c;const d=e.ownerDocument.defaultView??window,_=m=>{const f=qa(r.current).includes(CSS.escape(m.animationName));if(m.target===e&&f&&(l("ANIMATION_END"),!a.current)){const g=e.style.animationFillMode;e.style.animationFillMode="forwards",c=d.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=g)})}},p=m=>{m.target===e&&(i.current=qa(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",_),e.addEventListener("animationend",_),()=>{d.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",_),e.removeEventListener("animationend",_)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:T.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function qa(t){return(t==null?void 0:t.animationName)||"none"}function OO(t){var r,a;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(a=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:a.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var yO=T[" useId ".trim().toString()]||(()=>{}),IO=0;function Qt(t){const[e,n]=T.useState(yO());return mt(()=>{n(r=>r??String(IO++))},[t]),t||(e?`radix-${e}`:"")}var Va="Collapsible",[AO,J0]=Kt(Va),[xO,$o]=AO(Va),em=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,open:r,defaultOpen:a,disabled:i,onOpenChange:o,...s}=t,[l,c]=On({prop:r,defaultProp:a??!1,onChange:o,caller:Va});return u.jsx(xO,{scope:n,disabled:i,contentId:Qt(),open:l,onOpenToggle:T.useCallback(()=>c(d=>!d),[c]),children:u.jsx(De.div,{"data-state":Ko(l),"data-disabled":i?"":void 0,...s,ref:e})})});em.displayName=Va;var tm="CollapsibleTrigger",nm=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,...r}=t,a=$o(tm,n);return u.jsx(De.button,{type:"button","aria-controls":a.contentId,"aria-expanded":a.open||!1,"data-state":Ko(a.open),"data-disabled":a.disabled?"":void 0,disabled:a.disabled,...r,ref:e,onClick:de(t.onClick,a.onOpenToggle)})});nm.displayName=tm;var Wo="CollapsibleContent",DO=T.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=$o(Wo,t.__scopeCollapsible);return u.jsx(xt,{present:n||a.open,children:({present:i})=>u.jsx(wO,{...r,ref:e,present:i})})});DO.displayName=Wo;var wO=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,present:r,children:a,...i}=t,o=$o(Wo,n),[s,l]=T.useState(r),c=T.useRef(null),d=Ge(e,c),_=T.useRef(0),p=_.current,m=T.useRef(0),E=m.current,f=o.open||s,g=T.useRef(f),S=T.useRef(void 0);return T.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),mt(()=>{const b=c.current;if(b){S.current=S.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const h=b.getBoundingClientRect();_.current=h.height,m.current=h.width,g.current||(b.style.transitionDuration=S.current.transitionDuration,b.style.animationName=S.current.animationName),l(r)}},[o.open,r]),u.jsx(De.div,{"data-state":Ko(o.open),"data-disabled":o.disabled?"":void 0,id:o.contentId,hidden:!f,...i,ref:d,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...t.style},children:f&&a})});function Ko(t){return t?"open":"closed"}var MO=em;const rm=MO,am=nm,im=new URL("data:video/mp2t;base64,Ly8vIDxyZWZlcmVuY2UgbGliPSJ3ZWJ3b3JrZXIiIC8+CmltcG9ydCBtYXJrZWQgZnJvbSAnbWFya2VkJzsKCmRlY2xhcmUgY29uc3Qgc2VsZjogRGVkaWNhdGVkV29ya2VyR2xvYmFsU2NvcGU7CmNvbnN0IHNjb3BlOiBEZWRpY2F0ZWRXb3JrZXJHbG9iYWxTY29wZSA9IHNlbGY7CgpzY29wZS5wb3N0TWVzc2FnZT8uKHsgd29ya2VyX3JlYWR5OiB0cnVlIH0pOwoKc2NvcGUuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIChldmVudDogTWVzc2FnZUV2ZW50KSA9PiB7CiAgY29uc3QgcGF5bG9hZDogYW55ID0gZXZlbnQ/LmRhdGEgPz8ge307CiAgY29uc3QgaWQgPSB0eXBlb2YgcGF5bG9hZC5pZCA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLmlkIDogdW5kZWZpbmVkOwogIGNvbnN0IGtleSA9IHR5cGVvZiBwYXlsb2FkLmtleSA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLmtleSA6IHVuZGVmaW5lZDsKICBjb25zdCBzb3VyY2UgPSB0eXBlb2YgcGF5bG9hZC5zb3VyY2UgPT09ICdzdHJpbmcnID8gcGF5bG9hZC5zb3VyY2UgOiB1bmRlZmluZWQ7CiAgaWYgKCFpZCB8fCB0eXBlb2Ygc291cmNlICE9PSAnc3RyaW5nJykgcmV0dXJuOwoKICB0cnkgewogICAgY29uc3QgaHRtbCA9IG1hcmtlZC5wYXJzZShzb3VyY2UpOwogICAgc2NvcGUucG9zdE1lc3NhZ2UoeyBpZCwga2V5LCBodG1sIH0pOwogIH0gY2F0Y2ggKGVycikgewogICAgc2NvcGUucG9zdE1lc3NhZ2UoeyBpZCwga2V5LCBodG1sOiBgPHByZT5FcnJvciByZW5kZXJpbmcgbWFya2Rvd246ICR7U3RyaW5nKGVycil9PC9wcmU+YCB9KTsKICB9Cn0pOwo=",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:ro&&ro.tagName.toUpperCase()==="SCRIPT"&&ro.src||new URL("index.umd.js",document.baseURI).href),$r=im.toString(),LO=(()=>{try{if(typeof Worker>"u"||typeof URL>"u"||typeof Blob>"u")return!1;const t=new Blob(["export default null;"],{type:"application/javascript"}),e=URL.createObjectURL(t);return new Worker(e,{type:"module"}).terminate(),URL.revokeObjectURL(e),!0}catch{return!1}})(),PO=$r.includes("data:"),kO=(()=>{if(typeof navigator>"u")return!1;const t=navigator.userAgent.toLowerCase();return t.includes("safari")&&!t.includes("chrome")&&!t.includes("android")})(),Qo=LO&&!(PO&&kO),jo=t=>typeof t=="object"&&t!==null,Xo=t=>typeof t=="function"?t:jo(t)&&typeof t.parse=="function"?t.parse:null;let za=null;async function om(t){try{za||(za=Promise.resolve().then(()=>KM));const e=await za,n=jo(e)?e:{},r=Xo(n.parse)??Xo(n.marked)??Xo(n.default);return r?r(t):""}catch(e){throw za=null,e}}const UO=t=>jo(t)&&typeof t.highlightElement=="function"?{highlightElement:t.highlightElement}:null;console.log("[MarkdownContent] worker url",$r);const Wr=[];let Kr=!1;const sm={addEventListener:()=>{},removeEventListener:()=>{},postMessage:()=>{},terminate:()=>{}};let yn=sm;const lm=t=>{console.error("[MarkdownContent] worker error",t)};function Zo(t){if(yn&&yn!==sm)try{yn.removeEventListener("error",lm)}catch{}yn=t,Kr=!0;try{yn.addEventListener("error",lm)}catch(e){console.warn("[MarkdownContent] failed to register worker error handler",e)}try{for(;Wr.length;){const e=Wr.shift();if(e)try{e()}catch{}}}catch(e){console.warn("[MarkdownContent] markWorkerOnline notify failed",e)}}function FO(t){if(!Qo)return null;const e=t.indexOf("data:");if(e===-1)return null;const r=t.slice(e).match(/^data:[^;]+;base64,(.*)$/);if(!r)return null;try{const a=r[1],i=atob(a),o=Uint8Array.from(i,c=>c.charCodeAt(0)),s=new Blob([o],{type:"application/javascript"}),l=URL.createObjectURL(s);try{const c=new Worker(l,{type:"module"});return URL.revokeObjectURL(l),c}catch(c){return URL.revokeObjectURL(l),console.error("[MarkdownContent] failed to initialize worker from data URI blob",c),null}}catch(a){return console.warn("[MarkdownContent] failed to decode embedded data URI",a),null}}async function BO(t){if(Qo)try{let e="";const n=await fetch(t);if(e=await n.text(),n.ok||console.warn("[MarkdownContent] fetch worker non-ok",n.status,n.statusText),!e){console.warn("[MarkdownContent] worker fetch returned empty content; aborting worker init.");return}if(e.trim().startsWith("<")){console.warn("[MarkdownContent] worker fetch returned HTML; dev server may be redirecting. Aborting worker init.");return}const r=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(r);try{const i=new Worker(a,{type:"module"});Zo(i)}catch(i){console.error("[MarkdownContent] failed to initialize worker from blob",i)}finally{URL.revokeObjectURL(a)}}catch(e){console.error("[MarkdownContent] fetch worker failed",e)}}function GO(){if($r.includes("data:")){const t=FO($r);if(t){Zo(t);return}console.warn("[MarkdownContent] data URI bootstrap failed; worker will remain offline until fallback succeeds");return}try{const t=new Worker(im,{type:"module"});Zo(t)}catch(t){console.warn("[MarkdownContent] worker constructor failed, will try fetch+blob fallback",t),BO($r)}}Qo?GO():console.warn("[MarkdownContent] module workers not supported; falling back to main-thread markdown parsing");const Qr=new Map;function YO(t,e=!1){if(e){const a=t.slice(0,128);return`streaming:${Math.floor(t.length/50)*50}:${a}`}const n=t.slice(0,64),r=t.length>64?t.slice(-64):"";return`${t.length}:${n}:${r}`}function HO(t,e){const[n,r]=y.useState(t),a=y.useRef(t),i=y.useRef(null);return y.useEffect(()=>{if(!e){r(t);return}return a.current=t,i.current===null&&(i.current=requestAnimationFrame(()=>{i.current=null,r(a.current)})),()=>{i.current&&cancelAnimationFrame(i.current)}},[t,e]),n}function $a({content:t,className:e="",fallback:n=u.jsx("div",{"aria-busy":!0,children:"Rendering…"}),isStreaming:r=!1,hideFallbackDuringStreaming:a=!0,streamingThrottleMs:i=16,useWorker:o}){const s=HO(t,r),l=YO(s,r),[c,d]=y.useState(()=>{var E;return((E=Qr.get(l))==null?void 0:E.html)??null}),_=y.useRef(null),p=y.useRef([]);y.useEffect(()=>{p.current=[];const E=Qr.get(l);if(E&&E.source===s){E.html!==c&&d(E.html);return}if(E&&E.html!==c&&d(E.html),!(o!==void 0?o:Kr&&!r)){console.log(`[MarkdownContent] Using main-thread parsing (streaming: ${r}, worker: ${o})`);let I=!1;return(async()=>{try{const x=await om(s);Qr.set(l,{html:x,source:s}),I||d(x)}catch(x){console.error("[MarkdownContent] fallback parse failed",x)}})(),()=>{I=!0}}let g=!0,S=!1;const b=`${l}::${Date.now().toString(36)}::${Math.random().toString(36).slice(2)}`;_.current=b;const h=I=>{const x=I.data;if(!x||x.id!==b||x.key&&x.key!==l||!g)return;S=!0;const M=x.html??"";Qr.set(l,{html:M,source:s}),d(M)};yn.addEventListener("message",h);const v=()=>{try{yn.postMessage({id:b,key:l,source:s})}catch(I){console.error("[MarkdownContent] worker.postMessage threw",I)}},C=()=>{if(!r||i<=0){v();return}if(typeof window>"u"){v();return}const I=window.setTimeout(()=>{if(typeof window.requestAnimationFrame=="function"){const x=window.requestAnimationFrame(()=>{v()});p.current.push({type:"raf",id:x})}else v()},i);p.current.push({type:"timeout",id:I})};Kr?C():Wr.push(C);const N=((I,x,M)=>x?M?I>2e4?15e3:I>8e3?8e3:I>2e3?3e3:1e3:I>2e4?1e4:I>8e3?5e3:I>2e3?2e3:600:Math.min(15e3,2e3+Math.floor(I*.5)))(s.length,Kr,r),O=window.setTimeout(async()=>{if(!S){console.warn("[MarkdownContent] worker timeout (ms="+N+"), falling back to main-thread parse for",l);try{const I=await om(s);Qr.set(l,{html:I,source:s}),g&&_.current===b&&d(I)}catch(I){console.error("[MarkdownContent] fallback parse failed",I)}}},N);return()=>{if(g=!1,clearTimeout(O),yn.removeEventListener("message",h),_.current===b&&(_.current=null),!Kr){const I=Wr.indexOf(C);I>=0&&Wr.splice(I,1)}p.current.forEach(I=>{I.type==="timeout"?clearTimeout(I.id):I.type==="raf"&&cancelAnimationFrame(I.id)}),p.current=[]}},[s,c,r,l,i]);const m=y.useRef(null);return y.useEffect(()=>{if(!c)return;const E=m.current;if(!E)return;const f=Array.from(E.querySelectorAll("pre code"));if(!f.length)return;let g=null,S=!1;const b=(v,C)=>{for(const R of v){if(!R.isIntersecting)continue;const N=R.target;if(!g)Promise.resolve().then(()=>S0).then(O=>{if(S)return;const I=UO(O.default??O);if(I){g=I;try{f.forEach(x=>{E.contains(x)&&(g==null||g.highlightElement(x))})}catch{}}}).catch(()=>{});else try{g.highlightElement(N)}catch{}C.unobserve(N)}},h=new IntersectionObserver(b,{root:E,threshold:.1});return f.forEach(v=>h.observe(v)),()=>{S=!0,h.disconnect()}},[c]),c?u.jsx("div",{ref:m,className:K("markdown prose max-w-none break-words dark:prose-invert",e),dangerouslySetInnerHTML:{__html:c}}):r&&a?null:u.jsx("div",{className:K("markdown prose max-w-none break-words dark:prose-invert",e),children:n})}async function cm(t,e){return await Ft(t,{responseType:"blob",onDownloadProgress:r=>{try{e&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function dm(t,e){return await(await cm(`/chat/files/${t}/view`,e)).text()}async function qO(t,e){const n=await cm(`/chat/files/${t}/download`,e),r=URL.createObjectURL(n);let a=`file_${t}`;try{const o=await Ft(`/chat/files/${t}`);a=(o==null?void 0:o.filename)??a}catch{}const i=document.createElement("a");i.href=r,i.download=a,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}const VO=1,zO=1e6;let Jo=0;function $O(){return Jo=(Jo+1)%Number.MAX_SAFE_INTEGER,Jo.toString()}const es=new Map,um=t=>{if(es.has(t))return;const e=setTimeout(()=>{es.delete(t),jr({type:"REMOVE_TOAST",toastId:t})},zO);es.set(t,e)},WO=(t,e)=>{switch(e.type){case"ADD_TOAST":return{...t,toasts:[e.toast,...t.toasts].slice(0,VO)};case"UPDATE_TOAST":return{...t,toasts:t.toasts.map(n=>n.id===e.toast.id?{...n,...e.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=e;return n?um(n):t.toasts.forEach(r=>{um(r.id)}),{...t,toasts:t.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return e.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(n=>n.id!==e.toastId)}}},Wa=[];let Ka={toasts:[]};function jr(t){Ka=WO(Ka,t),Wa.forEach(e=>{e(Ka)})}function KO({...t}){const e=$O(),n=a=>jr({type:"UPDATE_TOAST",toast:{...a,id:e}}),r=()=>jr({type:"DISMISS_TOAST",toastId:e});return jr({type:"ADD_TOAST",toast:{...t,id:e,open:!0,onOpenChange:a=>{a||r()}}}),{id:e,dismiss:r,update:n}}function ts(){const[t,e]=T.useState(Ka);return T.useEffect(()=>(Wa.push(e),()=>{const n=Wa.indexOf(e);n>-1&&Wa.splice(n,1)}),[t]),{...t,toast:KO,dismiss:n=>jr({type:"DISMISS_TOAST",toastId:n})}}function gt(t){const e=T.useRef(t);return T.useEffect(()=>{e.current=t}),T.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function QO(t,e=globalThis==null?void 0:globalThis.document){const n=gt(t);T.useEffect(()=>{const r=a=>{a.key==="Escape"&&n(a)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var jO="DismissableLayer",ns="dismissableLayer.update",XO="dismissableLayer.pointerDownOutside",ZO="dismissableLayer.focusOutside",_m,pm=T.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Xr=T.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:a,onFocusOutside:i,onInteractOutside:o,onDismiss:s,...l}=t,c=T.useContext(pm),[d,_]=T.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=T.useState({}),E=Ge(e,N=>_(N)),f=Array.from(c.layers),[g]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=f.indexOf(g),b=d?f.indexOf(d):-1,h=c.layersWithOutsidePointerEventsDisabled.size>0,v=b>=S,C=ty(N=>{const O=N.target,I=[...c.branches].some(x=>x.contains(O));!v||I||(a==null||a(N),o==null||o(N),N.defaultPrevented||s==null||s())},p),R=ny(N=>{const O=N.target;[...c.branches].some(x=>x.contains(O))||(i==null||i(N),o==null||o(N),N.defaultPrevented||s==null||s())},p);return QO(N=>{b===c.layers.size-1&&(r==null||r(N),!N.defaultPrevented&&s&&(N.preventDefault(),s()))},p),T.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(_m=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),mm(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=_m)}},[d,p,n,c]),T.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),mm())},[d,c]),T.useEffect(()=>{const N=()=>m({});return document.addEventListener(ns,N),()=>document.removeEventListener(ns,N)},[]),u.jsx(De.div,{...l,ref:E,style:{pointerEvents:h?v?"auto":"none":void 0,...t.style},onFocusCapture:de(t.onFocusCapture,R.onFocusCapture),onBlurCapture:de(t.onBlurCapture,R.onBlurCapture),onPointerDownCapture:de(t.onPointerDownCapture,C.onPointerDownCapture)})});Xr.displayName=jO;var JO="DismissableLayerBranch",ey=T.forwardRef((t,e)=>{const n=T.useContext(pm),r=T.useRef(null),a=Ge(e,r);return T.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),u.jsx(De.div,{...t,ref:a})});ey.displayName=JO;function ty(t,e=globalThis==null?void 0:globalThis.document){const n=gt(t),r=T.useRef(!1),a=T.useRef(()=>{});return T.useEffect(()=>{const i=s=>{if(s.target&&!r.current){let l=function(){gm(XO,n,c,{discrete:!0})};const c={originalEvent:s};s.pointerType==="touch"?(e.removeEventListener("click",a.current),a.current=l,e.addEventListener("click",a.current,{once:!0})):l()}else e.removeEventListener("click",a.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",i),e.removeEventListener("click",a.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function ny(t,e=globalThis==null?void 0:globalThis.document){const n=gt(t),r=T.useRef(!1);return T.useEffect(()=>{const a=i=>{i.target&&!r.current&&gm(ZO,n,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",a),()=>e.removeEventListener("focusin",a)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function mm(){const t=new CustomEvent(ns);document.dispatchEvent(t)}function gm(t,e,n,{discrete:r}){const a=n.originalEvent.target,i=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&a.addEventListener(t,e,{once:!0}),r?Jp(a,i):a.dispatchEvent(i)}var rs="focusScope.autoFocusOnMount",as="focusScope.autoFocusOnUnmount",Em={bubbles:!1,cancelable:!0},ry="FocusScope",Qa=T.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:i,...o}=t,[s,l]=T.useState(null),c=gt(a),d=gt(i),_=T.useRef(null),p=Ge(e,f=>l(f)),m=T.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;T.useEffect(()=>{if(r){let f=function(h){if(m.paused||!s)return;const v=h.target;s.contains(v)?_.current=v:In(_.current,{select:!0})},g=function(h){if(m.paused||!s)return;const v=h.relatedTarget;v!==null&&(s.contains(v)||In(_.current,{select:!0}))},S=function(h){if(document.activeElement===document.body)for(const C of h)C.removedNodes.length>0&&In(s)};document.addEventListener("focusin",f),document.addEventListener("focusout",g);const b=new MutationObserver(S);return s&&b.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",f),document.removeEventListener("focusout",g),b.disconnect()}}},[r,s,m.paused]),T.useEffect(()=>{if(s){bm.add(m);const f=document.activeElement;if(!s.contains(f)){const S=new CustomEvent(rs,Em);s.addEventListener(rs,c),s.dispatchEvent(S),S.defaultPrevented||(ay(cy(fm(s)),{select:!0}),document.activeElement===f&&In(s))}return()=>{s.removeEventListener(rs,c),setTimeout(()=>{const S=new CustomEvent(as,Em);s.addEventListener(as,d),s.dispatchEvent(S),S.defaultPrevented||In(f??document.body,{select:!0}),s.removeEventListener(as,d),bm.remove(m)},0)}}},[s,c,d,m]);const E=T.useCallback(f=>{if(!n&&!r||m.paused)return;const g=f.key==="Tab"&&!f.altKey&&!f.ctrlKey&&!f.metaKey,S=document.activeElement;if(g&&S){const b=f.currentTarget,[h,v]=iy(b);h&&v?!f.shiftKey&&S===v?(f.preventDefault(),n&&In(h,{select:!0})):f.shiftKey&&S===h&&(f.preventDefault(),n&&In(v,{select:!0})):S===b&&f.preventDefault()}},[n,r,m.paused]);return u.jsx(De.div,{tabIndex:-1,...o,ref:p,onKeyDown:E})});Qa.displayName=ry;function ay(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(In(r,{select:e}),document.activeElement!==n)return}function iy(t){const e=fm(t),n=Sm(e,t),r=Sm(e.reverse(),t);return[n,r]}function fm(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function Sm(t,e){for(const n of t)if(!oy(n,{upTo:e}))return n}function oy(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function sy(t){return t instanceof HTMLInputElement&&"select"in t}function In(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&sy(t)&&e&&t.select()}}var bm=ly();function ly(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=Tm(t,e),t.unshift(e)},remove(e){var n;t=Tm(t,e),(n=t[0])==null||n.resume()}}}function Tm(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function cy(t){return t.filter(e=>e.tagName!=="A")}var dy="Portal",ja=T.forwardRef((t,e)=>{var s;const{container:n,...r}=t,[a,i]=T.useState(!1);mt(()=>i(!0),[]);const o=n||a&&((s=globalThis==null?void 0:globalThis.document)==null?void 0:s.body);return o?no.createPortal(u.jsx(De.div,{...r,ref:e}),o):null});ja.displayName=dy;var is=0;function os(){T.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??hm()),document.body.insertAdjacentElement("beforeend",t[1]??hm()),is++,()=>{is===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),is--}},[])}function hm(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var on=function(){return on=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},on.apply(this,arguments)};function Cm(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function uy(t,e,n){if(n||arguments.length===2)for(var r=0,a=e.length,i;r<a;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;var Xa="right-scroll-bar-position",Za="width-before-scroll-bar",_y="with-scroll-bars-hidden",py="--removed-body-scroll-bar-size";function ss(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function my(t,e){var n=y.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=e,n.facade}var gy=typeof window<"u"?T.useLayoutEffect:T.useEffect,Rm=new WeakMap;function Ey(t,e){var n=my(null,function(r){return t.forEach(function(a){return ss(a,r)})});return gy(function(){var r=Rm.get(n);if(r){var a=new Set(r),i=new Set(t),o=n.current;a.forEach(function(s){i.has(s)||ss(s,null)}),i.forEach(function(s){a.has(s)||ss(s,o)})}Rm.set(n,t)},[t]),n}function fy(t){return t}function Sy(t,e){e===void 0&&(e=fy);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:t},useMedium:function(i){var o=e(i,r);return n.push(o),function(){n=n.filter(function(s){return s!==o})}},assignSyncMedium:function(i){for(r=!0;n.length;){var o=n;n=[],o.forEach(i)}n={push:function(s){return i(s)},filter:function(){return n}}},assignMedium:function(i){r=!0;var o=[];if(n.length){var s=n;n=[],s.forEach(i),o=n}var l=function(){var d=o;o=[],d.forEach(i)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){o.push(d),c()},filter:function(d){return o=o.filter(d),n}}}};return a}function by(t){t===void 0&&(t={});var e=Sy(null);return e.options=on({async:!0,ssr:!1},t),e}var vm=function(t){var e=t.sideCar,n=Cm(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return T.createElement(r,on({},n))};vm.isSideCarExport=!0;function Ty(t,e){return t.useMedium(e),vm}var Nm=by(),ls=function(){},Ja=T.forwardRef(function(t,e){var n=T.useRef(null),r=T.useState({onScrollCapture:ls,onWheelCapture:ls,onTouchMoveCapture:ls}),a=r[0],i=r[1],o=t.forwardProps,s=t.children,l=t.className,c=t.removeScrollBar,d=t.enabled,_=t.shards,p=t.sideCar,m=t.noRelative,E=t.noIsolation,f=t.inert,g=t.allowPinchZoom,S=t.as,b=S===void 0?"div":S,h=t.gapMode,v=Cm(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,R=Ey([n,e]),N=on(on({},v),a);return T.createElement(T.Fragment,null,d&&T.createElement(C,{sideCar:Nm,removeScrollBar:c,shards:_,noRelative:m,noIsolation:E,inert:f,setCallbacks:i,allowPinchZoom:!!g,lockRef:n,gapMode:h}),o?T.cloneElement(T.Children.only(s),on(on({},N),{ref:R})):T.createElement(b,on({},N,{className:l,ref:R}),s))});Ja.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ja.classNames={fullWidth:Za,zeroRight:Xa};var hy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Cy(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=hy();return e&&t.setAttribute("nonce",e),t}function Ry(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function vy(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Ny=function(){var t=0,e=null;return{add:function(n){t==0&&(e=Cy())&&(Ry(e,n),vy(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Oy=function(){var t=Ny();return function(e,n){T.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},Om=function(){var t=Oy(),e=function(n){var r=n.styles,a=n.dynamic;return t(r,a),null};return e},yy={left:0,top:0,right:0,gap:0},cs=function(t){return parseInt(t||"",10)||0},Iy=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],a=e[t==="padding"?"paddingRight":"marginRight"];return[cs(n),cs(r),cs(a)]},Ay=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return yy;var e=Iy(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},xy=Om(),cr="data-scroll-locked",Dy=function(t,e,n,r){var a=t.left,i=t.top,o=t.right,s=t.gap;return n===void 0&&(n="margin"),`
|
|
38
|
+
`)}const Lv={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};function Pv(t,e){var n;switch(e.type){case"reset":return{messages:To(((n=e.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};case"seed":{const r=To(e.payload.messages),a={...t,messages:[...r,...t.messages],assemblingId:null};return Object.prototype.hasOwnProperty.call(e.payload,"checkpointId")&&(a.lastCheckpointId=e.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(e.payload,"checkpointNs")&&(a.lastCheckpointNs=e.payload.checkpointNs??null),console.log("[MessageReducer] seed action:",{incomingCount:e.payload.messages.length,sanitizedCount:r.length,checkpointId:a.lastCheckpointId}),a}case"prepend":{const r=To(e.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),t;const a=new Set(t.messages.map(o=>o.id)),i=r.filter(o=>!a.has(o.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:i.length,duplicates:r.length-i.length,finalTotal:i.length+t.messages.length}),i.length?{...t,messages:[...i,...t.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),t)}case"user_message":{const r=e.payload.message;if(t.assemblingId){const a=t.messages.findIndex(i=>i.id===t.assemblingId);if(a!==-1)return{...t,messages:[...t.messages.slice(0,a),r,...t.messages.slice(a)]}}return{...t,messages:[...t.messages,r]}}case"event":return Q_(t,e.payload.ev);case"batch":{const{events:r}=e.payload;return r.length?r.reduce((a,i)=>Q_(a,i),t):t}default:return t}}function K_(t=[]){const[e,n]=y.useReducer(Pv,{...Lv,messages:t}),r=y.useRef([]),a=y.useRef(null),i=y.useRef(null),o=y.useCallback(()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),a.current=null,i.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),s=y.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?a.current===null&&(a.current=window.requestAnimationFrame(()=>o())):i.current===null&&(i.current=setTimeout(o,8))},[o]),l=y.useCallback(d=>{r.current.push(d),s()},[s]);y.useEffect(()=>()=>{a.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(a.current),i.current!==null&&clearTimeout(i.current),r.current=[]},[]);const c=y.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,_)=>n({type:"seed",payload:{messages:d,..._??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:e,dispatch:n,...c}}function Q_(t,e){var n;if(e.type==="message_start"&&e.role==="assistant"){const r=e.id,a=Gv(e.model),i={id:r,role:"assistant",name:a||void 0,model:e.model,createdAt:new Date().toISOString(),content:[]};return{...t,assemblingId:r,messages:[...t.messages,i]}}if(e.type==="token"){const r=t.assemblingId??ho(t.messages);return r?{...t,messages:Uv(t.messages,r,e.content)}:t}if(e.type==="message_delta"){const r=t.assemblingId??ho(t.messages);return r?{...t,messages:j_(t.messages,r,e.delta)}:t}if(e.type==="message_end"){const r=t.assemblingId??ho(t.messages);if(!r)return{...t,assemblingId:null};const a=t.messages,i=a.findIndex(o=>o.id===r&&o.role==="assistant");if(i>=0&&!((n=a[i].content)==null?void 0:n.some(l=>{var c;return(l==null?void 0:l.type)==="text"&&((c=l.text)==null?void 0:c.trim())}))){const l=[...a.slice(0,i),...a.slice(i+1)];return{...t,assemblingId:null,messages:l}}return t}if(e.type==="tool_start"){const r=`tool-${e.id}`,a={type:"tool_call",id:e.id,name:e.name,args:e.args},i={id:r,role:"tool",name:e.name,createdAt:new Date().toISOString(),content:[a]};return{...t,messages:[...t.messages,i],toolIndex:{...t.toolIndex,[e.id]:r}}}if(e.type==="tool_result"){const r=t.toolIndex[e.id]??`tool-${e.id}`,a={type:"tool_result",toolCallId:e.id,output:e.output,error:e.error},i=t.messages.find(l=>l.id===r),o={id:r,role:"tool",content:[a],createdAt:new Date().toISOString()},s=i?j_(t.messages,r,[a]):[...t.messages,o];return{...t,messages:s}}if(e.type==="checkpoint"){const r=e.checkpointNs??t.lastCheckpointNs??null,a=Bv(t.messages,e.checkpointId,r);return{...t,lastCheckpointId:e.checkpointId,lastCheckpointNs:r,messages:a}}if(e.type==="branch"){const r=e.checkpointId??t.lastCheckpointId,a=e.checkpointNs??t.lastCheckpointNs;return{...t,lastBranch:e,lastCheckpointId:r??null,lastCheckpointNs:a??null}}if(e.type==="error"){const r={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${e.message}`}],createdAt:new Date().toISOString()};return{...t,messages:[...t.messages,r]}}return t}function To(t){return t.filter(e=>{if(e.role!=="assistant")return!0;const n=(e.content||[]).some(a=>{var i;return a&&a.type==="text"&&((i=a.text)==null?void 0:i.trim())}),r=(e.content||[]).some(a=>a&&a.type==="image_url");return!!(n||r)})}function kv(t,e,n){return e<0||e>=t.length?t:[...t.slice(0,e),n,...t.slice(e+1)]}function ho(t){for(let e=t.length-1;e>=0;e--)if(t[e].role==="assistant")return t[e].id;return null}function Uv(t,e,n){return t.map(r=>{if(r.id!==e)return r;const a=r.content.slice(),i=a[a.length-1];return i&&i.type==="text"?i.text+=n:a.push({type:"text",text:n}),{...r,content:a}})}function j_(t,e,n){return t.map(r=>r.id===e?{...r,content:Fv(r.content,n)}:r)}function Fv(t,e){const n=t.slice();for(const r of e)if(r.type==="text"){const a=n[n.length-1];(a==null?void 0:a.type)==="text"?a.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function Bv(t,e,n){for(let r=t.length-1;r>=0;r--)if(t[r].role==="assistant"){const i={...t[r],checkpointId:e,checkpointNs:n??void 0};return kv(t,r,i)}return t}function Gv(t){if(!t)return null;const e=t.split("/");return e[e.length-1]||null}function Yv(t,e){const n=t==null?void 0:t.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],a=o=>o&&typeof o=="object"&&typeof o.checkpointId=="string"&&typeof o.createdAt=="string",i=r.filter(a).map(o=>({checkpointId:o.checkpointId,checkpointNs:o.checkpointNs??"",createdAt:o.createdAt,messagesLen:o.messagesLen??0,preview:o.preview??"",role:o.role??null,parentId:o.parentId??null,editedMessageId:o.editedMessageId??null,branchLabel:o.branchLabel??null,lastMessageId:o.lastMessageId??null,hasMessages:typeof o.hasMessages=="boolean"?o.hasMessages:void 0}));return{threadId:(t==null?void 0:t.threadId)??e??null,checkpoints:i}}async function Hv(t){return await new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{try{const a=r.result,i=new Uint8Array(a);let o="";const s=i.byteLength;for(let l=0;l<s;l++)o+=String.fromCharCode(i[l]);e(btoa(o))}catch(a){n(a)}},r.onerror=a=>n(a),r.readAsArrayBuffer(t)})}async function qv(t,e=[],n,r,a,i){const o=[],s=[];for(const l of e)try{const c=await Hv(l);s.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:o,filesInfo:s}}const X_=y.createContext(null);function Pr({children:t,apiConfig:e,onError:n,onThreadChange:r,initialThreadId:a=null,autoLoadInitial:i=!0,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader"}){const l=gn;y.useEffect(()=>{e&&l.updateConfig({baseUrl:e.baseUrl,authToken:e.apiKey})},[l,e]);const{isStreaming:c,error:d,stream:_,stop:p,setToken:m}=W_({baseUrl:l.baseUrl,token:null,headers:e==null?void 0:e.headers,streamPath:"/chat/runs/stream"}),[E,f]=y.useState(()=>typeof l.getAuthToken=="function"?l.getAuthToken():null);y.useEffect(()=>{m(typeof l.getAuthToken=="function"?l.getAuthToken():null);const V=l.onTokenChange(F=>{f(F),m(F)});return()=>{V()}},[l,m]);const g=y.useCallback(V=>{l.setAuthToken(V)},[l]),{state:S,seed:b,prepend:h,pushUser:v,onEvent:C,reset:R}=K_(),N=20,[O,I]=y.useState(!1),[x,M]=y.useState(!1),[Y,z]=y.useState(null),[U,W]=y.useState(void 0),[D,B]=y.useState(void 0),L=y.useRef(!1),k=y.useRef([]),Q=y.useCallback(V=>{V.cursor!==void 0&&z(V.cursor),V.hasMore!==void 0&&I(V.hasMore),V.checkpointId!==void 0&&W(V.checkpointId),V.checkpointNs!==void 0&&B(V.checkpointNs)},[]),$=y.useCallback((V,F)=>new Promise((te,Se)=>{const se=async()=>{if(L.current){console.warn(`[ChatProvider] Operation "${F}" queued - another operation in progress`),k.current.push(se);return}L.current=!0;try{console.log(`[ChatProvider] Executing operation: ${F}`),await V(),te()}catch(we){console.error(`[ChatProvider] Operation "${F}" failed:`,we),Se(we)}finally{L.current=!1;const we=k.current.shift();we&&we().catch(()=>{})}};L.current?(k.current.push(se),console.log(`[ChatProvider] Queued operation: ${F}`)):se().catch(we=>{Se(we)})}),[]),J=y.useCallback((V,F)=>{const te=Array.isArray(V==null?void 0:V.messages)?V.messages:[];F==="replace"?(console.log("[ChatProvider] Replacing messages, count:",te.length),b(te,{checkpointId:(V==null?void 0:V.checkpointId)??null,checkpointNs:(V==null?void 0:V.checkpointNs)??null})):F==="prepend"&&te.length?(console.log("[ChatProvider] Calling prepend with",te.length,"messages"),h(te)):console.log("[ChatProvider] Skipping prepend - empty list or wrong mode"),z((V==null?void 0:V.nextCursor)??null),I(!!(V!=null&&V.hasMore)),W(Se=>(V==null?void 0:V.checkpointId)??Se??void 0),B(Se=>(V==null?void 0:V.checkpointNs)??Se??void 0)},[b,h]),[q,X]=y.useState([]),[re,le]=y.useState(null),H=y.useCallback(async()=>{const V=await l.listThreads();X(V)},[l]),[P,j]=y.useState(!1),ne=y.useCallback(async V=>{const F=(V==null?void 0:V.maxAttempts)??5,te=(V==null?void 0:V.baseDelayMs)??500,Se=(V==null?void 0:V.timeoutMs)??2e3;if(!l.baseUrl)return!1;const se=l.baseUrl.replace(/\/+$/,""),we=["/health","/api/health","/","/api/v2/health","/api/v2/chat/health"],Ze=async ct=>{try{const Tt=new AbortController,_t=setTimeout(()=>Tt.abort(),Se),ht=await fetch(ct,{method:"GET",signal:Tt.signal});return clearTimeout(_t),ht.ok}catch{return!1}},Nt=async ct=>{try{const Tt=new AbortController,_t=setTimeout(()=>Tt.abort(),Se),ht=await fetch(ct,{method:"HEAD",signal:Tt.signal});return clearTimeout(_t),ht.ok}catch{return!1}};for(let ct=0;ct<F;ct++){console.debug(`[ChatProvider] health-check attempt ${ct+1}/${F}`);for(const _t of we){let ht=_t;se.endsWith("/api")&&_t.startsWith("/api")&&(ht=_t.replace(/^\/api/,"")||"/");const en=ht==="/"?se+"/":se+ht;if(console.debug(`[ChatProvider] checking ${en}`),await Ze(en)||_t==="/"&&await Nt(se+"/"))return j(!0),!0}const Tt=te*Math.pow(2,ct);await new Promise(_t=>setTimeout(_t,Tt))}return j(!1),!1},[l.baseUrl]);y.useEffect(()=>{let V=!0;if(!l.baseUrl){console.debug("[ChatProvider] skipping initial refreshThreads: api.baseUrl not configured");return}return(async()=>{try{const F=await ne();if(!V)return;F?H().catch(()=>{}):console.warn("[ChatProvider] backend health-check failed — skipping initial loads")}catch{}})(),()=>{V=!1}},[H,l.baseUrl,ne]),y.useEffect(()=>{r==null||r(re)},[re,r]);const oe=y.useRef(null);y.useEffect(()=>{if(a&&i){if(!l.baseUrl){console.debug("[ChatProvider] skipping initial load: api.baseUrl not configured");return}if(!P){console.debug("[ChatProvider] deferring initial load until backend health-check passes");return}oe.current!==a&&(oe.current=a,be(a).catch(()=>{}))}},[a,i,l.baseUrl,P]);const ie=y.useRef(null),Oe=y.useRef(null),be=y.useCallback(async(V,F,te)=>{await $(async()=>{if(!l.baseUrl){console.debug("[ChatProvider] skipping loadThread: api.baseUrl not configured");return}if(ie.current){console.warn(`[ChatProvider] Thread load cancelled - another thread (${ie.current}) is loading`);return}Oe.current!==null&&Oe.current!==V&&(console.log(`[ChatProvider] Thread switch detected: ${Oe.current} -> ${V}`),R([])),ie.current=V,Oe.current=V;try{Q({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0}),le(V);const se=await l.getMessages({threadId:V,checkpointId:F,checkpointNs:te,limit:N}),we=Array.isArray(se==null?void 0:se.messages)?se.messages:[];console.log("[ChatProvider] Loading thread with",we.length,"messages"),b(we,{checkpointId:(se==null?void 0:se.checkpointId)??null,checkpointNs:(se==null?void 0:se.checkpointNs)??null}),z((se==null?void 0:se.nextCursor)??null),I(!!(se!=null&&se.hasMore)),W(Ze=>(se==null?void 0:se.checkpointId)??Ze??void 0),B(Ze=>(se==null?void 0:se.checkpointNs)??Ze??void 0)}finally{ie.current=null}},`loadThread-${V}`)},[l,$,Q,b]),ye=y.useCallback(async V=>{const F=await l.listCheckpoints(V);return Yv(F,V)},[l]),fe=y.useCallback(async(V,F)=>{await $(async()=>{if(!re)throw new Error("No active thread");Q({cursor:null,hasMore:!1,checkpointId:void 0,checkpointNs:void 0});const te=await l.getMessages({threadId:re,checkpointId:V,checkpointNs:F??void 0,limit:N});J(te,"replace")},`navigateToCheckpoint-${V}`)},[l,re,J,$,Q]),Le=y.useCallback(async()=>{if(!re)throw new Error("No active thread");await be(re)},[re,be]),ce=y.useRef(!1);y.useEffect(()=>{const V=ce.current;ce.current=c,V&&!c&&re&&$(async()=>{try{await H()}catch(F){console.warn("[ChatProvider] Post-streaming thread refresh failed:",F)}},"postStreamingRefresh")},[c,re,l,J,H,$]);const he=y.useCallback(async V=>{const F=await l.createThread(V);return await H(),await be(F.threadId),F.threadId},[l,H,be]),Re=y.useCallback(async V=>{await l.deleteThread(V),await H(),re===V&&(le(null),R([]),I(!1),z(null),W(void 0),B(void 0))},[l,H,re,R]),Ce=y.useCallback(async(V,F)=>{await l.updateThread(V,F),await H()},[l,H]),We=y.useCallback(async(V,F)=>{await $(async()=>{var pn;const te=(F==null?void 0:F.attachments)||[],{contentParts:Se,filesInfo:se}=await qv(l,te,e==null?void 0:e.uploadPath),we=[];V&&V.trim()&&we.push({type:"text",text:V.trim()});const Ze={id:((pn=crypto.randomUUID)==null?void 0:pn.call(crypto))||`user-${Date.now()}`,role:"user",content:we,createdAt:new Date().toISOString(),checkpointId:(F==null?void 0:F.checkpointId)??S.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??S.lastCheckpointNs??void 0};v(Ze);const Nt={...Ze,content:we},ct={...(F==null?void 0:F.payloadExtras)??{}},Tt=!!ct.edit,_t=ct.originalMessageId,ht=typeof _t=="string"?_t:void 0,en=te&&te.length>0,_n={...re?{threadId:re}:{},payload:{messages:[Nt],files_info:se,...o&&en&&s?{active_agent:s}:{},...ct},checkpointId:(F==null?void 0:F.checkpointId)??S.lastCheckpointId??void 0,checkpointNs:(F==null?void 0:F.checkpointNs)??S.lastCheckpointNs??void 0,nodeFilter:F==null?void 0:F.nodeFilter,config:F==null?void 0:F.config,edit:Tt,originalMessageId:ht};_(_n,ke=>C(ke),{onError:ke=>console.warn("stream error",ke),onOpen:({threadId:ke,created:ue})=>{!re&&ke&&(le(ke),ue&&H().catch(()=>{}))}})},"send")},[re,v,_,C,S.lastCheckpointId,S.lastCheckpointNs,l,e==null?void 0:e.uploadPath,H,le,o,s,$]),ze=y.useCallback(async V=>{if(!re)throw new Error("No active thread");if(x||!O)return;const F=Y;if(F){M(!0);try{const te=await l.getMessages({threadId:re,checkpointId:U,checkpointNs:D,limit:(V==null?void 0:V.limit)??N,beforeId:F});J(te,"prepend")}finally{M(!1)}}},[l,re,U,D,Y,O,x,J,N]),Ke={baseUrl:l.baseUrl,token:E,setToken:g,api:l,threads:q,currentThreadId:re,setCurrentThreadId:le,messages:S.messages,isStreaming:c,error:d,lastCheckpointId:S.lastCheckpointId,lastCheckpointNs:S.lastCheckpointNs,streamingAssistantId:S.assemblingId,hasMoreHistory:O,isLoadingHistory:x,loadOlderMessages:ze,historyPageSize:N,listCheckpoints:ye,navigateToCheckpoint:fe,returnToLatest:Le,refreshThreads:H,createThread:he,deleteThread:Re,renameThread:Ce,loadThread:be,send:We,stop:p};return u.jsx(X_.Provider,{value:Ke,children:t})}function Aa(){const t=y.useContext(X_);if(!t)throw new Error("useChat must be used within ChatProvider");return t}function K(...t){return oR.twMerge(iR.clsx(t))}const Vv=yr.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"}}),Qe=T.forwardRef(({className:t,variant:e,size:n,asChild:r=!1,...a},i)=>{const o=r?Dt.Slot:"button";return u.jsx(o,{className:K(Vv({variant:e,size:n,className:t})),ref:i,...a})});Qe.displayName="Button";const Z_=T.forwardRef(({className:t,...e},n)=>u.jsx("textarea",{className:K("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",t),ref:n,...e}));Z_.displayName="Textarea";function zv({initialValue:t="",editingMessageId:e=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:a=!1,maxLength:i=2e4,onSend:o,onCancelEdit:s,onStop:l,className:c="",textareaClassName:d="",allowEmptySend:_=!1}){const[p,m]=y.useState(t),[E,f]=y.useTransition(),g=y.useRef(null);y.useEffect(()=>{m(t??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[t,e]);const S=y.useCallback(()=>{const O=g.current;O&&(O.style.height="auto",O.style.height=`${O.scrollHeight}px`)},[]);y.useEffect(()=>{S()},[S]);const b=y.useCallback(async O=>{O&&O.preventDefault();const I=(p??"").trim();!I&&!_||f(()=>{try{const x=o(I);x&&typeof x.then=="function"?x.then(()=>{m(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(m(""),g.current&&(g.current.style.height="auto"))}catch{}})},[p,o,_]),h=y.useCallback(O=>{m(O.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),v=y.useCallback(O=>{O.key==="Enter"&&!O.shiftKey?(O.preventDefault(),b()):O.key==="Escape"&&e&&(O.preventDefault(),s==null||s())},[b,e,s]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${e?"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 u.jsx("form",{onSubmit:O=>void b(O),className:`w-full ${c}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(Z_,{ref:g,value:p,onChange:h,onKeyDown:v,placeholder:e?"Edit your message...":n,className:N,disabled:a,maxLength:i,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Qe,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:a||!l,children:u.jsx(pe.Square,{size:16})}):u.jsx(Qe,{type:"submit",size:"icon",className:"shrink-0",title:e?"Save changes":"Send message",disabled:a||!p.trim()&&!_||E,children:u.jsx(pe.Send,{size:16})})})]})})}const $v=y.memo(zv),xa=0,Cn=1,or=2,J_=4;function ep(t){return()=>t}function Wv(t){t()}function tp(t,e){return n=>t(e(n))}function np(t,e){return()=>t(e)}function Kv(t,e){return n=>t(e,n)}function Co(t){return t!==void 0}function Qv(...t){return()=>{t.map(Wv)}}function sr(){}function Da(t,e){return e(t),t}function jv(t,e){return e(t)}function nt(...t){return t}function Xe(t,e){return t(Cn,e)}function Fe(t,e){t(xa,e)}function Ro(t){t(or)}function lt(t){return t(J_)}function Te(t,e){return Xe(t,Kv(e,xa))}function $t(t,e){const n=t(Cn,r=>{n(),e(r)});return n}function rp(t){let e,n;return r=>a=>{e=a,n&&clearTimeout(n),n=setTimeout(()=>{r(e)},t)}}function ap(t,e){return t===e}function rt(t=ap){let e;return n=>r=>{t(e,r)||(e=r,n(r))}}function xe(t){return e=>n=>{t(n)&&e(n)}}function me(t){return e=>tp(e,t)}function nn(t){return e=>()=>{e(t)}}function Z(t,...e){const n=Xv(...e);return(r,a)=>{switch(r){case or:Ro(t);return;case Cn:return Xe(t,n(a))}}}function rn(t,e){return n=>r=>{n(e=t(e,r))}}function Gn(t){return e=>n=>{t>0?t--:e(n)}}function En(t){let e=null,n;return r=>a=>{e=a,!n&&(n=setTimeout(()=>{n=void 0,r(e)},t))}}function Be(...t){const e=new Array(t.length);let n=0,r=null;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);Xe(i,l=>{const c=n;n=n|s,e[o]=l,c!==a&&n===a&&r&&(r(),r=null)})}),i=>o=>{const s=()=>{i([o].concat(e))};n===a?s():r=s}}function Xv(...t){return e=>t.reduceRight(jv,e)}function Zv(t){let e,n;const r=()=>e==null?void 0:e();return function(a,i){switch(a){case Cn:return i?n===i?void 0:(r(),n=i,e=Xe(t,i),e):(r(),sr);case or:r(),n=null;return}}}function ae(t){let e=t;const n=qe();return(r,a)=>{switch(r){case xa:e=a;break;case Cn:{a(e);break}case J_:return e}return n(r,a)}}function ft(t,e){return Da(ae(e),n=>Te(t,n))}function qe(){const t=[];return(e,n)=>{switch(e){case xa:t.slice().forEach(r=>{r(n)});return;case or:t.splice(0,t.length);return;case Cn:return t.push(n),()=>{const r=t.indexOf(n);r>-1&&t.splice(r,1)}}}}function wt(t){return Da(qe(),e=>Te(t,e))}function $e(t,e=[],{singleton:n}={singleton:!0}){return{constructor:t,dependencies:e,id:Jv(),singleton:n}}const Jv=()=>Symbol();function eN(t){const e=new Map,n=({constructor:r,dependencies:a,id:i,singleton:o})=>{if(o&&e.has(i))return e.get(i);const s=r(a.map(l=>n(l)));return o&&e.set(i,s),s};return n(t)}function ut(...t){const e=qe(),n=new Array(t.length);let r=0;const a=Math.pow(2,t.length)-1;return t.forEach((i,o)=>{const s=Math.pow(2,o);Xe(i,l=>{n[o]=l,r=r|s,r===a&&Fe(e,n)})}),function(i,o){switch(i){case or:{Ro(e);return}case Cn:return r===a&&o(n),Xe(e,o)}}}function Ae(t,e=ap){return Z(t,rt(e))}function vo(...t){return function(e,n){switch(e){case or:return;case Cn:return Qv(...t.map(r=>Xe(r,n)))}}}var At=(t=>(t[t.DEBUG=0]="DEBUG",t[t.INFO=1]="INFO",t[t.WARN=2]="WARN",t[t.ERROR=3]="ERROR",t))(At||{});const tN={0:"debug",3:"error",1:"log",2:"warn"},nN=()=>typeof globalThis>"u"?window:globalThis,Rn=$e(()=>{const t=ae(3);return{log:ae((e,n,r=1)=>{var a;const i=(a=nN().VIRTUOSO_LOG_LEVEL)!=null?a:lt(t);r>=i&&console[tN[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",e,n)}),logLevel:t}},[],{singleton:!0});function Yn(t,e,n){return No(t,e,n).callbackRef}function No(t,e,n){const r=y.useRef(null);let a=o=>{};const i=y.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(o=>{const s=()=>{const l=o[0].target;l.offsetParent!==null&&t(l)};n?s():requestAnimationFrame(s)}):null,[t,n]);return a=o=>{o&&e?(i==null||i.observe(o),r.current=o):(r.current&&(i==null||i.unobserve(r.current)),r.current=null)},{callbackRef:a,ref:r}}function rN(t,e,n,r,a,i,o,s,l){const c=y.useCallback(d=>{const _=aN(d.children,e,s?"offsetWidth":"offsetHeight",a);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const m=p.lastElementChild.dataset.viewportType==="window";let E;m&&(E=p.ownerDocument.defaultView);const f=o?s?o.scrollLeft:o.scrollTop:m?s?E.scrollX||E.document.documentElement.scrollLeft:E.scrollY||E.document.documentElement.scrollTop:s?p.scrollLeft:p.scrollTop,g=o?s?o.scrollWidth:o.scrollHeight:m?s?E.document.documentElement.scrollWidth:E.document.documentElement.scrollHeight:s?p.scrollWidth:p.scrollHeight,S=o?s?o.offsetWidth:o.offsetHeight:m?s?E.innerWidth:E.innerHeight:s?p.offsetWidth:p.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(f,0),viewportHeight:S}),i==null||i(s?ip("column-gap",getComputedStyle(d).columnGap,a):ip("row-gap",getComputedStyle(d).rowGap,a)),_!==null&&t(_)},[t,e,a,i,o,r,s]);return No(c,n,l)}function aN(t,e,n,r){const a=t.length;if(a===0)return null;const i=[];for(let o=0;o<a;o++){const s=t.item(o);if(s.dataset.index===void 0)continue;const l=parseInt(s.dataset.index),c=parseFloat(s.dataset.knownSize),d=e(s,n);if(d===0&&r("Zero-sized element, this should not happen",{child:s},At.ERROR),d===c)continue;const _=i[i.length-1];i.length===0||_.size!==d||_.endIndex!==l-1?i.push({endIndex:l,size:d,startIndex:l}):i[i.length-1].endIndex++}return i}function ip(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,At.WARN),e==="normal"?0:parseInt(e??"0",10)}function op(t,e,n){const r=y.useRef(null),a=y.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let _,p;if(e){const m=e.getBoundingClientRect(),E=c.top-m.top;p=m.height-Math.max(0,E),_=E+e.scrollTop}else{const m=o.current.ownerDocument.defaultView;p=m.innerHeight-Math.max(0,c.top),_=c.top+m.scrollY}r.current={offsetTop:_,visibleHeight:p,visibleWidth:d},t(r.current)},[t,e]),{callbackRef:i,ref:o}=No(a,!0,n),s=y.useCallback(()=>{a(o.current)},[a,o]);return y.useEffect(()=>{var l;if(e){e.addEventListener("scroll",s);const c=new ResizeObserver(()=>{requestAnimationFrame(s)});return c.observe(e),()=>{e.removeEventListener("scroll",s),c.unobserve(e)}}else{const c=(l=o.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",s),c==null||c.addEventListener("resize",s),()=>{c==null||c.removeEventListener("scroll",s),c==null||c.removeEventListener("resize",s)}}},[s,e,o]),i}const Rt=$e(()=>{const t=qe(),e=qe(),n=ae(0),r=qe(),a=ae(0),i=qe(),o=qe(),s=ae(0),l=ae(0),c=ae(0),d=ae(0),_=qe(),p=qe(),m=ae(!1),E=ae(!1),f=ae(!1);return Te(Z(t,me(({scrollTop:g})=>g)),e),Te(Z(t,me(({scrollHeight:g})=>g)),o),Te(e,a),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:s,horizontalDirection:E,scrollBy:p,scrollContainerState:t,scrollHeight:o,scrollingInProgress:m,scrollTo:_,scrollTop:e,skipAnimationFrameInResizeObserver:f,smoothScrollTargetReached:r,statefulScrollTop:a,viewportHeight:i}},[],{singleton:!0}),kr={lvl:0};function sp(t,e){const n=t.length;if(n===0)return[];let{index:r,value:a}=e(t[0]);const i=[];for(let o=1;o<n;o++){const{index:s,value:l}=e(t[o]);i.push({end:s-1,start:r,value:a}),r=s,a=l}return i.push({end:1/0,start:r,value:a}),i}function et(t){return t===kr}function Ur(t,e){if(!et(t))return e===t.k?t.v:e<t.k?Ur(t.l,e):Ur(t.r,e)}function Wt(t,e,n="k"){if(et(t))return[-1/0,void 0];if(Number(t[n])===e)return[t.k,t.v];if(Number(t[n])<e){const r=Wt(t.r,e,n);return r[0]===-1/0?[t.k,t.v]:r}return Wt(t.l,e,n)}function Mt(t,e,n){return et(t)?dp(e,n,1):e===t.k?pt(t,{k:e,v:n}):e<t.k?up(pt(t,{l:Mt(t.l,e,n)})):up(pt(t,{r:Mt(t.r,e,n)}))}function lr(){return kr}function wa(t,e,n){if(et(t))return[];const r=Wt(t,e)[0];return iN(yo(t,r,n))}function Oo(t,e){if(et(t))return kr;const{k:n,l:r,r:a}=t;if(e===n){if(et(r))return a;if(et(a))return r;{const[i,o]=cp(r);return Ma(pt(t,{k:i,l:lp(r),v:o}))}}else return e<n?Ma(pt(t,{l:Oo(r,e)})):Ma(pt(t,{r:Oo(a,e)}))}function Hn(t){return et(t)?[]:[...Hn(t.l),{k:t.k,v:t.v},...Hn(t.r)]}function yo(t,e,n){if(et(t))return[];const{k:r,l:a,r:i,v:o}=t;let s=[];return r>e&&(s=s.concat(yo(a,e,n))),r>=e&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(yo(i,e,n))),s}function Ma(t){const{l:e,lvl:n,r}=t;if(r.lvl>=n-1&&e.lvl>=n-1)return t;if(n>r.lvl+1){if(Io(e))return _p(pt(t,{lvl:n-1}));if(!et(e)&&!et(e.r))return pt(e.r,{l:pt(e,{r:e.r.l}),lvl:n,r:pt(t,{l:e.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Io(t))return Ao(pt(t,{lvl:n-1}));if(!et(r)&&!et(r.l)){const a=r.l,i=Io(a)?r.lvl-1:r.lvl;return pt(a,{l:pt(t,{lvl:n-1,r:a.l}),lvl:a.lvl+1,r:Ao(pt(r,{l:a.r,lvl:i}))})}else throw new Error("Unexpected empty nodes")}}function pt(t,e){return dp(e.k!==void 0?e.k:t.k,e.v!==void 0?e.v:t.v,e.lvl!==void 0?e.lvl:t.lvl,e.l!==void 0?e.l:t.l,e.r!==void 0?e.r:t.r)}function lp(t){return et(t.r)?t.l:Ma(pt(t,{r:lp(t.r)}))}function Io(t){return et(t)||t.lvl>t.r.lvl}function cp(t){return et(t.r)?[t.k,t.v]:cp(t.r)}function dp(t,e,n,r=kr,a=kr){return{k:t,l:r,lvl:n,r:a,v:e}}function up(t){return Ao(_p(t))}function _p(t){const{l:e}=t;return!et(e)&&e.lvl===t.lvl?pt(e,{r:pt(t,{l:e.r})}):t}function Ao(t){const{lvl:e,r:n}=t;return!et(n)&&!et(n.r)&&n.lvl===e&&n.r.lvl===e?pt(n,{l:pt(t,{r:n.l}),lvl:e+1}):t}function iN(t){return sp(t,({k:e,v:n})=>({index:e,value:n}))}function pp(t,e){return!!(t&&t.startIndex===e.startIndex&&t.endIndex===e.endIndex)}function Fr(t,e){return!!(t&&t[0]===e[0]&&t[1]===e[1])}const xo=$e(()=>({recalcInProgress:ae(!1)}),[],{singleton:!0});function mp(t,e,n){return t[La(t,e,n)]}function La(t,e,n,r=0){let a=t.length-1;for(;r<=a;){const i=Math.floor((r+a)/2),o=t[i],s=n(o,e);if(s===0)return i;if(s===-1){if(a-r<2)return i-1;a=i-1}else{if(a===r)return i;r=i+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${e}`)}function oN(t,e,n,r){const a=La(t,e,r),i=La(t,n,r,a);return t.slice(a,i+1)}function vn(t,e){return Math.round(t.getBoundingClientRect()[e])}function Pa(t){return!et(t.groupOffsetTree)}function Do({index:t},e){return e===t?0:e<t?-1:1}function sN(){return{groupIndices:[],groupOffsetTree:lr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:lr()}}function lN(t,e){let n=et(t)?0:1/0;for(const r of e){const{endIndex:a,size:i,startIndex:o}=r;if(n=Math.min(n,o),et(t)){t=Mt(t,0,i);continue}const s=wa(t,o-1,a+1);if(s.some(gN(r)))continue;let l=!1,c=!1;for(const{end:d,start:_,value:p}of s)l?(a>=_||i===p)&&(t=Oo(t,_)):(c=p!==i,l=!0),d>a&&a>=_&&p!==i&&(t=Mt(t,a+1,p));c&&(t=Mt(t,o,i))}return[t,n]}function cN(t){return typeof t.groupIndex<"u"}function dN({offset:t},e){return e===t?0:e<t?-1:1}function Br(t,e,n){if(e.length===0)return 0;const{index:r,offset:a,size:i}=mp(e,t,Do),o=t-r,s=i*o+(o-1)*n+a;return s>0?s+n:s}function gp(t,e){if(!Pa(e))return t;let n=0;for(;e.groupIndices[n]<=t+n;)n++;return t+n}function Ep(t,e,n){if(cN(t))return e.groupIndices[t.groupIndex]+1;{const r=t.index==="LAST"?n:t.index;let a=gp(r,e);return a=Math.max(0,a,Math.min(n,a)),a}}function uN(t,e,n,r=0){return r>0&&(e=Math.max(e,mp(t,r,Do).offset)),sp(oN(t,e,n,dN),mN)}function _N(t,[e,n,r,a]){e.length>0&&r("received item sizes",e,At.DEBUG);const i=t.sizeTree;let o=i,s=0;if(n.length>0&&et(i)&&e.length===2){const p=e[0].size,m=e[1].size;o=n.reduce((E,f)=>Mt(Mt(E,f,p),f+1,m),o)}else[o,s]=lN(o,e);if(o===i)return t;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_}=wo(t.offsetTree,s,o,a);return{groupIndices:n,groupOffsetTree:n.reduce((p,m)=>Mt(p,m,Br(m,_,a)),lr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:_,sizeTree:o}}function pN(t){return Hn(t).map(({k:e,v:n},r,a)=>{const i=a[r+1];return{endIndex:i?i.k-1:1/0,size:n,startIndex:e}})}function fp(t,e){let n=0,r=0;for(;n<t;)n+=e[r+1]-e[r]-1,r++;return r-(n===t?0:1)}function wo(t,e,n,r){let a=t,i=0,o=0,s=0,l=0;if(e!==0){l=La(a,e-1,Do),s=a[l].offset;const c=Wt(n,e-1);i=c[0],o=c[1],a.length&&a[l].size===Wt(n,e)[1]&&(l-=1),a=a.slice(0,l+1)}else a=[];for(const{start:c,value:d}of wa(n,e,1/0)){const _=c-i,p=_*o+s+_*r;a.push({index:c,offset:p,size:d}),i=c,s=p,o=d}return{lastIndex:i,lastOffset:s,lastSize:o,offsetTree:a}}function mN(t){return{index:t.index,value:t}}function gN(t){const{endIndex:e,size:n,startIndex:r}=t;return a=>a.start===r&&(a.end===e||a.end===1/0)&&a.value===n}const EN={offsetHeight:"height",offsetWidth:"width"},an=$e(([{log:t},{recalcInProgress:e}])=>{const n=qe(),r=qe(),a=ft(r,0),i=qe(),o=qe(),s=ae(0),l=ae([]),c=ae(void 0),d=ae(void 0),_=ae((C,R)=>vn(C,EN[R])),p=ae(void 0),m=ae(0),E=sN(),f=ft(Z(n,Be(l,t,m),rn(_N,E),rt()),E),g=ft(Z(l,rt(),rn((C,R)=>({current:R,prev:C.current}),{current:[],prev:[]}),me(({prev:C})=>C)),[]);Te(Z(l,xe(C=>C.length>0),Be(f,m),me(([C,R,N])=>{const O=C.reduce((I,x,M)=>Mt(I,x,Br(x,R.offsetTree,N)||M),lr());return{...R,groupIndices:C,groupOffsetTree:O}})),f),Te(Z(r,Be(f),xe(([C,{lastIndex:R}])=>C<R),me(([C,{lastIndex:R,lastSize:N}])=>[{endIndex:R,size:N,startIndex:C}])),n),Te(c,d);const S=ft(Z(c,me(C=>C===void 0)),!0);Te(Z(d,xe(C=>C!==void 0&&et(lt(f).sizeTree)),me(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=wt(Z(n,Be(f),rn(({sizes:C},[R,N])=>({changed:N!==C,sizes:N}),{changed:!1,sizes:E}),me(C=>C.changed)));Xe(Z(s,rn((C,R)=>({diff:C.prev-R,prev:R}),{diff:0,prev:0}),me(C=>C.diff)),C=>{const{groupIndices:R}=lt(f);if(C>0)Fe(e,!0),Fe(i,C+fp(C,R));else if(C<0){const N=lt(g);N.length>0&&(C-=fp(-C,N)),Fe(o,C)}}),Xe(Z(s,Be(t)),([C,R])=>{C<0&&R("`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:s},At.ERROR)});const h=wt(i);Te(Z(i,Be(f),me(([C,R])=>{const N=R.groupIndices.length>0,O=[],I=R.lastSize;if(N){const x=Ur(R.sizeTree,0);let M=0,Y=0;for(;M<C;){const U=R.groupIndices[Y],W=R.groupIndices.length===Y+1?1/0:R.groupIndices[Y+1]-U-1;O.push({endIndex:U,size:x,startIndex:U}),O.push({endIndex:U+1+W-1,size:I,startIndex:U+1}),Y++,M+=W+1}const z=Hn(R.sizeTree);return M!==C&&z.shift(),z.reduce((U,{k:W,v:D})=>{let B=U.ranges;return U.prevSize!==0&&(B=[...U.ranges,{endIndex:W+C-1,size:U.prevSize,startIndex:U.prevIndex}]),{prevIndex:W+C,prevSize:D,ranges:B}},{prevIndex:C,prevSize:0,ranges:O}).ranges}return Hn(R.sizeTree).reduce((x,{k:M,v:Y})=>({prevIndex:M+C,prevSize:Y,ranges:[...x.ranges,{endIndex:M+C-1,size:x.prevSize,startIndex:x.prevIndex}]}),{prevIndex:0,prevSize:I,ranges:[]}).ranges})),n);const v=wt(Z(o,Be(f,m),me(([C,{offsetTree:R},N])=>{const O=-C;return Br(O,R,N)})));return Te(Z(o,Be(f,m),me(([C,R,N])=>{if(R.groupIndices.length>0){if(et(R.sizeTree))return R;let O=lr();const I=lt(g);let x=0,M=0,Y=0;for(;x<-C;){Y=I[M];const z=I[M+1]-Y-1;M++,x+=z+1}if(O=Hn(R.sizeTree).reduce((z,{k:U,v:W})=>Mt(z,Math.max(0,U+C),W),O),x!==-C){const z=Ur(R.sizeTree,Y);O=Mt(O,0,z);const U=Wt(R.sizeTree,-C+1)[1];O=Mt(O,1,U)}return{...R,sizeTree:O,...wo(R.offsetTree,0,O,N)}}else{const O=Hn(R.sizeTree).reduce((I,{k:x,v:M})=>Mt(I,Math.max(0,x+C),M),lr());return{...R,sizeTree:O,...wo(R.offsetTree,0,O,N)}}})),f),{beforeUnshiftWith:h,data:p,defaultItemSize:d,firstItemIndex:s,fixedItemSize:c,gap:m,groupIndices:l,itemSize:_,listRefresh:b,shiftWith:o,shiftWithOffset:v,sizeRanges:n,sizes:f,statefulTotalCount:a,totalCount:r,trackItemSizes:S,unshiftWith:i}},nt(Rn,xo),{singleton:!0});function fN(t){return t.reduce((e,n)=>(e.groupIndices.push(e.totalCount),e.totalCount+=n+1,e),{groupIndices:[],totalCount:0})}const Sp=$e(([{groupIndices:t,sizes:e,totalCount:n},{headerHeight:r,scrollTop:a}])=>{const i=qe(),o=qe(),s=wt(Z(i,me(fN)));return Te(Z(s,me(l=>l.totalCount)),n),Te(Z(s,me(l=>l.groupIndices)),t),Te(Z(ut(a,e,r),xe(([l,c])=>Pa(c)),me(([l,c,d])=>Wt(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),rt(),me(l=>[l])),o),{groupCounts:i,topItemsIndexes:o}},nt(an,Rt)),Nn=$e(([{log:t}])=>{const e=ae(!1),n=wt(Z(e,xe(r=>r),rt()));return Xe(e,r=>{r&<(t)("props updated",{},At.DEBUG)}),{didMount:n,propsReady:e}},nt(Rn),{singleton:!0}),SN=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function bp(t){const e=typeof t=="number"?{index:t}:t;return e.align||(e.align="start"),(!e.behavior||!SN)&&(e.behavior="auto"),e.offset||(e.offset=0),e}const Gr=$e(([{gap:t,listRefresh:e,sizes:n,totalCount:r},{fixedFooterHeight:a,fixedHeaderHeight:i,footerHeight:o,headerHeight:s,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:_},{log:p}])=>{const m=qe(),E=qe(),f=ae(0);let g=null,S=null,b=null;function h(){g&&(g(),g=null),b&&(b(),b=null),S&&(clearTimeout(S),S=null),Fe(l,!1)}return Te(Z(m,Be(n,_,r,f,s,o,p),Be(t,i,a),me(([[v,C,R,N,O,I,x,M],Y,z,U])=>{const W=bp(v),{align:D,behavior:B,offset:L}=W,k=N-1,Q=Ep(W,C,k);let $=Br(Q,C.offsetTree,Y)+I;D==="end"?($+=z+Wt(C.sizeTree,Q)[1]-R+U,Q===k&&($+=x)):D==="center"?$+=(z+Wt(C.sizeTree,Q)[1]-R+U)/2:$-=O,L&&($+=L);const J=q=>{h(),q?(M("retrying to scroll to",{location:v},At.DEBUG),Fe(m,v)):(Fe(E,!0),M("list did not change, scroll successful",{},At.DEBUG))};if(h(),B==="smooth"){let q=!1;b=Xe(e,X=>{q=q||X}),g=$t(d,()=>{J(q)})}else g=$t(Z(e,bN(150)),J);return S=setTimeout(()=>{h()},1200),Fe(l,!0),M("scrolling from index to",{behavior:B,index:Q,top:$},At.DEBUG),{behavior:B,top:$}})),c),{scrollTargetReached:E,scrollToIndex:m,topListHeight:f}},nt(an,Rt,Rn),{singleton:!0});function bN(t){return e=>{const n=setTimeout(()=>{e(!1)},t);return r=>{r&&(e(!0),clearTimeout(n))}}}function Mo(t,e){t==0?e():requestAnimationFrame(()=>{Mo(t-1,e)})}function Lo(t,e){const n=e-1;return typeof t=="number"?t:t.index==="LAST"?n:t.index}const Yr=$e(([{defaultItemSize:t,listRefresh:e,sizes:n},{scrollTop:r},{scrollTargetReached:a,scrollToIndex:i},{didMount:o}])=>{const s=ae(!0),l=ae(0),c=ae(!0);return Te(Z(o,Be(l),xe(([d,_])=>!!_),nn(!1)),s),Te(Z(o,Be(l),xe(([d,_])=>!!_),nn(!1)),c),Xe(Z(ut(e,o),Be(s,n,t,c),xe(([[,d],_,{sizeTree:p},m,E])=>d&&(!et(p)||Co(m))&&!_&&!E),Be(l)),([,d])=>{$t(a,()=>{Fe(c,!0)}),Mo(4,()=>{$t(r,()=>{Fe(s,!0)}),Fe(i,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:s}},nt(an,Rt,Gr,Nn),{singleton:!0});function Tp(t,e){return Math.abs(t-e)<1.01}const Hr="up",qr="down",TN="none",hN={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},CN=0,Vr=$e(([{footerHeight:t,headerHeight:e,scrollBy:n,scrollContainerState:r,scrollTop:a,viewportHeight:i}])=>{const o=ae(!1),s=ae(!0),l=qe(),c=qe(),d=ae(4),_=ae(CN),p=ft(Z(vo(Z(Ae(a),Gn(1),nn(!0)),Z(Ae(a),Gn(1),nn(!1),rp(100))),rt()),!1),m=ft(Z(vo(Z(n,nn(!0)),Z(n,nn(!1),rp(200))),rt()),!1);Te(Z(ut(Ae(a),Ae(_)),me(([b,h])=>b<=h),rt()),s),Te(Z(s,En(50)),c);const E=wt(Z(ut(r,Ae(i),Ae(e),Ae(t),Ae(d)),rn((b,[{scrollHeight:h,scrollTop:v},C,R,N,O])=>{const I=v+C-h>-O,x={scrollHeight:h,scrollTop:v,viewportHeight:C};if(I){let Y,z;return v>b.state.scrollTop?(Y="SCROLLED_DOWN",z=b.state.scrollTop-v):(Y="SIZE_DECREASED",z=b.state.scrollTop-v||b.scrollTopDelta),{atBottom:!0,atBottomBecause:Y,scrollTopDelta:z,state:x}}let M;return x.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":v<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:x}},hN),rt((b,h)=>b&&b.atBottom===h.atBottom))),f=ft(Z(r,rn((b,{scrollHeight:h,scrollTop:v,viewportHeight:C})=>{if(Tp(b.scrollHeight,h))return{changed:!1,jump:0,scrollHeight:h,scrollTop:v};{const R=h-(v+C)<1;return b.scrollTop!==v&&R?{changed:!0,jump:b.scrollTop-v,scrollHeight:h,scrollTop:v}:{changed:!0,jump:0,scrollHeight:h,scrollTop:v}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),xe(b=>b.changed),me(b=>b.jump)),0);Te(Z(E,me(b=>b.atBottom)),o),Te(Z(o,En(50)),l);const g=ae(qr);Te(Z(r,me(({scrollTop:b})=>b),rt(),rn((b,h)=>lt(m)?{direction:b.direction,prevScrollTop:h}:{direction:h<b.prevScrollTop?Hr:qr,prevScrollTop:h},{direction:qr,prevScrollTop:0}),me(b=>b.direction)),g),Te(Z(r,En(50),nn(TN)),g);const S=ae(0);return Te(Z(p,xe(b=>!b),nn(0)),S),Te(Z(a,En(100),Be(p),xe(([b,h])=>!!h),rn(([b,h],[v])=>[h,v],[0,0]),me(([b,h])=>h-b)),S),{atBottomState:E,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:_,isAtBottom:o,isAtTop:s,isScrolling:p,lastJumpDueToItemResize:f,scrollDirection:g,scrollVelocity:S}},nt(Rt)),ka="top",Ua="bottom",hp="none";function Cp(t,e,n){return typeof t=="number"?n===Hr&&e===ka||n===qr&&e===Ua?t:0:n===Hr?e===ka?t.main:t.reverse:e===Ua?t.main:t.reverse}function Rp(t,e){var n;return typeof t=="number"?t:(n=t[e])!=null?n:0}const Po=$e(([{deviation:t,fixedHeaderHeight:e,headerHeight:n,scrollTop:r,viewportHeight:a}])=>{const i=qe(),o=ae(0),s=ae(0),l=ae(0),c=ft(Z(ut(Ae(r),Ae(a),Ae(n),Ae(i,Fr),Ae(l),Ae(o),Ae(e),Ae(t),Ae(s)),me(([d,_,p,[m,E],f,g,S,b,h])=>{const v=d-b,C=g+S,R=Math.max(p-v,0);let N=hp;const O=Rp(h,ka),I=Rp(h,Ua);return m-=b,m+=p+S,E+=p+S,E-=b,m>d+C-O&&(N=Hr),E<d-R+_+I&&(N=qr),N!==hp?[Math.max(v-p-Cp(f,ka,N)-O,0),v-R-S+_+Cp(f,Ua,N)+I]:null}),xe(d=>d!=null),rt(Fr)),[0,0]);return{increaseViewportBy:s,listBoundary:i,overscan:l,topListHeight:o,visibleRange:c}},nt(Rt),{singleton:!0});function RN(t,e,n){if(Pa(e)){const r=gp(t,e);return[{index:Wt(e.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:t,offset:0,size:0}]}const ko={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Fa(t,e,n,r,a,i){const{lastIndex:o,lastOffset:s,lastSize:l}=a;let c=0,d=0;if(t.length>0){c=t[0].offset;const f=t[t.length-1];d=f.offset+f.size}const _=n-o,p=s+_*l+(_-1)*r,m=c,E=p-d;return{bottom:d,firstItemIndex:i,items:Np(t,a,i),offsetBottom:E,offsetTop:c,top:m,topItems:Np(e,a,i),topListHeight:e.reduce((f,g)=>g.size+f,0),totalCount:n}}function vp(t,e,n,r,a,i){let o=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-o>=t)break;o++}const s=t+o,l=Lo(e,s),c=Array.from({length:s}).map((d,_)=>({data:i[_+l],index:_+l,offset:0,size:0}));return Fa(c,[],s,a,n,r)}function Np(t,e,n){if(t.length===0)return[];if(!Pa(e))return t.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=t[0].index,a=t[t.length-1].index,i=[],o=wa(e.groupOffsetTree,r,a);let s,l=0;for(const c of t){(!s||s.end<c.index)&&(s=o.shift(),l=e.groupIndices.indexOf(s.start));let d;c.index===s.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},i.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return i}const qn=$e(([{data:t,firstItemIndex:e,gap:n,sizes:r,totalCount:a},i,{listBoundary:o,topListHeight:s,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:_},p,{didMount:m},{recalcInProgress:E}])=>{const f=ae([]),g=ae(0),S=qe();Te(i.topItemsIndexes,f);const b=ft(Z(ut(m,E,Ae(l,Fr),Ae(a),Ae(r),Ae(c),d,Ae(f),Ae(e),Ae(n),t),xe(([R,N,,O,,,,,,,I])=>{const x=I&&I.length!==O;return R&&!N&&!x}),me(([,,[R,N],O,I,x,M,Y,z,U,W])=>{const D=I,{offsetTree:B,sizeTree:L}=D,k=lt(g);if(O===0)return{...ko,totalCount:O};if(R===0&&N===0)return k===0?{...ko,totalCount:O}:vp(k,x,I,z,U,W||[]);if(et(L))return k>0?null:Fa(RN(Lo(x,O),D,W),[],O,U,D,z);const Q=[];if(Y.length>0){const re=Y[0],le=Y[Y.length-1];let H=0;for(const P of wa(L,re,le)){const j=P.value,ne=Math.max(P.start,re),oe=Math.min(P.end,le);for(let ie=ne;ie<=oe;ie++)Q.push({data:W==null?void 0:W[ie],index:ie,offset:H,size:j}),H+=j}}if(!M)return Fa([],Q,O,U,D,z);const $=Y.length>0?Y[Y.length-1]+1:0,J=uN(B,R,N,$);if(J.length===0)return null;const q=O-1,X=Da([],re=>{for(const le of J){const H=le.value;let P=H.offset,j=le.start;const ne=H.size;if(H.offset<R){j+=Math.floor((R-H.offset+U)/(ne+U));const ie=j-le.start;P+=ie*ne+ie*U}j<$&&(P+=($-j)*ne,j=$);const oe=Math.min(le.end,q);for(let ie=j;ie<=oe&&!(P>=N);ie++)re.push({data:W==null?void 0:W[ie],index:ie,offset:P,size:ne}),P+=ne+U}});return Fa(X,Q,O,U,D,z)}),xe(R=>R!==null),rt()),ko);Te(Z(t,xe(Co),me(R=>R==null?void 0:R.length)),a),Te(Z(b,me(R=>R.topListHeight)),_),Te(_,s),Te(Z(b,me(R=>[R.top,R.bottom])),o),Te(Z(b,me(R=>R.items)),S);const h=wt(Z(b,xe(({items:R})=>R.length>0),Be(a,t),xe(([{items:R},N])=>R[R.length-1].originalIndex===N-1),me(([,R,N])=>[R-1,N]),rt(Fr),me(([R])=>R))),v=wt(Z(b,En(200),xe(({items:R,topItems:N})=>R.length>0&&R[0].originalIndex===N.length),me(({items:R})=>R[0].index),rt())),C=wt(Z(b,xe(({items:R})=>R.length>0),me(({items:R})=>{let N=0,O=R.length-1;for(;R[N].type==="group"&&N<O;)N++;for(;R[O].type==="group"&&O>N;)O--;return{endIndex:R[O].index,startIndex:R[N].index}}),rt(pp)));return{endReached:h,initialItemCount:g,itemsRendered:S,listState:b,rangeChanged:C,startReached:v,topItemsIndexes:f,...p}},nt(an,Sp,Po,Yr,Gr,Vr,Nn,xo),{singleton:!0}),Op=$e(([{fixedFooterHeight:t,fixedHeaderHeight:e,footerHeight:n,headerHeight:r},{listState:a}])=>{const i=qe(),o=ft(Z(ut(n,t,r,e,a),me(([s,l,c,d,_])=>s+l+c+d+_.offsetBottom+_.bottom)),0);return Te(Ae(o),i),{totalListHeight:o,totalListHeightChanged:i}},nt(Rt,qn),{singleton:!0}),vN=$e(([{viewportHeight:t},{totalListHeight:e}])=>{const n=ae(!1),r=ft(Z(ut(n,t,e),xe(([a])=>a),me(([,a,i])=>Math.max(0,a-i)),En(0),rt()),0);return{alignToBottom:n,paddingTopAddition:r}},nt(Rt,Op),{singleton:!0}),yp=$e(()=>({context:ae(null)})),NN=({itemBottom:t,itemTop:e,locationParams:{align:n,behavior:r,...a},viewportBottom:i,viewportTop:o})=>e<o?{...a,align:n??"start",behavior:r}:t>i?{...a,align:n??"end",behavior:r}:null,Ip=$e(([{gap:t,sizes:e,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:a,headerHeight:i,scrollingInProgress:o,scrollTop:s,viewportHeight:l},{scrollToIndex:c}])=>{const d=qe();return Te(Z(d,Be(e,l,n,i,a,r,s),Be(t),me(([[_,p,m,E,f,g,S,b],h])=>{const{align:v,behavior:C,calculateViewLocation:R=NN,done:N,...O}=_,I=Ep(_,p,E-1),x=Br(I,p.offsetTree,h)+f+g,M=x+Wt(p.sizeTree,I)[1],Y=b+g,z=b+m-S,U=R({itemBottom:M,itemTop:x,locationParams:{align:v,behavior:C,...O},viewportBottom:z,viewportTop:Y});return U?N&&$t(Z(o,xe(W=>!W),Gn(lt(o)?1:2)),N):N&&N(),U}),xe(_=>_!==null)),c),{scrollIntoView:d}},nt(an,Rt,Gr,qn,Rn),{singleton:!0});function Ap(t){return t?t==="smooth"?"smooth":"auto":!1}const ON=(t,e)=>typeof t=="function"?Ap(t(e)):e&&Ap(t),yN=$e(([{listRefresh:t,totalCount:e,fixedItemSize:n,data:r},{atBottomState:a,isAtBottom:i},{scrollToIndex:o},{scrolledToInitialItem:s},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:_},{context:p},{scrollIntoView:m}])=>{const E=ae(!1),f=qe();let g=null;function S(C){Fe(o,{align:"end",behavior:C,index:"LAST"})}Xe(Z(ut(Z(Ae(e),Gn(1)),l),Be(Ae(E),i,s,_),me(([[C,R],N,O,I,x])=>{let M=R&&I,Y="auto";return M&&(Y=ON(N,O||x),M=M&&!!Y),{followOutputBehavior:Y,shouldFollow:M,totalCount:C}}),xe(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:R})=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("following output to ",{totalCount:R},At.DEBUG),S(C)}):g=$t(t,()=>{lt(d)("following output to ",{totalCount:R},At.DEBUG),S(C),g=null})});function b(C){const R=$t(a,N=>{C&&!N.atBottom&&N.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(lt(d)("scrolling to bottom due to increased size",{},At.DEBUG),S("auto"))});setTimeout(R,100)}Xe(Z(ut(Ae(E),e,c),xe(([C,,R])=>C&&R),rn(({value:C},[,R])=>({refreshed:C===R,value:R}),{refreshed:!1,value:0}),xe(({refreshed:C})=>C),Be(E,e)),([,C])=>{lt(s)&&b(C!==!1)}),Xe(f,()=>{b(lt(E)!==!1)}),Xe(ut(Ae(E),a),([C,R])=>{C&&!R.atBottom&&R.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&S("auto")});const h=ae(null),v=qe();return Te(vo(Z(Ae(r),me(C=>{var R;return(R=C==null?void 0:C.length)!=null?R:0})),Z(Ae(e))),v),Xe(Z(ut(Z(v,Gn(1)),l),Be(Ae(h),s,_,p),me(([[C,R],N,O,I,x])=>R&&O&&(N==null?void 0:N({context:x,totalCount:C,scrollingInProgress:I}))),xe(C=>!!C),En(0)),C=>{g&&(g(),g=null),lt(n)?requestAnimationFrame(()=>{lt(d)("scrolling into view",{}),Fe(m,C)}):g=$t(t,()=>{lt(d)("scrolling into view",{}),Fe(m,C),g=null})}),{autoscrollToBottom:f,followOutput:E,scrollIntoViewOnChange:h}},nt(an,Vr,Gr,Yr,Nn,Rn,Rt,yp,Ip)),IN=$e(([{data:t,firstItemIndex:e,gap:n,sizes:r},{initialTopMostItemIndex:a},{initialItemCount:i,listState:o},{didMount:s}])=>(Te(Z(s,Be(i),xe(([,l])=>l!==0),Be(a,r,e,n,t),me(([[,l],c,d,_,p,m=[]])=>vp(l,c,d,_,p,m))),o),{}),nt(an,Yr,qn,Nn),{singleton:!0}),AN=$e(([{didMount:t},{scrollTo:e},{listState:n}])=>{const r=ae(0);return Xe(Z(t,Be(r),xe(([,a])=>a!==0),me(([,a])=>({top:a}))),a=>{$t(Z(n,Gn(1),xe(i=>i.items.length>1)),()=>{requestAnimationFrame(()=>{Fe(e,a)})})}),{initialScrollTop:r}},nt(Nn,Rt,qn),{singleton:!0}),xp=$e(([{scrollVelocity:t}])=>{const e=ae(!1),n=qe(),r=ae(!1);return Te(Z(t,Be(r,e,n),xe(([a,i])=>!!i),me(([a,i,o,s])=>{const{enter:l,exit:c}=i;if(o){if(c(a,s))return!1}else if(l(a,s))return!0;return o}),rt()),e),Xe(Z(ut(e,t,n),Be(r)),([[a,i,o],s])=>{a&&s&&s.change&&s.change(i,o)}),{isSeeking:e,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:t}},nt(Vr),{singleton:!0}),Uo=$e(([{scrollContainerState:t,scrollTo:e}])=>{const n=qe(),r=qe(),a=qe(),i=ae(!1),o=ae(void 0);return Te(Z(ut(n,r),me(([{scrollHeight:s,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:s,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),Te(Z(e,Be(r),me(([s,{offsetTop:l}])=>({...s,top:s.top+l}))),a),{customScrollParent:o,useWindowScroll:i,windowScrollContainerState:n,windowScrollTo:a,windowViewportRect:r}},nt(Rt)),xN=$e(([{sizeRanges:t,sizes:e},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:a},{didMount:i},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:l}])=>{const c=qe(),d=ae(void 0),_=ae(null),p=ae(null);return Te(s,_),Te(l,p),Xe(Z(c,Be(e,r,o,_,p,n)),([m,E,f,g,S,b,h])=>{const v=pN(E.sizeTree);g&&S!==null&&b!==null&&(f=S.scrollTop-b.offsetTop),f-=h,m({ranges:v,scrollTop:f})}),Te(Z(d,xe(Co),me(DN)),a),Te(Z(i,Be(d),xe(([,m])=>m!==void 0),rt(),me(([,m])=>m.ranges)),t),{getState:c,restoreStateFrom:d}},nt(an,Rt,Yr,Nn,Uo));function DN(t){return{align:"start",index:0,offset:t.scrollTop}}const wN=$e(([{topItemsIndexes:t}])=>{const e=ae(0);return Te(Z(e,xe(n=>n>=0),me(n=>Array.from({length:n}).map((r,a)=>a))),t),{topItemCount:e}},nt(qn));function Dp(t){let e=!1,n;return()=>(e||(e=!0,n=t()),n)}const MN=Dp(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),LN=$e(([{deviation:t,scrollBy:e,scrollingInProgress:n,scrollTop:r},{isAtBottom:a,isScrolling:i,lastJumpDueToItemResize:o,scrollDirection:s},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:_,sizes:p},{log:m},{recalcInProgress:E}])=>{const f=wt(Z(l,Be(o),rn(([,S,b,h],[{bottom:v,items:C,offsetBottom:R,totalCount:N},O])=>{const I=v+R;let x=0;return b===N&&S.length>0&&C.length>0&&(C[0].originalIndex===0&&S[0].originalIndex===0||(x=I-h,x!==0&&(x+=O))),[x,C,N,I]},[0,[],0,0]),xe(([S])=>S!==0),Be(r,s,n,a,m,E),xe(([,S,b,h,,,v])=>!v&&!h&&S!==0&&b===Hr),me(([[S],,,,,b])=>(b("Upward scrolling compensation",{amount:S},At.DEBUG),S))));function g(S){S>0?(Fe(e,{behavior:"auto",top:-S}),Fe(t,0)):(Fe(t,0),Fe(e,{behavior:"auto",top:-S}))}return Xe(Z(f,Be(t,i)),([S,b,h])=>{h&&MN()?Fe(t,b-S):g(-S)}),Xe(Z(ut(ft(i,!1),t,E),xe(([S,b,h])=>!S&&!h&&b!==0),me(([S,b])=>b),En(1)),g),Te(Z(_,me(S=>({top:-S}))),e),Xe(Z(c,Be(p,d),me(([S,{groupIndices:b,lastSize:h,sizeTree:v},C])=>{function R(N){return N*(h+C)}if(b.length===0)return R(S);{let N=0;const O=Ur(v,0);let I=0,x=0;for(;I<S;){I++,N+=O;let M=b.length===x+1?1/0:b[x+1]-b[x]-1;I+M>S&&(N-=O,M=S-I+1),I+=M,N+=R(M),x++}return N}})),S=>{Fe(t,S),requestAnimationFrame(()=>{Fe(e,{top:S}),requestAnimationFrame(()=>{Fe(t,0),Fe(E,!1)})})}),{deviation:t}},nt(Rt,Vr,qn,an,Rn,xo)),PN=$e(([t,e,n,r,a,i,o,s,l,c,d])=>({...t,...e,...n,...r,...a,...i,...o,...s,...l,...c,...d}),nt(Po,IN,Nn,xp,Op,AN,vN,Uo,Ip,Rn,yp)),wp=$e(([{data:t,defaultItemSize:e,firstItemIndex:n,fixedItemSize:r,gap:a,groupIndices:i,itemSize:o,sizeRanges:s,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:_},{initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E},f,g,S,{listState:b,topItemsIndexes:h,...v},{scrollToIndex:C},R,{topItemCount:N},{groupCounts:O},I])=>(Te(v.rangeChanged,I.scrollSeekRangeChanged),Te(Z(I.windowViewportRect,me(x=>x.visibleHeight)),f.viewportHeight),{data:t,defaultItemHeight:e,firstItemIndex:n,fixedItemHeight:r,gap:a,groupCounts:O,initialItemFinalLocationReached:p,initialTopMostItemIndex:m,scrolledToInitialItem:E,sizeRanges:s,topItemCount:N,topItemsIndexes:h,totalCount:d,...S,groupIndices:i,itemSize:o,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:_,...v,...I,...f,sizes:l,...g}),nt(an,Yr,Rt,xN,yN,qn,Gr,LN,wN,Sp,PN));function kN(t,e){const n={},r={};let a=0;const i=t.length;for(;a<i;)r[t[a]]=1,a+=1;for(const o in e)Object.hasOwn(r,o)||(n[o]=e[o]);return n}const Ba=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Mp(t,e,n){const r=Object.keys(e.required||{}),a=Object.keys(e.optional||{}),i=Object.keys(e.methods||{}),o=Object.keys(e.events||{}),s=y.createContext({});function l(g,S){g.propsReady&&Fe(g.propsReady,!1);for(const b of r){const h=g[e.required[b]];Fe(h,S[b])}for(const b of a)if(b in S){const h=g[e.optional[b]];Fe(h,S[b])}g.propsReady&&Fe(g.propsReady,!0)}function c(g){return i.reduce((S,b)=>(S[b]=h=>{const v=g[e.methods[b]];Fe(v,h)},S),{})}function d(g){return o.reduce((S,b)=>(S[b]=Zv(g[e.events[b]]),S),{})}const _=y.forwardRef((g,S)=>{const{children:b,...h}=g,[v]=y.useState(()=>Da(eN(t),N=>{l(N,h)})),[C]=y.useState(np(d,v));Ba(()=>{for(const N of o)N in h&&Xe(C[N],h[N]);return()=>{Object.values(C).map(Ro)}},[h,C,v]),Ba(()=>{l(v,h)}),y.useImperativeHandle(S,ep(c(v)));const R=n;return u.jsx(s.Provider,{value:v,children:n?u.jsx(R,{...kN([...r,...a,...o],h),children:b}):b})}),p=g=>{const S=y.useContext(s);return y.useCallback(b=>{Fe(S[g],b)},[S,g])},m=g=>{const S=y.useContext(s)[g],b=y.useCallback(h=>Xe(S,h),[S]);return y.useSyncExternalStore(b,()=>lt(S),()=>lt(S))},E=g=>{const S=y.useContext(s)[g],[b,h]=y.useState(np(lt,S));return Ba(()=>Xe(S,v=>{v!==b&&h(ep(v))}),[S,b]),b},f=y.version.startsWith("18")?m:E;return{Component:_,useEmitter:(g,S)=>{const b=y.useContext(s)[g];Ba(()=>Xe(b,S),[S,b])},useEmitterValue:f,usePublisher:p}}const Lp=y.createContext(void 0),Pp=y.createContext(void 0),kp=typeof document<"u"?y.useLayoutEffect:y.useEffect;function Fo(t){return"self"in t}function UN(t){return"body"in t}function Up(t,e,n,r=sr,a,i){const o=y.useRef(null),s=y.useRef(null),l=y.useRef(null),c=y.useCallback(p=>{let m,E,f;const g=p.target;if(UN(g)||Fo(g)){const b=Fo(g)?g:g.defaultView;f=i?b.scrollX:b.scrollY,m=i?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,E=i?b.innerWidth:b.innerHeight}else f=i?g.scrollLeft:g.scrollTop,m=i?g.scrollWidth:g.scrollHeight,E=i?g.offsetWidth:g.offsetHeight;const S=()=>{t({scrollHeight:m,scrollTop:Math.max(f,0),viewportHeight:E})};p.suppressFlushSync?S():no.flushSync(S),s.current!==null&&(f===s.current||f<=0||f===m-E)&&(s.current=null,e(!0),l.current&&(clearTimeout(l.current),l.current=null))},[t,e,i]);y.useEffect(()=>{const p=a||o.current;return r(a||o.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[o,c,n,r,a]);function d(p){const m=o.current;if(!m||(i?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const E=p.behavior==="smooth";let f,g,S;Fo(m)?(g=Math.max(vn(m.document.documentElement,i?"width":"height"),i?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),f=i?m.innerWidth:m.innerHeight,S=i?window.scrollX:window.scrollY):(g=m[i?"scrollWidth":"scrollHeight"],f=vn(m,i?"width":"height"),S=m[i?"scrollLeft":"scrollTop"]);const b=g-f;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Tp(f,g)||p.top===S){t({scrollHeight:g,scrollTop:S,viewportHeight:f}),E&&e(!0);return}E?(s.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,s.current=null,e(!0)},1e3)):s.current=null,i&&(p={behavior:p.behavior,left:p.top}),m.scrollTo(p)}function _(p){i&&(p={behavior:p.behavior,left:p.top}),o.current.scrollBy(p)}return{scrollByCallback:_,scrollerRef:o,scrollToCallback:d}}const Bo="-webkit-sticky",Fp="sticky",Go=Dp(()=>{if(typeof document>"u")return Fp;const t=document.createElement("div");return t.style.position=Bo,t.style.position===Bo?Bo:Fp});function Yo(t){return t}const FN=$e(()=>{const t=ae(s=>`Item ${s}`),e=ae(s=>`Group ${s}`),n=ae({}),r=ae(Yo),a=ae("div"),i=ae(sr),o=(s,l=null)=>ft(Z(n,me(c=>c[s]),rt()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:o("EmptyPlaceholder"),FooterComponent:o("Footer"),GroupComponent:o("Group","div"),groupContent:e,HeaderComponent:o("Header"),HeaderFooterTag:a,ItemComponent:o("Item","div"),itemContent:t,ListComponent:o("List","div"),ScrollerComponent:o("Scroller","div"),scrollerRef:i,ScrollSeekPlaceholder:o("ScrollSeekPlaceholder"),TopItemListComponent:o("TopItemList")}}),BN=$e(([t,e])=>({...t,...e}),nt(wp,FN)),GN=({height:t})=>u.jsx("div",{style:{height:t}}),YN={overflowAnchor:"none",position:Go(),zIndex:1},Bp={overflowAnchor:"none"},HN={...Bp,display:"inline-block",height:"100%"},Gp=y.memo(function({showTopList:t=!1}){const e=Pe("listState"),n=Gt("sizeRanges"),r=Pe("useWindowScroll"),a=Pe("customScrollParent"),i=Gt("windowScrollContainerState"),o=Gt("scrollContainerState"),s=a||r?i:o,l=Pe("itemContent"),c=Pe("context"),d=Pe("groupContent"),_=Pe("trackItemSizes"),p=Pe("itemSize"),m=Pe("log"),E=Gt("gap"),f=Pe("horizontalDirection"),{callbackRef:g}=rN(n,p,_,t?sr:s,m,E,a,f,Pe("skipAnimationFrameInResizeObserver")),[S,b]=y.useState(0);Ho("deviation",U=>{S!==U&&b(U)});const h=Pe("EmptyPlaceholder"),v=Pe("ScrollSeekPlaceholder")||GN,C=Pe("ListComponent"),R=Pe("ItemComponent"),N=Pe("GroupComponent"),O=Pe("computeItemKey"),I=Pe("isSeeking"),x=Pe("groupIndices").length>0,M=Pe("alignToBottom"),Y=Pe("initialItemFinalLocationReached"),z=t?{}:{boxSizing:"border-box",...f?{display:"inline-block",height:"100%",marginLeft:S!==0?S:M?"auto":0,paddingLeft:e.offsetTop,paddingRight:e.offsetBottom,whiteSpace:"nowrap"}:{marginTop:S!==0?S:M?"auto":0,paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},...Y?{}:{visibility:"hidden"}};return!t&&e.totalCount===0&&h?u.jsx(h,{...St(h,c)}):u.jsx(C,{...St(C,c),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:z,children:(t?e.topItems:e.items).map(U=>{const W=U.originalIndex,D=O(W+e.firstItemIndex,U.data,c);return I?y.createElement(v,{...St(v,c),height:U.size,index:U.index,key:D,type:U.type||"item",...U.type==="group"?{}:{groupIndex:U.groupIndex}}):U.type==="group"?y.createElement(N,{...St(N,c),"data-index":W,"data-item-index":U.index,"data-known-size":U.size,key:D,style:YN},d(U.index,c)):y.createElement(R,{...St(R,c),...$N(R,U.data),"data-index":W,"data-item-group-index":U.groupIndex,"data-item-index":U.index,"data-known-size":U.size,key:D,style:f?HN:Bp},x?l(U.index,U.groupIndex,U.data,c):l(U.index,U.data,c))})})}),qN={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},VN={outline:"none",overflowX:"auto",position:"relative"},Ga=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:{}}),zN={position:Go(),top:0,width:"100%",zIndex:1};function St(t,e){if(typeof t!="string")return{context:e}}function $N(t,e){return{item:typeof t=="string"?void 0:e}}const WN=y.memo(function(){const t=Pe("HeaderComponent"),e=Gt("headerHeight"),n=Pe("HeaderFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,Pe("skipAnimationFrameInResizeObserver")),a=Pe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null}),KN=y.memo(function(){const t=Pe("FooterComponent"),e=Gt("footerHeight"),n=Pe("HeaderFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,Pe("skipAnimationFrameInResizeObserver")),a=Pe("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null});function Yp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("scrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("scrollerRef"),_=e("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:m,scrollToCallback:E}=Up(s,c,l,d,void 0,_);return t("scrollTo",E),t("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{..._?VN:qN,...a},tabIndex:0,...o,...St(l,i),children:r})})}function Hp({useEmitter:t,useEmitterValue:e,usePublisher:n}){return y.memo(function({children:r,style:a,context:i,...o}){const s=n("windowScrollContainerState"),l=e("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=e("totalListHeight"),_=e("deviation"),p=e("customScrollParent"),m=y.useRef(null),E=e("scrollerRef"),{scrollByCallback:f,scrollerRef:g,scrollToCallback:S}=Up(s,c,l,E,p);return kp(()=>{var b;return g.current=p||((b=m.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,p]),t("windowScrollTo",S),t("scrollBy",f),u.jsx(l,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...a,...d!==0?{height:d+_}:{}},...o,...St(l,i),children:r})})}const QN=({children:t})=>{const e=y.useContext(Lp),n=Gt("viewportHeight"),r=Gt("fixedItemHeight"),a=Pe("alignToBottom"),i=Pe("horizontalDirection"),o=y.useMemo(()=>tp(n,l=>vn(l,i?"width":"height")),[n,i]),s=Yn(o,!0,Pe("skipAnimationFrameInResizeObserver"));return y.useEffect(()=>{e&&(n(e.viewportHeight),r(e.itemHeight))},[e,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:s,style:Ga(a),children:t})},jN=({children:t})=>{const e=y.useContext(Lp),n=Gt("windowViewportRect"),r=Gt("fixedItemHeight"),a=Pe("customScrollParent"),i=op(n,a,Pe("skipAnimationFrameInResizeObserver")),o=Pe("alignToBottom");return y.useEffect(()=>{e&&(r(e.itemHeight),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:100}))},[e,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:i,style:Ga(o),children:t})},XN=({children:t})=>{const e=Pe("TopItemListComponent")||"div",n=Pe("headerHeight"),r={...zN,marginTop:`${n}px`},a=Pe("context");return u.jsx(e,{style:r,...St(e,a),children:t})},ZN=y.memo(function(t){const e=Pe("useWindowScroll"),n=Pe("topItemsIndexes").length>0,r=Pe("customScrollParent"),a=Pe("context");return u.jsxs(r||e?tO:eO,{...t,context:a,children:[n&&u.jsx(XN,{children:u.jsx(Gp,{showTopList:!0})}),u.jsxs(r||e?jN:QN,{children:[u.jsx(WN,{}),u.jsx(Gp,{}),u.jsx(KN,{})]})]})}),{Component:JN,useEmitter:Ho,useEmitterValue:Pe,usePublisher:Gt}=Mp(BN,{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"}},ZN),eO=Yp({useEmitter:Ho,useEmitterValue:Pe,usePublisher:Gt}),tO=Hp({useEmitter:Ho,useEmitterValue:Pe,usePublisher:Gt}),nO=JN;nt(wp,$e(()=>{const t=ae(c=>u.jsxs("td",{children:["Item $",c]})),e=ae(null),n=ae(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ae(null),a=ae(null),i=ae({}),o=ae(Yo),s=ae(sr),l=(c,d=null)=>ft(Z(i,me(_=>_[c]),rt()),d);return{components:i,computeItemKey:o,context:e,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:a,fixedHeaderContent:r,itemContent:t,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Go();const qp={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},rO={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Vp,floor:Ya,max:zr,min:qo,round:zp}=Math;function $p(t,e,n){return Array.from({length:e-t+1}).map((r,a)=>({data:n===null?null:n[a+t],index:a+t}))}function aO(t){return{...rO,items:t}}function Ha(t,e){return t&&t.width===e.width&&t.height===e.height}function iO(t,e){return t&&t.column===e.column&&t.row===e.row}const oO=$e(([{increaseViewportBy:t,listBoundary:e,overscan:n,visibleRange:r},{footerHeight:a,headerHeight:i,scrollBy:o,scrollContainerState:s,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:_},p,m,{didMount:E,propsReady:f},{customScrollParent:g,useWindowScroll:S,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:v},C])=>{const R=ae(0),N=ae(0),O=ae(qp),I=ae({height:0,width:0}),x=ae({height:0,width:0}),M=qe(),Y=qe(),z=ae(0),U=ae(null),W=ae({column:0,row:0}),D=qe(),B=qe(),L=ae(!1),k=ae(0),Q=ae(!0),$=ae(!1),J=ae(!1);Xe(Z(E,Be(k),xe(([P,j])=>!!j)),()=>{Fe(Q,!1)}),Xe(Z(ut(E,Q,x,I,k,$),xe(([P,j,ne,oe,,ie])=>P&&!j&&ne.height!==0&&oe.height!==0&&!ie)),([,,,,P])=>{Fe($,!0),Mo(1,()=>{Fe(M,P)}),$t(Z(c),()=>{Fe(e,[0,0]),Fe(Q,!0)})}),Te(Z(B,xe(P=>P!=null&&P.scrollTop>0),nn(0)),N),Xe(Z(E,Be(B),xe(([,P])=>P!=null)),([,P])=>{P&&(Fe(I,P.viewport),Fe(x,P.item),Fe(W,P.gap),P.scrollTop>0&&(Fe(L,!0),$t(Z(c,Gn(1)),j=>{Fe(L,!1)}),Fe(l,{top:P.scrollTop})))}),Te(Z(I,me(({height:P})=>P)),_),Te(Z(ut(Ae(I,Ha),Ae(x,Ha),Ae(W,(P,j)=>P&&P.column===j.column&&P.row===j.row),Ae(c)),me(([P,j,ne,oe])=>({gap:ne,item:j,scrollTop:oe,viewport:P}))),D),Te(Z(ut(Ae(R),r,Ae(W,iO),Ae(x,Ha),Ae(I,Ha),Ae(U),Ae(N),Ae(L),Ae(Q),Ae(k)),xe(([,,,,,,,P])=>!P),me(([P,[j,ne],oe,ie,Oe,be,ye,,fe,Le])=>{const{column:ce,row:he}=oe,{height:Re,width:Ce}=ie,{width:We}=Oe;if(ye===0&&(P===0||We===0))return qp;if(Ce===0){const Ze=Lo(Le,P),Nt=Ze+Math.max(ye-1,0);return aO($p(Ze,Nt,be))}const ze=Wp(We,Ce,ce);let Ke,V;fe?j===0&&ne===0&&ye>0?(Ke=0,V=ye-1):(Ke=ze*Ya((j+he)/(Re+he)),V=ze*Vp((ne+he)/(Re+he))-1,V=qo(P-1,zr(V,ze-1)),Ke=qo(V,zr(0,Ke))):(Ke=0,V=-1);const F=$p(Ke,V,be),{bottom:te,top:Se}=Kp(Oe,oe,ie,F),se=Vp(P/ze),we=se*Re+(se-1)*he-te;return{bottom:te,itemHeight:Re,items:F,itemWidth:Ce,offsetBottom:we,offsetTop:Se,top:Se}})),O),Te(Z(U,xe(P=>P!==null),me(P=>P.length)),R),Te(Z(ut(I,x,O,W),xe(([P,j,{items:ne}])=>ne.length>0&&j.height!==0&&P.height!==0),me(([P,j,{items:ne},oe])=>{const{bottom:ie,top:Oe}=Kp(P,oe,j,ne);return[Oe,ie]}),rt(Fr)),e);const q=ae(!1);Te(Z(c,Be(q),me(([P,j])=>j||P!==0)),q);const X=wt(Z(ut(O,R),xe(([{items:P}])=>P.length>0),Be(q),xe(([[P,j],ne])=>{const oe=P.items[P.items.length-1].index===j-1;return(ne||P.bottom>0&&P.itemHeight>0&&P.offsetBottom===0&&P.items.length===j)&&oe}),me(([[,P]])=>P-1),rt())),re=wt(Z(Ae(O),xe(({items:P})=>P.length>0&&P[0].index===0),nn(0),rt())),le=wt(Z(Ae(O),Be(L),xe(([{items:P},j])=>P.length>0&&!j),me(([{items:P}])=>({endIndex:P[P.length-1].index,startIndex:P[0].index})),rt(pp),En(0)));Te(le,m.scrollSeekRangeChanged),Te(Z(M,Be(I,x,R,W),me(([P,j,ne,oe,ie])=>{const Oe=bp(P),{align:be,behavior:ye,offset:fe}=Oe;let Le=Oe.index;Le==="LAST"&&(Le=oe-1),Le=zr(0,Le,qo(oe-1,Le));let ce=Vo(j,ie,ne,Le);return be==="end"?ce=zp(ce-j.height+ne.height):be==="center"&&(ce=zp(ce-j.height/2+ne.height/2)),fe&&(ce+=fe),{behavior:ye,top:ce}})),l);const H=ft(Z(O,me(P=>P.offsetBottom+P.bottom)),0);return Te(Z(v,me(P=>({height:P.visibleHeight,width:P.visibleWidth}))),I),{customScrollParent:g,data:U,deviation:z,footerHeight:a,gap:W,headerHeight:i,increaseViewportBy:t,initialItemCount:N,itemDimensions:x,overscan:n,restoreStateFrom:B,scrollBy:o,scrollContainerState:s,scrollHeight:Y,scrollTo:l,scrollToIndex:M,scrollTop:c,smoothScrollTargetReached:d,totalCount:R,useWindowScroll:S,viewportDimensions:I,windowScrollContainerState:b,windowScrollTo:h,windowViewportRect:v,...m,gridState:O,horizontalDirection:J,initialTopMostItemIndex:k,totalListHeight:H,...p,endReached:X,propsReady:f,rangeChanged:le,startReached:re,stateChanged:D,stateRestoreInProgress:L,...C}},nt(Po,Rt,Vr,xp,Nn,Uo,Rn));function Wp(t,e,n){return zr(1,Ya((t+n)/(Ya(e)+n)))}function Kp(t,e,n,r){const{height:a}=n;if(a===void 0||r.length===0)return{bottom:0,top:0};const i=Vo(t,e,n,r[0].index);return{bottom:Vo(t,e,n,r[r.length-1].index)+a,top:i}}function Vo(t,e,n,r){const a=Wp(t.width,n.width,e.column),i=Ya(r/a),o=i*n.height+zr(0,i-1)*e.row;return o>0?o+e.row:o}const sO=$e(()=>{const t=ae(_=>`Item ${_}`),e=ae({}),n=ae(null),r=ae("virtuoso-grid-item"),a=ae("virtuoso-grid-list"),i=ae(Yo),o=ae("div"),s=ae(sr),l=(_,p=null)=>ft(Z(e,me(m=>m[_]),rt()),p),c=ae(!1),d=ae(!1);return Te(Ae(d),c),{components:e,computeItemKey:i,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:o,itemClassName:r,ItemComponent:l("Item","div"),itemContent:t,listClassName:a,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),lO=$e(([t,e])=>({...t,...e}),nt(oO,sO)),cO=y.memo(function(){const t=at("gridState"),e=at("listClassName"),n=at("itemClassName"),r=at("itemContent"),a=at("computeItemKey"),i=at("isSeeking"),o=Yt("scrollHeight"),s=at("ItemComponent"),l=at("ListComponent"),c=at("ScrollSeekPlaceholder"),d=at("context"),_=Yt("itemDimensions"),p=Yt("gap"),m=at("log"),E=at("stateRestoreInProgress"),f=Yt("reportReadyState"),g=Yn(y.useMemo(()=>S=>{const b=S.parentElement.parentElement.scrollHeight;o(b);const h=S.firstChild;if(h){const{height:v,width:C}=h.getBoundingClientRect();_({height:v,width:C})}p({column:jp("column-gap",getComputedStyle(S).columnGap,m),row:jp("row-gap",getComputedStyle(S).rowGap,m)})},[o,_,p,m]),!0,!1);return kp(()=>{t.itemHeight>0&&t.itemWidth>0&&f(!0)},[t]),E?null:u.jsx(l,{className:e,ref:g,...St(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(S=>{const b=a(S.index,S.data,d);return i?u.jsx(c,{...St(c,d),height:t.itemHeight,index:S.index,width:t.itemWidth},b):y.createElement(s,{...St(s,d),className:n,"data-index":S.index,key:b},r(S.index,S.data,d))})})}),dO=y.memo(function(){const t=at("HeaderComponent"),e=Yt("headerHeight"),n=at("headerFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,!1),a=at("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null}),uO=y.memo(function(){const t=at("FooterComponent"),e=Yt("footerHeight"),n=at("headerFooterTag"),r=Yn(y.useMemo(()=>i=>{e(vn(i,"height"))},[e]),!0,!1),a=at("context");return t?u.jsx(n,{ref:r,children:u.jsx(t,{...St(t,a)})}):null}),_O=({children:t})=>{const e=y.useContext(Pp),n=Yt("itemDimensions"),r=Yt("viewportDimensions"),a=Yn(y.useMemo(()=>i=>{r(i.getBoundingClientRect())},[r]),!0,!1);return y.useEffect(()=>{e&&(r({height:e.viewportHeight,width:e.viewportWidth}),n({height:e.itemHeight,width:e.itemWidth}))},[e,r,n]),u.jsx("div",{ref:a,style:Ga(!1),children:t})},pO=({children:t})=>{const e=y.useContext(Pp),n=Yt("windowViewportRect"),r=Yt("itemDimensions"),a=at("customScrollParent"),i=op(n,a,!1);return y.useEffect(()=>{e&&(r({height:e.itemHeight,width:e.itemWidth}),n({offsetTop:0,visibleHeight:e.viewportHeight,visibleWidth:e.viewportWidth}))},[e,n,r]),u.jsx("div",{ref:i,style:Ga(!1),children:t})},mO=y.memo(function({...t}){const e=at("useWindowScroll"),n=at("customScrollParent"),r=n||e?EO:gO,a=n||e?pO:_O,i=at("context");return u.jsx(r,{...t,...St(r,i),children:u.jsxs(a,{children:[u.jsx(dO,{}),u.jsx(cO,{}),u.jsx(uO,{})]})})}),{useEmitter:Qp,useEmitterValue:at,usePublisher:Yt}=Mp(lO,{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"}},mO),gO=Yp({useEmitter:Qp,useEmitterValue:at,usePublisher:Yt}),EO=Hp({useEmitter:Qp,useEmitterValue:at,usePublisher:Yt});function jp(t,e,n){return e!=="normal"&&!(e!=null&&e.endsWith("px"))&&n(`${t} was not resolved to pixel value correctly`,e,At.WARN),e==="normal"?0:parseInt(e??"0",10)}const fO=yr.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 Xp({className:t,variant:e,...n}){return u.jsx("div",{className:K(fO({variant:e}),t),...n})}function de(t,e,{checkForDefaultPrevented:n=!0}={}){return function(a){if(t==null||t(a),n===!1||!a.defaultPrevented)return e==null?void 0:e(a)}}function SO(t,e){const n=T.createContext(e),r=i=>{const{children:o,...s}=i,l=T.useMemo(()=>s,Object.values(s));return u.jsx(n.Provider,{value:l,children:o})};r.displayName=t+"Provider";function a(i){const o=T.useContext(n);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${i}\` must be used within \`${t}\``)}return[r,a]}function Kt(t,e=[]){let n=[];function r(i,o){const s=T.createContext(o),l=n.length;n=[...n,o];const c=_=>{var S;const{scope:p,children:m,...E}=_,f=((S=p==null?void 0:p[t])==null?void 0:S[l])||s,g=T.useMemo(()=>E,Object.values(E));return u.jsx(f.Provider,{value:g,children:m})};c.displayName=i+"Provider";function d(_,p){var f;const m=((f=p==null?void 0:p[t])==null?void 0:f[l])||s,E=T.useContext(m);if(E)return E;if(o!==void 0)return o;throw new Error(`\`${_}\` must be used within \`${i}\``)}return[c,d]}const a=()=>{const i=n.map(o=>T.createContext(o));return function(s){const l=(s==null?void 0:s[t])||i;return T.useMemo(()=>({[`__scope${t}`]:{...s,[t]:l}}),[s,l])}};return a.scopeName=t,[r,bO(a,...e)]}function bO(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(i){const o=r.reduce((s,{useScope:l,scopeName:c})=>{const _=l(i)[`__scope${c}`];return{...s,..._}},{});return T.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return n.scopeName=e.scopeName,n}var mt=globalThis!=null&&globalThis.document?T.useLayoutEffect:()=>{},TO=T[" useInsertionEffect ".trim().toString()]||mt;function On({prop:t,defaultProp:e,onChange:n=()=>{},caller:r}){const[a,i,o]=hO({defaultProp:e,onChange:n}),s=t!==void 0,l=s?t:a;{const d=T.useRef(t!==void 0);T.useEffect(()=>{const _=d.current;_!==s&&console.warn(`${r} is changing from ${_?"controlled":"uncontrolled"} to ${s?"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=s},[s,r])}const c=T.useCallback(d=>{var _;if(s){const p=CO(d)?d(t):d;p!==t&&((_=o.current)==null||_.call(o,p))}else i(d)},[s,t,i,o]);return[l,c]}function hO({defaultProp:t,onChange:e}){const[n,r]=T.useState(t),a=T.useRef(n),i=T.useRef(e);return TO(()=>{i.current=e},[e]),T.useEffect(()=>{var o;a.current!==n&&((o=i.current)==null||o.call(i,n),a.current=n)},[n,a]),[n,r,i]}function CO(t){return typeof t=="function"}function Zp(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function zo(...t){return e=>{let n=!1;const r=t.map(a=>{const i=Zp(a,e);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():Zp(t[a],null)}}}}function Ge(...t){return T.useCallback(zo(...t),t)}var RO=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],De=RO.reduce((t,e)=>{const n=Dt.createSlot(`Primitive.${e}`),r=T.forwardRef((a,i)=>{const{asChild:o,...s}=a,l=o?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...s,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function Jp(t,e){t&&Ea.flushSync(()=>t.dispatchEvent(e))}function vO(t,e){return T.useReducer((n,r)=>e[n][r]??n,t)}var xt=t=>{const{present:e,children:n}=t,r=NO(e),a=typeof n=="function"?n({present:r.isPresent}):T.Children.only(n),i=Ge(r.ref,OO(a));return typeof n=="function"||r.isPresent?T.cloneElement(a,{ref:i}):null};xt.displayName="Presence";function NO(t){const[e,n]=T.useState(),r=T.useRef(null),a=T.useRef(t),i=T.useRef("none"),o=t?"mounted":"unmounted",[s,l]=vO(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return T.useEffect(()=>{const c=qa(r.current);i.current=s==="mounted"?c:"none"},[s]),mt(()=>{const c=r.current,d=a.current;if(d!==t){const p=i.current,m=qa(c);t?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),a.current=t}},[t,l]),mt(()=>{if(e){let c;const d=e.ownerDocument.defaultView??window,_=m=>{const f=qa(r.current).includes(CSS.escape(m.animationName));if(m.target===e&&f&&(l("ANIMATION_END"),!a.current)){const g=e.style.animationFillMode;e.style.animationFillMode="forwards",c=d.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=g)})}},p=m=>{m.target===e&&(i.current=qa(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",_),e.addEventListener("animationend",_),()=>{d.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",_),e.removeEventListener("animationend",_)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:T.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function qa(t){return(t==null?void 0:t.animationName)||"none"}function OO(t){var r,a;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(a=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:a.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var yO=T[" useId ".trim().toString()]||(()=>{}),IO=0;function Qt(t){const[e,n]=T.useState(yO());return mt(()=>{n(r=>r??String(IO++))},[t]),t||(e?`radix-${e}`:"")}var Va="Collapsible",[AO,J0]=Kt(Va),[xO,$o]=AO(Va),em=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,open:r,defaultOpen:a,disabled:i,onOpenChange:o,...s}=t,[l,c]=On({prop:r,defaultProp:a??!1,onChange:o,caller:Va});return u.jsx(xO,{scope:n,disabled:i,contentId:Qt(),open:l,onOpenToggle:T.useCallback(()=>c(d=>!d),[c]),children:u.jsx(De.div,{"data-state":Ko(l),"data-disabled":i?"":void 0,...s,ref:e})})});em.displayName=Va;var tm="CollapsibleTrigger",nm=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,...r}=t,a=$o(tm,n);return u.jsx(De.button,{type:"button","aria-controls":a.contentId,"aria-expanded":a.open||!1,"data-state":Ko(a.open),"data-disabled":a.disabled?"":void 0,disabled:a.disabled,...r,ref:e,onClick:de(t.onClick,a.onOpenToggle)})});nm.displayName=tm;var Wo="CollapsibleContent",DO=T.forwardRef((t,e)=>{const{forceMount:n,...r}=t,a=$o(Wo,t.__scopeCollapsible);return u.jsx(xt,{present:n||a.open,children:({present:i})=>u.jsx(wO,{...r,ref:e,present:i})})});DO.displayName=Wo;var wO=T.forwardRef((t,e)=>{const{__scopeCollapsible:n,present:r,children:a,...i}=t,o=$o(Wo,n),[s,l]=T.useState(r),c=T.useRef(null),d=Ge(e,c),_=T.useRef(0),p=_.current,m=T.useRef(0),E=m.current,f=o.open||s,g=T.useRef(f),S=T.useRef(void 0);return T.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),mt(()=>{const b=c.current;if(b){S.current=S.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const h=b.getBoundingClientRect();_.current=h.height,m.current=h.width,g.current||(b.style.transitionDuration=S.current.transitionDuration,b.style.animationName=S.current.animationName),l(r)}},[o.open,r]),u.jsx(De.div,{"data-state":Ko(o.open),"data-disabled":o.disabled?"":void 0,id:o.contentId,hidden:!f,...i,ref:d,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...t.style},children:f&&a})});function Ko(t){return t?"open":"closed"}var MO=em;const rm=MO,am=nm,im=new URL("data:video/mp2t;base64,Ly8vIDxyZWZlcmVuY2UgbGliPSJ3ZWJ3b3JrZXIiIC8+CmltcG9ydCBtYXJrZWQgZnJvbSAnbWFya2VkJzsKCmRlY2xhcmUgY29uc3Qgc2VsZjogRGVkaWNhdGVkV29ya2VyR2xvYmFsU2NvcGU7CmNvbnN0IHNjb3BlOiBEZWRpY2F0ZWRXb3JrZXJHbG9iYWxTY29wZSA9IHNlbGY7CgpzY29wZS5wb3N0TWVzc2FnZT8uKHsgd29ya2VyX3JlYWR5OiB0cnVlIH0pOwoKc2NvcGUuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsIChldmVudDogTWVzc2FnZUV2ZW50KSA9PiB7CiAgY29uc3QgcGF5bG9hZDogYW55ID0gZXZlbnQ/LmRhdGEgPz8ge307CiAgY29uc3QgaWQgPSB0eXBlb2YgcGF5bG9hZC5pZCA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLmlkIDogdW5kZWZpbmVkOwogIGNvbnN0IGtleSA9IHR5cGVvZiBwYXlsb2FkLmtleSA9PT0gJ3N0cmluZycgPyBwYXlsb2FkLmtleSA6IHVuZGVmaW5lZDsKICBjb25zdCBzb3VyY2UgPSB0eXBlb2YgcGF5bG9hZC5zb3VyY2UgPT09ICdzdHJpbmcnID8gcGF5bG9hZC5zb3VyY2UgOiB1bmRlZmluZWQ7CiAgaWYgKCFpZCB8fCB0eXBlb2Ygc291cmNlICE9PSAnc3RyaW5nJykgcmV0dXJuOwoKICB0cnkgewogICAgY29uc3QgaHRtbCA9IG1hcmtlZC5wYXJzZShzb3VyY2UpOwogICAgc2NvcGUucG9zdE1lc3NhZ2UoeyBpZCwga2V5LCBodG1sIH0pOwogIH0gY2F0Y2ggKGVycikgewogICAgc2NvcGUucG9zdE1lc3NhZ2UoeyBpZCwga2V5LCBodG1sOiBgPHByZT5FcnJvciByZW5kZXJpbmcgbWFya2Rvd246ICR7U3RyaW5nKGVycil9PC9wcmU+YCB9KTsKICB9Cn0pOwo=",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:ro&&ro.tagName.toUpperCase()==="SCRIPT"&&ro.src||new URL("index.umd.js",document.baseURI).href),$r=im.toString(),LO=(()=>{try{if(typeof Worker>"u"||typeof URL>"u"||typeof Blob>"u")return!1;const t=new Blob(["export default null;"],{type:"application/javascript"}),e=URL.createObjectURL(t);return new Worker(e,{type:"module"}).terminate(),URL.revokeObjectURL(e),!0}catch{return!1}})(),PO=$r.includes("data:"),kO=(()=>{if(typeof navigator>"u")return!1;const t=navigator.userAgent.toLowerCase();return t.includes("safari")&&!t.includes("chrome")&&!t.includes("android")})(),Qo=LO&&!(PO&&kO),jo=t=>typeof t=="object"&&t!==null,Xo=t=>typeof t=="function"?t:jo(t)&&typeof t.parse=="function"?t.parse:null;let za=null;async function om(t){try{za||(za=Promise.resolve().then(()=>KM));const e=await za,n=jo(e)?e:{},r=Xo(n.parse)??Xo(n.marked)??Xo(n.default);return r?r(t):""}catch(e){throw za=null,e}}const UO=t=>jo(t)&&typeof t.highlightElement=="function"?{highlightElement:t.highlightElement}:null;console.log("[MarkdownContent] worker url",$r);const Wr=[];let Kr=!1;const sm={addEventListener:()=>{},removeEventListener:()=>{},postMessage:()=>{},terminate:()=>{}};let yn=sm;const lm=t=>{console.error("[MarkdownContent] worker error",t)};function Zo(t){if(yn&&yn!==sm)try{yn.removeEventListener("error",lm)}catch{}yn=t,Kr=!0;try{yn.addEventListener("error",lm)}catch(e){console.warn("[MarkdownContent] failed to register worker error handler",e)}try{for(;Wr.length;){const e=Wr.shift();if(e)try{e()}catch{}}}catch(e){console.warn("[MarkdownContent] markWorkerOnline notify failed",e)}}function FO(t){if(!Qo)return null;const e=t.indexOf("data:");if(e===-1)return null;const r=t.slice(e).match(/^data:[^;]+;base64,(.*)$/);if(!r)return null;try{const a=r[1],i=atob(a),o=Uint8Array.from(i,c=>c.charCodeAt(0)),s=new Blob([o],{type:"application/javascript"}),l=URL.createObjectURL(s);try{const c=new Worker(l,{type:"module"});return URL.revokeObjectURL(l),c}catch(c){return URL.revokeObjectURL(l),console.error("[MarkdownContent] failed to initialize worker from data URI blob",c),null}}catch(a){return console.warn("[MarkdownContent] failed to decode embedded data URI",a),null}}async function BO(t){if(Qo)try{let e="";const n=await fetch(t);if(e=await n.text(),n.ok||console.warn("[MarkdownContent] fetch worker non-ok",n.status,n.statusText),!e){console.warn("[MarkdownContent] worker fetch returned empty content; aborting worker init.");return}if(e.trim().startsWith("<")){console.warn("[MarkdownContent] worker fetch returned HTML; dev server may be redirecting. Aborting worker init.");return}const r=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(r);try{const i=new Worker(a,{type:"module"});Zo(i)}catch(i){console.error("[MarkdownContent] failed to initialize worker from blob",i)}finally{URL.revokeObjectURL(a)}}catch(e){console.error("[MarkdownContent] fetch worker failed",e)}}function GO(){if($r.includes("data:")){const t=FO($r);if(t){Zo(t);return}console.warn("[MarkdownContent] data URI bootstrap failed; worker will remain offline until fallback succeeds");return}try{const t=new Worker(im,{type:"module"});Zo(t)}catch(t){console.warn("[MarkdownContent] worker constructor failed, will try fetch+blob fallback",t),BO($r)}}Qo?GO():console.warn("[MarkdownContent] module workers not supported; falling back to main-thread markdown parsing");const Qr=new Map;function YO(t,e=!1){if(e){const a=t.slice(0,128);return`streaming:${Math.floor(t.length/50)*50}:${a}`}const n=t.slice(0,64),r=t.length>64?t.slice(-64):"";return`${t.length}:${n}:${r}`}function HO(t,e){const[n,r]=y.useState(t),a=y.useRef(t),i=y.useRef(null);return y.useEffect(()=>{if(!e){r(t);return}return a.current=t,i.current===null&&(i.current=requestAnimationFrame(()=>{i.current=null,r(a.current)})),()=>{i.current&&cancelAnimationFrame(i.current)}},[t,e]),n}function $a({content:t,className:e="",fallback:n=u.jsx("div",{"aria-busy":!0,children:"Rendering…"}),isStreaming:r=!1,hideFallbackDuringStreaming:a=!0,streamingThrottleMs:i=16,useWorker:o}){const s=HO(t,r),l=YO(s,r),[c,d]=y.useState(()=>{var E;return((E=Qr.get(l))==null?void 0:E.html)??null}),_=y.useRef(null),p=y.useRef([]);y.useEffect(()=>{p.current=[];const E=Qr.get(l);if(E&&E.source===s){E.html!==c&&d(E.html);return}if(E&&E.html!==c&&d(E.html),!(o!==void 0?o:Kr&&!r)){console.log(`[MarkdownContent] Using main-thread parsing (streaming: ${r}, worker: ${o})`);let I=!1;return(async()=>{try{const x=await om(s);Qr.set(l,{html:x,source:s}),I||d(x)}catch(x){console.error("[MarkdownContent] fallback parse failed",x)}})(),()=>{I=!0}}let g=!0,S=!1;const b=`${l}::${Date.now().toString(36)}::${Math.random().toString(36).slice(2)}`;_.current=b;const h=I=>{const x=I.data;if(!x||x.id!==b||x.key&&x.key!==l||!g)return;S=!0;const M=x.html??"";Qr.set(l,{html:M,source:s}),d(M)};yn.addEventListener("message",h);const v=()=>{try{yn.postMessage({id:b,key:l,source:s})}catch(I){console.error("[MarkdownContent] worker.postMessage threw",I)}},C=()=>{if(!r||i<=0){v();return}if(typeof window>"u"){v();return}const I=window.setTimeout(()=>{if(typeof window.requestAnimationFrame=="function"){const x=window.requestAnimationFrame(()=>{v()});p.current.push({type:"raf",id:x})}else v()},i);p.current.push({type:"timeout",id:I})};Kr?C():Wr.push(C);const N=((I,x,M)=>x?M?I>2e4?15e3:I>8e3?8e3:I>2e3?3e3:1e3:I>2e4?1e4:I>8e3?5e3:I>2e3?2e3:600:Math.min(15e3,2e3+Math.floor(I*.5)))(s.length,Kr,r),O=window.setTimeout(async()=>{if(!S){console.warn("[MarkdownContent] worker timeout (ms="+N+"), falling back to main-thread parse for",l);try{const I=await om(s);Qr.set(l,{html:I,source:s}),g&&_.current===b&&d(I)}catch(I){console.error("[MarkdownContent] fallback parse failed",I)}}},N);return()=>{if(g=!1,clearTimeout(O),yn.removeEventListener("message",h),_.current===b&&(_.current=null),!Kr){const I=Wr.indexOf(C);I>=0&&Wr.splice(I,1)}p.current.forEach(I=>{I.type==="timeout"?clearTimeout(I.id):I.type==="raf"&&cancelAnimationFrame(I.id)}),p.current=[]}},[s,c,r,l,i]);const m=y.useRef(null);return y.useEffect(()=>{if(!c)return;const E=m.current;if(!E)return;const f=Array.from(E.querySelectorAll("pre code"));if(!f.length)return;let g=null,S=!1;const b=(v,C)=>{for(const R of v){if(!R.isIntersecting)continue;const N=R.target;if(!g)Promise.resolve().then(()=>S0).then(O=>{if(S)return;const I=UO(O.default??O);if(I){g=I;try{f.forEach(x=>{E.contains(x)&&(g==null||g.highlightElement(x))})}catch{}}}).catch(()=>{});else try{g.highlightElement(N)}catch{}C.unobserve(N)}},h=new IntersectionObserver(b,{root:E,threshold:.1});return f.forEach(v=>h.observe(v)),()=>{S=!0,h.disconnect()}},[c]),c?u.jsx("div",{ref:m,className:K("markdown prose max-w-none break-words dark:prose-invert",e),dangerouslySetInnerHTML:{__html:c}}):r&&a?null:u.jsx("div",{className:K("markdown prose max-w-none break-words dark:prose-invert",e),children:n})}async function cm(t,e){return await Ft(t,{responseType:"blob",onDownloadProgress:r=>{try{e&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function dm(t,e){return await(await cm(`/chat/files/${t}/view`,e)).text()}async function qO(t,e){const n=await cm(`/chat/files/${t}/download`,e),r=URL.createObjectURL(n);let a=`file_${t}`;try{const o=await Ft(`/chat/files/${t}`);a=(o==null?void 0:o.filename)??a}catch{}const i=document.createElement("a");i.href=r,i.download=a,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}const VO=1,zO=1e6;let Jo=0;function $O(){return Jo=(Jo+1)%Number.MAX_SAFE_INTEGER,Jo.toString()}const es=new Map,um=t=>{if(es.has(t))return;const e=setTimeout(()=>{es.delete(t),jr({type:"REMOVE_TOAST",toastId:t})},zO);es.set(t,e)},WO=(t,e)=>{switch(e.type){case"ADD_TOAST":return{...t,toasts:[e.toast,...t.toasts].slice(0,VO)};case"UPDATE_TOAST":return{...t,toasts:t.toasts.map(n=>n.id===e.toast.id?{...n,...e.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=e;return n?um(n):t.toasts.forEach(r=>{um(r.id)}),{...t,toasts:t.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return e.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(n=>n.id!==e.toastId)}}},Wa=[];let Ka={toasts:[]};function jr(t){Ka=WO(Ka,t),Wa.forEach(e=>{e(Ka)})}function KO({...t}){const e=$O(),n=a=>jr({type:"UPDATE_TOAST",toast:{...a,id:e}}),r=()=>jr({type:"DISMISS_TOAST",toastId:e});return jr({type:"ADD_TOAST",toast:{...t,id:e,open:!0,onOpenChange:a=>{a||r()}}}),{id:e,dismiss:r,update:n}}function ts(){const[t,e]=T.useState(Ka);return T.useEffect(()=>(Wa.push(e),()=>{const n=Wa.indexOf(e);n>-1&&Wa.splice(n,1)}),[t]),{...t,toast:KO,dismiss:n=>jr({type:"DISMISS_TOAST",toastId:n})}}function gt(t){const e=T.useRef(t);return T.useEffect(()=>{e.current=t}),T.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function QO(t,e=globalThis==null?void 0:globalThis.document){const n=gt(t);T.useEffect(()=>{const r=a=>{a.key==="Escape"&&n(a)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var jO="DismissableLayer",ns="dismissableLayer.update",XO="dismissableLayer.pointerDownOutside",ZO="dismissableLayer.focusOutside",_m,pm=T.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Xr=T.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:a,onFocusOutside:i,onInteractOutside:o,onDismiss:s,...l}=t,c=T.useContext(pm),[d,_]=T.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=T.useState({}),E=Ge(e,N=>_(N)),f=Array.from(c.layers),[g]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=f.indexOf(g),b=d?f.indexOf(d):-1,h=c.layersWithOutsidePointerEventsDisabled.size>0,v=b>=S,C=ty(N=>{const O=N.target,I=[...c.branches].some(x=>x.contains(O));!v||I||(a==null||a(N),o==null||o(N),N.defaultPrevented||s==null||s())},p),R=ny(N=>{const O=N.target;[...c.branches].some(x=>x.contains(O))||(i==null||i(N),o==null||o(N),N.defaultPrevented||s==null||s())},p);return QO(N=>{b===c.layers.size-1&&(r==null||r(N),!N.defaultPrevented&&s&&(N.preventDefault(),s()))},p),T.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(_m=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),mm(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=_m)}},[d,p,n,c]),T.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),mm())},[d,c]),T.useEffect(()=>{const N=()=>m({});return document.addEventListener(ns,N),()=>document.removeEventListener(ns,N)},[]),u.jsx(De.div,{...l,ref:E,style:{pointerEvents:h?v?"auto":"none":void 0,...t.style},onFocusCapture:de(t.onFocusCapture,R.onFocusCapture),onBlurCapture:de(t.onBlurCapture,R.onBlurCapture),onPointerDownCapture:de(t.onPointerDownCapture,C.onPointerDownCapture)})});Xr.displayName=jO;var JO="DismissableLayerBranch",ey=T.forwardRef((t,e)=>{const n=T.useContext(pm),r=T.useRef(null),a=Ge(e,r);return T.useEffect(()=>{const i=r.current;if(i)return n.branches.add(i),()=>{n.branches.delete(i)}},[n.branches]),u.jsx(De.div,{...t,ref:a})});ey.displayName=JO;function ty(t,e=globalThis==null?void 0:globalThis.document){const n=gt(t),r=T.useRef(!1),a=T.useRef(()=>{});return T.useEffect(()=>{const i=s=>{if(s.target&&!r.current){let l=function(){gm(XO,n,c,{discrete:!0})};const c={originalEvent:s};s.pointerType==="touch"?(e.removeEventListener("click",a.current),a.current=l,e.addEventListener("click",a.current,{once:!0})):l()}else e.removeEventListener("click",a.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",i),e.removeEventListener("click",a.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function ny(t,e=globalThis==null?void 0:globalThis.document){const n=gt(t),r=T.useRef(!1);return T.useEffect(()=>{const a=i=>{i.target&&!r.current&&gm(ZO,n,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",a),()=>e.removeEventListener("focusin",a)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function mm(){const t=new CustomEvent(ns);document.dispatchEvent(t)}function gm(t,e,n,{discrete:r}){const a=n.originalEvent.target,i=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&a.addEventListener(t,e,{once:!0}),r?Jp(a,i):a.dispatchEvent(i)}var rs="focusScope.autoFocusOnMount",as="focusScope.autoFocusOnUnmount",Em={bubbles:!1,cancelable:!0},ry="FocusScope",Qa=T.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:i,...o}=t,[s,l]=T.useState(null),c=gt(a),d=gt(i),_=T.useRef(null),p=Ge(e,f=>l(f)),m=T.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;T.useEffect(()=>{if(r){let f=function(h){if(m.paused||!s)return;const v=h.target;s.contains(v)?_.current=v:In(_.current,{select:!0})},g=function(h){if(m.paused||!s)return;const v=h.relatedTarget;v!==null&&(s.contains(v)||In(_.current,{select:!0}))},S=function(h){if(document.activeElement===document.body)for(const C of h)C.removedNodes.length>0&&In(s)};document.addEventListener("focusin",f),document.addEventListener("focusout",g);const b=new MutationObserver(S);return s&&b.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",f),document.removeEventListener("focusout",g),b.disconnect()}}},[r,s,m.paused]),T.useEffect(()=>{if(s){bm.add(m);const f=document.activeElement;if(!s.contains(f)){const S=new CustomEvent(rs,Em);s.addEventListener(rs,c),s.dispatchEvent(S),S.defaultPrevented||(ay(cy(fm(s)),{select:!0}),document.activeElement===f&&In(s))}return()=>{s.removeEventListener(rs,c),setTimeout(()=>{const S=new CustomEvent(as,Em);s.addEventListener(as,d),s.dispatchEvent(S),S.defaultPrevented||In(f??document.body,{select:!0}),s.removeEventListener(as,d),bm.remove(m)},0)}}},[s,c,d,m]);const E=T.useCallback(f=>{if(!n&&!r||m.paused)return;const g=f.key==="Tab"&&!f.altKey&&!f.ctrlKey&&!f.metaKey,S=document.activeElement;if(g&&S){const b=f.currentTarget,[h,v]=iy(b);h&&v?!f.shiftKey&&S===v?(f.preventDefault(),n&&In(h,{select:!0})):f.shiftKey&&S===h&&(f.preventDefault(),n&&In(v,{select:!0})):S===b&&f.preventDefault()}},[n,r,m.paused]);return u.jsx(De.div,{tabIndex:-1,...o,ref:p,onKeyDown:E})});Qa.displayName=ry;function ay(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(In(r,{select:e}),document.activeElement!==n)return}function iy(t){const e=fm(t),n=Sm(e,t),r=Sm(e.reverse(),t);return[n,r]}function fm(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function Sm(t,e){for(const n of t)if(!oy(n,{upTo:e}))return n}function oy(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function sy(t){return t instanceof HTMLInputElement&&"select"in t}function In(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&sy(t)&&e&&t.select()}}var bm=ly();function ly(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=Tm(t,e),t.unshift(e)},remove(e){var n;t=Tm(t,e),(n=t[0])==null||n.resume()}}}function Tm(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function cy(t){return t.filter(e=>e.tagName!=="A")}var dy="Portal",ja=T.forwardRef((t,e)=>{var s;const{container:n,...r}=t,[a,i]=T.useState(!1);mt(()=>i(!0),[]);const o=n||a&&((s=globalThis==null?void 0:globalThis.document)==null?void 0:s.body);return o?no.createPortal(u.jsx(De.div,{...r,ref:e}),o):null});ja.displayName=dy;var is=0;function os(){T.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??hm()),document.body.insertAdjacentElement("beforeend",t[1]??hm()),is++,()=>{is===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),is--}},[])}function hm(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var on=function(){return on=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},on.apply(this,arguments)};function Cm(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function uy(t,e,n){if(n||arguments.length===2)for(var r=0,a=e.length,i;r<a;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;var Xa="right-scroll-bar-position",Za="width-before-scroll-bar",_y="with-scroll-bars-hidden",py="--removed-body-scroll-bar-size";function ss(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function my(t,e){var n=y.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=e,n.facade}var gy=typeof window<"u"?T.useLayoutEffect:T.useEffect,Rm=new WeakMap;function Ey(t,e){var n=my(null,function(r){return t.forEach(function(a){return ss(a,r)})});return gy(function(){var r=Rm.get(n);if(r){var a=new Set(r),i=new Set(t),o=n.current;a.forEach(function(s){i.has(s)||ss(s,null)}),i.forEach(function(s){a.has(s)||ss(s,o)})}Rm.set(n,t)},[t]),n}function fy(t){return t}function Sy(t,e){e===void 0&&(e=fy);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:t},useMedium:function(i){var o=e(i,r);return n.push(o),function(){n=n.filter(function(s){return s!==o})}},assignSyncMedium:function(i){for(r=!0;n.length;){var o=n;n=[],o.forEach(i)}n={push:function(s){return i(s)},filter:function(){return n}}},assignMedium:function(i){r=!0;var o=[];if(n.length){var s=n;n=[],s.forEach(i),o=n}var l=function(){var d=o;o=[],d.forEach(i)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){o.push(d),c()},filter:function(d){return o=o.filter(d),n}}}};return a}function by(t){t===void 0&&(t={});var e=Sy(null);return e.options=on({async:!0,ssr:!1},t),e}var vm=function(t){var e=t.sideCar,n=Cm(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return T.createElement(r,on({},n))};vm.isSideCarExport=!0;function Ty(t,e){return t.useMedium(e),vm}var Nm=by(),ls=function(){},Ja=T.forwardRef(function(t,e){var n=T.useRef(null),r=T.useState({onScrollCapture:ls,onWheelCapture:ls,onTouchMoveCapture:ls}),a=r[0],i=r[1],o=t.forwardProps,s=t.children,l=t.className,c=t.removeScrollBar,d=t.enabled,_=t.shards,p=t.sideCar,m=t.noRelative,E=t.noIsolation,f=t.inert,g=t.allowPinchZoom,S=t.as,b=S===void 0?"div":S,h=t.gapMode,v=Cm(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,R=Ey([n,e]),N=on(on({},v),a);return T.createElement(T.Fragment,null,d&&T.createElement(C,{sideCar:Nm,removeScrollBar:c,shards:_,noRelative:m,noIsolation:E,inert:f,setCallbacks:i,allowPinchZoom:!!g,lockRef:n,gapMode:h}),o?T.cloneElement(T.Children.only(s),on(on({},N),{ref:R})):T.createElement(b,on({},N,{className:l,ref:R}),s))});Ja.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ja.classNames={fullWidth:Za,zeroRight:Xa};var hy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Cy(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=hy();return e&&t.setAttribute("nonce",e),t}function Ry(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function vy(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Ny=function(){var t=0,e=null;return{add:function(n){t==0&&(e=Cy())&&(Ry(e,n),vy(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Oy=function(){var t=Ny();return function(e,n){T.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},Om=function(){var t=Oy(),e=function(n){var r=n.styles,a=n.dynamic;return t(r,a),null};return e},yy={left:0,top:0,right:0,gap:0},cs=function(t){return parseInt(t||"",10)||0},Iy=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],a=e[t==="padding"?"paddingRight":"marginRight"];return[cs(n),cs(r),cs(a)]},Ay=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return yy;var e=Iy(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},xy=Om(),cr="data-scroll-locked",Dy=function(t,e,n,r){var a=t.left,i=t.top,o=t.right,s=t.gap;return n===void 0&&(n="margin"),`
|
|
39
39
|
.`.concat(_y,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(s,"px ").concat(r,`;
|
package/package.json
CHANGED