teodor-new-chat-ui 4.3.462 → 4.3.463
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 +209 -205
- package/dist/index.umd.js +6 -6
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function($,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom","lucide-react"],b):($=typeof globalThis<"u"?globalThis:$||self,b($.NewChatUI={},$.React,$.reactSlot,$.classVarianceAuthority,$.clsx,$.tailwindMerge,$.ReactDOM,$.LucideReact))})(this,function($,b,Yt,zr,rx,ox,Ro,ue){"use strict";var rN=Object.defineProperty;var oN=($,b,Yt)=>b in $?rN($,b,{enumerable:!0,configurable:!0,writable:!0,value:Yt}):$[b]=Yt;var tx=($,b,Yt)=>oN($,typeof b!="symbol"?b+"":b,Yt);function Zl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const p=Zl(b),Hr=Zl(Ro),Ql=120;function sx(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Ql?`${n.slice(0,Ql-3)}…`:n:""}function mi(e){return sx(e.content)||""}function ix(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=mi(o);s&&t.set(r.checkpointId,s)}}return t}function ec(e){const t=new Map,n=[],r=new Map,o=[];for(let c=0;c<e.length;c++){const d=e[c],h=d.checkpointId,m=h??`cp-${c}`,f=d.metadata??{},v=typeof f.step=="number"?f.step:null,g=typeof f.source=="string"?f.source:null;let x=null,y=null;const w=Array.isArray(d.messages)?d.messages:[];for(const T of w)T.role==="user"&&(y||(y=T),T.id&&(x=T.id));const S=d.next&&d.next.length>0?String(d.next[0]):null,k=d.parentConfig??null,C={id:m,step:v,source:g,createdAt:d.createdAt??null,namespace:d.checkpointNs??null,parentId:d.parentId??null,next:S,parentConfig:k,userMessageId:x};if(o.push(C),h&&t.set(h,C),h&&y){const T=mi(y);T&&r.set(h,T)}n.push({id:m,messageId:x,step:v,source:g,createdAt:d.createdAt??null,next:S,parentConfig:k})}const s=new Map;for(const c of o){if(!c.userMessageId)continue;const d=s.get(c.userMessageId)??[];d.push(c),s.set(c.userMessageId,d)}for(const c of s.values()){if(!c.length)continue;c.sort((h,m)=>{const f=h.createdAt?Date.parse(h.createdAt):0;return(m.createdAt?Date.parse(m.createdAt):0)-f});const d=c.length;for(let h=0;h<c.length;h++){const m=c[h];m.attemptCount=d,m.attemptIndex=h,m.isLatestAttempt=h===0}}return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const c=n[0];if(c)return t.get(c.id)},getCheckpoint:c=>t.get(c),getMessageAttempts:c=>{const d=[];for(const h of t.values())h.userMessageId===c&&d.push(h);return d.length?(d.sort((h,m)=>{const f=typeof h.attemptIndex=="number"?h.attemptIndex:Number.MAX_SAFE_INTEGER,v=typeof m.attemptIndex=="number"?m.attemptIndex:Number.MAX_SAFE_INTEGER;return f-v}),d):[]}}}function tc(e,t,n){if(!e)return{attemptCount:1,attemptIndex:0,attempts:[]};const r=n.getMessageAttempts(e);if(!r.length)return{attemptCount:1,attemptIndex:0,attempts:[]};let o=0;if(t){const s=r.findIndex(i=>i.id===t);s>=0&&(o=s)}return{attemptCount:r.length,attemptIndex:o,attempts:r}}function ax(e,t){return e?t.getCheckpoint(e)??null:null}function nc(e){return b.useMemo(()=>ec(e),[e])}function
|
|
1
|
+
(function($,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom","lucide-react"],b):($=typeof globalThis<"u"?globalThis:$||self,b($.NewChatUI={},$.React,$.reactSlot,$.classVarianceAuthority,$.clsx,$.tailwindMerge,$.ReactDOM,$.LucideReact))})(this,function($,b,Yt,zr,rx,ox,Ro,ue){"use strict";var rN=Object.defineProperty;var oN=($,b,Yt)=>b in $?rN($,b,{enumerable:!0,configurable:!0,writable:!0,value:Yt}):$[b]=Yt;var tx=($,b,Yt)=>oN($,typeof b!="symbol"?b+"":b,Yt);function Zl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const p=Zl(b),Hr=Zl(Ro),Ql=120;function sx(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Ql?`${n.slice(0,Ql-3)}…`:n:""}function mi(e){return sx(e.content)||""}function ix(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=mi(o);s&&t.set(r.checkpointId,s)}}return t}function ec(e){const t=new Map,n=[],r=new Map,o=[];for(let c=0;c<e.length;c++){const d=e[c],h=d.checkpointId,m=h??`cp-${c}`,f=d.metadata??{},v=typeof f.step=="number"?f.step:null,g=typeof f.source=="string"?f.source:null;let x=null,y=null;const w=Array.isArray(d.messages)?d.messages:[];for(const T of w)T.role==="user"&&(y||(y=T),T.id&&(x=T.id));const S=d.next&&d.next.length>0?String(d.next[0]):null,k=d.parentConfig??null,C={id:m,step:v,source:g,createdAt:d.createdAt??null,namespace:d.checkpointNs??null,parentId:d.parentId??null,next:S,parentConfig:k,userMessageId:x};if(o.push(C),h&&t.set(h,C),h&&y){const T=mi(y);T&&r.set(h,T)}n.push({id:m,messageId:x,step:v,source:g,createdAt:d.createdAt??null,next:S,parentConfig:k})}const s=new Map;for(const c of o){if(!c.userMessageId)continue;const d=s.get(c.userMessageId)??[];d.push(c),s.set(c.userMessageId,d)}for(const c of s.values()){if(!c.length)continue;c.sort((h,m)=>{const f=h.createdAt?Date.parse(h.createdAt):0;return(m.createdAt?Date.parse(m.createdAt):0)-f});const d=c.length;for(let h=0;h<c.length;h++){const m=c[h];m.attemptCount=d,m.attemptIndex=h,m.isLatestAttempt=h===0}}return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const c=n[0];if(c)return t.get(c.id)},getCheckpoint:c=>t.get(c),getMessageAttempts:c=>{const d=[];for(const h of t.values())h.userMessageId===c&&d.push(h);return d.length?(d.sort((h,m)=>{const f=typeof h.attemptIndex=="number"?h.attemptIndex:Number.MAX_SAFE_INTEGER,v=typeof m.attemptIndex=="number"?m.attemptIndex:Number.MAX_SAFE_INTEGER;return f-v}),d):[]}}}function tc(e,t,n){if(!e)return{attemptCount:1,attemptIndex:0,attempts:[]};const r=n.getMessageAttempts(e);if(!r.length)return{attemptCount:1,attemptIndex:0,attempts:[]};let o=0;if(t){const s=r.findIndex(i=>i.id===t);s>=0&&(o=s)}return{attemptCount:r.length,attemptIndex:o,attempts:r}}function ax(e,t){return e?t.getCheckpoint(e)??null:null}function nc(e){return b.useMemo(()=>ec(e),[e])}function Pn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Rn(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}}function rc(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function gi(e){const t=Pn(e);if(t)return Pn(t.configurable)??t}function Mn(e){const r=[...(Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[]).map((s,i)=>lx(s,i)).filter(s=>!!s)].sort((s,i)=>oc(i.createdAt)-oc(s.createdAt)),o=r[0]??null;return{threadId:(e==null?void 0:e.threadId)??"",latest:o,checkpoints:r,interrupt:(o==null?void 0:o.interrupt)??null}}function lx(e,t){var S;if(!e)return null;const r=(Array.isArray((S=e.values)==null?void 0:S.messages)?e.values.messages:[]).map(k=>cx(k)).filter(k=>!!k),o=Pn(e.metadata)??{},s=gi(e.config),i=Pn(e.parent_config??e.parentConfig),a=gi(i),l=Rn(s,["checkpoint_id","checkpointId"]),c=Rn(s,["checkpoint_ns","checkpointNs"]),d=Rn(a,["checkpoint_id","checkpointId"]),h=Rn(a,["checkpoint_id","checkpointId"])??null,m=Rn(a,["checkpoint_ns","checkpointNs"])??null,f=Pn(e.config),v=Array.isArray(e.tasks)?e.tasks.map(k=>({...k})):e.tasks??null,g=Array.isArray(e.next)?[...e.next]:e.next??null,x=typeof e.created_at=="string"&&e.created_at.trim()?e.created_at:typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),y={...o,step:rc(o,["step"])??0,source:Rn(o,["source"])??null},w=r.map(k=>({...k,checkpointId:l??null}));return{checkpointId:l??null,checkpointNs:c??null,createdAt:x,parentId:d??null,messages:w,nextCursor:h,nextCursorNs:m,interrupt:hx(r,t),metadata:y,config:f??null,parentConfig:i??null,next:g,tasks:v}}function cx(e){var s,i,a;if(!e||typeof e!="object")return null;const t=ux(e);if(!t)return null;const n=fx(e==null?void 0:e.content);if(!n.length)return null;const r=typeof e.createdAt=="string"?e.createdAt:typeof((s=e.additional_kwargs)==null?void 0:s.created_at)=="string"?(i=e.additional_kwargs)==null?void 0:i.created_at:new Date().toISOString();return{id:typeof e.id=="string"&&e.id.trim()?e.id:`msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`,role:t,name:typeof e.name=="string"?e.name:void 0,model:typeof e.model=="string"?e.model:((a=e.additional_kwargs)==null?void 0:a.model)??void 0,createdAt:r,content:n,additionalKwargs:e.additional_kwargs??void 0,responseMetadata:e.response_metadata??void 0,artifact:e.artifact??void 0,threadId:e.threadId??e.thread_id}}function ux(e){const t=typeof e.role=="string"?e.role:void 0;if(t&&dx(t))return t;const n=typeof e.type=="string"?e.type:void 0;if(!n)return null;switch(n){case"human":return"user";case"ai":return"assistant";case"tool":return"tool";case"system":return"system";default:return null}}function dx(e){return e==="assistant"||e==="user"||e==="system"||e==="tool"||e==="default_message"}function fx(e){return typeof e=="string"?[{type:"text",text:e}]:Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object"&&typeof t.type=="string")):[]}function hx(e,t){return px(e,t)}function px(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function oc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}var xi={exports:{}},Ur={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -32,11 +32,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
32
32
|
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[Ec]=this[Ec]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Yr(i);r[a]||(bv(o,i),r[a]=!0)}return U.isArray(t)?t.forEach(s):s(t),this}};Ht.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),U.reduceDescriptors(Ht.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),U.freezeMethods(Ht);function ki(e,t){const n=this||Gr,r=t||n,o=Ht.from(r.headers);let s=r.data;return U.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Ic(e){return!!(e&&e.__CANCEL__)}function gr(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}U.inherits(gr,Re,{__CANCEL__:!0});function Nc(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Re("Request failed with status code "+n.status,[Re.ERR_BAD_REQUEST,Re.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function wv(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function yv(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let h=s,m=0;for(;h!==o;)m+=n[h++],h=h%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const f=d&&c-d;return f?Math.round(m*1e3/f):void 0}}function Sv(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),h=d-n;h>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-h)))},()=>o&&i(o)]}const Bo=(e,t,n=3)=>{let r=0;const o=yv(50,250);return Sv(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const h={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(h)},n)},Ac=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},jc=e=>(...t)=>U.asap(()=>e(...t)),Cv=Pt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Pt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Pt.origin),Pt.navigator&&/(msie|trident)/i.test(Pt.navigator.userAgent)):()=>!0,Tv=Pt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];U.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),U.isString(r)&&i.push("path="+r),U.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function kv(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ev(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function _c(e,t,n){let r=!kv(t);return e&&(r||n==!1)?Ev(e,t):t}const Pc=e=>e instanceof Ht?{...e}:e;function Zn(e,t){t=t||{};const n={};function r(c,d,h,m){return U.isPlainObject(c)&&U.isPlainObject(d)?U.merge.call({caseless:m},c,d):U.isPlainObject(d)?U.merge({},d):U.isArray(d)?d.slice():d}function o(c,d,h,m){if(U.isUndefined(d)){if(!U.isUndefined(c))return r(void 0,c,h,m)}else return r(c,d,h,m)}function s(c,d){if(!U.isUndefined(d))return r(void 0,d)}function i(c,d){if(U.isUndefined(d)){if(!U.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,h){if(h in t)return r(c,d);if(h in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,h)=>o(Pc(c),Pc(d),h,!0)};return U.forEach(Object.keys({...e,...t}),function(d){const h=l[d]||o,m=h(e[d],t[d],d);U.isUndefined(m)&&h!==a||(n[d]=m)}),n}const Rc=e=>{const t=Zn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ht.from(i),t.url=Sc(_c(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),U.isFormData(n)){if(Pt.hasStandardBrowserEnv||Pt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(U.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,h])=>{c.includes(d.toLowerCase())&&i.set(d,h)})}}if(Pt.hasStandardBrowserEnv&&(r&&U.isFunction(r)&&(r=r(t)),r||r!==!1&&Cv(t.url))){const l=o&&s&&Tv.read(s);l&&i.set(o,l)}return t},Iv=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Rc(e);let s=o.data;const i=Ht.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,h,m,f,v;function g(){f&&f(),v&&v(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let x=new XMLHttpRequest;x.open(o.method.toUpperCase(),o.url,!0),x.timeout=o.timeout;function y(){if(!x)return;const S=Ht.from("getAllResponseHeaders"in x&&x.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?x.responseText:x.response,status:x.status,statusText:x.statusText,headers:S,config:e,request:x};Nc(function(E){n(E),g()},function(E){r(E),g()},C),x=null}"onloadend"in x?x.onloadend=y:x.onreadystatechange=function(){!x||x.readyState!==4||x.status===0&&!(x.responseURL&&x.responseURL.indexOf("file:")===0)||setTimeout(y)},x.onabort=function(){x&&(r(new Re("Request aborted",Re.ECONNABORTED,e,x)),x=null)},x.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Re(C,Re.ERR_NETWORK,e,x);T.event=k||null,r(T),x=null},x.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||Tc;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Re(k,C.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,x)),x=null},s===void 0&&i.setContentType(null),"setRequestHeader"in x&&U.forEach(i.toJSON(),function(k,C){x.setRequestHeader(C,k)}),U.isUndefined(o.withCredentials)||(x.withCredentials=!!o.withCredentials),a&&a!=="json"&&(x.responseType=o.responseType),c&&([m,v]=Bo(c,!0),x.addEventListener("progress",m)),l&&x.upload&&([h,f]=Bo(l),x.upload.addEventListener("progress",h),x.upload.addEventListener("loadend",f)),(o.cancelToken||o.signal)&&(d=S=>{x&&(r(!S||S.type?new gr(null,e,x):S),x.abort(),x=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=wv(o.url);if(w&&Pt.protocols.indexOf(w)===-1){r(new Re("Unsupported protocol "+w+":",Re.ERR_BAD_REQUEST,e));return}x.send(s||null)})},Nv=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Re?d:new gr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Re(`timeout ${t} of ms exceeded`,Re.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>U.asap(a),l}},Av=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},jv=async function*(e,t){for await(const n of _v(e))yield*Av(n,t)},_v=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Mc=(e,t,n,r)=>{const o=jv(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let h=d.byteLength;if(n){let m=s+=h;n(m)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Oc=64*1024,{isFunction:zo}=U,Pv=(({Request:e,Response:t})=>({Request:e,Response:t}))(U.global),{ReadableStream:Dc,TextEncoder:Lc}=U.global,$c=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Rv=e=>{e=U.merge.call({skipUndefined:!0},Pv,e);const{fetch:t,Request:n,Response:r}=e,o=t?zo(t):typeof fetch=="function",s=zo(n),i=zo(r);if(!o)return!1;const a=o&&zo(Dc),l=o&&(typeof Lc=="function"?(v=>g=>v.encode(g))(new Lc):async v=>new Uint8Array(await new n(v).arrayBuffer())),c=s&&a&&$c(()=>{let v=!1;const g=new n(Pt.origin,{body:new Dc,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!g}),d=i&&a&&$c(()=>U.isReadableStream(new r("").body)),h={stream:d&&(v=>v.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(v=>{!h[v]&&(h[v]=(g,x)=>{let y=g&&g[v];if(y)return y.call(g);throw new Re(`Response type '${v}' is not supported`,Re.ERR_NOT_SUPPORT,x)})});const m=async v=>{if(v==null)return 0;if(U.isBlob(v))return v.size;if(U.isSpecCompliantForm(v))return(await new n(Pt.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(U.isArrayBufferView(v)||U.isArrayBuffer(v))return v.byteLength;if(U.isURLSearchParams(v)&&(v=v+""),U.isString(v))return(await l(v)).byteLength},f=async(v,g)=>{const x=U.toFiniteNumber(v.getContentLength());return x??m(g)};return async v=>{let{url:g,method:x,data:y,signal:w,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:N,withCredentials:R="same-origin",fetchOptions:O}=Rc(v),L=t||fetch;E=E?(E+"").toLowerCase():"text";let q=Nv([w,S&&S.toAbortSignal()],k),W=null;const j=q&&q.unsubscribe&&(()=>{q.unsubscribe()});let X;try{if(T&&c&&x!=="get"&&x!=="head"&&(X=await f(N,y))!==0){let J=new n(g,{method:"POST",body:y,duplex:"half"}),P;if(U.isFormData(y)&&(P=J.headers.get("content-type"))&&N.setContentType(P),J.body){const[_,z]=Ac(X,Bo(jc(T)));y=Mc(J.body,Oc,_,z)}}U.isString(R)||(R=R?"include":"omit");const G=s&&"credentials"in n.prototype,B={...O,signal:q,method:x.toUpperCase(),headers:N.normalize().toJSON(),body:y,duplex:"half",credentials:G?R:void 0};W=s&&new n(g,B);let M=await(s?L(W,O):L(g,B));const I=d&&(E==="stream"||E==="response");if(d&&(C||I&&j)){const J={};["status","statusText","headers"].forEach(F=>{J[F]=M[F]});const P=U.toFiniteNumber(M.headers.get("content-length")),[_,z]=C&&Ac(P,Bo(jc(C),!0))||[];M=new r(Mc(M.body,Oc,_,()=>{z&&z(),j&&j()}),J)}E=E||"text";let K=await h[U.findKey(h,E)||"text"](M,v);return!I&&j&&j(),await new Promise((J,P)=>{Nc(J,P,{data:K,headers:Ht.from(M.headers),status:M.status,statusText:M.statusText,config:v,request:W})})}catch(G){throw j&&j(),G&&G.name==="TypeError"&&/Load failed|fetch/i.test(G.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,v,W),{cause:G.cause||G}):Re.from(G,G&&G.code,v,W)}}},Mv=new Map,Fc=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=Mv;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:Rv(t)),d=c;return c};Fc();const Ei={http:nv,xhr:Iv,fetch:{get:Fc}};U.forEach(Ei,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Bc=e=>`- ${e}`,Ov=e=>U.isFunction(e)||e===null||e===!1,zc={getAdapter:(e,t)=>{e=U.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Ov(r)&&(o=Ei[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(U.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
33
|
`+i.map(Bc).join(`
|
|
34
34
|
`):" "+Bc(i[0]):"as no adapter specified";throw new Re("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Ei};function Ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new gr(null,e)}function Hc(e){return Ii(e),e.headers=Ht.from(e.headers),e.data=ki.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),zc.getAdapter(e.adapter||Gr.adapter,e)(e).then(function(r){return Ii(e),r.data=ki.call(e,e.transformResponse,r),r.headers=Ht.from(r.headers),r},function(r){return Ic(r)||(Ii(e),r&&r.response&&(r.response.data=ki.call(e,e.transformResponse,r.response),r.response.headers=Ht.from(r.response.headers))),Promise.reject(r)})}const Uc="1.12.2",Ho={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Ho[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Wc={};Ho.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Uc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Re(o(i," has been removed"+(n?" in "+n:"")),Re.ERR_DEPRECATED);return n&&!Wc[i]&&(Wc[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},Ho.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Dv(e,t,n){if(typeof e!="object")throw new Re("options must be an object",Re.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Re("option "+s+" must be "+l,Re.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Re("Unknown option "+s,Re.ERR_BAD_OPTION)}}const Uo={assertOptions:Dv,validators:Ho},xn=Uo.validators;let Qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Cc,response:new Cc}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Zn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Uo.assertOptions(r,{silentJSONParsing:xn.transitional(xn.boolean),forcedJSONParsing:xn.transitional(xn.boolean),clarifyTimeoutError:xn.transitional(xn.boolean)},!1),o!=null&&(U.isFunction(o)?n.paramsSerializer={serialize:o}:Uo.assertOptions(o,{encode:xn.function,serialize:xn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Uo.assertOptions(n,{baseUrl:xn.spelling("baseURL"),withXsrfToken:xn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&U.merge(s.common,s[n.method]);s&&U.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Ht.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,h=0,m;if(!l){const v=[Hc.bind(this),void 0];for(v.unshift(...a),v.push(...c),m=v.length,d=Promise.resolve(n);h<m;)d=d.then(v[h++],v[h++]);return d}m=a.length;let f=n;for(;h<m;){const v=a[h++],g=a[h++];try{f=v(f)}catch(x){g.call(this,x);break}}try{d=Hc.call(this,f)}catch(v){return Promise.reject(v)}for(h=0,m=c.length;h<m;)d=d.then(c[h++],c[h++]);return d}getUri(t){t=Zn(this.defaults,t);const n=_c(t.baseURL,t.url,t.allowAbsoluteUrls);return Sc(n,t.params,t.paramsSerializer)}};U.forEach(["delete","get","head","options"],function(t){Qn.prototype[t]=function(n,r){return this.request(Zn(r||{},{method:t,url:n,data:(r||{}).data}))}}),U.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Zn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Qn.prototype[t]=n(),Qn.prototype[t+"Form"]=n(!0)});let Lv=class nx{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new gr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new nx(function(o){t=o}),cancel:t}}};function $v(e){return function(n){return e.apply(null,n)}}function Fv(e){return U.isObject(e)&&e.isAxiosError===!0}const Ni={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(Ni).forEach(([e,t])=>{Ni[t]=e});function Vc(e){const t=new Qn(e),n=ac(Qn.prototype.request,t);return U.extend(n,Qn.prototype,t,{allOwnKeys:!0}),U.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Vc(Zn(e,o))},n}const ft=Vc(Gr);ft.Axios=Qn,ft.CanceledError=gr,ft.CancelToken=Lv,ft.isCancel=Ic,ft.VERSION=Uc,ft.toFormData=$o,ft.AxiosError=Re,ft.Cancel=ft.CanceledError,ft.all=function(t){return Promise.all(t)},ft.spread=$v,ft.isAxiosError=Fv,ft.mergeConfig=Zn,ft.AxiosHeaders=Ht,ft.formToJSON=e=>kc(U.isHTMLForm(e)?new FormData(e):e),ft.getAdapter=zc.getAdapter,ft.HttpStatusCode=Ni,ft.default=ft;const{Axios:dN,AxiosError:fN,CanceledError:hN,isCancel:pN,CancelToken:mN,VERSION:gN,all:xN,Cancel:vN,isAxiosError:bN,spread:wN,toFormData:yN,AxiosHeaders:SN,HttpStatusCode:CN,formToJSON:TN,getAdapter:kN,mergeConfig:EN}=ft,Kc=typeof window<"u"?window.__API_BASE_URL__:void 0,qc=Kc?vn(Kc):void 0;function vn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Wo=null;const Ai=new Set;function Gc(){return Wo}function Vo(e){Wo=e,Ai.forEach(t=>t(e))}function Yc(e){return Ai.add(e),()=>Ai.delete(e)}const Xc=3e4,Jc=9e4,Xt=ft.create({...qc?{baseURL:qc}:{},timeout:Xc,withCredentials:!0});Xt.interceptors.request.use(e=>(Wo&&(e.headers.Authorization=`Bearer ${Wo}`),e)),Xt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Vo(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Jt(e,t){return Xt.defaults.baseURL?(await Xt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ko(e,t,n){return Xt.defaults.baseURL?(await Xt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Zc(e,t,n){return Xt.defaults.baseURL?(await Xt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function ji(e,t){return Xt.defaults.baseURL?(await Xt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function $t(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class qo{get baseUrl(){const t=Xt.defaults.baseURL;return t?vn(String(t)):""}updateConfig(t){t.baseUrl&&(Xt.defaults.baseURL=vn(String(t.baseUrl))),t.authToken!==void 0&&Vo(t.authToken)}getAuthToken(){return Gc()}setAuthToken(t){Vo(t)}onTokenChange(t){return Yc(t)}async listThreads(){const t=await Jt("/threads"),n=$t(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Jt("/threads/shared"),n=$t(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ko("/threads",t?{title:t}:void 0);return $t(r)}async updateThread(t,n){const r=await Zc(`/threads/${t}`,{title:n});return $t(r)}async deleteThread(t){const n=await ji(`/threads/${t}`);return $t(n)}async shareThread(t,n){const r=await Ko(`/threads/${t}/share`,{shared_with_user_id:n});return $t(r)}async threadInfo(t){const n=await Jt(`/threads/${t}/info`);return $t(n)}async listAgents(){const t=await Jt("/agents"),n=$t(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Jt(`/agents/${t}`);return $t(n)}async getAgentSchema(t){const n=await Jt(`/agents/${t}/schema`);return $t(n)}async getState(t){const n=await Jt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return $t(n)}async getStateHistory(t){const n=await Jt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Jc});return $t(n)}async cancelRun(t){const n=await Ko("/runs/cancel",{threadId:t});return $t(n)}async unshareThread(t,n){const r=await ji(`/threads/${t}/share/${n}`);return $t(r)}}const Mn=new qo,Bv=qo,zv=qo;async function _i(e,t){return await Jt(e,{responseType:"blob",onDownloadProgress:r=>{try{if(t&&r.lengthComputable){const o=r.loaded/r.total;t(o)}}catch{}},maxBodyLength:1/0})}async function Hv(e,t){const n=await _i(`/files/${e}/view`,t),r=URL.createObjectURL(n);window.open(r,"_blank"),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function Pi(e,t){return await(await _i(`/files/${e}/view`,t)).text()}async function Qc(e,t){const n=await _i(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Jt(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function Uv(e){return await Jt(`/files/${e}`)}async function eu(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Jt("/files",{params:r})}const tu=b.createContext(null);function nu({children:e,apiConfig:t}){const n=Mn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(tu.Provider,{value:r,children:e})}async function ru(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function ou(e=[]){const t=[],n=[];for(const r of e)try{const o=await ru(r);n.push({filename:r.name,data:o,mime_type:r.type||"application/octet-stream"})}catch{}return{contentParts:t,filesInfo:n}}function Xr(){const e=b.useContext(tu);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function su(e){return!!e&&typeof e=="object"&&"data"in e}function Ri(e){return e.filter(t=>{var i;if(t.role!=="assistant")return!0;const n=(t.content??[]).some(a=>{var l;return a&&a.type==="text"&&((l=a.text)==null?void 0:l.trim())}),r=(t.content??[]).some(a=>a&&a.type==="image_url"),o=(i=t.artifact)==null?void 0:i.plots,s=Array.isArray(o)&&o.length>0;return!!(n||r||s)})}function Jr(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Wv(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function iu(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function au(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function lu(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(h=>h.type==="text").map(h=>h.text??"").join(""),i=t.filter(h=>h.type!=="text"),a=o.lastText??au(e);let l="",c=e.slice();if(s){const h=Vv(a,s);if(h===""?l="":h===s?l=s:l=h,l){const m=c[c.length-1];if((m==null?void 0:m.type)==="text"){const f=m.text??"",v={...m,text:f+l};c=[...c.slice(0,c.length-1),v]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function cu(e){return e.replace(/\s+/g," ").trim()}function Vv(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=cu(e),o=cu(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Kv(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return Jr(e,r,s)}return e}function uu(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function qv(e={}){const t=b.useMemo(()=>vn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[h,m]=b.useState(""),[f,v]=b.useState(null),[g,x]=b.useState(0),[y,w]=b.useState(!1),[S,k]=b.useState(null),C=b.useRef(null),T=b.useRef(!0),E=b.useRef(0),N=b.useRef(null),R=b.useRef(null),O=b.useRef(null),L=b.useRef(null),q=b.useRef({messageId:null,lastSeq:null,lastText:""}),W=b.useCallback(B=>{o(B)},[]),j=b.useCallback(()=>{m(""),v(null),d(null),R.current=null,O.current=null,L.current=null,k(null),q.current={messageId:null,lastSeq:null,lastText:""}},[]),X=b.useCallback(()=>{var B;console.debug("[use-chat] stop() invoked - aborting stream"),(B=C.current)==null||B.abort(),C.current=null,N.current=null,l(!1),w(!1),E.current=0,x(0)},[]),G=b.useCallback((B,M,I)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&m(""),v(null),R.current=null,O.current=null,L.current=null,k(null),q.current={messageId:null,lastSeq:null,lastText:""};const K=new AbortController;C.current=K;let J=null,P=null,_=!1;return N.current={threadId:B.threadId??null,headers:{}},(async()=>{var F,re,V,D,Z,ee,Q,H,ae,ie,ge,ye,Te,Ae,ke,st,vt,kt;const z=Ve=>{var ze;try{const Ke=JSON.parse(JSON.stringify(Ve));return(ze=Ke==null?void 0:Ke.payload)!=null&&ze.files_info&&Array.isArray(Ke.payload.files_info)&&(Ke.payload.files_info=Ke.payload.files_info.map(Oe=>({...Oe,data:Oe!=null&&Oe.data?`<base64 ${String(Oe.data).length} chars>`:Oe==null?void 0:Oe.data}))),Ke}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,_t=((F=window.localStorage)==null?void 0:F.getItem("authToken"))||null;let Y=null;try{const Be=(re=window.localStorage)==null?void 0:re.getItem("chat-settings");Be&&(Y=((V=JSON.parse(Be))==null?void 0:V.apiKey)||null)}catch{}const fe=We||_t||Y||null;fe&&(Ve={Authorization:`Bearer ${fe}`})}}catch{}console.debug("[use-chat] POST",t+n,z(B));let ze={};if(typeof window<"u")try{const Pe=(D=window.localStorage)==null?void 0:D.getItem("authSessionId");Pe&&(ze={"X-Session-Id":Pe})}catch{}const Ke={...Ve,...ze,...s.current},Oe={"Content-Type":"application/json",Accept:"text/event-stream",...Ke},Ue=await fetch(t+n,{method:"POST",headers:Oe,body:JSON.stringify(B),signal:K.signal,credentials:i});if(N.current&&(N.current.headers=Ke),!Ue.ok||!Ue.body){const Pe=await Ue.text().catch(()=>"");console.debug("[use-chat] non-OK response",Ue.status,Pe==null?void 0:Pe.slice(0,500));const We=`stream ${Ue.status}${Pe?": "+Pe:""}`;throw(Z=I==null?void 0:I.onConnectionError)==null||Z.call(I,We),_=!0,J="error",P=We,new Error(We)}w(!0);const dt=Ue.body.getReader(),Nt=new TextDecoder;let nt="",At=[];E.current=0,x(0);let wt=0,mt=null;const Et=()=>{if(At.length){const Pe=At.join("");At=[],T.current&&m(We=>We+Pe)}mt=null},yt=()=>{typeof window<"u"&&mt==null&&(mt=requestAnimationFrame(Et))};let jt=Date.now();const qt=setInterval(()=>{var Pe;if(Date.now()-jt>18e5){const We="Stream idle timeout";d(We),J="error",P=We,K.abort(),(Pe=I==null?void 0:I.onError)==null||Pe.call(I,We)}},5e3),gt=1024*1024;try{const Pe=Ue.headers.get("X-Thread-Id")||Ue.headers.get("x-thread-id"),We=Ue.headers.get("X-Thread-Created")||Ue.headers.get("x-thread-created"),_t=Pe??null,Y=String(We??"").toLowerCase()==="true";for(N.current&&!N.current.threadId&&(N.current={...N.current,threadId:_t}),(ee=I==null?void 0:I.onOpen)==null||ee.call(I,{threadId:_t,created:Y});;){const{value:fe,done:Be}=await dt.read();if(Be)break;nt+=Nt.decode(fe,{stream:!0}),nt.length>gt&&(nt="",console.warn("Stream buffer reset: exceeded 1MB"));let xe;for(;(xe=nt.indexOf(`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Zn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Uo.assertOptions(r,{silentJSONParsing:xn.transitional(xn.boolean),forcedJSONParsing:xn.transitional(xn.boolean),clarifyTimeoutError:xn.transitional(xn.boolean)},!1),o!=null&&(U.isFunction(o)?n.paramsSerializer={serialize:o}:Uo.assertOptions(o,{encode:xn.function,serialize:xn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Uo.assertOptions(n,{baseUrl:xn.spelling("baseURL"),withXsrfToken:xn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&U.merge(s.common,s[n.method]);s&&U.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Ht.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,h=0,m;if(!l){const v=[Hc.bind(this),void 0];for(v.unshift(...a),v.push(...c),m=v.length,d=Promise.resolve(n);h<m;)d=d.then(v[h++],v[h++]);return d}m=a.length;let f=n;for(;h<m;){const v=a[h++],g=a[h++];try{f=v(f)}catch(x){g.call(this,x);break}}try{d=Hc.call(this,f)}catch(v){return Promise.reject(v)}for(h=0,m=c.length;h<m;)d=d.then(c[h++],c[h++]);return d}getUri(t){t=Zn(this.defaults,t);const n=_c(t.baseURL,t.url,t.allowAbsoluteUrls);return Sc(n,t.params,t.paramsSerializer)}};U.forEach(["delete","get","head","options"],function(t){Qn.prototype[t]=function(n,r){return this.request(Zn(r||{},{method:t,url:n,data:(r||{}).data}))}}),U.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Zn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Qn.prototype[t]=n(),Qn.prototype[t+"Form"]=n(!0)});let Lv=class nx{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new gr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new nx(function(o){t=o}),cancel:t}}};function $v(e){return function(n){return e.apply(null,n)}}function Fv(e){return U.isObject(e)&&e.isAxiosError===!0}const Ni={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(Ni).forEach(([e,t])=>{Ni[t]=e});function Vc(e){const t=new Qn(e),n=ac(Qn.prototype.request,t);return U.extend(n,Qn.prototype,t,{allOwnKeys:!0}),U.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Vc(Zn(e,o))},n}const ft=Vc(Gr);ft.Axios=Qn,ft.CanceledError=gr,ft.CancelToken=Lv,ft.isCancel=Ic,ft.VERSION=Uc,ft.toFormData=$o,ft.AxiosError=Re,ft.Cancel=ft.CanceledError,ft.all=function(t){return Promise.all(t)},ft.spread=$v,ft.isAxiosError=Fv,ft.mergeConfig=Zn,ft.AxiosHeaders=Ht,ft.formToJSON=e=>kc(U.isHTMLForm(e)?new FormData(e):e),ft.getAdapter=zc.getAdapter,ft.HttpStatusCode=Ni,ft.default=ft;const{Axios:dN,AxiosError:fN,CanceledError:hN,isCancel:pN,CancelToken:mN,VERSION:gN,all:xN,Cancel:vN,isAxiosError:bN,spread:wN,toFormData:yN,AxiosHeaders:SN,HttpStatusCode:CN,formToJSON:TN,getAdapter:kN,mergeConfig:EN}=ft,Kc=typeof window<"u"?window.__API_BASE_URL__:void 0,qc=Kc?vn(Kc):void 0;function vn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Wo=null;const Ai=new Set;function Gc(){return Wo}function Vo(e){Wo=e,Ai.forEach(t=>t(e))}function Yc(e){return Ai.add(e),()=>Ai.delete(e)}const Xc=3e4,Jc=9e4,Xt=ft.create({...qc?{baseURL:qc}:{},timeout:Xc,withCredentials:!0});Xt.interceptors.request.use(e=>(Wo&&(e.headers.Authorization=`Bearer ${Wo}`),e)),Xt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Vo(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Jt(e,t){return Xt.defaults.baseURL?(await Xt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ko(e,t,n){return Xt.defaults.baseURL?(await Xt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Zc(e,t,n){return Xt.defaults.baseURL?(await Xt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function ji(e,t){return Xt.defaults.baseURL?(await Xt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function $t(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class qo{get baseUrl(){const t=Xt.defaults.baseURL;return t?vn(String(t)):""}updateConfig(t){t.baseUrl&&(Xt.defaults.baseURL=vn(String(t.baseUrl))),t.authToken!==void 0&&Vo(t.authToken)}getAuthToken(){return Gc()}setAuthToken(t){Vo(t)}onTokenChange(t){return Yc(t)}async listThreads(){const t=await Jt("/threads"),n=$t(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Jt("/threads/shared"),n=$t(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ko("/threads",t?{title:t}:void 0);return $t(r)}async updateThread(t,n){const r=await Zc(`/threads/${t}`,{title:n});return $t(r)}async deleteThread(t){const n=await ji(`/threads/${t}`);return $t(n)}async shareThread(t,n){const r=await Ko(`/threads/${t}/share`,{shared_with_user_id:n});return $t(r)}async threadInfo(t){const n=await Jt(`/threads/${t}/info`);return $t(n)}async listAgents(){const t=await Jt("/agents"),n=$t(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Jt(`/agents/${t}`);return $t(n)}async getAgentSchema(t){const n=await Jt(`/agents/${t}/schema`);return $t(n)}async getState(t){const n=await Jt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return $t(n)}async getStateHistory(t){const n=await Jt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Jc});return $t(n)}async cancelRun(t){const n=await Ko("/runs/cancel",{threadId:t});return $t(n)}async unshareThread(t,n){const r=await ji(`/threads/${t}/share/${n}`);return $t(r)}}const Nn=new qo,Bv=qo,zv=qo;async function _i(e,t){return await Jt(e,{responseType:"blob",onDownloadProgress:r=>{try{if(t&&r.lengthComputable){const o=r.loaded/r.total;t(o)}}catch{}},maxBodyLength:1/0})}async function Hv(e,t){const n=await _i(`/files/${e}/view`,t),r=URL.createObjectURL(n);window.open(r,"_blank"),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function Pi(e,t){return await(await _i(`/files/${e}/view`,t)).text()}async function Qc(e,t){const n=await _i(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Jt(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function Uv(e){return await Jt(`/files/${e}`)}async function eu(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Jt("/files",{params:r})}const tu=b.createContext(null);function nu({children:e,apiConfig:t}){const n=Nn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(tu.Provider,{value:r,children:e})}async function ru(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function ou(e=[]){const t=[],n=[];for(const r of e)try{const o=await ru(r);n.push({filename:r.name,data:o,mime_type:r.type||"application/octet-stream"})}catch{}return{contentParts:t,filesInfo:n}}function Xr(){const e=b.useContext(tu);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function su(e){return!!e&&typeof e=="object"&&"data"in e}function Ri(e){return e.filter(t=>{var i;if(t.role!=="assistant")return!0;const n=(t.content??[]).some(a=>{var l;return a&&a.type==="text"&&((l=a.text)==null?void 0:l.trim())}),r=(t.content??[]).some(a=>a&&a.type==="image_url"),o=(i=t.artifact)==null?void 0:i.plots,s=Array.isArray(o)&&o.length>0;return!!(n||r||s)})}function Jr(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Wv(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function iu(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function au(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function lu(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(h=>h.type==="text").map(h=>h.text??"").join(""),i=t.filter(h=>h.type!=="text"),a=o.lastText??au(e);let l="",c=e.slice();if(s){const h=Vv(a,s);if(h===""?l="":h===s?l=s:l=h,l){const m=c[c.length-1];if((m==null?void 0:m.type)==="text"){const f=m.text??"",v={...m,text:f+l};c=[...c.slice(0,c.length-1),v]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function cu(e){return e.replace(/\s+/g," ").trim()}function Vv(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=cu(e),o=cu(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Kv(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return Jr(e,r,s)}return e}function uu(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function qv(e={}){const t=b.useMemo(()=>vn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=b.useState(e.token??null),s=b.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=b.useState(!1),[c,d]=b.useState(null),[h,m]=b.useState(""),[f,v]=b.useState(null),[g,x]=b.useState(0),[y,w]=b.useState(!1),[S,k]=b.useState(null),C=b.useRef(null),T=b.useRef(!0),E=b.useRef(0),N=b.useRef(null),R=b.useRef(null),O=b.useRef(null),L=b.useRef(null),q=b.useRef({messageId:null,lastSeq:null,lastText:""}),W=b.useCallback(B=>{o(B)},[]),j=b.useCallback(()=>{m(""),v(null),d(null),R.current=null,O.current=null,L.current=null,k(null),q.current={messageId:null,lastSeq:null,lastText:""}},[]),X=b.useCallback(()=>{var M,I;console.debug("[use-chat] stop() invoked - aborting stream");const B=(M=N.current)==null?void 0:M.threadId;B&&Nn.cancelRun(B).catch(K=>{console.warn("[use-chat] cancel run failed:",K)}),(I=C.current)==null||I.abort(),C.current=null,N.current=null,l(!1),w(!1),E.current=0,x(0)},[]),G=b.useCallback((B,M,I)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&m(""),v(null),R.current=null,O.current=null,L.current=null,k(null),q.current={messageId:null,lastSeq:null,lastText:""};const K=new AbortController;C.current=K;let J=null,P=null,_=!1;return N.current={threadId:B.threadId??null,headers:{}},(async()=>{var F,re,V,D,Z,ee,Q,H,ae,ie,ge,ye,Te,Ae,ke,st,vt,kt;const z=Ve=>{var ze;try{const Ke=JSON.parse(JSON.stringify(Ve));return(ze=Ke==null?void 0:Ke.payload)!=null&&ze.files_info&&Array.isArray(Ke.payload.files_info)&&(Ke.payload.files_info=Ke.payload.files_info.map(Oe=>({...Oe,data:Oe!=null&&Oe.data?`<base64 ${String(Oe.data).length} chars>`:Oe==null?void 0:Oe.data}))),Ke}catch{return Ve}};try{let Ve={};try{if(r)Ve={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,_t=((F=window.localStorage)==null?void 0:F.getItem("authToken"))||null;let Y=null;try{const Be=(re=window.localStorage)==null?void 0:re.getItem("chat-settings");Be&&(Y=((V=JSON.parse(Be))==null?void 0:V.apiKey)||null)}catch{}const fe=We||_t||Y||null;fe&&(Ve={Authorization:`Bearer ${fe}`})}}catch{}console.debug("[use-chat] POST",t+n,z(B));let ze={};if(typeof window<"u")try{const Pe=(D=window.localStorage)==null?void 0:D.getItem("authSessionId");Pe&&(ze={"X-Session-Id":Pe})}catch{}const Ke={...Ve,...ze,...s.current},Oe={"Content-Type":"application/json",Accept:"text/event-stream",...Ke},Ue=await fetch(t+n,{method:"POST",headers:Oe,body:JSON.stringify(B),signal:K.signal,credentials:i});if(N.current&&(N.current.headers=Ke),!Ue.ok||!Ue.body){const Pe=await Ue.text().catch(()=>"");console.debug("[use-chat] non-OK response",Ue.status,Pe==null?void 0:Pe.slice(0,500));const We=`stream ${Ue.status}${Pe?": "+Pe:""}`;throw(Z=I==null?void 0:I.onConnectionError)==null||Z.call(I,We),_=!0,J="error",P=We,new Error(We)}w(!0);const dt=Ue.body.getReader(),Nt=new TextDecoder;let nt="",At=[];E.current=0,x(0);let wt=0,mt=null;const Et=()=>{if(At.length){const Pe=At.join("");At=[],T.current&&m(We=>We+Pe)}mt=null},yt=()=>{typeof window<"u"&&mt==null&&(mt=requestAnimationFrame(Et))};let jt=Date.now();const qt=setInterval(()=>{var Pe;if(Date.now()-jt>18e5){const We="Stream idle timeout";d(We),J="error",P=We,K.abort(),(Pe=I==null?void 0:I.onError)==null||Pe.call(I,We)}},5e3),gt=1024*1024;try{const Pe=Ue.headers.get("X-Thread-Id")||Ue.headers.get("x-thread-id"),We=Ue.headers.get("X-Thread-Created")||Ue.headers.get("x-thread-created"),_t=Pe??null,Y=String(We??"").toLowerCase()==="true";for(N.current&&!N.current.threadId&&(N.current={...N.current,threadId:_t}),(ee=I==null?void 0:I.onOpen)==null||ee.call(I,{threadId:_t,created:Y});;){const{value:fe,done:Be}=await dt.read();if(Be)break;nt+=Nt.decode(fe,{stream:!0}),nt.length>gt&&(nt="",console.warn("Stream buffer reset: exceeded 1MB"));let xe;for(;(xe=nt.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const Fe=nt.slice(0,xe);nt=nt.slice(xe+2);const Ge=Fe.split(/\r?\n/),St=[];for(const Xe of Ge)if(!(!Xe||Xe.startsWith(":"))&&Xe.startsWith("data:")){const lt=Xe.slice(5);St.push(lt.startsWith(" ")?lt.slice(1):lt)}const Ct=St.join(`
|
|
38
|
-
`);if(!Ct)continue;let It;try{It=JSON.parse(Ct)}catch{console.debug("[use-chat] malformed SSE:",Ct.slice(0,200));continue}const Lt=su(It)?It.data:It;if(!Lt){console.warn("[use-chat] dropped envelope event without payload",It);continue}const je=Lt;jt=Date.now();const ct=je.seq;if(ct!==void 0){if(ct<=wt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ct,lastProcessedSeq:wt,type:je.type});continue}wt>0&&ct>wt+1&&((Q=I==null?void 0:I.onGap)==null||Q.call(I,{from:wt,to:ct})),wt=ct,E.current=ct,x(ct)}if(je.type==="message.start"&&je.role==="assistant"){const Xe=uu(je.model);q.current={messageId:je.id,lastSeq:ct??null,lastText:""},k({id:je.id,role:"assistant",name:Xe??void 0,model:je.model,createdAt:new Date().toISOString(),content:[]})}if(je.type==="checkpoint")R.current=je.checkpointId??null,O.current=je.checkpointNs??null,v(je.checkpointId??null);else if(je.type==="state_history"){L.current=je;try{const lt=Rn(je).latest;lt&&(R.current=lt.checkpointId??null,O.current=lt.checkpointNs??null,v(lt.checkpointId??null))}catch(Xe){console.warn("[use-chat] Failed to hydrate state_history payload",Xe)}}try{M==null||M(je)}catch(Xe){console.error("[use-chat] Error in onEvent callback:",Xe,"for event:",je.type)}if(je.type==="message.delta"){k(lt=>{const an=q.current;if(!lt||an.messageId!==lt.id)return lt;const{newParts:A,newMeta:te,changed:he}=lu(lt.content??[],je.delta,{lastSeq:an.lastSeq,lastText:an.lastText},ct??null);return he?(q.current={...an,lastSeq:te.lastSeq??an.lastSeq,lastText:te.lastText??an.lastText},{...lt,content:A}):lt});const Xe=je.delta.filter(lt=>lt.type==="text").map(lt=>lt.text).join("");Xe&&e.autoAppendAssistant!==!1&&(At.push(Xe),yt())}else if(je.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(H=I==null?void 0:I.onHeartbeat)==null||H.call(I,je)}catch(Xe){console.warn("[use-chat] heartbeat callback failed",Xe)}}else if(mt!==null&&cancelAnimationFrame(mt),Et(),je.type==="checkpoint")v(je.checkpointId);else if(je.type==="error"){const Xe=je;if(d(Xe.message),J="error",P=Xe.message,Xe.error_type==="auth_error"||Xe.code==="TOKEN_EXPIRED"||((ae=Xe.message)==null?void 0:ae.includes("token"))||((ie=Xe.message)==null?void 0:ie.includes("401"))||((ge=Xe.message)==null?void 0:ge.includes("unauthorized"))||((ye=Xe.message)==null?void 0:ye.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Xe.message);try{(Te=I==null?void 0:I.onAuthError)==null||Te.call(I,Xe.message)}catch(an){console.warn("[use-chat] onAuthError handler failed",an)}K.abort()}}}}Et(),J===null&&!K.signal.aborted&&(J="complete")}catch(Pe){if(Pe.name==="AbortError")J=J??"aborted";else{const We=Pe.message||String(Pe);J="error",P=We,d(We),(Ae=I==null?void 0:I.onError)==null||Ae.call(I,We)}}finally{try{await dt.cancel()}catch{}finally{(ke=dt.releaseLock)==null||ke.call(dt)}mt!==null&&typeof window<"u"&&window.cancelAnimationFrame(mt),clearInterval(qt)}}catch(Ve){if(Ve.name==="AbortError")J=J??"aborted";else{const ze=Ve.message||String(Ve);J="error",P=ze,d(ze),(st=I==null?void 0:I.onError)==null||st.call(I,ze),_||((vt=I==null?void 0:I.onConnectionError)==null||vt.call(I,ze),_=!0)}}finally{const Ve=E.current,ze=R.current,Ke=O.current,Oe=L.current,Ue=J??(K.signal.aborted?"aborted":P?"error":"complete");try{(kt=I==null?void 0:I.onClosed)==null||kt.call(I,{reason:Ue,lastSeq:Ve,lastCheckpointId:ze,lastCheckpointNs:Ke,lastStateHistory:Oe,error:P})}catch(dt){console.warn("[use-chat] onClosed callback failed",dt)}l(!1),w(!1),C.current=null,E.current=0,x(0),N.current=null}})(),{close:()=>K.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var B;T.current=!1,(B=C.current)==null||B.abort()},[]),{isStreaming:a,error:c,assistantText:h,assistantMessage:S,lastCheckpointId:f,lastSeq:g,connected:y,stream:G,stop:X,clear:j,setToken:W}}const Gv=["detail","message","error","description","title"];function Go(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Go(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of Gv){const r=Go(t[n]);if(r)return r}if("errors"in t){const n=Go(t.errors);if(n)return n}}return null}function Yv(e){if(!e)return"Request failed";const t=e.response,n=Go(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function du({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=b.useState([]),[a,l]=b.useState(t),[c,d]=b.useState(!1),[h,m]=b.useState(null),[f,v]=b.useState([]),[g,x]=b.useState(!1),[,y]=b.useState(null),[w,S]=b.useState(null),[k,C]=b.useState(!1),T=b.useRef(a),E=b.useRef(new Map);b.useEffect(()=>{T.current=a},[a]);const N=b.useCallback(async()=>{d(!0),m(null);try{const M=await e.listThreads();i(M??[])}catch(M){const I=String(M);m(I),n==null||n(I)}finally{d(!1)}},[e,n]),R=b.useCallback(async()=>{x(!0),y(null);try{const M=await e.listSharedThreads();v(M??[])}catch(M){const I=String(M);y(I),n==null||n(I)}finally{x(!1)}},[e,n]);b.useEffect(()=>{N()},[N]),b.useEffect(()=>{R()},[R]),b.useEffect(()=>{r==null||r(a)},[a,r]);const O=b.useCallback(async M=>{try{const I=await e.createThread(M);return l(I.threadId),await N(),I.threadId}catch(I){const K=String(I);return n==null||n(K),null}},[e,n,N]),L=b.useCallback(async M=>{const I=s;i(J=>J.filter(P=>P.threadId!==M));const K=new AbortController;E.current.set(M,K);try{await e.deleteThread(M),T.current===M&&(l(null),o==null||o())}catch(J){i(I);const P=String(J);n==null||n(P)}finally{E.current.delete(M)}},[e,o,n,s]),q=b.useCallback(async(M,I)=>{try{await e.updateThread(M,I),await N()}catch(K){n==null||n(String(K))}},[e,n,N]),W=b.useCallback(async(M,I)=>{C(!0),S("Sharing thread…");try{await e.shareThread(M,I),await R(),S("Shared successfully")}catch(K){const J=Yv(K);throw n==null||n(J),S(`Failed to share: ${J}`),new Error(J)}finally{C(!1)}},[e,n,R]),j=b.useCallback(async(M,I)=>{try{await e.unshareThread(M,I),await R()}catch(K){const J=String(K);throw n==null||n(J),K}},[e,n,R]),X=b.useMemo(()=>({createThread:O,deleteThread:L,renameThread:q,refreshThreads:N,refreshSharedThreads:R,shareThread:W,unshareThread:j}),[O,L,q,N,R,W,j]),G=b.useCallback(M=>{if(!(M!=null&&M.threadId))return;const I={threadId:M.threadId,title:M.title||`Thread ${M.threadId.slice(0,8)}`,createdAt:M.createdAt||new Date().toISOString(),updatedAt:M.updatedAt||new Date().toISOString(),messageCount:M.messageCount??1};i(K=>{let J=!1;const P=K.map(_=>_.threadId===I.threadId?(J=!0,console.debug("[useThreadsState] thread_info: updating existing thread",I.threadId),{..._,title:I.title??_.title,updatedAt:I.updatedAt??_.updatedAt,messageCount:I.messageCount??_.messageCount}):_);return J?P:(console.debug("[useThreadsState] thread_info: adding thread to list",I.threadId),[I,...K])})},[]),B=b.useCallback(()=>S(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:T,setCurrentThreadId:l,isLoadingThreads:c,threadsError:h,sharedThreads:f,isLoadingSharedThreads:g,actions:X,addThreadFromEvent:G,shareInFlight:k,shareStatus:w,clearShareStatus:B}}const fu=b.createContext(null);function hu({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{api:o}=Xr(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoadingThreads:c,threadsError:d,sharedThreads:h,isLoadingSharedThreads:m,actions:f,addThreadFromEvent:v,shareInFlight:g,shareStatus:x,clearShareStatus:y}=du({api:o,initialThreadId:t,onError:n,onThreadChange:r}),w=b.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoading:c,error:d,sharedThreads:h,isLoadingSharedThreads:m,actions:f,shareInFlight:g,shareStatus:x,clearShareStatus:y,addThreadFromEvent:v}),[s,i,a,l,c,d,h,m,f,g,x,y,v]);return u.jsx(fu.Provider,{value:w,children:e})}function xr(){const e=b.useContext(fu);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function Mi(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function pu(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Zr(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Zr).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(pu(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=Zr(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function vr(e){if(typeof e=="string")return e;if(pu(e))return"";try{const t=Zr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Xv(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function Jv(e){const t=vr(e);return typeof e=="string"&&Xv(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Qr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Mi(t);if(n!==null)return Qr(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Qr(e.content):e}function Zv(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Oi(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Yo(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Qv(e){const t=r=>{try{const o=Zr(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
39
|
-
`)):t(e)}function eb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function mu(e){if(e.role==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(i=>{switch(i.type){case"text":return`t:${i.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"",r="checkpointId"in e&&e.checkpointId?`cp:${e.checkpointId}`:"",o="checkpointNs"in e&&e.checkpointNs?`ns:${e.checkpointNs}`:"",s=[r,o].filter(Boolean).join("|");return`${e.id}:${t}:${n}${s?`:${s}`:""}`}function tb(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function nb(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function rb({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=tb(n),i=o?`data:${s};base64,${e}`:t,a=nb(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function ob(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return rb({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function gu(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const sb={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null};function ib(e,t){var n;switch(t.type){case"reset":return{messages:Ri(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,pendingInterrupt:null,messagesStreamMeta:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r]}}}return{...e,messages:[...e.messages,r]}}case"seed":{const r=Ri(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Ri(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(a=>a.id)),s=r.filter(a=>!o.has(a.id));if(!s.length)return e;const i=[...s,...e.messages];return{...e,messages:i}}case"event":return xu(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>xu(o,s),e):e}default:return e}}function ab(e=[]){const[t,n]=b.useReducer(ib,{...sb,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=b.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,h)=>n({type:"seed",payload:{messages:d,...h??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:(d,h)=>n({type:"user_message",payload:{message:d,editingMessageId:h}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function xu(e,t){var n,r,o;if(t.type==="message.start"&&t.role==="assistant"){const s=t.id,i=uu(t.model);if(e.messages.some(c=>c.id===s)){const c=e.messagesStreamMeta??{},d={...c,[s]:c[s]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:s,messagesStreamMeta:d}}const l={id:s,role:"assistant",name:i||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,l]}}if(t.type==="tool.start")return cb(e,t);if(t.type==="tool.progress")return ub(e,t);if(t.type==="tool.end")return db(e,t);if(t.type==="message.delta"){const s=e.assemblingId??iu(e.messages);if(!s)return e;const i=e.messages,a=i.findIndex(C=>C.id===s&&C.role==="assistant");if(a===-1)return e;const l=i[a],c=e.messagesStreamMeta,d=c??{},h=d[s],m=h??{lastSeq:null,lastText:au(l.content)},f=t.seq??null;if(f!==null&&typeof f=="number"&&typeof m.lastSeq=="number"&&f<=m.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:f,lastSeq:m.lastSeq}),e;const{newParts:v,newMeta:g,changed:x}=lu(l.content,t.delta,m,f);if(!x)return e;const y={...l,content:v},w=Jr(i,a,y),S=!h||h.lastSeq!==g.lastSeq||h.lastText!==g.lastText,k=S?{...d,[s]:g}:c;return S?{...e,messages:w,messagesStreamMeta:k}:{...e,messages:w}}if(t.type==="message.end"){const s=e.assemblingId??iu(e.messages);if(!s)return{...e,assemblingId:null};const i=e.messages,a=i.findIndex(l=>l.id===s&&l.role==="assistant");if(a>=0){const l=i[a];if(!((n=l.content)==null?void 0:n.some(d=>{var h;return(d==null?void 0:d.type)==="text"&&((h=d.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:l.id,contentTypes:(r=l.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=l.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const d=[...i.slice(0,a),...i.slice(a+1)];return{...e,assemblingId:null,messages:d}}}return e}if(t.type==="checkpoint"){const s=t.checkpointNs??e.lastCheckpointNs??null,i=Kv(e.messages,t.checkpointId,s);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:s,messages:i}}if(t.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}if(t.type==="state_history"){const s=Rn(t),i=s.interrupt,a=s.latest,l=i===null?Wv(e.messages):e.messages;return{...e,messages:l,pendingInterrupt:i,lastCheckpointId:(a==null?void 0:a.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(a==null?void 0:a.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function Di(e){return e.call_id??e.id??null}function vu(e){return e.id??e.call_id??`tool-${Date.now()}-${Math.random().toString(16).slice(2)}`}function bu(e,t,n,r){const o=t??`call-${Date.now()}-${Math.random().toString(16).slice(2)}`;return{id:e,role:"tool",name:n??void 0,content:[{type:"tool_call",id:o,name:n??"tool",args:r??{}}],createdAt:new Date().toISOString(),additionalKwargs:{toolCallId:o,toolName:n??void 0,toolStreaming:!0,toolProgress:[]}}}function Li(e,t){if(!t)return-1;for(let n=0;n<e.length;n+=1){const r=e[n];if(r.role!=="tool")continue;const o=r.additionalKwargs??{};if(typeof o.toolCallId=="string"&&o.toolCallId===t||Oi(r).toolCallId===t)return n}return-1}function lb(e){if(e==null)return[];const t=Qr(e);if(typeof t=="string"&&t.trim())return[{type:"text",text:t}];const n=vr(t??e);return n?[{type:"text",text:n}]:[]}function wu(e,t){const n=e.additionalKwargs??{},r=Array.isArray(n.toolProgress)?[...n.toolProgress]:[],o={...n,toolProgress:[...r,t]};return{...e,additionalKwargs:o}}function cb(e,t){const n=Di(t),r=Li(e.messages,n),o=t.name??t.tool??void 0,s=vu(t);if(r>=0){const a=e.messages[r],c={...a.additionalKwargs??{},toolStreaming:!0,toolProgress:[]},d={...a,name:o??a.name,additionalKwargs:c};return{...e,messages:Jr(e.messages,r,d)}}const i=bu(s,n,o,t.args);return{...e,messages:[...e.messages,i]}}function ub(e,t){const n=Di(t);if(!n)return e;const r=Li(e.messages,n);if(r===-1)return e;const o={type:t.type,content:typeof t.content=="string"?t.content:void 0,seq:t.seq??null,timestamp:new Date().toISOString()},s=t.metadata;s&&(o.metadata=s);const i=t.idx;typeof i=="number"&&(o.idx=i);const a=wu(e.messages[r],o);return{...e,messages:Jr(e.messages,r,a)}}function db(e,t){const n=Di(t),r=vu(t);let o=e.messages,s=Li(o,n);if(s===-1){const v=t.name??t.tool??void 0;o=[...o,bu(r,n,v,{})],s=o.length-1}const i=o[s],a=t.output??t.error??null,l=lb(a),c=[...i.content,...l],d={type:t.type,content:typeof t.output=="string"?t.output:void 0,seq:t.seq??null,timestamp:new Date().toISOString()};t.artifact&&(d.artifact=t.artifact);const h=wu(i,d),m=t.artifact??i.artifact,f={...h,name:t.name??t.tool??i.name,content:c,artifact:m,additionalKwargs:{...h.additionalKwargs??{},toolStreaming:!1}};return{...e,messages:Jr(o,s,f)}}function yu({api:e,seed:t,prepend:n,onError:r,currentThreadId:o,initialThreadId:s=null,initialCheckpointId:i=null,initialCheckpointNs:a=null,autoLoadInitial:l=!0,isStreaming:c,getMessages:d}){const[h,m]=b.useState(null),v=b.useMemo(()=>Rn(h),[h]).checkpoints,g=nc(v),x=g.timeline,[y,w]=b.useState(!1),[S,k]=b.useState(null),[C,T]=b.useState(!1),[E,N]=b.useState(!1),[R,O]=b.useState(!1),[L,q]=b.useState(null),W=b.useRef(o),j=b.useRef(null),X=b.useRef(null),G=b.useRef(null),B=b.useRef(null),M=b.useRef(null),I=b.useRef(new Map);b.useEffect(()=>{W.current=o},[o]);const K=b.useCallback(async Q=>{var ae,ie;if(!Q.threadId)return;const H=Q.threadId;(ae=Q.onStart)==null||ae.call(Q),Q.setLoading(!0);try{await Q.action(H)}catch(ge){if(W.current===H){const ye=String(ge);(ie=Q.handleError)==null||ie.call(Q,ye),r==null||r(ye)}throw ge}finally{Q.setLoading(!1)}},[r]),J=b.useCallback(async(Q,H)=>{if(!Q)return;const ae=`${Q}:${H??"latest"}`,ie=I.current.get(ae);if(ie)return ie;const ge=K({threadId:Q,setLoading:T,onStart:()=>q(null),handleError:ye=>q(ye),action:async ye=>{const Te=await e.getStateHistory({threadId:ye,checkpointId:H??void 0});if(W.current!==ye){console.log(`[useThreadHistoryState] Thread changed during load (was ${ye}, now ${W.current}), discarding stale data`);return}const{checkpoints:Ae}=Rn(Te),ke=Ae.find(st=>st.messages&&st.messages.length>0)??(H?Ae.find(st=>st.checkpointId===H):null)??Ae[0];t((ke==null?void 0:ke.messages)??[],{checkpointId:(ke==null?void 0:ke.checkpointId)??null,checkpointNs:(ke==null?void 0:ke.checkpointNs)??null}),m(Te),w(!!(ke!=null&&ke.nextCursor)),k((ke==null?void 0:ke.nextCursor)??null)}});I.current.set(ae,ge);try{await ge}finally{I.current.delete(ae)}return W.current===Q&&(M.current=ae),ge},[e,t,K]),P=b.useCallback(async(Q,H)=>{B.current=Q;try{await J(Q,H)}finally{B.current===Q&&(B.current=null)}},[J]),_=b.useCallback(Q=>{X.current=Q},[]),z=b.useCallback(Q=>{G.current=Q},[]),F=b.useCallback(Q=>{const H=Q.threadId??W.current;if(!H||W.current&&W.current!==H)return;const{checkpoints:ae}=Rn(Q);if(!ae.length)return;const ie=ae.find(ye=>ye.messages&&ye.messages.length>0)??ae.find(ye=>!!ye.checkpointId)??ae[0],ge=G.current===H;!c&&!ge&&t((ie==null?void 0:ie.messages)??[],{checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}),m(Q),w(!!(ie!=null&&ie.nextCursor)),k((ie==null?void 0:ie.nextCursor)??null),M.current=`${H}:latest`,X.current=null,G.current===H&&(G.current=null)},[t,c]),re=b.useCallback(async(Q,H)=>{const ae=W.current;await K({threadId:ae,setLoading:O,action:async ie=>{const ge=await e.getStateHistory({threadId:ie,checkpointId:Q,checkpointNs:H??void 0});if(W.current!==ie){console.log(`[useThreadHistoryState] Thread changed during checkpoint navigation (was ${ie}, now ${W.current}), discarding stale data`);return}const{checkpoints:ye}=Rn(ge),Te=ye.find(Ae=>Ae.checkpointId===Q&&(H?Ae.checkpointNs===H:!0));if(!Te){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:Q,checkpointNs:H});return}m(ge),t(Te.messages??[],{checkpointId:Te.checkpointId??null,checkpointNs:Te.checkpointNs??null})}}).catch(()=>{})},[e,t,K]),V=b.useCallback((Q,H)=>{t(d(),{checkpointId:Q??null,checkpointNs:H??null})},[d,t]),D=b.useCallback(async()=>{W.current&&await P(W.current)},[P]),Z=b.useCallback(async()=>{const Q=W.current;!Q||!S||await K({threadId:Q,setLoading:N,action:async H=>{const ae=await e.getStateHistory({threadId:H,checkpointId:S});if(W.current!==H)return;const{checkpoints:ie}=Rn(ae);if(ie.length>0){const ge=ie[ie.length-1];n((ge==null?void 0:ge.messages)??[]),w(!!(ge!=null&&ge.nextCursor)),k((ge==null?void 0:ge.nextCursor)??null)}}}).catch(()=>{})},[e,S,r,n,K]);b.useEffect(()=>{if(!l||!o||C||c)return;if(X.current===o){X.current=null,j.current=o;return}if(G.current===o){j.current=o;return}if(B.current===o){B.current=null,j.current=o;return}if(j.current===o)return;j.current=o;let Q;console.log("[useThreadHistoryState] Loading thread with latest checkpoint");const H=`${o}:latest`;M.current!==H&&P(o,Q)},[l,o,i,a,s,C,c,P]);const ee=b.useCallback(()=>{m(null),w(!1),k(null),T(!1),N(!1),O(!1),q(null),X.current=null,G.current=null,j.current=null,M.current=null,B.current=null},[]);return{threadCheckpoints:v,threadTimeline:x,checkpointIndex:g,isLoadingThread:C,isHistoryLoading:E,isLoadingCheckpoint:R,threadStateError:L,hasMoreHistory:y,loadThread:P,navigateToCheckpoint:re,loadOlderMessages:Z,setCurrentCheckpointId:V,returnToLatest:D,handleStateHistoryEvent:F,markSkipNextLoad:_,markStreamPendingThread:z,resetHistoryState:ee}}const Su=b.createContext(null),Cu=b.createContext(null);function eo(){const e=b.useContext(Su);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function Tu(){const e=b.useContext(Cu);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function ku({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,isStreaming:s,onError:i}){const{api:a}=Xr(),{currentThreadId:l}=xr(),{state:c,seed:d,prepend:h,pushUser:m,onEvent:f}=ab(),{threadCheckpoints:v,threadTimeline:g,checkpointIndex:x,isLoadingThread:y,isHistoryLoading:w,isLoadingCheckpoint:S,threadStateError:k,hasMoreHistory:C,loadThread:T,navigateToCheckpoint:E,loadOlderMessages:N,setCurrentCheckpointId:R,returnToLatest:O,handleStateHistoryEvent:L,markSkipNextLoad:q,markStreamPendingThread:W,resetHistoryState:j}=yu({api:a,seed:d,prepend:h,onError:i,currentThreadId:l,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:s,getMessages:b.useCallback(()=>c.messages,[c.messages])}),[X,G]=b.useState(()=>async()=>{throw new Error("clearThread is not ready")}),[B,M]=b.useState(()=>async()=>{throw new Error("respondToInterrupt is not ready")});b.useEffect(()=>{l||(d([],{}),j())},[l,d,j]);const I=b.useCallback(z=>G(()=>z),[]),K=b.useCallback(z=>M(()=>z),[]),J=b.useMemo(()=>({assemblingMessageId:c.assemblingId??null}),[c.assemblingId]),P=b.useMemo(()=>({threadId:l,messages:c.messages,interrupt:c.pendingInterrupt,checkpoint:{id:c.lastCheckpointId??null,namespace:c.lastCheckpointNs??null},checkpoints:v,checkpointIndex:x,timelineCheckpoints:g,metadata:J,isLoading:y,isHistoryLoading:w,isLoadingCheckpoint:S,error:k,hasMore:C,loadOlder:N,clearState:X,navigateToCheckpoint:E,setCurrentCheckpointId:R,returnToLatest:O,loadThread:T,clearThread:X,respondToInterrupt:B,messagePreviews:x.messagePreviews,handleStateHistoryEvent:L,markSkipNextLoad:q,markStreamPendingThread:W,resetHistoryState:j,pushUser:m,onEvent:f}),[l,c,v,g,x,J,y,w,S,k,C,N,X,E,R,O,T,B,x.messagePreviews,L,q,W,j,m,f]),_=b.useMemo(()=>({registerClearThread:I,registerRespondToInterrupt:K}),[I,K]);return u.jsx(Cu.Provider,{value:_,children:u.jsx(Su.Provider,{value:P,children:e})})}function Eu(e,t){if(!e)return null;const n=_n(e);if(!n)return null;const r=_n(n.configurable)??n;return Pn(r,t)??null}function fb(e){const t=Eu(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=Eu(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function hb(e,t){const n=typeof e.step=="number"?e.step:Number.POSITIVE_INFINITY,r=typeof t.step=="number"?t.step:Number.POSITIVE_INFINITY;if(n!==r)return n-r;const o=e.createdAt?Date.parse(e.createdAt):0,s=t.createdAt?Date.parse(t.createdAt):0;return o-s}function pb(e,t){const n=[...e].sort(hb);for(const r of n){if(r.messageId!==t)continue;const o=fb(r.parentConfig);if(!o)throw new Error(`Parent checkpoint info missing for message ${t}`);return o}throw new Error(`Message ${t} not found in timeline`)}const Iu=b.createContext(null),Nu=b.createContext(!1);function mb({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l,onToolEnd:c}){const{api:d,baseUrl:h}=Xr(),m=b.useMemo(()=>vn(h),[h]),{stream:f,stop:v,isStreaming:g,error:x,setToken:y}=qv({baseUrl:m}),[w,S]=b.useState(!1);return b.useEffect(()=>{S(g)},[g]),u.jsx(hu,{initialThreadId:t,onError:s,onThreadChange:a,children:u.jsx(ku,{initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,onError:s,isStreaming:w,children:u.jsx(Nu.Provider,{value:!0,children:u.jsx(gb,{api:d,streamApi:{stream:f,stop:v,isStreaming:g,error:x,setToken:y},onError:s,onAuthError:i,onConnectionError:l,onToolEnd:c,children:e})})})})}function gb({children:e,api:t,streamApi:n,onError:r,onAuthError:o,onConnectionError:s,onToolEnd:i}){const{stream:a,stop:l,isStreaming:c,error:d,setToken:h}=n,{setCurrentThreadId:m,currentThreadIdRef:f,addThreadFromEvent:v}=xr(),{checkpoint:g,timelineCheckpoints:x,handleStateHistoryEvent:y,markSkipNextLoad:w,markStreamPendingThread:S,resetHistoryState:k,pushUser:C,onEvent:T}=eo(),{registerClearThread:E,registerRespondToInterrupt:N}=Tu(),R=b.useCallback(B=>{v(B),f.current!==B.threadId&&((B.created??!f.current)&&w(B.threadId),S(B.threadId),m(B.threadId))},[v,w,S,m,f]),O=b.useCallback(B=>{B.type==="thread_info"?R(B):B.type==="state_history"?y(B):B.type==="tool.end"?i==null||i(B):T(B)},[R,y,T,i]),L=b.useCallback(B=>{a(B,O,{onError:M=>{console.error("[StreamingProvider] Stream error:",M),r==null||r(M)},onAuthError:M=>{console.error("[StreamingProvider] Auth error:",M),o==null||o(M)},onConnectionError:M=>{console.error("[StreamingProvider] Connection error:",M),s==null||s(M)}})},[a,O,r,o,s]),q=b.useRef(g);b.useEffect(()=>{q.current=g},[g]);const W=b.useCallback(async(B,M,I)=>{const K=f.current;if(!K)throw new Error("No active thread to handle interrupt");const J=M?I??!0:!1,P=q.current,_={threadId:K,checkpointId:P.id??void 0,checkpointNs:P.namespace??void 0,command:{kind:"resume",value:J}};L(_)},[f,L]);b.useEffect(()=>{N(W)},[W,N]);const j=b.useCallback(async()=>{l(),k(),m(null);try{await t.getAgent("default")}catch(B){console.warn("[StreamingProvider] Failed to refetch agent after clearing thread:",B)}},[t,k,m,l]);b.useEffect(()=>{E(j)},[j,E]);const X=b.useCallback(async(B,M)=>{let I=f.current;const K=(B==null?void 0:B.text)??"",J=(B==null?void 0:B.attachments)??[],P=(K==null?void 0:K.trim())??"",_={...(B==null?void 0:B.payload)??{}},z=Array.isArray(_.messages)?_.messages:void 0;z&&delete _.messages;const F=!!(z&&z.length);if(!I&&!P&&J.length===0&&!F)return;if(!I){const Ae=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ke=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);I=`${Ae}${ke}`,w(I),m(I)}const{contentParts:re,filesInfo:V}=await ou(J),D=[...re];P&&D.push({type:"text",text:K});const Z=M==null?void 0:M.originalMessageId,ee=!!(M!=null&&M.edit&&Z),Q=!F&&D.length>0;let H=null;Q&&(H={id:ee?Z:`msg-${Date.now()}`,role:"user",content:D,createdAt:new Date().toISOString()},ee?C(H,Z):C(H));const ae=F?z:H?[H]:[],ie={..._,...V.length?{files_info:V}:{}};ae.length?ie.messages=ae:"messages"in ie||(ie.messages=[]);let ge=(M==null?void 0:M.checkpointId)??g.id??void 0,ye=(M==null?void 0:M.checkpointNs)??g.namespace??void 0;if(ee&&Z){const Ae=pb(x,Z);ge=Ae.checkpointId,ye=Ae.checkpointNs??void 0}const Te={threadId:I,payload:ie,checkpointId:ge,checkpointNs:ye,edit:!!(M!=null&&M.edit)};L(Te)},[g,f,w,C,L,x]),G=b.useMemo(()=>({isStreaming:c,error:d,connectionState:c?"connected":"idle",submit:X,send:X,stop:l,setAuthToken:h}),[c,d,X,l,h]);return u.jsx(Iu.Provider,{value:G,children:e})}function $i(){const e=b.useContext(Iu);if(!e)throw new Error("useStream must be used within StreamingProvider");return e}function xb(){return b.useContext(Nu)}function Au(e){return typeof e=="object"&&e!==null}function vb(e,t){if(Object.is(e,t))return!0;if(!Au(e)||!Au(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function ju(e){const t=b.useRef(e),n=b.useRef(e);return vb(t.current,e)||(t.current=e,n.current=e),n.current}function br({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c,onToolEnd:d}){const h=ju(t),m=to(a),f=to(l),v=to(i),g=to(c),x=to(d),y=b.useMemo(()=>({initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:m,onAuthError:f,onConnectionError:v,onThreadChange:g,onToolEnd:x}),[n,r,o,s,m,f,v,g,x]);return u.jsx(nu,{apiConfig:h,children:u.jsx(mb,{...y,children:e})})}function to(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e},[e]),b.useCallback((...n)=>{const r=t.current;if(r)return r(...n)},[])}function wr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function bb(e){if(typeof e!="string")return;const t=e.trim();if(t)return vn(t)}function _u(){const e=[wr("__API_BASE_URL__"),wr("__CHAT_API_BASE_URL__"),wr("__CHAT_API_URL__")];for(const t of e){const n=bb(t);if(n)return n}}function Pu(){const e=[wr("__API_AUTH_TOKEN__"),wr("__CHAT_API_KEY__"),wr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Ru(...e){for(const t of e)if(typeof t=="string"&&t.trim())return vn(t);return vn()}function Mu(){const e={},t=_u(),n=Pu();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Ou(){const e=Mu(),t=Mn.getAuthToken(),n=_u();return{apiBaseUrl:Ru(e.baseUrl,Mn.baseUrl,n),apiKey:t||e.apiKey||Pu()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Fi="chat-settings";function Du(){try{const e=localStorage.getItem(Fi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Lu(e){try{const t={...e,apiBaseUrl:vn(e.apiBaseUrl)};localStorage.setItem(Fi,JSON.stringify(t)),t.apiKey&&Mn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function wb(){const e=Ou(),t=Du(),n=Mn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Ru(Mn.baseUrl,r,e.apiBaseUrl)}}function yb(e){Mn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),Lu(e)}function oe(...e){return ox.twMerge(rx.clsx(e))}const Sb=zr.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ze=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yt.Slot:"button";return u.jsx(i,{className:oe(Sb({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";function ce(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function $u(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function On(...e){return t=>{let n=!1;const r=e.map(o=>{const s=$u(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():$u(e[o],null)}}}}function Le(...e){return p.useCallback(On(...e),e)}function Cb(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,l=p.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=p.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function cn(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),l=n.length;n=[...n,i];const c=h=>{var y;const{scope:m,children:f,...v}=h,g=((y=m==null?void 0:m[e])==null?void 0:y[l])||a,x=p.useMemo(()=>v,Object.values(v));return u.jsx(g.Provider,{value:x,children:f})};c.displayName=s+"Provider";function d(h,m){var g;const f=((g=m==null?void 0:m[e])==null?void 0:g[l])||a,v=p.useContext(f);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>p.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Tb(o,...t)]}function Tb(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(s)[`__scope${c}`];return{...a,...h}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},kb=p[" useInsertionEffect ".trim().toString()]||Tt;function Dn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Eb({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=p.useRef(e!==void 0);p.useEffect(()=>{const h=d.current;h!==a&&console.warn(`${r} is changing from ${h?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=p.useCallback(d=>{var h;if(a){const m=Ib(d)?d(e):d;m!==e&&((h=i.current)==null||h.call(i,m))}else s(d)},[a,e,s,i]);return[l,c]}function Eb({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return kb(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Ib(e){return typeof e=="function"}var Nb=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ve=Nb.reduce((e,t)=>{const n=Yt.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bi(e,t){e&&Hr.flushSync(()=>e.dispatchEvent(t))}function Xo(e){const t=e+"CollectionProvider",[n,r]=cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:x,children:y}=g,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:x,itemMap:S,collectionRef:w,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=Yt.createSlot(a),c=b.forwardRef((g,x)=>{const{scope:y,children:w}=g,S=s(a,y),k=Le(x,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",h="data-radix-collection-item",m=Yt.createSlot(d),f=b.forwardRef((g,x)=>{const{scope:y,children:w,...S}=g,k=b.useRef(null),C=Le(x,k),T=s(d,y);return b.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(m,{[h]:"",ref:C,children:w})});f.displayName=d;function v(g){const x=s(e+"CollectionConsumer",g);return b.useCallback(()=>{const w=x.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${h}]`));return Array.from(x.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:c,ItemSlot:f},v,r]}var Ab=p.createContext(void 0);function Jo(e){const t=p.useContext(Ab);return e||t||"ltr"}function ht(e){const t=p.useRef(e);return p.useEffect(()=>{t.current=e}),p.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function jb(e,t=globalThis==null?void 0:globalThis.document){const n=ht(e);p.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var _b="DismissableLayer",zi="dismissableLayer.update",Pb="dismissableLayer.pointerDownOutside",Rb="dismissableLayer.focusOutside",Fu,Bu=p.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),yr=p.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=p.useContext(Bu),[d,h]=p.useState(null),m=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=p.useState({}),v=Le(t,E=>h(E)),g=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),w=d?g.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=y,C=Ob(E=>{const N=E.target,R=[...c.branches].some(O=>O.contains(N));!k||R||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},m),T=Db(E=>{const N=E.target;[...c.branches].some(O=>O.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},m);return jb(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},m),p.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(Fu=m.body.style.pointerEvents,m.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),Hu(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(m.body.style.pointerEvents=Fu)}},[d,m,n,c]),p.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),Hu())},[d,c]),p.useEffect(()=>{const E=()=>f({});return document.addEventListener(zi,E),()=>document.removeEventListener(zi,E)},[]),u.jsx(ve.div,{...l,ref:v,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ce(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ce(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ce(e.onPointerDownCapture,C.onPointerDownCapture)})});yr.displayName=_b;var Mb="DismissableLayerBranch",zu=p.forwardRef((e,t)=>{const n=p.useContext(Bu),r=p.useRef(null),o=Le(t,r);return p.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(ve.div,{...e,ref:o})});zu.displayName=Mb;function Ob(e,t=globalThis==null?void 0:globalThis.document){const n=ht(e),r=p.useRef(!1),o=p.useRef(()=>{});return p.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Uu(Pb,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Db(e,t=globalThis==null?void 0:globalThis.document){const n=ht(e),r=p.useRef(!1);return p.useEffect(()=>{const o=s=>{s.target&&!r.current&&Uu(Rb,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Hu(){const e=new CustomEvent(zi);document.dispatchEvent(e)}function Uu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Bi(o,s):o.dispatchEvent(s)}var Lb=yr,$b=zu,Hi=0;function Ui(){p.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Wu()),document.body.insertAdjacentElement("beforeend",e[1]??Wu()),Hi++,()=>{Hi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Hi--}},[])}function Wu(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Wi="focusScope.autoFocusOnMount",Vi="focusScope.autoFocusOnUnmount",Vu={bubbles:!1,cancelable:!0},Fb="FocusScope",Zo=p.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=p.useState(null),c=ht(o),d=ht(s),h=p.useRef(null),m=Le(t,g=>l(g)),f=p.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;p.useEffect(()=>{if(r){let g=function(S){if(f.paused||!a)return;const k=S.target;a.contains(k)?h.current=k:Ln(h.current,{select:!0})},x=function(S){if(f.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||Ln(h.current,{select:!0}))},y=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Ln(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const w=new MutationObserver(y);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),w.disconnect()}}},[r,a,f.paused]),p.useEffect(()=>{if(a){Gu.add(f);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(Wi,Vu);a.addEventListener(Wi,c),a.dispatchEvent(y),y.defaultPrevented||(Bb(Vb(Ku(a)),{select:!0}),document.activeElement===g&&Ln(a))}return()=>{a.removeEventListener(Wi,c),setTimeout(()=>{const y=new CustomEvent(Vi,Vu);a.addEventListener(Vi,d),a.dispatchEvent(y),y.defaultPrevented||Ln(g??document.body,{select:!0}),a.removeEventListener(Vi,d),Gu.remove(f)},0)}}},[a,c,d,f]);const v=p.useCallback(g=>{if(!n&&!r||f.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const w=g.currentTarget,[S,k]=zb(w);S&&k?!g.shiftKey&&y===k?(g.preventDefault(),n&&Ln(S,{select:!0})):g.shiftKey&&y===S&&(g.preventDefault(),n&&Ln(k,{select:!0})):y===w&&g.preventDefault()}},[n,r,f.paused]);return u.jsx(ve.div,{tabIndex:-1,...i,ref:m,onKeyDown:v})});Zo.displayName=Fb;function Bb(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Ln(r,{select:t}),document.activeElement!==n)return}function zb(e){const t=Ku(e),n=qu(t,e),r=qu(t.reverse(),e);return[n,r]}function Ku(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function qu(e,t){for(const n of e)if(!Hb(n,{upTo:t}))return n}function Hb(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Ub(e){return e instanceof HTMLInputElement&&"select"in e}function Ln(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ub(e)&&t&&e.select()}}var Gu=Wb();function Wb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Yu(e,t),e.unshift(t)},remove(t){var n;e=Yu(e,t),(n=e[0])==null||n.resume()}}}function Yu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Vb(e){return e.filter(t=>t.tagName!=="A")}var Kb=p[" useId ".trim().toString()]||(()=>{}),qb=0;function Rt(e){const[t,n]=p.useState(Kb());return Tt(()=>{n(r=>r??String(qb++))},[e]),t?`radix-${t}`:""}const Gb=["top","right","bottom","left"],$n=Math.min,Zt=Math.max,Qo=Math.round,es=Math.floor,bn=e=>({x:e,y:e}),Yb={left:"right",right:"left",bottom:"top",top:"bottom"},Xb={start:"end",end:"start"};function Ki(e,t,n){return Zt(e,$n(t,n))}function Nn(e,t){return typeof e=="function"?e(t):e}function An(e){return e.split("-")[0]}function Sr(e){return e.split("-")[1]}function qi(e){return e==="x"?"y":"x"}function Gi(e){return e==="y"?"height":"width"}const Jb=new Set(["top","bottom"]);function wn(e){return Jb.has(An(e))?"y":"x"}function Yi(e){return qi(wn(e))}function Zb(e,t,n){n===void 0&&(n=!1);const r=Sr(e),o=Yi(e),s=Gi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ts(i)),[i,ts(i)]}function Qb(e){const t=ts(e);return[Xi(e),t,Xi(t)]}function Xi(e){return e.replace(/start|end/g,t=>Xb[t])}const Xu=["left","right"],Ju=["right","left"],ew=["top","bottom"],tw=["bottom","top"];function nw(e,t,n){switch(e){case"top":case"bottom":return n?t?Ju:Xu:t?Xu:Ju;case"left":case"right":return t?ew:tw;default:return[]}}function rw(e,t,n,r){const o=Sr(e);let s=nw(An(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Xi)))),s}function ts(e){return e.replace(/left|right|bottom|top/g,t=>Yb[t])}function ow(e){return{top:0,right:0,bottom:0,left:0,...e}}function Zu(e){return typeof e!="number"?ow(e):{top:e,right:e,bottom:e,left:e}}function ns(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Qu(e,t,n){let{reference:r,floating:o}=e;const s=wn(t),i=Yi(t),a=Gi(i),l=An(t),c=s==="y",d=r.x+r.width/2-o.width/2,h=r.y+r.height/2-o.height/2,m=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:d,y:r.y-o.height};break;case"bottom":f={x:d,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:h};break;case"left":f={x:r.x-o.width,y:h};break;default:f={x:r.x,y:r.y}}switch(Sr(t)){case"start":f[i]-=m*(n&&c?-1:1);break;case"end":f[i]+=m*(n&&c?-1:1);break}return f}const sw=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:h}=Qu(c,r,l),m=r,f={},v=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:w,y:S,data:k,reset:C}=await y({x:d,y:h,initialPlacement:r,placement:m,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,h=S??h,f={...f,[x]:{...f[x],...k}},C&&v<=50&&(v++,typeof C=="object"&&(C.placement&&(m=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:h}=Qu(c,m,l)),g=-1)}return{x:d,y:h,placement:m,strategy:o,middlewareData:f}};async function no(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:m=!1,padding:f=0}=Nn(t,e),v=Zu(f),x=a[m?h==="floating"?"reference":"floating":h],y=ns(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=h==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=ns(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(y.top-C.top+v.top)/k.y,bottom:(C.bottom-y.bottom+v.bottom)/k.y,left:(y.left-C.left+v.left)/k.x,right:(C.right-y.right+v.right)/k.x}}const iw=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=Nn(e,t)||{};if(c==null)return{};const h=Zu(d),m={x:n,y:r},f=Yi(o),v=Gi(f),g=await i.getDimensions(c),x=f==="y",y=x?"top":"left",w=x?"bottom":"right",S=x?"clientHeight":"clientWidth",k=s.reference[v]+s.reference[f]-m[f]-s.floating[v],C=m[f]-s.reference[f],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[v]);const N=k/2-C/2,R=E/2-g[v]/2-1,O=$n(h[y],R),L=$n(h[w],R),q=O,W=E-g[v]-L,j=E/2-g[v]/2+N,X=Ki(q,j,W),G=!l.arrow&&Sr(o)!=null&&j!==X&&s.reference[v]/2-(j<q?O:L)-g[v]/2<0,B=G?j<q?j-q:j-W:0;return{[f]:m[f]+B,data:{[f]:X,centerOffset:j-X-B,...G&&{alignmentOffset:B}},reset:G}}}),aw=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:g=!0,...x}=Nn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=An(o),w=wn(a),S=An(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=m||(S||!g?[ts(a)]:Qb(a)),T=v!=="none";!m&&T&&C.push(...rw(a,g,v,k));const E=[a,...C],N=await no(t,x),R=[];let O=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(N[y]),h){const j=Zb(o,i,k);R.push(N[j[0]],N[j[1]])}if(O=[...O,{placement:o,overflows:R}],!R.every(j=>j<=0)){var L,q;const j=(((L=s.flip)==null?void 0:L.index)||0)+1,X=E[j];if(X&&(!(h==="alignment"?w!==wn(X):!1)||O.every(M=>wn(M.placement)===w?M.overflows[0]>0:!0)))return{data:{index:j,overflows:O},reset:{placement:X}};let G=(q=O.filter(B=>B.overflows[0]<=0).sort((B,M)=>B.overflows[1]-M.overflows[1])[0])==null?void 0:q.placement;if(!G)switch(f){case"bestFit":{var W;const B=(W=O.filter(M=>{if(T){const I=wn(M.placement);return I===w||I==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(I=>I>0).reduce((I,K)=>I+K,0)]).sort((M,I)=>M[1]-I[1])[0])==null?void 0:W[0];B&&(G=B);break}case"initialPlacement":G=a;break}if(o!==G)return{reset:{placement:G}}}return{}}}};function ed(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function td(e){return Gb.some(t=>e[t]>=0)}const lw=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Nn(e,t);switch(r){case"referenceHidden":{const s=await no(t,{...o,elementContext:"reference"}),i=ed(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:td(i)}}}case"escaped":{const s=await no(t,{...o,altBoundary:!0}),i=ed(s,n.floating);return{data:{escapedOffsets:i,escaped:td(i)}}}default:return{}}}}},nd=new Set(["left","top"]);async function cw(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=An(n),a=Sr(n),l=wn(n)==="y",c=nd.has(i)?-1:1,d=s&&l?-1:1,h=Nn(t,e);let{mainAxis:m,crossAxis:f,alignmentAxis:v}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof v=="number"&&(f=a==="end"?v*-1:v),l?{x:f*d,y:m*c}:{x:m*c,y:f*d}}const uw=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await cw(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},dw=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:x=>{let{x:y,y:w}=x;return{x:y,y:w}}},...l}=Nn(e,t),c={x:n,y:r},d=await no(t,l),h=wn(An(o)),m=qi(h);let f=c[m],v=c[h];if(s){const x=m==="y"?"top":"left",y=m==="y"?"bottom":"right",w=f+d[x],S=f-d[y];f=Ki(w,f,S)}if(i){const x=h==="y"?"top":"left",y=h==="y"?"bottom":"right",w=v+d[x],S=v-d[y];v=Ki(w,v,S)}const g=a.fn({...t,[m]:f,[h]:v});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[m]:s,[h]:i}}}}}},fw=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Nn(e,t),d={x:n,y:r},h=wn(o),m=qi(h);let f=d[m],v=d[h];const g=Nn(a,t),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const S=m==="y"?"height":"width",k=s.reference[m]-s.floating[S]+x.mainAxis,C=s.reference[m]+s.reference[S]-x.mainAxis;f<k?f=k:f>C&&(f=C)}if(c){var y,w;const S=m==="y"?"width":"height",k=nd.has(An(o)),C=s.reference[h]-s.floating[S]+(k&&((y=i.offset)==null?void 0:y[h])||0)+(k?0:x.crossAxis),T=s.reference[h]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[h])||0)-(k?x.crossAxis:0);v<C?v=C:v>T&&(v=T)}return{[m]:f,[h]:v}}}},hw=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=Nn(e,t),d=await no(t,c),h=An(o),m=Sr(o),f=wn(o)==="y",{width:v,height:g}=s.floating;let x,y;h==="top"||h==="bottom"?(x=h,y=m===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=h,x=m==="end"?"top":"bottom");const w=g-d.top-d.bottom,S=v-d.left-d.right,k=$n(g-d[x],w),C=$n(v-d[y],S),T=!t.middlewareData.shift;let E=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),T&&!m){const O=Zt(d.left,0),L=Zt(d.right,0),q=Zt(d.top,0),W=Zt(d.bottom,0);f?N=v-2*(O!==0||L!==0?O+L:Zt(d.left,d.right)):E=g-2*(q!==0||W!==0?q+W:Zt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const R=await i.getDimensions(a.floating);return v!==R.width||g!==R.height?{reset:{rects:!0}}:{}}}};function rs(){return typeof window<"u"}function Cr(e){return rd(e)?(e.nodeName||"").toLowerCase():"#document"}function Qt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function yn(e){var t;return(t=(rd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function rd(e){return rs()?e instanceof Node||e instanceof Qt(e).Node:!1}function un(e){return rs()?e instanceof Element||e instanceof Qt(e).Element:!1}function Sn(e){return rs()?e instanceof HTMLElement||e instanceof Qt(e).HTMLElement:!1}function od(e){return!rs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Qt(e).ShadowRoot}const pw=new Set(["inline","contents"]);function ro(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!pw.has(o)}const mw=new Set(["table","td","th"]);function gw(e){return mw.has(Cr(e))}const xw=[":popover-open",":modal"];function os(e){return xw.some(t=>{try{return e.matches(t)}catch{return!1}})}const vw=["transform","translate","scale","rotate","perspective"],bw=["transform","translate","scale","rotate","perspective","filter"],ww=["paint","layout","strict","content"];function Ji(e){const t=Zi(),n=un(e)?dn(e):e;return vw.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||bw.some(r=>(n.willChange||"").includes(r))||ww.some(r=>(n.contain||"").includes(r))}function yw(e){let t=Fn(e);for(;Sn(t)&&!Tr(t);){if(Ji(t))return t;if(os(t))return null;t=Fn(t)}return null}function Zi(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Sw=new Set(["html","body","#document"]);function Tr(e){return Sw.has(Cr(e))}function dn(e){return Qt(e).getComputedStyle(e)}function ss(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Fn(e){if(Cr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||od(e)&&e.host||yn(e);return od(t)?t.host:t}function sd(e){const t=Fn(e);return Tr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sn(t)&&ro(t)?t:sd(t)}function oo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=sd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Qt(o);if(s){const a=Qi(i);return t.concat(i,i.visualViewport||[],ro(o)?o:[],a&&n?oo(a):[])}return t.concat(o,oo(o,[],n))}function Qi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function id(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Qo(n)!==s||Qo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ea(e){return un(e)?e:e.contextElement}function kr(e){const t=ea(e);if(!Sn(t))return bn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=id(t);let i=(s?Qo(n.width):n.width)/r,a=(s?Qo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Cw=bn(0);function ad(e){const t=Qt(e);return!Zi()||!t.visualViewport?Cw:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Tw(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Qt(e)?!1:t}function er(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ea(e);let i=bn(1);t&&(r?un(r)&&(i=kr(r)):i=kr(e));const a=Tw(s,n,r)?ad(s):bn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,h=o.height/i.y;if(s){const m=Qt(s),f=r&&un(r)?Qt(r):r;let v=m,g=Qi(v);for(;g&&r&&f!==v;){const x=kr(g),y=g.getBoundingClientRect(),w=dn(g),S=y.left+(g.clientLeft+parseFloat(w.paddingLeft))*x.x,k=y.top+(g.clientTop+parseFloat(w.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,h*=x.y,l+=S,c+=k,v=Qt(g),g=Qi(v)}}return ns({width:d,height:h,x:l,y:c})}function is(e,t){const n=ss(e).scrollLeft;return t?t.left+n:er(yn(e)).left+n}function ld(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-is(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function kw(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=yn(r),a=t?os(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=bn(1);const d=bn(0),h=Sn(r);if((h||!h&&!s)&&((Cr(r)!=="body"||ro(i))&&(l=ss(r)),Sn(r))){const f=er(r);c=kr(r),d.x=f.x+r.clientLeft,d.y=f.y+r.clientTop}const m=i&&!h&&!s?ld(i,l):bn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+m.x,y:n.y*c.y-l.scrollTop*c.y+d.y+m.y}}function Ew(e){return Array.from(e.getClientRects())}function Iw(e){const t=yn(e),n=ss(e),r=e.ownerDocument.body,o=Zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+is(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const cd=25;function Nw(e,t){const n=Qt(e),r=yn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Zi();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=is(r);if(c<=0){const d=r.ownerDocument,h=d.body,m=getComputedStyle(h),f=d.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,v=Math.abs(r.clientWidth-h.clientWidth-f);v<=cd&&(s-=v)}else c<=cd&&(s+=c);return{width:s,height:i,x:a,y:l}}const Aw=new Set(["absolute","fixed"]);function jw(e,t){const n=er(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Sn(e)?kr(e):bn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function ud(e,t,n){let r;if(t==="viewport")r=Nw(e,n);else if(t==="document")r=Iw(yn(e));else if(un(t))r=jw(t,n);else{const o=ad(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ns(r)}function dd(e,t){const n=Fn(e);return n===t||!un(n)||Tr(n)?!1:dn(n).position==="fixed"||dd(n,t)}function _w(e,t){const n=t.get(e);if(n)return n;let r=oo(e,[],!1).filter(a=>un(a)&&Cr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Fn(e):e;for(;un(i)&&!Tr(i);){const a=dn(i),l=Ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Aw.has(o.position)||ro(i)&&!l&&dd(e,i))?r=r.filter(d=>d!==i):o=a,i=Fn(i)}return t.set(e,r),r}function Pw(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?os(t)?[]:_w(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const h=ud(t,d,o);return c.top=Zt(h.top,c.top),c.right=$n(h.right,c.right),c.bottom=$n(h.bottom,c.bottom),c.left=Zt(h.left,c.left),c},ud(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Rw(e){const{width:t,height:n}=id(e);return{width:t,height:n}}function Mw(e,t,n){const r=Sn(t),o=yn(t),s=n==="fixed",i=er(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=bn(0);function c(){l.x=is(o)}if(r||!r&&!s)if((Cr(t)!=="body"||ro(o))&&(a=ss(t)),r){const f=er(t,!0,s,t);l.x=f.x+t.clientLeft,l.y=f.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?ld(o,a):bn(0),h=i.left+a.scrollLeft-l.x-d.x,m=i.top+a.scrollTop-l.y-d.y;return{x:h,y:m,width:i.width,height:i.height}}function ta(e){return dn(e).position==="static"}function fd(e,t){if(!Sn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return yn(e)===n&&(n=n.ownerDocument.body),n}function hd(e,t){const n=Qt(e);if(os(e))return n;if(!Sn(e)){let o=Fn(e);for(;o&&!Tr(o);){if(un(o)&&!ta(o))return o;o=Fn(o)}return n}let r=fd(e,t);for(;r&&gw(r)&&ta(r);)r=fd(r,t);return r&&Tr(r)&&ta(r)&&!Ji(r)?n:r||yw(e)||n}const Ow=async function(e){const t=this.getOffsetParent||hd,n=this.getDimensions,r=await n(e.floating);return{reference:Mw(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Dw(e){return dn(e).direction==="rtl"}const Lw={convertOffsetParentRelativeRectToViewportRelativeRect:kw,getDocumentElement:yn,getClippingRect:Pw,getOffsetParent:hd,getElementRects:Ow,getClientRects:Ew,getDimensions:Rw,getScale:kr,isElement:un,isRTL:Dw};function pd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $w(e,t){let n=null,r;const o=yn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:h,width:m,height:f}=c;if(a||t(),!m||!f)return;const v=es(h),g=es(o.clientWidth-(d+m)),x=es(o.clientHeight-(h+f)),y=es(d),S={rootMargin:-v+"px "+-g+"px "+-x+"px "+-y+"px",threshold:Zt(0,$n(1,l))||1};let k=!0;function C(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!pd(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Fw(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=ea(e),d=o||s?[...c?oo(c):[],...oo(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const h=c&&a?$w(c,n):null;let m=-1,f=null;i&&(f=new ResizeObserver(y=>{let[w]=y;w&&w.target===c&&f&&(f.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var S;(S=f)==null||S.observe(t)})),n()}),c&&!l&&f.observe(c),f.observe(t));let v,g=l?er(e):null;l&&x();function x(){const y=er(e);g&&!pd(g,y)&&n(),g=y,v=requestAnimationFrame(x)}return n(),()=>{var y;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),h==null||h(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(v)}}const Bw=uw,zw=dw,Hw=aw,Uw=hw,Ww=lw,md=iw,Vw=fw,Kw=(e,t,n)=>{const r=new Map,o={platform:Lw,...n},s={...o.platform,_c:r};return sw(e,t,{...o,platform:s})};var qw=typeof document<"u",Gw=function(){},as=qw?b.useLayoutEffect:Gw;function ls(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!ls(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!ls(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function gd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xd(e,t){const n=gd(e);return Math.round(t*n)/n}function na(e){const t=p.useRef(e);return as(()=>{t.current=e}),t}function Yw(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,h]=p.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,f]=p.useState(r);ls(m,r)||f(r);const[v,g]=p.useState(null),[x,y]=p.useState(null),w=p.useCallback(M=>{M!==T.current&&(T.current=M,g(M))},[]),S=p.useCallback(M=>{M!==E.current&&(E.current=M,y(M))},[]),k=s||v,C=i||x,T=p.useRef(null),E=p.useRef(null),N=p.useRef(d),R=l!=null,O=na(l),L=na(o),q=na(c),W=p.useCallback(()=>{if(!T.current||!E.current)return;const M={placement:t,strategy:n,middleware:m};L.current&&(M.platform=L.current),Kw(T.current,E.current,M).then(I=>{const K={...I,isPositioned:q.current!==!1};j.current&&!ls(N.current,K)&&(N.current=K,Hr.flushSync(()=>{h(K)}))})},[m,t,n,L,q]);as(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,h(M=>({...M,isPositioned:!1})))},[c]);const j=p.useRef(!1);as(()=>(j.current=!0,()=>{j.current=!1}),[]),as(()=>{if(k&&(T.current=k),C&&(E.current=C),k&&C){if(O.current)return O.current(k,C,W);W()}},[k,C,W,O,R]);const X=p.useMemo(()=>({reference:T,floating:E,setReference:w,setFloating:S}),[w,S]),G=p.useMemo(()=>({reference:k,floating:C}),[k,C]),B=p.useMemo(()=>{const M={position:n,left:0,top:0};if(!G.floating)return M;const I=xd(G.floating,d.x),K=xd(G.floating,d.y);return a?{...M,transform:"translate("+I+"px, "+K+"px)",...gd(G.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:I,top:K}},[n,a,G.floating,d.x,d.y]);return p.useMemo(()=>({...d,update:W,refs:X,elements:G,floatingStyles:B}),[d,W,X,G,B])}const Xw=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?md({element:r.current,padding:o}).fn(n):{}:r?md({element:r,padding:o}).fn(n):{}}}},Jw=(e,t)=>({...Bw(e),options:[e,t]}),Zw=(e,t)=>({...zw(e),options:[e,t]}),Qw=(e,t)=>({...Vw(e),options:[e,t]}),ey=(e,t)=>({...Hw(e),options:[e,t]}),ty=(e,t)=>({...Uw(e),options:[e,t]}),ny=(e,t)=>({...Ww(e),options:[e,t]}),ry=(e,t)=>({...Xw(e),options:[e,t]});var oy="Arrow",vd=p.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(ve.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});vd.displayName=oy;var sy=vd;function bd(e){const[t,n]=p.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ra="Popper",[wd,Er]=cn(ra),[iy,yd]=wd(ra),Sd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=p.useState(null);return u.jsx(iy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Sd.displayName=ra;var Cd="PopperAnchor",Td=p.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=yd(Cd,n),i=p.useRef(null),a=Le(t,i),l=p.useRef(null);return p.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(ve.div,{...o,ref:a})});Td.displayName=Cd;var oa="PopperContent",[ay,ly]=wd(oa),kd=p.forwardRef((e,t)=>{var V,D,Z,ee,Q,H;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:h="partial",hideWhenDetached:m=!1,updatePositionStrategy:f="optimized",onPlaced:v,...g}=e,x=yd(oa,n),[y,w]=p.useState(null),S=Le(t,ae=>w(ae)),[k,C]=p.useState(null),T=bd(k),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),O=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],q=L.length>0,W={padding:O,boundary:L.filter(uy),altBoundary:q},{refs:j,floatingStyles:X,placement:G,isPositioned:B,middlewareData:M}=Yw({strategy:"fixed",placement:R,whileElementsMounted:(...ae)=>Fw(...ae,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[Jw({mainAxis:o+N,alignmentAxis:i}),l&&Zw({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Qw():void 0,...W}),l&&ey({...W}),ty({...W,apply:({elements:ae,rects:ie,availableWidth:ge,availableHeight:ye})=>{const{width:Te,height:Ae}=ie.reference,ke=ae.floating.style;ke.setProperty("--radix-popper-available-width",`${ge}px`),ke.setProperty("--radix-popper-available-height",`${ye}px`),ke.setProperty("--radix-popper-anchor-width",`${Te}px`),ke.setProperty("--radix-popper-anchor-height",`${Ae}px`)}}),k&&ry({element:k,padding:a}),dy({arrowWidth:E,arrowHeight:N}),m&&ny({strategy:"referenceHidden",...W})]}),[I,K]=Nd(G),J=ht(v);Tt(()=>{B&&(J==null||J())},[B,J]);const P=(V=M.arrow)==null?void 0:V.x,_=(D=M.arrow)==null?void 0:D.y,z=((Z=M.arrow)==null?void 0:Z.centerOffset)!==0,[F,re]=p.useState();return Tt(()=>{y&&re(window.getComputedStyle(y).zIndex)},[y]),u.jsx("div",{ref:j.setFloating,"data-radix-popper-content-wrapper":"",style:{...X,transform:B?X.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:F,"--radix-popper-transform-origin":[(ee=M.transformOrigin)==null?void 0:ee.x,(Q=M.transformOrigin)==null?void 0:Q.y].join(" "),...((H=M.hide)==null?void 0:H.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(ay,{scope:n,placedSide:I,onArrowChange:C,arrowX:P,arrowY:_,shouldHideArrow:z,children:u.jsx(ve.div,{"data-side":I,"data-align":K,...g,ref:S,style:{...g.style,animation:B?void 0:"none"}})})})});kd.displayName=oa;var Ed="PopperArrow",cy={top:"bottom",right:"left",bottom:"top",left:"right"},Id=p.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=ly(Ed,r),i=cy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(sy,{...o,ref:n,style:{...o.style,display:"block"}})})});Id.displayName=Ed;function uy(e){return e!==null}var dy=e=>({name:"transformOrigin",options:e,fn(t){var x,y,w;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=Nd(n),h={start:"0%",center:"50%",end:"100%"}[d],m=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let v="",g="";return c==="bottom"?(v=i?h:`${m}px`,g=`${-l}px`):c==="top"?(v=i?h:`${m}px`,g=`${r.floating.height+l}px`):c==="right"?(v=`${-l}px`,g=i?h:`${f}px`):c==="left"&&(v=`${r.floating.width+l}px`,g=i?h:`${f}px`),{data:{x:v,y:g}}}});function Nd(e){const[t,n="center"]=e.split("-");return[t,n]}var sa=Sd,ia=Td,aa=kd,la=Id,fy="Portal",so=p.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=p.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ro.createPortal(u.jsx(ve.div,{...r,ref:t}),i):null});so.displayName=fy;function hy(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var Ut=e=>{const{present:t,children:n}=e,r=py(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Le(r.ref,my(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};Ut.displayName="Presence";function py(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,l]=hy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const c=cs(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const m=s.current,f=cs(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&m!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,h=f=>{const g=cs(r.current).includes(CSS.escape(f.animationName));if(f.target===t&&g&&(l("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},m=f=>{f.target===t&&(s.current=cs(r.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function cs(e){return(e==null?void 0:e.animationName)||"none"}function my(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var ca="rovingFocusGroup.onEntryFocus",gy={bubbles:!1,cancelable:!0},io="RovingFocusGroup",[ua,Ad,xy]=Xo(io),[vy,jd]=cn(io,[xy]),[by,wy]=vy(io),_d=p.forwardRef((e,t)=>u.jsx(ua.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ua.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(yy,{...e,ref:t})})}));_d.displayName=io;var yy=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...h}=e,m=p.useRef(null),f=Le(t,m),v=Jo(s),[g,x]=Dn({prop:i,defaultProp:a??null,onChange:l,caller:io}),[y,w]=p.useState(!1),S=ht(c),k=Ad(n),C=p.useRef(!1),[T,E]=p.useState(0);return p.useEffect(()=>{const N=m.current;if(N)return N.addEventListener(ca,S),()=>N.removeEventListener(ca,S)},[S]),u.jsx(by,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:g,onItemFocus:p.useCallback(N=>x(N),[x]),onItemShiftTab:p.useCallback(()=>w(!0),[]),onFocusableItemAdd:p.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:p.useCallback(()=>E(N=>N-1),[]),children:u.jsx(ve.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...e.style},onMouseDown:ce(e.onMouseDown,()=>{C.current=!0}),onFocus:ce(e.onFocus,N=>{const R=!C.current;if(N.target===N.currentTarget&&R&&!y){const O=new CustomEvent(ca,gy);if(N.currentTarget.dispatchEvent(O),!O.defaultPrevented){const L=k().filter(G=>G.focusable),q=L.find(G=>G.active),W=L.find(G=>G.id===g),X=[q,W,...L].filter(Boolean).map(G=>G.ref.current);Md(X,d)}}C.current=!1}),onBlur:ce(e.onBlur,()=>w(!1))})})}),Pd="RovingFocusGroupItem",Rd=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Rt(),c=s||l,d=wy(Pd,n),h=d.currentTabStopId===c,m=Ad(n),{onFocusableItemAdd:f,onFocusableItemRemove:v,currentTabStopId:g}=d;return p.useEffect(()=>{if(r)return f(),()=>v()},[r,f,v]),u.jsx(ua.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(ve.span,{tabIndex:h?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ce(e.onMouseDown,x=>{r?d.onItemFocus(c):x.preventDefault()}),onFocus:ce(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ce(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){d.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=Ty(x,d.orientation,d.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let S=m().filter(k=>k.focusable).map(k=>k.ref.current);if(y==="last")S.reverse();else if(y==="prev"||y==="next"){y==="prev"&&S.reverse();const k=S.indexOf(x.currentTarget);S=d.loop?ky(S,k+1):S.slice(k+1)}setTimeout(()=>Md(S))}}),children:typeof i=="function"?i({isCurrentTabStop:h,hasTabStop:g!=null}):i})})});Rd.displayName=Pd;var Sy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Cy(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ty(e,t,n){const r=Cy(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Sy[r]}function Md(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function ky(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ey=_d,Iy=Rd,Ny=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Ir=new WeakMap,us=new WeakMap,ds={},da=0,Od=function(e){return e&&(e.host||Od(e.parentNode))},Ay=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Od(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},jy=function(e,t,n,r){var o=Ay(t,Array.isArray(e)?e:[e]);ds[n]||(ds[n]=new WeakMap);var s=ds[n],i=[],a=new Set,l=new Set(o),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};o.forEach(c);var d=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(m){if(a.has(m))d(m);else try{var f=m.getAttribute(r),v=f!==null&&f!=="false",g=(Ir.get(m)||0)+1,x=(s.get(m)||0)+1;Ir.set(m,g),s.set(m,x),i.push(m),g===1&&v&&us.set(m,!0),x===1&&m.setAttribute(n,"true"),v||m.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",m,y)}})};return d(t),a.clear(),da++,function(){i.forEach(function(h){var m=Ir.get(h)-1,f=s.get(h)-1;Ir.set(h,m),s.set(h,f),m||(us.has(h)||h.removeAttribute(r),us.delete(h)),f||h.removeAttribute(n)}),da--,da||(Ir=new WeakMap,Ir=new WeakMap,us=new WeakMap,ds={})}},fa=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Ny(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),jy(r,o,n,"aria-hidden")):function(){return null}},Cn=function(){return Cn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Cn.apply(this,arguments)};function Dd(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function _y(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var fs="right-scroll-bar-position",hs="width-before-scroll-bar",Py="with-scroll-bars-hidden",Ry="--removed-body-scroll-bar-size";function ha(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function My(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Oy=typeof window<"u"?p.useLayoutEffect:p.useEffect,Ld=new WeakMap;function Dy(e,t){var n=My(null,function(r){return e.forEach(function(o){return ha(o,r)})});return Oy(function(){var r=Ld.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ha(a,null)}),s.forEach(function(a){o.has(a)||ha(a,i)})}Ld.set(n,e)},[e]),n}function Ly(e){return e}function $y(e,t){t===void 0&&(t=Ly);var n=[],r=!1,o={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]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Fy(e){e===void 0&&(e={});var t=$y(null);return t.options=Cn({async:!0,ssr:!1},e),t}var $d=function(e){var t=e.sideCar,n=Dd(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return p.createElement(r,Cn({},n))};$d.isSideCarExport=!0;function By(e,t){return e.useMedium(t),$d}var Fd=Fy(),pa=function(){},ps=p.forwardRef(function(e,t){var n=p.useRef(null),r=p.useState({onScrollCapture:pa,onWheelCapture:pa,onTouchMoveCapture:pa}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,h=e.shards,m=e.sideCar,f=e.noRelative,v=e.noIsolation,g=e.inert,x=e.allowPinchZoom,y=e.as,w=y===void 0?"div":y,S=e.gapMode,k=Dd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=m,T=Dy([n,t]),E=Cn(Cn({},k),o);return p.createElement(p.Fragment,null,d&&p.createElement(C,{sideCar:Fd,removeScrollBar:c,shards:h,noRelative:f,noIsolation:v,inert:g,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:S}),i?p.cloneElement(p.Children.only(a),Cn(Cn({},E),{ref:T})):p.createElement(w,Cn({},E,{className:l,ref:T}),a))});ps.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ps.classNames={fullWidth:hs,zeroRight:fs};var zy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Hy(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=zy();return t&&e.setAttribute("nonce",t),e}function Uy(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Wy(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Vy=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Hy())&&(Uy(t,n),Wy(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ky=function(){var e=Vy();return function(t,n){p.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Bd=function(){var e=Ky(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},qy={left:0,top:0,right:0,gap:0},ma=function(e){return parseInt(e||"",10)||0},Gy=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[ma(n),ma(r),ma(o)]},Yy=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return qy;var t=Gy(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Xy=Bd(),Nr="data-scroll-locked",Jy=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
38
|
+
`);if(!Ct)continue;let It;try{It=JSON.parse(Ct)}catch{console.debug("[use-chat] malformed SSE:",Ct.slice(0,200));continue}const Lt=su(It)?It.data:It;if(!Lt){console.warn("[use-chat] dropped envelope event without payload",It);continue}const je=Lt;jt=Date.now();const ct=je.seq;if(ct!==void 0){if(ct<=wt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ct,lastProcessedSeq:wt,type:je.type});continue}wt>0&&ct>wt+1&&((Q=I==null?void 0:I.onGap)==null||Q.call(I,{from:wt,to:ct})),wt=ct,E.current=ct,x(ct)}if(je.type==="message.start"&&je.role==="assistant"){const Xe=uu(je.model);q.current={messageId:je.id,lastSeq:ct??null,lastText:""},k({id:je.id,role:"assistant",name:Xe??void 0,model:je.model,createdAt:new Date().toISOString(),content:[]})}if(je.type==="checkpoint")R.current=je.checkpointId??null,O.current=je.checkpointNs??null,v(je.checkpointId??null);else if(je.type==="state_history"){L.current=je;try{const lt=Mn(je).latest;lt&&(R.current=lt.checkpointId??null,O.current=lt.checkpointNs??null,v(lt.checkpointId??null))}catch(Xe){console.warn("[use-chat] Failed to hydrate state_history payload",Xe)}}try{M==null||M(je)}catch(Xe){console.error("[use-chat] Error in onEvent callback:",Xe,"for event:",je.type)}if(je.type==="message.delta"){k(lt=>{const an=q.current;if(!lt||an.messageId!==lt.id)return lt;const{newParts:A,newMeta:te,changed:he}=lu(lt.content??[],je.delta,{lastSeq:an.lastSeq,lastText:an.lastText},ct??null);return he?(q.current={...an,lastSeq:te.lastSeq??an.lastSeq,lastText:te.lastText??an.lastText},{...lt,content:A}):lt});const Xe=je.delta.filter(lt=>lt.type==="text").map(lt=>lt.text).join("");Xe&&e.autoAppendAssistant!==!1&&(At.push(Xe),yt())}else if(je.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(H=I==null?void 0:I.onHeartbeat)==null||H.call(I,je)}catch(Xe){console.warn("[use-chat] heartbeat callback failed",Xe)}}else if(mt!==null&&cancelAnimationFrame(mt),Et(),je.type==="checkpoint")v(je.checkpointId);else if(je.type==="error"){const Xe=je;if(d(Xe.message),J="error",P=Xe.message,Xe.error_type==="auth_error"||Xe.code==="TOKEN_EXPIRED"||((ae=Xe.message)==null?void 0:ae.includes("token"))||((ie=Xe.message)==null?void 0:ie.includes("401"))||((ge=Xe.message)==null?void 0:ge.includes("unauthorized"))||((ye=Xe.message)==null?void 0:ye.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Xe.message);try{(Te=I==null?void 0:I.onAuthError)==null||Te.call(I,Xe.message)}catch(an){console.warn("[use-chat] onAuthError handler failed",an)}K.abort()}}}}Et(),J===null&&!K.signal.aborted&&(J="complete")}catch(Pe){if(Pe.name==="AbortError")J=J??"aborted";else{const We=Pe.message||String(Pe);J="error",P=We,d(We),(Ae=I==null?void 0:I.onError)==null||Ae.call(I,We)}}finally{try{await dt.cancel()}catch{}finally{(ke=dt.releaseLock)==null||ke.call(dt)}mt!==null&&typeof window<"u"&&window.cancelAnimationFrame(mt),clearInterval(qt)}}catch(Ve){if(Ve.name==="AbortError")J=J??"aborted";else{const ze=Ve.message||String(Ve);J="error",P=ze,d(ze),(st=I==null?void 0:I.onError)==null||st.call(I,ze),_||((vt=I==null?void 0:I.onConnectionError)==null||vt.call(I,ze),_=!0)}}finally{const Ve=E.current,ze=R.current,Ke=O.current,Oe=L.current,Ue=J??(K.signal.aborted?"aborted":P?"error":"complete");try{(kt=I==null?void 0:I.onClosed)==null||kt.call(I,{reason:Ue,lastSeq:Ve,lastCheckpointId:ze,lastCheckpointNs:Ke,lastStateHistory:Oe,error:P})}catch(dt){console.warn("[use-chat] onClosed callback failed",dt)}l(!1),w(!1),C.current=null,E.current=0,x(0),N.current=null}})(),{close:()=>K.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var B;T.current=!1,(B=C.current)==null||B.abort()},[]),{isStreaming:a,error:c,assistantText:h,assistantMessage:S,lastCheckpointId:f,lastSeq:g,connected:y,stream:G,stop:X,clear:j,setToken:W}}const Gv=["detail","message","error","description","title"];function Go(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Go(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of Gv){const r=Go(t[n]);if(r)return r}if("errors"in t){const n=Go(t.errors);if(n)return n}}return null}function Yv(e){if(!e)return"Request failed";const t=e.response,n=Go(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function du({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=b.useState([]),[a,l]=b.useState(t),[c,d]=b.useState(!1),[h,m]=b.useState(null),[f,v]=b.useState([]),[g,x]=b.useState(!1),[,y]=b.useState(null),[w,S]=b.useState(null),[k,C]=b.useState(!1),T=b.useRef(a),E=b.useRef(new Map);b.useEffect(()=>{T.current=a},[a]);const N=b.useCallback(async()=>{d(!0),m(null);try{const M=await e.listThreads();i(M??[])}catch(M){const I=String(M);m(I),n==null||n(I)}finally{d(!1)}},[e,n]),R=b.useCallback(async()=>{x(!0),y(null);try{const M=await e.listSharedThreads();v(M??[])}catch(M){const I=String(M);y(I),n==null||n(I)}finally{x(!1)}},[e,n]);b.useEffect(()=>{N()},[N]),b.useEffect(()=>{R()},[R]),b.useEffect(()=>{r==null||r(a)},[a,r]);const O=b.useCallback(async M=>{try{const I=await e.createThread(M);return l(I.threadId),await N(),I.threadId}catch(I){const K=String(I);return n==null||n(K),null}},[e,n,N]),L=b.useCallback(async M=>{const I=s;i(J=>J.filter(P=>P.threadId!==M));const K=new AbortController;E.current.set(M,K);try{await e.deleteThread(M),T.current===M&&(l(null),o==null||o())}catch(J){i(I);const P=String(J);n==null||n(P)}finally{E.current.delete(M)}},[e,o,n,s]),q=b.useCallback(async(M,I)=>{try{await e.updateThread(M,I),await N()}catch(K){n==null||n(String(K))}},[e,n,N]),W=b.useCallback(async(M,I)=>{C(!0),S("Sharing thread…");try{await e.shareThread(M,I),await R(),S("Shared successfully")}catch(K){const J=Yv(K);throw n==null||n(J),S(`Failed to share: ${J}`),new Error(J)}finally{C(!1)}},[e,n,R]),j=b.useCallback(async(M,I)=>{try{await e.unshareThread(M,I),await R()}catch(K){const J=String(K);throw n==null||n(J),K}},[e,n,R]),X=b.useMemo(()=>({createThread:O,deleteThread:L,renameThread:q,refreshThreads:N,refreshSharedThreads:R,shareThread:W,unshareThread:j}),[O,L,q,N,R,W,j]),G=b.useCallback(M=>{if(!(M!=null&&M.threadId))return;const I={threadId:M.threadId,title:M.title||`Thread ${M.threadId.slice(0,8)}`,createdAt:M.createdAt||new Date().toISOString(),updatedAt:M.updatedAt||new Date().toISOString(),messageCount:M.messageCount??1};i(K=>{let J=!1;const P=K.map(_=>_.threadId===I.threadId?(J=!0,console.debug("[useThreadsState] thread_info: updating existing thread",I.threadId),{..._,title:I.title??_.title,updatedAt:I.updatedAt??_.updatedAt,messageCount:I.messageCount??_.messageCount}):_);return J?P:(console.debug("[useThreadsState] thread_info: adding thread to list",I.threadId),[I,...K])})},[]),B=b.useCallback(()=>S(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:T,setCurrentThreadId:l,isLoadingThreads:c,threadsError:h,sharedThreads:f,isLoadingSharedThreads:g,actions:X,addThreadFromEvent:G,shareInFlight:k,shareStatus:w,clearShareStatus:B}}const fu=b.createContext(null);function hu({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{api:o}=Xr(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoadingThreads:c,threadsError:d,sharedThreads:h,isLoadingSharedThreads:m,actions:f,addThreadFromEvent:v,shareInFlight:g,shareStatus:x,clearShareStatus:y}=du({api:o,initialThreadId:t,onError:n,onThreadChange:r}),w=b.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoading:c,error:d,sharedThreads:h,isLoadingSharedThreads:m,actions:f,shareInFlight:g,shareStatus:x,clearShareStatus:y,addThreadFromEvent:v}),[s,i,a,l,c,d,h,m,f,g,x,y,v]);return u.jsx(fu.Provider,{value:w,children:e})}function xr(){const e=b.useContext(fu);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function Mi(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function pu(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Zr(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Zr).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(pu(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=Zr(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function vr(e){if(typeof e=="string")return e;if(pu(e))return"";try{const t=Zr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Xv(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function Jv(e){const t=vr(e);return typeof e=="string"&&Xv(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Qr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Mi(t);if(n!==null)return Qr(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Qr(e.content):e}function Zv(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Oi(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Yo(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Qv(e){const t=r=>{try{const o=Zr(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
|
|
39
|
+
`)):t(e)}function eb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function mu(e){if(e.role==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(i=>{switch(i.type){case"text":return`t:${i.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"",r="checkpointId"in e&&e.checkpointId?`cp:${e.checkpointId}`:"",o="checkpointNs"in e&&e.checkpointNs?`ns:${e.checkpointNs}`:"",s=[r,o].filter(Boolean).join("|");return`${e.id}:${t}:${n}${s?`:${s}`:""}`}function tb(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function nb(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function rb({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=tb(n),i=o?`data:${s};base64,${e}`:t,a=nb(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function ob(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return rb({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function gu(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const sb={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null};function ib(e,t){var n;switch(t.type){case"reset":return{messages:Ri(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,pendingInterrupt:null,messagesStreamMeta:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r]}}}return{...e,messages:[...e.messages,r]}}case"seed":{const r=Ri(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Ri(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(a=>a.id)),s=r.filter(a=>!o.has(a.id));if(!s.length)return e;const i=[...s,...e.messages];return{...e,messages:i}}case"event":return xu(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>xu(o,s),e):e}default:return e}}function ab(e=[]){const[t,n]=b.useReducer(ib,{...sb,messages:e}),r=b.useRef([]),o=b.useRef(null),s=b.useRef(null),i=b.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=b.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=b.useCallback(d=>{r.current.push(d),a()},[a]);b.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=b.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,h)=>n({type:"seed",payload:{messages:d,...h??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:(d,h)=>n({type:"user_message",payload:{message:d,editingMessageId:h}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function xu(e,t){var n,r,o;if(t.type==="message.start"&&t.role==="assistant"){const s=t.id,i=uu(t.model);if(e.messages.some(c=>c.id===s)){const c=e.messagesStreamMeta??{},d={...c,[s]:c[s]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:s,messagesStreamMeta:d}}const l={id:s,role:"assistant",name:i||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,l]}}if(t.type==="tool.start")return cb(e,t);if(t.type==="tool.progress")return ub(e,t);if(t.type==="tool.end")return db(e,t);if(t.type==="message.delta"){const s=e.assemblingId??iu(e.messages);if(!s)return e;const i=e.messages,a=i.findIndex(C=>C.id===s&&C.role==="assistant");if(a===-1)return e;const l=i[a],c=e.messagesStreamMeta,d=c??{},h=d[s],m=h??{lastSeq:null,lastText:au(l.content)},f=t.seq??null;if(f!==null&&typeof f=="number"&&typeof m.lastSeq=="number"&&f<=m.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:f,lastSeq:m.lastSeq}),e;const{newParts:v,newMeta:g,changed:x}=lu(l.content,t.delta,m,f);if(!x)return e;const y={...l,content:v},w=Jr(i,a,y),S=!h||h.lastSeq!==g.lastSeq||h.lastText!==g.lastText,k=S?{...d,[s]:g}:c;return S?{...e,messages:w,messagesStreamMeta:k}:{...e,messages:w}}if(t.type==="message.end"){const s=e.assemblingId??iu(e.messages);if(!s)return{...e,assemblingId:null};const i=e.messages,a=i.findIndex(l=>l.id===s&&l.role==="assistant");if(a>=0){const l=i[a];if(!((n=l.content)==null?void 0:n.some(d=>{var h;return(d==null?void 0:d.type)==="text"&&((h=d.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:l.id,contentTypes:(r=l.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=l.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const d=[...i.slice(0,a),...i.slice(a+1)];return{...e,assemblingId:null,messages:d}}}return e}if(t.type==="checkpoint"){const s=t.checkpointNs??e.lastCheckpointNs??null,i=Kv(e.messages,t.checkpointId,s);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:s,messages:i}}if(t.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}if(t.type==="state_history"){const s=Mn(t),i=s.interrupt,a=s.latest,l=i===null?Wv(e.messages):e.messages;return{...e,messages:l,pendingInterrupt:i,lastCheckpointId:(a==null?void 0:a.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(a==null?void 0:a.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function Di(e){return e.call_id??e.id??null}function vu(e){return e.id??e.call_id??`tool-${Date.now()}-${Math.random().toString(16).slice(2)}`}function bu(e,t,n,r){const o=t??`call-${Date.now()}-${Math.random().toString(16).slice(2)}`;return{id:e,role:"tool",name:n??void 0,content:[{type:"tool_call",id:o,name:n??"tool",args:r??{}}],createdAt:new Date().toISOString(),additionalKwargs:{toolCallId:o,toolName:n??void 0,toolStreaming:!0,toolProgress:[]}}}function Li(e,t){if(!t)return-1;for(let n=0;n<e.length;n+=1){const r=e[n];if(r.role!=="tool")continue;const o=r.additionalKwargs??{};if(typeof o.toolCallId=="string"&&o.toolCallId===t||Oi(r).toolCallId===t)return n}return-1}function lb(e){if(e==null)return[];const t=Qr(e);if(typeof t=="string"&&t.trim())return[{type:"text",text:t}];const n=vr(t??e);return n?[{type:"text",text:n}]:[]}function wu(e,t){const n=e.additionalKwargs??{},r=Array.isArray(n.toolProgress)?[...n.toolProgress]:[],o={...n,toolProgress:[...r,t]};return{...e,additionalKwargs:o}}function cb(e,t){const n=Di(t),r=Li(e.messages,n),o=t.name??t.tool??void 0,s=vu(t);if(r>=0){const a=e.messages[r],c={...a.additionalKwargs??{},toolStreaming:!0,toolProgress:[]},d={...a,name:o??a.name,additionalKwargs:c};return{...e,messages:Jr(e.messages,r,d)}}const i=bu(s,n,o,t.args);return{...e,messages:[...e.messages,i]}}function ub(e,t){const n=Di(t);if(!n)return e;const r=Li(e.messages,n);if(r===-1)return e;const o={type:t.type,content:typeof t.content=="string"?t.content:void 0,seq:t.seq??null,timestamp:new Date().toISOString()},s=t.metadata;s&&(o.metadata=s);const i=t.idx;typeof i=="number"&&(o.idx=i);const a=wu(e.messages[r],o);return{...e,messages:Jr(e.messages,r,a)}}function db(e,t){const n=Di(t),r=vu(t);let o=e.messages,s=Li(o,n);if(s===-1){const v=t.name??t.tool??void 0;o=[...o,bu(r,n,v,{})],s=o.length-1}const i=o[s],a=t.output??t.error??null,l=lb(a),c=[...i.content,...l],d={type:t.type,content:typeof t.output=="string"?t.output:void 0,seq:t.seq??null,timestamp:new Date().toISOString()};t.artifact&&(d.artifact=t.artifact);const h=wu(i,d),m=t.artifact??i.artifact,f={...h,name:t.name??t.tool??i.name,content:c,artifact:m,additionalKwargs:{...h.additionalKwargs??{},toolStreaming:!1}};return{...e,messages:Jr(o,s,f)}}function yu({api:e,seed:t,prepend:n,onError:r,currentThreadId:o,initialThreadId:s=null,initialCheckpointId:i=null,initialCheckpointNs:a=null,autoLoadInitial:l=!0,isStreaming:c,getMessages:d}){const[h,m]=b.useState(null),v=b.useMemo(()=>Mn(h),[h]).checkpoints,g=nc(v),x=g.timeline,[y,w]=b.useState(!1),[S,k]=b.useState(null),[C,T]=b.useState(!1),[E,N]=b.useState(!1),[R,O]=b.useState(!1),[L,q]=b.useState(null),W=b.useRef(o),j=b.useRef(null),X=b.useRef(null),G=b.useRef(null),B=b.useRef(null),M=b.useRef(null),I=b.useRef(new Map);b.useEffect(()=>{W.current=o},[o]);const K=b.useCallback(async Q=>{var ae,ie;if(!Q.threadId)return;const H=Q.threadId;(ae=Q.onStart)==null||ae.call(Q),Q.setLoading(!0);try{await Q.action(H)}catch(ge){if(W.current===H){const ye=String(ge);(ie=Q.handleError)==null||ie.call(Q,ye),r==null||r(ye)}throw ge}finally{Q.setLoading(!1)}},[r]),J=b.useCallback(async(Q,H)=>{if(!Q)return;const ae=`${Q}:${H??"latest"}`,ie=I.current.get(ae);if(ie)return ie;const ge=K({threadId:Q,setLoading:T,onStart:()=>q(null),handleError:ye=>q(ye),action:async ye=>{const Te=await e.getStateHistory({threadId:ye,checkpointId:H??void 0});if(W.current!==ye){console.log(`[useThreadHistoryState] Thread changed during load (was ${ye}, now ${W.current}), discarding stale data`);return}const{checkpoints:Ae}=Mn(Te),ke=Ae.find(st=>st.messages&&st.messages.length>0)??(H?Ae.find(st=>st.checkpointId===H):null)??Ae[0];t((ke==null?void 0:ke.messages)??[],{checkpointId:(ke==null?void 0:ke.checkpointId)??null,checkpointNs:(ke==null?void 0:ke.checkpointNs)??null}),m(Te),w(!!(ke!=null&&ke.nextCursor)),k((ke==null?void 0:ke.nextCursor)??null)}});I.current.set(ae,ge);try{await ge}finally{I.current.delete(ae)}return W.current===Q&&(M.current=ae),ge},[e,t,K]),P=b.useCallback(async(Q,H)=>{B.current=Q;try{await J(Q,H)}finally{B.current===Q&&(B.current=null)}},[J]),_=b.useCallback(Q=>{X.current=Q},[]),z=b.useCallback(Q=>{G.current=Q},[]),F=b.useCallback(Q=>{const H=Q.threadId??W.current;if(!H||W.current&&W.current!==H)return;const{checkpoints:ae}=Mn(Q);if(!ae.length)return;const ie=ae.find(ye=>ye.messages&&ye.messages.length>0)??ae.find(ye=>!!ye.checkpointId)??ae[0],ge=G.current===H;!c&&!ge&&t((ie==null?void 0:ie.messages)??[],{checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}),m(Q),w(!!(ie!=null&&ie.nextCursor)),k((ie==null?void 0:ie.nextCursor)??null),M.current=`${H}:latest`,X.current=null,G.current===H&&(G.current=null)},[t,c]),re=b.useCallback(async(Q,H)=>{const ae=W.current;await K({threadId:ae,setLoading:O,action:async ie=>{const ge=await e.getStateHistory({threadId:ie,checkpointId:Q,checkpointNs:H??void 0});if(W.current!==ie){console.log(`[useThreadHistoryState] Thread changed during checkpoint navigation (was ${ie}, now ${W.current}), discarding stale data`);return}const{checkpoints:ye}=Mn(ge),Te=ye.find(Ae=>Ae.checkpointId===Q&&(H?Ae.checkpointNs===H:!0));if(!Te){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:Q,checkpointNs:H});return}m(ge),t(Te.messages??[],{checkpointId:Te.checkpointId??null,checkpointNs:Te.checkpointNs??null})}}).catch(()=>{})},[e,t,K]),V=b.useCallback((Q,H)=>{t(d(),{checkpointId:Q??null,checkpointNs:H??null})},[d,t]),D=b.useCallback(async()=>{W.current&&await P(W.current)},[P]),Z=b.useCallback(async()=>{const Q=W.current;!Q||!S||await K({threadId:Q,setLoading:N,action:async H=>{const ae=await e.getStateHistory({threadId:H,checkpointId:S});if(W.current!==H)return;const{checkpoints:ie}=Mn(ae);if(ie.length>0){const ge=ie[ie.length-1];n((ge==null?void 0:ge.messages)??[]),w(!!(ge!=null&&ge.nextCursor)),k((ge==null?void 0:ge.nextCursor)??null)}}}).catch(()=>{})},[e,S,r,n,K]);b.useEffect(()=>{if(!l||!o||C||c)return;if(X.current===o){X.current=null,j.current=o;return}if(G.current===o){j.current=o;return}if(B.current===o){B.current=null,j.current=o;return}if(j.current===o)return;j.current=o;let Q;console.log("[useThreadHistoryState] Loading thread with latest checkpoint");const H=`${o}:latest`;M.current!==H&&P(o,Q)},[l,o,i,a,s,C,c,P]);const ee=b.useCallback(()=>{m(null),w(!1),k(null),T(!1),N(!1),O(!1),q(null),X.current=null,G.current=null,j.current=null,M.current=null,B.current=null},[]);return{threadCheckpoints:v,threadTimeline:x,checkpointIndex:g,isLoadingThread:C,isHistoryLoading:E,isLoadingCheckpoint:R,threadStateError:L,hasMoreHistory:y,loadThread:P,navigateToCheckpoint:re,loadOlderMessages:Z,setCurrentCheckpointId:V,returnToLatest:D,handleStateHistoryEvent:F,markSkipNextLoad:_,markStreamPendingThread:z,resetHistoryState:ee}}const Su=b.createContext(null),Cu=b.createContext(null);function eo(){const e=b.useContext(Su);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function Tu(){const e=b.useContext(Cu);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function ku({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,isStreaming:s,onError:i}){const{api:a}=Xr(),{currentThreadId:l}=xr(),{state:c,seed:d,prepend:h,pushUser:m,onEvent:f}=ab(),{threadCheckpoints:v,threadTimeline:g,checkpointIndex:x,isLoadingThread:y,isHistoryLoading:w,isLoadingCheckpoint:S,threadStateError:k,hasMoreHistory:C,loadThread:T,navigateToCheckpoint:E,loadOlderMessages:N,setCurrentCheckpointId:R,returnToLatest:O,handleStateHistoryEvent:L,markSkipNextLoad:q,markStreamPendingThread:W,resetHistoryState:j}=yu({api:a,seed:d,prepend:h,onError:i,currentThreadId:l,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:s,getMessages:b.useCallback(()=>c.messages,[c.messages])}),[X,G]=b.useState(()=>async()=>{throw new Error("clearThread is not ready")}),[B,M]=b.useState(()=>async()=>{throw new Error("respondToInterrupt is not ready")});b.useEffect(()=>{l||(d([],{}),j())},[l,d,j]);const I=b.useCallback(z=>G(()=>z),[]),K=b.useCallback(z=>M(()=>z),[]),J=b.useMemo(()=>({assemblingMessageId:c.assemblingId??null}),[c.assemblingId]),P=b.useMemo(()=>({threadId:l,messages:c.messages,interrupt:c.pendingInterrupt,checkpoint:{id:c.lastCheckpointId??null,namespace:c.lastCheckpointNs??null},checkpoints:v,checkpointIndex:x,timelineCheckpoints:g,metadata:J,isLoading:y,isHistoryLoading:w,isLoadingCheckpoint:S,error:k,hasMore:C,loadOlder:N,clearState:X,navigateToCheckpoint:E,setCurrentCheckpointId:R,returnToLatest:O,loadThread:T,clearThread:X,respondToInterrupt:B,messagePreviews:x.messagePreviews,handleStateHistoryEvent:L,markSkipNextLoad:q,markStreamPendingThread:W,resetHistoryState:j,pushUser:m,onEvent:f}),[l,c,v,g,x,J,y,w,S,k,C,N,X,E,R,O,T,B,x.messagePreviews,L,q,W,j,m,f]),_=b.useMemo(()=>({registerClearThread:I,registerRespondToInterrupt:K}),[I,K]);return u.jsx(Cu.Provider,{value:_,children:u.jsx(Su.Provider,{value:P,children:e})})}function Eu(e,t){if(!e)return null;const n=Pn(e);if(!n)return null;const r=Pn(n.configurable)??n;return Rn(r,t)??null}function fb(e){const t=Eu(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=Eu(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function hb(e,t){const n=typeof e.step=="number"?e.step:Number.POSITIVE_INFINITY,r=typeof t.step=="number"?t.step:Number.POSITIVE_INFINITY;if(n!==r)return n-r;const o=e.createdAt?Date.parse(e.createdAt):0,s=t.createdAt?Date.parse(t.createdAt):0;return o-s}function pb(e,t){const n=[...e].sort(hb);for(const r of n){if(r.messageId!==t)continue;const o=fb(r.parentConfig);if(!o)throw new Error(`Parent checkpoint info missing for message ${t}`);return o}throw new Error(`Message ${t} not found in timeline`)}const Iu=b.createContext(null),Nu=b.createContext(!1);function mb({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l,onToolEnd:c}){const{api:d,baseUrl:h}=Xr(),m=b.useMemo(()=>vn(h),[h]),{stream:f,stop:v,isStreaming:g,error:x,setToken:y}=qv({baseUrl:m}),[w,S]=b.useState(!1);return b.useEffect(()=>{S(g)},[g]),u.jsx(hu,{initialThreadId:t,onError:s,onThreadChange:a,children:u.jsx(ku,{initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,onError:s,isStreaming:w,children:u.jsx(Nu.Provider,{value:!0,children:u.jsx(gb,{api:d,streamApi:{stream:f,stop:v,isStreaming:g,error:x,setToken:y},onError:s,onAuthError:i,onConnectionError:l,onToolEnd:c,children:e})})})})}function gb({children:e,api:t,streamApi:n,onError:r,onAuthError:o,onConnectionError:s,onToolEnd:i}){const{stream:a,stop:l,isStreaming:c,error:d,setToken:h}=n,{setCurrentThreadId:m,currentThreadIdRef:f,addThreadFromEvent:v}=xr(),{checkpoint:g,timelineCheckpoints:x,handleStateHistoryEvent:y,markSkipNextLoad:w,markStreamPendingThread:S,resetHistoryState:k,pushUser:C,onEvent:T}=eo(),{registerClearThread:E,registerRespondToInterrupt:N}=Tu(),R=b.useCallback(B=>{v(B),f.current!==B.threadId&&((B.created??!f.current)&&w(B.threadId),S(B.threadId),m(B.threadId))},[v,w,S,m,f]),O=b.useCallback(B=>{B.type==="thread_info"?R(B):B.type==="state_history"?y(B):B.type==="tool.end"?i==null||i(B):T(B)},[R,y,T,i]),L=b.useCallback(B=>{a(B,O,{onError:M=>{console.error("[StreamingProvider] Stream error:",M),r==null||r(M)},onAuthError:M=>{console.error("[StreamingProvider] Auth error:",M),o==null||o(M)},onConnectionError:M=>{console.error("[StreamingProvider] Connection error:",M),s==null||s(M)}})},[a,O,r,o,s]),q=b.useRef(g);b.useEffect(()=>{q.current=g},[g]);const W=b.useCallback(async(B,M,I)=>{const K=f.current;if(!K)throw new Error("No active thread to handle interrupt");const J=M?I??!0:!1,P=q.current,_={threadId:K,checkpointId:P.id??void 0,checkpointNs:P.namespace??void 0,command:{kind:"resume",value:J}};L(_)},[f,L]);b.useEffect(()=>{N(W)},[W,N]);const j=b.useCallback(async()=>{l(),k(),m(null);try{await t.getAgent("default")}catch(B){console.warn("[StreamingProvider] Failed to refetch agent after clearing thread:",B)}},[t,k,m,l]);b.useEffect(()=>{E(j)},[j,E]);const X=b.useCallback(async(B,M)=>{let I=f.current;const K=(B==null?void 0:B.text)??"",J=(B==null?void 0:B.attachments)??[],P=(K==null?void 0:K.trim())??"",_={...(B==null?void 0:B.payload)??{}},z=Array.isArray(_.messages)?_.messages:void 0;z&&delete _.messages;const F=!!(z&&z.length);if(!I&&!P&&J.length===0&&!F)return;if(!I){const Ae=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ke=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);I=`${Ae}${ke}`,w(I),m(I)}const{contentParts:re,filesInfo:V}=await ou(J),D=[...re];P&&D.push({type:"text",text:K});const Z=M==null?void 0:M.originalMessageId,ee=!!(M!=null&&M.edit&&Z),Q=!F&&D.length>0;let H=null;Q&&(H={id:ee?Z:`msg-${Date.now()}`,role:"user",content:D,createdAt:new Date().toISOString()},ee?C(H,Z):C(H));const ae=F?z:H?[H]:[],ie={..._,...V.length?{files_info:V}:{}};ae.length?ie.messages=ae:"messages"in ie||(ie.messages=[]);let ge=(M==null?void 0:M.checkpointId)??g.id??void 0,ye=(M==null?void 0:M.checkpointNs)??g.namespace??void 0;if(ee&&Z){const Ae=pb(x,Z);ge=Ae.checkpointId,ye=Ae.checkpointNs??void 0}const Te={threadId:I,payload:ie,checkpointId:ge,checkpointNs:ye,edit:!!(M!=null&&M.edit)};L(Te)},[g,f,w,C,L,x]),G=b.useMemo(()=>({isStreaming:c,error:d,connectionState:c?"connected":"idle",submit:X,send:X,stop:l,setAuthToken:h}),[c,d,X,l,h]);return u.jsx(Iu.Provider,{value:G,children:e})}function $i(){const e=b.useContext(Iu);if(!e)throw new Error("useStream must be used within StreamingProvider");return e}function xb(){return b.useContext(Nu)}function Au(e){return typeof e=="object"&&e!==null}function vb(e,t){if(Object.is(e,t))return!0;if(!Au(e)||!Au(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function ju(e){const t=b.useRef(e),n=b.useRef(e);return vb(t.current,e)||(t.current=e,n.current=e),n.current}function br({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c,onToolEnd:d}){const h=ju(t),m=to(a),f=to(l),v=to(i),g=to(c),x=to(d),y=b.useMemo(()=>({initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:m,onAuthError:f,onConnectionError:v,onThreadChange:g,onToolEnd:x}),[n,r,o,s,m,f,v,g,x]);return u.jsx(nu,{apiConfig:h,children:u.jsx(mb,{...y,children:e})})}function to(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e},[e]),b.useCallback((...n)=>{const r=t.current;if(r)return r(...n)},[])}function wr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function bb(e){if(typeof e!="string")return;const t=e.trim();if(t)return vn(t)}function _u(){const e=[wr("__API_BASE_URL__"),wr("__CHAT_API_BASE_URL__"),wr("__CHAT_API_URL__")];for(const t of e){const n=bb(t);if(n)return n}}function Pu(){const e=[wr("__API_AUTH_TOKEN__"),wr("__CHAT_API_KEY__"),wr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Ru(...e){for(const t of e)if(typeof t=="string"&&t.trim())return vn(t);return vn()}function Mu(){const e={},t=_u(),n=Pu();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Ou(){const e=Mu(),t=Nn.getAuthToken(),n=_u();return{apiBaseUrl:Ru(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||Pu()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Fi="chat-settings";function Du(){try{const e=localStorage.getItem(Fi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Lu(e){try{const t={...e,apiBaseUrl:vn(e.apiBaseUrl)};localStorage.setItem(Fi,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function wb(){const e=Ou(),t=Du(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Ru(Nn.baseUrl,r,e.apiBaseUrl)}}function yb(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),Lu(e)}function oe(...e){return ox.twMerge(rx.clsx(e))}const Sb=zr.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ze=p.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Yt.Slot:"button";return u.jsx(i,{className:oe(Sb({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";function ce(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function $u(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function On(...e){return t=>{let n=!1;const r=e.map(o=>{const s=$u(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():$u(e[o],null)}}}}function Le(...e){return p.useCallback(On(...e),e)}function Cb(e,t){const n=p.createContext(t),r=s=>{const{children:i,...a}=s,l=p.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=p.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function cn(e,t=[]){let n=[];function r(s,i){const a=p.createContext(i),l=n.length;n=[...n,i];const c=h=>{var y;const{scope:m,children:f,...v}=h,g=((y=m==null?void 0:m[e])==null?void 0:y[l])||a,x=p.useMemo(()=>v,Object.values(v));return u.jsx(g.Provider,{value:x,children:f})};c.displayName=s+"Provider";function d(h,m){var g;const f=((g=m==null?void 0:m[e])==null?void 0:g[l])||a,v=p.useContext(f);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>p.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return p.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Tb(o,...t)]}function Tb(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(s)[`__scope${c}`];return{...a,...h}},{});return p.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},kb=p[" useInsertionEffect ".trim().toString()]||Tt;function Dn({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Eb({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=p.useRef(e!==void 0);p.useEffect(()=>{const h=d.current;h!==a&&console.warn(`${r} is changing from ${h?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=p.useCallback(d=>{var h;if(a){const m=Ib(d)?d(e):d;m!==e&&((h=i.current)==null||h.call(i,m))}else s(d)},[a,e,s,i]);return[l,c]}function Eb({defaultProp:e,onChange:t}){const[n,r]=p.useState(e),o=p.useRef(n),s=p.useRef(t);return kb(()=>{s.current=t},[t]),p.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Ib(e){return typeof e=="function"}var Nb=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ve=Nb.reduce((e,t)=>{const n=Yt.createSlot(`Primitive.${t}`),r=p.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bi(e,t){e&&Hr.flushSync(()=>e.dispatchEvent(t))}function Xo(e){const t=e+"CollectionProvider",[n,r]=cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:x,children:y}=g,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:x,itemMap:S,collectionRef:w,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=Yt.createSlot(a),c=b.forwardRef((g,x)=>{const{scope:y,children:w}=g,S=s(a,y),k=Le(x,S.collectionRef);return u.jsx(l,{ref:k,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",h="data-radix-collection-item",m=Yt.createSlot(d),f=b.forwardRef((g,x)=>{const{scope:y,children:w,...S}=g,k=b.useRef(null),C=Le(x,k),T=s(d,y);return b.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(m,{[h]:"",ref:C,children:w})});f.displayName=d;function v(g){const x=s(e+"CollectionConsumer",g);return b.useCallback(()=>{const w=x.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${h}]`));return Array.from(x.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:c,ItemSlot:f},v,r]}var Ab=p.createContext(void 0);function Jo(e){const t=p.useContext(Ab);return e||t||"ltr"}function ht(e){const t=p.useRef(e);return p.useEffect(()=>{t.current=e}),p.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function jb(e,t=globalThis==null?void 0:globalThis.document){const n=ht(e);p.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var _b="DismissableLayer",zi="dismissableLayer.update",Pb="dismissableLayer.pointerDownOutside",Rb="dismissableLayer.focusOutside",Fu,Bu=p.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),yr=p.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=p.useContext(Bu),[d,h]=p.useState(null),m=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=p.useState({}),v=Le(t,E=>h(E)),g=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),w=d?g.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=w>=y,C=Ob(E=>{const N=E.target,R=[...c.branches].some(O=>O.contains(N));!k||R||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},m),T=Db(E=>{const N=E.target;[...c.branches].some(O=>O.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},m);return jb(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},m),p.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(Fu=m.body.style.pointerEvents,m.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),Hu(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(m.body.style.pointerEvents=Fu)}},[d,m,n,c]),p.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),Hu())},[d,c]),p.useEffect(()=>{const E=()=>f({});return document.addEventListener(zi,E),()=>document.removeEventListener(zi,E)},[]),u.jsx(ve.div,{...l,ref:v,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:ce(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ce(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ce(e.onPointerDownCapture,C.onPointerDownCapture)})});yr.displayName=_b;var Mb="DismissableLayerBranch",zu=p.forwardRef((e,t)=>{const n=p.useContext(Bu),r=p.useRef(null),o=Le(t,r);return p.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(ve.div,{...e,ref:o})});zu.displayName=Mb;function Ob(e,t=globalThis==null?void 0:globalThis.document){const n=ht(e),r=p.useRef(!1),o=p.useRef(()=>{});return p.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Uu(Pb,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Db(e,t=globalThis==null?void 0:globalThis.document){const n=ht(e),r=p.useRef(!1);return p.useEffect(()=>{const o=s=>{s.target&&!r.current&&Uu(Rb,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Hu(){const e=new CustomEvent(zi);document.dispatchEvent(e)}function Uu(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Bi(o,s):o.dispatchEvent(s)}var Lb=yr,$b=zu,Hi=0;function Ui(){p.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Wu()),document.body.insertAdjacentElement("beforeend",e[1]??Wu()),Hi++,()=>{Hi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Hi--}},[])}function Wu(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Wi="focusScope.autoFocusOnMount",Vi="focusScope.autoFocusOnUnmount",Vu={bubbles:!1,cancelable:!0},Fb="FocusScope",Zo=p.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=p.useState(null),c=ht(o),d=ht(s),h=p.useRef(null),m=Le(t,g=>l(g)),f=p.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;p.useEffect(()=>{if(r){let g=function(S){if(f.paused||!a)return;const k=S.target;a.contains(k)?h.current=k:Ln(h.current,{select:!0})},x=function(S){if(f.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||Ln(h.current,{select:!0}))},y=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Ln(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const w=new MutationObserver(y);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),w.disconnect()}}},[r,a,f.paused]),p.useEffect(()=>{if(a){Gu.add(f);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(Wi,Vu);a.addEventListener(Wi,c),a.dispatchEvent(y),y.defaultPrevented||(Bb(Vb(Ku(a)),{select:!0}),document.activeElement===g&&Ln(a))}return()=>{a.removeEventListener(Wi,c),setTimeout(()=>{const y=new CustomEvent(Vi,Vu);a.addEventListener(Vi,d),a.dispatchEvent(y),y.defaultPrevented||Ln(g??document.body,{select:!0}),a.removeEventListener(Vi,d),Gu.remove(f)},0)}}},[a,c,d,f]);const v=p.useCallback(g=>{if(!n&&!r||f.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const w=g.currentTarget,[S,k]=zb(w);S&&k?!g.shiftKey&&y===k?(g.preventDefault(),n&&Ln(S,{select:!0})):g.shiftKey&&y===S&&(g.preventDefault(),n&&Ln(k,{select:!0})):y===w&&g.preventDefault()}},[n,r,f.paused]);return u.jsx(ve.div,{tabIndex:-1,...i,ref:m,onKeyDown:v})});Zo.displayName=Fb;function Bb(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Ln(r,{select:t}),document.activeElement!==n)return}function zb(e){const t=Ku(e),n=qu(t,e),r=qu(t.reverse(),e);return[n,r]}function Ku(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function qu(e,t){for(const n of e)if(!Hb(n,{upTo:t}))return n}function Hb(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Ub(e){return e instanceof HTMLInputElement&&"select"in e}function Ln(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ub(e)&&t&&e.select()}}var Gu=Wb();function Wb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Yu(e,t),e.unshift(t)},remove(t){var n;e=Yu(e,t),(n=e[0])==null||n.resume()}}}function Yu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Vb(e){return e.filter(t=>t.tagName!=="A")}var Kb=p[" useId ".trim().toString()]||(()=>{}),qb=0;function Rt(e){const[t,n]=p.useState(Kb());return Tt(()=>{n(r=>r??String(qb++))},[e]),t?`radix-${t}`:""}const Gb=["top","right","bottom","left"],$n=Math.min,Zt=Math.max,Qo=Math.round,es=Math.floor,bn=e=>({x:e,y:e}),Yb={left:"right",right:"left",bottom:"top",top:"bottom"},Xb={start:"end",end:"start"};function Ki(e,t,n){return Zt(e,$n(t,n))}function An(e,t){return typeof e=="function"?e(t):e}function jn(e){return e.split("-")[0]}function Sr(e){return e.split("-")[1]}function qi(e){return e==="x"?"y":"x"}function Gi(e){return e==="y"?"height":"width"}const Jb=new Set(["top","bottom"]);function wn(e){return Jb.has(jn(e))?"y":"x"}function Yi(e){return qi(wn(e))}function Zb(e,t,n){n===void 0&&(n=!1);const r=Sr(e),o=Yi(e),s=Gi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ts(i)),[i,ts(i)]}function Qb(e){const t=ts(e);return[Xi(e),t,Xi(t)]}function Xi(e){return e.replace(/start|end/g,t=>Xb[t])}const Xu=["left","right"],Ju=["right","left"],ew=["top","bottom"],tw=["bottom","top"];function nw(e,t,n){switch(e){case"top":case"bottom":return n?t?Ju:Xu:t?Xu:Ju;case"left":case"right":return t?ew:tw;default:return[]}}function rw(e,t,n,r){const o=Sr(e);let s=nw(jn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Xi)))),s}function ts(e){return e.replace(/left|right|bottom|top/g,t=>Yb[t])}function ow(e){return{top:0,right:0,bottom:0,left:0,...e}}function Zu(e){return typeof e!="number"?ow(e):{top:e,right:e,bottom:e,left:e}}function ns(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Qu(e,t,n){let{reference:r,floating:o}=e;const s=wn(t),i=Yi(t),a=Gi(i),l=jn(t),c=s==="y",d=r.x+r.width/2-o.width/2,h=r.y+r.height/2-o.height/2,m=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:d,y:r.y-o.height};break;case"bottom":f={x:d,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:h};break;case"left":f={x:r.x-o.width,y:h};break;default:f={x:r.x,y:r.y}}switch(Sr(t)){case"start":f[i]-=m*(n&&c?-1:1);break;case"end":f[i]+=m*(n&&c?-1:1);break}return f}const sw=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:h}=Qu(c,r,l),m=r,f={},v=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:w,y:S,data:k,reset:C}=await y({x:d,y:h,initialPlacement:r,placement:m,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,h=S??h,f={...f,[x]:{...f[x],...k}},C&&v<=50&&(v++,typeof C=="object"&&(C.placement&&(m=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:h}=Qu(c,m,l)),g=-1)}return{x:d,y:h,placement:m,strategy:o,middlewareData:f}};async function no(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:m=!1,padding:f=0}=An(t,e),v=Zu(f),x=a[m?h==="floating"?"reference":"floating":h],y=ns(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=h==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=ns(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(y.top-C.top+v.top)/k.y,bottom:(C.bottom-y.bottom+v.bottom)/k.y,left:(y.left-C.left+v.left)/k.x,right:(C.right-y.right+v.right)/k.x}}const iw=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=An(e,t)||{};if(c==null)return{};const h=Zu(d),m={x:n,y:r},f=Yi(o),v=Gi(f),g=await i.getDimensions(c),x=f==="y",y=x?"top":"left",w=x?"bottom":"right",S=x?"clientHeight":"clientWidth",k=s.reference[v]+s.reference[f]-m[f]-s.floating[v],C=m[f]-s.reference[f],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[v]);const N=k/2-C/2,R=E/2-g[v]/2-1,O=$n(h[y],R),L=$n(h[w],R),q=O,W=E-g[v]-L,j=E/2-g[v]/2+N,X=Ki(q,j,W),G=!l.arrow&&Sr(o)!=null&&j!==X&&s.reference[v]/2-(j<q?O:L)-g[v]/2<0,B=G?j<q?j-q:j-W:0;return{[f]:m[f]+B,data:{[f]:X,centerOffset:j-X-B,...G&&{alignmentOffset:B}},reset:G}}}),aw=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:g=!0,...x}=An(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=jn(o),w=wn(a),S=jn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=m||(S||!g?[ts(a)]:Qb(a)),T=v!=="none";!m&&T&&C.push(...rw(a,g,v,k));const E=[a,...C],N=await no(t,x),R=[];let O=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(N[y]),h){const j=Zb(o,i,k);R.push(N[j[0]],N[j[1]])}if(O=[...O,{placement:o,overflows:R}],!R.every(j=>j<=0)){var L,q;const j=(((L=s.flip)==null?void 0:L.index)||0)+1,X=E[j];if(X&&(!(h==="alignment"?w!==wn(X):!1)||O.every(M=>wn(M.placement)===w?M.overflows[0]>0:!0)))return{data:{index:j,overflows:O},reset:{placement:X}};let G=(q=O.filter(B=>B.overflows[0]<=0).sort((B,M)=>B.overflows[1]-M.overflows[1])[0])==null?void 0:q.placement;if(!G)switch(f){case"bestFit":{var W;const B=(W=O.filter(M=>{if(T){const I=wn(M.placement);return I===w||I==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(I=>I>0).reduce((I,K)=>I+K,0)]).sort((M,I)=>M[1]-I[1])[0])==null?void 0:W[0];B&&(G=B);break}case"initialPlacement":G=a;break}if(o!==G)return{reset:{placement:G}}}return{}}}};function ed(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function td(e){return Gb.some(t=>e[t]>=0)}const lw=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=An(e,t);switch(r){case"referenceHidden":{const s=await no(t,{...o,elementContext:"reference"}),i=ed(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:td(i)}}}case"escaped":{const s=await no(t,{...o,altBoundary:!0}),i=ed(s,n.floating);return{data:{escapedOffsets:i,escaped:td(i)}}}default:return{}}}}},nd=new Set(["left","top"]);async function cw(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=jn(n),a=Sr(n),l=wn(n)==="y",c=nd.has(i)?-1:1,d=s&&l?-1:1,h=An(t,e);let{mainAxis:m,crossAxis:f,alignmentAxis:v}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof v=="number"&&(f=a==="end"?v*-1:v),l?{x:f*d,y:m*c}:{x:m*c,y:f*d}}const uw=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await cw(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},dw=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:x=>{let{x:y,y:w}=x;return{x:y,y:w}}},...l}=An(e,t),c={x:n,y:r},d=await no(t,l),h=wn(jn(o)),m=qi(h);let f=c[m],v=c[h];if(s){const x=m==="y"?"top":"left",y=m==="y"?"bottom":"right",w=f+d[x],S=f-d[y];f=Ki(w,f,S)}if(i){const x=h==="y"?"top":"left",y=h==="y"?"bottom":"right",w=v+d[x],S=v-d[y];v=Ki(w,v,S)}const g=a.fn({...t,[m]:f,[h]:v});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[m]:s,[h]:i}}}}}},fw=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=An(e,t),d={x:n,y:r},h=wn(o),m=qi(h);let f=d[m],v=d[h];const g=An(a,t),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const S=m==="y"?"height":"width",k=s.reference[m]-s.floating[S]+x.mainAxis,C=s.reference[m]+s.reference[S]-x.mainAxis;f<k?f=k:f>C&&(f=C)}if(c){var y,w;const S=m==="y"?"width":"height",k=nd.has(jn(o)),C=s.reference[h]-s.floating[S]+(k&&((y=i.offset)==null?void 0:y[h])||0)+(k?0:x.crossAxis),T=s.reference[h]+s.reference[S]+(k?0:((w=i.offset)==null?void 0:w[h])||0)-(k?x.crossAxis:0);v<C?v=C:v>T&&(v=T)}return{[m]:f,[h]:v}}}},hw=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=An(e,t),d=await no(t,c),h=jn(o),m=Sr(o),f=wn(o)==="y",{width:v,height:g}=s.floating;let x,y;h==="top"||h==="bottom"?(x=h,y=m===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=h,x=m==="end"?"top":"bottom");const w=g-d.top-d.bottom,S=v-d.left-d.right,k=$n(g-d[x],w),C=$n(v-d[y],S),T=!t.middlewareData.shift;let E=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),T&&!m){const O=Zt(d.left,0),L=Zt(d.right,0),q=Zt(d.top,0),W=Zt(d.bottom,0);f?N=v-2*(O!==0||L!==0?O+L:Zt(d.left,d.right)):E=g-2*(q!==0||W!==0?q+W:Zt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const R=await i.getDimensions(a.floating);return v!==R.width||g!==R.height?{reset:{rects:!0}}:{}}}};function rs(){return typeof window<"u"}function Cr(e){return rd(e)?(e.nodeName||"").toLowerCase():"#document"}function Qt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function yn(e){var t;return(t=(rd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function rd(e){return rs()?e instanceof Node||e instanceof Qt(e).Node:!1}function un(e){return rs()?e instanceof Element||e instanceof Qt(e).Element:!1}function Sn(e){return rs()?e instanceof HTMLElement||e instanceof Qt(e).HTMLElement:!1}function od(e){return!rs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Qt(e).ShadowRoot}const pw=new Set(["inline","contents"]);function ro(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!pw.has(o)}const mw=new Set(["table","td","th"]);function gw(e){return mw.has(Cr(e))}const xw=[":popover-open",":modal"];function os(e){return xw.some(t=>{try{return e.matches(t)}catch{return!1}})}const vw=["transform","translate","scale","rotate","perspective"],bw=["transform","translate","scale","rotate","perspective","filter"],ww=["paint","layout","strict","content"];function Ji(e){const t=Zi(),n=un(e)?dn(e):e;return vw.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||bw.some(r=>(n.willChange||"").includes(r))||ww.some(r=>(n.contain||"").includes(r))}function yw(e){let t=Fn(e);for(;Sn(t)&&!Tr(t);){if(Ji(t))return t;if(os(t))return null;t=Fn(t)}return null}function Zi(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Sw=new Set(["html","body","#document"]);function Tr(e){return Sw.has(Cr(e))}function dn(e){return Qt(e).getComputedStyle(e)}function ss(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Fn(e){if(Cr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||od(e)&&e.host||yn(e);return od(t)?t.host:t}function sd(e){const t=Fn(e);return Tr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Sn(t)&&ro(t)?t:sd(t)}function oo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=sd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Qt(o);if(s){const a=Qi(i);return t.concat(i,i.visualViewport||[],ro(o)?o:[],a&&n?oo(a):[])}return t.concat(o,oo(o,[],n))}function Qi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function id(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Qo(n)!==s||Qo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ea(e){return un(e)?e:e.contextElement}function kr(e){const t=ea(e);if(!Sn(t))return bn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=id(t);let i=(s?Qo(n.width):n.width)/r,a=(s?Qo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Cw=bn(0);function ad(e){const t=Qt(e);return!Zi()||!t.visualViewport?Cw:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Tw(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Qt(e)?!1:t}function er(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ea(e);let i=bn(1);t&&(r?un(r)&&(i=kr(r)):i=kr(e));const a=Tw(s,n,r)?ad(s):bn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,h=o.height/i.y;if(s){const m=Qt(s),f=r&&un(r)?Qt(r):r;let v=m,g=Qi(v);for(;g&&r&&f!==v;){const x=kr(g),y=g.getBoundingClientRect(),w=dn(g),S=y.left+(g.clientLeft+parseFloat(w.paddingLeft))*x.x,k=y.top+(g.clientTop+parseFloat(w.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,h*=x.y,l+=S,c+=k,v=Qt(g),g=Qi(v)}}return ns({width:d,height:h,x:l,y:c})}function is(e,t){const n=ss(e).scrollLeft;return t?t.left+n:er(yn(e)).left+n}function ld(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-is(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function kw(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=yn(r),a=t?os(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=bn(1);const d=bn(0),h=Sn(r);if((h||!h&&!s)&&((Cr(r)!=="body"||ro(i))&&(l=ss(r)),Sn(r))){const f=er(r);c=kr(r),d.x=f.x+r.clientLeft,d.y=f.y+r.clientTop}const m=i&&!h&&!s?ld(i,l):bn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+m.x,y:n.y*c.y-l.scrollTop*c.y+d.y+m.y}}function Ew(e){return Array.from(e.getClientRects())}function Iw(e){const t=yn(e),n=ss(e),r=e.ownerDocument.body,o=Zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+is(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const cd=25;function Nw(e,t){const n=Qt(e),r=yn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Zi();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=is(r);if(c<=0){const d=r.ownerDocument,h=d.body,m=getComputedStyle(h),f=d.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,v=Math.abs(r.clientWidth-h.clientWidth-f);v<=cd&&(s-=v)}else c<=cd&&(s+=c);return{width:s,height:i,x:a,y:l}}const Aw=new Set(["absolute","fixed"]);function jw(e,t){const n=er(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Sn(e)?kr(e):bn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function ud(e,t,n){let r;if(t==="viewport")r=Nw(e,n);else if(t==="document")r=Iw(yn(e));else if(un(t))r=jw(t,n);else{const o=ad(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ns(r)}function dd(e,t){const n=Fn(e);return n===t||!un(n)||Tr(n)?!1:dn(n).position==="fixed"||dd(n,t)}function _w(e,t){const n=t.get(e);if(n)return n;let r=oo(e,[],!1).filter(a=>un(a)&&Cr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Fn(e):e;for(;un(i)&&!Tr(i);){const a=dn(i),l=Ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&Aw.has(o.position)||ro(i)&&!l&&dd(e,i))?r=r.filter(d=>d!==i):o=a,i=Fn(i)}return t.set(e,r),r}function Pw(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?os(t)?[]:_w(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const h=ud(t,d,o);return c.top=Zt(h.top,c.top),c.right=$n(h.right,c.right),c.bottom=$n(h.bottom,c.bottom),c.left=Zt(h.left,c.left),c},ud(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Rw(e){const{width:t,height:n}=id(e);return{width:t,height:n}}function Mw(e,t,n){const r=Sn(t),o=yn(t),s=n==="fixed",i=er(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=bn(0);function c(){l.x=is(o)}if(r||!r&&!s)if((Cr(t)!=="body"||ro(o))&&(a=ss(t)),r){const f=er(t,!0,s,t);l.x=f.x+t.clientLeft,l.y=f.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?ld(o,a):bn(0),h=i.left+a.scrollLeft-l.x-d.x,m=i.top+a.scrollTop-l.y-d.y;return{x:h,y:m,width:i.width,height:i.height}}function ta(e){return dn(e).position==="static"}function fd(e,t){if(!Sn(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return yn(e)===n&&(n=n.ownerDocument.body),n}function hd(e,t){const n=Qt(e);if(os(e))return n;if(!Sn(e)){let o=Fn(e);for(;o&&!Tr(o);){if(un(o)&&!ta(o))return o;o=Fn(o)}return n}let r=fd(e,t);for(;r&&gw(r)&&ta(r);)r=fd(r,t);return r&&Tr(r)&&ta(r)&&!Ji(r)?n:r||yw(e)||n}const Ow=async function(e){const t=this.getOffsetParent||hd,n=this.getDimensions,r=await n(e.floating);return{reference:Mw(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Dw(e){return dn(e).direction==="rtl"}const Lw={convertOffsetParentRelativeRectToViewportRelativeRect:kw,getDocumentElement:yn,getClippingRect:Pw,getOffsetParent:hd,getElementRects:Ow,getClientRects:Ew,getDimensions:Rw,getScale:kr,isElement:un,isRTL:Dw};function pd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $w(e,t){let n=null,r;const o=yn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:h,width:m,height:f}=c;if(a||t(),!m||!f)return;const v=es(h),g=es(o.clientWidth-(d+m)),x=es(o.clientHeight-(h+f)),y=es(d),S={rootMargin:-v+"px "+-g+"px "+-x+"px "+-y+"px",threshold:Zt(0,$n(1,l))||1};let k=!0;function C(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!pd(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Fw(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=ea(e),d=o||s?[...c?oo(c):[],...oo(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const h=c&&a?$w(c,n):null;let m=-1,f=null;i&&(f=new ResizeObserver(y=>{let[w]=y;w&&w.target===c&&f&&(f.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var S;(S=f)==null||S.observe(t)})),n()}),c&&!l&&f.observe(c),f.observe(t));let v,g=l?er(e):null;l&&x();function x(){const y=er(e);g&&!pd(g,y)&&n(),g=y,v=requestAnimationFrame(x)}return n(),()=>{var y;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),h==null||h(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(v)}}const Bw=uw,zw=dw,Hw=aw,Uw=hw,Ww=lw,md=iw,Vw=fw,Kw=(e,t,n)=>{const r=new Map,o={platform:Lw,...n},s={...o.platform,_c:r};return sw(e,t,{...o,platform:s})};var qw=typeof document<"u",Gw=function(){},as=qw?b.useLayoutEffect:Gw;function ls(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!ls(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!ls(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function gd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xd(e,t){const n=gd(e);return Math.round(t*n)/n}function na(e){const t=p.useRef(e);return as(()=>{t.current=e}),t}function Yw(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,h]=p.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,f]=p.useState(r);ls(m,r)||f(r);const[v,g]=p.useState(null),[x,y]=p.useState(null),w=p.useCallback(M=>{M!==T.current&&(T.current=M,g(M))},[]),S=p.useCallback(M=>{M!==E.current&&(E.current=M,y(M))},[]),k=s||v,C=i||x,T=p.useRef(null),E=p.useRef(null),N=p.useRef(d),R=l!=null,O=na(l),L=na(o),q=na(c),W=p.useCallback(()=>{if(!T.current||!E.current)return;const M={placement:t,strategy:n,middleware:m};L.current&&(M.platform=L.current),Kw(T.current,E.current,M).then(I=>{const K={...I,isPositioned:q.current!==!1};j.current&&!ls(N.current,K)&&(N.current=K,Hr.flushSync(()=>{h(K)}))})},[m,t,n,L,q]);as(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,h(M=>({...M,isPositioned:!1})))},[c]);const j=p.useRef(!1);as(()=>(j.current=!0,()=>{j.current=!1}),[]),as(()=>{if(k&&(T.current=k),C&&(E.current=C),k&&C){if(O.current)return O.current(k,C,W);W()}},[k,C,W,O,R]);const X=p.useMemo(()=>({reference:T,floating:E,setReference:w,setFloating:S}),[w,S]),G=p.useMemo(()=>({reference:k,floating:C}),[k,C]),B=p.useMemo(()=>{const M={position:n,left:0,top:0};if(!G.floating)return M;const I=xd(G.floating,d.x),K=xd(G.floating,d.y);return a?{...M,transform:"translate("+I+"px, "+K+"px)",...gd(G.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:I,top:K}},[n,a,G.floating,d.x,d.y]);return p.useMemo(()=>({...d,update:W,refs:X,elements:G,floatingStyles:B}),[d,W,X,G,B])}const Xw=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?md({element:r.current,padding:o}).fn(n):{}:r?md({element:r,padding:o}).fn(n):{}}}},Jw=(e,t)=>({...Bw(e),options:[e,t]}),Zw=(e,t)=>({...zw(e),options:[e,t]}),Qw=(e,t)=>({...Vw(e),options:[e,t]}),ey=(e,t)=>({...Hw(e),options:[e,t]}),ty=(e,t)=>({...Uw(e),options:[e,t]}),ny=(e,t)=>({...Ww(e),options:[e,t]}),ry=(e,t)=>({...Xw(e),options:[e,t]});var oy="Arrow",vd=p.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(ve.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});vd.displayName=oy;var sy=vd;function bd(e){const[t,n]=p.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ra="Popper",[wd,Er]=cn(ra),[iy,yd]=wd(ra),Sd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=p.useState(null);return u.jsx(iy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Sd.displayName=ra;var Cd="PopperAnchor",Td=p.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=yd(Cd,n),i=p.useRef(null),a=Le(t,i),l=p.useRef(null);return p.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(ve.div,{...o,ref:a})});Td.displayName=Cd;var oa="PopperContent",[ay,ly]=wd(oa),kd=p.forwardRef((e,t)=>{var V,D,Z,ee,Q,H;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:h="partial",hideWhenDetached:m=!1,updatePositionStrategy:f="optimized",onPlaced:v,...g}=e,x=yd(oa,n),[y,w]=p.useState(null),S=Le(t,ae=>w(ae)),[k,C]=p.useState(null),T=bd(k),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),O=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],q=L.length>0,W={padding:O,boundary:L.filter(uy),altBoundary:q},{refs:j,floatingStyles:X,placement:G,isPositioned:B,middlewareData:M}=Yw({strategy:"fixed",placement:R,whileElementsMounted:(...ae)=>Fw(...ae,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[Jw({mainAxis:o+N,alignmentAxis:i}),l&&Zw({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Qw():void 0,...W}),l&&ey({...W}),ty({...W,apply:({elements:ae,rects:ie,availableWidth:ge,availableHeight:ye})=>{const{width:Te,height:Ae}=ie.reference,ke=ae.floating.style;ke.setProperty("--radix-popper-available-width",`${ge}px`),ke.setProperty("--radix-popper-available-height",`${ye}px`),ke.setProperty("--radix-popper-anchor-width",`${Te}px`),ke.setProperty("--radix-popper-anchor-height",`${Ae}px`)}}),k&&ry({element:k,padding:a}),dy({arrowWidth:E,arrowHeight:N}),m&&ny({strategy:"referenceHidden",...W})]}),[I,K]=Nd(G),J=ht(v);Tt(()=>{B&&(J==null||J())},[B,J]);const P=(V=M.arrow)==null?void 0:V.x,_=(D=M.arrow)==null?void 0:D.y,z=((Z=M.arrow)==null?void 0:Z.centerOffset)!==0,[F,re]=p.useState();return Tt(()=>{y&&re(window.getComputedStyle(y).zIndex)},[y]),u.jsx("div",{ref:j.setFloating,"data-radix-popper-content-wrapper":"",style:{...X,transform:B?X.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:F,"--radix-popper-transform-origin":[(ee=M.transformOrigin)==null?void 0:ee.x,(Q=M.transformOrigin)==null?void 0:Q.y].join(" "),...((H=M.hide)==null?void 0:H.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(ay,{scope:n,placedSide:I,onArrowChange:C,arrowX:P,arrowY:_,shouldHideArrow:z,children:u.jsx(ve.div,{"data-side":I,"data-align":K,...g,ref:S,style:{...g.style,animation:B?void 0:"none"}})})})});kd.displayName=oa;var Ed="PopperArrow",cy={top:"bottom",right:"left",bottom:"top",left:"right"},Id=p.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=ly(Ed,r),i=cy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(sy,{...o,ref:n,style:{...o.style,display:"block"}})})});Id.displayName=Ed;function uy(e){return e!==null}var dy=e=>({name:"transformOrigin",options:e,fn(t){var x,y,w;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=Nd(n),h={start:"0%",center:"50%",end:"100%"}[d],m=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let v="",g="";return c==="bottom"?(v=i?h:`${m}px`,g=`${-l}px`):c==="top"?(v=i?h:`${m}px`,g=`${r.floating.height+l}px`):c==="right"?(v=`${-l}px`,g=i?h:`${f}px`):c==="left"&&(v=`${r.floating.width+l}px`,g=i?h:`${f}px`),{data:{x:v,y:g}}}});function Nd(e){const[t,n="center"]=e.split("-");return[t,n]}var sa=Sd,ia=Td,aa=kd,la=Id,fy="Portal",so=p.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=p.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ro.createPortal(u.jsx(ve.div,{...r,ref:t}),i):null});so.displayName=fy;function hy(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var Ut=e=>{const{present:t,children:n}=e,r=py(t),o=typeof n=="function"?n({present:r.isPresent}):p.Children.only(n),s=Le(r.ref,my(o));return typeof n=="function"||r.isPresent?p.cloneElement(o,{ref:s}):null};Ut.displayName="Presence";function py(e){const[t,n]=p.useState(),r=p.useRef(null),o=p.useRef(e),s=p.useRef("none"),i=e?"mounted":"unmounted",[a,l]=hy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const c=cs(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const m=s.current,f=cs(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&m!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,h=f=>{const g=cs(r.current).includes(CSS.escape(f.animationName));if(f.target===t&&g&&(l("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},m=f=>{f.target===t&&(s.current=cs(r.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:p.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function cs(e){return(e==null?void 0:e.animationName)||"none"}function my(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var ca="rovingFocusGroup.onEntryFocus",gy={bubbles:!1,cancelable:!0},io="RovingFocusGroup",[ua,Ad,xy]=Xo(io),[vy,jd]=cn(io,[xy]),[by,wy]=vy(io),_d=p.forwardRef((e,t)=>u.jsx(ua.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ua.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(yy,{...e,ref:t})})}));_d.displayName=io;var yy=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...h}=e,m=p.useRef(null),f=Le(t,m),v=Jo(s),[g,x]=Dn({prop:i,defaultProp:a??null,onChange:l,caller:io}),[y,w]=p.useState(!1),S=ht(c),k=Ad(n),C=p.useRef(!1),[T,E]=p.useState(0);return p.useEffect(()=>{const N=m.current;if(N)return N.addEventListener(ca,S),()=>N.removeEventListener(ca,S)},[S]),u.jsx(by,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:g,onItemFocus:p.useCallback(N=>x(N),[x]),onItemShiftTab:p.useCallback(()=>w(!0),[]),onFocusableItemAdd:p.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:p.useCallback(()=>E(N=>N-1),[]),children:u.jsx(ve.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...e.style},onMouseDown:ce(e.onMouseDown,()=>{C.current=!0}),onFocus:ce(e.onFocus,N=>{const R=!C.current;if(N.target===N.currentTarget&&R&&!y){const O=new CustomEvent(ca,gy);if(N.currentTarget.dispatchEvent(O),!O.defaultPrevented){const L=k().filter(G=>G.focusable),q=L.find(G=>G.active),W=L.find(G=>G.id===g),X=[q,W,...L].filter(Boolean).map(G=>G.ref.current);Md(X,d)}}C.current=!1}),onBlur:ce(e.onBlur,()=>w(!1))})})}),Pd="RovingFocusGroupItem",Rd=p.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Rt(),c=s||l,d=wy(Pd,n),h=d.currentTabStopId===c,m=Ad(n),{onFocusableItemAdd:f,onFocusableItemRemove:v,currentTabStopId:g}=d;return p.useEffect(()=>{if(r)return f(),()=>v()},[r,f,v]),u.jsx(ua.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(ve.span,{tabIndex:h?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ce(e.onMouseDown,x=>{r?d.onItemFocus(c):x.preventDefault()}),onFocus:ce(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ce(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){d.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=Ty(x,d.orientation,d.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let S=m().filter(k=>k.focusable).map(k=>k.ref.current);if(y==="last")S.reverse();else if(y==="prev"||y==="next"){y==="prev"&&S.reverse();const k=S.indexOf(x.currentTarget);S=d.loop?ky(S,k+1):S.slice(k+1)}setTimeout(()=>Md(S))}}),children:typeof i=="function"?i({isCurrentTabStop:h,hasTabStop:g!=null}):i})})});Rd.displayName=Pd;var Sy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Cy(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ty(e,t,n){const r=Cy(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Sy[r]}function Md(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function ky(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ey=_d,Iy=Rd,Ny=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Ir=new WeakMap,us=new WeakMap,ds={},da=0,Od=function(e){return e&&(e.host||Od(e.parentNode))},Ay=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Od(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},jy=function(e,t,n,r){var o=Ay(t,Array.isArray(e)?e:[e]);ds[n]||(ds[n]=new WeakMap);var s=ds[n],i=[],a=new Set,l=new Set(o),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};o.forEach(c);var d=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(m){if(a.has(m))d(m);else try{var f=m.getAttribute(r),v=f!==null&&f!=="false",g=(Ir.get(m)||0)+1,x=(s.get(m)||0)+1;Ir.set(m,g),s.set(m,x),i.push(m),g===1&&v&&us.set(m,!0),x===1&&m.setAttribute(n,"true"),v||m.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",m,y)}})};return d(t),a.clear(),da++,function(){i.forEach(function(h){var m=Ir.get(h)-1,f=s.get(h)-1;Ir.set(h,m),s.set(h,f),m||(us.has(h)||h.removeAttribute(r),us.delete(h)),f||h.removeAttribute(n)}),da--,da||(Ir=new WeakMap,Ir=new WeakMap,us=new WeakMap,ds={})}},fa=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Ny(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),jy(r,o,n,"aria-hidden")):function(){return null}},Cn=function(){return Cn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Cn.apply(this,arguments)};function Dd(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function _y(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var fs="right-scroll-bar-position",hs="width-before-scroll-bar",Py="with-scroll-bars-hidden",Ry="--removed-body-scroll-bar-size";function ha(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function My(e,t){var n=b.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var Oy=typeof window<"u"?p.useLayoutEffect:p.useEffect,Ld=new WeakMap;function Dy(e,t){var n=My(null,function(r){return e.forEach(function(o){return ha(o,r)})});return Oy(function(){var r=Ld.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ha(a,null)}),s.forEach(function(a){o.has(a)||ha(a,i)})}Ld.set(n,e)},[e]),n}function Ly(e){return e}function $y(e,t){t===void 0&&(t=Ly);var n=[],r=!1,o={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]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Fy(e){e===void 0&&(e={});var t=$y(null);return t.options=Cn({async:!0,ssr:!1},e),t}var $d=function(e){var t=e.sideCar,n=Dd(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return p.createElement(r,Cn({},n))};$d.isSideCarExport=!0;function By(e,t){return e.useMedium(t),$d}var Fd=Fy(),pa=function(){},ps=p.forwardRef(function(e,t){var n=p.useRef(null),r=p.useState({onScrollCapture:pa,onWheelCapture:pa,onTouchMoveCapture:pa}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,h=e.shards,m=e.sideCar,f=e.noRelative,v=e.noIsolation,g=e.inert,x=e.allowPinchZoom,y=e.as,w=y===void 0?"div":y,S=e.gapMode,k=Dd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=m,T=Dy([n,t]),E=Cn(Cn({},k),o);return p.createElement(p.Fragment,null,d&&p.createElement(C,{sideCar:Fd,removeScrollBar:c,shards:h,noRelative:f,noIsolation:v,inert:g,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:S}),i?p.cloneElement(p.Children.only(a),Cn(Cn({},E),{ref:T})):p.createElement(w,Cn({},E,{className:l,ref:T}),a))});ps.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ps.classNames={fullWidth:hs,zeroRight:fs};var zy=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Hy(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=zy();return t&&e.setAttribute("nonce",t),e}function Uy(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Wy(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Vy=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Hy())&&(Uy(t,n),Wy(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ky=function(){var e=Vy();return function(t,n){p.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Bd=function(){var e=Ky(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},qy={left:0,top:0,right:0,gap:0},ma=function(e){return parseInt(e||"",10)||0},Gy=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[ma(n),ma(r),ma(o)]},Yy=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return qy;var t=Gy(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Xy=Bd(),Nr="data-scroll-locked",Jy=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
40
40
|
.`.concat(Py,` {
|
|
41
41
|
overflow: hidden `).concat(r,`;
|
|
42
42
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -76,7 +76,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
76
76
|
`)},zd=function(){var e=parseInt(document.body.getAttribute(Nr)||"0",10);return isFinite(e)?e:0},Zy=function(){p.useEffect(function(){return document.body.setAttribute(Nr,(zd()+1).toString()),function(){var e=zd()-1;e<=0?document.body.removeAttribute(Nr):document.body.setAttribute(Nr,e.toString())}},[])},Qy=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Zy();var s=p.useMemo(function(){return Yy(o)},[o]);return p.createElement(Xy,{styles:Jy(s,!t,o,n?"":"!important")})},ga=!1;if(typeof window<"u")try{var ms=Object.defineProperty({},"passive",{get:function(){return ga=!0,!0}});window.addEventListener("test",ms,ms),window.removeEventListener("test",ms,ms)}catch{ga=!1}var Ar=ga?{passive:!1}:!1,e0=function(e){return e.tagName==="TEXTAREA"},Hd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!e0(e)&&n[t]==="visible")},t0=function(e){return Hd(e,"overflowY")},n0=function(e){return Hd(e,"overflowX")},Ud=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Wd(e,r);if(o){var s=Vd(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},r0=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},o0=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Wd=function(e,t){return e==="v"?t0(t):n0(t)},Vd=function(e,t){return e==="v"?r0(t):o0(t)},s0=function(e,t){return e==="h"&&t==="rtl"?-1:1},i0=function(e,t,n,r,o){var s=s0(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,h=0,m=0;do{if(!a)break;var f=Vd(e,a),v=f[0],g=f[1],x=f[2],y=g-x-s*v;(v||y)&&Wd(e,a)&&(h+=y,m+=v);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(h)<1||!d&&Math.abs(m)<1)&&(c=!0),c},gs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Kd=function(e){return[e.deltaX,e.deltaY]},qd=function(e){return e&&"current"in e?e.current:e},a0=function(e,t){return e[0]===t[0]&&e[1]===t[1]},l0=function(e){return`
|
|
77
77
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
78
78
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
79
|
-
`)},c0=0,jr=[];function u0(e){var t=p.useRef([]),n=p.useRef([0,0]),r=p.useRef(),o=p.useState(c0++)[0],s=p.useState(Bd)[0],i=p.useRef(e);p.useEffect(function(){i.current=e},[e]),p.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=_y([e.lockRef.current],(e.shards||[]).map(qd),!0).filter(Boolean);return g.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=p.useCallback(function(g,x){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var y=gs(g),w=n.current,S="deltaX"in g?g.deltaX:w[0]-y[0],k="deltaY"in g?g.deltaY:w[1]-y[1],C,T=g.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in g&&E==="h"&&T.type==="range")return!1;var N=Ud(E,T);if(!N)return!0;if(N?C=E:(C=E==="v"?"h":"v",N=Ud(E,T)),!N)return!1;if(!r.current&&"changedTouches"in g&&(S||k)&&(r.current=C),!C)return!0;var R=r.current||C;return i0(R,x,g,R==="h"?S:k)},[]),l=p.useCallback(function(g){var x=g;if(!(!jr.length||jr[jr.length-1]!==s)){var y="deltaY"in x?Kd(x):gs(x),w=t.current.filter(function(C){return C.name===x.type&&(C.target===x.target||x.target===C.shadowParent)&&a0(C.delta,y)})[0];if(w&&w.should){x.cancelable&&x.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(qd).filter(Boolean).filter(function(C){return C.contains(x.target)}),k=S.length>0?a(x,S[0]):!i.current.noIsolation;k&&x.cancelable&&x.preventDefault()}}},[]),c=p.useCallback(function(g,x,y,w){var S={name:g,delta:x,target:y,should:w,shadowParent:d0(y)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=p.useCallback(function(g){n.current=gs(g),r.current=void 0},[]),h=p.useCallback(function(g){c(g.type,Kd(g),g.target,a(g,e.lockRef.current))},[]),m=p.useCallback(function(g){c(g.type,gs(g),g.target,a(g,e.lockRef.current))},[]);p.useEffect(function(){return jr.push(s),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:m}),document.addEventListener("wheel",l,Ar),document.addEventListener("touchmove",l,Ar),document.addEventListener("touchstart",d,Ar),function(){jr=jr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Ar),document.removeEventListener("touchmove",l,Ar),document.removeEventListener("touchstart",d,Ar)}},[]);var f=e.removeScrollBar,v=e.inert;return p.createElement(p.Fragment,null,v?p.createElement(s,{styles:l0(o)}):null,f?p.createElement(Qy,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function d0(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const f0=By(Fd,u0);var xs=p.forwardRef(function(e,t){return p.createElement(ps,Cn({},e,{ref:t,sideCar:f0}))});xs.classNames=ps.classNames;var xa=["Enter"," "],h0=["ArrowDown","PageUp","Home"],Gd=["ArrowUp","PageDown","End"],p0=[...h0,...Gd],m0={ltr:[...xa,"ArrowRight"],rtl:[...xa,"ArrowLeft"]},g0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ao="Menu",[lo,x0,v0]=Xo(ao),[tr,Yd]=cn(ao,[v0,Er,jd]),vs=Er(),Xd=jd(),[b0,nr]=tr(ao),[w0,co]=tr(ao),Jd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=vs(t),[l,c]=p.useState(null),d=p.useRef(!1),h=ht(s),m=Jo(o);return p.useEffect(()=>{const f=()=>{d.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},v=()=>d.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),u.jsx(sa,{...a,children:u.jsx(b0,{scope:t,open:n,onOpenChange:h,content:l,onContentChange:c,children:u.jsx(w0,{scope:t,onClose:p.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:d,dir:m,modal:i,children:r})})})};Jd.displayName=ao;var y0="MenuAnchor",va=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=vs(n);return u.jsx(ia,{...o,...r,ref:t})});va.displayName=y0;var ba="MenuPortal",[S0,Zd]=tr(ba,{forceMount:void 0}),Qd=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=nr(ba,t);return u.jsx(S0,{scope:t,forceMount:n,children:u.jsx(Ut,{present:n||s.open,children:u.jsx(so,{asChild:!0,container:o,children:r})})})};Qd.displayName=ba;var nn="MenuContent",[C0,wa]=tr(nn),ef=p.forwardRef((e,t)=>{const n=Zd(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=nr(nn,e.__scopeMenu),i=co(nn,e.__scopeMenu);return u.jsx(lo.Provider,{scope:e.__scopeMenu,children:u.jsx(Ut,{present:r||s.open,children:u.jsx(lo.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(T0,{...o,ref:t}):u.jsx(k0,{...o,ref:t})})})})}),T0=p.forwardRef((e,t)=>{const n=nr(nn,e.__scopeMenu),r=p.useRef(null),o=Le(t,r);return p.useEffect(()=>{const s=r.current;if(s)return fa(s)},[]),u.jsx(ya,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),k0=p.forwardRef((e,t)=>{const n=nr(nn,e.__scopeMenu);return u.jsx(ya,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),E0=Yt.createSlot("MenuContent.ScrollLock"),ya=p.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,onDismiss:f,disableOutsideScroll:v,...g}=e,x=nr(nn,n),y=co(nn,n),w=vs(n),S=Xd(n),k=x0(n),[C,T]=p.useState(null),E=p.useRef(null),N=Le(t,E,x.onContentChange),R=p.useRef(0),O=p.useRef(""),L=p.useRef(0),q=p.useRef(null),W=p.useRef("right"),j=p.useRef(0),X=v?xs:p.Fragment,G=v?{as:E0,allowPinchZoom:!0}:void 0,B=I=>{var V,D;const K=O.current+I,J=k().filter(Z=>!Z.disabled),P=document.activeElement,_=(V=J.find(Z=>Z.ref.current===P))==null?void 0:V.textValue,z=J.map(Z=>Z.textValue),F=$0(z,K,_),re=(D=J.find(Z=>Z.textValue===F))==null?void 0:D.ref.current;(function Z(ee){O.current=ee,window.clearTimeout(R.current),ee!==""&&(R.current=window.setTimeout(()=>Z(""),1e3))})(K),re&&setTimeout(()=>re.focus())};p.useEffect(()=>()=>window.clearTimeout(R.current),[]),Ui();const M=p.useCallback(I=>{var J,P;return W.current===((J=q.current)==null?void 0:J.side)&&B0(I,(P=q.current)==null?void 0:P.area)},[]);return u.jsx(C0,{scope:n,searchRef:O,onItemEnter:p.useCallback(I=>{M(I)&&I.preventDefault()},[M]),onItemLeave:p.useCallback(I=>{var K;M(I)||((K=E.current)==null||K.focus(),T(null))},[M]),onTriggerLeave:p.useCallback(I=>{M(I)&&I.preventDefault()},[M]),pointerGraceTimerRef:L,onPointerGraceIntentChange:p.useCallback(I=>{q.current=I},[]),children:u.jsx(X,{...G,children:u.jsx(Zo,{asChild:!0,trapped:o,onMountAutoFocus:ce(s,I=>{var K;I.preventDefault(),(K=E.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(yr,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,onDismiss:f,children:u.jsx(Ey,{asChild:!0,...S,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ce(l,I=>{y.isUsingKeyboardRef.current||I.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(aa,{role:"menu","aria-orientation":"vertical","data-state":vf(x.open),"data-radix-menu-content":"",dir:y.dir,...w,...g,ref:N,style:{outline:"none",...g.style},onKeyDown:ce(g.onKeyDown,I=>{const J=I.target.closest("[data-radix-menu-content]")===I.currentTarget,P=I.ctrlKey||I.altKey||I.metaKey,_=I.key.length===1;J&&(I.key==="Tab"&&I.preventDefault(),!P&&_&&B(I.key));const z=E.current;if(I.target!==z||!p0.includes(I.key))return;I.preventDefault();const re=k().filter(V=>!V.disabled).map(V=>V.ref.current);Gd.includes(I.key)&&re.reverse(),D0(re)}),onBlur:ce(e.onBlur,I=>{I.currentTarget.contains(I.target)||(window.clearTimeout(R.current),O.current="")}),onPointerMove:ce(e.onPointerMove,fo(I=>{const K=I.target,J=j.current!==I.clientX;if(I.currentTarget.contains(K)&&J){const P=I.clientX>j.current?"right":"left";W.current=P,j.current=I.clientX}}))})})})})})})});ef.displayName=nn;var I0="MenuGroup",Sa=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(ve.div,{role:"group",...r,ref:t})});Sa.displayName=I0;var N0="MenuLabel",tf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});tf.displayName=N0;var bs="MenuItem",nf="menu.itemSelect",ws=p.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=p.useRef(null),i=co(bs,e.__scopeMenu),a=wa(bs,e.__scopeMenu),l=Le(t,s),c=p.useRef(!1),d=()=>{const h=s.current;if(!n&&h){const m=new CustomEvent(nf,{bubbles:!0,cancelable:!0});h.addEventListener(nf,f=>r==null?void 0:r(f),{once:!0}),Bi(h,m),m.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(rf,{...o,ref:l,disabled:n,onClick:ce(e.onClick,d),onPointerDown:h=>{var m;(m=e.onPointerDown)==null||m.call(e,h),c.current=!0},onPointerUp:ce(e.onPointerUp,h=>{var m;c.current||(m=h.currentTarget)==null||m.click()}),onKeyDown:ce(e.onKeyDown,h=>{const m=a.searchRef.current!=="";n||m&&h.key===" "||xa.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});ws.displayName=bs;var rf=p.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=wa(bs,n),a=Xd(n),l=p.useRef(null),c=Le(t,l),[d,h]=p.useState(!1),[m,f]=p.useState("");return p.useEffect(()=>{const v=l.current;v&&f((v.textContent??"").trim())},[s.children]),u.jsx(lo.ItemSlot,{scope:n,disabled:r,textValue:o??m,children:u.jsx(Iy,{asChild:!0,...a,focusable:!r,children:u.jsx(ve.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ce(e.onPointerMove,fo(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ce(e.onPointerLeave,fo(v=>i.onItemLeave(v))),onFocus:ce(e.onFocus,()=>h(!0)),onBlur:ce(e.onBlur,()=>h(!1))})})})}),A0="MenuCheckboxItem",of=p.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(uf,{scope:e.__scopeMenu,checked:n,children:u.jsx(ws,{role:"menuitemcheckbox","aria-checked":ys(n)?"mixed":n,...o,ref:t,"data-state":Ta(n),onSelect:ce(o.onSelect,()=>r==null?void 0:r(ys(n)?!0:!n),{checkForDefaultPrevented:!1})})})});of.displayName=A0;var sf="MenuRadioGroup",[j0,_0]=tr(sf,{value:void 0,onValueChange:()=>{}}),af=p.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=ht(r);return u.jsx(j0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Sa,{...o,ref:t})})});af.displayName=sf;var lf="MenuRadioItem",cf=p.forwardRef((e,t)=>{const{value:n,...r}=e,o=_0(lf,e.__scopeMenu),s=n===o.value;return u.jsx(uf,{scope:e.__scopeMenu,checked:s,children:u.jsx(ws,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ta(s),onSelect:ce(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});cf.displayName=lf;var Ca="MenuItemIndicator",[uf,P0]=tr(Ca,{checked:!1}),df=p.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=P0(Ca,n);return u.jsx(Ut,{present:r||ys(s.checked)||s.checked===!0,children:u.jsx(ve.span,{...o,ref:t,"data-state":Ta(s.checked)})})});df.displayName=Ca;var R0="MenuSeparator",ff=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(ve.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});ff.displayName=R0;var M0="MenuArrow",hf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=vs(n);return u.jsx(la,{...o,...r,ref:t})});hf.displayName=M0;var O0="MenuSub",[IN,pf]=tr(O0),uo="MenuSubTrigger",mf=p.forwardRef((e,t)=>{const n=nr(uo,e.__scopeMenu),r=co(uo,e.__scopeMenu),o=pf(uo,e.__scopeMenu),s=wa(uo,e.__scopeMenu),i=p.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=p.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return p.useEffect(()=>d,[d]),p.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),u.jsx(va,{asChild:!0,...c,children:u.jsx(rf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":vf(n.open),...e,ref:On(t,o.onTriggerChange),onClick:h=>{var m;(m=e.onClick)==null||m.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ce(e.onPointerMove,fo(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ce(e.onPointerLeave,fo(h=>{var f,v;d();const m=(f=n.content)==null?void 0:f.getBoundingClientRect();if(m){const g=(v=n.content)==null?void 0:v.dataset.side,x=g==="right",y=x?-5:5,w=m[x?"left":"right"],S=m[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+y,y:h.clientY},{x:w,y:m.top},{x:S,y:m.top},{x:S,y:m.bottom},{x:w,y:m.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ce(e.onKeyDown,h=>{var f;const m=s.searchRef.current!=="";e.disabled||m&&h.key===" "||m0[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});mf.displayName=uo;var gf="MenuSubContent",xf=p.forwardRef((e,t)=>{const n=Zd(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=nr(nn,e.__scopeMenu),i=co(nn,e.__scopeMenu),a=pf(gf,e.__scopeMenu),l=p.useRef(null),c=Le(t,l);return u.jsx(lo.Provider,{scope:e.__scopeMenu,children:u.jsx(Ut,{present:r||s.open,children:u.jsx(lo.Slot,{scope:e.__scopeMenu,children:u.jsx(ya,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ce(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ce(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ce(e.onKeyDown,d=>{var f;const h=d.currentTarget.contains(d.target),m=g0[i.dir].includes(d.key);h&&m&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),d.preventDefault())})})})})})});xf.displayName=gf;function vf(e){return e?"open":"closed"}function ys(e){return e==="indeterminate"}function Ta(e){return ys(e)?"indeterminate":e?"checked":"unchecked"}function D0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function L0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function $0(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=L0(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function F0(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,h=l.x,m=l.y;d>r!=m>r&&n<(h-c)*(r-d)/(m-d)+c&&(o=!o)}return o}function B0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return F0(n,t)}function fo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var z0=Jd,H0=va,U0=Qd,W0=ef,V0=Sa,K0=tf,q0=ws,G0=of,Y0=af,X0=cf,J0=df,Z0=ff,Q0=hf,eS=mf,tS=xf,Ss="DropdownMenu",[nS,NN]=cn(Ss,[Yd]),Ft=Yd(),[rS,bf]=nS(Ss),wf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ft(t),c=p.useRef(null),[d,h]=Dn({prop:o,defaultProp:s??!1,onChange:i,caller:Ss});return u.jsx(rS,{scope:t,triggerId:Rt(),triggerRef:c,contentId:Rt(),open:d,onOpenChange:h,onOpenToggle:p.useCallback(()=>h(m=>!m),[h]),modal:a,children:u.jsx(z0,{...l,open:d,onOpenChange:h,dir:r,modal:a,children:n})})};wf.displayName=Ss;var yf="DropdownMenuTrigger",Sf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=bf(yf,n),i=Ft(n);return u.jsx(H0,{asChild:!0,...i,children:u.jsx(ve.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:On(t,s.triggerRef),onPointerDown:ce(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ce(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Sf.displayName=yf;var oS="DropdownMenuPortal",Cf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ft(t);return u.jsx(U0,{...r,...n})};Cf.displayName=oS;var Tf="DropdownMenuContent",kf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bf(Tf,n),s=Ft(n),i=p.useRef(!1);return u.jsx(W0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ce(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ce(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});kf.displayName=Tf;var sS="DropdownMenuGroup",iS=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(V0,{...o,...r,ref:t})});iS.displayName=sS;var aS="DropdownMenuLabel",Ef=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(K0,{...o,...r,ref:t})});Ef.displayName=aS;var lS="DropdownMenuItem",If=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(q0,{...o,...r,ref:t})});If.displayName=lS;var cS="DropdownMenuCheckboxItem",Nf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(G0,{...o,...r,ref:t})});Nf.displayName=cS;var uS="DropdownMenuRadioGroup",dS=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Y0,{...o,...r,ref:t})});dS.displayName=uS;var fS="DropdownMenuRadioItem",Af=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(X0,{...o,...r,ref:t})});Af.displayName=fS;var hS="DropdownMenuItemIndicator",jf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(J0,{...o,...r,ref:t})});jf.displayName=hS;var pS="DropdownMenuSeparator",_f=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Z0,{...o,...r,ref:t})});_f.displayName=pS;var mS="DropdownMenuArrow",gS=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Q0,{...o,...r,ref:t})});gS.displayName=mS;var xS="DropdownMenuSubTrigger",Pf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(eS,{...o,...r,ref:t})});Pf.displayName=xS;var vS="DropdownMenuSubContent",Rf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(tS,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Rf.displayName=vS;var bS=wf,wS=Sf,yS=Cf,Mf=kf,Of=Ef,Df=If,Lf=Nf,$f=Af,Ff=jf,Bf=_f,zf=Pf,Hf=Rf;const Cs=bS,Ts=wS,SS=p.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(zf,{ref:o,className:oe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(ue.ChevronRight,{className:"ml-auto h-4 w-4"})]}));SS.displayName=zf.displayName;const CS=p.forwardRef(({className:e,...t},n)=>u.jsx(Hf,{ref:n,className:oe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));CS.displayName=Hf.displayName;const ho=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(yS,{children:u.jsx(Mf,{ref:r,sideOffset:t,className:oe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));ho.displayName=Mf.displayName;const Bn=p.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Df,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Bn.displayName=Df.displayName;const TS=p.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(Lf,{ref:o,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Ff,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),t]}));TS.displayName=Lf.displayName;const kS=p.forwardRef(({className:e,children:t,...n},r)=>u.jsxs($f,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Ff,{children:u.jsx(ue.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));kS.displayName=$f.displayName;const ES=p.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Of,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ES.displayName=Of.displayName;const IS=p.forwardRef(({className:e,...t},n)=>u.jsx(Bf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));IS.displayName=Bf.displayName;const ka=p.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:oe("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));ka.displayName="Textarea";const NS=1e4;function Uf({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=NS,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:h="",textareaClassName:m="",allowEmptySend:f=!1,validate:v,onValidationError:g}){const x=i!==void 0,[y,w]=b.useState(e),S=(x?i:y)??"",[k,C]=b.useTransition(),T=b.useRef(null),E=b.useRef(0),N=b.useRef(null),R=b.useRef("");b.useEffect(()=>{x||(w(e??""),N.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,x]);const[O,L]=b.useState(null),q=b.useCallback(_=>_.length>s?`Message too long (${_.length}/${s} characters)`:null,[s]),W=b.useMemo(()=>v??q,[v,q]),j=b.useCallback(_=>{const z=W(_);return L(z),g==null||g(z),R.current=_,z},[W,g]),X=b.useCallback(()=>{const _=T.current;_&&(_.style.height="auto",_.style.height=`${_.scrollHeight}px`)},[]);b.useEffect(()=>{X()},[X,S]),b.useEffect(()=>{if(!O)return;const _=(S??"").trim();R.current!==_&&j(_)},[S,O,j]);const G=b.useCallback((_,{fromUser:z})=>{x||w(_),z&&(a==null||a(_))},[x,a]),B=b.useCallback(async _=>{_&&_.preventDefault();const z=(S??"").trim();if(!z&&!f||j(z))return;const F=++E.current;N.current={id:F,shouldClear:!0},C(()=>{var re,V,D;try{const Z=l(z);Z&&typeof Z.then=="function"?Z.then(()=>{var ee,Q;((ee=N.current)==null?void 0:ee.id)===F&&N.current.shouldClear&&(x||(w(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((Q=N.current)==null?void 0:Q.id)===F&&(N.current=null)}).catch(()=>{var ee;((ee=N.current)==null?void 0:ee.id)===F&&(N.current=null)}):(((re=N.current)==null?void 0:re.id)===F&&N.current.shouldClear&&(x||(w(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((V=N.current)==null?void 0:V.id)===F&&(N.current=null))}catch{((D=N.current)==null?void 0:D.id)===F&&(N.current=null)}})},[S,l,f,x,a,j]),M=b.useCallback(_=>{const z=_.target.value;G(z,{fromUser:!0}),N.current&&(N.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`),O&&j(z.trim())},[G,j,O]),I=b.useCallback(_=>{_.key==="Enter"&&!_.shiftKey?(_.preventDefault(),B()):_.key==="Escape"&&t&&(_.preventDefault(),c==null||c())},[B,t,c]),P=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${m}`;return u.jsx("form",{onSubmit:_=>void B(_),className:`w-full ${h}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsxs("div",{className:"flex-1",children:[u.jsx(ka,{ref:T,value:S,onChange:M,onKeyDown:I,placeholder:t?"Edit your message...":n,className:P,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"}),O&&u.jsx("p",{className:"mt-1 text-xs text-destructive font-medium",children:O})]}),u.jsx("div",{children:r?u.jsx(Ze,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ue.Square,{size:16})}):u.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!S.trim()&&!f||k,children:u.jsx(ue.Send,{size:16})})})]})})}const AS=b.memo(Uf),ks=0,zn=1,_r=2,Wf=4;function Vf(e){return()=>e}function jS(e){e()}function Kf(e,t){return n=>e(t(n))}function qf(e,t){return()=>e(t)}function _S(e,t){return n=>e(t,n)}function Ea(e){return e!==void 0}function PS(...e){return()=>{e.map(jS)}}function Pr(){}function Es(e,t){return t(e),e}function RS(e,t){return t(e)}function rt(...e){return e}function Je(e,t){return e(zn,t)}function Me(e,t){e(ks,t)}function Ia(e){e(_r)}function pt(e){return e(Wf)}function be(e,t){return Je(e,_S(t,ks))}function fn(e,t){const n=e(zn,r=>{n(),t(r)});return n}function Gf(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Yf(e,t){return e===t}function ot(e=Yf){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ne(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>Kf(t,e)}function Tn(e){return t=>()=>{t(e)}}function ne(e,...t){const n=MS(...t);return(r,o)=>{switch(r){case _r:Ia(e);return;case zn:return Je(e,n(o))}}}function kn(e,t){return n=>r=>{n(t=e(t,r))}}function rr(e){return t=>n=>{e>0?e--:t(n)}}function jn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Je(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function MS(...e){return t=>e.reduceRight(RS,t)}function OS(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case zn:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),Pr);case _r:r(),n=null;return}}}function se(e){let t=e;const n=He();return(r,o)=>{switch(r){case ks:t=o;break;case zn:{o(t);break}case Wf:return t}return n(r,o)}}function Mt(e,t){return Es(se(t),n=>be(e,n))}function He(){const e=[];return(t,n)=>{switch(t){case ks:e.slice().forEach(r=>{r(n)});return;case _r:e.splice(0,e.length);return;case zn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function en(e){return Es(He(),t=>be(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:DS(),singleton:n}}const DS=()=>Symbol();function LS(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function xt(...e){const t=He(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Je(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case _r:{Ia(t);return}case zn:return r===o&&i(n),Je(t,i)}}}function Ee(e,t=Yf){return ne(e,ot(t))}function Na(...e){return function(t,n){switch(t){case _r:return;case zn:return PS(...e.map(r=>Je(r,n)))}}}var Wt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Wt||{});const $S={0:"debug",3:"error",1:"log",2:"warn"},FS=()=>typeof globalThis>"u"?window:globalThis,Hn=qe(()=>{const e=se(3);return{log:se((t,n,r=1)=>{var o;const s=(o=FS().VIRTUOSO_LOG_LEVEL)!=null?o:pt(e);r>=s&&console[$S[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function or(e,t,n){return Aa(e,t,n).callbackRef}function Aa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function BS(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const h=zS(d.children,t,a?"offsetWidth":"offsetHeight",o);let m=d.parentElement;for(;!m.dataset.virtuosoScroller;)m=m.parentElement;const f=m.lastElementChild.dataset.viewportType==="window";let v;f&&(v=m.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:f?a?v.scrollX||v.document.documentElement.scrollLeft:v.scrollY||v.document.documentElement.scrollTop:a?m.scrollLeft:m.scrollTop,x=i?a?i.scrollWidth:i.scrollHeight:f?a?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight:a?m.scrollWidth:m.scrollHeight,y=i?a?i.offsetWidth:i.offsetHeight:f?a?v.innerWidth:v.innerHeight:a?m.offsetWidth:m.offsetHeight;r({scrollHeight:x,scrollTop:Math.max(g,0),viewportHeight:y}),s==null||s(a?Xf("column-gap",getComputedStyle(d).columnGap,o):Xf("row-gap",getComputedStyle(d).rowGap,o)),h!==null&&e(h)},[e,t,o,s,i,r,a]);return Aa(c,n,l)}function zS(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Wt.ERROR),d===c)continue;const h=s[s.length-1];s.length===0||h.size!==d||h.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Xf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Wt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Jf(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let h,m;if(t){const f=t.getBoundingClientRect(),v=c.top-f.top;m=f.height-Math.max(0,v),h=v+t.scrollTop}else{const f=i.current.ownerDocument.defaultView;m=f.innerHeight-Math.max(0,c.top),h=c.top+f.scrollY}r.current={offsetTop:h,visibleHeight:m,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Aa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Bt=qe(()=>{const e=He(),t=He(),n=se(0),r=He(),o=se(0),s=He(),i=He(),a=se(0),l=se(0),c=se(0),d=se(0),h=He(),m=He(),f=se(!1),v=se(!1),g=se(!1);return be(ne(e,pe(({scrollTop:x})=>x)),t),be(ne(e,pe(({scrollHeight:x})=>x)),i),be(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:v,scrollBy:m,scrollContainerState:e,scrollHeight:i,scrollingInProgress:f,scrollTo:h,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),po={lvl:0};function Zf(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function et(e){return e===po}function mo(e,t){if(!et(e))return t===e.k?e.v:t<e.k?mo(e.l,t):mo(e.r,t)}function hn(e,t,n="k"){if(et(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=hn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return hn(e.l,t,n)}function tn(e,t,n){return et(e)?th(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?nh(bt(e,{l:tn(e.l,t,n)})):nh(bt(e,{r:tn(e.r,t,n)}))}function Rr(){return po}function Is(e,t,n){if(et(e))return[];const r=hn(e,t)[0];return HS(_a(e,r,n))}function ja(e,t){if(et(e))return po;const{k:n,l:r,r:o}=e;if(t===n){if(et(r))return o;if(et(o))return r;{const[s,i]=eh(r);return Ns(bt(e,{k:s,l:Qf(r),v:i}))}}else return t<n?Ns(bt(e,{l:ja(r,t)})):Ns(bt(e,{r:ja(o,t)}))}function sr(e){return et(e)?[]:[...sr(e.l),{k:e.k,v:e.v},...sr(e.r)]}function _a(e,t,n){if(et(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(_a(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(_a(s,t,n))),a}function Ns(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Pa(t))return rh(bt(e,{lvl:n-1}));if(!et(t)&&!et(t.r))return bt(t.r,{l:bt(t,{r:t.r.l}),lvl:n,r:bt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Pa(e))return Ra(bt(e,{lvl:n-1}));if(!et(r)&&!et(r.l)){const o=r.l,s=Pa(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ra(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return th(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Qf(e){return et(e.r)?e.l:Ns(bt(e,{r:Qf(e.r)}))}function Pa(e){return et(e)||e.lvl>e.r.lvl}function eh(e){return et(e.r)?[e.k,e.v]:eh(e.r)}function th(e,t,n,r=po,o=po){return{k:e,l:r,lvl:n,r:o,v:t}}function nh(e){return Ra(rh(e))}function rh(e){const{l:t}=e;return!et(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function Ra(e){const{lvl:t,r:n}=e;return!et(n)&&!et(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function HS(e){return Zf(e,({k:t,v:n})=>({index:t,value:n}))}function oh(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function go(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ma=qe(()=>({recalcInProgress:se(!1)}),[],{singleton:!0});function sh(e,t,n){return e[As(e,t,n)]}function As(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function US(e,t,n,r){const o=As(e,t,r),s=As(e,n,r,o);return e.slice(o,s+1)}function Un(e,t){return Math.round(e.getBoundingClientRect()[t])}function js(e){return!et(e.groupOffsetTree)}function Oa({index:e},t){return t===e?0:t<e?-1:1}function WS(){return{groupIndices:[],groupOffsetTree:Rr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Rr()}}function VS(e,t){let n=et(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),et(e)){e=tn(e,0,s);continue}const a=Is(e,i-1,o+1);if(a.some(ZS(r)))continue;let l=!1,c=!1;for(const{end:d,start:h,value:m}of a)l?(o>=h||s===m)&&(e=ja(e,h)):(c=m!==s,l=!0),d>o&&o>=h&&m!==s&&(e=tn(e,o+1,m));c&&(e=tn(e,i,s))}return[e,n]}function KS(e){return typeof e.groupIndex<"u"}function qS({offset:e},t){return t===e?0:t<e?-1:1}function xo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=sh(t,e,Oa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ih(e,t){if(!js(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function ah(e,t,n){if(KS(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ih(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function GS(e,t,n,r=0){return r>0&&(t=Math.max(t,sh(e,r,Oa).offset)),Zf(US(e,t,n,qS),JS)}function YS(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Wt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&et(s)&&t.length===2){const m=t[0].size,f=t[1].size;i=n.reduce((v,g)=>tn(tn(v,g,m),g+1,f),i)}else[i,a]=VS(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:h}=Da(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((m,f)=>tn(m,f,xo(f,h,o)),Rr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:h,sizeTree:i}}function XS(e){return sr(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function lh(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function Da(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=As(o,t-1,Oa),a=o[l].offset;const c=hn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===hn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Is(n,t,1/0)){const h=c-s,m=h*i+a+h*r;o.push({index:c,offset:m,size:d}),s=c,a=m,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function JS(e){return{index:e.index,value:e}}function ZS(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const QS={offsetHeight:"height",offsetWidth:"width"},En=qe(([{log:e},{recalcInProgress:t}])=>{const n=He(),r=He(),o=Mt(r,0),s=He(),i=He(),a=se(0),l=se([]),c=se(void 0),d=se(void 0),h=se((C,T)=>Un(C,QS[T])),m=se(void 0),f=se(0),v=WS(),g=Mt(ne(n,$e(l,e,f),kn(YS,v),ot()),v),x=Mt(ne(l,ot(),kn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),pe(({prev:C})=>C)),[]);be(ne(l,Ne(C=>C.length>0),$e(g,f),pe(([C,T,E])=>{const N=C.reduce((R,O,L)=>tn(R,O,xo(O,T.offsetTree,E)||L),Rr());return{...T,groupIndices:C,groupOffsetTree:N}})),g),be(ne(r,$e(g),Ne(([C,{lastIndex:T}])=>C<T),pe(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),be(c,d);const y=Mt(ne(c,pe(C=>C===void 0)),!0);be(ne(d,Ne(C=>C!==void 0&&et(pt(g).sizeTree)),pe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const w=en(ne(n,$e(g),kn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:v}),pe(C=>C.changed)));Je(ne(a,kn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),pe(C=>C.diff)),C=>{const{groupIndices:T}=pt(g);if(C>0)Me(t,!0),Me(s,C+lh(C,T));else if(C<0){const E=pt(x);E.length>0&&(C-=lh(-C,E)),Me(i,C)}}),Je(ne(a,$e(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Wt.ERROR)});const S=en(s);be(ne(s,$e(g),pe(([C,T])=>{const E=T.groupIndices.length>0,N=[],R=T.lastSize;if(E){const O=mo(T.sizeTree,0);let L=0,q=0;for(;L<C;){const j=T.groupIndices[q],X=T.groupIndices.length===q+1?1/0:T.groupIndices[q+1]-j-1;N.push({endIndex:j,size:O,startIndex:j}),N.push({endIndex:j+1+X-1,size:R,startIndex:j+1}),q++,L+=X+1}const W=sr(T.sizeTree);return L!==C&&W.shift(),W.reduce((j,{k:X,v:G})=>{let B=j.ranges;return j.prevSize!==0&&(B=[...j.ranges,{endIndex:X+C-1,size:j.prevSize,startIndex:j.prevIndex}]),{prevIndex:X+C,prevSize:G,ranges:B}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return sr(T.sizeTree).reduce((O,{k:L,v:q})=>({prevIndex:L+C,prevSize:q,ranges:[...O.ranges,{endIndex:L+C-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=en(ne(i,$e(g,f),pe(([C,{offsetTree:T},E])=>{const N=-C;return xo(N,T,E)})));return be(ne(i,$e(g,f),pe(([C,T,E])=>{if(T.groupIndices.length>0){if(et(T.sizeTree))return T;let N=Rr();const R=pt(x);let O=0,L=0,q=0;for(;O<-C;){q=R[L];const W=R[L+1]-q-1;L++,O+=W+1}if(N=sr(T.sizeTree).reduce((W,{k:j,v:X})=>tn(W,Math.max(0,j+C),X),N),O!==-C){const W=mo(T.sizeTree,q);N=tn(N,0,W);const j=hn(T.sizeTree,-C+1)[1];N=tn(N,1,j)}return{...T,sizeTree:N,...Da(T.offsetTree,0,N,E)}}else{const N=sr(T.sizeTree).reduce((R,{k:O,v:L})=>tn(R,Math.max(0,O+C),L),Rr());return{...T,sizeTree:N,...Da(T.offsetTree,0,N,E)}}})),g),{beforeUnshiftWith:S,data:m,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:f,groupIndices:l,itemSize:h,listRefresh:w,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},rt(Hn,Ma),{singleton:!0});function eC(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const ch=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=He(),i=He(),a=en(ne(s,pe(eC)));return be(ne(a,pe(l=>l.totalCount)),n),be(ne(a,pe(l=>l.groupIndices)),e),be(ne(xt(o,t,r),Ne(([l,c])=>js(c)),pe(([l,c,d])=>hn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ot(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},rt(En,Bt)),Wn=qe(([{log:e}])=>{const t=se(!1),n=en(ne(t,Ne(r=>r),ot()));return Je(t,r=>{r&&pt(e)("props updated",{},Wt.DEBUG)}),{didMount:n,propsReady:t}},rt(Hn),{singleton:!0}),tC=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function uh(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!tC)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const vo=qe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:h},{log:m}])=>{const f=He(),v=He(),g=se(0);let x=null,y=null,w=null;function S(){x&&(x(),x=null),w&&(w(),w=null),y&&(clearTimeout(y),y=null),Me(l,!1)}return be(ne(f,$e(n,h,r,g,a,i,m),$e(e,s,o),pe(([[k,C,T,E,N,R,O,L],q,W,j])=>{const X=uh(k),{align:G,behavior:B,offset:M}=X,I=E-1,K=ah(X,C,I);let J=xo(K,C.offsetTree,q)+R;G==="end"?(J+=W+hn(C.sizeTree,K)[1]-T+j,K===I&&(J+=O)):G==="center"?J+=(W+hn(C.sizeTree,K)[1]-T+j)/2:J-=N,M&&(J+=M);const P=_=>{S(),_?(L("retrying to scroll to",{location:k},Wt.DEBUG),Me(f,k)):(Me(v,!0),L("list did not change, scroll successful",{},Wt.DEBUG))};if(S(),B==="smooth"){let _=!1;w=Je(t,z=>{_=_||z}),x=fn(d,()=>{P(_)})}else x=fn(ne(t,nC(150)),P);return y=setTimeout(()=>{S()},1200),Me(l,!0),L("scrolling from index to",{behavior:B,index:K,top:J},Wt.DEBUG),{behavior:B,top:J}})),c),{scrollTargetReached:v,scrollToIndex:f,topListHeight:g}},rt(En,Bt,Hn),{singleton:!0});function nC(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function La(e,t){e==0?t():requestAnimationFrame(()=>{La(e-1,t)})}function $a(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const bo=qe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=se(!0),l=se(0),c=se(!0);return be(ne(i,$e(l),Ne(([d,h])=>!!h),Tn(!1)),a),be(ne(i,$e(l),Ne(([d,h])=>!!h),Tn(!1)),c),Je(ne(xt(t,i),$e(a,n,e,c),Ne(([[,d],h,{sizeTree:m},f,v])=>d&&(!et(m)||Ea(f))&&!h&&!v),$e(l)),([,d])=>{fn(o,()=>{Me(c,!0)}),La(4,()=>{fn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},rt(En,Bt,vo,Wn),{singleton:!0});function dh(e,t){return Math.abs(e-t)<1.01}const wo="up",yo="down",rC="none",oC={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},sC=0,So=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=se(!1),a=se(!0),l=He(),c=He(),d=se(4),h=se(sC),m=Mt(ne(Na(ne(Ee(o),rr(1),Tn(!0)),ne(Ee(o),rr(1),Tn(!1),Gf(100))),ot()),!1),f=Mt(ne(Na(ne(n,Tn(!0)),ne(n,Tn(!1),Gf(200))),ot()),!1);be(ne(xt(Ee(o),Ee(h)),pe(([w,S])=>w<=S),ot()),a),be(ne(a,jn(50)),c);const v=en(ne(xt(r,Ee(s),Ee(t),Ee(e),Ee(d)),kn((w,[{scrollHeight:S,scrollTop:k},C,T,E,N])=>{const R=k+C-S>-N,O={scrollHeight:S,scrollTop:k,viewportHeight:C};if(R){let q,W;return k>w.state.scrollTop?(q="SCROLLED_DOWN",W=w.state.scrollTop-k):(q="SIZE_DECREASED",W=w.state.scrollTop-k||w.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:W,state:O}}let L;return O.scrollHeight>w.state.scrollHeight?L="SIZE_INCREASED":C<w.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":k<w.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:O}},oC),ot((w,S)=>w&&w.atBottom===S.atBottom))),g=Mt(ne(r,kn((w,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(dh(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return w.scrollTop!==k&&T?{changed:!0,jump:w.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ne(w=>w.changed),pe(w=>w.jump)),0);be(ne(v,pe(w=>w.atBottom)),i),be(ne(i,jn(50)),l);const x=se(yo);be(ne(r,pe(({scrollTop:w})=>w),ot(),kn((w,S)=>pt(f)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?wo:yo,prevScrollTop:S},{direction:yo,prevScrollTop:0}),pe(w=>w.direction)),x),be(ne(r,jn(50),Tn(rC)),x);const y=se(0);return be(ne(m,Ne(w=>!w),Tn(0)),y),be(ne(o,jn(100),$e(m),Ne(([w,S])=>!!S),kn(([w,S],[k])=>[S,k],[0,0]),pe(([w,S])=>S-w)),y),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:h,isAtBottom:i,isAtTop:a,isScrolling:m,lastJumpDueToItemResize:g,scrollDirection:x,scrollVelocity:y}},rt(Bt)),_s="top",Ps="bottom",fh="none";function hh(e,t,n){return typeof e=="number"?n===wo&&t===_s||n===yo&&t===Ps?e:0:n===wo?t===_s?e.main:e.reverse:t===Ps?e.main:e.reverse}function ph(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Fa=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=He(),i=se(0),a=se(0),l=se(0),c=Mt(ne(xt(Ee(r),Ee(o),Ee(n),Ee(s,go),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),pe(([d,h,m,[f,v],g,x,y,w,S])=>{const k=d-w,C=x+y,T=Math.max(m-k,0);let E=fh;const N=ph(S,_s),R=ph(S,Ps);return f-=w,f+=m+y,v+=m+y,v-=w,f>d+C-N&&(E=wo),v<d-T+h+R&&(E=yo),E!==fh?[Math.max(k-m-hh(g,_s,E)-N,0),k-T-y+h+hh(g,Ps,E)+R]:null}),Ne(d=>d!=null),ot(go)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},rt(Bt),{singleton:!0});function iC(e,t,n){if(js(t)){const r=ih(e,t);return[{index:hn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ba={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Rs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const h=n-i,m=a+h*l+(h-1)*r,f=c,v=m-d;return{bottom:d,firstItemIndex:s,items:gh(e,o,s),offsetBottom:v,offsetTop:c,top:f,topItems:gh(t,o,s),topListHeight:t.reduce((g,x)=>x.size+g,0),totalCount:n}}function mh(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=$a(t,a),c=Array.from({length:a}).map((d,h)=>({data:s[h+l],index:h+l,offset:0,size:0}));return Rs(c,[],a,o,n,r)}function gh(e,t,n){if(e.length===0)return[];if(!js(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Is(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const ir=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:h},m,{didMount:f},{recalcInProgress:v}])=>{const g=se([]),x=se(0),y=He();be(s.topItemsIndexes,g);const w=Mt(ne(xt(f,v,Ee(l,go),Ee(o),Ee(r),Ee(c),d,Ee(g),Ee(t),Ee(n),e),Ne(([T,E,,N,,,,,,,R])=>{const O=R&&R.length!==N;return T&&!E&&!O}),pe(([,,[T,E],N,R,O,L,q,W,j,X])=>{const G=R,{offsetTree:B,sizeTree:M}=G,I=pt(x);if(N===0)return{...Ba,totalCount:N};if(T===0&&E===0)return I===0?{...Ba,totalCount:N}:mh(I,O,R,W,j,X||[]);if(et(M))return I>0?null:Rs(iC($a(O,N),G,X),[],N,j,G,W);const K=[];if(q.length>0){const F=q[0],re=q[q.length-1];let V=0;for(const D of Is(M,F,re)){const Z=D.value,ee=Math.max(D.start,F),Q=Math.min(D.end,re);for(let H=ee;H<=Q;H++)K.push({data:X==null?void 0:X[H],index:H,offset:V,size:Z}),V+=Z}}if(!L)return Rs([],K,N,j,G,W);const J=q.length>0?q[q.length-1]+1:0,P=GS(B,T,E,J);if(P.length===0)return null;const _=N-1,z=Es([],F=>{for(const re of P){const V=re.value;let D=V.offset,Z=re.start;const ee=V.size;if(V.offset<T){Z+=Math.floor((T-V.offset+j)/(ee+j));const H=Z-re.start;D+=H*ee+H*j}Z<J&&(D+=(J-Z)*ee,Z=J);const Q=Math.min(re.end,_);for(let H=Z;H<=Q&&!(D>=E);H++)F.push({data:X==null?void 0:X[H],index:H,offset:D,size:ee}),D+=ee+j}});return Rs(z,K,N,j,G,W)}),Ne(T=>T!==null),ot()),Ba);be(ne(e,Ne(Ea),pe(T=>T==null?void 0:T.length)),o),be(ne(w,pe(T=>T.topListHeight)),h),be(h,a),be(ne(w,pe(T=>[T.top,T.bottom])),i),be(ne(w,pe(T=>T.items)),y);const S=en(ne(w,Ne(({items:T})=>T.length>0),$e(o,e),Ne(([{items:T},E])=>T[T.length-1].originalIndex===E-1),pe(([,T,E])=>[T-1,E]),ot(go),pe(([T])=>T))),k=en(ne(w,jn(200),Ne(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),pe(({items:T})=>T[0].index),ot())),C=en(ne(w,Ne(({items:T})=>T.length>0),pe(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),ot(oh)));return{endReached:S,initialItemCount:x,itemsRendered:y,listState:w,rangeChanged:C,startReached:k,topItemsIndexes:g,...m}},rt(En,ch,Fa,bo,vo,So,Wn,Ma),{singleton:!0}),xh=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=He(),i=Mt(ne(xt(n,e,r,t,o),pe(([a,l,c,d,h])=>a+l+c+d+h.offsetBottom+h.bottom)),0);return be(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},rt(Bt,ir),{singleton:!0}),aC=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=se(!1),r=Mt(ne(xt(n,e,t),Ne(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),jn(0),ot()),0);return{alignToBottom:n,paddingTopAddition:r}},rt(Bt,xh),{singleton:!0}),vh=qe(()=>({context:se(null)})),lC=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,bh=qe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=He();return be(ne(d,$e(t,l,n,s,o,r,a),$e(e),pe(([[h,m,f,v,g,x,y,w],S])=>{const{align:k,behavior:C,calculateViewLocation:T=lC,done:E,...N}=h,R=ah(h,m,v-1),O=xo(R,m.offsetTree,S)+g+x,L=O+hn(m.sizeTree,R)[1],q=w+x,W=w+f-y,j=T({itemBottom:L,itemTop:O,locationParams:{align:k,behavior:C,...N},viewportBottom:W,viewportTop:q});return j?E&&fn(ne(i,Ne(X=>!X),rr(pt(i)?1:2)),E):E&&E(),j}),Ne(h=>h!==null)),c),{scrollIntoView:d}},rt(En,Bt,vo,ir,Hn),{singleton:!0});function wh(e){return e?e==="smooth"?"smooth":"auto":!1}const cC=(e,t)=>typeof e=="function"?wh(e(t)):t&&wh(e),uC=qe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:h},{context:m},{scrollIntoView:f}])=>{const v=se(!1),g=He();let x=null;function y(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Je(ne(xt(ne(Ee(t),rr(1)),l),$e(Ee(v),s,a,h),pe(([[C,T],E,N,R,O])=>{let L=T&&R,q="auto";return L&&(q=cC(E,N||O),L=L&&!!q),{followOutputBehavior:q,shouldFollow:L,totalCount:C}}),Ne(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{x&&(x(),x=null),pt(n)?requestAnimationFrame(()=>{pt(d)("following output to ",{totalCount:T},Wt.DEBUG),y(C)}):x=fn(e,()=>{pt(d)("following output to ",{totalCount:T},Wt.DEBUG),y(C),x=null})});function w(C){const T=fn(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!x&&(pt(d)("scrolling to bottom due to increased size",{},Wt.DEBUG),y("auto"))});setTimeout(T,100)}Je(ne(xt(Ee(v),t,c),Ne(([C,,T])=>C&&T),kn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ne(({refreshed:C})=>C),$e(v,t)),([,C])=>{pt(a)&&w(C!==!1)}),Je(g,()=>{w(pt(v)!==!1)}),Je(xt(Ee(v),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const S=se(null),k=He();return be(Na(ne(Ee(r),pe(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),ne(Ee(t))),k),Je(ne(xt(ne(k,rr(1)),l),$e(Ee(S),a,h,m),pe(([[C,T],E,N,R,O])=>T&&N&&(E==null?void 0:E({context:O,totalCount:C,scrollingInProgress:R}))),Ne(C=>!!C),jn(0)),C=>{x&&(x(),x=null),pt(n)?requestAnimationFrame(()=>{pt(d)("scrolling into view",{}),Me(f,C)}):x=fn(e,()=>{pt(d)("scrolling into view",{}),Me(f,C),x=null})}),{autoscrollToBottom:g,followOutput:v,scrollIntoViewOnChange:S}},rt(En,So,vo,bo,Wn,Hn,Bt,vh,bh)),dC=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(be(ne(a,$e(s),Ne(([,l])=>l!==0),$e(o,r,t,n,e),pe(([[,l],c,d,h,m,f=[]])=>mh(l,c,d,h,m,f))),i),{}),rt(En,bo,ir,Wn),{singleton:!0}),fC=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=se(0);return Je(ne(e,$e(r),Ne(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{fn(ne(n,rr(1),Ne(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},rt(Wn,Bt,ir),{singleton:!0}),yh=qe(([{scrollVelocity:e}])=>{const t=se(!1),n=He(),r=se(!1);return be(ne(e,$e(r,t,n),Ne(([o,s])=>!!s),pe(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ot()),t),Je(ne(xt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},rt(So),{singleton:!0}),za=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=He(),r=He(),o=He(),s=se(!1),i=se(void 0);return be(ne(xt(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),be(ne(t,$e(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},rt(Bt)),hC=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=He(),d=se(void 0),h=se(null),m=se(null);return be(a,h),be(l,m),Je(ne(c,$e(t,r,i,h,m,n)),([f,v,g,x,y,w,S])=>{const k=XS(v.sizeTree);x&&y!==null&&w!==null&&(g=y.scrollTop-w.offsetTop),g-=S,f({ranges:k,scrollTop:g})}),be(ne(d,Ne(Ea),pe(pC)),o),be(ne(s,$e(d),Ne(([,f])=>f!==void 0),ot(),pe(([,f])=>f.ranges)),e),{getState:c,restoreStateFrom:d}},rt(En,Bt,bo,Wn,za));function pC(e){return{align:"start",index:0,offset:e.scrollTop}}const mC=qe(([{topItemsIndexes:e}])=>{const t=se(0);return be(ne(t,Ne(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},rt(ir));function Sh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const gC=Sh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),xC=qe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:h,sizes:m},{log:f},{recalcInProgress:v}])=>{const g=en(ne(l,$e(i),kn(([,y,w,S],[{bottom:k,items:C,offsetBottom:T,totalCount:E},N])=>{const R=k+T;let O=0;return w===E&&y.length>0&&C.length>0&&(C[0].originalIndex===0&&y[0].originalIndex===0||(O=R-S,O!==0&&(O+=N))),[O,C,E,R]},[0,[],0,0]),Ne(([y])=>y!==0),$e(r,a,n,o,f,v),Ne(([,y,w,S,,,k])=>!k&&!S&&y!==0&&w===wo),pe(([[y],,,,,w])=>(w("Upward scrolling compensation",{amount:y},Wt.DEBUG),y))));function x(y){y>0?(Me(t,{behavior:"auto",top:-y}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-y}))}return Je(ne(g,$e(e,s)),([y,w,S])=>{S&&gC()?Me(e,w-y):x(-y)}),Je(ne(xt(Mt(s,!1),e,v),Ne(([y,w,S])=>!y&&!S&&w!==0),pe(([y,w])=>w),jn(1)),x),be(ne(h,pe(y=>({top:-y}))),t),Je(ne(c,$e(m,d),pe(([y,{groupIndices:w,lastSize:S,sizeTree:k},C])=>{function T(E){return E*(S+C)}if(w.length===0)return T(y);{let E=0;const N=mo(k,0);let R=0,O=0;for(;R<y;){R++,E+=N;let L=w.length===O+1?1/0:w[O+1]-w[O]-1;R+L>y&&(E-=N,L=y-R+1),R+=L,E+=T(L),O++}return E}})),y=>{Me(e,y),requestAnimationFrame(()=>{Me(t,{top:y}),requestAnimationFrame(()=>{Me(e,0),Me(v,!1)})})}),{deviation:e}},rt(Bt,So,ir,En,Hn,Ma)),vC=qe(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),rt(Fa,dC,Wn,yh,xh,fC,aC,za,bh,Hn,vh)),Ch=qe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:h},{initialItemFinalLocationReached:m,initialTopMostItemIndex:f,scrolledToInitialItem:v},g,x,y,{listState:w,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},R])=>(be(k.rangeChanged,R.scrollSeekRangeChanged),be(ne(R.windowViewportRect,pe(O=>O.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:m,initialTopMostItemIndex:f,scrolledToInitialItem:v,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...y,groupIndices:s,itemSize:i,listState:w,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:h,...k,...R,...g,sizes:l,...x}),rt(En,bo,Bt,hC,uC,ir,vo,xC,mC,ch,vC));function bC(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Ms=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Th(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=b.createContext({});function l(x,y){x.propsReady&&Me(x.propsReady,!1);for(const w of r){const S=x[t.required[w]];Me(S,y[w])}for(const w of o)if(w in y){const S=x[t.optional[w]];Me(S,y[w])}x.propsReady&&Me(x.propsReady,!0)}function c(x){return s.reduce((y,w)=>(y[w]=S=>{const k=x[t.methods[w]];Me(k,S)},y),{})}function d(x){return i.reduce((y,w)=>(y[w]=OS(x[t.events[w]]),y),{})}const h=b.forwardRef((x,y)=>{const{children:w,...S}=x,[k]=b.useState(()=>Es(LS(e),E=>{l(E,S)})),[C]=b.useState(qf(d,k));Ms(()=>{for(const E of i)E in S&&Je(C[E],S[E]);return()=>{Object.values(C).map(Ia)}},[S,C,k]),Ms(()=>{l(k,S)}),b.useImperativeHandle(y,Vf(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...bC([...r,...o,...i],S),children:w}):w})}),m=x=>{const y=b.useContext(a);return b.useCallback(w=>{Me(y[x],w)},[y,x])},f=x=>{const y=b.useContext(a)[x],w=b.useCallback(S=>Je(y,S),[y]);return b.useSyncExternalStore(w,()=>pt(y),()=>pt(y))},v=x=>{const y=b.useContext(a)[x],[w,S]=b.useState(qf(pt,y));return Ms(()=>Je(y,k=>{k!==w&&S(Vf(k))}),[y,w]),w},g=b.version.startsWith("18")?f:v;return{Component:h,useEmitter:(x,y)=>{const w=b.useContext(a)[x];Ms(()=>Je(w,y),[y,w])},useEmitterValue:g,usePublisher:m}}const kh=b.createContext(void 0),Eh=b.createContext(void 0),Ih=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Ha(e){return"self"in e}function wC(e){return"body"in e}function Nh(e,t,n,r=Pr,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(m=>{let f,v,g;const x=m.target;if(wC(x)||Ha(x)){const w=Ha(x)?x:x.defaultView;g=s?w.scrollX:w.scrollY,f=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,v=s?w.innerWidth:w.innerHeight}else g=s?x.scrollLeft:x.scrollTop,f=s?x.scrollWidth:x.scrollHeight,v=s?x.offsetWidth:x.offsetHeight;const y=()=>{e({scrollHeight:f,scrollTop:Math.max(g,0),viewportHeight:v})};m.suppressFlushSync?y():Ro.flushSync(y),a.current!==null&&(g===a.current||g<=0||g===f-v)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const m=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:m}),m.addEventListener("scroll",c,{passive:!0}),()=>{r(null),m.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(m){const f=i.current;if(!f||(s?"offsetWidth"in f&&f.offsetWidth===0:"offsetHeight"in f&&f.offsetHeight===0))return;const v=m.behavior==="smooth";let g,x,y;Ha(f)?(x=Math.max(Un(f.document.documentElement,s?"width":"height"),s?f.document.documentElement.scrollWidth:f.document.documentElement.scrollHeight),g=s?f.innerWidth:f.innerHeight,y=s?window.scrollX:window.scrollY):(x=f[s?"scrollWidth":"scrollHeight"],g=Un(f,s?"width":"height"),y=f[s?"scrollLeft":"scrollTop"]);const w=x-g;if(m.top=Math.ceil(Math.max(Math.min(w,m.top),0)),dh(g,x)||m.top===y){e({scrollHeight:x,scrollTop:y,viewportHeight:g}),v&&t(!0);return}v?(a.current=m.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(m={behavior:m.behavior,left:m.top}),f.scrollTo(m)}function h(m){s&&(m={behavior:m.behavior,left:m.top}),i.current.scrollBy(m)}return{scrollByCallback:h,scrollerRef:i,scrollToCallback:d}}const Ua="-webkit-sticky",Ah="sticky",Wa=Sh(()=>{if(typeof document>"u")return Ah;const e=document.createElement("div");return e.style.position=Ua,e.style.position===Ua?Ua:Ah});function Va(e){return e}const yC=qe(()=>{const e=se(a=>`Item ${a}`),t=se(a=>`Group ${a}`),n=se({}),r=se(Va),o=se("div"),s=se(Pr),i=(a,l=null)=>Mt(ne(n,pe(c=>c[a]),ot()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),SC=qe(([e,t])=>({...e,...t}),rt(Ch,yC)),CC=({height:e})=>u.jsx("div",{style:{height:e}}),TC={overflowAnchor:"none",position:Wa(),zIndex:1},jh={overflowAnchor:"none"},kC={...jh,display:"inline-block",height:"100%"},_h=b.memo(function({showTopList:e=!1}){const t=_e("listState"),n=rn("sizeRanges"),r=_e("useWindowScroll"),o=_e("customScrollParent"),s=rn("windowScrollContainerState"),i=rn("scrollContainerState"),a=o||r?s:i,l=_e("itemContent"),c=_e("context"),d=_e("groupContent"),h=_e("trackItemSizes"),m=_e("itemSize"),f=_e("log"),v=rn("gap"),g=_e("horizontalDirection"),{callbackRef:x}=BS(n,m,h,e?Pr:a,f,v,o,g,_e("skipAnimationFrameInResizeObserver")),[y,w]=b.useState(0);Ka("deviation",j=>{y!==j&&w(j)});const S=_e("EmptyPlaceholder"),k=_e("ScrollSeekPlaceholder")||CC,C=_e("ListComponent"),T=_e("ItemComponent"),E=_e("GroupComponent"),N=_e("computeItemKey"),R=_e("isSeeking"),O=_e("groupIndices").length>0,L=_e("alignToBottom"),q=_e("initialItemFinalLocationReached"),W=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:y!==0?y:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...q?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Ot(S,c)}):u.jsx(C,{...Ot(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:x,style:W,children:(e?t.topItems:t.items).map(j=>{const X=j.originalIndex,G=N(X+t.firstItemIndex,j.data,c);return R?b.createElement(k,{...Ot(k,c),height:j.size,index:j.index,key:G,type:j.type||"item",...j.type==="group"?{}:{groupIndex:j.groupIndex}}):j.type==="group"?b.createElement(E,{...Ot(E,c),"data-index":X,"data-item-index":j.index,"data-known-size":j.size,key:G,style:TC},d(j.index,c)):b.createElement(T,{...Ot(T,c),...AC(T,j.data),"data-index":X,"data-item-group-index":j.groupIndex,"data-item-index":j.index,"data-known-size":j.size,key:G,style:g?kC:jh},O?l(j.index,j.groupIndex,j.data,c):l(j.index,j.data,c))})})}),EC={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},IC={outline:"none",overflowX:"auto",position:"relative"},Os=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),NC={position:Wa(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function AC(e,t){return{item:typeof e=="string"?void 0:t}}const jC=b.memo(function(){const e=_e("HeaderComponent"),t=rn("headerHeight"),n=_e("HeaderFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),_C=b.memo(function(){const e=_e("FooterComponent"),t=rn("footerHeight"),n=_e("HeaderFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null});function Ph({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),h=t("horizontalDirection")||!1,{scrollByCallback:m,scrollerRef:f,scrollToCallback:v}=Nh(a,c,l,d,void 0,h);return e("scrollTo",v),e("scrollBy",m),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:f,style:{...h?IC:EC,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function Rh({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),h=t("deviation"),m=t("customScrollParent"),f=b.useRef(null),v=t("scrollerRef"),{scrollByCallback:g,scrollerRef:x,scrollToCallback:y}=Nh(a,c,l,v,m);return Ih(()=>{var w;return x.current=m||((w=f.current)==null?void 0:w.ownerDocument.defaultView),()=>{x.current=null}},[x,m]),e("windowScrollTo",y),e("scrollBy",g),u.jsx(l,{ref:f,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+h}:{}},...i,...Ot(l,s),children:r})})}const PC=({children:e})=>{const t=b.useContext(kh),n=rn("viewportHeight"),r=rn("fixedItemHeight"),o=_e("alignToBottom"),s=_e("horizontalDirection"),i=b.useMemo(()=>Kf(n,l=>Un(l,s?"width":"height")),[n,s]),a=or(i,!0,_e("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Os(o),children:e})},RC=({children:e})=>{const t=b.useContext(kh),n=rn("windowViewportRect"),r=rn("fixedItemHeight"),o=_e("customScrollParent"),s=Jf(n,o,_e("skipAnimationFrameInResizeObserver")),i=_e("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:Os(i),children:e})},MC=({children:e})=>{const t=_e("TopItemListComponent")||"div",n=_e("headerHeight"),r={...NC,marginTop:`${n}px`},o=_e("context");return u.jsx(t,{style:r,...Ot(t,o),children:e})},OC=b.memo(function(e){const t=_e("useWindowScroll"),n=_e("topItemsIndexes").length>0,r=_e("customScrollParent"),o=_e("context");return u.jsxs(r||t?$C:LC,{...e,context:o,children:[n&&u.jsx(MC,{children:u.jsx(_h,{showTopList:!0})}),u.jsxs(r||t?RC:PC,{children:[u.jsx(jC,{}),u.jsx(_h,{}),u.jsx(_C,{})]})]})}),{Component:DC,useEmitter:Ka,useEmitterValue:_e,usePublisher:rn}=Th(SC,{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"}},OC),LC=Ph({useEmitter:Ka,useEmitterValue:_e,usePublisher:rn}),$C=Rh({useEmitter:Ka,useEmitterValue:_e,usePublisher:rn}),FC=DC;rt(Ch,qe(()=>{const e=se(c=>u.jsxs("td",{children:["Item $",c]})),t=se(null),n=se(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=se(null),o=se(null),s=se({}),i=se(Va),a=se(Pr),l=(c,d=null)=>Mt(ne(s,pe(h=>h[c]),ot()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Wa();const Mh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},BC={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Oh,floor:Ds,max:Co,min:qa,round:Dh}=Math;function Lh(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function zC(e){return{...BC,items:e}}function Ls(e,t){return e&&e.width===t.width&&e.height===t.height}function HC(e,t){return e&&e.column===t.column&&e.row===t.row}const UC=qe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:h},m,f,{didMount:v,propsReady:g},{customScrollParent:x,useWindowScroll:y,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k},C])=>{const T=se(0),E=se(0),N=se(Mh),R=se({height:0,width:0}),O=se({height:0,width:0}),L=He(),q=He(),W=se(0),j=se(null),X=se({column:0,row:0}),G=He(),B=He(),M=se(!1),I=se(0),K=se(!0),J=se(!1),P=se(!1);Je(ne(v,$e(I),Ne(([D,Z])=>!!Z)),()=>{Me(K,!1)}),Je(ne(xt(v,K,O,R,I,J),Ne(([D,Z,ee,Q,,H])=>D&&!Z&&ee.height!==0&&Q.height!==0&&!H)),([,,,,D])=>{Me(J,!0),La(1,()=>{Me(L,D)}),fn(ne(c),()=>{Me(t,[0,0]),Me(K,!0)})}),be(ne(B,Ne(D=>D!=null&&D.scrollTop>0),Tn(0)),E),Je(ne(v,$e(B),Ne(([,D])=>D!=null)),([,D])=>{D&&(Me(R,D.viewport),Me(O,D.item),Me(X,D.gap),D.scrollTop>0&&(Me(M,!0),fn(ne(c,rr(1)),Z=>{Me(M,!1)}),Me(l,{top:D.scrollTop})))}),be(ne(R,pe(({height:D})=>D)),h),be(ne(xt(Ee(R,Ls),Ee(O,Ls),Ee(X,(D,Z)=>D&&D.column===Z.column&&D.row===Z.row),Ee(c)),pe(([D,Z,ee,Q])=>({gap:ee,item:Z,scrollTop:Q,viewport:D}))),G),be(ne(xt(Ee(T),r,Ee(X,HC),Ee(O,Ls),Ee(R,Ls),Ee(j),Ee(E),Ee(M),Ee(K),Ee(I)),Ne(([,,,,,,,D])=>!D),pe(([D,[Z,ee],Q,H,ae,ie,ge,,ye,Te])=>{const{column:Ae,row:ke}=Q,{height:st,width:vt}=H,{width:kt}=ae;if(ge===0&&(D===0||kt===0))return Mh;if(vt===0){const At=$a(Te,D),wt=At+Math.max(ge-1,0);return zC(Lh(At,wt,ie))}const Ve=$h(kt,vt,Ae);let ze,Ke;ye?Z===0&&ee===0&&ge>0?(ze=0,Ke=ge-1):(ze=Ve*Ds((Z+ke)/(st+ke)),Ke=Ve*Oh((ee+ke)/(st+ke))-1,Ke=qa(D-1,Co(Ke,Ve-1)),ze=qa(Ke,Co(0,ze))):(ze=0,Ke=-1);const Oe=Lh(ze,Ke,ie),{bottom:Ue,top:dt}=Fh(ae,Q,H,Oe),Nt=Oh(D/Ve),nt=Nt*st+(Nt-1)*ke-Ue;return{bottom:Ue,itemHeight:st,items:Oe,itemWidth:vt,offsetBottom:nt,offsetTop:dt,top:dt}})),N),be(ne(j,Ne(D=>D!==null),pe(D=>D.length)),T),be(ne(xt(R,O,N,X),Ne(([D,Z,{items:ee}])=>ee.length>0&&Z.height!==0&&D.height!==0),pe(([D,Z,{items:ee},Q])=>{const{bottom:H,top:ae}=Fh(D,Q,Z,ee);return[ae,H]}),ot(go)),t);const _=se(!1);be(ne(c,$e(_),pe(([D,Z])=>Z||D!==0)),_);const z=en(ne(xt(N,T),Ne(([{items:D}])=>D.length>0),$e(_),Ne(([[D,Z],ee])=>{const Q=D.items[D.items.length-1].index===Z-1;return(ee||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===Z)&&Q}),pe(([[,D]])=>D-1),ot())),F=en(ne(Ee(N),Ne(({items:D})=>D.length>0&&D[0].index===0),Tn(0),ot())),re=en(ne(Ee(N),$e(M),Ne(([{items:D},Z])=>D.length>0&&!Z),pe(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ot(oh),jn(0)));be(re,f.scrollSeekRangeChanged),be(ne(L,$e(R,O,T,X),pe(([D,Z,ee,Q,H])=>{const ae=uh(D),{align:ie,behavior:ge,offset:ye}=ae;let Te=ae.index;Te==="LAST"&&(Te=Q-1),Te=Co(0,Te,qa(Q-1,Te));let Ae=Ga(Z,H,ee,Te);return ie==="end"?Ae=Dh(Ae-Z.height+ee.height):ie==="center"&&(Ae=Dh(Ae-Z.height/2+ee.height/2)),ye&&(Ae+=ye),{behavior:ge,top:Ae}})),l);const V=Mt(ne(N,pe(D=>D.offsetBottom+D.bottom)),0);return be(ne(k,pe(D=>({height:D.visibleHeight,width:D.visibleWidth}))),R),{customScrollParent:x,data:j,deviation:W,footerHeight:o,gap:X,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:O,overscan:n,restoreStateFrom:B,scrollBy:i,scrollContainerState:a,scrollHeight:q,scrollTo:l,scrollToIndex:L,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:y,viewportDimensions:R,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k,...f,gridState:N,horizontalDirection:P,initialTopMostItemIndex:I,totalListHeight:V,...m,endReached:z,propsReady:g,rangeChanged:re,startReached:F,stateChanged:G,stateRestoreInProgress:M,...C}},rt(Fa,Bt,So,yh,Wn,za,Hn));function $h(e,t,n){return Co(1,Ds((e+n)/(Ds(t)+n)))}function Fh(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ga(e,t,n,r[0].index);return{bottom:Ga(e,t,n,r[r.length-1].index)+o,top:s}}function Ga(e,t,n,r){const o=$h(e.width,n.width,t.column),s=Ds(r/o),i=s*n.height+Co(0,s-1)*t.row;return i>0?i+t.row:i}const WC=qe(()=>{const e=se(h=>`Item ${h}`),t=se({}),n=se(null),r=se("virtuoso-grid-item"),o=se("virtuoso-grid-list"),s=se(Va),i=se("div"),a=se(Pr),l=(h,m=null)=>Mt(ne(t,pe(f=>f[h]),ot()),m),c=se(!1),d=se(!1);return be(Ee(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),VC=qe(([e,t])=>({...e,...t}),rt(UC,WC)),KC=b.memo(function(){const e=at("gridState"),t=at("listClassName"),n=at("itemClassName"),r=at("itemContent"),o=at("computeItemKey"),s=at("isSeeking"),i=on("scrollHeight"),a=at("ItemComponent"),l=at("ListComponent"),c=at("ScrollSeekPlaceholder"),d=at("context"),h=on("itemDimensions"),m=on("gap"),f=at("log"),v=at("stateRestoreInProgress"),g=on("reportReadyState"),x=or(b.useMemo(()=>y=>{const w=y.parentElement.parentElement.scrollHeight;i(w);const S=y.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();h({height:k,width:C})}m({column:zh("column-gap",getComputedStyle(y).columnGap,f),row:zh("row-gap",getComputedStyle(y).rowGap,f)})},[i,h,m,f]),!0,!1);return Ih(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),v?null:u.jsx(l,{className:t,ref:x,...Ot(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(y=>{const w=o(y.index,y.data,d);return s?u.jsx(c,{...Ot(c,d),height:e.itemHeight,index:y.index,width:e.itemWidth},w):b.createElement(a,{...Ot(a,d),className:n,"data-index":y.index,key:w},r(y.index,y.data,d))})})}),qC=b.memo(function(){const e=at("HeaderComponent"),t=on("headerHeight"),n=at("headerFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,!1),o=at("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),GC=b.memo(function(){const e=at("FooterComponent"),t=on("footerHeight"),n=at("headerFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,!1),o=at("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),YC=({children:e})=>{const t=b.useContext(Eh),n=on("itemDimensions"),r=on("viewportDimensions"),o=or(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:Os(!1),children:e})},XC=({children:e})=>{const t=b.useContext(Eh),n=on("windowViewportRect"),r=on("itemDimensions"),o=at("customScrollParent"),s=Jf(n,o,!1);return b.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:Os(!1),children:e})},JC=b.memo(function({...e}){const t=at("useWindowScroll"),n=at("customScrollParent"),r=n||t?QC:ZC,o=n||t?XC:YC,s=at("context");return u.jsx(r,{...e,...Ot(r,s),children:u.jsxs(o,{children:[u.jsx(qC,{}),u.jsx(KC,{}),u.jsx(GC,{})]})})}),{useEmitter:Bh,useEmitterValue:at,usePublisher:on}=Th(VC,{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"}},JC),ZC=Ph({useEmitter:Bh,useEmitterValue:at,usePublisher:on}),QC=Rh({useEmitter:Bh,useEmitterValue:at,usePublisher:on});function zh(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Wt.WARN),t==="normal"?0:parseInt(t??"0",10)}var $s="Dialog",[Hh,jN]=cn($s),[eT,pn]=Hh($s),Uh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=p.useRef(null),l=p.useRef(null),[c,d]=Dn({prop:r,defaultProp:o??!1,onChange:s,caller:$s});return u.jsx(eT,{scope:t,triggerRef:a,contentRef:l,contentId:Rt(),titleId:Rt(),descriptionId:Rt(),open:c,onOpenChange:d,onOpenToggle:p.useCallback(()=>d(h=>!h),[d]),modal:i,children:n})};Uh.displayName=$s;var Wh="DialogTrigger",Vh=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Wh,n),s=Le(t,o.triggerRef);return u.jsx(ve.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ja(o.open),...r,ref:s,onClick:ce(e.onClick,o.onOpenToggle)})});Vh.displayName=Wh;var Ya="DialogPortal",[tT,Kh]=Hh(Ya,{forceMount:void 0}),qh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=pn(Ya,t);return u.jsx(tT,{scope:t,forceMount:n,children:p.Children.map(r,i=>u.jsx(Ut,{present:n||s.open,children:u.jsx(so,{asChild:!0,container:o,children:i})}))})};qh.displayName=Ya;var Fs="DialogOverlay",Gh=p.forwardRef((e,t)=>{const n=Kh(Fs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=pn(Fs,e.__scopeDialog);return s.modal?u.jsx(Ut,{present:r||s.open,children:u.jsx(rT,{...o,ref:t})}):null});Gh.displayName=Fs;var nT=Yt.createSlot("DialogOverlay.RemoveScroll"),rT=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Fs,n);return u.jsx(xs,{as:nT,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(ve.div,{"data-state":Ja(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ar="DialogContent",Yh=p.forwardRef((e,t)=>{const n=Kh(ar,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=pn(ar,e.__scopeDialog);return u.jsx(Ut,{present:r||s.open,children:s.modal?u.jsx(oT,{...o,ref:t}):u.jsx(sT,{...o,ref:t})})});Yh.displayName=ar;var oT=p.forwardRef((e,t)=>{const n=pn(ar,e.__scopeDialog),r=p.useRef(null),o=Le(t,n.contentRef,r);return p.useEffect(()=>{const s=r.current;if(s)return fa(s)},[]),u.jsx(Xh,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ce(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ce(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault())})}),sT=p.forwardRef((e,t)=>{const n=pn(ar,e.__scopeDialog),r=p.useRef(!1),o=p.useRef(!1);return u.jsx(Xh,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Xh=p.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=pn(ar,n),l=p.useRef(null),c=Le(t,l);return Ui(),u.jsxs(u.Fragment,{children:[u.jsx(Zo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(yr,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ja(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(iT,{titleId:a.titleId}),u.jsx(lT,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Xa="DialogTitle",Jh=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Xa,n);return u.jsx(ve.h2,{id:o.titleId,...r,ref:t})});Jh.displayName=Xa;var Zh="DialogDescription",Qh=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Zh,n);return u.jsx(ve.p,{id:o.descriptionId,...r,ref:t})});Qh.displayName=Zh;var ep="DialogClose",tp=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(ep,n);return u.jsx(ve.button,{type:"button",...r,ref:t,onClick:ce(e.onClick,()=>o.onOpenChange(!1))})});tp.displayName=ep;function Ja(e){return e?"open":"closed"}var np="DialogTitleWarning",[_N,rp]=Cb(np,{contentName:ar,titleName:Xa,docsSlug:"dialog"}),iT=({titleId:e})=>{const t=rp(np),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
79
|
+
`)},c0=0,jr=[];function u0(e){var t=p.useRef([]),n=p.useRef([0,0]),r=p.useRef(),o=p.useState(c0++)[0],s=p.useState(Bd)[0],i=p.useRef(e);p.useEffect(function(){i.current=e},[e]),p.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=_y([e.lockRef.current],(e.shards||[]).map(qd),!0).filter(Boolean);return g.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=p.useCallback(function(g,x){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var y=gs(g),w=n.current,S="deltaX"in g?g.deltaX:w[0]-y[0],k="deltaY"in g?g.deltaY:w[1]-y[1],C,T=g.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in g&&E==="h"&&T.type==="range")return!1;var N=Ud(E,T);if(!N)return!0;if(N?C=E:(C=E==="v"?"h":"v",N=Ud(E,T)),!N)return!1;if(!r.current&&"changedTouches"in g&&(S||k)&&(r.current=C),!C)return!0;var R=r.current||C;return i0(R,x,g,R==="h"?S:k)},[]),l=p.useCallback(function(g){var x=g;if(!(!jr.length||jr[jr.length-1]!==s)){var y="deltaY"in x?Kd(x):gs(x),w=t.current.filter(function(C){return C.name===x.type&&(C.target===x.target||x.target===C.shadowParent)&&a0(C.delta,y)})[0];if(w&&w.should){x.cancelable&&x.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(qd).filter(Boolean).filter(function(C){return C.contains(x.target)}),k=S.length>0?a(x,S[0]):!i.current.noIsolation;k&&x.cancelable&&x.preventDefault()}}},[]),c=p.useCallback(function(g,x,y,w){var S={name:g,delta:x,target:y,should:w,shadowParent:d0(y)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=p.useCallback(function(g){n.current=gs(g),r.current=void 0},[]),h=p.useCallback(function(g){c(g.type,Kd(g),g.target,a(g,e.lockRef.current))},[]),m=p.useCallback(function(g){c(g.type,gs(g),g.target,a(g,e.lockRef.current))},[]);p.useEffect(function(){return jr.push(s),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:m}),document.addEventListener("wheel",l,Ar),document.addEventListener("touchmove",l,Ar),document.addEventListener("touchstart",d,Ar),function(){jr=jr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Ar),document.removeEventListener("touchmove",l,Ar),document.removeEventListener("touchstart",d,Ar)}},[]);var f=e.removeScrollBar,v=e.inert;return p.createElement(p.Fragment,null,v?p.createElement(s,{styles:l0(o)}):null,f?p.createElement(Qy,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function d0(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const f0=By(Fd,u0);var xs=p.forwardRef(function(e,t){return p.createElement(ps,Cn({},e,{ref:t,sideCar:f0}))});xs.classNames=ps.classNames;var xa=["Enter"," "],h0=["ArrowDown","PageUp","Home"],Gd=["ArrowUp","PageDown","End"],p0=[...h0,...Gd],m0={ltr:[...xa,"ArrowRight"],rtl:[...xa,"ArrowLeft"]},g0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ao="Menu",[lo,x0,v0]=Xo(ao),[tr,Yd]=cn(ao,[v0,Er,jd]),vs=Er(),Xd=jd(),[b0,nr]=tr(ao),[w0,co]=tr(ao),Jd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=vs(t),[l,c]=p.useState(null),d=p.useRef(!1),h=ht(s),m=Jo(o);return p.useEffect(()=>{const f=()=>{d.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},v=()=>d.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),u.jsx(sa,{...a,children:u.jsx(b0,{scope:t,open:n,onOpenChange:h,content:l,onContentChange:c,children:u.jsx(w0,{scope:t,onClose:p.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:d,dir:m,modal:i,children:r})})})};Jd.displayName=ao;var y0="MenuAnchor",va=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=vs(n);return u.jsx(ia,{...o,...r,ref:t})});va.displayName=y0;var ba="MenuPortal",[S0,Zd]=tr(ba,{forceMount:void 0}),Qd=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=nr(ba,t);return u.jsx(S0,{scope:t,forceMount:n,children:u.jsx(Ut,{present:n||s.open,children:u.jsx(so,{asChild:!0,container:o,children:r})})})};Qd.displayName=ba;var nn="MenuContent",[C0,wa]=tr(nn),ef=p.forwardRef((e,t)=>{const n=Zd(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=nr(nn,e.__scopeMenu),i=co(nn,e.__scopeMenu);return u.jsx(lo.Provider,{scope:e.__scopeMenu,children:u.jsx(Ut,{present:r||s.open,children:u.jsx(lo.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(T0,{...o,ref:t}):u.jsx(k0,{...o,ref:t})})})})}),T0=p.forwardRef((e,t)=>{const n=nr(nn,e.__scopeMenu),r=p.useRef(null),o=Le(t,r);return p.useEffect(()=>{const s=r.current;if(s)return fa(s)},[]),u.jsx(ya,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),k0=p.forwardRef((e,t)=>{const n=nr(nn,e.__scopeMenu);return u.jsx(ya,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),E0=Yt.createSlot("MenuContent.ScrollLock"),ya=p.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,onDismiss:f,disableOutsideScroll:v,...g}=e,x=nr(nn,n),y=co(nn,n),w=vs(n),S=Xd(n),k=x0(n),[C,T]=p.useState(null),E=p.useRef(null),N=Le(t,E,x.onContentChange),R=p.useRef(0),O=p.useRef(""),L=p.useRef(0),q=p.useRef(null),W=p.useRef("right"),j=p.useRef(0),X=v?xs:p.Fragment,G=v?{as:E0,allowPinchZoom:!0}:void 0,B=I=>{var V,D;const K=O.current+I,J=k().filter(Z=>!Z.disabled),P=document.activeElement,_=(V=J.find(Z=>Z.ref.current===P))==null?void 0:V.textValue,z=J.map(Z=>Z.textValue),F=$0(z,K,_),re=(D=J.find(Z=>Z.textValue===F))==null?void 0:D.ref.current;(function Z(ee){O.current=ee,window.clearTimeout(R.current),ee!==""&&(R.current=window.setTimeout(()=>Z(""),1e3))})(K),re&&setTimeout(()=>re.focus())};p.useEffect(()=>()=>window.clearTimeout(R.current),[]),Ui();const M=p.useCallback(I=>{var J,P;return W.current===((J=q.current)==null?void 0:J.side)&&B0(I,(P=q.current)==null?void 0:P.area)},[]);return u.jsx(C0,{scope:n,searchRef:O,onItemEnter:p.useCallback(I=>{M(I)&&I.preventDefault()},[M]),onItemLeave:p.useCallback(I=>{var K;M(I)||((K=E.current)==null||K.focus(),T(null))},[M]),onTriggerLeave:p.useCallback(I=>{M(I)&&I.preventDefault()},[M]),pointerGraceTimerRef:L,onPointerGraceIntentChange:p.useCallback(I=>{q.current=I},[]),children:u.jsx(X,{...G,children:u.jsx(Zo,{asChild:!0,trapped:o,onMountAutoFocus:ce(s,I=>{var K;I.preventDefault(),(K=E.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(yr,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,onDismiss:f,children:u.jsx(Ey,{asChild:!0,...S,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ce(l,I=>{y.isUsingKeyboardRef.current||I.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(aa,{role:"menu","aria-orientation":"vertical","data-state":vf(x.open),"data-radix-menu-content":"",dir:y.dir,...w,...g,ref:N,style:{outline:"none",...g.style},onKeyDown:ce(g.onKeyDown,I=>{const J=I.target.closest("[data-radix-menu-content]")===I.currentTarget,P=I.ctrlKey||I.altKey||I.metaKey,_=I.key.length===1;J&&(I.key==="Tab"&&I.preventDefault(),!P&&_&&B(I.key));const z=E.current;if(I.target!==z||!p0.includes(I.key))return;I.preventDefault();const re=k().filter(V=>!V.disabled).map(V=>V.ref.current);Gd.includes(I.key)&&re.reverse(),D0(re)}),onBlur:ce(e.onBlur,I=>{I.currentTarget.contains(I.target)||(window.clearTimeout(R.current),O.current="")}),onPointerMove:ce(e.onPointerMove,fo(I=>{const K=I.target,J=j.current!==I.clientX;if(I.currentTarget.contains(K)&&J){const P=I.clientX>j.current?"right":"left";W.current=P,j.current=I.clientX}}))})})})})})})});ef.displayName=nn;var I0="MenuGroup",Sa=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(ve.div,{role:"group",...r,ref:t})});Sa.displayName=I0;var N0="MenuLabel",tf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});tf.displayName=N0;var bs="MenuItem",nf="menu.itemSelect",ws=p.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=p.useRef(null),i=co(bs,e.__scopeMenu),a=wa(bs,e.__scopeMenu),l=Le(t,s),c=p.useRef(!1),d=()=>{const h=s.current;if(!n&&h){const m=new CustomEvent(nf,{bubbles:!0,cancelable:!0});h.addEventListener(nf,f=>r==null?void 0:r(f),{once:!0}),Bi(h,m),m.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(rf,{...o,ref:l,disabled:n,onClick:ce(e.onClick,d),onPointerDown:h=>{var m;(m=e.onPointerDown)==null||m.call(e,h),c.current=!0},onPointerUp:ce(e.onPointerUp,h=>{var m;c.current||(m=h.currentTarget)==null||m.click()}),onKeyDown:ce(e.onKeyDown,h=>{const m=a.searchRef.current!=="";n||m&&h.key===" "||xa.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});ws.displayName=bs;var rf=p.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=wa(bs,n),a=Xd(n),l=p.useRef(null),c=Le(t,l),[d,h]=p.useState(!1),[m,f]=p.useState("");return p.useEffect(()=>{const v=l.current;v&&f((v.textContent??"").trim())},[s.children]),u.jsx(lo.ItemSlot,{scope:n,disabled:r,textValue:o??m,children:u.jsx(Iy,{asChild:!0,...a,focusable:!r,children:u.jsx(ve.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ce(e.onPointerMove,fo(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ce(e.onPointerLeave,fo(v=>i.onItemLeave(v))),onFocus:ce(e.onFocus,()=>h(!0)),onBlur:ce(e.onBlur,()=>h(!1))})})})}),A0="MenuCheckboxItem",of=p.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(uf,{scope:e.__scopeMenu,checked:n,children:u.jsx(ws,{role:"menuitemcheckbox","aria-checked":ys(n)?"mixed":n,...o,ref:t,"data-state":Ta(n),onSelect:ce(o.onSelect,()=>r==null?void 0:r(ys(n)?!0:!n),{checkForDefaultPrevented:!1})})})});of.displayName=A0;var sf="MenuRadioGroup",[j0,_0]=tr(sf,{value:void 0,onValueChange:()=>{}}),af=p.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=ht(r);return u.jsx(j0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Sa,{...o,ref:t})})});af.displayName=sf;var lf="MenuRadioItem",cf=p.forwardRef((e,t)=>{const{value:n,...r}=e,o=_0(lf,e.__scopeMenu),s=n===o.value;return u.jsx(uf,{scope:e.__scopeMenu,checked:s,children:u.jsx(ws,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ta(s),onSelect:ce(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});cf.displayName=lf;var Ca="MenuItemIndicator",[uf,P0]=tr(Ca,{checked:!1}),df=p.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=P0(Ca,n);return u.jsx(Ut,{present:r||ys(s.checked)||s.checked===!0,children:u.jsx(ve.span,{...o,ref:t,"data-state":Ta(s.checked)})})});df.displayName=Ca;var R0="MenuSeparator",ff=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(ve.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});ff.displayName=R0;var M0="MenuArrow",hf=p.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=vs(n);return u.jsx(la,{...o,...r,ref:t})});hf.displayName=M0;var O0="MenuSub",[IN,pf]=tr(O0),uo="MenuSubTrigger",mf=p.forwardRef((e,t)=>{const n=nr(uo,e.__scopeMenu),r=co(uo,e.__scopeMenu),o=pf(uo,e.__scopeMenu),s=wa(uo,e.__scopeMenu),i=p.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=p.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return p.useEffect(()=>d,[d]),p.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),u.jsx(va,{asChild:!0,...c,children:u.jsx(rf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":vf(n.open),...e,ref:On(t,o.onTriggerChange),onClick:h=>{var m;(m=e.onClick)==null||m.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ce(e.onPointerMove,fo(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ce(e.onPointerLeave,fo(h=>{var f,v;d();const m=(f=n.content)==null?void 0:f.getBoundingClientRect();if(m){const g=(v=n.content)==null?void 0:v.dataset.side,x=g==="right",y=x?-5:5,w=m[x?"left":"right"],S=m[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+y,y:h.clientY},{x:w,y:m.top},{x:S,y:m.top},{x:S,y:m.bottom},{x:w,y:m.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ce(e.onKeyDown,h=>{var f;const m=s.searchRef.current!=="";e.disabled||m&&h.key===" "||m0[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});mf.displayName=uo;var gf="MenuSubContent",xf=p.forwardRef((e,t)=>{const n=Zd(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=nr(nn,e.__scopeMenu),i=co(nn,e.__scopeMenu),a=pf(gf,e.__scopeMenu),l=p.useRef(null),c=Le(t,l);return u.jsx(lo.Provider,{scope:e.__scopeMenu,children:u.jsx(Ut,{present:r||s.open,children:u.jsx(lo.Slot,{scope:e.__scopeMenu,children:u.jsx(ya,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ce(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ce(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ce(e.onKeyDown,d=>{var f;const h=d.currentTarget.contains(d.target),m=g0[i.dir].includes(d.key);h&&m&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),d.preventDefault())})})})})})});xf.displayName=gf;function vf(e){return e?"open":"closed"}function ys(e){return e==="indeterminate"}function Ta(e){return ys(e)?"indeterminate":e?"checked":"unchecked"}function D0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function L0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function $0(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=L0(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function F0(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,h=l.x,m=l.y;d>r!=m>r&&n<(h-c)*(r-d)/(m-d)+c&&(o=!o)}return o}function B0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return F0(n,t)}function fo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var z0=Jd,H0=va,U0=Qd,W0=ef,V0=Sa,K0=tf,q0=ws,G0=of,Y0=af,X0=cf,J0=df,Z0=ff,Q0=hf,eS=mf,tS=xf,Ss="DropdownMenu",[nS,NN]=cn(Ss,[Yd]),Ft=Yd(),[rS,bf]=nS(Ss),wf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ft(t),c=p.useRef(null),[d,h]=Dn({prop:o,defaultProp:s??!1,onChange:i,caller:Ss});return u.jsx(rS,{scope:t,triggerId:Rt(),triggerRef:c,contentId:Rt(),open:d,onOpenChange:h,onOpenToggle:p.useCallback(()=>h(m=>!m),[h]),modal:a,children:u.jsx(z0,{...l,open:d,onOpenChange:h,dir:r,modal:a,children:n})})};wf.displayName=Ss;var yf="DropdownMenuTrigger",Sf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=bf(yf,n),i=Ft(n);return u.jsx(H0,{asChild:!0,...i,children:u.jsx(ve.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:On(t,s.triggerRef),onPointerDown:ce(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ce(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Sf.displayName=yf;var oS="DropdownMenuPortal",Cf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ft(t);return u.jsx(U0,{...r,...n})};Cf.displayName=oS;var Tf="DropdownMenuContent",kf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bf(Tf,n),s=Ft(n),i=p.useRef(!1);return u.jsx(W0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ce(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ce(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});kf.displayName=Tf;var sS="DropdownMenuGroup",iS=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(V0,{...o,...r,ref:t})});iS.displayName=sS;var aS="DropdownMenuLabel",Ef=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(K0,{...o,...r,ref:t})});Ef.displayName=aS;var lS="DropdownMenuItem",If=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(q0,{...o,...r,ref:t})});If.displayName=lS;var cS="DropdownMenuCheckboxItem",Nf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(G0,{...o,...r,ref:t})});Nf.displayName=cS;var uS="DropdownMenuRadioGroup",dS=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Y0,{...o,...r,ref:t})});dS.displayName=uS;var fS="DropdownMenuRadioItem",Af=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(X0,{...o,...r,ref:t})});Af.displayName=fS;var hS="DropdownMenuItemIndicator",jf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(J0,{...o,...r,ref:t})});jf.displayName=hS;var pS="DropdownMenuSeparator",_f=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Z0,{...o,...r,ref:t})});_f.displayName=pS;var mS="DropdownMenuArrow",gS=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(Q0,{...o,...r,ref:t})});gS.displayName=mS;var xS="DropdownMenuSubTrigger",Pf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(eS,{...o,...r,ref:t})});Pf.displayName=xS;var vS="DropdownMenuSubContent",Rf=p.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return u.jsx(tS,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Rf.displayName=vS;var bS=wf,wS=Sf,yS=Cf,Mf=kf,Of=Ef,Df=If,Lf=Nf,$f=Af,Ff=jf,Bf=_f,zf=Pf,Hf=Rf;const Cs=bS,Ts=wS,SS=p.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(zf,{ref:o,className:oe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(ue.ChevronRight,{className:"ml-auto h-4 w-4"})]}));SS.displayName=zf.displayName;const CS=p.forwardRef(({className:e,...t},n)=>u.jsx(Hf,{ref:n,className:oe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));CS.displayName=Hf.displayName;const ho=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(yS,{children:u.jsx(Mf,{ref:r,sideOffset:t,className:oe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));ho.displayName=Mf.displayName;const Bn=p.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Df,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Bn.displayName=Df.displayName;const TS=p.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(Lf,{ref:o,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Ff,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),t]}));TS.displayName=Lf.displayName;const kS=p.forwardRef(({className:e,children:t,...n},r)=>u.jsxs($f,{ref:r,className:oe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Ff,{children:u.jsx(ue.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));kS.displayName=$f.displayName;const ES=p.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Of,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ES.displayName=Of.displayName;const IS=p.forwardRef(({className:e,...t},n)=>u.jsx(Bf,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));IS.displayName=Bf.displayName;const ka=p.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:oe("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));ka.displayName="Textarea";const NS=1e4;function Uf({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=NS,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:h="",textareaClassName:m="",allowEmptySend:f=!1,validate:v,onValidationError:g}){const x=i!==void 0,[y,w]=b.useState(e),S=(x?i:y)??"",[k,C]=b.useTransition(),T=b.useRef(null),E=b.useRef(0),N=b.useRef(null),R=b.useRef("");b.useEffect(()=>{x||(w(e??""),N.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,x]);const[O,L]=b.useState(null),q=b.useCallback(_=>_.length>s?`Message too long (${_.length}/${s} characters)`:null,[s]),W=b.useMemo(()=>v??q,[v,q]),j=b.useCallback(_=>{const z=W(_);return L(z),g==null||g(z),R.current=_,z},[W,g]),X=b.useCallback(()=>{const _=T.current;_&&(_.style.height="auto",_.style.height=`${_.scrollHeight}px`)},[]);b.useEffect(()=>{X()},[X,S]),b.useEffect(()=>{if(!O)return;const _=(S??"").trim();R.current!==_&&j(_)},[S,O,j]);const G=b.useCallback((_,{fromUser:z})=>{x||w(_),z&&(a==null||a(_))},[x,a]),B=b.useCallback(async _=>{_&&_.preventDefault();const z=(S??"").trim();if(!z&&!f||j(z))return;const F=++E.current;N.current={id:F,shouldClear:!0},C(()=>{var re,V,D;try{const Z=l(z);Z&&typeof Z.then=="function"?Z.then(()=>{var ee,Q;((ee=N.current)==null?void 0:ee.id)===F&&N.current.shouldClear&&(x||(w(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((Q=N.current)==null?void 0:Q.id)===F&&(N.current=null)}).catch(()=>{var ee;((ee=N.current)==null?void 0:ee.id)===F&&(N.current=null)}):(((re=N.current)==null?void 0:re.id)===F&&N.current.shouldClear&&(x||(w(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((V=N.current)==null?void 0:V.id)===F&&(N.current=null))}catch{((D=N.current)==null?void 0:D.id)===F&&(N.current=null)}})},[S,l,f,x,a,j]),M=b.useCallback(_=>{const z=_.target.value;G(z,{fromUser:!0}),N.current&&(N.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`),O&&j(z.trim())},[G,j,O]),I=b.useCallback(_=>{_.key==="Enter"&&!_.shiftKey?(_.preventDefault(),B()):_.key==="Escape"&&t&&(_.preventDefault(),c==null||c())},[B,t,c]),P=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${m}`;return u.jsx("form",{onSubmit:_=>void B(_),className:`w-full ${h}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsxs("div",{className:"flex-1",children:[u.jsx(ka,{ref:T,value:S,onChange:M,onKeyDown:I,placeholder:t?"Edit your message...":n,className:P,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"}),O&&u.jsx("p",{className:"mt-1 text-xs text-destructive font-medium",children:O})]}),u.jsx("div",{children:r?u.jsx(Ze,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ue.Square,{size:16})}):u.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!S.trim()&&!f||k,children:u.jsx(ue.Send,{size:16})})})]})})}const AS=b.memo(Uf),ks=0,zn=1,_r=2,Wf=4;function Vf(e){return()=>e}function jS(e){e()}function Kf(e,t){return n=>e(t(n))}function qf(e,t){return()=>e(t)}function _S(e,t){return n=>e(t,n)}function Ea(e){return e!==void 0}function PS(...e){return()=>{e.map(jS)}}function Pr(){}function Es(e,t){return t(e),e}function RS(e,t){return t(e)}function rt(...e){return e}function Je(e,t){return e(zn,t)}function Me(e,t){e(ks,t)}function Ia(e){e(_r)}function pt(e){return e(Wf)}function be(e,t){return Je(e,_S(t,ks))}function fn(e,t){const n=e(zn,r=>{n(),t(r)});return n}function Gf(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Yf(e,t){return e===t}function ot(e=Yf){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ne(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>Kf(t,e)}function Tn(e){return t=>()=>{t(e)}}function ne(e,...t){const n=MS(...t);return(r,o)=>{switch(r){case _r:Ia(e);return;case zn:return Je(e,n(o))}}}function kn(e,t){return n=>r=>{n(t=e(t,r))}}function rr(e){return t=>n=>{e>0?e--:t(n)}}function _n(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Je(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function MS(...e){return t=>e.reduceRight(RS,t)}function OS(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case zn:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),Pr);case _r:r(),n=null;return}}}function se(e){let t=e;const n=He();return(r,o)=>{switch(r){case ks:t=o;break;case zn:{o(t);break}case Wf:return t}return n(r,o)}}function Mt(e,t){return Es(se(t),n=>be(e,n))}function He(){const e=[];return(t,n)=>{switch(t){case ks:e.slice().forEach(r=>{r(n)});return;case _r:e.splice(0,e.length);return;case zn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function en(e){return Es(He(),t=>be(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:DS(),singleton:n}}const DS=()=>Symbol();function LS(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function xt(...e){const t=He(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Je(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case _r:{Ia(t);return}case zn:return r===o&&i(n),Je(t,i)}}}function Ee(e,t=Yf){return ne(e,ot(t))}function Na(...e){return function(t,n){switch(t){case _r:return;case zn:return PS(...e.map(r=>Je(r,n)))}}}var Wt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Wt||{});const $S={0:"debug",3:"error",1:"log",2:"warn"},FS=()=>typeof globalThis>"u"?window:globalThis,Hn=qe(()=>{const e=se(3);return{log:se((t,n,r=1)=>{var o;const s=(o=FS().VIRTUOSO_LOG_LEVEL)!=null?o:pt(e);r>=s&&console[$S[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function or(e,t,n){return Aa(e,t,n).callbackRef}function Aa(e,t,n){const r=b.useRef(null);let o=i=>{};const s=b.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function BS(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const h=zS(d.children,t,a?"offsetWidth":"offsetHeight",o);let m=d.parentElement;for(;!m.dataset.virtuosoScroller;)m=m.parentElement;const f=m.lastElementChild.dataset.viewportType==="window";let v;f&&(v=m.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:f?a?v.scrollX||v.document.documentElement.scrollLeft:v.scrollY||v.document.documentElement.scrollTop:a?m.scrollLeft:m.scrollTop,x=i?a?i.scrollWidth:i.scrollHeight:f?a?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight:a?m.scrollWidth:m.scrollHeight,y=i?a?i.offsetWidth:i.offsetHeight:f?a?v.innerWidth:v.innerHeight:a?m.offsetWidth:m.offsetHeight;r({scrollHeight:x,scrollTop:Math.max(g,0),viewportHeight:y}),s==null||s(a?Xf("column-gap",getComputedStyle(d).columnGap,o):Xf("row-gap",getComputedStyle(d).rowGap,o)),h!==null&&e(h)},[e,t,o,s,i,r,a]);return Aa(c,n,l)}function zS(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Wt.ERROR),d===c)continue;const h=s[s.length-1];s.length===0||h.size!==d||h.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Xf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Wt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Jf(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let h,m;if(t){const f=t.getBoundingClientRect(),v=c.top-f.top;m=f.height-Math.max(0,v),h=v+t.scrollTop}else{const f=i.current.ownerDocument.defaultView;m=f.innerHeight-Math.max(0,c.top),h=c.top+f.scrollY}r.current={offsetTop:h,visibleHeight:m,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Aa(o,!0,n),a=b.useCallback(()=>{o(i.current)},[o,i]);return b.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Bt=qe(()=>{const e=He(),t=He(),n=se(0),r=He(),o=se(0),s=He(),i=He(),a=se(0),l=se(0),c=se(0),d=se(0),h=He(),m=He(),f=se(!1),v=se(!1),g=se(!1);return be(ne(e,pe(({scrollTop:x})=>x)),t),be(ne(e,pe(({scrollHeight:x})=>x)),i),be(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:v,scrollBy:m,scrollContainerState:e,scrollHeight:i,scrollingInProgress:f,scrollTo:h,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),po={lvl:0};function Zf(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function et(e){return e===po}function mo(e,t){if(!et(e))return t===e.k?e.v:t<e.k?mo(e.l,t):mo(e.r,t)}function hn(e,t,n="k"){if(et(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=hn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return hn(e.l,t,n)}function tn(e,t,n){return et(e)?th(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?nh(bt(e,{l:tn(e.l,t,n)})):nh(bt(e,{r:tn(e.r,t,n)}))}function Rr(){return po}function Is(e,t,n){if(et(e))return[];const r=hn(e,t)[0];return HS(_a(e,r,n))}function ja(e,t){if(et(e))return po;const{k:n,l:r,r:o}=e;if(t===n){if(et(r))return o;if(et(o))return r;{const[s,i]=eh(r);return Ns(bt(e,{k:s,l:Qf(r),v:i}))}}else return t<n?Ns(bt(e,{l:ja(r,t)})):Ns(bt(e,{r:ja(o,t)}))}function sr(e){return et(e)?[]:[...sr(e.l),{k:e.k,v:e.v},...sr(e.r)]}function _a(e,t,n){if(et(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(_a(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(_a(s,t,n))),a}function Ns(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Pa(t))return rh(bt(e,{lvl:n-1}));if(!et(t)&&!et(t.r))return bt(t.r,{l:bt(t,{r:t.r.l}),lvl:n,r:bt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Pa(e))return Ra(bt(e,{lvl:n-1}));if(!et(r)&&!et(r.l)){const o=r.l,s=Pa(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ra(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return th(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Qf(e){return et(e.r)?e.l:Ns(bt(e,{r:Qf(e.r)}))}function Pa(e){return et(e)||e.lvl>e.r.lvl}function eh(e){return et(e.r)?[e.k,e.v]:eh(e.r)}function th(e,t,n,r=po,o=po){return{k:e,l:r,lvl:n,r:o,v:t}}function nh(e){return Ra(rh(e))}function rh(e){const{l:t}=e;return!et(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function Ra(e){const{lvl:t,r:n}=e;return!et(n)&&!et(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function HS(e){return Zf(e,({k:t,v:n})=>({index:t,value:n}))}function oh(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function go(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ma=qe(()=>({recalcInProgress:se(!1)}),[],{singleton:!0});function sh(e,t,n){return e[As(e,t,n)]}function As(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function US(e,t,n,r){const o=As(e,t,r),s=As(e,n,r,o);return e.slice(o,s+1)}function Un(e,t){return Math.round(e.getBoundingClientRect()[t])}function js(e){return!et(e.groupOffsetTree)}function Oa({index:e},t){return t===e?0:t<e?-1:1}function WS(){return{groupIndices:[],groupOffsetTree:Rr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Rr()}}function VS(e,t){let n=et(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),et(e)){e=tn(e,0,s);continue}const a=Is(e,i-1,o+1);if(a.some(ZS(r)))continue;let l=!1,c=!1;for(const{end:d,start:h,value:m}of a)l?(o>=h||s===m)&&(e=ja(e,h)):(c=m!==s,l=!0),d>o&&o>=h&&m!==s&&(e=tn(e,o+1,m));c&&(e=tn(e,i,s))}return[e,n]}function KS(e){return typeof e.groupIndex<"u"}function qS({offset:e},t){return t===e?0:t<e?-1:1}function xo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=sh(t,e,Oa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ih(e,t){if(!js(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function ah(e,t,n){if(KS(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ih(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function GS(e,t,n,r=0){return r>0&&(t=Math.max(t,sh(e,r,Oa).offset)),Zf(US(e,t,n,qS),JS)}function YS(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Wt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&et(s)&&t.length===2){const m=t[0].size,f=t[1].size;i=n.reduce((v,g)=>tn(tn(v,g,m),g+1,f),i)}else[i,a]=VS(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:h}=Da(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((m,f)=>tn(m,f,xo(f,h,o)),Rr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:h,sizeTree:i}}function XS(e){return sr(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function lh(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function Da(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=As(o,t-1,Oa),a=o[l].offset;const c=hn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===hn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of Is(n,t,1/0)){const h=c-s,m=h*i+a+h*r;o.push({index:c,offset:m,size:d}),s=c,a=m,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function JS(e){return{index:e.index,value:e}}function ZS(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const QS={offsetHeight:"height",offsetWidth:"width"},En=qe(([{log:e},{recalcInProgress:t}])=>{const n=He(),r=He(),o=Mt(r,0),s=He(),i=He(),a=se(0),l=se([]),c=se(void 0),d=se(void 0),h=se((C,T)=>Un(C,QS[T])),m=se(void 0),f=se(0),v=WS(),g=Mt(ne(n,$e(l,e,f),kn(YS,v),ot()),v),x=Mt(ne(l,ot(),kn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),pe(({prev:C})=>C)),[]);be(ne(l,Ne(C=>C.length>0),$e(g,f),pe(([C,T,E])=>{const N=C.reduce((R,O,L)=>tn(R,O,xo(O,T.offsetTree,E)||L),Rr());return{...T,groupIndices:C,groupOffsetTree:N}})),g),be(ne(r,$e(g),Ne(([C,{lastIndex:T}])=>C<T),pe(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),be(c,d);const y=Mt(ne(c,pe(C=>C===void 0)),!0);be(ne(d,Ne(C=>C!==void 0&&et(pt(g).sizeTree)),pe(C=>[{endIndex:0,size:C,startIndex:0}])),n);const w=en(ne(n,$e(g),kn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:v}),pe(C=>C.changed)));Je(ne(a,kn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),pe(C=>C.diff)),C=>{const{groupIndices:T}=pt(g);if(C>0)Me(t,!0),Me(s,C+lh(C,T));else if(C<0){const E=pt(x);E.length>0&&(C-=lh(-C,E)),Me(i,C)}}),Je(ne(a,$e(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Wt.ERROR)});const S=en(s);be(ne(s,$e(g),pe(([C,T])=>{const E=T.groupIndices.length>0,N=[],R=T.lastSize;if(E){const O=mo(T.sizeTree,0);let L=0,q=0;for(;L<C;){const j=T.groupIndices[q],X=T.groupIndices.length===q+1?1/0:T.groupIndices[q+1]-j-1;N.push({endIndex:j,size:O,startIndex:j}),N.push({endIndex:j+1+X-1,size:R,startIndex:j+1}),q++,L+=X+1}const W=sr(T.sizeTree);return L!==C&&W.shift(),W.reduce((j,{k:X,v:G})=>{let B=j.ranges;return j.prevSize!==0&&(B=[...j.ranges,{endIndex:X+C-1,size:j.prevSize,startIndex:j.prevIndex}]),{prevIndex:X+C,prevSize:G,ranges:B}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return sr(T.sizeTree).reduce((O,{k:L,v:q})=>({prevIndex:L+C,prevSize:q,ranges:[...O.ranges,{endIndex:L+C-1,size:O.prevSize,startIndex:O.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=en(ne(i,$e(g,f),pe(([C,{offsetTree:T},E])=>{const N=-C;return xo(N,T,E)})));return be(ne(i,$e(g,f),pe(([C,T,E])=>{if(T.groupIndices.length>0){if(et(T.sizeTree))return T;let N=Rr();const R=pt(x);let O=0,L=0,q=0;for(;O<-C;){q=R[L];const W=R[L+1]-q-1;L++,O+=W+1}if(N=sr(T.sizeTree).reduce((W,{k:j,v:X})=>tn(W,Math.max(0,j+C),X),N),O!==-C){const W=mo(T.sizeTree,q);N=tn(N,0,W);const j=hn(T.sizeTree,-C+1)[1];N=tn(N,1,j)}return{...T,sizeTree:N,...Da(T.offsetTree,0,N,E)}}else{const N=sr(T.sizeTree).reduce((R,{k:O,v:L})=>tn(R,Math.max(0,O+C),L),Rr());return{...T,sizeTree:N,...Da(T.offsetTree,0,N,E)}}})),g),{beforeUnshiftWith:S,data:m,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:f,groupIndices:l,itemSize:h,listRefresh:w,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},rt(Hn,Ma),{singleton:!0});function eC(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const ch=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=He(),i=He(),a=en(ne(s,pe(eC)));return be(ne(a,pe(l=>l.totalCount)),n),be(ne(a,pe(l=>l.groupIndices)),e),be(ne(xt(o,t,r),Ne(([l,c])=>js(c)),pe(([l,c,d])=>hn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ot(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},rt(En,Bt)),Wn=qe(([{log:e}])=>{const t=se(!1),n=en(ne(t,Ne(r=>r),ot()));return Je(t,r=>{r&&pt(e)("props updated",{},Wt.DEBUG)}),{didMount:n,propsReady:t}},rt(Hn),{singleton:!0}),tC=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function uh(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!tC)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const vo=qe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:h},{log:m}])=>{const f=He(),v=He(),g=se(0);let x=null,y=null,w=null;function S(){x&&(x(),x=null),w&&(w(),w=null),y&&(clearTimeout(y),y=null),Me(l,!1)}return be(ne(f,$e(n,h,r,g,a,i,m),$e(e,s,o),pe(([[k,C,T,E,N,R,O,L],q,W,j])=>{const X=uh(k),{align:G,behavior:B,offset:M}=X,I=E-1,K=ah(X,C,I);let J=xo(K,C.offsetTree,q)+R;G==="end"?(J+=W+hn(C.sizeTree,K)[1]-T+j,K===I&&(J+=O)):G==="center"?J+=(W+hn(C.sizeTree,K)[1]-T+j)/2:J-=N,M&&(J+=M);const P=_=>{S(),_?(L("retrying to scroll to",{location:k},Wt.DEBUG),Me(f,k)):(Me(v,!0),L("list did not change, scroll successful",{},Wt.DEBUG))};if(S(),B==="smooth"){let _=!1;w=Je(t,z=>{_=_||z}),x=fn(d,()=>{P(_)})}else x=fn(ne(t,nC(150)),P);return y=setTimeout(()=>{S()},1200),Me(l,!0),L("scrolling from index to",{behavior:B,index:K,top:J},Wt.DEBUG),{behavior:B,top:J}})),c),{scrollTargetReached:v,scrollToIndex:f,topListHeight:g}},rt(En,Bt,Hn),{singleton:!0});function nC(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function La(e,t){e==0?t():requestAnimationFrame(()=>{La(e-1,t)})}function $a(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const bo=qe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=se(!0),l=se(0),c=se(!0);return be(ne(i,$e(l),Ne(([d,h])=>!!h),Tn(!1)),a),be(ne(i,$e(l),Ne(([d,h])=>!!h),Tn(!1)),c),Je(ne(xt(t,i),$e(a,n,e,c),Ne(([[,d],h,{sizeTree:m},f,v])=>d&&(!et(m)||Ea(f))&&!h&&!v),$e(l)),([,d])=>{fn(o,()=>{Me(c,!0)}),La(4,()=>{fn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},rt(En,Bt,vo,Wn),{singleton:!0});function dh(e,t){return Math.abs(e-t)<1.01}const wo="up",yo="down",rC="none",oC={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},sC=0,So=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=se(!1),a=se(!0),l=He(),c=He(),d=se(4),h=se(sC),m=Mt(ne(Na(ne(Ee(o),rr(1),Tn(!0)),ne(Ee(o),rr(1),Tn(!1),Gf(100))),ot()),!1),f=Mt(ne(Na(ne(n,Tn(!0)),ne(n,Tn(!1),Gf(200))),ot()),!1);be(ne(xt(Ee(o),Ee(h)),pe(([w,S])=>w<=S),ot()),a),be(ne(a,_n(50)),c);const v=en(ne(xt(r,Ee(s),Ee(t),Ee(e),Ee(d)),kn((w,[{scrollHeight:S,scrollTop:k},C,T,E,N])=>{const R=k+C-S>-N,O={scrollHeight:S,scrollTop:k,viewportHeight:C};if(R){let q,W;return k>w.state.scrollTop?(q="SCROLLED_DOWN",W=w.state.scrollTop-k):(q="SIZE_DECREASED",W=w.state.scrollTop-k||w.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:W,state:O}}let L;return O.scrollHeight>w.state.scrollHeight?L="SIZE_INCREASED":C<w.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":k<w.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:O}},oC),ot((w,S)=>w&&w.atBottom===S.atBottom))),g=Mt(ne(r,kn((w,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(dh(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return w.scrollTop!==k&&T?{changed:!0,jump:w.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ne(w=>w.changed),pe(w=>w.jump)),0);be(ne(v,pe(w=>w.atBottom)),i),be(ne(i,_n(50)),l);const x=se(yo);be(ne(r,pe(({scrollTop:w})=>w),ot(),kn((w,S)=>pt(f)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?wo:yo,prevScrollTop:S},{direction:yo,prevScrollTop:0}),pe(w=>w.direction)),x),be(ne(r,_n(50),Tn(rC)),x);const y=se(0);return be(ne(m,Ne(w=>!w),Tn(0)),y),be(ne(o,_n(100),$e(m),Ne(([w,S])=>!!S),kn(([w,S],[k])=>[S,k],[0,0]),pe(([w,S])=>S-w)),y),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:h,isAtBottom:i,isAtTop:a,isScrolling:m,lastJumpDueToItemResize:g,scrollDirection:x,scrollVelocity:y}},rt(Bt)),_s="top",Ps="bottom",fh="none";function hh(e,t,n){return typeof e=="number"?n===wo&&t===_s||n===yo&&t===Ps?e:0:n===wo?t===_s?e.main:e.reverse:t===Ps?e.main:e.reverse}function ph(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Fa=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=He(),i=se(0),a=se(0),l=se(0),c=Mt(ne(xt(Ee(r),Ee(o),Ee(n),Ee(s,go),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),pe(([d,h,m,[f,v],g,x,y,w,S])=>{const k=d-w,C=x+y,T=Math.max(m-k,0);let E=fh;const N=ph(S,_s),R=ph(S,Ps);return f-=w,f+=m+y,v+=m+y,v-=w,f>d+C-N&&(E=wo),v<d-T+h+R&&(E=yo),E!==fh?[Math.max(k-m-hh(g,_s,E)-N,0),k-T-y+h+hh(g,Ps,E)+R]:null}),Ne(d=>d!=null),ot(go)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},rt(Bt),{singleton:!0});function iC(e,t,n){if(js(t)){const r=ih(e,t);return[{index:hn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ba={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Rs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const h=n-i,m=a+h*l+(h-1)*r,f=c,v=m-d;return{bottom:d,firstItemIndex:s,items:gh(e,o,s),offsetBottom:v,offsetTop:c,top:f,topItems:gh(t,o,s),topListHeight:t.reduce((g,x)=>x.size+g,0),totalCount:n}}function mh(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=$a(t,a),c=Array.from({length:a}).map((d,h)=>({data:s[h+l],index:h+l,offset:0,size:0}));return Rs(c,[],a,o,n,r)}function gh(e,t,n){if(e.length===0)return[];if(!js(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Is(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const ir=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:h},m,{didMount:f},{recalcInProgress:v}])=>{const g=se([]),x=se(0),y=He();be(s.topItemsIndexes,g);const w=Mt(ne(xt(f,v,Ee(l,go),Ee(o),Ee(r),Ee(c),d,Ee(g),Ee(t),Ee(n),e),Ne(([T,E,,N,,,,,,,R])=>{const O=R&&R.length!==N;return T&&!E&&!O}),pe(([,,[T,E],N,R,O,L,q,W,j,X])=>{const G=R,{offsetTree:B,sizeTree:M}=G,I=pt(x);if(N===0)return{...Ba,totalCount:N};if(T===0&&E===0)return I===0?{...Ba,totalCount:N}:mh(I,O,R,W,j,X||[]);if(et(M))return I>0?null:Rs(iC($a(O,N),G,X),[],N,j,G,W);const K=[];if(q.length>0){const F=q[0],re=q[q.length-1];let V=0;for(const D of Is(M,F,re)){const Z=D.value,ee=Math.max(D.start,F),Q=Math.min(D.end,re);for(let H=ee;H<=Q;H++)K.push({data:X==null?void 0:X[H],index:H,offset:V,size:Z}),V+=Z}}if(!L)return Rs([],K,N,j,G,W);const J=q.length>0?q[q.length-1]+1:0,P=GS(B,T,E,J);if(P.length===0)return null;const _=N-1,z=Es([],F=>{for(const re of P){const V=re.value;let D=V.offset,Z=re.start;const ee=V.size;if(V.offset<T){Z+=Math.floor((T-V.offset+j)/(ee+j));const H=Z-re.start;D+=H*ee+H*j}Z<J&&(D+=(J-Z)*ee,Z=J);const Q=Math.min(re.end,_);for(let H=Z;H<=Q&&!(D>=E);H++)F.push({data:X==null?void 0:X[H],index:H,offset:D,size:ee}),D+=ee+j}});return Rs(z,K,N,j,G,W)}),Ne(T=>T!==null),ot()),Ba);be(ne(e,Ne(Ea),pe(T=>T==null?void 0:T.length)),o),be(ne(w,pe(T=>T.topListHeight)),h),be(h,a),be(ne(w,pe(T=>[T.top,T.bottom])),i),be(ne(w,pe(T=>T.items)),y);const S=en(ne(w,Ne(({items:T})=>T.length>0),$e(o,e),Ne(([{items:T},E])=>T[T.length-1].originalIndex===E-1),pe(([,T,E])=>[T-1,E]),ot(go),pe(([T])=>T))),k=en(ne(w,_n(200),Ne(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),pe(({items:T})=>T[0].index),ot())),C=en(ne(w,Ne(({items:T})=>T.length>0),pe(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),ot(oh)));return{endReached:S,initialItemCount:x,itemsRendered:y,listState:w,rangeChanged:C,startReached:k,topItemsIndexes:g,...m}},rt(En,ch,Fa,bo,vo,So,Wn,Ma),{singleton:!0}),xh=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=He(),i=Mt(ne(xt(n,e,r,t,o),pe(([a,l,c,d,h])=>a+l+c+d+h.offsetBottom+h.bottom)),0);return be(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},rt(Bt,ir),{singleton:!0}),aC=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=se(!1),r=Mt(ne(xt(n,e,t),Ne(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),_n(0),ot()),0);return{alignToBottom:n,paddingTopAddition:r}},rt(Bt,xh),{singleton:!0}),vh=qe(()=>({context:se(null)})),lC=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,bh=qe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=He();return be(ne(d,$e(t,l,n,s,o,r,a),$e(e),pe(([[h,m,f,v,g,x,y,w],S])=>{const{align:k,behavior:C,calculateViewLocation:T=lC,done:E,...N}=h,R=ah(h,m,v-1),O=xo(R,m.offsetTree,S)+g+x,L=O+hn(m.sizeTree,R)[1],q=w+x,W=w+f-y,j=T({itemBottom:L,itemTop:O,locationParams:{align:k,behavior:C,...N},viewportBottom:W,viewportTop:q});return j?E&&fn(ne(i,Ne(X=>!X),rr(pt(i)?1:2)),E):E&&E(),j}),Ne(h=>h!==null)),c),{scrollIntoView:d}},rt(En,Bt,vo,ir,Hn),{singleton:!0});function wh(e){return e?e==="smooth"?"smooth":"auto":!1}const cC=(e,t)=>typeof e=="function"?wh(e(t)):t&&wh(e),uC=qe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:h},{context:m},{scrollIntoView:f}])=>{const v=se(!1),g=He();let x=null;function y(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Je(ne(xt(ne(Ee(t),rr(1)),l),$e(Ee(v),s,a,h),pe(([[C,T],E,N,R,O])=>{let L=T&&R,q="auto";return L&&(q=cC(E,N||O),L=L&&!!q),{followOutputBehavior:q,shouldFollow:L,totalCount:C}}),Ne(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{x&&(x(),x=null),pt(n)?requestAnimationFrame(()=>{pt(d)("following output to ",{totalCount:T},Wt.DEBUG),y(C)}):x=fn(e,()=>{pt(d)("following output to ",{totalCount:T},Wt.DEBUG),y(C),x=null})});function w(C){const T=fn(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!x&&(pt(d)("scrolling to bottom due to increased size",{},Wt.DEBUG),y("auto"))});setTimeout(T,100)}Je(ne(xt(Ee(v),t,c),Ne(([C,,T])=>C&&T),kn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ne(({refreshed:C})=>C),$e(v,t)),([,C])=>{pt(a)&&w(C!==!1)}),Je(g,()=>{w(pt(v)!==!1)}),Je(xt(Ee(v),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const S=se(null),k=He();return be(Na(ne(Ee(r),pe(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),ne(Ee(t))),k),Je(ne(xt(ne(k,rr(1)),l),$e(Ee(S),a,h,m),pe(([[C,T],E,N,R,O])=>T&&N&&(E==null?void 0:E({context:O,totalCount:C,scrollingInProgress:R}))),Ne(C=>!!C),_n(0)),C=>{x&&(x(),x=null),pt(n)?requestAnimationFrame(()=>{pt(d)("scrolling into view",{}),Me(f,C)}):x=fn(e,()=>{pt(d)("scrolling into view",{}),Me(f,C),x=null})}),{autoscrollToBottom:g,followOutput:v,scrollIntoViewOnChange:S}},rt(En,So,vo,bo,Wn,Hn,Bt,vh,bh)),dC=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(be(ne(a,$e(s),Ne(([,l])=>l!==0),$e(o,r,t,n,e),pe(([[,l],c,d,h,m,f=[]])=>mh(l,c,d,h,m,f))),i),{}),rt(En,bo,ir,Wn),{singleton:!0}),fC=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=se(0);return Je(ne(e,$e(r),Ne(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{fn(ne(n,rr(1),Ne(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},rt(Wn,Bt,ir),{singleton:!0}),yh=qe(([{scrollVelocity:e}])=>{const t=se(!1),n=He(),r=se(!1);return be(ne(e,$e(r,t,n),Ne(([o,s])=>!!s),pe(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ot()),t),Je(ne(xt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},rt(So),{singleton:!0}),za=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=He(),r=He(),o=He(),s=se(!1),i=se(void 0);return be(ne(xt(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),be(ne(t,$e(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},rt(Bt)),hC=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=He(),d=se(void 0),h=se(null),m=se(null);return be(a,h),be(l,m),Je(ne(c,$e(t,r,i,h,m,n)),([f,v,g,x,y,w,S])=>{const k=XS(v.sizeTree);x&&y!==null&&w!==null&&(g=y.scrollTop-w.offsetTop),g-=S,f({ranges:k,scrollTop:g})}),be(ne(d,Ne(Ea),pe(pC)),o),be(ne(s,$e(d),Ne(([,f])=>f!==void 0),ot(),pe(([,f])=>f.ranges)),e),{getState:c,restoreStateFrom:d}},rt(En,Bt,bo,Wn,za));function pC(e){return{align:"start",index:0,offset:e.scrollTop}}const mC=qe(([{topItemsIndexes:e}])=>{const t=se(0);return be(ne(t,Ne(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},rt(ir));function Sh(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const gC=Sh(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),xC=qe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:h,sizes:m},{log:f},{recalcInProgress:v}])=>{const g=en(ne(l,$e(i),kn(([,y,w,S],[{bottom:k,items:C,offsetBottom:T,totalCount:E},N])=>{const R=k+T;let O=0;return w===E&&y.length>0&&C.length>0&&(C[0].originalIndex===0&&y[0].originalIndex===0||(O=R-S,O!==0&&(O+=N))),[O,C,E,R]},[0,[],0,0]),Ne(([y])=>y!==0),$e(r,a,n,o,f,v),Ne(([,y,w,S,,,k])=>!k&&!S&&y!==0&&w===wo),pe(([[y],,,,,w])=>(w("Upward scrolling compensation",{amount:y},Wt.DEBUG),y))));function x(y){y>0?(Me(t,{behavior:"auto",top:-y}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-y}))}return Je(ne(g,$e(e,s)),([y,w,S])=>{S&&gC()?Me(e,w-y):x(-y)}),Je(ne(xt(Mt(s,!1),e,v),Ne(([y,w,S])=>!y&&!S&&w!==0),pe(([y,w])=>w),_n(1)),x),be(ne(h,pe(y=>({top:-y}))),t),Je(ne(c,$e(m,d),pe(([y,{groupIndices:w,lastSize:S,sizeTree:k},C])=>{function T(E){return E*(S+C)}if(w.length===0)return T(y);{let E=0;const N=mo(k,0);let R=0,O=0;for(;R<y;){R++,E+=N;let L=w.length===O+1?1/0:w[O+1]-w[O]-1;R+L>y&&(E-=N,L=y-R+1),R+=L,E+=T(L),O++}return E}})),y=>{Me(e,y),requestAnimationFrame(()=>{Me(t,{top:y}),requestAnimationFrame(()=>{Me(e,0),Me(v,!1)})})}),{deviation:e}},rt(Bt,So,ir,En,Hn,Ma)),vC=qe(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),rt(Fa,dC,Wn,yh,xh,fC,aC,za,bh,Hn,vh)),Ch=qe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:h},{initialItemFinalLocationReached:m,initialTopMostItemIndex:f,scrolledToInitialItem:v},g,x,y,{listState:w,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},R])=>(be(k.rangeChanged,R.scrollSeekRangeChanged),be(ne(R.windowViewportRect,pe(O=>O.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:m,initialTopMostItemIndex:f,scrolledToInitialItem:v,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...y,groupIndices:s,itemSize:i,listState:w,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:h,...k,...R,...g,sizes:l,...x}),rt(En,bo,Bt,hC,uC,ir,vo,xC,mC,ch,vC));function bC(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Ms=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Th(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=b.createContext({});function l(x,y){x.propsReady&&Me(x.propsReady,!1);for(const w of r){const S=x[t.required[w]];Me(S,y[w])}for(const w of o)if(w in y){const S=x[t.optional[w]];Me(S,y[w])}x.propsReady&&Me(x.propsReady,!0)}function c(x){return s.reduce((y,w)=>(y[w]=S=>{const k=x[t.methods[w]];Me(k,S)},y),{})}function d(x){return i.reduce((y,w)=>(y[w]=OS(x[t.events[w]]),y),{})}const h=b.forwardRef((x,y)=>{const{children:w,...S}=x,[k]=b.useState(()=>Es(LS(e),E=>{l(E,S)})),[C]=b.useState(qf(d,k));Ms(()=>{for(const E of i)E in S&&Je(C[E],S[E]);return()=>{Object.values(C).map(Ia)}},[S,C,k]),Ms(()=>{l(k,S)}),b.useImperativeHandle(y,Vf(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...bC([...r,...o,...i],S),children:w}):w})}),m=x=>{const y=b.useContext(a);return b.useCallback(w=>{Me(y[x],w)},[y,x])},f=x=>{const y=b.useContext(a)[x],w=b.useCallback(S=>Je(y,S),[y]);return b.useSyncExternalStore(w,()=>pt(y),()=>pt(y))},v=x=>{const y=b.useContext(a)[x],[w,S]=b.useState(qf(pt,y));return Ms(()=>Je(y,k=>{k!==w&&S(Vf(k))}),[y,w]),w},g=b.version.startsWith("18")?f:v;return{Component:h,useEmitter:(x,y)=>{const w=b.useContext(a)[x];Ms(()=>Je(w,y),[y,w])},useEmitterValue:g,usePublisher:m}}const kh=b.createContext(void 0),Eh=b.createContext(void 0),Ih=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Ha(e){return"self"in e}function wC(e){return"body"in e}function Nh(e,t,n,r=Pr,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(m=>{let f,v,g;const x=m.target;if(wC(x)||Ha(x)){const w=Ha(x)?x:x.defaultView;g=s?w.scrollX:w.scrollY,f=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,v=s?w.innerWidth:w.innerHeight}else g=s?x.scrollLeft:x.scrollTop,f=s?x.scrollWidth:x.scrollHeight,v=s?x.offsetWidth:x.offsetHeight;const y=()=>{e({scrollHeight:f,scrollTop:Math.max(g,0),viewportHeight:v})};m.suppressFlushSync?y():Ro.flushSync(y),a.current!==null&&(g===a.current||g<=0||g===f-v)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const m=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:m}),m.addEventListener("scroll",c,{passive:!0}),()=>{r(null),m.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(m){const f=i.current;if(!f||(s?"offsetWidth"in f&&f.offsetWidth===0:"offsetHeight"in f&&f.offsetHeight===0))return;const v=m.behavior==="smooth";let g,x,y;Ha(f)?(x=Math.max(Un(f.document.documentElement,s?"width":"height"),s?f.document.documentElement.scrollWidth:f.document.documentElement.scrollHeight),g=s?f.innerWidth:f.innerHeight,y=s?window.scrollX:window.scrollY):(x=f[s?"scrollWidth":"scrollHeight"],g=Un(f,s?"width":"height"),y=f[s?"scrollLeft":"scrollTop"]);const w=x-g;if(m.top=Math.ceil(Math.max(Math.min(w,m.top),0)),dh(g,x)||m.top===y){e({scrollHeight:x,scrollTop:y,viewportHeight:g}),v&&t(!0);return}v?(a.current=m.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(m={behavior:m.behavior,left:m.top}),f.scrollTo(m)}function h(m){s&&(m={behavior:m.behavior,left:m.top}),i.current.scrollBy(m)}return{scrollByCallback:h,scrollerRef:i,scrollToCallback:d}}const Ua="-webkit-sticky",Ah="sticky",Wa=Sh(()=>{if(typeof document>"u")return Ah;const e=document.createElement("div");return e.style.position=Ua,e.style.position===Ua?Ua:Ah});function Va(e){return e}const yC=qe(()=>{const e=se(a=>`Item ${a}`),t=se(a=>`Group ${a}`),n=se({}),r=se(Va),o=se("div"),s=se(Pr),i=(a,l=null)=>Mt(ne(n,pe(c=>c[a]),ot()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),SC=qe(([e,t])=>({...e,...t}),rt(Ch,yC)),CC=({height:e})=>u.jsx("div",{style:{height:e}}),TC={overflowAnchor:"none",position:Wa(),zIndex:1},jh={overflowAnchor:"none"},kC={...jh,display:"inline-block",height:"100%"},_h=b.memo(function({showTopList:e=!1}){const t=_e("listState"),n=rn("sizeRanges"),r=_e("useWindowScroll"),o=_e("customScrollParent"),s=rn("windowScrollContainerState"),i=rn("scrollContainerState"),a=o||r?s:i,l=_e("itemContent"),c=_e("context"),d=_e("groupContent"),h=_e("trackItemSizes"),m=_e("itemSize"),f=_e("log"),v=rn("gap"),g=_e("horizontalDirection"),{callbackRef:x}=BS(n,m,h,e?Pr:a,f,v,o,g,_e("skipAnimationFrameInResizeObserver")),[y,w]=b.useState(0);Ka("deviation",j=>{y!==j&&w(j)});const S=_e("EmptyPlaceholder"),k=_e("ScrollSeekPlaceholder")||CC,C=_e("ListComponent"),T=_e("ItemComponent"),E=_e("GroupComponent"),N=_e("computeItemKey"),R=_e("isSeeking"),O=_e("groupIndices").length>0,L=_e("alignToBottom"),q=_e("initialItemFinalLocationReached"),W=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:y!==0?y:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...q?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Ot(S,c)}):u.jsx(C,{...Ot(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:x,style:W,children:(e?t.topItems:t.items).map(j=>{const X=j.originalIndex,G=N(X+t.firstItemIndex,j.data,c);return R?b.createElement(k,{...Ot(k,c),height:j.size,index:j.index,key:G,type:j.type||"item",...j.type==="group"?{}:{groupIndex:j.groupIndex}}):j.type==="group"?b.createElement(E,{...Ot(E,c),"data-index":X,"data-item-index":j.index,"data-known-size":j.size,key:G,style:TC},d(j.index,c)):b.createElement(T,{...Ot(T,c),...AC(T,j.data),"data-index":X,"data-item-group-index":j.groupIndex,"data-item-index":j.index,"data-known-size":j.size,key:G,style:g?kC:jh},O?l(j.index,j.groupIndex,j.data,c):l(j.index,j.data,c))})})}),EC={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},IC={outline:"none",overflowX:"auto",position:"relative"},Os=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),NC={position:Wa(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function AC(e,t){return{item:typeof e=="string"?void 0:t}}const jC=b.memo(function(){const e=_e("HeaderComponent"),t=rn("headerHeight"),n=_e("HeaderFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),_C=b.memo(function(){const e=_e("FooterComponent"),t=rn("footerHeight"),n=_e("HeaderFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null});function Ph({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),h=t("horizontalDirection")||!1,{scrollByCallback:m,scrollerRef:f,scrollToCallback:v}=Nh(a,c,l,d,void 0,h);return e("scrollTo",v),e("scrollBy",m),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:f,style:{...h?IC:EC,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function Rh({useEmitter:e,useEmitterValue:t,usePublisher:n}){return b.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),h=t("deviation"),m=t("customScrollParent"),f=b.useRef(null),v=t("scrollerRef"),{scrollByCallback:g,scrollerRef:x,scrollToCallback:y}=Nh(a,c,l,v,m);return Ih(()=>{var w;return x.current=m||((w=f.current)==null?void 0:w.ownerDocument.defaultView),()=>{x.current=null}},[x,m]),e("windowScrollTo",y),e("scrollBy",g),u.jsx(l,{ref:f,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+h}:{}},...i,...Ot(l,s),children:r})})}const PC=({children:e})=>{const t=b.useContext(kh),n=rn("viewportHeight"),r=rn("fixedItemHeight"),o=_e("alignToBottom"),s=_e("horizontalDirection"),i=b.useMemo(()=>Kf(n,l=>Un(l,s?"width":"height")),[n,s]),a=or(i,!0,_e("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Os(o),children:e})},RC=({children:e})=>{const t=b.useContext(kh),n=rn("windowViewportRect"),r=rn("fixedItemHeight"),o=_e("customScrollParent"),s=Jf(n,o,_e("skipAnimationFrameInResizeObserver")),i=_e("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:Os(i),children:e})},MC=({children:e})=>{const t=_e("TopItemListComponent")||"div",n=_e("headerHeight"),r={...NC,marginTop:`${n}px`},o=_e("context");return u.jsx(t,{style:r,...Ot(t,o),children:e})},OC=b.memo(function(e){const t=_e("useWindowScroll"),n=_e("topItemsIndexes").length>0,r=_e("customScrollParent"),o=_e("context");return u.jsxs(r||t?$C:LC,{...e,context:o,children:[n&&u.jsx(MC,{children:u.jsx(_h,{showTopList:!0})}),u.jsxs(r||t?RC:PC,{children:[u.jsx(jC,{}),u.jsx(_h,{}),u.jsx(_C,{})]})]})}),{Component:DC,useEmitter:Ka,useEmitterValue:_e,usePublisher:rn}=Th(SC,{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"}},OC),LC=Ph({useEmitter:Ka,useEmitterValue:_e,usePublisher:rn}),$C=Rh({useEmitter:Ka,useEmitterValue:_e,usePublisher:rn}),FC=DC;rt(Ch,qe(()=>{const e=se(c=>u.jsxs("td",{children:["Item $",c]})),t=se(null),n=se(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=se(null),o=se(null),s=se({}),i=se(Va),a=se(Pr),l=(c,d=null)=>Mt(ne(s,pe(h=>h[c]),ot()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Wa();const Mh={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},BC={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Oh,floor:Ds,max:Co,min:qa,round:Dh}=Math;function Lh(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function zC(e){return{...BC,items:e}}function Ls(e,t){return e&&e.width===t.width&&e.height===t.height}function HC(e,t){return e&&e.column===t.column&&e.row===t.row}const UC=qe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:h},m,f,{didMount:v,propsReady:g},{customScrollParent:x,useWindowScroll:y,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k},C])=>{const T=se(0),E=se(0),N=se(Mh),R=se({height:0,width:0}),O=se({height:0,width:0}),L=He(),q=He(),W=se(0),j=se(null),X=se({column:0,row:0}),G=He(),B=He(),M=se(!1),I=se(0),K=se(!0),J=se(!1),P=se(!1);Je(ne(v,$e(I),Ne(([D,Z])=>!!Z)),()=>{Me(K,!1)}),Je(ne(xt(v,K,O,R,I,J),Ne(([D,Z,ee,Q,,H])=>D&&!Z&&ee.height!==0&&Q.height!==0&&!H)),([,,,,D])=>{Me(J,!0),La(1,()=>{Me(L,D)}),fn(ne(c),()=>{Me(t,[0,0]),Me(K,!0)})}),be(ne(B,Ne(D=>D!=null&&D.scrollTop>0),Tn(0)),E),Je(ne(v,$e(B),Ne(([,D])=>D!=null)),([,D])=>{D&&(Me(R,D.viewport),Me(O,D.item),Me(X,D.gap),D.scrollTop>0&&(Me(M,!0),fn(ne(c,rr(1)),Z=>{Me(M,!1)}),Me(l,{top:D.scrollTop})))}),be(ne(R,pe(({height:D})=>D)),h),be(ne(xt(Ee(R,Ls),Ee(O,Ls),Ee(X,(D,Z)=>D&&D.column===Z.column&&D.row===Z.row),Ee(c)),pe(([D,Z,ee,Q])=>({gap:ee,item:Z,scrollTop:Q,viewport:D}))),G),be(ne(xt(Ee(T),r,Ee(X,HC),Ee(O,Ls),Ee(R,Ls),Ee(j),Ee(E),Ee(M),Ee(K),Ee(I)),Ne(([,,,,,,,D])=>!D),pe(([D,[Z,ee],Q,H,ae,ie,ge,,ye,Te])=>{const{column:Ae,row:ke}=Q,{height:st,width:vt}=H,{width:kt}=ae;if(ge===0&&(D===0||kt===0))return Mh;if(vt===0){const At=$a(Te,D),wt=At+Math.max(ge-1,0);return zC(Lh(At,wt,ie))}const Ve=$h(kt,vt,Ae);let ze,Ke;ye?Z===0&&ee===0&&ge>0?(ze=0,Ke=ge-1):(ze=Ve*Ds((Z+ke)/(st+ke)),Ke=Ve*Oh((ee+ke)/(st+ke))-1,Ke=qa(D-1,Co(Ke,Ve-1)),ze=qa(Ke,Co(0,ze))):(ze=0,Ke=-1);const Oe=Lh(ze,Ke,ie),{bottom:Ue,top:dt}=Fh(ae,Q,H,Oe),Nt=Oh(D/Ve),nt=Nt*st+(Nt-1)*ke-Ue;return{bottom:Ue,itemHeight:st,items:Oe,itemWidth:vt,offsetBottom:nt,offsetTop:dt,top:dt}})),N),be(ne(j,Ne(D=>D!==null),pe(D=>D.length)),T),be(ne(xt(R,O,N,X),Ne(([D,Z,{items:ee}])=>ee.length>0&&Z.height!==0&&D.height!==0),pe(([D,Z,{items:ee},Q])=>{const{bottom:H,top:ae}=Fh(D,Q,Z,ee);return[ae,H]}),ot(go)),t);const _=se(!1);be(ne(c,$e(_),pe(([D,Z])=>Z||D!==0)),_);const z=en(ne(xt(N,T),Ne(([{items:D}])=>D.length>0),$e(_),Ne(([[D,Z],ee])=>{const Q=D.items[D.items.length-1].index===Z-1;return(ee||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===Z)&&Q}),pe(([[,D]])=>D-1),ot())),F=en(ne(Ee(N),Ne(({items:D})=>D.length>0&&D[0].index===0),Tn(0),ot())),re=en(ne(Ee(N),$e(M),Ne(([{items:D},Z])=>D.length>0&&!Z),pe(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ot(oh),_n(0)));be(re,f.scrollSeekRangeChanged),be(ne(L,$e(R,O,T,X),pe(([D,Z,ee,Q,H])=>{const ae=uh(D),{align:ie,behavior:ge,offset:ye}=ae;let Te=ae.index;Te==="LAST"&&(Te=Q-1),Te=Co(0,Te,qa(Q-1,Te));let Ae=Ga(Z,H,ee,Te);return ie==="end"?Ae=Dh(Ae-Z.height+ee.height):ie==="center"&&(Ae=Dh(Ae-Z.height/2+ee.height/2)),ye&&(Ae+=ye),{behavior:ge,top:Ae}})),l);const V=Mt(ne(N,pe(D=>D.offsetBottom+D.bottom)),0);return be(ne(k,pe(D=>({height:D.visibleHeight,width:D.visibleWidth}))),R),{customScrollParent:x,data:j,deviation:W,footerHeight:o,gap:X,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:O,overscan:n,restoreStateFrom:B,scrollBy:i,scrollContainerState:a,scrollHeight:q,scrollTo:l,scrollToIndex:L,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:y,viewportDimensions:R,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:k,...f,gridState:N,horizontalDirection:P,initialTopMostItemIndex:I,totalListHeight:V,...m,endReached:z,propsReady:g,rangeChanged:re,startReached:F,stateChanged:G,stateRestoreInProgress:M,...C}},rt(Fa,Bt,So,yh,Wn,za,Hn));function $h(e,t,n){return Co(1,Ds((e+n)/(Ds(t)+n)))}function Fh(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ga(e,t,n,r[0].index);return{bottom:Ga(e,t,n,r[r.length-1].index)+o,top:s}}function Ga(e,t,n,r){const o=$h(e.width,n.width,t.column),s=Ds(r/o),i=s*n.height+Co(0,s-1)*t.row;return i>0?i+t.row:i}const WC=qe(()=>{const e=se(h=>`Item ${h}`),t=se({}),n=se(null),r=se("virtuoso-grid-item"),o=se("virtuoso-grid-list"),s=se(Va),i=se("div"),a=se(Pr),l=(h,m=null)=>Mt(ne(t,pe(f=>f[h]),ot()),m),c=se(!1),d=se(!1);return be(Ee(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),VC=qe(([e,t])=>({...e,...t}),rt(UC,WC)),KC=b.memo(function(){const e=at("gridState"),t=at("listClassName"),n=at("itemClassName"),r=at("itemContent"),o=at("computeItemKey"),s=at("isSeeking"),i=on("scrollHeight"),a=at("ItemComponent"),l=at("ListComponent"),c=at("ScrollSeekPlaceholder"),d=at("context"),h=on("itemDimensions"),m=on("gap"),f=at("log"),v=at("stateRestoreInProgress"),g=on("reportReadyState"),x=or(b.useMemo(()=>y=>{const w=y.parentElement.parentElement.scrollHeight;i(w);const S=y.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();h({height:k,width:C})}m({column:zh("column-gap",getComputedStyle(y).columnGap,f),row:zh("row-gap",getComputedStyle(y).rowGap,f)})},[i,h,m,f]),!0,!1);return Ih(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),v?null:u.jsx(l,{className:t,ref:x,...Ot(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(y=>{const w=o(y.index,y.data,d);return s?u.jsx(c,{...Ot(c,d),height:e.itemHeight,index:y.index,width:e.itemWidth},w):b.createElement(a,{...Ot(a,d),className:n,"data-index":y.index,key:w},r(y.index,y.data,d))})})}),qC=b.memo(function(){const e=at("HeaderComponent"),t=on("headerHeight"),n=at("headerFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,!1),o=at("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),GC=b.memo(function(){const e=at("FooterComponent"),t=on("footerHeight"),n=at("headerFooterTag"),r=or(b.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,!1),o=at("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),YC=({children:e})=>{const t=b.useContext(Eh),n=on("itemDimensions"),r=on("viewportDimensions"),o=or(b.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return b.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:Os(!1),children:e})},XC=({children:e})=>{const t=b.useContext(Eh),n=on("windowViewportRect"),r=on("itemDimensions"),o=at("customScrollParent"),s=Jf(n,o,!1);return b.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:Os(!1),children:e})},JC=b.memo(function({...e}){const t=at("useWindowScroll"),n=at("customScrollParent"),r=n||t?QC:ZC,o=n||t?XC:YC,s=at("context");return u.jsx(r,{...e,...Ot(r,s),children:u.jsxs(o,{children:[u.jsx(qC,{}),u.jsx(KC,{}),u.jsx(GC,{})]})})}),{useEmitter:Bh,useEmitterValue:at,usePublisher:on}=Th(VC,{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"}},JC),ZC=Ph({useEmitter:Bh,useEmitterValue:at,usePublisher:on}),QC=Rh({useEmitter:Bh,useEmitterValue:at,usePublisher:on});function zh(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Wt.WARN),t==="normal"?0:parseInt(t??"0",10)}var $s="Dialog",[Hh,jN]=cn($s),[eT,pn]=Hh($s),Uh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=p.useRef(null),l=p.useRef(null),[c,d]=Dn({prop:r,defaultProp:o??!1,onChange:s,caller:$s});return u.jsx(eT,{scope:t,triggerRef:a,contentRef:l,contentId:Rt(),titleId:Rt(),descriptionId:Rt(),open:c,onOpenChange:d,onOpenToggle:p.useCallback(()=>d(h=>!h),[d]),modal:i,children:n})};Uh.displayName=$s;var Wh="DialogTrigger",Vh=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Wh,n),s=Le(t,o.triggerRef);return u.jsx(ve.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ja(o.open),...r,ref:s,onClick:ce(e.onClick,o.onOpenToggle)})});Vh.displayName=Wh;var Ya="DialogPortal",[tT,Kh]=Hh(Ya,{forceMount:void 0}),qh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=pn(Ya,t);return u.jsx(tT,{scope:t,forceMount:n,children:p.Children.map(r,i=>u.jsx(Ut,{present:n||s.open,children:u.jsx(so,{asChild:!0,container:o,children:i})}))})};qh.displayName=Ya;var Fs="DialogOverlay",Gh=p.forwardRef((e,t)=>{const n=Kh(Fs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=pn(Fs,e.__scopeDialog);return s.modal?u.jsx(Ut,{present:r||s.open,children:u.jsx(rT,{...o,ref:t})}):null});Gh.displayName=Fs;var nT=Yt.createSlot("DialogOverlay.RemoveScroll"),rT=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Fs,n);return u.jsx(xs,{as:nT,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(ve.div,{"data-state":Ja(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),ar="DialogContent",Yh=p.forwardRef((e,t)=>{const n=Kh(ar,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=pn(ar,e.__scopeDialog);return u.jsx(Ut,{present:r||s.open,children:s.modal?u.jsx(oT,{...o,ref:t}):u.jsx(sT,{...o,ref:t})})});Yh.displayName=ar;var oT=p.forwardRef((e,t)=>{const n=pn(ar,e.__scopeDialog),r=p.useRef(null),o=Le(t,n.contentRef,r);return p.useEffect(()=>{const s=r.current;if(s)return fa(s)},[]),u.jsx(Xh,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ce(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ce(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault())})}),sT=p.forwardRef((e,t)=>{const n=pn(ar,e.__scopeDialog),r=p.useRef(!1),o=p.useRef(!1);return u.jsx(Xh,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Xh=p.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=pn(ar,n),l=p.useRef(null),c=Le(t,l);return Ui(),u.jsxs(u.Fragment,{children:[u.jsx(Zo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(yr,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ja(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(iT,{titleId:a.titleId}),u.jsx(lT,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Xa="DialogTitle",Jh=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Xa,n);return u.jsx(ve.h2,{id:o.titleId,...r,ref:t})});Jh.displayName=Xa;var Zh="DialogDescription",Qh=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(Zh,n);return u.jsx(ve.p,{id:o.descriptionId,...r,ref:t})});Qh.displayName=Zh;var ep="DialogClose",tp=p.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=pn(ep,n);return u.jsx(ve.button,{type:"button",...r,ref:t,onClick:ce(e.onClick,()=>o.onOpenChange(!1))})});tp.displayName=ep;function Ja(e){return e?"open":"closed"}var np="DialogTitleWarning",[_N,rp]=Cb(np,{contentName:ar,titleName:Xa,docsSlug:"dialog"}),iT=({titleId:e})=>{const t=rp(np),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
80
80
|
|
|
81
81
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
82
82
|
|
|
@@ -127,4 +127,4 @@ ${t}</tr>
|
|
|
127
127
|
`+(f.tokens?this.parseInline(f.tokens):f.text);r+=n?this.renderer.paragraph(m):m;continue}default:{const N='Token with "'+f.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ys{constructor(t){this.options=t||cr}preprocess(t){return t}postprocess(t){return t}}tx(Ys,"passThroughHooks",new Set(["preprocess","postprocess"]));function RT(e,t,n){return r=>{if(r.message+=`
|
|
128
128
|
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Dt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function wp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...we.defaults,...s};const i=RT(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(jT(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(h){return i(h)}const c=function(h){let m;if(!h)try{r.walkTokens&&we.walkTokens(l,r.walkTokens),m=t(l,r),r.hooks&&(m=r.hooks.postprocess(m))}catch(f){h=f}return r.highlight=a,h?i(h):o(null,m)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;we.walkTokens(l,function(h){h.type==="code"&&(d++,setTimeout(()=>{a(h.text,h.lang,function(m,f){if(m)return c(m);f!=null&&f!==h.text&&(h.text=f,h.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(we.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&we.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function we(e,t,n){return wp(Vn.lex,Kn.parse)(e,t,n)}we.options=we.setOptions=function(e){return we.defaults={...we.defaults,...e},xT(we.defaults),we},we.getDefaults=lp,we.defaults=cr,we.use=function(...e){const t=we.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=we.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=we.defaults.renderer||new sl;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=we.defaults.tokenizer||new ol;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=we.defaults.hooks||new Ys;for(const s in n.hooks){const i=o[s];Ys.passThroughHooks.has(s)?o[s]=a=>{if(we.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=we.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}we.setOptions(r)})},we.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(we,r)),r.type){case"table":{for(const o of r.header)n=n.concat(we.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(we.walkTokens(s.tokens,t));break}case"list":{n=n.concat(we.walkTokens(r.items,t));break}default:we.defaults.extensions&&we.defaults.extensions.childTokens&&we.defaults.extensions.childTokens[r.type]?we.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(we.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(we.walkTokens(r.tokens,t)))}return n},we.parseInline=wp(Vn.lexInline,Kn.parseInline),we.Parser=Kn,we.parser=Kn.parse,we.Renderer=sl,we.TextRenderer=vp,we.Lexer=Vn,we.lexer=Vn.lex,we.Tokenizer=ol,we.Slugger=bp,we.Hooks=Ys,we.parse=we,we.options,we.setOptions,we.use,we.walkTokens,we.parseInline,Kn.parse,Vn.lex;function qn({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{if(!e||typeof e!="string"||e.trim().length===0)return"";try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof we.parse=="function"?we.parse(i):we(i)}return typeof we.parse=="function"?we.parse(e):we(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=b.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:oe("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}function yp({preview:e,idx:t}){return u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const Sp={completed:{label:"Completed",badgeClass:"border border-green-200 bg-green-50 text-green-700"},success:{label:"Completed",badgeClass:"border border-green-200 bg-green-50 text-green-700"},failed:{label:"Failed",badgeClass:"border border-red-200 bg-red-50 text-red-700"},error:{label:"Failed",badgeClass:"border border-red-200 bg-red-50 text-red-700"},cancelled:{label:"Cancelled",badgeClass:"border border-orange-200 bg-orange-50 text-orange-700"},cancel:{label:"Cancelled",badgeClass:"border border-orange-200 bg-orange-50 text-orange-700"},pending:{label:"Pending",badgeClass:"border border-blue-200 bg-blue-50 text-blue-700"},processing:{label:"Processing",badgeClass:"border border-yellow-200 bg-yellow-50 text-yellow-700"}},MT=e=>{if(!e)return Sp.processing;const t=e.toLowerCase().trim();return Sp[t]??{label:t.replace(/(^\w|\s\w)/g,n=>n.toUpperCase()),badgeClass:"border border-slate-200 bg-slate-50 text-slate-800"}},OT=e=>e?e.length>10?`${e.slice(0,8)}…`:e:"";function Cp({artifact:e}){const t=MT(e.status),n=e.task_url??e.taskUrl??"";return u.jsxs("div",{className:"rounded-lg border border-blue-200/70 bg-blue-50/40 p-4 space-y-3",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-blue-600/10 text-blue-600",children:u.jsx(ue.Search,{className:"h-4 w-4"})}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-blue-700",children:"Research Task"}),u.jsxs("p",{className:"text-[11px] text-blue-900/80",children:["Task ID: ",u.jsx("span",{className:"font-mono",children:OT(e.task_id)})]})]})]}),t&&u.jsx("span",{className:`inline-flex items-center rounded-full px-3 py-1 text-[11px] font-semibold ${t.badgeClass}`,children:t.label})]}),e.query&&u.jsxs("div",{className:"rounded border border-blue-100 bg-white/80 px-3 py-2 text-xs text-blue-900/90",children:[u.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-blue-500",children:"Query"}),u.jsx("p",{className:"line-clamp-2 text-[11px] text-blue-900",children:e.query})]}),typeof e.results=="string"&&e.results.trim()&&u.jsxs("div",{className:"rounded border border-blue-100 bg-white/80 px-3 py-2 text-sm text-blue-900/90 space-y-1",children:[u.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-blue-500",children:"Results"}),u.jsx(qn,{content:e.results,allowHtml:!1,className:"prose text-xs !prose-sm prose-blue dark:prose-invert"})]}),u.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n?u.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 rounded-full border border-blue-600/80 bg-blue-600/10 px-3 py-1 text-xs font-semibold text-blue-700 transition hover:bg-blue-600/20",children:[u.jsx("span",{children:"Go to task"}),u.jsx(ue.ExternalLink,{className:"h-3 w-3"})]}):u.jsx("span",{className:"text-xs text-muted-foreground",children:"Task link unavailable"}),e.createdAt&&u.jsxs("p",{className:"text-[10px] text-blue-700/70",children:["Started: ",new Date(e.createdAt).toLocaleTimeString()]})]})]})}function Tp({artifact:e,idx:t=0}){const n=b.useMemo(()=>e?(Array.isArray(e.plots)?e.plots:[]).map(o=>ob(o)).filter(o=>o!==null):[],[e]);return(e==null?void 0:e.type)==="research_task_info"?u.jsx(Cp,{artifact:{type:"research_task_info",task_id:e.task_id,task_url:e.task_url,query:e.query,status:e.status,createdAt:e.createdAt}}):n.length>0?u.jsx("div",{className:"space-y-2",children:n.map((r,o)=>u.jsx(yp,{preview:r,idx:o},`${t}-plot-${o}`))}):e&&typeof e=="object"?u.jsx("div",{className:"rounded-lg border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/20 p-4",children:u.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Unknown artifact type: ",u.jsx("code",{className:"font-mono",children:e.type||"unknown"})]})}):null}const il=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));il.displayName="Card";const al=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));al.displayName="CardHeader";const ll=p.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));ll.displayName="CardTitle";const cl=p.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));cl.displayName="CardDescription";const ul=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));ul.displayName="CardContent";const kp=p.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));kp.displayName="CardFooter";function Ep({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=vr(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(il,{className:oe("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(al,{className:"pb-3",children:[u.jsx(ll,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(cl,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(ul,{className:"pt-0 pb-3",children:a}),u.jsx(kp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const DT="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function dl({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:DT,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:vr(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:vr(e)})}function Ip({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=b.useMemo(()=>{const a=e.additionalKwargs??{};return Array.isArray(a.toolProgress)?[...a.toolProgress]:[]},[e]),s=r.some(a=>a.type==="tool.start"||a.type==="tool.call"||a.type==="message.start")?`Running ${n}…`:void 0;return t||r.length>0?u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[t&&u.jsx(ue.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:s??`Running ${n}…`})]}),r.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:r.map((a,l)=>{var c;return u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:((c=a.type)==null?void 0:c.replace(/\./g," "))??"progress"}),u.jsx("span",{children:a.idx??l+1})]}),a.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:a.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof a.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",a.factsFound]}),typeof a.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",a.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${n}-${l}`)})})]}):null}function Np({className:e}){const[t,n]=b.useState(0);return b.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:oe("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function Ap({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:oe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(qn,{content:e,allowHtml:!1}):u.jsxs("pre",{className:oe("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ze,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(ue.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ue.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function jp({message:e,viewMode:t,isStreaming:n=!1}){const o=Oi(e).name||"tool",s=e.artifact??null,i=c=>{if(c==null)return null;const d=typeof c=="string"?Mi(c)??c:c;if(d&&typeof d=="object")return u.jsx(dl,{data:d});const h=typeof d=="string"?d:(()=>{try{return vr(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:h})},a=c=>{if(c==null)return null;const{content:d,isMarkdown:h}=Jv(c);return h?u.jsx(qn,{content:d,className:"text-current"}):i(c)},l=()=>{const c=e.content.find(m=>m.type!=="tool_call");if(!c)return u.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",o,"…"]})});if(c.type==="text"){const f=(c.text??"").trim();if(!f)return null;const v=Qr(f);return a(v)}const d=Zr(c),h=Qr(d);return a(h)};return u.jsxs("div",{className:"space-y-2",children:[s&&u.jsx(Tp,{artifact:s,idx:0}),u.jsx(Ip,{message:e,isStreaming:n}),t==="expanded"&&u.jsx(u.Fragment,{children:l()})]})}function _p(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=rl(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),h=b.useCallback(f=>{a(f),c(!0)},[]),m=b.useCallback(async(f,v,g)=>{var x,y;if(!t){f.preventDefault();return}if(o[g]){f.preventDefault();return}try{const w=String(v.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){f.preventDefault();const k=S[1],C=v.name||`file_${k}`,T=v.mimeType||"application/octet-stream";h({id:k,name:C,mimeType:T});return}if(w.startsWith("data:")){f.preventDefault(),s(C=>({...C,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await eu(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(v.name??""))?!1:typeof v.size=="number"&&typeof E.size=="number"?E.size===v.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${v.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");h({id:T.id,name:v.name||T.filename||`file_${T.id}`,mimeType:v.mimeType||T.mime_type||"application/octet-stream"}),(x=k.update)==null||x.call(k,{id:k.id,title:"Success",description:`Opened ${v.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(y=k.update)==null||y.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[g]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[g]:!1}))}},[t,o,r,n,h]);return{uploadingFiles:o,handleFileClick:m,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function Pp(e,t){return b.useMemo(()=>{if(t)return{contentParts:[],textContent:"",toolMeta:{},imageParts:[],fileParts:[],interruptParts:[],toolRaw:"",isToolStreaming:!1};const n=e,r=Array.isArray(n.content)?n.content:[],o=n.additionalKwargs??{};return{contentParts:r,textContent:Zv(r),toolMeta:Oi(n),imageParts:r.filter(s=>s.type==="image_url"),fileParts:r.filter(s=>s.type==="file"),interruptParts:r.filter(s=>s.type==="interrupt"),toolRaw:Qv(r),isToolStreaming:!!o.toolStreaming}},[e,t])}const LT={checkpoints:[],checkpointMetaByCheckpointId:new Map,timeline:[],messagePreviews:new Map,getLatest:()=>{},getCheckpoint:()=>{},getMessageAttempts:()=>[]},fl=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,hl=b.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:h,activeInterrupt:m,disableInterruptActions:f,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:x,checkpointIndex:y,onSelectCheckpoint:w}){const S=fl(t,n),k=t.role==="default_message",T=!!t.__syntheticStreaming,E=y??LT,N=!k&&"checkpointId"in t?t.checkpointId??null:null,{attemptCount:R,attemptIndex:O,attempts:L}=b.useMemo(()=>tc(t.id,N,E),[t.id,N,E]);return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":S,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Xs,{message:t,messageIndex:n,isStreamingMessage:T||r&&o===t.id&&t.role==="assistant",streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:h,activeInterrupt:m,disableInterruptActions:f,onInterruptActionStart:v,onInterruptActionEnd:g,showToolMessages:x,attemptCount:R,attemptIndex:O,attemptMetas:L,onSelectCheckpoint:w})})});hl.displayName="MessageRow";function $T(e,t,n){const[r,o]=b.useState(e),s=b.useRef([]);return b.useEffect(()=>{if(!t){o(e),s.current=e.map(a=>a.type==="text"?a.text??"":void 0);return}const i=e.map((a,l)=>{if(a.type!=="text")return s.current[l]=void 0,a;const c=a.text??"",d=s.current[l];return n(c)?(s.current[l]=c,a):{...a,text:d??""}});o(i)},[e,t,n]),r}function FT({message:e,isToolMessage:t,showToolMessages:n,toolViewMode:r,isToolStreaming:o,contentParts:s,textContent:i,imageParts:a,fileParts:l,interruptParts:c,isStreamingMessage:d,enableStreamingMarkdownBuffer:h,renderStreamingMarkdown:m,defaultMessage:f,handleFileClick:v,uploadingFiles:g,handleInterruptApprove:x,handleInterruptReject:y,disableInterruptActions:w,messageRole:S,truncateUserMessages:k,userMessagePreviewLength:C,isUserExpanded:T,setIsUserExpanded:E,isCompactLayout:N,activeInterruptId:R,activeInterruptValue:O,iconForeground:L}){const q=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ue.Loader,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),j=$T(s,(h??!0)&&d,Rp),X=b.useMemo(()=>j.filter(_=>_.type==="text"),[j]),G=b.useMemo(()=>X.map(_=>_.text??"").join(""),[X]),B=b.useMemo(()=>{if(!m)return null;const _=BT(G);return{stablePart:G.slice(0,_),tailPart:G.slice(_)}},[G,m]),M=b.useMemo(()=>{if(!B)return null;const{stablePart:_,tailPart:z}=B;return!_&&!z?null:u.jsxs("div",{className:"space-y-2",children:[_?u.jsx(qn,{content:_,allowHtml:!1}):null,z?u.jsx(qn,{content:z,allowHtml:!1}):null]})},[B]),I=b.useMemo(()=>{if(!m)return j;const _=[];let z=!1;for(const F of j){if(F.type==="text"){z||(_.push({type:"text",text:"",__streamingMarkdownAggregate:!0}),z=!0);continue}_.push(F)}return _},[j,m]),K=m?I:j,J=b.useCallback(({part:_,i:z})=>{if(_.type==="text"){if(m)return null;const F=_.text??"",re=F.trim(),V=Mi(re);return V&&S!=="tool"?u.jsx(dl,{data:V},z):S==="user"&&k&&re.length>C?u.jsx(Ap,{text:re,expanded:T,onExpandedChange:E,previewLength:C,isCompact:N},z):u.jsx(qn,{content:F,allowHtml:!1},z)}if(_.type==="image_url"){const F=_;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:F.url,alt:F.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},z)}if(_.type==="file"){const F=_,re=F.name||"file";return u.jsxs("a",{href:F.url,onClick:V=>v(V,F,z),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
129
129
|
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[g[z]?u.jsx(ue.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[re,g[z]?" (processing)":""]})]},z)}if(_.type==="interrupt"){const F=_,re=Yo((F==null?void 0:F.id)??(F==null?void 0:F.interrupt_id)),V=!!(R&&re&&re===R),D=V?O??(F==null?void 0:F.value):F==null?void 0:F.value,Z=re?{...F,id:re,interrupt_id:re}:F;return u.jsx(Ep,{interruptPart:Z,onApprove:x,onReject:y,disabled:w,isActive:V,payload:D},z)}return null},[R,O,w,v,x,y,N,T,S,k,g,C,m,E]),P=i.trim().length>0||a.length>0||l.length>0||c.length>0;if(!t&&l.length>0&&!d)return q();if(!t&&!P&&!d)return null;if(t)return n?u.jsx(jp,{message:e,viewMode:r,isStreaming:o},e.id):null;if(!f){const _=u.jsx("div",{className:"space-y-2",children:K.map((z,F)=>m&&zT(z)?M?u.jsx("div",{className:"space-y-2",children:M},`streaming-md-${F}`):null:u.jsx(J,{part:z,i:F},F))});return d?u.jsxs("div",{"aria-busy":"true",role:"status",children:[_,u.jsx(Np,{className:L})]}):_}return null}function Rp(e){return e?!(Io(e,/```/g)||Io(e,/`/g)||Io(e,/\*\*/g)||Io(e,/__/g)||Io(e,/~~/g)||/[^\\]\[[^\]]*$/.test(e)||/\[[^\]]*\]\([^)]*$/.test(e)):!0}function Io(e,t){const n=e.match(t);return((n==null?void 0:n.length)??0)%2!==0}function BT(e){if(!e)return 0;for(let t=e.length;t>=0;t-=1)if(Rp(e.slice(0,t)))return t;return 0}function zT(e){return e.type==="text"&&!!e.__streamingMarkdownAggregate}const HT=zr.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 Mp({className:e,variant:t,...n}){return u.jsx("div",{className:oe(HT({variant:t}),e),...n})}function UT({showTimestamp:e,showAgentName:t,isToolMessage:n,iconForeground:r,agentName:o,messageIcon:s,customHeaderClass:i,customActionsClass:a,isCompactLayout:l,showActions:c,isEditing:d,messageRole:h,toolViewMode:m,toolMeta:f,onToggleToolView:v,onCopy:g,onEdit:x,onRegenerate:y,showCheckpointControls:w,attemptCount:S,attemptIndex:k,handleOlderAttemptSelect:C,handleNewerAttemptSelect:T,messageCreatedAt:E,copied:N}){return!e&&!t&&!n?null:u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",l&&"mb-1 pb-1",r,i),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[s,t&&o&&u.jsx("span",{className:oe("font-medium",l?"text-xs":"text-sm"),children:o}),n&&u.jsxs(Mp,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",r,"border border-current/40",l&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":m==="expanded",onClick:v,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),v())},children:[u.jsx("span",{children:f.name??"Tool Output"}),f.toolCallId&&u.jsx("span",{className:"opacity-70",children:f.toolCallId.slice(0,8)}),m==="expanded"?u.jsx(ue.ChevronUp,{className:"h-3 w-3"}):u.jsx(ue.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[w&&S>1&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",k<S-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{k>=S-1||C()},"aria-label":"Older attempt (back in time)",disabled:k>=S-1,children:u.jsx(ue.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[S-k," / ",S]})}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",k>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{k<=0||T()},"aria-label":"Newer attempt (forward in time)",disabled:k<=0,children:u.jsx(ue.ChevronRight,{className:"h-3 w-3"})})]}),e&&E&&u.jsx("time",{className:oe("text-xs opacity-60",r,l&&"text-xs"),dateTime:new Date(E).toISOString(),title:new Date(E).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(E))}),c&&!d&&u.jsxs("div",{className:oe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",a),children:[u.jsx("div",{className:"relative",children:u.jsx(Ze,{variant:"ghost",size:"sm",onClick:g,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",r,l&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ue.Copy,{className:oe(N?"text-success":r,l?"h-3 w-3":"h-4 w-4")})})}),h==="user"&&x&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:x,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",r,l&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ue.Edit,{className:oe(r,l?"h-3 w-3":"h-4 w-4")})}),h==="assistant"&&y&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:y,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",r,l&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ue.RotateCcw,{className:oe(r,l?"h-3 w-3":"h-4 w-4")})})]})]})]})}const Xs=b.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:h=!0,customStyles:m={},streamingDebounceMs:f=300,renderStreamingMarkdown:v=!1,enableStreamingMarkdownBuffer:g,onEdit:x,onRegenerate:y,onCopy:w,activeInterrupt:S,disableInterruptActions:k=!1,onInterruptActionStart:C,onInterruptActionEnd:T,attemptCount:E=1,attemptIndex:N=0,onSelectCheckpoint:R,attemptMetas:O=[]}){const[L,q]=b.useState(!1),[W,j]=b.useState("preview"),[X,G]=b.useState(!1),{currentThreadId:B}=xr(),{respondToInterrupt:M}=eo(),I=l==="phone"||l==="half-screen",K=t.role,J=K==="tool",P=b.useMemo(()=>t.role==="default_message"?t:null,[t]),_=!!P,z=!(r&&K!=="user"),{uploadingFiles:F,handleFileClick:re,fileViewerOpen:V,currentFileInfo:D,closeFileViewer:Z}=_p({allowFileOpen:z,currentThreadId:B}),ee=b.useMemo(()=>{switch(K){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[K]),Q=Pp(t,P),{contentParts:H,imageParts:ae,fileParts:ie,interruptParts:ge,textContent:ye,toolMeta:Te,toolRaw:Ae,isToolStreaming:ke}=Q,st=g??f!==0,vt=(S==null?void 0:S.id)??(S==null?void 0:S.interrupt_id),kt=Yo(vt),Ve=S==null?void 0:S.value,ze=b.useCallback(async()=>{const Y=J?Ae:ye;async function fe(Be){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(Be);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const xe=new Blob([Be],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":xe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await fe(Y),q(!0),setTimeout(()=>q(!1),2e3),w==null||w(Y)}catch(Be){console.error("Failed to copy:",Be)}},[J,Ae,ye,w]),Ke=b.useCallback(()=>{if(!x||!t.id)return;const Y=(J?Ae:ye)??"",fe="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,Y,fe)},[x,t.id,J,Ae,ye,t]),Oe=b.useCallback(()=>{y==null||y(n)},[y,n]),Ue=b.useCallback(()=>{j(Y=>Y==="expanded"?"preview":"expanded")},[]),dt=b.useCallback(()=>{const fe=oe(I?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",ee);switch(K){case"user":return u.jsx(ue.User,{className:fe});case"assistant":return u.jsx(ue.Bot,{className:fe});case"tool":return u.jsx(ue.Wrench,{className:fe});default:return u.jsx(ue.Bot,{className:fe})}},[I,ee,K]),Nt=b.useCallback(()=>{const Y="group relative mb-4 flex w-full";switch(K){case"user":return oe(Y,"justify-end");case"assistant":case"tool":case"system":return oe(Y,"justify-start");default:return Y}},[K]),nt=b.useCallback(()=>{const Y=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",I&&"px-3 py-2 text-sm");if(_)return oe(Y,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(K){case"user":return oe(Y,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return oe(Y,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return oe(Y,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(Y,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(Y,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[I,_,K]),At=b.useCallback(async Y=>{if(k)return;const fe=Yo((Y==null?void 0:Y.id)??(Y==null?void 0:Y.interrupt_id));if(!fe){console.warn("Interrupt part missing id",Y);return}try{C==null||C(),await M(fe,!0)}catch(Be){console.error("Failed to approve interrupt:",Be)}finally{T==null||T()}},[k,T,C,M]),wt=b.useCallback(async Y=>{if(k)return;const fe=Yo((Y==null?void 0:Y.id)??(Y==null?void 0:Y.interrupt_id));if(!fe){console.warn("Interrupt part missing id",Y);return}try{C==null||C(),await M(fe,!1)}catch(Be){console.error("Failed to reject interrupt:",Be)}finally{T==null||T()}},[k,T,C,M]),mt=u.jsx(FT,{message:t,isToolMessage:J,showToolMessages:h,toolViewMode:W,isToolStreaming:ke,contentParts:H,textContent:ye,imageParts:ae,fileParts:ie,interruptParts:ge,isStreamingMessage:r,defaultMessage:P,enableStreamingMarkdownBuffer:st,renderStreamingMarkdown:v,handleFileClick:re,uploadingFiles:F,handleInterruptApprove:At,handleInterruptReject:wt,disableInterruptActions:k,messageRole:K,truncateUserMessages:c,userMessagePreviewLength:d,isUserExpanded:X,setIsUserExpanded:G,isCompactLayout:I,activeInterruptId:kt,activeInterruptValue:Ve,iconForeground:ee}),Et=b.useMemo(()=>P?"Assistant":eb(t),[P,t]),yt=dt(),jt=K==="user"&&(E??1)>1&&typeof R=="function",qt=(O==null?void 0:O.length)??0,gt=qt>0&&N<qt-1?O[N+1]:void 0,Pe=qt>0&&N>0?O[N-1]:void 0,We=b.useCallback(()=>{!gt||!R||R(gt.id,void 0,!!gt.isLatestAttempt)},[gt,R]),_t=b.useCallback(()=>{!Pe||!R||R(Pe.id,void 0,!!Pe.isLatestAttempt)},[Pe,R]);return J&&!h?null:_&&P?u.jsx("div",{className:oe(Nt(),m.container),children:u.jsxs("div",{className:oe(nt(),m.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ue.Bot,{className:oe("h-4 w-4",ee)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(qn,{content:P.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(Nt(),m.container),children:u.jsxs("div",{className:oe(nt(),m.content),children:[u.jsx(UT,{showTimestamp:i,showAgentName:a,isToolMessage:J,iconForeground:ee,agentName:Et,messageIcon:yt,customHeaderClass:m.header,customActionsClass:m.actions,isCompactLayout:I,showActions:s,isEditing:o,messageRole:K,toolViewMode:W,toolMeta:Te,onToggleToolView:Ue,onCopy:ze,onEdit:Ke,onRegenerate:Oe,showCheckpointControls:jt,attemptCount:E,attemptIndex:N,handleOlderAttemptSelect:We,handleNewerAttemptSelect:_t,messageCreatedAt:t.createdAt,copied:L}),u.jsx("div",{className:"relative",children:mt}),J&&W==="expanded"&&(Te.toolCallId||Te.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",I&&"text-xs"),children:[Te.name&&u.jsxs("div",{children:["Function: ",Te.name]}),Te.toolCallId&&u.jsxs("div",{children:["Call ID: ",Te.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:oe("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",m.actions),children:[u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>ze(),className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.Copy,{className:oe(L?"text-success":"text-current",I?"h-3 w-3":"h-4 w-4")})}),K==="user"&&x&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ke,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.Edit,{className:oe("text-current",I?"h-3 w-3":"h-4 w-4")})}),K==="assistant"&&y&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Oe,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",I&&"h-5 w-5"),children:u.jsx(ue.RotateCcw,{className:oe("text-current",I?"h-3 w-3":"h-4 w-4")})})]})]})}),D&&u.jsx(ap,{isOpen:V,onClose:Z,fileId:D.id,fileName:D.name,mimeType:D.mimeType})]})},(e,t)=>{var l,c,d,h,m,f,v,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&mu(e.message)===mu(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(x=>e[x]===t[x]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((h=t.customStyles)==null?void 0:h.content)&&((m=e.customStyles)==null?void 0:m.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((v=e.customStyles)==null?void 0:v.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=gu(e.message),a=gu(t.message);return i.length===a.length});Xs.displayName="MessageComponent";const pl=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:h,style:m,emptyMessage:f,followNewMessages:v=!0,isNavigatingCheckpoint:g=!1,onScrollAway:x,onAtBottom:y,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,checkpointIndex:E,activeCheckpointId:N,onSelectCheckpoint:R,createSyntheticThinkingMessage:O=!0,forceSyntheticThinking:L=!1},q)=>{const W=b.useRef(null),j=b.useRef(null),X=b.useRef(!1),G=b.useRef(!1),[B,M]=b.useState(!0),I=b.useMemo(()=>w?e.some(H=>H.role==="default_message"?!1:Array.isArray(H==null?void 0:H.content)&&H.content.some(ae=>ae&&ae.type==="interrupt"&&(ae.id??ae.interrupt_id)===w.id)):!1,[w,e]),K=b.useMemo(()=>{if(!w||I)return null;const H=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let ae;const ie=w.value;if(ie&&typeof ie=="object"&&!Array.isArray(ie)){const ge=ie.title;typeof ge=="string"&&ge.trim()&&(ae=ge.trim())}return{id:`interrupt-${H}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:H,value:ie,title:ae}]}},[w,I]),J=b.useMemo(()=>K?[...e,K]:e,[e,K]),P=b.useMemo(()=>{const H=n&&J.some(ie=>ie.id===n);return O&&(t||L)&&!H&&J.length>0?[...J,{id:"thinking-assistant",role:"assistant",content:[{type:"text",text:""}],createdAt:new Date().toISOString(),__syntheticStreaming:!0}]:J},[J,t,n,O,L]),_=b.useMemo(()=>T?P:P.filter(H=>(H==null?void 0:H.role)!=="tool"),[P,T]),z=b.useCallback(H=>{M(H),x&&x(!H),y&&y(H)},[x,y]),F=b.useMemo(()=>{if(a)return async()=>{if(!X.current){X.current=!0;try{await a()}finally{X.current=!1}}}},[a]),re=b.useMemo(()=>!v||g?!1:B?"auto":!1,[B,v,g]),V=b.useMemo(()=>{if(typeof f!="string")return null;const H=f.trim();return!H||_&&_.length>0?null:{id:"default-message",role:"default_message",content:H,createdAt:new Date().toISOString()}},[f,_]),D=["flex h-full flex-col md:flex-row",h].filter(Boolean).join(" "),Z=()=>V?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Xs,{message:V,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:f??"No messages yet. Start a conversation!"}),ee=_.length,Q=ee>0;return b.useEffect(()=>{var H,ae;if(ee===0){G.current=!1;return}if(!G.current)if(G.current=!0,W.current&&_.length>0){const ie=_.length-1;(ae=(H=W.current).scrollToIndex)==null||ae.call(H,{index:ie,align:"end",behavior:"auto"})}else j.current&&(j.current.scrollTop=j.current.scrollHeight)},[ee,_.length]),b.useImperativeHandle(q,()=>({scrollToLatest:()=>{var H,ae;if(W.current&&_.length>0){const ie=_.length-1;(ae=(H=W.current).scrollToIndex)==null||ae.call(H,{index:ie,align:"end",behavior:"auto"})}else j.current&&(j.current.scrollTop=j.current.scrollHeight)},scrollToTop:()=>{var H,ae;W.current&&_.length>0?(ae=(H=W.current).scrollToIndex)==null||ae.call(H,{index:0,align:"start",behavior:"auto"}):j.current&&(j.current.scrollTop=0)}}),[_]),u.jsx("div",{className:D,style:m,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:Q?u.jsx(FC,{ref:H=>{W.current=H},scrollerRef:H=>{j.current=H instanceof HTMLDivElement?H:null},data:_,followOutput:re,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{F&&F()},atBottomStateChange:z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(H,ae)=>fl(ae,H),itemContent:(H,ae)=>u.jsx(hl,{message:ae,index:H,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,checkpointIndex:E,activeCheckpointId:N,onSelectCheckpoint:R})}):Z()})})});pl.displayName="MessageList";const Op={value:""};function Mr({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,payloadExtras:h={},customStyles:m={},onMessageSent:f,onExcelUploadSuccess:v,onError:g}){const{api:x}=Xr(),{currentThreadId:y}=xr(),{threadId:w,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:N,checkpoints:R,interrupt:O,metadata:L,checkpointIndex:q}=eo(),{isStreaming:W,error:j,connectionState:X,submit:G,stop:B}=$i(),M=w??y??null,I=(N==null?void 0:N.id)??null,K=(N==null?void 0:N.namespace)??null,J=(L==null?void 0:L.assemblingMessageId)??null,P=O,[_,z]=b.useState(!1),[F,re]=b.useState(!1);b.useEffect(()=>{P||z(!1)},[P]);const V=b.useCallback(()=>{z(!0)},[]),D=b.useCallback(()=>{z(!1)},[]),Z=!!P||_,[ee,Q]=b.useState(null),[H,ae]=b.useState(""),[ie,ge]=b.useState(null),[ye,Te]=b.useState(null),[Ae,ke]=b.useState([]),[st,vt]=b.useState(0),[kt,Ve]=b.useState(0),[ze,Ke]=b.useState(!1),[Oe,Ue]=b.useState(null),[dt,Nt]=b.useState(null),[nt,At]=b.useState(!1),[wt,mt]=b.useState(null),Et=b.useRef(!1),[yt,jt]=b.useState(()=>Op.value),qt=b.useRef(yt),gt=b.useRef(null),Pe=b.useCallback(le=>{Op.value=le,jt(le)},[]),[We,_t]=b.useState(!1),Y=b.useRef(null),fe=b.useRef(null),Be=b.useRef(null),xe=b.useCallback(()=>{fe.current&&(fe.current.value=""),Be.current&&(Be.current.value=""),vt(le=>le+1),Ve(le=>le+1)},[]),Fe=b.useCallback(le=>{Pe(le)},[Pe]),Ge=b.useRef(!1);b.useEffect(()=>{Ge.current&&!W&&(ke([]),xe()),Ge.current=W},[W,xe]),b.useEffect(()=>{W||re(!1)},[W]),b.useEffect(()=>{L!=null&&L.assemblingMessageId&&re(!1)},[L==null?void 0:L.assemblingMessageId]);const[St,Ct]=b.useState("desktop");b.useEffect(()=>{const le=()=>{const de=window.innerWidth;Ct(de<640?"phone":de<1024?"tablet":"desktop")};return le(),window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[]),b.useEffect(()=>{Et.current=!1},[M]),b.useEffect(()=>{qt.current=yt},[yt]),b.useEffect(()=>{if(!ee){gt.current=null;return}gt.current===null&&(gt.current=qt.current),Pe(H??"")},[H,ee,Pe]),b.useEffect(()=>{(async()=>{if(!x.baseUrl){mt(null);return}try{const Ce=(await x.getAgent("default")).uiDefaultMessage||"";mt(Ce||null)}catch(de){console.warn("Failed to fetch default message:",de),mt(null)}})()},[x.baseUrl]),b.useEffect(()=>{j&&!nt&&(g==null||g(j))},[j,nt,g]);const It=async le=>{const de=le.trim();if(!(!de&&Ae.length===0))try{const Ce=ee?(ie==null?void 0:ie.checkpointId)??I??void 0:I??void 0,De=ee?(ie==null?void 0:ie.checkpointNs)??K??void 0:K??void 0;await G({text:de||"",attachments:Ae,payload:h},{checkpointId:Ce,checkpointNs:De,edit:!!ee,originalMessageId:ee??void 0}),f==null||f(de),re(!0),Pe(""),Te(null),ke([]),xe(),Q(null),ae(""),ge(null)}catch(Ce){const De=(Ce==null?void 0:Ce.message)||"Failed to send message";Te(De),g==null||g(De),re(!1)}},Lt=b.useCallback((le,de,Ce)=>{c&&(gt.current=yt,Q(le),ae(de),Pe(de),Te(null),ge({checkpointId:(Ce==null?void 0:Ce.checkpointId)??null,checkpointNs:(Ce==null?void 0:Ce.checkpointNs)??null}))},[yt,c,Pe]),je=b.useCallback(()=>{Q(null),ae(""),ge(null),Te(null),Pe(gt.current??yt),gt.current=null},[yt,Pe]),ct=b.useCallback((le,de,Ce)=>{Lt(le,de,Ce)},[Lt]),Xe=b.useCallback(le=>{let de=null;for(let ut=le-1;ut>=0;ut--)if(S[ut].role==="user"){de=S[ut];break}if(!de)return;const Ce=Array.isArray(de.content)?de.content:[],it=Ce.filter(ut=>(ut==null?void 0:ut.type)==="text").map(ut=>ut.text).join("")||(()=>{try{return JSON.stringify(Ce,null,2)}catch{return String(Ce)}})();it&&G({text:it,payload:h},{checkpointId:I??void 0,checkpointNs:K??void 0,edit:!0,originalMessageId:de.id})},[S,G,I,K,h]),lt=le=>{const de=Array.from(le.target.files||[]);ke(Ce=>[...Ce,...de]),le.target.value=""},an=le=>{ke(de=>{const Ce=de.filter((De,it)=>le!==it);return Ce.length===0&&xe(),Ce})},A=async le=>{const de=(le.target.files||[])[0];if(de){Ue(null),Nt(null),Ke(!0);try{await G({attachments:[de],payload:h},{checkpointId:I??void 0,checkpointNs:K??void 0});const Ce=`Uploaded ${de.name} - processing through chat stream`;Nt(Ce)}catch(Ce){const De=Ce instanceof Error?Ce.message:"Failed to upload Excel file";console.error("Excel upload failed",Ce),Ue(De),g==null||g(De)}finally{Ke(!1),le.target.value="",xe()}}},te=async le=>{if(y){_t(!0);try{if(!le){await E(),requestAnimationFrame(()=>{var De;(De=Y.current)==null||De.scrollToLatest()});return}const de=R.find(De=>De.checkpointId===le),Ce=(de==null?void 0:de.checkpointNs)??null;await T(le,Ce),requestAnimationFrame(()=>{var De;(De=Y.current)==null||De.scrollToTop()})}finally{_t(!1)}}},he=b.useCallback(async(le,de,Ce)=>{await te(Ce?null:le)},[te]),Ie=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${m.container||""}`,Ye=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${m.messagesArea||""}`,Qe=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${m.inputArea||""}`;return u.jsxs("div",{className:Ie,children:[!!j&&!nt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:j}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>At(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ue.X,{size:16})})]}),u.jsxs("div",{className:`relative ${Ye}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(pl,{ref:Y,className:"h-full",style:{height:"100%"},messages:S,isStreaming:W,streamingAssistantId:J,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:St,enableMessageEditing:c,editingMessageId:ee,onEdit:ct,onRegenerate:Xe,onCancelEdit:je,emptyMessage:wt??void 0,isNavigatingCheckpoint:We,activeInterrupt:P,disableInterruptActions:_,onInterruptActionStart:V,onInterruptActionEnd:D,showToolMessages:d,checkpointIndex:q,activeCheckpointId:I,onSelectCheckpoint:he,createSyntheticThinkingMessage:!0,forceSyntheticThinking:F}),(X==="reconnecting"||X==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),X==="reconnecting"?"Reconnecting…":"Connecting…"]})}),X==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||We)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:Qe,children:[ee&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ue.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:je,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ue.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:fe,type:"file",multiple:!0,onChange:le=>lt(le),className:"hidden"},st),Ae.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Ae.map((le,de)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(ue.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:le.name}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>an(de),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${le.name}`,children:u.jsx(ue.X,{size:12})})]},de))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Be,type:"file",accept:".xls,.xlsx,.xlsm",onChange:A,className:"hidden"},kt),ze&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),dt&&!ze&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:dt}),Oe&&!ze&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Oe})]})]}),ye&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:ye}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Cs,{children:[u.jsx(Ts,{asChild:!0,children:u.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:W||Z,title:"More input actions",className:m.moreButton||"",children:u.jsx(ue.Plus,{size:16})})}),u.jsxs(ho,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Bn,{onClick:()=>{var le;return(le=fe.current)==null?void 0:le.click()},className:"cursor-pointer",children:[u.jsx(ue.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Bn,{onClick:()=>{var le;ze||(le=Be.current)==null||le.click()},className:`cursor-pointer ${ze?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ue.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(AS,{initialValue:H,editingMessageId:ee,value:yt,onValueChange:Fe,placeholder:ee?"Edit your message...":t,isStreaming:W,disabled:Z,onSend:It,onCancelEdit:je,onStop:B,allowEmptySend:Ae.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${ee?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${ye?"border-red-400":""} ${m.textarea||""}`})})]})]})]})}var Dp=1,WT=.9,VT=.8,KT=.17,ml=.1,gl=.999,qT=.9999,GT=.99,YT=/[\\\/_+.#"@\[\(\{&]/,XT=/[\\\/_+.#"@\[\(\{&]/g,JT=/[\s-]/,Lp=/[\s-]/g;function xl(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?Dp:GT;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),d=0,h,m,f,v;c>=0;)h=xl(e,t,n,r,c+1,s+1,i),h>d&&(c===o?h*=Dp:YT.test(e.charAt(c-1))?(h*=VT,f=e.slice(o,c-1).match(XT),f&&o>0&&(h*=Math.pow(gl,f.length))):JT.test(e.charAt(c-1))?(h*=WT,v=e.slice(o,c-1).match(Lp),v&&o>0&&(h*=Math.pow(gl,v.length))):(h*=KT,o>0&&(h*=Math.pow(gl,c-o))),e.charAt(c)!==t.charAt(s)&&(h*=qT)),(h<ml&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(m=xl(e,t,n,r,c+1,s+2,i),m*ml>h&&(h=m*ml)),h>d&&(d=h),c=n.indexOf(l,c+1);return i[a]=d,d}function $p(e){return e.toLowerCase().replace(Lp," ")}function ZT(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,xl(e,t,$p(e),$p(t),0,0,{})}var No='[cmdk-group=""]',vl='[cmdk-group-items=""]',QT='[cmdk-group-heading=""]',Fp='[cmdk-item=""]',Bp=`${Fp}:not([aria-disabled="true"])`,bl="cmdk-item-select",Or="data-value",ek=(e,t,n)=>ZT(e,t,n),zp=p.createContext(void 0),Ao=()=>p.useContext(zp),Hp=p.createContext(void 0),wl=()=>p.useContext(Hp),Up=p.createContext(void 0),Wp=p.forwardRef((e,t)=>{let n=Dr(()=>{var P,_;return{search:"",value:(_=(P=e.value)!=null?P:e.defaultValue)!=null?_:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Dr(()=>new Set),o=Dr(()=>new Map),s=Dr(()=>new Map),i=Dr(()=>new Set),a=Vp(e),{label:l,children:c,value:d,onValueChange:h,filter:m,shouldFilter:f,loop:v,disablePointerSelection:g=!1,vimBindings:x=!0,...y}=e,w=Rt(),S=Rt(),k=Rt(),C=p.useRef(null),T=dk();ur(()=>{if(d!==void 0){let P=d.trim();n.current.value=P,E.emit()}},[d]),ur(()=>{T(6,W)},[]);let E=p.useMemo(()=>({subscribe:P=>(i.current.add(P),()=>i.current.delete(P)),snapshot:()=>n.current,setState:(P,_,z)=>{var F,re,V,D;if(!Object.is(n.current[P],_)){if(n.current[P]=_,P==="search")q(),O(),T(1,L);else if(P==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let Z=document.getElementById(k);Z?Z.focus():(F=document.getElementById(w))==null||F.focus()}if(T(7,()=>{var Z;n.current.selectedItemId=(Z=j())==null?void 0:Z.id,E.emit()}),z||T(5,W),((re=a.current)==null?void 0:re.value)!==void 0){let Z=_??"";(D=(V=a.current).onValueChange)==null||D.call(V,Z);return}}E.emit()}},emit:()=>{i.current.forEach(P=>P())}}),[]),N=p.useMemo(()=>({value:(P,_,z)=>{var F;_!==((F=s.current.get(P))==null?void 0:F.value)&&(s.current.set(P,{value:_,keywords:z}),n.current.filtered.items.set(P,R(_,z)),T(2,()=>{O(),E.emit()}))},item:(P,_)=>(r.current.add(P),_&&(o.current.has(_)?o.current.get(_).add(P):o.current.set(_,new Set([P]))),T(3,()=>{q(),O(),n.current.value||L(),E.emit()}),()=>{s.current.delete(P),r.current.delete(P),n.current.filtered.items.delete(P);let z=j();T(4,()=>{q(),(z==null?void 0:z.getAttribute("id"))===P&&L(),E.emit()})}),group:P=>(o.current.has(P)||o.current.set(P,new Set),()=>{s.current.delete(P),o.current.delete(P)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:w,inputId:k,labelId:S,listInnerRef:C}),[]);function R(P,_){var z,F;let re=(F=(z=a.current)==null?void 0:z.filter)!=null?F:ek;return P?re(P,n.current.search,_):0}function O(){if(!n.current.search||a.current.shouldFilter===!1)return;let P=n.current.filtered.items,_=[];n.current.filtered.groups.forEach(F=>{let re=o.current.get(F),V=0;re.forEach(D=>{let Z=P.get(D);V=Math.max(Z,V)}),_.push([F,V])});let z=C.current;X().sort((F,re)=>{var V,D;let Z=F.getAttribute("id"),ee=re.getAttribute("id");return((V=P.get(ee))!=null?V:0)-((D=P.get(Z))!=null?D:0)}).forEach(F=>{let re=F.closest(vl);re?re.appendChild(F.parentElement===re?F:F.closest(`${vl} > *`)):z.appendChild(F.parentElement===z?F:F.closest(`${vl} > *`))}),_.sort((F,re)=>re[1]-F[1]).forEach(F=>{var re;let V=(re=C.current)==null?void 0:re.querySelector(`${No}[${Or}="${encodeURIComponent(F[0])}"]`);V==null||V.parentElement.appendChild(V)})}function L(){let P=X().find(z=>z.getAttribute("aria-disabled")!=="true"),_=P==null?void 0:P.getAttribute(Or);E.setState("value",_||void 0)}function q(){var P,_,z,F;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let re=0;for(let V of r.current){let D=(_=(P=s.current.get(V))==null?void 0:P.value)!=null?_:"",Z=(F=(z=s.current.get(V))==null?void 0:z.keywords)!=null?F:[],ee=R(D,Z);n.current.filtered.items.set(V,ee),ee>0&&re++}for(let[V,D]of o.current)for(let Z of D)if(n.current.filtered.items.get(Z)>0){n.current.filtered.groups.add(V);break}n.current.filtered.count=re}function W(){var P,_,z;let F=j();F&&(((P=F.parentElement)==null?void 0:P.firstChild)===F&&((z=(_=F.closest(No))==null?void 0:_.querySelector(QT))==null||z.scrollIntoView({block:"nearest"})),F.scrollIntoView({block:"nearest"}))}function j(){var P;return(P=C.current)==null?void 0:P.querySelector(`${Fp}[aria-selected="true"]`)}function X(){var P;return Array.from(((P=C.current)==null?void 0:P.querySelectorAll(Bp))||[])}function G(P){let _=X()[P];_&&E.setState("value",_.getAttribute(Or))}function B(P){var _;let z=j(),F=X(),re=F.findIndex(D=>D===z),V=F[re+P];(_=a.current)!=null&&_.loop&&(V=re+P<0?F[F.length-1]:re+P===F.length?F[0]:F[re+P]),V&&E.setState("value",V.getAttribute(Or))}function M(P){let _=j(),z=_==null?void 0:_.closest(No),F;for(;z&&!F;)z=P>0?ck(z,No):uk(z,No),F=z==null?void 0:z.querySelector(Bp);F?E.setState("value",F.getAttribute(Or)):B(P)}let I=()=>G(X().length-1),K=P=>{P.preventDefault(),P.metaKey?I():P.altKey?M(1):B(1)},J=P=>{P.preventDefault(),P.metaKey?G(0):P.altKey?M(-1):B(-1)};return p.createElement(ve.div,{ref:t,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:P=>{var _;(_=y.onKeyDown)==null||_.call(y,P);let z=P.nativeEvent.isComposing||P.keyCode===229;if(!(P.defaultPrevented||z))switch(P.key){case"n":case"j":{x&&P.ctrlKey&&K(P);break}case"ArrowDown":{K(P);break}case"p":case"k":{x&&P.ctrlKey&&J(P);break}case"ArrowUp":{J(P);break}case"Home":{P.preventDefault(),G(0);break}case"End":{P.preventDefault(),I();break}case"Enter":{P.preventDefault();let F=j();if(F){let re=new Event(bl);F.dispatchEvent(re)}}}}},p.createElement("label",{"cmdk-label":"",htmlFor:N.inputId,id:N.labelId,style:hk},l),Js(e,P=>p.createElement(Hp.Provider,{value:E},p.createElement(zp.Provider,{value:N},P))))}),tk=p.forwardRef((e,t)=>{var n,r;let o=Rt(),s=p.useRef(null),i=p.useContext(Up),a=Ao(),l=Vp(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;ur(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let d=Kp(o,s,[e.value,e.children,s],e.keywords),h=wl(),m=Gn(T=>T.value&&T.value===d.current),f=Gn(T=>c||a.filter()===!1?!0:T.search?T.filtered.items.get(o)>0:!0);p.useEffect(()=>{let T=s.current;if(!(!T||e.disabled))return T.addEventListener(bl,v),()=>T.removeEventListener(bl,v)},[f,e.onSelect,e.disabled]);function v(){var T,E;g(),(E=(T=l.current).onSelect)==null||E.call(T,d.current)}function g(){h.setState("value",d.current,!0)}if(!f)return null;let{disabled:x,value:y,onSelect:w,forceMount:S,keywords:k,...C}=e;return p.createElement(ve.div,{ref:On(s,t),...C,id:o,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!m,"data-disabled":!!x,"data-selected":!!m,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:v},e.children)}),nk=p.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=Rt(),a=p.useRef(null),l=p.useRef(null),c=Rt(),d=Ao(),h=Gn(f=>o||d.filter()===!1?!0:f.search?f.filtered.groups.has(i):!0);ur(()=>d.group(i),[]),Kp(i,a,[e.value,e.heading,l]);let m=p.useMemo(()=>({id:i,forceMount:o}),[o]);return p.createElement(ve.div,{ref:On(a,t),...s,"cmdk-group":"",role:"presentation",hidden:h?void 0:!0},n&&p.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Js(e,f=>p.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},p.createElement(Up.Provider,{value:m},f))))}),rk=p.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=p.useRef(null),s=Gn(i=>!i.search);return!n&&!s?null:p.createElement(ve.div,{ref:On(o,t),...r,"cmdk-separator":"",role:"separator"})}),ok=p.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=wl(),i=Gn(c=>c.search),a=Gn(c=>c.selectedItemId),l=Ao();return p.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),p.createElement(ve.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),sk=p.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=p.useRef(null),i=p.useRef(null),a=Gn(c=>c.selectedItemId),l=Ao();return p.useEffect(()=>{if(i.current&&s.current){let c=i.current,d=s.current,h,m=new ResizeObserver(()=>{h=requestAnimationFrame(()=>{let f=c.offsetHeight;d.style.setProperty("--cmdk-list-height",f.toFixed(1)+"px")})});return m.observe(c),()=>{cancelAnimationFrame(h),m.unobserve(c)}}},[]),p.createElement(ve.div,{ref:On(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Js(e,c=>p.createElement("div",{ref:On(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),ik=p.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return p.createElement(Za,{open:n,onOpenChange:r},p.createElement(Qa,{container:i},p.createElement(To,{"cmdk-overlay":"",className:o}),p.createElement(ko,{"aria-label":e.label,"cmdk-dialog":"",className:s},p.createElement(Wp,{ref:t,...a}))))}),ak=p.forwardRef((e,t)=>Gn(n=>n.filtered.count===0)?p.createElement(ve.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),lk=p.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return p.createElement(ve.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Js(e,i=>p.createElement("div",{"aria-hidden":!0},i)))}),Vt=Object.assign(Wp,{List:sk,Item:tk,Input:ok,Group:nk,Separator:rk,Dialog:ik,Empty:ak,Loading:lk});function ck(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function uk(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Vp(e){let t=p.useRef(e);return ur(()=>{t.current=e}),t}var ur=typeof window>"u"?p.useEffect:p.useLayoutEffect;function Dr(e){let t=p.useRef();return t.current===void 0&&(t.current=e()),t}function Gn(e){let t=wl(),n=()=>e(t.snapshot());return p.useSyncExternalStore(t.subscribe,n,n)}function Kp(e,t,n,r=[]){let o=p.useRef(),s=Ao();return ur(()=>{var i;let a=(()=>{var c;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(c=d.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(Or,a),o.current=a}),o}var dk=()=>{let[e,t]=p.useState(),n=Dr(()=>new Map);return ur(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function fk(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Js({asChild:e,children:t},n){return e&&p.isValidElement(t)?p.cloneElement(fk(t),{ref:t.ref},n(t.props.children)):n(t)}var hk={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const yl=p.forwardRef(({className:e,...t},n)=>u.jsx(Vt,{ref:n,className:oe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));yl.displayName=Vt.displayName;const Sl=p.forwardRef(({className:e,...t},n)=>u.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[u.jsx(ue.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),u.jsx(Vt.Input,{ref:n,className:oe("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Sl.displayName=Vt.Input.displayName;const Cl=p.forwardRef(({className:e,...t},n)=>u.jsx(Vt.List,{ref:n,className:oe("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));Cl.displayName=Vt.List.displayName;const Tl=p.forwardRef((e,t)=>u.jsx(Vt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));Tl.displayName=Vt.Empty.displayName;const kl=p.forwardRef(({className:e,...t},n)=>u.jsx(Vt.Group,{ref:n,className:oe("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));kl.displayName=Vt.Group.displayName;const pk=p.forwardRef(({className:e,...t},n)=>u.jsx(Vt.Separator,{ref:n,className:oe("-mx-1 h-px bg-border",e),...t}));pk.displayName=Vt.Separator.displayName;const El=p.forwardRef(({className:e,...t},n)=>u.jsx(Vt.Item,{ref:n,className:oe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));El.displayName=Vt.Item.displayName;function Il(e,[t,n]){return Math.min(n,Math.max(t,e))}function mk(e,t){return p.useReducer((n,r)=>t[n][r]??n,e)}var Nl="ScrollArea",[qp,PN]=cn(Nl),[gk,sn]=qp(Nl),Gp=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=p.useState(null),[c,d]=p.useState(null),[h,m]=p.useState(null),[f,v]=p.useState(null),[g,x]=p.useState(null),[y,w]=p.useState(0),[S,k]=p.useState(0),[C,T]=p.useState(!1),[E,N]=p.useState(!1),R=Le(t,L=>l(L)),O=Jo(o);return u.jsx(gk,{scope:n,type:r,dir:O,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:h,onContentChange:m,scrollbarX:f,onScrollbarXChange:v,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:x,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:w,onCornerHeightChange:k,children:u.jsx(ve.div,{dir:O,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Gp.displayName=Nl;var Yp="ScrollAreaViewport",Xp=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=sn(Yp,n),a=p.useRef(null),l=Le(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(ve.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Xp.displayName=Yp;var In="ScrollAreaScrollbar",Al=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(In,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return p.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(xk,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(vk,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Jp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(jl,{...r,ref:t}):null});Al.displayName=In;var xk=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(In,e.__scopeScrollArea),[s,i]=p.useState(!1);return p.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Ut,{present:n||s,children:u.jsx(Jp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),vk=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(In,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ti(()=>l("SCROLL_END"),100),[a,l]=mk("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return p.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),p.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let h=c[d];const m=()=>{const f=c[d];h!==f&&(l("SCROLL"),i()),h=f};return c.addEventListener("scroll",m),()=>c.removeEventListener("scroll",m)}},[o.viewport,s,l,i]),u.jsx(Ut,{present:n||a!=="hidden",children:u.jsx(jl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ce(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ce(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Jp=p.forwardRef((e,t)=>{const n=sn(In,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=p.useState(!1),a=e.orientation==="horizontal",l=ti(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Lr(n.viewport,l),Lr(n.content,l),u.jsx(Ut,{present:r||s,children:u.jsx(jl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),jl=p.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=sn(In,e.__scopeScrollArea),s=p.useRef(null),i=p.useRef(0),[a,l]=p.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=nm(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:m=>i.current=m};function h(m,f){return Tk(m,i.current,a,f)}return n==="horizontal"?u.jsx(bk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,f=rm(m,a,o.dir);s.current.style.transform=`translate3d(${f}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=h(m,o.dir))}}):n==="vertical"?u.jsx(wk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,f=rm(m,a);s.current.style.transform=`translate3d(0, ${f}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=h(m))}}):null}),bk=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(In,e.__scopeScrollArea),[i,a]=p.useState(),l=p.useRef(null),c=Le(t,l,s.onScrollbarXChange);return p.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Qp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":ei(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,h)=>{if(s.viewport){const m=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(m),sm(m,h)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Qs(i.paddingLeft),paddingEnd:Qs(i.paddingRight)}})}})}),wk=p.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(In,e.__scopeScrollArea),[i,a]=p.useState(),l=p.useRef(null),c=Le(t,l,s.onScrollbarYChange);return p.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Qp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":ei(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,h)=>{if(s.viewport){const m=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(m),sm(m,h)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Qs(i.paddingTop),paddingEnd:Qs(i.paddingBottom)}})}})}),[yk,Zp]=qp(In),Qp=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:h,...m}=e,f=sn(In,n),[v,g]=p.useState(null),x=Le(t,R=>g(R)),y=p.useRef(null),w=p.useRef(""),S=f.viewport,k=r.content-r.viewport,C=ht(d),T=ht(l),E=ti(h,10);function N(R){if(y.current){const O=R.clientX-y.current.left,L=R.clientY-y.current.top;c({x:O,y:L})}}return p.useEffect(()=>{const R=O=>{const L=O.target;(v==null?void 0:v.contains(L))&&C(O,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[S,v,k,C]),p.useEffect(T,[r,T]),Lr(v,E),Lr(f.content,E),u.jsx(yk,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:ht(s),onThumbPointerUp:ht(i),onThumbPositionChange:T,onThumbPointerDown:ht(a),children:u.jsx(ve.div,{...m,ref:x,style:{position:"absolute",...m.style},onPointerDown:ce(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),y.current=v.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",f.viewport&&(f.viewport.style.scrollBehavior="auto"),N(R))}),onPointerMove:ce(e.onPointerMove,N),onPointerUp:ce(e.onPointerUp,R=>{const O=R.target;O.hasPointerCapture(R.pointerId)&&O.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=w.current,f.viewport&&(f.viewport.style.scrollBehavior=""),y.current=null})})})}),Zs="ScrollAreaThumb",em=p.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zp(Zs,e.__scopeScrollArea);return u.jsx(Ut,{present:n||o.hasThumb,children:u.jsx(Sk,{ref:t,...r})})}),Sk=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=sn(Zs,n),i=Zp(Zs,n),{onThumbPositionChange:a}=i,l=Le(t,h=>i.onThumbChange(h)),c=p.useRef(void 0),d=ti(()=>{c.current&&(c.current(),c.current=void 0)},100);return p.useEffect(()=>{const h=s.viewport;if(h){const m=()=>{if(d(),!c.current){const f=kk(h,a);c.current=f,a()}};return a(),h.addEventListener("scroll",m),()=>h.removeEventListener("scroll",m)}},[s.viewport,d,a]),u.jsx(ve.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ce(e.onPointerDownCapture,h=>{const f=h.target.getBoundingClientRect(),v=h.clientX-f.left,g=h.clientY-f.top;i.onThumbPointerDown({x:v,y:g})}),onPointerUp:ce(e.onPointerUp,i.onThumbPointerUp)})});em.displayName=Zs;var _l="ScrollAreaCorner",tm=p.forwardRef((e,t)=>{const n=sn(_l,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(Ck,{...e,ref:t}):null});tm.displayName=_l;var Ck=p.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=sn(_l,n),[s,i]=p.useState(0),[a,l]=p.useState(0),c=!!(s&&a);return Lr(o.scrollbarX,()=>{var h;const d=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Lr(o.scrollbarY,()=>{var h;const d=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(ve.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Qs(e){return e?parseInt(e,10):0}function nm(e,t){const n=e/t;return isNaN(n)?0:n}function ei(e){const t=nm(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function Tk(e,t,n,r="ltr"){const o=ei(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,h=r==="ltr"?[0,d]:[d*-1,0];return om([l,c],h)(e)}function rm(e,t,n="ltr"){const r=ei(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Il(e,l);return om([0,i],[0,a])(c)}function om(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function sm(e,t){return e>0&&e<t}var kk=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function ti(e,t){const n=ht(e),r=p.useRef(0);return p.useEffect(()=>()=>window.clearTimeout(r.current),[]),p.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Lr(e,t){const n=ht(t);Tt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var im=Gp,Ek=Xp,Ik=tm;const Pl=p.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(im,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(Ek,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(am,{}),u.jsx(Ik,{})]}));Pl.displayName=im.displayName;const am=p.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Al,{ref:r,orientation:t,className:oe("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(em,{className:"relative flex-1 rounded-full bg-border"})}));am.displayName=Al.displayName;const Rl=p.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:oe("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground 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 md:text-sm",e),ref:r,...n}));Rl.displayName="Input";const Nk="group relative p-3 rounded-lg cursor-pointer transition-colors border text-gray-900 dark:text-slate-100",Ak="bg-slate-700 border-slate-600 hover:bg-slate-600",jk="bg-slate-600 border-slate-500";function lm({thread:e,isActive:t,editingThreadId:n,editingTitle:r,onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:c,onDelete:d,showEditTitle:h,showDeleteButton:m,formatDate:f,getDisplayThreadTitle:v,secondaryLine:g,itemClassName:x,activeItemClassName:y}){const w=n===e.threadId,S=t?`${y??jk}`:`${x??Ak}`,k=C=>{C.stopPropagation(),o(e.threadId)};return u.jsxs("div",{onClick:k,className:`${Nk} ${S}`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:w?u.jsxs("div",{className:"flex items-center gap-2",onClick:C=>C.stopPropagation(),children:[u.jsx(Rl,{value:r,onChange:C=>i(C.target.value),onKeyDown:C=>{C.key==="Enter"?a(e.threadId):C.key==="Escape"&&l()},className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>a(e.threadId),className:"h-6 w-6 p-0",children:u.jsx(ue.Check,{size:12})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:l,className:"h-6 w-6 p-0",children:u.jsx(ue.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:v(e)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ue.Calendar,{size:10}),u.jsx("span",{children:f(e.updatedAt||e.createdAt)})]}),g&&u.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:g})]})}),u.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:u.jsxs(Cs,{children:[u.jsx(Ts,{asChild:!0,children:u.jsx(Ze,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:u.jsx(ue.MoreHorizontal,{size:12})})}),u.jsxs(ho,{align:"end",sideOffset:6,className:"w-44",children:[u.jsxs(Bn,{onClick:C=>{C.preventDefault(),c(e.threadId)},children:[u.jsx(ue.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),h&&n!==e.threadId&&u.jsxs(Bn,{onClick:C=>{C.preventDefault(),s(e,C)},children:[u.jsx(ue.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),m&&d&&u.jsxs(Bn,{className:"text-red-400 hover:text-red-300",onClick:C=>{C.preventDefault(),d(e.threadId,C)},children:[u.jsx(ue.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),t&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]})}const cm=25,um="thread-manager-view",_k=e=>e==="default"||e==="shared",Pk=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(um);if(_k(e))return e}catch{}return null};function dm({defaultView:e}={}){const[t,n]=b.useState(()=>Pk()??e??"default");b.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(um,t)}catch{}},[t]);const r=b.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const Rk=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function ni({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d,view:h,defaultView:m,onViewChange:f,viewOptions:v,viewState:g,showHeader:x=!0,shareTargets:y,isLoadingShareTargets:w,shareTargetFilter:S}){const{threads:k,sharedThreads:C,currentThreadId:T,setCurrentThreadId:E,isLoading:N,isLoadingSharedThreads:R,actions:O,shareInFlight:L,shareStatus:q,clearShareStatus:W}=xr(),{createThread:j,deleteThread:X,renameThread:G,shareThread:B}=O,{loadThread:M}=eo(),I=i??T,[K,J]=b.useState(Array.isArray(k)?k:[]),P=b.useRef(K.length>0),_=b.useRef(null),z=b.useRef(0),[F,re]=b.useState(null),[V,D]=b.useState(""),[Z,ee]=b.useState(!1),[Q,H]=b.useState(!1),[ae,ie]=b.useState(null),[ge,ye]=b.useState(""),Te=v&&v.length>0?v:Rk,Ae=dm({defaultView:m}),ke=g??Ae,st=h??ke.view,vt=b.useCallback(Y=>{h||ke.setView(Y),f==null||f(Y)},[h,f,ke]),kt=Te.find(Y=>Y.key===st)??Te[0],Ve=Y=>{ie(Y),ye(""),H(!0)},ze=()=>{H(!1),ie(null),ye(""),W()},Ke=b.useCallback(async Y=>{if(!(!ae||L)&&Y.id)try{await B(ae,Y.id),setTimeout(()=>ze(),600)}catch(fe){console.error("Failed to share thread:",fe)}},[ze,L,ae,B]),Oe=b.useMemo(()=>{const Y=y??[],fe=ge.trim().toLowerCase();return fe?S?Y.filter(Be=>S(Be,fe)):Y.filter(Be=>`${Be.label} ${Be.secondaryLabel??""}`.toLowerCase().includes(fe)):Y},[y,ge,S]),Ue=st==="shared",dt=Ue?C:K,Nt=Ue?R:N,nt=Ue?"No shared conversations yet":"No conversations yet",At=Y=>{const fe=Y.sharedAt?` • ${Pe(Y.sharedAt)}`:"";return`Shared by ${Y.sharedByUserId}${fe}`},wt=Y=>"sharedByUserId"in Y;b.useEffect(()=>{const Y=Array.isArray(k)?k:[];if(Y.length>0){P.current=!0,J(Y);return}N||(P.current=!1,J(Y))},[k,N]),b.useEffect(()=>{if(!_.current)return;const Y=_.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let fe=null,Be=null;return fe=requestAnimationFrame(()=>{Be=requestAnimationFrame(()=>{Y.scrollTop=z.current})}),()=>{fe!==null&&cancelAnimationFrame(fe),Be!==null&&cancelAnimationFrame(Be)}},[K]);const mt=async Y=>{try{E(Y),await M(Y),a==null||a(Y),l==null||l(Y)}catch(fe){console.error("Failed to select thread:",fe)}},Et=async()=>{try{ee(!0);const Y=await j();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{ee(!1)}},yt=async(Y,fe)=>{if(fe.stopPropagation(),!!confirm("Delete this thread?")){if(_.current){const Be=_.current.querySelector("[data-radix-scroll-area-viewport]");Be&&(z.current=Be.scrollTop)}try{await X(Y),d==null||d(Y)}catch(Be){console.error("Failed to delete thread:",Be)}}},jt=(Y,fe)=>{fe.stopPropagation(),re(Y.threadId),D(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},qt=async Y=>{if(V.trim())try{await G(Y,V.trim()),re(null),D("")}catch(fe){console.error("Failed to update title:",fe)}},gt=()=>{re(null),D("")},Pe=Y=>{if(!Y)return"";try{const fe=new Date(Y),xe=new Date().getTime()-fe.getTime(),Fe=Math.floor(xe/(1e3*60*60*24));return Fe===0?fe.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Fe===1?"Yesterday":Fe<7?`${Fe} days ago`:fe.toLocaleDateString()}catch{return""}},We=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,_t=Y=>{const fe=We(Y);return fe.length<=cm?fe:`${fe.slice(0,cm)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[x&&u.jsxs("div",{className:s.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&u.jsx("div",{className:"flex justify-end",children:u.jsxs(Ze,{onClick:Et,disabled:Z||N,className:s.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:Z?"Creating...":"New Chat",children:[u.jsx(ue.Edit3,{size:16}),u.jsx("span",{children:"New chat"})]})}),u.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[u.jsx("span",{children:"Current View"}),u.jsxs(Cs,{children:[u.jsx(Ts,{asChild:!0,children:u.jsx(Ze,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:kt.label})}),u.jsx(ho,{align:"start",sideOffset:6,className:"w-40",children:Te.map(Y=>u.jsxs(Bn,{className:"justify-between text-[12px]",onClick:fe=>{fe.preventDefault(),vt(Y.key)},children:[u.jsx("span",{children:Y.label}),st===Y.key&&u.jsx(ue.Check,{className:"h-3 w-3"})]},Y.key))})]})]})]}),u.jsx(Pl,{ref:_,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:Nt?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ue.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):dt.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(ue.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:nt})]}):dt.slice().sort((Y,fe)=>new Date(fe.updatedAt||fe.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsx(lm,{thread:Y,isActive:I===Y.threadId,editingThreadId:F,editingTitle:V,onSelect:mt,onStartEditing:jt,onEditingTitleChange:fe=>D(fe),onSaveEditing:qt,onCancelEditing:gt,onShare:()=>Ve(Y.threadId),onDelete:yt,showEditTitle:r,showDeleteButton:n,formatDate:Pe,getDisplayThreadTitle:_t,secondaryLine:Ue&&wt(Y)?At(Y):void 0,itemClassName:s.threadItem,activeItemClassName:s.activeThread},Y.threadId))})}),u.jsx(el,{open:Q,onOpenChange:Y=>!Y&&ze(),children:u.jsxs(zs,{className:"max-w-md p-0",children:[u.jsx(Hs,{children:u.jsx(Us,{children:"Share thread"})}),u.jsxs(yl,{children:[u.jsx(Sl,{autoFocus:!0,value:ge,onValueChange:Y=>ye(Y),placeholder:"Search for recipients..."}),u.jsxs(Cl,{children:[q&&u.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[L&&u.jsx(ue.Loader2,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{className:q.startsWith("Failed")?"text-red-500":q.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:q})]}),u.jsx(Tl,{children:w?u.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ue.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading recipients…"]}):"No matching recipients found"}),Oe.length>0&&u.jsx(kl,{heading:"Recipients",children:Oe.map(Y=>u.jsx(El,{onSelect:()=>Ke(Y),children:u.jsxs("div",{className:"flex flex-col items-start text-sm",children:[u.jsx("span",{className:"font-medium",children:Y.label}),Y.secondaryLabel&&u.jsx("span",{className:"text-xs text-muted-foreground",children:Y.secondaryLabel})]})},Y.id))})]})]})]})})]})}function Mk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=b.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(br,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Mr,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(br,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(ni,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Mr,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(br,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(ni,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Mr,{onError:s.onError,enableFileUpload:!0})})]})})}function Ok({apiConfig:e,className:t="",onError:n}){return u.jsx(br,{apiConfig:e,onError:n,children:u.jsx("div",{className:`h-full ${t}`,children:u.jsx(Mr,{})})})}function Dk({placeholder:e,onMessageSent:t}){const[n,r]=b.useState("chat");return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:"flex border-b border-gray-200 bg-gray-50",children:[u.jsx("button",{onClick:()=>r("chat"),className:`flex-1 px-3 py-2 text-sm font-medium transition-colors ${n==="chat"?"border-b-2 border-slate-800 text-slate-800 bg-white":"text-gray-600 hover:text-gray-800"}`,children:u.jsxs("div",{className:"flex items-center justify-center gap-2",children:[u.jsx(ue.MessageSquare,{size:14}),"Chat"]})}),u.jsx("button",{onClick:()=>r("threads"),className:`flex-1 px-3 py-2 text-sm font-medium transition-colors ${n==="threads"?"border-b-2 border-slate-800 text-slate-800 bg-white":"text-gray-600 hover:text-gray-800"}`,children:u.jsxs("div",{className:"flex items-center justify-center gap-2",children:[u.jsx(ue.History,{size:14}),"History"]})})]}),u.jsx("div",{className:"flex-1 min-h-0",children:n==="chat"?u.jsx(Mr,{placeholder:e??"Ask Serti AI anything...",autoFocus:!0,className:"h-full",onMessageSent:t}):u.jsx(ni,{showCreateButton:!0,className:"h-full",onThreadSelect:()=>r("chat")})})]})}function Lk({className:e="",placeholder:t,isAuthenticated:n=!0,onMessageSent:r,widgetTitle:o="Serti AI Navigator",widgetSubtitle:s="AI-Powered Assistant",...i}){const[a,l]=b.useState(!1);return n?u.jsx(br,{...i,children:u.jsx("div",{className:`fixed bottom-6 right-6 z-[9999] transition-all duration-300 ${e}`,children:u.jsxs("div",{className:`w-96 bg-white rounded-xl shadow-2xl border border-gray-200 overflow-hidden relative ${a?"scale-75":"scale-100"}`,children:[u.jsx("div",{className:"bg-slate-800 text-white p-4 flex-shrink-0",children:u.jsxs("div",{className:"flex items-center justify-between gap-3",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("div",{className:"relative h-10 w-10 rounded-full bg-gradient-to-br from-slate-500 to-slate-700 border border-white/30 flex items-center justify-center text-white text-sm font-bold",children:["S",u.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-slate-800 bg-emerald-400"})]}),u.jsxs("div",{className:"flex flex-col",children:[u.jsx("h3",{className:"text-lg font-semibold leading-tight",children:o}),u.jsx("p",{className:"text-xs text-white/70",children:s})]}),u.jsx("span",{className:"ml-2 inline-flex items-center justify-center rounded-full bg-red-500 px-2 py-0.5 text-[11px] font-semibold leading-none text-white",children:"1"})]}),u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Ze,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Options",children:u.jsx(ue.MoreHorizontal,{size:16})}),u.jsx(Ze,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Compose",children:u.jsx(ue.Edit3,{size:16})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:c=>{c.stopPropagation(),l(d=>!d)},className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:a?"Maximize":"Minimize",children:a?u.jsx(ue.Maximize2,{size:14}):u.jsx(ue.Minimize2,{size:14})})]})]})}),!a&&u.jsx("div",{className:"h-96 flex flex-col",children:u.jsx(Dk,{placeholder:t,onMessageSent:r})})]})})}):null}function $k({label:e="New chat",children:t,className:n,variant:r="ghost",size:o="sm",...s}){return u.jsxs(Ze,{variant:r,size:o,className:oe("gap-2 rounded-full px-3 font-semibold transition-all hover:scale-[1.01]",n),...s,children:[u.jsx(ue.Edit3,{size:16}),t??e]})}var Fk="Label",fm=p.forwardRef((e,t)=>u.jsx(ve.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));fm.displayName=Fk;var hm=fm;const Bk=zr.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),pm=p.forwardRef(({className:e,...t},n)=>u.jsx(hm,{ref:n,className:oe(Bk(),e),...t}));pm.displayName=hm.displayName;function mm(e){const t=p.useRef({value:e,previous:e});return p.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var gm=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),zk="VisuallyHidden",ri=p.forwardRef((e,t)=>u.jsx(ve.span,{...e,ref:t,style:{...gm,...e.style}}));ri.displayName=zk;var Hk=ri,Uk=[" ","Enter","ArrowUp","ArrowDown"],Wk=[" ","Enter"],dr="Select",[oi,si,Vk]=Xo(dr),[$r,RN]=cn(dr,[Vk,Er]),ii=Er(),[Kk,Yn]=$r(dr),[qk,Gk]=$r(dr),xm=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:h,disabled:m,required:f,form:v}=e,g=ii(t),[x,y]=p.useState(null),[w,S]=p.useState(null),[k,C]=p.useState(!1),T=Jo(c),[E,N]=Dn({prop:r,defaultProp:o??!1,onChange:s,caller:dr}),[R,O]=Dn({prop:i,defaultProp:a,onChange:l,caller:dr}),L=p.useRef(null),q=x?v||!!x.closest("form"):!0,[W,j]=p.useState(new Set),X=Array.from(W).map(G=>G.props.value).join(";");return u.jsx(sa,{...g,children:u.jsxs(Kk,{required:f,scope:t,trigger:x,onTriggerChange:y,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Rt(),value:R,onValueChange:O,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:L,disabled:m,children:[u.jsx(oi.Provider,{scope:t,children:u.jsx(qk,{scope:e.__scopeSelect,onNativeOptionAdd:p.useCallback(G=>{j(B=>new Set(B).add(G))},[]),onNativeOptionRemove:p.useCallback(G=>{j(B=>{const M=new Set(B);return M.delete(G),M})},[]),children:n})}),q?u.jsxs(zm,{"aria-hidden":!0,required:f,tabIndex:-1,name:d,autoComplete:h,value:R,onChange:G=>O(G.target.value),disabled:m,form:v,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(W)]},X):null]})})};xm.displayName=dr;var vm="SelectTrigger",bm=p.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ii(n),i=Yn(vm,n),a=i.disabled||r,l=Le(t,i.onTriggerChange),c=si(n),d=p.useRef("touch"),[h,m,f]=Um(g=>{const x=c().filter(S=>!S.disabled),y=x.find(S=>S.value===i.value),w=Wm(x,g,y);w!==void 0&&i.onValueChange(w.value)}),v=g=>{a||(i.onOpenChange(!0),f()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ia,{asChild:!0,...s,children:u.jsx(ve.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Hm(i.value)?"":void 0,...o,ref:l,onClick:ce(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&v(g)}),onPointerDown:ce(o.onPointerDown,g=>{d.current=g.pointerType;const x=g.target;x.hasPointerCapture(g.pointerId)&&x.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(v(g),g.preventDefault())}),onKeyDown:ce(o.onKeyDown,g=>{const x=h.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&m(g.key),!(x&&g.key===" ")&&Uk.includes(g.key)&&(v(),g.preventDefault())})})})});bm.displayName=vm;var wm="SelectValue",ym=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Yn(wm,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,h=Le(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(ve.span,{...a,ref:h,style:{pointerEvents:"none"},children:Hm(l.value)?u.jsx(u.Fragment,{children:i}):s})});ym.displayName=wm;var Yk="SelectIcon",Sm=p.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(ve.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Sm.displayName=Yk;var Xk="SelectPortal",Cm=e=>u.jsx(so,{asChild:!0,...e});Cm.displayName=Xk;var fr="SelectContent",Tm=p.forwardRef((e,t)=>{const n=Yn(fr,e.__scopeSelect),[r,o]=p.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Hr.createPortal(u.jsx(km,{scope:e.__scopeSelect,children:u.jsx(oi.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Em,{...e,ref:t})});Tm.displayName=fr;var mn=10,[km,Xn]=$r(fr),Jk="SelectContentImpl",Zk=Yt.createSlot("SelectContent.RemoveScroll"),Em=p.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:h,collisionBoundary:m,collisionPadding:f,sticky:v,hideWhenDetached:g,avoidCollisions:x,...y}=e,w=Yn(fr,n),[S,k]=p.useState(null),[C,T]=p.useState(null),E=Le(t,V=>k(V)),[N,R]=p.useState(null),[O,L]=p.useState(null),q=si(n),[W,j]=p.useState(!1),X=p.useRef(!1);p.useEffect(()=>{if(S)return fa(S)},[S]),Ui();const G=p.useCallback(V=>{const[D,...Z]=q().map(H=>H.ref.current),[ee]=Z.slice(-1),Q=document.activeElement;for(const H of V)if(H===Q||(H==null||H.scrollIntoView({block:"nearest"}),H===D&&C&&(C.scrollTop=0),H===ee&&C&&(C.scrollTop=C.scrollHeight),H==null||H.focus(),document.activeElement!==Q))return},[q,C]),B=p.useCallback(()=>G([N,S]),[G,N,S]);p.useEffect(()=>{W&&B()},[W,B]);const{onOpenChange:M,triggerPointerDownPosRef:I}=w;p.useEffect(()=>{if(S){let V={x:0,y:0};const D=ee=>{var Q,H;V={x:Math.abs(Math.round(ee.pageX)-(((Q=I.current)==null?void 0:Q.x)??0)),y:Math.abs(Math.round(ee.pageY)-(((H=I.current)==null?void 0:H.y)??0))}},Z=ee=>{V.x<=10&&V.y<=10?ee.preventDefault():S.contains(ee.target)||M(!1),document.removeEventListener("pointermove",D),I.current=null};return I.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",Z,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",Z,{capture:!0})}}},[S,M,I]),p.useEffect(()=>{const V=()=>M(!1);return window.addEventListener("blur",V),window.addEventListener("resize",V),()=>{window.removeEventListener("blur",V),window.removeEventListener("resize",V)}},[M]);const[K,J]=Um(V=>{const D=q().filter(Q=>!Q.disabled),Z=D.find(Q=>Q.ref.current===document.activeElement),ee=Wm(D,V,Z);ee&&setTimeout(()=>ee.ref.current.focus())}),P=p.useCallback((V,D,Z)=>{const ee=!X.current&&!Z;(w.value!==void 0&&w.value===D||ee)&&(R(V),ee&&(X.current=!0))},[w.value]),_=p.useCallback(()=>S==null?void 0:S.focus(),[S]),z=p.useCallback((V,D,Z)=>{const ee=!X.current&&!Z;(w.value!==void 0&&w.value===D||ee)&&L(V)},[w.value]),F=r==="popper"?Ml:Im,re=F===Ml?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:h,collisionBoundary:m,collisionPadding:f,sticky:v,hideWhenDetached:g,avoidCollisions:x}:{};return u.jsx(km,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:P,selectedItem:N,onItemLeave:_,itemTextRefCallback:z,focusSelectedItem:B,selectedItemText:O,position:r,isPositioned:W,searchRef:K,children:u.jsx(xs,{as:Zk,allowPinchZoom:!0,children:u.jsx(Zo,{asChild:!0,trapped:w.open,onMountAutoFocus:V=>{V.preventDefault()},onUnmountAutoFocus:ce(o,V=>{var D;(D=w.trigger)==null||D.focus({preventScroll:!0}),V.preventDefault()}),children:u.jsx(yr,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:V=>V.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(F,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:V=>V.preventDefault(),...y,...re,onPlaced:()=>j(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:ce(y.onKeyDown,V=>{const D=V.ctrlKey||V.altKey||V.metaKey;if(V.key==="Tab"&&V.preventDefault(),!D&&V.key.length===1&&J(V.key),["ArrowUp","ArrowDown","Home","End"].includes(V.key)){let ee=q().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);if(["ArrowUp","End"].includes(V.key)&&(ee=ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(V.key)){const Q=V.target,H=ee.indexOf(Q);ee=ee.slice(H+1)}setTimeout(()=>G(ee)),V.preventDefault()}})})})})})})});Em.displayName=Jk;var Qk="SelectItemAlignedPosition",Im=p.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Yn(fr,n),i=Xn(fr,n),[a,l]=p.useState(null),[c,d]=p.useState(null),h=Le(t,E=>d(E)),m=si(n),f=p.useRef(!1),v=p.useRef(!0),{viewport:g,selectedItem:x,selectedItemText:y,focusSelectedItem:w}=i,S=p.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&x&&y){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),O=y.getBoundingClientRect();if(s.dir!=="rtl"){const Q=O.left-N.left,H=R.left-Q,ae=E.left-H,ie=E.width+ae,ge=Math.max(ie,N.width),ye=window.innerWidth-mn,Te=Il(H,[mn,Math.max(mn,ye-ge)]);a.style.minWidth=ie+"px",a.style.left=Te+"px"}else{const Q=N.right-O.right,H=window.innerWidth-R.right-Q,ae=window.innerWidth-E.right-H,ie=E.width+ae,ge=Math.max(ie,N.width),ye=window.innerWidth-mn,Te=Il(H,[mn,Math.max(mn,ye-ge)]);a.style.minWidth=ie+"px",a.style.right=Te+"px"}const L=m(),q=window.innerHeight-mn*2,W=g.scrollHeight,j=window.getComputedStyle(c),X=parseInt(j.borderTopWidth,10),G=parseInt(j.paddingTop,10),B=parseInt(j.borderBottomWidth,10),M=parseInt(j.paddingBottom,10),I=X+G+W+M+B,K=Math.min(x.offsetHeight*5,I),J=window.getComputedStyle(g),P=parseInt(J.paddingTop,10),_=parseInt(J.paddingBottom,10),z=E.top+E.height/2-mn,F=q-z,re=x.offsetHeight/2,V=x.offsetTop+re,D=X+G+V,Z=I-D;if(D<=z){const Q=L.length>0&&x===L[L.length-1].ref.current;a.style.bottom="0px";const H=c.clientHeight-g.offsetTop-g.offsetHeight,ae=Math.max(F,re+(Q?_:0)+H+B),ie=D+ae;a.style.height=ie+"px"}else{const Q=L.length>0&&x===L[0].ref.current;a.style.top="0px";const ae=Math.max(z,X+g.offsetTop+(Q?P:0)+re)+Z;a.style.height=ae+"px",g.scrollTop=D-z+g.offsetTop}a.style.margin=`${mn}px 0`,a.style.minHeight=K+"px",a.style.maxHeight=q+"px",r==null||r(),requestAnimationFrame(()=>f.current=!0)}},[m,s.trigger,s.valueNode,a,c,g,x,y,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=p.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=p.useCallback(E=>{E&&v.current===!0&&(S(),w==null||w(),v.current=!1)},[S,w]);return u.jsx(tE,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:f,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(ve.div,{...o,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Im.displayName=Qk;var eE="SelectPopperPosition",Ml=p.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=mn,...s}=e,i=ii(n);return u.jsx(aa,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Ml.displayName=eE;var[tE,Ol]=$r(fr,{}),Dl="SelectViewport",Nm=p.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Xn(Dl,n),i=Ol(Dl,n),a=Le(t,s.onViewportChange),l=p.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(oi.Slot,{scope:n,children:u.jsx(ve.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ce(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:h,shouldExpandOnScrollRef:m}=i;if(m!=null&&m.current&&h){const f=Math.abs(l.current-d.scrollTop);if(f>0){const v=window.innerHeight-mn*2,g=parseFloat(h.style.minHeight),x=parseFloat(h.style.height),y=Math.max(g,x);if(y<v){const w=y+f,S=Math.min(v,w),k=w-S;h.style.height=S+"px",h.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,h.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Nm.displayName=Dl;var Am="SelectGroup",[nE,rE]=$r(Am),oE=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Rt();return u.jsx(nE,{scope:n,id:o,children:u.jsx(ve.div,{role:"group","aria-labelledby":o,...r,ref:t})})});oE.displayName=Am;var jm="SelectLabel",_m=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=rE(jm,n);return u.jsx(ve.div,{id:o.id,...r,ref:t})});_m.displayName=jm;var ai="SelectItem",[sE,Pm]=$r(ai),Rm=p.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Yn(ai,n),l=Xn(ai,n),c=a.value===r,[d,h]=p.useState(s??""),[m,f]=p.useState(!1),v=Le(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),g=Rt(),x=p.useRef("touch"),y=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(sE,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:p.useCallback(w=>{h(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(oi.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(ve.div,{role:"option","aria-labelledby":g,"data-highlighted":m?"":void 0,"aria-selected":c&&m,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:ce(i.onFocus,()=>f(!0)),onBlur:ce(i.onBlur,()=>f(!1)),onClick:ce(i.onClick,()=>{x.current!=="mouse"&&y()}),onPointerUp:ce(i.onPointerUp,()=>{x.current==="mouse"&&y()}),onPointerDown:ce(i.onPointerDown,w=>{x.current=w.pointerType}),onPointerMove:ce(i.onPointerMove,w=>{var S;x.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):x.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ce(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ce(i.onKeyDown,w=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&w.key===" "||(Wk.includes(w.key)&&y(),w.key===" "&&w.preventDefault())})})})})});Rm.displayName=ai;var jo="SelectItemText",Mm=p.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Yn(jo,n),a=Xn(jo,n),l=Pm(jo,n),c=Gk(jo,n),[d,h]=p.useState(null),m=Le(t,y=>h(y),l.onItemTextChange,y=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,y,l.value,l.disabled)}),f=d==null?void 0:d.textContent,v=p.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:f},l.value),[l.disabled,l.value,f]),{onNativeOptionAdd:g,onNativeOptionRemove:x}=c;return Tt(()=>(g(v),()=>x(v)),[g,x,v]),u.jsxs(u.Fragment,{children:[u.jsx(ve.span,{id:l.textId,...s,ref:m}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Hr.createPortal(s.children,i.valueNode):null]})});Mm.displayName=jo;var Om="SelectItemIndicator",Dm=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Pm(Om,n).isSelected?u.jsx(ve.span,{"aria-hidden":!0,...r,ref:t}):null});Dm.displayName=Om;var Ll="SelectScrollUpButton",Lm=p.forwardRef((e,t)=>{const n=Xn(Ll,e.__scopeSelect),r=Ol(Ll,e.__scopeSelect),[o,s]=p.useState(!1),i=Le(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(Fm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Lm.displayName=Ll;var $l="SelectScrollDownButton",$m=p.forwardRef((e,t)=>{const n=Xn($l,e.__scopeSelect),r=Ol($l,e.__scopeSelect),[o,s]=p.useState(!1),i=Le(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(Fm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});$m.displayName=$l;var Fm=p.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Xn("SelectScrollButton",n),i=p.useRef(null),a=si(n),l=p.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return p.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(h=>h.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(ve.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ce(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ce(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ce(o.onPointerLeave,()=>{l()})})}),iE="SelectSeparator",Bm=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(ve.div,{"aria-hidden":!0,...r,ref:t})});Bm.displayName=iE;var Fl="SelectArrow",aE=p.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ii(n),s=Yn(Fl,n),i=Xn(Fl,n);return s.open&&i.position==="popper"?u.jsx(la,{...o,...r,ref:t}):null});aE.displayName=Fl;var lE="SelectBubbleInput",zm=p.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=p.useRef(null),s=Le(r,o),i=mm(t);return p.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const h=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(h)}},[i,t]),u.jsx(ve.select,{...n,style:{...gm,...n.style},ref:s,defaultValue:t})});zm.displayName=lE;function Hm(e){return e===""||e===void 0}function Um(e){const t=ht(e),n=p.useRef(""),r=p.useRef(0),o=p.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=p.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return p.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Wm(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=cE(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function cE(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var uE=xm,Vm=bm,dE=ym,fE=Sm,hE=Cm,Km=Tm,pE=Nm,qm=_m,Gm=Rm,mE=Mm,gE=Dm,Ym=Lm,Xm=$m,Jm=Bm;const xE=uE,vE=dE,Zm=p.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Vm,{ref:r,className:oe("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(fE,{asChild:!0,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Zm.displayName=Vm.displayName;const Qm=p.forwardRef(({className:e,...t},n)=>u.jsx(Ym,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronUp,{className:"h-4 w-4"})}));Qm.displayName=Ym.displayName;const eg=p.forwardRef(({className:e,...t},n)=>u.jsx(Xm,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ue.ChevronDown,{className:"h-4 w-4"})}));eg.displayName=Xm.displayName;const tg=p.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(hE,{children:u.jsxs(Km,{ref:o,className:oe("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Qm,{}),u.jsx(pE,{className:oe("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(eg,{})]})}));tg.displayName=Km.displayName;const bE=p.forwardRef(({className:e,...t},n)=>u.jsx(qm,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));bE.displayName=qm.displayName;const ng=p.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Gm,{ref:r,className:oe("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(gE,{children:u.jsx(ue.Check,{className:"h-4 w-4"})})}),u.jsx(mE,{children:t})]}));ng.displayName=Gm.displayName;const wE=p.forwardRef(({className:e,...t},n)=>u.jsx(Jm,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));wE.displayName=Jm.displayName;var yE="Separator",rg="horizontal",SE=["horizontal","vertical"],og=p.forwardRef((e,t)=>{const{decorative:n,orientation:r=rg,...o}=e,s=CE(r)?r:rg,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(ve.div,{"data-orientation":s,...a,...o,ref:t})});og.displayName=yE;function CE(e){return SE.includes(e)}var sg=og;const ig=p.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(sg,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));ig.displayName=sg.displayName;var li="Switch",[TE,MN]=cn(li),[kE,EE]=TE(li),ag=p.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...h}=e,[m,f]=p.useState(null),v=Le(t,S=>f(S)),g=p.useRef(!1),x=m?d||!!m.closest("form"):!0,[y,w]=Dn({prop:o,defaultProp:s??!1,onChange:c,caller:li});return u.jsxs(kE,{scope:n,checked:y,disabled:a,children:[u.jsx(ve.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":dg(y),"data-disabled":a?"":void 0,disabled:a,value:l,...h,ref:v,onClick:ce(e.onClick,S=>{w(k=>!k),x&&(g.current=S.isPropagationStopped(),g.current||S.stopPropagation())})}),x&&u.jsx(ug,{control:m,bubbles:!g.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});ag.displayName=li;var lg="SwitchThumb",cg=p.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=EE(lg,n);return u.jsx(ve.span,{"data-state":dg(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});cg.displayName=lg;var IE="SwitchBubbleInput",ug=p.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=p.useRef(null),a=Le(i,s),l=mm(n),c=bd(t);return p.useEffect(()=>{const d=i.current;if(!d)return;const h=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(h,"checked").set;if(l!==n&&f){const v=new Event("click",{bubbles:r});f.call(d,n),d.dispatchEvent(v)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});ug.displayName=IE;function dg(e){return e?"checked":"unchecked"}var fg=ag,NE=cg;const hg=p.forwardRef(({className:e,...t},n)=>u.jsx(fg,{className:oe("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(NE,{className:oe("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));hg.displayName=fg.displayName;const AE=Za,jE=cT,_E=Qa,pg=p.forwardRef(({className:e,...t},n)=>u.jsx(To,{className:oe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));pg.displayName=To.displayName;const PE=zr.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),mg=p.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(_E,{children:[u.jsx(pg,{}),u.jsxs(ko,{ref:o,className:oe(PE({side:e}),t),...r,children:[n,u.jsxs(op,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(ue.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));mg.displayName=ko.displayName;const gg=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});gg.displayName="SheetHeader";const xg=p.forwardRef(({className:e,...t},n)=>u.jsx(lr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));xg.displayName=lr.displayName;const vg=p.forwardRef(({className:e,...t},n)=>u.jsx(Bs,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));vg.displayName=Bs.displayName;var[ci,ON]=cn("Tooltip",[Er]),ui=Er(),bg="TooltipProvider",RE=700,Bl="tooltip.open",[ME,zl]=ci(bg),wg=e=>{const{__scopeTooltip:t,delayDuration:n=RE,skipDelayDuration:r=300,disableHoverableContent:o=!1,children:s}=e,i=p.useRef(!0),a=p.useRef(!1),l=p.useRef(0);return p.useEffect(()=>{const c=l.current;return()=>window.clearTimeout(c)},[]),u.jsx(ME,{scope:t,isOpenDelayedRef:i,delayDuration:n,onOpen:p.useCallback(()=>{window.clearTimeout(l.current),i.current=!1},[]),onClose:p.useCallback(()=>{window.clearTimeout(l.current),l.current=window.setTimeout(()=>i.current=!0,r)},[r]),isPointerInTransitRef:a,onPointerInTransitChange:p.useCallback(c=>{a.current=c},[]),disableHoverableContent:o,children:s})};wg.displayName=bg;var _o="Tooltip",[OE,di]=ci(_o),yg=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:o,onOpenChange:s,disableHoverableContent:i,delayDuration:a}=e,l=zl(_o,e.__scopeTooltip),c=ui(t),[d,h]=p.useState(null),m=Rt(),f=p.useRef(0),v=i??l.disableHoverableContent,g=a??l.delayDuration,x=p.useRef(!1),[y,w]=Dn({prop:r,defaultProp:o??!1,onChange:E=>{E?(l.onOpen(),document.dispatchEvent(new CustomEvent(Bl))):l.onClose(),s==null||s(E)},caller:_o}),S=p.useMemo(()=>y?x.current?"delayed-open":"instant-open":"closed",[y]),k=p.useCallback(()=>{window.clearTimeout(f.current),f.current=0,x.current=!1,w(!0)},[w]),C=p.useCallback(()=>{window.clearTimeout(f.current),f.current=0,w(!1)},[w]),T=p.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>{x.current=!0,w(!0),f.current=0},g)},[g,w]);return p.useEffect(()=>()=>{f.current&&(window.clearTimeout(f.current),f.current=0)},[]),u.jsx(sa,{...c,children:u.jsx(OE,{scope:t,contentId:m,open:y,stateAttribute:S,trigger:d,onTriggerChange:h,onTriggerEnter:p.useCallback(()=>{l.isOpenDelayedRef.current?T():k()},[l.isOpenDelayedRef,T,k]),onTriggerLeave:p.useCallback(()=>{v?C():(window.clearTimeout(f.current),f.current=0)},[C,v]),onOpen:k,onClose:C,disableHoverableContent:v,children:n})})};yg.displayName=_o;var Hl="TooltipTrigger",Sg=p.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,o=di(Hl,n),s=zl(Hl,n),i=ui(n),a=p.useRef(null),l=Le(t,a,o.onTriggerChange),c=p.useRef(!1),d=p.useRef(!1),h=p.useCallback(()=>c.current=!1,[]);return p.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),u.jsx(ia,{asChild:!0,...i,children:u.jsx(ve.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...r,ref:l,onPointerMove:ce(e.onPointerMove,m=>{m.pointerType!=="touch"&&!d.current&&!s.isPointerInTransitRef.current&&(o.onTriggerEnter(),d.current=!0)}),onPointerLeave:ce(e.onPointerLeave,()=>{o.onTriggerLeave(),d.current=!1}),onPointerDown:ce(e.onPointerDown,()=>{o.open&&o.onClose(),c.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:ce(e.onFocus,()=>{c.current||o.onOpen()}),onBlur:ce(e.onBlur,o.onClose),onClick:ce(e.onClick,o.onClose)})})});Sg.displayName=Hl;var DE="TooltipPortal",[DN,LE]=ci(DE,{forceMount:void 0}),Fr="TooltipContent",Cg=p.forwardRef((e,t)=>{const n=LE(Fr,e.__scopeTooltip),{forceMount:r=n.forceMount,side:o="top",...s}=e,i=di(Fr,e.__scopeTooltip);return u.jsx(Ut,{present:r||i.open,children:i.disableHoverableContent?u.jsx(Tg,{side:o,...s,ref:t}):u.jsx($E,{side:o,...s,ref:t})})}),$E=p.forwardRef((e,t)=>{const n=di(Fr,e.__scopeTooltip),r=zl(Fr,e.__scopeTooltip),o=p.useRef(null),s=Le(t,o),[i,a]=p.useState(null),{trigger:l,onClose:c}=n,d=o.current,{onPointerInTransitChange:h}=r,m=p.useCallback(()=>{a(null),h(!1)},[h]),f=p.useCallback((v,g)=>{const x=v.currentTarget,y={x:v.clientX,y:v.clientY},w=UE(y,x.getBoundingClientRect()),S=WE(y,w),k=VE(g.getBoundingClientRect()),C=qE([...S,...k]);a(C),h(!0)},[h]);return p.useEffect(()=>()=>m(),[m]),p.useEffect(()=>{if(l&&d){const v=x=>f(x,d),g=x=>f(x,l);return l.addEventListener("pointerleave",v),d.addEventListener("pointerleave",g),()=>{l.removeEventListener("pointerleave",v),d.removeEventListener("pointerleave",g)}}},[l,d,f,m]),p.useEffect(()=>{if(i){const v=g=>{const x=g.target,y={x:g.clientX,y:g.clientY},w=(l==null?void 0:l.contains(x))||(d==null?void 0:d.contains(x)),S=!KE(y,i);w?m():S&&(m(),c())};return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[l,d,i,c,m]),u.jsx(Tg,{...e,ref:s})}),[FE,BE]=ci(_o,{isInside:!1}),zE=Yt.createSlottable("TooltipContent"),Tg=p.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":o,onEscapeKeyDown:s,onPointerDownOutside:i,...a}=e,l=di(Fr,n),c=ui(n),{onClose:d}=l;return p.useEffect(()=>(document.addEventListener(Bl,d),()=>document.removeEventListener(Bl,d)),[d]),p.useEffect(()=>{if(l.trigger){const h=m=>{const f=m.target;f!=null&&f.contains(l.trigger)&&d()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[l.trigger,d]),u.jsx(yr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:h=>h.preventDefault(),onDismiss:d,children:u.jsxs(aa,{"data-state":l.stateAttribute,...c,...a,ref:t,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[u.jsx(zE,{children:r}),u.jsx(FE,{scope:n,isInside:!0,children:u.jsx(Hk,{id:l.contentId,role:"tooltip",children:o||r})})]})})});Cg.displayName=Fr;var kg="TooltipArrow",HE=p.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,o=ui(n);return BE(kg,n).isInside?null:u.jsx(la,{...o,...r,ref:t})});HE.displayName=kg;function UE(e,t){const n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),o=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(n,r,o,s)){case s:return"left";case o:return"right";case n:return"top";case r:return"bottom";default:throw new Error("unreachable")}}function WE(e,t,n=5){const r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function VE(e){const{top:t,right:n,bottom:r,left:o}=e;return[{x:o,y:t},{x:n,y:t},{x:n,y:r},{x:o,y:r}]}function KE(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,h=l.x,m=l.y;d>r!=m>r&&n<(h-c)*(r-d)/(m-d)+c&&(o=!o)}return o}function qE(e){const t=e.slice();return t.sort((n,r)=>n.x<r.x?-1:n.x>r.x?1:n.y<r.y?-1:n.y>r.y?1:0),GE(t)}function GE(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const o=e[r];for(;t.length>=2;){const s=t[t.length-1],i=t[t.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))t.pop();else break}t.push(o)}t.pop();const n=[];for(let r=e.length-1;r>=0;r--){const o=e[r];for(;n.length>=2;){const s=n[n.length-1],i=n[n.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))n.pop();else break}n.push(o)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var YE=wg,XE=yg,JE=Sg,Eg=Cg;const ZE=YE,QE=XE,eI=JE,Ig=p.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Eg,{ref:r,sideOffset:t,className:oe("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n}));Ig.displayName=Eg.displayName;var Ul="ToastProvider",[Wl,tI,nI]=Xo("Toast"),[Ng,LN]=cn("Toast",[nI]),[rI,fi]=Ng(Ul),Ag=e=>{const{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=p.useState(null),[c,d]=p.useState(0),h=p.useRef(!1),m=p.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${Ul}\`. Expected non-empty \`string\`.`),u.jsx(Wl.Provider,{scope:t,children:u.jsx(rI,{scope:t,label:n,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:p.useCallback(()=>d(f=>f+1),[]),onToastRemove:p.useCallback(()=>d(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:m,children:i})})};Ag.displayName=Ul;var jg="ToastViewport",oI=["F8"],Vl="toast.viewportPause",Kl="toast.viewportResume",_g=p.forwardRef((e,t)=>{const{__scopeToast:n,hotkey:r=oI,label:o="Notifications ({hotkey})",...s}=e,i=fi(jg,n),a=tI(n),l=p.useRef(null),c=p.useRef(null),d=p.useRef(null),h=p.useRef(null),m=Le(t,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=i.toastCount>0;p.useEffect(()=>{const x=y=>{var S;r.length!==0&&r.every(k=>y[k]||y.code===k)&&((S=h.current)==null||S.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),p.useEffect(()=>{const x=l.current,y=h.current;if(v&&x&&y){const w=()=>{if(!i.isClosePausedRef.current){const T=new CustomEvent(Vl);y.dispatchEvent(T),i.isClosePausedRef.current=!0}},S=()=>{if(i.isClosePausedRef.current){const T=new CustomEvent(Kl);y.dispatchEvent(T),i.isClosePausedRef.current=!1}},k=T=>{!x.contains(T.relatedTarget)&&S()},C=()=>{x.contains(document.activeElement)||S()};return x.addEventListener("focusin",w),x.addEventListener("focusout",k),x.addEventListener("pointermove",w),x.addEventListener("pointerleave",C),window.addEventListener("blur",w),window.addEventListener("focus",S),()=>{x.removeEventListener("focusin",w),x.removeEventListener("focusout",k),x.removeEventListener("pointermove",w),x.removeEventListener("pointerleave",C),window.removeEventListener("blur",w),window.removeEventListener("focus",S)}}},[v,i.isClosePausedRef]);const g=p.useCallback(({tabbingDirection:x})=>{const w=a().map(S=>{const k=S.ref.current,C=[k,...xI(k)];return x==="forwards"?C:C.reverse()});return(x==="forwards"?w.reverse():w).flat()},[a]);return p.useEffect(()=>{const x=h.current;if(x){const y=w=>{var C,T,E;const S=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!S){const N=document.activeElement,R=w.shiftKey;if(w.target===x&&R){(C=c.current)==null||C.focus();return}const q=g({tabbingDirection:R?"backwards":"forwards"}),W=q.findIndex(j=>j===N);Yl(q.slice(W+1))?w.preventDefault():R?(T=c.current)==null||T.focus():(E=d.current)==null||E.focus()}};return x.addEventListener("keydown",y),()=>x.removeEventListener("keydown",y)}},[a,g]),u.jsxs($b,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:v?void 0:"none"},children:[v&&u.jsx(ql,{ref:c,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"forwards"});Yl(x)}}),u.jsx(Wl.Slot,{scope:n,children:u.jsx(ve.ol,{tabIndex:-1,...s,ref:m})}),v&&u.jsx(ql,{ref:d,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"backwards"});Yl(x)}})]})});_g.displayName=jg;var Pg="ToastFocusProxy",ql=p.forwardRef((e,t)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=e,s=fi(Pg,n);return u.jsx(ri,{tabIndex:0,...o,ref:t,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=s.viewport)!=null&&c.contains(a))&&r()}})});ql.displayName=Pg;var Po="Toast",sI="toast.swipeStart",iI="toast.swipeMove",aI="toast.swipeCancel",lI="toast.swipeEnd",Rg=p.forwardRef((e,t)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a,l]=Dn({prop:r,defaultProp:o??!0,onChange:s,caller:Po});return u.jsx(Ut,{present:n||a,children:u.jsx(dI,{open:a,...i,ref:t,onClose:()=>l(!1),onPause:ht(e.onPause),onResume:ht(e.onResume),onSwipeStart:ce(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ce(e.onSwipeMove,c=>{const{x:d,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:ce(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:ce(e.onSwipeEnd,c=>{const{x:d,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});Rg.displayName=Po;var[cI,uI]=Ng(Po,{onClose(){}}),dI=p.forwardRef((e,t)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:d,onSwipeMove:h,onSwipeCancel:m,onSwipeEnd:f,...v}=e,g=fi(Po,n),[x,y]=p.useState(null),w=Le(t,j=>y(j)),S=p.useRef(null),k=p.useRef(null),C=o||g.duration,T=p.useRef(0),E=p.useRef(C),N=p.useRef(0),{onToastAdd:R,onToastRemove:O}=g,L=ht(()=>{var X;(x==null?void 0:x.contains(document.activeElement))&&((X=g.viewport)==null||X.focus()),i()}),q=p.useCallback(j=>{!j||j===1/0||(window.clearTimeout(N.current),T.current=new Date().getTime(),N.current=window.setTimeout(L,j))},[L]);p.useEffect(()=>{const j=g.viewport;if(j){const X=()=>{q(E.current),c==null||c()},G=()=>{const B=new Date().getTime()-T.current;E.current=E.current-B,window.clearTimeout(N.current),l==null||l()};return j.addEventListener(Vl,G),j.addEventListener(Kl,X),()=>{j.removeEventListener(Vl,G),j.removeEventListener(Kl,X)}}},[g.viewport,C,l,c,q]),p.useEffect(()=>{s&&!g.isClosePausedRef.current&&q(C)},[s,C,g.isClosePausedRef,q]),p.useEffect(()=>(R(),()=>O()),[R,O]);const W=p.useMemo(()=>x?Bg(x):null,[x]);return g.viewport?u.jsxs(u.Fragment,{children:[W&&u.jsx(fI,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite",children:W}),u.jsx(cI,{scope:n,onClose:L,children:Hr.createPortal(u.jsx(Wl.ItemSlot,{scope:n,children:u.jsx(Lb,{asChild:!0,onEscapeKeyDown:ce(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||L(),g.isFocusedToastEscapeKeyDownRef.current=!1}),children:u.jsx(ve.li,{tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection,...v,ref:w,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:ce(e.onKeyDown,j=>{j.key==="Escape"&&(a==null||a(j.nativeEvent),j.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,L()))}),onPointerDown:ce(e.onPointerDown,j=>{j.button===0&&(S.current={x:j.clientX,y:j.clientY})}),onPointerMove:ce(e.onPointerMove,j=>{if(!S.current)return;const X=j.clientX-S.current.x,G=j.clientY-S.current.y,B=!!k.current,M=["left","right"].includes(g.swipeDirection),I=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,K=M?I(0,X):0,J=M?0:I(0,G),P=j.pointerType==="touch"?10:2,_={x:K,y:J},z={originalEvent:j,delta:_};B?(k.current=_,hi(iI,h,z,{discrete:!1})):zg(_,g.swipeDirection,P)?(k.current=_,hi(sI,d,z,{discrete:!1}),j.target.setPointerCapture(j.pointerId)):(Math.abs(X)>P||Math.abs(G)>P)&&(S.current=null)}),onPointerUp:ce(e.onPointerUp,j=>{const X=k.current,G=j.target;if(G.hasPointerCapture(j.pointerId)&&G.releasePointerCapture(j.pointerId),k.current=null,S.current=null,X){const B=j.currentTarget,M={originalEvent:j,delta:X};zg(X,g.swipeDirection,g.swipeThreshold)?hi(lI,f,M,{discrete:!0}):hi(aI,m,M,{discrete:!0}),B.addEventListener("click",I=>I.preventDefault(),{once:!0})}})})})}),g.viewport)})]}):null}),fI=e=>{const{__scopeToast:t,children:n,...r}=e,o=fi(Po,t),[s,i]=p.useState(!1),[a,l]=p.useState(!1);return mI(()=>i(!0)),p.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:u.jsx(so,{asChild:!0,children:u.jsx(ri,{...r,children:s&&u.jsxs(u.Fragment,{children:[o.label," ",n]})})})},hI="ToastTitle",Mg=p.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});Mg.displayName=hI;var pI="ToastDescription",Og=p.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return u.jsx(ve.div,{...r,ref:t})});Og.displayName=pI;var Dg="ToastAction",Lg=p.forwardRef((e,t)=>{const{altText:n,...r}=e;return n.trim()?u.jsx(Fg,{altText:n,asChild:!0,children:u.jsx(Gl,{...r,ref:t})}):(console.error(`Invalid prop \`altText\` supplied to \`${Dg}\`. Expected non-empty \`string\`.`),null)});Lg.displayName=Dg;var $g="ToastClose",Gl=p.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e,o=uI($g,n);return u.jsx(Fg,{asChild:!0,children:u.jsx(ve.button,{type:"button",...r,ref:t,onClick:ce(e.onClick,o.onClose)})})});Gl.displayName=$g;var Fg=p.forwardRef((e,t)=>{const{__scopeToast:n,altText:r,...o}=e;return u.jsx(ve.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:t})});function Bg(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),gI(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&t.push(i)}else t.push(...Bg(r))}}),t}function hi(e,t,n,{discrete:r}){const o=n.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Bi(o,s):o.dispatchEvent(s)}var zg=(e,t,n=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return t==="left"||t==="right"?s&&r>n:!s&&o>n};function mI(e=()=>{}){const t=ht(e);Tt(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[t])}function gI(e){return e.nodeType===e.ELEMENT_NODE}function xI(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Yl(e){const t=document.activeElement;return e.some(n=>n===t?!0:(n.focus(),document.activeElement!==t))}var vI=Ag,Hg=_g,Ug=Rg,Wg=Mg,Vg=Og,Kg=Lg,qg=Gl;const bI=vI,Gg=p.forwardRef(({className:e,...t},n)=>u.jsx(Hg,{ref:n,className:oe("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col p-4 md:max-w-[420px]",e),...t}));Gg.displayName=Hg.displayName;const wI=zr.cva("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground"}},defaultVariants:{variant:"default"}}),Yg=p.forwardRef(({className:e,variant:t,...n},r)=>u.jsx(Ug,{ref:r,className:oe(wI({variant:t}),e),...n}));Yg.displayName=Ug.displayName;const yI=p.forwardRef(({className:e,...t},n)=>u.jsx(Kg,{ref:n,className:oe("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",e),...t}));yI.displayName=Kg.displayName;const Xg=p.forwardRef(({className:e,...t},n)=>u.jsx(qg,{ref:n,className:oe("absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",e),"toast-close":"",...t,children:u.jsx(ue.X,{className:"h-4 w-4"})}));Xg.displayName=qg.displayName;const Jg=p.forwardRef(({className:e,...t},n)=>u.jsx(Wg,{ref:n,className:oe("text-sm font-semibold",e),...t}));Jg.displayName=Wg.displayName;const Zg=p.forwardRef(({className:e,...t},n)=>u.jsx(Vg,{ref:n,className:oe("text-sm opacity-90",e),...t}));Zg.displayName=Vg.displayName;function SI(){const{toasts:e}=rl();return u.jsxs(bI,{children:[e.map(function({id:t,title:n,description:r,action:o,...s}){return u.jsxs(Yg,{...s,children:[u.jsxs("div",{className:"grid gap-1",children:[n&&u.jsx(Jg,{children:n}),r&&u.jsx(Zg,{children:r})]}),o,u.jsx(Xg,{})]},t)}),u.jsx(Gg,{})]})}var CI=(e,t,n,r,o,s,i,a)=>{let l=document.documentElement,c=["light","dark"];function d(f){(Array.isArray(e)?e:[e]).forEach(v=>{let g=v==="class",x=g&&s?o.map(y=>s[y]||y):o;g?(l.classList.remove(...x),l.classList.add(s&&s[f]?s[f]:f)):l.setAttribute(v,f)}),h(f)}function h(f){a&&c.includes(f)&&(l.style.colorScheme=f)}function m(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)d(r);else try{let f=localStorage.getItem(t)||n,v=i&&f==="system"?m():f;d(v)}catch{}},TI=p.createContext(void 0),kI={setTheme:e=>{},themes:[]},EI=()=>{var e;return(e=p.useContext(TI))!=null?e:kI};p.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:o,defaultTheme:s,value:i,themes:a,nonce:l,scriptProps:c})=>{let d=JSON.stringify([n,t,s,e,a,i,r,o]).slice(1,-1);return p.createElement("script",{...c,suppressHydrationWarning:!0,nonce:typeof window>"u"?l:"",dangerouslySetInnerHTML:{__html:`(${CI.toString()})(${d})`}})});var II=e=>{switch(e){case"success":return jI;case"info":return PI;case"warning":return _I;case"error":return RI;default:return null}},NI=Array(12).fill(0),AI=({visible:e,className:t})=>b.createElement("div",{className:["sonner-loading-wrapper",t].filter(Boolean).join(" "),"data-visible":e},b.createElement("div",{className:"sonner-spinner"},NI.map((n,r)=>b.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${r}`})))),jI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),_I=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),PI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),RI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},b.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),MI=b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},b.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),b.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),OI=()=>{let[e,t]=b.useState(document.hidden);return b.useEffect(()=>{let n=()=>{t(document.hidden)};return document.addEventListener("visibilitychange",n),()=>window.removeEventListener("visibilitychange",n)},[]),e},Xl=1,DI=class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)}),this.publish=e=>{this.subscribers.forEach(t=>t(e))},this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]},this.create=e=>{var t;let{message:n,...r}=e,o=typeof(e==null?void 0:e.id)=="number"||((t=e.id)==null?void 0:t.length)>0?e.id:Xl++,s=this.toasts.find(a=>a.id===o),i=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(o)&&this.dismissedToasts.delete(o),s?this.toasts=this.toasts.map(a=>a.id===o?(this.publish({...a,...e,id:o,title:n}),{...a,...e,id:o,dismissible:i,title:n}):a):this.addToast({title:n,...r,dismissible:i,id:o}),o},this.dismiss=e=>(this.dismissedToasts.add(e),e||this.toasts.forEach(t=>{this.subscribers.forEach(n=>n({id:t.id,dismiss:!0}))}),this.subscribers.forEach(t=>t({id:e,dismiss:!0})),e),this.message=(e,t)=>this.create({...t,message:e}),this.error=(e,t)=>this.create({...t,message:e,type:"error"}),this.success=(e,t)=>this.create({...t,type:"success",message:e}),this.info=(e,t)=>this.create({...t,type:"info",message:e}),this.warning=(e,t)=>this.create({...t,type:"warning",message:e}),this.loading=(e,t)=>this.create({...t,type:"loading",message:e}),this.promise=(e,t)=>{if(!t)return;let n;t.loading!==void 0&&(n=this.create({...t,promise:e,type:"loading",message:t.loading,description:typeof t.description!="function"?t.description:void 0}));let r=e instanceof Promise?e:e(),o=n!==void 0,s,i=r.then(async l=>{if(s=["resolve",l],b.isValidElement(l))o=!1,this.create({id:n,type:"default",message:l});else if($I(l)&&!l.ok){o=!1;let c=typeof t.error=="function"?await t.error(`HTTP error! status: ${l.status}`):t.error,d=typeof t.description=="function"?await t.description(`HTTP error! status: ${l.status}`):t.description;this.create({id:n,type:"error",message:c,description:d})}else if(t.success!==void 0){o=!1;let c=typeof t.success=="function"?await t.success(l):t.success,d=typeof t.description=="function"?await t.description(l):t.description;this.create({id:n,type:"success",message:c,description:d})}}).catch(async l=>{if(s=["reject",l],t.error!==void 0){o=!1;let c=typeof t.error=="function"?await t.error(l):t.error,d=typeof t.description=="function"?await t.description(l):t.description;this.create({id:n,type:"error",message:c,description:d})}}).finally(()=>{var l;o&&(this.dismiss(n),n=void 0),(l=t.finally)==null||l.call(t)}),a=()=>new Promise((l,c)=>i.then(()=>s[0]==="reject"?c(s[1]):l(s[1])).catch(c));return typeof n!="string"&&typeof n!="number"?{unwrap:a}:Object.assign(n,{unwrap:a})},this.custom=(e,t)=>{let n=(t==null?void 0:t.id)||Xl++;return this.create({jsx:e(n),id:n,...t}),n},this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},Kt=new DI,LI=(e,t)=>{let n=(t==null?void 0:t.id)||Xl++;return Kt.addToast({title:e,...t,id:n}),n},$I=e=>e&&typeof e=="object"&&"ok"in e&&typeof e.ok=="boolean"&&"status"in e&&typeof e.status=="number",FI=LI,BI=()=>Kt.toasts,zI=()=>Kt.getActiveToasts();Object.assign(FI,{success:Kt.success,info:Kt.info,warning:Kt.warning,error:Kt.error,custom:Kt.custom,message:Kt.message,promise:Kt.promise,dismiss:Kt.dismiss,loading:Kt.loading},{getHistory:BI,getToasts:zI});function HI(e,{insertAt:t}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",t==="top"&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}HI(`:where(html[dir="ltr"]),:where([data-sonner-toaster][dir="ltr"]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir="rtl"]),:where([data-sonner-toaster][dir="rtl"]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}:where([data-sonner-toaster][data-lifted="true"]){transform:translateY(-10px)}@media (hover: none) and (pointer: coarse){:where([data-sonner-toaster][data-lifted="true"]){transform:none}}:where([data-sonner-toaster][data-x-position="right"]){right:var(--offset-right)}:where([data-sonner-toaster][data-x-position="left"]){left:var(--offset-left)}:where([data-sonner-toaster][data-x-position="center"]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position="top"]){top:var(--offset-top)}:where([data-sonner-toaster][data-y-position="bottom"]){bottom:var(--offset-bottom)}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled="true"]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position="top"]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position="bottom"]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise="true"]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:rgba(0,0,0,.08)}:where([data-sonner-toast][data-theme="dark"]) :where([data-cancel]){background:rgba(255,255,255,.3)}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]{background:var(--gray1)}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled="true"]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping="true"]):before{content:"";position:absolute;left:-50%;right:-50%;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position="top"][data-swiping="true"]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position="bottom"][data-swiping="true"]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping="false"][data-removed="true"]):before{content:"";position:absolute;inset:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted="true"]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded="false"][data-front="false"]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded="false"][data-front="false"][data-styled="true"])>*{opacity:0}:where([data-sonner-toast][data-visible="false"]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted="true"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed="true"][data-front="true"][data-swipe-out="false"]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed="true"][data-front="false"]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}
|
|
130
|
-
`);function pi(e){return e.label!==void 0}var UI=3,WI="32px",VI="16px",Qg=4e3,KI=356,qI=14,GI=20,YI=200;function gn(...e){return e.filter(Boolean).join(" ")}function XI(e){let[t,n]=e.split("-"),r=[];return t&&r.push(t),n&&r.push(n),r}var JI=e=>{var t,n,r,o,s,i,a,l,c,d,h;let{invert:m,toast:f,unstyled:v,interacting:g,setHeights:x,visibleToasts:y,heights:w,index:S,toasts:k,expanded:C,removeToast:T,defaultRichColors:E,closeButton:N,style:R,cancelButtonStyle:O,actionButtonStyle:L,className:q="",descriptionClassName:W="",duration:j,position:X,gap:G,loadingIcon:B,expandByDefault:M,classNames:I,icons:K,closeButtonAriaLabel:J="Close toast",pauseWhenPageIsHidden:P}=e,[_,z]=b.useState(null),[F,re]=b.useState(null),[V,D]=b.useState(!1),[Z,ee]=b.useState(!1),[Q,H]=b.useState(!1),[ae,ie]=b.useState(!1),[ge,ye]=b.useState(!1),[Te,Ae]=b.useState(0),[ke,st]=b.useState(0),vt=b.useRef(f.duration||j||Qg),kt=b.useRef(null),Ve=b.useRef(null),ze=S===0,Ke=S+1<=y,Oe=f.type,Ue=f.dismissible!==!1,dt=f.className||"",Nt=f.descriptionClassName||"",nt=b.useMemo(()=>w.findIndex(xe=>xe.toastId===f.id)||0,[w,f.id]),At=b.useMemo(()=>{var xe;return(xe=f.closeButton)!=null?xe:N},[f.closeButton,N]),wt=b.useMemo(()=>f.duration||j||Qg,[f.duration,j]),mt=b.useRef(0),Et=b.useRef(0),yt=b.useRef(0),jt=b.useRef(null),[qt,gt]=X.split("-"),Pe=b.useMemo(()=>w.reduce((xe,Fe,Ge)=>Ge>=nt?xe:xe+Fe.height,0),[w,nt]),We=OI(),_t=f.invert||m,Y=Oe==="loading";Et.current=b.useMemo(()=>nt*G+Pe,[nt,Pe]),b.useEffect(()=>{vt.current=wt},[wt]),b.useEffect(()=>{D(!0)},[]),b.useEffect(()=>{let xe=Ve.current;if(xe){let Fe=xe.getBoundingClientRect().height;return st(Fe),x(Ge=>[{toastId:f.id,height:Fe,position:f.position},...Ge]),()=>x(Ge=>Ge.filter(St=>St.toastId!==f.id))}},[x,f.id]),b.useLayoutEffect(()=>{if(!V)return;let xe=Ve.current,Fe=xe.style.height;xe.style.height="auto";let Ge=xe.getBoundingClientRect().height;xe.style.height=Fe,st(Ge),x(St=>St.find(Ct=>Ct.toastId===f.id)?St.map(Ct=>Ct.toastId===f.id?{...Ct,height:Ge}:Ct):[{toastId:f.id,height:Ge,position:f.position},...St])},[V,f.title,f.description,x,f.id]);let fe=b.useCallback(()=>{ee(!0),Ae(Et.current),x(xe=>xe.filter(Fe=>Fe.toastId!==f.id)),setTimeout(()=>{T(f)},YI)},[f,T,x,Et]);b.useEffect(()=>{if(f.promise&&Oe==="loading"||f.duration===1/0||f.type==="loading")return;let xe;return C||g||P&&We?(()=>{if(yt.current<mt.current){let Fe=new Date().getTime()-mt.current;vt.current=vt.current-Fe}yt.current=new Date().getTime()})():vt.current!==1/0&&(mt.current=new Date().getTime(),xe=setTimeout(()=>{var Fe;(Fe=f.onAutoClose)==null||Fe.call(f,f),fe()},vt.current)),()=>clearTimeout(xe)},[C,g,f,Oe,P,We,fe]),b.useEffect(()=>{f.delete&&fe()},[fe,f.delete]);function Be(){var xe,Fe,Ge;return K!=null&&K.loading?b.createElement("div",{className:gn(I==null?void 0:I.loader,(xe=f==null?void 0:f.classNames)==null?void 0:xe.loader,"sonner-loader"),"data-visible":Oe==="loading"},K.loading):B?b.createElement("div",{className:gn(I==null?void 0:I.loader,(Fe=f==null?void 0:f.classNames)==null?void 0:Fe.loader,"sonner-loader"),"data-visible":Oe==="loading"},B):b.createElement(AI,{className:gn(I==null?void 0:I.loader,(Ge=f==null?void 0:f.classNames)==null?void 0:Ge.loader),visible:Oe==="loading"})}return b.createElement("li",{tabIndex:0,ref:Ve,className:gn(q,dt,I==null?void 0:I.toast,(t=f==null?void 0:f.classNames)==null?void 0:t.toast,I==null?void 0:I.default,I==null?void 0:I[Oe],(n=f==null?void 0:f.classNames)==null?void 0:n[Oe]),"data-sonner-toast":"","data-rich-colors":(r=f.richColors)!=null?r:E,"data-styled":!(f.jsx||f.unstyled||v),"data-mounted":V,"data-promise":!!f.promise,"data-swiped":ge,"data-removed":Z,"data-visible":Ke,"data-y-position":qt,"data-x-position":gt,"data-index":S,"data-front":ze,"data-swiping":Q,"data-dismissible":Ue,"data-type":Oe,"data-invert":_t,"data-swipe-out":ae,"data-swipe-direction":F,"data-expanded":!!(C||M&&V),style:{"--index":S,"--toasts-before":S,"--z-index":k.length-S,"--offset":`${Z?Te:Et.current}px`,"--initial-height":M?"auto":`${ke}px`,...R,...f.style},onDragEnd:()=>{H(!1),z(null),jt.current=null},onPointerDown:xe=>{Y||!Ue||(kt.current=new Date,Ae(Et.current),xe.target.setPointerCapture(xe.pointerId),xe.target.tagName!=="BUTTON"&&(H(!0),jt.current={x:xe.clientX,y:xe.clientY}))},onPointerUp:()=>{var xe,Fe,Ge,St;if(ae||!Ue)return;jt.current=null;let Ct=Number(((xe=Ve.current)==null?void 0:xe.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),It=Number(((Fe=Ve.current)==null?void 0:Fe.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),Lt=new Date().getTime()-((Ge=kt.current)==null?void 0:Ge.getTime()),je=_==="x"?Ct:It,ct=Math.abs(je)/Lt;if(Math.abs(je)>=GI||ct>.11){Ae(Et.current),(St=f.onDismiss)==null||St.call(f,f),re(_==="x"?Ct>0?"right":"left":It>0?"down":"up"),fe(),ie(!0),ye(!1);return}H(!1),z(null)},onPointerMove:xe=>{var Fe,Ge,St,Ct;if(!jt.current||!Ue||((Fe=window.getSelection())==null?void 0:Fe.toString().length)>0)return;let It=xe.clientY-jt.current.y,Lt=xe.clientX-jt.current.x,je=(Ge=e.swipeDirections)!=null?Ge:XI(X);!_&&(Math.abs(Lt)>1||Math.abs(It)>1)&&z(Math.abs(Lt)>Math.abs(It)?"x":"y");let ct={x:0,y:0};_==="y"?(je.includes("top")||je.includes("bottom"))&&(je.includes("top")&&It<0||je.includes("bottom")&&It>0)&&(ct.y=It):_==="x"&&(je.includes("left")||je.includes("right"))&&(je.includes("left")&&Lt<0||je.includes("right")&&Lt>0)&&(ct.x=Lt),(Math.abs(ct.x)>0||Math.abs(ct.y)>0)&&ye(!0),(St=Ve.current)==null||St.style.setProperty("--swipe-amount-x",`${ct.x}px`),(Ct=Ve.current)==null||Ct.style.setProperty("--swipe-amount-y",`${ct.y}px`)}},At&&!f.jsx?b.createElement("button",{"aria-label":J,"data-disabled":Y,"data-close-button":!0,onClick:Y||!Ue?()=>{}:()=>{var xe;fe(),(xe=f.onDismiss)==null||xe.call(f,f)},className:gn(I==null?void 0:I.closeButton,(o=f==null?void 0:f.classNames)==null?void 0:o.closeButton)},(s=K==null?void 0:K.close)!=null?s:MI):null,f.jsx||b.isValidElement(f.title)?f.jsx?f.jsx:typeof f.title=="function"?f.title():f.title:b.createElement(b.Fragment,null,Oe||f.icon||f.promise?b.createElement("div",{"data-icon":"",className:gn(I==null?void 0:I.icon,(i=f==null?void 0:f.classNames)==null?void 0:i.icon)},f.promise||f.type==="loading"&&!f.icon?f.icon||Be():null,f.type!=="loading"?f.icon||(K==null?void 0:K[Oe])||II(Oe):null):null,b.createElement("div",{"data-content":"",className:gn(I==null?void 0:I.content,(a=f==null?void 0:f.classNames)==null?void 0:a.content)},b.createElement("div",{"data-title":"",className:gn(I==null?void 0:I.title,(l=f==null?void 0:f.classNames)==null?void 0:l.title)},typeof f.title=="function"?f.title():f.title),f.description?b.createElement("div",{"data-description":"",className:gn(W,Nt,I==null?void 0:I.description,(c=f==null?void 0:f.classNames)==null?void 0:c.description)},typeof f.description=="function"?f.description():f.description):null),b.isValidElement(f.cancel)?f.cancel:f.cancel&&pi(f.cancel)?b.createElement("button",{"data-button":!0,"data-cancel":!0,style:f.cancelButtonStyle||O,onClick:xe=>{var Fe,Ge;pi(f.cancel)&&Ue&&((Ge=(Fe=f.cancel).onClick)==null||Ge.call(Fe,xe),fe())},className:gn(I==null?void 0:I.cancelButton,(d=f==null?void 0:f.classNames)==null?void 0:d.cancelButton)},f.cancel.label):null,b.isValidElement(f.action)?f.action:f.action&&pi(f.action)?b.createElement("button",{"data-button":!0,"data-action":!0,style:f.actionButtonStyle||L,onClick:xe=>{var Fe,Ge;pi(f.action)&&((Ge=(Fe=f.action).onClick)==null||Ge.call(Fe,xe),!xe.defaultPrevented&&fe())},className:gn(I==null?void 0:I.actionButton,(h=f==null?void 0:f.classNames)==null?void 0:h.actionButton)},f.action.label):null))};function ex(){if(typeof window>"u"||typeof document>"u")return"ltr";let e=document.documentElement.getAttribute("dir");return e==="auto"||!e?window.getComputedStyle(document.documentElement).direction:e}function ZI(e,t){let n={};return[e,t].forEach((r,o)=>{let s=o===1,i=s?"--mobile-offset":"--offset",a=s?VI:WI;function l(c){["top","right","bottom","left"].forEach(d=>{n[`${i}-${d}`]=typeof c=="number"?`${c}px`:c})}typeof r=="number"||typeof r=="string"?l(r):typeof r=="object"?["top","right","bottom","left"].forEach(c=>{r[c]===void 0?n[`${i}-${c}`]=a:n[`${i}-${c}`]=typeof r[c]=="number"?`${r[c]}px`:r[c]}):l(a)}),n}var QI=b.forwardRef(function(e,t){let{invert:n,position:r="bottom-right",hotkey:o=["altKey","KeyT"],expand:s,closeButton:i,className:a,offset:l,mobileOffset:c,theme:d="light",richColors:h,duration:m,style:f,visibleToasts:v=UI,toastOptions:g,dir:x=ex(),gap:y=qI,loadingIcon:w,icons:S,containerAriaLabel:k="Notifications",pauseWhenPageIsHidden:C}=e,[T,E]=b.useState([]),N=b.useMemo(()=>Array.from(new Set([r].concat(T.filter(P=>P.position).map(P=>P.position)))),[T,r]),[R,O]=b.useState([]),[L,q]=b.useState(!1),[W,j]=b.useState(!1),[X,G]=b.useState(d!=="system"?d:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),B=b.useRef(null),M=o.join("+").replace(/Key/g,"").replace(/Digit/g,""),I=b.useRef(null),K=b.useRef(!1),J=b.useCallback(P=>{E(_=>{var z;return(z=_.find(F=>F.id===P.id))!=null&&z.delete||Kt.dismiss(P.id),_.filter(({id:F})=>F!==P.id)})},[]);return b.useEffect(()=>Kt.subscribe(P=>{if(P.dismiss){E(_=>_.map(z=>z.id===P.id?{...z,delete:!0}:z));return}setTimeout(()=>{Ro.flushSync(()=>{E(_=>{let z=_.findIndex(F=>F.id===P.id);return z!==-1?[..._.slice(0,z),{..._[z],...P},..._.slice(z+1)]:[P,..._]})})})}),[]),b.useEffect(()=>{if(d!=="system"){G(d);return}if(d==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?G("dark"):G("light")),typeof window>"u")return;let P=window.matchMedia("(prefers-color-scheme: dark)");try{P.addEventListener("change",({matches:_})=>{G(_?"dark":"light")})}catch{P.addListener(({matches:z})=>{try{G(z?"dark":"light")}catch(F){console.error(F)}})}},[d]),b.useEffect(()=>{T.length<=1&&q(!1)},[T]),b.useEffect(()=>{let P=_=>{var z,F;o.every(re=>_[re]||_.code===re)&&(q(!0),(z=B.current)==null||z.focus()),_.code==="Escape"&&(document.activeElement===B.current||(F=B.current)!=null&&F.contains(document.activeElement))&&q(!1)};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[o]),b.useEffect(()=>{if(B.current)return()=>{I.current&&(I.current.focus({preventScroll:!0}),I.current=null,K.current=!1)}},[B.current]),b.createElement("section",{ref:t,"aria-label":`${k} ${M}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},N.map((P,_)=>{var z;let[F,re]=P.split("-");return T.length?b.createElement("ol",{key:P,dir:x==="auto"?ex():x,tabIndex:-1,ref:B,className:a,"data-sonner-toaster":!0,"data-theme":X,"data-y-position":F,"data-lifted":L&&T.length>1&&!s,"data-x-position":re,style:{"--front-toast-height":`${((z=R[0])==null?void 0:z.height)||0}px`,"--width":`${KI}px`,"--gap":`${y}px`,...f,...ZI(l,c)},onBlur:V=>{K.current&&!V.currentTarget.contains(V.relatedTarget)&&(K.current=!1,I.current&&(I.current.focus({preventScroll:!0}),I.current=null))},onFocus:V=>{V.target instanceof HTMLElement&&V.target.dataset.dismissible==="false"||K.current||(K.current=!0,I.current=V.relatedTarget)},onMouseEnter:()=>q(!0),onMouseMove:()=>q(!0),onMouseLeave:()=>{W||q(!1)},onDragEnd:()=>q(!1),onPointerDown:V=>{V.target instanceof HTMLElement&&V.target.dataset.dismissible==="false"||j(!0)},onPointerUp:()=>j(!1)},T.filter(V=>!V.position&&_===0||V.position===P).map((V,D)=>{var Z,ee;return b.createElement(JI,{key:V.id,icons:S,index:D,toast:V,defaultRichColors:h,duration:(Z=g==null?void 0:g.duration)!=null?Z:m,className:g==null?void 0:g.className,descriptionClassName:g==null?void 0:g.descriptionClassName,invert:n,visibleToasts:v,closeButton:(ee=g==null?void 0:g.closeButton)!=null?ee:i,interacting:W,position:P,style:g==null?void 0:g.style,unstyled:g==null?void 0:g.unstyled,classNames:g==null?void 0:g.classNames,cancelButtonStyle:g==null?void 0:g.cancelButtonStyle,actionButtonStyle:g==null?void 0:g.actionButtonStyle,removeToast:J,toasts:T.filter(Q=>Q.position==V.position),heights:R.filter(Q=>Q.position==V.position),setHeights:O,expandByDefault:s,gap:y,loadingIcon:w,expanded:L,pauseWhenPageIsHidden:C,swipeDirections:e.swipeDirections})})):null}))});const eN=({...e})=>{const{theme:t="system"}=EI();return u.jsx(QI,{theme:t,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...e})};$.Api=zv,$.ApiClient=Bv,$.ApiProvider=nu,$.ArtifactRenderer=Tp,$.Badge=Mp,$.Button=Ze,$.Card=il,$.CardContent=ul,$.CardDescription=cl,$.CardHeader=al,$.CardTitle=ll,$.ChatApi=qo,$.ChatApp=Mk,$.ChatInput=Uf,$.ChatInterface=Mr,$.ChatProviders=br,$.ChatWidget=Lk,$.Command=yl,$.CommandEmpty=Tl,$.CommandGroup=kl,$.CommandInput=Sl,$.CommandItem=El,$.CommandList=Cl,$.DEFAULT_TIMEOUT_MS=Xc,$.Dialog=el,$.DialogContent=zs,$.DialogHeader=Hs,$.DialogTitle=Us,$.DropdownMenu=Cs,$.DropdownMenuContent=ho,$.DropdownMenuItem=Bn,$.DropdownMenuTrigger=Ts,$.FileViewerModal=ap,$.HISTORY_TIMEOUT_MS=Jc,$.Input=Rl,$.InterruptPartRenderer=Ep,$.Label=pm,$.MarkdownContent=qn,$.MessageComponent=Xs,$.MessageList=pl,$.MessageRow=hl,$.NewChatButton=$k,$.PlotArtifact=yp,$.ResearchTaskArtifact=Cp,$.SETTINGS_STORAGE_KEY=Fi,$.ScrollArea=Pl,$.Select=xE,$.SelectContent=tg,$.SelectItem=ng,$.SelectTrigger=Zm,$.SelectValue=vE,$.Separator=ig,$.Sheet=AE,$.SheetContent=mg,$.SheetDescription=vg,$.SheetHeader=gg,$.SheetTitle=xg,$.SheetTrigger=jE,$.SimpleChat=Ok,$.SimpleJsonView=dl,$.Sonner=eN,$.StreamProgress=Ip,$.Switch=hg,$.Textarea=ka,$.ThinkingIndicator=Np,$.ThreadListItem=lm,$.ThreadManager=ni,$.ThreadStateProvider=ku,$.ThreadsProvider=hu,$.TimelineColumn=xx,$.Toaster=SI,$.ToolComponent=jp,$.Tooltip=QE,$.TooltipContent=Ig,$.TooltipProvider=ZE,$.TooltipTrigger=eI,$.UserTextContent=Ap,$.applySettings=yb,$.buildCheckpointIndex=ec,$.buildCheckpointPreviewMap=ix,$.chatApiClient=Mn,$.del=ji,$.downloadFileById=Qc,$.extractConfigFields=gi,$.fileToBase64=ru,$.get=Jt,$.getChatToken=Gc,$.getCheckpointForMessage=ax,$.getCurrentSettings=wb,$.getDefaultApiConfig=Mu,$.getDefaultChatSettings=Ou,$.getFileContent=Pi,$.getFileInfo=Uv,$.getMessageAttemptInfo=tc,$.getMessageDomKey=fl,$.getPreviewForMessage=mi,$.httpClient=Xt,$.hydrateHistorySnapshots=Rn,$.isEnvelope=su,$.listFiles=eu,$.loadStoredSettings=Du,$.onChatTokenChanged=Yc,$.post=Ko,$.processAttachments=ou,$.put=Zc,$.readNumber=rc,$.readString=Pn,$.resolveChatBaseUrl=vn,$.saveSettings=Lu,$.setChatToken=Vo,$.toPlainObject=_n,$.unwrap=$t,$.useApi=Xr,$.useCheckpointIndex=nc,$.useFilePreview=_p,$.useHasChatSession=xb,$.useParsedMessageContent=Pp,$.useShallowStableValue=ju,$.useStream=$i,$.useStreamingHook=$i,$.useThreadHistoryState=yu,$.useThreadManagerViewState=dm,$.useThreadState=eo,$.useThreadStateUpdater=Tu,$.useThreads=xr,$.useThreadsState=du,$.viewFileById=Hv,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
|
130
|
+
`);function pi(e){return e.label!==void 0}var UI=3,WI="32px",VI="16px",Qg=4e3,KI=356,qI=14,GI=20,YI=200;function gn(...e){return e.filter(Boolean).join(" ")}function XI(e){let[t,n]=e.split("-"),r=[];return t&&r.push(t),n&&r.push(n),r}var JI=e=>{var t,n,r,o,s,i,a,l,c,d,h;let{invert:m,toast:f,unstyled:v,interacting:g,setHeights:x,visibleToasts:y,heights:w,index:S,toasts:k,expanded:C,removeToast:T,defaultRichColors:E,closeButton:N,style:R,cancelButtonStyle:O,actionButtonStyle:L,className:q="",descriptionClassName:W="",duration:j,position:X,gap:G,loadingIcon:B,expandByDefault:M,classNames:I,icons:K,closeButtonAriaLabel:J="Close toast",pauseWhenPageIsHidden:P}=e,[_,z]=b.useState(null),[F,re]=b.useState(null),[V,D]=b.useState(!1),[Z,ee]=b.useState(!1),[Q,H]=b.useState(!1),[ae,ie]=b.useState(!1),[ge,ye]=b.useState(!1),[Te,Ae]=b.useState(0),[ke,st]=b.useState(0),vt=b.useRef(f.duration||j||Qg),kt=b.useRef(null),Ve=b.useRef(null),ze=S===0,Ke=S+1<=y,Oe=f.type,Ue=f.dismissible!==!1,dt=f.className||"",Nt=f.descriptionClassName||"",nt=b.useMemo(()=>w.findIndex(xe=>xe.toastId===f.id)||0,[w,f.id]),At=b.useMemo(()=>{var xe;return(xe=f.closeButton)!=null?xe:N},[f.closeButton,N]),wt=b.useMemo(()=>f.duration||j||Qg,[f.duration,j]),mt=b.useRef(0),Et=b.useRef(0),yt=b.useRef(0),jt=b.useRef(null),[qt,gt]=X.split("-"),Pe=b.useMemo(()=>w.reduce((xe,Fe,Ge)=>Ge>=nt?xe:xe+Fe.height,0),[w,nt]),We=OI(),_t=f.invert||m,Y=Oe==="loading";Et.current=b.useMemo(()=>nt*G+Pe,[nt,Pe]),b.useEffect(()=>{vt.current=wt},[wt]),b.useEffect(()=>{D(!0)},[]),b.useEffect(()=>{let xe=Ve.current;if(xe){let Fe=xe.getBoundingClientRect().height;return st(Fe),x(Ge=>[{toastId:f.id,height:Fe,position:f.position},...Ge]),()=>x(Ge=>Ge.filter(St=>St.toastId!==f.id))}},[x,f.id]),b.useLayoutEffect(()=>{if(!V)return;let xe=Ve.current,Fe=xe.style.height;xe.style.height="auto";let Ge=xe.getBoundingClientRect().height;xe.style.height=Fe,st(Ge),x(St=>St.find(Ct=>Ct.toastId===f.id)?St.map(Ct=>Ct.toastId===f.id?{...Ct,height:Ge}:Ct):[{toastId:f.id,height:Ge,position:f.position},...St])},[V,f.title,f.description,x,f.id]);let fe=b.useCallback(()=>{ee(!0),Ae(Et.current),x(xe=>xe.filter(Fe=>Fe.toastId!==f.id)),setTimeout(()=>{T(f)},YI)},[f,T,x,Et]);b.useEffect(()=>{if(f.promise&&Oe==="loading"||f.duration===1/0||f.type==="loading")return;let xe;return C||g||P&&We?(()=>{if(yt.current<mt.current){let Fe=new Date().getTime()-mt.current;vt.current=vt.current-Fe}yt.current=new Date().getTime()})():vt.current!==1/0&&(mt.current=new Date().getTime(),xe=setTimeout(()=>{var Fe;(Fe=f.onAutoClose)==null||Fe.call(f,f),fe()},vt.current)),()=>clearTimeout(xe)},[C,g,f,Oe,P,We,fe]),b.useEffect(()=>{f.delete&&fe()},[fe,f.delete]);function Be(){var xe,Fe,Ge;return K!=null&&K.loading?b.createElement("div",{className:gn(I==null?void 0:I.loader,(xe=f==null?void 0:f.classNames)==null?void 0:xe.loader,"sonner-loader"),"data-visible":Oe==="loading"},K.loading):B?b.createElement("div",{className:gn(I==null?void 0:I.loader,(Fe=f==null?void 0:f.classNames)==null?void 0:Fe.loader,"sonner-loader"),"data-visible":Oe==="loading"},B):b.createElement(AI,{className:gn(I==null?void 0:I.loader,(Ge=f==null?void 0:f.classNames)==null?void 0:Ge.loader),visible:Oe==="loading"})}return b.createElement("li",{tabIndex:0,ref:Ve,className:gn(q,dt,I==null?void 0:I.toast,(t=f==null?void 0:f.classNames)==null?void 0:t.toast,I==null?void 0:I.default,I==null?void 0:I[Oe],(n=f==null?void 0:f.classNames)==null?void 0:n[Oe]),"data-sonner-toast":"","data-rich-colors":(r=f.richColors)!=null?r:E,"data-styled":!(f.jsx||f.unstyled||v),"data-mounted":V,"data-promise":!!f.promise,"data-swiped":ge,"data-removed":Z,"data-visible":Ke,"data-y-position":qt,"data-x-position":gt,"data-index":S,"data-front":ze,"data-swiping":Q,"data-dismissible":Ue,"data-type":Oe,"data-invert":_t,"data-swipe-out":ae,"data-swipe-direction":F,"data-expanded":!!(C||M&&V),style:{"--index":S,"--toasts-before":S,"--z-index":k.length-S,"--offset":`${Z?Te:Et.current}px`,"--initial-height":M?"auto":`${ke}px`,...R,...f.style},onDragEnd:()=>{H(!1),z(null),jt.current=null},onPointerDown:xe=>{Y||!Ue||(kt.current=new Date,Ae(Et.current),xe.target.setPointerCapture(xe.pointerId),xe.target.tagName!=="BUTTON"&&(H(!0),jt.current={x:xe.clientX,y:xe.clientY}))},onPointerUp:()=>{var xe,Fe,Ge,St;if(ae||!Ue)return;jt.current=null;let Ct=Number(((xe=Ve.current)==null?void 0:xe.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),It=Number(((Fe=Ve.current)==null?void 0:Fe.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),Lt=new Date().getTime()-((Ge=kt.current)==null?void 0:Ge.getTime()),je=_==="x"?Ct:It,ct=Math.abs(je)/Lt;if(Math.abs(je)>=GI||ct>.11){Ae(Et.current),(St=f.onDismiss)==null||St.call(f,f),re(_==="x"?Ct>0?"right":"left":It>0?"down":"up"),fe(),ie(!0),ye(!1);return}H(!1),z(null)},onPointerMove:xe=>{var Fe,Ge,St,Ct;if(!jt.current||!Ue||((Fe=window.getSelection())==null?void 0:Fe.toString().length)>0)return;let It=xe.clientY-jt.current.y,Lt=xe.clientX-jt.current.x,je=(Ge=e.swipeDirections)!=null?Ge:XI(X);!_&&(Math.abs(Lt)>1||Math.abs(It)>1)&&z(Math.abs(Lt)>Math.abs(It)?"x":"y");let ct={x:0,y:0};_==="y"?(je.includes("top")||je.includes("bottom"))&&(je.includes("top")&&It<0||je.includes("bottom")&&It>0)&&(ct.y=It):_==="x"&&(je.includes("left")||je.includes("right"))&&(je.includes("left")&&Lt<0||je.includes("right")&&Lt>0)&&(ct.x=Lt),(Math.abs(ct.x)>0||Math.abs(ct.y)>0)&&ye(!0),(St=Ve.current)==null||St.style.setProperty("--swipe-amount-x",`${ct.x}px`),(Ct=Ve.current)==null||Ct.style.setProperty("--swipe-amount-y",`${ct.y}px`)}},At&&!f.jsx?b.createElement("button",{"aria-label":J,"data-disabled":Y,"data-close-button":!0,onClick:Y||!Ue?()=>{}:()=>{var xe;fe(),(xe=f.onDismiss)==null||xe.call(f,f)},className:gn(I==null?void 0:I.closeButton,(o=f==null?void 0:f.classNames)==null?void 0:o.closeButton)},(s=K==null?void 0:K.close)!=null?s:MI):null,f.jsx||b.isValidElement(f.title)?f.jsx?f.jsx:typeof f.title=="function"?f.title():f.title:b.createElement(b.Fragment,null,Oe||f.icon||f.promise?b.createElement("div",{"data-icon":"",className:gn(I==null?void 0:I.icon,(i=f==null?void 0:f.classNames)==null?void 0:i.icon)},f.promise||f.type==="loading"&&!f.icon?f.icon||Be():null,f.type!=="loading"?f.icon||(K==null?void 0:K[Oe])||II(Oe):null):null,b.createElement("div",{"data-content":"",className:gn(I==null?void 0:I.content,(a=f==null?void 0:f.classNames)==null?void 0:a.content)},b.createElement("div",{"data-title":"",className:gn(I==null?void 0:I.title,(l=f==null?void 0:f.classNames)==null?void 0:l.title)},typeof f.title=="function"?f.title():f.title),f.description?b.createElement("div",{"data-description":"",className:gn(W,Nt,I==null?void 0:I.description,(c=f==null?void 0:f.classNames)==null?void 0:c.description)},typeof f.description=="function"?f.description():f.description):null),b.isValidElement(f.cancel)?f.cancel:f.cancel&&pi(f.cancel)?b.createElement("button",{"data-button":!0,"data-cancel":!0,style:f.cancelButtonStyle||O,onClick:xe=>{var Fe,Ge;pi(f.cancel)&&Ue&&((Ge=(Fe=f.cancel).onClick)==null||Ge.call(Fe,xe),fe())},className:gn(I==null?void 0:I.cancelButton,(d=f==null?void 0:f.classNames)==null?void 0:d.cancelButton)},f.cancel.label):null,b.isValidElement(f.action)?f.action:f.action&&pi(f.action)?b.createElement("button",{"data-button":!0,"data-action":!0,style:f.actionButtonStyle||L,onClick:xe=>{var Fe,Ge;pi(f.action)&&((Ge=(Fe=f.action).onClick)==null||Ge.call(Fe,xe),!xe.defaultPrevented&&fe())},className:gn(I==null?void 0:I.actionButton,(h=f==null?void 0:f.classNames)==null?void 0:h.actionButton)},f.action.label):null))};function ex(){if(typeof window>"u"||typeof document>"u")return"ltr";let e=document.documentElement.getAttribute("dir");return e==="auto"||!e?window.getComputedStyle(document.documentElement).direction:e}function ZI(e,t){let n={};return[e,t].forEach((r,o)=>{let s=o===1,i=s?"--mobile-offset":"--offset",a=s?VI:WI;function l(c){["top","right","bottom","left"].forEach(d=>{n[`${i}-${d}`]=typeof c=="number"?`${c}px`:c})}typeof r=="number"||typeof r=="string"?l(r):typeof r=="object"?["top","right","bottom","left"].forEach(c=>{r[c]===void 0?n[`${i}-${c}`]=a:n[`${i}-${c}`]=typeof r[c]=="number"?`${r[c]}px`:r[c]}):l(a)}),n}var QI=b.forwardRef(function(e,t){let{invert:n,position:r="bottom-right",hotkey:o=["altKey","KeyT"],expand:s,closeButton:i,className:a,offset:l,mobileOffset:c,theme:d="light",richColors:h,duration:m,style:f,visibleToasts:v=UI,toastOptions:g,dir:x=ex(),gap:y=qI,loadingIcon:w,icons:S,containerAriaLabel:k="Notifications",pauseWhenPageIsHidden:C}=e,[T,E]=b.useState([]),N=b.useMemo(()=>Array.from(new Set([r].concat(T.filter(P=>P.position).map(P=>P.position)))),[T,r]),[R,O]=b.useState([]),[L,q]=b.useState(!1),[W,j]=b.useState(!1),[X,G]=b.useState(d!=="system"?d:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),B=b.useRef(null),M=o.join("+").replace(/Key/g,"").replace(/Digit/g,""),I=b.useRef(null),K=b.useRef(!1),J=b.useCallback(P=>{E(_=>{var z;return(z=_.find(F=>F.id===P.id))!=null&&z.delete||Kt.dismiss(P.id),_.filter(({id:F})=>F!==P.id)})},[]);return b.useEffect(()=>Kt.subscribe(P=>{if(P.dismiss){E(_=>_.map(z=>z.id===P.id?{...z,delete:!0}:z));return}setTimeout(()=>{Ro.flushSync(()=>{E(_=>{let z=_.findIndex(F=>F.id===P.id);return z!==-1?[..._.slice(0,z),{..._[z],...P},..._.slice(z+1)]:[P,..._]})})})}),[]),b.useEffect(()=>{if(d!=="system"){G(d);return}if(d==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?G("dark"):G("light")),typeof window>"u")return;let P=window.matchMedia("(prefers-color-scheme: dark)");try{P.addEventListener("change",({matches:_})=>{G(_?"dark":"light")})}catch{P.addListener(({matches:z})=>{try{G(z?"dark":"light")}catch(F){console.error(F)}})}},[d]),b.useEffect(()=>{T.length<=1&&q(!1)},[T]),b.useEffect(()=>{let P=_=>{var z,F;o.every(re=>_[re]||_.code===re)&&(q(!0),(z=B.current)==null||z.focus()),_.code==="Escape"&&(document.activeElement===B.current||(F=B.current)!=null&&F.contains(document.activeElement))&&q(!1)};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[o]),b.useEffect(()=>{if(B.current)return()=>{I.current&&(I.current.focus({preventScroll:!0}),I.current=null,K.current=!1)}},[B.current]),b.createElement("section",{ref:t,"aria-label":`${k} ${M}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},N.map((P,_)=>{var z;let[F,re]=P.split("-");return T.length?b.createElement("ol",{key:P,dir:x==="auto"?ex():x,tabIndex:-1,ref:B,className:a,"data-sonner-toaster":!0,"data-theme":X,"data-y-position":F,"data-lifted":L&&T.length>1&&!s,"data-x-position":re,style:{"--front-toast-height":`${((z=R[0])==null?void 0:z.height)||0}px`,"--width":`${KI}px`,"--gap":`${y}px`,...f,...ZI(l,c)},onBlur:V=>{K.current&&!V.currentTarget.contains(V.relatedTarget)&&(K.current=!1,I.current&&(I.current.focus({preventScroll:!0}),I.current=null))},onFocus:V=>{V.target instanceof HTMLElement&&V.target.dataset.dismissible==="false"||K.current||(K.current=!0,I.current=V.relatedTarget)},onMouseEnter:()=>q(!0),onMouseMove:()=>q(!0),onMouseLeave:()=>{W||q(!1)},onDragEnd:()=>q(!1),onPointerDown:V=>{V.target instanceof HTMLElement&&V.target.dataset.dismissible==="false"||j(!0)},onPointerUp:()=>j(!1)},T.filter(V=>!V.position&&_===0||V.position===P).map((V,D)=>{var Z,ee;return b.createElement(JI,{key:V.id,icons:S,index:D,toast:V,defaultRichColors:h,duration:(Z=g==null?void 0:g.duration)!=null?Z:m,className:g==null?void 0:g.className,descriptionClassName:g==null?void 0:g.descriptionClassName,invert:n,visibleToasts:v,closeButton:(ee=g==null?void 0:g.closeButton)!=null?ee:i,interacting:W,position:P,style:g==null?void 0:g.style,unstyled:g==null?void 0:g.unstyled,classNames:g==null?void 0:g.classNames,cancelButtonStyle:g==null?void 0:g.cancelButtonStyle,actionButtonStyle:g==null?void 0:g.actionButtonStyle,removeToast:J,toasts:T.filter(Q=>Q.position==V.position),heights:R.filter(Q=>Q.position==V.position),setHeights:O,expandByDefault:s,gap:y,loadingIcon:w,expanded:L,pauseWhenPageIsHidden:C,swipeDirections:e.swipeDirections})})):null}))});const eN=({...e})=>{const{theme:t="system"}=EI();return u.jsx(QI,{theme:t,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...e})};$.Api=zv,$.ApiClient=Bv,$.ApiProvider=nu,$.ArtifactRenderer=Tp,$.Badge=Mp,$.Button=Ze,$.Card=il,$.CardContent=ul,$.CardDescription=cl,$.CardHeader=al,$.CardTitle=ll,$.ChatApi=qo,$.ChatApp=Mk,$.ChatInput=Uf,$.ChatInterface=Mr,$.ChatProviders=br,$.ChatWidget=Lk,$.Command=yl,$.CommandEmpty=Tl,$.CommandGroup=kl,$.CommandInput=Sl,$.CommandItem=El,$.CommandList=Cl,$.DEFAULT_TIMEOUT_MS=Xc,$.Dialog=el,$.DialogContent=zs,$.DialogHeader=Hs,$.DialogTitle=Us,$.DropdownMenu=Cs,$.DropdownMenuContent=ho,$.DropdownMenuItem=Bn,$.DropdownMenuTrigger=Ts,$.FileViewerModal=ap,$.HISTORY_TIMEOUT_MS=Jc,$.Input=Rl,$.InterruptPartRenderer=Ep,$.Label=pm,$.MarkdownContent=qn,$.MessageComponent=Xs,$.MessageList=pl,$.MessageRow=hl,$.NewChatButton=$k,$.PlotArtifact=yp,$.ResearchTaskArtifact=Cp,$.SETTINGS_STORAGE_KEY=Fi,$.ScrollArea=Pl,$.Select=xE,$.SelectContent=tg,$.SelectItem=ng,$.SelectTrigger=Zm,$.SelectValue=vE,$.Separator=ig,$.Sheet=AE,$.SheetContent=mg,$.SheetDescription=vg,$.SheetHeader=gg,$.SheetTitle=xg,$.SheetTrigger=jE,$.SimpleChat=Ok,$.SimpleJsonView=dl,$.Sonner=eN,$.StreamProgress=Ip,$.Switch=hg,$.Textarea=ka,$.ThinkingIndicator=Np,$.ThreadListItem=lm,$.ThreadManager=ni,$.ThreadStateProvider=ku,$.ThreadsProvider=hu,$.TimelineColumn=xx,$.Toaster=SI,$.ToolComponent=jp,$.Tooltip=QE,$.TooltipContent=Ig,$.TooltipProvider=ZE,$.TooltipTrigger=eI,$.UserTextContent=Ap,$.applySettings=yb,$.buildCheckpointIndex=ec,$.buildCheckpointPreviewMap=ix,$.chatApiClient=Nn,$.del=ji,$.downloadFileById=Qc,$.extractConfigFields=gi,$.fileToBase64=ru,$.get=Jt,$.getChatToken=Gc,$.getCheckpointForMessage=ax,$.getCurrentSettings=wb,$.getDefaultApiConfig=Mu,$.getDefaultChatSettings=Ou,$.getFileContent=Pi,$.getFileInfo=Uv,$.getMessageAttemptInfo=tc,$.getMessageDomKey=fl,$.getPreviewForMessage=mi,$.httpClient=Xt,$.hydrateHistorySnapshots=Mn,$.isEnvelope=su,$.listFiles=eu,$.loadStoredSettings=Du,$.onChatTokenChanged=Yc,$.post=Ko,$.processAttachments=ou,$.put=Zc,$.readNumber=rc,$.readString=Rn,$.resolveChatBaseUrl=vn,$.saveSettings=Lu,$.setChatToken=Vo,$.toPlainObject=Pn,$.unwrap=$t,$.useApi=Xr,$.useCheckpointIndex=nc,$.useFilePreview=_p,$.useHasChatSession=xb,$.useParsedMessageContent=Pp,$.useShallowStableValue=ju,$.useStream=$i,$.useStreamingHook=$i,$.useThreadHistoryState=yu,$.useThreadManagerViewState=dm,$.useThreadState=eo,$.useThreadStateUpdater=Tu,$.useThreads=xr,$.useThreadsState=du,$.viewFileById=Hv,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|