teodor-new-chat-ui 4.3.75 → 4.3.76
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/components/chat/MessageList.d.ts +1 -1
- package/dist/index.esm.js +3761 -3755
- package/dist/index.umd.js +63 -63
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(_e,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],b):(_e=typeof globalThis<"u"?globalThis:_e||self,b(_e.NewChatUI={},_e.React,_e.LucideReact,_e.reactSlot,_e.classVarianceAuthority,_e.clsx,_e.tailwindMerge,_e.ReactDOM))})(this,function(_e,b,me,sr,Ro,Tm,Em,
|
|
1
|
+
(function(_e,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],b):(_e=typeof globalThis<"u"?globalThis:_e||self,b(_e.NewChatUI={},_e.React,_e.LucideReact,_e.reactSlot,_e.classVarianceAuthority,_e.clsx,_e.tailwindMerge,_e.ReactDOM))})(this,function(_e,b,me,sr,Ro,Tm,Em,hi){"use strict";var Uk=Object.defineProperty;var Wk=(_e,b,me)=>b in _e?Uk(_e,b,{enumerable:!0,configurable:!0,writable:!0,value:me}):_e[b]=me;var Cm=(_e,b,me)=>Wk(_e,typeof b!="symbol"?b+"":b,me);function Cl(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 m=Cl(b),Po=Cl(hi);var pi={exports:{}},qr={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -27,72 +27,28 @@ Check the top-level render call using <`+ue+">.")}return H}}function kr(I,H){{if
|
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Ao,an,A,an),wn[an+Ao]=!0}}return I===r?Mn(Ie):Tr(Ie),Ie}}function Er(I,H,ue){return Un(I,H,ue,!0)}function Wr(I,H,ue){return Un(I,H,ue,!1)}var Vr=Wr,or=Er;Kr.Fragment=r,Kr.jsx=Vr,Kr.jsxs=or}()),Kr}process.env.NODE_ENV==="production"?hi.exports=Im():hi.exports=Am();var u=hi.exports;function El(e,t){return function(){return e.apply(t,arguments)}}const{toString:Nm}=Object.prototype,{getPrototypeOf:pi}=Object,{iterator:Oo,toStringTag:Il}=Symbol,Mo=(e=>t=>{const n=Nm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),ln=e=>(e=e.toLowerCase(),t=>Mo(t)===e),Do=e=>t=>typeof t===e,{isArray:Ir}=Array,Ar=Do("undefined");function Gr(e){return e!==null&&!Ar(e)&&e.constructor!==null&&!Ar(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Al=ln("ArrayBuffer");function _m(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Al(e.buffer),t}const jm=Do("string"),zt=Do("function"),Nl=Do("number"),Yr=e=>e!==null&&typeof e=="object",Rm=e=>e===!0||e===!1,Lo=e=>{if(Mo(e)!=="object")return!1;const t=pi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Il in e)&&!(Oo in e)},Pm=e=>{if(!Yr(e)||Gr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Om=ln("Date"),Mm=ln("File"),Dm=ln("Blob"),Lm=ln("FileList"),Fm=e=>Yr(e)&&zt(e.pipe),$m=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=Mo(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},zm=ln("URLSearchParams"),[Bm,Hm,Um,Wm]=["ReadableStream","Request","Response","Headers"].map(ln),Vm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Xr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Ir(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Gr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function _l(e,t){if(Gr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const ir=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,jl=e=>!Ar(e)&&e!==ir;function mi(){const{caseless:e,skipUndefined:t}=jl(this)&&this||{},n={},r=(o,s)=>{const i=e&&_l(n,s)||s;Lo(n[i])&&Lo(o)?n[i]=mi(n[i],o):Lo(o)?n[i]=mi({},o):Ir(o)?n[i]=o.slice():(!t||!Ar(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Xr(arguments[o],r);return n}const qm=(e,t,n,{allOwnKeys:r}={})=>(Xr(t,(o,s)=>{n&&zt(o)?e[s]=El(o,n):e[s]=o},{allOwnKeys:r}),e),Km=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Gm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Ym=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&pi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Xm=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Jm=e=>{if(!e)return null;if(Ir(e))return e;let t=e.length;if(!Nl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Zm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&pi(Uint8Array)),Qm=(e,t)=>{const r=(e&&e[Oo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},eg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},tg=ln("HTMLFormElement"),ng=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Rl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),rg=ln("RegExp"),Pl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Xr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},og=e=>{Pl(e,(t,n)=>{if(zt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(zt(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},sg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Ir(e)?r(e):r(String(e).split(t)),n},ig=()=>{},ag=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function lg(e){return!!(e&&zt(e.append)&&e[Il]==="FormData"&&e[Oo])}const cg=e=>{const t=new Array(10),n=(r,o)=>{if(Yr(r)){if(t.indexOf(r)>=0)return;if(Gr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Ir(r)?[]:{};return Xr(r,(i,a)=>{const l=n(i,o+1);!Ar(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},ug=ln("AsyncFunction"),dg=e=>e&&(Yr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Ol=((e,t)=>e?setImmediate:t?((n,r)=>(ir.addEventListener("message",({source:o,data:s})=>{o===ir&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),ir.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",zt(ir.postMessage)),fg=typeof queueMicrotask<"u"?queueMicrotask.bind(ir):typeof process<"u"&&process.nextTick||Ol,O={isArray:Ir,isArrayBuffer:Al,isBuffer:Gr,isFormData:$m,isArrayBufferView:_m,isString:jm,isNumber:Nl,isBoolean:Rm,isObject:Yr,isPlainObject:Lo,isEmptyObject:Pm,isReadableStream:Bm,isRequest:Hm,isResponse:Um,isHeaders:Wm,isUndefined:Ar,isDate:Om,isFile:Mm,isBlob:Dm,isRegExp:rg,isFunction:zt,isStream:Fm,isURLSearchParams:zm,isTypedArray:Zm,isFileList:Lm,forEach:Xr,merge:mi,extend:qm,trim:Vm,stripBOM:Km,inherits:Gm,toFlatObject:Ym,kindOf:Mo,kindOfTest:ln,endsWith:Xm,toArray:Jm,forEachEntry:Qm,matchAll:eg,isHTMLForm:tg,hasOwnProperty:Rl,hasOwnProp:Rl,reduceDescriptors:Pl,freezeMethods:og,toObjectSet:sg,toCamelCase:ng,noop:ig,toFiniteNumber:ag,findKey:_l,global:ir,isContextDefined:jl,isSpecCompliantForm:lg,toJSONObject:cg,isAsyncFn:ug,isThenable:dg,setImmediate:Ol,asap:fg,isIterable:e=>e!=null&&zt(e[Oo])};function Re(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(Re,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const Ml=Re.prototype,Dl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Dl[e]={value:e}}),Object.defineProperties(Re,Dl),Object.defineProperty(Ml,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(Ml);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Re.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const hg=null;function gi(e){return O.isPlainObject(e)||O.isArray(e)}function Ll(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function Fl(e,t,n){return e?e.concat(t).map(function(o,s){return o=Ll(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function pg(e){return O.isArray(e)&&!e.some(gi)}const mg=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function Fo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(y,v){return!O.isUndefined(v[y])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(g){if(g===null)return"";if(O.isDate(g))return g.toISOString();if(O.isBoolean(g))return g.toString();if(!l&&O.isBlob(g))throw new Re("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(g)||O.isTypedArray(g)?l&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function d(g,y,v){let x=g;if(g&&!v&&typeof g=="object"){if(O.endsWith(y,"{}"))y=r?y:y.slice(0,-2),g=JSON.stringify(g);else if(O.isArray(g)&&pg(g)||(O.isFileList(g)||O.endsWith(y,"[]"))&&(x=O.toArray(g)))return y=Ll(y),x.forEach(function(S,T){!(O.isUndefined(S)||S===null)&&t.append(i===!0?Fl([y],T,s):i===null?y:y+"[]",c(S))}),!1}return gi(g)?!0:(t.append(Fl(v,y,s),c(g)),!1)}const f=[],h=Object.assign(mg,{defaultVisitor:d,convertValue:c,isVisitable:gi});function p(g,y){if(!O.isUndefined(g)){if(f.indexOf(g)!==-1)throw Error("Circular reference detected in "+y.join("."));f.push(g),O.forEach(g,function(x,w){(!(O.isUndefined(x)||x===null)&&o.call(t,x,O.isString(w)?w.trim():w,y,h))===!0&&p(x,y?y.concat(w):[w])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return p(e),t}function $l(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function xi(e,t){this._pairs=[],e&&Fo(e,this,t)}const zl=xi.prototype;zl.append=function(t,n){this._pairs.push([t,n])},zl.toString=function(t){const n=t?function(r){return t.call(this,r,$l)}:$l;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function gg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Bl(e,t,n){if(!t)return e;const r=n&&n.encode||gg;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new xi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Hl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Ul={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},xg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:xi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},yi=typeof window<"u"&&typeof document<"u",vi=typeof navigator=="object"&&navigator||void 0,yg=yi&&(!vi||["ReactNative","NativeScript","NS"].indexOf(vi.product)<0),vg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",wg=yi&&window.location.href||"http://localhost",Rt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:yi,hasStandardBrowserEnv:yg,hasStandardBrowserWebWorkerEnv:vg,navigator:vi,origin:wg},Symbol.toStringTag,{value:"Module"})),...xg};function bg(e,t){return Fo(e,new Rt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Rt.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Sg(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Cg(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Wl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Cg(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Sg(r),o,n,0)}),n}return null}function kg(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Jr={transitional:Ul,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(Wl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return bg(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Fo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),kg(t)):t}],transformResponse:[function(t){const n=this.transitional||Jr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Re.from(a,Re.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Rt.classes.FormData,Blob:Rt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Jr.headers[e]={}});const Tg=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Eg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
-
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Tg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Vl=Symbol("internals");function Zr(e){return e&&String(e).trim().toLowerCase()}function $o(e){return e===!1||e==null?e:O.isArray(e)?e.map($o):String(e)}function Ig(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const Ag=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function
|
|
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[Vl]=this[Vl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Zr(i);r[a]||(_g(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Bt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Bt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Bt);function bi(e,t){const n=this||Jr,r=t||n,o=Bt.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ql(e){return!!(e&&e.__CANCEL__)}function Nr(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(Nr,Re,{__CANCEL__:!0});function Kl(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 jg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Rg(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 f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function Pg(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(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const zo=(e,t,n=3)=>{let r=0;const o=Rg(50,250);return Pg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={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(f)},n)},Gl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Yl=e=>(...t)=>O.asap(()=>e(...t)),Og=Rt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Rt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Rt.origin),Rt.navigator&&/(msie|trident)/i.test(Rt.navigator.userAgent)):()=>!0,Mg=Rt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.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 Dg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Lg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Xl(e,t,n){let r=!Dg(t);return e&&(r||n==!1)?Lg(e,t):t}const Jl=e=>e instanceof Bt?{...e}:e;function ar(e,t){t=t||{};const n={};function r(c,d,f,h){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:h},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,h){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f 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,f)=>o(Jl(c),Jl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);O.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Zl=e=>{const t=ar({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Bt.from(i),t.url=Bl(Xl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(Rt.hasStandardBrowserEnv||Rt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Rt.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&Og(t.url))){const l=o&&s&&Mg.read(s);l&&i.set(o,l)}return t},Fg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Zl(e);let s=o.data;const i=Bt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,g;function y(){p&&p(),g&&g(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let v=new XMLHttpRequest;v.open(o.method.toUpperCase(),o.url,!0),v.timeout=o.timeout;function x(){if(!v)return;const S=Bt.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:S,config:e,request:v};Kl(function(E){n(E),y()},function(E){r(E),y()},k),v=null}"onloadend"in v?v.onloadend=x:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(x)},v.onabort=function(){v&&(r(new Re("Request aborted",Re.ECONNABORTED,e,v)),v=null)},v.onerror=function(T){const k=T&&T.message?T.message:"Network Error",C=new Re(k,Re.ERR_NETWORK,e,v);C.event=T||null,r(C),v=null},v.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||Ul;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new Re(T,k.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,v)),v=null},s===void 0&&i.setContentType(null),"setRequestHeader"in v&&O.forEach(i.toJSON(),function(T,k){v.setRequestHeader(k,T)}),O.isUndefined(o.withCredentials)||(v.withCredentials=!!o.withCredentials),a&&a!=="json"&&(v.responseType=o.responseType),c&&([h,g]=zo(c,!0),v.addEventListener("progress",h)),l&&v.upload&&([f,p]=zo(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{v&&(r(!S||S.type?new Nr(null,e,v):S),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=jg(o.url);if(w&&Rt.protocols.indexOf(w)===-1){r(new Re("Unsupported protocol "+w+":",Re.ERR_BAD_REQUEST,e));return}v.send(s||null)})},$g=(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 Nr(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=()=>O.asap(a),l}},zg=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},Bg=async function*(e,t){for await(const n of Hg(e))yield*zg(n,t)},Hg=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()}},Ql=(e,t,n,r)=>{const o=Bg(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 f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},ec=64*1024,{isFunction:Bo}=O,Ug=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:tc,TextEncoder:nc}=O.global,rc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Wg=e=>{e=O.merge.call({skipUndefined:!0},Ug,e);const{fetch:t,Request:n,Response:r}=e,o=t?Bo(t):typeof fetch=="function",s=Bo(n),i=Bo(r);if(!o)return!1;const a=o&&Bo(tc),l=o&&(typeof nc=="function"?(g=>y=>g.encode(y))(new nc):async g=>new Uint8Array(await new n(g).arrayBuffer())),c=s&&a&&rc(()=>{let g=!1;const y=new n(Rt.origin,{body:new tc,method:"POST",get duplex(){return g=!0,"half"}}).headers.has("Content-Type");return g&&!y}),d=i&&a&&rc(()=>O.isReadableStream(new r("").body)),f={stream:d&&(g=>g.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!f[g]&&(f[g]=(y,v)=>{let x=y&&y[g];if(x)return x.call(y);throw new Re(`Response type '${g}' is not supported`,Re.ERR_NOT_SUPPORT,v)})});const h=async g=>{if(g==null)return 0;if(O.isBlob(g))return g.size;if(O.isSpecCompliantForm(g))return(await new n(Rt.origin,{method:"POST",body:g}).arrayBuffer()).byteLength;if(O.isArrayBufferView(g)||O.isArrayBuffer(g))return g.byteLength;if(O.isURLSearchParams(g)&&(g=g+""),O.isString(g))return(await l(g)).byteLength},p=async(g,y)=>{const v=O.toFiniteNumber(g.getContentLength());return v??h(y)};return async g=>{let{url:y,method:v,data:x,signal:w,cancelToken:S,timeout:T,onDownloadProgress:k,onUploadProgress:C,responseType:E,headers:_,withCredentials:j="same-origin",fetchOptions:D}=Zl(g),F=t||fetch;E=E?(E+"").toLowerCase():"text";let K=$g([w,S&&S.toAbortSignal()],T),P=null;const R=K&&K.unsubscribe&&(()=>{K.unsubscribe()});let L;try{if(C&&c&&v!=="get"&&v!=="head"&&(L=await p(_,x))!==0){let Q=new n(y,{method:"POST",body:x,duplex:"half"}),le;if(O.isFormData(x)&&(le=Q.headers.get("content-type"))&&_.setContentType(le),Q.body){const[B,ie]=Gl(L,zo(Yl(C)));x=Ql(Q.body,ec,B,ie)}}O.isString(j)||(j=j?"include":"omit");const U=s&&"credentials"in n.prototype,te={...D,signal:K,method:v.toUpperCase(),headers:_.normalize().toJSON(),body:x,duplex:"half",credentials:U?j:void 0};P=s&&new n(y,te);let V=await(s?F(P,D):F(y,te));const z=d&&(E==="stream"||E==="response");if(d&&(k||z&&R)){const Q={};["status","statusText","headers"].forEach(Ce=>{Q[Ce]=V[Ce]});const le=O.toFiniteNumber(V.headers.get("content-length")),[B,ie]=k&&Gl(le,zo(Yl(k),!0))||[];V=new r(Ql(V.body,ec,B,()=>{ie&&ie(),R&&R()}),Q)}E=E||"text";let G=await f[O.findKey(f,E)||"text"](V,g);return!z&&R&&R(),await new Promise((Q,le)=>{Kl(Q,le,{data:G,headers:Bt.from(V.headers),status:V.status,statusText:V.statusText,config:g,request:P})})}catch(U){throw R&&R(),U&&U.name==="TypeError"&&/Load failed|fetch/i.test(U.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,g,P),{cause:U.cause||U}):Re.from(U,U&&U.code,g,P)}}},Vg=new Map,oc=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=Vg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:Wg(t)),d=c;return c};oc();const Si={http:hg,xhr:Fg,fetch:{get:oc}};O.forEach(Si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const sc=e=>`- ${e}`,qg=e=>O.isFunction(e)||e===null||e===!1,ic={getAdapter:(e,t)=>{e=O.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,!qg(r)&&(o=Si[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(O.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 :
|
|
30
|
+
<%s key={someKey} {...props} />`,Ao,an,A,an),wn[an+Ao]=!0}}return I===r?Mn(Ie):Tr(Ie),Ie}}function Er(I,H,ue){return Un(I,H,ue,!0)}function Wr(I,H,ue){return Un(I,H,ue,!1)}var Vr=Wr,or=Er;Kr.Fragment=r,Kr.jsx=Vr,Kr.jsxs=or}()),Kr}process.env.NODE_ENV==="production"?pi.exports=Im():pi.exports=Am();var u=pi.exports;function El(e,t){return function(){return e.apply(t,arguments)}}const{toString:Nm}=Object.prototype,{getPrototypeOf:mi}=Object,{iterator:Oo,toStringTag:Il}=Symbol,Mo=(e=>t=>{const n=Nm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),ln=e=>(e=e.toLowerCase(),t=>Mo(t)===e),Do=e=>t=>typeof t===e,{isArray:Ir}=Array,Ar=Do("undefined");function Gr(e){return e!==null&&!Ar(e)&&e.constructor!==null&&!Ar(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Al=ln("ArrayBuffer");function _m(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Al(e.buffer),t}const jm=Do("string"),zt=Do("function"),Nl=Do("number"),Yr=e=>e!==null&&typeof e=="object",Rm=e=>e===!0||e===!1,Lo=e=>{if(Mo(e)!=="object")return!1;const t=mi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Il in e)&&!(Oo in e)},Pm=e=>{if(!Yr(e)||Gr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Om=ln("Date"),Mm=ln("File"),Dm=ln("Blob"),Lm=ln("FileList"),Fm=e=>Yr(e)&&zt(e.pipe),$m=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=Mo(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},zm=ln("URLSearchParams"),[Bm,Hm,Um,Wm]=["ReadableStream","Request","Response","Headers"].map(ln),Vm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Xr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Ir(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Gr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function _l(e,t){if(Gr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const ir=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,jl=e=>!Ar(e)&&e!==ir;function gi(){const{caseless:e,skipUndefined:t}=jl(this)&&this||{},n={},r=(o,s)=>{const i=e&&_l(n,s)||s;Lo(n[i])&&Lo(o)?n[i]=gi(n[i],o):Lo(o)?n[i]=gi({},o):Ir(o)?n[i]=o.slice():(!t||!Ar(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Xr(arguments[o],r);return n}const qm=(e,t,n,{allOwnKeys:r}={})=>(Xr(t,(o,s)=>{n&&zt(o)?e[s]=El(o,n):e[s]=o},{allOwnKeys:r}),e),Km=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Gm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Ym=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&mi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Xm=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Jm=e=>{if(!e)return null;if(Ir(e))return e;let t=e.length;if(!Nl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Zm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&mi(Uint8Array)),Qm=(e,t)=>{const r=(e&&e[Oo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},eg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},tg=ln("HTMLFormElement"),ng=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Rl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),rg=ln("RegExp"),Pl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Xr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},og=e=>{Pl(e,(t,n)=>{if(zt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(zt(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},sg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Ir(e)?r(e):r(String(e).split(t)),n},ig=()=>{},ag=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function lg(e){return!!(e&&zt(e.append)&&e[Il]==="FormData"&&e[Oo])}const cg=e=>{const t=new Array(10),n=(r,o)=>{if(Yr(r)){if(t.indexOf(r)>=0)return;if(Gr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Ir(r)?[]:{};return Xr(r,(i,a)=>{const l=n(i,o+1);!Ar(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},ug=ln("AsyncFunction"),dg=e=>e&&(Yr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Ol=((e,t)=>e?setImmediate:t?((n,r)=>(ir.addEventListener("message",({source:o,data:s})=>{o===ir&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),ir.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",zt(ir.postMessage)),fg=typeof queueMicrotask<"u"?queueMicrotask.bind(ir):typeof process<"u"&&process.nextTick||Ol,O={isArray:Ir,isArrayBuffer:Al,isBuffer:Gr,isFormData:$m,isArrayBufferView:_m,isString:jm,isNumber:Nl,isBoolean:Rm,isObject:Yr,isPlainObject:Lo,isEmptyObject:Pm,isReadableStream:Bm,isRequest:Hm,isResponse:Um,isHeaders:Wm,isUndefined:Ar,isDate:Om,isFile:Mm,isBlob:Dm,isRegExp:rg,isFunction:zt,isStream:Fm,isURLSearchParams:zm,isTypedArray:Zm,isFileList:Lm,forEach:Xr,merge:gi,extend:qm,trim:Vm,stripBOM:Km,inherits:Gm,toFlatObject:Ym,kindOf:Mo,kindOfTest:ln,endsWith:Xm,toArray:Jm,forEachEntry:Qm,matchAll:eg,isHTMLForm:tg,hasOwnProperty:Rl,hasOwnProp:Rl,reduceDescriptors:Pl,freezeMethods:og,toObjectSet:sg,toCamelCase:ng,noop:ig,toFiniteNumber:ag,findKey:_l,global:ir,isContextDefined:jl,isSpecCompliantForm:lg,toJSONObject:cg,isAsyncFn:ug,isThenable:dg,setImmediate:Ol,asap:fg,isIterable:e=>e!=null&&zt(e[Oo])};function Re(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(Re,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const Ml=Re.prototype,Dl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Dl[e]={value:e}}),Object.defineProperties(Re,Dl),Object.defineProperty(Ml,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(Ml);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Re.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const hg=null;function xi(e){return O.isPlainObject(e)||O.isArray(e)}function Ll(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function Fl(e,t,n){return e?e.concat(t).map(function(o,s){return o=Ll(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function pg(e){return O.isArray(e)&&!e.some(xi)}const mg=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function Fo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(y,v){return!O.isUndefined(v[y])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(g){if(g===null)return"";if(O.isDate(g))return g.toISOString();if(O.isBoolean(g))return g.toString();if(!l&&O.isBlob(g))throw new Re("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(g)||O.isTypedArray(g)?l&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function d(g,y,v){let x=g;if(g&&!v&&typeof g=="object"){if(O.endsWith(y,"{}"))y=r?y:y.slice(0,-2),g=JSON.stringify(g);else if(O.isArray(g)&&pg(g)||(O.isFileList(g)||O.endsWith(y,"[]"))&&(x=O.toArray(g)))return y=Ll(y),x.forEach(function(S,T){!(O.isUndefined(S)||S===null)&&t.append(i===!0?Fl([y],T,s):i===null?y:y+"[]",c(S))}),!1}return xi(g)?!0:(t.append(Fl(v,y,s),c(g)),!1)}const f=[],h=Object.assign(mg,{defaultVisitor:d,convertValue:c,isVisitable:xi});function p(g,y){if(!O.isUndefined(g)){if(f.indexOf(g)!==-1)throw Error("Circular reference detected in "+y.join("."));f.push(g),O.forEach(g,function(x,w){(!(O.isUndefined(x)||x===null)&&o.call(t,x,O.isString(w)?w.trim():w,y,h))===!0&&p(x,y?y.concat(w):[w])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return p(e),t}function $l(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function yi(e,t){this._pairs=[],e&&Fo(e,this,t)}const zl=yi.prototype;zl.append=function(t,n){this._pairs.push([t,n])},zl.toString=function(t){const n=t?function(r){return t.call(this,r,$l)}:$l;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function gg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Bl(e,t,n){if(!t)return e;const r=n&&n.encode||gg;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new yi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Hl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Ul={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},xg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:yi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},vi=typeof window<"u"&&typeof document<"u",wi=typeof navigator=="object"&&navigator||void 0,yg=vi&&(!wi||["ReactNative","NativeScript","NS"].indexOf(wi.product)<0),vg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",wg=vi&&window.location.href||"http://localhost",Rt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:vi,hasStandardBrowserEnv:yg,hasStandardBrowserWebWorkerEnv:vg,navigator:wi,origin:wg},Symbol.toStringTag,{value:"Module"})),...xg};function bg(e,t){return Fo(e,new Rt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Rt.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Sg(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Cg(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Wl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Cg(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Sg(r),o,n,0)}),n}return null}function kg(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Jr={transitional:Ul,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(Wl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return bg(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Fo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),kg(t)):t}],transformResponse:[function(t){const n=this.transitional||Jr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Re.from(a,Re.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Rt.classes.FormData,Blob:Rt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Jr.headers[e]={}});const Tg=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Eg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
+
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Tg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Vl=Symbol("internals");function Zr(e){return e&&String(e).trim().toLowerCase()}function $o(e){return e===!1||e==null?e:O.isArray(e)?e.map($o):String(e)}function Ig(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const Ag=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function bi(e,t,n,r,o){if(O.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!O.isString(t)){if(O.isString(r))return t.indexOf(r)!==-1;if(O.isRegExp(r))return r.test(t)}}function Ng(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function _g(e,t){const n=O.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Bt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Zr(l);if(!d)throw new Error("header name must be a non-empty string");const f=O.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=$o(a))}const i=(a,l)=>O.forEach(a,(c,d)=>s(c,d,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!Ag(t))i(Eg(t),n);else if(O.isObject(t)&&O.isIterable(t)){let a={},l,c;for(const d of t){if(!O.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?O.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Zr(t),t){const r=O.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Ig(o);if(O.isFunction(n))return n.call(this,o,r);if(O.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Zr(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||bi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Zr(i),i){const a=O.findKey(r,i);a&&(!n||bi(r,r[a],a,n))&&(delete r[a],o=!0)}}return O.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||bi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return O.forEach(this,(o,s)=>{const i=O.findKey(r,s);if(i){n[i]=$o(o),delete n[s];return}const a=t?Ng(s):String(s).trim();a!==s&&delete n[s],n[a]=$o(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
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[Vl]=this[Vl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Zr(i);r[a]||(_g(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Bt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Bt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Bt);function Si(e,t){const n=this||Jr,r=t||n,o=Bt.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ql(e){return!!(e&&e.__CANCEL__)}function Nr(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(Nr,Re,{__CANCEL__:!0});function Kl(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 jg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Rg(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 f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function Pg(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(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const zo=(e,t,n=3)=>{let r=0;const o=Rg(50,250);return Pg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={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(f)},n)},Gl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Yl=e=>(...t)=>O.asap(()=>e(...t)),Og=Rt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Rt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Rt.origin),Rt.navigator&&/(msie|trident)/i.test(Rt.navigator.userAgent)):()=>!0,Mg=Rt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.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 Dg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Lg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Xl(e,t,n){let r=!Dg(t);return e&&(r||n==!1)?Lg(e,t):t}const Jl=e=>e instanceof Bt?{...e}:e;function ar(e,t){t=t||{};const n={};function r(c,d,f,h){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:h},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,h){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f 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,f)=>o(Jl(c),Jl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);O.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Zl=e=>{const t=ar({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Bt.from(i),t.url=Bl(Xl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(Rt.hasStandardBrowserEnv||Rt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Rt.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&Og(t.url))){const l=o&&s&&Mg.read(s);l&&i.set(o,l)}return t},Fg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Zl(e);let s=o.data;const i=Bt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,g;function y(){p&&p(),g&&g(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let v=new XMLHttpRequest;v.open(o.method.toUpperCase(),o.url,!0),v.timeout=o.timeout;function x(){if(!v)return;const S=Bt.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:S,config:e,request:v};Kl(function(E){n(E),y()},function(E){r(E),y()},k),v=null}"onloadend"in v?v.onloadend=x:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(x)},v.onabort=function(){v&&(r(new Re("Request aborted",Re.ECONNABORTED,e,v)),v=null)},v.onerror=function(T){const k=T&&T.message?T.message:"Network Error",C=new Re(k,Re.ERR_NETWORK,e,v);C.event=T||null,r(C),v=null},v.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||Ul;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new Re(T,k.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,v)),v=null},s===void 0&&i.setContentType(null),"setRequestHeader"in v&&O.forEach(i.toJSON(),function(T,k){v.setRequestHeader(k,T)}),O.isUndefined(o.withCredentials)||(v.withCredentials=!!o.withCredentials),a&&a!=="json"&&(v.responseType=o.responseType),c&&([h,g]=zo(c,!0),v.addEventListener("progress",h)),l&&v.upload&&([f,p]=zo(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{v&&(r(!S||S.type?new Nr(null,e,v):S),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const w=jg(o.url);if(w&&Rt.protocols.indexOf(w)===-1){r(new Re("Unsupported protocol "+w+":",Re.ERR_BAD_REQUEST,e));return}v.send(s||null)})},$g=(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 Nr(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=()=>O.asap(a),l}},zg=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},Bg=async function*(e,t){for await(const n of Hg(e))yield*zg(n,t)},Hg=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()}},Ql=(e,t,n,r)=>{const o=Bg(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 f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},ec=64*1024,{isFunction:Bo}=O,Ug=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:tc,TextEncoder:nc}=O.global,rc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Wg=e=>{e=O.merge.call({skipUndefined:!0},Ug,e);const{fetch:t,Request:n,Response:r}=e,o=t?Bo(t):typeof fetch=="function",s=Bo(n),i=Bo(r);if(!o)return!1;const a=o&&Bo(tc),l=o&&(typeof nc=="function"?(g=>y=>g.encode(y))(new nc):async g=>new Uint8Array(await new n(g).arrayBuffer())),c=s&&a&&rc(()=>{let g=!1;const y=new n(Rt.origin,{body:new tc,method:"POST",get duplex(){return g=!0,"half"}}).headers.has("Content-Type");return g&&!y}),d=i&&a&&rc(()=>O.isReadableStream(new r("").body)),f={stream:d&&(g=>g.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!f[g]&&(f[g]=(y,v)=>{let x=y&&y[g];if(x)return x.call(y);throw new Re(`Response type '${g}' is not supported`,Re.ERR_NOT_SUPPORT,v)})});const h=async g=>{if(g==null)return 0;if(O.isBlob(g))return g.size;if(O.isSpecCompliantForm(g))return(await new n(Rt.origin,{method:"POST",body:g}).arrayBuffer()).byteLength;if(O.isArrayBufferView(g)||O.isArrayBuffer(g))return g.byteLength;if(O.isURLSearchParams(g)&&(g=g+""),O.isString(g))return(await l(g)).byteLength},p=async(g,y)=>{const v=O.toFiniteNumber(g.getContentLength());return v??h(y)};return async g=>{let{url:y,method:v,data:x,signal:w,cancelToken:S,timeout:T,onDownloadProgress:k,onUploadProgress:C,responseType:E,headers:_,withCredentials:j="same-origin",fetchOptions:D}=Zl(g),F=t||fetch;E=E?(E+"").toLowerCase():"text";let K=$g([w,S&&S.toAbortSignal()],T),P=null;const R=K&&K.unsubscribe&&(()=>{K.unsubscribe()});let L;try{if(C&&c&&v!=="get"&&v!=="head"&&(L=await p(_,x))!==0){let Q=new n(y,{method:"POST",body:x,duplex:"half"}),le;if(O.isFormData(x)&&(le=Q.headers.get("content-type"))&&_.setContentType(le),Q.body){const[B,ie]=Gl(L,zo(Yl(C)));x=Ql(Q.body,ec,B,ie)}}O.isString(j)||(j=j?"include":"omit");const U=s&&"credentials"in n.prototype,te={...D,signal:K,method:v.toUpperCase(),headers:_.normalize().toJSON(),body:x,duplex:"half",credentials:U?j:void 0};P=s&&new n(y,te);let V=await(s?F(P,D):F(y,te));const z=d&&(E==="stream"||E==="response");if(d&&(k||z&&R)){const Q={};["status","statusText","headers"].forEach(Ce=>{Q[Ce]=V[Ce]});const le=O.toFiniteNumber(V.headers.get("content-length")),[B,ie]=k&&Gl(le,zo(Yl(k),!0))||[];V=new r(Ql(V.body,ec,B,()=>{ie&&ie(),R&&R()}),Q)}E=E||"text";let G=await f[O.findKey(f,E)||"text"](V,g);return!z&&R&&R(),await new Promise((Q,le)=>{Kl(Q,le,{data:G,headers:Bt.from(V.headers),status:V.status,statusText:V.statusText,config:g,request:P})})}catch(U){throw R&&R(),U&&U.name==="TypeError"&&/Load failed|fetch/i.test(U.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,g,P),{cause:U.cause||U}):Re.from(U,U&&U.code,g,P)}}},Vg=new Map,oc=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=Vg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:Wg(t)),d=c;return c};oc();const Ci={http:hg,xhr:Fg,fetch:{get:oc}};O.forEach(Ci,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const sc=e=>`- ${e}`,qg=e=>O.isFunction(e)||e===null||e===!1,ic={getAdapter:(e,t)=>{e=O.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,!qg(r)&&(o=Ci[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(O.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(sc).join(`
|
|
34
|
-
`):" "+sc(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:
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=ar(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Uo.assertOptions(r,{silentJSONParsing:bn.transitional(bn.boolean),forcedJSONParsing:bn.transitional(bn.boolean),clarifyTimeoutError:bn.transitional(bn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:Uo.assertOptions(o,{encode:bn.function,serialize:bn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Uo.assertOptions(n,{baseUrl:bn.spelling("baseURL"),withXsrfToken:bn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=Bt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(y){typeof y.runWhen=="function"&&y.runWhen(n)===!1||(l=l&&y.synchronous,a.unshift(y.fulfilled,y.rejected))});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let d,f=0,h;if(!l){const g=[ac.bind(this),void 0];for(g.unshift(...a),g.push(...c),h=g.length,d=Promise.resolve(n);f<h;)d=d.then(g[f++],g[f++]);return d}h=a.length;let p=n;for(;f<h;){const g=a[f++],y=a[f++];try{p=g(p)}catch(v){y.call(this,v);break}}try{d=ac.call(this,p)}catch(g){return Promise.reject(g)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=ar(this.defaults,t);const n=Xl(t.baseURL,t.url,t.allowAbsoluteUrls);return Bl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){lr.prototype[t]=function(n,r){return this.request(ar(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(ar(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}lr.prototype[t]=n(),lr.prototype[t+"Form"]=n(!0)});let Gg=class km{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 Nr(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 km(function(o){t=o}),cancel:t}}};function Yg(e){return function(n){return e.apply(null,n)}}function Xg(e){return O.isObject(e)&&e.isAxiosError===!0}const ki={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(ki).forEach(([e,t])=>{ki[t]=e});function uc(e){const t=new lr(e),n=El(lr.prototype.request,t);return O.extend(n,lr.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return uc(ar(e,o))},n}const pt=uc(Jr);pt.Axios=lr,pt.CanceledError=Nr,pt.CancelToken=Gg,pt.isCancel=ql,pt.VERSION=lc,pt.toFormData=Fo,pt.AxiosError=Re,pt.Cancel=pt.CanceledError,pt.all=function(t){return Promise.all(t)},pt.spread=Yg,pt.isAxiosError=Xg,pt.mergeConfig=ar,pt.AxiosHeaders=Bt,pt.formToJSON=e=>Wl(O.isHTMLForm(e)?new FormData(e):e),pt.getAdapter=ic.getAdapter,pt.HttpStatusCode=ki,pt.default=pt;const{Axios:Jk,AxiosError:Zk,CanceledError:Qk,isCancel:eT,CancelToken:tT,VERSION:nT,all:rT,Cancel:oT,isAxiosError:sT,spread:iT,toFormData:aT,AxiosHeaders:lT,HttpStatusCode:cT,formToJSON:uT,getAdapter:dT,mergeConfig:fT}=pt,dc=typeof window<"u"?window.__API_BASE_URL__:void 0,fc=dc?$n(dc):void 0;function $n(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 Ti=new Set;function hc(){return Wo}function Ei(e){Wo=e,Ti.forEach(t=>t(e))}function pc(e){return Ti.add(e),()=>Ti.delete(e)}const Zt=pt.create({...fc?{baseURL:fc}:{},timeout:3e4,withCredentials:!0});Zt.interceptors.request.use(e=>(Wo&&(e.headers.Authorization=`Bearer ${Wo}`),e)),Zt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function cn(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ii(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function mc(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function gc(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function un(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class xc{get baseUrl(){const t=Zt.defaults.baseURL;return t?$n(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=$n(String(t.baseUrl))),t.authToken!==void 0&&Ei(t.authToken)}getAuthToken(){return hc()}setAuthToken(t){Ei(t)}onTokenChange(t){return pc(t)}async listThreads(){const t=await cn("/threads"),n=un(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ii("/threads",t?{title:t}:void 0);return un(r)}async updateThread(t,n){const r=await mc(`/threads/${t}`,{title:n});return un(r)}async deleteThread(t){const n=await gc(`/threads/${t}`);return un(n)}async threadInfo(t){const n=await cn(`/threads/${t}/info`);return un(n)}async listAgents(){const t=await cn("/agents"),n=un(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await cn(`/agents/${t}`);return un(n)}async getAgentSchema(t){const n=await cn(`/agents/${t}/schema`);return un(n)}async getState(t){const n=await cn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return un(n)}async getStateHistory(t){const n=await cn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return un(n)}async cancelRun(t){const n=await Ii("/runs/cancel",{threadId:t});return un(n)}}const Wn=new xc,yc=b.createContext(null);function Jg({children:e,apiConfig:t}){const n=Wn;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(yc.Provider,{value:r,children:e})}function Ai(){const e=b.useContext(yc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Zg(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 Qg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Zg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const ex={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ni(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Qr(e,t){return`${e??""}::${t??""}`}function _i(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Ni(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=nx(t),i=vc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function vc(e,t){if(!Ni(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(j=>!!j&&typeof j=="object").map(j=>({...j})):a===null?null:void 0,c=r.map((j,D)=>cx(j,D)).filter(j=>!!j),d=Ht(e.config),f=Ht(d==null?void 0:d.configurable),h=dt(f,["checkpoint_id","checkpointId"]),p=dt(f,["checkpoint_ns","checkpointNs"]),g=Ht(e==null?void 0:e.parentConfig),y=Ht(g==null?void 0:g.configurable),v=dt(y,["checkpoint_id","checkpointId"])??null,x=dt(y,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=Ht(e==null?void 0:e.metadata),C=dt(k,["branch_label","branchLabel"]),E=dt(y,["checkpoint_id","checkpointId"]),_=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:v,nextCursorNs:x,interrupt:tx(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:g??null,next:_??null,tasks:l??null,values:i??null}}function tx(e,t,n){const r=ax(e,n);return r||ix(t,n)}function nx(e){const t=new Map;e.forEach((o,s)=>{if(!Ni(o))return;const i=vc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Qr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,rx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>bc(s.createdAt??"")-bc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function rx(e,t){return{...e,metadata:Vo(e.metadata,t.metadata)??null,config:Vo(e.config,t.config)??null,parentConfig:Vo(e.parentConfig,t.parentConfig)??null,next:ox(e.next,t.next)??null,tasks:sx(e.tasks,t.tasks)??null,values:Vo(e.values,t.values)??null}}function Vo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function ox(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function sx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function ix(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 ax(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=lx(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=eo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=eo(r.state,`${o}-state`);if(s)return s}}return null}function lx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,g=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",y=Array.isArray(d)?d:void 0,v=h.length?h[h.length-1]:void 0;return{id:p,name:g,interrupts:y,state:v!==void 0?v:f}}const n=Ht(e);if(!n)return null;const r=dt(n,["id","task_id","taskId"])??t,o=dt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function eo(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=wc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=eo(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=eo(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=eo(l,t,n+1,r);if(c)return c}}return null}function wc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=wc(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function bc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function cx(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ht(e)??{},o=Ht(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=ex[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Ht(o.additional_kwargs)??Ht(o.additionalKwargs),d=Ht(o.response_metadata)??Ht(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),h=dt(c,["checkpointId","checkpoint_id"]),p=dt(c,["checkpointNs","checkpoint_ns"]),g=ux(o.content),y={id:l,role:i,content:g};f&&(y.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(y.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(y.model=String(d.model_name)),!y.model&&typeof o.model=="string"&&(y.model=o.model),h&&(y.checkpointId=h),p&&(y.checkpointNs=p);const v=mx(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),x=d?{...d}:void 0;v&&Object.keys(v).length&&(y.additionalKwargs=v),x&&Object.keys(x).length&&(y.responseMetadata=x);const w=dx((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(y.content=[...y.content,...w]),i==="tool"){const S=fx(o,y.content);S&&(y.content=S)}return y}function ux(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Sc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Sc(e);return t?[t]:[]}return[]}function Sc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=dt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=dt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Cc(t)??null;if(n==="tool_end"){const o=dt(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=dt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Cc(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Ht(e.function),["name"]);if(!n||!r)return null;const o=hx(e.args??e.arguments??((s=Ht(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function dx(e){return Array.isArray(e)?e.map((t,n)=>Cc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function fx(e,t){const n=dt(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?px(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[...t,s]}function hx(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function px(e){try{return JSON.parse(e)}catch{return e}}function Ht(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function mx(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function gx(e){return e.type!=="thread_info"&&e.type!=="token"}const xx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function yx(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:ji(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=ji(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),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=ji(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Tc(o,s),e):e}case"interrupt_response":return{...e,messages:Ic(e.messages),pendingInterrupt:null};default:return e}}function kc(e=[]){const[t,n]=b.useReducer(yx,{...xx,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,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Tc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=kx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const c={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,c]}}if(t.type==="message_delta"){const i=e.assemblingId??Ac(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Nc(c.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:g,changed:y}=Sx(c.content,t.delta,f,h);if(!y)return e;const v={...c,content:p},x=Ec(a,l,v),w={...d,[i]:g};return{...e,messages:x,messagesStreamMeta:w}}if(t.type==="message_end"){const i=e.assemblingId??Ac(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(c=>c.id===i&&c.role==="assistant");if(l>=0){const c=a[l];if(!((n=c.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=c.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 f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,c={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[c]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},c=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=c?wx(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Cx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="state_history"){const i=_i(t),a=i.interrupt,l=i.latest,c=a===null?Ic(e.messages):e.messages;return{...e,messages:c,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return e}function ji(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function Ec(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Ic(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 Ac(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function vx(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function wx(e,t,n){return vx(e,t,r=>({...r,content:bx(r.content,n)}))}function bx(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const c=i(s),d=i(l);if(c.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(c.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(c)&&c.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=jc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Nc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Sx(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(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Nc(e);let l="",c=e.slice();if(s){const f=jc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",g={...h,text:p+l};c=[...c.slice(0,c.length-1),g]}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 _c(e){return e.replace(/\s+/g," ").trim()}function jc(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=_c(e),o=_c(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 Cx(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 Ec(e,r,s)}return e}function kx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Rc(e={}){const t=b.useMemo(()=>$n(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),[f,h]=b.useState(""),[p,g]=b.useState(null),[y,v]=b.useState(0),[x,w]=b.useState(!1),S=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),C=b.useRef(null),E=b.useCallback(F=>{o(F)},[]),_=b.useCallback(()=>{h(""),g(null),d(null)},[]),j=b.useCallback(()=>{var F;console.debug("[use-chat] stop() invoked - aborting stream"),(F=S.current)==null||F.abort(),S.current=null,C.current=null,l(!1),w(!1),k.current=0,v(0)},[]),D=b.useCallback((F,K,P)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const R=new AbortController;return S.current=R,C.current={threadId:F.threadId??null,headers:{}},(async()=>{var U,te,V,z,G,Q,le,B,ie;const L=Ce=>{var ke;try{const q=JSON.parse(JSON.stringify(Ce));return(ke=q==null?void 0:q.payload)!=null&&ke.files_info&&Array.isArray(q.payload.files_info)&&(q.payload.files_info=q.payload.files_info.map(M=>({...M,data:M!=null&&M.data?`<base64 ${String(M.data).length} chars>`:M==null?void 0:M.data}))),q}catch{return Ce}};try{let Ce={};try{if(r)Ce={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const it=window.__AUTH_TOKEN__,gt=((U=window.localStorage)==null?void 0:U.getItem("authToken"))||null;let re=null;try{const we=(te=window.localStorage)==null?void 0:te.getItem("chat-settings");we&&(re=((V=JSON.parse(we))==null?void 0:V.apiKey)||null)}catch{}const ve=it||gt||re||null;ve&&(Ce={Authorization:`Bearer ${ve}`})}}catch{}console.debug("[use-chat] POST",t+n,L(F));let ke={};if(typeof window<"u")try{const We=(z=window.localStorage)==null?void 0:z.getItem("authSessionId");We&&(ke={"X-Session-Id":We})}catch{}const q={...Ce,...ke,...s.current},M={"Content-Type":"application/json",Accept:"text/event-stream",...q},X=await fetch(t+n,{method:"POST",headers:M,body:JSON.stringify(F),signal:R.signal,credentials:i});if(C.current&&(C.current.headers=q),!X.ok||!X.body){const We=await X.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",X.status,We==null?void 0:We.slice(0,500)),new Error(`stream ${X.status}${We?": "+We:""}`)}w(!0);const ne=X.body.getReader(),xe=new TextDecoder;let se="",ae=[];k.current=0,v(0);let Ue=0,Ke=null;const ot=()=>{if(ae.length){const We=ae.join("");ae=[],T.current&&h(it=>it+We)}Ke=null},st=()=>{typeof window<"u"&&Ke==null&&(Ke=requestAnimationFrame(ot))};let ut=Date.now();const et=setInterval(()=>{var We;if(Date.now()-ut>6e4){const it="Stream idle timeout";d(it),R.abort(),(We=P==null?void 0:P.onError)==null||We.call(P,it)}},5e3),De=1024*1024;try{const We=X.headers.get("X-Thread-Id")||X.headers.get("x-thread-id"),it=X.headers.get("X-Thread-Created")||X.headers.get("x-thread-created"),gt=We??null,re=String(it??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:gt}),(G=P==null?void 0:P.onOpen)==null||G.call(P,{threadId:gt,created:re});;){const{value:ve,done:we}=await ne.read();if(we)break;se+=xe.decode(ve,{stream:!0}),se.length>De&&(se="",console.warn("Stream buffer reset: exceeded 1MB"));let Ye;for(;(Ye=se.indexOf(`
|
|
34
|
+
`):" "+sc(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:Ci};function ki(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Nr(null,e)}function ac(e){return ki(e),e.headers=Bt.from(e.headers),e.data=Si.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),ic.getAdapter(e.adapter||Jr.adapter,e)(e).then(function(r){return ki(e),r.data=Si.call(e,e.transformResponse,r),r.headers=Bt.from(r.headers),r},function(r){return ql(r)||(ki(e),r&&r.response&&(r.response.data=Si.call(e,e.transformResponse,r.response),r.response.headers=Bt.from(r.response.headers))),Promise.reject(r)})}const lc="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 cc={};Ho.transitional=function(t,n,r){function o(s,i){return"[Axios v"+lc+"] 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&&!cc[i]&&(cc[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 Kg(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:Kg,validators:Ho},bn=Uo.validators;let lr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Hl,response:new Hl}}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=ar(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Uo.assertOptions(r,{silentJSONParsing:bn.transitional(bn.boolean),forcedJSONParsing:bn.transitional(bn.boolean),clarifyTimeoutError:bn.transitional(bn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:Uo.assertOptions(o,{encode:bn.function,serialize:bn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Uo.assertOptions(n,{baseUrl:bn.spelling("baseURL"),withXsrfToken:bn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=Bt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(y){typeof y.runWhen=="function"&&y.runWhen(n)===!1||(l=l&&y.synchronous,a.unshift(y.fulfilled,y.rejected))});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let d,f=0,h;if(!l){const g=[ac.bind(this),void 0];for(g.unshift(...a),g.push(...c),h=g.length,d=Promise.resolve(n);f<h;)d=d.then(g[f++],g[f++]);return d}h=a.length;let p=n;for(;f<h;){const g=a[f++],y=a[f++];try{p=g(p)}catch(v){y.call(this,v);break}}try{d=ac.call(this,p)}catch(g){return Promise.reject(g)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=ar(this.defaults,t);const n=Xl(t.baseURL,t.url,t.allowAbsoluteUrls);return Bl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){lr.prototype[t]=function(n,r){return this.request(ar(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(ar(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}lr.prototype[t]=n(),lr.prototype[t+"Form"]=n(!0)});let Gg=class km{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 Nr(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 km(function(o){t=o}),cancel:t}}};function Yg(e){return function(n){return e.apply(null,n)}}function Xg(e){return O.isObject(e)&&e.isAxiosError===!0}const Ti={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(Ti).forEach(([e,t])=>{Ti[t]=e});function uc(e){const t=new lr(e),n=El(lr.prototype.request,t);return O.extend(n,lr.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return uc(ar(e,o))},n}const pt=uc(Jr);pt.Axios=lr,pt.CanceledError=Nr,pt.CancelToken=Gg,pt.isCancel=ql,pt.VERSION=lc,pt.toFormData=Fo,pt.AxiosError=Re,pt.Cancel=pt.CanceledError,pt.all=function(t){return Promise.all(t)},pt.spread=Yg,pt.isAxiosError=Xg,pt.mergeConfig=ar,pt.AxiosHeaders=Bt,pt.formToJSON=e=>Wl(O.isHTMLForm(e)?new FormData(e):e),pt.getAdapter=ic.getAdapter,pt.HttpStatusCode=Ti,pt.default=pt;const{Axios:Jk,AxiosError:Zk,CanceledError:Qk,isCancel:eT,CancelToken:tT,VERSION:nT,all:rT,Cancel:oT,isAxiosError:sT,spread:iT,toFormData:aT,AxiosHeaders:lT,HttpStatusCode:cT,formToJSON:uT,getAdapter:dT,mergeConfig:fT}=pt,dc=typeof window<"u"?window.__API_BASE_URL__:void 0,fc=dc?$n(dc):void 0;function $n(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 Ei=new Set;function hc(){return Wo}function Ii(e){Wo=e,Ei.forEach(t=>t(e))}function pc(e){return Ei.add(e),()=>Ei.delete(e)}const Zt=pt.create({...fc?{baseURL:fc}:{},timeout:3e4,withCredentials:!0});Zt.interceptors.request.use(e=>(Wo&&(e.headers.Authorization=`Bearer ${Wo}`),e)),Zt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function cn(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ai(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function mc(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function gc(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function un(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class xc{get baseUrl(){const t=Zt.defaults.baseURL;return t?$n(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=$n(String(t.baseUrl))),t.authToken!==void 0&&Ii(t.authToken)}getAuthToken(){return hc()}setAuthToken(t){Ii(t)}onTokenChange(t){return pc(t)}async listThreads(){const t=await cn("/threads"),n=un(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ai("/threads",t?{title:t}:void 0);return un(r)}async updateThread(t,n){const r=await mc(`/threads/${t}`,{title:n});return un(r)}async deleteThread(t){const n=await gc(`/threads/${t}`);return un(n)}async threadInfo(t){const n=await cn(`/threads/${t}/info`);return un(n)}async listAgents(){const t=await cn("/agents"),n=un(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await cn(`/agents/${t}`);return un(n)}async getAgentSchema(t){const n=await cn(`/agents/${t}/schema`);return un(n)}async getState(t){const n=await cn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return un(n)}async getStateHistory(t){const n=await cn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return un(n)}async cancelRun(t){const n=await Ai("/runs/cancel",{threadId:t});return un(n)}}const Wn=new xc,yc=b.createContext(null);function Jg({children:e,apiConfig:t}){const n=Wn;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(yc.Provider,{value:r,children:e})}function Ni(){const e=b.useContext(yc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Zg(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 Qg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await Zg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const ex={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function _i(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Qr(e,t){return`${e??""}::${t??""}`}function ji(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!_i(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=nx(t),i=vc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function vc(e,t){if(!_i(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(j=>!!j&&typeof j=="object").map(j=>({...j})):a===null?null:void 0,c=r.map((j,D)=>cx(j,D)).filter(j=>!!j),d=Ht(e.config),f=Ht(d==null?void 0:d.configurable),h=dt(f,["checkpoint_id","checkpointId"]),p=dt(f,["checkpoint_ns","checkpointNs"]),g=Ht(e==null?void 0:e.parentConfig),y=Ht(g==null?void 0:g.configurable),v=dt(y,["checkpoint_id","checkpointId"])??null,x=dt(y,["checkpoint_ns","checkpointNs"])??null,w=e==null?void 0:e.createdAt,S=typeof w=="string"&&w.trim()?w:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=Ht(e==null?void 0:e.metadata),C=dt(k,["branch_label","branchLabel"]),E=dt(y,["checkpoint_id","checkpointId"]),_=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:v,nextCursorNs:x,interrupt:tx(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:g??null,next:_??null,tasks:l??null,values:i??null}}function tx(e,t,n){const r=ax(e,n);return r||ix(t,n)}function nx(e){const t=new Map;e.forEach((o,s)=>{if(!_i(o))return;const i=vc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Qr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,rx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>bc(s.createdAt??"")-bc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function rx(e,t){return{...e,metadata:Vo(e.metadata,t.metadata)??null,config:Vo(e.config,t.config)??null,parentConfig:Vo(e.parentConfig,t.parentConfig)??null,next:ox(e.next,t.next)??null,tasks:sx(e.tasks,t.tasks)??null,values:Vo(e.values,t.values)??null}}function Vo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function ox(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function sx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function ix(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 ax(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=lx(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=eo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=eo(r.state,`${o}-state`);if(s)return s}}return null}function lx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,g=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",y=Array.isArray(d)?d:void 0,v=h.length?h[h.length-1]:void 0;return{id:p,name:g,interrupts:y,state:v!==void 0?v:f}}const n=Ht(e);if(!n)return null;const r=dt(n,["id","task_id","taskId"])??t,o=dt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function eo(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=wc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=eo(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=eo(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=eo(l,t,n+1,r);if(c)return c}}return null}function wc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=wc(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function bc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function cx(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ht(e)??{},o=Ht(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=ex[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Ht(o.additional_kwargs)??Ht(o.additionalKwargs),d=Ht(o.response_metadata)??Ht(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),h=dt(c,["checkpointId","checkpoint_id"]),p=dt(c,["checkpointNs","checkpoint_ns"]),g=ux(o.content),y={id:l,role:i,content:g};f&&(y.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(y.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(y.model=String(d.model_name)),!y.model&&typeof o.model=="string"&&(y.model=o.model),h&&(y.checkpointId=h),p&&(y.checkpointNs=p);const v=mx(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),x=d?{...d}:void 0;v&&Object.keys(v).length&&(y.additionalKwargs=v),x&&Object.keys(x).length&&(y.responseMetadata=x);const w=dx((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(y.content=[...y.content,...w]),i==="tool"){const S=fx(o,y.content);S&&(y.content=S)}return y}function ux(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Sc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Sc(e);return t?[t]:[]}return[]}function Sc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=dt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=dt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Cc(t)??null;if(n==="tool_end"){const o=dt(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=dt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Cc(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Ht(e.function),["name"]);if(!n||!r)return null;const o=hx(e.args??e.arguments??((s=Ht(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function dx(e){return Array.isArray(e)?e.map((t,n)=>Cc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function fx(e,t){const n=dt(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?px(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[...t,s]}function hx(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function px(e){try{return JSON.parse(e)}catch{return e}}function Ht(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function mx(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function gx(e){return e.type!=="thread_info"&&e.type!=="token"}const xx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function yx(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ri(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),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),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ri(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Tc(o,s),e):e}case"interrupt_response":return{...e,messages:Ic(e.messages),pendingInterrupt:null};default:return e}}function kc(e=[]){const[t,n]=b.useReducer(yx,{...xx,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,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Tc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=kx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const c={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,c]}}if(t.type==="message_delta"){const i=e.assemblingId??Ac(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Nc(c.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:g,changed:y}=Sx(c.content,t.delta,f,h);if(!y)return e;const v={...c,content:p},x=Ec(a,l,v),w={...d,[i]:g};return{...e,messages:x,messagesStreamMeta:w}}if(t.type==="message_end"){const i=e.assemblingId??Ac(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(c=>c.id===i&&c.role==="assistant");if(l>=0){const c=a[l];if(!((n=c.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=c.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 f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,c={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[c]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},c=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=c?wx(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Cx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="state_history"){const i=ji(t),a=i.interrupt,l=i.latest,c=a===null?Ic(e.messages):e.messages;return{...e,messages:c,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return e}function Ri(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function Ec(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Ic(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 Ac(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function vx(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function wx(e,t,n){return vx(e,t,r=>({...r,content:bx(r.content,n)}))}function bx(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const c=i(s),d=i(l);if(c.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(c.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(c)&&c.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=jc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Nc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Sx(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(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Nc(e);let l="",c=e.slice();if(s){const f=jc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",g={...h,text:p+l};c=[...c.slice(0,c.length-1),g]}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 _c(e){return e.replace(/\s+/g," ").trim()}function jc(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=_c(e),o=_c(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 Cx(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 Ec(e,r,s)}return e}function kx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Rc(e={}){const t=b.useMemo(()=>$n(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),[f,h]=b.useState(""),[p,g]=b.useState(null),[y,v]=b.useState(0),[x,w]=b.useState(!1),S=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),C=b.useRef(null),E=b.useCallback(F=>{o(F)},[]),_=b.useCallback(()=>{h(""),g(null),d(null)},[]),j=b.useCallback(()=>{var F;console.debug("[use-chat] stop() invoked - aborting stream"),(F=S.current)==null||F.abort(),S.current=null,C.current=null,l(!1),w(!1),k.current=0,v(0)},[]),D=b.useCallback((F,K,P)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const R=new AbortController;return S.current=R,C.current={threadId:F.threadId??null,headers:{}},(async()=>{var U,te,V,z,G,Q,le,B,ie;const L=Ce=>{var ke;try{const q=JSON.parse(JSON.stringify(Ce));return(ke=q==null?void 0:q.payload)!=null&&ke.files_info&&Array.isArray(q.payload.files_info)&&(q.payload.files_info=q.payload.files_info.map(M=>({...M,data:M!=null&&M.data?`<base64 ${String(M.data).length} chars>`:M==null?void 0:M.data}))),q}catch{return Ce}};try{let Ce={};try{if(r)Ce={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const it=window.__AUTH_TOKEN__,gt=((U=window.localStorage)==null?void 0:U.getItem("authToken"))||null;let re=null;try{const we=(te=window.localStorage)==null?void 0:te.getItem("chat-settings");we&&(re=((V=JSON.parse(we))==null?void 0:V.apiKey)||null)}catch{}const ve=it||gt||re||null;ve&&(Ce={Authorization:`Bearer ${ve}`})}}catch{}console.debug("[use-chat] POST",t+n,L(F));let ke={};if(typeof window<"u")try{const We=(z=window.localStorage)==null?void 0:z.getItem("authSessionId");We&&(ke={"X-Session-Id":We})}catch{}const q={...Ce,...ke,...s.current},M={"Content-Type":"application/json",Accept:"text/event-stream",...q},X=await fetch(t+n,{method:"POST",headers:M,body:JSON.stringify(F),signal:R.signal,credentials:i});if(C.current&&(C.current.headers=q),!X.ok||!X.body){const We=await X.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",X.status,We==null?void 0:We.slice(0,500)),new Error(`stream ${X.status}${We?": "+We:""}`)}w(!0);const ne=X.body.getReader(),xe=new TextDecoder;let se="",ae=[];k.current=0,v(0);let Ue=0,Ke=null;const ot=()=>{if(ae.length){const We=ae.join("");ae=[],T.current&&h(it=>it+We)}Ke=null},st=()=>{typeof window<"u"&&Ke==null&&(Ke=requestAnimationFrame(ot))};let ut=Date.now();const et=setInterval(()=>{var We;if(Date.now()-ut>6e4){const it="Stream idle timeout";d(it),R.abort(),(We=P==null?void 0:P.onError)==null||We.call(P,it)}},5e3),De=1024*1024;try{const We=X.headers.get("X-Thread-Id")||X.headers.get("x-thread-id"),it=X.headers.get("X-Thread-Created")||X.headers.get("x-thread-created"),gt=We??null,re=String(it??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:gt}),(G=P==null?void 0:P.onOpen)==null||G.call(P,{threadId:gt,created:re});;){const{value:ve,done:we}=await ne.read();if(we)break;se+=xe.decode(ve,{stream:!0}),se.length>De&&(se="",console.warn("Stream buffer reset: exceeded 1MB"));let Ye;for(;(Ye=se.indexOf(`
|
|
36
36
|
|
|
37
37
|
`))>=0;){const xt=se.slice(0,Ye);se=se.slice(Ye+2);const ft=Ex(xt);if(!ft)continue;let wt;try{wt=JSON.parse(ft)}catch{console.debug("[use-chat] malformed SSE:",ft.slice(0,200));continue}const Fe=Tx(wt)?wt.data:wt;ut=Date.now();const Ze=Fe.seq;if(Ze!==void 0){if(Ze<=Ue){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ze,lastProcessedSeq:Ue,type:Fe.type});continue}Ue>0&&Ze>Ue+1&&((Q=P==null?void 0:P.onGap)==null||Q.call(P,{from:Ue,to:Ze})),Ue=Ze,k.current=Ze,v(Ze)}console.debug("[use-chat] received event",{seq:Fe.seq,type:Fe.type,preview:(()=>{var Tt;try{return Fe.type==="message_delta"?{deltaTypes:(Tt=Fe.delta)==null?void 0:Tt.map(St=>St.type),textLen:(Fe.delta||[]).filter(St=>St.type==="text").map(St=>String(St.text||"").length)}:Fe.content||Fe.delta?{hasContent:!0}:{}}catch(St){return{err:String(St)}}})()});try{K==null||K(Fe)}catch(Tt){console.error("[use-chat] Error in onEvent callback:",Tt,"for event:",Fe.type)}if(Fe.type==="token"&&e.autoAppendAssistant!==!1)ae.push(Fe.content),st();else if(Fe.type==="message_delta"){const Tt=Fe.delta.filter(St=>St.type==="text").map(St=>St.text).join("");Tt&&e.autoAppendAssistant!==!1&&(ae.push(Tt),st())}else Fe.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(Ke!==null&&cancelAnimationFrame(Ke),ot(),Fe.type==="checkpoint"?g(Fe.checkpointId):Fe.type==="error"&&d(Fe.message))}}ot()}catch(We){if(We.name!=="AbortError"){const it=We.message||String(We);d(it),(le=P==null?void 0:P.onError)==null||le.call(P,it)}}finally{try{await ne.cancel()}catch{}finally{(B=ne.releaseLock)==null||B.call(ne)}Ke!==null&&typeof window<"u"&&window.cancelAnimationFrame(Ke),clearInterval(et),l(!1),w(!1),S.current=null,k.current=0,v(0),C.current=null}}catch(Ce){if(Ce.name!=="AbortError"){const ke=Ce.message||String(Ce);d(ke),(ie=P==null?void 0:P.onError)==null||ie.call(P,ke)}}finally{l(!1),w(!1),S.current=null,k.current=0,v(0),C.current=null}})(),{close:()=>R.abort()}},[t,n,r,e.autoAppendAssistant]);return b.useEffect(()=>()=>{var F;T.current=!1,(F=S.current)==null||F.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:y,connected:x,stream:D,stop:j,clear:_,setToken:E}}function Tx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Ex(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
38
|
-
`)}function Ix({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=b.useRef(null),i=b.useCallback(p=>{const g=p.seq??null;if(g!==null){const y=s.current;if(y!==null){if(g<=y)return;g>y+1&&(o==null||o({from:y,to:g}))}s.current=g}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p);try{t(p)}catch(y){console.error("[useChatStreamingService] Error in onThreadInfo handler:",y)}return}if(gx(p)){try{n(p)}catch(y){console.error("[useChatStreamingService] Error in onMessageEvent handler:",y)}return}try{r==null||r(p)}catch(y){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",y)}},[n,o,t,r]),{stream:a,stop:l,isStreaming:c,error:d,setToken:f}=Rc({baseUrl:e,token:null}),h=b.useCallback((p,g)=>{s.current=null,a(p,i,{onOpen:g==null?void 0:g.onOpen,onError:y=>{var v;(v=g==null?void 0:g.onError)==null||v.call(g,y)},onGap:(g==null?void 0:g.onGap)??o})},[i,o,a]);return b.useMemo(()=>({startStream:h,stop:l,isStreaming:c,error:d,setAuthToken:f}),[h,l,c,d,f])}function Ri(e){return e==null?e:{...e}}function Ax(e){return e==null?e:{...e}}function Nx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function _x(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function Qt(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=Ri(e==null?void 0:e.metadata),s=Ri(e==null?void 0:e.config),i=Ri(e==null?void 0:e.parentConfig),a=Nx(e==null?void 0:e.next),l=_x(e==null?void 0:e.tasks),c=Ax(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),c!==void 0&&(d.values=c),d}function jx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function Pc(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}const qo=300;function Oc(e,t=qo){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function cr(){return typeof window<"u"&&typeof window.localStorage<"u"}function Pi(e){if(!cr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Oi(e,t){if(!cr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Mi(e){if(cr())try{window.localStorage.removeItem(e)}catch{}}const Rx="cachedThreads",Px="v1",Di=200;function Ox(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Li(e,t){return`cachedThreads:v1:${e}:${Ox(t||"anon")}`}function Mx(){const e=Pi(Rx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Dx(e){const t=Pi(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function Fi(e,t){Oi(e,JSON.stringify(t))}function $i(e){const t=Dx(e);if(t.length>0)return t;const n=Mx();if(n.length>0)try{Fi(e,n.slice(0,Di))}catch{}return n}function Ko(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function zi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Bi(e,t){return`${e}${t}`}function Lx(e,t){const n=Pi(Bi(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:Qt(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function Fx(e,t,n=100){if(!cr())return;const r=Qt(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=Bi(e,t.threadId),i=JSON.stringify(o);if(!Oi(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const c=window.localStorage.key(l);if(!c||c===s||!c.startsWith(e))continue;const d=window.localStorage.getItem(c);if(!d){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:c,updatedAt:h})}catch{a.push({key:c,updatedAt:0})}}a.sort((l,c)=>l.updatedAt-c.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),Oi(s,i))break}catch{}}function $x(e,t){Mi(Bi(e,t))}function zx(e){if(cr())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}const Mc=b.createContext(null),Dc=b.createContext(null),Lc=b.createContext(null),Bx=b.createContext(!1),Fc=50,Hx=750;function $c(e,t,n){return`${e}__${t??""}__${n??""}`}function Go(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Ux(e,t){return Go(e,t)}function Wx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function Vx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function zc(e,t){const n=Go(e.metadata,t.metadata),r=Go(e.config,t.config),o=Go(e.parentConfig,t.parentConfig),s=Wx(e.next,t.next),i=Vx(e.tasks,t.tasks),a=Ux(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function qx({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:c}=Ai(),d=b.useMemo(()=>$n(c),[c]),f=b.useMemo(()=>{try{return new URL(c).host}catch{return"unknown"}},[c]),h=b.useMemo(()=>`threadPayload:${Px}:${f}:`,[f]),p=b.useCallback(A=>Lx(h,A),[h]),g=b.useCallback((A,N=100)=>{Fx(h,A,N)},[h]),y=b.useCallback(A=>{$x(h,A)},[h]),v=b.useCallback(()=>{zx(h)},[h]),[x,w]=b.useState(()=>{var A;return Li(f,(A=l.getAuthToken)==null?void 0:A.call(l))}),[S,T]=b.useState(()=>{var N;const A=$i(Li(f,(N=l.getAuthToken)==null?void 0:N.call(l)));return Ko(A)}),k=b.useMemo(()=>zi(S),[S]),[C,E]=b.useState(t),[_,j]=b.useState(!1),[D,F]=b.useState(!1),[K,P]=b.useState(null),[R,L]=b.useState(null),[U,te]=b.useState(null),[V,z]=b.useState([]),G=b.useCallback(()=>{const A=$i(x);b.startTransition(()=>{T(Ko(A))})},[x]),[Q,le]=b.useState(!1),[B,ie]=b.useState(!1),[Ce,ke]=b.useState(null),[q,M]=b.useState(void 0),[X,ne]=b.useState(void 0),[xe,se]=b.useState(void 0),{state:ae,dispatch:Ue,seed:Ke,prepend:ot,pushUser:st,onEvent:ut,reset:et}=kc(),De=b.useRef(C);b.useEffect(()=>{De.current=C},[C]);const We=b.useRef(!1),it=b.useRef([]),gt=b.useRef(null),re=b.useRef(null),ve=b.useRef(new Map),we=b.useRef(C),Ye=b.useRef(!1),xt=b.useRef(null),ft=b.useRef(new Map),wt=b.useRef(new Map),Fe=b.useRef(new Map),Ze=b.useRef(new Map),Tt=b.useCallback(A=>{if(!A){z([]);return}const N=ft.current.get(A);if(!N||!N.length){z([]);return}z(N.map(Y=>Qt(Y,{cloneMessages:!0})))},[]);b.useEffect(()=>{Tt(C)},[C,Tt]);const St=b.useCallback(()=>{var ee;const A=Ze.current;if(A.size<=Fc)return;const N=Array.from(A.entries()).sort((ce,Z)=>ce[1].timestamp-Z[1].timestamp),Y=A.size-Fc;for(let ce=0;ce<Y;ce++){const Z=(ee=N[ce])==null?void 0:ee[0];Z&&A.delete(Z)}},[]),Yt=b.useCallback((A,N,Y)=>{if(!A)return;const ee=Y==="replace"?[]:ft.current.get(A)??[],ce=Y==="replace"?N:[...N,...ee];if(!ce.length){Y==="replace"&&ft.current.set(A,[]);return}const Z=new Map;for(const Be of ce){if(!(Be!=null&&Be.checkpointId))continue;const Oe=`${Be.checkpointId}::${Be.checkpointNs??""}`,Qe=Qt(Be,{cloneMessages:!0}),yt=Z.get(Oe);if(!yt){Z.set(Oe,Qe);continue}const Nt=zc(yt,Qe);Z.set(Oe,{...yt,...Nt})}const ze=Array.from(Z.values()).sort((Be,Oe)=>{const Qe=Number.isFinite(Date.parse(Be.createdAt??""))?Date.parse(Be.createdAt??""):0;return(Number.isFinite(Date.parse(Oe.createdAt??""))?Date.parse(Oe.createdAt??""):0)-Qe});ft.current.set(A,ze),A===De.current&&Tt(A)},[Tt]),Et=b.useCallback((A,N,Y)=>{if(!A)return;const ee=wt.current.get(A),ce=Y==="replace"||!ee?new Map:new Map(ee);if(N&&typeof N=="object")for(const[Z,ze]of Object.entries(N)){if(!(ze!=null&&ze.checkpointId))continue;const Be=Z||Qr(ze.checkpointId,ze.checkpointNs??null);ce.set(Be,Qt(ze,{cloneMessages:!0}))}wt.current.set(A,ce)},[]),rr=b.useCallback((A,N)=>{const{threadId:Y,checkpointId:ee=null,checkpointNs:ce=null}=A,Z=$c(Y,ee,ce);if(N!=null&&N.force)Fe.current.delete(Z),Ze.current.delete(Z);else{if(N!=null&&N.preferCache){const Qe=Ze.current.get(Z);if(Qe)return Promise.resolve(Qe.payload)}const Oe=Fe.current.get(Z);if(Oe)return Oe}const Be=l.getStateHistory({threadId:Y,checkpointId:ee??void 0,checkpointNs:ce??void 0}).then(Oe=>(Ze.current.set(Z,{payload:Oe,timestamp:Date.now()}),St(),Oe)).finally(()=>{Fe.current.get(Z)===Be&&Fe.current.delete(Z)});return Fe.current.set(Z,Be),Be},[l,St]),Xt=b.useCallback((A,N)=>new Promise((Y,ee)=>{const ce=async()=>{We.current=!0;try{await A(),Y()}catch(Z){ee(Z)}finally{We.current=!1;const Z=it.current.shift();Z&&Z().catch(()=>{})}};We.current?it.current.push(ce):ce().catch(Z=>{ee(Z)})}),[]),xn=b.useRef(k.length),sn=b.useRef(!1);b.useEffect(()=>{xn.current=k.length},[k.length]),b.useEffect(()=>{const A=ae.pendingInterrupt??jx(ae.messages);Pc(U,A)||te(A??null)},[U,ae.messages,ae.pendingInterrupt]);const Dt=b.useCallback(async()=>{const A=xn.current>0;A||j(!0);try{const N=await l.listThreads();b.startTransition(()=>{T(Y=>{const ee=ze=>ze.map(Be=>`${Be.threadId}:${Be.updatedAt??""}:${Be.messageCount??""}`).join("|"),ce=zi(Y);return ee(ce)===ee(N)||N.length===0&&ce.length>0&&!sn.current?Y:Ko(N)})}),P(null),sn.current||(sn.current=!0)}catch(N){i==null||i(String(N)),console.error("[ChatSessionProvider] Failed to refresh threads:",N),P(String(N))}finally{A||j(!1)}},[l,i]),Pn=b.useRef(!1),yn=b.useRef(null),ht=b.useRef(null),vn=b.useRef(""),On=b.useCallback((A,N)=>{if(!cr())return;ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null);const Y=A.map(ce=>`${ce.threadId}:${ce.updatedAt??""}:${ce.messageCount??""}`).join("|");if(A.length===0){try{Mi(x)}catch{}vn.current="";return}if(Y===vn.current)return;const ee=()=>{try{const ce=A.slice(0,Di);Fi(x,ce),vn.current=Y}catch{}finally{ht.current=null}};if(N!=null&&N.immediate){ee();return}ht.current=window.setTimeout(()=>{Oc(ee)},qo)},[x]),kr=b.useCallback(()=>{On(k,{immediate:!0})},[On,k]),Jt=b.useCallback((A,N,Y,ee)=>{var Sm;const ce=Y??De.current;if(!ce)return;const Z=Qt(A),ze=ce===De.current,Be=(ee==null?void 0:ee.persist)!==!1;if(N==="replace"){if(Be){const It={threadId:ce,snapshot:Qt(A,{cloneMessages:!0})};ve.current.set(ce,It),we.current=ce}if(!ze)return;Ke(Z.messages,{checkpointId:Z.checkpointId??null,checkpointNs:Z.checkpointNs??null,pendingInterrupt:Z.interrupt??null}),te(Z.interrupt??null),ke(Z.nextCursor??null),le(!!Z.nextCursor),M(Z.checkpointId??void 0),ne(Z.checkpointNs??void 0),se(Z.nextCursorNs??void 0);return}const Oe=ve.current.get(ce),Qe=(Oe==null?void 0:Oe.snapshot)??null,yt=Array.isArray(Qe==null?void 0:Qe.messages)?Qe.messages:[],Nt=Qt(Qe),Dn=Array.isArray(A==null?void 0:A.messages)?A.messages:[],_t=new Set,jt=[...Dn,...yt].filter(It=>{const Sl=It==null?void 0:It.id;return Sl?_t.has(Sl)?!1:(_t.add(Sl),!0):!0}),No=zc(Nt,Z),_o={checkpointId:Nt.checkpointId??Z.checkpointId??null,checkpointNs:Nt.checkpointNs??Z.checkpointNs??null,createdAt:Z.createdAt??Nt.createdAt??null,parentId:Z.parentId??Nt.parentId??null,branchLabel:Z.branchLabel??Nt.branchLabel??null,lastMessageId:((Sm=jt[jt.length-1])==null?void 0:Sm.id)??null,messagesLen:jt.length,hasMessages:jt.length>0,messages:jt,nextCursor:Z.nextCursor??Nt.nextCursor??null,nextCursorNs:Z.nextCursorNs??Nt.nextCursorNs??null,interrupt:Nt.interrupt??Z.interrupt??null,...No};if(ve.current.set(ce,{threadId:ce,snapshot:Qt(_o,{cloneMessages:!0})}),!ze)return;Dn.length&&ot(Dn);const Ln=A&&Object.prototype.hasOwnProperty.call(A,"checkpointId")?A.checkpointId:void 0,jo=A&&Object.prototype.hasOwnProperty.call(A,"checkpointNs")?A.checkpointNs:void 0,Fn=A&&Object.prototype.hasOwnProperty.call(A,"nextCursor")?A.nextCursor:void 0,bl=A&&Object.prototype.hasOwnProperty.call(A,"nextCursorNs")?A.nextCursorNs:void 0;ke(It=>Fn!==void 0?Fn??It??null:It??null),le(It=>Fn!==void 0?!!Fn:It),M(It=>Ln!==void 0?Ln??It??void 0:It??void 0),ne(It=>jo!==void 0?jo??It??void 0:It??void 0),se(It=>bl!==void 0?bl??void 0:It)},[ot,Ke,te]),Tr=b.useCallback(A=>{if(A.threadId!=null&&A.threadId!==De.current)return;const N=Qt(A.snapshot,{cloneMessages:!0});Ke(N.messages,{checkpointId:N.checkpointId??null,checkpointNs:N.checkpointNs??null,pendingInterrupt:N.interrupt??null}),te(N.interrupt??null),ke(N.nextCursor??null),le(!!N.nextCursor),M(N.checkpointId??void 0),ne(N.checkpointNs??void 0),se(N.nextCursorNs??void 0),we.current=A.threadId,Tt(A.threadId??De.current??null)},[Ke,te,Tt]),Mn=b.useCallback(A=>{if(!A)return;ve.current.delete(A),y(A),ft.current.delete(A),wt.current.delete(A),A===De.current&&z([]);const N=`${A}__`;for(const Y of Fe.current.keys())Y.startsWith(N)&&Fe.current.delete(Y);for(const Y of Ze.current.keys())Y.startsWith(N)&&Ze.current.delete(Y);we.current===A&&(we.current=null)},[y]),wn=b.useCallback(()=>{const A=De.current;A&&Mn(A),et([]),le(!1),ie(!1),ke(null),M(void 0),ne(void 0),se(void 0)},[Mn,et]),Un=b.useCallback(({from:A,to:N})=>{const Y=De.current;Y&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${A} -> ${N}) for thread ${Y}`)},[]),Er=b.useCallback(A=>{const N=A.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:N,title:A.title,created:A.created,currentThreads:k.length});const Y={threadId:N,title:A.title||`Thread ${N.slice(0,8)}`,createdAt:A.createdAt||new Date().toISOString(),updatedAt:A.updatedAt||new Date().toISOString(),messageCount:A.messageCount||0};De.current!==N&&(!De.current&&ae.messages.length<=1&&(re.current=N),E(N)),b.startTransition(()=>{T(ee=>{const ce=ee.byId[N];return ce?ce.title===Y.title&&ce.updatedAt===Y.updatedAt&&ce.messageCount===Y.messageCount?ee:{byId:{...ee.byId,[N]:Y},order:ee.order}:{byId:{...ee.byId,[N]:Y},order:[N,...ee.order]}})})},[ae.messages.length]),{startStream:Wr,stop:Vr,isStreaming:or,error:I,setAuthToken:H}=Ix({baseUrl:d,onThreadInfo:Er,onMessageEvent:ut,onUnhandledEvent:A=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${A.type}`,A)},onSequenceGap:Un});b.useEffect(()=>{Pn.current=or},[or]),b.useEffect(()=>{if(!cr())return;ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null);const A=k.map(Y=>`${Y.threadId}:${Y.updatedAt??""}:${Y.messageCount??""}`).join("|");if(k.length===0){try{Mi(x)}catch{}vn.current="";return}if(A===vn.current)return;const N=()=>{try{const Y=k.slice(0,Di);Fi(x,Y),vn.current=A}catch{}finally{ht.current=null}};return ht.current=window.setTimeout(()=>{Oc(N),ht.current=null},qo),()=>{ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null)}},[k,On]),b.useEffect(()=>{var ee;const A=l.getAuthToken();H(A);const N=ce=>{const Z=Li(f,ce);xt.current!==Z&&(xt.current=Z,Ye.current=!1),w(Z);const ze=$i(Z);b.startTransition(()=>{T(Ko(ze))}),ce&&!Ye.current&&(Ye.current=!0)};N(A);const Y=(ee=l.onTokenChange)==null?void 0:ee.call(l,ce=>{ce!==A&&(H(ce),v(),Fe.current.clear(),Ze.current.clear(),N(ce))});return()=>{Y==null||Y()}},[l,f,H,v]);const ue=b.useCallback(async A=>{var ee;const N=`Thread ${(ee=crypto.randomUUID)==null?void 0:ee.call(crypto)}`,Y={threadId:N,title:A||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};T(ce=>({byId:{...ce.byId,[N]:Y},order:[N,...ce.order]})),E(N);try{const ce=await l.createThread(A),Z=typeof ce=="string"?ce:ce.threadId;return T(ze=>{const Be=ze.byId[N];if(!Be)return ze;const Oe={...ze.byId};delete Oe[N],Oe[Z]={...Be,threadId:Z};const Qe=ze.order.map(yt=>yt===N?Z:yt);return{byId:Oe,order:Qe}}),E(Z),setTimeout(()=>Dt(),10),P(null),Z}catch(ce){throw T(Z=>{if(!Z.byId[N])return Z;const ze={...Z.byId};delete ze[N];const Be=Z.order.filter(Oe=>Oe!==N);return{byId:ze,order:Be}}),E(null),P(String(ce)),ce}},[l,Dt]),Te=b.useCallback(async A=>{try{await l.deleteThread(A);let N=null;T(Y=>{if(!Y.byId[A])return Y;const ee={...Y.byId};delete ee[A];const ce=Y.order.filter(ze=>ze!==A),Z={byId:ee,order:ce};return N=zi(Z),Z}),N&&On(N,{immediate:!0}),Mn(A),De.current===A&&(re.current=A,E(null),De.current=null,we.current=null,wn()),await Dt(),P(null)}catch(N){throw P(String(N)),N}},[l,wn,Mn,Dt,On]),qe=b.useCallback(async(A,N)=>{try{await l.updateThread(A,N),T(Y=>{const ee=Y.byId[A];return ee?{byId:{...Y.byId,[A]:{...ee,title:N}},order:Y.order}:Y}),P(null)}catch(Y){throw await Dt(),P(String(Y)),Y}},[l,Dt]),$e=b.useCallback(async(A,N,Y,ee=!1)=>{await Xt(async()=>{if(re.current===A&&!ee){re.current=null;return}if(gt.current===A&&!ee)return;E(_t=>_t===A?_t:A),De.current=A;const ze=$c(A,N??null,Y??null),Be=Ze.current.get(ze),Oe=!ee&&!N&&!Y&&Be&&Date.now()-Be.timestamp<Hx,Qe=!ee&&!N&&!Y;let yt=!1;if(Qe){const _t=ve.current.get(A);if(_t)Tr(_t),yt=!0;else{const jt=p(A);jt&&(ve.current.set(A,jt),Tr(jt),yt=!0)}}const Nt=ee||!yt||!!N||!!Y,Dn=async _t=>{_t&&F(!0),gt.current=A;try{const jt=await rr({threadId:A,checkpointId:N,checkpointNs:Y},{force:ee}),{latest:No,checkpoints:_o,snapshots:Ln}=_i(jt);Jt(No,"replace",A),Yt(A,_o,"replace"),Et(A,Ln,"replace"),L(null)}catch(jt){throw(!yt||ee||_t)&&(i==null||i(String(jt))),L(String(jt)),jt}finally{gt.current=null,_t&&F(!1)}};Nt?await Dn(!0):Qe&&yt&&!Oe&&Dn(!1).catch(_t=>{console.warn("[ChatSessionProvider] Background refresh failed:",_t)})},`loadThread-${A}`)},[Tr,Jt,Xt,rr,i,Yt,Et]),Le=b.useCallback(async()=>{await Xt(async()=>{const A=De.current;A&&Mn(A),re.current=null,E(null),De.current=null,we.current=null,wn(),M(void 0),ne(void 0),se(void 0),z([]);try{localStorage.removeItem("lastThreadId")}catch(N){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",N)}},"clearCurrentThread")},[wn,Mn,Xt]),$=b.useCallback(async(A,N)=>{var Z;const Y=De.current;if(!Y)throw new Error("No active thread");const ee=Qr(A,N??null),ce=(Z=wt.current.get(Y))==null?void 0:Z.get(ee);if(ce){await Xt(async()=>{Jt(ce,"replace",Y,{persist:!1})},`navigateToCheckpoint-${Y}-${ee}`);return}await $e(Y,A,N??void 0,!0)},[Jt,Xt,$e]),de=b.useCallback(async()=>{if(!De.current)throw new Error("No active thread");await $e(De.current,void 0,void 0,!0)},[$e]),he=b.useCallback(async()=>{if(!De.current)throw new Error("No active thread");if(B||!Q)return;const A=Ce;if(A){ie(!0);try{const N=De.current,Y=await rr({threadId:N,checkpointId:A??q??null,checkpointNs:xe??X??null}),{latest:ee,checkpoints:ce,snapshots:Z}=_i(Y),ze=N?wt.current.get(N):null;let Be=ce.length>0;if(Be&&ze&&ze.size>0&&(Be=ce.some(Oe=>{if(!(Oe!=null&&Oe.checkpointId))return!1;const Qe=Qr(Oe.checkpointId,Oe.checkpointNs??null);return!ze.has(Qe)})),!Be){ke(null),se(void 0),le(!1),L(null);return}Jt(ee,"prepend",N??void 0),N&&(Yt(N,ce,"prepend"),Et(N,Z,"prepend")),L(null)}catch(N){throw L(String(N)),N}finally{ie(!1)}}},[Jt,rr,Q,q,X,xe,Ce,B,Yt,Et]),Ie=b.useCallback(A=>{if(A!=null&&A.threadId){if(A.checkpointId){const N=Qr(A.checkpointId,A.checkpointNs??null),Y=Qt({...A,interrupt:A.interrupt??null},{cloneMessages:!0});Et(A.threadId,{[N]:Y},"prepend")}Jt(A,"replace",A.threadId)}},[Jt,Et]),tt=b.useCallback(async(A,N)=>{var jo;const Y=De.current,ee=(A==null?void 0:A.text)??"",ce=(A==null?void 0:A.attachments)??[],Z=ce.length?ce:(N==null?void 0:N.attachments)??[],ze={...(N==null?void 0:N.payloadExtras)??{},...(A==null?void 0:A.payload)??{}};if(!Y&&!Object.keys(ze).length&&Z.length===0&&!ee.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!Y&&!ze.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Be,filesInfo:Oe}=await Qg(l,Z),Qe=[...Be];ee&&ee.trim()&&Qe.push({type:"text",text:ee.trim()});const yt=!!Y,Nt=yt?(N==null?void 0:N.checkpointId)??ae.lastCheckpointId??void 0:void 0,Dn=yt?(N==null?void 0:N.checkpointNs)??ae.lastCheckpointNs??void 0:void 0,_t={id:((jo=crypto.randomUUID)==null?void 0:jo.call(crypto))||`user-${Date.now()}`,role:"user",content:Qe,createdAt:new Date().toISOString(),...Nt!=null?{checkpointId:Nt}:{},...Dn!=null?{checkpointNs:Dn}:{}};Qe.length>0&&st(_t);const jt={..._t,content:Qe},No=Z.length>0,_o={messages:Qe.length>0?[jt]:[],files_info:Oe,...o&&No&&s?{active_agent:s}:{},...ze},Ln={threadId:Y??null,payload:_o,checkpointId:Nt??null,checkpointNs:Dn??null,nodeFilter:(N==null?void 0:N.nodeFilter)??null,config:N==null?void 0:N.config,command:(N==null?void 0:N.command)??null};Ln.threadId||delete Ln.threadId,Ln.command||delete Ln.command,Wr(Ln,{onError:Fn=>{console.warn("[ChatSessionProvider] Stream error:",Fn)},onOpen:({threadId:Fn})=>{!De.current&&Fn&&(ae.messages.length<=1&&(re.current=Fn),E(Fn))},onGap:Un})},[l,o,s,Un,ae.lastCheckpointId,ae.lastCheckpointNs,ae.messages.length,st,Wr]),Lt=b.useCallback(async(A,N,Y)=>{if(!De.current)throw new Error("No active thread to handle interrupt");const ce=N?Y??!0:!1;try{try{Ue({type:"interrupt_response",payload:{interruptId:A}})}catch(Z){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Z)}await tt({payload:{}},{checkpointId:ae.lastCheckpointId??void 0,checkpointNs:ae.lastCheckpointNs??void 0,command:{kind:"resume",value:ce}}),te(null)}catch(Z){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${A}:`,Z),Z}},[Ue,ae.lastCheckpointId,ae.lastCheckpointNs,tt]);b.useEffect(()=>{if(a==null||a(C),C)try{localStorage.setItem("lastThreadId",C)}catch(A){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",A)}},[C,a]),b.useEffect(()=>((async()=>{try{if(Dt().catch(N=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",N),i==null||i(String(N))}),!r&&!t)try{const N=localStorage.getItem("lastThreadId");N&&(E(N),n&&await $e(N))}catch(N){console.warn("[ChatSessionProvider] Failed to restore last thread:",N)}else t&&n&&await $e(t)}catch(N){console.error("[ChatSessionProvider] Initialization failed:",N),i==null||i(String(N))}})(),()=>{}),[]),b.useEffect(()=>{const A=De.current;if(!A||we.current!==A)return;ae.messages.length&&ae.messages[ae.messages.length-1];const N=Qt({checkpointId:ae.lastCheckpointId??null,checkpointNs:ae.lastCheckpointNs??null,messages:ae.messages.slice(),nextCursor:Ce??null,nextCursorNs:xe??null,interrupt:ae.pendingInterrupt??U??null}),Y=ve.current.get(A),ee=Y==null?void 0:Y.snapshot,ce=!ee||ee.messages.length!==N.messages.length||ee.messages.some((Oe,Qe)=>{var yt;return(Oe==null?void 0:Oe.id)!==((yt=N.messages[Qe])==null?void 0:yt.id)}),Z=((ee==null?void 0:ee.checkpointId)??null)!==N.checkpointId||((ee==null?void 0:ee.checkpointNs)??null)!==N.checkpointNs,ze=((ee==null?void 0:ee.nextCursor)??null)!==N.nextCursor||((ee==null?void 0:ee.nextCursorNs)??null)!==N.nextCursorNs,Be=!Pc((ee==null?void 0:ee.interrupt)??null,N.interrupt??null);if(ce||Z||ze||Be){const Oe={threadId:A,snapshot:N};ve.current.set(A,Oe),yn.current&&window.clearTimeout(yn.current),yn.current=window.setTimeout(()=>{try{g(Oe,100)}catch(Qe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",Qe)}},qo)}},[Ce,xe,ae.lastCheckpointId,ae.lastCheckpointNs,ae.messages,ae.pendingInterrupt,U,g]);const an=b.useMemo(()=>({threads:k,currentThreadId:C,setCurrentThreadId:E,isLoading:_,error:K,actions:{createThread:ue,deleteThread:Te,renameThread:qe,refreshThreads:()=>Dt()},persistThreadsCache:kr,hydrateFromCache:G}),[k,C,_,K,ue,Te,qe,Dt,kr,G,E]),Ct=b.useMemo(()=>{const A=ae.lastBranch??null,N=ae.assemblingId??null,Y=A||N?{branchLabel:(A==null?void 0:A.branchLabel)??null,lastBranch:A,assemblingMessageId:N}:null;return{threadId:C,messages:ae.messages,interrupt:U,checkpoint:{id:ae.lastCheckpointId??null,namespace:ae.lastCheckpointNs??null},checkpoints:V,metadata:Y,isLoading:D,isHistoryLoading:B,error:R,hasMore:Q,loadOlder:he,seedFromSnapshot:Ie,clearState:wn,navigateToCheckpoint:$,returnToLatest:de,loadThread:$e,clearThread:Le,respondToInterrupt:Lt}},[Le,wn,C,U,Q,B,D,he,$e,ae.assemblingId,ae.lastBranch,ae.lastCheckpointId,ae.lastCheckpointNs,ae.messages,$,Lt,de,Ie,R,V]),Ao=b.useMemo(()=>({isStreaming:or,error:I,submit:tt,send:tt,stop:Vr,setAuthToken:H}),[or,I,tt,Vr,H]);return u.jsx(Bx.Provider,{value:!0,children:u.jsx(Lc.Provider,{value:Ao,children:u.jsx(Mc.Provider,{value:an,children:u.jsx(Dc.Provider,{value:Ct,children:e})})})})}function Yo(){const e=b.useContext(Mc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Xo(){const e=b.useContext(Dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Bc(){const e=b.useContext(Lc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Jo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return u.jsx(Jg,{apiConfig:t,children:u.jsx(qx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function oe(...e){return Em.twMerge(Tm.clsx(e))}const Kx=Ro.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Xe=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?sr.Slot:"button";return u.jsx(i,{className:oe(Kx({variant:t,size:n,className:e})),ref:s,...o})});Xe.displayName="Button";const Hc=m.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}));Hc.displayName="Textarea";function Gx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const g=i!==void 0,[y,v]=b.useState(e),x=(g?i:y)??"",[w,S]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{g||(v(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,g]);const E=b.useCallback(()=>{const L=T.current;L&&(L.style.height="auto",L.style.height=`${L.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,x]);const _=b.useCallback((L,{fromUser:U})=>{g||v(L),U&&(a==null||a(L))},[g,a]),j=b.useCallback(async L=>{L&&L.preventDefault();const U=(x??"").trim();if(!U&&!p)return;const te=++k.current;C.current={id:te,shouldClear:!0},S(()=>{var V,z,G;try{const Q=l(U);Q&&typeof Q.then=="function"?Q.then(()=>{var le,B;((le=C.current)==null?void 0:le.id)===te&&C.current.shouldClear&&(g||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((B=C.current)==null?void 0:B.id)===te&&(C.current=null)}).catch(()=>{var le;((le=C.current)==null?void 0:le.id)===te&&(C.current=null)}):(((V=C.current)==null?void 0:V.id)===te&&C.current.shouldClear&&(g||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((z=C.current)==null?void 0:z.id)===te&&(C.current=null))}catch{((G=C.current)==null?void 0:G.id)===te&&(C.current=null)}})},[x,l,p,g,a]),D=b.useCallback(L=>{const U=L.target.value;_(U,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[_]),F=b.useCallback(L=>{L.key==="Enter"&&!L.shiftKey?(L.preventDefault(),j()):L.key==="Escape"&&t&&(L.preventDefault(),c==null||c())},[j,t,c]),R=`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))]":""} ${h}`;return u.jsx("form",{onSubmit:L=>void j(L),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(Hc,{ref:T,value:x,onChange:D,onKeyDown:F,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Xe,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(me.Square,{size:16})}):u.jsx(Xe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||w,children:u.jsx(me.Send,{size:16})})})]})})}const Yx=b.memo(Gx),Zo=0,Vn=1,_r=2,Uc=4;function Wc(e){return()=>e}function Xx(e){e()}function Vc(e,t){return n=>e(t(n))}function qc(e,t){return()=>e(t)}function Jx(e,t){return n=>e(t,n)}function Hi(e){return e!==void 0}function Zx(...e){return()=>{e.map(Xx)}}function jr(){}function Qo(e,t){return t(e),e}function Qx(e,t){return t(e)}function at(...e){return e}function Je(e,t){return e(Vn,t)}function Pe(e,t){e(Zo,t)}function Ui(e){e(_r)}function mt(e){return e(Uc)}function ye(e,t){return Je(e,Jx(t,Zo))}function dn(e,t){const n=e(Vn,r=>{n(),t(r)});return n}function Kc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Gc(e,t){return e===t}function lt(e=Gc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function fe(e){return t=>Vc(t,e)}function Sn(e){return t=>()=>{t(e)}}function W(e,...t){const n=ey(...t);return(r,o)=>{switch(r){case _r:Ui(e);return;case Vn:return Je(e,n(o))}}}function Cn(e,t){return n=>r=>{n(t=e(t,r))}}function ur(e){return t=>n=>{e>0?e--:t(n)}}function zn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Me(...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 ey(...e){return t=>e.reduceRight(Qx,t)}function ty(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Vn:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),jr);case _r:r(),n=null;return}}}function J(e){let t=e;const n=Ve();return(r,o)=>{switch(r){case Zo:t=o;break;case Vn:{o(t);break}case Uc:return t}return n(r,o)}}function Pt(e,t){return Qo(J(t),n=>ye(e,n))}function Ve(){const e=[];return(t,n)=>{switch(t){case Zo:e.slice().forEach(r=>{r(n)});return;case _r:e.splice(0,e.length);return;case Vn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Wt(e){return Qo(Ve(),t=>ye(e,t))}function Ge(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:ny(),singleton:n}}const ny=()=>Symbol();function ry(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 vt(...e){const t=Ve(),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&&Pe(t,n)})}),function(s,i){switch(s){case _r:{Ui(t);return}case Vn:return r===o&&i(n),Je(t,i)}}}function Ee(e,t=Gc){return W(e,lt(t))}function Wi(...e){return function(t,n){switch(t){case _r:return;case Vn:return Zx(...e.map(r=>Je(r,n)))}}}var Ut=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ut||{});const oy={0:"debug",3:"error",1:"log",2:"warn"},sy=()=>typeof globalThis>"u"?window:globalThis,qn=Ge(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=sy().VIRTUOSO_LOG_LEVEL)!=null?o:mt(e);r>=s&&console[oy[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function dr(e,t,n){return Vi(e,t,n).callbackRef}function Vi(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 iy(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=ay(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let g;p&&(g=h.ownerDocument.defaultView);const y=i?a?i.scrollLeft:i.scrollTop:p?a?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:p?a?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?g.innerWidth:g.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(y,0),viewportHeight:x}),s==null||s(a?Yc("column-gap",getComputedStyle(d).columnGap,o):Yc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Vi(c,n,l)}function ay(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},Ut.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Yc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ut.WARN),t==="normal"?0:parseInt(t??"0",10)}function Xc(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 f,h;if(t){const p=t.getBoundingClientRect(),g=c.top-p.top;h=p.height-Math.max(0,g),f=g+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Vi(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 Ft=Ge(()=>{const e=Ve(),t=Ve(),n=J(0),r=Ve(),o=J(0),s=Ve(),i=Ve(),a=J(0),l=J(0),c=J(0),d=J(0),f=Ve(),h=Ve(),p=J(!1),g=J(!1),y=J(!1);return ye(W(e,fe(({scrollTop:v})=>v)),t),ye(W(e,fe(({scrollHeight:v})=>v)),i),ye(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:g,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:y,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),to={lvl:0};function Jc(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 nt(e){return e===to}function no(e,t){if(!nt(e))return t===e.k?e.v:t<e.k?no(e.l,t):no(e.r,t)}function fn(e,t,n="k"){if(nt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=fn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return fn(e.l,t,n)}function Vt(e,t,n){return nt(e)?eu(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?tu(bt(e,{l:Vt(e.l,t,n)})):tu(bt(e,{r:Vt(e.r,t,n)}))}function Rr(){return to}function es(e,t,n){if(nt(e))return[];const r=fn(e,t)[0];return ly(Ki(e,r,n))}function qi(e,t){if(nt(e))return to;const{k:n,l:r,r:o}=e;if(t===n){if(nt(r))return o;if(nt(o))return r;{const[s,i]=Qc(r);return ts(bt(e,{k:s,l:Zc(r),v:i}))}}else return t<n?ts(bt(e,{l:qi(r,t)})):ts(bt(e,{r:qi(o,t)}))}function fr(e){return nt(e)?[]:[...fr(e.l),{k:e.k,v:e.v},...fr(e.r)]}function Ki(e,t,n){if(nt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Ki(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Ki(s,t,n))),a}function ts(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(Gi(t))return nu(bt(e,{lvl:n-1}));if(!nt(t)&&!nt(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(Gi(e))return Yi(bt(e,{lvl:n-1}));if(!nt(r)&&!nt(r.l)){const o=r.l,s=Gi(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Yi(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return eu(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 Zc(e){return nt(e.r)?e.l:ts(bt(e,{r:Zc(e.r)}))}function Gi(e){return nt(e)||e.lvl>e.r.lvl}function Qc(e){return nt(e.r)?[e.k,e.v]:Qc(e.r)}function eu(e,t,n,r=to,o=to){return{k:e,l:r,lvl:n,r:o,v:t}}function tu(e){return Yi(nu(e))}function nu(e){const{l:t}=e;return!nt(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function Yi(e){const{lvl:t,r:n}=e;return!nt(n)&&!nt(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function ly(e){return Jc(e,({k:t,v:n})=>({index:t,value:n}))}function ru(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function ro(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Xi=Ge(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function ou(e,t,n){return e[ns(e,t,n)]}function ns(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 cy(e,t,n,r){const o=ns(e,t,r),s=ns(e,n,r,o);return e.slice(o,s+1)}function Kn(e,t){return Math.round(e.getBoundingClientRect()[t])}function rs(e){return!nt(e.groupOffsetTree)}function Ji({index:e},t){return t===e?0:t<e?-1:1}function uy(){return{groupIndices:[],groupOffsetTree:Rr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Rr()}}function dy(e,t){let n=nt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),nt(e)){e=Vt(e,0,s);continue}const a=es(e,i-1,o+1);if(a.some(yy(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=qi(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Vt(e,o+1,h));c&&(e=Vt(e,i,s))}return[e,n]}function fy(e){return typeof e.groupIndex<"u"}function hy({offset:e},t){return t===e?0:t<e?-1:1}function oo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ou(t,e,Ji),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function su(e,t){if(!rs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function iu(e,t,n){if(fy(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=su(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function py(e,t,n,r=0){return r>0&&(t=Math.max(t,ou(e,r,Ji).offset)),Jc(cy(e,t,n,hy),xy)}function my(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ut.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&nt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((g,y)=>Vt(Vt(g,y,h),y+1,p),i)}else[i,a]=dy(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=Zi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Vt(h,p,oo(p,f,o)),Rr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function gy(e){return fr(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 au(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 Zi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ns(o,t-1,Ji),a=o[l].offset;const c=fn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===fn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of es(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function xy(e){return{index:e.index,value:e}}function yy(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 vy={offsetHeight:"height",offsetWidth:"width"},kn=Ge(([{log:e},{recalcInProgress:t}])=>{const n=Ve(),r=Ve(),o=Pt(r,0),s=Ve(),i=Ve(),a=J(0),l=J([]),c=J(void 0),d=J(void 0),f=J((k,C)=>Kn(k,vy[C])),h=J(void 0),p=J(0),g=uy(),y=Pt(W(n,Me(l,e,p),Cn(my,g),lt()),g),v=Pt(W(l,lt(),Cn((k,C)=>({current:C,prev:k.current}),{current:[],prev:[]}),fe(({prev:k})=>k)),[]);ye(W(l,Ae(k=>k.length>0),Me(y,p),fe(([k,C,E])=>{const _=k.reduce((j,D,F)=>Vt(j,D,oo(D,C.offsetTree,E)||F),Rr());return{...C,groupIndices:k,groupOffsetTree:_}})),y),ye(W(r,Me(y),Ae(([k,{lastIndex:C}])=>k<C),fe(([k,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:k}])),n),ye(c,d);const x=Pt(W(c,fe(k=>k===void 0)),!0);ye(W(d,Ae(k=>k!==void 0&&nt(mt(y).sizeTree)),fe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=Wt(W(n,Me(y),Cn(({sizes:k},[C,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:g}),fe(k=>k.changed)));Je(W(a,Cn((k,C)=>({diff:k.prev-C,prev:C}),{diff:0,prev:0}),fe(k=>k.diff)),k=>{const{groupIndices:C}=mt(y);if(k>0)Pe(t,!0),Pe(s,k+au(k,C));else if(k<0){const E=mt(v);E.length>0&&(k-=au(-k,E)),Pe(i,k)}}),Je(W(a,Me(e)),([k,C])=>{k<0&&C("`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},Ut.ERROR)});const S=Wt(s);ye(W(s,Me(y),fe(([k,C])=>{const E=C.groupIndices.length>0,_=[],j=C.lastSize;if(E){const D=no(C.sizeTree,0);let F=0,K=0;for(;F<k;){const R=C.groupIndices[K],L=C.groupIndices.length===K+1?1/0:C.groupIndices[K+1]-R-1;_.push({endIndex:R,size:D,startIndex:R}),_.push({endIndex:R+1+L-1,size:j,startIndex:R+1}),K++,F+=L+1}const P=fr(C.sizeTree);return F!==k&&P.shift(),P.reduce((R,{k:L,v:U})=>{let te=R.ranges;return R.prevSize!==0&&(te=[...R.ranges,{endIndex:L+k-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:L+k,prevSize:U,ranges:te}},{prevIndex:k,prevSize:0,ranges:_}).ranges}return fr(C.sizeTree).reduce((D,{k:F,v:K})=>({prevIndex:F+k,prevSize:K,ranges:[...D.ranges,{endIndex:F+k-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const T=Wt(W(i,Me(y,p),fe(([k,{offsetTree:C},E])=>{const _=-k;return oo(_,C,E)})));return ye(W(i,Me(y,p),fe(([k,C,E])=>{if(C.groupIndices.length>0){if(nt(C.sizeTree))return C;let _=Rr();const j=mt(v);let D=0,F=0,K=0;for(;D<-k;){K=j[F];const P=j[F+1]-K-1;F++,D+=P+1}if(_=fr(C.sizeTree).reduce((P,{k:R,v:L})=>Vt(P,Math.max(0,R+k),L),_),D!==-k){const P=no(C.sizeTree,K);_=Vt(_,0,P);const R=fn(C.sizeTree,-k+1)[1];_=Vt(_,1,R)}return{...C,sizeTree:_,...Zi(C.offsetTree,0,_,E)}}else{const _=fr(C.sizeTree).reduce((j,{k:D,v:F})=>Vt(j,Math.max(0,D+k),F),Rr());return{...C,sizeTree:_,...Zi(C.offsetTree,0,_,E)}}})),y),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:y,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},at(qn,Xi),{singleton:!0});function wy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const lu=Ge(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ve(),i=Ve(),a=Wt(W(s,fe(wy)));return ye(W(a,fe(l=>l.totalCount)),n),ye(W(a,fe(l=>l.groupIndices)),e),ye(W(vt(o,t,r),Ae(([l,c])=>rs(c)),fe(([l,c,d])=>fn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),lt(),fe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},at(kn,Ft)),Gn=Ge(([{log:e}])=>{const t=J(!1),n=Wt(W(t,Ae(r=>r),lt()));return Je(t,r=>{r&&mt(e)("props updated",{},Ut.DEBUG)}),{didMount:n,propsReady:t}},at(qn),{singleton:!0}),by=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function cu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!by)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const so=Ge(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ve(),g=Ve(),y=J(0);let v=null,x=null,w=null;function S(){v&&(v(),v=null),w&&(w(),w=null),x&&(clearTimeout(x),x=null),Pe(l,!1)}return ye(W(p,Me(n,f,r,y,a,i,h),Me(e,s,o),fe(([[T,k,C,E,_,j,D,F],K,P,R])=>{const L=cu(T),{align:U,behavior:te,offset:V}=L,z=E-1,G=iu(L,k,z);let Q=oo(G,k.offsetTree,K)+j;U==="end"?(Q+=P+fn(k.sizeTree,G)[1]-C+R,G===z&&(Q+=D)):U==="center"?Q+=(P+fn(k.sizeTree,G)[1]-C+R)/2:Q-=_,V&&(Q+=V);const le=B=>{S(),B?(F("retrying to scroll to",{location:T},Ut.DEBUG),Pe(p,T)):(Pe(g,!0),F("list did not change, scroll successful",{},Ut.DEBUG))};if(S(),te==="smooth"){let B=!1;w=Je(t,ie=>{B=B||ie}),v=dn(d,()=>{le(B)})}else v=dn(W(t,Sy(150)),le);return x=setTimeout(()=>{S()},1200),Pe(l,!0),F("scrolling from index to",{behavior:te,index:G,top:Q},Ut.DEBUG),{behavior:te,top:Q}})),c),{scrollTargetReached:g,scrollToIndex:p,topListHeight:y}},at(kn,Ft,qn),{singleton:!0});function Sy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Qi(e,t){e==0?t():requestAnimationFrame(()=>{Qi(e-1,t)})}function ea(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const io=Ge(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=J(!0),l=J(0),c=J(!0);return ye(W(i,Me(l),Ae(([d,f])=>!!f),Sn(!1)),a),ye(W(i,Me(l),Ae(([d,f])=>!!f),Sn(!1)),c),Je(W(vt(t,i),Me(a,n,e,c),Ae(([[,d],f,{sizeTree:h},p,g])=>d&&(!nt(h)||Hi(p))&&!f&&!g),Me(l)),([,d])=>{dn(o,()=>{Pe(c,!0)}),Qi(4,()=>{dn(r,()=>{Pe(a,!0)}),Pe(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},at(kn,Ft,so,Gn),{singleton:!0});function uu(e,t){return Math.abs(e-t)<1.01}const ao="up",lo="down",Cy="none",ky={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ty=0,co=Ge(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=Ve(),c=Ve(),d=J(4),f=J(Ty),h=Pt(W(Wi(W(Ee(o),ur(1),Sn(!0)),W(Ee(o),ur(1),Sn(!1),Kc(100))),lt()),!1),p=Pt(W(Wi(W(n,Sn(!0)),W(n,Sn(!1),Kc(200))),lt()),!1);ye(W(vt(Ee(o),Ee(f)),fe(([w,S])=>w<=S),lt()),a),ye(W(a,zn(50)),c);const g=Wt(W(vt(r,Ee(s),Ee(t),Ee(e),Ee(d)),Cn((w,[{scrollHeight:S,scrollTop:T},k,C,E,_])=>{const j=T+k-S>-_,D={scrollHeight:S,scrollTop:T,viewportHeight:k};if(j){let K,P;return T>w.state.scrollTop?(K="SCROLLED_DOWN",P=w.state.scrollTop-T):(K="SIZE_DECREASED",P=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:K,scrollTopDelta:P,state:D}}let F;return D.scrollHeight>w.state.scrollHeight?F="SIZE_INCREASED":k<w.state.viewportHeight?F="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?F="SCROLLING_UPWARDS":F="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:F,state:D}},ky),lt((w,S)=>w&&w.atBottom===S.atBottom))),y=Pt(W(r,Cn((w,{scrollHeight:S,scrollTop:T,viewportHeight:k})=>{if(uu(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:T};{const C=S-(T+k)<1;return w.scrollTop!==T&&C?{changed:!0,jump:w.scrollTop-T,scrollHeight:S,scrollTop:T}:{changed:!0,jump:0,scrollHeight:S,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(w=>w.changed),fe(w=>w.jump)),0);ye(W(g,fe(w=>w.atBottom)),i),ye(W(i,zn(50)),l);const v=J(lo);ye(W(r,fe(({scrollTop:w})=>w),lt(),Cn((w,S)=>mt(p)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?ao:lo,prevScrollTop:S},{direction:lo,prevScrollTop:0}),fe(w=>w.direction)),v),ye(W(r,zn(50),Sn(Cy)),v);const x=J(0);return ye(W(h,Ae(w=>!w),Sn(0)),x),ye(W(o,zn(100),Me(h),Ae(([w,S])=>!!S),Cn(([w,S],[T])=>[S,T],[0,0]),fe(([w,S])=>S-w)),x),{atBottomState:g,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:y,scrollDirection:v,scrollVelocity:x}},at(Ft)),os="top",ss="bottom",du="none";function fu(e,t,n){return typeof e=="number"?n===ao&&t===os||n===lo&&t===ss?e:0:n===ao?t===os?e.main:e.reverse:t===ss?e.main:e.reverse}function hu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ta=Ge(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ve(),i=J(0),a=J(0),l=J(0),c=Pt(W(vt(Ee(r),Ee(o),Ee(n),Ee(s,ro),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),fe(([d,f,h,[p,g],y,v,x,w,S])=>{const T=d-w,k=v+x,C=Math.max(h-T,0);let E=du;const _=hu(S,os),j=hu(S,ss);return p-=w,p+=h+x,g+=h+x,g-=w,p>d+k-_&&(E=ao),g<d-C+f+j&&(E=lo),E!==du?[Math.max(T-h-fu(y,os,E)-_,0),T-C-x+f+fu(y,ss,E)+j]:null}),Ae(d=>d!=null),lt(ro)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},at(Ft),{singleton:!0});function Ey(e,t,n){if(rs(t)){const r=su(e,t);return[{index:fn(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 na={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function is(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 y=e[e.length-1];d=y.offset+y.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,g=h-d;return{bottom:d,firstItemIndex:s,items:mu(e,o,s),offsetBottom:g,offsetTop:c,top:p,topItems:mu(t,o,s),topListHeight:t.reduce((y,v)=>v.size+y,0),totalCount:n}}function pu(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=ea(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return is(c,[],a,o,n,r)}function mu(e,t,n){if(e.length===0)return[];if(!rs(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=es(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 hr=Ge(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:g}])=>{const y=J([]),v=J(0),x=Ve();ye(s.topItemsIndexes,y);const w=Pt(W(vt(p,g,Ee(l,ro),Ee(o),Ee(r),Ee(c),d,Ee(y),Ee(t),Ee(n),e),Ae(([C,E,,_,,,,,,,j])=>{const D=j&&j.length!==_;return C&&!E&&!D}),fe(([,,[C,E],_,j,D,F,K,P,R,L])=>{const U=j,{offsetTree:te,sizeTree:V}=U,z=mt(v);if(_===0)return{...na,totalCount:_};if(C===0&&E===0)return z===0?{...na,totalCount:_}:pu(z,D,j,P,R,L||[]);if(nt(V))return z>0?null:is(Ey(ea(D,_),U,L),[],_,R,U,P);const G=[];if(K.length>0){const Ce=K[0],ke=K[K.length-1];let q=0;for(const M of es(V,Ce,ke)){const X=M.value,ne=Math.max(M.start,Ce),xe=Math.min(M.end,ke);for(let se=ne;se<=xe;se++)G.push({data:L==null?void 0:L[se],index:se,offset:q,size:X}),q+=X}}if(!F)return is([],G,_,R,U,P);const Q=K.length>0?K[K.length-1]+1:0,le=py(te,C,E,Q);if(le.length===0)return null;const B=_-1,ie=Qo([],Ce=>{for(const ke of le){const q=ke.value;let M=q.offset,X=ke.start;const ne=q.size;if(q.offset<C){X+=Math.floor((C-q.offset+R)/(ne+R));const se=X-ke.start;M+=se*ne+se*R}X<Q&&(M+=(Q-X)*ne,X=Q);const xe=Math.min(ke.end,B);for(let se=X;se<=xe&&!(M>=E);se++)Ce.push({data:L==null?void 0:L[se],index:se,offset:M,size:ne}),M+=ne+R}});return is(ie,G,_,R,U,P)}),Ae(C=>C!==null),lt()),na);ye(W(e,Ae(Hi),fe(C=>C==null?void 0:C.length)),o),ye(W(w,fe(C=>C.topListHeight)),f),ye(f,a),ye(W(w,fe(C=>[C.top,C.bottom])),i),ye(W(w,fe(C=>C.items)),x);const S=Wt(W(w,Ae(({items:C})=>C.length>0),Me(o,e),Ae(([{items:C},E])=>C[C.length-1].originalIndex===E-1),fe(([,C,E])=>[C-1,E]),lt(ro),fe(([C])=>C))),T=Wt(W(w,zn(200),Ae(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),fe(({items:C})=>C[0].index),lt())),k=Wt(W(w,Ae(({items:C})=>C.length>0),fe(({items:C})=>{let E=0,_=C.length-1;for(;C[E].type==="group"&&E<_;)E++;for(;C[_].type==="group"&&_>E;)_--;return{endIndex:C[_].index,startIndex:C[E].index}}),lt(ru)));return{endReached:S,initialItemCount:v,itemsRendered:x,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:y,...h}},at(kn,lu,ta,io,so,co,Gn,Xi),{singleton:!0}),gu=Ge(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ve(),i=Pt(W(vt(n,e,r,t,o),fe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ye(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},at(Ft,hr),{singleton:!0}),Iy=Ge(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=Pt(W(vt(n,e,t),Ae(([o])=>o),fe(([,o,s])=>Math.max(0,o-s)),zn(0),lt()),0);return{alignToBottom:n,paddingTopAddition:r}},at(Ft,gu),{singleton:!0}),xu=Ge(()=>({context:J(null)})),Ay=({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,yu=Ge(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ve();return ye(W(d,Me(t,l,n,s,o,r,a),Me(e),fe(([[f,h,p,g,y,v,x,w],S])=>{const{align:T,behavior:k,calculateViewLocation:C=Ay,done:E,..._}=f,j=iu(f,h,g-1),D=oo(j,h.offsetTree,S)+y+v,F=D+fn(h.sizeTree,j)[1],K=w+v,P=w+p-x,R=C({itemBottom:F,itemTop:D,locationParams:{align:T,behavior:k,..._},viewportBottom:P,viewportTop:K});return R?E&&dn(W(i,Ae(L=>!L),ur(mt(i)?1:2)),E):E&&E(),R}),Ae(f=>f!==null)),c),{scrollIntoView:d}},at(kn,Ft,so,hr,qn),{singleton:!0});function vu(e){return e?e==="smooth"?"smooth":"auto":!1}const Ny=(e,t)=>typeof e=="function"?vu(e(t)):t&&vu(e),_y=Ge(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const g=J(!1),y=Ve();let v=null;function x(k){Pe(i,{align:"end",behavior:k,index:"LAST"})}Je(W(vt(W(Ee(t),ur(1)),l),Me(Ee(g),s,a,f),fe(([[k,C],E,_,j,D])=>{let F=C&&j,K="auto";return F&&(K=Ny(E,_||D),F=F&&!!K),{followOutputBehavior:K,shouldFollow:F,totalCount:k}}),Ae(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:C})=>{v&&(v(),v=null),mt(n)?requestAnimationFrame(()=>{mt(d)("following output to ",{totalCount:C},Ut.DEBUG),x(k)}):v=dn(e,()=>{mt(d)("following output to ",{totalCount:C},Ut.DEBUG),x(k),v=null})});function w(k){const C=dn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(mt(d)("scrolling to bottom due to increased size",{},Ut.DEBUG),x("auto"))});setTimeout(C,100)}Je(W(vt(Ee(g),t,c),Ae(([k,,C])=>k&&C),Cn(({value:k},[,C])=>({refreshed:k===C,value:C}),{refreshed:!1,value:0}),Ae(({refreshed:k})=>k),Me(g,t)),([,k])=>{mt(a)&&w(k!==!1)}),Je(y,()=>{w(mt(g)!==!1)}),Je(vt(Ee(g),o),([k,C])=>{k&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=J(null),T=Ve();return ye(Wi(W(Ee(r),fe(k=>{var C;return(C=k==null?void 0:k.length)!=null?C:0})),W(Ee(t))),T),Je(W(vt(W(T,ur(1)),l),Me(Ee(S),a,f,h),fe(([[k,C],E,_,j,D])=>C&&_&&(E==null?void 0:E({context:D,totalCount:k,scrollingInProgress:j}))),Ae(k=>!!k),zn(0)),k=>{v&&(v(),v=null),mt(n)?requestAnimationFrame(()=>{mt(d)("scrolling into view",{}),Pe(p,k)}):v=dn(e,()=>{mt(d)("scrolling into view",{}),Pe(p,k),v=null})}),{autoscrollToBottom:y,followOutput:g,scrollIntoViewOnChange:S}},at(kn,co,so,io,Gn,qn,Ft,xu,yu)),jy=Ge(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ye(W(a,Me(s),Ae(([,l])=>l!==0),Me(o,r,t,n,e),fe(([[,l],c,d,f,h,p=[]])=>pu(l,c,d,f,h,p))),i),{}),at(kn,io,hr,Gn),{singleton:!0}),Ry=Ge(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return Je(W(e,Me(r),Ae(([,o])=>o!==0),fe(([,o])=>({top:o}))),o=>{dn(W(n,ur(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},at(Gn,Ft,hr),{singleton:!0}),wu=Ge(([{scrollVelocity:e}])=>{const t=J(!1),n=Ve(),r=J(!1);return ye(W(e,Me(r,t,n),Ae(([o,s])=>!!s),fe(([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}),lt()),t),Je(W(vt(t,e,n),Me(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},at(co),{singleton:!0}),ra=Ge(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ve(),r=Ve(),o=Ve(),s=J(!1),i=J(void 0);return ye(W(vt(n,r),fe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ye(W(t,Me(r),fe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},at(Ft)),Py=Ge(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ve(),d=J(void 0),f=J(null),h=J(null);return ye(a,f),ye(l,h),Je(W(c,Me(t,r,i,f,h,n)),([p,g,y,v,x,w,S])=>{const T=gy(g.sizeTree);v&&x!==null&&w!==null&&(y=x.scrollTop-w.offsetTop),y-=S,p({ranges:T,scrollTop:y})}),ye(W(d,Ae(Hi),fe(Oy)),o),ye(W(s,Me(d),Ae(([,p])=>p!==void 0),lt(),fe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},at(kn,Ft,io,Gn,ra));function Oy(e){return{align:"start",index:0,offset:e.scrollTop}}const My=Ge(([{topItemsIndexes:e}])=>{const t=J(0);return ye(W(t,Ae(n=>n>=0),fe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},at(hr));function bu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Dy=bu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Ly=Ge(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:g}])=>{const y=Wt(W(l,Me(i),Cn(([,x,w,S],[{bottom:T,items:k,offsetBottom:C,totalCount:E},_])=>{const j=T+C;let D=0;return w===E&&x.length>0&&k.length>0&&(k[0].originalIndex===0&&x[0].originalIndex===0||(D=j-S,D!==0&&(D+=_))),[D,k,E,j]},[0,[],0,0]),Ae(([x])=>x!==0),Me(r,a,n,o,p,g),Ae(([,x,w,S,,,T])=>!T&&!S&&x!==0&&w===ao),fe(([[x],,,,,w])=>(w("Upward scrolling compensation",{amount:x},Ut.DEBUG),x))));function v(x){x>0?(Pe(t,{behavior:"auto",top:-x}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-x}))}return Je(W(y,Me(e,s)),([x,w,S])=>{S&&Dy()?Pe(e,w-x):v(-x)}),Je(W(vt(Pt(s,!1),e,g),Ae(([x,w,S])=>!x&&!S&&w!==0),fe(([x,w])=>w),zn(1)),v),ye(W(f,fe(x=>({top:-x}))),t),Je(W(c,Me(h,d),fe(([x,{groupIndices:w,lastSize:S,sizeTree:T},k])=>{function C(E){return E*(S+k)}if(w.length===0)return C(x);{let E=0;const _=no(T,0);let j=0,D=0;for(;j<x;){j++,E+=_;let F=w.length===D+1?1/0:w[D+1]-w[D]-1;j+F>x&&(E-=_,F=x-j+1),j+=F,E+=C(F),D++}return E}})),x=>{Pe(e,x),requestAnimationFrame(()=>{Pe(t,{top:x}),requestAnimationFrame(()=>{Pe(e,0),Pe(g,!1)})})}),{deviation:e}},at(Ft,co,hr,kn,qn,Xi)),Fy=Ge(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),at(ta,jy,Gn,wu,gu,Ry,Iy,ra,yu,qn,xu)),Su=Ge(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:g},y,v,x,{listState:w,topItemsIndexes:S,...T},{scrollToIndex:k},C,{topItemCount:E},{groupCounts:_},j])=>(ye(T.rangeChanged,j.scrollSeekRangeChanged),ye(W(j.windowViewportRect,fe(D=>D.visibleHeight)),y.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:_,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:g,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,...j,...y,sizes:l,...v}),at(kn,io,Ft,Py,_y,hr,so,Ly,My,lu,Fy));function $y(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 as=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Cu(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(v,x){v.propsReady&&Pe(v.propsReady,!1);for(const w of r){const S=v[t.required[w]];Pe(S,x[w])}for(const w of o)if(w in x){const S=v[t.optional[w]];Pe(S,x[w])}v.propsReady&&Pe(v.propsReady,!0)}function c(v){return s.reduce((x,w)=>(x[w]=S=>{const T=v[t.methods[w]];Pe(T,S)},x),{})}function d(v){return i.reduce((x,w)=>(x[w]=ty(v[t.events[w]]),x),{})}const f=b.forwardRef((v,x)=>{const{children:w,...S}=v,[T]=b.useState(()=>Qo(ry(e),E=>{l(E,S)})),[k]=b.useState(qc(d,T));as(()=>{for(const E of i)E in S&&Je(k[E],S[E]);return()=>{Object.values(k).map(Ui)}},[S,k,T]),as(()=>{l(T,S)}),b.useImperativeHandle(x,Wc(c(T)));const C=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(C,{...$y([...r,...o,...i],S),children:w}):w})}),h=v=>{const x=b.useContext(a);return b.useCallback(w=>{Pe(x[v],w)},[x,v])},p=v=>{const x=b.useContext(a)[v],w=b.useCallback(S=>Je(x,S),[x]);return b.useSyncExternalStore(w,()=>mt(x),()=>mt(x))},g=v=>{const x=b.useContext(a)[v],[w,S]=b.useState(qc(mt,x));return as(()=>Je(x,T=>{T!==w&&S(Wc(T))}),[x,w]),w},y=b.version.startsWith("18")?p:g;return{Component:f,useEmitter:(v,x)=>{const w=b.useContext(a)[v];as(()=>Je(w,x),[x,w])},useEmitterValue:y,usePublisher:h}}const ku=b.createContext(void 0),Tu=b.createContext(void 0),Eu=typeof document<"u"?b.useLayoutEffect:b.useEffect;function oa(e){return"self"in e}function zy(e){return"body"in e}function Iu(e,t,n,r=jr,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(h=>{let p,g,y;const v=h.target;if(zy(v)||oa(v)){const w=oa(v)?v:v.defaultView;y=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,g=s?w.innerWidth:w.innerHeight}else y=s?v.scrollLeft:v.scrollTop,p=s?v.scrollWidth:v.scrollHeight,g=s?v.offsetWidth:v.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(y,0),viewportHeight:g})};h.suppressFlushSync?x():fi.flushSync(x),a.current!==null&&(y===a.current||y<=0||y===p-g)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const g=h.behavior==="smooth";let y,v,x;oa(p)?(v=Math.max(Kn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),y=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(v=p[s?"scrollWidth":"scrollHeight"],y=Kn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const w=v-y;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),uu(y,v)||h.top===x){e({scrollHeight:v,scrollTop:x,viewportHeight:y}),g&&t(!0);return}g?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const sa="-webkit-sticky",Au="sticky",ia=bu(()=>{if(typeof document>"u")return Au;const e=document.createElement("div");return e.style.position=sa,e.style.position===sa?sa:Au});function aa(e){return e}const By=Ge(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(aa),o=J("div"),s=J(jr),i=(a,l=null)=>Pt(W(n,fe(c=>c[a]),lt()),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")}}),Hy=Ge(([e,t])=>({...e,...t}),at(Su,By)),Uy=({height:e})=>u.jsx("div",{style:{height:e}}),Wy={overflowAnchor:"none",position:ia(),zIndex:1},Nu={overflowAnchor:"none"},Vy={...Nu,display:"inline-block",height:"100%"},_u=b.memo(function({showTopList:e=!1}){const t=je("listState"),n=en("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),c=je("context"),d=je("groupContent"),f=je("trackItemSizes"),h=je("itemSize"),p=je("log"),g=en("gap"),y=je("horizontalDirection"),{callbackRef:v}=iy(n,h,f,e?jr:a,p,g,o,y,je("skipAnimationFrameInResizeObserver")),[x,w]=b.useState(0);la("deviation",R=>{x!==R&&w(R)});const S=je("EmptyPlaceholder"),T=je("ScrollSeekPlaceholder")||Uy,k=je("ListComponent"),C=je("ItemComponent"),E=je("GroupComponent"),_=je("computeItemKey"),j=je("isSeeking"),D=je("groupIndices").length>0,F=je("alignToBottom"),K=je("initialItemFinalLocationReached"),P=e?{}:{boxSizing:"border-box",...y?{display:"inline-block",height:"100%",marginLeft:x!==0?x:F?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:F?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...K?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Ot(S,c)}):u.jsx(k,{...Ot(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:P,children:(e?t.topItems:t.items).map(R=>{const L=R.originalIndex,U=_(L+t.firstItemIndex,R.data,c);return j?b.createElement(T,{...Ot(T,c),height:R.size,index:R.index,key:U,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?b.createElement(E,{...Ot(E,c),"data-index":L,"data-item-index":R.index,"data-known-size":R.size,key:U,style:Wy},d(R.index,c)):b.createElement(C,{...Ot(C,c),...Yy(C,R.data),"data-index":L,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:U,style:y?Vy:Nu},D?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),qy={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Ky={outline:"none",overflowX:"auto",position:"relative"},ls=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Gy={position:ia(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function Yy(e,t){return{item:typeof e=="string"?void 0:t}}const Xy=b.memo(function(){const e=je("HeaderComponent"),t=en("headerHeight"),n=je("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),Jy=b.memo(function(){const e=je("FooterComponent"),t=en("footerHeight"),n=je("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null});function ju({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"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:g}=Iu(a,c,l,d,void 0,f);return e("scrollTo",g),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Ky:qy,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function Ru({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"),f=t("deviation"),h=t("customScrollParent"),p=b.useRef(null),g=t("scrollerRef"),{scrollByCallback:y,scrollerRef:v,scrollToCallback:x}=Iu(a,c,l,g,h);return Eu(()=>{var w;return v.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",x),e("scrollBy",y),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Ot(l,s),children:r})})}const Zy=({children:e})=>{const t=b.useContext(ku),n=en("viewportHeight"),r=en("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=b.useMemo(()=>Vc(n,l=>Kn(l,s?"width":"height")),[n,s]),a=dr(i,!0,je("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:ls(o),children:e})},Qy=({children:e})=>{const t=b.useContext(ku),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=je("customScrollParent"),s=Xc(n,o,je("skipAnimationFrameInResizeObserver")),i=je("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:ls(i),children:e})},ev=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...Gy,marginTop:`${n}px`},o=je("context");return u.jsx(t,{style:r,...Ot(t,o),children:e})},tv=b.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return u.jsxs(r||t?ov:rv,{...e,context:o,children:[n&&u.jsx(ev,{children:u.jsx(_u,{showTopList:!0})}),u.jsxs(r||t?Qy:Zy,{children:[u.jsx(Xy,{}),u.jsx(_u,{}),u.jsx(Jy,{})]})]})}),{Component:nv,useEmitter:la,useEmitterValue:je,usePublisher:en}=Cu(Hy,{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"}},tv),rv=ju({useEmitter:la,useEmitterValue:je,usePublisher:en}),ov=Ru({useEmitter:la,useEmitterValue:je,usePublisher:en}),sv=nv;at(Su,Ge(()=>{const e=J(c=>u.jsxs("td",{children:["Item $",c]})),t=J(null),n=J(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=J(null),o=J(null),s=J({}),i=J(aa),a=J(jr),l=(c,d=null)=>Pt(W(s,fe(f=>f[c]),lt()),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")}})),ia();const Pu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},iv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ou,floor:cs,max:uo,min:ca,round:Mu}=Math;function Du(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function av(e){return{...iv,items:e}}function us(e,t){return e&&e.width===t.width&&e.height===t.height}function lv(e,t){return e&&e.column===t.column&&e.row===t.row}const cv=Ge(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:g,propsReady:y},{customScrollParent:v,useWindowScroll:x,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T},k])=>{const C=J(0),E=J(0),_=J(Pu),j=J({height:0,width:0}),D=J({height:0,width:0}),F=Ve(),K=Ve(),P=J(0),R=J(null),L=J({column:0,row:0}),U=Ve(),te=Ve(),V=J(!1),z=J(0),G=J(!0),Q=J(!1),le=J(!1);Je(W(g,Me(z),Ae(([M,X])=>!!X)),()=>{Pe(G,!1)}),Je(W(vt(g,G,D,j,z,Q),Ae(([M,X,ne,xe,,se])=>M&&!X&&ne.height!==0&&xe.height!==0&&!se)),([,,,,M])=>{Pe(Q,!0),Qi(1,()=>{Pe(F,M)}),dn(W(c),()=>{Pe(t,[0,0]),Pe(G,!0)})}),ye(W(te,Ae(M=>M!=null&&M.scrollTop>0),Sn(0)),E),Je(W(g,Me(te),Ae(([,M])=>M!=null)),([,M])=>{M&&(Pe(j,M.viewport),Pe(D,M.item),Pe(L,M.gap),M.scrollTop>0&&(Pe(V,!0),dn(W(c,ur(1)),X=>{Pe(V,!1)}),Pe(l,{top:M.scrollTop})))}),ye(W(j,fe(({height:M})=>M)),f),ye(W(vt(Ee(j,us),Ee(D,us),Ee(L,(M,X)=>M&&M.column===X.column&&M.row===X.row),Ee(c)),fe(([M,X,ne,xe])=>({gap:ne,item:X,scrollTop:xe,viewport:M}))),U),ye(W(vt(Ee(C),r,Ee(L,lv),Ee(D,us),Ee(j,us),Ee(R),Ee(E),Ee(V),Ee(G),Ee(z)),Ae(([,,,,,,,M])=>!M),fe(([M,[X,ne],xe,se,ae,Ue,Ke,,ot,st])=>{const{column:ut,row:et}=xe,{height:De,width:We}=se,{width:it}=ae;if(Ke===0&&(M===0||it===0))return Pu;if(We===0){const Fe=ea(st,M),Ze=Fe+Math.max(Ke-1,0);return av(Du(Fe,Ze,Ue))}const gt=Lu(it,We,ut);let re,ve;ot?X===0&&ne===0&&Ke>0?(re=0,ve=Ke-1):(re=gt*cs((X+et)/(De+et)),ve=gt*Ou((ne+et)/(De+et))-1,ve=ca(M-1,uo(ve,gt-1)),re=ca(ve,uo(0,re))):(re=0,ve=-1);const we=Du(re,ve,Ue),{bottom:Ye,top:xt}=Fu(ae,xe,se,we),ft=Ou(M/gt),wt=ft*De+(ft-1)*et-Ye;return{bottom:Ye,itemHeight:De,items:we,itemWidth:We,offsetBottom:wt,offsetTop:xt,top:xt}})),_),ye(W(R,Ae(M=>M!==null),fe(M=>M.length)),C),ye(W(vt(j,D,_,L),Ae(([M,X,{items:ne}])=>ne.length>0&&X.height!==0&&M.height!==0),fe(([M,X,{items:ne},xe])=>{const{bottom:se,top:ae}=Fu(M,xe,X,ne);return[ae,se]}),lt(ro)),t);const B=J(!1);ye(W(c,Me(B),fe(([M,X])=>X||M!==0)),B);const ie=Wt(W(vt(_,C),Ae(([{items:M}])=>M.length>0),Me(B),Ae(([[M,X],ne])=>{const xe=M.items[M.items.length-1].index===X-1;return(ne||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===X)&&xe}),fe(([[,M]])=>M-1),lt())),Ce=Wt(W(Ee(_),Ae(({items:M})=>M.length>0&&M[0].index===0),Sn(0),lt())),ke=Wt(W(Ee(_),Me(V),Ae(([{items:M},X])=>M.length>0&&!X),fe(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),lt(ru),zn(0)));ye(ke,p.scrollSeekRangeChanged),ye(W(F,Me(j,D,C,L),fe(([M,X,ne,xe,se])=>{const ae=cu(M),{align:Ue,behavior:Ke,offset:ot}=ae;let st=ae.index;st==="LAST"&&(st=xe-1),st=uo(0,st,ca(xe-1,st));let ut=ua(X,se,ne,st);return Ue==="end"?ut=Mu(ut-X.height+ne.height):Ue==="center"&&(ut=Mu(ut-X.height/2+ne.height/2)),ot&&(ut+=ot),{behavior:Ke,top:ut}})),l);const q=Pt(W(_,fe(M=>M.offsetBottom+M.bottom)),0);return ye(W(T,fe(M=>({height:M.visibleHeight,width:M.visibleWidth}))),j),{customScrollParent:v,data:R,deviation:P,footerHeight:o,gap:L,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:D,overscan:n,restoreStateFrom:te,scrollBy:i,scrollContainerState:a,scrollHeight:K,scrollTo:l,scrollToIndex:F,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T,...p,gridState:_,horizontalDirection:le,initialTopMostItemIndex:z,totalListHeight:q,...h,endReached:ie,propsReady:y,rangeChanged:ke,startReached:Ce,stateChanged:U,stateRestoreInProgress:V,...k}},at(ta,Ft,co,wu,Gn,ra,qn));function Lu(e,t,n){return uo(1,cs((e+n)/(cs(t)+n)))}function Fu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ua(e,t,n,r[0].index);return{bottom:ua(e,t,n,r[r.length-1].index)+o,top:s}}function ua(e,t,n,r){const o=Lu(e.width,n.width,t.column),s=cs(r/o),i=s*n.height+uo(0,s-1)*t.row;return i>0?i+t.row:i}const uv=Ge(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(aa),i=J("div"),a=J(jr),l=(f,h=null)=>Pt(W(t,fe(p=>p[f]),lt()),h),c=J(!1),d=J(!1);return ye(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")}}),dv=Ge(([e,t])=>({...e,...t}),at(cv,uv)),fv=b.memo(function(){const e=ct("gridState"),t=ct("listClassName"),n=ct("itemClassName"),r=ct("itemContent"),o=ct("computeItemKey"),s=ct("isSeeking"),i=tn("scrollHeight"),a=ct("ItemComponent"),l=ct("ListComponent"),c=ct("ScrollSeekPlaceholder"),d=ct("context"),f=tn("itemDimensions"),h=tn("gap"),p=ct("log"),g=ct("stateRestoreInProgress"),y=tn("reportReadyState"),v=dr(b.useMemo(()=>x=>{const w=x.parentElement.parentElement.scrollHeight;i(w);const S=x.firstChild;if(S){const{height:T,width:k}=S.getBoundingClientRect();f({height:T,width:k})}h({column:zu("column-gap",getComputedStyle(x).columnGap,p),row:zu("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Eu(()=>{e.itemHeight>0&&e.itemWidth>0&&y(!0)},[e]),g?null:u.jsx(l,{className:t,ref:v,...Ot(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const w=o(x.index,x.data,d);return s?u.jsx(c,{...Ot(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},w):b.createElement(a,{...Ot(a,d),className:n,"data-index":x.index,key:w},r(x.index,x.data,d))})})}),hv=b.memo(function(){const e=ct("HeaderComponent"),t=tn("headerHeight"),n=ct("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,!1),o=ct("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),pv=b.memo(function(){const e=ct("FooterComponent"),t=tn("footerHeight"),n=ct("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,!1),o=ct("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),mv=({children:e})=>{const t=b.useContext(Tu),n=tn("itemDimensions"),r=tn("viewportDimensions"),o=dr(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:ls(!1),children:e})},gv=({children:e})=>{const t=b.useContext(Tu),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=ct("customScrollParent"),s=Xc(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:ls(!1),children:e})},xv=b.memo(function({...e}){const t=ct("useWindowScroll"),n=ct("customScrollParent"),r=n||t?vv:yv,o=n||t?gv:mv,s=ct("context");return u.jsx(r,{...e,...Ot(r,s),children:u.jsxs(o,{children:[u.jsx(hv,{}),u.jsx(fv,{}),u.jsx(pv,{})]})})}),{useEmitter:$u,useEmitterValue:ct,usePublisher:tn}=Cu(dv,{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"}},xv),yv=ju({useEmitter:$u,useEmitterValue:ct,usePublisher:tn}),vv=Ru({useEmitter:$u,useEmitterValue:ct,usePublisher:tn});function zu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ut.WARN),t==="normal"?0:parseInt(t??"0",10)}const wv=Ro.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Bu({className:e,variant:t,...n}){return u.jsx("div",{className:oe(wv({variant:t}),e),...n})}const fo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));fo.displayName="Card";const ho=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));ho.displayName="CardHeader";const po=m.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));po.displayName="CardTitle";const Hu=m.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Hu.displayName="CardDescription";const mo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));mo.displayName="CardContent";const Uu=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));Uu.displayName="CardFooter";function ge(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 bv(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...g}=f,y=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,v=m.useMemo(()=>g,Object.values(g));return u.jsx(y.Provider,{value:v,children:p})};c.displayName=s+"Provider";function d(f,h){var y;const p=((y=h==null?void 0:h[e])==null?void 0:y[l])||a,g=m.useContext(p);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Sv(o,...t)]}function Sv(...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 f=l(s)[`__scope${c}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var kt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},Cv=m[" useInsertionEffect ".trim().toString()]||kt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=kv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=m.useCallback(d=>{var f;if(a){const h=Tv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function kv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return Cv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Tv(e){return typeof e=="function"}function Wu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function da(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Wu(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():Wu(e[o],null)}}}}function He(...e){return m.useCallback(da(...e),e)}var Ev=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=Ev.reduce((e,t)=>{const n=sr.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Vu(e,t){e&&Po.flushSync(()=>e.dispatchEvent(t))}function Iv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var qt=e=>{const{present:t,children:n}=e,r=Av(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=He(r.ref,Nv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};qt.displayName="Presence";function Av(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Iv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const c=ds(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=ds(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),kt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const y=ds(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&y&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},h=p=>{p.target===t&&(s.current=ds(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function ds(e){return(e==null?void 0:e.animationName)||"none"}function Nv(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 _v=m[" useId ".trim().toString()]||(()=>{}),jv=0;function En(e){const[t,n]=m.useState(_v());return kt(()=>{n(r=>r??String(jv++))},[e]),e||(t?`radix-${t}`:"")}var fs="Collapsible",[Rv,pT]=Tn(fs),[Pv,fa]=Rv(fs),qu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,c]=pr({prop:r,defaultProp:o??!1,onChange:i,caller:fs});return u.jsx(Pv,{scope:n,disabled:s,contentId:En(),open:l,onOpenToggle:m.useCallback(()=>c(d=>!d),[c]),children:u.jsx(Ne.div,{"data-state":pa(l),"data-disabled":s?"":void 0,...a,ref:t})})});qu.displayName=fs;var Ku="CollapsibleTrigger",Gu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=fa(Ku,n);return u.jsx(Ne.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":pa(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ge(e.onClick,o.onOpenToggle)})});Gu.displayName=Ku;var ha="CollapsibleContent",Ov=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=fa(ha,e.__scopeCollapsible);return u.jsx(qt,{present:n||o.open,children:({present:s})=>u.jsx(Mv,{...r,ref:t,present:s})})});Ov.displayName=ha;var Mv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=fa(ha,n),[a,l]=m.useState(r),c=m.useRef(null),d=He(t,c),f=m.useRef(0),h=f.current,p=m.useRef(0),g=p.current,y=i.open||a,v=m.useRef(y),x=m.useRef(void 0);return m.useEffect(()=>{const w=requestAnimationFrame(()=>v.current=!1);return()=>cancelAnimationFrame(w)},[]),kt(()=>{const w=c.current;if(w){x.current=x.current||{transitionDuration:w.style.transitionDuration,animationName:w.style.animationName},w.style.transitionDuration="0s",w.style.animationName="none";const S=w.getBoundingClientRect();f.current=S.height,p.current=S.width,v.current||(w.style.transitionDuration=x.current.transitionDuration,w.style.animationName=x.current.animationName),l(r)}},[i.open,r]),u.jsx(Ne.div,{"data-state":pa(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!y,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":g?`${g}px`:void 0,...e.style},children:y&&o})});function pa(e){return e?"open":"closed"}var Dv=qu;const Lv=Dv,Fv=Gu,$v=1,zv=1e6;let ma=0;function Bv(){return ma=(ma+1)%Number.MAX_SAFE_INTEGER,ma.toString()}const ga=new Map,Yu=e=>{if(ga.has(e))return;const t=setTimeout(()=>{ga.delete(e),go({type:"REMOVE_TOAST",toastId:e})},zv);ga.set(e,t)},Hv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,$v)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?Yu(n):e.toasts.forEach(r=>{Yu(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},hs=[];let ps={toasts:[]};function go(e){ps=Hv(ps,e),hs.forEach(t=>{t(ps)})}function Uv({...e}){const t=Bv(),n=o=>go({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>go({type:"DISMISS_TOAST",toastId:t});return go({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function xa(){const[e,t]=m.useState(ps);return m.useEffect(()=>(hs.push(t),()=>{const n=hs.indexOf(t);n>-1&&hs.splice(n,1)}),[e]),{...e,toast:Uv,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}async function Xu(e,t){return await cn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Ju(e,t){return await(await Xu(`/files/${e}/view`,t)).text()}async function Wv(e,t){const n=await Xu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await cn(`/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 Vv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await cn("/files",{params:r})}function Zu(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 Qu(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function xo(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(xo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(Qu(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=xo(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 ms(e){if(typeof e=="string")return e;if(Qu(e))return"";try{const t=xo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function At(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function qv(e,t=globalThis==null?void 0:globalThis.document){const n=At(e);m.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 Kv="DismissableLayer",ya="dismissableLayer.update",Gv="dismissableLayer.pointerDownOutside",Yv="dismissableLayer.focusOutside",ed,td=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),gs=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=m.useContext(td),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),g=He(t,E=>f(E)),y=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=y.indexOf(v),w=d?y.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=x,k=Zv(E=>{const _=E.target,j=[...c.branches].some(D=>D.contains(_));!T||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),C=Qv(E=>{const _=E.target;[...c.branches].some(D=>D.contains(_))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return qv(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(ed=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),nd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=ed)}},[d,h,n,c]),m.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),nd())},[d,c]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(ya,E),()=>document.removeEventListener(ya,E)},[]),u.jsx(Ne.div,{...l,ref:g,style:{pointerEvents:S?T?"auto":"none":void 0,...e.style},onFocusCapture:ge(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ge(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ge(e.onPointerDownCapture,k.onPointerDownCapture)})});gs.displayName=Kv;var Xv="DismissableLayerBranch",Jv=m.forwardRef((e,t)=>{const n=m.useContext(td),r=m.useRef(null),o=He(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ne.div,{...e,ref:o})});Jv.displayName=Xv;function Zv(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){rd(Gv,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 Qv(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&rd(Yv,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 nd(){const e=new CustomEvent(ya);document.dispatchEvent(e)}function rd(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?Vu(o,s):o.dispatchEvent(s)}var va="focusScope.autoFocusOnMount",wa="focusScope.autoFocusOnUnmount",od={bubbles:!1,cancelable:!0},ew="FocusScope",xs=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),c=At(o),d=At(s),f=m.useRef(null),h=He(t,y=>l(y)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let y=function(S){if(p.paused||!a)return;const T=S.target;a.contains(T)?f.current=T:Yn(f.current,{select:!0})},v=function(S){if(p.paused||!a)return;const T=S.relatedTarget;T!==null&&(a.contains(T)||Yn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&Yn(a)};document.addEventListener("focusin",y),document.addEventListener("focusout",v);const w=new MutationObserver(x);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",v),w.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){ad.add(p);const y=document.activeElement;if(!a.contains(y)){const x=new CustomEvent(va,od);a.addEventListener(va,c),a.dispatchEvent(x),x.defaultPrevented||(tw(iw(sd(a)),{select:!0}),document.activeElement===y&&Yn(a))}return()=>{a.removeEventListener(va,c),setTimeout(()=>{const x=new CustomEvent(wa,od);a.addEventListener(wa,d),a.dispatchEvent(x),x.defaultPrevented||Yn(y??document.body,{select:!0}),a.removeEventListener(wa,d),ad.remove(p)},0)}}},[a,c,d,p]);const g=m.useCallback(y=>{if(!n&&!r||p.paused)return;const v=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,x=document.activeElement;if(v&&x){const w=y.currentTarget,[S,T]=nw(w);S&&T?!y.shiftKey&&x===T?(y.preventDefault(),n&&Yn(S,{select:!0})):y.shiftKey&&x===S&&(y.preventDefault(),n&&Yn(T,{select:!0})):x===w&&y.preventDefault()}},[n,r,p.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});xs.displayName=ew;function tw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Yn(r,{select:t}),document.activeElement!==n)return}function nw(e){const t=sd(e),n=id(t,e),r=id(t.reverse(),e);return[n,r]}function sd(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 id(e,t){for(const n of e)if(!rw(n,{upTo:t}))return n}function rw(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 ow(e){return e instanceof HTMLInputElement&&"select"in e}function Yn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&ow(e)&&t&&e.select()}}var ad=sw();function sw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=ld(e,t),e.unshift(t)},remove(t){var n;e=ld(e,t),(n=e[0])==null||n.resume()}}}function ld(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function iw(e){return e.filter(t=>t.tagName!=="A")}var aw="Portal",ys=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?fi.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});ys.displayName=aw;var ba=0;function Sa(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??cd()),document.body.insertAdjacentElement("beforeend",e[1]??cd()),ba++,()=>{ba===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ba--}},[])}function cd(){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 In=function(){return In=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},In.apply(this,arguments)};function ud(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 lw(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 vs="right-scroll-bar-position",ws="width-before-scroll-bar",cw="with-scroll-bars-hidden",uw="--removed-body-scroll-bar-size";function Ca(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dw(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 fw=typeof window<"u"?m.useLayoutEffect:m.useEffect,dd=new WeakMap;function hw(e,t){var n=dw(null,function(r){return e.forEach(function(o){return Ca(o,r)})});return fw(function(){var r=dd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Ca(a,null)}),s.forEach(function(a){o.has(a)||Ca(a,i)})}dd.set(n,e)},[e]),n}function pw(e){return e}function mw(e,t){t===void 0&&(t=pw);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 gw(e){e===void 0&&(e={});var t=mw(null);return t.options=In({async:!0,ssr:!1},e),t}var fd=function(e){var t=e.sideCar,n=ud(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 m.createElement(r,In({},n))};fd.isSideCarExport=!0;function xw(e,t){return e.useMedium(t),fd}var hd=gw(),ka=function(){},bs=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:ka,onWheelCapture:ka,onTouchMoveCapture:ka}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,g=e.noIsolation,y=e.inert,v=e.allowPinchZoom,x=e.as,w=x===void 0?"div":x,S=e.gapMode,T=ud(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,C=hw([n,t]),E=In(In({},T),o);return m.createElement(m.Fragment,null,d&&m.createElement(k,{sideCar:hd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:g,inert:y,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),In(In({},E),{ref:C})):m.createElement(w,In({},E,{className:l,ref:C}),a))});bs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},bs.classNames={fullWidth:ws,zeroRight:vs};var yw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yw();return t&&e.setAttribute("nonce",t),e}function ww(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function bw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vw())&&(ww(t,n),bw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cw=function(){var e=Sw();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},pd=function(){var e=Cw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},kw={left:0,top:0,right:0,gap:0},Ta=function(e){return parseInt(e||"",10)||0},Tw=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[Ta(n),Ta(r),Ta(o)]},Ew=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kw;var t=Tw(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])}},Iw=pd(),Pr="data-scroll-locked",Aw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
39
|
-
.`.concat(cw,` {
|
|
40
|
-
overflow: hidden `).concat(r,`;
|
|
41
|
-
padding-right: `).concat(a,"px ").concat(r,`;
|
|
42
|
-
}
|
|
43
|
-
body[`).concat(Pr,`] {
|
|
44
|
-
overflow: hidden `).concat(r,`;
|
|
45
|
-
overscroll-behavior: contain;
|
|
46
|
-
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
47
|
-
padding-left: `.concat(o,`px;
|
|
48
|
-
padding-top: `).concat(s,`px;
|
|
49
|
-
padding-right: `).concat(i,`px;
|
|
50
|
-
margin-left:0;
|
|
51
|
-
margin-top:0;
|
|
52
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
53
|
-
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.`).concat(vs,` {
|
|
57
|
-
right: `).concat(a,"px ").concat(r,`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.`).concat(ws,` {
|
|
61
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.`).concat(vs," .").concat(vs,` {
|
|
65
|
-
right: 0 `).concat(r,`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.`).concat(ws," .").concat(ws,` {
|
|
69
|
-
margin-right: 0 `).concat(r,`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
body[`).concat(Pr,`] {
|
|
73
|
-
`).concat(uw,": ").concat(a,`px;
|
|
74
|
-
}
|
|
75
|
-
`)},md=function(){var e=parseInt(document.body.getAttribute(Pr)||"0",10);return isFinite(e)?e:0},Nw=function(){m.useEffect(function(){return document.body.setAttribute(Pr,(md()+1).toString()),function(){var e=md()-1;e<=0?document.body.removeAttribute(Pr):document.body.setAttribute(Pr,e.toString())}},[])},_w=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Nw();var s=m.useMemo(function(){return Ew(o)},[o]);return m.createElement(Iw,{styles:Aw(s,!t,o,n?"":"!important")})},Ea=!1;if(typeof window<"u")try{var Ss=Object.defineProperty({},"passive",{get:function(){return Ea=!0,!0}});window.addEventListener("test",Ss,Ss),window.removeEventListener("test",Ss,Ss)}catch{Ea=!1}var Or=Ea?{passive:!1}:!1,jw=function(e){return e.tagName==="TEXTAREA"},gd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!jw(e)&&n[t]==="visible")},Rw=function(e){return gd(e,"overflowY")},Pw=function(e){return gd(e,"overflowX")},xd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=yd(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},Ow=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Mw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},yd=function(e,t){return e==="v"?Rw(t):Pw(t)},vd=function(e,t){return e==="v"?Ow(t):Mw(t)},Dw=function(e,t){return e==="h"&&t==="rtl"?-1:1},Lw=function(e,t,n,r,o){var s=Dw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=vd(e,a),g=p[0],y=p[1],v=p[2],x=y-v-s*g;(g||x)&&yd(e,a)&&(f+=x,h+=g);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(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},Cs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},wd=function(e){return[e.deltaX,e.deltaY]},bd=function(e){return e&&"current"in e?e.current:e},Fw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},$w=function(e){return`
|
|
76
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},zw=0,Mr=[];function Bw(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(zw++)[0],s=m.useState(pd)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var y=lw([e.lockRef.current],(e.shards||[]).map(bd),!0).filter(Boolean);return y.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),y.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(y,v){if("touches"in y&&y.touches.length===2||y.type==="wheel"&&y.ctrlKey)return!i.current.allowPinchZoom;var x=Cs(y),w=n.current,S="deltaX"in y?y.deltaX:w[0]-x[0],T="deltaY"in y?y.deltaY:w[1]-x[1],k,C=y.target,E=Math.abs(S)>Math.abs(T)?"h":"v";if("touches"in y&&E==="h"&&C.type==="range")return!1;var _=xd(E,C);if(!_)return!0;if(_?k=E:(k=E==="v"?"h":"v",_=xd(E,C)),!_)return!1;if(!r.current&&"changedTouches"in y&&(S||T)&&(r.current=k),!k)return!0;var j=r.current||k;return Lw(j,v,y,j==="h"?S:T)},[]),l=m.useCallback(function(y){var v=y;if(!(!Mr.length||Mr[Mr.length-1]!==s)){var x="deltaY"in v?wd(v):Cs(v),w=t.current.filter(function(k){return k.name===v.type&&(k.target===v.target||v.target===k.shadowParent)&&Fw(k.delta,x)})[0];if(w&&w.should){v.cancelable&&v.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(bd).filter(Boolean).filter(function(k){return k.contains(v.target)}),T=S.length>0?a(v,S[0]):!i.current.noIsolation;T&&v.cancelable&&v.preventDefault()}}},[]),c=m.useCallback(function(y,v,x,w){var S={name:y,delta:v,target:x,should:w,shadowParent:Hw(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(T){return T!==S})},1)},[]),d=m.useCallback(function(y){n.current=Cs(y),r.current=void 0},[]),f=m.useCallback(function(y){c(y.type,wd(y),y.target,a(y,e.lockRef.current))},[]),h=m.useCallback(function(y){c(y.type,Cs(y),y.target,a(y,e.lockRef.current))},[]);m.useEffect(function(){return Mr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Or),document.addEventListener("touchmove",l,Or),document.addEventListener("touchstart",d,Or),function(){Mr=Mr.filter(function(y){return y!==s}),document.removeEventListener("wheel",l,Or),document.removeEventListener("touchmove",l,Or),document.removeEventListener("touchstart",d,Or)}},[]);var p=e.removeScrollBar,g=e.inert;return m.createElement(m.Fragment,null,g?m.createElement(s,{styles:$w(o)}):null,p?m.createElement(_w,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Hw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Uw=xw(hd,Bw);var ks=m.forwardRef(function(e,t){return m.createElement(bs,In({},e,{ref:t,sideCar:Uw}))});ks.classNames=bs.classNames;var Ww=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Dr=new WeakMap,Ts=new WeakMap,Es={},Ia=0,Sd=function(e){return e&&(e.host||Sd(e.parentNode))},Vw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Sd(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})},qw=function(e,t,n,r){var o=Vw(t,Array.isArray(e)?e:[e]);Es[n]||(Es[n]=new WeakMap);var s=Es[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),g=p!==null&&p!=="false",y=(Dr.get(h)||0)+1,v=(s.get(h)||0)+1;Dr.set(h,y),s.set(h,v),i.push(h),y===1&&g&&Ts.set(h,!0),v===1&&h.setAttribute(n,"true"),g||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),Ia++,function(){i.forEach(function(f){var h=Dr.get(f)-1,p=s.get(f)-1;Dr.set(f,h),s.set(f,p),h||(Ts.has(f)||f.removeAttribute(r),Ts.delete(f)),p||f.removeAttribute(n)}),Ia--,Ia||(Dr=new WeakMap,Dr=new WeakMap,Ts=new WeakMap,Es={})}},Aa=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Ww(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),qw(r,o,n,"aria-hidden")):function(){return null}},Is="Dialog",[Cd,mT]=Tn(Is),[Kw,hn]=Cd(Is),kd=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[c,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:Is});return u.jsx(Kw,{scope:t,triggerRef:a,contentRef:l,contentId:En(),titleId:En(),descriptionId:En(),open:c,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};kd.displayName=Is;var Td="DialogTrigger",Ed=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Td,n),s=He(t,o.triggerRef);return u.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ja(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Ed.displayName=Td;var Na="DialogPortal",[Gw,Id]=Cd(Na,{forceMount:void 0}),Ad=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=hn(Na,t);return u.jsx(Gw,{scope:t,forceMount:n,children:m.Children.map(r,i=>u.jsx(qt,{present:n||s.open,children:u.jsx(ys,{asChild:!0,container:o,children:i})}))})};Ad.displayName=Na;var As="DialogOverlay",Nd=m.forwardRef((e,t)=>{const n=Id(As,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(As,e.__scopeDialog);return s.modal?u.jsx(qt,{present:r||s.open,children:u.jsx(Xw,{...o,ref:t})}):null});Nd.displayName=As;var Yw=sr.createSlot("DialogOverlay.RemoveScroll"),Xw=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(As,n);return u.jsx(ks,{as:Yw,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":ja(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),mr="DialogContent",_d=m.forwardRef((e,t)=>{const n=Id(mr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(mr,e.__scopeDialog);return u.jsx(qt,{present:r||s.open,children:s.modal?u.jsx(Jw,{...o,ref:t}):u.jsx(Zw,{...o,ref:t})})});_d.displayName=mr;var Jw=m.forwardRef((e,t)=>{const n=hn(mr,e.__scopeDialog),r=m.useRef(null),o=He(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Aa(s)},[]),u.jsx(jd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ge(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ge(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault())})}),Zw=m.forwardRef((e,t)=>{const n=hn(mr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return u.jsx(jd,{...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()}})}),jd=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=hn(mr,n),l=m.useRef(null),c=He(t,l);return Sa(),u.jsxs(u.Fragment,{children:[u.jsx(xs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(gs,{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(Qw,{titleId:a.titleId}),u.jsx(tb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),_a="DialogTitle",Rd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(_a,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Rd.displayName=_a;var Pd="DialogDescription",Od=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Pd,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Od.displayName=Pd;var Md="DialogClose",Dd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Md,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Dd.displayName=Md;function ja(e){return e?"open":"closed"}var Ld="DialogTitleWarning",[gT,Fd]=bv(Ld,{contentName:mr,titleName:_a,docsSlug:"dialog"}),Qw=({titleId:e})=>{const t=Fd(Ld),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
79
|
-
|
|
80
|
-
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
81
|
-
|
|
82
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},eb="DialogDescriptionWarning",tb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Fd(eb).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},$d=kd,nb=Ed,zd=Ad,Ns=Nd,_s=_d,gr=Rd,js=Od,Bd=Dd;const rb=$d,ob=zd,Hd=m.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,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}));Hd.displayName=Ns.displayName;const Ud=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const c=l.type;if(c===gr||(c==null?void 0:c.displayName)===gr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(ob,{children:[u.jsx(Hd,{}),u.jsxs(_s,{ref:r,className:oe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(gr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Bd,{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-accent data-[state=open]:text-muted-foreground",children:[u.jsx(me.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Ud.displayName=_s.displayName;const Wd=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Wd.displayName="DialogHeader";const Vd=m.forwardRef(({className:e,...t},n)=>u.jsx(gr,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));Vd.displayName=gr.displayName;const sb=m.forwardRef(({className:e,...t},n)=>u.jsx(js,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));sb.displayName=js.displayName;function ib({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=b.useState(!1),[a,l]=b.useState(null),[c,d]=b.useState(null),{toast:f}=xa(),h=b.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Ju(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);b.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await Wv(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},g=async()=>{if(n)try{const x=await Ju(n),w=new Blob([x],{type:o}),S=URL.createObjectURL(w);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},y=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(me.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Xe,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(me.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),v=()=>o.startsWith("image/")?u.jsx(me.Image,{className:"h-5 w-5"}):u.jsx(me.FileText,{className:"h-5 w-5"});return u.jsx(rb,{open:e,onOpenChange:t,children:u.jsxs(Ud,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Wd,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[v(),u.jsxs("div",{children:[u.jsx(Vd,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Xe,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(me.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Xe,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(me.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:y()})]})})}function qd(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let xr=qd();function ab(e){xr=e}const Kd=/[&<>"']/,lb=new RegExp(Kd.source,"g"),Gd=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,cb=new RegExp(Gd.source,"g"),ub={"&":"&","<":"<",">":">",'"':""","'":"'"},Yd=e=>ub[e];function Mt(e,t){if(t){if(Kd.test(e))return e.replace(lb,Yd)}else if(Gd.test(e))return e.replace(cb,Yd);return e}const db=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Xd(e){return e.replace(db,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const fb=/(^|[^\[])\^/g;function rt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(fb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const hb=/[^\w:]/g,pb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Jd(e,t,n){if(e){let r;try{r=decodeURIComponent(Xd(n)).replace(hb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!pb.test(n)&&(n=yb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Rs={},mb=/^[^:]+:\/*[^/]*$/,gb=/^([^:]+:)[\s\S]*$/,xb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function yb(e,t){Rs[" "+e]||(mb.test(e)?Rs[" "+e]=e+"/":Rs[" "+e]=Os(e,"/",!0)),e=Rs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(gb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(xb,"$1")+t:e+t}const Ps={exec:function(){}};function Zd(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Os(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function vb(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function wb(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function Qd(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function ef(e,t,n,r){const o=t.href,s=t.title?Mt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:Mt(i)}}function bb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
38
|
+
`)}function Ix({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=b.useRef(null),i=b.useCallback(p=>{const g=p.seq??null;if(g!==null){const y=s.current;if(y!==null){if(g<=y)return;g>y+1&&(o==null||o({from:y,to:g}))}s.current=g}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p);try{t(p)}catch(y){console.error("[useChatStreamingService] Error in onThreadInfo handler:",y)}return}if(gx(p)){try{n(p)}catch(y){console.error("[useChatStreamingService] Error in onMessageEvent handler:",y)}return}try{r==null||r(p)}catch(y){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",y)}},[n,o,t,r]),{stream:a,stop:l,isStreaming:c,error:d,setToken:f}=Rc({baseUrl:e,token:null}),h=b.useCallback((p,g)=>{s.current=null,a(p,i,{onOpen:g==null?void 0:g.onOpen,onError:y=>{var v;(v=g==null?void 0:g.onError)==null||v.call(g,y)},onGap:(g==null?void 0:g.onGap)??o})},[i,o,a]);return b.useMemo(()=>({startStream:h,stop:l,isStreaming:c,error:d,setAuthToken:f}),[h,l,c,d,f])}function Pi(e){return e==null?e:{...e}}function Ax(e){return e==null?e:{...e}}function Nx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function _x(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function Qt(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=Pi(e==null?void 0:e.metadata),s=Pi(e==null?void 0:e.config),i=Pi(e==null?void 0:e.parentConfig),a=Nx(e==null?void 0:e.next),l=_x(e==null?void 0:e.tasks),c=Ax(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),c!==void 0&&(d.values=c),d}function jx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function Pc(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}const qo=300;function Oc(e,t=qo){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function cr(){return typeof window<"u"&&typeof window.localStorage<"u"}function Oi(e){if(!cr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Mi(e,t){if(!cr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Di(e){if(cr())try{window.localStorage.removeItem(e)}catch{}}const Rx="cachedThreads",Px="v1",Li=200;function Ox(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Fi(e,t){return`cachedThreads:v1:${e}:${Ox(t||"anon")}`}function Mx(){const e=Oi(Rx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Dx(e){const t=Oi(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function $i(e,t){Mi(e,JSON.stringify(t))}function zi(e){const t=Dx(e);if(t.length>0)return t;const n=Mx();if(n.length>0)try{$i(e,n.slice(0,Li))}catch{}return n}function Ko(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function Bi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Hi(e,t){return`${e}${t}`}function Lx(e,t){const n=Oi(Hi(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:Qt(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function Fx(e,t,n=100){if(!cr())return;const r=Qt(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=Hi(e,t.threadId),i=JSON.stringify(o);if(!Mi(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const c=window.localStorage.key(l);if(!c||c===s||!c.startsWith(e))continue;const d=window.localStorage.getItem(c);if(!d){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:c,updatedAt:h})}catch{a.push({key:c,updatedAt:0})}}a.sort((l,c)=>l.updatedAt-c.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),Mi(s,i))break}catch{}}function $x(e,t){Di(Hi(e,t))}function zx(e){if(cr())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}const Mc=b.createContext(null),Dc=b.createContext(null),Lc=b.createContext(null),Bx=b.createContext(!1),Fc=50,Hx=750;function $c(e,t,n){return`${e}__${t??""}__${n??""}`}function Go(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Ux(e,t){return Go(e,t)}function Wx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function Vx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function zc(e,t){const n=Go(e.metadata,t.metadata),r=Go(e.config,t.config),o=Go(e.parentConfig,t.parentConfig),s=Wx(e.next,t.next),i=Vx(e.tasks,t.tasks),a=Ux(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function qx({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:c}=Ni(),d=b.useMemo(()=>$n(c),[c]),f=b.useMemo(()=>{try{return new URL(c).host}catch{return"unknown"}},[c]),h=b.useMemo(()=>`threadPayload:${Px}:${f}:`,[f]),p=b.useCallback(A=>Lx(h,A),[h]),g=b.useCallback((A,N=100)=>{Fx(h,A,N)},[h]),y=b.useCallback(A=>{$x(h,A)},[h]),v=b.useCallback(()=>{zx(h)},[h]),[x,w]=b.useState(()=>{var A;return Fi(f,(A=l.getAuthToken)==null?void 0:A.call(l))}),[S,T]=b.useState(()=>{var N;const A=zi(Fi(f,(N=l.getAuthToken)==null?void 0:N.call(l)));return Ko(A)}),k=b.useMemo(()=>Bi(S),[S]),[C,E]=b.useState(t),[_,j]=b.useState(!1),[D,F]=b.useState(!1),[K,P]=b.useState(null),[R,L]=b.useState(null),[U,te]=b.useState(null),[V,z]=b.useState([]),G=b.useCallback(()=>{const A=zi(x);b.startTransition(()=>{T(Ko(A))})},[x]),[Q,le]=b.useState(!1),[B,ie]=b.useState(!1),[Ce,ke]=b.useState(null),[q,M]=b.useState(void 0),[X,ne]=b.useState(void 0),[xe,se]=b.useState(void 0),{state:ae,dispatch:Ue,seed:Ke,prepend:ot,pushUser:st,onEvent:ut,reset:et}=kc(),De=b.useRef(C);b.useEffect(()=>{De.current=C},[C]);const We=b.useRef(!1),it=b.useRef([]),gt=b.useRef(null),re=b.useRef(null),ve=b.useRef(new Map),we=b.useRef(C),Ye=b.useRef(!1),xt=b.useRef(null),ft=b.useRef(new Map),wt=b.useRef(new Map),Fe=b.useRef(new Map),Ze=b.useRef(new Map),Tt=b.useCallback(A=>{if(!A){z([]);return}const N=ft.current.get(A);if(!N||!N.length){z([]);return}z(N.map(Y=>Qt(Y,{cloneMessages:!0})))},[]);b.useEffect(()=>{Tt(C)},[C,Tt]);const St=b.useCallback(()=>{var ee;const A=Ze.current;if(A.size<=Fc)return;const N=Array.from(A.entries()).sort((ce,Z)=>ce[1].timestamp-Z[1].timestamp),Y=A.size-Fc;for(let ce=0;ce<Y;ce++){const Z=(ee=N[ce])==null?void 0:ee[0];Z&&A.delete(Z)}},[]),Yt=b.useCallback((A,N,Y)=>{if(!A)return;const ee=Y==="replace"?[]:ft.current.get(A)??[],ce=Y==="replace"?N:[...N,...ee];if(!ce.length){Y==="replace"&&ft.current.set(A,[]);return}const Z=new Map;for(const Be of ce){if(!(Be!=null&&Be.checkpointId))continue;const Oe=`${Be.checkpointId}::${Be.checkpointNs??""}`,Qe=Qt(Be,{cloneMessages:!0}),yt=Z.get(Oe);if(!yt){Z.set(Oe,Qe);continue}const Nt=zc(yt,Qe);Z.set(Oe,{...yt,...Nt})}const ze=Array.from(Z.values()).sort((Be,Oe)=>{const Qe=Number.isFinite(Date.parse(Be.createdAt??""))?Date.parse(Be.createdAt??""):0;return(Number.isFinite(Date.parse(Oe.createdAt??""))?Date.parse(Oe.createdAt??""):0)-Qe});ft.current.set(A,ze),A===De.current&&Tt(A)},[Tt]),Et=b.useCallback((A,N,Y)=>{if(!A)return;const ee=wt.current.get(A),ce=Y==="replace"||!ee?new Map:new Map(ee);if(N&&typeof N=="object")for(const[Z,ze]of Object.entries(N)){if(!(ze!=null&&ze.checkpointId))continue;const Be=Z||Qr(ze.checkpointId,ze.checkpointNs??null);ce.set(Be,Qt(ze,{cloneMessages:!0}))}wt.current.set(A,ce)},[]),rr=b.useCallback((A,N)=>{const{threadId:Y,checkpointId:ee=null,checkpointNs:ce=null}=A,Z=$c(Y,ee,ce);if(N!=null&&N.force)Fe.current.delete(Z),Ze.current.delete(Z);else{if(N!=null&&N.preferCache){const Qe=Ze.current.get(Z);if(Qe)return Promise.resolve(Qe.payload)}const Oe=Fe.current.get(Z);if(Oe)return Oe}const Be=l.getStateHistory({threadId:Y,checkpointId:ee??void 0,checkpointNs:ce??void 0}).then(Oe=>(Ze.current.set(Z,{payload:Oe,timestamp:Date.now()}),St(),Oe)).finally(()=>{Fe.current.get(Z)===Be&&Fe.current.delete(Z)});return Fe.current.set(Z,Be),Be},[l,St]),Xt=b.useCallback((A,N)=>new Promise((Y,ee)=>{const ce=async()=>{We.current=!0;try{await A(),Y()}catch(Z){ee(Z)}finally{We.current=!1;const Z=it.current.shift();Z&&Z().catch(()=>{})}};We.current?it.current.push(ce):ce().catch(Z=>{ee(Z)})}),[]),xn=b.useRef(k.length),sn=b.useRef(!1);b.useEffect(()=>{xn.current=k.length},[k.length]),b.useEffect(()=>{const A=ae.pendingInterrupt??jx(ae.messages);Pc(U,A)||te(A??null)},[U,ae.messages,ae.pendingInterrupt]);const Dt=b.useCallback(async()=>{const A=xn.current>0;A||j(!0);try{const N=await l.listThreads();b.startTransition(()=>{T(Y=>{const ee=ze=>ze.map(Be=>`${Be.threadId}:${Be.updatedAt??""}:${Be.messageCount??""}`).join("|"),ce=Bi(Y);return ee(ce)===ee(N)||N.length===0&&ce.length>0&&!sn.current?Y:Ko(N)})}),P(null),sn.current||(sn.current=!0)}catch(N){i==null||i(String(N)),console.error("[ChatSessionProvider] Failed to refresh threads:",N),P(String(N))}finally{A||j(!1)}},[l,i]),Pn=b.useRef(!1),yn=b.useRef(null),ht=b.useRef(null),vn=b.useRef(""),On=b.useCallback((A,N)=>{if(!cr())return;ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null);const Y=A.map(ce=>`${ce.threadId}:${ce.updatedAt??""}:${ce.messageCount??""}`).join("|");if(A.length===0){try{Di(x)}catch{}vn.current="";return}if(Y===vn.current)return;const ee=()=>{try{const ce=A.slice(0,Li);$i(x,ce),vn.current=Y}catch{}finally{ht.current=null}};if(N!=null&&N.immediate){ee();return}ht.current=window.setTimeout(()=>{Oc(ee)},qo)},[x]),kr=b.useCallback(()=>{On(k,{immediate:!0})},[On,k]),Jt=b.useCallback((A,N,Y,ee)=>{var Sm;const ce=Y??De.current;if(!ce)return;const Z=Qt(A),ze=ce===De.current,Be=(ee==null?void 0:ee.persist)!==!1;if(N==="replace"){if(Be){const It={threadId:ce,snapshot:Qt(A,{cloneMessages:!0})};ve.current.set(ce,It),we.current=ce}if(!ze)return;Ke(Z.messages,{checkpointId:Z.checkpointId??null,checkpointNs:Z.checkpointNs??null,pendingInterrupt:Z.interrupt??null}),te(Z.interrupt??null),ke(Z.nextCursor??null),le(!!Z.nextCursor),M(Z.checkpointId??void 0),ne(Z.checkpointNs??void 0),se(Z.nextCursorNs??void 0);return}const Oe=ve.current.get(ce),Qe=(Oe==null?void 0:Oe.snapshot)??null,yt=Array.isArray(Qe==null?void 0:Qe.messages)?Qe.messages:[],Nt=Qt(Qe),Dn=Array.isArray(A==null?void 0:A.messages)?A.messages:[],_t=new Set,jt=[...Dn,...yt].filter(It=>{const Sl=It==null?void 0:It.id;return Sl?_t.has(Sl)?!1:(_t.add(Sl),!0):!0}),No=zc(Nt,Z),_o={checkpointId:Nt.checkpointId??Z.checkpointId??null,checkpointNs:Nt.checkpointNs??Z.checkpointNs??null,createdAt:Z.createdAt??Nt.createdAt??null,parentId:Z.parentId??Nt.parentId??null,branchLabel:Z.branchLabel??Nt.branchLabel??null,lastMessageId:((Sm=jt[jt.length-1])==null?void 0:Sm.id)??null,messagesLen:jt.length,hasMessages:jt.length>0,messages:jt,nextCursor:Z.nextCursor??Nt.nextCursor??null,nextCursorNs:Z.nextCursorNs??Nt.nextCursorNs??null,interrupt:Nt.interrupt??Z.interrupt??null,...No};if(ve.current.set(ce,{threadId:ce,snapshot:Qt(_o,{cloneMessages:!0})}),!ze)return;Dn.length&&ot(Dn);const Ln=A&&Object.prototype.hasOwnProperty.call(A,"checkpointId")?A.checkpointId:void 0,jo=A&&Object.prototype.hasOwnProperty.call(A,"checkpointNs")?A.checkpointNs:void 0,Fn=A&&Object.prototype.hasOwnProperty.call(A,"nextCursor")?A.nextCursor:void 0,bl=A&&Object.prototype.hasOwnProperty.call(A,"nextCursorNs")?A.nextCursorNs:void 0;ke(It=>Fn!==void 0?Fn??It??null:It??null),le(It=>Fn!==void 0?!!Fn:It),M(It=>Ln!==void 0?Ln??It??void 0:It??void 0),ne(It=>jo!==void 0?jo??It??void 0:It??void 0),se(It=>bl!==void 0?bl??void 0:It)},[ot,Ke,te]),Tr=b.useCallback(A=>{if(A.threadId!=null&&A.threadId!==De.current)return;const N=Qt(A.snapshot,{cloneMessages:!0});Ke(N.messages,{checkpointId:N.checkpointId??null,checkpointNs:N.checkpointNs??null,pendingInterrupt:N.interrupt??null}),te(N.interrupt??null),ke(N.nextCursor??null),le(!!N.nextCursor),M(N.checkpointId??void 0),ne(N.checkpointNs??void 0),se(N.nextCursorNs??void 0),we.current=A.threadId,Tt(A.threadId??De.current??null)},[Ke,te,Tt]),Mn=b.useCallback(A=>{if(!A)return;ve.current.delete(A),y(A),ft.current.delete(A),wt.current.delete(A),A===De.current&&z([]);const N=`${A}__`;for(const Y of Fe.current.keys())Y.startsWith(N)&&Fe.current.delete(Y);for(const Y of Ze.current.keys())Y.startsWith(N)&&Ze.current.delete(Y);we.current===A&&(we.current=null)},[y]),wn=b.useCallback(()=>{const A=De.current;A&&Mn(A),et([]),le(!1),ie(!1),ke(null),M(void 0),ne(void 0),se(void 0)},[Mn,et]),Un=b.useCallback(({from:A,to:N})=>{const Y=De.current;Y&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${A} -> ${N}) for thread ${Y}`)},[]),Er=b.useCallback(A=>{const N=A.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:N,title:A.title,created:A.created,currentThreads:k.length});const Y={threadId:N,title:A.title||`Thread ${N.slice(0,8)}`,createdAt:A.createdAt||new Date().toISOString(),updatedAt:A.updatedAt||new Date().toISOString(),messageCount:A.messageCount||0};De.current!==N&&(!De.current&&ae.messages.length<=1&&(re.current=N),E(N)),b.startTransition(()=>{T(ee=>{const ce=ee.byId[N];return ce?ce.title===Y.title&&ce.updatedAt===Y.updatedAt&&ce.messageCount===Y.messageCount?ee:{byId:{...ee.byId,[N]:Y},order:ee.order}:{byId:{...ee.byId,[N]:Y},order:[N,...ee.order]}})})},[ae.messages.length]),{startStream:Wr,stop:Vr,isStreaming:or,error:I,setAuthToken:H}=Ix({baseUrl:d,onThreadInfo:Er,onMessageEvent:ut,onUnhandledEvent:A=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${A.type}`,A)},onSequenceGap:Un});b.useEffect(()=>{Pn.current=or},[or]),b.useEffect(()=>{if(!cr())return;ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null);const A=k.map(Y=>`${Y.threadId}:${Y.updatedAt??""}:${Y.messageCount??""}`).join("|");if(k.length===0){try{Di(x)}catch{}vn.current="";return}if(A===vn.current)return;const N=()=>{try{const Y=k.slice(0,Li);$i(x,Y),vn.current=A}catch{}finally{ht.current=null}};return ht.current=window.setTimeout(()=>{Oc(N),ht.current=null},qo),()=>{ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null)}},[k,On]),b.useEffect(()=>{var ee;const A=l.getAuthToken();H(A);const N=ce=>{const Z=Fi(f,ce);xt.current!==Z&&(xt.current=Z,Ye.current=!1),w(Z);const ze=zi(Z);b.startTransition(()=>{T(Ko(ze))}),ce&&!Ye.current&&(Ye.current=!0)};N(A);const Y=(ee=l.onTokenChange)==null?void 0:ee.call(l,ce=>{ce!==A&&(H(ce),v(),Fe.current.clear(),Ze.current.clear(),N(ce))});return()=>{Y==null||Y()}},[l,f,H,v]);const ue=b.useCallback(async A=>{var ee;const N=`Thread ${(ee=crypto.randomUUID)==null?void 0:ee.call(crypto)}`,Y={threadId:N,title:A||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};T(ce=>({byId:{...ce.byId,[N]:Y},order:[N,...ce.order]})),E(N);try{const ce=await l.createThread(A),Z=typeof ce=="string"?ce:ce.threadId;return T(ze=>{const Be=ze.byId[N];if(!Be)return ze;const Oe={...ze.byId};delete Oe[N],Oe[Z]={...Be,threadId:Z};const Qe=ze.order.map(yt=>yt===N?Z:yt);return{byId:Oe,order:Qe}}),E(Z),setTimeout(()=>Dt(),10),P(null),Z}catch(ce){throw T(Z=>{if(!Z.byId[N])return Z;const ze={...Z.byId};delete ze[N];const Be=Z.order.filter(Oe=>Oe!==N);return{byId:ze,order:Be}}),E(null),P(String(ce)),ce}},[l,Dt]),Te=b.useCallback(async A=>{try{await l.deleteThread(A);let N=null;T(Y=>{if(!Y.byId[A])return Y;const ee={...Y.byId};delete ee[A];const ce=Y.order.filter(ze=>ze!==A),Z={byId:ee,order:ce};return N=Bi(Z),Z}),N&&On(N,{immediate:!0}),Mn(A),De.current===A&&(re.current=A,E(null),De.current=null,we.current=null,wn()),await Dt(),P(null)}catch(N){throw P(String(N)),N}},[l,wn,Mn,Dt,On]),qe=b.useCallback(async(A,N)=>{try{await l.updateThread(A,N),T(Y=>{const ee=Y.byId[A];return ee?{byId:{...Y.byId,[A]:{...ee,title:N}},order:Y.order}:Y}),P(null)}catch(Y){throw await Dt(),P(String(Y)),Y}},[l,Dt]),$e=b.useCallback(async(A,N,Y,ee=!1)=>{await Xt(async()=>{if(re.current===A&&!ee){re.current=null;return}if(gt.current===A&&!ee)return;E(_t=>_t===A?_t:A),De.current=A;const ze=$c(A,N??null,Y??null),Be=Ze.current.get(ze),Oe=!ee&&!N&&!Y&&Be&&Date.now()-Be.timestamp<Hx,Qe=!ee&&!N&&!Y;let yt=!1;if(Qe){const _t=ve.current.get(A);if(_t)Tr(_t),yt=!0;else{const jt=p(A);jt&&(ve.current.set(A,jt),Tr(jt),yt=!0)}}const Nt=ee||!yt||!!N||!!Y,Dn=async _t=>{_t&&F(!0),gt.current=A;try{const jt=await rr({threadId:A,checkpointId:N,checkpointNs:Y},{force:ee}),{latest:No,checkpoints:_o,snapshots:Ln}=ji(jt);Jt(No,"replace",A),Yt(A,_o,"replace"),Et(A,Ln,"replace"),L(null)}catch(jt){throw(!yt||ee||_t)&&(i==null||i(String(jt))),L(String(jt)),jt}finally{gt.current=null,_t&&F(!1)}};Nt?await Dn(!0):Qe&&yt&&!Oe&&Dn(!1).catch(_t=>{console.warn("[ChatSessionProvider] Background refresh failed:",_t)})},`loadThread-${A}`)},[Tr,Jt,Xt,rr,i,Yt,Et]),Le=b.useCallback(async()=>{await Xt(async()=>{const A=De.current;A&&Mn(A),re.current=null,E(null),De.current=null,we.current=null,wn(),M(void 0),ne(void 0),se(void 0),z([]);try{localStorage.removeItem("lastThreadId")}catch(N){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",N)}},"clearCurrentThread")},[wn,Mn,Xt]),$=b.useCallback(async(A,N)=>{var Z;const Y=De.current;if(!Y)throw new Error("No active thread");const ee=Qr(A,N??null),ce=(Z=wt.current.get(Y))==null?void 0:Z.get(ee);if(ce){await Xt(async()=>{Jt(ce,"replace",Y,{persist:!1})},`navigateToCheckpoint-${Y}-${ee}`);return}await $e(Y,A,N??void 0,!0)},[Jt,Xt,$e]),de=b.useCallback(async()=>{if(!De.current)throw new Error("No active thread");await $e(De.current,void 0,void 0,!0)},[$e]),he=b.useCallback(async()=>{if(!De.current)throw new Error("No active thread");if(B||!Q)return;const A=Ce;if(A){ie(!0);try{const N=De.current,Y=await rr({threadId:N,checkpointId:A??q??null,checkpointNs:xe??X??null}),{latest:ee,checkpoints:ce,snapshots:Z}=ji(Y),ze=N?wt.current.get(N):null;let Be=ce.length>0;if(Be&&ze&&ze.size>0&&(Be=ce.some(Oe=>{if(!(Oe!=null&&Oe.checkpointId))return!1;const Qe=Qr(Oe.checkpointId,Oe.checkpointNs??null);return!ze.has(Qe)})),!Be){ke(null),se(void 0),le(!1),L(null);return}Jt(ee,"prepend",N??void 0),N&&(Yt(N,ce,"prepend"),Et(N,Z,"prepend")),L(null)}catch(N){throw L(String(N)),N}finally{ie(!1)}}},[Jt,rr,Q,q,X,xe,Ce,B,Yt,Et]),Ie=b.useCallback(A=>{if(A!=null&&A.threadId){if(A.checkpointId){const N=Qr(A.checkpointId,A.checkpointNs??null),Y=Qt({...A,interrupt:A.interrupt??null},{cloneMessages:!0});Et(A.threadId,{[N]:Y},"prepend")}Jt(A,"replace",A.threadId)}},[Jt,Et]),tt=b.useCallback(async(A,N)=>{var jo;const Y=De.current,ee=(A==null?void 0:A.text)??"",ce=(A==null?void 0:A.attachments)??[],Z=ce.length?ce:(N==null?void 0:N.attachments)??[],ze={...(N==null?void 0:N.payloadExtras)??{},...(A==null?void 0:A.payload)??{}};if(!Y&&!Object.keys(ze).length&&Z.length===0&&!ee.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!Y&&!ze.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Be,filesInfo:Oe}=await Qg(l,Z),Qe=[...Be];ee&&ee.trim()&&Qe.push({type:"text",text:ee.trim()});const yt=!!Y,Nt=yt?(N==null?void 0:N.checkpointId)??ae.lastCheckpointId??void 0:void 0,Dn=yt?(N==null?void 0:N.checkpointNs)??ae.lastCheckpointNs??void 0:void 0,_t={id:((jo=crypto.randomUUID)==null?void 0:jo.call(crypto))||`user-${Date.now()}`,role:"user",content:Qe,createdAt:new Date().toISOString(),...Nt!=null?{checkpointId:Nt}:{},...Dn!=null?{checkpointNs:Dn}:{}};Qe.length>0&&st(_t);const jt={..._t,content:Qe},No=Z.length>0,_o={messages:Qe.length>0?[jt]:[],files_info:Oe,...o&&No&&s?{active_agent:s}:{},...ze},Ln={threadId:Y??null,payload:_o,checkpointId:Nt??null,checkpointNs:Dn??null,nodeFilter:(N==null?void 0:N.nodeFilter)??null,config:N==null?void 0:N.config,command:(N==null?void 0:N.command)??null};Ln.threadId||delete Ln.threadId,Ln.command||delete Ln.command,Wr(Ln,{onError:Fn=>{console.warn("[ChatSessionProvider] Stream error:",Fn)},onOpen:({threadId:Fn})=>{!De.current&&Fn&&(ae.messages.length<=1&&(re.current=Fn),E(Fn))},onGap:Un})},[l,o,s,Un,ae.lastCheckpointId,ae.lastCheckpointNs,ae.messages.length,st,Wr]),Lt=b.useCallback(async(A,N,Y)=>{if(!De.current)throw new Error("No active thread to handle interrupt");const ce=N?Y??!0:!1;try{try{Ue({type:"interrupt_response",payload:{interruptId:A}})}catch(Z){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Z)}await tt({payload:{}},{checkpointId:ae.lastCheckpointId??void 0,checkpointNs:ae.lastCheckpointNs??void 0,command:{kind:"resume",value:ce}}),te(null)}catch(Z){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${A}:`,Z),Z}},[Ue,ae.lastCheckpointId,ae.lastCheckpointNs,tt]);b.useEffect(()=>{if(a==null||a(C),C)try{localStorage.setItem("lastThreadId",C)}catch(A){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",A)}},[C,a]),b.useEffect(()=>((async()=>{try{if(Dt().catch(N=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",N),i==null||i(String(N))}),!r&&!t)try{const N=localStorage.getItem("lastThreadId");N&&(E(N),n&&await $e(N))}catch(N){console.warn("[ChatSessionProvider] Failed to restore last thread:",N)}else t&&n&&await $e(t)}catch(N){console.error("[ChatSessionProvider] Initialization failed:",N),i==null||i(String(N))}})(),()=>{}),[]),b.useEffect(()=>{const A=De.current;if(!A||we.current!==A)return;ae.messages.length&&ae.messages[ae.messages.length-1];const N=Qt({checkpointId:ae.lastCheckpointId??null,checkpointNs:ae.lastCheckpointNs??null,messages:ae.messages.slice(),nextCursor:Ce??null,nextCursorNs:xe??null,interrupt:ae.pendingInterrupt??U??null}),Y=ve.current.get(A),ee=Y==null?void 0:Y.snapshot,ce=!ee||ee.messages.length!==N.messages.length||ee.messages.some((Oe,Qe)=>{var yt;return(Oe==null?void 0:Oe.id)!==((yt=N.messages[Qe])==null?void 0:yt.id)}),Z=((ee==null?void 0:ee.checkpointId)??null)!==N.checkpointId||((ee==null?void 0:ee.checkpointNs)??null)!==N.checkpointNs,ze=((ee==null?void 0:ee.nextCursor)??null)!==N.nextCursor||((ee==null?void 0:ee.nextCursorNs)??null)!==N.nextCursorNs,Be=!Pc((ee==null?void 0:ee.interrupt)??null,N.interrupt??null);if(ce||Z||ze||Be){const Oe={threadId:A,snapshot:N};ve.current.set(A,Oe),yn.current&&window.clearTimeout(yn.current),yn.current=window.setTimeout(()=>{try{g(Oe,100)}catch(Qe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",Qe)}},qo)}},[Ce,xe,ae.lastCheckpointId,ae.lastCheckpointNs,ae.messages,ae.pendingInterrupt,U,g]);const an=b.useMemo(()=>({threads:k,currentThreadId:C,setCurrentThreadId:E,isLoading:_,error:K,actions:{createThread:ue,deleteThread:Te,renameThread:qe,refreshThreads:()=>Dt()},persistThreadsCache:kr,hydrateFromCache:G}),[k,C,_,K,ue,Te,qe,Dt,kr,G,E]),Ct=b.useMemo(()=>{const A=ae.lastBranch??null,N=ae.assemblingId??null,Y=A||N?{branchLabel:(A==null?void 0:A.branchLabel)??null,lastBranch:A,assemblingMessageId:N}:null;return{threadId:C,messages:ae.messages,interrupt:U,checkpoint:{id:ae.lastCheckpointId??null,namespace:ae.lastCheckpointNs??null},checkpoints:V,metadata:Y,isLoading:D,isHistoryLoading:B,error:R,hasMore:Q,loadOlder:he,seedFromSnapshot:Ie,clearState:wn,navigateToCheckpoint:$,returnToLatest:de,loadThread:$e,clearThread:Le,respondToInterrupt:Lt}},[Le,wn,C,U,Q,B,D,he,$e,ae.assemblingId,ae.lastBranch,ae.lastCheckpointId,ae.lastCheckpointNs,ae.messages,$,Lt,de,Ie,R,V]),Ao=b.useMemo(()=>({isStreaming:or,error:I,submit:tt,send:tt,stop:Vr,setAuthToken:H}),[or,I,tt,Vr,H]);return u.jsx(Bx.Provider,{value:!0,children:u.jsx(Lc.Provider,{value:Ao,children:u.jsx(Mc.Provider,{value:an,children:u.jsx(Dc.Provider,{value:Ct,children:e})})})})}function Yo(){const e=b.useContext(Mc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Xo(){const e=b.useContext(Dc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Bc(){const e=b.useContext(Lc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Jo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return u.jsx(Jg,{apiConfig:t,children:u.jsx(qx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function oe(...e){return Em.twMerge(Tm.clsx(e))}const Kx=Ro.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Xe=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?sr.Slot:"button";return u.jsx(i,{className:oe(Kx({variant:t,size:n,className:e})),ref:s,...o})});Xe.displayName="Button";const Hc=m.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}));Hc.displayName="Textarea";function Gx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const g=i!==void 0,[y,v]=b.useState(e),x=(g?i:y)??"",[w,S]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{g||(v(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,g]);const E=b.useCallback(()=>{const L=T.current;L&&(L.style.height="auto",L.style.height=`${L.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,x]);const _=b.useCallback((L,{fromUser:U})=>{g||v(L),U&&(a==null||a(L))},[g,a]),j=b.useCallback(async L=>{L&&L.preventDefault();const U=(x??"").trim();if(!U&&!p)return;const te=++k.current;C.current={id:te,shouldClear:!0},S(()=>{var V,z,G;try{const Q=l(U);Q&&typeof Q.then=="function"?Q.then(()=>{var le,B;((le=C.current)==null?void 0:le.id)===te&&C.current.shouldClear&&(g||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((B=C.current)==null?void 0:B.id)===te&&(C.current=null)}).catch(()=>{var le;((le=C.current)==null?void 0:le.id)===te&&(C.current=null)}):(((V=C.current)==null?void 0:V.id)===te&&C.current.shouldClear&&(g||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((z=C.current)==null?void 0:z.id)===te&&(C.current=null))}catch{((G=C.current)==null?void 0:G.id)===te&&(C.current=null)}})},[x,l,p,g,a]),D=b.useCallback(L=>{const U=L.target.value;_(U,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[_]),F=b.useCallback(L=>{L.key==="Enter"&&!L.shiftKey?(L.preventDefault(),j()):L.key==="Escape"&&t&&(L.preventDefault(),c==null||c())},[j,t,c]),R=`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))]":""} ${h}`;return u.jsx("form",{onSubmit:L=>void j(L),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(Hc,{ref:T,value:x,onChange:D,onKeyDown:F,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Xe,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(me.Square,{size:16})}):u.jsx(Xe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||w,children:u.jsx(me.Send,{size:16})})})]})})}const Yx=b.memo(Gx),Zo=0,Vn=1,_r=2,Uc=4;function Wc(e){return()=>e}function Xx(e){e()}function Vc(e,t){return n=>e(t(n))}function qc(e,t){return()=>e(t)}function Jx(e,t){return n=>e(t,n)}function Ui(e){return e!==void 0}function Zx(...e){return()=>{e.map(Xx)}}function jr(){}function Qo(e,t){return t(e),e}function Qx(e,t){return t(e)}function at(...e){return e}function Je(e,t){return e(Vn,t)}function Pe(e,t){e(Zo,t)}function Wi(e){e(_r)}function mt(e){return e(Uc)}function ye(e,t){return Je(e,Jx(t,Zo))}function dn(e,t){const n=e(Vn,r=>{n(),t(r)});return n}function Kc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Gc(e,t){return e===t}function lt(e=Gc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function fe(e){return t=>Vc(t,e)}function Sn(e){return t=>()=>{t(e)}}function W(e,...t){const n=ey(...t);return(r,o)=>{switch(r){case _r:Wi(e);return;case Vn:return Je(e,n(o))}}}function Cn(e,t){return n=>r=>{n(t=e(t,r))}}function ur(e){return t=>n=>{e>0?e--:t(n)}}function zn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Me(...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 ey(...e){return t=>e.reduceRight(Qx,t)}function ty(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Vn:return s?n===s?void 0:(r(),n=s,t=Je(e,s),t):(r(),jr);case _r:r(),n=null;return}}}function J(e){let t=e;const n=Ve();return(r,o)=>{switch(r){case Zo:t=o;break;case Vn:{o(t);break}case Uc:return t}return n(r,o)}}function Pt(e,t){return Qo(J(t),n=>ye(e,n))}function Ve(){const e=[];return(t,n)=>{switch(t){case Zo:e.slice().forEach(r=>{r(n)});return;case _r:e.splice(0,e.length);return;case Vn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Wt(e){return Qo(Ve(),t=>ye(e,t))}function Ge(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:ny(),singleton:n}}const ny=()=>Symbol();function ry(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 vt(...e){const t=Ve(),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&&Pe(t,n)})}),function(s,i){switch(s){case _r:{Wi(t);return}case Vn:return r===o&&i(n),Je(t,i)}}}function Ee(e,t=Gc){return W(e,lt(t))}function Vi(...e){return function(t,n){switch(t){case _r:return;case Vn:return Zx(...e.map(r=>Je(r,n)))}}}var Ut=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ut||{});const oy={0:"debug",3:"error",1:"log",2:"warn"},sy=()=>typeof globalThis>"u"?window:globalThis,qn=Ge(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=sy().VIRTUOSO_LOG_LEVEL)!=null?o:mt(e);r>=s&&console[oy[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function dr(e,t,n){return qi(e,t,n).callbackRef}function qi(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 iy(e,t,n,r,o,s,i,a,l){const c=b.useCallback(d=>{const f=ay(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let g;p&&(g=h.ownerDocument.defaultView);const y=i?a?i.scrollLeft:i.scrollTop:p?a?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:p?a?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?g.innerWidth:g.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(y,0),viewportHeight:x}),s==null||s(a?Yc("column-gap",getComputedStyle(d).columnGap,o):Yc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return qi(c,n,l)}function ay(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},Ut.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Yc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ut.WARN),t==="normal"?0:parseInt(t??"0",10)}function Xc(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 f,h;if(t){const p=t.getBoundingClientRect(),g=c.top-p.top;h=p.height-Math.max(0,g),f=g+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=qi(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 Ft=Ge(()=>{const e=Ve(),t=Ve(),n=J(0),r=Ve(),o=J(0),s=Ve(),i=Ve(),a=J(0),l=J(0),c=J(0),d=J(0),f=Ve(),h=Ve(),p=J(!1),g=J(!1),y=J(!1);return ye(W(e,fe(({scrollTop:v})=>v)),t),ye(W(e,fe(({scrollHeight:v})=>v)),i),ye(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:g,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:y,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),to={lvl:0};function Jc(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 nt(e){return e===to}function no(e,t){if(!nt(e))return t===e.k?e.v:t<e.k?no(e.l,t):no(e.r,t)}function fn(e,t,n="k"){if(nt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=fn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return fn(e.l,t,n)}function Vt(e,t,n){return nt(e)?eu(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?tu(bt(e,{l:Vt(e.l,t,n)})):tu(bt(e,{r:Vt(e.r,t,n)}))}function Rr(){return to}function es(e,t,n){if(nt(e))return[];const r=fn(e,t)[0];return ly(Gi(e,r,n))}function Ki(e,t){if(nt(e))return to;const{k:n,l:r,r:o}=e;if(t===n){if(nt(r))return o;if(nt(o))return r;{const[s,i]=Qc(r);return ts(bt(e,{k:s,l:Zc(r),v:i}))}}else return t<n?ts(bt(e,{l:Ki(r,t)})):ts(bt(e,{r:Ki(o,t)}))}function fr(e){return nt(e)?[]:[...fr(e.l),{k:e.k,v:e.v},...fr(e.r)]}function Gi(e,t,n){if(nt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Gi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Gi(s,t,n))),a}function ts(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(Yi(t))return nu(bt(e,{lvl:n-1}));if(!nt(t)&&!nt(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(Yi(e))return Xi(bt(e,{lvl:n-1}));if(!nt(r)&&!nt(r.l)){const o=r.l,s=Yi(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Xi(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return eu(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 Zc(e){return nt(e.r)?e.l:ts(bt(e,{r:Zc(e.r)}))}function Yi(e){return nt(e)||e.lvl>e.r.lvl}function Qc(e){return nt(e.r)?[e.k,e.v]:Qc(e.r)}function eu(e,t,n,r=to,o=to){return{k:e,l:r,lvl:n,r:o,v:t}}function tu(e){return Xi(nu(e))}function nu(e){const{l:t}=e;return!nt(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function Xi(e){const{lvl:t,r:n}=e;return!nt(n)&&!nt(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function ly(e){return Jc(e,({k:t,v:n})=>({index:t,value:n}))}function ru(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function ro(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ji=Ge(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function ou(e,t,n){return e[ns(e,t,n)]}function ns(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 cy(e,t,n,r){const o=ns(e,t,r),s=ns(e,n,r,o);return e.slice(o,s+1)}function Kn(e,t){return Math.round(e.getBoundingClientRect()[t])}function rs(e){return!nt(e.groupOffsetTree)}function Zi({index:e},t){return t===e?0:t<e?-1:1}function uy(){return{groupIndices:[],groupOffsetTree:Rr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Rr()}}function dy(e,t){let n=nt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),nt(e)){e=Vt(e,0,s);continue}const a=es(e,i-1,o+1);if(a.some(yy(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Ki(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Vt(e,o+1,h));c&&(e=Vt(e,i,s))}return[e,n]}function fy(e){return typeof e.groupIndex<"u"}function hy({offset:e},t){return t===e?0:t<e?-1:1}function oo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ou(t,e,Zi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function su(e,t){if(!rs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function iu(e,t,n){if(fy(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=su(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function py(e,t,n,r=0){return r>0&&(t=Math.max(t,ou(e,r,Zi).offset)),Jc(cy(e,t,n,hy),xy)}function my(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ut.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&nt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((g,y)=>Vt(Vt(g,y,h),y+1,p),i)}else[i,a]=dy(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=Qi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Vt(h,p,oo(p,f,o)),Rr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function gy(e){return fr(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 au(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 Qi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ns(o,t-1,Zi),a=o[l].offset;const c=fn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===fn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of es(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function xy(e){return{index:e.index,value:e}}function yy(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 vy={offsetHeight:"height",offsetWidth:"width"},kn=Ge(([{log:e},{recalcInProgress:t}])=>{const n=Ve(),r=Ve(),o=Pt(r,0),s=Ve(),i=Ve(),a=J(0),l=J([]),c=J(void 0),d=J(void 0),f=J((k,C)=>Kn(k,vy[C])),h=J(void 0),p=J(0),g=uy(),y=Pt(W(n,Me(l,e,p),Cn(my,g),lt()),g),v=Pt(W(l,lt(),Cn((k,C)=>({current:C,prev:k.current}),{current:[],prev:[]}),fe(({prev:k})=>k)),[]);ye(W(l,Ae(k=>k.length>0),Me(y,p),fe(([k,C,E])=>{const _=k.reduce((j,D,F)=>Vt(j,D,oo(D,C.offsetTree,E)||F),Rr());return{...C,groupIndices:k,groupOffsetTree:_}})),y),ye(W(r,Me(y),Ae(([k,{lastIndex:C}])=>k<C),fe(([k,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:k}])),n),ye(c,d);const x=Pt(W(c,fe(k=>k===void 0)),!0);ye(W(d,Ae(k=>k!==void 0&&nt(mt(y).sizeTree)),fe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=Wt(W(n,Me(y),Cn(({sizes:k},[C,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:g}),fe(k=>k.changed)));Je(W(a,Cn((k,C)=>({diff:k.prev-C,prev:C}),{diff:0,prev:0}),fe(k=>k.diff)),k=>{const{groupIndices:C}=mt(y);if(k>0)Pe(t,!0),Pe(s,k+au(k,C));else if(k<0){const E=mt(v);E.length>0&&(k-=au(-k,E)),Pe(i,k)}}),Je(W(a,Me(e)),([k,C])=>{k<0&&C("`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},Ut.ERROR)});const S=Wt(s);ye(W(s,Me(y),fe(([k,C])=>{const E=C.groupIndices.length>0,_=[],j=C.lastSize;if(E){const D=no(C.sizeTree,0);let F=0,K=0;for(;F<k;){const R=C.groupIndices[K],L=C.groupIndices.length===K+1?1/0:C.groupIndices[K+1]-R-1;_.push({endIndex:R,size:D,startIndex:R}),_.push({endIndex:R+1+L-1,size:j,startIndex:R+1}),K++,F+=L+1}const P=fr(C.sizeTree);return F!==k&&P.shift(),P.reduce((R,{k:L,v:U})=>{let te=R.ranges;return R.prevSize!==0&&(te=[...R.ranges,{endIndex:L+k-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:L+k,prevSize:U,ranges:te}},{prevIndex:k,prevSize:0,ranges:_}).ranges}return fr(C.sizeTree).reduce((D,{k:F,v:K})=>({prevIndex:F+k,prevSize:K,ranges:[...D.ranges,{endIndex:F+k-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const T=Wt(W(i,Me(y,p),fe(([k,{offsetTree:C},E])=>{const _=-k;return oo(_,C,E)})));return ye(W(i,Me(y,p),fe(([k,C,E])=>{if(C.groupIndices.length>0){if(nt(C.sizeTree))return C;let _=Rr();const j=mt(v);let D=0,F=0,K=0;for(;D<-k;){K=j[F];const P=j[F+1]-K-1;F++,D+=P+1}if(_=fr(C.sizeTree).reduce((P,{k:R,v:L})=>Vt(P,Math.max(0,R+k),L),_),D!==-k){const P=no(C.sizeTree,K);_=Vt(_,0,P);const R=fn(C.sizeTree,-k+1)[1];_=Vt(_,1,R)}return{...C,sizeTree:_,...Qi(C.offsetTree,0,_,E)}}else{const _=fr(C.sizeTree).reduce((j,{k:D,v:F})=>Vt(j,Math.max(0,D+k),F),Rr());return{...C,sizeTree:_,...Qi(C.offsetTree,0,_,E)}}})),y),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:y,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},at(qn,Ji),{singleton:!0});function wy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const lu=Ge(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ve(),i=Ve(),a=Wt(W(s,fe(wy)));return ye(W(a,fe(l=>l.totalCount)),n),ye(W(a,fe(l=>l.groupIndices)),e),ye(W(vt(o,t,r),Ae(([l,c])=>rs(c)),fe(([l,c,d])=>fn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),lt(),fe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},at(kn,Ft)),Gn=Ge(([{log:e}])=>{const t=J(!1),n=Wt(W(t,Ae(r=>r),lt()));return Je(t,r=>{r&&mt(e)("props updated",{},Ut.DEBUG)}),{didMount:n,propsReady:t}},at(qn),{singleton:!0}),by=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function cu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!by)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const so=Ge(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ve(),g=Ve(),y=J(0);let v=null,x=null,w=null;function S(){v&&(v(),v=null),w&&(w(),w=null),x&&(clearTimeout(x),x=null),Pe(l,!1)}return ye(W(p,Me(n,f,r,y,a,i,h),Me(e,s,o),fe(([[T,k,C,E,_,j,D,F],K,P,R])=>{const L=cu(T),{align:U,behavior:te,offset:V}=L,z=E-1,G=iu(L,k,z);let Q=oo(G,k.offsetTree,K)+j;U==="end"?(Q+=P+fn(k.sizeTree,G)[1]-C+R,G===z&&(Q+=D)):U==="center"?Q+=(P+fn(k.sizeTree,G)[1]-C+R)/2:Q-=_,V&&(Q+=V);const le=B=>{S(),B?(F("retrying to scroll to",{location:T},Ut.DEBUG),Pe(p,T)):(Pe(g,!0),F("list did not change, scroll successful",{},Ut.DEBUG))};if(S(),te==="smooth"){let B=!1;w=Je(t,ie=>{B=B||ie}),v=dn(d,()=>{le(B)})}else v=dn(W(t,Sy(150)),le);return x=setTimeout(()=>{S()},1200),Pe(l,!0),F("scrolling from index to",{behavior:te,index:G,top:Q},Ut.DEBUG),{behavior:te,top:Q}})),c),{scrollTargetReached:g,scrollToIndex:p,topListHeight:y}},at(kn,Ft,qn),{singleton:!0});function Sy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ea(e,t){e==0?t():requestAnimationFrame(()=>{ea(e-1,t)})}function ta(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const io=Ge(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=J(!0),l=J(0),c=J(!0);return ye(W(i,Me(l),Ae(([d,f])=>!!f),Sn(!1)),a),ye(W(i,Me(l),Ae(([d,f])=>!!f),Sn(!1)),c),Je(W(vt(t,i),Me(a,n,e,c),Ae(([[,d],f,{sizeTree:h},p,g])=>d&&(!nt(h)||Ui(p))&&!f&&!g),Me(l)),([,d])=>{dn(o,()=>{Pe(c,!0)}),ea(4,()=>{dn(r,()=>{Pe(a,!0)}),Pe(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},at(kn,Ft,so,Gn),{singleton:!0});function uu(e,t){return Math.abs(e-t)<1.01}const ao="up",lo="down",Cy="none",ky={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ty=0,co=Ge(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=Ve(),c=Ve(),d=J(4),f=J(Ty),h=Pt(W(Vi(W(Ee(o),ur(1),Sn(!0)),W(Ee(o),ur(1),Sn(!1),Kc(100))),lt()),!1),p=Pt(W(Vi(W(n,Sn(!0)),W(n,Sn(!1),Kc(200))),lt()),!1);ye(W(vt(Ee(o),Ee(f)),fe(([w,S])=>w<=S),lt()),a),ye(W(a,zn(50)),c);const g=Wt(W(vt(r,Ee(s),Ee(t),Ee(e),Ee(d)),Cn((w,[{scrollHeight:S,scrollTop:T},k,C,E,_])=>{const j=T+k-S>-_,D={scrollHeight:S,scrollTop:T,viewportHeight:k};if(j){let K,P;return T>w.state.scrollTop?(K="SCROLLED_DOWN",P=w.state.scrollTop-T):(K="SIZE_DECREASED",P=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:K,scrollTopDelta:P,state:D}}let F;return D.scrollHeight>w.state.scrollHeight?F="SIZE_INCREASED":k<w.state.viewportHeight?F="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?F="SCROLLING_UPWARDS":F="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:F,state:D}},ky),lt((w,S)=>w&&w.atBottom===S.atBottom))),y=Pt(W(r,Cn((w,{scrollHeight:S,scrollTop:T,viewportHeight:k})=>{if(uu(w.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:T};{const C=S-(T+k)<1;return w.scrollTop!==T&&C?{changed:!0,jump:w.scrollTop-T,scrollHeight:S,scrollTop:T}:{changed:!0,jump:0,scrollHeight:S,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(w=>w.changed),fe(w=>w.jump)),0);ye(W(g,fe(w=>w.atBottom)),i),ye(W(i,zn(50)),l);const v=J(lo);ye(W(r,fe(({scrollTop:w})=>w),lt(),Cn((w,S)=>mt(p)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?ao:lo,prevScrollTop:S},{direction:lo,prevScrollTop:0}),fe(w=>w.direction)),v),ye(W(r,zn(50),Sn(Cy)),v);const x=J(0);return ye(W(h,Ae(w=>!w),Sn(0)),x),ye(W(o,zn(100),Me(h),Ae(([w,S])=>!!S),Cn(([w,S],[T])=>[S,T],[0,0]),fe(([w,S])=>S-w)),x),{atBottomState:g,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:y,scrollDirection:v,scrollVelocity:x}},at(Ft)),os="top",ss="bottom",du="none";function fu(e,t,n){return typeof e=="number"?n===ao&&t===os||n===lo&&t===ss?e:0:n===ao?t===os?e.main:e.reverse:t===ss?e.main:e.reverse}function hu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const na=Ge(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ve(),i=J(0),a=J(0),l=J(0),c=Pt(W(vt(Ee(r),Ee(o),Ee(n),Ee(s,ro),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),fe(([d,f,h,[p,g],y,v,x,w,S])=>{const T=d-w,k=v+x,C=Math.max(h-T,0);let E=du;const _=hu(S,os),j=hu(S,ss);return p-=w,p+=h+x,g+=h+x,g-=w,p>d+k-_&&(E=ao),g<d-C+f+j&&(E=lo),E!==du?[Math.max(T-h-fu(y,os,E)-_,0),T-C-x+f+fu(y,ss,E)+j]:null}),Ae(d=>d!=null),lt(ro)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},at(Ft),{singleton:!0});function Ey(e,t,n){if(rs(t)){const r=su(e,t);return[{index:fn(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 ra={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function is(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 y=e[e.length-1];d=y.offset+y.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,g=h-d;return{bottom:d,firstItemIndex:s,items:mu(e,o,s),offsetBottom:g,offsetTop:c,top:p,topItems:mu(t,o,s),topListHeight:t.reduce((y,v)=>v.size+y,0),totalCount:n}}function pu(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=ta(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return is(c,[],a,o,n,r)}function mu(e,t,n){if(e.length===0)return[];if(!rs(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=es(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 hr=Ge(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:g}])=>{const y=J([]),v=J(0),x=Ve();ye(s.topItemsIndexes,y);const w=Pt(W(vt(p,g,Ee(l,ro),Ee(o),Ee(r),Ee(c),d,Ee(y),Ee(t),Ee(n),e),Ae(([C,E,,_,,,,,,,j])=>{const D=j&&j.length!==_;return C&&!E&&!D}),fe(([,,[C,E],_,j,D,F,K,P,R,L])=>{const U=j,{offsetTree:te,sizeTree:V}=U,z=mt(v);if(_===0)return{...ra,totalCount:_};if(C===0&&E===0)return z===0?{...ra,totalCount:_}:pu(z,D,j,P,R,L||[]);if(nt(V))return z>0?null:is(Ey(ta(D,_),U,L),[],_,R,U,P);const G=[];if(K.length>0){const Ce=K[0],ke=K[K.length-1];let q=0;for(const M of es(V,Ce,ke)){const X=M.value,ne=Math.max(M.start,Ce),xe=Math.min(M.end,ke);for(let se=ne;se<=xe;se++)G.push({data:L==null?void 0:L[se],index:se,offset:q,size:X}),q+=X}}if(!F)return is([],G,_,R,U,P);const Q=K.length>0?K[K.length-1]+1:0,le=py(te,C,E,Q);if(le.length===0)return null;const B=_-1,ie=Qo([],Ce=>{for(const ke of le){const q=ke.value;let M=q.offset,X=ke.start;const ne=q.size;if(q.offset<C){X+=Math.floor((C-q.offset+R)/(ne+R));const se=X-ke.start;M+=se*ne+se*R}X<Q&&(M+=(Q-X)*ne,X=Q);const xe=Math.min(ke.end,B);for(let se=X;se<=xe&&!(M>=E);se++)Ce.push({data:L==null?void 0:L[se],index:se,offset:M,size:ne}),M+=ne+R}});return is(ie,G,_,R,U,P)}),Ae(C=>C!==null),lt()),ra);ye(W(e,Ae(Ui),fe(C=>C==null?void 0:C.length)),o),ye(W(w,fe(C=>C.topListHeight)),f),ye(f,a),ye(W(w,fe(C=>[C.top,C.bottom])),i),ye(W(w,fe(C=>C.items)),x);const S=Wt(W(w,Ae(({items:C})=>C.length>0),Me(o,e),Ae(([{items:C},E])=>C[C.length-1].originalIndex===E-1),fe(([,C,E])=>[C-1,E]),lt(ro),fe(([C])=>C))),T=Wt(W(w,zn(200),Ae(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),fe(({items:C})=>C[0].index),lt())),k=Wt(W(w,Ae(({items:C})=>C.length>0),fe(({items:C})=>{let E=0,_=C.length-1;for(;C[E].type==="group"&&E<_;)E++;for(;C[_].type==="group"&&_>E;)_--;return{endIndex:C[_].index,startIndex:C[E].index}}),lt(ru)));return{endReached:S,initialItemCount:v,itemsRendered:x,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:y,...h}},at(kn,lu,na,io,so,co,Gn,Ji),{singleton:!0}),gu=Ge(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ve(),i=Pt(W(vt(n,e,r,t,o),fe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ye(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},at(Ft,hr),{singleton:!0}),Iy=Ge(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=Pt(W(vt(n,e,t),Ae(([o])=>o),fe(([,o,s])=>Math.max(0,o-s)),zn(0),lt()),0);return{alignToBottom:n,paddingTopAddition:r}},at(Ft,gu),{singleton:!0}),xu=Ge(()=>({context:J(null)})),Ay=({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,yu=Ge(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ve();return ye(W(d,Me(t,l,n,s,o,r,a),Me(e),fe(([[f,h,p,g,y,v,x,w],S])=>{const{align:T,behavior:k,calculateViewLocation:C=Ay,done:E,..._}=f,j=iu(f,h,g-1),D=oo(j,h.offsetTree,S)+y+v,F=D+fn(h.sizeTree,j)[1],K=w+v,P=w+p-x,R=C({itemBottom:F,itemTop:D,locationParams:{align:T,behavior:k,..._},viewportBottom:P,viewportTop:K});return R?E&&dn(W(i,Ae(L=>!L),ur(mt(i)?1:2)),E):E&&E(),R}),Ae(f=>f!==null)),c),{scrollIntoView:d}},at(kn,Ft,so,hr,qn),{singleton:!0});function vu(e){return e?e==="smooth"?"smooth":"auto":!1}const Ny=(e,t)=>typeof e=="function"?vu(e(t)):t&&vu(e),_y=Ge(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const g=J(!1),y=Ve();let v=null;function x(k){Pe(i,{align:"end",behavior:k,index:"LAST"})}Je(W(vt(W(Ee(t),ur(1)),l),Me(Ee(g),s,a,f),fe(([[k,C],E,_,j,D])=>{let F=C&&j,K="auto";return F&&(K=Ny(E,_||D),F=F&&!!K),{followOutputBehavior:K,shouldFollow:F,totalCount:k}}),Ae(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:C})=>{v&&(v(),v=null),mt(n)?requestAnimationFrame(()=>{mt(d)("following output to ",{totalCount:C},Ut.DEBUG),x(k)}):v=dn(e,()=>{mt(d)("following output to ",{totalCount:C},Ut.DEBUG),x(k),v=null})});function w(k){const C=dn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(mt(d)("scrolling to bottom due to increased size",{},Ut.DEBUG),x("auto"))});setTimeout(C,100)}Je(W(vt(Ee(g),t,c),Ae(([k,,C])=>k&&C),Cn(({value:k},[,C])=>({refreshed:k===C,value:C}),{refreshed:!1,value:0}),Ae(({refreshed:k})=>k),Me(g,t)),([,k])=>{mt(a)&&w(k!==!1)}),Je(y,()=>{w(mt(g)!==!1)}),Je(vt(Ee(g),o),([k,C])=>{k&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=J(null),T=Ve();return ye(Vi(W(Ee(r),fe(k=>{var C;return(C=k==null?void 0:k.length)!=null?C:0})),W(Ee(t))),T),Je(W(vt(W(T,ur(1)),l),Me(Ee(S),a,f,h),fe(([[k,C],E,_,j,D])=>C&&_&&(E==null?void 0:E({context:D,totalCount:k,scrollingInProgress:j}))),Ae(k=>!!k),zn(0)),k=>{v&&(v(),v=null),mt(n)?requestAnimationFrame(()=>{mt(d)("scrolling into view",{}),Pe(p,k)}):v=dn(e,()=>{mt(d)("scrolling into view",{}),Pe(p,k),v=null})}),{autoscrollToBottom:y,followOutput:g,scrollIntoViewOnChange:S}},at(kn,co,so,io,Gn,qn,Ft,xu,yu)),jy=Ge(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ye(W(a,Me(s),Ae(([,l])=>l!==0),Me(o,r,t,n,e),fe(([[,l],c,d,f,h,p=[]])=>pu(l,c,d,f,h,p))),i),{}),at(kn,io,hr,Gn),{singleton:!0}),Ry=Ge(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return Je(W(e,Me(r),Ae(([,o])=>o!==0),fe(([,o])=>({top:o}))),o=>{dn(W(n,ur(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},at(Gn,Ft,hr),{singleton:!0}),wu=Ge(([{scrollVelocity:e}])=>{const t=J(!1),n=Ve(),r=J(!1);return ye(W(e,Me(r,t,n),Ae(([o,s])=>!!s),fe(([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}),lt()),t),Je(W(vt(t,e,n),Me(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},at(co),{singleton:!0}),oa=Ge(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ve(),r=Ve(),o=Ve(),s=J(!1),i=J(void 0);return ye(W(vt(n,r),fe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ye(W(t,Me(r),fe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},at(Ft)),Py=Ge(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ve(),d=J(void 0),f=J(null),h=J(null);return ye(a,f),ye(l,h),Je(W(c,Me(t,r,i,f,h,n)),([p,g,y,v,x,w,S])=>{const T=gy(g.sizeTree);v&&x!==null&&w!==null&&(y=x.scrollTop-w.offsetTop),y-=S,p({ranges:T,scrollTop:y})}),ye(W(d,Ae(Ui),fe(Oy)),o),ye(W(s,Me(d),Ae(([,p])=>p!==void 0),lt(),fe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},at(kn,Ft,io,Gn,oa));function Oy(e){return{align:"start",index:0,offset:e.scrollTop}}const My=Ge(([{topItemsIndexes:e}])=>{const t=J(0);return ye(W(t,Ae(n=>n>=0),fe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},at(hr));function bu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Dy=bu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Ly=Ge(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:g}])=>{const y=Wt(W(l,Me(i),Cn(([,x,w,S],[{bottom:T,items:k,offsetBottom:C,totalCount:E},_])=>{const j=T+C;let D=0;return w===E&&x.length>0&&k.length>0&&(k[0].originalIndex===0&&x[0].originalIndex===0||(D=j-S,D!==0&&(D+=_))),[D,k,E,j]},[0,[],0,0]),Ae(([x])=>x!==0),Me(r,a,n,o,p,g),Ae(([,x,w,S,,,T])=>!T&&!S&&x!==0&&w===ao),fe(([[x],,,,,w])=>(w("Upward scrolling compensation",{amount:x},Ut.DEBUG),x))));function v(x){x>0?(Pe(t,{behavior:"auto",top:-x}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-x}))}return Je(W(y,Me(e,s)),([x,w,S])=>{S&&Dy()?Pe(e,w-x):v(-x)}),Je(W(vt(Pt(s,!1),e,g),Ae(([x,w,S])=>!x&&!S&&w!==0),fe(([x,w])=>w),zn(1)),v),ye(W(f,fe(x=>({top:-x}))),t),Je(W(c,Me(h,d),fe(([x,{groupIndices:w,lastSize:S,sizeTree:T},k])=>{function C(E){return E*(S+k)}if(w.length===0)return C(x);{let E=0;const _=no(T,0);let j=0,D=0;for(;j<x;){j++,E+=_;let F=w.length===D+1?1/0:w[D+1]-w[D]-1;j+F>x&&(E-=_,F=x-j+1),j+=F,E+=C(F),D++}return E}})),x=>{Pe(e,x),requestAnimationFrame(()=>{Pe(t,{top:x}),requestAnimationFrame(()=>{Pe(e,0),Pe(g,!1)})})}),{deviation:e}},at(Ft,co,hr,kn,qn,Ji)),Fy=Ge(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),at(na,jy,Gn,wu,gu,Ry,Iy,oa,yu,qn,xu)),Su=Ge(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:g},y,v,x,{listState:w,topItemsIndexes:S,...T},{scrollToIndex:k},C,{topItemCount:E},{groupCounts:_},j])=>(ye(T.rangeChanged,j.scrollSeekRangeChanged),ye(W(j.windowViewportRect,fe(D=>D.visibleHeight)),y.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:_,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:g,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,...j,...y,sizes:l,...v}),at(kn,io,Ft,Py,_y,hr,so,Ly,My,lu,Fy));function $y(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 as=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Cu(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(v,x){v.propsReady&&Pe(v.propsReady,!1);for(const w of r){const S=v[t.required[w]];Pe(S,x[w])}for(const w of o)if(w in x){const S=v[t.optional[w]];Pe(S,x[w])}v.propsReady&&Pe(v.propsReady,!0)}function c(v){return s.reduce((x,w)=>(x[w]=S=>{const T=v[t.methods[w]];Pe(T,S)},x),{})}function d(v){return i.reduce((x,w)=>(x[w]=ty(v[t.events[w]]),x),{})}const f=b.forwardRef((v,x)=>{const{children:w,...S}=v,[T]=b.useState(()=>Qo(ry(e),E=>{l(E,S)})),[k]=b.useState(qc(d,T));as(()=>{for(const E of i)E in S&&Je(k[E],S[E]);return()=>{Object.values(k).map(Wi)}},[S,k,T]),as(()=>{l(T,S)}),b.useImperativeHandle(x,Wc(c(T)));const C=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(C,{...$y([...r,...o,...i],S),children:w}):w})}),h=v=>{const x=b.useContext(a);return b.useCallback(w=>{Pe(x[v],w)},[x,v])},p=v=>{const x=b.useContext(a)[v],w=b.useCallback(S=>Je(x,S),[x]);return b.useSyncExternalStore(w,()=>mt(x),()=>mt(x))},g=v=>{const x=b.useContext(a)[v],[w,S]=b.useState(qc(mt,x));return as(()=>Je(x,T=>{T!==w&&S(Wc(T))}),[x,w]),w},y=b.version.startsWith("18")?p:g;return{Component:f,useEmitter:(v,x)=>{const w=b.useContext(a)[v];as(()=>Je(w,x),[x,w])},useEmitterValue:y,usePublisher:h}}const ku=b.createContext(void 0),Tu=b.createContext(void 0),Eu=typeof document<"u"?b.useLayoutEffect:b.useEffect;function sa(e){return"self"in e}function zy(e){return"body"in e}function Iu(e,t,n,r=jr,o,s){const i=b.useRef(null),a=b.useRef(null),l=b.useRef(null),c=b.useCallback(h=>{let p,g,y;const v=h.target;if(zy(v)||sa(v)){const w=sa(v)?v:v.defaultView;y=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,g=s?w.innerWidth:w.innerHeight}else y=s?v.scrollLeft:v.scrollTop,p=s?v.scrollWidth:v.scrollHeight,g=s?v.offsetWidth:v.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(y,0),viewportHeight:g})};h.suppressFlushSync?x():hi.flushSync(x),a.current!==null&&(y===a.current||y<=0||y===p-g)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);b.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const g=h.behavior==="smooth";let y,v,x;sa(p)?(v=Math.max(Kn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),y=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(v=p[s?"scrollWidth":"scrollHeight"],y=Kn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const w=v-y;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),uu(y,v)||h.top===x){e({scrollHeight:v,scrollTop:x,viewportHeight:y}),g&&t(!0);return}g?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ia="-webkit-sticky",Au="sticky",aa=bu(()=>{if(typeof document>"u")return Au;const e=document.createElement("div");return e.style.position=ia,e.style.position===ia?ia:Au});function la(e){return e}const By=Ge(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(la),o=J("div"),s=J(jr),i=(a,l=null)=>Pt(W(n,fe(c=>c[a]),lt()),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")}}),Hy=Ge(([e,t])=>({...e,...t}),at(Su,By)),Uy=({height:e})=>u.jsx("div",{style:{height:e}}),Wy={overflowAnchor:"none",position:aa(),zIndex:1},Nu={overflowAnchor:"none"},Vy={...Nu,display:"inline-block",height:"100%"},_u=b.memo(function({showTopList:e=!1}){const t=je("listState"),n=en("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),c=je("context"),d=je("groupContent"),f=je("trackItemSizes"),h=je("itemSize"),p=je("log"),g=en("gap"),y=je("horizontalDirection"),{callbackRef:v}=iy(n,h,f,e?jr:a,p,g,o,y,je("skipAnimationFrameInResizeObserver")),[x,w]=b.useState(0);ca("deviation",R=>{x!==R&&w(R)});const S=je("EmptyPlaceholder"),T=je("ScrollSeekPlaceholder")||Uy,k=je("ListComponent"),C=je("ItemComponent"),E=je("GroupComponent"),_=je("computeItemKey"),j=je("isSeeking"),D=je("groupIndices").length>0,F=je("alignToBottom"),K=je("initialItemFinalLocationReached"),P=e?{}:{boxSizing:"border-box",...y?{display:"inline-block",height:"100%",marginLeft:x!==0?x:F?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:F?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...K?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Ot(S,c)}):u.jsx(k,{...Ot(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:P,children:(e?t.topItems:t.items).map(R=>{const L=R.originalIndex,U=_(L+t.firstItemIndex,R.data,c);return j?b.createElement(T,{...Ot(T,c),height:R.size,index:R.index,key:U,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?b.createElement(E,{...Ot(E,c),"data-index":L,"data-item-index":R.index,"data-known-size":R.size,key:U,style:Wy},d(R.index,c)):b.createElement(C,{...Ot(C,c),...Yy(C,R.data),"data-index":L,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:U,style:y?Vy:Nu},D?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),qy={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Ky={outline:"none",overflowX:"auto",position:"relative"},ls=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Gy={position:aa(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function Yy(e,t){return{item:typeof e=="string"?void 0:t}}const Xy=b.memo(function(){const e=je("HeaderComponent"),t=en("headerHeight"),n=je("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),Jy=b.memo(function(){const e=je("FooterComponent"),t=en("footerHeight"),n=je("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null});function ju({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"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:g}=Iu(a,c,l,d,void 0,f);return e("scrollTo",g),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Ky:qy,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function Ru({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"),f=t("deviation"),h=t("customScrollParent"),p=b.useRef(null),g=t("scrollerRef"),{scrollByCallback:y,scrollerRef:v,scrollToCallback:x}=Iu(a,c,l,g,h);return Eu(()=>{var w;return v.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",x),e("scrollBy",y),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Ot(l,s),children:r})})}const Zy=({children:e})=>{const t=b.useContext(ku),n=en("viewportHeight"),r=en("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=b.useMemo(()=>Vc(n,l=>Kn(l,s?"width":"height")),[n,s]),a=dr(i,!0,je("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:ls(o),children:e})},Qy=({children:e})=>{const t=b.useContext(ku),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=je("customScrollParent"),s=Xc(n,o,je("skipAnimationFrameInResizeObserver")),i=je("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:ls(i),children:e})},ev=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...Gy,marginTop:`${n}px`},o=je("context");return u.jsx(t,{style:r,...Ot(t,o),children:e})},tv=b.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return u.jsxs(r||t?ov:rv,{...e,context:o,children:[n&&u.jsx(ev,{children:u.jsx(_u,{showTopList:!0})}),u.jsxs(r||t?Qy:Zy,{children:[u.jsx(Xy,{}),u.jsx(_u,{}),u.jsx(Jy,{})]})]})}),{Component:nv,useEmitter:ca,useEmitterValue:je,usePublisher:en}=Cu(Hy,{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"}},tv),rv=ju({useEmitter:ca,useEmitterValue:je,usePublisher:en}),ov=Ru({useEmitter:ca,useEmitterValue:je,usePublisher:en}),sv=nv;at(Su,Ge(()=>{const e=J(c=>u.jsxs("td",{children:["Item $",c]})),t=J(null),n=J(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=J(null),o=J(null),s=J({}),i=J(la),a=J(jr),l=(c,d=null)=>Pt(W(s,fe(f=>f[c]),lt()),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")}})),aa();const Pu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},iv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ou,floor:cs,max:uo,min:ua,round:Mu}=Math;function Du(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function av(e){return{...iv,items:e}}function us(e,t){return e&&e.width===t.width&&e.height===t.height}function lv(e,t){return e&&e.column===t.column&&e.row===t.row}const cv=Ge(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:g,propsReady:y},{customScrollParent:v,useWindowScroll:x,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T},k])=>{const C=J(0),E=J(0),_=J(Pu),j=J({height:0,width:0}),D=J({height:0,width:0}),F=Ve(),K=Ve(),P=J(0),R=J(null),L=J({column:0,row:0}),U=Ve(),te=Ve(),V=J(!1),z=J(0),G=J(!0),Q=J(!1),le=J(!1);Je(W(g,Me(z),Ae(([M,X])=>!!X)),()=>{Pe(G,!1)}),Je(W(vt(g,G,D,j,z,Q),Ae(([M,X,ne,xe,,se])=>M&&!X&&ne.height!==0&&xe.height!==0&&!se)),([,,,,M])=>{Pe(Q,!0),ea(1,()=>{Pe(F,M)}),dn(W(c),()=>{Pe(t,[0,0]),Pe(G,!0)})}),ye(W(te,Ae(M=>M!=null&&M.scrollTop>0),Sn(0)),E),Je(W(g,Me(te),Ae(([,M])=>M!=null)),([,M])=>{M&&(Pe(j,M.viewport),Pe(D,M.item),Pe(L,M.gap),M.scrollTop>0&&(Pe(V,!0),dn(W(c,ur(1)),X=>{Pe(V,!1)}),Pe(l,{top:M.scrollTop})))}),ye(W(j,fe(({height:M})=>M)),f),ye(W(vt(Ee(j,us),Ee(D,us),Ee(L,(M,X)=>M&&M.column===X.column&&M.row===X.row),Ee(c)),fe(([M,X,ne,xe])=>({gap:ne,item:X,scrollTop:xe,viewport:M}))),U),ye(W(vt(Ee(C),r,Ee(L,lv),Ee(D,us),Ee(j,us),Ee(R),Ee(E),Ee(V),Ee(G),Ee(z)),Ae(([,,,,,,,M])=>!M),fe(([M,[X,ne],xe,se,ae,Ue,Ke,,ot,st])=>{const{column:ut,row:et}=xe,{height:De,width:We}=se,{width:it}=ae;if(Ke===0&&(M===0||it===0))return Pu;if(We===0){const Fe=ta(st,M),Ze=Fe+Math.max(Ke-1,0);return av(Du(Fe,Ze,Ue))}const gt=Lu(it,We,ut);let re,ve;ot?X===0&&ne===0&&Ke>0?(re=0,ve=Ke-1):(re=gt*cs((X+et)/(De+et)),ve=gt*Ou((ne+et)/(De+et))-1,ve=ua(M-1,uo(ve,gt-1)),re=ua(ve,uo(0,re))):(re=0,ve=-1);const we=Du(re,ve,Ue),{bottom:Ye,top:xt}=Fu(ae,xe,se,we),ft=Ou(M/gt),wt=ft*De+(ft-1)*et-Ye;return{bottom:Ye,itemHeight:De,items:we,itemWidth:We,offsetBottom:wt,offsetTop:xt,top:xt}})),_),ye(W(R,Ae(M=>M!==null),fe(M=>M.length)),C),ye(W(vt(j,D,_,L),Ae(([M,X,{items:ne}])=>ne.length>0&&X.height!==0&&M.height!==0),fe(([M,X,{items:ne},xe])=>{const{bottom:se,top:ae}=Fu(M,xe,X,ne);return[ae,se]}),lt(ro)),t);const B=J(!1);ye(W(c,Me(B),fe(([M,X])=>X||M!==0)),B);const ie=Wt(W(vt(_,C),Ae(([{items:M}])=>M.length>0),Me(B),Ae(([[M,X],ne])=>{const xe=M.items[M.items.length-1].index===X-1;return(ne||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===X)&&xe}),fe(([[,M]])=>M-1),lt())),Ce=Wt(W(Ee(_),Ae(({items:M})=>M.length>0&&M[0].index===0),Sn(0),lt())),ke=Wt(W(Ee(_),Me(V),Ae(([{items:M},X])=>M.length>0&&!X),fe(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),lt(ru),zn(0)));ye(ke,p.scrollSeekRangeChanged),ye(W(F,Me(j,D,C,L),fe(([M,X,ne,xe,se])=>{const ae=cu(M),{align:Ue,behavior:Ke,offset:ot}=ae;let st=ae.index;st==="LAST"&&(st=xe-1),st=uo(0,st,ua(xe-1,st));let ut=da(X,se,ne,st);return Ue==="end"?ut=Mu(ut-X.height+ne.height):Ue==="center"&&(ut=Mu(ut-X.height/2+ne.height/2)),ot&&(ut+=ot),{behavior:Ke,top:ut}})),l);const q=Pt(W(_,fe(M=>M.offsetBottom+M.bottom)),0);return ye(W(T,fe(M=>({height:M.visibleHeight,width:M.visibleWidth}))),j),{customScrollParent:v,data:R,deviation:P,footerHeight:o,gap:L,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:D,overscan:n,restoreStateFrom:te,scrollBy:i,scrollContainerState:a,scrollHeight:K,scrollTo:l,scrollToIndex:F,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:x,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T,...p,gridState:_,horizontalDirection:le,initialTopMostItemIndex:z,totalListHeight:q,...h,endReached:ie,propsReady:y,rangeChanged:ke,startReached:Ce,stateChanged:U,stateRestoreInProgress:V,...k}},at(na,Ft,co,wu,Gn,oa,qn));function Lu(e,t,n){return uo(1,cs((e+n)/(cs(t)+n)))}function Fu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=da(e,t,n,r[0].index);return{bottom:da(e,t,n,r[r.length-1].index)+o,top:s}}function da(e,t,n,r){const o=Lu(e.width,n.width,t.column),s=cs(r/o),i=s*n.height+uo(0,s-1)*t.row;return i>0?i+t.row:i}const uv=Ge(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(la),i=J("div"),a=J(jr),l=(f,h=null)=>Pt(W(t,fe(p=>p[f]),lt()),h),c=J(!1),d=J(!1);return ye(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")}}),dv=Ge(([e,t])=>({...e,...t}),at(cv,uv)),fv=b.memo(function(){const e=ct("gridState"),t=ct("listClassName"),n=ct("itemClassName"),r=ct("itemContent"),o=ct("computeItemKey"),s=ct("isSeeking"),i=tn("scrollHeight"),a=ct("ItemComponent"),l=ct("ListComponent"),c=ct("ScrollSeekPlaceholder"),d=ct("context"),f=tn("itemDimensions"),h=tn("gap"),p=ct("log"),g=ct("stateRestoreInProgress"),y=tn("reportReadyState"),v=dr(b.useMemo(()=>x=>{const w=x.parentElement.parentElement.scrollHeight;i(w);const S=x.firstChild;if(S){const{height:T,width:k}=S.getBoundingClientRect();f({height:T,width:k})}h({column:zu("column-gap",getComputedStyle(x).columnGap,p),row:zu("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Eu(()=>{e.itemHeight>0&&e.itemWidth>0&&y(!0)},[e]),g?null:u.jsx(l,{className:t,ref:v,...Ot(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const w=o(x.index,x.data,d);return s?u.jsx(c,{...Ot(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},w):b.createElement(a,{...Ot(a,d),className:n,"data-index":x.index,key:w},r(x.index,x.data,d))})})}),hv=b.memo(function(){const e=ct("HeaderComponent"),t=tn("headerHeight"),n=ct("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,!1),o=ct("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),pv=b.memo(function(){const e=ct("FooterComponent"),t=tn("footerHeight"),n=ct("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(Kn(s,"height"))},[t]),!0,!1),o=ct("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Ot(e,o)})}):null}),mv=({children:e})=>{const t=b.useContext(Tu),n=tn("itemDimensions"),r=tn("viewportDimensions"),o=dr(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:ls(!1),children:e})},gv=({children:e})=>{const t=b.useContext(Tu),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=ct("customScrollParent"),s=Xc(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:ls(!1),children:e})},xv=b.memo(function({...e}){const t=ct("useWindowScroll"),n=ct("customScrollParent"),r=n||t?vv:yv,o=n||t?gv:mv,s=ct("context");return u.jsx(r,{...e,...Ot(r,s),children:u.jsxs(o,{children:[u.jsx(hv,{}),u.jsx(fv,{}),u.jsx(pv,{})]})})}),{useEmitter:$u,useEmitterValue:ct,usePublisher:tn}=Cu(dv,{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"}},xv),yv=ju({useEmitter:$u,useEmitterValue:ct,usePublisher:tn}),vv=Ru({useEmitter:$u,useEmitterValue:ct,usePublisher:tn});function zu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ut.WARN),t==="normal"?0:parseInt(t??"0",10)}function Bu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let pr=Bu();function wv(e){pr=e}const Hu=/[&<>"']/,bv=new RegExp(Hu.source,"g"),Uu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Sv=new RegExp(Uu.source,"g"),Cv={"&":"&","<":"<",">":">",'"':""","'":"'"},Wu=e=>Cv[e];function Mt(e,t){if(t){if(Hu.test(e))return e.replace(bv,Wu)}else if(Uu.test(e))return e.replace(Sv,Wu);return e}const kv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Vu(e){return e.replace(kv,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const Tv=/(^|[^\[])\^/g;function rt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Tv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Ev=/[^\w:]/g,Iv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function qu(e,t,n){if(e){let r;try{r=decodeURIComponent(Vu(n)).replace(Ev,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Iv.test(n)&&(n=jv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const ds={},Av=/^[^:]+:\/*[^/]*$/,Nv=/^([^:]+:)[\s\S]*$/,_v=/^([^:]+:\/*[^/]*)[\s\S]*$/;function jv(e,t){ds[" "+e]||(Av.test(e)?ds[" "+e]=e+"/":ds[" "+e]=hs(e,"/",!0)),e=ds[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Nv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(_v,"$1")+t:e+t}const fs={exec:function(){}};function Ku(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function hs(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function Rv(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function Pv(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function Gu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Yu(e,t,n,r){const o=t.href,s=t.title?Mt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:Mt(i)}}function Ov(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
83
39
|
`).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
|
|
84
|
-
`)}class
|
|
85
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=
|
|
40
|
+
`)}class fa{constructor(t){this.options=t||pr}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:hs(r,`
|
|
41
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Ov(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=hs(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,h,p,g,y=n[1].trim();const v=y.length>1,x={type:"list",raw:"",ordered:v,start:v?+y.slice(0,-1):"",loose:!1,items:[]};y=v?`\\d{1,9}\\${y.slice(-1)}`:`\\${y}`,this.options.pedantic&&(y=v?y:"[*+-]");const w=new RegExp(`^( {0,3}${y})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(g=!1,!(!(n=w.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
86
42
|
`,1)[0].replace(/^\t+/,T=>" ".repeat(3*T.length)),f=t.split(`
|
|
87
43
|
`,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
88
44
|
`,t=t.substring(f.length+1),g=!0),!g){const T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),k=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
89
45
|
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(C.test(f)||E.test(f)||T.test(f)||k.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
90
46
|
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||C.test(d)||E.test(d)||k.test(d))break;p+=`
|
|
91
47
|
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
92
|
-
`,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const S=x.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const T=x.items[a].tokens.filter(C=>C.type==="space"),k=T.length>0&&T.some(C=>/\n.*\n/.test(C.raw));x.loose=k}if(x.loose)for(a=0;a<S;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):Mt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:
|
|
93
|
-
`):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=
|
|
94
|
-
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:Mt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):Mt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=
|
|
95
|
-
]`).replace("lheading",be.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const pe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:
|
|
48
|
+
`,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const S=x.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const T=x.items[a].tokens.filter(C=>C.type==="space"),k=T.length>0&&T.some(C=>/\n.*\n/.test(C.raw));x.loose=k}if(x.loose)for(a=0;a<S;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):Mt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:Ku(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
49
|
+
`):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=Ku(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
|
|
50
|
+
`?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:Mt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):Mt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=hs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=Rv(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),Yu(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return Yu(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const g=h.slice(1,-1);return{type:"em",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Mt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=Mt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Mt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=Mt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=Mt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):Mt(r[0]):r[0]:o=Mt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const be={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:fs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};be._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,be._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,be.def=rt(be.def).replace("label",be._label).replace("title",be._title).getRegex(),be.bullet=/(?:[*+-]|\d{1,9}[.)])/,be.listItemStart=rt(/^( *)(bull) */).replace("bull",be.bullet).getRegex(),be.list=rt(be.list).replace(/bull/g,be.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+be.def.source+")").getRegex(),be._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",be._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,be.html=rt(be.html,"i").replace("comment",be._comment).replace("tag",be._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),be.paragraph=rt(be._paragraph).replace("hr",be.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",be._tag).getRegex(),be.blockquote=rt(be.blockquote).replace("paragraph",be.paragraph).getRegex(),be.normal={...be},be.gfm={...be.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},be.gfm.table=rt(be.gfm.table).replace("hr",be.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",be._tag).getRegex(),be.gfm.paragraph=rt(be._paragraph).replace("hr",be.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",be.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",be._tag).getRegex(),be.pedantic={...be.normal,html:rt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",be._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:fs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:rt(be.normal._paragraph).replace("hr",be.hr).replace("heading",` *#{1,6} *[^
|
|
51
|
+
]`).replace("lheading",be.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const pe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:fs,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:fs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};pe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",pe.punctuation=rt(pe.punctuation).replace(/punctuation/g,pe._punctuation).getRegex(),pe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,pe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,pe._comment=rt(be._comment).replace("(?:-->|$)","-->").getRegex(),pe.emStrong.lDelim=rt(pe.emStrong.lDelim).replace(/punct/g,pe._punctuation).getRegex(),pe.emStrong.rDelimAst=rt(pe.emStrong.rDelimAst,"g").replace(/punct/g,pe._punctuation).getRegex(),pe.emStrong.rDelimUnd=rt(pe.emStrong.rDelimUnd,"g").replace(/punct/g,pe._punctuation).getRegex(),pe._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,pe._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,pe._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,pe.autolink=rt(pe.autolink).replace("scheme",pe._scheme).replace("email",pe._email).getRegex(),pe._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,pe.tag=rt(pe.tag).replace("comment",pe._comment).replace("attribute",pe._attribute).getRegex(),pe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,pe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,pe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,pe.link=rt(pe.link).replace("label",pe._label).replace("href",pe._href).replace("title",pe._title).getRegex(),pe.reflink=rt(pe.reflink).replace("label",pe._label).replace("ref",be._label).getRegex(),pe.nolink=rt(pe.nolink).replace("ref",be._label).getRegex(),pe.reflinkSearch=rt(pe.reflinkSearch,"g").replace("reflink",pe.reflink).replace("nolink",pe.nolink).getRegex(),pe.normal={...pe},pe.pedantic={...pe.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:rt(/^!?\[(label)\]\((.*?)\)/).replace("label",pe._label).getRegex(),reflink:rt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",pe._label).getRegex()},pe.gfm={...pe.normal,escape:rt(pe.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},pe.gfm.url=rt(pe.gfm.url,"i").replace("email",pe.gfm._extended_email).getRegex(),pe.breaks={...pe.gfm,br:rt(pe.br).replace("{2,}","*").getRegex(),text:rt(pe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function Mv(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}function Xu(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class Yn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||pr,this.options.tokenizer=this.options.tokenizer||new fa,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:be.normal,inline:pe.normal};this.options.pedantic?(n.block=be.pedantic,n.inline=pe.pedantic):this.options.gfm&&(n.block=be.gfm,this.options.breaks?n.inline=pe.breaks:n.inline=pe.gfm),this.tokenizer.rules=n}static get rules(){return{block:be,inline:pe}}static lex(t,n){return new Yn(n).lex(t)}static lexInline(t,n){return new Yn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
96
52
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
|
|
97
53
|
`:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
|
|
98
54
|
`+r.raw,o.text+=`
|
|
@@ -102,7 +58,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
102
58
|
`+r.raw,o.text+=`
|
|
103
59
|
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
|
|
104
60
|
`+r.raw,o.text+=`
|
|
105
|
-
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+
|
|
61
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+Gu("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(a=this.tokenizer.rules.inline.blockSkip.exec(i))!=null;)i=i.slice(0,a.index)+"["+Gu("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,Xu)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,Xu))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,Mv)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class ha{constructor(t){this.options=t||pr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
|
|
106
62
|
`,o?'<pre><code class="'+this.options.langPrefix+Mt(o)+'">'+(r?t:Mt(t,!0))+`</code></pre>
|
|
107
63
|
`:"<pre><code>"+(r?t:Mt(t,!0))+`</code></pre>
|
|
108
64
|
`}blockquote(t){return`<blockquote>
|
|
@@ -122,10 +78,54 @@ ${t}</blockquote>
|
|
|
122
78
|
`}tablerow(t){return`<tr>
|
|
123
79
|
${t}</tr>
|
|
124
80
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
125
|
-
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=
|
|
126
|
-
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const _='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(_);return}else throw new Error(_)}}}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
|
|
127
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Mt(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 of(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=Cb(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(wb(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(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&Se.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;Se.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.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(Se.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&&Se.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Se(e,t,n){return of(Xn.lex,Jn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},ab(Se.defaults),Se},Se.getDefaults=qd,Se.defaults=xr,Se.use=function(...e){const t=Se.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Se.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=Se.defaults.renderer||new Pa;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=Se.defaults.tokenizer||new Ra;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=Se.defaults.hooks||new Ms;for(const s in n.hooks){const i=o[s];Ms.passThroughHooks.has(s)?o[s]=a=>{if(Se.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=Se.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}}Se.setOptions(r)})},Se.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Se,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Se.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Se.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Se.walkTokens(r.items,t));break}default:Se.defaults.extensions&&Se.defaults.extensions.childTokens&&Se.defaults.extensions.childTokens[r.type]?Se.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Se.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Se.walkTokens(r.tokens,t)))}return n},Se.parseInline=of(Xn.lexInline,Jn.parseInline),Se.Parser=Jn,Se.parser=Jn.parse,Se.Renderer=Pa,Se.TextRenderer=nf,Se.Lexer=Xn,Se.lexer=Xn.lex,Se.Tokenizer=Ra,Se.Slugger=rf,Se.Hooks=Ms,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Jn.parse,Xn.lex;function Oa({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{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 Se.parse(i)}return Se.parse(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(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return u.jsx("div",{className:oe("markdown prose max-w-none break-words dark:prose-invert","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",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const kb="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 Tb(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function sf(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Ds(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Eb(e){const t=o=>{try{const s=xo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="tool_end");let r="";if(n.length)try{n.length===1?r=t(n[0].output):r=t(n.map(o=>({toolCallId:o.toolCallId,output:o.output})))}catch{r=""}else r=t(e);return r||""}function Ib(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function af(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function Ab({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)]})}const lf=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=200,showToolMessages:f=!0,customStyles:h={},onEdit:p,onRegenerate:g,onCancelEdit:y,onCopy:v,activeInterrupt:x,disableInterruptActions:w=!1,onInterruptActionStart:S,onInterruptActionEnd:T}){const[k,C]=b.useState(!1),[E,_]=b.useState("preview"),[j,D]=b.useState(!1),{currentThreadId:F}=Yo(),{respondToInterrupt:K}=Xo(),P=l==="phone"||l==="half-screen",R=t.role,L=R==="tool",U=!(r&&R!=="user"),{uploadingFiles:te,handleFileClick:V,fileViewerOpen:z,currentFileInfo:G,closeFileViewer:Q}=_b({allowFileOpen:U,currentThreadId:F}),le=b.useMemo(()=>{switch(R){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))]"}},[R]),B=b.useMemo(()=>Tb(t.content),[t.content]),ie=b.useMemo(()=>sf(t.content),[t.content]),Ce=b.useMemo(()=>t.content.filter(re=>re.type==="image_url"),[t.content]),ke=b.useMemo(()=>t.content.filter(re=>re.type==="file"),[t.content]),q=b.useMemo(()=>t.content.filter(re=>re.type==="interrupt"),[t.content]),M=(x==null?void 0:x.id)??(x==null?void 0:x.interrupt_id),X=Ds(M),ne=x==null?void 0:x.value,xe=b.useMemo(()=>Eb(t.content),[t.content]),se=b.useCallback(async()=>{const re=L?xe:B;async function ve(we){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(we);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Ye=new Blob([we],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Ye})]);return}throw new Error("Clipboard API not supported in this context.")}try{await ve(re),C(!0),setTimeout(()=>C(!1),2e3),v==null||v(re)}catch(we){console.error("Failed to copy:",we)}},[L,xe,B,v]),ae=b.useCallback(()=>{if(!p)return;const re=L?xe:B;p(t.id,re)},[p,t.id,L,xe,B]),Ue=b.useCallback(()=>{g==null||g(n)},[g,n]),Ke=b.useCallback(()=>{const ve=oe(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",le);switch(R){case"user":return u.jsx(me.User,{className:ve});case"assistant":return u.jsx(me.Bot,{className:ve});case"tool":return u.jsx(me.Wrench,{className:ve});default:return u.jsx(me.Bot,{className:ve})}},[P,le,R]),ot=b.useCallback(()=>{const re="group relative mb-4 flex w-full";switch(R){case"user":return oe(re,"justify-end");case"assistant":case"tool":case"system":return oe(re,"justify-start");default:return re}},[R]),st=b.useCallback(()=>{const re=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");switch(R){case"user":return oe(re,"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(re,"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(re,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(re,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(re,"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")}},[P,R]),ut=b.useCallback(async re=>{if(w)return;const ve=Ds((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id));if(!ve){console.warn("Interrupt part missing id",re);return}try{S==null||S(),await K(ve,!0)}catch(we){console.error("Failed to approve interrupt:",we)}finally{T==null||T()}},[w,T,S,K]),et=b.useCallback(async re=>{if(w)return;const ve=Ds((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id));if(!ve){console.warn("Interrupt part missing id",re);return}try{S==null||S(),await K(ve,!1)}catch(we){console.error("Failed to reject interrupt:",we)}finally{T==null||T()}},[w,T,S,K]),De=b.useCallback(({part:re,i:ve})=>{if(re.type==="text"){const we=re.text??"",Ye=we.trim(),xt=Zu(Ye);return xt&&R!=="tool"?u.jsx(cf,{data:xt},ve):R==="user"&&c&&Ye.length>d?u.jsx(jb,{text:Ye,expanded:j,onExpandedChange:D,previewLength:d,isCompact:P},ve):u.jsx(Oa,{content:we,allowHtml:!1},ve)}if(re.type==="image_url"){const we=re;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:we.url,alt:we.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},ve)}if(re.type==="file"){const we=re,Ye=we.name||"file";return u.jsxs("a",{href:we.url,onClick:xt=>V(xt,we,ve),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
128
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[te[ve]?u.jsx(me.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Ye,te[ve]?" (processing)":""]})]},ve)}if(re.type==="interrupt"){const we=re,Ye=Ds((we==null?void 0:we.id)??(we==null?void 0:we.interrupt_id)),xt=!!(X&&Ye&&Ye===X),ft=xt?ne??(we==null?void 0:we.value):we==null?void 0:we.value,wt=Ye?{...we,id:Ye,interrupt_id:Ye}:we;return u.jsx(Nb,{interruptPart:wt,onApprove:ut,onReject:et,disabled:w,isActive:xt,payload:ft},ve)}return null},[V,te,ut,et,R,c,d,j,P,X,ne,x,w,q]),We=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(me.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),it=b.useCallback(()=>{const re=B.trim().length>0||Ce.length>0||ke.length>0||q.length>0;if(!L&&ke.length>0&&!r)return We();if(!L&&!re&&!r)return null;if(L)return u.jsx(Rb,{message:t,viewMode:E},t.id);if(!L){const ve=u.jsx("div",{className:"space-y-2",children:t.content.map((we,Ye)=>u.jsx(De,{part:we,i:Ye},Ye))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ve,u.jsx(Ab,{className:le})]}):ve}},[B,Ce.length,ke.length,q.length,r,L,E,We,le]),gt=b.useMemo(()=>Ib(t),[t]);return L&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(ot(),h.container),children:u.jsxs("div",{className:oe(st(),h.content),children:[(i||a||L)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",le,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ke(),a&>&&u.jsx("span",{className:oe("font-medium",P?"text-xs":"text-sm"),children:gt}),L&&u.jsxs(Bu,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",le,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E==="expanded",onClick:()=>_(re=>re==="expanded"?"preview":"expanded"),onKeyDown:re=>{(re.key==="Enter"||re.key===" ")&&(re.preventDefault(),_(ve=>ve==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ie.name??"Tool Output"}),ie.toolCallId&&u.jsx("span",{className:"opacity-70",children:ie.toolCallId.slice(0,8)}),E==="expanded"?u.jsx(me.ChevronUp,{className:"h-3 w-3"}):u.jsx(me.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",le,P&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:oe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>se(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",le,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(me.Copy,{className:oe(k?"text-success":le,P?"h-3 w-3":"h-4 w-4")})})}),R==="user"&&p&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ae,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",le,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(me.Edit,{className:oe(le,P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:Ue,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",le,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(me.RotateCcw,{className:oe(le,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:it()}),L&&E==="expanded"&&(ie.toolCallId||ie.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[ie.name&&u.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&u.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||L)&&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",h.actions),children:[u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>se(),className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(me.Copy,{className:oe(k?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="user"&&p&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ae,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(me.Edit,{className:oe("text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:Ue,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(me.RotateCcw,{className:oe("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),G&&u.jsx(ib,{isOpen:z,onClose:Q,fileId:G.id,fileName:G.name,mimeType:G.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&af(e.message)===af(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(g=>e[g]===t[g]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function cf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:kb,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:ms(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ms(e)})}function Nb({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=ms(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(fo,{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(ho,{className:"pb-3",children:[u.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Hu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(mo,{className:"pt-0 pb-3",children:a}),u.jsx(Uu,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Xe,{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(Xe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function _b(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=xa(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,g,y)=>{var v,x;if(!t){p.preventDefault();return}if(o[y]){p.preventDefault();return}try{const w=String(g.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=g.name||`file_${T}`,C=g.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[y]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Vv(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const C=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:g.name||C.filename||`file_${C.id}`,mimeType:g.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[y]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[y]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function jb({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return u.jsxs(Lv,{open:t,onOpenChange:n,children:[u.jsx("div",{className:oe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(Oa,{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:[e.substring(0,r),"..."]})}),u.jsx(Fv,{asChild:!0,children:u.jsx(Xe,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:t?u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Rb({message:e,viewMode:t}){const r=sf(e.content).name||"tool",o=a=>{if(a==null)return null;const l=typeof a=="string"?Zu(a)??a:a;if(l&&typeof l=="object")return u.jsx(cf,{data:l});const c=typeof l=="string"?l:(()=>{try{return ms(l)}catch{return String(l??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:c})};if(t==="preview")return null;const s=e.content.find(a=>a.type!=="tool_call");if(!s)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(me.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(s.type==="text"){const l=(s.text??"").trim();return l?o(l):null}const i=xo(s);return o(i)}const uf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ma=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:f,style:h,emptyMessage:p,followNewMessages:g=!0,isNavigatingCheckpoint:y=!1,onScrollAway:v,onAtBottom:x,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C=!0},E)=>{const _=b.useRef(null),j=b.useRef(null),D=b.useRef(!1),[F,K]=b.useState(!0),P=b.useMemo(()=>w?e.some(G=>Array.isArray(G==null?void 0:G.content)&&G.content.some(Q=>Q&&Q.type==="interrupt"&&(Q.id??Q.interrupt_id)===w.id)):!1,[w,e]),R=b.useMemo(()=>{if(!w||P)return null;const G=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let Q;const le=w.value;if(le&&typeof le=="object"&&!Array.isArray(le)){const B=le.title;typeof B=="string"&&B.trim()&&(Q=B.trim())}return{id:`interrupt-${G}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:G,value:le,title:Q}]}},[w,P]),L=b.useMemo(()=>R?[...e,R]:e,[e,R]),U=b.useMemo(()=>C?L:L.filter(G=>(G==null?void 0:G.role)!=="tool"),[L,C]),te=b.useCallback(G=>{K(G),v&&v(!G),x&&x(G)},[v,x]),V=b.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),z=b.useMemo(()=>!g||y?!1:F?"auto":!1,[F,g,y]);return U.length===0?u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:f,style:h,children:u.jsx(sv,{ref:G=>{_.current=G},scrollerRef:G=>{j.current=G instanceof HTMLDivElement?G:null},data:U,followOutput:z,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{V&&V()},atBottomStateChange:te,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(G,Q)=>uf(Q,G),itemContent:(G,Q)=>{const le=uf(Q,G);return u.jsx("div",{className:"mb-4 last:mb-0","data-message-id":le,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(lf,{message:Q,messageIndex:G,isStreamingMessage:t&&n===Q.id,streamingDebounceMs:r,isEditing:i===Q.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(G),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C})})}})})});Ma.displayName="MessageList";const Ls=1e4;function Pb(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
81
|
+
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=qu(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=qu(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class Ju{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class Zu{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Xn{constructor(t){this.options=t||pr,this.options.renderer=this.options.renderer||new ha,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Ju,this.slugger=new Zu}static parse(t,n){return new Xn(n).parse(t)}static parseInline(t,n){return new Xn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,g,y,v,x,w,S,T,k,C;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Vu(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(g=p.ordered,y=p.start,v=p.loose,a=p.items.length,h="",s=0;s<a;s++)w=p.items[s],S=w.checked,T=w.task,x="",w.task&&(k=this.renderer.checkbox(S),v?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=k+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=k+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:k}):x+=k),x+=this.parse(w.tokens,v),h+=this.renderer.listitem(x,T,S);r+=this.renderer.list(h,g,y);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
82
|
+
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const _='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(_);return}else throw new Error(_)}}}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 ps{constructor(t){this.options=t||pr}preprocess(t){return t}postprocess(t){return t}}Cm(ps,"passThroughHooks",new Set(["preprocess","postprocess"]));function Dv(e,t,n){return r=>{if(r.message+=`
|
|
83
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Mt(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 Qu(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=Dv(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(Pv(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(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&Se.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;Se.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.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(Se.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&&Se.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Se(e,t,n){return Qu(Yn.lex,Xn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},wv(Se.defaults),Se},Se.getDefaults=Bu,Se.defaults=pr,Se.use=function(...e){const t=Se.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Se.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=Se.defaults.renderer||new ha;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=Se.defaults.tokenizer||new fa;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=Se.defaults.hooks||new ps;for(const s in n.hooks){const i=o[s];ps.passThroughHooks.has(s)?o[s]=a=>{if(Se.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=Se.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}}Se.setOptions(r)})},Se.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Se,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Se.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Se.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Se.walkTokens(r.items,t));break}default:Se.defaults.extensions&&Se.defaults.extensions.childTokens&&Se.defaults.extensions.childTokens[r.type]?Se.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Se.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Se.walkTokens(r.tokens,t)))}return n},Se.parseInline=Qu(Yn.lexInline,Xn.parseInline),Se.Parser=Xn,Se.parser=Xn.parse,Se.Renderer=ha,Se.TextRenderer=Ju,Se.Lexer=Yn,Se.lexer=Yn.lex,Se.Tokenizer=fa,Se.Slugger=Zu,Se.Hooks=ps,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Xn.parse,Yn.lex;function ms({content:e,className:t="",allowHtml:n=!1,style:r}){const o=b.useMemo(()=>{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 Se.parse(i)}return Se.parse(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(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return u.jsx("div",{className:oe("markdown prose max-w-none break-words dark:prose-invert","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",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const Lv=Ro.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function ed({className:e,variant:t,...n}){return u.jsx("div",{className:oe(Lv({variant:t}),e),...n})}const fo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));fo.displayName="Card";const ho=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));ho.displayName="CardHeader";const po=m.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));po.displayName="CardTitle";const td=m.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));td.displayName="CardDescription";const mo=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));mo.displayName="CardContent";const nd=m.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));nd.displayName="CardFooter";function ge(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 Fv(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:h,children:p,...g}=f,y=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,v=m.useMemo(()=>g,Object.values(g));return u.jsx(y.Provider,{value:v,children:p})};c.displayName=s+"Provider";function d(f,h){var y;const p=((y=h==null?void 0:h[e])==null?void 0:y[l])||a,g=m.useContext(p);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,$v(o,...t)]}function $v(...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 f=l(s)[`__scope${c}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var kt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},zv=m[" useInsertionEffect ".trim().toString()]||kt;function mr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Bv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=m.useCallback(d=>{var f;if(a){const h=Hv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function Bv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return zv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Hv(e){return typeof e=="function"}function rd(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function pa(...e){return t=>{let n=!1;const r=e.map(o=>{const s=rd(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():rd(e[o],null)}}}}function He(...e){return m.useCallback(pa(...e),e)}var Uv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=Uv.reduce((e,t)=>{const n=sr.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function od(e,t){e&&Po.flushSync(()=>e.dispatchEvent(t))}function Wv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var qt=e=>{const{present:t,children:n}=e,r=Vv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=He(r.ref,qv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};qt.displayName="Presence";function Vv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const c=gs(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=gs(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),kt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const y=gs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&y&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},h=p=>{p.target===t&&(s.current=gs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function gs(e){return(e==null?void 0:e.animationName)||"none"}function qv(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 Kv=m[" useId ".trim().toString()]||(()=>{}),Gv=0;function En(e){const[t,n]=m.useState(Kv());return kt(()=>{n(r=>r??String(Gv++))},[e]),e||(t?`radix-${t}`:"")}var xs="Collapsible",[Yv,pT]=Tn(xs),[Xv,ma]=Yv(xs),sd=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,c]=mr({prop:r,defaultProp:o??!1,onChange:i,caller:xs});return u.jsx(Xv,{scope:n,disabled:s,contentId:En(),open:l,onOpenToggle:m.useCallback(()=>c(d=>!d),[c]),children:u.jsx(Ne.div,{"data-state":xa(l),"data-disabled":s?"":void 0,...a,ref:t})})});sd.displayName=xs;var id="CollapsibleTrigger",ad=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ma(id,n);return u.jsx(Ne.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":xa(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ge(e.onClick,o.onOpenToggle)})});ad.displayName=id;var ga="CollapsibleContent",Jv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ma(ga,e.__scopeCollapsible);return u.jsx(qt,{present:n||o.open,children:({present:s})=>u.jsx(Zv,{...r,ref:t,present:s})})});Jv.displayName=ga;var Zv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ma(ga,n),[a,l]=m.useState(r),c=m.useRef(null),d=He(t,c),f=m.useRef(0),h=f.current,p=m.useRef(0),g=p.current,y=i.open||a,v=m.useRef(y),x=m.useRef(void 0);return m.useEffect(()=>{const w=requestAnimationFrame(()=>v.current=!1);return()=>cancelAnimationFrame(w)},[]),kt(()=>{const w=c.current;if(w){x.current=x.current||{transitionDuration:w.style.transitionDuration,animationName:w.style.animationName},w.style.transitionDuration="0s",w.style.animationName="none";const S=w.getBoundingClientRect();f.current=S.height,p.current=S.width,v.current||(w.style.transitionDuration=x.current.transitionDuration,w.style.animationName=x.current.animationName),l(r)}},[i.open,r]),u.jsx(Ne.div,{"data-state":xa(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!y,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":g?`${g}px`:void 0,...e.style},children:y&&o})});function xa(e){return e?"open":"closed"}var Qv=sd;const ew=Qv,tw=ad,nw=1,rw=1e6;let ya=0;function ow(){return ya=(ya+1)%Number.MAX_SAFE_INTEGER,ya.toString()}const va=new Map,ld=e=>{if(va.has(e))return;const t=setTimeout(()=>{va.delete(e),go({type:"REMOVE_TOAST",toastId:e})},rw);va.set(e,t)},sw=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,nw)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?ld(n):e.toasts.forEach(r=>{ld(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},ys=[];let vs={toasts:[]};function go(e){vs=sw(vs,e),ys.forEach(t=>{t(vs)})}function iw({...e}){const t=ow(),n=o=>go({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>go({type:"DISMISS_TOAST",toastId:t});return go({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function wa(){const[e,t]=m.useState(vs);return m.useEffect(()=>(ys.push(t),()=>{const n=ys.indexOf(t);n>-1&&ys.splice(n,1)}),[e]),{...e,toast:iw,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}async function cd(e,t){return await cn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function ud(e,t){return await(await cd(`/files/${e}/view`,t)).text()}async function aw(e,t){const n=await cd(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await cn(`/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 lw(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await cn("/files",{params:r})}function dd(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 fd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function xo(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(xo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(fd(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=xo(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 ws(e){if(typeof e=="string")return e;if(fd(e))return"";try{const t=xo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function At(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function cw(e,t=globalThis==null?void 0:globalThis.document){const n=At(e);m.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 uw="DismissableLayer",ba="dismissableLayer.update",dw="dismissableLayer.pointerDownOutside",fw="dismissableLayer.focusOutside",hd,pd=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),bs=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=m.useContext(pd),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),g=He(t,E=>f(E)),y=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=y.indexOf(v),w=d?y.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=x,k=mw(E=>{const _=E.target,j=[...c.branches].some(D=>D.contains(_));!T||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),C=gw(E=>{const _=E.target;[...c.branches].some(D=>D.contains(_))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return cw(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(hd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),md(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=hd)}},[d,h,n,c]),m.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),md())},[d,c]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(ba,E),()=>document.removeEventListener(ba,E)},[]),u.jsx(Ne.div,{...l,ref:g,style:{pointerEvents:S?T?"auto":"none":void 0,...e.style},onFocusCapture:ge(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ge(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ge(e.onPointerDownCapture,k.onPointerDownCapture)})});bs.displayName=uw;var hw="DismissableLayerBranch",pw=m.forwardRef((e,t)=>{const n=m.useContext(pd),r=m.useRef(null),o=He(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ne.div,{...e,ref:o})});pw.displayName=hw;function mw(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){gd(dw,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 gw(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&gd(fw,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 md(){const e=new CustomEvent(ba);document.dispatchEvent(e)}function gd(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?od(o,s):o.dispatchEvent(s)}var Sa="focusScope.autoFocusOnMount",Ca="focusScope.autoFocusOnUnmount",xd={bubbles:!1,cancelable:!0},xw="FocusScope",Ss=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),c=At(o),d=At(s),f=m.useRef(null),h=He(t,y=>l(y)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let y=function(S){if(p.paused||!a)return;const T=S.target;a.contains(T)?f.current=T:Jn(f.current,{select:!0})},v=function(S){if(p.paused||!a)return;const T=S.relatedTarget;T!==null&&(a.contains(T)||Jn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&Jn(a)};document.addEventListener("focusin",y),document.addEventListener("focusout",v);const w=new MutationObserver(x);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",v),w.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){wd.add(p);const y=document.activeElement;if(!a.contains(y)){const x=new CustomEvent(Sa,xd);a.addEventListener(Sa,c),a.dispatchEvent(x),x.defaultPrevented||(yw(Cw(yd(a)),{select:!0}),document.activeElement===y&&Jn(a))}return()=>{a.removeEventListener(Sa,c),setTimeout(()=>{const x=new CustomEvent(Ca,xd);a.addEventListener(Ca,d),a.dispatchEvent(x),x.defaultPrevented||Jn(y??document.body,{select:!0}),a.removeEventListener(Ca,d),wd.remove(p)},0)}}},[a,c,d,p]);const g=m.useCallback(y=>{if(!n&&!r||p.paused)return;const v=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,x=document.activeElement;if(v&&x){const w=y.currentTarget,[S,T]=vw(w);S&&T?!y.shiftKey&&x===T?(y.preventDefault(),n&&Jn(S,{select:!0})):y.shiftKey&&x===S&&(y.preventDefault(),n&&Jn(T,{select:!0})):x===w&&y.preventDefault()}},[n,r,p.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});Ss.displayName=xw;function yw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Jn(r,{select:t}),document.activeElement!==n)return}function vw(e){const t=yd(e),n=vd(t,e),r=vd(t.reverse(),e);return[n,r]}function yd(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 vd(e,t){for(const n of e)if(!ww(n,{upTo:t}))return n}function ww(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 bw(e){return e instanceof HTMLInputElement&&"select"in e}function Jn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&bw(e)&&t&&e.select()}}var wd=Sw();function Sw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=bd(e,t),e.unshift(t)},remove(t){var n;e=bd(e,t),(n=e[0])==null||n.resume()}}}function bd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Cw(e){return e.filter(t=>t.tagName!=="A")}var kw="Portal",Cs=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?hi.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});Cs.displayName=kw;var ka=0;function Ta(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sd()),document.body.insertAdjacentElement("beforeend",e[1]??Sd()),ka++,()=>{ka===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),ka--}},[])}function Sd(){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 In=function(){return In=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},In.apply(this,arguments)};function Cd(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 Tw(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 ks="right-scroll-bar-position",Ts="width-before-scroll-bar",Ew="with-scroll-bars-hidden",Iw="--removed-body-scroll-bar-size";function Ea(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Aw(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 Nw=typeof window<"u"?m.useLayoutEffect:m.useEffect,kd=new WeakMap;function _w(e,t){var n=Aw(null,function(r){return e.forEach(function(o){return Ea(o,r)})});return Nw(function(){var r=kd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Ea(a,null)}),s.forEach(function(a){o.has(a)||Ea(a,i)})}kd.set(n,e)},[e]),n}function jw(e){return e}function Rw(e,t){t===void 0&&(t=jw);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 Pw(e){e===void 0&&(e={});var t=Rw(null);return t.options=In({async:!0,ssr:!1},e),t}var Td=function(e){var t=e.sideCar,n=Cd(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 m.createElement(r,In({},n))};Td.isSideCarExport=!0;function Ow(e,t){return e.useMedium(t),Td}var Ed=Pw(),Ia=function(){},Es=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Ia,onWheelCapture:Ia,onTouchMoveCapture:Ia}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,g=e.noIsolation,y=e.inert,v=e.allowPinchZoom,x=e.as,w=x===void 0?"div":x,S=e.gapMode,T=Cd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,C=_w([n,t]),E=In(In({},T),o);return m.createElement(m.Fragment,null,d&&m.createElement(k,{sideCar:Ed,removeScrollBar:c,shards:f,noRelative:p,noIsolation:g,inert:y,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),In(In({},E),{ref:C})):m.createElement(w,In({},E,{className:l,ref:C}),a))});Es.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Es.classNames={fullWidth:Ts,zeroRight:ks};var Mw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Dw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Mw();return t&&e.setAttribute("nonce",t),e}function Lw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Fw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var $w=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Dw())&&(Lw(t,n),Fw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},zw=function(){var e=$w();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Id=function(){var e=zw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Bw={left:0,top:0,right:0,gap:0},Aa=function(e){return parseInt(e||"",10)||0},Hw=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[Aa(n),Aa(r),Aa(o)]},Uw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Bw;var t=Hw(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])}},Ww=Id(),Pr="data-scroll-locked",Vw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
84
|
+
.`.concat(Ew,` {
|
|
85
|
+
overflow: hidden `).concat(r,`;
|
|
86
|
+
padding-right: `).concat(a,"px ").concat(r,`;
|
|
87
|
+
}
|
|
88
|
+
body[`).concat(Pr,`] {
|
|
89
|
+
overflow: hidden `).concat(r,`;
|
|
90
|
+
overscroll-behavior: contain;
|
|
91
|
+
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
92
|
+
padding-left: `.concat(o,`px;
|
|
93
|
+
padding-top: `).concat(s,`px;
|
|
94
|
+
padding-right: `).concat(i,`px;
|
|
95
|
+
margin-left:0;
|
|
96
|
+
margin-top:0;
|
|
97
|
+
margin-right: `).concat(a,"px ").concat(r,`;
|
|
98
|
+
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.`).concat(ks,` {
|
|
102
|
+
right: `).concat(a,"px ").concat(r,`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.`).concat(Ts,` {
|
|
106
|
+
margin-right: `).concat(a,"px ").concat(r,`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.`).concat(ks," .").concat(ks,` {
|
|
110
|
+
right: 0 `).concat(r,`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.`).concat(Ts," .").concat(Ts,` {
|
|
114
|
+
margin-right: 0 `).concat(r,`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
body[`).concat(Pr,`] {
|
|
118
|
+
`).concat(Iw,": ").concat(a,`px;
|
|
119
|
+
}
|
|
120
|
+
`)},Ad=function(){var e=parseInt(document.body.getAttribute(Pr)||"0",10);return isFinite(e)?e:0},qw=function(){m.useEffect(function(){return document.body.setAttribute(Pr,(Ad()+1).toString()),function(){var e=Ad()-1;e<=0?document.body.removeAttribute(Pr):document.body.setAttribute(Pr,e.toString())}},[])},Kw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;qw();var s=m.useMemo(function(){return Uw(o)},[o]);return m.createElement(Ww,{styles:Vw(s,!t,o,n?"":"!important")})},Na=!1;if(typeof window<"u")try{var Is=Object.defineProperty({},"passive",{get:function(){return Na=!0,!0}});window.addEventListener("test",Is,Is),window.removeEventListener("test",Is,Is)}catch{Na=!1}var Or=Na?{passive:!1}:!1,Gw=function(e){return e.tagName==="TEXTAREA"},Nd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Gw(e)&&n[t]==="visible")},Yw=function(e){return Nd(e,"overflowY")},Xw=function(e){return Nd(e,"overflowX")},_d=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=jd(e,r);if(o){var s=Rd(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Jw=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Zw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},jd=function(e,t){return e==="v"?Yw(t):Xw(t)},Rd=function(e,t){return e==="v"?Jw(t):Zw(t)},Qw=function(e,t){return e==="h"&&t==="rtl"?-1:1},eb=function(e,t,n,r,o){var s=Qw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Rd(e,a),g=p[0],y=p[1],v=p[2],x=y-v-s*g;(g||x)&&jd(e,a)&&(f+=x,h+=g);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(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},As=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Pd=function(e){return[e.deltaX,e.deltaY]},Od=function(e){return e&&"current"in e?e.current:e},tb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},nb=function(e){return`
|
|
121
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
122
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
123
|
+
`)},rb=0,Mr=[];function ob(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(rb++)[0],s=m.useState(Id)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var y=Tw([e.lockRef.current],(e.shards||[]).map(Od),!0).filter(Boolean);return y.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),y.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(y,v){if("touches"in y&&y.touches.length===2||y.type==="wheel"&&y.ctrlKey)return!i.current.allowPinchZoom;var x=As(y),w=n.current,S="deltaX"in y?y.deltaX:w[0]-x[0],T="deltaY"in y?y.deltaY:w[1]-x[1],k,C=y.target,E=Math.abs(S)>Math.abs(T)?"h":"v";if("touches"in y&&E==="h"&&C.type==="range")return!1;var _=_d(E,C);if(!_)return!0;if(_?k=E:(k=E==="v"?"h":"v",_=_d(E,C)),!_)return!1;if(!r.current&&"changedTouches"in y&&(S||T)&&(r.current=k),!k)return!0;var j=r.current||k;return eb(j,v,y,j==="h"?S:T)},[]),l=m.useCallback(function(y){var v=y;if(!(!Mr.length||Mr[Mr.length-1]!==s)){var x="deltaY"in v?Pd(v):As(v),w=t.current.filter(function(k){return k.name===v.type&&(k.target===v.target||v.target===k.shadowParent)&&tb(k.delta,x)})[0];if(w&&w.should){v.cancelable&&v.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(Od).filter(Boolean).filter(function(k){return k.contains(v.target)}),T=S.length>0?a(v,S[0]):!i.current.noIsolation;T&&v.cancelable&&v.preventDefault()}}},[]),c=m.useCallback(function(y,v,x,w){var S={name:y,delta:v,target:x,should:w,shadowParent:sb(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(T){return T!==S})},1)},[]),d=m.useCallback(function(y){n.current=As(y),r.current=void 0},[]),f=m.useCallback(function(y){c(y.type,Pd(y),y.target,a(y,e.lockRef.current))},[]),h=m.useCallback(function(y){c(y.type,As(y),y.target,a(y,e.lockRef.current))},[]);m.useEffect(function(){return Mr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Or),document.addEventListener("touchmove",l,Or),document.addEventListener("touchstart",d,Or),function(){Mr=Mr.filter(function(y){return y!==s}),document.removeEventListener("wheel",l,Or),document.removeEventListener("touchmove",l,Or),document.removeEventListener("touchstart",d,Or)}},[]);var p=e.removeScrollBar,g=e.inert;return m.createElement(m.Fragment,null,g?m.createElement(s,{styles:nb(o)}):null,p?m.createElement(Kw,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function sb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ib=Ow(Ed,ob);var Ns=m.forwardRef(function(e,t){return m.createElement(Es,In({},e,{ref:t,sideCar:ib}))});Ns.classNames=Es.classNames;var ab=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Dr=new WeakMap,_s=new WeakMap,js={},_a=0,Md=function(e){return e&&(e.host||Md(e.parentNode))},lb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Md(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})},cb=function(e,t,n,r){var o=lb(t,Array.isArray(e)?e:[e]);js[n]||(js[n]=new WeakMap);var s=js[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),g=p!==null&&p!=="false",y=(Dr.get(h)||0)+1,v=(s.get(h)||0)+1;Dr.set(h,y),s.set(h,v),i.push(h),y===1&&g&&_s.set(h,!0),v===1&&h.setAttribute(n,"true"),g||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),_a++,function(){i.forEach(function(f){var h=Dr.get(f)-1,p=s.get(f)-1;Dr.set(f,h),s.set(f,p),h||(_s.has(f)||f.removeAttribute(r),_s.delete(f)),p||f.removeAttribute(n)}),_a--,_a||(Dr=new WeakMap,Dr=new WeakMap,_s=new WeakMap,js={})}},ja=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=ab(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),cb(r,o,n,"aria-hidden")):function(){return null}},Rs="Dialog",[Dd,mT]=Tn(Rs),[ub,hn]=Dd(Rs),Ld=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[c,d]=mr({prop:r,defaultProp:o??!1,onChange:s,caller:Rs});return u.jsx(ub,{scope:t,triggerRef:a,contentRef:l,contentId:En(),titleId:En(),descriptionId:En(),open:c,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Ld.displayName=Rs;var Fd="DialogTrigger",$d=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Fd,n),s=He(t,o.triggerRef);return u.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Oa(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});$d.displayName=Fd;var Ra="DialogPortal",[db,zd]=Dd(Ra,{forceMount:void 0}),Bd=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=hn(Ra,t);return u.jsx(db,{scope:t,forceMount:n,children:m.Children.map(r,i=>u.jsx(qt,{present:n||s.open,children:u.jsx(Cs,{asChild:!0,container:o,children:i})}))})};Bd.displayName=Ra;var Ps="DialogOverlay",Hd=m.forwardRef((e,t)=>{const n=zd(Ps,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(Ps,e.__scopeDialog);return s.modal?u.jsx(qt,{present:r||s.open,children:u.jsx(hb,{...o,ref:t})}):null});Hd.displayName=Ps;var fb=sr.createSlot("DialogOverlay.RemoveScroll"),hb=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Ps,n);return u.jsx(Ns,{as:fb,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":Oa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),gr="DialogContent",Ud=m.forwardRef((e,t)=>{const n=zd(gr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(gr,e.__scopeDialog);return u.jsx(qt,{present:r||s.open,children:s.modal?u.jsx(pb,{...o,ref:t}):u.jsx(mb,{...o,ref:t})})});Ud.displayName=gr;var pb=m.forwardRef((e,t)=>{const n=hn(gr,e.__scopeDialog),r=m.useRef(null),o=He(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return ja(s)},[]),u.jsx(Wd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ge(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ge(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault())})}),mb=m.forwardRef((e,t)=>{const n=hn(gr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return u.jsx(Wd,{...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()}})}),Wd=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=hn(gr,n),l=m.useRef(null),c=He(t,l);return Ta(),u.jsxs(u.Fragment,{children:[u.jsx(Ss,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(bs,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Oa(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(gb,{titleId:a.titleId}),u.jsx(yb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Pa="DialogTitle",Vd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Pa,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Vd.displayName=Pa;var qd="DialogDescription",Kd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(qd,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Kd.displayName=qd;var Gd="DialogClose",Yd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Gd,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Yd.displayName=Gd;function Oa(e){return e?"open":"closed"}var Xd="DialogTitleWarning",[gT,Jd]=Fv(Xd,{contentName:gr,titleName:Pa,docsSlug:"dialog"}),gb=({titleId:e})=>{const t=Jd(Xd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
124
|
+
|
|
125
|
+
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
126
|
+
|
|
127
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},xb="DialogDescriptionWarning",yb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Jd(xb).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Zd=Ld,vb=$d,Qd=Bd,Os=Hd,Ms=Ud,xr=Vd,Ds=Kd,ef=Yd;const wb=Zd,bb=Qd,tf=m.forwardRef(({className:e,...t},n)=>u.jsx(Os,{ref:n,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}));tf.displayName=Os.displayName;const nf=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const c=l.type;if(c===xr||(c==null?void 0:c.displayName)===xr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(bb,{children:[u.jsx(tf,{}),u.jsxs(Ms,{ref:r,className:oe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(xr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(ef,{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-accent data-[state=open]:text-muted-foreground",children:[u.jsx(me.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});nf.displayName=Ms.displayName;const rf=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});rf.displayName="DialogHeader";const of=m.forwardRef(({className:e,...t},n)=>u.jsx(xr,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));of.displayName=xr.displayName;const Sb=m.forwardRef(({className:e,...t},n)=>u.jsx(Ds,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Sb.displayName=Ds.displayName;function Cb({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=b.useState(!1),[a,l]=b.useState(null),[c,d]=b.useState(null),{toast:f}=wa(),h=b.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await ud(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);b.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await aw(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},g=async()=>{if(n)try{const x=await ud(n),w=new Blob([x],{type:o}),S=URL.createObjectURL(w);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},y=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(me.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Xe,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(me.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),v=()=>o.startsWith("image/")?u.jsx(me.Image,{className:"h-5 w-5"}):u.jsx(me.FileText,{className:"h-5 w-5"});return u.jsx(wb,{open:e,onOpenChange:t,children:u.jsxs(nf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(rf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[v(),u.jsxs("div",{children:[u.jsx(of,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Xe,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(me.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Xe,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(me.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:y()})]})})}const kb="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 Tb(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function sf(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Ls(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Eb(e){const t=o=>{try{const s=xo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="tool_end");let r="";if(n.length)try{n.length===1?r=t(n[0].output):r=t(n.map(o=>({toolCallId:o.toolCallId,output:o.output})))}catch{r=""}else r=t(e);return r||""}function Ib(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function af(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function Ab({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)]})}const lf=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=200,showToolMessages:f=!0,customStyles:h={},onEdit:p,onRegenerate:g,onCancelEdit:y,onCopy:v,activeInterrupt:x,disableInterruptActions:w=!1,onInterruptActionStart:S,onInterruptActionEnd:T}){const[k,C]=b.useState(!1),[E,_]=b.useState("preview"),[j,D]=b.useState(!1),{currentThreadId:F}=Yo(),{respondToInterrupt:K}=Xo(),P=l==="phone"||l==="half-screen",R=t.role,L=R==="tool",U=!(r&&R!=="user"),{uploadingFiles:te,handleFileClick:V,fileViewerOpen:z,currentFileInfo:G,closeFileViewer:Q}=_b({allowFileOpen:U,currentThreadId:F}),le=b.useMemo(()=>{switch(R){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))]"}},[R]),B=b.useMemo(()=>Tb(t.content),[t.content]),ie=b.useMemo(()=>sf(t.content),[t.content]),Ce=b.useMemo(()=>t.content.filter(re=>re.type==="image_url"),[t.content]),ke=b.useMemo(()=>t.content.filter(re=>re.type==="file"),[t.content]),q=b.useMemo(()=>t.content.filter(re=>re.type==="interrupt"),[t.content]),M=(x==null?void 0:x.id)??(x==null?void 0:x.interrupt_id),X=Ls(M),ne=x==null?void 0:x.value,xe=b.useMemo(()=>Eb(t.content),[t.content]),se=b.useCallback(async()=>{const re=L?xe:B;async function ve(we){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(we);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Ye=new Blob([we],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Ye})]);return}throw new Error("Clipboard API not supported in this context.")}try{await ve(re),C(!0),setTimeout(()=>C(!1),2e3),v==null||v(re)}catch(we){console.error("Failed to copy:",we)}},[L,xe,B,v]),ae=b.useCallback(()=>{if(!p)return;const re=L?xe:B;p(t.id,re)},[p,t.id,L,xe,B]),Ue=b.useCallback(()=>{g==null||g(n)},[g,n]),Ke=b.useCallback(()=>{const ve=oe(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",le);switch(R){case"user":return u.jsx(me.User,{className:ve});case"assistant":return u.jsx(me.Bot,{className:ve});case"tool":return u.jsx(me.Wrench,{className:ve});default:return u.jsx(me.Bot,{className:ve})}},[P,le,R]),ot=b.useCallback(()=>{const re="group relative mb-4 flex w-full";switch(R){case"user":return oe(re,"justify-end");case"assistant":case"tool":case"system":return oe(re,"justify-start");default:return re}},[R]),st=b.useCallback(()=>{const re=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");switch(R){case"user":return oe(re,"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(re,"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(re,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(re,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(re,"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")}},[P,R]),ut=b.useCallback(async re=>{if(w)return;const ve=Ls((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id));if(!ve){console.warn("Interrupt part missing id",re);return}try{S==null||S(),await K(ve,!0)}catch(we){console.error("Failed to approve interrupt:",we)}finally{T==null||T()}},[w,T,S,K]),et=b.useCallback(async re=>{if(w)return;const ve=Ls((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id));if(!ve){console.warn("Interrupt part missing id",re);return}try{S==null||S(),await K(ve,!1)}catch(we){console.error("Failed to reject interrupt:",we)}finally{T==null||T()}},[w,T,S,K]),De=b.useCallback(({part:re,i:ve})=>{if(re.type==="text"){const we=re.text??"",Ye=we.trim(),xt=dd(Ye);return xt&&R!=="tool"?u.jsx(cf,{data:xt},ve):R==="user"&&c&&Ye.length>d?u.jsx(jb,{text:Ye,expanded:j,onExpandedChange:D,previewLength:d,isCompact:P},ve):u.jsx(ms,{content:we,allowHtml:!1},ve)}if(re.type==="image_url"){const we=re;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:we.url,alt:we.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},ve)}if(re.type==="file"){const we=re,Ye=we.name||"file";return u.jsxs("a",{href:we.url,onClick:xt=>V(xt,we,ve),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
128
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[te[ve]?u.jsx(me.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Ye,te[ve]?" (processing)":""]})]},ve)}if(re.type==="interrupt"){const we=re,Ye=Ls((we==null?void 0:we.id)??(we==null?void 0:we.interrupt_id)),xt=!!(X&&Ye&&Ye===X),ft=xt?ne??(we==null?void 0:we.value):we==null?void 0:we.value,wt=Ye?{...we,id:Ye,interrupt_id:Ye}:we;return u.jsx(Nb,{interruptPart:wt,onApprove:ut,onReject:et,disabled:w,isActive:xt,payload:ft},ve)}return null},[V,te,ut,et,R,c,d,j,P,X,ne,x,w,q]),We=b.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(me.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),it=b.useCallback(()=>{const re=B.trim().length>0||Ce.length>0||ke.length>0||q.length>0;if(!L&&ke.length>0&&!r)return We();if(!L&&!re&&!r)return null;if(L)return u.jsx(Rb,{message:t,viewMode:E},t.id);if(!L){const ve=u.jsx("div",{className:"space-y-2",children:t.content.map((we,Ye)=>u.jsx(De,{part:we,i:Ye},Ye))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ve,u.jsx(Ab,{className:le})]}):ve}},[B,Ce.length,ke.length,q.length,r,L,E,We,le]),gt=b.useMemo(()=>Ib(t),[t]);return L&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(ot(),h.container),children:u.jsxs("div",{className:oe(st(),h.content),children:[(i||a||L)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",le,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ke(),a&>&&u.jsx("span",{className:oe("font-medium",P?"text-xs":"text-sm"),children:gt}),L&&u.jsxs(ed,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",le,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E==="expanded",onClick:()=>_(re=>re==="expanded"?"preview":"expanded"),onKeyDown:re=>{(re.key==="Enter"||re.key===" ")&&(re.preventDefault(),_(ve=>ve==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ie.name??"Tool Output"}),ie.toolCallId&&u.jsx("span",{className:"opacity-70",children:ie.toolCallId.slice(0,8)}),E==="expanded"?u.jsx(me.ChevronUp,{className:"h-3 w-3"}):u.jsx(me.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",le,P&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:oe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>se(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",le,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(me.Copy,{className:oe(k?"text-success":le,P?"h-3 w-3":"h-4 w-4")})})}),R==="user"&&p&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ae,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",le,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(me.Edit,{className:oe(le,P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:Ue,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",le,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(me.RotateCcw,{className:oe(le,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:it()}),L&&E==="expanded"&&(ie.toolCallId||ie.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[ie.name&&u.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&u.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||L)&&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",h.actions),children:[u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>se(),className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(me.Copy,{className:oe(k?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="user"&&p&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ae,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(me.Edit,{className:oe("text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:Ue,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(me.RotateCcw,{className:oe("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),G&&u.jsx(Cb,{isOpen:z,onClose:Q,fileId:G.id,fileName:G.name,mimeType:G.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&af(e.message)===af(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(g=>e[g]===t[g]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function cf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:kb,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:ws(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ws(e)})}function Nb({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=ws(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(fo,{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(ho,{className:"pb-3",children:[u.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(td,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(mo,{className:"pt-0 pb-3",children:a}),u.jsx(nd,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Xe,{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(Xe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function _b(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=wa(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),d=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,g,y)=>{var v,x;if(!t){p.preventDefault();return}if(o[y]){p.preventDefault();return}try{const w=String(g.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=g.name||`file_${T}`,C=g.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[y]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await lw(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const C=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:g.name||C.filename||`file_${C.id}`,mimeType:g.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[y]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[y]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function jb({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return u.jsxs(ew,{open:t,onOpenChange:n,children:[u.jsx("div",{className:oe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(ms,{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:[e.substring(0,r),"..."]})}),u.jsx(tw,{asChild:!0,children:u.jsx(Xe,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:t?u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Rb({message:e,viewMode:t}){const r=sf(e.content).name||"tool",o=a=>{if(a==null)return null;const l=typeof a=="string"?dd(a)??a:a;if(l&&typeof l=="object")return u.jsx(cf,{data:l});const c=typeof l=="string"?l:(()=>{try{return ws(l)}catch{return String(l??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:c})};if(t==="preview")return null;const s=e.content.find(a=>a.type!=="tool_call");if(!s)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(me.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(s.type==="text"){const l=(s.text??"").trim();return l?o(l):null}const i=xo(s);return o(i)}const uf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ma=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:f,style:h,emptyMessage:p,followNewMessages:g=!0,isNavigatingCheckpoint:y=!1,onScrollAway:v,onAtBottom:x,activeInterrupt:w,disableInterruptActions:S=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C=!0},E)=>{const _=b.useRef(null),j=b.useRef(null),D=b.useRef(!1),[F,K]=b.useState(!0),P=b.useMemo(()=>w?e.some(G=>Array.isArray(G==null?void 0:G.content)&&G.content.some(Q=>Q&&Q.type==="interrupt"&&(Q.id??Q.interrupt_id)===w.id)):!1,[w,e]),R=b.useMemo(()=>{if(!w||P)return null;const G=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let Q;const le=w.value;if(le&&typeof le=="object"&&!Array.isArray(le)){const B=le.title;typeof B=="string"&&B.trim()&&(Q=B.trim())}return{id:`interrupt-${G}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:G,value:le,title:Q}]}},[w,P]),L=b.useMemo(()=>R?[...e,R]:e,[e,R]),U=b.useMemo(()=>C?L:L.filter(G=>(G==null?void 0:G.role)!=="tool"),[L,C]),te=b.useCallback(G=>{K(G),v&&v(!G),x&&x(G)},[v,x]),V=b.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),z=b.useMemo(()=>!g||y?!1:F?"auto":!1,[F,g,y]);return U.length===0?u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:typeof p=="string"?u.jsx(ms,{content:p,className:"prose-sm text-sm"}):p||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:f,style:h,children:u.jsx(sv,{ref:G=>{_.current=G},scrollerRef:G=>{j.current=G instanceof HTMLDivElement?G:null},data:U,followOutput:z,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{V&&V()},atBottomStateChange:te,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(G,Q)=>uf(Q,G),itemContent:(G,Q)=>{const le=uf(Q,G);return u.jsx("div",{className:"mb-4 last:mb-0","data-message-id":le,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(lf,{message:Q,messageIndex:G,isStreamingMessage:t&&n===Q.id,streamingDebounceMs:r,isEditing:i===Q.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(G),onCancelEdit:d,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C})})}})})});Ma.displayName="MessageList";const Fs=1e4;function Pb(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
129
129
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
130
130
|
|
|
131
131
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -133,4 +133,4 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
133
133
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
134
134
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
135
135
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
136
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Ob(e,t=Ls){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function Mb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Ob(t),Pb(t)}function Da(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=y=>{const{scope:v,children:x}=y,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:v,itemMap:S,collectionRef:w,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=sr.createSlot(a),c=b.forwardRef((y,v)=>{const{scope:x,children:w}=y,S=s(a,x),T=He(v,S.collectionRef);return u.jsx(l,{ref:T,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=sr.createSlot(d),p=b.forwardRef((y,v)=>{const{scope:x,children:w,...S}=y,T=b.useRef(null),k=He(v,T),C=s(d,x);return b.useEffect(()=>(C.itemMap.set(T,{ref:T,...S}),()=>void C.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=d;function g(y){const v=s(e+"CollectionConsumer",y);return b.useCallback(()=>{const w=v.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(v.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[v.collectionRef,v.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},g,r]}var Db=m.createContext(void 0);function Fs(e){const t=m.useContext(Db);return e||t||"ltr"}const Lb=["top","right","bottom","left"],Zn=Math.min,Kt=Math.max,$s=Math.round,zs=Math.floor,An=e=>({x:e,y:e}),Fb={left:"right",right:"left",bottom:"top",top:"bottom"},$b={start:"end",end:"start"};function La(e,t,n){return Kt(e,Zn(t,n))}function Bn(e,t){return typeof e=="function"?e(t):e}function Hn(e){return e.split("-")[0]}function Lr(e){return e.split("-")[1]}function Fa(e){return e==="x"?"y":"x"}function $a(e){return e==="y"?"height":"width"}const zb=new Set(["top","bottom"]);function Nn(e){return zb.has(Hn(e))?"y":"x"}function za(e){return Fa(Nn(e))}function Bb(e,t,n){n===void 0&&(n=!1);const r=Lr(e),o=za(e),s=$a(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Bs(i)),[i,Bs(i)]}function Hb(e){const t=Bs(e);return[Ba(e),t,Ba(t)]}function Ba(e){return e.replace(/start|end/g,t=>$b[t])}const df=["left","right"],ff=["right","left"],Ub=["top","bottom"],Wb=["bottom","top"];function Vb(e,t,n){switch(e){case"top":case"bottom":return n?t?ff:df:t?df:ff;case"left":case"right":return t?Ub:Wb;default:return[]}}function qb(e,t,n,r){const o=Lr(e);let s=Vb(Hn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ba)))),s}function Bs(e){return e.replace(/left|right|bottom|top/g,t=>Fb[t])}function Kb(e){return{top:0,right:0,bottom:0,left:0,...e}}function hf(e){return typeof e!="number"?Kb(e):{top:e,right:e,bottom:e,left:e}}function Hs(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 pf(e,t,n){let{reference:r,floating:o}=e;const s=Nn(t),i=za(t),a=$a(i),l=Hn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Lr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Gb=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:f}=pf(c,r,l),h=r,p={},g=0;for(let y=0;y<a.length;y++){const{name:v,fn:x}=a[y],{x:w,y:S,data:T,reset:k}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,p={...p,[v]:{...p[v],...T}},k&&g<=50&&(g++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(c=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=pf(c,h,l)),y=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function yo(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:f="floating",altBoundary:h=!1,padding:p=0}=Bn(t,e),g=hf(p),v=a[h?f==="floating"?"reference":"floating":f],x=Hs(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="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)),T=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},k=Hs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(x.top-k.top+g.top)/T.y,bottom:(k.bottom-x.bottom+g.bottom)/T.y,left:(x.left-k.left+g.left)/T.x,right:(k.right-x.right+g.right)/T.x}}const Yb=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}=Bn(e,t)||{};if(c==null)return{};const f=hf(d),h={x:n,y:r},p=za(o),g=$a(p),y=await i.getDimensions(c),v=p==="y",x=v?"top":"left",w=v?"bottom":"right",S=v?"clientHeight":"clientWidth",T=s.reference[g]+s.reference[p]-h[p]-s.floating[g],k=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[g]);const _=T/2-k/2,j=E/2-y[g]/2-1,D=Zn(f[x],j),F=Zn(f[w],j),K=D,P=E-y[g]-F,R=E/2-y[g]/2+_,L=La(K,R,P),U=!l.arrow&&Lr(o)!=null&&R!==L&&s.reference[g]/2-(R<K?D:F)-y[g]/2<0,te=U?R<K?R-K:R-P:0;return{[p]:h[p]+te,data:{[p]:L,centerOffset:R-L-te,...U&&{alignmentOffset:te}},reset:U}}}),Xb=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:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:y=!0,...v}=Bn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Hn(o),w=Nn(a),S=Hn(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(S||!y?[Bs(a)]:Hb(a)),C=g!=="none";!h&&C&&k.push(...qb(a,y,g,T));const E=[a,...k],_=await yo(t,v),j=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(_[x]),f){const R=Bb(o,i,T);j.push(_[R[0]],_[R[1]])}if(D=[...D,{placement:o,overflows:j}],!j.every(R=>R<=0)){var F,K;const R=(((F=s.flip)==null?void 0:F.index)||0)+1,L=E[R];if(L&&(!(f==="alignment"?w!==Nn(L):!1)||D.every(V=>Nn(V.placement)===w?V.overflows[0]>0:!0)))return{data:{index:R,overflows:D},reset:{placement:L}};let U=(K=D.filter(te=>te.overflows[0]<=0).sort((te,V)=>te.overflows[1]-V.overflows[1])[0])==null?void 0:K.placement;if(!U)switch(p){case"bestFit":{var P;const te=(P=D.filter(V=>{if(C){const z=Nn(V.placement);return z===w||z==="y"}return!0}).map(V=>[V.placement,V.overflows.filter(z=>z>0).reduce((z,G)=>z+G,0)]).sort((V,z)=>V[1]-z[1])[0])==null?void 0:P[0];te&&(U=te);break}case"initialPlacement":U=a;break}if(o!==U)return{reset:{placement:U}}}return{}}}};function mf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function gf(e){return Lb.some(t=>e[t]>=0)}const Jb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Bn(e,t);switch(r){case"referenceHidden":{const s=await yo(t,{...o,elementContext:"reference"}),i=mf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:gf(i)}}}case"escaped":{const s=await yo(t,{...o,altBoundary:!0}),i=mf(s,n.floating);return{data:{escapedOffsets:i,escaped:gf(i)}}}default:return{}}}}},xf=new Set(["left","top"]);async function Zb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Hn(n),a=Lr(n),l=Nn(n)==="y",c=xf.has(i)?-1:1,d=s&&l?-1:1,f=Bn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Qb=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 Zb(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}}}}},e0=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:v=>{let{x,y:w}=v;return{x,y:w}}},...l}=Bn(e,t),c={x:n,y:r},d=await yo(t,l),f=Nn(Hn(o)),h=Fa(f);let p=c[h],g=c[f];if(s){const v=h==="y"?"top":"left",x=h==="y"?"bottom":"right",w=p+d[v],S=p-d[x];p=La(w,p,S)}if(i){const v=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=g+d[v],S=g-d[x];g=La(w,g,S)}const y=a.fn({...t,[h]:p,[f]:g});return{...y,data:{x:y.x-n,y:y.y-r,enabled:{[h]:s,[f]:i}}}}}},t0=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}=Bn(e,t),d={x:n,y:r},f=Nn(o),h=Fa(f);let p=d[h],g=d[f];const y=Bn(a,t),v=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(l){const S=h==="y"?"height":"width",T=s.reference[h]-s.floating[S]+v.mainAxis,k=s.reference[h]+s.reference[S]-v.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var x,w;const S=h==="y"?"width":"height",T=xf.has(Hn(o)),k=s.reference[f]-s.floating[S]+(T&&((x=i.offset)==null?void 0:x[f])||0)+(T?0:v.crossAxis),C=s.reference[f]+s.reference[S]+(T?0:((w=i.offset)==null?void 0:w[f])||0)-(T?v.crossAxis:0);g<k?g=k:g>C&&(g=C)}return{[h]:p,[f]:g}}}},n0=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}=Bn(e,t),d=await yo(t,c),f=Hn(o),h=Lr(o),p=Nn(o)==="y",{width:g,height:y}=s.floating;let v,x;f==="top"||f==="bottom"?(v=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,v=h==="end"?"top":"bottom");const w=y-d.top-d.bottom,S=g-d.left-d.right,T=Zn(y-d[v],w),k=Zn(g-d[x],S),C=!t.middlewareData.shift;let E=T,_=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(_=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!h){const D=Kt(d.left,0),F=Kt(d.right,0),K=Kt(d.top,0),P=Kt(d.bottom,0);p?_=g-2*(D!==0||F!==0?D+F:Kt(d.left,d.right)):E=y-2*(K!==0||P!==0?K+P:Kt(d.top,d.bottom))}await l({...t,availableWidth:_,availableHeight:E});const j=await i.getDimensions(a.floating);return g!==j.width||y!==j.height?{reset:{rects:!0}}:{}}}};function Us(){return typeof window<"u"}function Fr(e){return yf(e)?(e.nodeName||"").toLowerCase():"#document"}function Gt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function _n(e){var t;return(t=(yf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function yf(e){return Us()?e instanceof Node||e instanceof Gt(e).Node:!1}function pn(e){return Us()?e instanceof Element||e instanceof Gt(e).Element:!1}function jn(e){return Us()?e instanceof HTMLElement||e instanceof Gt(e).HTMLElement:!1}function vf(e){return!Us()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gt(e).ShadowRoot}const r0=new Set(["inline","contents"]);function vo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=mn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!r0.has(o)}const o0=new Set(["table","td","th"]);function s0(e){return o0.has(Fr(e))}const i0=[":popover-open",":modal"];function Ws(e){return i0.some(t=>{try{return e.matches(t)}catch{return!1}})}const a0=["transform","translate","scale","rotate","perspective"],l0=["transform","translate","scale","rotate","perspective","filter"],c0=["paint","layout","strict","content"];function Ha(e){const t=Ua(),n=pn(e)?mn(e):e;return a0.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)||l0.some(r=>(n.willChange||"").includes(r))||c0.some(r=>(n.contain||"").includes(r))}function u0(e){let t=Qn(e);for(;jn(t)&&!$r(t);){if(Ha(t))return t;if(Ws(t))return null;t=Qn(t)}return null}function Ua(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const d0=new Set(["html","body","#document"]);function $r(e){return d0.has(Fr(e))}function mn(e){return Gt(e).getComputedStyle(e)}function Vs(e){return pn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Qn(e){if(Fr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||vf(e)&&e.host||_n(e);return vf(t)?t.host:t}function wf(e){const t=Qn(e);return $r(t)?e.ownerDocument?e.ownerDocument.body:e.body:jn(t)&&vo(t)?t:wf(t)}function wo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=wf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Gt(o);if(s){const a=Wa(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?wo(a):[])}return t.concat(o,wo(o,[],n))}function Wa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bf(e){const t=mn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=jn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=$s(n)!==s||$s(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Va(e){return pn(e)?e:e.contextElement}function zr(e){const t=Va(e);if(!jn(t))return An(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=bf(t);let i=(s?$s(n.width):n.width)/r,a=(s?$s(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const f0=An(0);function Sf(e){const t=Gt(e);return!Ua()||!t.visualViewport?f0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function h0(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Gt(e)?!1:t}function yr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Va(e);let i=An(1);t&&(r?pn(r)&&(i=zr(r)):i=zr(e));const a=h0(s,n,r)?Sf(s):An(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Gt(s),p=r&&pn(r)?Gt(r):r;let g=h,y=Wa(g);for(;y&&r&&p!==g;){const v=zr(y),x=y.getBoundingClientRect(),w=mn(y),S=x.left+(y.clientLeft+parseFloat(w.paddingLeft))*v.x,T=x.top+(y.clientTop+parseFloat(w.paddingTop))*v.y;l*=v.x,c*=v.y,d*=v.x,f*=v.y,l+=S,c+=T,g=Gt(y),y=Wa(g)}}return Hs({width:d,height:f,x:l,y:c})}function qs(e,t){const n=Vs(e).scrollLeft;return t?t.left+n:yr(_n(e)).left+n}function Cf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-qs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function p0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=_n(r),a=t?Ws(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=An(1);const d=An(0),f=jn(r);if((f||!f&&!s)&&((Fr(r)!=="body"||vo(i))&&(l=Vs(r)),jn(r))){const p=yr(r);c=zr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Cf(i,l):An(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function m0(e){return Array.from(e.getClientRects())}function g0(e){const t=_n(e),n=Vs(e),r=e.ownerDocument.body,o=Kt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Kt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+qs(e);const a=-n.scrollTop;return mn(r).direction==="rtl"&&(i+=Kt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const kf=25;function x0(e,t){const n=Gt(e),r=_n(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=Ua();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=qs(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,g=Math.abs(r.clientWidth-f.clientWidth-p);g<=kf&&(s-=g)}else c<=kf&&(s+=c);return{width:s,height:i,x:a,y:l}}const y0=new Set(["absolute","fixed"]);function v0(e,t){const n=yr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=jn(e)?zr(e):An(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 Tf(e,t,n){let r;if(t==="viewport")r=x0(e,n);else if(t==="document")r=g0(_n(e));else if(pn(t))r=v0(t,n);else{const o=Sf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Hs(r)}function Ef(e,t){const n=Qn(e);return n===t||!pn(n)||$r(n)?!1:mn(n).position==="fixed"||Ef(n,t)}function w0(e,t){const n=t.get(e);if(n)return n;let r=wo(e,[],!1).filter(a=>pn(a)&&Fr(a)!=="body"),o=null;const s=mn(e).position==="fixed";let i=s?Qn(e):e;for(;pn(i)&&!$r(i);){const a=mn(i),l=Ha(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&y0.has(o.position)||vo(i)&&!l&&Ef(e,i))?r=r.filter(d=>d!==i):o=a,i=Qn(i)}return t.set(e,r),r}function b0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Ws(t)?[]:w0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Tf(t,d,o);return c.top=Kt(f.top,c.top),c.right=Zn(f.right,c.right),c.bottom=Zn(f.bottom,c.bottom),c.left=Kt(f.left,c.left),c},Tf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function S0(e){const{width:t,height:n}=bf(e);return{width:t,height:n}}function C0(e,t,n){const r=jn(t),o=_n(t),s=n==="fixed",i=yr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=An(0);function c(){l.x=qs(o)}if(r||!r&&!s)if((Fr(t)!=="body"||vo(o))&&(a=Vs(t)),r){const p=yr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Cf(o,a):An(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function qa(e){return mn(e).position==="static"}function If(e,t){if(!jn(e)||mn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return _n(e)===n&&(n=n.ownerDocument.body),n}function Af(e,t){const n=Gt(e);if(Ws(e))return n;if(!jn(e)){let o=Qn(e);for(;o&&!$r(o);){if(pn(o)&&!qa(o))return o;o=Qn(o)}return n}let r=If(e,t);for(;r&&s0(r)&&qa(r);)r=If(r,t);return r&&$r(r)&&qa(r)&&!Ha(r)?n:r||u0(e)||n}const k0=async function(e){const t=this.getOffsetParent||Af,n=this.getDimensions,r=await n(e.floating);return{reference:C0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function T0(e){return mn(e).direction==="rtl"}const E0={convertOffsetParentRelativeRectToViewportRelativeRect:p0,getDocumentElement:_n,getClippingRect:b0,getOffsetParent:Af,getElementRects:k0,getClientRects:m0,getDimensions:S0,getScale:zr,isElement:pn,isRTL:T0};function Nf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function I0(e,t){let n=null,r;const o=_n(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:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const g=zs(f),y=zs(o.clientWidth-(d+h)),v=zs(o.clientHeight-(f+p)),x=zs(d),S={rootMargin:-g+"px "+-y+"px "+-v+"px "+-x+"px",threshold:Kt(0,Zn(1,l))||1};let T=!0;function k(C){const E=C[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Nf(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,S)}n.observe(e)}return i(!0),s}function A0(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=Va(e),d=o||s?[...c?wo(c):[],...wo(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?I0(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[w]=x;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let g,y=l?yr(e):null;l&&v();function v(){const x=yr(e);y&&!Nf(y,x)&&n(),y=x,g=requestAnimationFrame(v)}return n(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const N0=Qb,_0=e0,j0=Xb,R0=n0,P0=Jb,_f=Yb,O0=t0,M0=(e,t,n)=>{const r=new Map,o={platform:E0,...n},s={...o.platform,_c:r};return Gb(e,t,{...o,platform:s})};var D0=typeof document<"u",L0=function(){},Ks=D0?b.useLayoutEffect:L0;function Gs(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(!Gs(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)&&!Gs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function jf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Rf(e,t){const n=jf(e);return Math.round(t*n)/n}function Ka(e){const t=m.useRef(e);return Ks(()=>{t.current=e}),t}function F0(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,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Gs(h,r)||p(r);const[g,y]=m.useState(null),[v,x]=m.useState(null),w=m.useCallback(V=>{V!==C.current&&(C.current=V,y(V))},[]),S=m.useCallback(V=>{V!==E.current&&(E.current=V,x(V))},[]),T=s||g,k=i||v,C=m.useRef(null),E=m.useRef(null),_=m.useRef(d),j=l!=null,D=Ka(l),F=Ka(o),K=Ka(c),P=m.useCallback(()=>{if(!C.current||!E.current)return;const V={placement:t,strategy:n,middleware:h};F.current&&(V.platform=F.current),M0(C.current,E.current,V).then(z=>{const G={...z,isPositioned:K.current!==!1};R.current&&!Gs(_.current,G)&&(_.current=G,Po.flushSync(()=>{f(G)}))})},[h,t,n,F,K]);Ks(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,f(V=>({...V,isPositioned:!1})))},[c]);const R=m.useRef(!1);Ks(()=>(R.current=!0,()=>{R.current=!1}),[]),Ks(()=>{if(T&&(C.current=T),k&&(E.current=k),T&&k){if(D.current)return D.current(T,k,P);P()}},[T,k,P,D,j]);const L=m.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),U=m.useMemo(()=>({reference:T,floating:k}),[T,k]),te=m.useMemo(()=>{const V={position:n,left:0,top:0};if(!U.floating)return V;const z=Rf(U.floating,d.x),G=Rf(U.floating,d.y);return a?{...V,transform:"translate("+z+"px, "+G+"px)",...jf(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:z,top:G}},[n,a,U.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:P,refs:L,elements:U,floatingStyles:te}),[d,P,L,U,te])}const $0=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?_f({element:r.current,padding:o}).fn(n):{}:r?_f({element:r,padding:o}).fn(n):{}}}},z0=(e,t)=>({...N0(e),options:[e,t]}),B0=(e,t)=>({..._0(e),options:[e,t]}),H0=(e,t)=>({...O0(e),options:[e,t]}),U0=(e,t)=>({...j0(e),options:[e,t]}),W0=(e,t)=>({...R0(e),options:[e,t]}),V0=(e,t)=>({...P0(e),options:[e,t]}),q0=(e,t)=>({...$0(e),options:[e,t]});var K0="Arrow",Pf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ne.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"})})});Pf.displayName=K0;var G0=Pf;function Of(e){const[t,n]=m.useState(void 0);return kt(()=>{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 Ga="Popper",[Mf,Ys]=Tn(Ga),[Y0,Df]=Mf(Ga),Lf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return u.jsx(Y0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Lf.displayName=Ga;var Ff="PopperAnchor",$f=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Df(Ff,n),i=m.useRef(null),a=He(t,i),l=m.useRef(null);return m.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(Ne.div,{...o,ref:a})});$f.displayName=Ff;var Ya="PopperContent",[X0,J0]=Mf(Ya),zf=m.forwardRef((e,t)=>{var q,M,X,ne,xe,se;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:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:g,...y}=e,v=Df(Ya,n),[x,w]=m.useState(null),S=He(t,ae=>w(ae)),[T,k]=m.useState(null),C=Of(T),E=(C==null?void 0:C.width)??0,_=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),D=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},F=Array.isArray(c)?c:[c],K=F.length>0,P={padding:D,boundary:F.filter(Q0),altBoundary:K},{refs:R,floatingStyles:L,placement:U,isPositioned:te,middlewareData:V}=F0({strategy:"fixed",placement:j,whileElementsMounted:(...ae)=>A0(...ae,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[z0({mainAxis:o+_,alignmentAxis:i}),l&&B0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?H0():void 0,...P}),l&&U0({...P}),W0({...P,apply:({elements:ae,rects:Ue,availableWidth:Ke,availableHeight:ot})=>{const{width:st,height:ut}=Ue.reference,et=ae.floating.style;et.setProperty("--radix-popper-available-width",`${Ke}px`),et.setProperty("--radix-popper-available-height",`${ot}px`),et.setProperty("--radix-popper-anchor-width",`${st}px`),et.setProperty("--radix-popper-anchor-height",`${ut}px`)}}),T&&q0({element:T,padding:a}),eS({arrowWidth:E,arrowHeight:_}),h&&V0({strategy:"referenceHidden",...P})]}),[z,G]=Uf(U),Q=At(g);kt(()=>{te&&(Q==null||Q())},[te,Q]);const le=(q=V.arrow)==null?void 0:q.x,B=(M=V.arrow)==null?void 0:M.y,ie=((X=V.arrow)==null?void 0:X.centerOffset)!==0,[Ce,ke]=m.useState();return kt(()=>{x&&ke(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:te?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ce,"--radix-popper-transform-origin":[(ne=V.transformOrigin)==null?void 0:ne.x,(xe=V.transformOrigin)==null?void 0:xe.y].join(" "),...((se=V.hide)==null?void 0:se.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(X0,{scope:n,placedSide:z,onArrowChange:k,arrowX:le,arrowY:B,shouldHideArrow:ie,children:u.jsx(Ne.div,{"data-side":z,"data-align":G,...y,ref:S,style:{...y.style,animation:te?void 0:"none"}})})})});zf.displayName=Ya;var Bf="PopperArrow",Z0={top:"bottom",right:"left",bottom:"top",left:"right"},Hf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=J0(Bf,r),i=Z0[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(G0,{...o,ref:n,style:{...o.style,display:"block"}})})});Hf.displayName=Bf;function Q0(e){return e!==null}var eS=e=>({name:"transformOrigin",options:e,fn(t){var v,x,w;const{placement:n,rects:r,middlewareData:o}=t,i=((v=o.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=Uf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let g="",y="";return c==="bottom"?(g=i?f:`${h}px`,y=`${-l}px`):c==="top"?(g=i?f:`${h}px`,y=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,y=i?f:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,y=i?f:`${p}px`),{data:{x:g,y}}}});function Uf(e){const[t,n="center"]=e.split("-");return[t,n]}var Wf=Lf,Vf=$f,qf=zf,Kf=Hf,Xa="rovingFocusGroup.onEntryFocus",tS={bubbles:!1,cancelable:!0},bo="RovingFocusGroup",[Ja,Gf,nS]=Da(bo),[rS,Yf]=Tn(bo,[nS]),[oS,sS]=rS(bo),Xf=m.forwardRef((e,t)=>u.jsx(Ja.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Ja.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(iS,{...e,ref:t})})}));Xf.displayName=bo;var iS=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=He(t,h),g=Fs(s),[y,v]=pr({prop:i,defaultProp:a??null,onChange:l,caller:bo}),[x,w]=m.useState(!1),S=At(c),T=Gf(n),k=m.useRef(!1),[C,E]=m.useState(0);return m.useEffect(()=>{const _=h.current;if(_)return _.addEventListener(Xa,S),()=>_.removeEventListener(Xa,S)},[S]),u.jsx(oS,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:y,onItemFocus:m.useCallback(_=>v(_),[v]),onItemShiftTab:m.useCallback(()=>w(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:m.useCallback(()=>E(_=>_-1),[]),children:u.jsx(Ne.div,{tabIndex:x||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ge(e.onMouseDown,()=>{k.current=!0}),onFocus:ge(e.onFocus,_=>{const j=!k.current;if(_.target===_.currentTarget&&j&&!x){const D=new CustomEvent(Xa,tS);if(_.currentTarget.dispatchEvent(D),!D.defaultPrevented){const F=T().filter(U=>U.focusable),K=F.find(U=>U.active),P=F.find(U=>U.id===y),L=[K,P,...F].filter(Boolean).map(U=>U.ref.current);Qf(L,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),Jf="RovingFocusGroupItem",Zf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=En(),c=s||l,d=sS(Jf,n),f=d.currentTabStopId===c,h=Gf(n),{onFocusableItemAdd:p,onFocusableItemRemove:g,currentTabStopId:y}=d;return m.useEffect(()=>{if(r)return p(),()=>g()},[r,p,g]),u.jsx(Ja.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ge(e.onMouseDown,v=>{r?d.onItemFocus(c):v.preventDefault()}),onFocus:ge(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ge(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const x=cS(v,d.orientation,d.dir);if(x!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let S=h().filter(T=>T.focusable).map(T=>T.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const T=S.indexOf(v.currentTarget);S=d.loop?uS(S,T+1):S.slice(T+1)}setTimeout(()=>Qf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:y!=null}):i})})});Zf.displayName=Jf;var aS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function lS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function cS(e,t,n){const r=lS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return aS[r]}function Qf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function uS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var dS=Xf,fS=Zf,Za=["Enter"," "],hS=["ArrowDown","PageUp","Home"],eh=["ArrowUp","PageDown","End"],pS=[...hS,...eh],mS={ltr:[...Za,"ArrowRight"],rtl:[...Za,"ArrowLeft"]},gS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,xS,yS]=Da(So),[vr,th]=Tn(So,[yS,Ys,Yf]),Xs=Ys(),nh=Yf(),[vS,wr]=vr(So),[wS,ko]=vr(So),rh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Xs(t),[l,c]=m.useState(null),d=m.useRef(!1),f=At(s),h=Fs(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(Wf,{...a,children:u.jsx(vS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(wS,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};rh.displayName=So;var bS="MenuAnchor",Qa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Xs(n);return u.jsx(Vf,{...o,...r,ref:t})});Qa.displayName=bS;var el="MenuPortal",[SS,oh]=vr(el,{forceMount:void 0}),sh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=wr(el,t);return u.jsx(SS,{scope:t,forceMount:n,children:u.jsx(qt,{present:n||s.open,children:u.jsx(ys,{asChild:!0,container:o,children:r})})})};sh.displayName=el;var nn="MenuContent",[CS,tl]=vr(nn),ih=m.forwardRef((e,t)=>{const n=oh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=ko(nn,e.__scopeMenu);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(qt,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(kS,{...o,ref:t}):u.jsx(TS,{...o,ref:t})})})})}),kS=m.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu),r=m.useRef(null),o=He(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Aa(s)},[]),u.jsx(nl,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),TS=m.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu);return u.jsx(nl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ES=sr.createSlot("MenuContent.ScrollLock"),nl=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:g,...y}=e,v=wr(nn,n),x=ko(nn,n),w=Xs(n),S=nh(n),T=xS(n),[k,C]=m.useState(null),E=m.useRef(null),_=He(t,E,v.onContentChange),j=m.useRef(0),D=m.useRef(""),F=m.useRef(0),K=m.useRef(null),P=m.useRef("right"),R=m.useRef(0),L=g?ks:m.Fragment,U=g?{as:ES,allowPinchZoom:!0}:void 0,te=z=>{var q,M;const G=D.current+z,Q=T().filter(X=>!X.disabled),le=document.activeElement,B=(q=Q.find(X=>X.ref.current===le))==null?void 0:q.textValue,ie=Q.map(X=>X.textValue),Ce=FS(ie,G,B),ke=(M=Q.find(X=>X.textValue===Ce))==null?void 0:M.ref.current;(function X(ne){D.current=ne,window.clearTimeout(j.current),ne!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(G),ke&&setTimeout(()=>ke.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),Sa();const V=m.useCallback(z=>{var Q,le;return P.current===((Q=K.current)==null?void 0:Q.side)&&zS(z,(le=K.current)==null?void 0:le.area)},[]);return u.jsx(CS,{scope:n,searchRef:D,onItemEnter:m.useCallback(z=>{V(z)&&z.preventDefault()},[V]),onItemLeave:m.useCallback(z=>{var G;V(z)||((G=E.current)==null||G.focus(),C(null))},[V]),onTriggerLeave:m.useCallback(z=>{V(z)&&z.preventDefault()},[V]),pointerGraceTimerRef:F,onPointerGraceIntentChange:m.useCallback(z=>{K.current=z},[]),children:u.jsx(L,{...U,children:u.jsx(xs,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,z=>{var G;z.preventDefault(),(G=E.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(gs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(dS,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:ge(l,z=>{x.isUsingKeyboardRef.current||z.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(qf,{role:"menu","aria-orientation":"vertical","data-state":Ch(v.open),"data-radix-menu-content":"",dir:x.dir,...w,...y,ref:_,style:{outline:"none",...y.style},onKeyDown:ge(y.onKeyDown,z=>{const Q=z.target.closest("[data-radix-menu-content]")===z.currentTarget,le=z.ctrlKey||z.altKey||z.metaKey,B=z.key.length===1;Q&&(z.key==="Tab"&&z.preventDefault(),!le&&B&&te(z.key));const ie=E.current;if(z.target!==ie||!pS.includes(z.key))return;z.preventDefault();const ke=T().filter(q=>!q.disabled).map(q=>q.ref.current);eh.includes(z.key)&&ke.reverse(),DS(ke)}),onBlur:ge(e.onBlur,z=>{z.currentTarget.contains(z.target)||(window.clearTimeout(j.current),D.current="")}),onPointerMove:ge(e.onPointerMove,Eo(z=>{const G=z.target,Q=R.current!==z.clientX;if(z.currentTarget.contains(G)&&Q){const le=z.clientX>R.current?"right":"left";P.current=le,R.current=z.clientX}}))})})})})})})});ih.displayName=nn;var IS="MenuGroup",rl=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});rl.displayName=IS;var AS="MenuLabel",ah=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});ah.displayName=AS;var Js="MenuItem",lh="menu.itemSelect",Zs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=ko(Js,e.__scopeMenu),a=tl(Js,e.__scopeMenu),l=He(t,s),c=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(lh,{bubbles:!0,cancelable:!0});f.addEventListener(lh,p=>r==null?void 0:r(p),{once:!0}),Vu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(ch,{...o,ref:l,disabled:n,onClick:ge(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ge(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ge(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Za.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Zs.displayName=Js;var ch=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=tl(Js,n),a=nh(n),l=m.useRef(null),c=He(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const g=l.current;g&&p((g.textContent??"").trim())},[s.children]),u.jsx(Co.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(fS,{asChild:!0,...a,focusable:!r,children:u.jsx(Ne.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ge(e.onPointerMove,Eo(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Eo(g=>i.onItemLeave(g))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),NS="MenuCheckboxItem",uh=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(mh,{scope:e.__scopeMenu,checked:n,children:u.jsx(Zs,{role:"menuitemcheckbox","aria-checked":Qs(n)?"mixed":n,...o,ref:t,"data-state":sl(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(Qs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});uh.displayName=NS;var dh="MenuRadioGroup",[_S,jS]=vr(dh,{value:void 0,onValueChange:()=>{}}),fh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=At(r);return u.jsx(_S,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(rl,{...o,ref:t})})});fh.displayName=dh;var hh="MenuRadioItem",ph=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=jS(hh,e.__scopeMenu),s=n===o.value;return u.jsx(mh,{scope:e.__scopeMenu,checked:s,children:u.jsx(Zs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":sl(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});ph.displayName=hh;var ol="MenuItemIndicator",[mh,RS]=vr(ol,{checked:!1}),gh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=RS(ol,n);return u.jsx(qt,{present:r||Qs(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":sl(s.checked)})})});gh.displayName=ol;var PS="MenuSeparator",xh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});xh.displayName=PS;var OS="MenuArrow",yh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Xs(n);return u.jsx(Kf,{...o,...r,ref:t})});yh.displayName=OS;var MS="MenuSub",[xT,vh]=vr(MS),To="MenuSubTrigger",wh=m.forwardRef((e,t)=>{const n=wr(To,e.__scopeMenu),r=ko(To,e.__scopeMenu),o=vh(To,e.__scopeMenu),s=tl(To,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Qa,{asChild:!0,...c,children:u.jsx(ch,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Ch(n.open),...e,ref:da(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ge(e.onPointerMove,Eo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ge(e.onPointerLeave,Eo(f=>{var p,g;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const y=(g=n.content)==null?void 0:g.dataset.side,v=y==="right",x=v?-5:5,w=h[v?"left":"right"],S=h[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:w,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:w,y:h.bottom}],side:y}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ge(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||mS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});wh.displayName=To;var bh="MenuSubContent",Sh=m.forwardRef((e,t)=>{const n=oh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=ko(nn,e.__scopeMenu),a=vh(bh,e.__scopeMenu),l=m.useRef(null),c=He(t,l);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(qt,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:u.jsx(nl,{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 f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ge(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ge(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ge(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=gS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Sh.displayName=bh;function Ch(e){return e?"open":"closed"}function Qs(e){return e==="indeterminate"}function sl(e){return Qs(e)?"indeterminate":e?"checked":"unchecked"}function DS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function LS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function FS(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=LS(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 $S(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,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function zS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return $S(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var BS=rh,HS=Qa,US=sh,WS=ih,VS=rl,qS=ah,KS=Zs,GS=uh,YS=fh,XS=ph,JS=gh,ZS=xh,QS=yh,eC=wh,tC=Sh,ei="DropdownMenu",[nC,yT]=Tn(ei,[th]),$t=th(),[rC,kh]=nC(ei),Th=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=$t(t),c=m.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:ei});return u.jsx(rC,{scope:t,triggerId:En(),triggerRef:c,contentId:En(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(BS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Th.displayName=ei;var Eh="DropdownMenuTrigger",Ih=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=kh(Eh,n),i=$t(n);return u.jsx(HS,{asChild:!0,...i,children:u.jsx(Ne.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:da(t,s.triggerRef),onPointerDown:ge(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ge(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ih.displayName=Eh;var oC="DropdownMenuPortal",Ah=e=>{const{__scopeDropdownMenu:t,...n}=e,r=$t(t);return u.jsx(US,{...r,...n})};Ah.displayName=oC;var Nh="DropdownMenuContent",_h=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=kh(Nh,n),s=$t(n),i=m.useRef(!1);return u.jsx(WS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ge(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ge(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)"}})});_h.displayName=Nh;var sC="DropdownMenuGroup",iC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(VS,{...o,...r,ref:t})});iC.displayName=sC;var aC="DropdownMenuLabel",jh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(qS,{...o,...r,ref:t})});jh.displayName=aC;var lC="DropdownMenuItem",Rh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(KS,{...o,...r,ref:t})});Rh.displayName=lC;var cC="DropdownMenuCheckboxItem",Ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(GS,{...o,...r,ref:t})});Ph.displayName=cC;var uC="DropdownMenuRadioGroup",dC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(YS,{...o,...r,ref:t})});dC.displayName=uC;var fC="DropdownMenuRadioItem",Oh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(XS,{...o,...r,ref:t})});Oh.displayName=fC;var hC="DropdownMenuItemIndicator",Mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(JS,{...o,...r,ref:t})});Mh.displayName=hC;var pC="DropdownMenuSeparator",Dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(ZS,{...o,...r,ref:t})});Dh.displayName=pC;var mC="DropdownMenuArrow",gC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(QS,{...o,...r,ref:t})});gC.displayName=mC;var xC="DropdownMenuSubTrigger",Lh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(eC,{...o,...r,ref:t})});Lh.displayName=xC;var yC="DropdownMenuSubContent",Fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(tC,{...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)"}})});Fh.displayName=yC;var vC=Th,wC=Ih,bC=Ah,$h=_h,zh=jh,Bh=Rh,Hh=Ph,Uh=Oh,Wh=Mh,Vh=Dh,qh=Lh,Kh=Fh;const SC=vC,CC=wC,kC=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(qh,{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(me.ChevronRight,{className:"ml-auto h-4 w-4"})]}));kC.displayName=qh.displayName;const TC=m.forwardRef(({className:e,...t},n)=>u.jsx(Kh,{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}));TC.displayName=Kh.displayName;const Gh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(bC,{children:u.jsx($h,{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})}));Gh.displayName=$h.displayName;const il=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Bh,{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}));il.displayName=Bh.displayName;const EC=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(Hh,{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(Wh,{children:u.jsx(me.Check,{className:"h-4 w-4"})})}),t]}));EC.displayName=Hh.displayName;const IC=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Uh,{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(Wh,{children:u.jsx(me.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));IC.displayName=Uh.displayName;const AC=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(zh,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));AC.displayName=zh.displayName;const NC=m.forwardRef(({className:e,...t},n)=>u.jsx(Vh,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));NC.displayName=Vh.displayName;const Yh={value:""};function ti({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,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:g}){const{api:y}=Ai(),{currentThreadId:v}=Yo(),{threadId:x,messages:w,hasMore:S,isHistoryLoading:T,isLoading:k,loadOlder:C,navigateToCheckpoint:E,returnToLatest:_,checkpoint:j,checkpoints:D,interrupt:F,metadata:K}=Xo(),{isStreaming:P,error:R,submit:L,stop:U}=Bc(),te=x??v??null,V=(j==null?void 0:j.id)??null,z=(j==null?void 0:j.namespace)??null,G=(K==null?void 0:K.assemblingMessageId)??null,Q=F,[le,B]=b.useState(!1);b.useEffect(()=>{Q||B(!1)},[Q]);const ie=b.useCallback(()=>{B(!0)},[]),Ce=b.useCallback(()=>{B(!1)},[]),ke=!!Q||le,[q,M]=b.useState(null),[X,ne]=b.useState(""),[xe,se]=b.useState(null),[ae,Ue]=b.useState([]),[Ke,ot]=b.useState(0),[st,ut]=b.useState(0),[et,De]=b.useState(!1),[We,it]=b.useState(null),[gt,re]=b.useState(null),[ve,we]=b.useState(!1),[Ye,xt]=b.useState(null),[ft,wt]=b.useState(!1),Fe=b.useRef(!1),[Ze,Tt]=b.useState(()=>Yh.value),St=b.useRef(Ze),Yt=b.useRef(null),Et=b.useCallback($=>{Yh.value=$,Tt($)},[]),[rr,Xt]=b.useState(!1),xn=b.useCallback(($,de)=>{if(!$||typeof $!="object")return null;const he=$[de];return typeof he=="number"?he:null},[]),sn=b.useCallback(($,de)=>{if(!$||typeof $!="object")return null;const he=$[de];return typeof he=="string"&&he.trim()?he:null},[]),Dt=b.useMemo(()=>{const $=Array.isArray(D)?[...D]:[];return $.some(he=>xn(he.metadata,"step")!==null)&&$.sort((he,Ie)=>{const tt=xn(he.metadata,"step"),Lt=xn(Ie.metadata,"step");if(tt!==null||Lt!==null)return(Lt??Number.NEGATIVE_INFINITY)-(tt??Number.NEGATIVE_INFINITY);const an=Date.parse(he.createdAt??""),Ct=Date.parse(Ie.createdAt??"");return Number.isNaN(an)||Number.isNaN(Ct)?0:Ct-an}),$},[D,xn]),Pn=b.useRef(null),yn=b.useRef(null),ht=b.useCallback(()=>{Pn.current&&(Pn.current.value=""),yn.current&&(yn.current.value=""),ot($=>$+1),ut($=>$+1)},[]),vn=b.useCallback($=>{Et($)},[Et]),On=b.useRef(!1);b.useEffect(()=>{On.current&&!P&&(Ue([]),ht()),On.current=P},[P,ht]);const[kr,Jt]=b.useState("desktop");b.useEffect(()=>{const $=()=>{const de=window.innerWidth;Jt(de<640?"phone":de<1024?"tablet":"desktop")};return $(),window.addEventListener("resize",$),()=>window.removeEventListener("resize",$)},[]),b.useEffect(()=>{wt(!1),Fe.current=!1},[te]),b.useEffect(()=>{St.current=Ze},[Ze]),b.useEffect(()=>{if(!q){Yt.current=null;return}Yt.current===null&&(Yt.current=St.current),Et(X??"")},[X,q,Et]);const Tr=b.useCallback(async()=>{if(!(!S||T||!ft))try{await C()}catch($){console.warn("loadOlder failed",$)}},[S,ft,T,C]);b.useEffect(()=>{(async()=>{if(!y.baseUrl){xt(null);return}try{const de=await y.getAgent("default");xt(de.uiDefaultMessage||null)}catch(de){console.warn("Failed to fetch default message:",de),xt(null)}})()},[y.baseUrl]),b.useEffect(()=>{R&&!ve&&(g==null||g(R))},[R,ve,g]);const Mn=$=>{if($.length>Ls)return`Message too long (${$.length}/${Ls} characters)`;try{return Mb($),null}catch(de){return(de==null?void 0:de.message)||"Invalid message"}},wn=async $=>{const de=$.trim();if(!(!de&&ae.length===0)){if(de){const he=Mn(de);if(he){se(he);return}}try{await L({text:de||"",attachments:ae,payload:q?{edit:!0,originalMessageId:q}:void 0},{checkpointId:V??void 0,checkpointNs:z??void 0}),h==null||h(de),Et(""),se(null),Ue([]),ht(),M(null),ne("")}catch(he){const Ie=(he==null?void 0:he.message)||"Failed to send message";se(Ie),g==null||g(Ie)}}},Un=b.useCallback(($,de)=>{c&&(Yt.current=Ze,M($),ne(de),Et(de),se(null))},[Ze,c,Et]),Er=b.useCallback(()=>{M(null),ne(""),se(null),Et(Yt.current??Ze),Yt.current=null},[Ze,Et]),Wr=b.useCallback(($,de)=>{Un($,de)},[Un]),Vr=b.useCallback($=>{const de=he=>{const Ie=he.content||[],tt=Ie.filter(Lt=>Lt.type==="text").map(Lt=>Lt.text).join("");if(tt)return tt;try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}};for(let he=$-1;he>=0;he--)if(w[he].role==="user"){const Ie=de(w[he]);Ie&&L({text:Ie},{checkpointId:V??void 0,checkpointNs:z??void 0});break}},[w,L,V,z]),or=$=>{const de=Array.from($.target.files||[]);Ue(he=>[...he,...de]),$.target.value=""},I=$=>{Ue(de=>{const he=de.filter((Ie,tt)=>$!==tt);return he.length===0&&ht(),he})},H=async $=>{const de=($.target.files||[])[0];if(de){it(null),re(null),De(!0);try{await L({attachments:[de]},{checkpointId:V??void 0,checkpointNs:z??void 0});const he=`Uploaded ${de.name} - processing through chat stream`;re(he)}catch(he){const Ie=he instanceof Error?he.message:"Failed to upload Excel file";console.error("Excel upload failed",he),it(Ie),g==null||g(Ie)}finally{De(!1),$.target.value="",ht()}}},ue=$=>{if(!$)return"Unknown";const de=Date.parse($);return Number.isNaN(de)?$:new Date(de).toLocaleString()},Te=async $=>{if(v){Xt(!0);try{if(!$){await _();return}const de=Dt.find(Ie=>Ie.checkpointId===$),he=(de==null?void 0:de.checkpointNs)??null;await E($,he)}finally{Xt(!1)}}},qe=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,$e=`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 ${f.messagesArea||""}`,Le=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`;return u.jsxs("div",{className:qe,children:[!!R&&!ve&&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:R}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>we(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(me.X,{size:16})})]}),v&&D.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:V??"",onChange:$=>{const de=$.target.value||null;Te(de)},children:[u.jsx("option",{value:"",children:"Latest"}),Dt.map($=>{const de=xn($.metadata,"step"),he=sn($.metadata,"source"),Ie=[];de!==null&&Ie.push(`Step ${de}`),he&&Ie.push(he);const tt=Ie.length?` — ${Ie.join(" • ")}`:"";return u.jsxs("option",{value:$.checkpointId,children:[ue($.createdAt),tt]},$.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${$e}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Ma,{className:"h-full",style:{height:"100%"},messages:w,isStreaming:P,streamingAssistantId:G,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:kr,enableMessageEditing:c,editingMessageId:q,onStartReached:()=>{ft&&Tr()},onScrollAway:$=>{if(!Fe.current){Fe.current=!0;return}$&&wt(!0)},onEdit:Wr,onRegenerate:Vr,onCancelEdit:Er,emptyMessage:Ye??void 0,isNavigatingCheckpoint:rr,activeInterrupt:Q,disableInterruptActions:le,onInterruptActionStart:ie,onInterruptActionEnd:Ce,showToolMessages:d}),k&&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(me.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),u.jsxs("div",{className:Le,children:[q&&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(me.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:Er,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(me.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:Pn,type:"file",multiple:!0,onChange:$=>or($),className:"hidden"},Ke),ae.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:ae.map(($,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(me.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:$.name}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>I(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 ${$.name}`,children:u.jsx(me.X,{size:12})})]},de))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:yn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:H,className:"hidden"},st),et&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(me.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!et&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),We&&!et&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:We})]})]}),xe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:xe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(SC,{children:[u.jsx(CC,{asChild:!0,children:u.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:P||ke,title:"More input actions",className:f.moreButton||"",children:u.jsx(me.Plus,{size:16})})}),u.jsxs(Gh,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(il,{onClick:()=>{var $;return($=Pn.current)==null?void 0:$.click()},className:"cursor-pointer",children:[u.jsx(me.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(il,{onClick:()=>{var $;et||($=yn.current)==null||$.click()},className:`cursor-pointer ${et?"opacity-60 pointer-events-none":""}`,children:[u.jsx(me.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(Yx,{initialValue:X,editingMessageId:q,value:Ze,onValueChange:vn,placeholder:q?"Edit your message...":t,isStreaming:P,disabled:ke,maxLength:Ls,onSend:wn,onCancelEdit:Er,onStop:U,allowEmptySend:ae.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${q?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${xe?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const ni=m.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}));ni.displayName="Input";function al(e,[t,n]){return Math.min(n,Math.max(t,e))}function _C(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var ll="ScrollArea",[Xh,vT]=Tn(ll),[jC,rn]=Xh(ll),Jh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[c,d]=m.useState(null),[f,h]=m.useState(null),[p,g]=m.useState(null),[y,v]=m.useState(null),[x,w]=m.useState(0),[S,T]=m.useState(0),[k,C]=m.useState(!1),[E,_]=m.useState(!1),j=He(t,F=>l(F)),D=Fs(o);return u.jsx(jC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:g,scrollbarXEnabled:k,onScrollbarXEnabledChange:C,scrollbarY:y,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:_,onCornerWidthChange:w,onCornerHeightChange:T,children:u.jsx(Ne.div,{dir:D,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Jh.displayName=ll;var Zh="ScrollAreaViewport",Qh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=rn(Zh,n),a=m.useRef(null),l=He(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(Ne.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})})]})});Qh.displayName=Zh;var Rn="ScrollAreaScrollbar",cl=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(RC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(PC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(ep,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(ul,{...r,ref:t}):null});cl.displayName=Rn;var RC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.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(qt,{present:n||s,children:u.jsx(ep,{"data-state":s?"visible":"hidden",...r,ref:t})})}),PC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ii(()=>l("SCROLL_END"),100),[a,l]=_C("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 m.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(qt,{present:n||a!=="hidden",children:u.jsx(ul,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),ep=m.forwardRef((e,t)=>{const n=rn(Rn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=ii(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Br(n.viewport,l),Br(n.content,l),u.jsx(qt,{present:r||s,children:u.jsx(ul,{"data-state":s?"visible":"hidden",...o,ref:t})})}),ul=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=rn(Rn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return $C(h,i.current,a,p)}return n==="horizontal"?u.jsx(OC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=ip(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(MC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=ip(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),OC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=He(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(np,{"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":si(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),lp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:oi(i.paddingLeft),paddingEnd:oi(i.paddingRight)}})}})}),MC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=He(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(np,{"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":si(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),lp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:oi(i.paddingTop),paddingEnd:oi(i.paddingBottom)}})}})}),[DC,tp]=Xh(Rn),np=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...h}=e,p=rn(Rn,n),[g,y]=m.useState(null),v=He(t,j=>y(j)),x=m.useRef(null),w=m.useRef(""),S=p.viewport,T=r.content-r.viewport,k=At(d),C=At(l),E=ii(f,10);function _(j){if(x.current){const D=j.clientX-x.current.left,F=j.clientY-x.current.top;c({x:D,y:F})}}return m.useEffect(()=>{const j=D=>{const F=D.target;(g==null?void 0:g.contains(F))&&k(D,T)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,g,T,k]),m.useEffect(C,[r,C]),Br(g,E),Br(p.content,E),u.jsx(DC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:At(s),onThumbPointerUp:At(i),onThumbPositionChange:C,onThumbPointerDown:At(a),children:u.jsx(Ne.div,{...h,ref:v,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),x.current=g.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),_(j))}),onPointerMove:ge(e.onPointerMove,_),onPointerUp:ge(e.onPointerUp,j=>{const D=j.target;D.hasPointerCapture(j.pointerId)&&D.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),ri="ScrollAreaThumb",rp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tp(ri,e.__scopeScrollArea);return u.jsx(qt,{present:n||o.hasThumb,children:u.jsx(LC,{ref:t,...r})})}),LC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=rn(ri,n),i=tp(ri,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),c=m.useRef(void 0),d=ii(()=>{c.current&&(c.current(),c.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=zC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(Ne.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:ge(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),g=f.clientX-p.left,y=f.clientY-p.top;i.onThumbPointerDown({x:g,y})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});rp.displayName=ri;var dl="ScrollAreaCorner",op=m.forwardRef((e,t)=>{const n=rn(dl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(FC,{...e,ref:t}):null});op.displayName=dl;var FC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=rn(dl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),c=!!(s&&a);return Br(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Br(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.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 oi(e){return e?parseInt(e,10):0}function sp(e,t){const n=e/t;return isNaN(n)?0:n}function si(e){const t=sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function $C(e,t,n,r="ltr"){const o=si(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,f=r==="ltr"?[0,d]:[d*-1,0];return ap([l,c],f)(e)}function ip(e,t,n="ltr"){const r=si(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=al(e,l);return ap([0,i],[0,a])(c)}function ap(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 lp(e,t){return e>0&&e<t}var zC=(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 ii(e,t){const n=At(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Br(e,t){const n=At(t);kt(()=>{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 cp=Jh,BC=Qh,HC=op;const up=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(cp,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(BC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(dp,{}),u.jsx(HC,{})]}));up.displayName=cp.displayName;const dp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(cl,{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(rp,{className:"relative flex-1 rounded-full bg-border"})}));dp.displayName=cl.displayName;function fl({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}){const{threads:f,currentThreadId:h,isLoading:p,actions:g}=Yo(),{loadThread:y}=Xo(),{createThread:v,deleteThread:x,renameThread:w}=g,[S,T]=b.useState(Array.isArray(f)?f:[]),k=b.useRef(S.length>0),C=b.useRef(null),E=b.useRef(0),[_,j]=b.useState(null),[D,F]=b.useState(""),[K,P]=b.useState(!1);b.useEffect(()=>{const B=Array.isArray(f)?f:[];if(B.length>0){k.current=!0,T(B);return}p||(k.current=!1,T(B))},[f,p]),b.useEffect(()=>{if(!C.current)return;const B=C.current.querySelector("[data-radix-scroll-area-viewport]");if(!B)return;let ie=null,Ce=null;return ie=requestAnimationFrame(()=>{Ce=requestAnimationFrame(()=>{B.scrollTop=E.current})}),()=>{ie!==null&&cancelAnimationFrame(ie),Ce!==null&&cancelAnimationFrame(Ce)}},[S]);const R=async B=>{try{await y(B),a==null||a(B),l==null||l(B)}catch(ie){console.error("Failed to select thread:",ie)}},L=async()=>{try{P(!0);const B=await v();c==null||c(B),a==null||a(B)}catch(B){console.error("Failed to create thread:",B)}finally{P(!1)}},U=async(B,ie)=>{if(ie.stopPropagation(),!!confirm("Delete this thread?")){if(C.current){const Ce=C.current.querySelector("[data-radix-scroll-area-viewport]");Ce&&(E.current=Ce.scrollTop)}try{await x(B),d==null||d(B)}catch(Ce){console.error("Failed to delete thread:",Ce)}}},te=(B,ie)=>{ie.stopPropagation(),j(B.threadId),F(B.title||`Thread ${B.threadId.slice(0,8)}`)},V=async B=>{if(D.trim())try{await w(B,D.trim()),j(null),F("")}catch(ie){console.error("Failed to update title:",ie)}},z=()=>{j(null),F("")},G=(B,ie)=>{B.key==="Enter"?V(ie):B.key==="Escape"&&z()},Q=B=>{if(!B)return"";try{const ie=new Date(B),ke=new Date().getTime()-ie.getTime(),q=Math.floor(ke/(1e3*60*60*24));return q===0?ie.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:ie.toLocaleDateString()}catch{return""}},le=B=>B.title||`Thread ${B.threadId.slice(0,8)}`;return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Xe,{onClick:L,disabled:K||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:K?"Creating...":"New Chat",children:u.jsx(me.MessageSquarePlus,{size:20})})}),u.jsx(up,{ref:C,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:p?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(me.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(me.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:"No conversations yet"})]}):S.slice().sort((B,ie)=>new Date(ie.updatedAt||ie.createdAt||"").getTime()-new Date(B.updatedAt||B.createdAt||"").getTime()).map(B=>u.jsxs("div",{onClick:()=>R(B.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===B.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:_===B.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ie=>ie.stopPropagation(),children:[u.jsx(ni,{value:D,onChange:ie=>F(ie.target.value),onKeyDown:ie=>G(ie,B.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>V(B.threadId),className:"h-6 w-6 p-0",children:u.jsx(me.Check,{size:12})}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:z,className:"h-6 w-6 p-0",children:u.jsx(me.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:le(B)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(me.Calendar,{size:10}),u.jsx("span",{children:Q(B.updatedAt||B.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==B.threadId&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ie=>te(B,ie),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(me.Edit3,{size:12})}),n&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ie=>U(B.threadId,ie),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(me.Trash2,{size:12})})]})]}),i===B.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},B.threadId))})})]})}function Hr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function UC(e){if(typeof e!="string")return;const t=e.trim();if(t)return $n(t)}function fp(){const e=[Hr("__API_BASE_URL__"),Hr("__CHAT_API_BASE_URL__"),Hr("__CHAT_API_URL__")];for(const t of e){const n=UC(t);if(n)return n}}function hp(){const e=[Hr("__API_AUTH_TOKEN__"),Hr("__CHAT_API_KEY__"),Hr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return $n(t);return $n()}function mp(){const e={},t=fp(),n=hp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function gp(){const e=mp(),t=Wn.getAuthToken(),n=fp();return{apiBaseUrl:pp(e.baseUrl,Wn.baseUrl,n),apiKey:t||e.apiKey||hp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const xp="chat-settings";function WC(){try{const e=localStorage.getItem(xp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function VC(e){try{const t={...e,apiBaseUrl:$n(e.apiBaseUrl)};localStorage.setItem(xp,JSON.stringify(t)),t.apiKey&&Wn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function qC(){const e=gp(),t=WC(),n=Wn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:pp(Wn.baseUrl,r,e.apiBaseUrl)}}function KC(e){Wn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),VC(e)}var GC="Label",yp=m.forwardRef((e,t)=>u.jsx(Ne.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())}}));yp.displayName=GC;var vp=yp;const YC=Ro.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),on=m.forwardRef(({className:e,...t},n)=>u.jsx(vp,{ref:n,className:oe(YC(),e),...t}));on.displayName=vp.displayName;function wp(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var ai="Switch",[XC,wT]=Tn(ai),[JC,ZC]=XC(ai),bp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,p]=m.useState(null),g=He(t,S=>p(S)),y=m.useRef(!1),v=h?d||!!h.closest("form"):!0,[x,w]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:ai});return u.jsxs(JC,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Tp(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:ge(e.onClick,S=>{w(T=>!T),v&&(y.current=S.isPropagationStopped(),y.current||S.stopPropagation())})}),v&&u.jsx(kp,{control:h,bubbles:!y.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});bp.displayName=ai;var Sp="SwitchThumb",Cp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=ZC(Sp,n);return u.jsx(Ne.span,{"data-state":Tp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Cp.displayName=Sp;var QC="SwitchBubbleInput",kp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=He(i,s),l=wp(n),c=Of(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const g=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(g)}},[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}})});kp.displayName=QC;function Tp(e){return e?"checked":"unchecked"}var Ep=bp,ek=Cp;const er=m.forwardRef(({className:e,...t},n)=>u.jsx(Ep,{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(ek,{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")})}));er.displayName=Ep.displayName;var Ip=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"}),tk="VisuallyHidden",nk=m.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Ip,...e.style}}));nk.displayName=tk;var rk=[" ","Enter","ArrowUp","ArrowDown"],ok=[" ","Enter"],br="Select",[li,ci,sk]=Da(br),[Ur,bT]=Tn(br,[sk,Ys]),ui=Ys(),[ik,tr]=Ur(br),[ak,lk]=Ur(br),Ap=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:g}=e,y=ui(t),[v,x]=m.useState(null),[w,S]=m.useState(null),[T,k]=m.useState(!1),C=Fs(c),[E,_]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:br}),[j,D]=pr({prop:i,defaultProp:a,onChange:l,caller:br}),F=m.useRef(null),K=v?g||!!v.closest("form"):!0,[P,R]=m.useState(new Set),L=Array.from(P).map(U=>U.props.value).join(";");return u.jsx(Wf,{...y,children:u.jsxs(ik,{required:p,scope:t,trigger:v,onTriggerChange:x,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:En(),value:j,onValueChange:D,open:E,onOpenChange:_,dir:C,triggerPointerDownPosRef:F,disabled:h,children:[u.jsx(li.Provider,{scope:t,children:u.jsx(ak,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(U=>{R(te=>new Set(te).add(U))},[]),onNativeOptionRemove:m.useCallback(U=>{R(te=>{const V=new Set(te);return V.delete(U),V})},[]),children:n})}),K?u.jsxs(Zp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:U=>D(U.target.value),disabled:h,form:g,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(P)]},L):null]})})};Ap.displayName=br;var Np="SelectTrigger",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ui(n),i=tr(Np,n),a=i.disabled||r,l=He(t,i.onTriggerChange),c=ci(n),d=m.useRef("touch"),[f,h,p]=em(y=>{const v=c().filter(S=>!S.disabled),x=v.find(S=>S.value===i.value),w=tm(v,y,x);w!==void 0&&i.onValueChange(w.value)}),g=y=>{a||(i.onOpenChange(!0),p()),y&&(i.triggerPointerDownPosRef.current={x:Math.round(y.pageX),y:Math.round(y.pageY)})};return u.jsx(Vf,{asChild:!0,...s,children:u.jsx(Ne.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":Qp(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,y=>{y.currentTarget.focus(),d.current!=="mouse"&&g(y)}),onPointerDown:ge(o.onPointerDown,y=>{d.current=y.pointerType;const v=y.target;v.hasPointerCapture(y.pointerId)&&v.releasePointerCapture(y.pointerId),y.button===0&&y.ctrlKey===!1&&y.pointerType==="mouse"&&(g(y),y.preventDefault())}),onKeyDown:ge(o.onKeyDown,y=>{const v=f.current!=="";!(y.ctrlKey||y.altKey||y.metaKey)&&y.key.length===1&&h(y.key),!(v&&y.key===" ")&&rk.includes(y.key)&&(g(),y.preventDefault())})})})});_p.displayName=Np;var jp="SelectValue",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=tr(jp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=He(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qp(l.value)?u.jsx(u.Fragment,{children:i}):s})});Rp.displayName=jp;var ck="SelectIcon",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Pp.displayName=ck;var uk="SelectPortal",Op=e=>u.jsx(ys,{asChild:!0,...e});Op.displayName=uk;var Sr="SelectContent",Mp=m.forwardRef((e,t)=>{const n=tr(Sr,e.__scopeSelect),[r,o]=m.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Po.createPortal(u.jsx(Dp,{scope:e.__scopeSelect,children:u.jsx(li.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Lp,{...e,ref:t})});Mp.displayName=Sr;var gn=10,[Dp,nr]=Ur(Sr),dk="SelectContentImpl",fk=sr.createSlot("SelectContent.RemoveScroll"),Lp=m.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:f,collisionBoundary:h,collisionPadding:p,sticky:g,hideWhenDetached:y,avoidCollisions:v,...x}=e,w=tr(Sr,n),[S,T]=m.useState(null),[k,C]=m.useState(null),E=He(t,q=>T(q)),[_,j]=m.useState(null),[D,F]=m.useState(null),K=ci(n),[P,R]=m.useState(!1),L=m.useRef(!1);m.useEffect(()=>{if(S)return Aa(S)},[S]),Sa();const U=m.useCallback(q=>{const[M,...X]=K().map(se=>se.ref.current),[ne]=X.slice(-1),xe=document.activeElement;for(const se of q)if(se===xe||(se==null||se.scrollIntoView({block:"nearest"}),se===M&&k&&(k.scrollTop=0),se===ne&&k&&(k.scrollTop=k.scrollHeight),se==null||se.focus(),document.activeElement!==xe))return},[K,k]),te=m.useCallback(()=>U([_,S]),[U,_,S]);m.useEffect(()=>{P&&te()},[P,te]);const{onOpenChange:V,triggerPointerDownPosRef:z}=w;m.useEffect(()=>{if(S){let q={x:0,y:0};const M=ne=>{var xe,se;q={x:Math.abs(Math.round(ne.pageX)-(((xe=z.current)==null?void 0:xe.x)??0)),y:Math.abs(Math.round(ne.pageY)-(((se=z.current)==null?void 0:se.y)??0))}},X=ne=>{q.x<=10&&q.y<=10?ne.preventDefault():S.contains(ne.target)||V(!1),document.removeEventListener("pointermove",M),z.current=null};return z.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,V,z]),m.useEffect(()=>{const q=()=>V(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[V]);const[G,Q]=em(q=>{const M=K().filter(xe=>!xe.disabled),X=M.find(xe=>xe.ref.current===document.activeElement),ne=tm(M,q,X);ne&&setTimeout(()=>ne.ref.current.focus())}),le=m.useCallback((q,M,X)=>{const ne=!L.current&&!X;(w.value!==void 0&&w.value===M||ne)&&(j(q),ne&&(L.current=!0))},[w.value]),B=m.useCallback(()=>S==null?void 0:S.focus(),[S]),ie=m.useCallback((q,M,X)=>{const ne=!L.current&&!X;(w.value!==void 0&&w.value===M||ne)&&F(q)},[w.value]),Ce=r==="popper"?hl:Fp,ke=Ce===hl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:g,hideWhenDetached:y,avoidCollisions:v}:{};return u.jsx(Dp,{scope:n,content:S,viewport:k,onViewportChange:C,itemRefCallback:le,selectedItem:_,onItemLeave:B,itemTextRefCallback:ie,focusSelectedItem:te,selectedItemText:D,position:r,isPositioned:P,searchRef:G,children:u.jsx(ks,{as:fk,allowPinchZoom:!0,children:u.jsx(xs,{asChild:!0,trapped:w.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ge(o,q=>{var M;(M=w.trigger)==null||M.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(gs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(Ce,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:q=>q.preventDefault(),...x,...ke,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,q=>{const M=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!M&&q.key.length===1&&Q(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let ne=K().filter(xe=>!xe.disabled).map(xe=>xe.ref.current);if(["ArrowUp","End"].includes(q.key)&&(ne=ne.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const xe=q.target,se=ne.indexOf(xe);ne=ne.slice(se+1)}setTimeout(()=>U(ne)),q.preventDefault()}})})})})})})});Lp.displayName=dk;var hk="SelectItemAlignedPosition",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=tr(Sr,n),i=nr(Sr,n),[a,l]=m.useState(null),[c,d]=m.useState(null),f=He(t,E=>d(E)),h=ci(n),p=m.useRef(!1),g=m.useRef(!0),{viewport:y,selectedItem:v,selectedItemText:x,focusSelectedItem:w}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&y&&v&&x){const E=s.trigger.getBoundingClientRect(),_=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const xe=D.left-_.left,se=j.left-xe,ae=E.left-se,Ue=E.width+ae,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,st=al(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.left=st+"px"}else{const xe=_.right-D.right,se=window.innerWidth-j.right-xe,ae=window.innerWidth-E.right-se,Ue=E.width+ae,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,st=al(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.right=st+"px"}const F=h(),K=window.innerHeight-gn*2,P=y.scrollHeight,R=window.getComputedStyle(c),L=parseInt(R.borderTopWidth,10),U=parseInt(R.paddingTop,10),te=parseInt(R.borderBottomWidth,10),V=parseInt(R.paddingBottom,10),z=L+U+P+V+te,G=Math.min(v.offsetHeight*5,z),Q=window.getComputedStyle(y),le=parseInt(Q.paddingTop,10),B=parseInt(Q.paddingBottom,10),ie=E.top+E.height/2-gn,Ce=K-ie,ke=v.offsetHeight/2,q=v.offsetTop+ke,M=L+U+q,X=z-M;if(M<=ie){const xe=F.length>0&&v===F[F.length-1].ref.current;a.style.bottom="0px";const se=c.clientHeight-y.offsetTop-y.offsetHeight,ae=Math.max(Ce,ke+(xe?B:0)+se+te),Ue=M+ae;a.style.height=Ue+"px"}else{const xe=F.length>0&&v===F[0].ref.current;a.style.top="0px";const ae=Math.max(ie,L+y.offsetTop+(xe?le:0)+ke)+X;a.style.height=ae+"px",y.scrollTop=M-ie+y.offsetTop}a.style.margin=`${gn}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=K+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,y,v,x,s.dir,r]);kt(()=>S(),[S]);const[T,k]=m.useState();kt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const C=m.useCallback(E=>{E&&g.current===!0&&(S(),w==null||w(),g.current=!1)},[S,w]);return u.jsx(mk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:u.jsx(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fp.displayName=hk;var pk="SelectPopperPosition",hl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=gn,...s}=e,i=ui(n);return u.jsx(qf,{...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)"}})});hl.displayName=pk;var[mk,pl]=Ur(Sr,{}),ml="SelectViewport",$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=nr(ml,n),i=pl(ml,n),a=He(t,s.onViewportChange),l=m.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(li.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ge(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const g=window.innerHeight-gn*2,y=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),x=Math.max(y,v);if(x<g){const w=x+p,S=Math.min(g,w),T=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});$p.displayName=ml;var zp="SelectGroup",[gk,xk]=Ur(zp),yk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=En();return u.jsx(gk,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});yk.displayName=zp;var Bp="SelectLabel",Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=xk(Bp,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});Hp.displayName=Bp;var di="SelectItem",[vk,Up]=Ur(di),Wp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=tr(di,n),l=nr(di,n),c=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),g=He(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),y=En(),v=m.useRef("touch"),x=()=>{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(vk,{scope:n,value:r,disabled:o,textId:y,isSelected:c,onItemTextChange:m.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(li.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":y,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:g,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{v.current!=="mouse"&&x()}),onPointerUp:ge(i.onPointerUp,()=>{v.current==="mouse"&&x()}),onPointerDown:ge(i.onPointerDown,w=>{v.current=w.pointerType}),onPointerMove:ge(i.onPointerMove,w=>{var S;v.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):v.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ge(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ge(i.onKeyDown,w=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&w.key===" "||(ok.includes(w.key)&&x(),w.key===" "&&w.preventDefault())})})})})});Wp.displayName=di;var Io="SelectItemText",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=tr(Io,n),a=nr(Io,n),l=Up(Io,n),c=lk(Io,n),[d,f]=m.useState(null),h=He(t,x=>f(x),l.onItemTextChange,x=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,g=m.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:y,onNativeOptionRemove:v}=c;return kt(()=>(y(g),()=>v(g)),[y,v,g]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Po.createPortal(s.children,i.valueNode):null]})});Vp.displayName=Io;var qp="SelectItemIndicator",Kp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Up(qp,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});Kp.displayName=qp;var gl="SelectScrollUpButton",Gp=m.forwardRef((e,t)=>{const n=nr(gl,e.__scopeSelect),r=pl(gl,e.__scopeSelect),[o,s]=m.useState(!1),i=He(t,r.onScrollButtonChange);return kt(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Gp.displayName=gl;var xl="SelectScrollDownButton",Yp=m.forwardRef((e,t)=>{const n=nr(xl,e.__scopeSelect),r=pl(xl,e.__scopeSelect),[o,s]=m.useState(!1),i=He(t,r.onScrollButtonChange);return kt(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Yp.displayName=xl;var Xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=nr("SelectScrollButton",n),i=m.useRef(null),a=ci(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),kt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ge(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ge(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ge(o.onPointerLeave,()=>{l()})})}),wk="SelectSeparator",Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});Jp.displayName=wk;var yl="SelectArrow",bk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ui(n),s=tr(yl,n),i=nr(yl,n);return s.open&&i.position==="popper"?u.jsx(Kf,{...o,...r,ref:t}):null});bk.displayName=yl;var Sk="SelectBubbleInput",Zp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=He(r,o),i=wp(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ne.select,{...n,style:{...Ip,...n.style},ref:s,defaultValue:t})});Zp.displayName=Sk;function Qp(e){return e===""||e===void 0}function em(e){const t=At(e),n=m.useRef(""),r=m.useRef(0),o=m.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=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function tm(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=Ck(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 Ck(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kk=Ap,nm=_p,Tk=Rp,Ek=Pp,Ik=Op,rm=Mp,Ak=$p,om=Hp,sm=Wp,Nk=Vp,_k=Kp,im=Gp,am=Yp,lm=Jp;const cm=kk,um=Tk,vl=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(nm,{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(Ek,{asChild:!0,children:u.jsx(me.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));vl.displayName=nm.displayName;const dm=m.forwardRef(({className:e,...t},n)=>u.jsx(im,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(me.ChevronUp,{className:"h-4 w-4"})}));dm.displayName=im.displayName;const fm=m.forwardRef(({className:e,...t},n)=>u.jsx(am,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(me.ChevronDown,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const wl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Ik,{children:u.jsxs(rm,{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(dm,{}),u.jsx(Ak,{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(fm,{})]})}));wl.displayName=rm.displayName;const jk=m.forwardRef(({className:e,...t},n)=>u.jsx(om,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));jk.displayName=om.displayName;const Cr=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(sm,{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(_k,{children:u.jsx(me.Check,{className:"h-4 w-4"})})}),u.jsx(Nk,{children:t})]}));Cr.displayName=sm.displayName;const Rk=m.forwardRef(({className:e,...t},n)=>u.jsx(lm,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));Rk.displayName=lm.displayName;var Pk="Separator",hm="horizontal",Ok=["horizontal","vertical"],pm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=hm,...o}=e,s=Mk(r)?r:hm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});pm.displayName=Pk;function Mk(e){return Ok.includes(e)}var mm=pm;const gm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(mm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gm.displayName=mm.displayName;const Dk=$d,Lk=nb,Fk=zd,xm=m.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{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}));xm.displayName=Ns.displayName;const $k=Ro.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"}}),ym=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(Fk,{children:[u.jsx(xm,{}),u.jsxs(_s,{ref:o,className:oe($k({side:e}),t),...r,children:[n,u.jsxs(Bd,{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(me.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ym.displayName=_s.displayName;const vm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});vm.displayName="SheetHeader";const wm=m.forwardRef(({className:e,...t},n)=>u.jsx(gr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));wm.displayName=gr.displayName;const bm=m.forwardRef(({className:e,...t},n)=>u.jsx(js,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));bm.displayName=js.displayName;const zk={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function Bk({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=xa();b.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);d(v)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(zk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(e),d(!1),o(!1)},y=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(Dk,{open:r,onOpenChange:o,children:[u.jsx(Lk,{asChild:!0,children:u.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[u.jsx(me.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Bu,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(ym,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(vm,{children:[u.jsx(wm,{children:"Chat Settings"}),u.jsx(bm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(fo,{children:[u.jsx(ho,{className:"pb-3",children:u.jsxs(po,{className:"text-lg flex items-center gap-2",children:[u.jsx(me.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(mo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(ni,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(x=>({...x,api:{...x.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Xe,{variant:"outline",onClick:y,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(er,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(x=>({...x,api:{...x.api,enableAuth:v}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(ni,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(x=>({...x,api:{...x.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Xe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(me.EyeOff,{className:"h-4 w-4"}):u.jsx(me.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(fo,{children:[u.jsx(ho,{className:"pb-3",children:u.jsxs(po,{className:"text-lg flex items-center gap-2",children:[u.jsx(me.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(mo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(cm,{value:a.ui.layout,onValueChange:v=>l(x=>({...x,ui:{...x.ui,layout:v}})),children:[u.jsx(vl,{children:u.jsx(um,{})}),u.jsxs(wl,{children:[u.jsx(Cr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Cr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Cr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"theme",children:"Theme"}),u.jsxs(cm,{value:a.ui.theme,onValueChange:v=>l(x=>({...x,ui:{...x.ui,theme:v}})),children:[u.jsx(vl,{children:u.jsx(um,{})}),u.jsxs(wl,{children:[u.jsx(Cr,{value:"light",children:"Light"}),u.jsx(Cr,{value:"dark",children:"Dark"}),u.jsx(Cr,{value:"system",children:"System"})]})]})]}),u.jsx(gm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(er,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showTimestamps:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(er,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showAgentNames:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(er,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,compactMessages:v}}))})]})]})]})]}),u.jsxs(fo,{children:[u.jsx(ho,{className:"pb-3",children:u.jsxs(po,{className:"text-lg flex items-center gap-2",children:[u.jsx(me.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(mo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(on,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(er,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,autoSave:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(on,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(er,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(on,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(er,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:v}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Xe,{variant:"outline",onClick:p,children:[u.jsx(me.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Xe,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Xe,{onClick:h,disabled:!c,children:[u.jsx(me.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function Hk({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(Jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(ti,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Jo,{...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(fl,{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(ti,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Jo,{...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(fl,{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(ti,{onError:s.onError,enableFileUpload:!0})})]})})}_e.ChatApi=xc,_e.ChatInterface=ti,_e.ChatProviders=Jo,_e.ChatSettings=Bk,_e.MarkdownContent=Oa,_e.MessageComponent=lf,_e.MessageList=Ma,_e.ThreadManager=fl,_e.applySettings=KC,_e.chatApiClient=Wn,_e.default=Hk,_e.del=gc,_e.get=cn,_e.getChatToken=hc,_e.getCurrentSettings=qC,_e.getDefaultApiConfig=mp,_e.getDefaultChatSettings=gp,_e.onChatTokenChanged=pc,_e.post=Ii,_e.put=mc,_e.setChatToken=Ei,_e.useApi=Ai,_e.useChatStream=Rc,_e.useMessagesReducer=kc,_e.useStream=Bc,_e.useThreadState=Xo,_e.useThreads=Yo,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
136
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Ob(e,t=Fs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function Mb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Ob(t),Pb(t)}function Da(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=y=>{const{scope:v,children:x}=y,w=b.useRef(null),S=b.useRef(new Map).current;return u.jsx(o,{scope:v,itemMap:S,collectionRef:w,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=sr.createSlot(a),c=b.forwardRef((y,v)=>{const{scope:x,children:w}=y,S=s(a,x),T=He(v,S.collectionRef);return u.jsx(l,{ref:T,children:w})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=sr.createSlot(d),p=b.forwardRef((y,v)=>{const{scope:x,children:w,...S}=y,T=b.useRef(null),k=He(v,T),C=s(d,x);return b.useEffect(()=>(C.itemMap.set(T,{ref:T,...S}),()=>void C.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=d;function g(y){const v=s(e+"CollectionConsumer",y);return b.useCallback(()=>{const w=v.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(v.itemMap.values()).sort((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[v.collectionRef,v.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},g,r]}var Db=m.createContext(void 0);function $s(e){const t=m.useContext(Db);return e||t||"ltr"}const Lb=["top","right","bottom","left"],Zn=Math.min,Kt=Math.max,zs=Math.round,Bs=Math.floor,An=e=>({x:e,y:e}),Fb={left:"right",right:"left",bottom:"top",top:"bottom"},$b={start:"end",end:"start"};function La(e,t,n){return Kt(e,Zn(t,n))}function Bn(e,t){return typeof e=="function"?e(t):e}function Hn(e){return e.split("-")[0]}function Lr(e){return e.split("-")[1]}function Fa(e){return e==="x"?"y":"x"}function $a(e){return e==="y"?"height":"width"}const zb=new Set(["top","bottom"]);function Nn(e){return zb.has(Hn(e))?"y":"x"}function za(e){return Fa(Nn(e))}function Bb(e,t,n){n===void 0&&(n=!1);const r=Lr(e),o=za(e),s=$a(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Hs(i)),[i,Hs(i)]}function Hb(e){const t=Hs(e);return[Ba(e),t,Ba(t)]}function Ba(e){return e.replace(/start|end/g,t=>$b[t])}const df=["left","right"],ff=["right","left"],Ub=["top","bottom"],Wb=["bottom","top"];function Vb(e,t,n){switch(e){case"top":case"bottom":return n?t?ff:df:t?df:ff;case"left":case"right":return t?Ub:Wb;default:return[]}}function qb(e,t,n,r){const o=Lr(e);let s=Vb(Hn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ba)))),s}function Hs(e){return e.replace(/left|right|bottom|top/g,t=>Fb[t])}function Kb(e){return{top:0,right:0,bottom:0,left:0,...e}}function hf(e){return typeof e!="number"?Kb(e):{top:e,right:e,bottom:e,left:e}}function Us(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 pf(e,t,n){let{reference:r,floating:o}=e;const s=Nn(t),i=za(t),a=$a(i),l=Hn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Lr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Gb=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:f}=pf(c,r,l),h=r,p={},g=0;for(let y=0;y<a.length;y++){const{name:v,fn:x}=a[y],{x:w,y:S,data:T,reset:k}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=w??d,f=S??f,p={...p,[v]:{...p[v],...T}},k&&g<=50&&(g++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(c=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=pf(c,h,l)),y=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function yo(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:f="floating",altBoundary:h=!1,padding:p=0}=Bn(t,e),g=hf(p),v=a[h?f==="floating"?"reference":"floating":f],x=Us(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),w=f==="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)),T=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},k=Us(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(x.top-k.top+g.top)/T.y,bottom:(k.bottom-x.bottom+g.bottom)/T.y,left:(x.left-k.left+g.left)/T.x,right:(k.right-x.right+g.right)/T.x}}const Yb=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}=Bn(e,t)||{};if(c==null)return{};const f=hf(d),h={x:n,y:r},p=za(o),g=$a(p),y=await i.getDimensions(c),v=p==="y",x=v?"top":"left",w=v?"bottom":"right",S=v?"clientHeight":"clientWidth",T=s.reference[g]+s.reference[p]-h[p]-s.floating[g],k=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[g]);const _=T/2-k/2,j=E/2-y[g]/2-1,D=Zn(f[x],j),F=Zn(f[w],j),K=D,P=E-y[g]-F,R=E/2-y[g]/2+_,L=La(K,R,P),U=!l.arrow&&Lr(o)!=null&&R!==L&&s.reference[g]/2-(R<K?D:F)-y[g]/2<0,te=U?R<K?R-K:R-P:0;return{[p]:h[p]+te,data:{[p]:L,centerOffset:R-L-te,...U&&{alignmentOffset:te}},reset:U}}}),Xb=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:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:y=!0,...v}=Bn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Hn(o),w=Nn(a),S=Hn(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(S||!y?[Hs(a)]:Hb(a)),C=g!=="none";!h&&C&&k.push(...qb(a,y,g,T));const E=[a,...k],_=await yo(t,v),j=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(_[x]),f){const R=Bb(o,i,T);j.push(_[R[0]],_[R[1]])}if(D=[...D,{placement:o,overflows:j}],!j.every(R=>R<=0)){var F,K;const R=(((F=s.flip)==null?void 0:F.index)||0)+1,L=E[R];if(L&&(!(f==="alignment"?w!==Nn(L):!1)||D.every(V=>Nn(V.placement)===w?V.overflows[0]>0:!0)))return{data:{index:R,overflows:D},reset:{placement:L}};let U=(K=D.filter(te=>te.overflows[0]<=0).sort((te,V)=>te.overflows[1]-V.overflows[1])[0])==null?void 0:K.placement;if(!U)switch(p){case"bestFit":{var P;const te=(P=D.filter(V=>{if(C){const z=Nn(V.placement);return z===w||z==="y"}return!0}).map(V=>[V.placement,V.overflows.filter(z=>z>0).reduce((z,G)=>z+G,0)]).sort((V,z)=>V[1]-z[1])[0])==null?void 0:P[0];te&&(U=te);break}case"initialPlacement":U=a;break}if(o!==U)return{reset:{placement:U}}}return{}}}};function mf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function gf(e){return Lb.some(t=>e[t]>=0)}const Jb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Bn(e,t);switch(r){case"referenceHidden":{const s=await yo(t,{...o,elementContext:"reference"}),i=mf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:gf(i)}}}case"escaped":{const s=await yo(t,{...o,altBoundary:!0}),i=mf(s,n.floating);return{data:{escapedOffsets:i,escaped:gf(i)}}}default:return{}}}}},xf=new Set(["left","top"]);async function Zb(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Hn(n),a=Lr(n),l=Nn(n)==="y",c=xf.has(i)?-1:1,d=s&&l?-1:1,f=Bn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const Qb=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 Zb(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}}}}},e0=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:v=>{let{x,y:w}=v;return{x,y:w}}},...l}=Bn(e,t),c={x:n,y:r},d=await yo(t,l),f=Nn(Hn(o)),h=Fa(f);let p=c[h],g=c[f];if(s){const v=h==="y"?"top":"left",x=h==="y"?"bottom":"right",w=p+d[v],S=p-d[x];p=La(w,p,S)}if(i){const v=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=g+d[v],S=g-d[x];g=La(w,g,S)}const y=a.fn({...t,[h]:p,[f]:g});return{...y,data:{x:y.x-n,y:y.y-r,enabled:{[h]:s,[f]:i}}}}}},t0=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}=Bn(e,t),d={x:n,y:r},f=Nn(o),h=Fa(f);let p=d[h],g=d[f];const y=Bn(a,t),v=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(l){const S=h==="y"?"height":"width",T=s.reference[h]-s.floating[S]+v.mainAxis,k=s.reference[h]+s.reference[S]-v.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var x,w;const S=h==="y"?"width":"height",T=xf.has(Hn(o)),k=s.reference[f]-s.floating[S]+(T&&((x=i.offset)==null?void 0:x[f])||0)+(T?0:v.crossAxis),C=s.reference[f]+s.reference[S]+(T?0:((w=i.offset)==null?void 0:w[f])||0)-(T?v.crossAxis:0);g<k?g=k:g>C&&(g=C)}return{[h]:p,[f]:g}}}},n0=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}=Bn(e,t),d=await yo(t,c),f=Hn(o),h=Lr(o),p=Nn(o)==="y",{width:g,height:y}=s.floating;let v,x;f==="top"||f==="bottom"?(v=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,v=h==="end"?"top":"bottom");const w=y-d.top-d.bottom,S=g-d.left-d.right,T=Zn(y-d[v],w),k=Zn(g-d[x],S),C=!t.middlewareData.shift;let E=T,_=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(_=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=w),C&&!h){const D=Kt(d.left,0),F=Kt(d.right,0),K=Kt(d.top,0),P=Kt(d.bottom,0);p?_=g-2*(D!==0||F!==0?D+F:Kt(d.left,d.right)):E=y-2*(K!==0||P!==0?K+P:Kt(d.top,d.bottom))}await l({...t,availableWidth:_,availableHeight:E});const j=await i.getDimensions(a.floating);return g!==j.width||y!==j.height?{reset:{rects:!0}}:{}}}};function Ws(){return typeof window<"u"}function Fr(e){return yf(e)?(e.nodeName||"").toLowerCase():"#document"}function Gt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function _n(e){var t;return(t=(yf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function yf(e){return Ws()?e instanceof Node||e instanceof Gt(e).Node:!1}function pn(e){return Ws()?e instanceof Element||e instanceof Gt(e).Element:!1}function jn(e){return Ws()?e instanceof HTMLElement||e instanceof Gt(e).HTMLElement:!1}function vf(e){return!Ws()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gt(e).ShadowRoot}const r0=new Set(["inline","contents"]);function vo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=mn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!r0.has(o)}const o0=new Set(["table","td","th"]);function s0(e){return o0.has(Fr(e))}const i0=[":popover-open",":modal"];function Vs(e){return i0.some(t=>{try{return e.matches(t)}catch{return!1}})}const a0=["transform","translate","scale","rotate","perspective"],l0=["transform","translate","scale","rotate","perspective","filter"],c0=["paint","layout","strict","content"];function Ha(e){const t=Ua(),n=pn(e)?mn(e):e;return a0.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)||l0.some(r=>(n.willChange||"").includes(r))||c0.some(r=>(n.contain||"").includes(r))}function u0(e){let t=Qn(e);for(;jn(t)&&!$r(t);){if(Ha(t))return t;if(Vs(t))return null;t=Qn(t)}return null}function Ua(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const d0=new Set(["html","body","#document"]);function $r(e){return d0.has(Fr(e))}function mn(e){return Gt(e).getComputedStyle(e)}function qs(e){return pn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Qn(e){if(Fr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||vf(e)&&e.host||_n(e);return vf(t)?t.host:t}function wf(e){const t=Qn(e);return $r(t)?e.ownerDocument?e.ownerDocument.body:e.body:jn(t)&&vo(t)?t:wf(t)}function wo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=wf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Gt(o);if(s){const a=Wa(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?wo(a):[])}return t.concat(o,wo(o,[],n))}function Wa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bf(e){const t=mn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=jn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=zs(n)!==s||zs(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Va(e){return pn(e)?e:e.contextElement}function zr(e){const t=Va(e);if(!jn(t))return An(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=bf(t);let i=(s?zs(n.width):n.width)/r,a=(s?zs(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const f0=An(0);function Sf(e){const t=Gt(e);return!Ua()||!t.visualViewport?f0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function h0(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Gt(e)?!1:t}function yr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Va(e);let i=An(1);t&&(r?pn(r)&&(i=zr(r)):i=zr(e));const a=h0(s,n,r)?Sf(s):An(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Gt(s),p=r&&pn(r)?Gt(r):r;let g=h,y=Wa(g);for(;y&&r&&p!==g;){const v=zr(y),x=y.getBoundingClientRect(),w=mn(y),S=x.left+(y.clientLeft+parseFloat(w.paddingLeft))*v.x,T=x.top+(y.clientTop+parseFloat(w.paddingTop))*v.y;l*=v.x,c*=v.y,d*=v.x,f*=v.y,l+=S,c+=T,g=Gt(y),y=Wa(g)}}return Us({width:d,height:f,x:l,y:c})}function Ks(e,t){const n=qs(e).scrollLeft;return t?t.left+n:yr(_n(e)).left+n}function Cf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ks(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function p0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=_n(r),a=t?Vs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=An(1);const d=An(0),f=jn(r);if((f||!f&&!s)&&((Fr(r)!=="body"||vo(i))&&(l=qs(r)),jn(r))){const p=yr(r);c=zr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Cf(i,l):An(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function m0(e){return Array.from(e.getClientRects())}function g0(e){const t=_n(e),n=qs(e),r=e.ownerDocument.body,o=Kt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Kt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ks(e);const a=-n.scrollTop;return mn(r).direction==="rtl"&&(i+=Kt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const kf=25;function x0(e,t){const n=Gt(e),r=_n(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=Ua();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ks(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,g=Math.abs(r.clientWidth-f.clientWidth-p);g<=kf&&(s-=g)}else c<=kf&&(s+=c);return{width:s,height:i,x:a,y:l}}const y0=new Set(["absolute","fixed"]);function v0(e,t){const n=yr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=jn(e)?zr(e):An(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 Tf(e,t,n){let r;if(t==="viewport")r=x0(e,n);else if(t==="document")r=g0(_n(e));else if(pn(t))r=v0(t,n);else{const o=Sf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Us(r)}function Ef(e,t){const n=Qn(e);return n===t||!pn(n)||$r(n)?!1:mn(n).position==="fixed"||Ef(n,t)}function w0(e,t){const n=t.get(e);if(n)return n;let r=wo(e,[],!1).filter(a=>pn(a)&&Fr(a)!=="body"),o=null;const s=mn(e).position==="fixed";let i=s?Qn(e):e;for(;pn(i)&&!$r(i);){const a=mn(i),l=Ha(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&y0.has(o.position)||vo(i)&&!l&&Ef(e,i))?r=r.filter(d=>d!==i):o=a,i=Qn(i)}return t.set(e,r),r}function b0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Vs(t)?[]:w0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Tf(t,d,o);return c.top=Kt(f.top,c.top),c.right=Zn(f.right,c.right),c.bottom=Zn(f.bottom,c.bottom),c.left=Kt(f.left,c.left),c},Tf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function S0(e){const{width:t,height:n}=bf(e);return{width:t,height:n}}function C0(e,t,n){const r=jn(t),o=_n(t),s=n==="fixed",i=yr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=An(0);function c(){l.x=Ks(o)}if(r||!r&&!s)if((Fr(t)!=="body"||vo(o))&&(a=qs(t)),r){const p=yr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Cf(o,a):An(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function qa(e){return mn(e).position==="static"}function If(e,t){if(!jn(e)||mn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return _n(e)===n&&(n=n.ownerDocument.body),n}function Af(e,t){const n=Gt(e);if(Vs(e))return n;if(!jn(e)){let o=Qn(e);for(;o&&!$r(o);){if(pn(o)&&!qa(o))return o;o=Qn(o)}return n}let r=If(e,t);for(;r&&s0(r)&&qa(r);)r=If(r,t);return r&&$r(r)&&qa(r)&&!Ha(r)?n:r||u0(e)||n}const k0=async function(e){const t=this.getOffsetParent||Af,n=this.getDimensions,r=await n(e.floating);return{reference:C0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function T0(e){return mn(e).direction==="rtl"}const E0={convertOffsetParentRelativeRectToViewportRelativeRect:p0,getDocumentElement:_n,getClippingRect:b0,getOffsetParent:Af,getElementRects:k0,getClientRects:m0,getDimensions:S0,getScale:zr,isElement:pn,isRTL:T0};function Nf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function I0(e,t){let n=null,r;const o=_n(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:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const g=Bs(f),y=Bs(o.clientWidth-(d+h)),v=Bs(o.clientHeight-(f+p)),x=Bs(d),S={rootMargin:-g+"px "+-y+"px "+-v+"px "+-x+"px",threshold:Kt(0,Zn(1,l))||1};let T=!0;function k(C){const E=C[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Nf(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,S)}n.observe(e)}return i(!0),s}function A0(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=Va(e),d=o||s?[...c?wo(c):[],...wo(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?I0(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[w]=x;w&&w.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let g,y=l?yr(e):null;l&&v();function v(){const x=yr(e);y&&!Nf(y,x)&&n(),y=x,g=requestAnimationFrame(v)}return n(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const N0=Qb,_0=e0,j0=Xb,R0=n0,P0=Jb,_f=Yb,O0=t0,M0=(e,t,n)=>{const r=new Map,o={platform:E0,...n},s={...o.platform,_c:r};return Gb(e,t,{...o,platform:s})};var D0=typeof document<"u",L0=function(){},Gs=D0?b.useLayoutEffect:L0;function Ys(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(!Ys(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)&&!Ys(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function jf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Rf(e,t){const n=jf(e);return Math.round(t*n)/n}function Ka(e){const t=m.useRef(e);return Gs(()=>{t.current=e}),t}function F0(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,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Ys(h,r)||p(r);const[g,y]=m.useState(null),[v,x]=m.useState(null),w=m.useCallback(V=>{V!==C.current&&(C.current=V,y(V))},[]),S=m.useCallback(V=>{V!==E.current&&(E.current=V,x(V))},[]),T=s||g,k=i||v,C=m.useRef(null),E=m.useRef(null),_=m.useRef(d),j=l!=null,D=Ka(l),F=Ka(o),K=Ka(c),P=m.useCallback(()=>{if(!C.current||!E.current)return;const V={placement:t,strategy:n,middleware:h};F.current&&(V.platform=F.current),M0(C.current,E.current,V).then(z=>{const G={...z,isPositioned:K.current!==!1};R.current&&!Ys(_.current,G)&&(_.current=G,Po.flushSync(()=>{f(G)}))})},[h,t,n,F,K]);Gs(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,f(V=>({...V,isPositioned:!1})))},[c]);const R=m.useRef(!1);Gs(()=>(R.current=!0,()=>{R.current=!1}),[]),Gs(()=>{if(T&&(C.current=T),k&&(E.current=k),T&&k){if(D.current)return D.current(T,k,P);P()}},[T,k,P,D,j]);const L=m.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),U=m.useMemo(()=>({reference:T,floating:k}),[T,k]),te=m.useMemo(()=>{const V={position:n,left:0,top:0};if(!U.floating)return V;const z=Rf(U.floating,d.x),G=Rf(U.floating,d.y);return a?{...V,transform:"translate("+z+"px, "+G+"px)",...jf(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:z,top:G}},[n,a,U.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:P,refs:L,elements:U,floatingStyles:te}),[d,P,L,U,te])}const $0=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?_f({element:r.current,padding:o}).fn(n):{}:r?_f({element:r,padding:o}).fn(n):{}}}},z0=(e,t)=>({...N0(e),options:[e,t]}),B0=(e,t)=>({..._0(e),options:[e,t]}),H0=(e,t)=>({...O0(e),options:[e,t]}),U0=(e,t)=>({...j0(e),options:[e,t]}),W0=(e,t)=>({...R0(e),options:[e,t]}),V0=(e,t)=>({...P0(e),options:[e,t]}),q0=(e,t)=>({...$0(e),options:[e,t]});var K0="Arrow",Pf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ne.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"})})});Pf.displayName=K0;var G0=Pf;function Of(e){const[t,n]=m.useState(void 0);return kt(()=>{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 Ga="Popper",[Mf,Xs]=Tn(Ga),[Y0,Df]=Mf(Ga),Lf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return u.jsx(Y0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Lf.displayName=Ga;var Ff="PopperAnchor",$f=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Df(Ff,n),i=m.useRef(null),a=He(t,i),l=m.useRef(null);return m.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(Ne.div,{...o,ref:a})});$f.displayName=Ff;var Ya="PopperContent",[X0,J0]=Mf(Ya),zf=m.forwardRef((e,t)=>{var q,M,X,ne,xe,se;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:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:g,...y}=e,v=Df(Ya,n),[x,w]=m.useState(null),S=He(t,ae=>w(ae)),[T,k]=m.useState(null),C=Of(T),E=(C==null?void 0:C.width)??0,_=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),D=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},F=Array.isArray(c)?c:[c],K=F.length>0,P={padding:D,boundary:F.filter(Q0),altBoundary:K},{refs:R,floatingStyles:L,placement:U,isPositioned:te,middlewareData:V}=F0({strategy:"fixed",placement:j,whileElementsMounted:(...ae)=>A0(...ae,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[z0({mainAxis:o+_,alignmentAxis:i}),l&&B0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?H0():void 0,...P}),l&&U0({...P}),W0({...P,apply:({elements:ae,rects:Ue,availableWidth:Ke,availableHeight:ot})=>{const{width:st,height:ut}=Ue.reference,et=ae.floating.style;et.setProperty("--radix-popper-available-width",`${Ke}px`),et.setProperty("--radix-popper-available-height",`${ot}px`),et.setProperty("--radix-popper-anchor-width",`${st}px`),et.setProperty("--radix-popper-anchor-height",`${ut}px`)}}),T&&q0({element:T,padding:a}),eS({arrowWidth:E,arrowHeight:_}),h&&V0({strategy:"referenceHidden",...P})]}),[z,G]=Uf(U),Q=At(g);kt(()=>{te&&(Q==null||Q())},[te,Q]);const le=(q=V.arrow)==null?void 0:q.x,B=(M=V.arrow)==null?void 0:M.y,ie=((X=V.arrow)==null?void 0:X.centerOffset)!==0,[Ce,ke]=m.useState();return kt(()=>{x&&ke(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:te?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ce,"--radix-popper-transform-origin":[(ne=V.transformOrigin)==null?void 0:ne.x,(xe=V.transformOrigin)==null?void 0:xe.y].join(" "),...((se=V.hide)==null?void 0:se.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(X0,{scope:n,placedSide:z,onArrowChange:k,arrowX:le,arrowY:B,shouldHideArrow:ie,children:u.jsx(Ne.div,{"data-side":z,"data-align":G,...y,ref:S,style:{...y.style,animation:te?void 0:"none"}})})})});zf.displayName=Ya;var Bf="PopperArrow",Z0={top:"bottom",right:"left",bottom:"top",left:"right"},Hf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=J0(Bf,r),i=Z0[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(G0,{...o,ref:n,style:{...o.style,display:"block"}})})});Hf.displayName=Bf;function Q0(e){return e!==null}var eS=e=>({name:"transformOrigin",options:e,fn(t){var v,x,w;const{placement:n,rects:r,middlewareData:o}=t,i=((v=o.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=Uf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let g="",y="";return c==="bottom"?(g=i?f:`${h}px`,y=`${-l}px`):c==="top"?(g=i?f:`${h}px`,y=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,y=i?f:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,y=i?f:`${p}px`),{data:{x:g,y}}}});function Uf(e){const[t,n="center"]=e.split("-");return[t,n]}var Wf=Lf,Vf=$f,qf=zf,Kf=Hf,Xa="rovingFocusGroup.onEntryFocus",tS={bubbles:!1,cancelable:!0},bo="RovingFocusGroup",[Ja,Gf,nS]=Da(bo),[rS,Yf]=Tn(bo,[nS]),[oS,sS]=rS(bo),Xf=m.forwardRef((e,t)=>u.jsx(Ja.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Ja.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(iS,{...e,ref:t})})}));Xf.displayName=bo;var iS=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=He(t,h),g=$s(s),[y,v]=mr({prop:i,defaultProp:a??null,onChange:l,caller:bo}),[x,w]=m.useState(!1),S=At(c),T=Gf(n),k=m.useRef(!1),[C,E]=m.useState(0);return m.useEffect(()=>{const _=h.current;if(_)return _.addEventListener(Xa,S),()=>_.removeEventListener(Xa,S)},[S]),u.jsx(oS,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:y,onItemFocus:m.useCallback(_=>v(_),[v]),onItemShiftTab:m.useCallback(()=>w(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:m.useCallback(()=>E(_=>_-1),[]),children:u.jsx(Ne.div,{tabIndex:x||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ge(e.onMouseDown,()=>{k.current=!0}),onFocus:ge(e.onFocus,_=>{const j=!k.current;if(_.target===_.currentTarget&&j&&!x){const D=new CustomEvent(Xa,tS);if(_.currentTarget.dispatchEvent(D),!D.defaultPrevented){const F=T().filter(U=>U.focusable),K=F.find(U=>U.active),P=F.find(U=>U.id===y),L=[K,P,...F].filter(Boolean).map(U=>U.ref.current);Qf(L,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),Jf="RovingFocusGroupItem",Zf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=En(),c=s||l,d=sS(Jf,n),f=d.currentTabStopId===c,h=Gf(n),{onFocusableItemAdd:p,onFocusableItemRemove:g,currentTabStopId:y}=d;return m.useEffect(()=>{if(r)return p(),()=>g()},[r,p,g]),u.jsx(Ja.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ge(e.onMouseDown,v=>{r?d.onItemFocus(c):v.preventDefault()}),onFocus:ge(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ge(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const x=cS(v,d.orientation,d.dir);if(x!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let S=h().filter(T=>T.focusable).map(T=>T.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const T=S.indexOf(v.currentTarget);S=d.loop?uS(S,T+1):S.slice(T+1)}setTimeout(()=>Qf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:y!=null}):i})})});Zf.displayName=Jf;var aS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function lS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function cS(e,t,n){const r=lS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return aS[r]}function Qf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function uS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var dS=Xf,fS=Zf,Za=["Enter"," "],hS=["ArrowDown","PageUp","Home"],eh=["ArrowUp","PageDown","End"],pS=[...hS,...eh],mS={ltr:[...Za,"ArrowRight"],rtl:[...Za,"ArrowLeft"]},gS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,xS,yS]=Da(So),[vr,th]=Tn(So,[yS,Xs,Yf]),Js=Xs(),nh=Yf(),[vS,wr]=vr(So),[wS,ko]=vr(So),rh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Js(t),[l,c]=m.useState(null),d=m.useRef(!1),f=At(s),h=$s(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(Wf,{...a,children:u.jsx(vS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(wS,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};rh.displayName=So;var bS="MenuAnchor",Qa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Js(n);return u.jsx(Vf,{...o,...r,ref:t})});Qa.displayName=bS;var el="MenuPortal",[SS,oh]=vr(el,{forceMount:void 0}),sh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=wr(el,t);return u.jsx(SS,{scope:t,forceMount:n,children:u.jsx(qt,{present:n||s.open,children:u.jsx(Cs,{asChild:!0,container:o,children:r})})})};sh.displayName=el;var nn="MenuContent",[CS,tl]=vr(nn),ih=m.forwardRef((e,t)=>{const n=oh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=ko(nn,e.__scopeMenu);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(qt,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(kS,{...o,ref:t}):u.jsx(TS,{...o,ref:t})})})})}),kS=m.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu),r=m.useRef(null),o=He(t,r);return m.useEffect(()=>{const s=r.current;if(s)return ja(s)},[]),u.jsx(nl,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),TS=m.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu);return u.jsx(nl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ES=sr.createSlot("MenuContent.ScrollLock"),nl=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:g,...y}=e,v=wr(nn,n),x=ko(nn,n),w=Js(n),S=nh(n),T=xS(n),[k,C]=m.useState(null),E=m.useRef(null),_=He(t,E,v.onContentChange),j=m.useRef(0),D=m.useRef(""),F=m.useRef(0),K=m.useRef(null),P=m.useRef("right"),R=m.useRef(0),L=g?Ns:m.Fragment,U=g?{as:ES,allowPinchZoom:!0}:void 0,te=z=>{var q,M;const G=D.current+z,Q=T().filter(X=>!X.disabled),le=document.activeElement,B=(q=Q.find(X=>X.ref.current===le))==null?void 0:q.textValue,ie=Q.map(X=>X.textValue),Ce=FS(ie,G,B),ke=(M=Q.find(X=>X.textValue===Ce))==null?void 0:M.ref.current;(function X(ne){D.current=ne,window.clearTimeout(j.current),ne!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(G),ke&&setTimeout(()=>ke.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),Ta();const V=m.useCallback(z=>{var Q,le;return P.current===((Q=K.current)==null?void 0:Q.side)&&zS(z,(le=K.current)==null?void 0:le.area)},[]);return u.jsx(CS,{scope:n,searchRef:D,onItemEnter:m.useCallback(z=>{V(z)&&z.preventDefault()},[V]),onItemLeave:m.useCallback(z=>{var G;V(z)||((G=E.current)==null||G.focus(),C(null))},[V]),onTriggerLeave:m.useCallback(z=>{V(z)&&z.preventDefault()},[V]),pointerGraceTimerRef:F,onPointerGraceIntentChange:m.useCallback(z=>{K.current=z},[]),children:u.jsx(L,{...U,children:u.jsx(Ss,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,z=>{var G;z.preventDefault(),(G=E.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(bs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(dS,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:ge(l,z=>{x.isUsingKeyboardRef.current||z.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(qf,{role:"menu","aria-orientation":"vertical","data-state":Ch(v.open),"data-radix-menu-content":"",dir:x.dir,...w,...y,ref:_,style:{outline:"none",...y.style},onKeyDown:ge(y.onKeyDown,z=>{const Q=z.target.closest("[data-radix-menu-content]")===z.currentTarget,le=z.ctrlKey||z.altKey||z.metaKey,B=z.key.length===1;Q&&(z.key==="Tab"&&z.preventDefault(),!le&&B&&te(z.key));const ie=E.current;if(z.target!==ie||!pS.includes(z.key))return;z.preventDefault();const ke=T().filter(q=>!q.disabled).map(q=>q.ref.current);eh.includes(z.key)&&ke.reverse(),DS(ke)}),onBlur:ge(e.onBlur,z=>{z.currentTarget.contains(z.target)||(window.clearTimeout(j.current),D.current="")}),onPointerMove:ge(e.onPointerMove,Eo(z=>{const G=z.target,Q=R.current!==z.clientX;if(z.currentTarget.contains(G)&&Q){const le=z.clientX>R.current?"right":"left";P.current=le,R.current=z.clientX}}))})})})})})})});ih.displayName=nn;var IS="MenuGroup",rl=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});rl.displayName=IS;var AS="MenuLabel",ah=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});ah.displayName=AS;var Zs="MenuItem",lh="menu.itemSelect",Qs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=ko(Zs,e.__scopeMenu),a=tl(Zs,e.__scopeMenu),l=He(t,s),c=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(lh,{bubbles:!0,cancelable:!0});f.addEventListener(lh,p=>r==null?void 0:r(p),{once:!0}),od(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(ch,{...o,ref:l,disabled:n,onClick:ge(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ge(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ge(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Za.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Qs.displayName=Zs;var ch=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=tl(Zs,n),a=nh(n),l=m.useRef(null),c=He(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const g=l.current;g&&p((g.textContent??"").trim())},[s.children]),u.jsx(Co.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(fS,{asChild:!0,...a,focusable:!r,children:u.jsx(Ne.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ge(e.onPointerMove,Eo(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Eo(g=>i.onItemLeave(g))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),NS="MenuCheckboxItem",uh=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(mh,{scope:e.__scopeMenu,checked:n,children:u.jsx(Qs,{role:"menuitemcheckbox","aria-checked":ei(n)?"mixed":n,...o,ref:t,"data-state":sl(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(ei(n)?!0:!n),{checkForDefaultPrevented:!1})})})});uh.displayName=NS;var dh="MenuRadioGroup",[_S,jS]=vr(dh,{value:void 0,onValueChange:()=>{}}),fh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=At(r);return u.jsx(_S,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(rl,{...o,ref:t})})});fh.displayName=dh;var hh="MenuRadioItem",ph=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=jS(hh,e.__scopeMenu),s=n===o.value;return u.jsx(mh,{scope:e.__scopeMenu,checked:s,children:u.jsx(Qs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":sl(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});ph.displayName=hh;var ol="MenuItemIndicator",[mh,RS]=vr(ol,{checked:!1}),gh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=RS(ol,n);return u.jsx(qt,{present:r||ei(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":sl(s.checked)})})});gh.displayName=ol;var PS="MenuSeparator",xh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});xh.displayName=PS;var OS="MenuArrow",yh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Js(n);return u.jsx(Kf,{...o,...r,ref:t})});yh.displayName=OS;var MS="MenuSub",[xT,vh]=vr(MS),To="MenuSubTrigger",wh=m.forwardRef((e,t)=>{const n=wr(To,e.__scopeMenu),r=ko(To,e.__scopeMenu),o=vh(To,e.__scopeMenu),s=tl(To,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Qa,{asChild:!0,...c,children:u.jsx(ch,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Ch(n.open),...e,ref:pa(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ge(e.onPointerMove,Eo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ge(e.onPointerLeave,Eo(f=>{var p,g;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const y=(g=n.content)==null?void 0:g.dataset.side,v=y==="right",x=v?-5:5,w=h[v?"left":"right"],S=h[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:w,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:w,y:h.bottom}],side:y}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ge(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||mS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});wh.displayName=To;var bh="MenuSubContent",Sh=m.forwardRef((e,t)=>{const n=oh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=ko(nn,e.__scopeMenu),a=vh(bh,e.__scopeMenu),l=m.useRef(null),c=He(t,l);return u.jsx(Co.Provider,{scope:e.__scopeMenu,children:u.jsx(qt,{present:r||s.open,children:u.jsx(Co.Slot,{scope:e.__scopeMenu,children:u.jsx(nl,{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 f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ge(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ge(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ge(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=gS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Sh.displayName=bh;function Ch(e){return e?"open":"closed"}function ei(e){return e==="indeterminate"}function sl(e){return ei(e)?"indeterminate":e?"checked":"unchecked"}function DS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function LS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function FS(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=LS(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 $S(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,f=l.x,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function zS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return $S(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var BS=rh,HS=Qa,US=sh,WS=ih,VS=rl,qS=ah,KS=Qs,GS=uh,YS=fh,XS=ph,JS=gh,ZS=xh,QS=yh,eC=wh,tC=Sh,ti="DropdownMenu",[nC,yT]=Tn(ti,[th]),$t=th(),[rC,kh]=nC(ti),Th=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=$t(t),c=m.useRef(null),[d,f]=mr({prop:o,defaultProp:s??!1,onChange:i,caller:ti});return u.jsx(rC,{scope:t,triggerId:En(),triggerRef:c,contentId:En(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(BS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Th.displayName=ti;var Eh="DropdownMenuTrigger",Ih=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=kh(Eh,n),i=$t(n);return u.jsx(HS,{asChild:!0,...i,children:u.jsx(Ne.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:pa(t,s.triggerRef),onPointerDown:ge(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ge(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ih.displayName=Eh;var oC="DropdownMenuPortal",Ah=e=>{const{__scopeDropdownMenu:t,...n}=e,r=$t(t);return u.jsx(US,{...r,...n})};Ah.displayName=oC;var Nh="DropdownMenuContent",_h=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=kh(Nh,n),s=$t(n),i=m.useRef(!1);return u.jsx(WS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ge(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ge(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)"}})});_h.displayName=Nh;var sC="DropdownMenuGroup",iC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(VS,{...o,...r,ref:t})});iC.displayName=sC;var aC="DropdownMenuLabel",jh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(qS,{...o,...r,ref:t})});jh.displayName=aC;var lC="DropdownMenuItem",Rh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(KS,{...o,...r,ref:t})});Rh.displayName=lC;var cC="DropdownMenuCheckboxItem",Ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(GS,{...o,...r,ref:t})});Ph.displayName=cC;var uC="DropdownMenuRadioGroup",dC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(YS,{...o,...r,ref:t})});dC.displayName=uC;var fC="DropdownMenuRadioItem",Oh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(XS,{...o,...r,ref:t})});Oh.displayName=fC;var hC="DropdownMenuItemIndicator",Mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(JS,{...o,...r,ref:t})});Mh.displayName=hC;var pC="DropdownMenuSeparator",Dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(ZS,{...o,...r,ref:t})});Dh.displayName=pC;var mC="DropdownMenuArrow",gC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(QS,{...o,...r,ref:t})});gC.displayName=mC;var xC="DropdownMenuSubTrigger",Lh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(eC,{...o,...r,ref:t})});Lh.displayName=xC;var yC="DropdownMenuSubContent",Fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(tC,{...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)"}})});Fh.displayName=yC;var vC=Th,wC=Ih,bC=Ah,$h=_h,zh=jh,Bh=Rh,Hh=Ph,Uh=Oh,Wh=Mh,Vh=Dh,qh=Lh,Kh=Fh;const SC=vC,CC=wC,kC=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(qh,{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(me.ChevronRight,{className:"ml-auto h-4 w-4"})]}));kC.displayName=qh.displayName;const TC=m.forwardRef(({className:e,...t},n)=>u.jsx(Kh,{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}));TC.displayName=Kh.displayName;const Gh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(bC,{children:u.jsx($h,{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})}));Gh.displayName=$h.displayName;const il=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Bh,{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}));il.displayName=Bh.displayName;const EC=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(Hh,{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(Wh,{children:u.jsx(me.Check,{className:"h-4 w-4"})})}),t]}));EC.displayName=Hh.displayName;const IC=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Uh,{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(Wh,{children:u.jsx(me.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));IC.displayName=Uh.displayName;const AC=m.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(zh,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));AC.displayName=zh.displayName;const NC=m.forwardRef(({className:e,...t},n)=>u.jsx(Vh,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));NC.displayName=Vh.displayName;const Yh={value:""};function ni({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,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:g}){const{api:y}=Ni(),{currentThreadId:v}=Yo(),{threadId:x,messages:w,hasMore:S,isHistoryLoading:T,isLoading:k,loadOlder:C,navigateToCheckpoint:E,returnToLatest:_,checkpoint:j,checkpoints:D,interrupt:F,metadata:K}=Xo(),{isStreaming:P,error:R,submit:L,stop:U}=Bc(),te=x??v??null,V=(j==null?void 0:j.id)??null,z=(j==null?void 0:j.namespace)??null,G=(K==null?void 0:K.assemblingMessageId)??null,Q=F,[le,B]=b.useState(!1);b.useEffect(()=>{Q||B(!1)},[Q]);const ie=b.useCallback(()=>{B(!0)},[]),Ce=b.useCallback(()=>{B(!1)},[]),ke=!!Q||le,[q,M]=b.useState(null),[X,ne]=b.useState(""),[xe,se]=b.useState(null),[ae,Ue]=b.useState([]),[Ke,ot]=b.useState(0),[st,ut]=b.useState(0),[et,De]=b.useState(!1),[We,it]=b.useState(null),[gt,re]=b.useState(null),[ve,we]=b.useState(!1),[Ye,xt]=b.useState(null),[ft,wt]=b.useState(!1),Fe=b.useRef(!1),[Ze,Tt]=b.useState(()=>Yh.value),St=b.useRef(Ze),Yt=b.useRef(null),Et=b.useCallback($=>{Yh.value=$,Tt($)},[]),[rr,Xt]=b.useState(!1),xn=b.useCallback(($,de)=>{if(!$||typeof $!="object")return null;const he=$[de];return typeof he=="number"?he:null},[]),sn=b.useCallback(($,de)=>{if(!$||typeof $!="object")return null;const he=$[de];return typeof he=="string"&&he.trim()?he:null},[]),Dt=b.useMemo(()=>{const $=Array.isArray(D)?[...D]:[];return $.some(he=>xn(he.metadata,"step")!==null)&&$.sort((he,Ie)=>{const tt=xn(he.metadata,"step"),Lt=xn(Ie.metadata,"step");if(tt!==null||Lt!==null)return(Lt??Number.NEGATIVE_INFINITY)-(tt??Number.NEGATIVE_INFINITY);const an=Date.parse(he.createdAt??""),Ct=Date.parse(Ie.createdAt??"");return Number.isNaN(an)||Number.isNaN(Ct)?0:Ct-an}),$},[D,xn]),Pn=b.useRef(null),yn=b.useRef(null),ht=b.useCallback(()=>{Pn.current&&(Pn.current.value=""),yn.current&&(yn.current.value=""),ot($=>$+1),ut($=>$+1)},[]),vn=b.useCallback($=>{Et($)},[Et]),On=b.useRef(!1);b.useEffect(()=>{On.current&&!P&&(Ue([]),ht()),On.current=P},[P,ht]);const[kr,Jt]=b.useState("desktop");b.useEffect(()=>{const $=()=>{const de=window.innerWidth;Jt(de<640?"phone":de<1024?"tablet":"desktop")};return $(),window.addEventListener("resize",$),()=>window.removeEventListener("resize",$)},[]),b.useEffect(()=>{wt(!1),Fe.current=!1},[te]),b.useEffect(()=>{St.current=Ze},[Ze]),b.useEffect(()=>{if(!q){Yt.current=null;return}Yt.current===null&&(Yt.current=St.current),Et(X??"")},[X,q,Et]);const Tr=b.useCallback(async()=>{if(!(!S||T||!ft))try{await C()}catch($){console.warn("loadOlder failed",$)}},[S,ft,T,C]);b.useEffect(()=>{(async()=>{if(!y.baseUrl){xt(null);return}try{const de=await y.getAgent("default");xt(de.uiDefaultMessage||null)}catch(de){console.warn("Failed to fetch default message:",de),xt(null)}})()},[y.baseUrl]),b.useEffect(()=>{R&&!ve&&(g==null||g(R))},[R,ve,g]);const Mn=$=>{if($.length>Fs)return`Message too long (${$.length}/${Fs} characters)`;try{return Mb($),null}catch(de){return(de==null?void 0:de.message)||"Invalid message"}},wn=async $=>{const de=$.trim();if(!(!de&&ae.length===0)){if(de){const he=Mn(de);if(he){se(he);return}}try{await L({text:de||"",attachments:ae,payload:q?{edit:!0,originalMessageId:q}:void 0},{checkpointId:V??void 0,checkpointNs:z??void 0}),h==null||h(de),Et(""),se(null),Ue([]),ht(),M(null),ne("")}catch(he){const Ie=(he==null?void 0:he.message)||"Failed to send message";se(Ie),g==null||g(Ie)}}},Un=b.useCallback(($,de)=>{c&&(Yt.current=Ze,M($),ne(de),Et(de),se(null))},[Ze,c,Et]),Er=b.useCallback(()=>{M(null),ne(""),se(null),Et(Yt.current??Ze),Yt.current=null},[Ze,Et]),Wr=b.useCallback(($,de)=>{Un($,de)},[Un]),Vr=b.useCallback($=>{const de=he=>{const Ie=he.content||[],tt=Ie.filter(Lt=>Lt.type==="text").map(Lt=>Lt.text).join("");if(tt)return tt;try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}};for(let he=$-1;he>=0;he--)if(w[he].role==="user"){const Ie=de(w[he]);Ie&&L({text:Ie},{checkpointId:V??void 0,checkpointNs:z??void 0});break}},[w,L,V,z]),or=$=>{const de=Array.from($.target.files||[]);Ue(he=>[...he,...de]),$.target.value=""},I=$=>{Ue(de=>{const he=de.filter((Ie,tt)=>$!==tt);return he.length===0&&ht(),he})},H=async $=>{const de=($.target.files||[])[0];if(de){it(null),re(null),De(!0);try{await L({attachments:[de]},{checkpointId:V??void 0,checkpointNs:z??void 0});const he=`Uploaded ${de.name} - processing through chat stream`;re(he)}catch(he){const Ie=he instanceof Error?he.message:"Failed to upload Excel file";console.error("Excel upload failed",he),it(Ie),g==null||g(Ie)}finally{De(!1),$.target.value="",ht()}}},ue=$=>{if(!$)return"Unknown";const de=Date.parse($);return Number.isNaN(de)?$:new Date(de).toLocaleString()},Te=async $=>{if(v){Xt(!0);try{if(!$){await _();return}const de=Dt.find(Ie=>Ie.checkpointId===$),he=(de==null?void 0:de.checkpointNs)??null;await E($,he)}finally{Xt(!1)}}},qe=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,$e=`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 ${f.messagesArea||""}`,Le=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`;return u.jsxs("div",{className:qe,children:[!!R&&!ve&&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:R}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>we(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(me.X,{size:16})})]}),v&&D.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:V??"",onChange:$=>{const de=$.target.value||null;Te(de)},children:[u.jsx("option",{value:"",children:"Latest"}),Dt.map($=>{const de=xn($.metadata,"step"),he=sn($.metadata,"source"),Ie=[];de!==null&&Ie.push(`Step ${de}`),he&&Ie.push(he);const tt=Ie.length?` — ${Ie.join(" • ")}`:"";return u.jsxs("option",{value:$.checkpointId,children:[ue($.createdAt),tt]},$.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${$e}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Ma,{className:"h-full",style:{height:"100%"},messages:w,isStreaming:P,streamingAssistantId:G,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:kr,enableMessageEditing:c,editingMessageId:q,onStartReached:()=>{ft&&Tr()},onScrollAway:$=>{if(!Fe.current){Fe.current=!0;return}$&&wt(!0)},onEdit:Wr,onRegenerate:Vr,onCancelEdit:Er,emptyMessage:Ye??void 0,isNavigatingCheckpoint:rr,activeInterrupt:Q,disableInterruptActions:le,onInterruptActionStart:ie,onInterruptActionEnd:Ce,showToolMessages:d}),k&&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(me.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),u.jsxs("div",{className:Le,children:[q&&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(me.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:Er,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(me.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:Pn,type:"file",multiple:!0,onChange:$=>or($),className:"hidden"},Ke),ae.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:ae.map(($,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(me.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:$.name}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>I(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 ${$.name}`,children:u.jsx(me.X,{size:12})})]},de))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:yn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:H,className:"hidden"},st),et&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(me.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!et&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),We&&!et&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:We})]})]}),xe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:xe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(SC,{children:[u.jsx(CC,{asChild:!0,children:u.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:P||ke,title:"More input actions",className:f.moreButton||"",children:u.jsx(me.Plus,{size:16})})}),u.jsxs(Gh,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(il,{onClick:()=>{var $;return($=Pn.current)==null?void 0:$.click()},className:"cursor-pointer",children:[u.jsx(me.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(il,{onClick:()=>{var $;et||($=yn.current)==null||$.click()},className:`cursor-pointer ${et?"opacity-60 pointer-events-none":""}`,children:[u.jsx(me.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(Yx,{initialValue:X,editingMessageId:q,value:Ze,onValueChange:vn,placeholder:q?"Edit your message...":t,isStreaming:P,disabled:ke,maxLength:Fs,onSend:wn,onCancelEdit:Er,onStop:U,allowEmptySend:ae.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${q?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${xe?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const ri=m.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}));ri.displayName="Input";function al(e,[t,n]){return Math.min(n,Math.max(t,e))}function _C(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var ll="ScrollArea",[Xh,vT]=Tn(ll),[jC,rn]=Xh(ll),Jh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[c,d]=m.useState(null),[f,h]=m.useState(null),[p,g]=m.useState(null),[y,v]=m.useState(null),[x,w]=m.useState(0),[S,T]=m.useState(0),[k,C]=m.useState(!1),[E,_]=m.useState(!1),j=He(t,F=>l(F)),D=$s(o);return u.jsx(jC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:g,scrollbarXEnabled:k,onScrollbarXEnabledChange:C,scrollbarY:y,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:_,onCornerWidthChange:w,onCornerHeightChange:T,children:u.jsx(Ne.div,{dir:D,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Jh.displayName=ll;var Zh="ScrollAreaViewport",Qh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=rn(Zh,n),a=m.useRef(null),l=He(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(Ne.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})})]})});Qh.displayName=Zh;var Rn="ScrollAreaScrollbar",cl=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(RC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(PC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(ep,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(ul,{...r,ref:t}):null});cl.displayName=Rn;var RC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.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(qt,{present:n||s,children:u.jsx(ep,{"data-state":s?"visible":"hidden",...r,ref:t})})}),PC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ai(()=>l("SCROLL_END"),100),[a,l]=_C("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 m.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(qt,{present:n||a!=="hidden",children:u.jsx(ul,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),ep=m.forwardRef((e,t)=>{const n=rn(Rn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=ai(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Br(n.viewport,l),Br(n.content,l),u.jsx(qt,{present:r||s,children:u.jsx(ul,{"data-state":s?"visible":"hidden",...o,ref:t})})}),ul=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=rn(Rn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return $C(h,i.current,a,p)}return n==="horizontal"?u.jsx(OC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=ip(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(MC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=ip(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),OC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=He(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(np,{"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":ii(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),lp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:si(i.paddingLeft),paddingEnd:si(i.paddingRight)}})}})}),MC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),c=He(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(np,{"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":ii(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),lp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:si(i.paddingTop),paddingEnd:si(i.paddingBottom)}})}})}),[DC,tp]=Xh(Rn),np=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...h}=e,p=rn(Rn,n),[g,y]=m.useState(null),v=He(t,j=>y(j)),x=m.useRef(null),w=m.useRef(""),S=p.viewport,T=r.content-r.viewport,k=At(d),C=At(l),E=ai(f,10);function _(j){if(x.current){const D=j.clientX-x.current.left,F=j.clientY-x.current.top;c({x:D,y:F})}}return m.useEffect(()=>{const j=D=>{const F=D.target;(g==null?void 0:g.contains(F))&&k(D,T)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,g,T,k]),m.useEffect(C,[r,C]),Br(g,E),Br(p.content,E),u.jsx(DC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:At(s),onThumbPointerUp:At(i),onThumbPositionChange:C,onThumbPointerDown:At(a),children:u.jsx(Ne.div,{...h,ref:v,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),x.current=g.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),_(j))}),onPointerMove:ge(e.onPointerMove,_),onPointerUp:ge(e.onPointerUp,j=>{const D=j.target;D.hasPointerCapture(j.pointerId)&&D.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),oi="ScrollAreaThumb",rp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tp(oi,e.__scopeScrollArea);return u.jsx(qt,{present:n||o.hasThumb,children:u.jsx(LC,{ref:t,...r})})}),LC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=rn(oi,n),i=tp(oi,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),c=m.useRef(void 0),d=ai(()=>{c.current&&(c.current(),c.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=zC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(Ne.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:ge(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),g=f.clientX-p.left,y=f.clientY-p.top;i.onThumbPointerDown({x:g,y})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});rp.displayName=oi;var dl="ScrollAreaCorner",op=m.forwardRef((e,t)=>{const n=rn(dl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(FC,{...e,ref:t}):null});op.displayName=dl;var FC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=rn(dl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),c=!!(s&&a);return Br(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Br(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.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 si(e){return e?parseInt(e,10):0}function sp(e,t){const n=e/t;return isNaN(n)?0:n}function ii(e){const t=sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function $C(e,t,n,r="ltr"){const o=ii(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,f=r==="ltr"?[0,d]:[d*-1,0];return ap([l,c],f)(e)}function ip(e,t,n="ltr"){const r=ii(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=al(e,l);return ap([0,i],[0,a])(c)}function ap(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 lp(e,t){return e>0&&e<t}var zC=(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 ai(e,t){const n=At(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Br(e,t){const n=At(t);kt(()=>{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 cp=Jh,BC=Qh,HC=op;const up=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(cp,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(BC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(dp,{}),u.jsx(HC,{})]}));up.displayName=cp.displayName;const dp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(cl,{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(rp,{className:"relative flex-1 rounded-full bg-border"})}));dp.displayName=cl.displayName;function fl({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}){const{threads:f,currentThreadId:h,isLoading:p,actions:g}=Yo(),{loadThread:y}=Xo(),{createThread:v,deleteThread:x,renameThread:w}=g,[S,T]=b.useState(Array.isArray(f)?f:[]),k=b.useRef(S.length>0),C=b.useRef(null),E=b.useRef(0),[_,j]=b.useState(null),[D,F]=b.useState(""),[K,P]=b.useState(!1);b.useEffect(()=>{const B=Array.isArray(f)?f:[];if(B.length>0){k.current=!0,T(B);return}p||(k.current=!1,T(B))},[f,p]),b.useEffect(()=>{if(!C.current)return;const B=C.current.querySelector("[data-radix-scroll-area-viewport]");if(!B)return;let ie=null,Ce=null;return ie=requestAnimationFrame(()=>{Ce=requestAnimationFrame(()=>{B.scrollTop=E.current})}),()=>{ie!==null&&cancelAnimationFrame(ie),Ce!==null&&cancelAnimationFrame(Ce)}},[S]);const R=async B=>{try{await y(B),a==null||a(B),l==null||l(B)}catch(ie){console.error("Failed to select thread:",ie)}},L=async()=>{try{P(!0);const B=await v();c==null||c(B),a==null||a(B)}catch(B){console.error("Failed to create thread:",B)}finally{P(!1)}},U=async(B,ie)=>{if(ie.stopPropagation(),!!confirm("Delete this thread?")){if(C.current){const Ce=C.current.querySelector("[data-radix-scroll-area-viewport]");Ce&&(E.current=Ce.scrollTop)}try{await x(B),d==null||d(B)}catch(Ce){console.error("Failed to delete thread:",Ce)}}},te=(B,ie)=>{ie.stopPropagation(),j(B.threadId),F(B.title||`Thread ${B.threadId.slice(0,8)}`)},V=async B=>{if(D.trim())try{await w(B,D.trim()),j(null),F("")}catch(ie){console.error("Failed to update title:",ie)}},z=()=>{j(null),F("")},G=(B,ie)=>{B.key==="Enter"?V(ie):B.key==="Escape"&&z()},Q=B=>{if(!B)return"";try{const ie=new Date(B),ke=new Date().getTime()-ie.getTime(),q=Math.floor(ke/(1e3*60*60*24));return q===0?ie.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:ie.toLocaleDateString()}catch{return""}},le=B=>B.title||`Thread ${B.threadId.slice(0,8)}`;return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Xe,{onClick:L,disabled:K||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:K?"Creating...":"New Chat",children:u.jsx(me.MessageSquarePlus,{size:20})})}),u.jsx(up,{ref:C,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:p?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(me.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(me.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:"No conversations yet"})]}):S.slice().sort((B,ie)=>new Date(ie.updatedAt||ie.createdAt||"").getTime()-new Date(B.updatedAt||B.createdAt||"").getTime()).map(B=>u.jsxs("div",{onClick:()=>R(B.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===B.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:_===B.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ie=>ie.stopPropagation(),children:[u.jsx(ri,{value:D,onChange:ie=>F(ie.target.value),onKeyDown:ie=>G(ie,B.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>V(B.threadId),className:"h-6 w-6 p-0",children:u.jsx(me.Check,{size:12})}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:z,className:"h-6 w-6 p-0",children:u.jsx(me.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:le(B)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(me.Calendar,{size:10}),u.jsx("span",{children:Q(B.updatedAt||B.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==B.threadId&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ie=>te(B,ie),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(me.Edit3,{size:12})}),n&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:ie=>U(B.threadId,ie),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(me.Trash2,{size:12})})]})]}),i===B.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},B.threadId))})})]})}function Hr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function UC(e){if(typeof e!="string")return;const t=e.trim();if(t)return $n(t)}function fp(){const e=[Hr("__API_BASE_URL__"),Hr("__CHAT_API_BASE_URL__"),Hr("__CHAT_API_URL__")];for(const t of e){const n=UC(t);if(n)return n}}function hp(){const e=[Hr("__API_AUTH_TOKEN__"),Hr("__CHAT_API_KEY__"),Hr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return $n(t);return $n()}function mp(){const e={},t=fp(),n=hp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function gp(){const e=mp(),t=Wn.getAuthToken(),n=fp();return{apiBaseUrl:pp(e.baseUrl,Wn.baseUrl,n),apiKey:t||e.apiKey||hp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const xp="chat-settings";function WC(){try{const e=localStorage.getItem(xp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function VC(e){try{const t={...e,apiBaseUrl:$n(e.apiBaseUrl)};localStorage.setItem(xp,JSON.stringify(t)),t.apiKey&&Wn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function qC(){const e=gp(),t=WC(),n=Wn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:pp(Wn.baseUrl,r,e.apiBaseUrl)}}function KC(e){Wn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),VC(e)}var GC="Label",yp=m.forwardRef((e,t)=>u.jsx(Ne.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())}}));yp.displayName=GC;var vp=yp;const YC=Ro.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),on=m.forwardRef(({className:e,...t},n)=>u.jsx(vp,{ref:n,className:oe(YC(),e),...t}));on.displayName=vp.displayName;function wp(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var li="Switch",[XC,wT]=Tn(li),[JC,ZC]=XC(li),bp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[h,p]=m.useState(null),g=He(t,S=>p(S)),y=m.useRef(!1),v=h?d||!!h.closest("form"):!0,[x,w]=mr({prop:o,defaultProp:s??!1,onChange:c,caller:li});return u.jsxs(JC,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Tp(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:ge(e.onClick,S=>{w(T=>!T),v&&(y.current=S.isPropagationStopped(),y.current||S.stopPropagation())})}),v&&u.jsx(kp,{control:h,bubbles:!y.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});bp.displayName=li;var Sp="SwitchThumb",Cp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=ZC(Sp,n);return u.jsx(Ne.span,{"data-state":Tp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Cp.displayName=Sp;var QC="SwitchBubbleInput",kp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=He(i,s),l=wp(n),c=Of(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const g=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(g)}},[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}})});kp.displayName=QC;function Tp(e){return e?"checked":"unchecked"}var Ep=bp,ek=Cp;const er=m.forwardRef(({className:e,...t},n)=>u.jsx(Ep,{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(ek,{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")})}));er.displayName=Ep.displayName;var Ip=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"}),tk="VisuallyHidden",nk=m.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Ip,...e.style}}));nk.displayName=tk;var rk=[" ","Enter","ArrowUp","ArrowDown"],ok=[" ","Enter"],br="Select",[ci,ui,sk]=Da(br),[Ur,bT]=Tn(br,[sk,Xs]),di=Xs(),[ik,tr]=Ur(br),[ak,lk]=Ur(br),Ap=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:h,required:p,form:g}=e,y=di(t),[v,x]=m.useState(null),[w,S]=m.useState(null),[T,k]=m.useState(!1),C=$s(c),[E,_]=mr({prop:r,defaultProp:o??!1,onChange:s,caller:br}),[j,D]=mr({prop:i,defaultProp:a,onChange:l,caller:br}),F=m.useRef(null),K=v?g||!!v.closest("form"):!0,[P,R]=m.useState(new Set),L=Array.from(P).map(U=>U.props.value).join(";");return u.jsx(Wf,{...y,children:u.jsxs(ik,{required:p,scope:t,trigger:v,onTriggerChange:x,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:En(),value:j,onValueChange:D,open:E,onOpenChange:_,dir:C,triggerPointerDownPosRef:F,disabled:h,children:[u.jsx(ci.Provider,{scope:t,children:u.jsx(ak,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(U=>{R(te=>new Set(te).add(U))},[]),onNativeOptionRemove:m.useCallback(U=>{R(te=>{const V=new Set(te);return V.delete(U),V})},[]),children:n})}),K?u.jsxs(Zp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:U=>D(U.target.value),disabled:h,form:g,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(P)]},L):null]})})};Ap.displayName=br;var Np="SelectTrigger",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=di(n),i=tr(Np,n),a=i.disabled||r,l=He(t,i.onTriggerChange),c=ui(n),d=m.useRef("touch"),[f,h,p]=em(y=>{const v=c().filter(S=>!S.disabled),x=v.find(S=>S.value===i.value),w=tm(v,y,x);w!==void 0&&i.onValueChange(w.value)}),g=y=>{a||(i.onOpenChange(!0),p()),y&&(i.triggerPointerDownPosRef.current={x:Math.round(y.pageX),y:Math.round(y.pageY)})};return u.jsx(Vf,{asChild:!0,...s,children:u.jsx(Ne.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":Qp(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,y=>{y.currentTarget.focus(),d.current!=="mouse"&&g(y)}),onPointerDown:ge(o.onPointerDown,y=>{d.current=y.pointerType;const v=y.target;v.hasPointerCapture(y.pointerId)&&v.releasePointerCapture(y.pointerId),y.button===0&&y.ctrlKey===!1&&y.pointerType==="mouse"&&(g(y),y.preventDefault())}),onKeyDown:ge(o.onKeyDown,y=>{const v=f.current!=="";!(y.ctrlKey||y.altKey||y.metaKey)&&y.key.length===1&&h(y.key),!(v&&y.key===" ")&&rk.includes(y.key)&&(g(),y.preventDefault())})})})});_p.displayName=Np;var jp="SelectValue",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=tr(jp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=He(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qp(l.value)?u.jsx(u.Fragment,{children:i}):s})});Rp.displayName=jp;var ck="SelectIcon",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Pp.displayName=ck;var uk="SelectPortal",Op=e=>u.jsx(Cs,{asChild:!0,...e});Op.displayName=uk;var Sr="SelectContent",Mp=m.forwardRef((e,t)=>{const n=tr(Sr,e.__scopeSelect),[r,o]=m.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Po.createPortal(u.jsx(Dp,{scope:e.__scopeSelect,children:u.jsx(ci.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Lp,{...e,ref:t})});Mp.displayName=Sr;var gn=10,[Dp,nr]=Ur(Sr),dk="SelectContentImpl",fk=sr.createSlot("SelectContent.RemoveScroll"),Lp=m.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:f,collisionBoundary:h,collisionPadding:p,sticky:g,hideWhenDetached:y,avoidCollisions:v,...x}=e,w=tr(Sr,n),[S,T]=m.useState(null),[k,C]=m.useState(null),E=He(t,q=>T(q)),[_,j]=m.useState(null),[D,F]=m.useState(null),K=ui(n),[P,R]=m.useState(!1),L=m.useRef(!1);m.useEffect(()=>{if(S)return ja(S)},[S]),Ta();const U=m.useCallback(q=>{const[M,...X]=K().map(se=>se.ref.current),[ne]=X.slice(-1),xe=document.activeElement;for(const se of q)if(se===xe||(se==null||se.scrollIntoView({block:"nearest"}),se===M&&k&&(k.scrollTop=0),se===ne&&k&&(k.scrollTop=k.scrollHeight),se==null||se.focus(),document.activeElement!==xe))return},[K,k]),te=m.useCallback(()=>U([_,S]),[U,_,S]);m.useEffect(()=>{P&&te()},[P,te]);const{onOpenChange:V,triggerPointerDownPosRef:z}=w;m.useEffect(()=>{if(S){let q={x:0,y:0};const M=ne=>{var xe,se;q={x:Math.abs(Math.round(ne.pageX)-(((xe=z.current)==null?void 0:xe.x)??0)),y:Math.abs(Math.round(ne.pageY)-(((se=z.current)==null?void 0:se.y)??0))}},X=ne=>{q.x<=10&&q.y<=10?ne.preventDefault():S.contains(ne.target)||V(!1),document.removeEventListener("pointermove",M),z.current=null};return z.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",X,{capture:!0})}}},[S,V,z]),m.useEffect(()=>{const q=()=>V(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[V]);const[G,Q]=em(q=>{const M=K().filter(xe=>!xe.disabled),X=M.find(xe=>xe.ref.current===document.activeElement),ne=tm(M,q,X);ne&&setTimeout(()=>ne.ref.current.focus())}),le=m.useCallback((q,M,X)=>{const ne=!L.current&&!X;(w.value!==void 0&&w.value===M||ne)&&(j(q),ne&&(L.current=!0))},[w.value]),B=m.useCallback(()=>S==null?void 0:S.focus(),[S]),ie=m.useCallback((q,M,X)=>{const ne=!L.current&&!X;(w.value!==void 0&&w.value===M||ne)&&F(q)},[w.value]),Ce=r==="popper"?hl:Fp,ke=Ce===hl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:g,hideWhenDetached:y,avoidCollisions:v}:{};return u.jsx(Dp,{scope:n,content:S,viewport:k,onViewportChange:C,itemRefCallback:le,selectedItem:_,onItemLeave:B,itemTextRefCallback:ie,focusSelectedItem:te,selectedItemText:D,position:r,isPositioned:P,searchRef:G,children:u.jsx(Ns,{as:fk,allowPinchZoom:!0,children:u.jsx(Ss,{asChild:!0,trapped:w.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ge(o,q=>{var M;(M=w.trigger)==null||M.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(bs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:u.jsx(Ce,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:q=>q.preventDefault(),...x,...ke,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,q=>{const M=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!M&&q.key.length===1&&Q(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let ne=K().filter(xe=>!xe.disabled).map(xe=>xe.ref.current);if(["ArrowUp","End"].includes(q.key)&&(ne=ne.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const xe=q.target,se=ne.indexOf(xe);ne=ne.slice(se+1)}setTimeout(()=>U(ne)),q.preventDefault()}})})})})})})});Lp.displayName=dk;var hk="SelectItemAlignedPosition",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=tr(Sr,n),i=nr(Sr,n),[a,l]=m.useState(null),[c,d]=m.useState(null),f=He(t,E=>d(E)),h=ui(n),p=m.useRef(!1),g=m.useRef(!0),{viewport:y,selectedItem:v,selectedItemText:x,focusSelectedItem:w}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&y&&v&&x){const E=s.trigger.getBoundingClientRect(),_=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const xe=D.left-_.left,se=j.left-xe,ae=E.left-se,Ue=E.width+ae,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,st=al(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.left=st+"px"}else{const xe=_.right-D.right,se=window.innerWidth-j.right-xe,ae=window.innerWidth-E.right-se,Ue=E.width+ae,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,st=al(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.right=st+"px"}const F=h(),K=window.innerHeight-gn*2,P=y.scrollHeight,R=window.getComputedStyle(c),L=parseInt(R.borderTopWidth,10),U=parseInt(R.paddingTop,10),te=parseInt(R.borderBottomWidth,10),V=parseInt(R.paddingBottom,10),z=L+U+P+V+te,G=Math.min(v.offsetHeight*5,z),Q=window.getComputedStyle(y),le=parseInt(Q.paddingTop,10),B=parseInt(Q.paddingBottom,10),ie=E.top+E.height/2-gn,Ce=K-ie,ke=v.offsetHeight/2,q=v.offsetTop+ke,M=L+U+q,X=z-M;if(M<=ie){const xe=F.length>0&&v===F[F.length-1].ref.current;a.style.bottom="0px";const se=c.clientHeight-y.offsetTop-y.offsetHeight,ae=Math.max(Ce,ke+(xe?B:0)+se+te),Ue=M+ae;a.style.height=Ue+"px"}else{const xe=F.length>0&&v===F[0].ref.current;a.style.top="0px";const ae=Math.max(ie,L+y.offsetTop+(xe?le:0)+ke)+X;a.style.height=ae+"px",y.scrollTop=M-ie+y.offsetTop}a.style.margin=`${gn}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=K+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,y,v,x,s.dir,r]);kt(()=>S(),[S]);const[T,k]=m.useState();kt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const C=m.useCallback(E=>{E&&g.current===!0&&(S(),w==null||w(),g.current=!1)},[S,w]);return u.jsx(mk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:u.jsx(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fp.displayName=hk;var pk="SelectPopperPosition",hl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=gn,...s}=e,i=di(n);return u.jsx(qf,{...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)"}})});hl.displayName=pk;var[mk,pl]=Ur(Sr,{}),ml="SelectViewport",$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=nr(ml,n),i=pl(ml,n),a=He(t,s.onViewportChange),l=m.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(ci.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ge(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const g=window.innerHeight-gn*2,y=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),x=Math.max(y,v);if(x<g){const w=x+p,S=Math.min(g,w),T=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});$p.displayName=ml;var zp="SelectGroup",[gk,xk]=Ur(zp),yk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=En();return u.jsx(gk,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});yk.displayName=zp;var Bp="SelectLabel",Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=xk(Bp,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});Hp.displayName=Bp;var fi="SelectItem",[vk,Up]=Ur(fi),Wp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=tr(fi,n),l=nr(fi,n),c=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),g=He(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),y=En(),v=m.useRef("touch"),x=()=>{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(vk,{scope:n,value:r,disabled:o,textId:y,isSelected:c,onItemTextChange:m.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:u.jsx(ci.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":y,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:g,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{v.current!=="mouse"&&x()}),onPointerUp:ge(i.onPointerUp,()=>{v.current==="mouse"&&x()}),onPointerDown:ge(i.onPointerDown,w=>{v.current=w.pointerType}),onPointerMove:ge(i.onPointerMove,w=>{var S;v.current=w.pointerType,o?(S=l.onItemLeave)==null||S.call(l):v.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ge(i.onPointerLeave,w=>{var S;w.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ge(i.onKeyDown,w=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&w.key===" "||(ok.includes(w.key)&&x(),w.key===" "&&w.preventDefault())})})})})});Wp.displayName=fi;var Io="SelectItemText",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=tr(Io,n),a=nr(Io,n),l=Up(Io,n),c=lk(Io,n),[d,f]=m.useState(null),h=He(t,x=>f(x),l.onItemTextChange,x=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,g=m.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:y,onNativeOptionRemove:v}=c;return kt(()=>(y(g),()=>v(g)),[y,v,g]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Po.createPortal(s.children,i.valueNode):null]})});Vp.displayName=Io;var qp="SelectItemIndicator",Kp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Up(qp,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});Kp.displayName=qp;var gl="SelectScrollUpButton",Gp=m.forwardRef((e,t)=>{const n=nr(gl,e.__scopeSelect),r=pl(gl,e.__scopeSelect),[o,s]=m.useState(!1),i=He(t,r.onScrollButtonChange);return kt(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Gp.displayName=gl;var xl="SelectScrollDownButton",Yp=m.forwardRef((e,t)=>{const n=nr(xl,e.__scopeSelect),r=pl(xl,e.__scopeSelect),[o,s]=m.useState(!1),i=He(t,r.onScrollButtonChange);return kt(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Yp.displayName=xl;var Xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=nr("SelectScrollButton",n),i=m.useRef(null),a=ui(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),kt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ge(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ge(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ge(o.onPointerLeave,()=>{l()})})}),wk="SelectSeparator",Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});Jp.displayName=wk;var yl="SelectArrow",bk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=di(n),s=tr(yl,n),i=nr(yl,n);return s.open&&i.position==="popper"?u.jsx(Kf,{...o,...r,ref:t}):null});bk.displayName=yl;var Sk="SelectBubbleInput",Zp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=He(r,o),i=wp(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ne.select,{...n,style:{...Ip,...n.style},ref:s,defaultValue:t})});Zp.displayName=Sk;function Qp(e){return e===""||e===void 0}function em(e){const t=At(e),n=m.useRef(""),r=m.useRef(0),o=m.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=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function tm(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=Ck(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 Ck(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kk=Ap,nm=_p,Tk=Rp,Ek=Pp,Ik=Op,rm=Mp,Ak=$p,om=Hp,sm=Wp,Nk=Vp,_k=Kp,im=Gp,am=Yp,lm=Jp;const cm=kk,um=Tk,vl=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(nm,{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(Ek,{asChild:!0,children:u.jsx(me.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));vl.displayName=nm.displayName;const dm=m.forwardRef(({className:e,...t},n)=>u.jsx(im,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(me.ChevronUp,{className:"h-4 w-4"})}));dm.displayName=im.displayName;const fm=m.forwardRef(({className:e,...t},n)=>u.jsx(am,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(me.ChevronDown,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const wl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Ik,{children:u.jsxs(rm,{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(dm,{}),u.jsx(Ak,{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(fm,{})]})}));wl.displayName=rm.displayName;const jk=m.forwardRef(({className:e,...t},n)=>u.jsx(om,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));jk.displayName=om.displayName;const Cr=m.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(sm,{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(_k,{children:u.jsx(me.Check,{className:"h-4 w-4"})})}),u.jsx(Nk,{children:t})]}));Cr.displayName=sm.displayName;const Rk=m.forwardRef(({className:e,...t},n)=>u.jsx(lm,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));Rk.displayName=lm.displayName;var Pk="Separator",hm="horizontal",Ok=["horizontal","vertical"],pm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=hm,...o}=e,s=Mk(r)?r:hm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});pm.displayName=Pk;function Mk(e){return Ok.includes(e)}var mm=pm;const gm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(mm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gm.displayName=mm.displayName;const Dk=Zd,Lk=vb,Fk=Qd,xm=m.forwardRef(({className:e,...t},n)=>u.jsx(Os,{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}));xm.displayName=Os.displayName;const $k=Ro.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"}}),ym=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(Fk,{children:[u.jsx(xm,{}),u.jsxs(Ms,{ref:o,className:oe($k({side:e}),t),...r,children:[n,u.jsxs(ef,{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(me.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ym.displayName=Ms.displayName;const vm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});vm.displayName="SheetHeader";const wm=m.forwardRef(({className:e,...t},n)=>u.jsx(xr,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));wm.displayName=xr.displayName;const bm=m.forwardRef(({className:e,...t},n)=>u.jsx(Ds,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));bm.displayName=Ds.displayName;const zk={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function Bk({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,d]=b.useState(!1),{toast:f}=wa();b.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);d(v)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(zk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(e),d(!1),o(!1)},y=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(Dk,{open:r,onOpenChange:o,children:[u.jsx(Lk,{asChild:!0,children:u.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[u.jsx(me.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(ed,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(ym,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(vm,{children:[u.jsx(wm,{children:"Chat Settings"}),u.jsx(bm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(fo,{children:[u.jsx(ho,{className:"pb-3",children:u.jsxs(po,{className:"text-lg flex items-center gap-2",children:[u.jsx(me.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(mo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(ri,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(x=>({...x,api:{...x.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Xe,{variant:"outline",onClick:y,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(er,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(x=>({...x,api:{...x.api,enableAuth:v}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(ri,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(x=>({...x,api:{...x.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Xe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(me.EyeOff,{className:"h-4 w-4"}):u.jsx(me.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(fo,{children:[u.jsx(ho,{className:"pb-3",children:u.jsxs(po,{className:"text-lg flex items-center gap-2",children:[u.jsx(me.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(mo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(cm,{value:a.ui.layout,onValueChange:v=>l(x=>({...x,ui:{...x.ui,layout:v}})),children:[u.jsx(vl,{children:u.jsx(um,{})}),u.jsxs(wl,{children:[u.jsx(Cr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Cr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Cr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(on,{htmlFor:"theme",children:"Theme"}),u.jsxs(cm,{value:a.ui.theme,onValueChange:v=>l(x=>({...x,ui:{...x.ui,theme:v}})),children:[u.jsx(vl,{children:u.jsx(um,{})}),u.jsxs(wl,{children:[u.jsx(Cr,{value:"light",children:"Light"}),u.jsx(Cr,{value:"dark",children:"Dark"}),u.jsx(Cr,{value:"system",children:"System"})]})]})]}),u.jsx(gm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(er,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showTimestamps:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(er,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showAgentNames:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(on,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(er,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,compactMessages:v}}))})]})]})]})]}),u.jsxs(fo,{children:[u.jsx(ho,{className:"pb-3",children:u.jsxs(po,{className:"text-lg flex items-center gap-2",children:[u.jsx(me.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(mo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(on,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(er,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,autoSave:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(on,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(er,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(on,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(er,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:v}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Xe,{variant:"outline",onClick:p,children:[u.jsx(me.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Xe,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Xe,{onClick:h,disabled:!c,children:[u.jsx(me.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function Hk({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(Jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(ni,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Jo,{...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(fl,{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(ni,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Jo,{...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(fl,{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(ni,{onError:s.onError,enableFileUpload:!0})})]})})}_e.ChatApi=xc,_e.ChatInterface=ni,_e.ChatProviders=Jo,_e.ChatSettings=Bk,_e.MarkdownContent=ms,_e.MessageComponent=lf,_e.MessageList=Ma,_e.ThreadManager=fl,_e.applySettings=KC,_e.chatApiClient=Wn,_e.default=Hk,_e.del=gc,_e.get=cn,_e.getChatToken=hc,_e.getCurrentSettings=qC,_e.getDefaultApiConfig=mp,_e.getDefaultChatSettings=gp,_e.onChatTokenChanged=pc,_e.post=Ai,_e.put=mc,_e.setChatToken=Ii,_e.useApi=Ni,_e.useChatStream=Rc,_e.useMessagesReducer=kc,_e.useStream=Bc,_e.useThreadState=Xo,_e.useThreads=Yo,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|