teodor-new-chat-ui 4.3.92 → 4.3.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +441 -448
- package/dist/index.umd.js +14 -14
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(Ne,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):(Ne=typeof globalThis<"u"?globalThis:Ne||self,b(Ne.NewChatUI={},Ne.React,Ne.LucideReact,Ne.reactSlot,Ne.classVarianceAuthority,Ne.clsx,Ne.tailwindMerge,Ne.ReactDOM))})(this,function(Ne,b,fe,sr,Oo,jm,Rm,gi){"use strict";var Gk=Object.defineProperty;var Yk=(Ne,b,fe)=>b in Ne?Gk(Ne,b,{enumerable:!0,configurable:!0,writable:!0,value:fe}):Ne[b]=fe;var Am=(Ne,b,fe)=>Yk(Ne,typeof b!="symbol"?b+"":b,fe);function jl(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 y=jl(b),Mo=jl(gi);var xi={exports:{}},Kr={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+I+"`."}return""}}function pt(I){return""}var vn={};function On(I){{var U=yn();if(!U){var le=typeof I=="string"?I:I.displayName||I.name;le&&(U=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+le+">.")}return U}}function kr(I,U){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var le=On(U);if(vn[le])return;vn[le]=!0;var Ce="";I&&I._owner&&I._owner!==Xt.current&&(Ce=" It was passed a child from "+P(I._owner.type)+"."),sn(I),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',le,Ce),sn(null)}}function Jt(I,U){{if(typeof I!="object")return;if(lt(I))for(var le=0;le<I.length;le++){var Ce=I[le];Pn(Ce)&&kr(Ce,U)}else if(Pn(I))I._store&&(I._store.validated=!0);else if(I){var Ge=v(I);if(typeof Ge=="function"&&Ge!==I.entries)for(var $e=Ge.call(I),Fe;!(Fe=$e.next()).done;)Pn(Fe.value)&&kr(Fe.value,U)}}}function Tr(I){{var U=I.type;if(U==null||typeof U=="string")return;var le;if(typeof U=="function")le=U.propTypes;else if(typeof U=="object"&&(U.$$typeof===l||U.$$typeof===f))le=U.propTypes;else return;if(le){var Ce=P(U);Me(le,I.props,"prop",Ce,I)}else if(U.PropTypes!==void 0&&!Dt){Dt=!0;var Ge=P(U);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ge||"Unknown")}typeof U.getDefaultProps=="function"&&!U.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Mn(I){{for(var U=Object.keys(I.props),le=0;le<U.length;le++){var Ce=U[le];if(Ce!=="children"&&Ce!=="key"){sn(I),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ce),sn(null);break}}I.ref!==null&&(sn(I),w("Invalid attribute `ref` supplied to `React.Fragment`."),sn(null))}}var wn={};function Un(I,U,le,Ce,Ge,$e){{var Fe=D(I);if(!Fe){var z="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(z+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ue=pt();ue?z+=ue:z+=yn();var me;I===null?me="null":lt(I)?me="array":I!==void 0&&I.$$typeof===t?(me="<"+(P(I.type)||"Unknown")+" />",z=" Did you accidentally export a JSX literal instead of a component?"):me=typeof I,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",me,z)}var Re=rr(I,U,le,Ge,$e);if(Re==null)return Re;if(Fe){var rt=U.children;if(rt!==void 0)if(Ce)if(lt(rt)){for(var Lt=0;Lt<rt.length;Lt++)Jt(rt[Lt],I);Object.freeze&&Object.freeze(rt)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Jt(rt,I)}if(ot.call(U,"key")){var an=P(I),Ct=Object.keys(U).filter(function(
|
|
25
|
+
Check the top-level render call using <`+le+">.")}return U}}function kr(I,U){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var le=On(U);if(vn[le])return;vn[le]=!0;var Ce="";I&&I._owner&&I._owner!==Xt.current&&(Ce=" It was passed a child from "+P(I._owner.type)+"."),sn(I),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',le,Ce),sn(null)}}function Jt(I,U){{if(typeof I!="object")return;if(lt(I))for(var le=0;le<I.length;le++){var Ce=I[le];Pn(Ce)&&kr(Ce,U)}else if(Pn(I))I._store&&(I._store.validated=!0);else if(I){var Ge=v(I);if(typeof Ge=="function"&&Ge!==I.entries)for(var $e=Ge.call(I),Fe;!(Fe=$e.next()).done;)Pn(Fe.value)&&kr(Fe.value,U)}}}function Tr(I){{var U=I.type;if(U==null||typeof U=="string")return;var le;if(typeof U=="function")le=U.propTypes;else if(typeof U=="object"&&(U.$$typeof===l||U.$$typeof===f))le=U.propTypes;else return;if(le){var Ce=P(U);Me(le,I.props,"prop",Ce,I)}else if(U.PropTypes!==void 0&&!Dt){Dt=!0;var Ge=P(U);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ge||"Unknown")}typeof U.getDefaultProps=="function"&&!U.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Mn(I){{for(var U=Object.keys(I.props),le=0;le<U.length;le++){var Ce=U[le];if(Ce!=="children"&&Ce!=="key"){sn(I),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ce),sn(null);break}}I.ref!==null&&(sn(I),w("Invalid attribute `ref` supplied to `React.Fragment`."),sn(null))}}var wn={};function Un(I,U,le,Ce,Ge,$e){{var Fe=D(I);if(!Fe){var z="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(z+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ue=pt();ue?z+=ue:z+=yn();var me;I===null?me="null":lt(I)?me="array":I!==void 0&&I.$$typeof===t?(me="<"+(P(I.type)||"Unknown")+" />",z=" Did you accidentally export a JSX literal instead of a component?"):me=typeof I,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",me,z)}var Re=rr(I,U,le,Ge,$e);if(Re==null)return Re;if(Fe){var rt=U.children;if(rt!==void 0)if(Ce)if(lt(rt)){for(var Lt=0;Lt<rt.length;Lt++)Jt(rt[Lt],I);Object.freeze&&Object.freeze(rt)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Jt(rt,I)}if(ot.call(U,"key")){var an=P(I),Ct=Object.keys(U).filter(function(A){return A!=="key"}),_o=Ct.length>0?"{key: someKey, "+Ct.join(": ..., ")+": ...}":"{key: someKey}";if(!wn[an+_o]){var N=Ct.length>0?"{"+Ct.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
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} />`,_o,an,A,an),wn[an+_o]=!0}}return I===r?Mn(Re):Tr(Re),Re}}function Er(I,U,le){return Un(I,U,le,!0)}function Wr(I,U,le){return Un(I,U,le,!1)}var Vr=Wr,or=Er;qr.Fragment=r,qr.jsx=Vr,qr.jsxs=or}()),qr}process.env.NODE_ENV==="production"?xi.exports=Pm():xi.exports=Om();var d=xi.exports;function Ol(e,t){return function(){return e.apply(t,arguments)}}const{toString:Mm}=Object.prototype,{getPrototypeOf:yi}=Object,{iterator:Do,toStringTag:Ml}=Symbol,Lo=(e=>t=>{const n=Mm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),ln=e=>(e=e.toLowerCase(),t=>Lo(t)===e),Fo=e=>t=>typeof t===e,{isArray:Ir}=Array,Ar=Fo("undefined");function Gr(e){return e!==null&&!Ar(e)&&e.constructor!==null&&!Ar(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Dl=ln("ArrayBuffer");function Dm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Dl(e.buffer),t}const Lm=Fo("string"),zt=Fo("function"),Ll=Fo("number"),Yr=e=>e!==null&&typeof e=="object",Fm=e=>e===!0||e===!1,$o=e=>{if(Lo(e)!=="object")return!1;const t=yi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ml in e)&&!(Do in e)},$m=e=>{if(!Yr(e)||Gr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},zm=ln("Date"),Bm=ln("File"),Hm=ln("Blob"),Um=ln("FileList"),Wm=e=>Yr(e)&&zt(e.pipe),Vm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=Lo(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},Km=ln("URLSearchParams"),[qm,Gm,Ym,Xm]=["ReadableStream","Request","Response","Headers"].map(ln),Jm=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 Fl(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,$l=e=>!Ar(e)&&e!==ir;function vi(){const{caseless:e,skipUndefined:t}=$l(this)&&this||{},n={},r=(o,s)=>{const i=e&&Fl(n,s)||s;$o(n[i])&&$o(o)?n[i]=vi(n[i],o):$o(o)?n[i]=vi({},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 Zm=(e,t,n,{allOwnKeys:r}={})=>(Xr(t,(o,s)=>{n&&zt(o)?e[s]=Ol(o,n):e[s]=o},{allOwnKeys:r}),e),Qm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),eg=(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)},tg=(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&&yi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},ng=(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},rg=e=>{if(!e)return null;if(Ir(e))return e;let t=e.length;if(!Ll(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},og=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&yi(Uint8Array)),sg=(e,t)=>{const r=(e&&e[Do]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ag=ln("HTMLFormElement"),lg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),zl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),cg=ln("RegExp"),Bl=(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)},ug=e=>{Bl(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+"'")})}})},dg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Ir(e)?r(e):r(String(e).split(t)),n},fg=()=>{},hg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function pg(e){return!!(e&&zt(e.append)&&e[Ml]==="FormData"&&e[Do])}const mg=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)},gg=ln("AsyncFunction"),xg=e=>e&&(Yr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Hl=((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)),yg=typeof queueMicrotask<"u"?queueMicrotask.bind(ir):typeof process<"u"&&process.nextTick||Hl,O={isArray:Ir,isArrayBuffer:Dl,isBuffer:Gr,isFormData:Vm,isArrayBufferView:Dm,isString:Lm,isNumber:Ll,isBoolean:Fm,isObject:Yr,isPlainObject:$o,isEmptyObject:$m,isReadableStream:qm,isRequest:Gm,isResponse:Ym,isHeaders:Xm,isUndefined:Ar,isDate:zm,isFile:Bm,isBlob:Hm,isRegExp:cg,isFunction:zt,isStream:Wm,isURLSearchParams:Km,isTypedArray:og,isFileList:Um,forEach:Xr,merge:vi,extend:Zm,trim:Jm,stripBOM:Qm,inherits:eg,toFlatObject:tg,kindOf:Lo,kindOfTest:ln,endsWith:ng,toArray:rg,forEachEntry:sg,matchAll:ig,isHTMLForm:ag,hasOwnProperty:zl,hasOwnProp:zl,reduceDescriptors:Bl,freezeMethods:ug,toObjectSet:dg,toCamelCase:lg,noop:fg,toFiniteNumber:hg,findKey:Fl,global:ir,isContextDefined:$l,isSpecCompliantForm:pg,toJSONObject:mg,isAsyncFn:gg,isThenable:xg,setImmediate:Hl,asap:yg,isIterable:e=>e!=null&&zt(e[Do])};function _e(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(_e,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 Ul=_e.prototype,Wl={};["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=>{Wl[e]={value:e}}),Object.defineProperties(_e,Wl),Object.defineProperty(Ul,"isAxiosError",{value:!0}),_e.from=(e,t,n,r,o,s)=>{const i=Object.create(Ul);O.toFlatObject(e,i,function(u){return u!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return _e.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 vg=null;function wi(e){return O.isPlainObject(e)||O.isArray(e)}function Vl(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function Kl(e,t,n){return e?e.concat(t).map(function(o,s){return o=Vl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function wg(e){return O.isArray(e)&&!e.some(wi)}const bg=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function zo(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(x,v){return!O.isUndefined(v[x])});const r=n.metaTokens,o=n.visitor||u,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(m){if(m===null)return"";if(O.isDate(m))return m.toISOString();if(O.isBoolean(m))return m.toString();if(!l&&O.isBlob(m))throw new _e("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(m)||O.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function u(m,x,v){let g=m;if(m&&!v&&typeof m=="object"){if(O.endsWith(x,"{}"))x=r?x:x.slice(0,-2),m=JSON.stringify(m);else if(O.isArray(m)&&wg(m)||(O.isFileList(m)||O.endsWith(x,"[]"))&&(g=O.toArray(m)))return x=Vl(x),g.forEach(function(S,T){!(O.isUndefined(S)||S===null)&&t.append(i===!0?Kl([x],T,s):i===null?x:x+"[]",c(S))}),!1}return wi(m)?!0:(t.append(Kl(v,x,s),c(m)),!1)}const f=[],h=Object.assign(bg,{defaultVisitor:u,convertValue:c,isVisitable:wi});function p(m,x){if(!O.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(m),O.forEach(m,function(g,w){(!(O.isUndefined(g)||g===null)&&o.call(t,g,O.isString(w)?w.trim():w,x,h))===!0&&p(g,x?x.concat(w):[w])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return p(e),t}function ql(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function bi(e,t){this._pairs=[],e&&zo(e,this,t)}const Gl=bi.prototype;Gl.append=function(t,n){this._pairs.push([t,n])},Gl.toString=function(t){const n=t?function(r){return t.call(this,r,ql)}:ql;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Sg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Yl(e,t,n){if(!t)return e;const r=n&&n.encode||Sg;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 bi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Xl{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 Jl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Cg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:bi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Si=typeof window<"u"&&typeof document<"u",Ci=typeof navigator=="object"&&navigator||void 0,kg=Si&&(!Ci||["ReactNative","NativeScript","NS"].indexOf(Ci.product)<0),Tg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Eg=Si&&window.location.href||"http://localhost",Rt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Si,hasStandardBrowserEnv:kg,hasStandardBrowserWebWorkerEnv:Tg,navigator:Ci,origin:Eg},Symbol.toStringTag,{value:"Module"})),...Cg};function Ig(e,t){return zo(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 Ag(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ng(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 Zl(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]=Ng(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Ag(r),o,n,0)}),n}return null}function _g(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:Jl,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(Zl(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 Ig(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return zo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),_g(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"?_e.from(a,_e.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 jg=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"]),Rg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
30
|
+
<%s key={someKey} {...props} />`,_o,an,N,an),wn[an+_o]=!0}}return I===r?Mn(Re):Tr(Re),Re}}function Er(I,U,le){return Un(I,U,le,!0)}function Wr(I,U,le){return Un(I,U,le,!1)}var Vr=Wr,or=Er;qr.Fragment=r,qr.jsx=Vr,qr.jsxs=or}()),qr}process.env.NODE_ENV==="production"?xi.exports=Pm():xi.exports=Om();var d=xi.exports;function Ol(e,t){return function(){return e.apply(t,arguments)}}const{toString:Mm}=Object.prototype,{getPrototypeOf:yi}=Object,{iterator:Do,toStringTag:Ml}=Symbol,Lo=(e=>t=>{const n=Mm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),ln=e=>(e=e.toLowerCase(),t=>Lo(t)===e),Fo=e=>t=>typeof t===e,{isArray:Ir}=Array,Nr=Fo("undefined");function Gr(e){return e!==null&&!Nr(e)&&e.constructor!==null&&!Nr(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Dl=ln("ArrayBuffer");function Dm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Dl(e.buffer),t}const Lm=Fo("string"),zt=Fo("function"),Ll=Fo("number"),Yr=e=>e!==null&&typeof e=="object",Fm=e=>e===!0||e===!1,$o=e=>{if(Lo(e)!=="object")return!1;const t=yi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ml in e)&&!(Do in e)},$m=e=>{if(!Yr(e)||Gr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},zm=ln("Date"),Bm=ln("File"),Hm=ln("Blob"),Um=ln("FileList"),Wm=e=>Yr(e)&&zt(e.pipe),Vm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=Lo(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},Km=ln("URLSearchParams"),[qm,Gm,Ym,Xm]=["ReadableStream","Request","Response","Headers"].map(ln),Jm=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 Fl(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,$l=e=>!Nr(e)&&e!==ir;function vi(){const{caseless:e,skipUndefined:t}=$l(this)&&this||{},n={},r=(o,s)=>{const i=e&&Fl(n,s)||s;$o(n[i])&&$o(o)?n[i]=vi(n[i],o):$o(o)?n[i]=vi({},o):Ir(o)?n[i]=o.slice():(!t||!Nr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Xr(arguments[o],r);return n}const Zm=(e,t,n,{allOwnKeys:r}={})=>(Xr(t,(o,s)=>{n&&zt(o)?e[s]=Ol(o,n):e[s]=o},{allOwnKeys:r}),e),Qm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),eg=(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)},tg=(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&&yi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},ng=(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},rg=e=>{if(!e)return null;if(Ir(e))return e;let t=e.length;if(!Ll(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},og=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&yi(Uint8Array)),sg=(e,t)=>{const r=(e&&e[Do]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ag=ln("HTMLFormElement"),lg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),zl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),cg=ln("RegExp"),Bl=(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)},ug=e=>{Bl(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+"'")})}})},dg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Ir(e)?r(e):r(String(e).split(t)),n},fg=()=>{},hg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function pg(e){return!!(e&&zt(e.append)&&e[Ml]==="FormData"&&e[Do])}const mg=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);!Nr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},gg=ln("AsyncFunction"),xg=e=>e&&(Yr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Hl=((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)),yg=typeof queueMicrotask<"u"?queueMicrotask.bind(ir):typeof process<"u"&&process.nextTick||Hl,O={isArray:Ir,isArrayBuffer:Dl,isBuffer:Gr,isFormData:Vm,isArrayBufferView:Dm,isString:Lm,isNumber:Ll,isBoolean:Fm,isObject:Yr,isPlainObject:$o,isEmptyObject:$m,isReadableStream:qm,isRequest:Gm,isResponse:Ym,isHeaders:Xm,isUndefined:Nr,isDate:zm,isFile:Bm,isBlob:Hm,isRegExp:cg,isFunction:zt,isStream:Wm,isURLSearchParams:Km,isTypedArray:og,isFileList:Um,forEach:Xr,merge:vi,extend:Zm,trim:Jm,stripBOM:Qm,inherits:eg,toFlatObject:tg,kindOf:Lo,kindOfTest:ln,endsWith:ng,toArray:rg,forEachEntry:sg,matchAll:ig,isHTMLForm:ag,hasOwnProperty:zl,hasOwnProp:zl,reduceDescriptors:Bl,freezeMethods:ug,toObjectSet:dg,toCamelCase:lg,noop:fg,toFiniteNumber:hg,findKey:Fl,global:ir,isContextDefined:$l,isSpecCompliantForm:pg,toJSONObject:mg,isAsyncFn:gg,isThenable:xg,setImmediate:Hl,asap:yg,isIterable:e=>e!=null&&zt(e[Do])};function _e(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(_e,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 Ul=_e.prototype,Wl={};["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=>{Wl[e]={value:e}}),Object.defineProperties(_e,Wl),Object.defineProperty(Ul,"isAxiosError",{value:!0}),_e.from=(e,t,n,r,o,s)=>{const i=Object.create(Ul);O.toFlatObject(e,i,function(u){return u!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return _e.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 vg=null;function wi(e){return O.isPlainObject(e)||O.isArray(e)}function Vl(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function Kl(e,t,n){return e?e.concat(t).map(function(o,s){return o=Vl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function wg(e){return O.isArray(e)&&!e.some(wi)}const bg=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function zo(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(x,v){return!O.isUndefined(v[x])});const r=n.metaTokens,o=n.visitor||u,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(m){if(m===null)return"";if(O.isDate(m))return m.toISOString();if(O.isBoolean(m))return m.toString();if(!l&&O.isBlob(m))throw new _e("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(m)||O.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function u(m,x,v){let g=m;if(m&&!v&&typeof m=="object"){if(O.endsWith(x,"{}"))x=r?x:x.slice(0,-2),m=JSON.stringify(m);else if(O.isArray(m)&&wg(m)||(O.isFileList(m)||O.endsWith(x,"[]"))&&(g=O.toArray(m)))return x=Vl(x),g.forEach(function(S,T){!(O.isUndefined(S)||S===null)&&t.append(i===!0?Kl([x],T,s):i===null?x:x+"[]",c(S))}),!1}return wi(m)?!0:(t.append(Kl(v,x,s),c(m)),!1)}const f=[],h=Object.assign(bg,{defaultVisitor:u,convertValue:c,isVisitable:wi});function p(m,x){if(!O.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(m),O.forEach(m,function(g,w){(!(O.isUndefined(g)||g===null)&&o.call(t,g,O.isString(w)?w.trim():w,x,h))===!0&&p(g,x?x.concat(w):[w])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return p(e),t}function ql(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function bi(e,t){this._pairs=[],e&&zo(e,this,t)}const Gl=bi.prototype;Gl.append=function(t,n){this._pairs.push([t,n])},Gl.toString=function(t){const n=t?function(r){return t.call(this,r,ql)}:ql;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Sg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Yl(e,t,n){if(!t)return e;const r=n&&n.encode||Sg;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 bi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Xl{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 Jl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Cg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:bi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Si=typeof window<"u"&&typeof document<"u",Ci=typeof navigator=="object"&&navigator||void 0,kg=Si&&(!Ci||["ReactNative","NativeScript","NS"].indexOf(Ci.product)<0),Tg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Eg=Si&&window.location.href||"http://localhost",Rt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Si,hasStandardBrowserEnv:kg,hasStandardBrowserWebWorkerEnv:Tg,navigator:Ci,origin:Eg},Symbol.toStringTag,{value:"Module"})),...Cg};function Ig(e,t){return zo(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 Ng(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ag(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 Zl(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]=Ag(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Ng(r),o,n,0)}),n}return null}function _g(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:Jl,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(Zl(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 Ig(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return zo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),_g(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"?_e.from(a,_e.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 jg=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"]),Rg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
31
|
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&jg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Ql=Symbol("internals");function Zr(e){return e&&String(e).trim().toLowerCase()}function Bo(e){return e===!1||e==null?e:O.isArray(e)?e.map(Bo):String(e)}function Pg(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 Og=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ki(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 Mg(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Dg(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 u=Zr(l);if(!u)throw new Error("header name must be a non-empty string");const f=O.findKey(o,u);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=Bo(a))}const i=(a,l)=>O.forEach(a,(c,u)=>s(c,u,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!Og(t))i(Rg(t),n);else if(O.isObject(t)&&O.isIterable(t)){let a={},l,c;for(const u of t){if(!O.isArray(u))throw TypeError("Object iterator must return a key-value pair");a[c=u[0]]=(l=a[c])?O.isArray(l)?[...l,u[1]]:[l,u[1]]:u[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 Pg(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||ki(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||ki(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||ki(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]=Bo(o),delete n[s];return}const a=t?Mg(s):String(s).trim();a!==s&&delete n[s],n[a]=Bo(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[Ql]=this[Ql]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Zr(i);r[a]||(Dg(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 Ti(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 ec(e){return!!(e&&e.__CANCEL__)}function Nr(e,t,n){_e.call(this,e??"canceled",_e.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(Nr,_e,{__CANCEL__:!0});function tc(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new _e("Request failed with status code "+n.status,[_e.ERR_BAD_REQUEST,_e.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Lg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Fg(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(),u=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=u&&c-u;return p?Math.round(h*1e3/p):void 0}}function $g(e,t){let n=0,r=1e3/t,o,s;const i=(c,u=Date.now())=>{n=u,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const u=Date.now(),f=u-n;f>=r?i(c,u):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ho=(e,t,n=3)=>{let r=0;const o=Fg(50,250);return $g(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),u=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&&u?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},nc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},rc=e=>(...t)=>O.asap(()=>e(...t)),zg=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,Bg=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 Hg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ug(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function oc(e,t,n){let r=!Hg(t);return e&&(r||n==!1)?Ug(e,t):t}const sc=e=>e instanceof Bt?{...e}:e;function ar(e,t){t=t||{};const n={};function r(c,u,f,h){return O.isPlainObject(c)&&O.isPlainObject(u)?O.merge.call({caseless:h},c,u):O.isPlainObject(u)?O.merge({},u):O.isArray(u)?u.slice():u}function o(c,u,f,h){if(O.isUndefined(u)){if(!O.isUndefined(c))return r(void 0,c,f,h)}else return r(c,u,f,h)}function s(c,u){if(!O.isUndefined(u))return r(void 0,u)}function i(c,u){if(O.isUndefined(u)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,u)}function a(c,u,f){if(f in t)return r(c,u);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,u,f)=>o(sc(c),sc(u),f,!0)};return O.forEach(Object.keys({...e,...t}),function(u){const f=l[u]||o,h=f(e[u],t[u],u);O.isUndefined(h)&&f!==a||(n[u]=h)}),n}const ic=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=Yl(oc(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(([u,f])=>{c.includes(u.toLowerCase())&&i.set(u,f)})}}if(Rt.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&zg(t.url))){const l=o&&s&&Bg.read(s);l&&i.set(o,l)}return t},Wg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=ic(e);let s=o.data;const i=Bt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,u,f,h,p,m;function x(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(u),o.signal&&o.signal.removeEventListener("abort",u)}let v=new XMLHttpRequest;v.open(o.method.toUpperCase(),o.url,!0),v.timeout=o.timeout;function g(){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};tc(function(E){n(E),x()},function(E){r(E),x()},k),v=null}"onloadend"in v?v.onloadend=g:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(g)},v.onabort=function(){v&&(r(new _e("Request aborted",_e.ECONNABORTED,e,v)),v=null)},v.onerror=function(T){const k=T&&T.message?T.message:"Network Error",C=new _e(k,_e.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||Jl;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new _e(T,k.clarifyTimeoutError?_e.ETIMEDOUT:_e.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,m]=Ho(c,!0),v.addEventListener("progress",h)),l&&v.upload&&([f,p]=Ho(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(u=S=>{v&&(r(!S||S.type?new Nr(null,e,v):S),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(u),o.signal&&(o.signal.aborted?u():o.signal.addEventListener("abort",u)));const w=Lg(o.url);if(w&&Rt.protocols.indexOf(w)===-1){r(new _e("Unsupported protocol "+w+":",_e.ERR_BAD_REQUEST,e));return}v.send(s||null)})},Vg=(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 u=c instanceof Error?c:this.reason;r.abort(u instanceof _e?u:new Nr(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,s(new _e(`timeout ${t} of ms exceeded`,_e.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}},Kg=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},qg=async function*(e,t){for await(const n of Gg(e))yield*Kg(n,t)},Gg=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()}},ac=(e,t,n,r)=>{const o=qg(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:u}=await o.next();if(c){a(),l.close();return}let f=u.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(u))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},lc=64*1024,{isFunction:Uo}=O,Yg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:cc,TextEncoder:uc}=O.global,dc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Xg=e=>{e=O.merge.call({skipUndefined:!0},Yg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Uo(t):typeof fetch=="function",s=Uo(n),i=Uo(r);if(!o)return!1;const a=o&&Uo(cc),l=o&&(typeof uc=="function"?(m=>x=>m.encode(x))(new uc):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&dc(()=>{let m=!1;const x=new n(Rt.origin,{body:new cc,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!x}),u=i&&a&&dc(()=>O.isReadableStream(new r("").body)),f={stream:u&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(x,v)=>{let g=x&&x[m];if(g)return g.call(x);throw new _e(`Response type '${m}' is not supported`,_e.ERR_NOT_SUPPORT,v)})});const h=async m=>{if(m==null)return 0;if(O.isBlob(m))return m.size;if(O.isSpecCompliantForm(m))return(await new n(Rt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(O.isArrayBufferView(m)||O.isArrayBuffer(m))return m.byteLength;if(O.isURLSearchParams(m)&&(m=m+""),O.isString(m))return(await l(m)).byteLength},p=async(m,x)=>{const v=O.toFiniteNumber(m.getContentLength());return v??h(x)};return async m=>{let{url:x,method:v,data:g,signal:w,cancelToken:S,timeout:T,onDownloadProgress:k,onUploadProgress:C,responseType:E,headers:_,withCredentials:j="same-origin",fetchOptions:D}=ic(m),$=t||fetch;E=E?(E+"").toLowerCase():"text";let q=Vg([w,S&&S.toAbortSignal()],T),P=null;const R=q&&q.unsubscribe&&(()=>{q.unsubscribe()});let L;try{if(C&&c&&v!=="get"&&v!=="head"&&(L=await p(_,g))!==0){let W=new n(x,{method:"POST",body:g,duplex:"half"}),ce;if(O.isFormData(g)&&(ce=W.headers.get("content-type"))&&_.setContentType(ce),W.body){const[H,Z]=nc(L,Ho(rc(C)));g=ac(W.body,lc,H,Z)}}O.isString(j)||(j=j?"include":"omit");const F=s&&"credentials"in n.prototype,ne={...D,signal:q,method:v.toUpperCase(),headers:_.normalize().toJSON(),body:g,duplex:"half",credentials:F?j:void 0};P=s&&new n(x,ne);let K=await(s?$(P,D):$(x,ne));const B=u&&(E==="stream"||E==="response");if(u&&(k||B&&R)){const W={};["status","statusText","headers"].forEach(we=>{W[we]=K[we]});const ce=O.toFiniteNumber(K.headers.get("content-length")),[H,Z]=k&&nc(ce,Ho(rc(k),!0))||[];K=new r(ac(K.body,lc,H,()=>{Z&&Z(),R&&R()}),W)}E=E||"text";let pe=await f[O.findKey(f,E)||"text"](K,m);return!B&&R&&R(),await new Promise((W,ce)=>{tc(W,ce,{data:pe,headers:Bt.from(K.headers),status:K.status,statusText:K.statusText,config:m,request:P})})}catch(F){throw R&&R(),F&&F.name==="TypeError"&&/Load failed|fetch/i.test(F.message)?Object.assign(new _e("Network Error",_e.ERR_NETWORK,m,P),{cause:F.cause||F}):_e.from(F,F&&F.code,m,P)}}},Jg=new Map,fc=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,u=Jg;for(;a--;)l=s[a],c=u.get(l),c===void 0&&u.set(l,c=a?new Map:Xg(t)),u=c;return c};fc();const Ei={http:vg,xhr:Wg,fetch:{get:fc}};O.forEach(Ei,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const hc=e=>`- ${e}`,Zg=e=>O.isFunction(e)||e===null||e===!1,pc={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,!Zg(r)&&(o=Ei[(a=String(r)).toLowerCase()],o===void 0))throw new _e(`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 :
|
|
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[Ql]=this[Ql]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Zr(i);r[a]||(Dg(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 Ti(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 ec(e){return!!(e&&e.__CANCEL__)}function Ar(e,t,n){_e.call(this,e??"canceled",_e.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(Ar,_e,{__CANCEL__:!0});function tc(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new _e("Request failed with status code "+n.status,[_e.ERR_BAD_REQUEST,_e.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Lg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Fg(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(),u=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=u&&c-u;return p?Math.round(h*1e3/p):void 0}}function $g(e,t){let n=0,r=1e3/t,o,s;const i=(c,u=Date.now())=>{n=u,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const u=Date.now(),f=u-n;f>=r?i(c,u):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ho=(e,t,n=3)=>{let r=0;const o=Fg(50,250);return $g(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),u=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&&u?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},nc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},rc=e=>(...t)=>O.asap(()=>e(...t)),zg=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,Bg=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 Hg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ug(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function oc(e,t,n){let r=!Hg(t);return e&&(r||n==!1)?Ug(e,t):t}const sc=e=>e instanceof Bt?{...e}:e;function ar(e,t){t=t||{};const n={};function r(c,u,f,h){return O.isPlainObject(c)&&O.isPlainObject(u)?O.merge.call({caseless:h},c,u):O.isPlainObject(u)?O.merge({},u):O.isArray(u)?u.slice():u}function o(c,u,f,h){if(O.isUndefined(u)){if(!O.isUndefined(c))return r(void 0,c,f,h)}else return r(c,u,f,h)}function s(c,u){if(!O.isUndefined(u))return r(void 0,u)}function i(c,u){if(O.isUndefined(u)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,u)}function a(c,u,f){if(f in t)return r(c,u);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,u,f)=>o(sc(c),sc(u),f,!0)};return O.forEach(Object.keys({...e,...t}),function(u){const f=l[u]||o,h=f(e[u],t[u],u);O.isUndefined(h)&&f!==a||(n[u]=h)}),n}const ic=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=Yl(oc(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(([u,f])=>{c.includes(u.toLowerCase())&&i.set(u,f)})}}if(Rt.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&zg(t.url))){const l=o&&s&&Bg.read(s);l&&i.set(o,l)}return t},Wg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=ic(e);let s=o.data;const i=Bt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,u,f,h,p,m;function x(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(u),o.signal&&o.signal.removeEventListener("abort",u)}let v=new XMLHttpRequest;v.open(o.method.toUpperCase(),o.url,!0),v.timeout=o.timeout;function g(){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};tc(function(E){n(E),x()},function(E){r(E),x()},k),v=null}"onloadend"in v?v.onloadend=g:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(g)},v.onabort=function(){v&&(r(new _e("Request aborted",_e.ECONNABORTED,e,v)),v=null)},v.onerror=function(T){const k=T&&T.message?T.message:"Network Error",C=new _e(k,_e.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||Jl;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new _e(T,k.clarifyTimeoutError?_e.ETIMEDOUT:_e.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,m]=Ho(c,!0),v.addEventListener("progress",h)),l&&v.upload&&([f,p]=Ho(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(u=S=>{v&&(r(!S||S.type?new Ar(null,e,v):S),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(u),o.signal&&(o.signal.aborted?u():o.signal.addEventListener("abort",u)));const w=Lg(o.url);if(w&&Rt.protocols.indexOf(w)===-1){r(new _e("Unsupported protocol "+w+":",_e.ERR_BAD_REQUEST,e));return}v.send(s||null)})},Vg=(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 u=c instanceof Error?c:this.reason;r.abort(u instanceof _e?u:new Ar(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,s(new _e(`timeout ${t} of ms exceeded`,_e.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}},Kg=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},qg=async function*(e,t){for await(const n of Gg(e))yield*Kg(n,t)},Gg=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()}},ac=(e,t,n,r)=>{const o=qg(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:u}=await o.next();if(c){a(),l.close();return}let f=u.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(u))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},lc=64*1024,{isFunction:Uo}=O,Yg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:cc,TextEncoder:uc}=O.global,dc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Xg=e=>{e=O.merge.call({skipUndefined:!0},Yg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Uo(t):typeof fetch=="function",s=Uo(n),i=Uo(r);if(!o)return!1;const a=o&&Uo(cc),l=o&&(typeof uc=="function"?(m=>x=>m.encode(x))(new uc):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&dc(()=>{let m=!1;const x=new n(Rt.origin,{body:new cc,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!x}),u=i&&a&&dc(()=>O.isReadableStream(new r("").body)),f={stream:u&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(x,v)=>{let g=x&&x[m];if(g)return g.call(x);throw new _e(`Response type '${m}' is not supported`,_e.ERR_NOT_SUPPORT,v)})});const h=async m=>{if(m==null)return 0;if(O.isBlob(m))return m.size;if(O.isSpecCompliantForm(m))return(await new n(Rt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(O.isArrayBufferView(m)||O.isArrayBuffer(m))return m.byteLength;if(O.isURLSearchParams(m)&&(m=m+""),O.isString(m))return(await l(m)).byteLength},p=async(m,x)=>{const v=O.toFiniteNumber(m.getContentLength());return v??h(x)};return async m=>{let{url:x,method:v,data:g,signal:w,cancelToken:S,timeout:T,onDownloadProgress:k,onUploadProgress:C,responseType:E,headers:_,withCredentials:j="same-origin",fetchOptions:D}=ic(m),$=t||fetch;E=E?(E+"").toLowerCase():"text";let q=Vg([w,S&&S.toAbortSignal()],T),P=null;const R=q&&q.unsubscribe&&(()=>{q.unsubscribe()});let L;try{if(C&&c&&v!=="get"&&v!=="head"&&(L=await p(_,g))!==0){let W=new n(x,{method:"POST",body:g,duplex:"half"}),ce;if(O.isFormData(g)&&(ce=W.headers.get("content-type"))&&_.setContentType(ce),W.body){const[H,Z]=nc(L,Ho(rc(C)));g=ac(W.body,lc,H,Z)}}O.isString(j)||(j=j?"include":"omit");const F=s&&"credentials"in n.prototype,ne={...D,signal:q,method:v.toUpperCase(),headers:_.normalize().toJSON(),body:g,duplex:"half",credentials:F?j:void 0};P=s&&new n(x,ne);let K=await(s?$(P,D):$(x,ne));const B=u&&(E==="stream"||E==="response");if(u&&(k||B&&R)){const W={};["status","statusText","headers"].forEach(we=>{W[we]=K[we]});const ce=O.toFiniteNumber(K.headers.get("content-length")),[H,Z]=k&&nc(ce,Ho(rc(k),!0))||[];K=new r(ac(K.body,lc,H,()=>{Z&&Z(),R&&R()}),W)}E=E||"text";let pe=await f[O.findKey(f,E)||"text"](K,m);return!B&&R&&R(),await new Promise((W,ce)=>{tc(W,ce,{data:pe,headers:Bt.from(K.headers),status:K.status,statusText:K.statusText,config:m,request:P})})}catch(F){throw R&&R(),F&&F.name==="TypeError"&&/Load failed|fetch/i.test(F.message)?Object.assign(new _e("Network Error",_e.ERR_NETWORK,m,P),{cause:F.cause||F}):_e.from(F,F&&F.code,m,P)}}},Jg=new Map,fc=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,u=Jg;for(;a--;)l=s[a],c=u.get(l),c===void 0&&u.set(l,c=a?new Map:Xg(t)),u=c;return c};fc();const Ei={http:vg,xhr:Wg,fetch:{get:fc}};O.forEach(Ei,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const hc=e=>`- ${e}`,Zg=e=>O.isFunction(e)||e===null||e===!1,pc={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,!Zg(r)&&(o=Ei[(a=String(r)).toLowerCase()],o===void 0))throw new _e(`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(hc).join(`
|
|
34
|
-
`):" "+hc(i[0]):"as no adapter specified";throw new _e("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Ei};function Ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new
|
|
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&&Vo.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}:Vo.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),Vo.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"],m=>{delete s[m]}),n.headers=Bt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let u,f=0,h;if(!l){const m=[mc.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,u=Promise.resolve(n);f<h;)u=u.then(m[f++],m[f++]);return u}h=a.length;let p=n;for(;f<h;){const m=a[f++],x=a[f++];try{p=m(p)}catch(v){x.call(this,v);break}}try{u=mc.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)u=u.then(c[f++],c[f++]);return u}getUri(t){t=ar(this.defaults,t);const n=oc(t.baseURL,t.url,t.allowAbsoluteUrls);return Yl(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 ex=class _m{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 _m(function(o){t=o}),cancel:t}}};function tx(e){return function(n){return e.apply(null,n)}}function nx(e){return O.isObject(e)&&e.isAxiosError===!0}const Ai={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(Ai).forEach(([e,t])=>{Ai[t]=e});function yc(e){const t=new lr(e),n=Ol(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 yc(ar(e,o))},n}const mt=yc(Jr);mt.Axios=lr,mt.CanceledError=Nr,mt.CancelToken=ex,mt.isCancel=ec,mt.VERSION=gc,mt.toFormData=zo,mt.AxiosError=_e,mt.Cancel=mt.CanceledError,mt.all=function(t){return Promise.all(t)},mt.spread=tx,mt.isAxiosError=nx,mt.mergeConfig=ar,mt.AxiosHeaders=Bt,mt.formToJSON=e=>Zl(O.isHTMLForm(e)?new FormData(e):e),mt.getAdapter=pc.getAdapter,mt.HttpStatusCode=Ai,mt.default=mt;const{Axios:nT,AxiosError:rT,CanceledError:oT,isCancel:sT,CancelToken:iT,VERSION:aT,all:lT,Cancel:cT,isAxiosError:uT,spread:dT,toFormData:fT,AxiosHeaders:hT,HttpStatusCode:pT,formToJSON:mT,getAdapter:gT,mergeConfig:xT}=mt,vc=typeof window<"u"?window.__API_BASE_URL__:void 0,wc=vc?$n(vc):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 Ko=null;const Ni=new Set;function bc(){return Ko}function _i(e){Ko=e,Ni.forEach(t=>t(e))}function Sc(e){return Ni.add(e),()=>Ni.delete(e)}const Zt=mt.create({...wc?{baseURL:wc}:{},timeout:3e4,withCredentials:!0});Zt.interceptors.request.use(e=>(Ko&&(e.headers.Authorization=`Bearer ${Ko}`),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 ji(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 Cc(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 kc(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 Tc{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&&_i(t.authToken)}getAuthToken(){return bc()}setAuthToken(t){_i(t)}onTokenChange(t){return Sc(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 ji("/threads",t?{title:t}:void 0);return un(r)}async updateThread(t,n){const r=await Cc(`/threads/${t}`,{title:n});return un(r)}async deleteThread(t){const n=await kc(`/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 ji("/runs/cancel",{threadId:t});return un(n)}}const Wn=new Tc,Ec=b.createContext(null);function rx({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 d.jsx(Ec.Provider,{value:r,children:e})}function Ri(){const e=b.useContext(Ec);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function ox(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 sx(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await ox(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const ix={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Pi(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 Oi(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(!Pi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=lx(t),i=Ic(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Ic(e,t){if(!Pi(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)=>mx(j,D)).filter(j=>!!j),u=Ht(e.config),f=Ht(u==null?void 0:u.configurable),h=vt(f,["checkpoint_id","checkpointId"]),p=vt(f,["checkpoint_ns","checkpointNs"]),m=Ht(e==null?void 0:e.parentConfig),x=Ht(m==null?void 0:m.configurable),v=vt(x,["checkpoint_id","checkpointId"])??null,g=vt(x,["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=vt(k,["branch_label","branchLabel"]),E=vt(x,["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:g,interrupt:ax(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:u??null,parentConfig:m??null,next:_??null,tasks:l??null,values:i??null}}function ax(e,t,n){const r=hx(e,n);return r||fx(t,n)}function lx(e){const t=new Map;e.forEach((o,s)=>{if(!Pi(o))return;const i=Ic(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,cx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Nc(s.createdAt??"")-Nc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function cx(e,t){return{...e,metadata:qo(e.metadata,t.metadata)??null,config:qo(e.config,t.config)??null,parentConfig:qo(e.parentConfig,t.parentConfig)??null,next:ux(e.next,t.next)??null,tasks:dx(e.tasks,t.tasks)??null,values:qo(e.values,t.values)??null}}function qo(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 Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function dx(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 fx(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 hx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=px(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 px(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,u,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(u)?u:void 0,v=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:x,state:v!==void 0?v:f}}const n=Ht(e);if(!n)return null;const r=vt(n,["id","task_id","taskId"])??t,o=vt(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=Ac(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 Ac(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=vt(n,["type","event","kind"]),o=vt(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=Ac(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 Nc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function mx(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=ix[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),u=Ht(o.response_metadata)??Ht(o.responseMetadata),f=vt(c,["createdAt","created_at"])??vt(o,["created_at","createdAt"]),h=vt(c,["checkpointId","checkpoint_id"]),p=vt(c,["checkpointNs","checkpoint_ns"]),m=gx(o.content),x={id:l,role:i,content:m};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(u==null?void 0:u.model_name)=="string"&&(x.model=String(u.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const v=wx(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),g=u?{...u}:void 0;v&&Object.keys(v).length&&(x.additionalKwargs=v),g&&Object.keys(g).length&&(x.responseMetadata=g);const w=xx((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=yx(o,x.content);S&&(x.content=S)}return x}function gx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>_c(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=_c(e);return t?[t]:[]}return[]}function _c(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=vt(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=vt(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 jc(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=vt(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 jc(e,t){var s;const n=vt(e,["id","call_id"])??t,r=vt(e,["name"])??vt(Ht(e.function),["name"]);if(!n||!r)return null;const o=vx(e.args??e.arguments??((s=Ht(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function xx(e){return Array.isArray(e)?e.map((t,n)=>jc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function yx(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function vx(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 Ht(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function vt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function wx(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 bx(e){return e.type!=="thread_info"&&e.type!=="token"}const Sx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Cx(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:Mi(((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=Mi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Mi(t.payload.messages);if(!r.length)return 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 Pc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pc(o,s),e):e}case"interrupt_response":return{...e,messages:Oc(e.messages),pendingInterrupt:null};default:return e}}function Rc(e=[]){const[t,n]=b.useReducer(Cx,{...Sx,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 u=r.current;u.length&&(r.current=[],n({type:"batch",payload:{events:u}}))},[]),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(u=>{r.current.push(u),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:u=>n({type:"reset",payload:{messages:u}}),seed:(u,f)=>n({type:"seed",payload:{messages:u,...f??{}}}),prepend:u=>n({type:"prepend",payload:{messages:u}}),pushUser:u=>n({type:"user_message",payload:{message:u}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Pc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Ix(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const u={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,u]}}if(t.type==="message_delta"){const a=e.assemblingId??Mc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(T=>T.id===a&&T.role==="assistant");if(c===-1)return e;const u=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:Fc(u.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:m,newMeta:x,changed:v}=kx(u.content,t.delta,h,p);if(!v)return e;const g={...u,content:m},w=Go(l,c,g),S={...f,[a]:x};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Mc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(u=>u.id===a&&u.role==="assistant");if(c>=0){const u=l[c];if(!((n=u.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=u.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Dc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const u=a.length?a:l?[l]:[],f=Lc(e,u,c),h=f>=0?e.messages[f]:null,p=l??u[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,x=u[0]??p,v={type:"tool_call",id:x,name:c,args:t.args};if(h){const S=Li(h,u,c,t.args),T={...h,name:h.name??c,additionalKwargs:S},k=f,C=k>=0?Go(e.messages,k,T):e.messages,E=Yo(T,u),_=Fi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:_}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[v],additionalKwargs:Li(void 0,u.length?u:[x],c,t.args)},w=Yo(g,u.length?u:[x]);return{...e,messages:[...e.messages,g],toolIndex:Fi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=Dc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Lc(e,a,l),u=c>=0?e.messages[c]:null,f=l??(u==null?void 0:u.name)??((s=u==null?void 0:u.additionalKwargs)==null?void 0:s.toolName)??"tool",h=a[0]??((i=u==null?void 0:u.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(u==null?void 0:u.id)??`tool-${h}`,m=Yo(u,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const v={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},g=(u==null?void 0:u.createdAt)??new Date().toISOString(),w=Li(u??void 0,m.length?m:a,f),S={id:p,role:"tool",name:f??(u==null?void 0:u.name)??"tool",content:[v],createdAt:g,additionalKwargs:w},T=c>=0?Go(e.messages,c,S):[...e.messages,S],k=Yo(S,a.length?a:m);return{...e,messages:T,toolIndex:Fi(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Ex(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=Oi(t),l=a.interrupt,c=a.latest,u=l===null?Oc(e.messages):e.messages;return{...e,messages:u,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return e}function Mi(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 Go(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Oc(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 Mc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Dc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function Di(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function Li(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Di(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Yo(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Di(e);for(const o of r)n.add(o);return Array.from(n)}function Fi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function Lc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(Di(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function Fc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function kx(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??Fc(e);let l="",c=e.slice();if(s){const f=Tx(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??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const u=!!(l||i.length);return{newParts:c,newMeta:o,changed:u}}function $c(e){return e.replace(/\s+/g," ").trim()}function Tx(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 Ex(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 Go(e,r,s)}return e}function Ix(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function zc(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,u]=b.useState(null),[f,h]=b.useState(""),[p,m]=b.useState(null),[x,v]=b.useState(0),[g,w]=b.useState(!1),S=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),C=b.useRef(null),E=b.useCallback($=>{o($)},[]),_=b.useCallback(()=>{h(""),m(null),u(null)},[]),j=b.useCallback(()=>{var $;console.debug("[use-chat] stop() invoked - aborting stream"),($=S.current)==null||$.abort(),S.current=null,C.current=null,l(!1),w(!1),k.current=0,v(0)},[]),D=b.useCallback(($,q,P)=>{S.current&&(S.current.abort(),S.current=null),l(!0),u(null),e.autoAppendAssistant!==!1&&h("");const R=new AbortController;return S.current=R,C.current={threadId:$.threadId??null,headers:{}},(async()=>{var F,ne,K,B,pe,W,ce,H,Z;const L=we=>{var ye;try{const G=JSON.parse(JSON.stringify(we));return(ye=G==null?void 0:G.payload)!=null&&ye.files_info&&Array.isArray(G.payload.files_info)&&(G.payload.files_info=G.payload.files_info.map(M=>({...M,data:M!=null&&M.data?`<base64 ${String(M.data).length} chars>`:M==null?void 0:M.data}))),G}catch{return we}};try{let we={};try{if(r)we={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const lt=window.__AUTH_TOKEN__,xt=((F=window.localStorage)==null?void 0:F.getItem("authToken"))||null;let dt=null;try{const ie=(ne=window.localStorage)==null?void 0:ne.getItem("chat-settings");ie&&(dt=((K=JSON.parse(ie))==null?void 0:K.apiKey)||null)}catch{}const Je=lt||xt||dt||null;Je&&(we={Authorization:`Bearer ${Je}`})}}catch{}console.debug("[use-chat] POST",t+n,L($));let ye={};if(typeof window<"u")try{const We=(B=window.localStorage)==null?void 0:B.getItem("authSessionId");We&&(ye={"X-Session-Id":We})}catch{}const G={...we,...ye,...s.current},M={"Content-Type":"application/json",Accept:"text/event-stream",...G},X=await fetch(t+n,{method:"POST",headers:M,body:JSON.stringify($),signal:R.signal,credentials:i});if(C.current&&(C.current.headers=G),!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 oe=X.body.getReader(),xe=new TextDecoder;let se="",re=[];k.current=0,v(0);let Ue=0,Ke=null;const ot=()=>{if(re.length){const We=re.join("");re=[],T.current&&h(lt=>lt+We)}Ke=null},at=()=>{typeof window<"u"&&Ke==null&&(Ke=requestAnimationFrame(ot))};let ht=Date.now();const tt=setInterval(()=>{var We;if(Date.now()-ht>6e4){const lt="Stream idle timeout";u(lt),R.abort(),(We=P==null?void 0:P.onError)==null||We.call(P,lt)}},5e3),Me=1024*1024;try{const We=X.headers.get("X-Thread-Id")||X.headers.get("x-thread-id"),lt=X.headers.get("X-Thread-Created")||X.headers.get("x-thread-created"),xt=We??null,dt=String(lt??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:xt}),(pe=P==null?void 0:P.onOpen)==null||pe.call(P,{threadId:xt,created:dt});;){const{value:Je,done:ie}=await oe.read();if(ie)break;se+=xe.decode(Je,{stream:!0}),se.length>Me&&(se="",console.warn("Stream buffer reset: exceeded 1MB"));let je;for(;(je=se.indexOf(`
|
|
34
|
+
`):" "+hc(i[0]):"as no adapter specified";throw new _e("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Ei};function Ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ar(null,e)}function mc(e){return Ii(e),e.headers=Bt.from(e.headers),e.data=Ti.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),pc.getAdapter(e.adapter||Jr.adapter,e)(e).then(function(r){return Ii(e),r.data=Ti.call(e,e.transformResponse,r),r.headers=Bt.from(r.headers),r},function(r){return ec(r)||(Ii(e),r&&r.response&&(r.response.data=Ti.call(e,e.transformResponse,r.response),r.response.headers=Bt.from(r.response.headers))),Promise.reject(r)})}const gc="1.12.2",Wo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Wo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const xc={};Wo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+gc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new _e(o(i," has been removed"+(n?" in "+n:"")),_e.ERR_DEPRECATED);return n&&!xc[i]&&(xc[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}},Wo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Qg(e,t,n){if(typeof e!="object")throw new _e("options must be an object",_e.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 _e("option "+s+" must be "+l,_e.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new _e("Unknown option "+s,_e.ERR_BAD_OPTION)}}const Vo={assertOptions:Qg,validators:Wo},bn=Vo.validators;let lr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Xl,response:new Xl}}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&&Vo.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}:Vo.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),Vo.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"],m=>{delete s[m]}),n.headers=Bt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let u,f=0,h;if(!l){const m=[mc.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,u=Promise.resolve(n);f<h;)u=u.then(m[f++],m[f++]);return u}h=a.length;let p=n;for(;f<h;){const m=a[f++],x=a[f++];try{p=m(p)}catch(v){x.call(this,v);break}}try{u=mc.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)u=u.then(c[f++],c[f++]);return u}getUri(t){t=ar(this.defaults,t);const n=oc(t.baseURL,t.url,t.allowAbsoluteUrls);return Yl(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 ex=class _m{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 Ar(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 _m(function(o){t=o}),cancel:t}}};function tx(e){return function(n){return e.apply(null,n)}}function nx(e){return O.isObject(e)&&e.isAxiosError===!0}const Ni={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ni).forEach(([e,t])=>{Ni[t]=e});function yc(e){const t=new lr(e),n=Ol(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 yc(ar(e,o))},n}const mt=yc(Jr);mt.Axios=lr,mt.CanceledError=Ar,mt.CancelToken=ex,mt.isCancel=ec,mt.VERSION=gc,mt.toFormData=zo,mt.AxiosError=_e,mt.Cancel=mt.CanceledError,mt.all=function(t){return Promise.all(t)},mt.spread=tx,mt.isAxiosError=nx,mt.mergeConfig=ar,mt.AxiosHeaders=Bt,mt.formToJSON=e=>Zl(O.isHTMLForm(e)?new FormData(e):e),mt.getAdapter=pc.getAdapter,mt.HttpStatusCode=Ni,mt.default=mt;const{Axios:nT,AxiosError:rT,CanceledError:oT,isCancel:sT,CancelToken:iT,VERSION:aT,all:lT,Cancel:cT,isAxiosError:uT,spread:dT,toFormData:fT,AxiosHeaders:hT,HttpStatusCode:pT,formToJSON:mT,getAdapter:gT,mergeConfig:xT}=mt,vc=typeof window<"u"?window.__API_BASE_URL__:void 0,wc=vc?$n(vc):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 Ko=null;const Ai=new Set;function bc(){return Ko}function _i(e){Ko=e,Ai.forEach(t=>t(e))}function Sc(e){return Ai.add(e),()=>Ai.delete(e)}const Zt=mt.create({...wc?{baseURL:wc}:{},timeout:3e4,withCredentials:!0});Zt.interceptors.request.use(e=>(Ko&&(e.headers.Authorization=`Bearer ${Ko}`),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 ji(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 Cc(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 kc(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 Tc{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&&_i(t.authToken)}getAuthToken(){return bc()}setAuthToken(t){_i(t)}onTokenChange(t){return Sc(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 ji("/threads",t?{title:t}:void 0);return un(r)}async updateThread(t,n){const r=await Cc(`/threads/${t}`,{title:n});return un(r)}async deleteThread(t){const n=await kc(`/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 ji("/runs/cancel",{threadId:t});return un(n)}}const Wn=new Tc,Ec=b.createContext(null);function rx({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 d.jsx(Ec.Provider,{value:r,children:e})}function Ri(){const e=b.useContext(Ec);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function ox(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 sx(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await ox(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const ix={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Pi(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 Oi(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(!Pi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=lx(t),i=Ic(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Ic(e,t){if(!Pi(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)=>mx(j,D)).filter(j=>!!j),u=Ht(e.config),f=Ht(u==null?void 0:u.configurable),h=vt(f,["checkpoint_id","checkpointId"]),p=vt(f,["checkpoint_ns","checkpointNs"]),m=Ht(e==null?void 0:e.parentConfig),x=Ht(m==null?void 0:m.configurable),v=vt(x,["checkpoint_id","checkpointId"])??null,g=vt(x,["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=vt(k,["branch_label","branchLabel"]),E=vt(x,["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:g,interrupt:ax(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:u??null,parentConfig:m??null,next:_??null,tasks:l??null,values:i??null}}function ax(e,t,n){const r=hx(e,n);return r||fx(t,n)}function lx(e){const t=new Map;e.forEach((o,s)=>{if(!Pi(o))return;const i=Ic(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,cx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Ac(s.createdAt??"")-Ac(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function cx(e,t){return{...e,metadata:qo(e.metadata,t.metadata)??null,config:qo(e.config,t.config)??null,parentConfig:qo(e.parentConfig,t.parentConfig)??null,next:ux(e.next,t.next)??null,tasks:dx(e.tasks,t.tasks)??null,values:qo(e.values,t.values)??null}}function qo(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 Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function dx(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 fx(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 hx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=px(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 px(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,u,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(u)?u:void 0,v=h.length?h[h.length-1]:void 0;return{id:p,name:m,interrupts:x,state:v!==void 0?v:f}}const n=Ht(e);if(!n)return null;const r=vt(n,["id","task_id","taskId"])??t,o=vt(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=Nc(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 Nc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=vt(n,["type","event","kind"]),o=vt(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=Nc(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 Ac(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function mx(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=ix[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),u=Ht(o.response_metadata)??Ht(o.responseMetadata),f=vt(c,["createdAt","created_at"])??vt(o,["created_at","createdAt"]),h=vt(c,["checkpointId","checkpoint_id"]),p=vt(c,["checkpointNs","checkpoint_ns"]),m=gx(o.content),x={id:l,role:i,content:m};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(u==null?void 0:u.model_name)=="string"&&(x.model=String(u.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const v=wx(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),g=u?{...u}:void 0;v&&Object.keys(v).length&&(x.additionalKwargs=v),g&&Object.keys(g).length&&(x.responseMetadata=g);const w=xx((c==null?void 0:c.tool_calls)??o.tool_calls);if(w.length&&(x.content=[...x.content,...w]),i==="tool"){const S=yx(o,x.content);S&&(x.content=S)}return x}function gx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>_c(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=_c(e);return t?[t]:[]}return[]}function _c(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=vt(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=vt(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 jc(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=vt(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 jc(e,t){var s;const n=vt(e,["id","call_id"])??t,r=vt(e,["name"])??vt(Ht(e.function),["name"]);if(!n||!r)return null;const o=vx(e.args??e.arguments??((s=Ht(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function xx(e){return Array.isArray(e)?e.map((t,n)=>jc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function yx(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function vx(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 Ht(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function vt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function wx(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 bx(e){return e.type!=="thread_info"&&e.type!=="token"}const Sx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Cx(e,t){var n;switch(t.type){case"reset":return{messages:Mi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Mi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Mi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}: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 Pc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Pc(o,s),e):e}case"interrupt_response":return{...e,messages:Oc(e.messages),pendingInterrupt:null};default:return e}}function Rc(e=[]){const[t,n]=b.useReducer(Cx,{...Sx,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 u=r.current;u.length&&(r.current=[],n({type:"batch",payload:{events:u}}))},[]),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(u=>{r.current.push(u),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:u=>n({type:"reset",payload:{messages:u}}),seed:(u,f)=>n({type:"seed",payload:{messages:u,...f??{}}}),prepend:u=>n({type:"prepend",payload:{messages:u}}),pushUser:u=>n({type:"user_message",payload:{message:u}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Pc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Ix(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}const u={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,u]}}if(t.type==="message_delta"){const a=e.assemblingId??Mc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(T=>T.id===a&&T.role==="assistant");if(c===-1)return e;const u=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:Fc(u.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:m,newMeta:x,changed:v}=kx(u.content,t.delta,h,p);if(!v)return e;const g={...u,content:m},w=Go(l,c,g),S={...f,[a]:x};return{...e,messages:w,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Mc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(u=>u.id===a&&u.role==="assistant");if(c>=0){const u=l[c];if(!((n=u.content)==null?void 0:n.some(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=u.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Dc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const u=a.length?a:l?[l]:[],f=Lc(e,u,c),h=f>=0?e.messages[f]:null,p=l??u[0]??`${c}-${Date.now()}`,m=(h==null?void 0:h.id)??`tool-${p}`,x=u[0]??p,v={type:"tool_call",id:x,name:c,args:t.args};if(h){const S=Li(h,u,c,t.args),T={...h,name:h.name??c,additionalKwargs:S},k=f,C=k>=0?Go(e.messages,k,T):e.messages,E=Yo(T,u),_=Fi(e.toolIndex,m,E);return{...e,messages:C,toolIndex:_}}const g={id:m,role:"tool",name:c,createdAt:new Date().toISOString(),content:[v],additionalKwargs:Li(void 0,u.length?u:[x],c,t.args)},w=Yo(g,u.length?u:[x]);return{...e,messages:[...e.messages,g],toolIndex:Fi(e.toolIndex,m,w)}}if(t.type==="tool_end"){const a=Dc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Lc(e,a,l),u=c>=0?e.messages[c]:null,f=l??(u==null?void 0:u.name)??((s=u==null?void 0:u.additionalKwargs)==null?void 0:s.toolName)??"tool",h=a[0]??((i=u==null?void 0:u.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(u==null?void 0:u.id)??`tool-${h}`,m=Yo(u,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const v={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},g=(u==null?void 0:u.createdAt)??new Date().toISOString(),w=Li(u??void 0,m.length?m:a,f),S={id:p,role:"tool",name:f??(u==null?void 0:u.name)??"tool",content:[v],createdAt:g,additionalKwargs:w},T=c>=0?Go(e.messages,c,S):[...e.messages,S],k=Yo(S,a.length?a:m);return{...e,messages:T,toolIndex:Fi(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Ex(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=Oi(t),l=a.interrupt,c=a.latest,u=l===null?Oc(e.messages):e.messages;return{...e,messages:u,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return e}function Mi(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 Go(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Oc(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 Mc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Dc(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function Di(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function Li(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Di(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Yo(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Di(e);for(const o of r)n.add(o);return Array.from(n)}function Fi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function Lc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(Di(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function Fc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function kx(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??Fc(e);let l="",c=e.slice();if(s){const f=Tx(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??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const u=!!(l||i.length);return{newParts:c,newMeta:o,changed:u}}function $c(e){return e.replace(/\s+/g," ").trim()}function Tx(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 Ex(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 Go(e,r,s)}return e}function Ix(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function zc(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,u]=b.useState(null),[f,h]=b.useState(""),[p,m]=b.useState(null),[x,v]=b.useState(0),[g,w]=b.useState(!1),S=b.useRef(null),T=b.useRef(!0),k=b.useRef(0),C=b.useRef(null),E=b.useCallback($=>{o($)},[]),_=b.useCallback(()=>{h(""),m(null),u(null)},[]),j=b.useCallback(()=>{var $;console.debug("[use-chat] stop() invoked - aborting stream"),($=S.current)==null||$.abort(),S.current=null,C.current=null,l(!1),w(!1),k.current=0,v(0)},[]),D=b.useCallback(($,q,P)=>{S.current&&(S.current.abort(),S.current=null),l(!0),u(null),e.autoAppendAssistant!==!1&&h("");const R=new AbortController;return S.current=R,C.current={threadId:$.threadId??null,headers:{}},(async()=>{var F,ne,K,B,pe,W,ce,H,Z;const L=we=>{var ye;try{const G=JSON.parse(JSON.stringify(we));return(ye=G==null?void 0:G.payload)!=null&&ye.files_info&&Array.isArray(G.payload.files_info)&&(G.payload.files_info=G.payload.files_info.map(M=>({...M,data:M!=null&&M.data?`<base64 ${String(M.data).length} chars>`:M==null?void 0:M.data}))),G}catch{return we}};try{let we={};try{if(r)we={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const lt=window.__AUTH_TOKEN__,xt=((F=window.localStorage)==null?void 0:F.getItem("authToken"))||null;let dt=null;try{const ie=(ne=window.localStorage)==null?void 0:ne.getItem("chat-settings");ie&&(dt=((K=JSON.parse(ie))==null?void 0:K.apiKey)||null)}catch{}const Je=lt||xt||dt||null;Je&&(we={Authorization:`Bearer ${Je}`})}}catch{}console.debug("[use-chat] POST",t+n,L($));let ye={};if(typeof window<"u")try{const We=(B=window.localStorage)==null?void 0:B.getItem("authSessionId");We&&(ye={"X-Session-Id":We})}catch{}const G={...we,...ye,...s.current},M={"Content-Type":"application/json",Accept:"text/event-stream",...G},X=await fetch(t+n,{method:"POST",headers:M,body:JSON.stringify($),signal:R.signal,credentials:i});if(C.current&&(C.current.headers=G),!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 oe=X.body.getReader(),xe=new TextDecoder;let se="",re=[];k.current=0,v(0);let Ue=0,Ke=null;const ot=()=>{if(re.length){const We=re.join("");re=[],T.current&&h(lt=>lt+We)}Ke=null},at=()=>{typeof window<"u"&&Ke==null&&(Ke=requestAnimationFrame(ot))};let ht=Date.now();const tt=setInterval(()=>{var We;if(Date.now()-ht>6e4){const lt="Stream idle timeout";u(lt),R.abort(),(We=P==null?void 0:P.onError)==null||We.call(P,lt)}},5e3),Me=1024*1024;try{const We=X.headers.get("X-Thread-Id")||X.headers.get("x-thread-id"),lt=X.headers.get("X-Thread-Created")||X.headers.get("x-thread-created"),xt=We??null,dt=String(lt??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:xt}),(pe=P==null?void 0:P.onOpen)==null||pe.call(P,{threadId:xt,created:dt});;){const{value:Je,done:ie}=await oe.read();if(ie)break;se+=xe.decode(Je,{stream:!0}),se.length>Me&&(se="",console.warn("Stream buffer reset: exceeded 1MB"));let je;for(;(je=se.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const ke=se.slice(0,je);se=se.slice(je+2);const qe=
|
|
38
|
-
`)}function _x({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=b.useRef(null),i=b.useCallback(p=>{const m=p.seq??null;if(m!==null){const x=s.current;if(x!==null){if(m<=x)return;m>x+1&&(o==null||o({from:x,to:m}))}s.current=m}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p);try{t(p)}catch(x){console.error("[useChatStreamingService] Error in onThreadInfo handler:",x)}return}if(bx(p)){try{n(p)}catch(x){console.error("[useChatStreamingService] Error in onMessageEvent handler:",x)}return}try{r==null||r(p)}catch(x){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",x)}},[n,o,t,r]),{stream:a,stop:l,isStreaming:c,error:u,setToken:f}=zc({baseUrl:e,token:null}),h=b.useCallback((p,m)=>{s.current=null,a(p,i,{onOpen:m==null?void 0:m.onOpen,onError:x=>{var v;(v=m==null?void 0:m.onError)==null||v.call(m,x)},onGap:(m==null?void 0:m.onGap)??o})},[i,o,a]);return b.useMemo(()=>({startStream:h,stop:l,isStreaming:c,error:u,setAuthToken:f}),[h,l,c,u,f])}function $i(e){return e==null?e:{...e}}function jx(e){return e==null?e:{...e}}function Rx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function Px(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=$i(e==null?void 0:e.metadata),s=$i(e==null?void 0:e.config),i=$i(e==null?void 0:e.parentConfig),a=Rx(e==null?void 0:e.next),l=Px(e==null?void 0:e.tasks),c=jx(e==null?void 0:e.values),u={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&&(u.metadata=o),s!==void 0&&(u.config=s),i!==void 0&&(u.parentConfig=i),a!==void 0&&(u.next=a),l!==void 0&&(u.tasks=l),c!==void 0&&(u.values=c),u}function Ox(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 Bc(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 Xo=300;function Hc(e,t=Xo){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 zi(e){if(!cr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Bi(e,t){if(!cr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Hi(e){if(cr())try{window.localStorage.removeItem(e)}catch{}}const Mx="cachedThreads",Dx="v1",Ui=200;function Lx(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 Wi(e,t){return`cachedThreads:v1:${e}:${Lx(t||"anon")}`}function Fx(){const e=zi(Mx);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 $x(e){const t=zi(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 Vi(e,t){Bi(e,JSON.stringify(t))}function Ki(e){const t=$x(e);if(t.length>0)return t;const n=Fx();if(n.length>0)try{Vi(e,n.slice(0,Ui))}catch{}return n}function Jo(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 qi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Gi(e,t){return`${e}${t}`}function zx(e,t){const n=zi(Gi(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 Bx(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=Gi(e,t.threadId),i=JSON.stringify(o);if(!Bi(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 u=window.localStorage.getItem(c);if(!u){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(u),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),Bi(s,i))break}catch{}}function Hx(e,t){Hi(Gi(e,t))}function Ux(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 Uc=b.createContext(null),Wc=b.createContext(null),Vc=b.createContext(null),Wx=b.createContext(!1),Kc=50,Vx=750;function qc(e,t,n){return`${e}__${t??""}__${n??""}`}function Zo(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 Kx(e,t){return Zo(e,t)}function qx(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 Gx(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 Gc(e,t){const n=Zo(e.metadata,t.metadata),r=Zo(e.config,t.config),o=Zo(e.parentConfig,t.parentConfig),s=qx(e.next,t.next),i=Gx(e.tasks,t.tasks),a=Kx(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 Yx({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}=Ri(),u=b.useMemo(()=>$n(c),[c]),f=b.useMemo(()=>{try{return new URL(c).host}catch{return"unknown"}},[c]),h=b.useMemo(()=>`threadPayload:${Dx}:${f}:`,[f]),p=b.useCallback(A=>zx(h,A),[h]),m=b.useCallback((A,N=100)=>{Bx(h,A,N)},[h]),x=b.useCallback(A=>{Hx(h,A)},[h]),v=b.useCallback(()=>{Ux(h)},[h]),[g,w]=b.useState(()=>{var A;return Wi(f,(A=l.getAuthToken)==null?void 0:A.call(l))}),[S,T]=b.useState(()=>{var N;const A=Ki(Wi(f,(N=l.getAuthToken)==null?void 0:N.call(l)));return Jo(A)}),k=b.useMemo(()=>qi(S),[S]),[C,E]=b.useState(t),[_,j]=b.useState(!1),[D,$]=b.useState(!1),[q,P]=b.useState(null),[R,L]=b.useState(null),[F,ne]=b.useState(null),[K,B]=b.useState([]),pe=b.useCallback(()=>{const A=Ki(g);b.startTransition(()=>{T(Jo(A))})},[g]),[W,ce]=b.useState(!1),[H,Z]=b.useState(!1),[we,ye]=b.useState(null),[G,M]=b.useState(void 0),[X,oe]=b.useState(void 0),[xe,se]=b.useState(void 0),{state:re,dispatch:Ue,seed:Ke,prepend:ot,pushUser:at,onEvent:ht,reset:tt}=Rc(),Me=b.useRef(C);b.useEffect(()=>{Me.current=C},[C]);const We=b.useRef(!1),lt=b.useRef([]),xt=b.useRef(null),dt=b.useRef(null),Je=b.useRef(new Map),ie=b.useRef(C),je=b.useRef(!1),ke=b.useRef(null),qe=b.useRef(new Map),nt=b.useRef(new Map),Oe=b.useRef(new Map),Xe=b.useRef(new Map),Tt=b.useCallback(A=>{if(!A){B([]);return}const N=qe.current.get(A);if(!N||!N.length){B([]);return}B(N.map(Y=>Qt(Y,{cloneMessages:!0})))},[]);b.useEffect(()=>{Tt(C)},[C,Tt]);const St=b.useCallback(()=>{var te;const A=Xe.current;if(A.size<=Kc)return;const N=Array.from(A.entries()).sort((ae,Q)=>ae[1].timestamp-Q[1].timestamp),Y=A.size-Kc;for(let ae=0;ae<Y;ae++){const Q=(te=N[ae])==null?void 0:te[0];Q&&A.delete(Q)}},[]),Yt=b.useCallback((A,N,Y)=>{if(!A)return;const te=Y==="replace"?[]:qe.current.get(A)??[],ae=Y==="replace"?N:[...N,...te];if(!ae.length){Y==="replace"&&qe.current.set(A,[]);return}const Q=new Map;for(const Be of ae){if(!(Be!=null&&Be.checkpointId))continue;const De=`${Be.checkpointId}::${Be.checkpointNs??""}`,et=Qt(Be,{cloneMessages:!0}),yt=Q.get(De);if(!yt){Q.set(De,et);continue}const Nt=Gc(yt,et);Q.set(De,{...yt,...Nt})}const ze=Array.from(Q.values()).sort((Be,De)=>{const et=Number.isFinite(Date.parse(Be.createdAt??""))?Date.parse(Be.createdAt??""):0;return(Number.isFinite(Date.parse(De.createdAt??""))?Date.parse(De.createdAt??""):0)-et});qe.current.set(A,ze),A===Me.current&&Tt(A)},[Tt]),Et=b.useCallback((A,N,Y)=>{if(!A)return;const te=nt.current.get(A),ae=Y==="replace"||!te?new Map:new Map(te);if(N&&typeof N=="object")for(const[Q,ze]of Object.entries(N)){if(!(ze!=null&&ze.checkpointId))continue;const Be=Q||Qr(ze.checkpointId,ze.checkpointNs??null);ae.set(Be,Qt(ze,{cloneMessages:!0}))}nt.current.set(A,ae)},[]),rr=b.useCallback((A,N)=>{const{threadId:Y,checkpointId:te=null,checkpointNs:ae=null}=A,Q=qc(Y,te,ae);if(N!=null&&N.force)Oe.current.delete(Q),Xe.current.delete(Q);else{if(N!=null&&N.preferCache){const et=Xe.current.get(Q);if(et)return Promise.resolve(et.payload)}const De=Oe.current.get(Q);if(De)return De}const Be=l.getStateHistory({threadId:Y,checkpointId:te??void 0,checkpointNs:ae??void 0}).then(De=>(Xe.current.set(Q,{payload:De,timestamp:Date.now()}),St(),De)).finally(()=>{Oe.current.get(Q)===Be&&Oe.current.delete(Q)});return Oe.current.set(Q,Be),Be},[l,St]),Xt=b.useCallback((A,N)=>new Promise((Y,te)=>{const ae=async()=>{We.current=!0;try{await A(),Y()}catch(Q){te(Q)}finally{We.current=!1;const Q=lt.current.shift();Q&&Q().catch(()=>{})}};We.current?lt.current.push(ae):ae().catch(Q=>{te(Q)})}),[]),xn=b.useRef(k.length),sn=b.useRef(!1);b.useEffect(()=>{xn.current=k.length},[k.length]),b.useEffect(()=>{const A=re.pendingInterrupt??Ox(re.messages);Bc(F,A)||ne(A??null)},[F,re.messages,re.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 te=ze=>ze.map(Be=>`${Be.threadId}:${Be.updatedAt??""}:${Be.messageCount??""}`).join("|"),ae=qi(Y);return te(ae)===te(N)||N.length===0&&ae.length>0&&!sn.current?Y:Jo(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),pt=b.useRef(null),vn=b.useRef(""),On=b.useCallback((A,N)=>{if(!cr())return;pt.current!==null&&(window.clearTimeout(pt.current),pt.current=null);const Y=A.map(ae=>`${ae.threadId}:${ae.updatedAt??""}:${ae.messageCount??""}`).join("|");if(A.length===0){try{Hi(g)}catch{}vn.current="";return}if(Y===vn.current)return;const te=()=>{try{const ae=A.slice(0,Ui);Vi(g,ae),vn.current=Y}catch{}finally{pt.current=null}};if(N!=null&&N.immediate){te();return}pt.current=window.setTimeout(()=>{Hc(te)},Xo)},[g]),kr=b.useCallback(()=>{On(k,{immediate:!0})},[On,k]),Jt=b.useCallback((A,N,Y,te)=>{var Am;const ae=Y??Me.current;if(!ae)return;const Q=Qt(A),ze=ae===Me.current,Be=(te==null?void 0:te.persist)!==!1;if(N==="replace"){if(Be){const It={threadId:ae,snapshot:Qt(A,{cloneMessages:!0})};Je.current.set(ae,It),ie.current=ae}if(!ze)return;Ke(Q.messages,{checkpointId:Q.checkpointId??null,checkpointNs:Q.checkpointNs??null,pendingInterrupt:Q.interrupt??null}),ne(Q.interrupt??null),ye(Q.nextCursor??null),ce(!!Q.nextCursor),M(Q.checkpointId??void 0),oe(Q.checkpointNs??void 0),se(Q.nextCursorNs??void 0);return}const De=Je.current.get(ae),et=(De==null?void 0:De.snapshot)??null,yt=Array.isArray(et==null?void 0:et.messages)?et.messages:[],Nt=Qt(et),Dn=Array.isArray(A==null?void 0:A.messages)?A.messages:[],_t=new Set,jt=[...Dn,...yt].filter(It=>{const _l=It==null?void 0:It.id;return _l?_t.has(_l)?!1:(_t.add(_l),!0):!0}),jo=Gc(Nt,Q),Ro={checkpointId:Nt.checkpointId??Q.checkpointId??null,checkpointNs:Nt.checkpointNs??Q.checkpointNs??null,createdAt:Q.createdAt??Nt.createdAt??null,parentId:Q.parentId??Nt.parentId??null,branchLabel:Q.branchLabel??Nt.branchLabel??null,lastMessageId:((Am=jt[jt.length-1])==null?void 0:Am.id)??null,messagesLen:jt.length,hasMessages:jt.length>0,messages:jt,nextCursor:Q.nextCursor??Nt.nextCursor??null,nextCursorNs:Q.nextCursorNs??Nt.nextCursorNs??null,interrupt:Nt.interrupt??Q.interrupt??null,...jo};if(Je.current.set(ae,{threadId:ae,snapshot:Qt(Ro,{cloneMessages:!0})}),!ze)return;Dn.length&&ot(Dn);const Ln=A&&Object.prototype.hasOwnProperty.call(A,"checkpointId")?A.checkpointId:void 0,Po=A&&Object.prototype.hasOwnProperty.call(A,"checkpointNs")?A.checkpointNs:void 0,Fn=A&&Object.prototype.hasOwnProperty.call(A,"nextCursor")?A.nextCursor:void 0,Nl=A&&Object.prototype.hasOwnProperty.call(A,"nextCursorNs")?A.nextCursorNs:void 0;ye(It=>Fn!==void 0?Fn??It??null:It??null),ce(It=>Fn!==void 0?!!Fn:It),M(It=>Ln!==void 0?Ln??It??void 0:It??void 0),oe(It=>Po!==void 0?Po??It??void 0:It??void 0),se(It=>Nl!==void 0?Nl??void 0:It)},[ot,Ke,ne]),Tr=b.useCallback(A=>{if(A.threadId!=null&&A.threadId!==Me.current)return;const N=Qt(A.snapshot,{cloneMessages:!0});Ke(N.messages,{checkpointId:N.checkpointId??null,checkpointNs:N.checkpointNs??null,pendingInterrupt:N.interrupt??null}),ne(N.interrupt??null),ye(N.nextCursor??null),ce(!!N.nextCursor),M(N.checkpointId??void 0),oe(N.checkpointNs??void 0),se(N.nextCursorNs??void 0),ie.current=A.threadId,Tt(A.threadId??Me.current??null)},[Ke,ne,Tt]),Mn=b.useCallback(A=>{if(!A)return;Je.current.delete(A),x(A),qe.current.delete(A),nt.current.delete(A),A===Me.current&&B([]);const N=`${A}__`;for(const Y of Oe.current.keys())Y.startsWith(N)&&Oe.current.delete(Y);for(const Y of Xe.current.keys())Y.startsWith(N)&&Xe.current.delete(Y);ie.current===A&&(ie.current=null)},[x]),wn=b.useCallback(()=>{const A=Me.current;A&&Mn(A),tt([]),ce(!1),Z(!1),ye(null),M(void 0),oe(void 0),se(void 0)},[Mn,tt]),Un=b.useCallback(({from:A,to:N})=>{const Y=Me.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};Me.current!==N&&(!Me.current&&re.messages.length<=1&&(dt.current=N),E(N)),b.startTransition(()=>{T(te=>{const ae=te.byId[N];return ae?ae.title===Y.title&&ae.updatedAt===Y.updatedAt&&ae.messageCount===Y.messageCount?te:{byId:{...te.byId,[N]:Y},order:te.order}:{byId:{...te.byId,[N]:Y},order:[N,...te.order]}})})},[re.messages.length]),{startStream:Wr,stop:Vr,isStreaming:or,error:I,setAuthToken:U}=_x({baseUrl:u,onThreadInfo:Er,onMessageEvent:ht,onUnhandledEvent:A=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${A.type}`,A)},onSequenceGap:Un});b.useEffect(()=>{Pn.current=or},[or]),b.useEffect(()=>{if(!cr())return;pt.current!==null&&(window.clearTimeout(pt.current),pt.current=null);const A=k.map(Y=>`${Y.threadId}:${Y.updatedAt??""}:${Y.messageCount??""}`).join("|");if(k.length===0){try{Hi(g)}catch{}vn.current="";return}if(A===vn.current)return;const N=()=>{try{const Y=k.slice(0,Ui);Vi(g,Y),vn.current=A}catch{}finally{pt.current=null}};return pt.current=window.setTimeout(()=>{Hc(N),pt.current=null},Xo),()=>{pt.current!==null&&(window.clearTimeout(pt.current),pt.current=null)}},[k,On]),b.useEffect(()=>{var te;const A=l.getAuthToken();U(A);const N=ae=>{const Q=Wi(f,ae);ke.current!==Q&&(ke.current=Q,je.current=!1),w(Q);const ze=Ki(Q);b.startTransition(()=>{T(Jo(ze))}),ae&&!je.current&&(je.current=!0)};N(A);const Y=(te=l.onTokenChange)==null?void 0:te.call(l,ae=>{ae!==A&&(U(ae),v(),Oe.current.clear(),Xe.current.clear(),N(ae))});return()=>{Y==null||Y()}},[l,f,U,v]);const le=b.useCallback(async A=>{var te;const N=`Thread ${(te=crypto.randomUUID)==null?void 0:te.call(crypto)}`,Y={threadId:N,title:A||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};T(ae=>({byId:{...ae.byId,[N]:Y},order:[N,...ae.order]})),E(N);try{const ae=await l.createThread(A),Q=typeof ae=="string"?ae:ae.threadId;return T(ze=>{const Be=ze.byId[N];if(!Be)return ze;const De={...ze.byId};delete De[N],De[Q]={...Be,threadId:Q};const et=ze.order.map(yt=>yt===N?Q:yt);return{byId:De,order:et}}),E(Q),setTimeout(()=>Dt(),10),P(null),Q}catch(ae){throw T(Q=>{if(!Q.byId[N])return Q;const ze={...Q.byId};delete ze[N];const Be=Q.order.filter(De=>De!==N);return{byId:ze,order:Be}}),E(null),P(String(ae)),ae}},[l,Dt]),Ce=b.useCallback(async A=>{try{await l.deleteThread(A);let N=null;T(Y=>{if(!Y.byId[A])return Y;const te={...Y.byId};delete te[A];const ae=Y.order.filter(ze=>ze!==A),Q={byId:te,order:ae};return N=qi(Q),Q}),N&&On(N,{immediate:!0}),Mn(A),Me.current===A&&(dt.current=A,E(null),Me.current=null,ie.current=null,wn()),await Dt(),P(null)}catch(N){throw P(String(N)),N}},[l,wn,Mn,Dt,On]),Ge=b.useCallback(async(A,N)=>{try{await l.updateThread(A,N),T(Y=>{const te=Y.byId[A];return te?{byId:{...Y.byId,[A]:{...te,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,te=!1)=>{await Xt(async()=>{if(dt.current===A&&!te){dt.current=null;return}if(xt.current===A&&!te)return;E(_t=>_t===A?_t:A),Me.current=A;const ze=qc(A,N??null,Y??null),Be=Xe.current.get(ze),De=!te&&!N&&!Y&&Be&&Date.now()-Be.timestamp<Vx,et=!te&&!N&&!Y;let yt=!1;if(et){const _t=Je.current.get(A);if(_t)Tr(_t),yt=!0;else{const jt=p(A);jt&&(Je.current.set(A,jt),Tr(jt),yt=!0)}}const Nt=te||!yt||!!N||!!Y,Dn=async _t=>{_t&&$(!0),xt.current=A;try{const jt=await rr({threadId:A,checkpointId:N,checkpointNs:Y},{force:te}),{latest:jo,checkpoints:Ro,snapshots:Ln}=Oi(jt);Jt(jo,"replace",A),Yt(A,Ro,"replace"),Et(A,Ln,"replace"),L(null)}catch(jt){throw(!yt||te||_t)&&(i==null||i(String(jt))),L(String(jt)),jt}finally{xt.current=null,_t&&$(!1)}};Nt?await Dn(!0):et&&yt&&!De&&Dn(!1).catch(_t=>{console.warn("[ChatSessionProvider] Background refresh failed:",_t)})},`loadThread-${A}`)},[Tr,Jt,Xt,rr,i,Yt,Et]),Fe=b.useCallback(async()=>{await Xt(async()=>{const A=Me.current;A&&Mn(A),dt.current=null,E(null),Me.current=null,ie.current=null,wn(),M(void 0),oe(void 0),se(void 0),B([]);try{localStorage.removeItem("lastThreadId")}catch(N){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",N)}},"clearCurrentThread")},[wn,Mn,Xt]),z=b.useCallback(async(A,N)=>{var Q;const Y=Me.current;if(!Y)throw new Error("No active thread");const te=Qr(A,N??null),ae=(Q=nt.current.get(Y))==null?void 0:Q.get(te);if(ae){await Xt(async()=>{Jt(ae,"replace",Y,{persist:!1})},`navigateToCheckpoint-${Y}-${te}`);return}await $e(Y,A,N??void 0,!0)},[Jt,Xt,$e]),ue=b.useCallback(async()=>{if(!Me.current)throw new Error("No active thread");await $e(Me.current,void 0,void 0,!0)},[$e]),me=b.useCallback(async()=>{if(!Me.current)throw new Error("No active thread");if(H||!W)return;const A=we;if(A){Z(!0);try{const N=Me.current,Y=await rr({threadId:N,checkpointId:A??G??null,checkpointNs:xe??X??null}),{latest:te,checkpoints:ae,snapshots:Q}=Oi(Y),ze=N?nt.current.get(N):null;let Be=ae.length>0;if(Be&&ze&&ze.size>0&&(Be=ae.some(De=>{if(!(De!=null&&De.checkpointId))return!1;const et=Qr(De.checkpointId,De.checkpointNs??null);return!ze.has(et)})),!Be){ye(null),se(void 0),ce(!1),L(null);return}Jt(te,"prepend",N??void 0),N&&(Yt(N,ae,"prepend"),Et(N,Q,"prepend")),L(null)}catch(N){throw L(String(N)),N}finally{Z(!1)}}},[Jt,rr,W,G,X,xe,we,H,Yt,Et]),Re=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]),rt=b.useCallback(async(A,N)=>{var Po;const Y=Me.current,te=(A==null?void 0:A.text)??"",ae=(A==null?void 0:A.attachments)??[],Q=ae.length?ae:(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&&Q.length===0&&!te.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:De}=await sx(l,Q),et=[...Be];te&&te.trim()&&et.push({type:"text",text:te.trim()});const yt=!!Y,Nt=yt?(N==null?void 0:N.checkpointId)??re.lastCheckpointId??void 0:void 0,Dn=yt?(N==null?void 0:N.checkpointNs)??re.lastCheckpointNs??void 0:void 0,_t={id:((Po=crypto.randomUUID)==null?void 0:Po.call(crypto))||`user-${Date.now()}`,role:"user",content:et,createdAt:new Date().toISOString(),...Nt!=null?{checkpointId:Nt}:{},...Dn!=null?{checkpointNs:Dn}:{}};et.length>0&&at(_t);const jt={..._t,content:et},jo=Q.length>0,Ro={messages:et.length>0?[jt]:[],files_info:De,...o&&jo&&s?{active_agent:s}:{},...ze},Ln={threadId:Y??null,payload:Ro,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})=>{!Me.current&&Fn&&(re.messages.length<=1&&(dt.current=Fn),E(Fn))},onGap:Un})},[l,o,s,Un,re.lastCheckpointId,re.lastCheckpointNs,re.messages.length,at,Wr]),Lt=b.useCallback(async(A,N,Y)=>{if(!Me.current)throw new Error("No active thread to handle interrupt");const ae=N?Y??!0:!1;try{try{Ue({type:"interrupt_response",payload:{interruptId:A}})}catch(Q){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Q)}await rt({payload:{}},{checkpointId:re.lastCheckpointId??void 0,checkpointNs:re.lastCheckpointNs??void 0,command:{kind:"resume",value:ae}}),ne(null)}catch(Q){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${A}:`,Q),Q}},[Ue,re.lastCheckpointId,re.lastCheckpointNs,rt]);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=Me.current;if(!A||ie.current!==A)return;re.messages.length&&re.messages[re.messages.length-1];const N=Qt({checkpointId:re.lastCheckpointId??null,checkpointNs:re.lastCheckpointNs??null,messages:re.messages.slice(),nextCursor:we??null,nextCursorNs:xe??null,interrupt:re.pendingInterrupt??F??null}),Y=Je.current.get(A),te=Y==null?void 0:Y.snapshot,ae=!te||te.messages.length!==N.messages.length||te.messages.some((De,et)=>{var yt;return(De==null?void 0:De.id)!==((yt=N.messages[et])==null?void 0:yt.id)}),Q=((te==null?void 0:te.checkpointId)??null)!==N.checkpointId||((te==null?void 0:te.checkpointNs)??null)!==N.checkpointNs,ze=((te==null?void 0:te.nextCursor)??null)!==N.nextCursor||((te==null?void 0:te.nextCursorNs)??null)!==N.nextCursorNs,Be=!Bc((te==null?void 0:te.interrupt)??null,N.interrupt??null);if(ae||Q||ze||Be){const De={threadId:A,snapshot:N};Je.current.set(A,De),yn.current&&window.clearTimeout(yn.current),yn.current=window.setTimeout(()=>{try{m(De,100)}catch(et){console.warn("[ChatSessionProvider] Failed to persist thread payload:",et)}},Xo)}},[we,xe,re.lastCheckpointId,re.lastCheckpointNs,re.messages,re.pendingInterrupt,F,m]);const an=b.useMemo(()=>({threads:k,currentThreadId:C,setCurrentThreadId:E,isLoading:_,error:q,actions:{createThread:le,deleteThread:Ce,renameThread:Ge,refreshThreads:()=>Dt()},persistThreadsCache:kr,hydrateFromCache:pe}),[k,C,_,q,le,Ce,Ge,Dt,kr,pe,E]),Ct=b.useMemo(()=>{const A=re.lastBranch??null,N=re.assemblingId??null,Y=A||N?{branchLabel:(A==null?void 0:A.branchLabel)??null,lastBranch:A,assemblingMessageId:N}:null;return{threadId:C,messages:re.messages,interrupt:F,checkpoint:{id:re.lastCheckpointId??null,namespace:re.lastCheckpointNs??null},checkpoints:K,metadata:Y,isLoading:D,isHistoryLoading:H,error:R,hasMore:W,loadOlder:me,seedFromSnapshot:Re,clearState:wn,navigateToCheckpoint:z,returnToLatest:ue,loadThread:$e,clearThread:Fe,respondToInterrupt:Lt}},[Fe,wn,C,F,W,H,D,me,$e,re.assemblingId,re.lastBranch,re.lastCheckpointId,re.lastCheckpointNs,re.messages,z,Lt,ue,Re,R,K]),_o=b.useMemo(()=>({isStreaming:or,error:I,submit:rt,send:rt,stop:Vr,setAuthToken:U}),[or,I,rt,Vr,U]);return d.jsx(Wx.Provider,{value:!0,children:d.jsx(Vc.Provider,{value:_o,children:d.jsx(Uc.Provider,{value:an,children:d.jsx(Wc.Provider,{value:Ct,children:e})})})})}function Qo(){const e=b.useContext(Uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function es(){const e=b.useContext(Wc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Yc(){const e=b.useContext(Vc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function ts({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 d.jsx(rx,{apiConfig:t,children:d.jsx(Yx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function ee(...e){return Rm.twMerge(jm.clsx(e))}const Xx=Oo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ze=y.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?sr.Slot:"button";return d.jsx(i,{className:ee(Xx({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";const Xc=y.forwardRef(({className:e,...t},n)=>d.jsx("textarea",{className:ee("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}));Xc.displayName="Textarea";function Jx({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:u,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const m=i!==void 0,[x,v]=b.useState(e),g=(m?i:x)??"",[w,S]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(v(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const L=T.current;L&&(L.style.height="auto",L.style.height=`${L.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const _=b.useCallback((L,{fromUser:F})=>{m||v(L),F&&(a==null||a(L))},[m,a]),j=b.useCallback(async L=>{L&&L.preventDefault();const F=(g??"").trim();if(!F&&!p)return;const ne=++k.current;C.current={id:ne,shouldClear:!0},S(()=>{var K,B,pe;try{const W=l(F);W&&typeof W.then=="function"?W.then(()=>{var ce,H;((ce=C.current)==null?void 0:ce.id)===ne&&C.current.shouldClear&&(m||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((H=C.current)==null?void 0:H.id)===ne&&(C.current=null)}).catch(()=>{var ce;((ce=C.current)==null?void 0:ce.id)===ne&&(C.current=null)}):(((K=C.current)==null?void 0:K.id)===ne&&C.current.shouldClear&&(m||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((B=C.current)==null?void 0:B.id)===ne&&(C.current=null))}catch{((pe=C.current)==null?void 0:pe.id)===ne&&(C.current=null)}})},[g,l,p,m,a]),D=b.useCallback(L=>{const F=L.target.value;_(F,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[_]),$=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 d.jsx("form",{onSubmit:L=>void j(L),className:`w-full ${f}`,children:d.jsxs("div",{className:"flex items-end gap-2",children:[d.jsx("div",{className:"flex-1",children:d.jsx(Xc,{ref:T,value:g,onChange:D,onKeyDown:$,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),d.jsx("div",{children:r?d.jsx(Ze,{type:"button",onClick:()=>{u==null||u()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!u,children:d.jsx(fe.Square,{size:16})}):d.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!p||w,children:d.jsx(fe.Send,{size:16})})})]})})}const Zx=b.memo(Jx),ns=0,Vn=1,_r=2,Jc=4;function Zc(e){return()=>e}function Qx(e){e()}function Qc(e,t){return n=>e(t(n))}function eu(e,t){return()=>e(t)}function ey(e,t){return n=>e(t,n)}function Yi(e){return e!==void 0}function ty(...e){return()=>{e.map(Qx)}}function jr(){}function rs(e,t){return t(e),e}function ny(e,t){return t(e)}function ct(...e){return e}function Qe(e,t){return e(Vn,t)}function Pe(e,t){e(ns,t)}function Xi(e){e(_r)}function gt(e){return e(Jc)}function ve(e,t){return Qe(e,ey(t,ns))}function dn(e,t){const n=e(Vn,r=>{n(),t(r)});return n}function tu(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function nu(e,t){return e===t}function ut(e=nu){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ee(e){return t=>n=>{e(n)&&t(n)}}function de(e){return t=>Qc(t,e)}function Sn(e){return t=>()=>{t(e)}}function V(e,...t){const n=ry(...t);return(r,o)=>{switch(r){case _r:Xi(e);return;case Vn:return Qe(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 Le(...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);Qe(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 ry(...e){return t=>e.reduceRight(ny,t)}function oy(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=Qe(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 ns:t=o;break;case Vn:{o(t);break}case Jc:return t}return n(r,o)}}function Pt(e,t){return rs(J(t),n=>ve(e,n))}function Ve(){const e=[];return(t,n)=>{switch(t){case ns: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 rs(Ve(),t=>ve(e,t))}function Ye(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:sy(),singleton:n}}const sy=()=>Symbol();function iy(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 wt(...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);Qe(s,l=>{n[i]=l,r=r|a,r===o&&Pe(t,n)})}),function(s,i){switch(s){case _r:{Xi(t);return}case Vn:return r===o&&i(n),Qe(t,i)}}}function Te(e,t=nu){return V(e,ut(t))}function Ji(...e){return function(t,n){switch(t){case _r:return;case Vn:return ty(...e.map(r=>Qe(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 ay={0:"debug",3:"error",1:"log",2:"warn"},ly=()=>typeof globalThis>"u"?window:globalThis,Kn=Ye(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=ly().VIRTUOSO_LOG_LEVEL)!=null?o:gt(e);r>=s&&console[ay[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 Zi(e,t,n).callbackRef}function Zi(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 cy(e,t,n,r,o,s,i,a,l){const c=b.useCallback(u=>{const f=uy(u.children,t,a?"offsetWidth":"offsetHeight",o);let h=u.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let m;p&&(m=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(x,0),viewportHeight:g}),s==null||s(a?ru("column-gap",getComputedStyle(u).columnGap,o):ru("row-gap",getComputedStyle(u).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Zi(c,n,l)}function uy(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),u=t(a,n);if(u===0&&r("Zero-sized element, this should not happen",{child:a},Ut.ERROR),u===c)continue;const f=s[s.length-1];s.length===0||f.size!==u||f.endIndex!==l-1?s.push({endIndex:l,size:u,startIndex:l}):s[s.length-1].endIndex++}return s}function ru(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 ou(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),u=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+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:u},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Zi(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=Ye(()=>{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),u=J(0),f=Ve(),h=Ve(),p=J(!1),m=J(!1),x=J(!1);return ve(V(e,de(({scrollTop:v})=>v)),t),ve(V(e,de(({scrollHeight:v})=>v)),i),ve(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:u,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),to={lvl:0};function su(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 st(e){return e===to}function no(e,t){if(!st(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(st(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 st(e)?lu(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?cu(bt(e,{l:Vt(e.l,t,n)})):cu(bt(e,{r:Vt(e.r,t,n)}))}function Rr(){return to}function os(e,t,n){if(st(e))return[];const r=fn(e,t)[0];return dy(ea(e,r,n))}function Qi(e,t){if(st(e))return to;const{k:n,l:r,r:o}=e;if(t===n){if(st(r))return o;if(st(o))return r;{const[s,i]=au(r);return ss(bt(e,{k:s,l:iu(r),v:i}))}}else return t<n?ss(bt(e,{l:Qi(r,t)})):ss(bt(e,{r:Qi(o,t)}))}function fr(e){return st(e)?[]:[...fr(e.l),{k:e.k,v:e.v},...fr(e.r)]}function ea(e,t,n){if(st(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ea(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ea(s,t,n))),a}function ss(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(ta(t))return uu(bt(e,{lvl:n-1}));if(!st(t)&&!st(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(ta(e))return na(bt(e,{lvl:n-1}));if(!st(r)&&!st(r.l)){const o=r.l,s=ta(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:na(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return lu(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 iu(e){return st(e.r)?e.l:ss(bt(e,{r:iu(e.r)}))}function ta(e){return st(e)||e.lvl>e.r.lvl}function au(e){return st(e.r)?[e.k,e.v]:au(e.r)}function lu(e,t,n,r=to,o=to){return{k:e,l:r,lvl:n,r:o,v:t}}function cu(e){return na(uu(e))}function uu(e){const{l:t}=e;return!st(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function na(e){const{lvl:t,r:n}=e;return!st(n)&&!st(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function dy(e){return su(e,({k:t,v:n})=>({index:t,value:n}))}function du(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 ra=Ye(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function fu(e,t,n){return e[is(e,t,n)]}function is(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 fy(e,t,n,r){const o=is(e,t,r),s=is(e,n,r,o);return e.slice(o,s+1)}function qn(e,t){return Math.round(e.getBoundingClientRect()[t])}function as(e){return!st(e.groupOffsetTree)}function oa({index:e},t){return t===e?0:t<e?-1:1}function hy(){return{groupIndices:[],groupOffsetTree:Rr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Rr()}}function py(e,t){let n=st(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),st(e)){e=Vt(e,0,s);continue}const a=os(e,i-1,o+1);if(a.some(by(r)))continue;let l=!1,c=!1;for(const{end:u,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Qi(e,f)):(c=h!==s,l=!0),u>o&&o>=f&&h!==s&&(e=Vt(e,o+1,h));c&&(e=Vt(e,i,s))}return[e,n]}function my(e){return typeof e.groupIndex<"u"}function gy({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}=fu(t,e,oa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function hu(e,t){if(!as(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function pu(e,t,n){if(my(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=hu(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function xy(e,t,n,r=0){return r>0&&(t=Math.max(t,fu(e,r,oa).offset)),su(fy(e,t,n,gy),wy)}function yy(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&&st(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,x)=>Vt(Vt(m,x,h),x+1,p),i)}else[i,a]=py(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:u,offsetTree:f}=sa(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:u,offsetTree:f,sizeTree:i}}function vy(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 mu(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 sa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=is(o,t-1,oa),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:u}of os(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:u}),s=c,a=h,i=u}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function wy(e){return{index:e.index,value:e}}function by(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 Sy={offsetHeight:"height",offsetWidth:"width"},kn=Ye(([{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),u=J(void 0),f=J((k,C)=>qn(k,Sy[C])),h=J(void 0),p=J(0),m=hy(),x=Pt(V(n,Le(l,e,p),Cn(yy,m),ut()),m),v=Pt(V(l,ut(),Cn((k,C)=>({current:C,prev:k.current}),{current:[],prev:[]}),de(({prev:k})=>k)),[]);ve(V(l,Ee(k=>k.length>0),Le(x,p),de(([k,C,E])=>{const _=k.reduce((j,D,$)=>Vt(j,D,oo(D,C.offsetTree,E)||$),Rr());return{...C,groupIndices:k,groupOffsetTree:_}})),x),ve(V(r,Le(x),Ee(([k,{lastIndex:C}])=>k<C),de(([k,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:k}])),n),ve(c,u);const g=Pt(V(c,de(k=>k===void 0)),!0);ve(V(u,Ee(k=>k!==void 0&&st(gt(x).sizeTree)),de(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=Wt(V(n,Le(x),Cn(({sizes:k},[C,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:m}),de(k=>k.changed)));Qe(V(a,Cn((k,C)=>({diff:k.prev-C,prev:C}),{diff:0,prev:0}),de(k=>k.diff)),k=>{const{groupIndices:C}=gt(x);if(k>0)Pe(t,!0),Pe(s,k+mu(k,C));else if(k<0){const E=gt(v);E.length>0&&(k-=mu(-k,E)),Pe(i,k)}}),Qe(V(a,Le(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);ve(V(s,Le(x),de(([k,C])=>{const E=C.groupIndices.length>0,_=[],j=C.lastSize;if(E){const D=no(C.sizeTree,0);let $=0,q=0;for(;$<k;){const R=C.groupIndices[q],L=C.groupIndices.length===q+1?1/0:C.groupIndices[q+1]-R-1;_.push({endIndex:R,size:D,startIndex:R}),_.push({endIndex:R+1+L-1,size:j,startIndex:R+1}),q++,$+=L+1}const P=fr(C.sizeTree);return $!==k&&P.shift(),P.reduce((R,{k:L,v:F})=>{let ne=R.ranges;return R.prevSize!==0&&(ne=[...R.ranges,{endIndex:L+k-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:L+k,prevSize:F,ranges:ne}},{prevIndex:k,prevSize:0,ranges:_}).ranges}return fr(C.sizeTree).reduce((D,{k:$,v:q})=>({prevIndex:$+k,prevSize:q,ranges:[...D.ranges,{endIndex:$+k-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const T=Wt(V(i,Le(x,p),de(([k,{offsetTree:C},E])=>{const _=-k;return oo(_,C,E)})));return ve(V(i,Le(x,p),de(([k,C,E])=>{if(C.groupIndices.length>0){if(st(C.sizeTree))return C;let _=Rr();const j=gt(v);let D=0,$=0,q=0;for(;D<-k;){q=j[$];const P=j[$+1]-q-1;$++,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,q);_=Vt(_,0,P);const R=fn(C.sizeTree,-k+1)[1];_=Vt(_,1,R)}return{...C,sizeTree:_,...sa(C.offsetTree,0,_,E)}}else{const _=fr(C.sizeTree).reduce((j,{k:D,v:$})=>Vt(j,Math.max(0,D+k),$),Rr());return{...C,sizeTree:_,...sa(C.offsetTree,0,_,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:u,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},ct(Kn,ra),{singleton:!0});function Cy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const gu=Ye(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ve(),i=Ve(),a=Wt(V(s,de(Cy)));return ve(V(a,de(l=>l.totalCount)),n),ve(V(a,de(l=>l.groupIndices)),e),ve(V(wt(o,t,r),Ee(([l,c])=>as(c)),de(([l,c,u])=>fn(c.groupOffsetTree,Math.max(l-u,0),"v")[0]),ut(),de(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(kn,Ft)),Gn=Ye(([{log:e}])=>{const t=J(!1),n=Wt(V(t,Ee(r=>r),ut()));return Qe(t,r=>{r&>(e)("props updated",{},Ut.DEBUG)}),{didMount:n,propsReady:t}},ct(Kn),{singleton:!0}),ky=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function xu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ky)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const so=Ye(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:u,viewportHeight:f},{log:h}])=>{const p=Ve(),m=Ve(),x=J(0);let v=null,g=null,w=null;function S(){v&&(v(),v=null),w&&(w(),w=null),g&&(clearTimeout(g),g=null),Pe(l,!1)}return ve(V(p,Le(n,f,r,x,a,i,h),Le(e,s,o),de(([[T,k,C,E,_,j,D,$],q,P,R])=>{const L=xu(T),{align:F,behavior:ne,offset:K}=L,B=E-1,pe=pu(L,k,B);let W=oo(pe,k.offsetTree,q)+j;F==="end"?(W+=P+fn(k.sizeTree,pe)[1]-C+R,pe===B&&(W+=D)):F==="center"?W+=(P+fn(k.sizeTree,pe)[1]-C+R)/2:W-=_,K&&(W+=K);const ce=H=>{S(),H?($("retrying to scroll to",{location:T},Ut.DEBUG),Pe(p,T)):(Pe(m,!0),$("list did not change, scroll successful",{},Ut.DEBUG))};if(S(),ne==="smooth"){let H=!1;w=Qe(t,Z=>{H=H||Z}),v=dn(u,()=>{ce(H)})}else v=dn(V(t,Ty(150)),ce);return g=setTimeout(()=>{S()},1200),Pe(l,!0),$("scrolling from index to",{behavior:ne,index:pe,top:W},Ut.DEBUG),{behavior:ne,top:W}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:x}},ct(kn,Ft,Kn),{singleton:!0});function Ty(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ia(e,t){e==0?t():requestAnimationFrame(()=>{ia(e-1,t)})}function aa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const io=Ye(([{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 ve(V(i,Le(l),Ee(([u,f])=>!!f),Sn(!1)),a),ve(V(i,Le(l),Ee(([u,f])=>!!f),Sn(!1)),c),Qe(V(wt(t,i),Le(a,n,e,c),Ee(([[,u],f,{sizeTree:h},p,m])=>u&&(!st(h)||Yi(p))&&!f&&!m),Le(l)),([,u])=>{dn(o,()=>{Pe(c,!0)}),ia(4,()=>{dn(r,()=>{Pe(a,!0)}),Pe(s,u)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(kn,Ft,so,Gn),{singleton:!0});function yu(e,t){return Math.abs(e-t)<1.01}const ao="up",lo="down",Ey="none",Iy={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ay=0,co=Ye(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=Ve(),c=Ve(),u=J(4),f=J(Ay),h=Pt(V(Ji(V(Te(o),ur(1),Sn(!0)),V(Te(o),ur(1),Sn(!1),tu(100))),ut()),!1),p=Pt(V(Ji(V(n,Sn(!0)),V(n,Sn(!1),tu(200))),ut()),!1);ve(V(wt(Te(o),Te(f)),de(([w,S])=>w<=S),ut()),a),ve(V(a,zn(50)),c);const m=Wt(V(wt(r,Te(s),Te(t),Te(e),Te(u)),Cn((w,[{scrollHeight:S,scrollTop:T},k,C,E,_])=>{const j=T+k-S>-_,D={scrollHeight:S,scrollTop:T,viewportHeight:k};if(j){let q,P;return T>w.state.scrollTop?(q="SCROLLED_DOWN",P=w.state.scrollTop-T):(q="SIZE_DECREASED",P=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:P,state:D}}let $;return D.scrollHeight>w.state.scrollHeight?$="SIZE_INCREASED":k<w.state.viewportHeight?$="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?$="SCROLLING_UPWARDS":$="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:$,state:D}},Iy),ut((w,S)=>w&&w.atBottom===S.atBottom))),x=Pt(V(r,Cn((w,{scrollHeight:S,scrollTop:T,viewportHeight:k})=>{if(yu(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}),Ee(w=>w.changed),de(w=>w.jump)),0);ve(V(m,de(w=>w.atBottom)),i),ve(V(i,zn(50)),l);const v=J(lo);ve(V(r,de(({scrollTop:w})=>w),ut(),Cn((w,S)=>gt(p)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?ao:lo,prevScrollTop:S},{direction:lo,prevScrollTop:0}),de(w=>w.direction)),v),ve(V(r,zn(50),Sn(Ey)),v);const g=J(0);return ve(V(h,Ee(w=>!w),Sn(0)),g),ve(V(o,zn(100),Le(h),Ee(([w,S])=>!!S),Cn(([w,S],[T])=>[S,T],[0,0]),de(([w,S])=>S-w)),g),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:u,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:v,scrollVelocity:g}},ct(Ft)),ls="top",cs="bottom",vu="none";function wu(e,t,n){return typeof e=="number"?n===ao&&t===ls||n===lo&&t===cs?e:0:n===ao?t===ls?e.main:e.reverse:t===cs?e.main:e.reverse}function bu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const la=Ye(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ve(),i=J(0),a=J(0),l=J(0),c=Pt(V(wt(Te(r),Te(o),Te(n),Te(s,ro),Te(l),Te(i),Te(t),Te(e),Te(a)),de(([u,f,h,[p,m],x,v,g,w,S])=>{const T=u-w,k=v+g,C=Math.max(h-T,0);let E=vu;const _=bu(S,ls),j=bu(S,cs);return p-=w,p+=h+g,m+=h+g,m-=w,p>u+k-_&&(E=ao),m<u-C+f+j&&(E=lo),E!==vu?[Math.max(T-h-wu(x,ls,E)-_,0),T-C-g+f+wu(x,cs,E)+j]:null}),Ee(u=>u!=null),ut(ro)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Ft),{singleton:!0});function Ny(e,t,n){if(as(t)){const r=hu(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 ca={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function us(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,u=0;if(e.length>0){c=e[0].offset;const x=e[e.length-1];u=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-u;return{bottom:u,firstItemIndex:s,items:Cu(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Cu(t,o,s),topListHeight:t.reduce((x,v)=>v.size+x,0),totalCount:n}}function Su(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const u of n.groupIndices){if(u-i>=e)break;i++}const a=e+i,l=aa(t,a),c=Array.from({length:a}).map((u,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return us(c,[],a,o,n,r)}function Cu(e,t,n){if(e.length===0)return[];if(!as(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=os(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 u;c.index===a.start?u={index:l,type:"group"}:u={groupIndex:l,index:c.index-(l+1)+n},s.push({...u,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const hr=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:u},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const x=J([]),v=J(0),g=Ve();ve(s.topItemsIndexes,x);const w=Pt(V(wt(p,m,Te(l,ro),Te(o),Te(r),Te(c),u,Te(x),Te(t),Te(n),e),Ee(([C,E,,_,,,,,,,j])=>{const D=j&&j.length!==_;return C&&!E&&!D}),de(([,,[C,E],_,j,D,$,q,P,R,L])=>{const F=j,{offsetTree:ne,sizeTree:K}=F,B=gt(v);if(_===0)return{...ca,totalCount:_};if(C===0&&E===0)return B===0?{...ca,totalCount:_}:Su(B,D,j,P,R,L||[]);if(st(K))return B>0?null:us(Ny(aa(D,_),F,L),[],_,R,F,P);const pe=[];if(q.length>0){const we=q[0],ye=q[q.length-1];let G=0;for(const M of os(K,we,ye)){const X=M.value,oe=Math.max(M.start,we),xe=Math.min(M.end,ye);for(let se=oe;se<=xe;se++)pe.push({data:L==null?void 0:L[se],index:se,offset:G,size:X}),G+=X}}if(!$)return us([],pe,_,R,F,P);const W=q.length>0?q[q.length-1]+1:0,ce=xy(ne,C,E,W);if(ce.length===0)return null;const H=_-1,Z=rs([],we=>{for(const ye of ce){const G=ye.value;let M=G.offset,X=ye.start;const oe=G.size;if(G.offset<C){X+=Math.floor((C-G.offset+R)/(oe+R));const se=X-ye.start;M+=se*oe+se*R}X<W&&(M+=(W-X)*oe,X=W);const xe=Math.min(ye.end,H);for(let se=X;se<=xe&&!(M>=E);se++)we.push({data:L==null?void 0:L[se],index:se,offset:M,size:oe}),M+=oe+R}});return us(Z,pe,_,R,F,P)}),Ee(C=>C!==null),ut()),ca);ve(V(e,Ee(Yi),de(C=>C==null?void 0:C.length)),o),ve(V(w,de(C=>C.topListHeight)),f),ve(f,a),ve(V(w,de(C=>[C.top,C.bottom])),i),ve(V(w,de(C=>C.items)),g);const S=Wt(V(w,Ee(({items:C})=>C.length>0),Le(o,e),Ee(([{items:C},E])=>C[C.length-1].originalIndex===E-1),de(([,C,E])=>[C-1,E]),ut(ro),de(([C])=>C))),T=Wt(V(w,zn(200),Ee(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),de(({items:C})=>C[0].index),ut())),k=Wt(V(w,Ee(({items:C})=>C.length>0),de(({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}}),ut(du)));return{endReached:S,initialItemCount:v,itemsRendered:g,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:x,...h}},ct(kn,gu,la,io,so,co,Gn,ra),{singleton:!0}),ku=Ye(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ve(),i=Pt(V(wt(n,e,r,t,o),de(([a,l,c,u,f])=>a+l+c+u+f.offsetBottom+f.bottom)),0);return ve(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Ft,hr),{singleton:!0}),_y=Ye(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=Pt(V(wt(n,e,t),Ee(([o])=>o),de(([,o,s])=>Math.max(0,o-s)),zn(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Ft,ku),{singleton:!0}),Tu=Ye(()=>({context:J(null)})),jy=({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,Eu=Ye(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const u=Ve();return ve(V(u,Le(t,l,n,s,o,r,a),Le(e),de(([[f,h,p,m,x,v,g,w],S])=>{const{align:T,behavior:k,calculateViewLocation:C=jy,done:E,..._}=f,j=pu(f,h,m-1),D=oo(j,h.offsetTree,S)+x+v,$=D+fn(h.sizeTree,j)[1],q=w+v,P=w+p-g,R=C({itemBottom:$,itemTop:D,locationParams:{align:T,behavior:k,..._},viewportBottom:P,viewportTop:q});return R?E&&dn(V(i,Ee(L=>!L),ur(gt(i)?1:2)),E):E&&E(),R}),Ee(f=>f!==null)),c),{scrollIntoView:u}},ct(kn,Ft,so,hr,Kn),{singleton:!0});function Iu(e){return e?e==="smooth"?"smooth":"auto":!1}const Ry=(e,t)=>typeof e=="function"?Iu(e(t)):t&&Iu(e),Py=Ye(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:u},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=J(!1),x=Ve();let v=null;function g(k){Pe(i,{align:"end",behavior:k,index:"LAST"})}Qe(V(wt(V(Te(t),ur(1)),l),Le(Te(m),s,a,f),de(([[k,C],E,_,j,D])=>{let $=C&&j,q="auto";return $&&(q=Ry(E,_||D),$=$&&!!q),{followOutputBehavior:q,shouldFollow:$,totalCount:k}}),Ee(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:C})=>{v&&(v(),v=null),gt(n)?requestAnimationFrame(()=>{gt(u)("following output to ",{totalCount:C},Ut.DEBUG),g(k)}):v=dn(e,()=>{gt(u)("following output to ",{totalCount:C},Ut.DEBUG),g(k),v=null})});function w(k){const C=dn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(gt(u)("scrolling to bottom due to increased size",{},Ut.DEBUG),g("auto"))});setTimeout(C,100)}Qe(V(wt(Te(m),t,c),Ee(([k,,C])=>k&&C),Cn(({value:k},[,C])=>({refreshed:k===C,value:C}),{refreshed:!1,value:0}),Ee(({refreshed:k})=>k),Le(m,t)),([,k])=>{gt(a)&&w(k!==!1)}),Qe(x,()=>{w(gt(m)!==!1)}),Qe(wt(Te(m),o),([k,C])=>{k&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=J(null),T=Ve();return ve(Ji(V(Te(r),de(k=>{var C;return(C=k==null?void 0:k.length)!=null?C:0})),V(Te(t))),T),Qe(V(wt(V(T,ur(1)),l),Le(Te(S),a,f,h),de(([[k,C],E,_,j,D])=>C&&_&&(E==null?void 0:E({context:D,totalCount:k,scrollingInProgress:j}))),Ee(k=>!!k),zn(0)),k=>{v&&(v(),v=null),gt(n)?requestAnimationFrame(()=>{gt(u)("scrolling into view",{}),Pe(p,k)}):v=dn(e,()=>{gt(u)("scrolling into view",{}),Pe(p,k),v=null})}),{autoscrollToBottom:x,followOutput:m,scrollIntoViewOnChange:S}},ct(kn,co,so,io,Gn,Kn,Ft,Tu,Eu)),Oy=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(V(a,Le(s),Ee(([,l])=>l!==0),Le(o,r,t,n,e),de(([[,l],c,u,f,h,p=[]])=>Su(l,c,u,f,h,p))),i),{}),ct(kn,io,hr,Gn),{singleton:!0}),My=Ye(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return Qe(V(e,Le(r),Ee(([,o])=>o!==0),de(([,o])=>({top:o}))),o=>{dn(V(n,ur(1),Ee(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},ct(Gn,Ft,hr),{singleton:!0}),Au=Ye(([{scrollVelocity:e}])=>{const t=J(!1),n=Ve(),r=J(!1);return ve(V(e,Le(r,t,n),Ee(([o,s])=>!!s),de(([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}),ut()),t),Qe(V(wt(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(co),{singleton:!0}),ua=Ye(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ve(),r=Ve(),o=Ve(),s=J(!1),i=J(void 0);return ve(V(wt(n,r),de(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:u}])=>({scrollHeight:a,scrollTop:Math.max(0,l-u),viewportHeight:c}))),e),ve(V(t,Le(r),de(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Ft)),Dy=Ye(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ve(),u=J(void 0),f=J(null),h=J(null);return ve(a,f),ve(l,h),Qe(V(c,Le(t,r,i,f,h,n)),([p,m,x,v,g,w,S])=>{const T=vy(m.sizeTree);v&&g!==null&&w!==null&&(x=g.scrollTop-w.offsetTop),x-=S,p({ranges:T,scrollTop:x})}),ve(V(u,Ee(Yi),de(Ly)),o),ve(V(s,Le(u),Ee(([,p])=>p!==void 0),ut(),de(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:u}},ct(kn,Ft,io,Gn,ua));function Ly(e){return{align:"start",index:0,offset:e.scrollTop}}const Fy=Ye(([{topItemsIndexes:e}])=>{const t=J(0);return ve(V(t,Ee(n=>n>=0),de(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(hr));function Nu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const $y=Nu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),zy=Ye(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:u,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const x=Wt(V(l,Le(i),Cn(([,g,w,S],[{bottom:T,items:k,offsetBottom:C,totalCount:E},_])=>{const j=T+C;let D=0;return w===E&&g.length>0&&k.length>0&&(k[0].originalIndex===0&&g[0].originalIndex===0||(D=j-S,D!==0&&(D+=_))),[D,k,E,j]},[0,[],0,0]),Ee(([g])=>g!==0),Le(r,a,n,o,p,m),Ee(([,g,w,S,,,T])=>!T&&!S&&g!==0&&w===ao),de(([[g],,,,,w])=>(w("Upward scrolling compensation",{amount:g},Ut.DEBUG),g))));function v(g){g>0?(Pe(t,{behavior:"auto",top:-g}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-g}))}return Qe(V(x,Le(e,s)),([g,w,S])=>{S&&$y()?Pe(e,w-g):v(-g)}),Qe(V(wt(Pt(s,!1),e,m),Ee(([g,w,S])=>!g&&!S&&w!==0),de(([g,w])=>w),zn(1)),v),ve(V(f,de(g=>({top:-g}))),t),Qe(V(c,Le(h,u),de(([g,{groupIndices:w,lastSize:S,sizeTree:T},k])=>{function C(E){return E*(S+k)}if(w.length===0)return C(g);{let E=0;const _=no(T,0);let j=0,D=0;for(;j<g;){j++,E+=_;let $=w.length===D+1?1/0:w[D+1]-w[D]-1;j+$>g&&(E-=_,$=g-j+1),j+=$,E+=C($),D++}return E}})),g=>{Pe(e,g),requestAnimationFrame(()=>{Pe(t,{top:g}),requestAnimationFrame(()=>{Pe(e,0),Pe(m,!1)})})}),{deviation:e}},ct(Ft,co,hr,kn,Kn,ra)),By=Ye(([e,t,n,r,o,s,i,a,l,c,u])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...u}),ct(la,Oy,Gn,Au,ku,My,_y,ua,Eu,Kn,Tu)),_u=Ye(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:u,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},x,v,g,{listState:w,topItemsIndexes:S,...T},{scrollToIndex:k},C,{topItemCount:E},{groupCounts:_},j])=>(ve(T.rangeChanged,j.scrollSeekRangeChanged),ve(V(j.windowViewportRect,de(D=>D.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:_,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:u,...g,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,...j,...x,sizes:l,...v}),ct(kn,io,Ft,Dy,Py,hr,so,zy,Fy,gu,By));function Hy(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 ds=typeof document<"u"?b.useLayoutEffect:b.useEffect;function ju(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,g){v.propsReady&&Pe(v.propsReady,!1);for(const w of r){const S=v[t.required[w]];Pe(S,g[w])}for(const w of o)if(w in g){const S=v[t.optional[w]];Pe(S,g[w])}v.propsReady&&Pe(v.propsReady,!0)}function c(v){return s.reduce((g,w)=>(g[w]=S=>{const T=v[t.methods[w]];Pe(T,S)},g),{})}function u(v){return i.reduce((g,w)=>(g[w]=oy(v[t.events[w]]),g),{})}const f=b.forwardRef((v,g)=>{const{children:w,...S}=v,[T]=b.useState(()=>rs(iy(e),E=>{l(E,S)})),[k]=b.useState(eu(u,T));ds(()=>{for(const E of i)E in S&&Qe(k[E],S[E]);return()=>{Object.values(k).map(Xi)}},[S,k,T]),ds(()=>{l(T,S)}),b.useImperativeHandle(g,Zc(c(T)));const C=n;return d.jsx(a.Provider,{value:T,children:n?d.jsx(C,{...Hy([...r,...o,...i],S),children:w}):w})}),h=v=>{const g=b.useContext(a);return b.useCallback(w=>{Pe(g[v],w)},[g,v])},p=v=>{const g=b.useContext(a)[v],w=b.useCallback(S=>Qe(g,S),[g]);return b.useSyncExternalStore(w,()=>gt(g),()=>gt(g))},m=v=>{const g=b.useContext(a)[v],[w,S]=b.useState(eu(gt,g));return ds(()=>Qe(g,T=>{T!==w&&S(Zc(T))}),[g,w]),w},x=b.version.startsWith("18")?p:m;return{Component:f,useEmitter:(v,g)=>{const w=b.useContext(a)[v];ds(()=>Qe(w,g),[g,w])},useEmitterValue:x,usePublisher:h}}const Ru=b.createContext(void 0),Pu=b.createContext(void 0),Ou=typeof document<"u"?b.useLayoutEffect:b.useEffect;function da(e){return"self"in e}function Uy(e){return"body"in e}function Mu(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,m,x;const v=h.target;if(Uy(v)||da(v)){const w=da(v)?v:v.defaultView;x=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else x=s?v.scrollLeft:v.scrollTop,p=s?v.scrollWidth:v.scrollHeight,m=s?v.offsetWidth:v.offsetHeight;const g=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:m})};h.suppressFlushSync?g():gi.flushSync(g),a.current!==null&&(x===a.current||x<=0||x===p-m)&&(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 u(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const m=h.behavior==="smooth";let x,v,g;da(p)?(v=Math.max(qn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,g=s?window.scrollX:window.scrollY):(v=p[s?"scrollWidth":"scrollHeight"],x=qn(p,s?"width":"height"),g=p[s?"scrollLeft":"scrollTop"]);const w=v-x;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),yu(x,v)||h.top===g){e({scrollHeight:v,scrollTop:g,viewportHeight:x}),m&&t(!0);return}m?(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:u}}const fa="-webkit-sticky",Du="sticky",ha=Nu(()=>{if(typeof document>"u")return Du;const e=document.createElement("div");return e.style.position=fa,e.style.position===fa?fa:Du});function pa(e){return e}const Wy=Ye(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(pa),o=J("div"),s=J(jr),i=(a,l=null)=>Pt(V(n,de(c=>c[a]),ut()),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")}}),Vy=Ye(([e,t])=>({...e,...t}),ct(_u,Wy)),Ky=({height:e})=>d.jsx("div",{style:{height:e}}),qy={overflowAnchor:"none",position:ha(),zIndex:1},Lu={overflowAnchor:"none"},Gy={...Lu,display:"inline-block",height:"100%"},Fu=b.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=en("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),c=Ne("context"),u=Ne("groupContent"),f=Ne("trackItemSizes"),h=Ne("itemSize"),p=Ne("log"),m=en("gap"),x=Ne("horizontalDirection"),{callbackRef:v}=cy(n,h,f,e?jr:a,p,m,o,x,Ne("skipAnimationFrameInResizeObserver")),[g,w]=b.useState(0);ma("deviation",R=>{g!==R&&w(R)});const S=Ne("EmptyPlaceholder"),T=Ne("ScrollSeekPlaceholder")||Ky,k=Ne("ListComponent"),C=Ne("ItemComponent"),E=Ne("GroupComponent"),_=Ne("computeItemKey"),j=Ne("isSeeking"),D=Ne("groupIndices").length>0,$=Ne("alignToBottom"),q=Ne("initialItemFinalLocationReached"),P=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:g!==0?g:$?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:$?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...q?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?d.jsx(S,{...Ot(S,c)}):d.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,F=_(L+t.firstItemIndex,R.data,c);return j?b.createElement(T,{...Ot(T,c),height:R.size,index:R.index,key:F,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:F,style:qy},u(R.index,c)):b.createElement(C,{...Ot(C,c),...Zy(C,R.data),"data-index":L,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:F,style:x?Gy:Lu},D?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),Yy={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Xy={outline:"none",overflowX:"auto",position:"relative"},fs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Jy={position:ha(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function Zy(e,t){return{item:typeof e=="string"?void 0:t}}const Qy=b.memo(function(){const e=Ne("HeaderComponent"),t=en("headerHeight"),n=Ne("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null}),ev=b.memo(function(){const e=Ne("FooterComponent"),t=en("footerHeight"),n=Ne("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null});function $u({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"),u=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=Mu(a,c,l,u,void 0,f);return e("scrollTo",m),e("scrollBy",h),d.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Xy:Yy,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function zu({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"),u=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:x,scrollerRef:v,scrollToCallback:g}=Mu(a,c,l,m,h);return Ou(()=>{var w;return v.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",g),e("scrollBy",x),d.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...u!==0?{height:u+f}:{}},...i,...Ot(l,s),children:r})})}const tv=({children:e})=>{const t=b.useContext(Ru),n=en("viewportHeight"),r=en("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=b.useMemo(()=>Qc(n,l=>qn(l,s?"width":"height")),[n,s]),a=dr(i,!0,Ne("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),d.jsx("div",{"data-viewport-type":"element",ref:a,style:fs(o),children:e})},nv=({children:e})=>{const t=b.useContext(Ru),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=Ne("customScrollParent"),s=ou(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),d.jsx("div",{"data-viewport-type":"window",ref:s,style:fs(i),children:e})},rv=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...Jy,marginTop:`${n}px`},o=Ne("context");return d.jsx(t,{style:r,...Ot(t,o),children:e})},ov=b.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return d.jsxs(r||t?av:iv,{...e,context:o,children:[n&&d.jsx(rv,{children:d.jsx(Fu,{showTopList:!0})}),d.jsxs(r||t?nv:tv,{children:[d.jsx(Qy,{}),d.jsx(Fu,{}),d.jsx(ev,{})]})]})}),{Component:sv,useEmitter:ma,useEmitterValue:Ne,usePublisher:en}=ju(Vy,{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"}},ov),iv=$u({useEmitter:ma,useEmitterValue:Ne,usePublisher:en}),av=zu({useEmitter:ma,useEmitterValue:Ne,usePublisher:en}),lv=sv;ct(_u,Ye(()=>{const e=J(c=>d.jsxs("td",{children:["Item $",c]})),t=J(null),n=J(c=>d.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=J(null),o=J(null),s=J({}),i=J(pa),a=J(jr),l=(c,u=null)=>Pt(V(s,de(f=>f[c]),ut()),u);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")}})),ha();const Bu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},cv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Hu,floor:hs,max:uo,min:ga,round:Uu}=Math;function Wu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function uv(e){return{...cv,items:e}}function ps(e,t){return e&&e.width===t.width&&e.height===t.height}function dv(e,t){return e&&e.column===t.column&&e.row===t.row}const fv=Ye(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:u,viewportHeight:f},h,p,{didMount:m,propsReady:x},{customScrollParent:v,useWindowScroll:g,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T},k])=>{const C=J(0),E=J(0),_=J(Bu),j=J({height:0,width:0}),D=J({height:0,width:0}),$=Ve(),q=Ve(),P=J(0),R=J(null),L=J({column:0,row:0}),F=Ve(),ne=Ve(),K=J(!1),B=J(0),pe=J(!0),W=J(!1),ce=J(!1);Qe(V(m,Le(B),Ee(([M,X])=>!!X)),()=>{Pe(pe,!1)}),Qe(V(wt(m,pe,D,j,B,W),Ee(([M,X,oe,xe,,se])=>M&&!X&&oe.height!==0&&xe.height!==0&&!se)),([,,,,M])=>{Pe(W,!0),ia(1,()=>{Pe($,M)}),dn(V(c),()=>{Pe(t,[0,0]),Pe(pe,!0)})}),ve(V(ne,Ee(M=>M!=null&&M.scrollTop>0),Sn(0)),E),Qe(V(m,Le(ne),Ee(([,M])=>M!=null)),([,M])=>{M&&(Pe(j,M.viewport),Pe(D,M.item),Pe(L,M.gap),M.scrollTop>0&&(Pe(K,!0),dn(V(c,ur(1)),X=>{Pe(K,!1)}),Pe(l,{top:M.scrollTop})))}),ve(V(j,de(({height:M})=>M)),f),ve(V(wt(Te(j,ps),Te(D,ps),Te(L,(M,X)=>M&&M.column===X.column&&M.row===X.row),Te(c)),de(([M,X,oe,xe])=>({gap:oe,item:X,scrollTop:xe,viewport:M}))),F),ve(V(wt(Te(C),r,Te(L,dv),Te(D,ps),Te(j,ps),Te(R),Te(E),Te(K),Te(pe),Te(B)),Ee(([,,,,,,,M])=>!M),de(([M,[X,oe],xe,se,re,Ue,Ke,,ot,at])=>{const{column:ht,row:tt}=xe,{height:Me,width:We}=se,{width:lt}=re;if(Ke===0&&(M===0||lt===0))return Bu;if(We===0){const Oe=aa(at,M),Xe=Oe+Math.max(Ke-1,0);return uv(Wu(Oe,Xe,Ue))}const xt=Vu(lt,We,ht);let dt,Je;ot?X===0&&oe===0&&Ke>0?(dt=0,Je=Ke-1):(dt=xt*hs((X+tt)/(Me+tt)),Je=xt*Hu((oe+tt)/(Me+tt))-1,Je=ga(M-1,uo(Je,xt-1)),dt=ga(Je,uo(0,dt))):(dt=0,Je=-1);const ie=Wu(dt,Je,Ue),{bottom:je,top:ke}=Ku(re,xe,se,ie),qe=Hu(M/xt),nt=qe*Me+(qe-1)*tt-je;return{bottom:je,itemHeight:Me,items:ie,itemWidth:We,offsetBottom:nt,offsetTop:ke,top:ke}})),_),ve(V(R,Ee(M=>M!==null),de(M=>M.length)),C),ve(V(wt(j,D,_,L),Ee(([M,X,{items:oe}])=>oe.length>0&&X.height!==0&&M.height!==0),de(([M,X,{items:oe},xe])=>{const{bottom:se,top:re}=Ku(M,xe,X,oe);return[re,se]}),ut(ro)),t);const H=J(!1);ve(V(c,Le(H),de(([M,X])=>X||M!==0)),H);const Z=Wt(V(wt(_,C),Ee(([{items:M}])=>M.length>0),Le(H),Ee(([[M,X],oe])=>{const xe=M.items[M.items.length-1].index===X-1;return(oe||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===X)&&xe}),de(([[,M]])=>M-1),ut())),we=Wt(V(Te(_),Ee(({items:M})=>M.length>0&&M[0].index===0),Sn(0),ut())),ye=Wt(V(Te(_),Le(K),Ee(([{items:M},X])=>M.length>0&&!X),de(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),ut(du),zn(0)));ve(ye,p.scrollSeekRangeChanged),ve(V($,Le(j,D,C,L),de(([M,X,oe,xe,se])=>{const re=xu(M),{align:Ue,behavior:Ke,offset:ot}=re;let at=re.index;at==="LAST"&&(at=xe-1),at=uo(0,at,ga(xe-1,at));let ht=xa(X,se,oe,at);return Ue==="end"?ht=Uu(ht-X.height+oe.height):Ue==="center"&&(ht=Uu(ht-X.height/2+oe.height/2)),ot&&(ht+=ot),{behavior:Ke,top:ht}})),l);const G=Pt(V(_,de(M=>M.offsetBottom+M.bottom)),0);return ve(V(T,de(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:ne,scrollBy:i,scrollContainerState:a,scrollHeight:q,scrollTo:l,scrollToIndex:$,scrollTop:c,smoothScrollTargetReached:u,totalCount:C,useWindowScroll:g,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T,...p,gridState:_,horizontalDirection:ce,initialTopMostItemIndex:B,totalListHeight:G,...h,endReached:Z,propsReady:x,rangeChanged:ye,startReached:we,stateChanged:F,stateRestoreInProgress:K,...k}},ct(la,Ft,co,Au,Gn,ua,Kn));function Vu(e,t,n){return uo(1,hs((e+n)/(hs(t)+n)))}function Ku(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=xa(e,t,n,r[0].index);return{bottom:xa(e,t,n,r[r.length-1].index)+o,top:s}}function xa(e,t,n,r){const o=Vu(e.width,n.width,t.column),s=hs(r/o),i=s*n.height+uo(0,s-1)*t.row;return i>0?i+t.row:i}const hv=Ye(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(pa),i=J("div"),a=J(jr),l=(f,h=null)=>Pt(V(t,de(p=>p[f]),ut()),h),c=J(!1),u=J(!1);return ve(Te(u),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:u,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),pv=Ye(([e,t])=>({...e,...t}),ct(fv,hv)),mv=b.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=tn("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),u=ft("context"),f=tn("itemDimensions"),h=tn("gap"),p=ft("log"),m=ft("stateRestoreInProgress"),x=tn("reportReadyState"),v=dr(b.useMemo(()=>g=>{const w=g.parentElement.parentElement.scrollHeight;i(w);const S=g.firstChild;if(S){const{height:T,width:k}=S.getBoundingClientRect();f({height:T,width:k})}h({column:Gu("column-gap",getComputedStyle(g).columnGap,p),row:Gu("row-gap",getComputedStyle(g).rowGap,p)})},[i,f,h,p]),!0,!1);return Ou(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),m?null:d.jsx(l,{className:t,ref:v,...Ot(l,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const w=o(g.index,g.data,u);return s?d.jsx(c,{...Ot(c,u),height:e.itemHeight,index:g.index,width:e.itemWidth},w):b.createElement(a,{...Ot(a,u),className:n,"data-index":g.index,key:w},r(g.index,g.data,u))})})}),gv=b.memo(function(){const e=ft("HeaderComponent"),t=tn("headerHeight"),n=ft("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,!1),o=ft("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null}),xv=b.memo(function(){const e=ft("FooterComponent"),t=tn("footerHeight"),n=ft("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,!1),o=ft("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null}),yv=({children:e})=>{const t=b.useContext(Pu),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]),d.jsx("div",{ref:o,style:fs(!1),children:e})},vv=({children:e})=>{const t=b.useContext(Pu),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=ft("customScrollParent"),s=ou(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]),d.jsx("div",{ref:s,style:fs(!1),children:e})},wv=b.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?Sv:bv,o=n||t?vv:yv,s=ft("context");return d.jsx(r,{...e,...Ot(r,s),children:d.jsxs(o,{children:[d.jsx(gv,{}),d.jsx(mv,{}),d.jsx(xv,{})]})})}),{useEmitter:qu,useEmitterValue:ft,usePublisher:tn}=ju(pv,{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"}},wv),bv=$u({useEmitter:qu,useEmitterValue:ft,usePublisher:tn}),Sv=zu({useEmitter:qu,useEmitterValue:ft,usePublisher:tn});function Gu(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 Cv=Oo.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 Yu({className:e,variant:t,...n}){return d.jsx("div",{className:ee(Cv({variant:t}),e),...n})}const fo=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));fo.displayName="Card";const ho=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("flex flex-col space-y-1.5 p-6",e),...t}));ho.displayName="CardHeader";const po=y.forwardRef(({className:e,...t},n)=>d.jsx("h3",{ref:n,className:ee("text-2xl font-semibold leading-none tracking-tight",e),...t}));po.displayName="CardTitle";const Xu=y.forwardRef(({className:e,...t},n)=>d.jsx("p",{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));Xu.displayName="CardDescription";const mo=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("p-6 pt-0",e),...t}));mo.displayName="CardContent";const Ju=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("flex items-center p-6 pt-0",e),...t}));Ju.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 kv(e,t){const n=y.createContext(t),r=s=>{const{children:i,...a}=s,l=y.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=y.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=y.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:h,children:p,...m}=f,x=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,v=y.useMemo(()=>m,Object.values(m));return d.jsx(x.Provider,{value:v,children:p})};c.displayName=s+"Provider";function u(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,m=y.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,u]}const o=()=>{const s=n.map(i=>y.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return y.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Tv(o,...t)]}function Tv(...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 y.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var kt=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Ev=y[" useInsertionEffect ".trim().toString()]||kt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Iv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const u=y.useRef(e!==void 0);y.useEffect(()=>{const f=u.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.`),u.current=a},[a,r])}const c=y.useCallback(u=>{var f;if(a){const h=Av(u)?u(e):u;h!==e&&((f=i.current)==null||f.call(i,h))}else s(u)},[a,e,s,i]);return[l,c]}function Iv({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),o=y.useRef(n),s=y.useRef(t);return Ev(()=>{s.current=t},[t]),y.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Av(e){return typeof e=="function"}function Zu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ya(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Zu(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():Zu(e[o],null)}}}}function He(...e){return y.useCallback(ya(...e),e)}var Nv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ie=Nv.reduce((e,t)=>{const n=sr.createSlot(`Primitive.${t}`),r=y.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Qu(e,t){e&&Mo.flushSync(()=>e.dispatchEvent(t))}function _v(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Kt=e=>{const{present:t,children:n}=e,r=jv(t),o=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),s=He(r.ref,Rv(o));return typeof n=="function"||r.isPresent?y.cloneElement(o,{ref:s}):null};Kt.displayName="Presence";function jv(e){const[t,n]=y.useState(),r=y.useRef(null),o=y.useRef(e),s=y.useRef("none"),i=e?"mounted":"unmounted",[a,l]=_v(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{const c=ms(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,u=o.current;if(u!==e){const h=s.current,p=ms(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),kt(()=>{if(t){let c;const u=t.ownerDocument.defaultView??window,f=p=>{const x=ms(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",c=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},h=p=>{p.target===t&&(s.current=ms(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{u.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:y.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function ms(e){return(e==null?void 0:e.animationName)||"none"}function Rv(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 Pv=y[" useId ".trim().toString()]||(()=>{}),Ov=0;function En(e){const[t,n]=y.useState(Pv());return kt(()=>{n(r=>r??String(Ov++))},[e]),e||(t?`radix-${t}`:"")}var gs="Collapsible",[Mv,vT]=Tn(gs),[Dv,va]=Mv(gs),ed=y.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:gs});return d.jsx(Dv,{scope:n,disabled:s,contentId:En(),open:l,onOpenToggle:y.useCallback(()=>c(u=>!u),[c]),children:d.jsx(Ie.div,{"data-state":ba(l),"data-disabled":s?"":void 0,...a,ref:t})})});ed.displayName=gs;var td="CollapsibleTrigger",nd=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=va(td,n);return d.jsx(Ie.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":ba(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ge(e.onClick,o.onOpenToggle)})});nd.displayName=td;var wa="CollapsibleContent",Lv=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=va(wa,e.__scopeCollapsible);return d.jsx(Kt,{present:n||o.open,children:({present:s})=>d.jsx(Fv,{...r,ref:t,present:s})})});Lv.displayName=wa;var Fv=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=va(wa,n),[a,l]=y.useState(r),c=y.useRef(null),u=He(t,c),f=y.useRef(0),h=f.current,p=y.useRef(0),m=p.current,x=i.open||a,v=y.useRef(x),g=y.useRef(void 0);return y.useEffect(()=>{const w=requestAnimationFrame(()=>v.current=!1);return()=>cancelAnimationFrame(w)},[]),kt(()=>{const w=c.current;if(w){g.current=g.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=g.current.transitionDuration,w.style.animationName=g.current.animationName),l(r)}},[i.open,r]),d.jsx(Ie.div,{"data-state":ba(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:u,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:x&&o})});function ba(e){return e?"open":"closed"}var $v=ed;const zv=$v,Bv=nd,Hv=1,Uv=1e6;let Sa=0;function Wv(){return Sa=(Sa+1)%Number.MAX_SAFE_INTEGER,Sa.toString()}const Ca=new Map,rd=e=>{if(Ca.has(e))return;const t=setTimeout(()=>{Ca.delete(e),go({type:"REMOVE_TOAST",toastId:e})},Uv);Ca.set(e,t)},Vv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Hv)};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?rd(n):e.toasts.forEach(r=>{rd(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)}}},xs=[];let ys={toasts:[]};function go(e){ys=Vv(ys,e),xs.forEach(t=>{t(ys)})}function Kv({...e}){const t=Wv(),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 ka(){const[e,t]=y.useState(ys);return y.useEffect(()=>(xs.push(t),()=>{const n=xs.indexOf(t);n>-1&&xs.splice(n,1)}),[e]),{...e,toast:Kv,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}async function od(e,t){return await cn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function sd(e,t){return await(await od(`/files/${e}/view`,t)).text()}async function qv(e,t){const n=await od(`/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 Gv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await cn("/files",{params:r})}function Ta(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 id(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;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(id(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 yo(e){if(typeof e=="string")return e;if(id(e))return"";try{const t=xo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Yv(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function Xv(e){const t=yo(e);return typeof e=="string"&&Yv(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function vs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ta(t);if(n!==null)return vs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?vs(e.content):e}function At(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Jv(e,t=globalThis==null?void 0:globalThis.document){const n=At(e);y.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 Zv="DismissableLayer",Ea="dismissableLayer.update",Qv="dismissableLayer.pointerDownOutside",ew="dismissableLayer.focusOutside",ad,ld=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ws=y.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=y.useContext(ld),[u,f]=y.useState(null),h=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=y.useState({}),m=He(t,E=>f(E)),x=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=x.indexOf(v),w=u?x.indexOf(u):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=g,k=rw(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=ow(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 Jv(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),y.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(ad=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),cd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=ad)}},[u,h,n,c]),y.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),cd())},[u,c]),y.useEffect(()=>{const E=()=>p({});return document.addEventListener(Ea,E),()=>document.removeEventListener(Ea,E)},[]),d.jsx(Ie.div,{...l,ref:m,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)})});ws.displayName=Zv;var tw="DismissableLayerBranch",nw=y.forwardRef((e,t)=>{const n=y.useContext(ld),r=y.useRef(null),o=He(t,r);return y.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(Ie.div,{...e,ref:o})});nw.displayName=tw;function rw(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=y.useRef(!1),o=y.useRef(()=>{});return y.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){ud(Qv,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 ow(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=y.useRef(!1);return y.useEffect(()=>{const o=s=>{s.target&&!r.current&&ud(ew,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 cd(){const e=new CustomEvent(Ea);document.dispatchEvent(e)}function ud(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?Qu(o,s):o.dispatchEvent(s)}var Ia="focusScope.autoFocusOnMount",Aa="focusScope.autoFocusOnUnmount",dd={bubbles:!1,cancelable:!0},sw="FocusScope",bs=y.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=y.useState(null),c=At(o),u=At(s),f=y.useRef(null),h=He(t,x=>l(x)),p=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(r){let x=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}))},g=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&Yn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",v);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",v),w.disconnect()}}},[r,a,p.paused]),y.useEffect(()=>{if(a){pd.add(p);const x=document.activeElement;if(!a.contains(x)){const g=new CustomEvent(Ia,dd);a.addEventListener(Ia,c),a.dispatchEvent(g),g.defaultPrevented||(iw(dw(fd(a)),{select:!0}),document.activeElement===x&&Yn(a))}return()=>{a.removeEventListener(Ia,c),setTimeout(()=>{const g=new CustomEvent(Aa,dd);a.addEventListener(Aa,u),a.dispatchEvent(g),g.defaultPrevented||Yn(x??document.body,{select:!0}),a.removeEventListener(Aa,u),pd.remove(p)},0)}}},[a,c,u,p]);const m=y.useCallback(x=>{if(!n&&!r||p.paused)return;const v=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(v&&g){const w=x.currentTarget,[S,T]=aw(w);S&&T?!x.shiftKey&&g===T?(x.preventDefault(),n&&Yn(S,{select:!0})):x.shiftKey&&g===S&&(x.preventDefault(),n&&Yn(T,{select:!0})):g===w&&x.preventDefault()}},[n,r,p.paused]);return d.jsx(Ie.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});bs.displayName=sw;function iw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Yn(r,{select:t}),document.activeElement!==n)return}function aw(e){const t=fd(e),n=hd(t,e),r=hd(t.reverse(),e);return[n,r]}function fd(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 hd(e,t){for(const n of e)if(!lw(n,{upTo:t}))return n}function lw(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 cw(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&&cw(e)&&t&&e.select()}}var pd=uw();function uw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=md(e,t),e.unshift(t)},remove(t){var n;e=md(e,t),(n=e[0])==null||n.resume()}}}function md(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function dw(e){return e.filter(t=>t.tagName!=="A")}var fw="Portal",Ss=y.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=y.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?gi.createPortal(d.jsx(Ie.div,{...r,ref:t}),i):null});Ss.displayName=fw;var Na=0;function _a(){y.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??gd()),document.body.insertAdjacentElement("beforeend",e[1]??gd()),Na++,()=>{Na===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Na--}},[])}function gd(){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 xd(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 hw(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 Cs="right-scroll-bar-position",ks="width-before-scroll-bar",pw="with-scroll-bars-hidden",mw="--removed-body-scroll-bar-size";function ja(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function gw(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 xw=typeof window<"u"?y.useLayoutEffect:y.useEffect,yd=new WeakMap;function yw(e,t){var n=gw(null,function(r){return e.forEach(function(o){return ja(o,r)})});return xw(function(){var r=yd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ja(a,null)}),s.forEach(function(a){o.has(a)||ja(a,i)})}yd.set(n,e)},[e]),n}function vw(e){return e}function ww(e,t){t===void 0&&(t=vw);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 u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return o}function bw(e){e===void 0&&(e={});var t=ww(null);return t.options=In({async:!0,ssr:!1},e),t}var vd=function(e){var t=e.sideCar,n=xd(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 y.createElement(r,In({},n))};vd.isSideCarExport=!0;function Sw(e,t){return e.useMedium(t),vd}var wd=bw(),Ra=function(){},Ts=y.forwardRef(function(e,t){var n=y.useRef(null),r=y.useState({onScrollCapture:Ra,onWheelCapture:Ra,onTouchMoveCapture:Ra}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,x=e.inert,v=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,T=xd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,C=yw([n,t]),E=In(In({},T),o);return y.createElement(y.Fragment,null,u&&y.createElement(k,{sideCar:wd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:x,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:S}),i?y.cloneElement(y.Children.only(a),In(In({},E),{ref:C})):y.createElement(w,In({},E,{className:l,ref:C}),a))});Ts.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ts.classNames={fullWidth:ks,zeroRight:Cs};var Cw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function kw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Cw();return t&&e.setAttribute("nonce",t),e}function Tw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Ew(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Iw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=kw())&&(Tw(t,n),Ew(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Aw=function(){var e=Iw();return function(t,n){y.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},bd=function(){var e=Aw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Nw={left:0,top:0,right:0,gap:0},Pa=function(e){return parseInt(e||"",10)||0},_w=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[Pa(n),Pa(r),Pa(o)]},jw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Nw;var t=_w(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])}},Rw=bd(),Pr="data-scroll-locked",Pw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
37
|
+
`))>=0;){const ke=se.slice(0,je);se=se.slice(je+2);const qe=Ax(ke);if(!qe)continue;let nt;try{nt=JSON.parse(qe)}catch{console.debug("[use-chat] malformed SSE:",qe.slice(0,200));continue}const Oe=Nx(nt)?nt.data:nt;ht=Date.now();const Xe=Oe.seq;if(Xe!==void 0){if(Xe<=Ue){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Xe,lastProcessedSeq:Ue,type:Oe.type});continue}Ue>0&&Xe>Ue+1&&((W=P==null?void 0:P.onGap)==null||W.call(P,{from:Ue,to:Xe})),Ue=Xe,k.current=Xe,v(Xe)}console.debug("[use-chat] received event",{seq:Oe.seq,type:Oe.type,preview:(()=>{var Tt;try{return Oe.type==="message_delta"?{deltaTypes:(Tt=Oe.delta)==null?void 0:Tt.map(St=>St.type),textLen:(Oe.delta||[]).filter(St=>St.type==="text").map(St=>String(St.text||"").length)}:Oe.content||Oe.delta?{hasContent:!0}:{}}catch(St){return{err:String(St)}}})()});try{q==null||q(Oe)}catch(Tt){console.error("[use-chat] Error in onEvent callback:",Tt,"for event:",Oe.type)}if(Oe.type==="token"&&e.autoAppendAssistant!==!1)re.push(Oe.content),at();else if(Oe.type==="message_delta"){const Tt=Oe.delta.filter(St=>St.type==="text").map(St=>St.text).join("");Tt&&e.autoAppendAssistant!==!1&&(re.push(Tt),at())}else Oe.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(Ke!==null&&cancelAnimationFrame(Ke),ot(),Oe.type==="checkpoint"?m(Oe.checkpointId):Oe.type==="error"&&u(Oe.message))}}ot()}catch(We){if(We.name!=="AbortError"){const lt=We.message||String(We);u(lt),(ce=P==null?void 0:P.onError)==null||ce.call(P,lt)}}finally{try{await oe.cancel()}catch{}finally{(H=oe.releaseLock)==null||H.call(oe)}Ke!==null&&typeof window<"u"&&window.cancelAnimationFrame(Ke),clearInterval(tt),l(!1),w(!1),S.current=null,k.current=0,v(0),C.current=null}}catch(we){if(we.name!=="AbortError"){const ye=we.message||String(we);u(ye),(Z=P==null?void 0:P.onError)==null||Z.call(P,ye)}}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 $;T.current=!1,($=S.current)==null||$.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:x,connected:g,stream:D,stop:j,clear:_,setToken:E}}function Nx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Ax(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 _x({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=b.useRef(null),i=b.useCallback(p=>{const m=p.seq??null;if(m!==null){const x=s.current;if(x!==null){if(m<=x)return;m>x+1&&(o==null||o({from:x,to:m}))}s.current=m}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p);try{t(p)}catch(x){console.error("[useChatStreamingService] Error in onThreadInfo handler:",x)}return}if(bx(p)){try{n(p)}catch(x){console.error("[useChatStreamingService] Error in onMessageEvent handler:",x)}return}try{r==null||r(p)}catch(x){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",x)}},[n,o,t,r]),{stream:a,stop:l,isStreaming:c,error:u,setToken:f}=zc({baseUrl:e,token:null}),h=b.useCallback((p,m)=>{s.current=null,a(p,i,{onOpen:m==null?void 0:m.onOpen,onError:x=>{var v;(v=m==null?void 0:m.onError)==null||v.call(m,x)},onGap:(m==null?void 0:m.onGap)??o})},[i,o,a]);return b.useMemo(()=>({startStream:h,stop:l,isStreaming:c,error:u,setAuthToken:f}),[h,l,c,u,f])}function $i(e){return e==null?e:{...e}}function jx(e){return e==null?e:{...e}}function Rx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function Px(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=$i(e==null?void 0:e.metadata),s=$i(e==null?void 0:e.config),i=$i(e==null?void 0:e.parentConfig),a=Rx(e==null?void 0:e.next),l=Px(e==null?void 0:e.tasks),c=jx(e==null?void 0:e.values),u={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&&(u.metadata=o),s!==void 0&&(u.config=s),i!==void 0&&(u.parentConfig=i),a!==void 0&&(u.next=a),l!==void 0&&(u.tasks=l),c!==void 0&&(u.values=c),u}function Ox(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 Bc(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 Xo=300;function Hc(e,t=Xo){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 zi(e){if(!cr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Bi(e,t){if(!cr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Hi(e){if(cr())try{window.localStorage.removeItem(e)}catch{}}const Mx="cachedThreads",Dx="v1",Ui=200;function Lx(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 Wi(e,t){return`cachedThreads:v1:${e}:${Lx(t||"anon")}`}function Fx(){const e=zi(Mx);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 $x(e){const t=zi(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 Vi(e,t){Bi(e,JSON.stringify(t))}function Ki(e){const t=$x(e);if(t.length>0)return t;const n=Fx();if(n.length>0)try{Vi(e,n.slice(0,Ui))}catch{}return n}function Jo(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 qi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Gi(e,t){return`${e}${t}`}function zx(e,t){const n=zi(Gi(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 Bx(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=Gi(e,t.threadId),i=JSON.stringify(o);if(!Bi(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 u=window.localStorage.getItem(c);if(!u){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(u),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),Bi(s,i))break}catch{}}function Hx(e,t){Hi(Gi(e,t))}function Ux(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 Uc=b.createContext(null),Wc=b.createContext(null),Vc=b.createContext(null),Wx=b.createContext(!1),Kc=50,Vx=750;function qc(e,t,n){return`${e}__${t??""}__${n??""}`}function Zo(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 Kx(e,t){return Zo(e,t)}function qx(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 Gx(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 Gc(e,t){const n=Zo(e.metadata,t.metadata),r=Zo(e.config,t.config),o=Zo(e.parentConfig,t.parentConfig),s=qx(e.next,t.next),i=Gx(e.tasks,t.tasks),a=Kx(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 Yx({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}=Ri(),u=b.useMemo(()=>$n(c),[c]),f=b.useMemo(()=>{try{return new URL(c).host}catch{return"unknown"}},[c]),h=b.useMemo(()=>`threadPayload:${Dx}:${f}:`,[f]),p=b.useCallback(N=>zx(h,N),[h]),m=b.useCallback((N,A=100)=>{Bx(h,N,A)},[h]),x=b.useCallback(N=>{Hx(h,N)},[h]),v=b.useCallback(()=>{Ux(h)},[h]),[g,w]=b.useState(()=>{var N;return Wi(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[S,T]=b.useState(()=>{var A;const N=Ki(Wi(f,(A=l.getAuthToken)==null?void 0:A.call(l)));return Jo(N)}),k=b.useMemo(()=>qi(S),[S]),[C,E]=b.useState(t),[_,j]=b.useState(!1),[D,$]=b.useState(!1),[q,P]=b.useState(null),[R,L]=b.useState(null),[F,ne]=b.useState(null),[K,B]=b.useState([]),pe=b.useCallback(()=>{const N=Ki(g);b.startTransition(()=>{T(Jo(N))})},[g]),[W,ce]=b.useState(!1),[H,Z]=b.useState(!1),[we,ye]=b.useState(null),[G,M]=b.useState(void 0),[X,oe]=b.useState(void 0),[xe,se]=b.useState(void 0),{state:re,dispatch:Ue,seed:Ke,prepend:ot,pushUser:at,onEvent:ht,reset:tt}=Rc(),Me=b.useRef(C);b.useEffect(()=>{Me.current=C},[C]);const We=b.useRef(!1),lt=b.useRef([]),xt=b.useRef(null),dt=b.useRef(null),Je=b.useRef(new Map),ie=b.useRef(C),je=b.useRef(!1),ke=b.useRef(null),qe=b.useRef(new Map),nt=b.useRef(new Map),Oe=b.useRef(new Map),Xe=b.useRef(new Map),Tt=b.useCallback(N=>{if(!N){B([]);return}const A=qe.current.get(N);if(!A||!A.length){B([]);return}B(A.map(Y=>Qt(Y,{cloneMessages:!0})))},[]);b.useEffect(()=>{Tt(C)},[C,Tt]);const St=b.useCallback(()=>{var te;const N=Xe.current;if(N.size<=Kc)return;const A=Array.from(N.entries()).sort((ae,Q)=>ae[1].timestamp-Q[1].timestamp),Y=N.size-Kc;for(let ae=0;ae<Y;ae++){const Q=(te=A[ae])==null?void 0:te[0];Q&&N.delete(Q)}},[]),Yt=b.useCallback((N,A,Y)=>{if(!N)return;const te=Y==="replace"?[]:qe.current.get(N)??[],ae=Y==="replace"?A:[...A,...te];if(!ae.length){Y==="replace"&&qe.current.set(N,[]);return}const Q=new Map;for(const Be of ae){if(!(Be!=null&&Be.checkpointId))continue;const De=`${Be.checkpointId}::${Be.checkpointNs??""}`,et=Qt(Be,{cloneMessages:!0}),yt=Q.get(De);if(!yt){Q.set(De,et);continue}const At=Gc(yt,et);Q.set(De,{...yt,...At})}const ze=Array.from(Q.values()).sort((Be,De)=>{const et=Number.isFinite(Date.parse(Be.createdAt??""))?Date.parse(Be.createdAt??""):0;return(Number.isFinite(Date.parse(De.createdAt??""))?Date.parse(De.createdAt??""):0)-et});qe.current.set(N,ze),N===Me.current&&Tt(N)},[Tt]),Et=b.useCallback((N,A,Y)=>{if(!N)return;const te=nt.current.get(N),ae=Y==="replace"||!te?new Map:new Map(te);if(A&&typeof A=="object")for(const[Q,ze]of Object.entries(A)){if(!(ze!=null&&ze.checkpointId))continue;const Be=Q||Qr(ze.checkpointId,ze.checkpointNs??null);ae.set(Be,Qt(ze,{cloneMessages:!0}))}nt.current.set(N,ae)},[]),rr=b.useCallback((N,A)=>{const{threadId:Y,checkpointId:te=null,checkpointNs:ae=null}=N,Q=qc(Y,te,ae);if(A!=null&&A.force)Oe.current.delete(Q),Xe.current.delete(Q);else{if(A!=null&&A.preferCache){const et=Xe.current.get(Q);if(et)return Promise.resolve(et.payload)}const De=Oe.current.get(Q);if(De)return De}const Be=l.getStateHistory({threadId:Y,checkpointId:te??void 0,checkpointNs:ae??void 0}).then(De=>(Xe.current.set(Q,{payload:De,timestamp:Date.now()}),St(),De)).finally(()=>{Oe.current.get(Q)===Be&&Oe.current.delete(Q)});return Oe.current.set(Q,Be),Be},[l,St]),Xt=b.useCallback((N,A)=>new Promise((Y,te)=>{const ae=async()=>{We.current=!0;try{await N(),Y()}catch(Q){te(Q)}finally{We.current=!1;const Q=lt.current.shift();Q&&Q().catch(()=>{})}};We.current?lt.current.push(ae):ae().catch(Q=>{te(Q)})}),[]),xn=b.useRef(k.length),sn=b.useRef(!1);b.useEffect(()=>{xn.current=k.length},[k.length]),b.useEffect(()=>{const N=re.pendingInterrupt??Ox(re.messages);Bc(F,N)||ne(N??null)},[F,re.messages,re.pendingInterrupt]);const Dt=b.useCallback(async()=>{const N=xn.current>0;N||j(!0);try{const A=await l.listThreads();b.startTransition(()=>{T(Y=>{const te=ze=>ze.map(Be=>`${Be.threadId}:${Be.updatedAt??""}:${Be.messageCount??""}`).join("|"),ae=qi(Y);return te(ae)===te(A)||A.length===0&&ae.length>0&&!sn.current?Y:Jo(A)})}),P(null),sn.current||(sn.current=!0)}catch(A){i==null||i(String(A)),console.error("[ChatSessionProvider] Failed to refresh threads:",A),P(String(A))}finally{N||j(!1)}},[l,i]),Pn=b.useRef(!1),yn=b.useRef(null),pt=b.useRef(null),vn=b.useRef(""),On=b.useCallback((N,A)=>{if(!cr())return;pt.current!==null&&(window.clearTimeout(pt.current),pt.current=null);const Y=N.map(ae=>`${ae.threadId}:${ae.updatedAt??""}:${ae.messageCount??""}`).join("|");if(N.length===0){try{Hi(g)}catch{}vn.current="";return}if(Y===vn.current)return;const te=()=>{try{const ae=N.slice(0,Ui);Vi(g,ae),vn.current=Y}catch{}finally{pt.current=null}};if(A!=null&&A.immediate){te();return}pt.current=window.setTimeout(()=>{Hc(te)},Xo)},[g]),kr=b.useCallback(()=>{On(k,{immediate:!0})},[On,k]),Jt=b.useCallback((N,A,Y,te)=>{var Nm;const ae=Y??Me.current;if(!ae)return;const Q=Qt(N),ze=ae===Me.current,Be=(te==null?void 0:te.persist)!==!1;if(A==="replace"){if(Be){const It={threadId:ae,snapshot:Qt(N,{cloneMessages:!0})};Je.current.set(ae,It),ie.current=ae}if(!ze)return;Ke(Q.messages,{checkpointId:Q.checkpointId??null,checkpointNs:Q.checkpointNs??null,pendingInterrupt:Q.interrupt??null}),ne(Q.interrupt??null),ye(Q.nextCursor??null),ce(!!Q.nextCursor),M(Q.checkpointId??void 0),oe(Q.checkpointNs??void 0),se(Q.nextCursorNs??void 0);return}const De=Je.current.get(ae),et=(De==null?void 0:De.snapshot)??null,yt=Array.isArray(et==null?void 0:et.messages)?et.messages:[],At=Qt(et),Dn=Array.isArray(N==null?void 0:N.messages)?N.messages:[],_t=new Set,jt=[...Dn,...yt].filter(It=>{const _l=It==null?void 0:It.id;return _l?_t.has(_l)?!1:(_t.add(_l),!0):!0}),jo=Gc(At,Q),Ro={checkpointId:At.checkpointId??Q.checkpointId??null,checkpointNs:At.checkpointNs??Q.checkpointNs??null,createdAt:Q.createdAt??At.createdAt??null,parentId:Q.parentId??At.parentId??null,branchLabel:Q.branchLabel??At.branchLabel??null,lastMessageId:((Nm=jt[jt.length-1])==null?void 0:Nm.id)??null,messagesLen:jt.length,hasMessages:jt.length>0,messages:jt,nextCursor:Q.nextCursor??At.nextCursor??null,nextCursorNs:Q.nextCursorNs??At.nextCursorNs??null,interrupt:At.interrupt??Q.interrupt??null,...jo};if(Je.current.set(ae,{threadId:ae,snapshot:Qt(Ro,{cloneMessages:!0})}),!ze)return;Dn.length&&ot(Dn);const Ln=N&&Object.prototype.hasOwnProperty.call(N,"checkpointId")?N.checkpointId:void 0,Po=N&&Object.prototype.hasOwnProperty.call(N,"checkpointNs")?N.checkpointNs:void 0,Fn=N&&Object.prototype.hasOwnProperty.call(N,"nextCursor")?N.nextCursor:void 0,Al=N&&Object.prototype.hasOwnProperty.call(N,"nextCursorNs")?N.nextCursorNs:void 0;ye(It=>Fn!==void 0?Fn??It??null:It??null),ce(It=>Fn!==void 0?!!Fn:It),M(It=>Ln!==void 0?Ln??It??void 0:It??void 0),oe(It=>Po!==void 0?Po??It??void 0:It??void 0),se(It=>Al!==void 0?Al??void 0:It)},[ot,Ke,ne]),Tr=b.useCallback(N=>{if(N.threadId!=null&&N.threadId!==Me.current)return;const A=Qt(N.snapshot,{cloneMessages:!0});Ke(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),ne(A.interrupt??null),ye(A.nextCursor??null),ce(!!A.nextCursor),M(A.checkpointId??void 0),oe(A.checkpointNs??void 0),se(A.nextCursorNs??void 0),ie.current=N.threadId,Tt(N.threadId??Me.current??null)},[Ke,ne,Tt]),Mn=b.useCallback(N=>{if(!N)return;Je.current.delete(N),x(N),qe.current.delete(N),nt.current.delete(N),N===Me.current&&B([]);const A=`${N}__`;for(const Y of Oe.current.keys())Y.startsWith(A)&&Oe.current.delete(Y);for(const Y of Xe.current.keys())Y.startsWith(A)&&Xe.current.delete(Y);ie.current===N&&(ie.current=null)},[x]),wn=b.useCallback(()=>{const N=Me.current;N&&Mn(N),tt([]),ce(!1),Z(!1),ye(null),M(void 0),oe(void 0),se(void 0)},[Mn,tt]),Un=b.useCallback(({from:N,to:A})=>{const Y=Me.current;Y&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${A}) for thread ${Y}`)},[]),Er=b.useCallback(N=>{const A=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:A,title:N.title,created:N.created,currentThreads:k.length});const Y={threadId:A,title:N.title||`Thread ${A.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};Me.current!==A&&(!Me.current&&re.messages.length<=1&&(dt.current=A),E(A)),b.startTransition(()=>{T(te=>{const ae=te.byId[A];return ae?ae.title===Y.title&&ae.updatedAt===Y.updatedAt&&ae.messageCount===Y.messageCount?te:{byId:{...te.byId,[A]:Y},order:te.order}:{byId:{...te.byId,[A]:Y},order:[A,...te.order]}})})},[re.messages.length]),{startStream:Wr,stop:Vr,isStreaming:or,error:I,setAuthToken:U}=_x({baseUrl:u,onThreadInfo:Er,onMessageEvent:ht,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:Un});b.useEffect(()=>{Pn.current=or},[or]),b.useEffect(()=>{if(!cr())return;pt.current!==null&&(window.clearTimeout(pt.current),pt.current=null);const N=k.map(Y=>`${Y.threadId}:${Y.updatedAt??""}:${Y.messageCount??""}`).join("|");if(k.length===0){try{Hi(g)}catch{}vn.current="";return}if(N===vn.current)return;const A=()=>{try{const Y=k.slice(0,Ui);Vi(g,Y),vn.current=N}catch{}finally{pt.current=null}};return pt.current=window.setTimeout(()=>{Hc(A),pt.current=null},Xo),()=>{pt.current!==null&&(window.clearTimeout(pt.current),pt.current=null)}},[k,On]),b.useEffect(()=>{var te;const N=l.getAuthToken();U(N);const A=ae=>{const Q=Wi(f,ae);ke.current!==Q&&(ke.current=Q,je.current=!1),w(Q);const ze=Ki(Q);b.startTransition(()=>{T(Jo(ze))}),ae&&!je.current&&(je.current=!0)};A(N);const Y=(te=l.onTokenChange)==null?void 0:te.call(l,ae=>{ae!==N&&(U(ae),v(),Oe.current.clear(),Xe.current.clear(),A(ae))});return()=>{Y==null||Y()}},[l,f,U,v]);const le=b.useCallback(async N=>{var te;const A=`Thread ${(te=crypto.randomUUID)==null?void 0:te.call(crypto)}`,Y={threadId:A,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};T(ae=>({byId:{...ae.byId,[A]:Y},order:[A,...ae.order]})),E(A);try{const ae=await l.createThread(N),Q=typeof ae=="string"?ae:ae.threadId;return T(ze=>{const Be=ze.byId[A];if(!Be)return ze;const De={...ze.byId};delete De[A],De[Q]={...Be,threadId:Q};const et=ze.order.map(yt=>yt===A?Q:yt);return{byId:De,order:et}}),E(Q),setTimeout(()=>Dt(),10),P(null),Q}catch(ae){throw T(Q=>{if(!Q.byId[A])return Q;const ze={...Q.byId};delete ze[A];const Be=Q.order.filter(De=>De!==A);return{byId:ze,order:Be}}),E(null),P(String(ae)),ae}},[l,Dt]),Ce=b.useCallback(async N=>{try{await l.deleteThread(N);let A=null;T(Y=>{if(!Y.byId[N])return Y;const te={...Y.byId};delete te[N];const ae=Y.order.filter(ze=>ze!==N),Q={byId:te,order:ae};return A=qi(Q),Q}),A&&On(A,{immediate:!0}),Mn(N),Me.current===N&&(dt.current=N,E(null),Me.current=null,ie.current=null,wn()),await Dt(),P(null)}catch(A){throw P(String(A)),A}},[l,wn,Mn,Dt,On]),Ge=b.useCallback(async(N,A)=>{try{await l.updateThread(N,A),T(Y=>{const te=Y.byId[N];return te?{byId:{...Y.byId,[N]:{...te,title:A}},order:Y.order}:Y}),P(null)}catch(Y){throw await Dt(),P(String(Y)),Y}},[l,Dt]),$e=b.useCallback(async(N,A,Y,te=!1)=>{await Xt(async()=>{if(dt.current===N&&!te){dt.current=null;return}if(xt.current===N&&!te)return;E(_t=>_t===N?_t:N),Me.current=N;const ze=qc(N,A??null,Y??null),Be=Xe.current.get(ze),De=!te&&!A&&!Y&&Be&&Date.now()-Be.timestamp<Vx,et=!te&&!A&&!Y;let yt=!1;if(et){const _t=Je.current.get(N);if(_t)Tr(_t),yt=!0;else{const jt=p(N);jt&&(Je.current.set(N,jt),Tr(jt),yt=!0)}}const At=te||!yt||!!A||!!Y,Dn=async _t=>{_t&&$(!0),xt.current=N;try{const jt=await rr({threadId:N,checkpointId:A,checkpointNs:Y},{force:te}),{latest:jo,checkpoints:Ro,snapshots:Ln}=Oi(jt);Jt(jo,"replace",N),Yt(N,Ro,"replace"),Et(N,Ln,"replace"),L(null)}catch(jt){throw(!yt||te||_t)&&(i==null||i(String(jt))),L(String(jt)),jt}finally{xt.current=null,_t&&$(!1)}};At?await Dn(!0):et&&yt&&!De&&Dn(!1).catch(_t=>{console.warn("[ChatSessionProvider] Background refresh failed:",_t)})},`loadThread-${N}`)},[Tr,Jt,Xt,rr,i,Yt,Et]),Fe=b.useCallback(async()=>{await Xt(async()=>{const N=Me.current;N&&Mn(N),dt.current=null,E(null),Me.current=null,ie.current=null,wn(),M(void 0),oe(void 0),se(void 0),B([]);try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[wn,Mn,Xt]),z=b.useCallback(async(N,A)=>{var Q;const Y=Me.current;if(!Y)throw new Error("No active thread");const te=Qr(N,A??null),ae=(Q=nt.current.get(Y))==null?void 0:Q.get(te);if(ae){await Xt(async()=>{Jt(ae,"replace",Y,{persist:!1})},`navigateToCheckpoint-${Y}-${te}`);return}await $e(Y,N,A??void 0,!0)},[Jt,Xt,$e]),ue=b.useCallback(async()=>{if(!Me.current)throw new Error("No active thread");await $e(Me.current,void 0,void 0,!0)},[$e]),me=b.useCallback(async()=>{if(!Me.current)throw new Error("No active thread");if(H||!W)return;const N=we;if(N){Z(!0);try{const A=Me.current,Y=await rr({threadId:A,checkpointId:N??G??null,checkpointNs:xe??X??null}),{latest:te,checkpoints:ae,snapshots:Q}=Oi(Y),ze=A?nt.current.get(A):null;let Be=ae.length>0;if(Be&&ze&&ze.size>0&&(Be=ae.some(De=>{if(!(De!=null&&De.checkpointId))return!1;const et=Qr(De.checkpointId,De.checkpointNs??null);return!ze.has(et)})),!Be){ye(null),se(void 0),ce(!1),L(null);return}Jt(te,"prepend",A??void 0),A&&(Yt(A,ae,"prepend"),Et(A,Q,"prepend")),L(null)}catch(A){throw L(String(A)),A}finally{Z(!1)}}},[Jt,rr,W,G,X,xe,we,H,Yt,Et]),Re=b.useCallback(N=>{if(N!=null&&N.threadId){if(N.checkpointId){const A=Qr(N.checkpointId,N.checkpointNs??null),Y=Qt({...N,interrupt:N.interrupt??null},{cloneMessages:!0});Et(N.threadId,{[A]:Y},"prepend")}Jt(N,"replace",N.threadId)}},[Jt,Et]),rt=b.useCallback(async(N,A)=>{var Po;const Y=Me.current,te=(N==null?void 0:N.text)??"",ae=(N==null?void 0:N.attachments)??[],Q=ae.length?ae:(A==null?void 0:A.attachments)??[],ze={...(A==null?void 0:A.payloadExtras)??{},...(N==null?void 0:N.payload)??{}};if(!Y&&!Object.keys(ze).length&&Q.length===0&&!te.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:De}=await sx(l,Q),et=[...Be];te&&te.trim()&&et.push({type:"text",text:te.trim()});const yt=!!Y,At=yt?(A==null?void 0:A.checkpointId)??re.lastCheckpointId??void 0:void 0,Dn=yt?(A==null?void 0:A.checkpointNs)??re.lastCheckpointNs??void 0:void 0,_t={id:((Po=crypto.randomUUID)==null?void 0:Po.call(crypto))||`user-${Date.now()}`,role:"user",content:et,createdAt:new Date().toISOString(),...At!=null?{checkpointId:At}:{},...Dn!=null?{checkpointNs:Dn}:{}};et.length>0&&at(_t);const jt={..._t,content:et},jo=Q.length>0,Ro={messages:et.length>0?[jt]:[],files_info:De,...o&&jo&&s?{active_agent:s}:{},...ze},Ln={threadId:Y??null,payload:Ro,checkpointId:At??null,checkpointNs:Dn??null,nodeFilter:(A==null?void 0:A.nodeFilter)??null,config:A==null?void 0:A.config,command:(A==null?void 0:A.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})=>{!Me.current&&Fn&&(re.messages.length<=1&&(dt.current=Fn),E(Fn))},onGap:Un})},[l,o,s,Un,re.lastCheckpointId,re.lastCheckpointNs,re.messages.length,at,Wr]),Lt=b.useCallback(async(N,A,Y)=>{if(!Me.current)throw new Error("No active thread to handle interrupt");const ae=A?Y??!0:!1;try{try{Ue({type:"interrupt_response",payload:{interruptId:N}})}catch(Q){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Q)}await rt({payload:{}},{checkpointId:re.lastCheckpointId??void 0,checkpointNs:re.lastCheckpointNs??void 0,command:{kind:"resume",value:ae}}),ne(null)}catch(Q){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,Q),Q}},[Ue,re.lastCheckpointId,re.lastCheckpointNs,rt]);b.useEffect(()=>{if(a==null||a(C),C)try{localStorage.setItem("lastThreadId",C)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[C,a]),b.useEffect(()=>((async()=>{try{if(Dt().catch(A=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",A),i==null||i(String(A))}),!r&&!t)try{const A=localStorage.getItem("lastThreadId");A&&(E(A),n&&await $e(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await $e(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),b.useEffect(()=>{const N=Me.current;if(!N||ie.current!==N)return;re.messages.length&&re.messages[re.messages.length-1];const A=Qt({checkpointId:re.lastCheckpointId??null,checkpointNs:re.lastCheckpointNs??null,messages:re.messages.slice(),nextCursor:we??null,nextCursorNs:xe??null,interrupt:re.pendingInterrupt??F??null}),Y=Je.current.get(N),te=Y==null?void 0:Y.snapshot,ae=!te||te.messages.length!==A.messages.length||te.messages.some((De,et)=>{var yt;return(De==null?void 0:De.id)!==((yt=A.messages[et])==null?void 0:yt.id)}),Q=((te==null?void 0:te.checkpointId)??null)!==A.checkpointId||((te==null?void 0:te.checkpointNs)??null)!==A.checkpointNs,ze=((te==null?void 0:te.nextCursor)??null)!==A.nextCursor||((te==null?void 0:te.nextCursorNs)??null)!==A.nextCursorNs,Be=!Bc((te==null?void 0:te.interrupt)??null,A.interrupt??null);if(ae||Q||ze||Be){const De={threadId:N,snapshot:A};Je.current.set(N,De),yn.current&&window.clearTimeout(yn.current),yn.current=window.setTimeout(()=>{try{m(De,100)}catch(et){console.warn("[ChatSessionProvider] Failed to persist thread payload:",et)}},Xo)}},[we,xe,re.lastCheckpointId,re.lastCheckpointNs,re.messages,re.pendingInterrupt,F,m]);const an=b.useMemo(()=>({threads:k,currentThreadId:C,setCurrentThreadId:E,isLoading:_,error:q,actions:{createThread:le,deleteThread:Ce,renameThread:Ge,refreshThreads:()=>Dt()},persistThreadsCache:kr,hydrateFromCache:pe}),[k,C,_,q,le,Ce,Ge,Dt,kr,pe,E]),Ct=b.useMemo(()=>{const N=re.lastBranch??null,A=re.assemblingId??null,Y=N||A?{branchLabel:(N==null?void 0:N.branchLabel)??null,lastBranch:N,assemblingMessageId:A}:null;return{threadId:C,messages:re.messages,interrupt:F,checkpoint:{id:re.lastCheckpointId??null,namespace:re.lastCheckpointNs??null},checkpoints:K,metadata:Y,isLoading:D,isHistoryLoading:H,error:R,hasMore:W,loadOlder:me,seedFromSnapshot:Re,clearState:wn,navigateToCheckpoint:z,returnToLatest:ue,loadThread:$e,clearThread:Fe,respondToInterrupt:Lt}},[Fe,wn,C,F,W,H,D,me,$e,re.assemblingId,re.lastBranch,re.lastCheckpointId,re.lastCheckpointNs,re.messages,z,Lt,ue,Re,R,K]),_o=b.useMemo(()=>({isStreaming:or,error:I,submit:rt,send:rt,stop:Vr,setAuthToken:U}),[or,I,rt,Vr,U]);return d.jsx(Wx.Provider,{value:!0,children:d.jsx(Vc.Provider,{value:_o,children:d.jsx(Uc.Provider,{value:an,children:d.jsx(Wc.Provider,{value:Ct,children:e})})})})}function Qo(){const e=b.useContext(Uc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function es(){const e=b.useContext(Wc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Yc(){const e=b.useContext(Vc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function ts({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 d.jsx(rx,{apiConfig:t,children:d.jsx(Yx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function ee(...e){return Rm.twMerge(jm.clsx(e))}const Xx=Oo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ze=y.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?sr.Slot:"button";return d.jsx(i,{className:ee(Xx({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";const Xc=y.forwardRef(({className:e,...t},n)=>d.jsx("textarea",{className:ee("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}));Xc.displayName="Textarea";function Jx({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:u,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const m=i!==void 0,[x,v]=b.useState(e),g=(m?i:x)??"",[w,S]=b.useTransition(),T=b.useRef(null),k=b.useRef(0),C=b.useRef(null);b.useEffect(()=>{m||(v(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,m]);const E=b.useCallback(()=>{const L=T.current;L&&(L.style.height="auto",L.style.height=`${L.scrollHeight}px`)},[]);b.useEffect(()=>{E()},[E,g]);const _=b.useCallback((L,{fromUser:F})=>{m||v(L),F&&(a==null||a(L))},[m,a]),j=b.useCallback(async L=>{L&&L.preventDefault();const F=(g??"").trim();if(!F&&!p)return;const ne=++k.current;C.current={id:ne,shouldClear:!0},S(()=>{var K,B,pe;try{const W=l(F);W&&typeof W.then=="function"?W.then(()=>{var ce,H;((ce=C.current)==null?void 0:ce.id)===ne&&C.current.shouldClear&&(m||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((H=C.current)==null?void 0:H.id)===ne&&(C.current=null)}).catch(()=>{var ce;((ce=C.current)==null?void 0:ce.id)===ne&&(C.current=null)}):(((K=C.current)==null?void 0:K.id)===ne&&C.current.shouldClear&&(m||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((B=C.current)==null?void 0:B.id)===ne&&(C.current=null))}catch{((pe=C.current)==null?void 0:pe.id)===ne&&(C.current=null)}})},[g,l,p,m,a]),D=b.useCallback(L=>{const F=L.target.value;_(F,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[_]),$=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 d.jsx("form",{onSubmit:L=>void j(L),className:`w-full ${f}`,children:d.jsxs("div",{className:"flex items-end gap-2",children:[d.jsx("div",{className:"flex-1",children:d.jsx(Xc,{ref:T,value:g,onChange:D,onKeyDown:$,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),d.jsx("div",{children:r?d.jsx(Ze,{type:"button",onClick:()=>{u==null||u()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!u,children:d.jsx(fe.Square,{size:16})}):d.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!p||w,children:d.jsx(fe.Send,{size:16})})})]})})}const Zx=b.memo(Jx),ns=0,Vn=1,_r=2,Jc=4;function Zc(e){return()=>e}function Qx(e){e()}function Qc(e,t){return n=>e(t(n))}function eu(e,t){return()=>e(t)}function ey(e,t){return n=>e(t,n)}function Yi(e){return e!==void 0}function ty(...e){return()=>{e.map(Qx)}}function jr(){}function rs(e,t){return t(e),e}function ny(e,t){return t(e)}function ct(...e){return e}function Qe(e,t){return e(Vn,t)}function Pe(e,t){e(ns,t)}function Xi(e){e(_r)}function gt(e){return e(Jc)}function ve(e,t){return Qe(e,ey(t,ns))}function dn(e,t){const n=e(Vn,r=>{n(),t(r)});return n}function tu(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function nu(e,t){return e===t}function ut(e=nu){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ee(e){return t=>n=>{e(n)&&t(n)}}function de(e){return t=>Qc(t,e)}function Sn(e){return t=>()=>{t(e)}}function V(e,...t){const n=ry(...t);return(r,o)=>{switch(r){case _r:Xi(e);return;case Vn:return Qe(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 Le(...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);Qe(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 ry(...e){return t=>e.reduceRight(ny,t)}function oy(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=Qe(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 ns:t=o;break;case Vn:{o(t);break}case Jc:return t}return n(r,o)}}function Pt(e,t){return rs(J(t),n=>ve(e,n))}function Ve(){const e=[];return(t,n)=>{switch(t){case ns: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 rs(Ve(),t=>ve(e,t))}function Ye(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:sy(),singleton:n}}const sy=()=>Symbol();function iy(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 wt(...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);Qe(s,l=>{n[i]=l,r=r|a,r===o&&Pe(t,n)})}),function(s,i){switch(s){case _r:{Xi(t);return}case Vn:return r===o&&i(n),Qe(t,i)}}}function Te(e,t=nu){return V(e,ut(t))}function Ji(...e){return function(t,n){switch(t){case _r:return;case Vn:return ty(...e.map(r=>Qe(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 ay={0:"debug",3:"error",1:"log",2:"warn"},ly=()=>typeof globalThis>"u"?window:globalThis,Kn=Ye(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=ly().VIRTUOSO_LOG_LEVEL)!=null?o:gt(e);r>=s&&console[ay[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 Zi(e,t,n).callbackRef}function Zi(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 cy(e,t,n,r,o,s,i,a,l){const c=b.useCallback(u=>{const f=uy(u.children,t,a?"offsetWidth":"offsetHeight",o);let h=u.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let m;p&&(m=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(x,0),viewportHeight:g}),s==null||s(a?ru("column-gap",getComputedStyle(u).columnGap,o):ru("row-gap",getComputedStyle(u).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Zi(c,n,l)}function uy(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),u=t(a,n);if(u===0&&r("Zero-sized element, this should not happen",{child:a},Ut.ERROR),u===c)continue;const f=s[s.length-1];s.length===0||f.size!==u||f.endIndex!==l-1?s.push({endIndex:l,size:u,startIndex:l}):s[s.length-1].endIndex++}return s}function ru(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 ou(e,t,n){const r=b.useRef(null),o=b.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),u=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+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:u},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Zi(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=Ye(()=>{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),u=J(0),f=Ve(),h=Ve(),p=J(!1),m=J(!1),x=J(!1);return ve(V(e,de(({scrollTop:v})=>v)),t),ve(V(e,de(({scrollHeight:v})=>v)),i),ve(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:u,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),to={lvl:0};function su(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 st(e){return e===to}function no(e,t){if(!st(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(st(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 st(e)?lu(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?cu(bt(e,{l:Vt(e.l,t,n)})):cu(bt(e,{r:Vt(e.r,t,n)}))}function Rr(){return to}function os(e,t,n){if(st(e))return[];const r=fn(e,t)[0];return dy(ea(e,r,n))}function Qi(e,t){if(st(e))return to;const{k:n,l:r,r:o}=e;if(t===n){if(st(r))return o;if(st(o))return r;{const[s,i]=au(r);return ss(bt(e,{k:s,l:iu(r),v:i}))}}else return t<n?ss(bt(e,{l:Qi(r,t)})):ss(bt(e,{r:Qi(o,t)}))}function fr(e){return st(e)?[]:[...fr(e.l),{k:e.k,v:e.v},...fr(e.r)]}function ea(e,t,n){if(st(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ea(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ea(s,t,n))),a}function ss(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(ta(t))return uu(bt(e,{lvl:n-1}));if(!st(t)&&!st(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(ta(e))return na(bt(e,{lvl:n-1}));if(!st(r)&&!st(r.l)){const o=r.l,s=ta(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:na(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return lu(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 iu(e){return st(e.r)?e.l:ss(bt(e,{r:iu(e.r)}))}function ta(e){return st(e)||e.lvl>e.r.lvl}function au(e){return st(e.r)?[e.k,e.v]:au(e.r)}function lu(e,t,n,r=to,o=to){return{k:e,l:r,lvl:n,r:o,v:t}}function cu(e){return na(uu(e))}function uu(e){const{l:t}=e;return!st(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function na(e){const{lvl:t,r:n}=e;return!st(n)&&!st(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function dy(e){return su(e,({k:t,v:n})=>({index:t,value:n}))}function du(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 ra=Ye(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function fu(e,t,n){return e[is(e,t,n)]}function is(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 fy(e,t,n,r){const o=is(e,t,r),s=is(e,n,r,o);return e.slice(o,s+1)}function qn(e,t){return Math.round(e.getBoundingClientRect()[t])}function as(e){return!st(e.groupOffsetTree)}function oa({index:e},t){return t===e?0:t<e?-1:1}function hy(){return{groupIndices:[],groupOffsetTree:Rr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Rr()}}function py(e,t){let n=st(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),st(e)){e=Vt(e,0,s);continue}const a=os(e,i-1,o+1);if(a.some(by(r)))continue;let l=!1,c=!1;for(const{end:u,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Qi(e,f)):(c=h!==s,l=!0),u>o&&o>=f&&h!==s&&(e=Vt(e,o+1,h));c&&(e=Vt(e,i,s))}return[e,n]}function my(e){return typeof e.groupIndex<"u"}function gy({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}=fu(t,e,oa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function hu(e,t){if(!as(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function pu(e,t,n){if(my(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=hu(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function xy(e,t,n,r=0){return r>0&&(t=Math.max(t,fu(e,r,oa).offset)),su(fy(e,t,n,gy),wy)}function yy(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&&st(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,x)=>Vt(Vt(m,x,h),x+1,p),i)}else[i,a]=py(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:u,offsetTree:f}=sa(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:u,offsetTree:f,sizeTree:i}}function vy(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 mu(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 sa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=is(o,t-1,oa),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:u}of os(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:u}),s=c,a=h,i=u}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function wy(e){return{index:e.index,value:e}}function by(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 Sy={offsetHeight:"height",offsetWidth:"width"},kn=Ye(([{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),u=J(void 0),f=J((k,C)=>qn(k,Sy[C])),h=J(void 0),p=J(0),m=hy(),x=Pt(V(n,Le(l,e,p),Cn(yy,m),ut()),m),v=Pt(V(l,ut(),Cn((k,C)=>({current:C,prev:k.current}),{current:[],prev:[]}),de(({prev:k})=>k)),[]);ve(V(l,Ee(k=>k.length>0),Le(x,p),de(([k,C,E])=>{const _=k.reduce((j,D,$)=>Vt(j,D,oo(D,C.offsetTree,E)||$),Rr());return{...C,groupIndices:k,groupOffsetTree:_}})),x),ve(V(r,Le(x),Ee(([k,{lastIndex:C}])=>k<C),de(([k,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:k}])),n),ve(c,u);const g=Pt(V(c,de(k=>k===void 0)),!0);ve(V(u,Ee(k=>k!==void 0&&st(gt(x).sizeTree)),de(k=>[{endIndex:0,size:k,startIndex:0}])),n);const w=Wt(V(n,Le(x),Cn(({sizes:k},[C,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:m}),de(k=>k.changed)));Qe(V(a,Cn((k,C)=>({diff:k.prev-C,prev:C}),{diff:0,prev:0}),de(k=>k.diff)),k=>{const{groupIndices:C}=gt(x);if(k>0)Pe(t,!0),Pe(s,k+mu(k,C));else if(k<0){const E=gt(v);E.length>0&&(k-=mu(-k,E)),Pe(i,k)}}),Qe(V(a,Le(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);ve(V(s,Le(x),de(([k,C])=>{const E=C.groupIndices.length>0,_=[],j=C.lastSize;if(E){const D=no(C.sizeTree,0);let $=0,q=0;for(;$<k;){const R=C.groupIndices[q],L=C.groupIndices.length===q+1?1/0:C.groupIndices[q+1]-R-1;_.push({endIndex:R,size:D,startIndex:R}),_.push({endIndex:R+1+L-1,size:j,startIndex:R+1}),q++,$+=L+1}const P=fr(C.sizeTree);return $!==k&&P.shift(),P.reduce((R,{k:L,v:F})=>{let ne=R.ranges;return R.prevSize!==0&&(ne=[...R.ranges,{endIndex:L+k-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:L+k,prevSize:F,ranges:ne}},{prevIndex:k,prevSize:0,ranges:_}).ranges}return fr(C.sizeTree).reduce((D,{k:$,v:q})=>({prevIndex:$+k,prevSize:q,ranges:[...D.ranges,{endIndex:$+k-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const T=Wt(V(i,Le(x,p),de(([k,{offsetTree:C},E])=>{const _=-k;return oo(_,C,E)})));return ve(V(i,Le(x,p),de(([k,C,E])=>{if(C.groupIndices.length>0){if(st(C.sizeTree))return C;let _=Rr();const j=gt(v);let D=0,$=0,q=0;for(;D<-k;){q=j[$];const P=j[$+1]-q-1;$++,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,q);_=Vt(_,0,P);const R=fn(C.sizeTree,-k+1)[1];_=Vt(_,1,R)}return{...C,sizeTree:_,...sa(C.offsetTree,0,_,E)}}else{const _=fr(C.sizeTree).reduce((j,{k:D,v:$})=>Vt(j,Math.max(0,D+k),$),Rr());return{...C,sizeTree:_,...sa(C.offsetTree,0,_,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:u,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},ct(Kn,ra),{singleton:!0});function Cy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const gu=Ye(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ve(),i=Ve(),a=Wt(V(s,de(Cy)));return ve(V(a,de(l=>l.totalCount)),n),ve(V(a,de(l=>l.groupIndices)),e),ve(V(wt(o,t,r),Ee(([l,c])=>as(c)),de(([l,c,u])=>fn(c.groupOffsetTree,Math.max(l-u,0),"v")[0]),ut(),de(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(kn,Ft)),Gn=Ye(([{log:e}])=>{const t=J(!1),n=Wt(V(t,Ee(r=>r),ut()));return Qe(t,r=>{r&>(e)("props updated",{},Ut.DEBUG)}),{didMount:n,propsReady:t}},ct(Kn),{singleton:!0}),ky=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function xu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ky)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const so=Ye(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:u,viewportHeight:f},{log:h}])=>{const p=Ve(),m=Ve(),x=J(0);let v=null,g=null,w=null;function S(){v&&(v(),v=null),w&&(w(),w=null),g&&(clearTimeout(g),g=null),Pe(l,!1)}return ve(V(p,Le(n,f,r,x,a,i,h),Le(e,s,o),de(([[T,k,C,E,_,j,D,$],q,P,R])=>{const L=xu(T),{align:F,behavior:ne,offset:K}=L,B=E-1,pe=pu(L,k,B);let W=oo(pe,k.offsetTree,q)+j;F==="end"?(W+=P+fn(k.sizeTree,pe)[1]-C+R,pe===B&&(W+=D)):F==="center"?W+=(P+fn(k.sizeTree,pe)[1]-C+R)/2:W-=_,K&&(W+=K);const ce=H=>{S(),H?($("retrying to scroll to",{location:T},Ut.DEBUG),Pe(p,T)):(Pe(m,!0),$("list did not change, scroll successful",{},Ut.DEBUG))};if(S(),ne==="smooth"){let H=!1;w=Qe(t,Z=>{H=H||Z}),v=dn(u,()=>{ce(H)})}else v=dn(V(t,Ty(150)),ce);return g=setTimeout(()=>{S()},1200),Pe(l,!0),$("scrolling from index to",{behavior:ne,index:pe,top:W},Ut.DEBUG),{behavior:ne,top:W}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:x}},ct(kn,Ft,Kn),{singleton:!0});function Ty(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ia(e,t){e==0?t():requestAnimationFrame(()=>{ia(e-1,t)})}function aa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const io=Ye(([{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 ve(V(i,Le(l),Ee(([u,f])=>!!f),Sn(!1)),a),ve(V(i,Le(l),Ee(([u,f])=>!!f),Sn(!1)),c),Qe(V(wt(t,i),Le(a,n,e,c),Ee(([[,u],f,{sizeTree:h},p,m])=>u&&(!st(h)||Yi(p))&&!f&&!m),Le(l)),([,u])=>{dn(o,()=>{Pe(c,!0)}),ia(4,()=>{dn(r,()=>{Pe(a,!0)}),Pe(s,u)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(kn,Ft,so,Gn),{singleton:!0});function yu(e,t){return Math.abs(e-t)<1.01}const ao="up",lo="down",Ey="none",Iy={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ny=0,co=Ye(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=Ve(),c=Ve(),u=J(4),f=J(Ny),h=Pt(V(Ji(V(Te(o),ur(1),Sn(!0)),V(Te(o),ur(1),Sn(!1),tu(100))),ut()),!1),p=Pt(V(Ji(V(n,Sn(!0)),V(n,Sn(!1),tu(200))),ut()),!1);ve(V(wt(Te(o),Te(f)),de(([w,S])=>w<=S),ut()),a),ve(V(a,zn(50)),c);const m=Wt(V(wt(r,Te(s),Te(t),Te(e),Te(u)),Cn((w,[{scrollHeight:S,scrollTop:T},k,C,E,_])=>{const j=T+k-S>-_,D={scrollHeight:S,scrollTop:T,viewportHeight:k};if(j){let q,P;return T>w.state.scrollTop?(q="SCROLLED_DOWN",P=w.state.scrollTop-T):(q="SIZE_DECREASED",P=w.state.scrollTop-T||w.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:P,state:D}}let $;return D.scrollHeight>w.state.scrollHeight?$="SIZE_INCREASED":k<w.state.viewportHeight?$="VIEWPORT_HEIGHT_DECREASING":T<w.state.scrollTop?$="SCROLLING_UPWARDS":$="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:$,state:D}},Iy),ut((w,S)=>w&&w.atBottom===S.atBottom))),x=Pt(V(r,Cn((w,{scrollHeight:S,scrollTop:T,viewportHeight:k})=>{if(yu(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}),Ee(w=>w.changed),de(w=>w.jump)),0);ve(V(m,de(w=>w.atBottom)),i),ve(V(i,zn(50)),l);const v=J(lo);ve(V(r,de(({scrollTop:w})=>w),ut(),Cn((w,S)=>gt(p)?{direction:w.direction,prevScrollTop:S}:{direction:S<w.prevScrollTop?ao:lo,prevScrollTop:S},{direction:lo,prevScrollTop:0}),de(w=>w.direction)),v),ve(V(r,zn(50),Sn(Ey)),v);const g=J(0);return ve(V(h,Ee(w=>!w),Sn(0)),g),ve(V(o,zn(100),Le(h),Ee(([w,S])=>!!S),Cn(([w,S],[T])=>[S,T],[0,0]),de(([w,S])=>S-w)),g),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:u,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:v,scrollVelocity:g}},ct(Ft)),ls="top",cs="bottom",vu="none";function wu(e,t,n){return typeof e=="number"?n===ao&&t===ls||n===lo&&t===cs?e:0:n===ao?t===ls?e.main:e.reverse:t===cs?e.main:e.reverse}function bu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const la=Ye(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ve(),i=J(0),a=J(0),l=J(0),c=Pt(V(wt(Te(r),Te(o),Te(n),Te(s,ro),Te(l),Te(i),Te(t),Te(e),Te(a)),de(([u,f,h,[p,m],x,v,g,w,S])=>{const T=u-w,k=v+g,C=Math.max(h-T,0);let E=vu;const _=bu(S,ls),j=bu(S,cs);return p-=w,p+=h+g,m+=h+g,m-=w,p>u+k-_&&(E=ao),m<u-C+f+j&&(E=lo),E!==vu?[Math.max(T-h-wu(x,ls,E)-_,0),T-C-g+f+wu(x,cs,E)+j]:null}),Ee(u=>u!=null),ut(ro)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Ft),{singleton:!0});function Ay(e,t,n){if(as(t)){const r=hu(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 ca={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function us(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,u=0;if(e.length>0){c=e[0].offset;const x=e[e.length-1];u=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-u;return{bottom:u,firstItemIndex:s,items:Cu(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:Cu(t,o,s),topListHeight:t.reduce((x,v)=>v.size+x,0),totalCount:n}}function Su(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const u of n.groupIndices){if(u-i>=e)break;i++}const a=e+i,l=aa(t,a),c=Array.from({length:a}).map((u,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return us(c,[],a,o,n,r)}function Cu(e,t,n){if(e.length===0)return[];if(!as(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=os(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 u;c.index===a.start?u={index:l,type:"group"}:u={groupIndex:l,index:c.index-(l+1)+n},s.push({...u,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const hr=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:u},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const x=J([]),v=J(0),g=Ve();ve(s.topItemsIndexes,x);const w=Pt(V(wt(p,m,Te(l,ro),Te(o),Te(r),Te(c),u,Te(x),Te(t),Te(n),e),Ee(([C,E,,_,,,,,,,j])=>{const D=j&&j.length!==_;return C&&!E&&!D}),de(([,,[C,E],_,j,D,$,q,P,R,L])=>{const F=j,{offsetTree:ne,sizeTree:K}=F,B=gt(v);if(_===0)return{...ca,totalCount:_};if(C===0&&E===0)return B===0?{...ca,totalCount:_}:Su(B,D,j,P,R,L||[]);if(st(K))return B>0?null:us(Ay(aa(D,_),F,L),[],_,R,F,P);const pe=[];if(q.length>0){const we=q[0],ye=q[q.length-1];let G=0;for(const M of os(K,we,ye)){const X=M.value,oe=Math.max(M.start,we),xe=Math.min(M.end,ye);for(let se=oe;se<=xe;se++)pe.push({data:L==null?void 0:L[se],index:se,offset:G,size:X}),G+=X}}if(!$)return us([],pe,_,R,F,P);const W=q.length>0?q[q.length-1]+1:0,ce=xy(ne,C,E,W);if(ce.length===0)return null;const H=_-1,Z=rs([],we=>{for(const ye of ce){const G=ye.value;let M=G.offset,X=ye.start;const oe=G.size;if(G.offset<C){X+=Math.floor((C-G.offset+R)/(oe+R));const se=X-ye.start;M+=se*oe+se*R}X<W&&(M+=(W-X)*oe,X=W);const xe=Math.min(ye.end,H);for(let se=X;se<=xe&&!(M>=E);se++)we.push({data:L==null?void 0:L[se],index:se,offset:M,size:oe}),M+=oe+R}});return us(Z,pe,_,R,F,P)}),Ee(C=>C!==null),ut()),ca);ve(V(e,Ee(Yi),de(C=>C==null?void 0:C.length)),o),ve(V(w,de(C=>C.topListHeight)),f),ve(f,a),ve(V(w,de(C=>[C.top,C.bottom])),i),ve(V(w,de(C=>C.items)),g);const S=Wt(V(w,Ee(({items:C})=>C.length>0),Le(o,e),Ee(([{items:C},E])=>C[C.length-1].originalIndex===E-1),de(([,C,E])=>[C-1,E]),ut(ro),de(([C])=>C))),T=Wt(V(w,zn(200),Ee(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),de(({items:C})=>C[0].index),ut())),k=Wt(V(w,Ee(({items:C})=>C.length>0),de(({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}}),ut(du)));return{endReached:S,initialItemCount:v,itemsRendered:g,listState:w,rangeChanged:k,startReached:T,topItemsIndexes:x,...h}},ct(kn,gu,la,io,so,co,Gn,ra),{singleton:!0}),ku=Ye(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ve(),i=Pt(V(wt(n,e,r,t,o),de(([a,l,c,u,f])=>a+l+c+u+f.offsetBottom+f.bottom)),0);return ve(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Ft,hr),{singleton:!0}),_y=Ye(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=Pt(V(wt(n,e,t),Ee(([o])=>o),de(([,o,s])=>Math.max(0,o-s)),zn(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Ft,ku),{singleton:!0}),Tu=Ye(()=>({context:J(null)})),jy=({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,Eu=Ye(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const u=Ve();return ve(V(u,Le(t,l,n,s,o,r,a),Le(e),de(([[f,h,p,m,x,v,g,w],S])=>{const{align:T,behavior:k,calculateViewLocation:C=jy,done:E,..._}=f,j=pu(f,h,m-1),D=oo(j,h.offsetTree,S)+x+v,$=D+fn(h.sizeTree,j)[1],q=w+v,P=w+p-g,R=C({itemBottom:$,itemTop:D,locationParams:{align:T,behavior:k,..._},viewportBottom:P,viewportTop:q});return R?E&&dn(V(i,Ee(L=>!L),ur(gt(i)?1:2)),E):E&&E(),R}),Ee(f=>f!==null)),c),{scrollIntoView:u}},ct(kn,Ft,so,hr,Kn),{singleton:!0});function Iu(e){return e?e==="smooth"?"smooth":"auto":!1}const Ry=(e,t)=>typeof e=="function"?Iu(e(t)):t&&Iu(e),Py=Ye(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:u},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=J(!1),x=Ve();let v=null;function g(k){Pe(i,{align:"end",behavior:k,index:"LAST"})}Qe(V(wt(V(Te(t),ur(1)),l),Le(Te(m),s,a,f),de(([[k,C],E,_,j,D])=>{let $=C&&j,q="auto";return $&&(q=Ry(E,_||D),$=$&&!!q),{followOutputBehavior:q,shouldFollow:$,totalCount:k}}),Ee(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:C})=>{v&&(v(),v=null),gt(n)?requestAnimationFrame(()=>{gt(u)("following output to ",{totalCount:C},Ut.DEBUG),g(k)}):v=dn(e,()=>{gt(u)("following output to ",{totalCount:C},Ut.DEBUG),g(k),v=null})});function w(k){const C=dn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(gt(u)("scrolling to bottom due to increased size",{},Ut.DEBUG),g("auto"))});setTimeout(C,100)}Qe(V(wt(Te(m),t,c),Ee(([k,,C])=>k&&C),Cn(({value:k},[,C])=>({refreshed:k===C,value:C}),{refreshed:!1,value:0}),Ee(({refreshed:k})=>k),Le(m,t)),([,k])=>{gt(a)&&w(k!==!1)}),Qe(x,()=>{w(gt(m)!==!1)}),Qe(wt(Te(m),o),([k,C])=>{k&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=J(null),T=Ve();return ve(Ji(V(Te(r),de(k=>{var C;return(C=k==null?void 0:k.length)!=null?C:0})),V(Te(t))),T),Qe(V(wt(V(T,ur(1)),l),Le(Te(S),a,f,h),de(([[k,C],E,_,j,D])=>C&&_&&(E==null?void 0:E({context:D,totalCount:k,scrollingInProgress:j}))),Ee(k=>!!k),zn(0)),k=>{v&&(v(),v=null),gt(n)?requestAnimationFrame(()=>{gt(u)("scrolling into view",{}),Pe(p,k)}):v=dn(e,()=>{gt(u)("scrolling into view",{}),Pe(p,k),v=null})}),{autoscrollToBottom:x,followOutput:m,scrollIntoViewOnChange:S}},ct(kn,co,so,io,Gn,Kn,Ft,Tu,Eu)),Oy=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(V(a,Le(s),Ee(([,l])=>l!==0),Le(o,r,t,n,e),de(([[,l],c,u,f,h,p=[]])=>Su(l,c,u,f,h,p))),i),{}),ct(kn,io,hr,Gn),{singleton:!0}),My=Ye(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return Qe(V(e,Le(r),Ee(([,o])=>o!==0),de(([,o])=>({top:o}))),o=>{dn(V(n,ur(1),Ee(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},ct(Gn,Ft,hr),{singleton:!0}),Nu=Ye(([{scrollVelocity:e}])=>{const t=J(!1),n=Ve(),r=J(!1);return ve(V(e,Le(r,t,n),Ee(([o,s])=>!!s),de(([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}),ut()),t),Qe(V(wt(t,e,n),Le(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(co),{singleton:!0}),ua=Ye(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ve(),r=Ve(),o=Ve(),s=J(!1),i=J(void 0);return ve(V(wt(n,r),de(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:u}])=>({scrollHeight:a,scrollTop:Math.max(0,l-u),viewportHeight:c}))),e),ve(V(t,Le(r),de(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Ft)),Dy=Ye(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ve(),u=J(void 0),f=J(null),h=J(null);return ve(a,f),ve(l,h),Qe(V(c,Le(t,r,i,f,h,n)),([p,m,x,v,g,w,S])=>{const T=vy(m.sizeTree);v&&g!==null&&w!==null&&(x=g.scrollTop-w.offsetTop),x-=S,p({ranges:T,scrollTop:x})}),ve(V(u,Ee(Yi),de(Ly)),o),ve(V(s,Le(u),Ee(([,p])=>p!==void 0),ut(),de(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:u}},ct(kn,Ft,io,Gn,ua));function Ly(e){return{align:"start",index:0,offset:e.scrollTop}}const Fy=Ye(([{topItemsIndexes:e}])=>{const t=J(0);return ve(V(t,Ee(n=>n>=0),de(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(hr));function Au(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const $y=Au(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),zy=Ye(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:u,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const x=Wt(V(l,Le(i),Cn(([,g,w,S],[{bottom:T,items:k,offsetBottom:C,totalCount:E},_])=>{const j=T+C;let D=0;return w===E&&g.length>0&&k.length>0&&(k[0].originalIndex===0&&g[0].originalIndex===0||(D=j-S,D!==0&&(D+=_))),[D,k,E,j]},[0,[],0,0]),Ee(([g])=>g!==0),Le(r,a,n,o,p,m),Ee(([,g,w,S,,,T])=>!T&&!S&&g!==0&&w===ao),de(([[g],,,,,w])=>(w("Upward scrolling compensation",{amount:g},Ut.DEBUG),g))));function v(g){g>0?(Pe(t,{behavior:"auto",top:-g}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-g}))}return Qe(V(x,Le(e,s)),([g,w,S])=>{S&&$y()?Pe(e,w-g):v(-g)}),Qe(V(wt(Pt(s,!1),e,m),Ee(([g,w,S])=>!g&&!S&&w!==0),de(([g,w])=>w),zn(1)),v),ve(V(f,de(g=>({top:-g}))),t),Qe(V(c,Le(h,u),de(([g,{groupIndices:w,lastSize:S,sizeTree:T},k])=>{function C(E){return E*(S+k)}if(w.length===0)return C(g);{let E=0;const _=no(T,0);let j=0,D=0;for(;j<g;){j++,E+=_;let $=w.length===D+1?1/0:w[D+1]-w[D]-1;j+$>g&&(E-=_,$=g-j+1),j+=$,E+=C($),D++}return E}})),g=>{Pe(e,g),requestAnimationFrame(()=>{Pe(t,{top:g}),requestAnimationFrame(()=>{Pe(e,0),Pe(m,!1)})})}),{deviation:e}},ct(Ft,co,hr,kn,Kn,ra)),By=Ye(([e,t,n,r,o,s,i,a,l,c,u])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...u}),ct(la,Oy,Gn,Nu,ku,My,_y,ua,Eu,Kn,Tu)),_u=Ye(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:u,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},x,v,g,{listState:w,topItemsIndexes:S,...T},{scrollToIndex:k},C,{topItemCount:E},{groupCounts:_},j])=>(ve(T.rangeChanged,j.scrollSeekRangeChanged),ve(V(j.windowViewportRect,de(D=>D.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:_,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:u,...g,groupIndices:s,itemSize:i,listState:w,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,...j,...x,sizes:l,...v}),ct(kn,io,Ft,Dy,Py,hr,so,zy,Fy,gu,By));function Hy(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 ds=typeof document<"u"?b.useLayoutEffect:b.useEffect;function ju(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,g){v.propsReady&&Pe(v.propsReady,!1);for(const w of r){const S=v[t.required[w]];Pe(S,g[w])}for(const w of o)if(w in g){const S=v[t.optional[w]];Pe(S,g[w])}v.propsReady&&Pe(v.propsReady,!0)}function c(v){return s.reduce((g,w)=>(g[w]=S=>{const T=v[t.methods[w]];Pe(T,S)},g),{})}function u(v){return i.reduce((g,w)=>(g[w]=oy(v[t.events[w]]),g),{})}const f=b.forwardRef((v,g)=>{const{children:w,...S}=v,[T]=b.useState(()=>rs(iy(e),E=>{l(E,S)})),[k]=b.useState(eu(u,T));ds(()=>{for(const E of i)E in S&&Qe(k[E],S[E]);return()=>{Object.values(k).map(Xi)}},[S,k,T]),ds(()=>{l(T,S)}),b.useImperativeHandle(g,Zc(c(T)));const C=n;return d.jsx(a.Provider,{value:T,children:n?d.jsx(C,{...Hy([...r,...o,...i],S),children:w}):w})}),h=v=>{const g=b.useContext(a);return b.useCallback(w=>{Pe(g[v],w)},[g,v])},p=v=>{const g=b.useContext(a)[v],w=b.useCallback(S=>Qe(g,S),[g]);return b.useSyncExternalStore(w,()=>gt(g),()=>gt(g))},m=v=>{const g=b.useContext(a)[v],[w,S]=b.useState(eu(gt,g));return ds(()=>Qe(g,T=>{T!==w&&S(Zc(T))}),[g,w]),w},x=b.version.startsWith("18")?p:m;return{Component:f,useEmitter:(v,g)=>{const w=b.useContext(a)[v];ds(()=>Qe(w,g),[g,w])},useEmitterValue:x,usePublisher:h}}const Ru=b.createContext(void 0),Pu=b.createContext(void 0),Ou=typeof document<"u"?b.useLayoutEffect:b.useEffect;function da(e){return"self"in e}function Uy(e){return"body"in e}function Mu(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,m,x;const v=h.target;if(Uy(v)||da(v)){const w=da(v)?v:v.defaultView;x=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else x=s?v.scrollLeft:v.scrollTop,p=s?v.scrollWidth:v.scrollHeight,m=s?v.offsetWidth:v.offsetHeight;const g=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:m})};h.suppressFlushSync?g():gi.flushSync(g),a.current!==null&&(x===a.current||x<=0||x===p-m)&&(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 u(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const m=h.behavior==="smooth";let x,v,g;da(p)?(v=Math.max(qn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,g=s?window.scrollX:window.scrollY):(v=p[s?"scrollWidth":"scrollHeight"],x=qn(p,s?"width":"height"),g=p[s?"scrollLeft":"scrollTop"]);const w=v-x;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),yu(x,v)||h.top===g){e({scrollHeight:v,scrollTop:g,viewportHeight:x}),m&&t(!0);return}m?(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:u}}const fa="-webkit-sticky",Du="sticky",ha=Au(()=>{if(typeof document>"u")return Du;const e=document.createElement("div");return e.style.position=fa,e.style.position===fa?fa:Du});function pa(e){return e}const Wy=Ye(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(pa),o=J("div"),s=J(jr),i=(a,l=null)=>Pt(V(n,de(c=>c[a]),ut()),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")}}),Vy=Ye(([e,t])=>({...e,...t}),ct(_u,Wy)),Ky=({height:e})=>d.jsx("div",{style:{height:e}}),qy={overflowAnchor:"none",position:ha(),zIndex:1},Lu={overflowAnchor:"none"},Gy={...Lu,display:"inline-block",height:"100%"},Fu=b.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=en("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),u=Ae("groupContent"),f=Ae("trackItemSizes"),h=Ae("itemSize"),p=Ae("log"),m=en("gap"),x=Ae("horizontalDirection"),{callbackRef:v}=cy(n,h,f,e?jr:a,p,m,o,x,Ae("skipAnimationFrameInResizeObserver")),[g,w]=b.useState(0);ma("deviation",R=>{g!==R&&w(R)});const S=Ae("EmptyPlaceholder"),T=Ae("ScrollSeekPlaceholder")||Ky,k=Ae("ListComponent"),C=Ae("ItemComponent"),E=Ae("GroupComponent"),_=Ae("computeItemKey"),j=Ae("isSeeking"),D=Ae("groupIndices").length>0,$=Ae("alignToBottom"),q=Ae("initialItemFinalLocationReached"),P=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:g!==0?g:$?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:$?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...q?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?d.jsx(S,{...Ot(S,c)}):d.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,F=_(L+t.firstItemIndex,R.data,c);return j?b.createElement(T,{...Ot(T,c),height:R.size,index:R.index,key:F,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:F,style:qy},u(R.index,c)):b.createElement(C,{...Ot(C,c),...Zy(C,R.data),"data-index":L,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:F,style:x?Gy:Lu},D?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),Yy={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Xy={outline:"none",overflowX:"auto",position:"relative"},fs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Jy={position:ha(),top:0,width:"100%",zIndex:1};function Ot(e,t){if(typeof e!="string")return{context:t}}function Zy(e,t){return{item:typeof e=="string"?void 0:t}}const Qy=b.memo(function(){const e=Ae("HeaderComponent"),t=en("headerHeight"),n=Ae("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null}),ev=b.memo(function(){const e=Ae("FooterComponent"),t=en("footerHeight"),n=Ae("HeaderFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null});function $u({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"),u=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=Mu(a,c,l,u,void 0,f);return e("scrollTo",m),e("scrollBy",h),d.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Xy:Yy,...o},tabIndex:0,...i,...Ot(l,s),children:r})})}function zu({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"),u=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=b.useRef(null),m=t("scrollerRef"),{scrollByCallback:x,scrollerRef:v,scrollToCallback:g}=Mu(a,c,l,m,h);return Ou(()=>{var w;return v.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",g),e("scrollBy",x),d.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...u!==0?{height:u+f}:{}},...i,...Ot(l,s),children:r})})}const tv=({children:e})=>{const t=b.useContext(Ru),n=en("viewportHeight"),r=en("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=b.useMemo(()=>Qc(n,l=>qn(l,s?"width":"height")),[n,s]),a=dr(i,!0,Ae("skipAnimationFrameInResizeObserver"));return b.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),d.jsx("div",{"data-viewport-type":"element",ref:a,style:fs(o),children:e})},nv=({children:e})=>{const t=b.useContext(Ru),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=Ae("customScrollParent"),s=ou(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return b.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),d.jsx("div",{"data-viewport-type":"window",ref:s,style:fs(i),children:e})},rv=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...Jy,marginTop:`${n}px`},o=Ae("context");return d.jsx(t,{style:r,...Ot(t,o),children:e})},ov=b.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return d.jsxs(r||t?av:iv,{...e,context:o,children:[n&&d.jsx(rv,{children:d.jsx(Fu,{showTopList:!0})}),d.jsxs(r||t?nv:tv,{children:[d.jsx(Qy,{}),d.jsx(Fu,{}),d.jsx(ev,{})]})]})}),{Component:sv,useEmitter:ma,useEmitterValue:Ae,usePublisher:en}=ju(Vy,{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"}},ov),iv=$u({useEmitter:ma,useEmitterValue:Ae,usePublisher:en}),av=zu({useEmitter:ma,useEmitterValue:Ae,usePublisher:en}),lv=sv;ct(_u,Ye(()=>{const e=J(c=>d.jsxs("td",{children:["Item $",c]})),t=J(null),n=J(c=>d.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=J(null),o=J(null),s=J({}),i=J(pa),a=J(jr),l=(c,u=null)=>Pt(V(s,de(f=>f[c]),ut()),u);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")}})),ha();const Bu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},cv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Hu,floor:hs,max:uo,min:ga,round:Uu}=Math;function Wu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function uv(e){return{...cv,items:e}}function ps(e,t){return e&&e.width===t.width&&e.height===t.height}function dv(e,t){return e&&e.column===t.column&&e.row===t.row}const fv=Ye(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:u,viewportHeight:f},h,p,{didMount:m,propsReady:x},{customScrollParent:v,useWindowScroll:g,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T},k])=>{const C=J(0),E=J(0),_=J(Bu),j=J({height:0,width:0}),D=J({height:0,width:0}),$=Ve(),q=Ve(),P=J(0),R=J(null),L=J({column:0,row:0}),F=Ve(),ne=Ve(),K=J(!1),B=J(0),pe=J(!0),W=J(!1),ce=J(!1);Qe(V(m,Le(B),Ee(([M,X])=>!!X)),()=>{Pe(pe,!1)}),Qe(V(wt(m,pe,D,j,B,W),Ee(([M,X,oe,xe,,se])=>M&&!X&&oe.height!==0&&xe.height!==0&&!se)),([,,,,M])=>{Pe(W,!0),ia(1,()=>{Pe($,M)}),dn(V(c),()=>{Pe(t,[0,0]),Pe(pe,!0)})}),ve(V(ne,Ee(M=>M!=null&&M.scrollTop>0),Sn(0)),E),Qe(V(m,Le(ne),Ee(([,M])=>M!=null)),([,M])=>{M&&(Pe(j,M.viewport),Pe(D,M.item),Pe(L,M.gap),M.scrollTop>0&&(Pe(K,!0),dn(V(c,ur(1)),X=>{Pe(K,!1)}),Pe(l,{top:M.scrollTop})))}),ve(V(j,de(({height:M})=>M)),f),ve(V(wt(Te(j,ps),Te(D,ps),Te(L,(M,X)=>M&&M.column===X.column&&M.row===X.row),Te(c)),de(([M,X,oe,xe])=>({gap:oe,item:X,scrollTop:xe,viewport:M}))),F),ve(V(wt(Te(C),r,Te(L,dv),Te(D,ps),Te(j,ps),Te(R),Te(E),Te(K),Te(pe),Te(B)),Ee(([,,,,,,,M])=>!M),de(([M,[X,oe],xe,se,re,Ue,Ke,,ot,at])=>{const{column:ht,row:tt}=xe,{height:Me,width:We}=se,{width:lt}=re;if(Ke===0&&(M===0||lt===0))return Bu;if(We===0){const Oe=aa(at,M),Xe=Oe+Math.max(Ke-1,0);return uv(Wu(Oe,Xe,Ue))}const xt=Vu(lt,We,ht);let dt,Je;ot?X===0&&oe===0&&Ke>0?(dt=0,Je=Ke-1):(dt=xt*hs((X+tt)/(Me+tt)),Je=xt*Hu((oe+tt)/(Me+tt))-1,Je=ga(M-1,uo(Je,xt-1)),dt=ga(Je,uo(0,dt))):(dt=0,Je=-1);const ie=Wu(dt,Je,Ue),{bottom:je,top:ke}=Ku(re,xe,se,ie),qe=Hu(M/xt),nt=qe*Me+(qe-1)*tt-je;return{bottom:je,itemHeight:Me,items:ie,itemWidth:We,offsetBottom:nt,offsetTop:ke,top:ke}})),_),ve(V(R,Ee(M=>M!==null),de(M=>M.length)),C),ve(V(wt(j,D,_,L),Ee(([M,X,{items:oe}])=>oe.length>0&&X.height!==0&&M.height!==0),de(([M,X,{items:oe},xe])=>{const{bottom:se,top:re}=Ku(M,xe,X,oe);return[re,se]}),ut(ro)),t);const H=J(!1);ve(V(c,Le(H),de(([M,X])=>X||M!==0)),H);const Z=Wt(V(wt(_,C),Ee(([{items:M}])=>M.length>0),Le(H),Ee(([[M,X],oe])=>{const xe=M.items[M.items.length-1].index===X-1;return(oe||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===X)&&xe}),de(([[,M]])=>M-1),ut())),we=Wt(V(Te(_),Ee(({items:M})=>M.length>0&&M[0].index===0),Sn(0),ut())),ye=Wt(V(Te(_),Le(K),Ee(([{items:M},X])=>M.length>0&&!X),de(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),ut(du),zn(0)));ve(ye,p.scrollSeekRangeChanged),ve(V($,Le(j,D,C,L),de(([M,X,oe,xe,se])=>{const re=xu(M),{align:Ue,behavior:Ke,offset:ot}=re;let at=re.index;at==="LAST"&&(at=xe-1),at=uo(0,at,ga(xe-1,at));let ht=xa(X,se,oe,at);return Ue==="end"?ht=Uu(ht-X.height+oe.height):Ue==="center"&&(ht=Uu(ht-X.height/2+oe.height/2)),ot&&(ht+=ot),{behavior:Ke,top:ht}})),l);const G=Pt(V(_,de(M=>M.offsetBottom+M.bottom)),0);return ve(V(T,de(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:ne,scrollBy:i,scrollContainerState:a,scrollHeight:q,scrollTo:l,scrollToIndex:$,scrollTop:c,smoothScrollTargetReached:u,totalCount:C,useWindowScroll:g,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:S,windowViewportRect:T,...p,gridState:_,horizontalDirection:ce,initialTopMostItemIndex:B,totalListHeight:G,...h,endReached:Z,propsReady:x,rangeChanged:ye,startReached:we,stateChanged:F,stateRestoreInProgress:K,...k}},ct(la,Ft,co,Nu,Gn,ua,Kn));function Vu(e,t,n){return uo(1,hs((e+n)/(hs(t)+n)))}function Ku(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=xa(e,t,n,r[0].index);return{bottom:xa(e,t,n,r[r.length-1].index)+o,top:s}}function xa(e,t,n,r){const o=Vu(e.width,n.width,t.column),s=hs(r/o),i=s*n.height+uo(0,s-1)*t.row;return i>0?i+t.row:i}const hv=Ye(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(pa),i=J("div"),a=J(jr),l=(f,h=null)=>Pt(V(t,de(p=>p[f]),ut()),h),c=J(!1),u=J(!1);return ve(Te(u),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:u,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),pv=Ye(([e,t])=>({...e,...t}),ct(fv,hv)),mv=b.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=tn("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),u=ft("context"),f=tn("itemDimensions"),h=tn("gap"),p=ft("log"),m=ft("stateRestoreInProgress"),x=tn("reportReadyState"),v=dr(b.useMemo(()=>g=>{const w=g.parentElement.parentElement.scrollHeight;i(w);const S=g.firstChild;if(S){const{height:T,width:k}=S.getBoundingClientRect();f({height:T,width:k})}h({column:Gu("column-gap",getComputedStyle(g).columnGap,p),row:Gu("row-gap",getComputedStyle(g).rowGap,p)})},[i,f,h,p]),!0,!1);return Ou(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),m?null:d.jsx(l,{className:t,ref:v,...Ot(l,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const w=o(g.index,g.data,u);return s?d.jsx(c,{...Ot(c,u),height:e.itemHeight,index:g.index,width:e.itemWidth},w):b.createElement(a,{...Ot(a,u),className:n,"data-index":g.index,key:w},r(g.index,g.data,u))})})}),gv=b.memo(function(){const e=ft("HeaderComponent"),t=tn("headerHeight"),n=ft("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,!1),o=ft("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null}),xv=b.memo(function(){const e=ft("FooterComponent"),t=tn("footerHeight"),n=ft("headerFooterTag"),r=dr(b.useMemo(()=>s=>{t(qn(s,"height"))},[t]),!0,!1),o=ft("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...Ot(e,o)})}):null}),yv=({children:e})=>{const t=b.useContext(Pu),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]),d.jsx("div",{ref:o,style:fs(!1),children:e})},vv=({children:e})=>{const t=b.useContext(Pu),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=ft("customScrollParent"),s=ou(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]),d.jsx("div",{ref:s,style:fs(!1),children:e})},wv=b.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?Sv:bv,o=n||t?vv:yv,s=ft("context");return d.jsx(r,{...e,...Ot(r,s),children:d.jsxs(o,{children:[d.jsx(gv,{}),d.jsx(mv,{}),d.jsx(xv,{})]})})}),{useEmitter:qu,useEmitterValue:ft,usePublisher:tn}=ju(pv,{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"}},wv),bv=$u({useEmitter:qu,useEmitterValue:ft,usePublisher:tn}),Sv=zu({useEmitter:qu,useEmitterValue:ft,usePublisher:tn});function Gu(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 Cv=Oo.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 Yu({className:e,variant:t,...n}){return d.jsx("div",{className:ee(Cv({variant:t}),e),...n})}const fo=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));fo.displayName="Card";const ho=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("flex flex-col space-y-1.5 p-6",e),...t}));ho.displayName="CardHeader";const po=y.forwardRef(({className:e,...t},n)=>d.jsx("h3",{ref:n,className:ee("text-2xl font-semibold leading-none tracking-tight",e),...t}));po.displayName="CardTitle";const Xu=y.forwardRef(({className:e,...t},n)=>d.jsx("p",{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));Xu.displayName="CardDescription";const mo=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("p-6 pt-0",e),...t}));mo.displayName="CardContent";const Ju=y.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:ee("flex items-center p-6 pt-0",e),...t}));Ju.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 kv(e,t){const n=y.createContext(t),r=s=>{const{children:i,...a}=s,l=y.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=y.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=y.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:h,children:p,...m}=f,x=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,v=y.useMemo(()=>m,Object.values(m));return d.jsx(x.Provider,{value:v,children:p})};c.displayName=s+"Provider";function u(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,m=y.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,u]}const o=()=>{const s=n.map(i=>y.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return y.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Tv(o,...t)]}function Tv(...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 y.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var kt=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Ev=y[" useInsertionEffect ".trim().toString()]||kt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Iv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const u=y.useRef(e!==void 0);y.useEffect(()=>{const f=u.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.`),u.current=a},[a,r])}const c=y.useCallback(u=>{var f;if(a){const h=Nv(u)?u(e):u;h!==e&&((f=i.current)==null||f.call(i,h))}else s(u)},[a,e,s,i]);return[l,c]}function Iv({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),o=y.useRef(n),s=y.useRef(t);return Ev(()=>{s.current=t},[t]),y.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Nv(e){return typeof e=="function"}function Zu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ya(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Zu(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():Zu(e[o],null)}}}}function He(...e){return y.useCallback(ya(...e),e)}var Av=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ie=Av.reduce((e,t)=>{const n=sr.createSlot(`Primitive.${t}`),r=y.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Qu(e,t){e&&Mo.flushSync(()=>e.dispatchEvent(t))}function _v(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Kt=e=>{const{present:t,children:n}=e,r=jv(t),o=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),s=He(r.ref,Rv(o));return typeof n=="function"||r.isPresent?y.cloneElement(o,{ref:s}):null};Kt.displayName="Presence";function jv(e){const[t,n]=y.useState(),r=y.useRef(null),o=y.useRef(e),s=y.useRef("none"),i=e?"mounted":"unmounted",[a,l]=_v(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{const c=ms(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,u=o.current;if(u!==e){const h=s.current,p=ms(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),kt(()=>{if(t){let c;const u=t.ownerDocument.defaultView??window,f=p=>{const x=ms(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",c=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},h=p=>{p.target===t&&(s.current=ms(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{u.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:y.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function ms(e){return(e==null?void 0:e.animationName)||"none"}function Rv(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 Pv=y[" useId ".trim().toString()]||(()=>{}),Ov=0;function En(e){const[t,n]=y.useState(Pv());return kt(()=>{n(r=>r??String(Ov++))},[e]),e||(t?`radix-${t}`:"")}var gs="Collapsible",[Mv,vT]=Tn(gs),[Dv,va]=Mv(gs),ed=y.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:gs});return d.jsx(Dv,{scope:n,disabled:s,contentId:En(),open:l,onOpenToggle:y.useCallback(()=>c(u=>!u),[c]),children:d.jsx(Ie.div,{"data-state":ba(l),"data-disabled":s?"":void 0,...a,ref:t})})});ed.displayName=gs;var td="CollapsibleTrigger",nd=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=va(td,n);return d.jsx(Ie.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":ba(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ge(e.onClick,o.onOpenToggle)})});nd.displayName=td;var wa="CollapsibleContent",Lv=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=va(wa,e.__scopeCollapsible);return d.jsx(Kt,{present:n||o.open,children:({present:s})=>d.jsx(Fv,{...r,ref:t,present:s})})});Lv.displayName=wa;var Fv=y.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=va(wa,n),[a,l]=y.useState(r),c=y.useRef(null),u=He(t,c),f=y.useRef(0),h=f.current,p=y.useRef(0),m=p.current,x=i.open||a,v=y.useRef(x),g=y.useRef(void 0);return y.useEffect(()=>{const w=requestAnimationFrame(()=>v.current=!1);return()=>cancelAnimationFrame(w)},[]),kt(()=>{const w=c.current;if(w){g.current=g.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=g.current.transitionDuration,w.style.animationName=g.current.animationName),l(r)}},[i.open,r]),d.jsx(Ie.div,{"data-state":ba(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:u,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:x&&o})});function ba(e){return e?"open":"closed"}var $v=ed;const zv=$v,Bv=nd,Hv=1,Uv=1e6;let Sa=0;function Wv(){return Sa=(Sa+1)%Number.MAX_SAFE_INTEGER,Sa.toString()}const Ca=new Map,rd=e=>{if(Ca.has(e))return;const t=setTimeout(()=>{Ca.delete(e),go({type:"REMOVE_TOAST",toastId:e})},Uv);Ca.set(e,t)},Vv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Hv)};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?rd(n):e.toasts.forEach(r=>{rd(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)}}},xs=[];let ys={toasts:[]};function go(e){ys=Vv(ys,e),xs.forEach(t=>{t(ys)})}function Kv({...e}){const t=Wv(),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 ka(){const[e,t]=y.useState(ys);return y.useEffect(()=>(xs.push(t),()=>{const n=xs.indexOf(t);n>-1&&xs.splice(n,1)}),[e]),{...e,toast:Kv,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}async function od(e,t){return await cn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function sd(e,t){return await(await od(`/files/${e}/view`,t)).text()}async function qv(e,t){const n=await od(`/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 Gv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await cn("/files",{params:r})}function Ta(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 id(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;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(id(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 yo(e){if(typeof e=="string")return e;if(id(e))return"";try{const t=xo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Yv(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function Xv(e){const t=yo(e);return typeof e=="string"&&Yv(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function vs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ta(t);if(n!==null)return vs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?vs(e.content):e}function Nt(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Jv(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e);y.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 Zv="DismissableLayer",Ea="dismissableLayer.update",Qv="dismissableLayer.pointerDownOutside",ew="dismissableLayer.focusOutside",ad,ld=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ws=y.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=y.useContext(ld),[u,f]=y.useState(null),h=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=y.useState({}),m=He(t,E=>f(E)),x=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=x.indexOf(v),w=u?x.indexOf(u):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,T=w>=g,k=rw(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=ow(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 Jv(E=>{w===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),y.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(ad=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),cd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=ad)}},[u,h,n,c]),y.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),cd())},[u,c]),y.useEffect(()=>{const E=()=>p({});return document.addEventListener(Ea,E),()=>document.removeEventListener(Ea,E)},[]),d.jsx(Ie.div,{...l,ref:m,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)})});ws.displayName=Zv;var tw="DismissableLayerBranch",nw=y.forwardRef((e,t)=>{const n=y.useContext(ld),r=y.useRef(null),o=He(t,r);return y.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(Ie.div,{...e,ref:o})});nw.displayName=tw;function rw(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e),r=y.useRef(!1),o=y.useRef(()=>{});return y.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){ud(Qv,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 ow(e,t=globalThis==null?void 0:globalThis.document){const n=Nt(e),r=y.useRef(!1);return y.useEffect(()=>{const o=s=>{s.target&&!r.current&&ud(ew,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 cd(){const e=new CustomEvent(Ea);document.dispatchEvent(e)}function ud(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?Qu(o,s):o.dispatchEvent(s)}var Ia="focusScope.autoFocusOnMount",Na="focusScope.autoFocusOnUnmount",dd={bubbles:!1,cancelable:!0},sw="FocusScope",bs=y.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=y.useState(null),c=Nt(o),u=Nt(s),f=y.useRef(null),h=He(t,x=>l(x)),p=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(r){let x=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}))},g=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&Yn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",v);const w=new MutationObserver(g);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",v),w.disconnect()}}},[r,a,p.paused]),y.useEffect(()=>{if(a){pd.add(p);const x=document.activeElement;if(!a.contains(x)){const g=new CustomEvent(Ia,dd);a.addEventListener(Ia,c),a.dispatchEvent(g),g.defaultPrevented||(iw(dw(fd(a)),{select:!0}),document.activeElement===x&&Yn(a))}return()=>{a.removeEventListener(Ia,c),setTimeout(()=>{const g=new CustomEvent(Na,dd);a.addEventListener(Na,u),a.dispatchEvent(g),g.defaultPrevented||Yn(x??document.body,{select:!0}),a.removeEventListener(Na,u),pd.remove(p)},0)}}},[a,c,u,p]);const m=y.useCallback(x=>{if(!n&&!r||p.paused)return;const v=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,g=document.activeElement;if(v&&g){const w=x.currentTarget,[S,T]=aw(w);S&&T?!x.shiftKey&&g===T?(x.preventDefault(),n&&Yn(S,{select:!0})):x.shiftKey&&g===S&&(x.preventDefault(),n&&Yn(T,{select:!0})):g===w&&x.preventDefault()}},[n,r,p.paused]);return d.jsx(Ie.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});bs.displayName=sw;function iw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Yn(r,{select:t}),document.activeElement!==n)return}function aw(e){const t=fd(e),n=hd(t,e),r=hd(t.reverse(),e);return[n,r]}function fd(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 hd(e,t){for(const n of e)if(!lw(n,{upTo:t}))return n}function lw(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 cw(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&&cw(e)&&t&&e.select()}}var pd=uw();function uw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=md(e,t),e.unshift(t)},remove(t){var n;e=md(e,t),(n=e[0])==null||n.resume()}}}function md(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function dw(e){return e.filter(t=>t.tagName!=="A")}var fw="Portal",Ss=y.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=y.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?gi.createPortal(d.jsx(Ie.div,{...r,ref:t}),i):null});Ss.displayName=fw;var Aa=0;function _a(){y.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??gd()),document.body.insertAdjacentElement("beforeend",e[1]??gd()),Aa++,()=>{Aa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Aa--}},[])}function gd(){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 xd(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 hw(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 Cs="right-scroll-bar-position",ks="width-before-scroll-bar",pw="with-scroll-bars-hidden",mw="--removed-body-scroll-bar-size";function ja(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function gw(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 xw=typeof window<"u"?y.useLayoutEffect:y.useEffect,yd=new WeakMap;function yw(e,t){var n=gw(null,function(r){return e.forEach(function(o){return ja(o,r)})});return xw(function(){var r=yd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ja(a,null)}),s.forEach(function(a){o.has(a)||ja(a,i)})}yd.set(n,e)},[e]),n}function vw(e){return e}function ww(e,t){t===void 0&&(t=vw);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 u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return o}function bw(e){e===void 0&&(e={});var t=ww(null);return t.options=In({async:!0,ssr:!1},e),t}var vd=function(e){var t=e.sideCar,n=xd(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 y.createElement(r,In({},n))};vd.isSideCarExport=!0;function Sw(e,t){return e.useMedium(t),vd}var wd=bw(),Ra=function(){},Ts=y.forwardRef(function(e,t){var n=y.useRef(null),r=y.useState({onScrollCapture:Ra,onWheelCapture:Ra,onTouchMoveCapture:Ra}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,x=e.inert,v=e.allowPinchZoom,g=e.as,w=g===void 0?"div":g,S=e.gapMode,T=xd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,C=yw([n,t]),E=In(In({},T),o);return y.createElement(y.Fragment,null,u&&y.createElement(k,{sideCar:wd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:x,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:S}),i?y.cloneElement(y.Children.only(a),In(In({},E),{ref:C})):y.createElement(w,In({},E,{className:l,ref:C}),a))});Ts.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ts.classNames={fullWidth:ks,zeroRight:Cs};var Cw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function kw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Cw();return t&&e.setAttribute("nonce",t),e}function Tw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Ew(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Iw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=kw())&&(Tw(t,n),Ew(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Nw=function(){var e=Iw();return function(t,n){y.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},bd=function(){var e=Nw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Aw={left:0,top:0,right:0,gap:0},Pa=function(e){return parseInt(e||"",10)||0},_w=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[Pa(n),Pa(r),Pa(o)]},jw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Aw;var t=_w(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])}},Rw=bd(),Pr="data-scroll-locked",Pw=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
39
|
.`.concat(pw,` {
|
|
40
40
|
overflow: hidden `).concat(r,`;
|
|
41
41
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -72,10 +72,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
72
72
|
body[`).concat(Pr,`] {
|
|
73
73
|
`).concat(mw,": ").concat(a,`px;
|
|
74
74
|
}
|
|
75
|
-
`)},Sd=function(){var e=parseInt(document.body.getAttribute(Pr)||"0",10);return isFinite(e)?e:0},Ow=function(){y.useEffect(function(){return document.body.setAttribute(Pr,(Sd()+1).toString()),function(){var e=Sd()-1;e<=0?document.body.removeAttribute(Pr):document.body.setAttribute(Pr,e.toString())}},[])},Mw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Ow();var s=y.useMemo(function(){return jw(o)},[o]);return y.createElement(Rw,{styles:Pw(s,!t,o,n?"":"!important")})},Oa=!1;if(typeof window<"u")try{var Es=Object.defineProperty({},"passive",{get:function(){return Oa=!0,!0}});window.addEventListener("test",Es,Es),window.removeEventListener("test",Es,Es)}catch{Oa=!1}var Or=Oa?{passive:!1}:!1,Dw=function(e){return e.tagName==="TEXTAREA"},Cd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Dw(e)&&n[t]==="visible")},Lw=function(e){return Cd(e,"overflowY")},Fw=function(e){return Cd(e,"overflowX")},kd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Td(e,r);if(o){var s=Ed(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},$w=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]},Td=function(e,t){return e==="v"?Lw(t):Fw(t)},Ed=function(e,t){return e==="v"?$w(t):zw(t)},Bw=function(e,t){return e==="h"&&t==="rtl"?-1:1},Hw=function(e,t,n,r,o){var s=Bw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,u=i>0,f=0,h=0;do{if(!a)break;var p=Ed(e,a),m=p[0],x=p[1],v=p[2],g=x-v-s*m;(m||g)&&Td(e,a)&&(f+=g,h+=m);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(u&&Math.abs(f)<1||!u&&Math.abs(h)<1)&&(c=!0),c},Is=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Id=function(e){return[e.deltaX,e.deltaY]},
|
|
75
|
+
`)},Sd=function(){var e=parseInt(document.body.getAttribute(Pr)||"0",10);return isFinite(e)?e:0},Ow=function(){y.useEffect(function(){return document.body.setAttribute(Pr,(Sd()+1).toString()),function(){var e=Sd()-1;e<=0?document.body.removeAttribute(Pr):document.body.setAttribute(Pr,e.toString())}},[])},Mw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Ow();var s=y.useMemo(function(){return jw(o)},[o]);return y.createElement(Rw,{styles:Pw(s,!t,o,n?"":"!important")})},Oa=!1;if(typeof window<"u")try{var Es=Object.defineProperty({},"passive",{get:function(){return Oa=!0,!0}});window.addEventListener("test",Es,Es),window.removeEventListener("test",Es,Es)}catch{Oa=!1}var Or=Oa?{passive:!1}:!1,Dw=function(e){return e.tagName==="TEXTAREA"},Cd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Dw(e)&&n[t]==="visible")},Lw=function(e){return Cd(e,"overflowY")},Fw=function(e){return Cd(e,"overflowX")},kd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Td(e,r);if(o){var s=Ed(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},$w=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]},Td=function(e,t){return e==="v"?Lw(t):Fw(t)},Ed=function(e,t){return e==="v"?$w(t):zw(t)},Bw=function(e,t){return e==="h"&&t==="rtl"?-1:1},Hw=function(e,t,n,r,o){var s=Bw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,u=i>0,f=0,h=0;do{if(!a)break;var p=Ed(e,a),m=p[0],x=p[1],v=p[2],g=x-v-s*m;(m||g)&&Td(e,a)&&(f+=g,h+=m);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(u&&Math.abs(f)<1||!u&&Math.abs(h)<1)&&(c=!0),c},Is=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Id=function(e){return[e.deltaX,e.deltaY]},Nd=function(e){return e&&"current"in e?e.current:e},Uw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Ww=function(e){return`
|
|
76
76
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
77
77
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
78
|
-
`)},Vw=0,Mr=[];function Kw(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),o=y.useState(Vw++)[0],s=y.useState(bd)[0],i=y.useRef(e);y.useEffect(function(){i.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var x=hw([e.lockRef.current],(e.shards||[]).map(
|
|
78
|
+
`)},Vw=0,Mr=[];function Kw(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),o=y.useState(Vw++)[0],s=y.useState(bd)[0],i=y.useRef(e);y.useEffect(function(){i.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var x=hw([e.lockRef.current],(e.shards||[]).map(Nd),!0).filter(Boolean);return x.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=y.useCallback(function(x,v){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var g=Is(x),w=n.current,S="deltaX"in x?x.deltaX:w[0]-g[0],T="deltaY"in x?x.deltaY:w[1]-g[1],k,C=x.target,E=Math.abs(S)>Math.abs(T)?"h":"v";if("touches"in x&&E==="h"&&C.type==="range")return!1;var _=kd(E,C);if(!_)return!0;if(_?k=E:(k=E==="v"?"h":"v",_=kd(E,C)),!_)return!1;if(!r.current&&"changedTouches"in x&&(S||T)&&(r.current=k),!k)return!0;var j=r.current||k;return Hw(j,v,x,j==="h"?S:T)},[]),l=y.useCallback(function(x){var v=x;if(!(!Mr.length||Mr[Mr.length-1]!==s)){var g="deltaY"in v?Id(v):Is(v),w=t.current.filter(function(k){return k.name===v.type&&(k.target===v.target||v.target===k.shadowParent)&&Uw(k.delta,g)})[0];if(w&&w.should){v.cancelable&&v.preventDefault();return}if(!w){var S=(i.current.shards||[]).map(Nd).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=y.useCallback(function(x,v,g,w){var S={name:x,delta:v,target:g,should:w,shadowParent:qw(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(T){return T!==S})},1)},[]),u=y.useCallback(function(x){n.current=Is(x),r.current=void 0},[]),f=y.useCallback(function(x){c(x.type,Id(x),x.target,a(x,e.lockRef.current))},[]),h=y.useCallback(function(x){c(x.type,Is(x),x.target,a(x,e.lockRef.current))},[]);y.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",u,Or),function(){Mr=Mr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,Or),document.removeEventListener("touchmove",l,Or),document.removeEventListener("touchstart",u,Or)}},[]);var p=e.removeScrollBar,m=e.inert;return y.createElement(y.Fragment,null,m?y.createElement(s,{styles:Ww(o)}):null,p?y.createElement(Mw,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function qw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Gw=Sw(wd,Kw);var Ns=y.forwardRef(function(e,t){return y.createElement(Ts,In({},e,{ref:t,sideCar:Gw}))});Ns.classNames=Ts.classNames;var Yw=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Dr=new WeakMap,As=new WeakMap,_s={},Ma=0,Ad=function(e){return e&&(e.host||Ad(e.parentNode))},Xw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Ad(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})},Jw=function(e,t,n,r){var o=Xw(t,Array.isArray(e)?e:[e]);_s[n]||(_s[n]=new WeakMap);var s=_s[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 u=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))u(h);else try{var p=h.getAttribute(r),m=p!==null&&p!=="false",x=(Dr.get(h)||0)+1,v=(s.get(h)||0)+1;Dr.set(h,x),s.set(h,v),i.push(h),x===1&&m&&As.set(h,!0),v===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return u(t),a.clear(),Ma++,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||(As.has(f)||f.removeAttribute(r),As.delete(f)),p||f.removeAttribute(n)}),Ma--,Ma||(Dr=new WeakMap,Dr=new WeakMap,As=new WeakMap,_s={})}},Da=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Yw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Jw(r,o,n,"aria-hidden")):function(){return null}},js="Dialog",[_d,wT]=Tn(js),[Zw,hn]=_d(js),jd=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=y.useRef(null),l=y.useRef(null),[c,u]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:js});return d.jsx(Zw,{scope:t,triggerRef:a,contentRef:l,contentId:En(),titleId:En(),descriptionId:En(),open:c,onOpenChange:u,onOpenToggle:y.useCallback(()=>u(f=>!f),[u]),modal:i,children:n})};jd.displayName=js;var Rd="DialogTrigger",Pd=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Rd,n),s=He(t,o.triggerRef);return d.jsx(Ie.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":$a(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Pd.displayName=Rd;var La="DialogPortal",[Qw,Od]=_d(La,{forceMount:void 0}),Md=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=hn(La,t);return d.jsx(Qw,{scope:t,forceMount:n,children:y.Children.map(r,i=>d.jsx(Kt,{present:n||s.open,children:d.jsx(Ss,{asChild:!0,container:o,children:i})}))})};Md.displayName=La;var Rs="DialogOverlay",Dd=y.forwardRef((e,t)=>{const n=Od(Rs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(Rs,e.__scopeDialog);return s.modal?d.jsx(Kt,{present:r||s.open,children:d.jsx(tb,{...o,ref:t})}):null});Dd.displayName=Rs;var eb=sr.createSlot("DialogOverlay.RemoveScroll"),tb=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Rs,n);return d.jsx(Ns,{as:eb,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ie.div,{"data-state":$a(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),mr="DialogContent",Ld=y.forwardRef((e,t)=>{const n=Od(mr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=hn(mr,e.__scopeDialog);return d.jsx(Kt,{present:r||s.open,children:s.modal?d.jsx(nb,{...o,ref:t}):d.jsx(rb,{...o,ref:t})})});Ld.displayName=mr;var nb=y.forwardRef((e,t)=>{const n=hn(mr,e.__scopeDialog),r=y.useRef(null),o=He(t,n.contentRef,r);return y.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),d.jsx(Fd,{...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())})}),rb=y.forwardRef((e,t)=>{const n=hn(mr,e.__scopeDialog),r=y.useRef(!1),o=y.useRef(!1);return d.jsx(Fd,{...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()}})}),Fd=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=hn(mr,n),l=y.useRef(null),c=He(t,l);return _a(),d.jsxs(d.Fragment,{children:[d.jsx(bs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(ws,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":$a(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(ob,{titleId:a.titleId}),d.jsx(ib,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Fa="DialogTitle",$d=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Fa,n);return d.jsx(Ie.h2,{id:o.titleId,...r,ref:t})});$d.displayName=Fa;var zd="DialogDescription",Bd=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(zd,n);return d.jsx(Ie.p,{id:o.descriptionId,...r,ref:t})});Bd.displayName=zd;var Hd="DialogClose",Ud=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=hn(Hd,n);return d.jsx(Ie.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Ud.displayName=Hd;function $a(e){return e?"open":"closed"}var Wd="DialogTitleWarning",[bT,Vd]=kv(Wd,{contentName:mr,titleName:Fa,docsSlug:"dialog"}),ob=({titleId:e})=>{const t=Vd(Wd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
79
79
|
|
|
80
80
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
81
81
|
|
|
@@ -123,10 +123,10 @@ ${t}</blockquote>
|
|
|
123
123
|
${t}</tr>
|
|
124
124
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
125
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=of(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=of(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 uf{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 df{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 Jn{constructor(t){this.options=t||xr,this.options.renderer=this.options.renderer||new Ba,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new uf,this.slugger=new df}static parse(t,n){return new Jn(n).parse(t)}static parseInline(t,n){return new Jn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,u,f,h,p,m,x,v,g,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,rf(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="",u="",a=p.header.length,s=0;s<a;s++)u+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(u),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],u="",l=c.length,i=0;i<l;i++)u+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(u)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(m=p.ordered,x=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,g="",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}):g+=k),g+=this.parse(w.tokens,v),h+=this.renderer.listitem(g,T,S);r+=this.renderer.list(h,m,x);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+=`
|
|
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 $s{constructor(t){this.options=t||xr}preprocess(t){return t}postprocess(t){return t}}
|
|
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 ff(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=
|
|
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 $s{constructor(t){this.options=t||xr}preprocess(t){return t}postprocess(t){return t}}Am($s,"passThroughHooks",new Set(["preprocess","postprocess"]));function Nb(e,t,n){return r=>{if(r.message+=`
|
|
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 ff(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=Nb(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(Tb(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 u=0;Se.walkTokens(l,function(f){f.type==="code"&&(u++,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),u--,u===0&&c()})},0))}),u===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 ff(Xn.lex,Jn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},fb(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 Ba;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 za;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 $s;for(const s in n.hooks){const i=o[s];$s.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=ff(Xn.lexInline,Jn.parseInline),Se.Parser=Jn,Se.parser=Jn.parse,Se.Renderer=Ba,Se.TextRenderer=uf,Se.Lexer=Xn,Se.lexer=Xn.lex,Se.Tokenizer=za,Se.Slugger=df,Se.Hooks=$s,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Jn.parse,Xn.lex;function vo({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(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return d.jsx("div",{className:ee("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const Ab="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 _b(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function hf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function zs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function jb(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==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
|
|
128
128
|
`)):r=t(e),r||""}function Rb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function pf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;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"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function Pb({className:e}){const[t,n]=b.useState(0);return b.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),d.jsxs("span",{"aria-live":"polite",className:ee("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ha=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:u=200,showToolMessages:f=!0,customStyles:h={},onEdit:p,onRegenerate:m,onCancelEdit:x,onCopy:v,activeInterrupt:g,disableInterruptActions:w=!1,onInterruptActionStart:S,onInterruptActionEnd:T}){const[k,C]=b.useState(!1),[E,_]=b.useState("preview"),[j,D]=b.useState(!1),{currentThreadId:$}=Qo(),{respondToInterrupt:q}=es(),P=l==="phone"||l==="half-screen",R=t.role,L=R==="tool",F=b.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ne=!!F,K=!(r&&R!=="user"),{uploadingFiles:B,handleFileClick:pe,fileViewerOpen:W,currentFileInfo:ce,closeFileViewer:H}=Mb({allowFileOpen:K,currentThreadId:$}),Z=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]),we=b.useMemo(()=>F?"":_b(t.content),[F,t]),ye=b.useMemo(()=>F?{}:hf(t),[F,t]),G=b.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="image_url"),[F,t]),M=b.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="file"),[F,t]),X=b.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="interrupt"),[F,t]),oe=(g==null?void 0:g.id)??(g==null?void 0:g.interrupt_id),xe=zs(oe),se=g==null?void 0:g.value,re=b.useMemo(()=>F?"":jb(t.content),[F,t]),Ue=b.useCallback(async()=>{const ie=L?re:we;async function je(ke){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ke);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const qe=new Blob([ke],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":qe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await je(ie),C(!0),setTimeout(()=>C(!1),2e3),v==null||v(ie)}catch(ke){console.error("Failed to copy:",ke)}},[L,re,we,v]),Ke=b.useCallback(()=>{if(!p)return;const ie=L?re:we;p(t.id,ie)},[p,t.id,L,re,we]),ot=b.useCallback(()=>{m==null||m(n)},[m,n]),at=b.useCallback(()=>{const je=ee(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(R){case"user":return d.jsx(fe.User,{className:je});case"assistant":return d.jsx(fe.Bot,{className:je});case"tool":return d.jsx(fe.Wrench,{className:je});default:return d.jsx(fe.Bot,{className:je})}},[P,Z,R]),ht=b.useCallback(()=>{const ie="group relative mb-4 flex w-full";switch(R){case"user":return ee(ie,"justify-end");case"assistant":case"tool":case"system":return ee(ie,"justify-start");default:return ie}},[R]),tt=b.useCallback(()=>{const ie=ee("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ne)return ee(ie,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(R){case"user":return ee(ie,"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 ee(ie,"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 ee(ie,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ee(ie,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ee(ie,"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,ne,R]);if(ne&&F)return d.jsx("div",{className:ee(ht(),h.container),children:d.jsxs("div",{className:ee(tt(),h.content),children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[d.jsx(fe.Bot,{className:ee("h-4 w-4",Z)}),a&&d.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),d.jsx(vo,{content:F.content,className:"text-current"})]})});const Me=b.useCallback(async ie=>{if(w)return;const je=zs((ie==null?void 0:ie.id)??(ie==null?void 0:ie.interrupt_id));if(!je){console.warn("Interrupt part missing id",ie);return}try{S==null||S(),await q(je,!0)}catch(ke){console.error("Failed to approve interrupt:",ke)}finally{T==null||T()}},[w,T,S,q]),We=b.useCallback(async ie=>{if(w)return;const je=zs((ie==null?void 0:ie.id)??(ie==null?void 0:ie.interrupt_id));if(!je){console.warn("Interrupt part missing id",ie);return}try{S==null||S(),await q(je,!1)}catch(ke){console.error("Failed to reject interrupt:",ke)}finally{T==null||T()}},[w,T,S,q]),lt=b.useCallback(({part:ie,i:je})=>{if(ie.type==="text"){const ke=ie.text??"",qe=ke.trim(),nt=Ta(qe);return nt&&R!=="tool"?d.jsx(mf,{data:nt},je):R==="user"&&c&&qe.length>u?d.jsx(Db,{text:qe,expanded:j,onExpandedChange:D,previewLength:u,isCompact:P},je):d.jsx(vo,{content:ke,allowHtml:!1},je)}if(ie.type==="image_url"){const ke=ie;return d.jsx("div",{className:"my-2",children:d.jsx("img",{src:ke.url,alt:ke.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},je)}if(ie.type==="file"){const ke=ie,qe=ke.name||"file";return d.jsxs("a",{href:ke.url,onClick:nt=>pe(nt,ke,je),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
129
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[B[je]?d.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}):null,d.jsxs("span",{className:"truncate max-w-[180px]",children:[qe,B[je]?" (processing)":""]})]},je)}if(ie.type==="interrupt"){const ke=ie,qe=zs((ke==null?void 0:ke.id)??(ke==null?void 0:ke.interrupt_id)),nt=!!(xe&&qe&&qe===xe),Oe=nt?se??(ke==null?void 0:ke.value):ke==null?void 0:ke.value,Xe=qe?{...ke,id:qe,interrupt_id:qe}:ke;return d.jsx(Ob,{interruptPart:Xe,onApprove:Me,onReject:We,disabled:w,isActive:nt,payload:Oe},je)}return null},[pe,B,Me,We,R,c,u,j,P,xe,se,g,w,X]),xt=b.useCallback(()=>d.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[d.jsx(fe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),d.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),dt=b.useCallback(()=>{const ie=we.trim().length>0||G.length>0||M.length>0||X.length>0;if(!L&&M.length>0&&!r)return xt();if(!L&&!ie&&!r)return null;if(L)return d.jsx(Lb,{message:t,viewMode:E},t.id);if(!L&&!F){const je=t,ke=d.jsx("div",{className:"space-y-2",children:je.content.map((qe,nt)=>d.jsx(lt,{part:qe,i:nt},nt))});return r?d.jsxs("div",{"aria-busy":"true",role:"status",children:[ke,d.jsx(Pb,{className:Z})]}):ke}},[we,G.length,M.length,X.length,r,L,E,xt,Z]),Je=b.useMemo(()=>F?"Assistant":Rb(t),[F,t]);return L&&!f?null:d.jsxs(d.Fragment,{children:[d.jsx("div",{className:ee(ht(),h.container),children:d.jsxs("div",{className:ee(tt(),h.content),children:[(i||a||L)&&d.jsxs("div",{className:ee("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",Z,h.header),children:[d.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Je&&d.jsx("span",{className:ee("font-medium",P?"text-xs":"text-sm"),children:Je}),L&&d.jsxs(Yu,{variant:"outline",className:ee("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E==="expanded",onClick:()=>_(ie=>ie==="expanded"?"preview":"expanded"),onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),_(je=>je==="expanded"?"preview":"expanded"))},children:[d.jsx("span",{children:ye.name??"Tool Output"}),ye.toolCallId&&d.jsx("span",{className:"opacity-70",children:ye.toolCallId.slice(0,8)}),E==="expanded"?d.jsx(fe.ChevronUp,{className:"h-3 w-3"}):d.jsx(fe.ChevronDown,{className:"h-3 w-3"})]})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&d.jsx("time",{className:ee("text-xs opacity-60",Z,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&&d.jsxs("div",{className:ee("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[d.jsx("div",{className:"relative",children:d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:d.jsx(fe.Copy,{className:ee(k?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),R==="user"&&p&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ke,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:d.jsx(fe.Edit,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&m&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:d.jsx(fe.RotateCcw,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),d.jsx("div",{className:"relative",children:dt()}),L&&E==="expanded"&&(ye.toolCallId||ye.name)&&d.jsxs("div",{className:ee("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[ye.name&&d.jsxs("div",{children:["Function: ",ye.name]}),ye.toolCallId&&d.jsxs("div",{children:["Call ID: ",ye.toolCallId]})]}),!(i||a||L)&&s&&!o&&d.jsxs("div",{className:ee("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:d.jsx(fe.Copy,{className:ee(k?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="user"&&p&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ke,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:d.jsx(fe.Edit,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&m&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:d.jsx(fe.RotateCcw,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),ce&&d.jsx(db,{isOpen:W,onClose:H,fileId:ce.id,fileName:ce.name,mimeType:ce.mimeType})]})},(e,t)=>{var i,a,l,c,u,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&pf(e.message)===pf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),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)&&((u=e.customStyles)==null?void 0:u.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 mf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?d.jsx("div",{className:Nb,children:d.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>d.jsx("li",{children:String(n)},r))})}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:yo(e)}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:yo(e)})}function Ob({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=d.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=yo(s);a=d.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 d.jsxs(fo,{className:ee("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:[d.jsxs(ho,{className:"pb-3",children:[d.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),d.jsx(Xu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&d.jsx(mo,{className:"pt-0 pb-3",children:a}),d.jsx(Ju,{className:"pt-0",children:d.jsxs("div",{className:"flex gap-2 ml-auto",children:[d.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),d.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function Mb(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ka(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),u=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,m,x)=>{var v,g;if(!t){p.preventDefault();return}if(o[x]){p.preventDefault();return}try{const w=String(m.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=m.name||`file_${T}`,C=m.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[x]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Gv(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??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${m.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:m.name||C.filename||`file_${C.id}`,mimeType:m.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(g=T.update)==null||g.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[x]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:u}}function Db({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return d.jsxs(zv,{open:t,onOpenChange:n,children:[d.jsx("div",{className:ee("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?d.jsx(vo,{content:e,allowHtml:!1}):d.jsxs("pre",{className:ee("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),"..."]})}),d.jsx(Bv,{asChild:!0,children:d.jsx(Ze,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:t?d.jsxs(d.Fragment,{children:[d.jsx(fe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):d.jsxs(d.Fragment,{children:[d.jsx(fe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Lb({message:e,viewMode:t}){const r=hf(e).name||"tool",o=c=>{if(c==null)return null;const u=typeof c=="string"?Ta(c)??c:c;if(u&&typeof u=="object")return d.jsx(mf,{data:u});const f=typeof u=="string"?u:(()=>{try{return yo(u)}catch{return String(u??"")}})();return d.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:u,isMarkdown:f}=Xv(c);return f?d.jsx(vo,{content:u,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return d.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}),d.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const u=(i.text??"").trim();if(!u)return null;const f=vs(u);return s(f)}const a=xo(i),l=vs(a);return s(l)}const gf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ua=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:u,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:x=!1,onScrollAway:v,onAtBottom:g,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),[$,q]=b.useState(!0),P=b.useMemo(()=>w?e.some(W=>"type"in W&&W.type==="default_message"?!1:Array.isArray(W==null?void 0:W.content)&&W.content.some(ce=>ce&&ce.type==="interrupt"&&(ce.id??ce.interrupt_id)===w.id)):!1,[w,e]),R=b.useMemo(()=>{if(!w||P)return null;const W=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let ce;const H=w.value;if(H&&typeof H=="object"&&!Array.isArray(H)){const Z=H.title;typeof Z=="string"&&Z.trim()&&(ce=Z.trim())}return{id:`interrupt-${W}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:W,value:H,title:ce}]}},[w,P]),L=b.useMemo(()=>R?[...e,R]:e,[e,R]),F=b.useMemo(()=>C?L:L.filter(W=>(W==null?void 0:W.role)!=="tool"),[L,C]),ne=b.useCallback(W=>{q(W),v&&v(!W),g&&g(W)},[v,g]),K=b.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),B=b.useMemo(()=>!m||x?!1:$?"auto":!1,[$,m,x]),pe=b.useMemo(()=>{if(typeof p!="string")return null;const W=p.trim();return W?{id:"default-message",role:"assistant",type:"default_message",content:W,createdAt:new Date().toISOString()}:null},[p]);return F.length===0?pe?d.jsx("div",{className:f,style:h,children:d.jsx("div",{className:"p-6 overflow-y-auto h-full flex items-start justify-center",children:d.jsx("div",{className:"w-full max-w-full",children:d.jsx(Ha,{message:pe,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})})}):d.jsx("div",{className:f,style:h,children:d.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:p||"No messages yet. Start a conversation!"})}):d.jsx("div",{className:f,style:h,children:d.jsx(lv,{ref:W=>{_.current=W},scrollerRef:W=>{j.current=W instanceof HTMLDivElement?W:null},data:F,followOutput:B,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{K&&K()},atBottomStateChange:ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(W,ce)=>gf(ce,W),itemContent:(W,ce)=>{const H=gf(ce,W);return d.jsx("div",{className:"mb-4 last:mb-0","data-message-id":H,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:d.jsx(Ha,{message:ce,messageIndex:W,isStreamingMessage:t&&n===ce.id,streamingDebounceMs:r,isEditing:i===ce.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(W),onCancelEdit:u,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C})})}})})});Ua.displayName="MessageList";const Bs=1e4;function Fb(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
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[B[je]?d.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}):null,d.jsxs("span",{className:"truncate max-w-[180px]",children:[qe,B[je]?" (processing)":""]})]},je)}if(ie.type==="interrupt"){const ke=ie,qe=zs((ke==null?void 0:ke.id)??(ke==null?void 0:ke.interrupt_id)),nt=!!(xe&&qe&&qe===xe),Oe=nt?se??(ke==null?void 0:ke.value):ke==null?void 0:ke.value,Xe=qe?{...ke,id:qe,interrupt_id:qe}:ke;return d.jsx(Ob,{interruptPart:Xe,onApprove:Me,onReject:We,disabled:w,isActive:nt,payload:Oe},je)}return null},[pe,B,Me,We,R,c,u,j,P,xe,se,g,w,X]),xt=b.useCallback(()=>d.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[d.jsx(fe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),d.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),dt=b.useCallback(()=>{const ie=we.trim().length>0||G.length>0||M.length>0||X.length>0;if(!L&&M.length>0&&!r)return xt();if(!L&&!ie&&!r)return null;if(L)return d.jsx(Lb,{message:t,viewMode:E},t.id);if(!L&&!F){const je=t,ke=d.jsx("div",{className:"space-y-2",children:je.content.map((qe,nt)=>d.jsx(lt,{part:qe,i:nt},nt))});return r?d.jsxs("div",{"aria-busy":"true",role:"status",children:[ke,d.jsx(Pb,{className:Z})]}):ke}},[we,G.length,M.length,X.length,r,L,E,xt,Z]),Je=b.useMemo(()=>F?"Assistant":Rb(t),[F,t]);return L&&!f?null:d.jsxs(d.Fragment,{children:[d.jsx("div",{className:ee(ht(),h.container),children:d.jsxs("div",{className:ee(tt(),h.content),children:[(i||a||L)&&d.jsxs("div",{className:ee("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",Z,h.header),children:[d.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Je&&d.jsx("span",{className:ee("font-medium",P?"text-xs":"text-sm"),children:Je}),L&&d.jsxs(Yu,{variant:"outline",className:ee("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E==="expanded",onClick:()=>_(ie=>ie==="expanded"?"preview":"expanded"),onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),_(je=>je==="expanded"?"preview":"expanded"))},children:[d.jsx("span",{children:ye.name??"Tool Output"}),ye.toolCallId&&d.jsx("span",{className:"opacity-70",children:ye.toolCallId.slice(0,8)}),E==="expanded"?d.jsx(fe.ChevronUp,{className:"h-3 w-3"}):d.jsx(fe.ChevronDown,{className:"h-3 w-3"})]})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&d.jsx("time",{className:ee("text-xs opacity-60",Z,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&&d.jsxs("div",{className:ee("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[d.jsx("div",{className:"relative",children:d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:d.jsx(fe.Copy,{className:ee(k?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),R==="user"&&p&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ke,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:d.jsx(fe.Edit,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&m&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:d.jsx(fe.RotateCcw,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),d.jsx("div",{className:"relative",children:dt()}),L&&E==="expanded"&&(ye.toolCallId||ye.name)&&d.jsxs("div",{className:ee("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[ye.name&&d.jsxs("div",{children:["Function: ",ye.name]}),ye.toolCallId&&d.jsxs("div",{children:["Call ID: ",ye.toolCallId]})]}),!(i||a||L)&&s&&!o&&d.jsxs("div",{className:ee("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:d.jsx(fe.Copy,{className:ee(k?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="user"&&p&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ke,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:d.jsx(fe.Edit,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&m&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:d.jsx(fe.RotateCcw,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),ce&&d.jsx(db,{isOpen:W,onClose:H,fileId:ce.id,fileName:ce.name,mimeType:ce.mimeType})]})},(e,t)=>{var i,a,l,c,u,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&pf(e.message)===pf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),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)&&((u=e.customStyles)==null?void 0:u.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 mf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?d.jsx("div",{className:Ab,children:d.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>d.jsx("li",{children:String(n)},r))})}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:yo(e)}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:yo(e)})}function Ob({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=d.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=yo(s);a=d.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 d.jsxs(fo,{className:ee("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:[d.jsxs(ho,{className:"pb-3",children:[d.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),d.jsx(Xu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&d.jsx(mo,{className:"pt-0 pb-3",children:a}),d.jsx(Ju,{className:"pt-0",children:d.jsxs("div",{className:"flex gap-2 ml-auto",children:[d.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),d.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function Mb(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ka(),[o,s]=b.useState({}),[i,a]=b.useState(null),[l,c]=b.useState(!1),u=b.useCallback(()=>{c(!1),a(null)},[]),f=b.useCallback(p=>{a(p),c(!0)},[]),h=b.useCallback(async(p,m,x)=>{var v,g;if(!t){p.preventDefault();return}if(o[x]){p.preventDefault();return}try{const w=String(m.url??""),S=w.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=m.name||`file_${T}`,C=m.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(w.startsWith("data:")){p.preventDefault(),s(k=>({...k,[x]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Gv(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??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${m.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:m.name||C.filename||`file_${C.id}`,mimeType:m.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(g=T.update)==null||g.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[x]:!1}))}}}catch(w){console.error("File click error:",w),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:u}}function Db({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return d.jsxs(zv,{open:t,onOpenChange:n,children:[d.jsx("div",{className:ee("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?d.jsx(vo,{content:e,allowHtml:!1}):d.jsxs("pre",{className:ee("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),"..."]})}),d.jsx(Bv,{asChild:!0,children:d.jsx(Ze,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:t?d.jsxs(d.Fragment,{children:[d.jsx(fe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):d.jsxs(d.Fragment,{children:[d.jsx(fe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Lb({message:e,viewMode:t}){const r=hf(e).name||"tool",o=c=>{if(c==null)return null;const u=typeof c=="string"?Ta(c)??c:c;if(u&&typeof u=="object")return d.jsx(mf,{data:u});const f=typeof u=="string"?u:(()=>{try{return yo(u)}catch{return String(u??"")}})();return d.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:u,isMarkdown:f}=Xv(c);return f?d.jsx(vo,{content:u,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return d.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}),d.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const u=(i.text??"").trim();if(!u)return null;const f=vs(u);return s(f)}const a=xo(i),l=vs(a);return s(l)}const gf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Ua=b.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:u,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:x=!1,onScrollAway:v,onAtBottom:g,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),[$,q]=b.useState(!0),P=b.useMemo(()=>w?e.some(W=>"type"in W&&W.type==="default_message"?!1:Array.isArray(W==null?void 0:W.content)&&W.content.some(ce=>ce&&ce.type==="interrupt"&&(ce.id??ce.interrupt_id)===w.id)):!1,[w,e]),R=b.useMemo(()=>{if(!w||P)return null;const W=w.id&&String(w.id).trim()?String(w.id).trim():"pending-interrupt";let ce;const H=w.value;if(H&&typeof H=="object"&&!Array.isArray(H)){const Z=H.title;typeof Z=="string"&&Z.trim()&&(ce=Z.trim())}return{id:`interrupt-${W}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:W,value:H,title:ce}]}},[w,P]),L=b.useMemo(()=>R?[...e,R]:e,[e,R]),F=b.useMemo(()=>C?L:L.filter(W=>(W==null?void 0:W.role)!=="tool"),[L,C]),ne=b.useCallback(W=>{q(W),v&&v(!W),g&&g(W)},[v,g]),K=b.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),B=b.useMemo(()=>!m||x?!1:$?"auto":!1,[$,m,x]),pe=b.useMemo(()=>{if(typeof p!="string")return null;const W=p.trim();return W?{id:"default-message",role:"assistant",type:"default_message",content:W,createdAt:new Date().toISOString()}:null},[p]);return F.length===0?pe?d.jsx("div",{className:f,style:h,children:d.jsx("div",{className:"p-6 overflow-y-auto h-full flex items-start justify-center",children:d.jsx("div",{className:"w-full max-w-full",children:d.jsx(Ha,{message:pe,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})})}):d.jsx("div",{className:f,style:h,children:d.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:p||"No messages yet. Start a conversation!"})}):d.jsx("div",{className:f,style:h,children:d.jsx(lv,{ref:W=>{_.current=W},scrollerRef:W=>{j.current=W instanceof HTMLDivElement?W:null},data:F,followOutput:B,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{K&&K()},atBottomStateChange:ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(W,ce)=>gf(ce,W),itemContent:(W,ce)=>{const H=gf(ce,W);return d.jsx("div",{className:"mb-4 last:mb-0","data-message-id":H,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:d.jsx(Ha,{message:ce,messageIndex:W,isStreamingMessage:t&&n===ce.id,streamingDebounceMs:r,isEditing:i===ce.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(W),onCancelEdit:u,activeInterrupt:w,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C})})}})})});Ua.displayName="MessageList";const Bs=1e4;function Fb(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,`
|
|
130
130
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
131
131
|
|
|
132
132
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -134,4 +134,4 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
134
134
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
135
135
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
136
136
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
137
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function $b(e,t=Bs){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 zb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),$b(t),Fb(t)}function Wa(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:v,children:g}=x,w=b.useRef(null),S=b.useRef(new Map).current;return d.jsx(o,{scope:v,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=sr.createSlot(a),c=b.forwardRef((x,v)=>{const{scope:g,children:w}=x,S=s(a,g),T=He(v,S.collectionRef);return d.jsx(l,{ref:T,children:w})});c.displayName=a;const u=e+"CollectionItemSlot",f="data-radix-collection-item",h=sr.createSlot(u),p=b.forwardRef((x,v)=>{const{scope:g,children:w,...S}=x,T=b.useRef(null),k=He(v,T),C=s(u,g);return b.useEffect(()=>(C.itemMap.set(T,{ref:T,...S}),()=>void C.itemMap.delete(T))),d.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=u;function m(x){const v=s(e+"CollectionConsumer",x);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},m,r]}var Bb=y.createContext(void 0);function Hs(e){const t=y.useContext(Bb);return e||t||"ltr"}const Hb=["top","right","bottom","left"],Zn=Math.min,qt=Math.max,Us=Math.round,Ws=Math.floor,An=e=>({x:e,y:e}),Ub={left:"right",right:"left",bottom:"top",top:"bottom"},Wb={start:"end",end:"start"};function Va(e,t,n){return qt(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 Ka(e){return e==="x"?"y":"x"}function qa(e){return e==="y"?"height":"width"}const Vb=new Set(["top","bottom"]);function Nn(e){return Vb.has(Hn(e))?"y":"x"}function Ga(e){return Ka(Nn(e))}function Kb(e,t,n){n===void 0&&(n=!1);const r=Lr(e),o=Ga(e),s=qa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Vs(i)),[i,Vs(i)]}function qb(e){const t=Vs(e);return[Ya(e),t,Ya(t)]}function Ya(e){return e.replace(/start|end/g,t=>Wb[t])}const xf=["left","right"],yf=["right","left"],Gb=["top","bottom"],Yb=["bottom","top"];function Xb(e,t,n){switch(e){case"top":case"bottom":return n?t?yf:xf:t?xf:yf;case"left":case"right":return t?Gb:Yb;default:return[]}}function Jb(e,t,n,r){const o=Lr(e);let s=Xb(Hn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ya)))),s}function Vs(e){return e.replace(/left|right|bottom|top/g,t=>Ub[t])}function Zb(e){return{top:0,right:0,bottom:0,left:0,...e}}function vf(e){return typeof e!="number"?Zb(e):{top:e,right:e,bottom:e,left:e}}function Ks(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 wf(e,t,n){let{reference:r,floating:o}=e;const s=Nn(t),i=Ga(t),a=qa(i),l=Hn(t),c=s==="y",u=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:u,y:r.y-o.height};break;case"bottom":p={x:u,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 Qb=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:u,y:f}=wf(c,r,l),h=r,p={},m=0;for(let x=0;x<a.length;x++){const{name:v,fn:g}=a[x],{x:w,y:S,data:T,reset:k}=await g({x:u,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});u=w??u,f=S??f,p={...p,[v]:{...p[v],...T}},k&&m<=50&&(m++,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:u,y:f}=wf(c,h,l)),x=-1)}return{x:u,y:f,placement:h,strategy:o,middlewareData:p}};async function wo(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:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Bn(t,e),m=vf(p),v=a[h?f==="floating"?"reference":"floating":f],g=Ks(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:u,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=Ks(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-k.top+m.top)/T.y,bottom:(k.bottom-g.bottom+m.bottom)/T.y,left:(g.left-k.left+m.left)/T.x,right:(k.right-g.right+m.right)/T.x}}const e0=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:u=0}=Bn(e,t)||{};if(c==null)return{};const f=vf(u),h={x:n,y:r},p=Ga(o),m=qa(p),x=await i.getDimensions(c),v=p==="y",g=v?"top":"left",w=v?"bottom":"right",S=v?"clientHeight":"clientWidth",T=s.reference[m]+s.reference[p]-h[p]-s.floating[m],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[m]);const _=T/2-k/2,j=E/2-x[m]/2-1,D=Zn(f[g],j),$=Zn(f[w],j),q=D,P=E-x[m]-$,R=E/2-x[m]/2+_,L=Va(q,R,P),F=!l.arrow&&Lr(o)!=null&&R!==L&&s.reference[m]/2-(R<q?D:$)-x[m]/2<0,ne=F?R<q?R-q:R-P:0;return{[p]:h[p]+ne,data:{[p]:L,centerOffset:R-L-ne,...F&&{alignmentOffset:ne}},reset:F}}}),t0=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:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:x=!0,...v}=Bn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=Hn(o),w=Nn(a),S=Hn(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(S||!x?[Vs(a)]:qb(a)),C=m!=="none";!h&&C&&k.push(...Jb(a,x,m,T));const E=[a,...k],_=await wo(t,v),j=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&j.push(_[g]),f){const R=Kb(o,i,T);j.push(_[R[0]],_[R[1]])}if(D=[...D,{placement:o,overflows:j}],!j.every(R=>R<=0)){var $,q;const R=((($=s.flip)==null?void 0:$.index)||0)+1,L=E[R];if(L&&(!(f==="alignment"?w!==Nn(L):!1)||D.every(K=>Nn(K.placement)===w?K.overflows[0]>0:!0)))return{data:{index:R,overflows:D},reset:{placement:L}};let F=(q=D.filter(ne=>ne.overflows[0]<=0).sort((ne,K)=>ne.overflows[1]-K.overflows[1])[0])==null?void 0:q.placement;if(!F)switch(p){case"bestFit":{var P;const ne=(P=D.filter(K=>{if(C){const B=Nn(K.placement);return B===w||B==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(B=>B>0).reduce((B,pe)=>B+pe,0)]).sort((K,B)=>K[1]-B[1])[0])==null?void 0:P[0];ne&&(F=ne);break}case"initialPlacement":F=a;break}if(o!==F)return{reset:{placement:F}}}return{}}}};function bf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Sf(e){return Hb.some(t=>e[t]>=0)}const n0=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 wo(t,{...o,elementContext:"reference"}),i=bf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Sf(i)}}}case"escaped":{const s=await wo(t,{...o,altBoundary:!0}),i=bf(s,n.floating);return{data:{escapedOffsets:i,escaped:Sf(i)}}}default:return{}}}}},Cf=new Set(["left","top"]);async function r0(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=Cf.has(i)?-1:1,u=s&&l?-1:1,f=Bn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*u,y:h*c}:{x:h*c,y:p*u}}const o0=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 r0(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}}}}},s0=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:g,y:w}=v;return{x:g,y:w}}},...l}=Bn(e,t),c={x:n,y:r},u=await wo(t,l),f=Nn(Hn(o)),h=Ka(f);let p=c[h],m=c[f];if(s){const v=h==="y"?"top":"left",g=h==="y"?"bottom":"right",w=p+u[v],S=p-u[g];p=Va(w,p,S)}if(i){const v=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+u[v],S=m-u[g];m=Va(w,m,S)}const x=a.fn({...t,[h]:p,[f]:m});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},i0=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),u={x:n,y:r},f=Nn(o),h=Ka(f);let p=u[h],m=u[f];const x=Bn(a,t),v=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};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 g,w;const S=h==="y"?"width":"height",T=Cf.has(Hn(o)),k=s.reference[f]-s.floating[S]+(T&&((g=i.offset)==null?void 0:g[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);m<k?m=k:m>C&&(m=C)}return{[h]:p,[f]:m}}}},a0=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),u=await wo(t,c),f=Hn(o),h=Lr(o),p=Nn(o)==="y",{width:m,height:x}=s.floating;let v,g;f==="top"||f==="bottom"?(v=f,g=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,v=h==="end"?"top":"bottom");const w=x-u.top-u.bottom,S=m-u.left-u.right,T=Zn(x-u[v],w),k=Zn(m-u[g],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=qt(u.left,0),$=qt(u.right,0),q=qt(u.top,0),P=qt(u.bottom,0);p?_=m-2*(D!==0||$!==0?D+$:qt(u.left,u.right)):E=x-2*(q!==0||P!==0?q+P:qt(u.top,u.bottom))}await l({...t,availableWidth:_,availableHeight:E});const j=await i.getDimensions(a.floating);return m!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function qs(){return typeof window<"u"}function Fr(e){return kf(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=(kf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function kf(e){return qs()?e instanceof Node||e instanceof Gt(e).Node:!1}function pn(e){return qs()?e instanceof Element||e instanceof Gt(e).Element:!1}function jn(e){return qs()?e instanceof HTMLElement||e instanceof Gt(e).HTMLElement:!1}function Tf(e){return!qs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gt(e).ShadowRoot}const l0=new Set(["inline","contents"]);function bo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=mn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!l0.has(o)}const c0=new Set(["table","td","th"]);function u0(e){return c0.has(Fr(e))}const d0=[":popover-open",":modal"];function Gs(e){return d0.some(t=>{try{return e.matches(t)}catch{return!1}})}const f0=["transform","translate","scale","rotate","perspective"],h0=["transform","translate","scale","rotate","perspective","filter"],p0=["paint","layout","strict","content"];function Xa(e){const t=Ja(),n=pn(e)?mn(e):e;return f0.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)||h0.some(r=>(n.willChange||"").includes(r))||p0.some(r=>(n.contain||"").includes(r))}function m0(e){let t=Qn(e);for(;jn(t)&&!$r(t);){if(Xa(t))return t;if(Gs(t))return null;t=Qn(t)}return null}function Ja(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const g0=new Set(["html","body","#document"]);function $r(e){return g0.has(Fr(e))}function mn(e){return Gt(e).getComputedStyle(e)}function Ys(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||Tf(e)&&e.host||_n(e);return Tf(t)?t.host:t}function Ef(e){const t=Qn(e);return $r(t)?e.ownerDocument?e.ownerDocument.body:e.body:jn(t)&&bo(t)?t:Ef(t)}function So(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Ef(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Gt(o);if(s){const a=Za(i);return t.concat(i,i.visualViewport||[],bo(o)?o:[],a&&n?So(a):[])}return t.concat(o,So(o,[],n))}function Za(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function If(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=Us(n)!==s||Us(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Qa(e){return pn(e)?e:e.contextElement}function zr(e){const t=Qa(e);if(!jn(t))return An(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=If(t);let i=(s?Us(n.width):n.width)/r,a=(s?Us(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const x0=An(0);function Af(e){const t=Gt(e);return!Ja()||!t.visualViewport?x0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function y0(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=Qa(e);let i=An(1);t&&(r?pn(r)&&(i=zr(r)):i=zr(e));const a=y0(s,n,r)?Af(s):An(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const h=Gt(s),p=r&&pn(r)?Gt(r):r;let m=h,x=Za(m);for(;x&&r&&p!==m;){const v=zr(x),g=x.getBoundingClientRect(),w=mn(x),S=g.left+(x.clientLeft+parseFloat(w.paddingLeft))*v.x,T=g.top+(x.clientTop+parseFloat(w.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,f*=v.y,l+=S,c+=T,m=Gt(x),x=Za(m)}}return Ks({width:u,height:f,x:l,y:c})}function Xs(e,t){const n=Ys(e).scrollLeft;return t?t.left+n:yr(_n(e)).left+n}function Nf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Xs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function v0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=_n(r),a=t?Gs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=An(1);const u=An(0),f=jn(r);if((f||!f&&!s)&&((Fr(r)!=="body"||bo(i))&&(l=Ys(r)),jn(r))){const p=yr(r);c=zr(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const h=i&&!f&&!s?Nf(i,l):An(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+h.x,y:n.y*c.y-l.scrollTop*c.y+u.y+h.y}}function w0(e){return Array.from(e.getClientRects())}function b0(e){const t=_n(e),n=Ys(e),r=e.ownerDocument.body,o=qt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=qt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Xs(e);const a=-n.scrollTop;return mn(r).direction==="rtl"&&(i+=qt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const _f=25;function S0(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 u=Ja();(!u||u&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Xs(r);if(c<=0){const u=r.ownerDocument,f=u.body,h=getComputedStyle(f),p=u.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=_f&&(s-=m)}else c<=_f&&(s+=c);return{width:s,height:i,x:a,y:l}}const C0=new Set(["absolute","fixed"]);function k0(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 jf(e,t,n){let r;if(t==="viewport")r=S0(e,n);else if(t==="document")r=b0(_n(e));else if(pn(t))r=k0(t,n);else{const o=Af(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ks(r)}function Rf(e,t){const n=Qn(e);return n===t||!pn(n)||$r(n)?!1:mn(n).position==="fixed"||Rf(n,t)}function T0(e,t){const n=t.get(e);if(n)return n;let r=So(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=Xa(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&C0.has(o.position)||bo(i)&&!l&&Rf(e,i))?r=r.filter(u=>u!==i):o=a,i=Qn(i)}return t.set(e,r),r}function E0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Gs(t)?[]:T0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const f=jf(t,u,o);return c.top=qt(f.top,c.top),c.right=Zn(f.right,c.right),c.bottom=Zn(f.bottom,c.bottom),c.left=qt(f.left,c.left),c},jf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function I0(e){const{width:t,height:n}=If(e);return{width:t,height:n}}function A0(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=Xs(o)}if(r||!r&&!s)if((Fr(t)!=="body"||bo(o))&&(a=Ys(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 u=o&&!r&&!s?Nf(o,a):An(0),f=i.left+a.scrollLeft-l.x-u.x,h=i.top+a.scrollTop-l.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function el(e){return mn(e).position==="static"}function Pf(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 Of(e,t){const n=Gt(e);if(Gs(e))return n;if(!jn(e)){let o=Qn(e);for(;o&&!$r(o);){if(pn(o)&&!el(o))return o;o=Qn(o)}return n}let r=Pf(e,t);for(;r&&u0(r)&&el(r);)r=Pf(r,t);return r&&$r(r)&&el(r)&&!Xa(r)?n:r||m0(e)||n}const N0=async function(e){const t=this.getOffsetParent||Of,n=this.getDimensions,r=await n(e.floating);return{reference:A0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function _0(e){return mn(e).direction==="rtl"}const j0={convertOffsetParentRelativeRectToViewportRelativeRect:v0,getDocumentElement:_n,getClippingRect:E0,getOffsetParent:Of,getElementRects:N0,getClientRects:w0,getDimensions:I0,getScale:zr,isElement:pn,isRTL:_0};function Mf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function R0(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:u,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=Ws(f),x=Ws(o.clientWidth-(u+h)),v=Ws(o.clientHeight-(f+p)),g=Ws(u),S={rootMargin:-m+"px "+-x+"px "+-v+"px "+-g+"px",threshold:qt(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&&!Mf(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 P0(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=Qa(e),u=o||s?[...c?So(c):[],...So(t)]:[];u.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?R0(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(g=>{let[w]=g;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 m,x=l?yr(e):null;l&&v();function v(){const g=yr(e);x&&!Mf(x,g)&&n(),x=g,m=requestAnimationFrame(v)}return n(),()=>{var g;u.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=p)==null||g.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const O0=o0,M0=s0,D0=t0,L0=a0,F0=n0,Df=e0,$0=i0,z0=(e,t,n)=>{const r=new Map,o={platform:j0,...n},s={...o.platform,_c:r};return Qb(e,t,{...o,platform:s})};var B0=typeof document<"u",H0=function(){},Js=B0?b.useLayoutEffect:H0;function Zs(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(!Zs(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)&&!Zs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Lf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ff(e,t){const n=Lf(e);return Math.round(t*n)/n}function tl(e){const t=y.useRef(e);return Js(()=>{t.current=e}),t}function U0(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,[u,f]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=y.useState(r);Zs(h,r)||p(r);const[m,x]=y.useState(null),[v,g]=y.useState(null),w=y.useCallback(K=>{K!==C.current&&(C.current=K,x(K))},[]),S=y.useCallback(K=>{K!==E.current&&(E.current=K,g(K))},[]),T=s||m,k=i||v,C=y.useRef(null),E=y.useRef(null),_=y.useRef(u),j=l!=null,D=tl(l),$=tl(o),q=tl(c),P=y.useCallback(()=>{if(!C.current||!E.current)return;const K={placement:t,strategy:n,middleware:h};$.current&&(K.platform=$.current),z0(C.current,E.current,K).then(B=>{const pe={...B,isPositioned:q.current!==!1};R.current&&!Zs(_.current,pe)&&(_.current=pe,Mo.flushSync(()=>{f(pe)}))})},[h,t,n,$,q]);Js(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,f(K=>({...K,isPositioned:!1})))},[c]);const R=y.useRef(!1);Js(()=>(R.current=!0,()=>{R.current=!1}),[]),Js(()=>{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=y.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),F=y.useMemo(()=>({reference:T,floating:k}),[T,k]),ne=y.useMemo(()=>{const K={position:n,left:0,top:0};if(!F.floating)return K;const B=Ff(F.floating,u.x),pe=Ff(F.floating,u.y);return a?{...K,transform:"translate("+B+"px, "+pe+"px)",...Lf(F.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:B,top:pe}},[n,a,F.floating,u.x,u.y]);return y.useMemo(()=>({...u,update:P,refs:L,elements:F,floatingStyles:ne}),[u,P,L,F,ne])}const W0=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?Df({element:r.current,padding:o}).fn(n):{}:r?Df({element:r,padding:o}).fn(n):{}}}},V0=(e,t)=>({...O0(e),options:[e,t]}),K0=(e,t)=>({...M0(e),options:[e,t]}),q0=(e,t)=>({...$0(e),options:[e,t]}),G0=(e,t)=>({...D0(e),options:[e,t]}),Y0=(e,t)=>({...L0(e),options:[e,t]}),X0=(e,t)=>({...F0(e),options:[e,t]}),J0=(e,t)=>({...W0(e),options:[e,t]});var Z0="Arrow",$f=y.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return d.jsx(Ie.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});$f.displayName=Z0;var Q0=$f;function zf(e){const[t,n]=y.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 nl="Popper",[Bf,Qs]=Tn(nl),[eS,Hf]=Bf(nl),Uf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=y.useState(null);return d.jsx(eS,{scope:t,anchor:r,onAnchorChange:o,children:n})};Uf.displayName=nl;var Wf="PopperAnchor",Vf=y.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Hf(Wf,n),i=y.useRef(null),a=He(t,i),l=y.useRef(null);return y.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:d.jsx(Ie.div,{...o,ref:a})});Vf.displayName=Wf;var rl="PopperContent",[tS,nS]=Bf(rl),Kf=y.forwardRef((e,t)=>{var G,M,X,oe,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:u=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...x}=e,v=Hf(rl,n),[g,w]=y.useState(null),S=He(t,re=>w(re)),[T,k]=y.useState(null),C=zf(T),E=(C==null?void 0:C.width)??0,_=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),D=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},$=Array.isArray(c)?c:[c],q=$.length>0,P={padding:D,boundary:$.filter(oS),altBoundary:q},{refs:R,floatingStyles:L,placement:F,isPositioned:ne,middlewareData:K}=U0({strategy:"fixed",placement:j,whileElementsMounted:(...re)=>P0(...re,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[V0({mainAxis:o+_,alignmentAxis:i}),l&&K0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?q0():void 0,...P}),l&&G0({...P}),Y0({...P,apply:({elements:re,rects:Ue,availableWidth:Ke,availableHeight:ot})=>{const{width:at,height:ht}=Ue.reference,tt=re.floating.style;tt.setProperty("--radix-popper-available-width",`${Ke}px`),tt.setProperty("--radix-popper-available-height",`${ot}px`),tt.setProperty("--radix-popper-anchor-width",`${at}px`),tt.setProperty("--radix-popper-anchor-height",`${ht}px`)}}),T&&J0({element:T,padding:a}),sS({arrowWidth:E,arrowHeight:_}),h&&X0({strategy:"referenceHidden",...P})]}),[B,pe]=Yf(F),W=At(m);kt(()=>{ne&&(W==null||W())},[ne,W]);const ce=(G=K.arrow)==null?void 0:G.x,H=(M=K.arrow)==null?void 0:M.y,Z=((X=K.arrow)==null?void 0:X.centerOffset)!==0,[we,ye]=y.useState();return kt(()=>{g&&ye(window.getComputedStyle(g).zIndex)},[g]),d.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:ne?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:we,"--radix-popper-transform-origin":[(oe=K.transformOrigin)==null?void 0:oe.x,(xe=K.transformOrigin)==null?void 0:xe.y].join(" "),...((se=K.hide)==null?void 0:se.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(tS,{scope:n,placedSide:B,onArrowChange:k,arrowX:ce,arrowY:H,shouldHideArrow:Z,children:d.jsx(Ie.div,{"data-side":B,"data-align":pe,...x,ref:S,style:{...x.style,animation:ne?void 0:"none"}})})})});Kf.displayName=rl;var qf="PopperArrow",rS={top:"bottom",right:"left",bottom:"top",left:"right"},Gf=y.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=nS(qf,r),i=rS[s.placedSide];return d.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:d.jsx(Q0,{...o,ref:n,style:{...o.style,display:"block"}})})});Gf.displayName=qf;function oS(e){return e!==null}var sS=e=>({name:"transformOrigin",options:e,fn(t){var v,g,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,u]=Yf(n),f={start:"0%",center:"50%",end:"100%"}[u],h=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",x="";return c==="bottom"?(m=i?f:`${h}px`,x=`${-l}px`):c==="top"?(m=i?f:`${h}px`,x=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,x=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:m,y:x}}}});function Yf(e){const[t,n="center"]=e.split("-");return[t,n]}var Xf=Uf,Jf=Vf,Zf=Kf,Qf=Gf,ol="rovingFocusGroup.onEntryFocus",iS={bubbles:!1,cancelable:!0},Co="RovingFocusGroup",[sl,eh,aS]=Wa(Co),[lS,th]=Tn(Co,[aS]),[cS,uS]=lS(Co),nh=y.forwardRef((e,t)=>d.jsx(sl.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(sl.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(dS,{...e,ref:t})})}));nh.displayName=Co;var dS=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...f}=e,h=y.useRef(null),p=He(t,h),m=Hs(s),[x,v]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Co}),[g,w]=y.useState(!1),S=At(c),T=eh(n),k=y.useRef(!1),[C,E]=y.useState(0);return y.useEffect(()=>{const _=h.current;if(_)return _.addEventListener(ol,S),()=>_.removeEventListener(ol,S)},[S]),d.jsx(cS,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:x,onItemFocus:y.useCallback(_=>v(_),[v]),onItemShiftTab:y.useCallback(()=>w(!0),[]),onFocusableItemAdd:y.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:y.useCallback(()=>E(_=>_-1),[]),children:d.jsx(Ie.div,{tabIndex:g||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&&!g){const D=new CustomEvent(ol,iS);if(_.currentTarget.dispatchEvent(D),!D.defaultPrevented){const $=T().filter(F=>F.focusable),q=$.find(F=>F.active),P=$.find(F=>F.id===x),L=[q,P,...$].filter(Boolean).map(F=>F.ref.current);sh(L,u)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),rh="RovingFocusGroupItem",oh=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=En(),c=s||l,u=uS(rh,n),f=u.currentTabStopId===c,h=eh(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:x}=u;return y.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),d.jsx(sl.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:d.jsx(Ie.span,{tabIndex:f?0:-1,"data-orientation":u.orientation,...a,ref:t,onMouseDown:ge(e.onMouseDown,v=>{r?u.onItemFocus(c):v.preventDefault()}),onFocus:ge(e.onFocus,()=>u.onItemFocus(c)),onKeyDown:ge(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){u.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const g=pS(v,u.orientation,u.dir);if(g!==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(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const T=S.indexOf(v.currentTarget);S=u.loop?mS(S,T+1):S.slice(T+1)}setTimeout(()=>sh(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});oh.displayName=rh;var fS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function hS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pS(e,t,n){const r=hS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fS[r]}function sh(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function mS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var gS=nh,xS=oh,il=["Enter"," "],yS=["ArrowDown","PageUp","Home"],ih=["ArrowUp","PageDown","End"],vS=[...yS,...ih],wS={ltr:[...il,"ArrowRight"],rtl:[...il,"ArrowLeft"]},bS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ko="Menu",[To,SS,CS]=Wa(ko),[vr,ah]=Tn(ko,[CS,Qs,th]),ei=Qs(),lh=th(),[kS,wr]=vr(ko),[TS,Eo]=vr(ko),ch=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ei(t),[l,c]=y.useState(null),u=y.useRef(!1),f=At(s),h=Hs(o);return y.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),d.jsx(Xf,{...a,children:d.jsx(kS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:d.jsx(TS,{scope:t,onClose:y.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:h,modal:i,children:r})})})};ch.displayName=ko;var ES="MenuAnchor",al=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ei(n);return d.jsx(Jf,{...o,...r,ref:t})});al.displayName=ES;var ll="MenuPortal",[IS,uh]=vr(ll,{forceMount:void 0}),dh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=wr(ll,t);return d.jsx(IS,{scope:t,forceMount:n,children:d.jsx(Kt,{present:n||s.open,children:d.jsx(Ss,{asChild:!0,container:o,children:r})})})};dh.displayName=ll;var nn="MenuContent",[AS,cl]=vr(nn),fh=y.forwardRef((e,t)=>{const n=uh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=Eo(nn,e.__scopeMenu);return d.jsx(To.Provider,{scope:e.__scopeMenu,children:d.jsx(Kt,{present:r||s.open,children:d.jsx(To.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(NS,{...o,ref:t}):d.jsx(_S,{...o,ref:t})})})})}),NS=y.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu),r=y.useRef(null),o=He(t,r);return y.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),d.jsx(ul,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),_S=y.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu);return d.jsx(ul,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),jS=sr.createSlot("MenuContent.ScrollLock"),ul=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...x}=e,v=wr(nn,n),g=Eo(nn,n),w=ei(n),S=lh(n),T=SS(n),[k,C]=y.useState(null),E=y.useRef(null),_=He(t,E,v.onContentChange),j=y.useRef(0),D=y.useRef(""),$=y.useRef(0),q=y.useRef(null),P=y.useRef("right"),R=y.useRef(0),L=m?As:y.Fragment,F=m?{as:jS,allowPinchZoom:!0}:void 0,ne=B=>{var G,M;const pe=D.current+B,W=T().filter(X=>!X.disabled),ce=document.activeElement,H=(G=W.find(X=>X.ref.current===ce))==null?void 0:G.textValue,Z=W.map(X=>X.textValue),we=US(Z,pe,H),ye=(M=W.find(X=>X.textValue===we))==null?void 0:M.ref.current;(function X(oe){D.current=oe,window.clearTimeout(j.current),oe!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(pe),ye&&setTimeout(()=>ye.focus())};y.useEffect(()=>()=>window.clearTimeout(j.current),[]),_a();const K=y.useCallback(B=>{var W,ce;return P.current===((W=q.current)==null?void 0:W.side)&&VS(B,(ce=q.current)==null?void 0:ce.area)},[]);return d.jsx(AS,{scope:n,searchRef:D,onItemEnter:y.useCallback(B=>{K(B)&&B.preventDefault()},[K]),onItemLeave:y.useCallback(B=>{var pe;K(B)||((pe=E.current)==null||pe.focus(),C(null))},[K]),onTriggerLeave:y.useCallback(B=>{K(B)&&B.preventDefault()},[K]),pointerGraceTimerRef:$,onPointerGraceIntentChange:y.useCallback(B=>{q.current=B},[]),children:d.jsx(L,{...F,children:d.jsx(bs,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,B=>{var pe;B.preventDefault(),(pe=E.current)==null||pe.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(ws,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:d.jsx(gS,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:ge(l,B=>{g.isUsingKeyboardRef.current||B.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(Zf,{role:"menu","aria-orientation":"vertical","data-state":Nh(v.open),"data-radix-menu-content":"",dir:g.dir,...w,...x,ref:_,style:{outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,B=>{const W=B.target.closest("[data-radix-menu-content]")===B.currentTarget,ce=B.ctrlKey||B.altKey||B.metaKey,H=B.key.length===1;W&&(B.key==="Tab"&&B.preventDefault(),!ce&&H&&ne(B.key));const Z=E.current;if(B.target!==Z||!vS.includes(B.key))return;B.preventDefault();const ye=T().filter(G=>!G.disabled).map(G=>G.ref.current);ih.includes(B.key)&&ye.reverse(),BS(ye)}),onBlur:ge(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(j.current),D.current="")}),onPointerMove:ge(e.onPointerMove,Ao(B=>{const pe=B.target,W=R.current!==B.clientX;if(B.currentTarget.contains(pe)&&W){const ce=B.clientX>R.current?"right":"left";P.current=ce,R.current=B.clientX}}))})})})})})})});fh.displayName=nn;var RS="MenuGroup",dl=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ie.div,{role:"group",...r,ref:t})});dl.displayName=RS;var PS="MenuLabel",hh=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ie.div,{...r,ref:t})});hh.displayName=PS;var ti="MenuItem",ph="menu.itemSelect",ni=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=y.useRef(null),i=Eo(ti,e.__scopeMenu),a=cl(ti,e.__scopeMenu),l=He(t,s),c=y.useRef(!1),u=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ph,{bubbles:!0,cancelable:!0});f.addEventListener(ph,p=>r==null?void 0:r(p),{once:!0}),Qu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(mh,{...o,ref:l,disabled:n,onClick:ge(e.onClick,u),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===" "||il.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ni.displayName=ti;var mh=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=cl(ti,n),a=lh(n),l=y.useRef(null),c=He(t,l),[u,f]=y.useState(!1),[h,p]=y.useState("");return y.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),d.jsx(To.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:d.jsx(xS,{asChild:!0,...a,focusable:!r,children:d.jsx(Ie.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ge(e.onPointerMove,Ao(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Ao(m=>i.onItemLeave(m))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),OS="MenuCheckboxItem",gh=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return d.jsx(bh,{scope:e.__scopeMenu,checked:n,children:d.jsx(ni,{role:"menuitemcheckbox","aria-checked":ri(n)?"mixed":n,...o,ref:t,"data-state":hl(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(ri(n)?!0:!n),{checkForDefaultPrevented:!1})})})});gh.displayName=OS;var xh="MenuRadioGroup",[MS,DS]=vr(xh,{value:void 0,onValueChange:()=>{}}),yh=y.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=At(r);return d.jsx(MS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:d.jsx(dl,{...o,ref:t})})});yh.displayName=xh;var vh="MenuRadioItem",wh=y.forwardRef((e,t)=>{const{value:n,...r}=e,o=DS(vh,e.__scopeMenu),s=n===o.value;return d.jsx(bh,{scope:e.__scopeMenu,checked:s,children:d.jsx(ni,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":hl(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});wh.displayName=vh;var fl="MenuItemIndicator",[bh,LS]=vr(fl,{checked:!1}),Sh=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=LS(fl,n);return d.jsx(Kt,{present:r||ri(s.checked)||s.checked===!0,children:d.jsx(Ie.span,{...o,ref:t,"data-state":hl(s.checked)})})});Sh.displayName=fl;var FS="MenuSeparator",Ch=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ie.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Ch.displayName=FS;var $S="MenuArrow",kh=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ei(n);return d.jsx(Qf,{...o,...r,ref:t})});kh.displayName=$S;var zS="MenuSub",[ST,Th]=vr(zS),Io="MenuSubTrigger",Eh=y.forwardRef((e,t)=>{const n=wr(Io,e.__scopeMenu),r=Eo(Io,e.__scopeMenu),o=Th(Io,e.__scopeMenu),s=cl(Io,e.__scopeMenu),i=y.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=y.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return y.useEffect(()=>u,[u]),y.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),d.jsx(al,{asChild:!0,...c,children:d.jsx(mh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Nh(n.open),...e,ref:ya(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,Ao(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:ge(e.onPointerLeave,Ao(f=>{var p,m;u();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(m=n.content)==null?void 0:m.dataset.side,v=x==="right",g=v?-5:5,w=h[v?"left":"right"],S=h[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:w,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:w,y:h.bottom}],side:x}),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===" "||wS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Eh.displayName=Io;var Ih="MenuSubContent",Ah=y.forwardRef((e,t)=>{const n=uh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=Eo(nn,e.__scopeMenu),a=Th(Ih,e.__scopeMenu),l=y.useRef(null),c=He(t,l);return d.jsx(To.Provider,{scope:e.__scopeMenu,children:d.jsx(Kt,{present:r||s.open,children:d.jsx(To.Slot,{scope:e.__scopeMenu,children:d.jsx(ul,{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:u=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ge(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ge(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ge(e.onKeyDown,u=>{var p;const f=u.currentTarget.contains(u.target),h=bS[i.dir].includes(u.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});Ah.displayName=Ih;function Nh(e){return e?"open":"closed"}function ri(e){return e==="indeterminate"}function hl(e){return ri(e)?"indeterminate":e?"checked":"unchecked"}function BS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function HS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function US(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=HS(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 WS(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,u=a.y,f=l.x,h=l.y;u>r!=h>r&&n<(f-c)*(r-u)/(h-u)+c&&(o=!o)}return o}function VS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return WS(n,t)}function Ao(e){return t=>t.pointerType==="mouse"?e(t):void 0}var KS=ch,qS=al,GS=dh,YS=fh,XS=dl,JS=hh,ZS=ni,QS=gh,eC=yh,tC=wh,nC=Sh,rC=Ch,oC=kh,sC=Eh,iC=Ah,oi="DropdownMenu",[aC,CT]=Tn(oi,[ah]),$t=ah(),[lC,_h]=aC(oi),jh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=$t(t),c=y.useRef(null),[u,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:oi});return d.jsx(lC,{scope:t,triggerId:En(),triggerRef:c,contentId:En(),open:u,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(h=>!h),[f]),modal:a,children:d.jsx(KS,{...l,open:u,onOpenChange:f,dir:r,modal:a,children:n})})};jh.displayName=oi;var Rh="DropdownMenuTrigger",Ph=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=_h(Rh,n),i=$t(n);return d.jsx(qS,{asChild:!0,...i,children:d.jsx(Ie.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:ya(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())})})})});Ph.displayName=Rh;var cC="DropdownMenuPortal",Oh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=$t(t);return d.jsx(GS,{...r,...n})};Oh.displayName=cC;var Mh="DropdownMenuContent",Dh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=_h(Mh,n),s=$t(n),i=y.useRef(!1);return d.jsx(YS,{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,u=l.button===2||c;(!o.modal||u)&&(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)"}})});Dh.displayName=Mh;var uC="DropdownMenuGroup",dC=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(XS,{...o,...r,ref:t})});dC.displayName=uC;var fC="DropdownMenuLabel",Lh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(JS,{...o,...r,ref:t})});Lh.displayName=fC;var hC="DropdownMenuItem",Fh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(ZS,{...o,...r,ref:t})});Fh.displayName=hC;var pC="DropdownMenuCheckboxItem",$h=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(QS,{...o,...r,ref:t})});$h.displayName=pC;var mC="DropdownMenuRadioGroup",gC=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(eC,{...o,...r,ref:t})});gC.displayName=mC;var xC="DropdownMenuRadioItem",zh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(tC,{...o,...r,ref:t})});zh.displayName=xC;var yC="DropdownMenuItemIndicator",Bh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(nC,{...o,...r,ref:t})});Bh.displayName=yC;var vC="DropdownMenuSeparator",Hh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(rC,{...o,...r,ref:t})});Hh.displayName=vC;var wC="DropdownMenuArrow",bC=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(oC,{...o,...r,ref:t})});bC.displayName=wC;var SC="DropdownMenuSubTrigger",Uh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(sC,{...o,...r,ref:t})});Uh.displayName=SC;var CC="DropdownMenuSubContent",Wh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(iC,{...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)"}})});Wh.displayName=CC;var kC=jh,TC=Ph,EC=Oh,Vh=Dh,Kh=Lh,qh=Fh,Gh=$h,Yh=zh,Xh=Bh,Jh=Hh,Zh=Uh,Qh=Wh;const IC=kC,AC=TC,NC=y.forwardRef(({className:e,inset:t,children:n,...r},o)=>d.jsxs(Zh,{ref:o,className:ee("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,d.jsx(fe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));NC.displayName=Zh.displayName;const _C=y.forwardRef(({className:e,...t},n)=>d.jsx(Qh,{ref:n,className:ee("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}));_C.displayName=Qh.displayName;const ep=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>d.jsx(EC,{children:d.jsx(Vh,{ref:r,sideOffset:t,className:ee("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})}));ep.displayName=Vh.displayName;const pl=y.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(qh,{ref:r,className:ee("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}));pl.displayName=qh.displayName;const jC=y.forwardRef(({className:e,children:t,checked:n,...r},o)=>d.jsxs(Gh,{ref:o,className:ee("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:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Xh,{children:d.jsx(fe.Check,{className:"h-4 w-4"})})}),t]}));jC.displayName=Gh.displayName;const RC=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(Yh,{ref:r,className:ee("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:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Xh,{children:d.jsx(fe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));RC.displayName=Yh.displayName;const PC=y.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(Kh,{ref:r,className:ee("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));PC.displayName=Kh.displayName;const OC=y.forwardRef(({className:e,...t},n)=>d.jsx(Jh,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));OC.displayName=Jh.displayName;const tp={value:""};function si({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:u=!0,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:m}){const{api:x}=Ri(),{currentThreadId:v}=Qo(),{threadId:g,messages:w,hasMore:S,isHistoryLoading:T,isLoading:k,loadOlder:C,navigateToCheckpoint:E,returnToLatest:_,checkpoint:j,checkpoints:D,interrupt:$,metadata:q}=es(),{isStreaming:P,error:R,submit:L,stop:F}=Yc(),ne=g??v??null,K=(j==null?void 0:j.id)??null,B=(j==null?void 0:j.namespace)??null,pe=(q==null?void 0:q.assemblingMessageId)??null,W=$,[ce,H]=b.useState(!1);b.useEffect(()=>{W||H(!1)},[W]);const Z=b.useCallback(()=>{H(!0)},[]),we=b.useCallback(()=>{H(!1)},[]),ye=!!W||ce,[G,M]=b.useState(null),[X,oe]=b.useState(""),[xe,se]=b.useState(null),[re,Ue]=b.useState([]),[Ke,ot]=b.useState(0),[at,ht]=b.useState(0),[tt,Me]=b.useState(!1),[We,lt]=b.useState(null),[xt,dt]=b.useState(null),[Je,ie]=b.useState(!1),[je,ke]=b.useState(null),[qe,nt]=b.useState(!1),Oe=b.useRef(!1),[Xe,Tt]=b.useState(()=>tp.value),St=b.useRef(Xe),Yt=b.useRef(null),Et=b.useCallback(z=>{tp.value=z,Tt(z)},[]),[rr,Xt]=b.useState(!1),xn=b.useCallback((z,ue)=>{if(!z||typeof z!="object")return null;const me=z[ue];return typeof me=="number"?me:null},[]),sn=b.useCallback((z,ue)=>{if(!z||typeof z!="object")return null;const me=z[ue];return typeof me=="string"&&me.trim()?me:null},[]),Dt=b.useMemo(()=>{const z=Array.isArray(D)?[...D]:[];return z.some(me=>xn(me.metadata,"step")!==null)&&z.sort((me,Re)=>{const rt=xn(me.metadata,"step"),Lt=xn(Re.metadata,"step");if(rt!==null||Lt!==null)return(Lt??Number.NEGATIVE_INFINITY)-(rt??Number.NEGATIVE_INFINITY);const an=Date.parse(me.createdAt??""),Ct=Date.parse(Re.createdAt??"");return Number.isNaN(an)||Number.isNaN(Ct)?0:Ct-an}),z},[D,xn]),Pn=b.useRef(null),yn=b.useRef(null),pt=b.useCallback(()=>{Pn.current&&(Pn.current.value=""),yn.current&&(yn.current.value=""),ot(z=>z+1),ht(z=>z+1)},[]),vn=b.useCallback(z=>{Et(z)},[Et]),On=b.useRef(!1);b.useEffect(()=>{On.current&&!P&&(Ue([]),pt()),On.current=P},[P,pt]);const[kr,Jt]=b.useState("desktop");b.useEffect(()=>{const z=()=>{const ue=window.innerWidth;Jt(ue<640?"phone":ue<1024?"tablet":"desktop")};return z(),window.addEventListener("resize",z),()=>window.removeEventListener("resize",z)},[]),b.useEffect(()=>{nt(!1),Oe.current=!1},[ne]),b.useEffect(()=>{St.current=Xe},[Xe]),b.useEffect(()=>{if(!G){Yt.current=null;return}Yt.current===null&&(Yt.current=St.current),Et(X??"")},[X,G,Et]);const Tr=b.useCallback(async()=>{if(!(!S||T||!qe))try{await C()}catch(z){console.warn("loadOlder failed",z)}},[S,qe,T,C]);b.useEffect(()=>{(async()=>{if(!x.baseUrl){ke(null);return}try{const me=(await x.getAgent("default")).uiDefaultMessage||"";ke(me||null)}catch(ue){console.warn("Failed to fetch default message:",ue),ke(null)}})()},[x.baseUrl]),b.useEffect(()=>{R&&!Je&&(m==null||m(R))},[R,Je,m]);const Mn=z=>{if(z.length>Bs)return`Message too long (${z.length}/${Bs} characters)`;try{return zb(z),null}catch(ue){return(ue==null?void 0:ue.message)||"Invalid message"}},wn=async z=>{const ue=z.trim();if(!(!ue&&re.length===0)){if(ue){const me=Mn(ue);if(me){se(me);return}}try{await L({text:ue||"",attachments:re,payload:G?{edit:!0,originalMessageId:G}:void 0},{checkpointId:K??void 0,checkpointNs:B??void 0}),h==null||h(ue),Et(""),se(null),Ue([]),pt(),M(null),oe("")}catch(me){const Re=(me==null?void 0:me.message)||"Failed to send message";se(Re),m==null||m(Re)}}},Un=b.useCallback((z,ue)=>{c&&(Yt.current=Xe,M(z),oe(ue),Et(ue),se(null))},[Xe,c,Et]),Er=b.useCallback(()=>{M(null),oe(""),se(null),Et(Yt.current??Xe),Yt.current=null},[Xe,Et]),Wr=b.useCallback((z,ue)=>{Un(z,ue)},[Un]),Vr=b.useCallback(z=>{for(let ue=z-1;ue>=0;ue--)if(w[ue].role==="user"){const me=w[ue].content||[],rt=me.filter(Lt=>Lt.type==="text").map(Lt=>Lt.text).join("")||(()=>{try{return JSON.stringify(me,null,2)}catch{return String(me)}})();rt&&L({text:rt},{checkpointId:K??void 0,checkpointNs:B??void 0});break}},[w,L,K,B]),or=z=>{const ue=Array.from(z.target.files||[]);Ue(me=>[...me,...ue]),z.target.value=""},I=z=>{Ue(ue=>{const me=ue.filter((Re,rt)=>z!==rt);return me.length===0&&pt(),me})},U=async z=>{const ue=(z.target.files||[])[0];if(ue){lt(null),dt(null),Me(!0);try{await L({attachments:[ue]},{checkpointId:K??void 0,checkpointNs:B??void 0});const me=`Uploaded ${ue.name} - processing through chat stream`;dt(me)}catch(me){const Re=me instanceof Error?me.message:"Failed to upload Excel file";console.error("Excel upload failed",me),lt(Re),m==null||m(Re)}finally{Me(!1),z.target.value="",pt()}}},le=z=>{if(!z)return"Unknown";const ue=Date.parse(z);return Number.isNaN(ue)?z:new Date(ue).toLocaleString()},Ce=async z=>{if(v){Xt(!0);try{if(!z){await _();return}const ue=Dt.find(Re=>Re.checkpointId===z),me=(ue==null?void 0:ue.checkpointNs)??null;await E(z,me)}finally{Xt(!1)}}},Ge=`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||""}`,Fe=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`;return d.jsxs("div",{className:Ge,children:[!!R&&!Je&&d.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:[d.jsx("span",{children:R}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>ie(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:d.jsx(fe.X,{size:16})})]}),v&&D.length>0&&d.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:[d.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),d.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:K??"",onChange:z=>{const ue=z.target.value||null;Ce(ue)},children:[d.jsx("option",{value:"",children:"Latest"}),Dt.map(z=>{const ue=xn(z.metadata,"step"),me=sn(z.metadata,"source"),Re=[];ue!==null&&Re.push(`Step ${ue}`),me&&Re.push(me);const rt=Re.length?` — ${Re.join(" • ")}`:"";return d.jsxs("option",{value:z.checkpointId,children:[le(z.createdAt),rt]},z.checkpointId)})]})]}),d.jsxs("div",{className:`relative ${$e}`,style:r?{maxHeight:r}:void 0,children:[d.jsx(Ua,{className:"h-full",style:{height:"100%"},messages:w,isStreaming:P,streamingAssistantId:pe,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:kr,enableMessageEditing:c,editingMessageId:G,onStartReached:()=>{qe&&Tr()},onScrollAway:z=>{if(!Oe.current){Oe.current=!0;return}z&&nt(!0)},onEdit:Wr,onRegenerate:Vr,onCancelEdit:Er,emptyMessage:je??void 0,isNavigatingCheckpoint:rr,activeInterrupt:W,disableInterruptActions:ce,onInterruptActionStart:Z,onInterruptActionEnd:we,showToolMessages:u}),k&&d.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:[d.jsx(fe.Loader2,{className:"h-6 w-6 animate-spin"}),d.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),d.jsxs("div",{className:Fe,children:[G&&d.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(fe.Edit3,{size:16,className:"text-blue-600"}),d.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Er,className:"text-blue-600 hover:bg-blue-100",children:d.jsx(fe.X,{size:16})})]})}),(a||l)&&d.jsxs("div",{className:"mb-3 space-y-3",children:[a&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:Pn,type:"file",multiple:!0,onChange:z=>or(z),className:"hidden"},Ke),re.length>0&&d.jsx("div",{className:"flex flex-wrap gap-2",children:re.map((z,ue)=>d.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:[d.jsx(fe.Paperclip,{size:14}),d.jsx("span",{className:"truncate max-w-[150px]",children:z.name}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>I(ue),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 ${z.name}`,children:d.jsx(fe.X,{size:12})})]},ue))})]}),l&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:yn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:U,className:"hidden"},at),tt&&d.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(fe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!tt&&d.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),We&&!tt&&d.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:We})]})]}),xe&&d.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:xe}),d.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&d.jsxs(IC,{children:[d.jsx(AC,{asChild:!0,children:d.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:P||ye,title:"More input actions",className:f.moreButton||"",children:d.jsx(fe.Plus,{size:16})})}),d.jsxs(ep,{align:"start",sideOffset:6,className:"w-52",children:[a&&d.jsxs(pl,{onClick:()=>{var z;return(z=Pn.current)==null?void 0:z.click()},className:"cursor-pointer",children:[d.jsx(fe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&d.jsxs(pl,{onClick:()=>{var z;tt||(z=yn.current)==null||z.click()},className:`cursor-pointer ${tt?"opacity-60 pointer-events-none":""}`,children:[d.jsx(fe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),d.jsx("div",{className:"flex-1",children:d.jsx(Zx,{initialValue:X,editingMessageId:G,value:Xe,onValueChange:vn,placeholder:G?"Edit your message...":t,isStreaming:P,disabled:ye,maxLength:Bs,onSend:wn,onCancelEdit:Er,onStop:F,allowEmptySend:re.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${G?"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 ii=y.forwardRef(({className:e,type:t,...n},r)=>d.jsx("input",{type:t,className:ee("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}));ii.displayName="Input";function ml(e,[t,n]){return Math.min(n,Math.max(t,e))}function MC(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var gl="ScrollArea",[np,kT]=Tn(gl),[DC,rn]=np(gl),rp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=y.useState(null),[c,u]=y.useState(null),[f,h]=y.useState(null),[p,m]=y.useState(null),[x,v]=y.useState(null),[g,w]=y.useState(0),[S,T]=y.useState(0),[k,C]=y.useState(!1),[E,_]=y.useState(!1),j=He(t,$=>l($)),D=Hs(o);return d.jsx(DC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:u,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:k,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:_,onCornerWidthChange:w,onCornerHeightChange:T,children:d.jsx(Ie.div,{dir:D,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});rp.displayName=gl;var op="ScrollAreaViewport",sp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=rn(op,n),a=y.useRef(null),l=He(t,a,i.onViewportChange);return d.jsxs(d.Fragment,{children:[d.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}),d.jsx(Ie.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:d.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});sp.displayName=op;var Rn="ScrollAreaScrollbar",xl=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return y.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?d.jsx(LC,{...r,ref:t,forceMount:n}):o.type==="scroll"?d.jsx(FC,{...r,ref:t,forceMount:n}):o.type==="auto"?d.jsx(ip,{...r,ref:t,forceMount:n}):o.type==="always"?d.jsx(yl,{...r,ref:t}):null});xl.displayName=Rn;var LC=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),[s,i]=y.useState(!1);return y.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},u=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",u),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),d.jsx(Kt,{present:n||s,children:d.jsx(ip,{"data-state":s?"visible":"hidden",...r,ref:t})})}),FC=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ui(()=>l("SCROLL_END"),100),[a,l]=MC("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 y.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),y.useEffect(()=>{const c=o.viewport,u=s?"scrollLeft":"scrollTop";if(c){let f=c[u];const h=()=>{const p=c[u];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),d.jsx(Kt,{present:n||a!=="hidden",children:d.jsx(yl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),ip=y.forwardRef((e,t)=>{const n=rn(Rn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=y.useState(!1),a=e.orientation==="horizontal",l=ui(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:u)}},10);return Br(n.viewport,l),Br(n.content,l),d.jsx(Kt,{present:r||s,children:d.jsx(yl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),yl=y.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=rn(Rn,e.__scopeScrollArea),s=y.useRef(null),i=y.useRef(0),[a,l]=y.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=dp(a.viewport,a.content),u={...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 WC(h,i.current,a,p)}return n==="horizontal"?d.jsx($C,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=fp(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"?d.jsx(zC,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=fp(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}),$C=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=He(t,l,s.onScrollbarXChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(lp,{"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":ci(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(h),pp(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:li(i.paddingLeft),paddingEnd:li(i.paddingRight)}})}})}),zC=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=He(t,l,s.onScrollbarYChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(lp,{"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":ci(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(h),pp(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:li(i.paddingTop),paddingEnd:li(i.paddingBottom)}})}})}),[BC,ap]=np(Rn),lp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:u,onResize:f,...h}=e,p=rn(Rn,n),[m,x]=y.useState(null),v=He(t,j=>x(j)),g=y.useRef(null),w=y.useRef(""),S=p.viewport,T=r.content-r.viewport,k=At(u),C=At(l),E=ui(f,10);function _(j){if(g.current){const D=j.clientX-g.current.left,$=j.clientY-g.current.top;c({x:D,y:$})}}return y.useEffect(()=>{const j=D=>{const $=D.target;(m==null?void 0:m.contains($))&&k(D,T)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,m,T,k]),y.useEffect(C,[r,C]),Br(m,E),Br(p.content,E),d.jsx(BC,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:At(s),onThumbPointerUp:At(i),onThumbPositionChange:C,onThumbPointerDown:At(a),children:d.jsx(Ie.div,{...h,ref:v,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=m.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=""),g.current=null})})})}),ai="ScrollAreaThumb",cp=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ap(ai,e.__scopeScrollArea);return d.jsx(Kt,{present:n||o.hasThumb,children:d.jsx(HC,{ref:t,...r})})}),HC=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=rn(ai,n),i=ap(ai,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),c=y.useRef(void 0),u=ui(()=>{c.current&&(c.current(),c.current=void 0)},100);return y.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(u(),!c.current){const p=VC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,u,a]),d.jsx(Ie.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(),m=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:m,y:x})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});cp.displayName=ai;var vl="ScrollAreaCorner",up=y.forwardRef((e,t)=>{const n=rn(vl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?d.jsx(UC,{...e,ref:t}):null});up.displayName=vl;var UC=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=rn(vl,n),[s,i]=y.useState(0),[a,l]=y.useState(0),c=!!(s&&a);return Br(o.scrollbarX,()=>{var f;const u=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(u),l(u)}),Br(o.scrollbarY,()=>{var f;const u=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(u),i(u)}),c?d.jsx(Ie.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 li(e){return e?parseInt(e,10):0}function dp(e,t){const n=e/t;return isNaN(n)?0:n}function ci(e){const t=dp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function WC(e,t,n,r="ltr"){const o=ci(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,u=n.content-n.viewport,f=r==="ltr"?[0,u]:[u*-1,0];return hp([l,c],f)(e)}function fp(e,t,n="ltr"){const r=ci(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=ml(e,l);return hp([0,i],[0,a])(c)}function hp(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 pp(e,t){return e>0&&e<t}var VC=(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 ui(e,t){const n=At(e),r=y.useRef(0);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),y.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 mp=rp,KC=sp,qC=up;const gp=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(mp,{ref:r,className:ee("relative overflow-hidden",e),...n,children:[d.jsx(KC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),d.jsx(xp,{}),d.jsx(qC,{})]}));gp.displayName=mp.displayName;const xp=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>d.jsx(xl,{ref:r,orientation:t,className:ee("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:d.jsx(cp,{className:"relative flex-1 rounded-full bg-border"})}));xp.displayName=xl.displayName;function wl({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:u}){const{threads:f,currentThreadId:h,isLoading:p,actions:m}=Qo(),{loadThread:x}=es(),{createThread:v,deleteThread:g,renameThread:w}=m,[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,$]=b.useState(""),[q,P]=b.useState(!1);b.useEffect(()=>{const H=Array.isArray(f)?f:[];if(H.length>0){k.current=!0,T(H);return}p||(k.current=!1,T(H))},[f,p]),b.useEffect(()=>{if(!C.current)return;const H=C.current.querySelector("[data-radix-scroll-area-viewport]");if(!H)return;let Z=null,we=null;return Z=requestAnimationFrame(()=>{we=requestAnimationFrame(()=>{H.scrollTop=E.current})}),()=>{Z!==null&&cancelAnimationFrame(Z),we!==null&&cancelAnimationFrame(we)}},[S]);const R=async H=>{try{await x(H),a==null||a(H),l==null||l(H)}catch(Z){console.error("Failed to select thread:",Z)}},L=async()=>{try{P(!0);const H=await v();c==null||c(H),a==null||a(H)}catch(H){console.error("Failed to create thread:",H)}finally{P(!1)}},F=async(H,Z)=>{if(Z.stopPropagation(),!!confirm("Delete this thread?")){if(C.current){const we=C.current.querySelector("[data-radix-scroll-area-viewport]");we&&(E.current=we.scrollTop)}try{await g(H),u==null||u(H)}catch(we){console.error("Failed to delete thread:",we)}}},ne=(H,Z)=>{Z.stopPropagation(),j(H.threadId),$(H.title||`Thread ${H.threadId.slice(0,8)}`)},K=async H=>{if(D.trim())try{await w(H,D.trim()),j(null),$("")}catch(Z){console.error("Failed to update title:",Z)}},B=()=>{j(null),$("")},pe=(H,Z)=>{H.key==="Enter"?K(Z):H.key==="Escape"&&B()},W=H=>{if(!H)return"";try{const Z=new Date(H),ye=new Date().getTime()-Z.getTime(),G=Math.floor(ye/(1e3*60*60*24));return G===0?Z.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):G===1?"Yesterday":G<7?`${G} days ago`:Z.toLocaleDateString()}catch{return""}},ce=H=>H.title||`Thread ${H.threadId.slice(0,8)}`;return d.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&d.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:d.jsx(Ze,{onClick:L,disabled:q||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:q?"Creating...":"New Chat",children:d.jsx(fe.MessageSquarePlus,{size:20})})}),d.jsx(gp,{ref:C,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:d.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?d.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[d.jsx(fe.Loader2,{className:"h-5 w-5 animate-spin"}),d.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?d.jsxs("div",{className:"text-center py-8 text-slate-400",children:[d.jsx(fe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),d.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((H,Z)=>new Date(Z.updatedAt||Z.createdAt||"").getTime()-new Date(H.updatedAt||H.createdAt||"").getTime()).map(H=>d.jsxs("div",{onClick:()=>R(H.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===H.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:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("div",{className:"flex-1 min-w-0",children:_===H.threadId?d.jsxs("div",{className:"flex items-center gap-2",onClick:Z=>Z.stopPropagation(),children:[d.jsx(ii,{value:D,onChange:Z=>$(Z.target.value),onKeyDown:Z=>pe(Z,H.threadId),className:"h-6 text-sm",autoFocus:!0}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>K(H.threadId),className:"h-6 w-6 p-0",children:d.jsx(fe.Check,{size:12})}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:B,className:"h-6 w-6 p-0",children:d.jsx(fe.X,{size:12})})]}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:ce(H)}),d.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[d.jsx(fe.Calendar,{size:10}),d.jsx("span",{children:W(H.updatedAt||H.createdAt)})]})]})}),d.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==H.threadId&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Z=>ne(H,Z),className:"h-6 w-6 p-0",title:"Edit title",children:d.jsx(fe.Edit3,{size:12})}),n&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Z=>F(H.threadId,Z),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:d.jsx(fe.Trash2,{size:12})})]})]}),i===H.threadId&&d.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},H.threadId))})})]})}function Hr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function GC(e){if(typeof e!="string")return;const t=e.trim();if(t)return $n(t)}function yp(){const e=[Hr("__API_BASE_URL__"),Hr("__CHAT_API_BASE_URL__"),Hr("__CHAT_API_URL__")];for(const t of e){const n=GC(t);if(n)return n}}function vp(){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 wp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return $n(t);return $n()}function bp(){const e={},t=yp(),n=vp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Sp(){const e=bp(),t=Wn.getAuthToken(),n=yp();return{apiBaseUrl:wp(e.baseUrl,Wn.baseUrl,n),apiKey:t||e.apiKey||vp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Cp="chat-settings";function YC(){try{const e=localStorage.getItem(Cp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function XC(e){try{const t={...e,apiBaseUrl:$n(e.apiBaseUrl)};localStorage.setItem(Cp,JSON.stringify(t)),t.apiKey&&Wn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function JC(){const e=Sp(),t=YC(),n=Wn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:wp(Wn.baseUrl,r,e.apiBaseUrl)}}function ZC(e){Wn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),XC(e)}var QC="Label",kp=y.forwardRef((e,t)=>d.jsx(Ie.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())}}));kp.displayName=QC;var Tp=kp;const ek=Oo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),on=y.forwardRef(({className:e,...t},n)=>d.jsx(Tp,{ref:n,className:ee(ek(),e),...t}));on.displayName=Tp.displayName;function Ep(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var di="Switch",[tk,TT]=Tn(di),[nk,rk]=tk(di),Ip=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:u,...f}=e,[h,p]=y.useState(null),m=He(t,S=>p(S)),x=y.useRef(!1),v=h?u||!!h.closest("form"):!0,[g,w]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:di});return d.jsxs(nk,{scope:n,checked:g,disabled:a,children:[d.jsx(Ie.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":jp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ge(e.onClick,S=>{w(T=>!T),v&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),v&&d.jsx(_p,{control:h,bubbles:!x.current,name:r,value:l,checked:g,required:i,disabled:a,form:u,style:{transform:"translateX(-100%)"}})]})});Ip.displayName=di;var Ap="SwitchThumb",Np=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rk(Ap,n);return d.jsx(Ie.span,{"data-state":jp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Np.displayName=Ap;var ok="SwitchBubbleInput",_p=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=y.useRef(null),a=He(i,s),l=Ep(n),c=zf(t);return y.useEffect(()=>{const u=i.current;if(!u)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const m=new Event("click",{bubbles:r});p.call(u,n),u.dispatchEvent(m)}},[l,n,r]),d.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}})});_p.displayName=ok;function jp(e){return e?"checked":"unchecked"}var Rp=Ip,sk=Np;const er=y.forwardRef(({className:e,...t},n)=>d.jsx(Rp,{className:ee("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:d.jsx(sk,{className:ee("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=Rp.displayName;var Pp=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"}),ik="VisuallyHidden",ak=y.forwardRef((e,t)=>d.jsx(Ie.span,{...e,ref:t,style:{...Pp,...e.style}}));ak.displayName=ik;var lk=[" ","Enter","ArrowUp","ArrowDown"],ck=[" ","Enter"],br="Select",[fi,hi,uk]=Wa(br),[Ur,ET]=Tn(br,[uk,Qs]),pi=Qs(),[dk,tr]=Ur(br),[fk,hk]=Ur(br),Op=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:u,autoComplete:f,disabled:h,required:p,form:m}=e,x=pi(t),[v,g]=y.useState(null),[w,S]=y.useState(null),[T,k]=y.useState(!1),C=Hs(c),[E,_]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:br}),[j,D]=pr({prop:i,defaultProp:a,onChange:l,caller:br}),$=y.useRef(null),q=v?m||!!v.closest("form"):!0,[P,R]=y.useState(new Set),L=Array.from(P).map(F=>F.props.value).join(";");return d.jsx(Xf,{...x,children:d.jsxs(dk,{required:p,scope:t,trigger:v,onTriggerChange:g,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:En(),value:j,onValueChange:D,open:E,onOpenChange:_,dir:C,triggerPointerDownPosRef:$,disabled:h,children:[d.jsx(fi.Provider,{scope:t,children:d.jsx(fk,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(F=>{R(ne=>new Set(ne).add(F))},[]),onNativeOptionRemove:y.useCallback(F=>{R(ne=>{const K=new Set(ne);return K.delete(F),K})},[]),children:n})}),q?d.jsxs(om,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:f,value:j,onChange:F=>D(F.target.value),disabled:h,form:m,children:[j===void 0?d.jsx("option",{value:""}):null,Array.from(P)]},L):null]})})};Op.displayName=br;var Mp="SelectTrigger",Dp=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=pi(n),i=tr(Mp,n),a=i.disabled||r,l=He(t,i.onTriggerChange),c=hi(n),u=y.useRef("touch"),[f,h,p]=im(x=>{const v=c().filter(S=>!S.disabled),g=v.find(S=>S.value===i.value),w=am(v,x,g);w!==void 0&&i.onValueChange(w.value)}),m=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return d.jsx(Jf,{asChild:!0,...s,children:d.jsx(Ie.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":sm(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,x=>{x.currentTarget.focus(),u.current!=="mouse"&&m(x)}),onPointerDown:ge(o.onPointerDown,x=>{u.current=x.pointerType;const v=x.target;v.hasPointerCapture(x.pointerId)&&v.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(m(x),x.preventDefault())}),onKeyDown:ge(o.onKeyDown,x=>{const v=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(v&&x.key===" ")&&lk.includes(x.key)&&(m(),x.preventDefault())})})})});Dp.displayName=Mp;var Lp="SelectValue",Fp=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=tr(Lp,n),{onValueNodeHasChildrenChange:c}=l,u=s!==void 0,f=He(t,l.onValueNodeChange);return kt(()=>{c(u)},[c,u]),d.jsx(Ie.span,{...a,ref:f,style:{pointerEvents:"none"},children:sm(l.value)?d.jsx(d.Fragment,{children:i}):s})});Fp.displayName=Lp;var pk="SelectIcon",$p=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return d.jsx(Ie.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});$p.displayName=pk;var mk="SelectPortal",zp=e=>d.jsx(Ss,{asChild:!0,...e});zp.displayName=mk;var Sr="SelectContent",Bp=y.forwardRef((e,t)=>{const n=tr(Sr,e.__scopeSelect),[r,o]=y.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Mo.createPortal(d.jsx(Hp,{scope:e.__scopeSelect,children:d.jsx(fi.Slot,{scope:e.__scopeSelect,children:d.jsx("div",{children:e.children})})}),s):null}return d.jsx(Up,{...e,ref:t})});Bp.displayName=Sr;var gn=10,[Hp,nr]=Ur(Sr),gk="SelectContentImpl",xk=sr.createSlot("SelectContent.RemoveScroll"),Up=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:x,avoidCollisions:v,...g}=e,w=tr(Sr,n),[S,T]=y.useState(null),[k,C]=y.useState(null),E=He(t,G=>T(G)),[_,j]=y.useState(null),[D,$]=y.useState(null),q=hi(n),[P,R]=y.useState(!1),L=y.useRef(!1);y.useEffect(()=>{if(S)return Da(S)},[S]),_a();const F=y.useCallback(G=>{const[M,...X]=q().map(se=>se.ref.current),[oe]=X.slice(-1),xe=document.activeElement;for(const se of G)if(se===xe||(se==null||se.scrollIntoView({block:"nearest"}),se===M&&k&&(k.scrollTop=0),se===oe&&k&&(k.scrollTop=k.scrollHeight),se==null||se.focus(),document.activeElement!==xe))return},[q,k]),ne=y.useCallback(()=>F([_,S]),[F,_,S]);y.useEffect(()=>{P&&ne()},[P,ne]);const{onOpenChange:K,triggerPointerDownPosRef:B}=w;y.useEffect(()=>{if(S){let G={x:0,y:0};const M=oe=>{var xe,se;G={x:Math.abs(Math.round(oe.pageX)-(((xe=B.current)==null?void 0:xe.x)??0)),y:Math.abs(Math.round(oe.pageY)-(((se=B.current)==null?void 0:se.y)??0))}},X=oe=>{G.x<=10&&G.y<=10?oe.preventDefault():S.contains(oe.target)||K(!1),document.removeEventListener("pointermove",M),B.current=null};return B.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,K,B]),y.useEffect(()=>{const G=()=>K(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[K]);const[pe,W]=im(G=>{const M=q().filter(xe=>!xe.disabled),X=M.find(xe=>xe.ref.current===document.activeElement),oe=am(M,G,X);oe&&setTimeout(()=>oe.ref.current.focus())}),ce=y.useCallback((G,M,X)=>{const oe=!L.current&&!X;(w.value!==void 0&&w.value===M||oe)&&(j(G),oe&&(L.current=!0))},[w.value]),H=y.useCallback(()=>S==null?void 0:S.focus(),[S]),Z=y.useCallback((G,M,X)=>{const oe=!L.current&&!X;(w.value!==void 0&&w.value===M||oe)&&$(G)},[w.value]),we=r==="popper"?bl:Wp,ye=we===bl?{side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:x,avoidCollisions:v}:{};return d.jsx(Hp,{scope:n,content:S,viewport:k,onViewportChange:C,itemRefCallback:ce,selectedItem:_,onItemLeave:H,itemTextRefCallback:Z,focusSelectedItem:ne,selectedItemText:D,position:r,isPositioned:P,searchRef:pe,children:d.jsx(As,{as:xk,allowPinchZoom:!0,children:d.jsx(bs,{asChild:!0,trapped:w.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:ge(o,G=>{var M;(M=w.trigger)==null||M.focus({preventScroll:!0}),G.preventDefault()}),children:d.jsx(ws,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:d.jsx(we,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:G=>G.preventDefault(),...g,...ye,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:ge(g.onKeyDown,G=>{const M=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!M&&G.key.length===1&&W(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let oe=q().filter(xe=>!xe.disabled).map(xe=>xe.ref.current);if(["ArrowUp","End"].includes(G.key)&&(oe=oe.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const xe=G.target,se=oe.indexOf(xe);oe=oe.slice(se+1)}setTimeout(()=>F(oe)),G.preventDefault()}})})})})})})});Up.displayName=gk;var yk="SelectItemAlignedPosition",Wp=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=tr(Sr,n),i=nr(Sr,n),[a,l]=y.useState(null),[c,u]=y.useState(null),f=He(t,E=>u(E)),h=hi(n),p=y.useRef(!1),m=y.useRef(!0),{viewport:x,selectedItem:v,selectedItemText:g,focusSelectedItem:w}=i,S=y.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&v&&g){const E=s.trigger.getBoundingClientRect(),_=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),D=g.getBoundingClientRect();if(s.dir!=="rtl"){const xe=D.left-_.left,se=j.left-xe,re=E.left-se,Ue=E.width+re,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,at=ml(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.left=at+"px"}else{const xe=_.right-D.right,se=window.innerWidth-j.right-xe,re=window.innerWidth-E.right-se,Ue=E.width+re,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,at=ml(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.right=at+"px"}const $=h(),q=window.innerHeight-gn*2,P=x.scrollHeight,R=window.getComputedStyle(c),L=parseInt(R.borderTopWidth,10),F=parseInt(R.paddingTop,10),ne=parseInt(R.borderBottomWidth,10),K=parseInt(R.paddingBottom,10),B=L+F+P+K+ne,pe=Math.min(v.offsetHeight*5,B),W=window.getComputedStyle(x),ce=parseInt(W.paddingTop,10),H=parseInt(W.paddingBottom,10),Z=E.top+E.height/2-gn,we=q-Z,ye=v.offsetHeight/2,G=v.offsetTop+ye,M=L+F+G,X=B-M;if(M<=Z){const xe=$.length>0&&v===$[$.length-1].ref.current;a.style.bottom="0px";const se=c.clientHeight-x.offsetTop-x.offsetHeight,re=Math.max(we,ye+(xe?H:0)+se+ne),Ue=M+re;a.style.height=Ue+"px"}else{const xe=$.length>0&&v===$[0].ref.current;a.style.top="0px";const re=Math.max(Z,L+x.offsetTop+(xe?ce:0)+ye)+X;a.style.height=re+"px",x.scrollTop=M-Z+x.offsetTop}a.style.margin=`${gn}px 0`,a.style.minHeight=pe+"px",a.style.maxHeight=q+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,x,v,g,s.dir,r]);kt(()=>S(),[S]);const[T,k]=y.useState();kt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const C=y.useCallback(E=>{E&&m.current===!0&&(S(),w==null||w(),m.current=!1)},[S,w]);return d.jsx(wk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:d.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:d.jsx(Ie.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Wp.displayName=yk;var vk="SelectPopperPosition",bl=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=gn,...s}=e,i=pi(n);return d.jsx(Zf,{...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)"}})});bl.displayName=vk;var[wk,Sl]=Ur(Sr,{}),Cl="SelectViewport",Vp=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=nr(Cl,n),i=Sl(Cl,n),a=He(t,s.onViewportChange),l=y.useRef(0);return d.jsxs(d.Fragment,{children:[d.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}),d.jsx(fi.Slot,{scope:n,children:d.jsx(Ie.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 u=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-u.scrollTop);if(p>0){const m=window.innerHeight-gn*2,x=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),g=Math.max(x,v);if(g<m){const w=g+p,S=Math.min(m,w),T=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(u.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=u.scrollTop})})})]})});Vp.displayName=Cl;var Kp="SelectGroup",[bk,Sk]=Ur(Kp),Ck=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=En();return d.jsx(bk,{scope:n,id:o,children:d.jsx(Ie.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Ck.displayName=Kp;var qp="SelectLabel",Gp=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sk(qp,n);return d.jsx(Ie.div,{id:o.id,...r,ref:t})});Gp.displayName=qp;var mi="SelectItem",[kk,Yp]=Ur(mi),Xp=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=tr(mi,n),l=nr(mi,n),c=a.value===r,[u,f]=y.useState(s??""),[h,p]=y.useState(!1),m=He(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),x=En(),v=y.useRef("touch"),g=()=>{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 d.jsx(kk,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:y.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:d.jsx(fi.ItemSlot,{scope:n,value:r,disabled:o,textValue:u,children:d.jsx(Ie.div,{role:"option","aria-labelledby":x,"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:m,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{v.current!=="mouse"&&g()}),onPointerUp:ge(i.onPointerUp,()=>{v.current==="mouse"&&g()}),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===" "||(ck.includes(w.key)&&g(),w.key===" "&&w.preventDefault())})})})})});Xp.displayName=mi;var No="SelectItemText",Jp=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=tr(No,n),a=nr(No,n),l=Yp(No,n),c=hk(No,n),[u,f]=y.useState(null),h=He(t,g=>f(g),l.onItemTextChange,g=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,g,l.value,l.disabled)}),p=u==null?void 0:u.textContent,m=y.useMemo(()=>d.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:v}=c;return kt(()=>(x(m),()=>v(m)),[x,v,m]),d.jsxs(d.Fragment,{children:[d.jsx(Ie.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Mo.createPortal(s.children,i.valueNode):null]})});Jp.displayName=No;var Zp="SelectItemIndicator",Qp=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Yp(Zp,n).isSelected?d.jsx(Ie.span,{"aria-hidden":!0,...r,ref:t}):null});Qp.displayName=Zp;var kl="SelectScrollUpButton",em=y.forwardRef((e,t)=>{const n=nr(kl,e.__scopeSelect),r=Sl(kl,e.__scopeSelect),[o,s]=y.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?d.jsx(nm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});em.displayName=kl;var Tl="SelectScrollDownButton",tm=y.forwardRef((e,t)=>{const n=nr(Tl,e.__scopeSelect),r=Sl(Tl,e.__scopeSelect),[o,s]=y.useState(!1),i=He(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,u=Math.ceil(l.scrollTop)<c;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?d.jsx(nm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});tm.displayName=Tl;var nm=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=nr("SelectScrollButton",n),i=y.useRef(null),a=hi(n),l=y.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return y.useEffect(()=>()=>l(),[l]),kt(()=>{var u;const c=a().find(f=>f.ref.current===document.activeElement);(u=c==null?void 0:c.ref.current)==null||u.scrollIntoView({block:"nearest"})},[a]),d.jsx(Ie.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()})})}),Tk="SelectSeparator",rm=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return d.jsx(Ie.div,{"aria-hidden":!0,...r,ref:t})});rm.displayName=Tk;var El="SelectArrow",Ek=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=pi(n),s=tr(El,n),i=nr(El,n);return s.open&&i.position==="popper"?d.jsx(Qf,{...o,...r,ref:t}):null});Ek.displayName=El;var Ik="SelectBubbleInput",om=y.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=y.useRef(null),s=He(r,o),i=Ep(t);return y.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,u=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&u){const f=new Event("change",{bubbles:!0});u.call(a,t),a.dispatchEvent(f)}},[i,t]),d.jsx(Ie.select,{...n,style:{...Pp,...n.style},ref:s,defaultValue:t})});om.displayName=Ik;function sm(e){return e===""||e===void 0}function im(e){const t=At(e),n=y.useRef(""),r=y.useRef(0),o=y.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=y.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function am(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=Ak(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 Ak(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Nk=Op,lm=Dp,_k=Fp,jk=$p,Rk=zp,cm=Bp,Pk=Vp,um=Gp,dm=Xp,Ok=Jp,Mk=Qp,fm=em,hm=tm,pm=rm;const mm=Nk,gm=_k,Il=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(lm,{ref:r,className:ee("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,d.jsx(jk,{asChild:!0,children:d.jsx(fe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Il.displayName=lm.displayName;const xm=y.forwardRef(({className:e,...t},n)=>d.jsx(fm,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:d.jsx(fe.ChevronUp,{className:"h-4 w-4"})}));xm.displayName=fm.displayName;const ym=y.forwardRef(({className:e,...t},n)=>d.jsx(hm,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:d.jsx(fe.ChevronDown,{className:"h-4 w-4"})}));ym.displayName=hm.displayName;const Al=y.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>d.jsx(Rk,{children:d.jsxs(cm,{ref:o,className:ee("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:[d.jsx(xm,{}),d.jsx(Pk,{className:ee("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),d.jsx(ym,{})]})}));Al.displayName=cm.displayName;const Dk=y.forwardRef(({className:e,...t},n)=>d.jsx(um,{ref:n,className:ee("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Dk.displayName=um.displayName;const Cr=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(dm,{ref:r,className:ee("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:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Mk,{children:d.jsx(fe.Check,{className:"h-4 w-4"})})}),d.jsx(Ok,{children:t})]}));Cr.displayName=dm.displayName;const Lk=y.forwardRef(({className:e,...t},n)=>d.jsx(pm,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));Lk.displayName=pm.displayName;var Fk="Separator",vm="horizontal",$k=["horizontal","vertical"],wm=y.forwardRef((e,t)=>{const{decorative:n,orientation:r=vm,...o}=e,s=zk(r)?r:vm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return d.jsx(Ie.div,{"data-orientation":s,...a,...o,ref:t})});wm.displayName=Fk;function zk(e){return $k.includes(e)}var bm=wm;const Sm=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>d.jsx(bm,{ref:o,decorative:n,orientation:t,className:ee("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Sm.displayName=bm.displayName;const Bk=Kd,Hk=ab,Uk=qd,Cm=y.forwardRef(({className:e,...t},n)=>d.jsx(Ps,{className:ee("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}));Cm.displayName=Ps.displayName;const Wk=Oo.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"}}),km=y.forwardRef(({side:e="right",className:t,children:n,...r},o)=>d.jsxs(Uk,{children:[d.jsx(Cm,{}),d.jsxs(Os,{ref:o,className:ee(Wk({side:e}),t),...r,children:[n,d.jsxs(Gd,{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:[d.jsx(fe.X,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));km.displayName=Os.displayName;const Tm=({className:e,...t})=>d.jsx("div",{className:ee("flex flex-col space-y-2 text-center sm:text-left",e),...t});Tm.displayName="SheetHeader";const Em=y.forwardRef(({className:e,...t},n)=>d.jsx(gr,{ref:n,className:ee("text-lg font-semibold text-foreground",e),...t}));Em.displayName=gr.displayName;const Im=y.forwardRef(({className:e,...t},n)=>d.jsx(Ms,{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));Im.displayName=Ms.displayName;const Vk={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 Kk({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,u]=b.useState(!1),{toast:f}=ka();b.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);u(v)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),u(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(Vk),u(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),u(!1),o(!1)},x=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return d.jsxs(Bk,{open:r,onOpenChange:o,children:[d.jsx(Hk,{asChild:!0,children:d.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[d.jsx(fe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&d.jsx(Yu,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),d.jsxs(km,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[d.jsxs(Tm,{children:[d.jsx(Em,{children:"Chat Settings"}),d.jsx(Im,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),d.jsxs("div",{className:"space-y-6 py-6",children:[d.jsxs(fo,{children:[d.jsx(ho,{className:"pb-3",children:d.jsxs(po,{className:"text-lg flex items-center gap-2",children:[d.jsx(fe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),d.jsxs(mo,{className:"space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"api-url",children:"API Base URL"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(ii,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(g=>({...g,api:{...g.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),d.jsx(Ze,{variant:"outline",onClick:x,children:"Test"})]})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"enable-auth",children:"Enable Authentication"}),d.jsx(er,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(g=>({...g,api:{...g.api,enableAuth:v}}))})]}),a.api.enableAuth&&d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"auth-token",children:"Authentication Token"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(ii,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(g=>({...g,api:{...g.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),d.jsx(Ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?d.jsx(fe.EyeOff,{className:"h-4 w-4"}):d.jsx(fe.Eye,{className:"h-4 w-4"})})]})]})]})]}),d.jsxs(fo,{children:[d.jsx(ho,{className:"pb-3",children:d.jsxs(po,{className:"text-lg flex items-center gap-2",children:[d.jsx(fe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),d.jsxs(mo,{className:"space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"layout",children:"Layout Style"}),d.jsxs(mm,{value:a.ui.layout,onValueChange:v=>l(g=>({...g,ui:{...g.ui,layout:v}})),children:[d.jsx(Il,{children:d.jsx(gm,{})}),d.jsxs(Al,{children:[d.jsx(Cr,{value:"sidebar",children:"Sidebar Layout"}),d.jsx(Cr,{value:"fullscreen",children:"Fullscreen"}),d.jsx(Cr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"theme",children:"Theme"}),d.jsxs(mm,{value:a.ui.theme,onValueChange:v=>l(g=>({...g,ui:{...g.ui,theme:v}})),children:[d.jsx(Il,{children:d.jsx(gm,{})}),d.jsxs(Al,{children:[d.jsx(Cr,{value:"light",children:"Light"}),d.jsx(Cr,{value:"dark",children:"Dark"}),d.jsx(Cr,{value:"system",children:"System"})]})]})]}),d.jsx(Sm,{}),d.jsxs("div",{className:"space-y-3",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"show-timestamps",children:"Show Timestamps"}),d.jsx(er,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showTimestamps:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"show-agent-names",children:"Show Agent Names"}),d.jsx(er,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showAgentNames:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"compact-messages",children:"Compact Messages"}),d.jsx(er,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,compactMessages:v}}))})]})]})]})]}),d.jsxs(fo,{children:[d.jsx(ho,{className:"pb-3",children:d.jsxs(po,{className:"text-lg flex items-center gap-2",children:[d.jsx(fe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),d.jsxs(mo,{className:"space-y-4",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(on,{htmlFor:"auto-save",children:"Auto-save Conversations"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),d.jsx(er,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,autoSave:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(on,{htmlFor:"enable-streaming",children:"Enable Streaming"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),d.jsx(er,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(on,{htmlFor:"typing-indicator",children:"Typing Indicator"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),d.jsx(er,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:v}}))})]})]})]})]}),d.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[d.jsxs(Ze,{variant:"outline",onClick:p,children:[d.jsx(fe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Ze,{variant:"outline",onClick:m,children:"Cancel"}),d.jsxs(Ze,{onClick:h,disabled:!c,children:[d.jsx(fe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function qk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const u="h-full";switch(c){case"phone":return`${u} max-w-none`;case"tablet":return`${u} max-w-4xl mx-auto`;case"half-screen":return`${u} max-w-2xl`;case"desktop":default:return`${u} 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 u;(u=s.onThreadChange)==null||u.call(s,c)},[s]);return e==="fullscreen"?d.jsx(ts,{...s,onThreadChange:l,children:d.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:d.jsx(si,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?d.jsx(ts,{...s,onThreadChange:l,children:d.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:d.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&d.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(wl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(si,{onError:s.onError,enableFileUpload:!0})})]})})}):d.jsx(ts,{...s,onThreadChange:l,children:d.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&d.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(wl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(si,{onError:s.onError,enableFileUpload:!0})})]})})}Ae.ChatApi=Tc,Ae.ChatInterface=si,Ae.ChatProviders=ts,Ae.ChatSettings=Kk,Ae.MarkdownContent=vo,Ae.MessageComponent=Ha,Ae.MessageList=Ua,Ae.ThreadManager=wl,Ae.applySettings=ZC,Ae.chatApiClient=Wn,Ae.default=qk,Ae.del=kc,Ae.get=cn,Ae.getChatToken=bc,Ae.getCurrentSettings=JC,Ae.getDefaultApiConfig=bp,Ae.getDefaultChatSettings=Sp,Ae.onChatTokenChanged=Sc,Ae.post=ji,Ae.put=Cc,Ae.setChatToken=_i,Ae.useApi=Ri,Ae.useChatStream=zc,Ae.useMessagesReducer=Rc,Ae.useStream=Yc,Ae.useThreadState=es,Ae.useThreads=Qo,Object.defineProperties(Ae,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
137
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function $b(e,t=Bs){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 zb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),$b(t),Fb(t)}function Wa(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:v,children:g}=x,w=b.useRef(null),S=b.useRef(new Map).current;return d.jsx(o,{scope:v,itemMap:S,collectionRef:w,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=sr.createSlot(a),c=b.forwardRef((x,v)=>{const{scope:g,children:w}=x,S=s(a,g),T=He(v,S.collectionRef);return d.jsx(l,{ref:T,children:w})});c.displayName=a;const u=e+"CollectionItemSlot",f="data-radix-collection-item",h=sr.createSlot(u),p=b.forwardRef((x,v)=>{const{scope:g,children:w,...S}=x,T=b.useRef(null),k=He(v,T),C=s(u,g);return b.useEffect(()=>(C.itemMap.set(T,{ref:T,...S}),()=>void C.itemMap.delete(T))),d.jsx(h,{[f]:"",ref:k,children:w})});p.displayName=u;function m(x){const v=s(e+"CollectionConsumer",x);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},m,r]}var Bb=y.createContext(void 0);function Hs(e){const t=y.useContext(Bb);return e||t||"ltr"}const Hb=["top","right","bottom","left"],Zn=Math.min,qt=Math.max,Us=Math.round,Ws=Math.floor,Nn=e=>({x:e,y:e}),Ub={left:"right",right:"left",bottom:"top",top:"bottom"},Wb={start:"end",end:"start"};function Va(e,t,n){return qt(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 Ka(e){return e==="x"?"y":"x"}function qa(e){return e==="y"?"height":"width"}const Vb=new Set(["top","bottom"]);function An(e){return Vb.has(Hn(e))?"y":"x"}function Ga(e){return Ka(An(e))}function Kb(e,t,n){n===void 0&&(n=!1);const r=Lr(e),o=Ga(e),s=qa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Vs(i)),[i,Vs(i)]}function qb(e){const t=Vs(e);return[Ya(e),t,Ya(t)]}function Ya(e){return e.replace(/start|end/g,t=>Wb[t])}const xf=["left","right"],yf=["right","left"],Gb=["top","bottom"],Yb=["bottom","top"];function Xb(e,t,n){switch(e){case"top":case"bottom":return n?t?yf:xf:t?xf:yf;case"left":case"right":return t?Gb:Yb;default:return[]}}function Jb(e,t,n,r){const o=Lr(e);let s=Xb(Hn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ya)))),s}function Vs(e){return e.replace(/left|right|bottom|top/g,t=>Ub[t])}function Zb(e){return{top:0,right:0,bottom:0,left:0,...e}}function vf(e){return typeof e!="number"?Zb(e):{top:e,right:e,bottom:e,left:e}}function Ks(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 wf(e,t,n){let{reference:r,floating:o}=e;const s=An(t),i=Ga(t),a=qa(i),l=Hn(t),c=s==="y",u=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:u,y:r.y-o.height};break;case"bottom":p={x:u,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 Qb=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:u,y:f}=wf(c,r,l),h=r,p={},m=0;for(let x=0;x<a.length;x++){const{name:v,fn:g}=a[x],{x:w,y:S,data:T,reset:k}=await g({x:u,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});u=w??u,f=S??f,p={...p,[v]:{...p[v],...T}},k&&m<=50&&(m++,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:u,y:f}=wf(c,h,l)),x=-1)}return{x:u,y:f,placement:h,strategy:o,middlewareData:p}};async function wo(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:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Bn(t,e),m=vf(p),v=a[h?f==="floating"?"reference":"floating":f],g=Ks(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:u,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=Ks(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:S,strategy:l}):w);return{top:(g.top-k.top+m.top)/T.y,bottom:(k.bottom-g.bottom+m.bottom)/T.y,left:(g.left-k.left+m.left)/T.x,right:(k.right-g.right+m.right)/T.x}}const e0=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:u=0}=Bn(e,t)||{};if(c==null)return{};const f=vf(u),h={x:n,y:r},p=Ga(o),m=qa(p),x=await i.getDimensions(c),v=p==="y",g=v?"top":"left",w=v?"bottom":"right",S=v?"clientHeight":"clientWidth",T=s.reference[m]+s.reference[p]-h[p]-s.floating[m],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[m]);const _=T/2-k/2,j=E/2-x[m]/2-1,D=Zn(f[g],j),$=Zn(f[w],j),q=D,P=E-x[m]-$,R=E/2-x[m]/2+_,L=Va(q,R,P),F=!l.arrow&&Lr(o)!=null&&R!==L&&s.reference[m]/2-(R<q?D:$)-x[m]/2<0,ne=F?R<q?R-q:R-P:0;return{[p]:h[p]+ne,data:{[p]:L,centerOffset:R-L-ne,...F&&{alignmentOffset:ne}},reset:F}}}),t0=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:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:x=!0,...v}=Bn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=Hn(o),w=An(a),S=Hn(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(S||!x?[Vs(a)]:qb(a)),C=m!=="none";!h&&C&&k.push(...Jb(a,x,m,T));const E=[a,...k],_=await wo(t,v),j=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&j.push(_[g]),f){const R=Kb(o,i,T);j.push(_[R[0]],_[R[1]])}if(D=[...D,{placement:o,overflows:j}],!j.every(R=>R<=0)){var $,q;const R=((($=s.flip)==null?void 0:$.index)||0)+1,L=E[R];if(L&&(!(f==="alignment"?w!==An(L):!1)||D.every(K=>An(K.placement)===w?K.overflows[0]>0:!0)))return{data:{index:R,overflows:D},reset:{placement:L}};let F=(q=D.filter(ne=>ne.overflows[0]<=0).sort((ne,K)=>ne.overflows[1]-K.overflows[1])[0])==null?void 0:q.placement;if(!F)switch(p){case"bestFit":{var P;const ne=(P=D.filter(K=>{if(C){const B=An(K.placement);return B===w||B==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(B=>B>0).reduce((B,pe)=>B+pe,0)]).sort((K,B)=>K[1]-B[1])[0])==null?void 0:P[0];ne&&(F=ne);break}case"initialPlacement":F=a;break}if(o!==F)return{reset:{placement:F}}}return{}}}};function bf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Sf(e){return Hb.some(t=>e[t]>=0)}const n0=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 wo(t,{...o,elementContext:"reference"}),i=bf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Sf(i)}}}case"escaped":{const s=await wo(t,{...o,altBoundary:!0}),i=bf(s,n.floating);return{data:{escapedOffsets:i,escaped:Sf(i)}}}default:return{}}}}},Cf=new Set(["left","top"]);async function r0(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=An(n)==="y",c=Cf.has(i)?-1:1,u=s&&l?-1:1,f=Bn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*u,y:h*c}:{x:h*c,y:p*u}}const o0=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 r0(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}}}}},s0=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:g,y:w}=v;return{x:g,y:w}}},...l}=Bn(e,t),c={x:n,y:r},u=await wo(t,l),f=An(Hn(o)),h=Ka(f);let p=c[h],m=c[f];if(s){const v=h==="y"?"top":"left",g=h==="y"?"bottom":"right",w=p+u[v],S=p-u[g];p=Va(w,p,S)}if(i){const v=f==="y"?"top":"left",g=f==="y"?"bottom":"right",w=m+u[v],S=m-u[g];m=Va(w,m,S)}const x=a.fn({...t,[h]:p,[f]:m});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},i0=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),u={x:n,y:r},f=An(o),h=Ka(f);let p=u[h],m=u[f];const x=Bn(a,t),v=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};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 g,w;const S=h==="y"?"width":"height",T=Cf.has(Hn(o)),k=s.reference[f]-s.floating[S]+(T&&((g=i.offset)==null?void 0:g[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);m<k?m=k:m>C&&(m=C)}return{[h]:p,[f]:m}}}},a0=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),u=await wo(t,c),f=Hn(o),h=Lr(o),p=An(o)==="y",{width:m,height:x}=s.floating;let v,g;f==="top"||f==="bottom"?(v=f,g=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,v=h==="end"?"top":"bottom");const w=x-u.top-u.bottom,S=m-u.left-u.right,T=Zn(x-u[v],w),k=Zn(m-u[g],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=qt(u.left,0),$=qt(u.right,0),q=qt(u.top,0),P=qt(u.bottom,0);p?_=m-2*(D!==0||$!==0?D+$:qt(u.left,u.right)):E=x-2*(q!==0||P!==0?q+P:qt(u.top,u.bottom))}await l({...t,availableWidth:_,availableHeight:E});const j=await i.getDimensions(a.floating);return m!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function qs(){return typeof window<"u"}function Fr(e){return kf(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=(kf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function kf(e){return qs()?e instanceof Node||e instanceof Gt(e).Node:!1}function pn(e){return qs()?e instanceof Element||e instanceof Gt(e).Element:!1}function jn(e){return qs()?e instanceof HTMLElement||e instanceof Gt(e).HTMLElement:!1}function Tf(e){return!qs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gt(e).ShadowRoot}const l0=new Set(["inline","contents"]);function bo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=mn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!l0.has(o)}const c0=new Set(["table","td","th"]);function u0(e){return c0.has(Fr(e))}const d0=[":popover-open",":modal"];function Gs(e){return d0.some(t=>{try{return e.matches(t)}catch{return!1}})}const f0=["transform","translate","scale","rotate","perspective"],h0=["transform","translate","scale","rotate","perspective","filter"],p0=["paint","layout","strict","content"];function Xa(e){const t=Ja(),n=pn(e)?mn(e):e;return f0.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)||h0.some(r=>(n.willChange||"").includes(r))||p0.some(r=>(n.contain||"").includes(r))}function m0(e){let t=Qn(e);for(;jn(t)&&!$r(t);){if(Xa(t))return t;if(Gs(t))return null;t=Qn(t)}return null}function Ja(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const g0=new Set(["html","body","#document"]);function $r(e){return g0.has(Fr(e))}function mn(e){return Gt(e).getComputedStyle(e)}function Ys(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||Tf(e)&&e.host||_n(e);return Tf(t)?t.host:t}function Ef(e){const t=Qn(e);return $r(t)?e.ownerDocument?e.ownerDocument.body:e.body:jn(t)&&bo(t)?t:Ef(t)}function So(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Ef(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Gt(o);if(s){const a=Za(i);return t.concat(i,i.visualViewport||[],bo(o)?o:[],a&&n?So(a):[])}return t.concat(o,So(o,[],n))}function Za(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function If(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=Us(n)!==s||Us(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Qa(e){return pn(e)?e:e.contextElement}function zr(e){const t=Qa(e);if(!jn(t))return Nn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=If(t);let i=(s?Us(n.width):n.width)/r,a=(s?Us(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const x0=Nn(0);function Nf(e){const t=Gt(e);return!Ja()||!t.visualViewport?x0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function y0(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=Qa(e);let i=Nn(1);t&&(r?pn(r)&&(i=zr(r)):i=zr(e));const a=y0(s,n,r)?Nf(s):Nn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const h=Gt(s),p=r&&pn(r)?Gt(r):r;let m=h,x=Za(m);for(;x&&r&&p!==m;){const v=zr(x),g=x.getBoundingClientRect(),w=mn(x),S=g.left+(x.clientLeft+parseFloat(w.paddingLeft))*v.x,T=g.top+(x.clientTop+parseFloat(w.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,f*=v.y,l+=S,c+=T,m=Gt(x),x=Za(m)}}return Ks({width:u,height:f,x:l,y:c})}function Xs(e,t){const n=Ys(e).scrollLeft;return t?t.left+n:yr(_n(e)).left+n}function Af(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Xs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function v0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=_n(r),a=t?Gs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Nn(1);const u=Nn(0),f=jn(r);if((f||!f&&!s)&&((Fr(r)!=="body"||bo(i))&&(l=Ys(r)),jn(r))){const p=yr(r);c=zr(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const h=i&&!f&&!s?Af(i,l):Nn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+h.x,y:n.y*c.y-l.scrollTop*c.y+u.y+h.y}}function w0(e){return Array.from(e.getClientRects())}function b0(e){const t=_n(e),n=Ys(e),r=e.ownerDocument.body,o=qt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=qt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Xs(e);const a=-n.scrollTop;return mn(r).direction==="rtl"&&(i+=qt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const _f=25;function S0(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 u=Ja();(!u||u&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Xs(r);if(c<=0){const u=r.ownerDocument,f=u.body,h=getComputedStyle(f),p=u.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=_f&&(s-=m)}else c<=_f&&(s+=c);return{width:s,height:i,x:a,y:l}}const C0=new Set(["absolute","fixed"]);function k0(e,t){const n=yr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=jn(e)?zr(e):Nn(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 jf(e,t,n){let r;if(t==="viewport")r=S0(e,n);else if(t==="document")r=b0(_n(e));else if(pn(t))r=k0(t,n);else{const o=Nf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ks(r)}function Rf(e,t){const n=Qn(e);return n===t||!pn(n)||$r(n)?!1:mn(n).position==="fixed"||Rf(n,t)}function T0(e,t){const n=t.get(e);if(n)return n;let r=So(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=Xa(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&C0.has(o.position)||bo(i)&&!l&&Rf(e,i))?r=r.filter(u=>u!==i):o=a,i=Qn(i)}return t.set(e,r),r}function E0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Gs(t)?[]:T0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const f=jf(t,u,o);return c.top=qt(f.top,c.top),c.right=Zn(f.right,c.right),c.bottom=Zn(f.bottom,c.bottom),c.left=qt(f.left,c.left),c},jf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function I0(e){const{width:t,height:n}=If(e);return{width:t,height:n}}function N0(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=Nn(0);function c(){l.x=Xs(o)}if(r||!r&&!s)if((Fr(t)!=="body"||bo(o))&&(a=Ys(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 u=o&&!r&&!s?Af(o,a):Nn(0),f=i.left+a.scrollLeft-l.x-u.x,h=i.top+a.scrollTop-l.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function el(e){return mn(e).position==="static"}function Pf(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 Of(e,t){const n=Gt(e);if(Gs(e))return n;if(!jn(e)){let o=Qn(e);for(;o&&!$r(o);){if(pn(o)&&!el(o))return o;o=Qn(o)}return n}let r=Pf(e,t);for(;r&&u0(r)&&el(r);)r=Pf(r,t);return r&&$r(r)&&el(r)&&!Xa(r)?n:r||m0(e)||n}const A0=async function(e){const t=this.getOffsetParent||Of,n=this.getDimensions,r=await n(e.floating);return{reference:N0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function _0(e){return mn(e).direction==="rtl"}const j0={convertOffsetParentRelativeRectToViewportRelativeRect:v0,getDocumentElement:_n,getClippingRect:E0,getOffsetParent:Of,getElementRects:A0,getClientRects:w0,getDimensions:I0,getScale:zr,isElement:pn,isRTL:_0};function Mf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function R0(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:u,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=Ws(f),x=Ws(o.clientWidth-(u+h)),v=Ws(o.clientHeight-(f+p)),g=Ws(u),S={rootMargin:-m+"px "+-x+"px "+-v+"px "+-g+"px",threshold:qt(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&&!Mf(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 P0(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=Qa(e),u=o||s?[...c?So(c):[],...So(t)]:[];u.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?R0(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(g=>{let[w]=g;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 m,x=l?yr(e):null;l&&v();function v(){const g=yr(e);x&&!Mf(x,g)&&n(),x=g,m=requestAnimationFrame(v)}return n(),()=>{var g;u.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(g=p)==null||g.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const O0=o0,M0=s0,D0=t0,L0=a0,F0=n0,Df=e0,$0=i0,z0=(e,t,n)=>{const r=new Map,o={platform:j0,...n},s={...o.platform,_c:r};return Qb(e,t,{...o,platform:s})};var B0=typeof document<"u",H0=function(){},Js=B0?b.useLayoutEffect:H0;function Zs(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(!Zs(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)&&!Zs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Lf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ff(e,t){const n=Lf(e);return Math.round(t*n)/n}function tl(e){const t=y.useRef(e);return Js(()=>{t.current=e}),t}function U0(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,[u,f]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=y.useState(r);Zs(h,r)||p(r);const[m,x]=y.useState(null),[v,g]=y.useState(null),w=y.useCallback(K=>{K!==C.current&&(C.current=K,x(K))},[]),S=y.useCallback(K=>{K!==E.current&&(E.current=K,g(K))},[]),T=s||m,k=i||v,C=y.useRef(null),E=y.useRef(null),_=y.useRef(u),j=l!=null,D=tl(l),$=tl(o),q=tl(c),P=y.useCallback(()=>{if(!C.current||!E.current)return;const K={placement:t,strategy:n,middleware:h};$.current&&(K.platform=$.current),z0(C.current,E.current,K).then(B=>{const pe={...B,isPositioned:q.current!==!1};R.current&&!Zs(_.current,pe)&&(_.current=pe,Mo.flushSync(()=>{f(pe)}))})},[h,t,n,$,q]);Js(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,f(K=>({...K,isPositioned:!1})))},[c]);const R=y.useRef(!1);Js(()=>(R.current=!0,()=>{R.current=!1}),[]),Js(()=>{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=y.useMemo(()=>({reference:C,floating:E,setReference:w,setFloating:S}),[w,S]),F=y.useMemo(()=>({reference:T,floating:k}),[T,k]),ne=y.useMemo(()=>{const K={position:n,left:0,top:0};if(!F.floating)return K;const B=Ff(F.floating,u.x),pe=Ff(F.floating,u.y);return a?{...K,transform:"translate("+B+"px, "+pe+"px)",...Lf(F.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:B,top:pe}},[n,a,F.floating,u.x,u.y]);return y.useMemo(()=>({...u,update:P,refs:L,elements:F,floatingStyles:ne}),[u,P,L,F,ne])}const W0=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?Df({element:r.current,padding:o}).fn(n):{}:r?Df({element:r,padding:o}).fn(n):{}}}},V0=(e,t)=>({...O0(e),options:[e,t]}),K0=(e,t)=>({...M0(e),options:[e,t]}),q0=(e,t)=>({...$0(e),options:[e,t]}),G0=(e,t)=>({...D0(e),options:[e,t]}),Y0=(e,t)=>({...L0(e),options:[e,t]}),X0=(e,t)=>({...F0(e),options:[e,t]}),J0=(e,t)=>({...W0(e),options:[e,t]});var Z0="Arrow",$f=y.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return d.jsx(Ie.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});$f.displayName=Z0;var Q0=$f;function zf(e){const[t,n]=y.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 nl="Popper",[Bf,Qs]=Tn(nl),[eS,Hf]=Bf(nl),Uf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=y.useState(null);return d.jsx(eS,{scope:t,anchor:r,onAnchorChange:o,children:n})};Uf.displayName=nl;var Wf="PopperAnchor",Vf=y.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Hf(Wf,n),i=y.useRef(null),a=He(t,i),l=y.useRef(null);return y.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:d.jsx(Ie.div,{...o,ref:a})});Vf.displayName=Wf;var rl="PopperContent",[tS,nS]=Bf(rl),Kf=y.forwardRef((e,t)=>{var G,M,X,oe,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:u=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...x}=e,v=Hf(rl,n),[g,w]=y.useState(null),S=He(t,re=>w(re)),[T,k]=y.useState(null),C=zf(T),E=(C==null?void 0:C.width)??0,_=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),D=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},$=Array.isArray(c)?c:[c],q=$.length>0,P={padding:D,boundary:$.filter(oS),altBoundary:q},{refs:R,floatingStyles:L,placement:F,isPositioned:ne,middlewareData:K}=U0({strategy:"fixed",placement:j,whileElementsMounted:(...re)=>P0(...re,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[V0({mainAxis:o+_,alignmentAxis:i}),l&&K0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?q0():void 0,...P}),l&&G0({...P}),Y0({...P,apply:({elements:re,rects:Ue,availableWidth:Ke,availableHeight:ot})=>{const{width:at,height:ht}=Ue.reference,tt=re.floating.style;tt.setProperty("--radix-popper-available-width",`${Ke}px`),tt.setProperty("--radix-popper-available-height",`${ot}px`),tt.setProperty("--radix-popper-anchor-width",`${at}px`),tt.setProperty("--radix-popper-anchor-height",`${ht}px`)}}),T&&J0({element:T,padding:a}),sS({arrowWidth:E,arrowHeight:_}),h&&X0({strategy:"referenceHidden",...P})]}),[B,pe]=Yf(F),W=Nt(m);kt(()=>{ne&&(W==null||W())},[ne,W]);const ce=(G=K.arrow)==null?void 0:G.x,H=(M=K.arrow)==null?void 0:M.y,Z=((X=K.arrow)==null?void 0:X.centerOffset)!==0,[we,ye]=y.useState();return kt(()=>{g&&ye(window.getComputedStyle(g).zIndex)},[g]),d.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...L,transform:ne?L.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:we,"--radix-popper-transform-origin":[(oe=K.transformOrigin)==null?void 0:oe.x,(xe=K.transformOrigin)==null?void 0:xe.y].join(" "),...((se=K.hide)==null?void 0:se.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(tS,{scope:n,placedSide:B,onArrowChange:k,arrowX:ce,arrowY:H,shouldHideArrow:Z,children:d.jsx(Ie.div,{"data-side":B,"data-align":pe,...x,ref:S,style:{...x.style,animation:ne?void 0:"none"}})})})});Kf.displayName=rl;var qf="PopperArrow",rS={top:"bottom",right:"left",bottom:"top",left:"right"},Gf=y.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=nS(qf,r),i=rS[s.placedSide];return d.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:d.jsx(Q0,{...o,ref:n,style:{...o.style,display:"block"}})})});Gf.displayName=qf;function oS(e){return e!==null}var sS=e=>({name:"transformOrigin",options:e,fn(t){var v,g,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,u]=Yf(n),f={start:"0%",center:"50%",end:"100%"}[u],h=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+l/2;let m="",x="";return c==="bottom"?(m=i?f:`${h}px`,x=`${-l}px`):c==="top"?(m=i?f:`${h}px`,x=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,x=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:m,y:x}}}});function Yf(e){const[t,n="center"]=e.split("-");return[t,n]}var Xf=Uf,Jf=Vf,Zf=Kf,Qf=Gf,ol="rovingFocusGroup.onEntryFocus",iS={bubbles:!1,cancelable:!0},Co="RovingFocusGroup",[sl,eh,aS]=Wa(Co),[lS,th]=Tn(Co,[aS]),[cS,uS]=lS(Co),nh=y.forwardRef((e,t)=>d.jsx(sl.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(sl.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(dS,{...e,ref:t})})}));nh.displayName=Co;var dS=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...f}=e,h=y.useRef(null),p=He(t,h),m=Hs(s),[x,v]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Co}),[g,w]=y.useState(!1),S=Nt(c),T=eh(n),k=y.useRef(!1),[C,E]=y.useState(0);return y.useEffect(()=>{const _=h.current;if(_)return _.addEventListener(ol,S),()=>_.removeEventListener(ol,S)},[S]),d.jsx(cS,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:x,onItemFocus:y.useCallback(_=>v(_),[v]),onItemShiftTab:y.useCallback(()=>w(!0),[]),onFocusableItemAdd:y.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:y.useCallback(()=>E(_=>_-1),[]),children:d.jsx(Ie.div,{tabIndex:g||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&&!g){const D=new CustomEvent(ol,iS);if(_.currentTarget.dispatchEvent(D),!D.defaultPrevented){const $=T().filter(F=>F.focusable),q=$.find(F=>F.active),P=$.find(F=>F.id===x),L=[q,P,...$].filter(Boolean).map(F=>F.ref.current);sh(L,u)}}k.current=!1}),onBlur:ge(e.onBlur,()=>w(!1))})})}),rh="RovingFocusGroupItem",oh=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=En(),c=s||l,u=uS(rh,n),f=u.currentTabStopId===c,h=eh(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:x}=u;return y.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),d.jsx(sl.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:d.jsx(Ie.span,{tabIndex:f?0:-1,"data-orientation":u.orientation,...a,ref:t,onMouseDown:ge(e.onMouseDown,v=>{r?u.onItemFocus(c):v.preventDefault()}),onFocus:ge(e.onFocus,()=>u.onItemFocus(c)),onKeyDown:ge(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){u.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const g=pS(v,u.orientation,u.dir);if(g!==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(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const T=S.indexOf(v.currentTarget);S=u.loop?mS(S,T+1):S.slice(T+1)}setTimeout(()=>sh(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});oh.displayName=rh;var fS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function hS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pS(e,t,n){const r=hS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fS[r]}function sh(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function mS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var gS=nh,xS=oh,il=["Enter"," "],yS=["ArrowDown","PageUp","Home"],ih=["ArrowUp","PageDown","End"],vS=[...yS,...ih],wS={ltr:[...il,"ArrowRight"],rtl:[...il,"ArrowLeft"]},bS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ko="Menu",[To,SS,CS]=Wa(ko),[vr,ah]=Tn(ko,[CS,Qs,th]),ei=Qs(),lh=th(),[kS,wr]=vr(ko),[TS,Eo]=vr(ko),ch=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ei(t),[l,c]=y.useState(null),u=y.useRef(!1),f=Nt(s),h=Hs(o);return y.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),d.jsx(Xf,{...a,children:d.jsx(kS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:d.jsx(TS,{scope:t,onClose:y.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:h,modal:i,children:r})})})};ch.displayName=ko;var ES="MenuAnchor",al=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ei(n);return d.jsx(Jf,{...o,...r,ref:t})});al.displayName=ES;var ll="MenuPortal",[IS,uh]=vr(ll,{forceMount:void 0}),dh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=wr(ll,t);return d.jsx(IS,{scope:t,forceMount:n,children:d.jsx(Kt,{present:n||s.open,children:d.jsx(Ss,{asChild:!0,container:o,children:r})})})};dh.displayName=ll;var nn="MenuContent",[NS,cl]=vr(nn),fh=y.forwardRef((e,t)=>{const n=uh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=Eo(nn,e.__scopeMenu);return d.jsx(To.Provider,{scope:e.__scopeMenu,children:d.jsx(Kt,{present:r||s.open,children:d.jsx(To.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(AS,{...o,ref:t}):d.jsx(_S,{...o,ref:t})})})})}),AS=y.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu),r=y.useRef(null),o=He(t,r);return y.useEffect(()=>{const s=r.current;if(s)return Da(s)},[]),d.jsx(ul,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),_S=y.forwardRef((e,t)=>{const n=wr(nn,e.__scopeMenu);return d.jsx(ul,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),jS=sr.createSlot("MenuContent.ScrollLock"),ul=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...x}=e,v=wr(nn,n),g=Eo(nn,n),w=ei(n),S=lh(n),T=SS(n),[k,C]=y.useState(null),E=y.useRef(null),_=He(t,E,v.onContentChange),j=y.useRef(0),D=y.useRef(""),$=y.useRef(0),q=y.useRef(null),P=y.useRef("right"),R=y.useRef(0),L=m?Ns:y.Fragment,F=m?{as:jS,allowPinchZoom:!0}:void 0,ne=B=>{var G,M;const pe=D.current+B,W=T().filter(X=>!X.disabled),ce=document.activeElement,H=(G=W.find(X=>X.ref.current===ce))==null?void 0:G.textValue,Z=W.map(X=>X.textValue),we=US(Z,pe,H),ye=(M=W.find(X=>X.textValue===we))==null?void 0:M.ref.current;(function X(oe){D.current=oe,window.clearTimeout(j.current),oe!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(pe),ye&&setTimeout(()=>ye.focus())};y.useEffect(()=>()=>window.clearTimeout(j.current),[]),_a();const K=y.useCallback(B=>{var W,ce;return P.current===((W=q.current)==null?void 0:W.side)&&VS(B,(ce=q.current)==null?void 0:ce.area)},[]);return d.jsx(NS,{scope:n,searchRef:D,onItemEnter:y.useCallback(B=>{K(B)&&B.preventDefault()},[K]),onItemLeave:y.useCallback(B=>{var pe;K(B)||((pe=E.current)==null||pe.focus(),C(null))},[K]),onTriggerLeave:y.useCallback(B=>{K(B)&&B.preventDefault()},[K]),pointerGraceTimerRef:$,onPointerGraceIntentChange:y.useCallback(B=>{q.current=B},[]),children:d.jsx(L,{...F,children:d.jsx(bs,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,B=>{var pe;B.preventDefault(),(pe=E.current)==null||pe.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(ws,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:d.jsx(gS,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:ge(l,B=>{g.isUsingKeyboardRef.current||B.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(Zf,{role:"menu","aria-orientation":"vertical","data-state":Ah(v.open),"data-radix-menu-content":"",dir:g.dir,...w,...x,ref:_,style:{outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,B=>{const W=B.target.closest("[data-radix-menu-content]")===B.currentTarget,ce=B.ctrlKey||B.altKey||B.metaKey,H=B.key.length===1;W&&(B.key==="Tab"&&B.preventDefault(),!ce&&H&&ne(B.key));const Z=E.current;if(B.target!==Z||!vS.includes(B.key))return;B.preventDefault();const ye=T().filter(G=>!G.disabled).map(G=>G.ref.current);ih.includes(B.key)&&ye.reverse(),BS(ye)}),onBlur:ge(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(j.current),D.current="")}),onPointerMove:ge(e.onPointerMove,No(B=>{const pe=B.target,W=R.current!==B.clientX;if(B.currentTarget.contains(pe)&&W){const ce=B.clientX>R.current?"right":"left";P.current=ce,R.current=B.clientX}}))})})})})})})});fh.displayName=nn;var RS="MenuGroup",dl=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ie.div,{role:"group",...r,ref:t})});dl.displayName=RS;var PS="MenuLabel",hh=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ie.div,{...r,ref:t})});hh.displayName=PS;var ti="MenuItem",ph="menu.itemSelect",ni=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=y.useRef(null),i=Eo(ti,e.__scopeMenu),a=cl(ti,e.__scopeMenu),l=He(t,s),c=y.useRef(!1),u=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ph,{bubbles:!0,cancelable:!0});f.addEventListener(ph,p=>r==null?void 0:r(p),{once:!0}),Qu(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(mh,{...o,ref:l,disabled:n,onClick:ge(e.onClick,u),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===" "||il.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ni.displayName=ti;var mh=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=cl(ti,n),a=lh(n),l=y.useRef(null),c=He(t,l),[u,f]=y.useState(!1),[h,p]=y.useState("");return y.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),d.jsx(To.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:d.jsx(xS,{asChild:!0,...a,focusable:!r,children:d.jsx(Ie.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ge(e.onPointerMove,No(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,No(m=>i.onItemLeave(m))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),OS="MenuCheckboxItem",gh=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return d.jsx(bh,{scope:e.__scopeMenu,checked:n,children:d.jsx(ni,{role:"menuitemcheckbox","aria-checked":ri(n)?"mixed":n,...o,ref:t,"data-state":hl(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(ri(n)?!0:!n),{checkForDefaultPrevented:!1})})})});gh.displayName=OS;var xh="MenuRadioGroup",[MS,DS]=vr(xh,{value:void 0,onValueChange:()=>{}}),yh=y.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Nt(r);return d.jsx(MS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:d.jsx(dl,{...o,ref:t})})});yh.displayName=xh;var vh="MenuRadioItem",wh=y.forwardRef((e,t)=>{const{value:n,...r}=e,o=DS(vh,e.__scopeMenu),s=n===o.value;return d.jsx(bh,{scope:e.__scopeMenu,checked:s,children:d.jsx(ni,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":hl(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});wh.displayName=vh;var fl="MenuItemIndicator",[bh,LS]=vr(fl,{checked:!1}),Sh=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=LS(fl,n);return d.jsx(Kt,{present:r||ri(s.checked)||s.checked===!0,children:d.jsx(Ie.span,{...o,ref:t,"data-state":hl(s.checked)})})});Sh.displayName=fl;var FS="MenuSeparator",Ch=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ie.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Ch.displayName=FS;var $S="MenuArrow",kh=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ei(n);return d.jsx(Qf,{...o,...r,ref:t})});kh.displayName=$S;var zS="MenuSub",[ST,Th]=vr(zS),Io="MenuSubTrigger",Eh=y.forwardRef((e,t)=>{const n=wr(Io,e.__scopeMenu),r=Eo(Io,e.__scopeMenu),o=Th(Io,e.__scopeMenu),s=cl(Io,e.__scopeMenu),i=y.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=y.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return y.useEffect(()=>u,[u]),y.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),d.jsx(al,{asChild:!0,...c,children:d.jsx(mh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Ah(n.open),...e,ref:ya(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,No(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:ge(e.onPointerLeave,No(f=>{var p,m;u();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(m=n.content)==null?void 0:m.dataset.side,v=x==="right",g=v?-5:5,w=h[v?"left":"right"],S=h[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:w,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:w,y:h.bottom}],side:x}),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===" "||wS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Eh.displayName=Io;var Ih="MenuSubContent",Nh=y.forwardRef((e,t)=>{const n=uh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=wr(nn,e.__scopeMenu),i=Eo(nn,e.__scopeMenu),a=Th(Ih,e.__scopeMenu),l=y.useRef(null),c=He(t,l);return d.jsx(To.Provider,{scope:e.__scopeMenu,children:d.jsx(Kt,{present:r||s.open,children:d.jsx(To.Slot,{scope:e.__scopeMenu,children:d.jsx(ul,{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:u=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ge(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ge(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ge(e.onKeyDown,u=>{var p;const f=u.currentTarget.contains(u.target),h=bS[i.dir].includes(u.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});Nh.displayName=Ih;function Ah(e){return e?"open":"closed"}function ri(e){return e==="indeterminate"}function hl(e){return ri(e)?"indeterminate":e?"checked":"unchecked"}function BS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function HS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function US(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=HS(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 WS(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,u=a.y,f=l.x,h=l.y;u>r!=h>r&&n<(f-c)*(r-u)/(h-u)+c&&(o=!o)}return o}function VS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return WS(n,t)}function No(e){return t=>t.pointerType==="mouse"?e(t):void 0}var KS=ch,qS=al,GS=dh,YS=fh,XS=dl,JS=hh,ZS=ni,QS=gh,eC=yh,tC=wh,nC=Sh,rC=Ch,oC=kh,sC=Eh,iC=Nh,oi="DropdownMenu",[aC,CT]=Tn(oi,[ah]),$t=ah(),[lC,_h]=aC(oi),jh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=$t(t),c=y.useRef(null),[u,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:oi});return d.jsx(lC,{scope:t,triggerId:En(),triggerRef:c,contentId:En(),open:u,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(h=>!h),[f]),modal:a,children:d.jsx(KS,{...l,open:u,onOpenChange:f,dir:r,modal:a,children:n})})};jh.displayName=oi;var Rh="DropdownMenuTrigger",Ph=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=_h(Rh,n),i=$t(n);return d.jsx(qS,{asChild:!0,...i,children:d.jsx(Ie.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:ya(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())})})})});Ph.displayName=Rh;var cC="DropdownMenuPortal",Oh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=$t(t);return d.jsx(GS,{...r,...n})};Oh.displayName=cC;var Mh="DropdownMenuContent",Dh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=_h(Mh,n),s=$t(n),i=y.useRef(!1);return d.jsx(YS,{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,u=l.button===2||c;(!o.modal||u)&&(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)"}})});Dh.displayName=Mh;var uC="DropdownMenuGroup",dC=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(XS,{...o,...r,ref:t})});dC.displayName=uC;var fC="DropdownMenuLabel",Lh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(JS,{...o,...r,ref:t})});Lh.displayName=fC;var hC="DropdownMenuItem",Fh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(ZS,{...o,...r,ref:t})});Fh.displayName=hC;var pC="DropdownMenuCheckboxItem",$h=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(QS,{...o,...r,ref:t})});$h.displayName=pC;var mC="DropdownMenuRadioGroup",gC=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(eC,{...o,...r,ref:t})});gC.displayName=mC;var xC="DropdownMenuRadioItem",zh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(tC,{...o,...r,ref:t})});zh.displayName=xC;var yC="DropdownMenuItemIndicator",Bh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(nC,{...o,...r,ref:t})});Bh.displayName=yC;var vC="DropdownMenuSeparator",Hh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(rC,{...o,...r,ref:t})});Hh.displayName=vC;var wC="DropdownMenuArrow",bC=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(oC,{...o,...r,ref:t})});bC.displayName=wC;var SC="DropdownMenuSubTrigger",Uh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(sC,{...o,...r,ref:t})});Uh.displayName=SC;var CC="DropdownMenuSubContent",Wh=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return d.jsx(iC,{...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)"}})});Wh.displayName=CC;var kC=jh,TC=Ph,EC=Oh,Vh=Dh,Kh=Lh,qh=Fh,Gh=$h,Yh=zh,Xh=Bh,Jh=Hh,Zh=Uh,Qh=Wh;const IC=kC,NC=TC,AC=y.forwardRef(({className:e,inset:t,children:n,...r},o)=>d.jsxs(Zh,{ref:o,className:ee("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,d.jsx(fe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));AC.displayName=Zh.displayName;const _C=y.forwardRef(({className:e,...t},n)=>d.jsx(Qh,{ref:n,className:ee("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}));_C.displayName=Qh.displayName;const ep=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>d.jsx(EC,{children:d.jsx(Vh,{ref:r,sideOffset:t,className:ee("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})}));ep.displayName=Vh.displayName;const pl=y.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(qh,{ref:r,className:ee("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}));pl.displayName=qh.displayName;const jC=y.forwardRef(({className:e,children:t,checked:n,...r},o)=>d.jsxs(Gh,{ref:o,className:ee("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:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Xh,{children:d.jsx(fe.Check,{className:"h-4 w-4"})})}),t]}));jC.displayName=Gh.displayName;const RC=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(Yh,{ref:r,className:ee("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:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Xh,{children:d.jsx(fe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));RC.displayName=Yh.displayName;const PC=y.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(Kh,{ref:r,className:ee("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));PC.displayName=Kh.displayName;const OC=y.forwardRef(({className:e,...t},n)=>d.jsx(Jh,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));OC.displayName=Jh.displayName;const tp={value:""};function si({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:u=!0,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:m}){const{api:x}=Ri(),{currentThreadId:v}=Qo(),{threadId:g,messages:w,hasMore:S,isHistoryLoading:T,isLoading:k,loadOlder:C,navigateToCheckpoint:E,returnToLatest:_,checkpoint:j,checkpoints:D,interrupt:$,metadata:q}=es(),{isStreaming:P,error:R,submit:L,stop:F}=Yc(),ne=g??v??null,K=(j==null?void 0:j.id)??null,B=(j==null?void 0:j.namespace)??null,pe=(q==null?void 0:q.assemblingMessageId)??null,W=$,[ce,H]=b.useState(!1);b.useEffect(()=>{W||H(!1)},[W]);const Z=b.useCallback(()=>{H(!0)},[]),we=b.useCallback(()=>{H(!1)},[]),ye=!!W||ce,[G,M]=b.useState(null),[X,oe]=b.useState(""),[xe,se]=b.useState(null),[re,Ue]=b.useState([]),[Ke,ot]=b.useState(0),[at,ht]=b.useState(0),[tt,Me]=b.useState(!1),[We,lt]=b.useState(null),[xt,dt]=b.useState(null),[Je,ie]=b.useState(!1),[je,ke]=b.useState(null),[qe,nt]=b.useState(!1),Oe=b.useRef(!1),[Xe,Tt]=b.useState(()=>tp.value),St=b.useRef(Xe),Yt=b.useRef(null),Et=b.useCallback(z=>{tp.value=z,Tt(z)},[]),[rr,Xt]=b.useState(!1),xn=b.useCallback((z,ue)=>{if(!z||typeof z!="object")return null;const me=z[ue];return typeof me=="number"?me:null},[]),sn=b.useCallback((z,ue)=>{if(!z||typeof z!="object")return null;const me=z[ue];return typeof me=="string"&&me.trim()?me:null},[]),Dt=b.useMemo(()=>{const z=Array.isArray(D)?[...D]:[];return z.some(me=>xn(me.metadata,"step")!==null)&&z.sort((me,Re)=>{const rt=xn(me.metadata,"step"),Lt=xn(Re.metadata,"step");if(rt!==null||Lt!==null)return(Lt??Number.NEGATIVE_INFINITY)-(rt??Number.NEGATIVE_INFINITY);const an=Date.parse(me.createdAt??""),Ct=Date.parse(Re.createdAt??"");return Number.isNaN(an)||Number.isNaN(Ct)?0:Ct-an}),z},[D,xn]),Pn=b.useRef(null),yn=b.useRef(null),pt=b.useCallback(()=>{Pn.current&&(Pn.current.value=""),yn.current&&(yn.current.value=""),ot(z=>z+1),ht(z=>z+1)},[]),vn=b.useCallback(z=>{Et(z)},[Et]),On=b.useRef(!1);b.useEffect(()=>{On.current&&!P&&(Ue([]),pt()),On.current=P},[P,pt]);const[kr,Jt]=b.useState("desktop");b.useEffect(()=>{const z=()=>{const ue=window.innerWidth;Jt(ue<640?"phone":ue<1024?"tablet":"desktop")};return z(),window.addEventListener("resize",z),()=>window.removeEventListener("resize",z)},[]),b.useEffect(()=>{nt(!1),Oe.current=!1},[ne]),b.useEffect(()=>{St.current=Xe},[Xe]),b.useEffect(()=>{if(!G){Yt.current=null;return}Yt.current===null&&(Yt.current=St.current),Et(X??"")},[X,G,Et]);const Tr=b.useCallback(async()=>{if(!(!S||T||!qe))try{await C()}catch(z){console.warn("loadOlder failed",z)}},[S,qe,T,C]);b.useEffect(()=>{(async()=>{if(!x.baseUrl){ke(null);return}try{const me=(await x.getAgent("default")).uiDefaultMessage||"";ke(me||null)}catch(ue){console.warn("Failed to fetch default message:",ue),ke(null)}})()},[x.baseUrl]),b.useEffect(()=>{R&&!Je&&(m==null||m(R))},[R,Je,m]);const Mn=z=>{if(z.length>Bs)return`Message too long (${z.length}/${Bs} characters)`;try{return zb(z),null}catch(ue){return(ue==null?void 0:ue.message)||"Invalid message"}},wn=async z=>{const ue=z.trim();if(!(!ue&&re.length===0)){if(ue){const me=Mn(ue);if(me){se(me);return}}try{await L({text:ue||"",attachments:re,payload:G?{edit:!0,originalMessageId:G}:void 0},{checkpointId:K??void 0,checkpointNs:B??void 0}),h==null||h(ue),Et(""),se(null),Ue([]),pt(),M(null),oe("")}catch(me){const Re=(me==null?void 0:me.message)||"Failed to send message";se(Re),m==null||m(Re)}}},Un=b.useCallback((z,ue)=>{c&&(Yt.current=Xe,M(z),oe(ue),Et(ue),se(null))},[Xe,c,Et]),Er=b.useCallback(()=>{M(null),oe(""),se(null),Et(Yt.current??Xe),Yt.current=null},[Xe,Et]),Wr=b.useCallback((z,ue)=>{Un(z,ue)},[Un]),Vr=b.useCallback(z=>{for(let ue=z-1;ue>=0;ue--)if(w[ue].role==="user"){const me=w[ue].content||[],rt=me.filter(Lt=>Lt.type==="text").map(Lt=>Lt.text).join("")||(()=>{try{return JSON.stringify(me,null,2)}catch{return String(me)}})();rt&&L({text:rt},{checkpointId:K??void 0,checkpointNs:B??void 0});break}},[w,L,K,B]),or=z=>{const ue=Array.from(z.target.files||[]);Ue(me=>[...me,...ue]),z.target.value=""},I=z=>{Ue(ue=>{const me=ue.filter((Re,rt)=>z!==rt);return me.length===0&&pt(),me})},U=async z=>{const ue=(z.target.files||[])[0];if(ue){lt(null),dt(null),Me(!0);try{await L({attachments:[ue]},{checkpointId:K??void 0,checkpointNs:B??void 0});const me=`Uploaded ${ue.name} - processing through chat stream`;dt(me)}catch(me){const Re=me instanceof Error?me.message:"Failed to upload Excel file";console.error("Excel upload failed",me),lt(Re),m==null||m(Re)}finally{Me(!1),z.target.value="",pt()}}},le=z=>{if(!z)return"Unknown";const ue=Date.parse(z);return Number.isNaN(ue)?z:new Date(ue).toLocaleString()},Ce=async z=>{if(v){Xt(!0);try{if(!z){await _();return}const ue=Dt.find(Re=>Re.checkpointId===z),me=(ue==null?void 0:ue.checkpointNs)??null;await E(z,me)}finally{Xt(!1)}}},Ge=`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||""}`,Fe=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`;return d.jsxs("div",{className:Ge,children:[!!R&&!Je&&d.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:[d.jsx("span",{children:R}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>ie(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:d.jsx(fe.X,{size:16})})]}),v&&D.length>0&&d.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:[d.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),d.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:K??"",onChange:z=>{const ue=z.target.value||null;Ce(ue)},children:[d.jsx("option",{value:"",children:"Latest"}),Dt.map(z=>{const ue=xn(z.metadata,"step"),me=sn(z.metadata,"source"),Re=[];ue!==null&&Re.push(`Step ${ue}`),me&&Re.push(me);const rt=Re.length?` — ${Re.join(" • ")}`:"";return d.jsxs("option",{value:z.checkpointId,children:[le(z.createdAt),rt]},z.checkpointId)})]})]}),d.jsxs("div",{className:`relative ${$e}`,style:r?{maxHeight:r}:void 0,children:[d.jsx(Ua,{className:"h-full",style:{height:"100%"},messages:w,isStreaming:P,streamingAssistantId:pe,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:kr,enableMessageEditing:c,editingMessageId:G,onStartReached:()=>{qe&&Tr()},onScrollAway:z=>{if(!Oe.current){Oe.current=!0;return}z&&nt(!0)},onEdit:Wr,onRegenerate:Vr,onCancelEdit:Er,emptyMessage:je??void 0,isNavigatingCheckpoint:rr,activeInterrupt:W,disableInterruptActions:ce,onInterruptActionStart:Z,onInterruptActionEnd:we,showToolMessages:u}),k&&d.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:[d.jsx(fe.Loader2,{className:"h-6 w-6 animate-spin"}),d.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),d.jsxs("div",{className:Fe,children:[G&&d.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(fe.Edit3,{size:16,className:"text-blue-600"}),d.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Er,className:"text-blue-600 hover:bg-blue-100",children:d.jsx(fe.X,{size:16})})]})}),(a||l)&&d.jsxs("div",{className:"mb-3 space-y-3",children:[a&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:Pn,type:"file",multiple:!0,onChange:z=>or(z),className:"hidden"},Ke),re.length>0&&d.jsx("div",{className:"flex flex-wrap gap-2",children:re.map((z,ue)=>d.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:[d.jsx(fe.Paperclip,{size:14}),d.jsx("span",{className:"truncate max-w-[150px]",children:z.name}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>I(ue),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 ${z.name}`,children:d.jsx(fe.X,{size:12})})]},ue))})]}),l&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:yn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:U,className:"hidden"},at),tt&&d.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(fe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!tt&&d.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),We&&!tt&&d.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:We})]})]}),xe&&d.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:xe}),d.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&d.jsxs(IC,{children:[d.jsx(NC,{asChild:!0,children:d.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:P||ye,title:"More input actions",className:f.moreButton||"",children:d.jsx(fe.Plus,{size:16})})}),d.jsxs(ep,{align:"start",sideOffset:6,className:"w-52",children:[a&&d.jsxs(pl,{onClick:()=>{var z;return(z=Pn.current)==null?void 0:z.click()},className:"cursor-pointer",children:[d.jsx(fe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&d.jsxs(pl,{onClick:()=>{var z;tt||(z=yn.current)==null||z.click()},className:`cursor-pointer ${tt?"opacity-60 pointer-events-none":""}`,children:[d.jsx(fe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),d.jsx("div",{className:"flex-1",children:d.jsx(Zx,{initialValue:X,editingMessageId:G,value:Xe,onValueChange:vn,placeholder:G?"Edit your message...":t,isStreaming:P,disabled:ye,maxLength:Bs,onSend:wn,onCancelEdit:Er,onStop:F,allowEmptySend:re.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${G?"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 ii=y.forwardRef(({className:e,type:t,...n},r)=>d.jsx("input",{type:t,className:ee("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}));ii.displayName="Input";function ml(e,[t,n]){return Math.min(n,Math.max(t,e))}function MC(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var gl="ScrollArea",[np,kT]=Tn(gl),[DC,rn]=np(gl),rp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=y.useState(null),[c,u]=y.useState(null),[f,h]=y.useState(null),[p,m]=y.useState(null),[x,v]=y.useState(null),[g,w]=y.useState(0),[S,T]=y.useState(0),[k,C]=y.useState(!1),[E,_]=y.useState(!1),j=He(t,$=>l($)),D=Hs(o);return d.jsx(DC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:u,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:k,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:_,onCornerWidthChange:w,onCornerHeightChange:T,children:d.jsx(Ie.div,{dir:D,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});rp.displayName=gl;var op="ScrollAreaViewport",sp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=rn(op,n),a=y.useRef(null),l=He(t,a,i.onViewportChange);return d.jsxs(d.Fragment,{children:[d.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}),d.jsx(Ie.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:d.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});sp.displayName=op;var Rn="ScrollAreaScrollbar",xl=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return y.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?d.jsx(LC,{...r,ref:t,forceMount:n}):o.type==="scroll"?d.jsx(FC,{...r,ref:t,forceMount:n}):o.type==="auto"?d.jsx(ip,{...r,ref:t,forceMount:n}):o.type==="always"?d.jsx(yl,{...r,ref:t}):null});xl.displayName=Rn;var LC=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),[s,i]=y.useState(!1);return y.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},u=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",u),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),d.jsx(Kt,{present:n||s,children:d.jsx(ip,{"data-state":s?"visible":"hidden",...r,ref:t})})}),FC=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(Rn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ui(()=>l("SCROLL_END"),100),[a,l]=MC("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 y.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),y.useEffect(()=>{const c=o.viewport,u=s?"scrollLeft":"scrollTop";if(c){let f=c[u];const h=()=>{const p=c[u];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),d.jsx(Kt,{present:n||a!=="hidden",children:d.jsx(yl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),ip=y.forwardRef((e,t)=>{const n=rn(Rn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=y.useState(!1),a=e.orientation==="horizontal",l=ui(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:u)}},10);return Br(n.viewport,l),Br(n.content,l),d.jsx(Kt,{present:r||s,children:d.jsx(yl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),yl=y.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=rn(Rn,e.__scopeScrollArea),s=y.useRef(null),i=y.useRef(0),[a,l]=y.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=dp(a.viewport,a.content),u={...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 WC(h,i.current,a,p)}return n==="horizontal"?d.jsx($C,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=fp(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"?d.jsx(zC,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=fp(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}),$C=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=He(t,l,s.onScrollbarXChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(lp,{"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":ci(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(h),pp(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:li(i.paddingLeft),paddingEnd:li(i.paddingRight)}})}})}),zC=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(Rn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=He(t,l,s.onScrollbarYChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(lp,{"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":ci(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(h),pp(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:li(i.paddingTop),paddingEnd:li(i.paddingBottom)}})}})}),[BC,ap]=np(Rn),lp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:u,onResize:f,...h}=e,p=rn(Rn,n),[m,x]=y.useState(null),v=He(t,j=>x(j)),g=y.useRef(null),w=y.useRef(""),S=p.viewport,T=r.content-r.viewport,k=Nt(u),C=Nt(l),E=ui(f,10);function _(j){if(g.current){const D=j.clientX-g.current.left,$=j.clientY-g.current.top;c({x:D,y:$})}}return y.useEffect(()=>{const j=D=>{const $=D.target;(m==null?void 0:m.contains($))&&k(D,T)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,m,T,k]),y.useEffect(C,[r,C]),Br(m,E),Br(p.content,E),d.jsx(BC,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Nt(s),onThumbPointerUp:Nt(i),onThumbPositionChange:C,onThumbPointerDown:Nt(a),children:d.jsx(Ie.div,{...h,ref:v,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=m.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=""),g.current=null})})})}),ai="ScrollAreaThumb",cp=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ap(ai,e.__scopeScrollArea);return d.jsx(Kt,{present:n||o.hasThumb,children:d.jsx(HC,{ref:t,...r})})}),HC=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=rn(ai,n),i=ap(ai,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),c=y.useRef(void 0),u=ui(()=>{c.current&&(c.current(),c.current=void 0)},100);return y.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(u(),!c.current){const p=VC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,u,a]),d.jsx(Ie.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(),m=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:m,y:x})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});cp.displayName=ai;var vl="ScrollAreaCorner",up=y.forwardRef((e,t)=>{const n=rn(vl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?d.jsx(UC,{...e,ref:t}):null});up.displayName=vl;var UC=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=rn(vl,n),[s,i]=y.useState(0),[a,l]=y.useState(0),c=!!(s&&a);return Br(o.scrollbarX,()=>{var f;const u=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(u),l(u)}),Br(o.scrollbarY,()=>{var f;const u=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(u),i(u)}),c?d.jsx(Ie.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 li(e){return e?parseInt(e,10):0}function dp(e,t){const n=e/t;return isNaN(n)?0:n}function ci(e){const t=dp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function WC(e,t,n,r="ltr"){const o=ci(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,u=n.content-n.viewport,f=r==="ltr"?[0,u]:[u*-1,0];return hp([l,c],f)(e)}function fp(e,t,n="ltr"){const r=ci(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=ml(e,l);return hp([0,i],[0,a])(c)}function hp(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 pp(e,t){return e>0&&e<t}var VC=(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 ui(e,t){const n=Nt(e),r=y.useRef(0);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),y.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Br(e,t){const n=Nt(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 mp=rp,KC=sp,qC=up;const gp=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(mp,{ref:r,className:ee("relative overflow-hidden",e),...n,children:[d.jsx(KC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),d.jsx(xp,{}),d.jsx(qC,{})]}));gp.displayName=mp.displayName;const xp=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>d.jsx(xl,{ref:r,orientation:t,className:ee("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:d.jsx(cp,{className:"relative flex-1 rounded-full bg-border"})}));xp.displayName=xl.displayName;function wl({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:u}){const{threads:f,currentThreadId:h,isLoading:p,actions:m}=Qo(),{loadThread:x}=es(),{createThread:v,deleteThread:g,renameThread:w}=m,[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,$]=b.useState(""),[q,P]=b.useState(!1);b.useEffect(()=>{const H=Array.isArray(f)?f:[];if(H.length>0){k.current=!0,T(H);return}p||(k.current=!1,T(H))},[f,p]),b.useEffect(()=>{if(!C.current)return;const H=C.current.querySelector("[data-radix-scroll-area-viewport]");if(!H)return;let Z=null,we=null;return Z=requestAnimationFrame(()=>{we=requestAnimationFrame(()=>{H.scrollTop=E.current})}),()=>{Z!==null&&cancelAnimationFrame(Z),we!==null&&cancelAnimationFrame(we)}},[S]);const R=async H=>{try{await x(H),a==null||a(H),l==null||l(H)}catch(Z){console.error("Failed to select thread:",Z)}},L=async()=>{try{P(!0);const H=await v();c==null||c(H),a==null||a(H)}catch(H){console.error("Failed to create thread:",H)}finally{P(!1)}},F=async(H,Z)=>{if(Z.stopPropagation(),!!confirm("Delete this thread?")){if(C.current){const we=C.current.querySelector("[data-radix-scroll-area-viewport]");we&&(E.current=we.scrollTop)}try{await g(H),u==null||u(H)}catch(we){console.error("Failed to delete thread:",we)}}},ne=(H,Z)=>{Z.stopPropagation(),j(H.threadId),$(H.title||`Thread ${H.threadId.slice(0,8)}`)},K=async H=>{if(D.trim())try{await w(H,D.trim()),j(null),$("")}catch(Z){console.error("Failed to update title:",Z)}},B=()=>{j(null),$("")},pe=(H,Z)=>{H.key==="Enter"?K(Z):H.key==="Escape"&&B()},W=H=>{if(!H)return"";try{const Z=new Date(H),ye=new Date().getTime()-Z.getTime(),G=Math.floor(ye/(1e3*60*60*24));return G===0?Z.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):G===1?"Yesterday":G<7?`${G} days ago`:Z.toLocaleDateString()}catch{return""}},ce=H=>H.title||`Thread ${H.threadId.slice(0,8)}`;return d.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&d.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:d.jsx(Ze,{onClick:L,disabled:q||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:q?"Creating...":"New Chat",children:d.jsx(fe.MessageSquarePlus,{size:20})})}),d.jsx(gp,{ref:C,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:d.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?d.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[d.jsx(fe.Loader2,{className:"h-5 w-5 animate-spin"}),d.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?d.jsxs("div",{className:"text-center py-8 text-slate-400",children:[d.jsx(fe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),d.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((H,Z)=>new Date(Z.updatedAt||Z.createdAt||"").getTime()-new Date(H.updatedAt||H.createdAt||"").getTime()).map(H=>d.jsxs("div",{onClick:()=>R(H.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===H.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:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("div",{className:"flex-1 min-w-0",children:_===H.threadId?d.jsxs("div",{className:"flex items-center gap-2",onClick:Z=>Z.stopPropagation(),children:[d.jsx(ii,{value:D,onChange:Z=>$(Z.target.value),onKeyDown:Z=>pe(Z,H.threadId),className:"h-6 text-sm",autoFocus:!0}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>K(H.threadId),className:"h-6 w-6 p-0",children:d.jsx(fe.Check,{size:12})}),d.jsx(Ze,{variant:"ghost",size:"sm",onClick:B,className:"h-6 w-6 p-0",children:d.jsx(fe.X,{size:12})})]}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:ce(H)}),d.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[d.jsx(fe.Calendar,{size:10}),d.jsx("span",{children:W(H.updatedAt||H.createdAt)})]})]})}),d.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==H.threadId&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Z=>ne(H,Z),className:"h-6 w-6 p-0",title:"Edit title",children:d.jsx(fe.Edit3,{size:12})}),n&&d.jsx(Ze,{variant:"ghost",size:"sm",onClick:Z=>F(H.threadId,Z),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:d.jsx(fe.Trash2,{size:12})})]})]}),i===H.threadId&&d.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},H.threadId))})})]})}function Hr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function GC(e){if(typeof e!="string")return;const t=e.trim();if(t)return $n(t)}function yp(){const e=[Hr("__API_BASE_URL__"),Hr("__CHAT_API_BASE_URL__"),Hr("__CHAT_API_URL__")];for(const t of e){const n=GC(t);if(n)return n}}function vp(){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 wp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return $n(t);return $n()}function bp(){const e={},t=yp(),n=vp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Sp(){const e=bp(),t=Wn.getAuthToken(),n=yp();return{apiBaseUrl:wp(e.baseUrl,Wn.baseUrl,n),apiKey:t||e.apiKey||vp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Cp="chat-settings";function YC(){try{const e=localStorage.getItem(Cp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function XC(e){try{const t={...e,apiBaseUrl:$n(e.apiBaseUrl)};localStorage.setItem(Cp,JSON.stringify(t)),t.apiKey&&Wn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function JC(){const e=Sp(),t=YC(),n=Wn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:wp(Wn.baseUrl,r,e.apiBaseUrl)}}function ZC(e){Wn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),XC(e)}var QC="Label",kp=y.forwardRef((e,t)=>d.jsx(Ie.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())}}));kp.displayName=QC;var Tp=kp;const ek=Oo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),on=y.forwardRef(({className:e,...t},n)=>d.jsx(Tp,{ref:n,className:ee(ek(),e),...t}));on.displayName=Tp.displayName;function Ep(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var di="Switch",[tk,TT]=Tn(di),[nk,rk]=tk(di),Ip=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:u,...f}=e,[h,p]=y.useState(null),m=He(t,S=>p(S)),x=y.useRef(!1),v=h?u||!!h.closest("form"):!0,[g,w]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:di});return d.jsxs(nk,{scope:n,checked:g,disabled:a,children:[d.jsx(Ie.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":jp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ge(e.onClick,S=>{w(T=>!T),v&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),v&&d.jsx(_p,{control:h,bubbles:!x.current,name:r,value:l,checked:g,required:i,disabled:a,form:u,style:{transform:"translateX(-100%)"}})]})});Ip.displayName=di;var Np="SwitchThumb",Ap=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rk(Np,n);return d.jsx(Ie.span,{"data-state":jp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Ap.displayName=Np;var ok="SwitchBubbleInput",_p=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=y.useRef(null),a=He(i,s),l=Ep(n),c=zf(t);return y.useEffect(()=>{const u=i.current;if(!u)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const m=new Event("click",{bubbles:r});p.call(u,n),u.dispatchEvent(m)}},[l,n,r]),d.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}})});_p.displayName=ok;function jp(e){return e?"checked":"unchecked"}var Rp=Ip,sk=Ap;const er=y.forwardRef(({className:e,...t},n)=>d.jsx(Rp,{className:ee("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:d.jsx(sk,{className:ee("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=Rp.displayName;var Pp=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"}),ik="VisuallyHidden",ak=y.forwardRef((e,t)=>d.jsx(Ie.span,{...e,ref:t,style:{...Pp,...e.style}}));ak.displayName=ik;var lk=[" ","Enter","ArrowUp","ArrowDown"],ck=[" ","Enter"],br="Select",[fi,hi,uk]=Wa(br),[Ur,ET]=Tn(br,[uk,Qs]),pi=Qs(),[dk,tr]=Ur(br),[fk,hk]=Ur(br),Op=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:u,autoComplete:f,disabled:h,required:p,form:m}=e,x=pi(t),[v,g]=y.useState(null),[w,S]=y.useState(null),[T,k]=y.useState(!1),C=Hs(c),[E,_]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:br}),[j,D]=pr({prop:i,defaultProp:a,onChange:l,caller:br}),$=y.useRef(null),q=v?m||!!v.closest("form"):!0,[P,R]=y.useState(new Set),L=Array.from(P).map(F=>F.props.value).join(";");return d.jsx(Xf,{...x,children:d.jsxs(dk,{required:p,scope:t,trigger:v,onTriggerChange:g,valueNode:w,onValueNodeChange:S,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:En(),value:j,onValueChange:D,open:E,onOpenChange:_,dir:C,triggerPointerDownPosRef:$,disabled:h,children:[d.jsx(fi.Provider,{scope:t,children:d.jsx(fk,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(F=>{R(ne=>new Set(ne).add(F))},[]),onNativeOptionRemove:y.useCallback(F=>{R(ne=>{const K=new Set(ne);return K.delete(F),K})},[]),children:n})}),q?d.jsxs(om,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:f,value:j,onChange:F=>D(F.target.value),disabled:h,form:m,children:[j===void 0?d.jsx("option",{value:""}):null,Array.from(P)]},L):null]})})};Op.displayName=br;var Mp="SelectTrigger",Dp=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=pi(n),i=tr(Mp,n),a=i.disabled||r,l=He(t,i.onTriggerChange),c=hi(n),u=y.useRef("touch"),[f,h,p]=im(x=>{const v=c().filter(S=>!S.disabled),g=v.find(S=>S.value===i.value),w=am(v,x,g);w!==void 0&&i.onValueChange(w.value)}),m=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return d.jsx(Jf,{asChild:!0,...s,children:d.jsx(Ie.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":sm(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,x=>{x.currentTarget.focus(),u.current!=="mouse"&&m(x)}),onPointerDown:ge(o.onPointerDown,x=>{u.current=x.pointerType;const v=x.target;v.hasPointerCapture(x.pointerId)&&v.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(m(x),x.preventDefault())}),onKeyDown:ge(o.onKeyDown,x=>{const v=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(v&&x.key===" ")&&lk.includes(x.key)&&(m(),x.preventDefault())})})})});Dp.displayName=Mp;var Lp="SelectValue",Fp=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=tr(Lp,n),{onValueNodeHasChildrenChange:c}=l,u=s!==void 0,f=He(t,l.onValueNodeChange);return kt(()=>{c(u)},[c,u]),d.jsx(Ie.span,{...a,ref:f,style:{pointerEvents:"none"},children:sm(l.value)?d.jsx(d.Fragment,{children:i}):s})});Fp.displayName=Lp;var pk="SelectIcon",$p=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return d.jsx(Ie.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});$p.displayName=pk;var mk="SelectPortal",zp=e=>d.jsx(Ss,{asChild:!0,...e});zp.displayName=mk;var Sr="SelectContent",Bp=y.forwardRef((e,t)=>{const n=tr(Sr,e.__scopeSelect),[r,o]=y.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Mo.createPortal(d.jsx(Hp,{scope:e.__scopeSelect,children:d.jsx(fi.Slot,{scope:e.__scopeSelect,children:d.jsx("div",{children:e.children})})}),s):null}return d.jsx(Up,{...e,ref:t})});Bp.displayName=Sr;var gn=10,[Hp,nr]=Ur(Sr),gk="SelectContentImpl",xk=sr.createSlot("SelectContent.RemoveScroll"),Up=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:x,avoidCollisions:v,...g}=e,w=tr(Sr,n),[S,T]=y.useState(null),[k,C]=y.useState(null),E=He(t,G=>T(G)),[_,j]=y.useState(null),[D,$]=y.useState(null),q=hi(n),[P,R]=y.useState(!1),L=y.useRef(!1);y.useEffect(()=>{if(S)return Da(S)},[S]),_a();const F=y.useCallback(G=>{const[M,...X]=q().map(se=>se.ref.current),[oe]=X.slice(-1),xe=document.activeElement;for(const se of G)if(se===xe||(se==null||se.scrollIntoView({block:"nearest"}),se===M&&k&&(k.scrollTop=0),se===oe&&k&&(k.scrollTop=k.scrollHeight),se==null||se.focus(),document.activeElement!==xe))return},[q,k]),ne=y.useCallback(()=>F([_,S]),[F,_,S]);y.useEffect(()=>{P&&ne()},[P,ne]);const{onOpenChange:K,triggerPointerDownPosRef:B}=w;y.useEffect(()=>{if(S){let G={x:0,y:0};const M=oe=>{var xe,se;G={x:Math.abs(Math.round(oe.pageX)-(((xe=B.current)==null?void 0:xe.x)??0)),y:Math.abs(Math.round(oe.pageY)-(((se=B.current)==null?void 0:se.y)??0))}},X=oe=>{G.x<=10&&G.y<=10?oe.preventDefault():S.contains(oe.target)||K(!1),document.removeEventListener("pointermove",M),B.current=null};return B.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,K,B]),y.useEffect(()=>{const G=()=>K(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[K]);const[pe,W]=im(G=>{const M=q().filter(xe=>!xe.disabled),X=M.find(xe=>xe.ref.current===document.activeElement),oe=am(M,G,X);oe&&setTimeout(()=>oe.ref.current.focus())}),ce=y.useCallback((G,M,X)=>{const oe=!L.current&&!X;(w.value!==void 0&&w.value===M||oe)&&(j(G),oe&&(L.current=!0))},[w.value]),H=y.useCallback(()=>S==null?void 0:S.focus(),[S]),Z=y.useCallback((G,M,X)=>{const oe=!L.current&&!X;(w.value!==void 0&&w.value===M||oe)&&$(G)},[w.value]),we=r==="popper"?bl:Wp,ye=we===bl?{side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:x,avoidCollisions:v}:{};return d.jsx(Hp,{scope:n,content:S,viewport:k,onViewportChange:C,itemRefCallback:ce,selectedItem:_,onItemLeave:H,itemTextRefCallback:Z,focusSelectedItem:ne,selectedItemText:D,position:r,isPositioned:P,searchRef:pe,children:d.jsx(Ns,{as:xk,allowPinchZoom:!0,children:d.jsx(bs,{asChild:!0,trapped:w.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:ge(o,G=>{var M;(M=w.trigger)==null||M.focus({preventScroll:!0}),G.preventDefault()}),children:d.jsx(ws,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:d.jsx(we,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:G=>G.preventDefault(),...g,...ye,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:ge(g.onKeyDown,G=>{const M=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!M&&G.key.length===1&&W(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let oe=q().filter(xe=>!xe.disabled).map(xe=>xe.ref.current);if(["ArrowUp","End"].includes(G.key)&&(oe=oe.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const xe=G.target,se=oe.indexOf(xe);oe=oe.slice(se+1)}setTimeout(()=>F(oe)),G.preventDefault()}})})})})})})});Up.displayName=gk;var yk="SelectItemAlignedPosition",Wp=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=tr(Sr,n),i=nr(Sr,n),[a,l]=y.useState(null),[c,u]=y.useState(null),f=He(t,E=>u(E)),h=hi(n),p=y.useRef(!1),m=y.useRef(!0),{viewport:x,selectedItem:v,selectedItemText:g,focusSelectedItem:w}=i,S=y.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&v&&g){const E=s.trigger.getBoundingClientRect(),_=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),D=g.getBoundingClientRect();if(s.dir!=="rtl"){const xe=D.left-_.left,se=j.left-xe,re=E.left-se,Ue=E.width+re,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,at=ml(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.left=at+"px"}else{const xe=_.right-D.right,se=window.innerWidth-j.right-xe,re=window.innerWidth-E.right-se,Ue=E.width+re,Ke=Math.max(Ue,_.width),ot=window.innerWidth-gn,at=ml(se,[gn,Math.max(gn,ot-Ke)]);a.style.minWidth=Ue+"px",a.style.right=at+"px"}const $=h(),q=window.innerHeight-gn*2,P=x.scrollHeight,R=window.getComputedStyle(c),L=parseInt(R.borderTopWidth,10),F=parseInt(R.paddingTop,10),ne=parseInt(R.borderBottomWidth,10),K=parseInt(R.paddingBottom,10),B=L+F+P+K+ne,pe=Math.min(v.offsetHeight*5,B),W=window.getComputedStyle(x),ce=parseInt(W.paddingTop,10),H=parseInt(W.paddingBottom,10),Z=E.top+E.height/2-gn,we=q-Z,ye=v.offsetHeight/2,G=v.offsetTop+ye,M=L+F+G,X=B-M;if(M<=Z){const xe=$.length>0&&v===$[$.length-1].ref.current;a.style.bottom="0px";const se=c.clientHeight-x.offsetTop-x.offsetHeight,re=Math.max(we,ye+(xe?H:0)+se+ne),Ue=M+re;a.style.height=Ue+"px"}else{const xe=$.length>0&&v===$[0].ref.current;a.style.top="0px";const re=Math.max(Z,L+x.offsetTop+(xe?ce:0)+ye)+X;a.style.height=re+"px",x.scrollTop=M-Z+x.offsetTop}a.style.margin=`${gn}px 0`,a.style.minHeight=pe+"px",a.style.maxHeight=q+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,x,v,g,s.dir,r]);kt(()=>S(),[S]);const[T,k]=y.useState();kt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const C=y.useCallback(E=>{E&&m.current===!0&&(S(),w==null||w(),m.current=!1)},[S,w]);return d.jsx(wk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:d.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:d.jsx(Ie.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Wp.displayName=yk;var vk="SelectPopperPosition",bl=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=gn,...s}=e,i=pi(n);return d.jsx(Zf,{...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)"}})});bl.displayName=vk;var[wk,Sl]=Ur(Sr,{}),Cl="SelectViewport",Vp=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=nr(Cl,n),i=Sl(Cl,n),a=He(t,s.onViewportChange),l=y.useRef(0);return d.jsxs(d.Fragment,{children:[d.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}),d.jsx(fi.Slot,{scope:n,children:d.jsx(Ie.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 u=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-u.scrollTop);if(p>0){const m=window.innerHeight-gn*2,x=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),g=Math.max(x,v);if(g<m){const w=g+p,S=Math.min(m,w),T=w-S;f.style.height=S+"px",f.style.bottom==="0px"&&(u.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=u.scrollTop})})})]})});Vp.displayName=Cl;var Kp="SelectGroup",[bk,Sk]=Ur(Kp),Ck=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=En();return d.jsx(bk,{scope:n,id:o,children:d.jsx(Ie.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Ck.displayName=Kp;var qp="SelectLabel",Gp=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sk(qp,n);return d.jsx(Ie.div,{id:o.id,...r,ref:t})});Gp.displayName=qp;var mi="SelectItem",[kk,Yp]=Ur(mi),Xp=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=tr(mi,n),l=nr(mi,n),c=a.value===r,[u,f]=y.useState(s??""),[h,p]=y.useState(!1),m=He(t,w=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,w,r,o)}),x=En(),v=y.useRef("touch"),g=()=>{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 d.jsx(kk,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:y.useCallback(w=>{f(S=>S||((w==null?void 0:w.textContent)??"").trim())},[]),children:d.jsx(fi.ItemSlot,{scope:n,value:r,disabled:o,textValue:u,children:d.jsx(Ie.div,{role:"option","aria-labelledby":x,"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:m,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{v.current!=="mouse"&&g()}),onPointerUp:ge(i.onPointerUp,()=>{v.current==="mouse"&&g()}),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===" "||(ck.includes(w.key)&&g(),w.key===" "&&w.preventDefault())})})})})});Xp.displayName=mi;var Ao="SelectItemText",Jp=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=tr(Ao,n),a=nr(Ao,n),l=Yp(Ao,n),c=hk(Ao,n),[u,f]=y.useState(null),h=He(t,g=>f(g),l.onItemTextChange,g=>{var w;return(w=a.itemTextRefCallback)==null?void 0:w.call(a,g,l.value,l.disabled)}),p=u==null?void 0:u.textContent,m=y.useMemo(()=>d.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:v}=c;return kt(()=>(x(m),()=>v(m)),[x,v,m]),d.jsxs(d.Fragment,{children:[d.jsx(Ie.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Mo.createPortal(s.children,i.valueNode):null]})});Jp.displayName=Ao;var Zp="SelectItemIndicator",Qp=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Yp(Zp,n).isSelected?d.jsx(Ie.span,{"aria-hidden":!0,...r,ref:t}):null});Qp.displayName=Zp;var kl="SelectScrollUpButton",em=y.forwardRef((e,t)=>{const n=nr(kl,e.__scopeSelect),r=Sl(kl,e.__scopeSelect),[o,s]=y.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?d.jsx(nm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});em.displayName=kl;var Tl="SelectScrollDownButton",tm=y.forwardRef((e,t)=>{const n=nr(Tl,e.__scopeSelect),r=Sl(Tl,e.__scopeSelect),[o,s]=y.useState(!1),i=He(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,u=Math.ceil(l.scrollTop)<c;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?d.jsx(nm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});tm.displayName=Tl;var nm=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=nr("SelectScrollButton",n),i=y.useRef(null),a=hi(n),l=y.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return y.useEffect(()=>()=>l(),[l]),kt(()=>{var u;const c=a().find(f=>f.ref.current===document.activeElement);(u=c==null?void 0:c.ref.current)==null||u.scrollIntoView({block:"nearest"})},[a]),d.jsx(Ie.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()})})}),Tk="SelectSeparator",rm=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return d.jsx(Ie.div,{"aria-hidden":!0,...r,ref:t})});rm.displayName=Tk;var El="SelectArrow",Ek=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=pi(n),s=tr(El,n),i=nr(El,n);return s.open&&i.position==="popper"?d.jsx(Qf,{...o,...r,ref:t}):null});Ek.displayName=El;var Ik="SelectBubbleInput",om=y.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=y.useRef(null),s=He(r,o),i=Ep(t);return y.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,u=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&u){const f=new Event("change",{bubbles:!0});u.call(a,t),a.dispatchEvent(f)}},[i,t]),d.jsx(Ie.select,{...n,style:{...Pp,...n.style},ref:s,defaultValue:t})});om.displayName=Ik;function sm(e){return e===""||e===void 0}function im(e){const t=Nt(e),n=y.useRef(""),r=y.useRef(0),o=y.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=y.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function am(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=Nk(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 Nk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ak=Op,lm=Dp,_k=Fp,jk=$p,Rk=zp,cm=Bp,Pk=Vp,um=Gp,dm=Xp,Ok=Jp,Mk=Qp,fm=em,hm=tm,pm=rm;const mm=Ak,gm=_k,Il=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(lm,{ref:r,className:ee("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,d.jsx(jk,{asChild:!0,children:d.jsx(fe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Il.displayName=lm.displayName;const xm=y.forwardRef(({className:e,...t},n)=>d.jsx(fm,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:d.jsx(fe.ChevronUp,{className:"h-4 w-4"})}));xm.displayName=fm.displayName;const ym=y.forwardRef(({className:e,...t},n)=>d.jsx(hm,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:d.jsx(fe.ChevronDown,{className:"h-4 w-4"})}));ym.displayName=hm.displayName;const Nl=y.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>d.jsx(Rk,{children:d.jsxs(cm,{ref:o,className:ee("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:[d.jsx(xm,{}),d.jsx(Pk,{className:ee("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),d.jsx(ym,{})]})}));Nl.displayName=cm.displayName;const Dk=y.forwardRef(({className:e,...t},n)=>d.jsx(um,{ref:n,className:ee("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Dk.displayName=um.displayName;const Cr=y.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(dm,{ref:r,className:ee("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:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(Mk,{children:d.jsx(fe.Check,{className:"h-4 w-4"})})}),d.jsx(Ok,{children:t})]}));Cr.displayName=dm.displayName;const Lk=y.forwardRef(({className:e,...t},n)=>d.jsx(pm,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));Lk.displayName=pm.displayName;var Fk="Separator",vm="horizontal",$k=["horizontal","vertical"],wm=y.forwardRef((e,t)=>{const{decorative:n,orientation:r=vm,...o}=e,s=zk(r)?r:vm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return d.jsx(Ie.div,{"data-orientation":s,...a,...o,ref:t})});wm.displayName=Fk;function zk(e){return $k.includes(e)}var bm=wm;const Sm=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>d.jsx(bm,{ref:o,decorative:n,orientation:t,className:ee("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Sm.displayName=bm.displayName;const Bk=Kd,Hk=ab,Uk=qd,Cm=y.forwardRef(({className:e,...t},n)=>d.jsx(Ps,{className:ee("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}));Cm.displayName=Ps.displayName;const Wk=Oo.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"}}),km=y.forwardRef(({side:e="right",className:t,children:n,...r},o)=>d.jsxs(Uk,{children:[d.jsx(Cm,{}),d.jsxs(Os,{ref:o,className:ee(Wk({side:e}),t),...r,children:[n,d.jsxs(Gd,{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:[d.jsx(fe.X,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));km.displayName=Os.displayName;const Tm=({className:e,...t})=>d.jsx("div",{className:ee("flex flex-col space-y-2 text-center sm:text-left",e),...t});Tm.displayName="SheetHeader";const Em=y.forwardRef(({className:e,...t},n)=>d.jsx(gr,{ref:n,className:ee("text-lg font-semibold text-foreground",e),...t}));Em.displayName=gr.displayName;const Im=y.forwardRef(({className:e,...t},n)=>d.jsx(Ms,{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));Im.displayName=Ms.displayName;const Vk={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 Kk({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(e),[c,u]=b.useState(!1),{toast:f}=ka();b.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);u(v)},[a,e]),b.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),u(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(Vk),u(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),u(!1),o(!1)},x=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return d.jsxs(Bk,{open:r,onOpenChange:o,children:[d.jsx(Hk,{asChild:!0,children:d.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[d.jsx(fe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&d.jsx(Yu,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),d.jsxs(km,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[d.jsxs(Tm,{children:[d.jsx(Em,{children:"Chat Settings"}),d.jsx(Im,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),d.jsxs("div",{className:"space-y-6 py-6",children:[d.jsxs(fo,{children:[d.jsx(ho,{className:"pb-3",children:d.jsxs(po,{className:"text-lg flex items-center gap-2",children:[d.jsx(fe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),d.jsxs(mo,{className:"space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"api-url",children:"API Base URL"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(ii,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(g=>({...g,api:{...g.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),d.jsx(Ze,{variant:"outline",onClick:x,children:"Test"})]})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"enable-auth",children:"Enable Authentication"}),d.jsx(er,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(g=>({...g,api:{...g.api,enableAuth:v}}))})]}),a.api.enableAuth&&d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"auth-token",children:"Authentication Token"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(ii,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(g=>({...g,api:{...g.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),d.jsx(Ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?d.jsx(fe.EyeOff,{className:"h-4 w-4"}):d.jsx(fe.Eye,{className:"h-4 w-4"})})]})]})]})]}),d.jsxs(fo,{children:[d.jsx(ho,{className:"pb-3",children:d.jsxs(po,{className:"text-lg flex items-center gap-2",children:[d.jsx(fe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),d.jsxs(mo,{className:"space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"layout",children:"Layout Style"}),d.jsxs(mm,{value:a.ui.layout,onValueChange:v=>l(g=>({...g,ui:{...g.ui,layout:v}})),children:[d.jsx(Il,{children:d.jsx(gm,{})}),d.jsxs(Nl,{children:[d.jsx(Cr,{value:"sidebar",children:"Sidebar Layout"}),d.jsx(Cr,{value:"fullscreen",children:"Fullscreen"}),d.jsx(Cr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(on,{htmlFor:"theme",children:"Theme"}),d.jsxs(mm,{value:a.ui.theme,onValueChange:v=>l(g=>({...g,ui:{...g.ui,theme:v}})),children:[d.jsx(Il,{children:d.jsx(gm,{})}),d.jsxs(Nl,{children:[d.jsx(Cr,{value:"light",children:"Light"}),d.jsx(Cr,{value:"dark",children:"Dark"}),d.jsx(Cr,{value:"system",children:"System"})]})]})]}),d.jsx(Sm,{}),d.jsxs("div",{className:"space-y-3",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"show-timestamps",children:"Show Timestamps"}),d.jsx(er,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showTimestamps:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"show-agent-names",children:"Show Agent Names"}),d.jsx(er,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showAgentNames:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx(on,{htmlFor:"compact-messages",children:"Compact Messages"}),d.jsx(er,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,compactMessages:v}}))})]})]})]})]}),d.jsxs(fo,{children:[d.jsx(ho,{className:"pb-3",children:d.jsxs(po,{className:"text-lg flex items-center gap-2",children:[d.jsx(fe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),d.jsxs(mo,{className:"space-y-4",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(on,{htmlFor:"auto-save",children:"Auto-save Conversations"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),d.jsx(er,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,autoSave:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(on,{htmlFor:"enable-streaming",children:"Enable Streaming"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),d.jsx(er,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:v}}))})]}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{children:[d.jsx(on,{htmlFor:"typing-indicator",children:"Typing Indicator"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),d.jsx(er,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:v}}))})]})]})]})]}),d.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[d.jsxs(Ze,{variant:"outline",onClick:p,children:[d.jsx(fe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Ze,{variant:"outline",onClick:m,children:"Cancel"}),d.jsxs(Ze,{onClick:h,disabled:!c,children:[d.jsx(fe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function qk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const u="h-full";switch(c){case"phone":return`${u} max-w-none`;case"tablet":return`${u} max-w-4xl mx-auto`;case"half-screen":return`${u} max-w-2xl`;case"desktop":default:return`${u} 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 u;(u=s.onThreadChange)==null||u.call(s,c)},[s]);return e==="fullscreen"?d.jsx(ts,{...s,onThreadChange:l,children:d.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:d.jsx(si,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?d.jsx(ts,{...s,onThreadChange:l,children:d.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:d.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&d.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(wl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(si,{onError:s.onError,enableFileUpload:!0})})]})})}):d.jsx(ts,{...s,onThreadChange:l,children:d.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&d.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(wl,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(si,{onError:s.onError,enableFileUpload:!0})})]})})}Ne.ChatApi=Tc,Ne.ChatInterface=si,Ne.ChatProviders=ts,Ne.ChatSettings=Kk,Ne.MarkdownContent=vo,Ne.MessageComponent=Ha,Ne.MessageList=Ua,Ne.ThreadManager=wl,Ne.applySettings=ZC,Ne.chatApiClient=Wn,Ne.default=qk,Ne.del=kc,Ne.get=cn,Ne.getChatToken=bc,Ne.getCurrentSettings=JC,Ne.getDefaultApiConfig=bp,Ne.getDefaultChatSettings=Sp,Ne.onChatTokenChanged=Sc,Ne.post=ji,Ne.put=Cc,Ne.setChatToken=_i,Ne.useApi=Ri,Ne.useChatStream=zc,Ne.useMessagesReducer=Rc,Ne.useStream=Yc,Ne.useThreadState=es,Ne.useThreads=Qo,Object.defineProperties(Ne,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|