teodor-new-chat-ui 4.1.48 → 4.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat/MarkdownContent.d.ts +3 -1
- package/dist/components/langgraph_sdk_pack/components/ChatPageExample.d.ts +6 -0
- package/dist/components/langgraph_sdk_pack/components/LangChainComponent copy.d.ts +7 -0
- package/dist/components/langgraph_sdk_pack/components/LangChainComponent.d.ts +7 -0
- package/dist/components/langgraph_sdk_pack/components/LangChainMessageComponent.d.ts +26 -0
- package/dist/components/langgraph_sdk_pack/components/LangChainMessageList.d.ts +38 -0
- package/dist/components/langgraph_sdk_pack/components/LangGraphThreadManager.d.ts +31 -0
- package/dist/components/langgraph_sdk_pack/hooks/useLangGraphThreadManager.d.ts +57 -0
- package/dist/components/ui/sheet.d.ts +1 -1
- package/dist/hooks/useLangGraphThreadManager.d.ts +57 -0
- package/dist/index.esm.js +33 -8
- package/dist/index.umd.js +21 -21
- package/dist/types/api.d.ts +6 -2
- package/package.json +1 -1
- package/dist/components/chat/TestChatApp.d.ts +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(Ne,S){typeof exports=="object"&&typeof module<"u"?S(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"],S):(Ne=typeof globalThis<"u"?globalThis:Ne||self,S(Ne.NewChatUI={},Ne.React,Ne.LucideReact,Ne.reactSlot,Ne.classVarianceAuthority,Ne.clsx,Ne.tailwindMerge,Ne.ReactDOM))})(this,function(Ne,S,re,Mn,io,zp,Bp,Ls){"use strict";var jC=Object.defineProperty;var _C=(Ne,S,re)=>S in Ne?jC(Ne,S,{enumerable:!0,configurable:!0,writable:!0,value:re}):Ne[S]=re;var Fp=(Ne,S,re)=>_C(Ne,typeof S!="symbol"?S+"":S,re);function
|
|
1
|
+
(function(Ne,S){typeof exports=="object"&&typeof module<"u"?S(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"],S):(Ne=typeof globalThis<"u"?globalThis:Ne||self,S(Ne.NewChatUI={},Ne.React,Ne.LucideReact,Ne.reactSlot,Ne.classVarianceAuthority,Ne.clsx,Ne.tailwindMerge,Ne.ReactDOM))})(this,function(Ne,S,re,Mn,io,zp,Bp,Ls){"use strict";var jC=Object.defineProperty;var _C=(Ne,S,re)=>S in Ne?jC(Ne,S,{enumerable:!0,configurable:!0,writable:!0,value:re}):Ne[S]=re;var Fp=(Ne,S,re)=>_C(Ne,typeof S!="symbol"?S+"":S,re);function qa(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const m=qa(S),ao=qa(Ls);var Fs={exports:{}},Ir={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Ka;function Hp(){if(Ka)return Ir;Ka=1;var e=S,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,u){var d,f={},h=null,p=null;u!==void 0&&(h=""+u),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return Ir.Fragment=n,Ir.jsx=i,Ir.jsxs=i,Ir}var Nr={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Ga;function Up(){return Ga||(Ga=1,process.env.NODE_ENV!=="production"&&function(){var e=S,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function g(b){if(b===null||typeof b!="object")return null;var j=w&&b[w]||b[v];return typeof j=="function"?j:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(b){{for(var j=arguments.length,D=new Array(j>1?j-1:0),U=1;U<j;U++)D[U-1]=arguments[U];C("error",b,D)}}function C(b,j,D){{var U=x.ReactDebugCurrentFrame,G=U.getStackAddendum();G!==""&&(j+="%s",D=D.concat([G]));var ve=D.map(function(me){return String(me)});ve.unshift("Warning: "+j),Function.prototype.apply.call(console[b],console,ve)}}var E=!1,T=!1,k=!1,I=!1,A=!1,_;_=Symbol.for("react.module.reference");function R(b){return!!(typeof b=="string"||typeof b=="function"||b===r||b===s||A||b===o||b===u||b===d||I||b===p||E||T||k||typeof b=="object"&&b!==null&&(b.$$typeof===h||b.$$typeof===f||b.$$typeof===i||b.$$typeof===a||b.$$typeof===l||b.$$typeof===_||b.getModuleId!==void 0))}function L(b,j,D){var U=b.displayName;if(U)return U;var G=j.displayName||j.name||"";return G!==""?D+"("+G+")":D}function F(b){return b.displayName||"Context"}function V(b){if(b==null)return null;if(typeof b.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof b=="function")return b.displayName||b.name||null;if(typeof b=="string")return b;switch(b){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof b=="object")switch(b.$$typeof){case a:var j=b;return F(j)+".Consumer";case i:var D=b;return F(D._context)+".Provider";case l:return L(b,b.render,"ForwardRef");case f:var U=b.displayName||null;return U!==null?U:V(b.type)||"Memo";case h:{var G=b,ve=G._payload,me=G._init;try{return V(me(ve))}catch{return null}}}return null}var O=Object.assign,Y=0,
|
|
18
|
-
`+
|
|
17
|
+
*/var Ga;function Up(){return Ga||(Ga=1,process.env.NODE_ENV!=="production"&&function(){var e=S,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),w=Symbol.iterator,v="@@iterator";function g(b){if(b===null||typeof b!="object")return null;var j=w&&b[w]||b[v];return typeof j=="function"?j:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(b){{for(var j=arguments.length,D=new Array(j>1?j-1:0),U=1;U<j;U++)D[U-1]=arguments[U];C("error",b,D)}}function C(b,j,D){{var U=x.ReactDebugCurrentFrame,G=U.getStackAddendum();G!==""&&(j+="%s",D=D.concat([G]));var ve=D.map(function(me){return String(me)});ve.unshift("Warning: "+j),Function.prototype.apply.call(console[b],console,ve)}}var E=!1,T=!1,k=!1,I=!1,A=!1,_;_=Symbol.for("react.module.reference");function R(b){return!!(typeof b=="string"||typeof b=="function"||b===r||b===s||A||b===o||b===u||b===d||I||b===p||E||T||k||typeof b=="object"&&b!==null&&(b.$$typeof===h||b.$$typeof===f||b.$$typeof===i||b.$$typeof===a||b.$$typeof===l||b.$$typeof===_||b.getModuleId!==void 0))}function L(b,j,D){var U=b.displayName;if(U)return U;var G=j.displayName||j.name||"";return G!==""?D+"("+G+")":D}function F(b){return b.displayName||"Context"}function V(b){if(b==null)return null;if(typeof b.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof b=="function")return b.displayName||b.name||null;if(typeof b=="string")return b;switch(b){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof b=="object")switch(b.$$typeof){case a:var j=b;return F(j)+".Consumer";case i:var D=b;return F(D._context)+".Provider";case l:return L(b,b.render,"ForwardRef");case f:var U=b.displayName||null;return U!==null?U:V(b.type)||"Memo";case h:{var G=b,ve=G._payload,me=G._init;try{return V(me(ve))}catch{return null}}}return null}var O=Object.assign,Y=0,q,X,B,$,z,H,ge;function de(){}de.__reactDisabledLog=!0;function ee(){{if(Y===0){q=console.log,X=console.info,B=console.warn,$=console.error,z=console.group,H=console.groupCollapsed,ge=console.groupEnd;var b={configurable:!0,enumerable:!0,value:de,writable:!0};Object.defineProperties(console,{info:b,log:b,warn:b,error:b,group:b,groupCollapsed:b,groupEnd:b})}Y++}}function je(){{if(Y--,Y===0){var b={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},b,{value:q}),info:O({},b,{value:X}),warn:O({},b,{value:B}),error:O({},b,{value:$}),group:O({},b,{value:z}),groupCollapsed:O({},b,{value:H}),groupEnd:O({},b,{value:ge})})}Y<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Te=x.ReactCurrentDispatcher,K;function M(b,j,D){{if(K===void 0)try{throw Error()}catch(G){var U=G.stack.trim().match(/\n( *(at )?)/);K=U&&U[1]||""}return`
|
|
18
|
+
`+K+b}}var Z=!1,ne;{var Q=typeof WeakMap=="function"?WeakMap:Map;ne=new Q}function le(b,j){if(!b||Z)return"";{var D=ne.get(b);if(D!==void 0)return D}var U;Z=!0;var G=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ve;ve=Te.current,Te.current=null,ee();try{if(j){var me=function(){throw Error()};if(Object.defineProperty(me.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(me,[])}catch(ht){U=ht}Reflect.construct(b,[],me)}else{try{me.call()}catch(ht){U=ht}b.call(me.prototype)}}else{try{throw Error()}catch(ht){U=ht}b()}}catch(ht){if(ht&&U&&typeof ht.stack=="string"){for(var he=ht.stack.split(`
|
|
19
19
|
`),He=U.stack.split(`
|
|
20
20
|
`),Ge=he.length-1,Xe=He.length-1;Ge>=1&&Xe>=0&&he[Ge]!==He[Xe];)Xe--;for(;Ge>=1&&Xe>=0;Ge--,Xe--)if(he[Ge]!==He[Xe]){if(Ge!==1||Xe!==1)do if(Ge--,Xe--,Xe<0||he[Ge]!==He[Xe]){var dt=`
|
|
21
|
-
`+he[Ge].replace(" at new "," at ");return b.displayName&&dt.includes("<anonymous>")&&(dt=dt.replace("<anonymous>",b.displayName)),typeof b=="function"&&ne.set(b,dt),dt}while(Ge>=1&&Xe>=0);break}}}finally{Z=!1,Te.current=ve,je(),Error.prepareStackTrace=G}var yt=b?b.displayName||b.name:"",fn=yt?M(yt):"";return typeof b=="function"&&ne.set(b,fn),fn}function Be(b,j,D){return le(b,!1)}function Ye(b){var j=b.prototype;return!!(j&&j.isReactComponent)}function
|
|
21
|
+
`+he[Ge].replace(" at new "," at ");return b.displayName&&dt.includes("<anonymous>")&&(dt=dt.replace("<anonymous>",b.displayName)),typeof b=="function"&&ne.set(b,dt),dt}while(Ge>=1&&Xe>=0);break}}}finally{Z=!1,Te.current=ve,je(),Error.prepareStackTrace=G}var yt=b?b.displayName||b.name:"",fn=yt?M(yt):"";return typeof b=="function"&&ne.set(b,fn),fn}function Be(b,j,D){return le(b,!1)}function Ye(b){var j=b.prototype;return!!(j&&j.isReactComponent)}function Ke(b,j,D){if(b==null)return"";if(typeof b=="function")return le(b,Ye(b));if(typeof b=="string")return M(b);switch(b){case u:return M("Suspense");case d:return M("SuspenseList")}if(typeof b=="object")switch(b.$$typeof){case l:return Be(b.render);case f:return Ke(b.type,j,D);case h:{var U=b,G=U._payload,ve=U._init;try{return Ke(ve(G),j,D)}catch{}}}return""}var Ce=Object.prototype.hasOwnProperty,_e={},Qe=x.ReactDebugCurrentFrame;function Ue(b){if(b){var j=b._owner,D=Ke(b.type,b._source,j?j.type:null);Qe.setExtraStackFrame(D)}else Qe.setExtraStackFrame(null)}function ot(b,j,D,U,G){{var ve=Function.call.bind(Ce);for(var me in b)if(ve(b,me)){var he=void 0;try{if(typeof b[me]!="function"){var He=Error((U||"React class")+": "+D+" type `"+me+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof b[me]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw He.name="Invariant Violation",He}he=b[me](j,me,U,D,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Ge){he=Ge}he&&!(he instanceof Error)&&(Ue(G),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",U||"React class",D,me,typeof he),Ue(null)),he instanceof Error&&!(he.message in _e)&&(_e[he.message]=!0,Ue(G),y("Failed %s type: %s",D,he.message),Ue(null))}}}var lt=Array.isArray;function ie(b){return lt(b)}function ue(b){{var j=typeof Symbol=="function"&&Symbol.toStringTag,D=j&&b[Symbol.toStringTag]||b.constructor.name||"Object";return D}}function we(b){try{return pe(b),!1}catch{return!0}}function pe(b){return""+b}function xe(b){if(we(b))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ue(b)),pe(b)}var Re=x.ReactCurrentOwner,Me={key:!0,ref:!0,__self:!0,__source:!0},Pe,st;function mt(b){if(Ce.call(b,"ref")){var j=Object.getOwnPropertyDescriptor(b,"ref").get;if(j&&j.isReactWarning)return!1}return b.ref!==void 0}function cn(b){if(Ce.call(b,"key")){var j=Object.getOwnPropertyDescriptor(b,"key").get;if(j&&j.isReactWarning)return!1}return b.key!==void 0}function un(b,j){typeof b.ref=="string"&&Re.current}function dn(b,j){{var D=function(){Pe||(Pe=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",j))};D.isReactWarning=!0,Object.defineProperty(b,"key",{get:D,configurable:!0})}}function Rn(b,j){{var D=function(){st||(st=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",j))};D.isReactWarning=!0,Object.defineProperty(b,"ref",{get:D,configurable:!0})}}var er=function(b,j,D,U,G,ve,me){var he={$$typeof:t,type:b,key:j,ref:D,props:me,_owner:ve};return he._store={},Object.defineProperty(he._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(he,"_self",{configurable:!1,enumerable:!1,writable:!1,value:U}),Object.defineProperty(he,"_source",{configurable:!1,enumerable:!1,writable:!1,value:G}),Object.freeze&&(Object.freeze(he.props),Object.freeze(he)),he};function yr(b,j,D,U,G){{var ve,me={},he=null,He=null;D!==void 0&&(xe(D),he=""+D),cn(j)&&(xe(j.key),he=""+j.key),mt(j)&&(He=j.ref,un(j,G));for(ve in j)Ce.call(j,ve)&&!Me.hasOwnProperty(ve)&&(me[ve]=j[ve]);if(b&&b.defaultProps){var Ge=b.defaultProps;for(ve in Ge)me[ve]===void 0&&(me[ve]=Ge[ve])}if(he||He){var Xe=typeof b=="function"?b.displayName||b.name||"Unknown":b;he&&dn(me,Xe),He&&Rn(me,Xe)}return er(b,he,He,G,U,Re.current,me)}}var Pn=x.ReactCurrentOwner,xn=x.ReactDebugCurrentFrame;function Yt(b){if(b){var j=b._owner,D=Ke(b.type,b._source,j?j.type:null);xn.setExtraStackFrame(D)}else xn.setExtraStackFrame(null)}var vn;vn=!1;function On(b){return typeof b=="object"&&b!==null&&b.$$typeof===t}function tr(){{if(Pn.current){var b=V(Pn.current.type);if(b)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+b+"`."}return""}}function Sr(b){return""}var It={};function Cr(b){{var j=tr();if(!j){var D=typeof b=="string"?b:b.displayName||b.name;D&&(j=`
|
|
24
24
|
|
|
@@ -27,16 +27,16 @@ Check the top-level render call using <`+D+">.")}return j}}function oe(b,j){{if(
|
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Er,fn,Va,fn),bt[fn+Er]=!0}}return b===r?et(Xe):Fe(Xe),Xe}}function nr(b,j,D){return Mt(b,j,D,!0)}function Tr(b,j,D){return Mt(b,j,D,!1)}var kr=Tr,N=nr;Nr.Fragment=r,Nr.jsx=kr,Nr.jsxs=N}()),Nr}process.env.NODE_ENV==="production"?Fs.exports=Hp():Fs.exports=Up();var c=Fs.exports;function Ya(e,t){return function(){return e.apply(t,arguments)}}const{toString:Wp}=Object.prototype,{getPrototypeOf:$s}=Object,{iterator:lo,toStringTag:Xa}=Symbol,co=(e=>t=>{const n=Wp.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Ht=e=>(e=e.toLowerCase(),t=>co(t)===e),uo=e=>t=>typeof t===e,{isArray:rr}=Array,or=uo("undefined");function Ar(e){return e!==null&&!or(e)&&e.constructor!==null&&!or(e.constructor)&&Tt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ja=Ht("ArrayBuffer");function Vp(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ja(e.buffer),t}const Kp=uo("string"),Tt=uo("function"),Za=uo("number"),jr=e=>e!==null&&typeof e=="object",qp=e=>e===!0||e===!1,fo=e=>{if(co(e)!=="object")return!1;const t=$s(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xa in e)&&!(lo in e)},Gp=e=>{if(!jr(e)||Ar(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Yp=Ht("Date"),Xp=Ht("File"),Jp=Ht("Blob"),Zp=Ht("FileList"),Qp=e=>jr(e)&&Tt(e.pipe),em=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Tt(e.append)&&((t=co(e))==="formdata"||t==="object"&&Tt(e.toString)&&e.toString()==="[object FormData]"))},tm=Ht("URLSearchParams"),[nm,rm,om,sm]=["ReadableStream","Request","Response","Headers"].map(Ht),im=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function _r(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),rr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Ar(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 Qa(e,t){if(Ar(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 Dn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,el=e=>!or(e)&&e!==Dn;function zs(){const{caseless:e,skipUndefined:t}=el(this)&&this||{},n={},r=(o,s)=>{const i=e&&Qa(n,s)||s;fo(n[i])&&fo(o)?n[i]=zs(n[i],o):fo(o)?n[i]=zs({},o):rr(o)?n[i]=o.slice():(!t||!or(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&_r(arguments[o],r);return n}const am=(e,t,n,{allOwnKeys:r}={})=>(_r(t,(o,s)=>{n&&Tt(o)?e[s]=Ya(o,n):e[s]=o},{allOwnKeys:r}),e),lm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),cm=(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)},um=(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&&$s(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},dm=(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},fm=e=>{if(!e)return null;if(rr(e))return e;let t=e.length;if(!Za(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},hm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&$s(Uint8Array)),pm=(e,t)=>{const r=(e&&e[lo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},mm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},gm=Ht("HTMLFormElement"),xm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),vm=Ht("RegExp"),nl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};_r(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wm=e=>{nl(e,(t,n)=>{if(Tt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Tt(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+"'")})}})},bm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return rr(e)?r(e):r(String(e).split(t)),n},ym=()=>{},Sm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Cm(e){return!!(e&&Tt(e.append)&&e[Xa]==="FormData"&&e[lo])}const Tm=e=>{const t=new Array(10),n=(r,o)=>{if(jr(r)){if(t.indexOf(r)>=0)return;if(Ar(r))return r;if(!("toJSON"in r)){t[o]=r;const s=rr(r)?[]:{};return _r(r,(i,a)=>{const l=n(i,o+1);!or(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},km=Ht("AsyncFunction"),Em=e=>e&&(jr(e)||Tt(e))&&Tt(e.then)&&Tt(e.catch),rl=((e,t)=>e?setImmediate:t?((n,r)=>(Dn.addEventListener("message",({source:o,data:s})=>{o===Dn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Dn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Tt(Dn.postMessage)),Im=typeof queueMicrotask<"u"?queueMicrotask.bind(Dn):typeof process<"u"&&process.nextTick||rl,P={isArray:rr,isArrayBuffer:Ja,isBuffer:Ar,isFormData:em,isArrayBufferView:Vp,isString:Kp,isNumber:Za,isBoolean:qp,isObject:jr,isPlainObject:fo,isEmptyObject:Gp,isReadableStream:nm,isRequest:rm,isResponse:om,isHeaders:sm,isUndefined:or,isDate:Yp,isFile:Xp,isBlob:Jp,isRegExp:vm,isFunction:Tt,isStream:Qp,isURLSearchParams:tm,isTypedArray:hm,isFileList:Zp,forEach:_r,merge:zs,extend:am,trim:im,stripBOM:lm,inherits:cm,toFlatObject:um,kindOf:co,kindOfTest:Ht,endsWith:dm,toArray:fm,forEachEntry:pm,matchAll:mm,isHTMLForm:gm,hasOwnProperty:tl,hasOwnProp:tl,reduceDescriptors:nl,freezeMethods:wm,toObjectSet:bm,toCamelCase:xm,noop:ym,toFiniteNumber:Sm,findKey:Qa,global:Dn,isContextDefined:el,isSpecCompliantForm:Cm,toJSONObject:Tm,isAsyncFn:km,isThenable:Em,setImmediate:rl,asap:Im,isIterable:e=>e!=null&&Tt(e[lo])};function Oe(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)}P.inherits(Oe,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:P.toJSONObject(this.config),code:this.code,status:this.status}}});const ol=Oe.prototype,sl={};["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=>{sl[e]={value:e}}),Object.defineProperties(Oe,sl),Object.defineProperty(ol,"isAxiosError",{value:!0}),Oe.from=(e,t,n,r,o,s)=>{const i=Object.create(ol);P.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Oe.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 Nm=null;function Bs(e){return P.isPlainObject(e)||P.isArray(e)}function il(e){return P.endsWith(e,"[]")?e.slice(0,-2):e}function al(e,t,n){return e?e.concat(t).map(function(o,s){return o=il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Am(e){return P.isArray(e)&&!e.some(Bs)}const jm=P.toFlatObject(P,{},null,function(t){return/^is[A-Z]/.test(t)});function ho(e,t,n){if(!P.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=P.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(v,g){return!P.isUndefined(g[v])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&P.isSpecCompliantForm(t);if(!P.isFunction(o))throw new TypeError("visitor must be a function");function u(w){if(w===null)return"";if(P.isDate(w))return w.toISOString();if(P.isBoolean(w))return w.toString();if(!l&&P.isBlob(w))throw new Oe("Blob is not supported. Use a Buffer instead.");return P.isArrayBuffer(w)||P.isTypedArray(w)?l&&typeof Blob=="function"?new Blob([w]):Buffer.from(w):w}function d(w,v,g){let x=w;if(w&&!g&&typeof w=="object"){if(P.endsWith(v,"{}"))v=r?v:v.slice(0,-2),w=JSON.stringify(w);else if(P.isArray(w)&&Am(w)||(P.isFileList(w)||P.endsWith(v,"[]"))&&(x=P.toArray(w)))return v=il(v),x.forEach(function(C,E){!(P.isUndefined(C)||C===null)&&t.append(i===!0?al([v],E,s):i===null?v:v+"[]",u(C))}),!1}return Bs(w)?!0:(t.append(al(g,v,s),u(w)),!1)}const f=[],h=Object.assign(jm,{defaultVisitor:d,convertValue:u,isVisitable:Bs});function p(w,v){if(!P.isUndefined(w)){if(f.indexOf(w)!==-1)throw Error("Circular reference detected in "+v.join("."));f.push(w),P.forEach(w,function(x,y){(!(P.isUndefined(x)||x===null)&&o.call(t,x,P.isString(y)?y.trim():y,v,h))===!0&&p(x,v?v.concat(y):[y])}),f.pop()}}if(!P.isObject(e))throw new TypeError("data must be an object");return p(e),t}function ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Hs(e,t){this._pairs=[],e&&ho(e,this,t)}const cl=Hs.prototype;cl.append=function(t,n){this._pairs.push([t,n])},cl.toString=function(t){const n=t?function(r){return t.call(this,r,ll)}:ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function _m(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ul(e,t,n){if(!t)return e;const r=n&&n.encode||_m;P.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=P.isURLSearchParams(t)?t.toString():new Hs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dl{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){P.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Rm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Hs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Us=typeof window<"u"&&typeof document<"u",Ws=typeof navigator=="object"&&navigator||void 0,Pm=Us&&(!Ws||["ReactNative","NativeScript","NS"].indexOf(Ws.product)<0),Om=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Mm=Us&&window.location.href||"http://localhost",gt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Us,hasStandardBrowserEnv:Pm,hasStandardBrowserWebWorkerEnv:Om,navigator:Ws,origin:Mm},Symbol.toStringTag,{value:"Module"})),...Rm};function Dm(e,t){return ho(e,new gt.classes.URLSearchParams,{visitor:function(n,r,o,s){return gt.isNode&&P.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Lm(e){return P.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Fm(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 hl(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&&P.isArray(o)?o.length:i,l?(P.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!P.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&P.isArray(o[i])&&(o[i]=Fm(o[i])),!a)}if(P.isFormData(e)&&P.isFunction(e.entries)){const n={};return P.forEachEntry(e,(r,o)=>{t(Lm(r),o,n,0)}),n}return null}function $m(e,t,n){if(P.isString(e))try{return(t||JSON.parse)(e),P.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Rr={transitional:fl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=P.isObject(t);if(s&&P.isHTMLForm(t)&&(t=new FormData(t)),P.isFormData(t))return o?JSON.stringify(hl(t)):t;if(P.isArrayBuffer(t)||P.isBuffer(t)||P.isStream(t)||P.isFile(t)||P.isBlob(t)||P.isReadableStream(t))return t;if(P.isArrayBufferView(t))return t.buffer;if(P.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 Dm(t,this.formSerializer).toString();if((a=P.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return ho(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),$m(t)):t}],transformResponse:[function(t){const n=this.transitional||Rr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(P.isResponse(t)||P.isReadableStream(t))return t;if(t&&P.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"?Oe.from(a,Oe.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:gt.classes.FormData,Blob:gt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};P.forEach(["delete","get","head","post","put","patch"],e=>{Rr.headers[e]={}});const zm=P.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"]),Bm=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
30
|
+
<%s key={someKey} {...props} />`,Er,fn,Va,fn),bt[fn+Er]=!0}}return b===r?et(Xe):Fe(Xe),Xe}}function nr(b,j,D){return Mt(b,j,D,!0)}function Tr(b,j,D){return Mt(b,j,D,!1)}var kr=Tr,N=nr;Nr.Fragment=r,Nr.jsx=kr,Nr.jsxs=N}()),Nr}process.env.NODE_ENV==="production"?Fs.exports=Hp():Fs.exports=Up();var c=Fs.exports;function Ya(e,t){return function(){return e.apply(t,arguments)}}const{toString:Wp}=Object.prototype,{getPrototypeOf:$s}=Object,{iterator:lo,toStringTag:Xa}=Symbol,co=(e=>t=>{const n=Wp.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Ht=e=>(e=e.toLowerCase(),t=>co(t)===e),uo=e=>t=>typeof t===e,{isArray:rr}=Array,or=uo("undefined");function Ar(e){return e!==null&&!or(e)&&e.constructor!==null&&!or(e.constructor)&&Tt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ja=Ht("ArrayBuffer");function Vp(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ja(e.buffer),t}const qp=uo("string"),Tt=uo("function"),Za=uo("number"),jr=e=>e!==null&&typeof e=="object",Kp=e=>e===!0||e===!1,fo=e=>{if(co(e)!=="object")return!1;const t=$s(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xa in e)&&!(lo in e)},Gp=e=>{if(!jr(e)||Ar(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Yp=Ht("Date"),Xp=Ht("File"),Jp=Ht("Blob"),Zp=Ht("FileList"),Qp=e=>jr(e)&&Tt(e.pipe),em=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Tt(e.append)&&((t=co(e))==="formdata"||t==="object"&&Tt(e.toString)&&e.toString()==="[object FormData]"))},tm=Ht("URLSearchParams"),[nm,rm,om,sm]=["ReadableStream","Request","Response","Headers"].map(Ht),im=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function _r(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),rr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Ar(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 Qa(e,t){if(Ar(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 Dn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,el=e=>!or(e)&&e!==Dn;function zs(){const{caseless:e,skipUndefined:t}=el(this)&&this||{},n={},r=(o,s)=>{const i=e&&Qa(n,s)||s;fo(n[i])&&fo(o)?n[i]=zs(n[i],o):fo(o)?n[i]=zs({},o):rr(o)?n[i]=o.slice():(!t||!or(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&_r(arguments[o],r);return n}const am=(e,t,n,{allOwnKeys:r}={})=>(_r(t,(o,s)=>{n&&Tt(o)?e[s]=Ya(o,n):e[s]=o},{allOwnKeys:r}),e),lm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),cm=(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)},um=(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&&$s(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},dm=(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},fm=e=>{if(!e)return null;if(rr(e))return e;let t=e.length;if(!Za(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},hm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&$s(Uint8Array)),pm=(e,t)=>{const r=(e&&e[lo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},mm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},gm=Ht("HTMLFormElement"),xm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),vm=Ht("RegExp"),nl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};_r(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wm=e=>{nl(e,(t,n)=>{if(Tt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Tt(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+"'")})}})},bm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return rr(e)?r(e):r(String(e).split(t)),n},ym=()=>{},Sm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Cm(e){return!!(e&&Tt(e.append)&&e[Xa]==="FormData"&&e[lo])}const Tm=e=>{const t=new Array(10),n=(r,o)=>{if(jr(r)){if(t.indexOf(r)>=0)return;if(Ar(r))return r;if(!("toJSON"in r)){t[o]=r;const s=rr(r)?[]:{};return _r(r,(i,a)=>{const l=n(i,o+1);!or(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},km=Ht("AsyncFunction"),Em=e=>e&&(jr(e)||Tt(e))&&Tt(e.then)&&Tt(e.catch),rl=((e,t)=>e?setImmediate:t?((n,r)=>(Dn.addEventListener("message",({source:o,data:s})=>{o===Dn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Dn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Tt(Dn.postMessage)),Im=typeof queueMicrotask<"u"?queueMicrotask.bind(Dn):typeof process<"u"&&process.nextTick||rl,P={isArray:rr,isArrayBuffer:Ja,isBuffer:Ar,isFormData:em,isArrayBufferView:Vp,isString:qp,isNumber:Za,isBoolean:Kp,isObject:jr,isPlainObject:fo,isEmptyObject:Gp,isReadableStream:nm,isRequest:rm,isResponse:om,isHeaders:sm,isUndefined:or,isDate:Yp,isFile:Xp,isBlob:Jp,isRegExp:vm,isFunction:Tt,isStream:Qp,isURLSearchParams:tm,isTypedArray:hm,isFileList:Zp,forEach:_r,merge:zs,extend:am,trim:im,stripBOM:lm,inherits:cm,toFlatObject:um,kindOf:co,kindOfTest:Ht,endsWith:dm,toArray:fm,forEachEntry:pm,matchAll:mm,isHTMLForm:gm,hasOwnProperty:tl,hasOwnProp:tl,reduceDescriptors:nl,freezeMethods:wm,toObjectSet:bm,toCamelCase:xm,noop:ym,toFiniteNumber:Sm,findKey:Qa,global:Dn,isContextDefined:el,isSpecCompliantForm:Cm,toJSONObject:Tm,isAsyncFn:km,isThenable:Em,setImmediate:rl,asap:Im,isIterable:e=>e!=null&&Tt(e[lo])};function Oe(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)}P.inherits(Oe,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:P.toJSONObject(this.config),code:this.code,status:this.status}}});const ol=Oe.prototype,sl={};["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=>{sl[e]={value:e}}),Object.defineProperties(Oe,sl),Object.defineProperty(ol,"isAxiosError",{value:!0}),Oe.from=(e,t,n,r,o,s)=>{const i=Object.create(ol);P.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Oe.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 Nm=null;function Bs(e){return P.isPlainObject(e)||P.isArray(e)}function il(e){return P.endsWith(e,"[]")?e.slice(0,-2):e}function al(e,t,n){return e?e.concat(t).map(function(o,s){return o=il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Am(e){return P.isArray(e)&&!e.some(Bs)}const jm=P.toFlatObject(P,{},null,function(t){return/^is[A-Z]/.test(t)});function ho(e,t,n){if(!P.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=P.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(v,g){return!P.isUndefined(g[v])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&P.isSpecCompliantForm(t);if(!P.isFunction(o))throw new TypeError("visitor must be a function");function u(w){if(w===null)return"";if(P.isDate(w))return w.toISOString();if(P.isBoolean(w))return w.toString();if(!l&&P.isBlob(w))throw new Oe("Blob is not supported. Use a Buffer instead.");return P.isArrayBuffer(w)||P.isTypedArray(w)?l&&typeof Blob=="function"?new Blob([w]):Buffer.from(w):w}function d(w,v,g){let x=w;if(w&&!g&&typeof w=="object"){if(P.endsWith(v,"{}"))v=r?v:v.slice(0,-2),w=JSON.stringify(w);else if(P.isArray(w)&&Am(w)||(P.isFileList(w)||P.endsWith(v,"[]"))&&(x=P.toArray(w)))return v=il(v),x.forEach(function(C,E){!(P.isUndefined(C)||C===null)&&t.append(i===!0?al([v],E,s):i===null?v:v+"[]",u(C))}),!1}return Bs(w)?!0:(t.append(al(g,v,s),u(w)),!1)}const f=[],h=Object.assign(jm,{defaultVisitor:d,convertValue:u,isVisitable:Bs});function p(w,v){if(!P.isUndefined(w)){if(f.indexOf(w)!==-1)throw Error("Circular reference detected in "+v.join("."));f.push(w),P.forEach(w,function(x,y){(!(P.isUndefined(x)||x===null)&&o.call(t,x,P.isString(y)?y.trim():y,v,h))===!0&&p(x,v?v.concat(y):[y])}),f.pop()}}if(!P.isObject(e))throw new TypeError("data must be an object");return p(e),t}function ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Hs(e,t){this._pairs=[],e&&ho(e,this,t)}const cl=Hs.prototype;cl.append=function(t,n){this._pairs.push([t,n])},cl.toString=function(t){const n=t?function(r){return t.call(this,r,ll)}:ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function _m(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ul(e,t,n){if(!t)return e;const r=n&&n.encode||_m;P.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=P.isURLSearchParams(t)?t.toString():new Hs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dl{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){P.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Rm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Hs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Us=typeof window<"u"&&typeof document<"u",Ws=typeof navigator=="object"&&navigator||void 0,Pm=Us&&(!Ws||["ReactNative","NativeScript","NS"].indexOf(Ws.product)<0),Om=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Mm=Us&&window.location.href||"http://localhost",gt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Us,hasStandardBrowserEnv:Pm,hasStandardBrowserWebWorkerEnv:Om,navigator:Ws,origin:Mm},Symbol.toStringTag,{value:"Module"})),...Rm};function Dm(e,t){return ho(e,new gt.classes.URLSearchParams,{visitor:function(n,r,o,s){return gt.isNode&&P.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Lm(e){return P.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Fm(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 hl(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&&P.isArray(o)?o.length:i,l?(P.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!P.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&P.isArray(o[i])&&(o[i]=Fm(o[i])),!a)}if(P.isFormData(e)&&P.isFunction(e.entries)){const n={};return P.forEachEntry(e,(r,o)=>{t(Lm(r),o,n,0)}),n}return null}function $m(e,t,n){if(P.isString(e))try{return(t||JSON.parse)(e),P.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Rr={transitional:fl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=P.isObject(t);if(s&&P.isHTMLForm(t)&&(t=new FormData(t)),P.isFormData(t))return o?JSON.stringify(hl(t)):t;if(P.isArrayBuffer(t)||P.isBuffer(t)||P.isStream(t)||P.isFile(t)||P.isBlob(t)||P.isReadableStream(t))return t;if(P.isArrayBufferView(t))return t.buffer;if(P.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 Dm(t,this.formSerializer).toString();if((a=P.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return ho(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),$m(t)):t}],transformResponse:[function(t){const n=this.transitional||Rr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(P.isResponse(t)||P.isReadableStream(t))return t;if(t&&P.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"?Oe.from(a,Oe.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:gt.classes.FormData,Blob:gt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};P.forEach(["delete","get","head","post","put","patch"],e=>{Rr.headers[e]={}});const zm=P.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"]),Bm=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]&&zm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},pl=Symbol("internals");function Pr(e){return e&&String(e).trim().toLowerCase()}function po(e){return e===!1||e==null?e:P.isArray(e)?e.map(po):String(e)}function Hm(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 Um=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Vs(e,t,n,r,o){if(P.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!P.isString(t)){if(P.isString(r))return t.indexOf(r)!==-1;if(P.isRegExp(r))return r.test(t)}}function Wm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Vm(e,t){const n=P.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 kt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=Pr(l);if(!d)throw new Error("header name must be a non-empty string");const f=P.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||l]=po(a))}const i=(a,l)=>P.forEach(a,(u,d)=>s(u,d,l));if(P.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(P.isString(t)&&(t=t.trim())&&!Um(t))i(Bm(t),n);else if(P.isObject(t)&&P.isIterable(t)){let a={},l,u;for(const d of t){if(!P.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(l=a[u])?P.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Pr(t),t){const r=P.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Hm(o);if(P.isFunction(n))return n.call(this,o,r);if(P.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Pr(t),t){const r=P.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Vs(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Pr(i),i){const a=P.findKey(r,i);a&&(!n||Vs(r,r[a],a,n))&&(delete r[a],o=!0)}}return P.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||Vs(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return P.forEach(this,(o,s)=>{const i=P.findKey(r,s);if(i){n[i]=po(o),delete n[s];return}const a=t?Wm(s):String(s).trim();a!==s&&delete n[s],n[a]=po(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return P.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&P.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[pl]=this[pl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Pr(i);r[a]||(Vm(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};kt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors(kt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods(kt);function Ks(e,t){const n=this||Rr,r=t||n,o=kt.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ml(e){return!!(e&&e.__CANCEL__)}function sr(e,t,n){Oe.call(this,e??"canceled",Oe.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(sr,Oe,{__CANCEL__:!0});function gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Oe("Request failed with status code "+n.status,[Oe.ERR_BAD_REQUEST,Oe.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Km(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function qm(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 u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;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),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function Gm(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const mo=(e,t,n=3)=>{let r=0;const o=qm(50,250);return Gm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},xl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},vl=e=>(...t)=>P.asap(()=>e(...t)),Ym=gt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,gt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(gt.origin),gt.navigator&&/(msie|trident)/i.test(gt.navigator.userAgent)):()=>!0,Xm=gt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.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 Jm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Zm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function wl(e,t,n){let r=!Jm(t);return e&&(r||n==!1)?Zm(e,t):t}const bl=e=>e instanceof kt?{...e}:e;function Ln(e,t){t=t||{};const n={};function r(u,d,f,h){return P.isPlainObject(u)&&P.isPlainObject(d)?P.merge.call({caseless:h},u,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(u,d,f,h){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!P.isUndefined(d))return r(void 0,d)}function i(u,d){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}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:(u,d,f)=>o(bl(u),bl(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);P.isUndefined(h)&&f!==a||(n[d]=h)}),n}const yl=e=>{const t=Ln({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=kt.from(i),t.url=ul(wl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(gt.hasStandardBrowserEnv||gt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(gt.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&Ym(t.url))){const l=o&&s&&Xm.read(s);l&&i.set(o,l)}return t},Qm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=yl(e);let s=o.data;const i=kt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,w;function v(){p&&p(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function x(){if(!g)return;const C=kt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),T={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:C,config:e,request:g};gl(function(I){n(I),v()},function(I){r(I),v()},T),g=null}"onloadend"in g?g.onloadend=x:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(x)},g.onabort=function(){g&&(r(new Oe("Request aborted",Oe.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const T=E&&E.message?E.message:"Network Error",k=new Oe(T,Oe.ERR_NETWORK,e,g);k.event=E||null,r(k),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const T=o.transitional||fl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Oe(E,T.clarifyTimeoutError?Oe.ETIMEDOUT:Oe.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&P.forEach(i.toJSON(),function(E,T){g.setRequestHeader(T,E)}),P.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=mo(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=mo(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{g&&(r(!C||C.type?new sr(null,e,g):C),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const y=Km(o.url);if(y&>.protocols.indexOf(y)===-1){r(new Oe("Unsupported protocol "+y+":",Oe.ERR_BAD_REQUEST,e));return}g.send(s||null)})},eg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Oe?d:new sr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Oe(`timeout ${t} of ms exceeded`,Oe.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>P.asap(a),l}},tg=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},ng=async function*(e,t){for await(const n of rg(e))yield*tg(n,t)},rg=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()}},Sl=(e,t,n,r)=>{const o=ng(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Cl=64*1024,{isFunction:go}=P,og=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:Tl,TextEncoder:kl}=P.global,El=(e,...t)=>{try{return!!e(...t)}catch{return!1}},sg=e=>{e=P.merge.call({skipUndefined:!0},og,e);const{fetch:t,Request:n,Response:r}=e,o=t?go(t):typeof fetch=="function",s=go(n),i=go(r);if(!o)return!1;const a=o&&go(Tl),l=o&&(typeof kl=="function"?(w=>v=>w.encode(v))(new kl):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&El(()=>{let w=!1;const v=new n(gt.origin,{body:new Tl,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!v}),d=i&&a&&El(()=>P.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(v,g)=>{let x=v&&v[w];if(x)return x.call(v);throw new Oe(`Response type '${w}' is not supported`,Oe.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(P.isBlob(w))return w.size;if(P.isSpecCompliantForm(w))return(await new n(gt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(P.isArrayBufferView(w)||P.isArrayBuffer(w))return w.byteLength;if(P.isURLSearchParams(w)&&(w=w+""),P.isString(w))return(await l(w)).byteLength},p=async(w,v)=>{const g=P.toFiniteNumber(w.getContentLength());return g??h(v)};return async w=>{let{url:v,method:g,data:x,signal:y,cancelToken:C,timeout:E,onDownloadProgress:T,onUploadProgress:k,responseType:I,headers:A,withCredentials:_="same-origin",fetchOptions:R}=yl(w),L=t||fetch;I=I?(I+"").toLowerCase():"text";let F=eg([y,C&&C.toAbortSignal()],E),V=null;const O=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let Y;try{if(k&&u&&g!=="get"&&g!=="head"&&(Y=await p(A,x))!==0){let H=new n(v,{method:"POST",body:x,duplex:"half"}),ge;if(P.isFormData(x)&&(ge=H.headers.get("content-type"))&&A.setContentType(ge),H.body){const[de,ee]=xl(Y,mo(vl(k)));x=Sl(H.body,Cl,de,ee)}}P.isString(_)||(_=_?"include":"omit");const K=s&&"credentials"in n.prototype,X={...R,signal:F,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:K?_:void 0};V=s&&new n(v,X);let B=await(s?L(V,R):L(v,X));const $=d&&(I==="stream"||I==="response");if(d&&(T||$&&O)){const H={};["status","statusText","headers"].forEach(je=>{H[je]=B[je]});const ge=P.toFiniteNumber(B.headers.get("content-length")),[de,ee]=T&&xl(ge,mo(vl(T),!0))||[];B=new r(Sl(B.body,Cl,de,()=>{ee&&ee(),O&&O()}),H)}I=I||"text";let z=await f[P.findKey(f,I)||"text"](B,w);return!$&&O&&O(),await new Promise((H,ge)=>{gl(H,ge,{data:z,headers:kt.from(B.headers),status:B.status,statusText:B.statusText,config:w,request:V})})}catch(K){throw O&&O(),K&&K.name==="TypeError"&&/Load failed|fetch/i.test(K.message)?Object.assign(new Oe("Network Error",Oe.ERR_NETWORK,w,V),{cause:K.cause||K}):Oe.from(K,K&&K.code,w,V)}}},ig=new Map,Il=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,u,d=ig;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:sg(t)),d=u;return u};Il();const qs={http:Nm,xhr:Qm,fetch:{get:Il}};P.forEach(qs,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Nl=e=>`- ${e}`,ag=e=>P.isFunction(e)||e===null||e===!1,Al={getAdapter:(e,t)=>{e=P.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,!ag(r)&&(o=qs[(a=String(r)).toLowerCase()],o===void 0))throw new Oe(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!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[pl]=this[pl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Pr(i);r[a]||(Vm(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};kt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors(kt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods(kt);function qs(e,t){const n=this||Rr,r=t||n,o=kt.from(r.headers);let s=r.data;return P.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ml(e){return!!(e&&e.__CANCEL__)}function sr(e,t,n){Oe.call(this,e??"canceled",Oe.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(sr,Oe,{__CANCEL__:!0});function gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Oe("Request failed with status code "+n.status,[Oe.ERR_BAD_REQUEST,Oe.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function qm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Km(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 u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;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),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function Gm(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const mo=(e,t,n=3)=>{let r=0;const o=Km(50,250);return Gm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},xl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},vl=e=>(...t)=>P.asap(()=>e(...t)),Ym=gt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,gt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(gt.origin),gt.navigator&&/(msie|trident)/i.test(gt.navigator.userAgent)):()=>!0,Xm=gt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];P.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),P.isString(r)&&i.push("path="+r),P.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 Jm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Zm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function wl(e,t,n){let r=!Jm(t);return e&&(r||n==!1)?Zm(e,t):t}const bl=e=>e instanceof kt?{...e}:e;function Ln(e,t){t=t||{};const n={};function r(u,d,f,h){return P.isPlainObject(u)&&P.isPlainObject(d)?P.merge.call({caseless:h},u,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(u,d,f,h){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!P.isUndefined(d))return r(void 0,d)}function i(u,d){if(P.isUndefined(d)){if(!P.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}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:(u,d,f)=>o(bl(u),bl(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);P.isUndefined(h)&&f!==a||(n[d]=h)}),n}const yl=e=>{const t=Ln({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=kt.from(i),t.url=ul(wl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(gt.hasStandardBrowserEnv||gt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(gt.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&Ym(t.url))){const l=o&&s&&Xm.read(s);l&&i.set(o,l)}return t},Qm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=yl(e);let s=o.data;const i=kt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,w;function v(){p&&p(),w&&w(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function x(){if(!g)return;const C=kt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),T={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:C,config:e,request:g};gl(function(I){n(I),v()},function(I){r(I),v()},T),g=null}"onloadend"in g?g.onloadend=x:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(x)},g.onabort=function(){g&&(r(new Oe("Request aborted",Oe.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const T=E&&E.message?E.message:"Network Error",k=new Oe(T,Oe.ERR_NETWORK,e,g);k.event=E||null,r(k),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const T=o.transitional||fl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Oe(E,T.clarifyTimeoutError?Oe.ETIMEDOUT:Oe.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&P.forEach(i.toJSON(),function(E,T){g.setRequestHeader(T,E)}),P.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,w]=mo(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=mo(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{g&&(r(!C||C.type?new sr(null,e,g):C),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const y=qm(o.url);if(y&>.protocols.indexOf(y)===-1){r(new Oe("Unsupported protocol "+y+":",Oe.ERR_BAD_REQUEST,e));return}g.send(s||null)})},eg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Oe?d:new sr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Oe(`timeout ${t} of ms exceeded`,Oe.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>P.asap(a),l}},tg=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},ng=async function*(e,t){for await(const n of rg(e))yield*tg(n,t)},rg=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()}},Sl=(e,t,n,r)=>{const o=ng(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Cl=64*1024,{isFunction:go}=P,og=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:Tl,TextEncoder:kl}=P.global,El=(e,...t)=>{try{return!!e(...t)}catch{return!1}},sg=e=>{e=P.merge.call({skipUndefined:!0},og,e);const{fetch:t,Request:n,Response:r}=e,o=t?go(t):typeof fetch=="function",s=go(n),i=go(r);if(!o)return!1;const a=o&&go(Tl),l=o&&(typeof kl=="function"?(w=>v=>w.encode(v))(new kl):async w=>new Uint8Array(await new n(w).arrayBuffer())),u=s&&a&&El(()=>{let w=!1;const v=new n(gt.origin,{body:new Tl,method:"POST",get duplex(){return w=!0,"half"}}).headers.has("Content-Type");return w&&!v}),d=i&&a&&El(()=>P.isReadableStream(new r("").body)),f={stream:d&&(w=>w.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(w=>{!f[w]&&(f[w]=(v,g)=>{let x=v&&v[w];if(x)return x.call(v);throw new Oe(`Response type '${w}' is not supported`,Oe.ERR_NOT_SUPPORT,g)})});const h=async w=>{if(w==null)return 0;if(P.isBlob(w))return w.size;if(P.isSpecCompliantForm(w))return(await new n(gt.origin,{method:"POST",body:w}).arrayBuffer()).byteLength;if(P.isArrayBufferView(w)||P.isArrayBuffer(w))return w.byteLength;if(P.isURLSearchParams(w)&&(w=w+""),P.isString(w))return(await l(w)).byteLength},p=async(w,v)=>{const g=P.toFiniteNumber(w.getContentLength());return g??h(v)};return async w=>{let{url:v,method:g,data:x,signal:y,cancelToken:C,timeout:E,onDownloadProgress:T,onUploadProgress:k,responseType:I,headers:A,withCredentials:_="same-origin",fetchOptions:R}=yl(w),L=t||fetch;I=I?(I+"").toLowerCase():"text";let F=eg([y,C&&C.toAbortSignal()],E),V=null;const O=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let Y;try{if(k&&u&&g!=="get"&&g!=="head"&&(Y=await p(A,x))!==0){let H=new n(v,{method:"POST",body:x,duplex:"half"}),ge;if(P.isFormData(x)&&(ge=H.headers.get("content-type"))&&A.setContentType(ge),H.body){const[de,ee]=xl(Y,mo(vl(k)));x=Sl(H.body,Cl,de,ee)}}P.isString(_)||(_=_?"include":"omit");const q=s&&"credentials"in n.prototype,X={...R,signal:F,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:q?_:void 0};V=s&&new n(v,X);let B=await(s?L(V,R):L(v,X));const $=d&&(I==="stream"||I==="response");if(d&&(T||$&&O)){const H={};["status","statusText","headers"].forEach(je=>{H[je]=B[je]});const ge=P.toFiniteNumber(B.headers.get("content-length")),[de,ee]=T&&xl(ge,mo(vl(T),!0))||[];B=new r(Sl(B.body,Cl,de,()=>{ee&&ee(),O&&O()}),H)}I=I||"text";let z=await f[P.findKey(f,I)||"text"](B,w);return!$&&O&&O(),await new Promise((H,ge)=>{gl(H,ge,{data:z,headers:kt.from(B.headers),status:B.status,statusText:B.statusText,config:w,request:V})})}catch(q){throw O&&O(),q&&q.name==="TypeError"&&/Load failed|fetch/i.test(q.message)?Object.assign(new Oe("Network Error",Oe.ERR_NETWORK,w,V),{cause:q.cause||q}):Oe.from(q,q&&q.code,w,V)}}},ig=new Map,Il=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,u,d=ig;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:sg(t)),d=u;return u};Il();const Ks={http:Nm,xhr:Qm,fetch:{get:Il}};P.forEach(Ks,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Nl=e=>`- ${e}`,ag=e=>P.isFunction(e)||e===null||e===!1,Al={getAdapter:(e,t)=>{e=P.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,!ag(r)&&(o=Ks[(a=String(r)).toLowerCase()],o===void 0))throw new Oe(`Unknown adapter '${a}'`);if(o&&(P.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
33
|
`+i.map(Nl).join(`
|
|
34
|
-
`):" "+Nl(i[0]):"as no adapter specified";throw new Oe("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Ln(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&vo.assertOptions(r,{silentJSONParsing:Xt.transitional(Xt.boolean),forcedJSONParsing:Xt.transitional(Xt.boolean),clarifyTimeoutError:Xt.transitional(Xt.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:vo.assertOptions(o,{encode:Xt.function,serialize:Xt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),vo.assertOptions(n,{baseUrl:Xt.spelling("baseURL"),withXsrfToken:Xt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=kt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(l=l&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});const u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,f=0,h;if(!l){const w=[jl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],v=a[f++];try{p=w(p)}catch(g){v.call(this,g);break}}try{d=jl.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Ln(this.defaults,t);const n=wl(t.baseURL,t.url,t.allowAbsoluteUrls);return ul(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){Fn.prototype[t]=function(n,r){return this.request(Ln(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Ln(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Fn.prototype[t]=n(),Fn.prototype[t+"Form"]=n(!0)});let cg=class $p{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 sr(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 $p(function(o){t=o}),cancel:t}}};function ug(e){return function(n){return e.apply(null,n)}}function dg(e){return P.isObject(e)&&e.isAxiosError===!0}const Ys={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(Ys).forEach(([e,t])=>{Ys[t]=e});function Pl(e){const t=new Fn(e),n=Ya(Fn.prototype.request,t);return P.extend(n,Fn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Pl(Ln(e,o))},n}const it=Pl(Rr);it.Axios=Fn,it.CanceledError=sr,it.CancelToken=cg,it.isCancel=ml,it.VERSION=_l,it.toFormData=ho,it.AxiosError=Oe,it.Cancel=it.CanceledError,it.all=function(t){return Promise.all(t)},it.spread=ug,it.isAxiosError=dg,it.mergeConfig=Ln,it.AxiosHeaders=kt,it.formToJSON=e=>hl(P.isHTMLForm(e)?new FormData(e):e),it.getAdapter=Al.getAdapter,it.HttpStatusCode=Ys,it.default=it;const{Axios:FC,AxiosError:$C,CanceledError:zC,isCancel:BC,CancelToken:HC,VERSION:UC,all:WC,Cancel:VC,isAxiosError:KC,spread:qC,toFormData:GC,AxiosHeaders:YC,HttpStatusCode:XC,formToJSON:JC,getAdapter:ZC,mergeConfig:QC}=it,Ol=typeof window<"u"?window.__API_BASE_URL__:void 0,Ml=Ol?hn(Ol):void 0;function hn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let wo=null;const Xs=new Set;function Dl(){return wo}function Js(e){wo=e,Xs.forEach(t=>t(e))}function Ll(e){return Xs.add(e),()=>Xs.delete(e)}const Dt=it.create({...Ml?{baseURL:Ml}:{},timeout:3e4,withCredentials:!0});Dt.interceptors.request.use(e=>(wo&&(e.headers.Authorization=`Bearer ${wo}`),e)),Dt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Nt(e,t){return Dt.defaults.baseURL?(await Dt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Zs(e,t,n){return Dt.defaults.baseURL?(await Dt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fl(e,t,n){return Dt.defaults.baseURL?(await Dt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t){return Dt.defaults.baseURL?(await Dt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function At(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class zl{get baseUrl(){const t=Dt.defaults.baseURL;return t?hn(String(t)):""}updateConfig(t){t.baseUrl&&(Dt.defaults.baseURL=hn(String(t.baseUrl))),t.authToken!==void 0&&Js(t.authToken)}getAuthToken(){return Dl()}setAuthToken(t){Js(t)}onTokenChange(t){return Ll(t)}async listThreads(){const t=await Nt("/threads"),n=At(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Zs("/threads",t?{title:t}:void 0);return At(r)}async updateThread(t,n){const r=await Fl(`/threads/${t}`,{title:n});return At(r)}async deleteThread(t){const n=await $l(`/threads/${t}`);return At(n)}async threadInfo(t){const n=await Nt(`/threads/${t}/info`);return At(n)}async listAgents(){const t=await Nt("/agents"),n=At(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Nt(`/agents/${t}`);return At(n)}async getAgentSchema(t){const n=await Nt(`/agents/${t}/schema`);return At(n)}async getMessages(t){const n=await Nt(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return At(n)}async getState(t){const n=await Nt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async getStateHistory(t){const n=await Nt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async listCheckpoints(t){const n=await Nt(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return At(n)}resumeStream(t){}async resume(t){const n=await Zs("/runs/resume",{thread_id:t.threadId,value:t.value});return At(n)}}const wn=new zl,Bl=S.createContext(null);function fg({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 c.jsx(Bl.Provider,{value:r,children:e})}function Qs(){const e=S.useContext(Bl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function hg(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function pg(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 mg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await pg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}function gg(e){return e.type!=="thread_info"&&e.type!=="token"}const xg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{}};function vg(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:ei(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=ei(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=ei(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Ul(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Ul(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Hl(e=[]){const[t,n]=S.useReducer(vg,{...xg,messages:e}),r=S.useRef([]),o=S.useRef(null),s=S.useRef(null),i=S.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=S.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=S.useCallback(d=>{r.current.push(d),a()},[a]);S.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=S.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Ul(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=yg(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??ti(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(C=>C.id===i&&C.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Gl(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:w,changed:v}=wg(u.content,t.delta,f,h);if(!v)return e;const g={...u,content:p},x=Wl(a,l,g),y={...d,[i]:w};return{...e,messages:x,messagesStreamMeta:y}}if(t.type==="message_end"){const i=e.assemblingId??ti(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?Kl(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=bg(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??ti(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:Kl(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:Vl(e.messages,l,f=>({...f,content:ql(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function ei(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 Wl(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function ti(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Vl(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Kl(e,t,n){return Vl(e,t,r=>({...r,content:ql(r.content,n)}))}function ql(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=Xl(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Gl(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function wg(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??Gl(e);let l="",u=e.slice();if(s){const f=Xl(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",w={...h,text:p+l};u=[...u.slice(0,u.length-1),w]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function Yl(e){return e.replace(/\s+/g," ").trim()}function Xl(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=Yl(e),o=Yl(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 bg(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 Wl(e,r,s)}return e}function yg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Jl(e={}){const t=S.useMemo(()=>hn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=S.useState(e.token??null),s=S.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=S.useState(!1),[u,d]=S.useState(null),[f,h]=S.useState(""),[p,w]=S.useState(null),[v,g]=S.useState(0),[x,y]=S.useState(!1),C=S.useRef(null),E=S.useRef(!0),T=S.useRef(0),k=S.useCallback(R=>{o(R)},[]),I=S.useCallback(()=>{var R;(R=C.current)==null||R.abort(),C.current=null,l(!1),y(!1),T.current=0,g(0)},[]),A=S.useCallback(()=>{h(""),w(null),d(null)},[]),_=S.useCallback((R,L,F)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return C.current=V,(async()=>{var Y,K,X,B,$,z,H,ge;const O=de=>{var ee;try{const je=JSON.parse(JSON.stringify(de));return(ee=je==null?void 0:je.payload)!=null&&ee.files_info&&Array.isArray(je.payload.files_info)&&(je.payload.files_info=je.payload.files_info.map(Te=>({...Te,data:Te!=null&&Te.data?`<base64 ${String(Te.data).length} chars>`:Te==null?void 0:Te.data}))),je}catch{return de}};try{let de={};try{if(r)de={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const _e=window.__AUTH_TOKEN__,Qe=((Y=window.localStorage)==null?void 0:Y.getItem("authToken"))||null;let Ue=null;try{const lt=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");lt&&(Ue=((X=JSON.parse(lt))==null?void 0:X.apiKey)||null)}catch{}const ot=_e||Qe||Ue||null;ot&&(de={Authorization:`Bearer ${ot}`})}}catch{}console.debug("[use-chat] POST",t+n,O(R));const ee=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...de,...s.current},body:JSON.stringify(R),signal:V.signal,credentials:i});if(!ee.ok||!ee.body){const Ce=await ee.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",ee.status,Ce==null?void 0:Ce.slice(0,500)),new Error(`stream ${ee.status}${Ce?": "+Ce:""}`)}y(!0);const je=ee.body.getReader(),Te=new TextDecoder;let q="",M=[];T.current=0,g(0);let Z=0,ne=null;const Q=()=>{if(M.length){const Ce=M.join("");M=[],E.current&&h(_e=>_e+Ce)}ne=null},le=()=>{typeof window<"u"&&ne==null&&(ne=requestAnimationFrame(Q))};let Be=Date.now();const Ye=setInterval(()=>{var Ce;if(Date.now()-Be>6e4){const _e="Stream idle timeout";d(_e),V.abort(),(Ce=F==null?void 0:F.onError)==null||Ce.call(F,_e)}},5e3),qe=1024*1024;try{const Ce=ee.headers.get("X-Thread-Id")||ee.headers.get("x-thread-id"),_e=ee.headers.get("X-Thread-Created")||ee.headers.get("x-thread-created"),Qe=Ce??null,Ue=String(_e??"").toLowerCase()==="true";for((B=F==null?void 0:F.onOpen)==null||B.call(F,{threadId:Qe,created:Ue});;){const{value:ot,done:lt}=await je.read();if(lt)break;q+=Te.decode(ot,{stream:!0}),q.length>qe&&(q="",console.warn("Stream buffer reset: exceeded 1MB"));let ie;for(;(ie=q.indexOf(`
|
|
34
|
+
`):" "+Nl(i[0]):"as no adapter specified";throw new Oe("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Ks};function Gs(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new sr(null,e)}function jl(e){return Gs(e),e.headers=kt.from(e.headers),e.data=qs.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Al.getAdapter(e.adapter||Rr.adapter,e)(e).then(function(r){return Gs(e),r.data=qs.call(e,e.transformResponse,r),r.headers=kt.from(r.headers),r},function(r){return ml(r)||(Gs(e),r&&r.response&&(r.response.data=qs.call(e,e.transformResponse,r.response),r.response.headers=kt.from(r.response.headers))),Promise.reject(r)})}const _l="1.12.2",xo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{xo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Rl={};xo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+_l+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Oe(o(i," has been removed"+(n?" in "+n:"")),Oe.ERR_DEPRECATED);return n&&!Rl[i]&&(Rl[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}},xo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function lg(e,t,n){if(typeof e!="object")throw new Oe("options must be an object",Oe.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 Oe("option "+s+" must be "+l,Oe.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Oe("Unknown option "+s,Oe.ERR_BAD_OPTION)}}const vo={assertOptions:lg,validators:xo},Xt=vo.validators;let Fn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new dl,response:new dl}}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=Ln(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&vo.assertOptions(r,{silentJSONParsing:Xt.transitional(Xt.boolean),forcedJSONParsing:Xt.transitional(Xt.boolean),clarifyTimeoutError:Xt.transitional(Xt.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:vo.assertOptions(o,{encode:Xt.function,serialize:Xt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),vo.assertOptions(n,{baseUrl:Xt.spelling("baseURL"),withXsrfToken:Xt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&P.merge(s.common,s[n.method]);s&&P.forEach(["delete","get","head","post","put","patch","common"],w=>{delete s[w]}),n.headers=kt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(n)===!1||(l=l&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});const u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,f=0,h;if(!l){const w=[jl.bind(this),void 0];for(w.unshift(...a),w.push(...u),h=w.length,d=Promise.resolve(n);f<h;)d=d.then(w[f++],w[f++]);return d}h=a.length;let p=n;for(;f<h;){const w=a[f++],v=a[f++];try{p=w(p)}catch(g){v.call(this,g);break}}try{d=jl.call(this,p)}catch(w){return Promise.reject(w)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Ln(this.defaults,t);const n=wl(t.baseURL,t.url,t.allowAbsoluteUrls);return ul(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){Fn.prototype[t]=function(n,r){return this.request(Ln(r||{},{method:t,url:n,data:(r||{}).data}))}}),P.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Ln(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Fn.prototype[t]=n(),Fn.prototype[t+"Form"]=n(!0)});let cg=class $p{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 sr(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 $p(function(o){t=o}),cancel:t}}};function ug(e){return function(n){return e.apply(null,n)}}function dg(e){return P.isObject(e)&&e.isAxiosError===!0}const Ys={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(Ys).forEach(([e,t])=>{Ys[t]=e});function Pl(e){const t=new Fn(e),n=Ya(Fn.prototype.request,t);return P.extend(n,Fn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Pl(Ln(e,o))},n}const it=Pl(Rr);it.Axios=Fn,it.CanceledError=sr,it.CancelToken=cg,it.isCancel=ml,it.VERSION=_l,it.toFormData=ho,it.AxiosError=Oe,it.Cancel=it.CanceledError,it.all=function(t){return Promise.all(t)},it.spread=ug,it.isAxiosError=dg,it.mergeConfig=Ln,it.AxiosHeaders=kt,it.formToJSON=e=>hl(P.isHTMLForm(e)?new FormData(e):e),it.getAdapter=Al.getAdapter,it.HttpStatusCode=Ys,it.default=it;const{Axios:FC,AxiosError:$C,CanceledError:zC,isCancel:BC,CancelToken:HC,VERSION:UC,all:WC,Cancel:VC,isAxiosError:qC,spread:KC,toFormData:GC,AxiosHeaders:YC,HttpStatusCode:XC,formToJSON:JC,getAdapter:ZC,mergeConfig:QC}=it,Ol=typeof window<"u"?window.__API_BASE_URL__:void 0,Ml=Ol?hn(Ol):void 0;function hn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let wo=null;const Xs=new Set;function Dl(){return wo}function Js(e){wo=e,Xs.forEach(t=>t(e))}function Ll(e){return Xs.add(e),()=>Xs.delete(e)}const Dt=it.create({...Ml?{baseURL:Ml}:{},timeout:3e4,withCredentials:!0});Dt.interceptors.request.use(e=>(wo&&(e.headers.Authorization=`Bearer ${wo}`),e)),Dt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function Nt(e,t){return Dt.defaults.baseURL?(await Dt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Zs(e,t,n){return Dt.defaults.baseURL?(await Dt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fl(e,t,n){return Dt.defaults.baseURL?(await Dt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t){return Dt.defaults.baseURL?(await Dt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function At(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class zl{get baseUrl(){const t=Dt.defaults.baseURL;return t?hn(String(t)):""}updateConfig(t){t.baseUrl&&(Dt.defaults.baseURL=hn(String(t.baseUrl))),t.authToken!==void 0&&Js(t.authToken)}getAuthToken(){return Dl()}setAuthToken(t){Js(t)}onTokenChange(t){return Ll(t)}async listThreads(){const t=await Nt("/threads"),n=At(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Zs("/threads",t?{title:t}:void 0);return At(r)}async updateThread(t,n){const r=await Fl(`/threads/${t}`,{title:n});return At(r)}async deleteThread(t){const n=await $l(`/threads/${t}`);return At(n)}async threadInfo(t){const n=await Nt(`/threads/${t}/info`);return At(n)}async listAgents(){const t=await Nt("/agents"),n=At(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Nt(`/agents/${t}`);return At(n)}async getAgentSchema(t){const n=await Nt(`/agents/${t}/schema`);return At(n)}async getMessages(t){const n=await Nt(`/threads/${t.threadId}/messages`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return At(n)}async getState(t){const n=await Nt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async getStateHistory(t){const n=await Nt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return At(n)}async listCheckpoints(t){const n=await Nt(`/threads/${t}/checkpoints`,{params:{thread_id:t}});return At(n)}resumeStream(t){}async resume(t){const n=await Zs("/runs/resume",{thread_id:t.threadId,value:t.value});return At(n)}}const wn=new zl,Bl=S.createContext(null);function fg({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 c.jsx(Bl.Provider,{value:r,children:e})}function Qs(){const e=S.useContext(Bl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function hg(e,t){const n=e==null?void 0:e.checkpoints,r=Array.isArray(n)?n.slice():n?Object.values(n):[],o=i=>i&&typeof i=="object"&&i!==null&&"checkpointId"in i&&"createdAt"in i&&typeof i.checkpointId=="string"&&typeof i.createdAt=="string",s=r.filter(o).map(i=>{const a=i;return{checkpointId:a.checkpointId,checkpointNs:a.checkpointNs??"",createdAt:a.createdAt,messagesLen:a.messagesLen??0,preview:a.preview??"",role:a.role??null,parentId:a.parentId??null,editedMessageId:a.editedMessageId??null,branchLabel:a.branchLabel??null,lastMessageId:a.lastMessageId??null,hasMessages:typeof a.hasMessages=="boolean"?a.hasMessages:void 0}});return{threadId:(e==null?void 0:e.threadId)??t??null,checkpoints:s}}async function pg(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 mg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await pg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}function gg(e){return e.type!=="thread_info"&&e.type!=="token"}const xg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{}};function vg(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:ei(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=ei(t.payload.messages),o={...e,messages:r,assemblingId:null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=ei(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Ul(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Ul(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Hl(e=[]){const[t,n]=S.useReducer(vg,{...xg,messages:e}),r=S.useRef([]),o=S.useRef(null),s=S.useRef(null),i=S.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=S.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=S.useCallback(d=>{r.current.push(d),a()},[a]);S.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=S.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Ul(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=yg(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??ti(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(C=>C.id===i&&C.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Gl(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:w,changed:v}=wg(u.content,t.delta,f,h);if(!v)return e;const g={...u,content:p},x=Wl(a,l,g),y={...d,[i]:w};return{...e,messages:x,messagesStreamMeta:y}}if(t.type==="message_end"){const i=e.assemblingId??ti(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?ql(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=bg(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??ti(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:ql(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:Vl(e.messages,l,f=>({...f,content:Kl(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function ei(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 Wl(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function ti(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Vl(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function ql(e,t,n){return Vl(e,t,r=>({...r,content:Kl(r.content,n)}))}function Kl(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=Xl(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Gl(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function wg(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??Gl(e);let l="",u=e.slice();if(s){const f=Xl(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",w={...h,text:p+l};u=[...u.slice(0,u.length-1),w]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function Yl(e){return e.replace(/\s+/g," ").trim()}function Xl(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=Yl(e),o=Yl(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 bg(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 Wl(e,r,s)}return e}function yg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Jl(e={}){const t=S.useMemo(()=>hn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=S.useState(e.token??null),s=S.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=S.useState(!1),[u,d]=S.useState(null),[f,h]=S.useState(""),[p,w]=S.useState(null),[v,g]=S.useState(0),[x,y]=S.useState(!1),C=S.useRef(null),E=S.useRef(!0),T=S.useRef(0),k=S.useCallback(R=>{o(R)},[]),I=S.useCallback(()=>{var R;(R=C.current)==null||R.abort(),C.current=null,l(!1),y(!1),T.current=0,g(0)},[]),A=S.useCallback(()=>{h(""),w(null),d(null)},[]),_=S.useCallback((R,L,F)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return C.current=V,(async()=>{var Y,q,X,B,$,z,H,ge;const O=de=>{var ee;try{const je=JSON.parse(JSON.stringify(de));return(ee=je==null?void 0:je.payload)!=null&&ee.files_info&&Array.isArray(je.payload.files_info)&&(je.payload.files_info=je.payload.files_info.map(Te=>({...Te,data:Te!=null&&Te.data?`<base64 ${String(Te.data).length} chars>`:Te==null?void 0:Te.data}))),je}catch{return de}};try{let de={};try{if(r)de={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const _e=window.__AUTH_TOKEN__,Qe=((Y=window.localStorage)==null?void 0:Y.getItem("authToken"))||null;let Ue=null;try{const lt=(q=window.localStorage)==null?void 0:q.getItem("chat-settings");lt&&(Ue=((X=JSON.parse(lt))==null?void 0:X.apiKey)||null)}catch{}const ot=_e||Qe||Ue||null;ot&&(de={Authorization:`Bearer ${ot}`})}}catch{}console.debug("[use-chat] POST",t+n,O(R));const ee=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...de,...s.current},body:JSON.stringify(R),signal:V.signal,credentials:i});if(!ee.ok||!ee.body){const Ce=await ee.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",ee.status,Ce==null?void 0:Ce.slice(0,500)),new Error(`stream ${ee.status}${Ce?": "+Ce:""}`)}y(!0);const je=ee.body.getReader(),Te=new TextDecoder;let K="",M=[];T.current=0,g(0);let Z=0,ne=null;const Q=()=>{if(M.length){const Ce=M.join("");M=[],E.current&&h(_e=>_e+Ce)}ne=null},le=()=>{typeof window<"u"&&ne==null&&(ne=requestAnimationFrame(Q))};let Be=Date.now();const Ye=setInterval(()=>{var Ce;if(Date.now()-Be>6e4){const _e="Stream idle timeout";d(_e),V.abort(),(Ce=F==null?void 0:F.onError)==null||Ce.call(F,_e)}},5e3),Ke=1024*1024;try{const Ce=ee.headers.get("X-Thread-Id")||ee.headers.get("x-thread-id"),_e=ee.headers.get("X-Thread-Created")||ee.headers.get("x-thread-created"),Qe=Ce??null,Ue=String(_e??"").toLowerCase()==="true";for((B=F==null?void 0:F.onOpen)==null||B.call(F,{threadId:Qe,created:Ue});;){const{value:ot,done:lt}=await je.read();if(lt)break;K+=Te.decode(ot,{stream:!0}),K.length>Ke&&(K="",console.warn("Stream buffer reset: exceeded 1MB"));let ie;for(;(ie=K.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const ue=
|
|
38
|
-
`)}function Tg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=S.useRef(null),i=S.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(gg(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Jl({baseUrl:e,token:null}),h=S.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return S.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Zl=S.createContext(null),Ql=S.createContext(null),ec=S.createContext(null),kg=S.createContext(!1),Eg=20,Ig="cachedThreads",Ng="v1",bo=300,ni=200;function tc(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,bo)}function ir(){return typeof window<"u"&&typeof window.localStorage<"u"}function ri(e){if(!ir())return null;try{return window.localStorage.getItem(e)}catch{return null}}function nc(e,t){if(ir())try{window.localStorage.setItem(e,t)}catch{}}function oi(e){if(ir())try{window.localStorage.removeItem(e)}catch{}}function Ag(){const e=ri(Ig);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 jg(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 si(e,t){return`cachedThreads:v1:${e}:${jg(t||"anon")}`}function _g(e){const t=ri(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 ii(e,t){try{nc(e,JSON.stringify(t))}catch{}}function rc(e){const t=_g(e);if(t.length>0)return t;const n=Ag();if(n.length>0)try{ii(e,n.slice(0,ni))}catch{}return n}function ai(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 li(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Rg({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:u}=Qs(),d=S.useMemo(()=>hn(u),[u]),f=S.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=S.useMemo(()=>`threadPayload:${Ng}:${f}:`,[f]),p=S.useCallback(N=>`${h}${N}`,[h]),w=S.useCallback(N=>{if(!N||typeof N!="object")return null;const b=N;return typeof b.threadId!="string"||!Array.isArray(b.messages)?null:{threadId:b.threadId,messages:b.messages,hasMore:!!b.hasMore,nextCursor:b.nextCursor??null,checkpointId:b.checkpointId??null,checkpointNs:b.checkpointNs??null}},[]),v=S.useCallback(N=>{const b=ri(p(N));if(!b)return null;try{const j=JSON.parse(b);return w(j)}catch{return null}},[p,w]),g=S.useCallback((N,b=100)=>{const j={...N,messages:Array.isArray(N.messages)?N.messages.slice(-b):[]};try{nc(p(N.threadId),JSON.stringify(j))}catch{}},[p]),x=S.useCallback(N=>{oi(p(N))},[p]),y=S.useCallback(()=>{if(ir())try{const N=h;for(let b=0;b<window.localStorage.length;b++){const j=window.localStorage.key(b);j&&j.startsWith(N)&&window.localStorage.removeItem(j)}}catch{}},[h]),[C,E]=S.useState(()=>{var N;return si(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[T,k]=S.useState(()=>{var b;const N=rc(si(f,(b=l.getAuthToken)==null?void 0:b.call(l)));return ai(N)}),I=S.useMemo(()=>li(T),[T]),[A,_]=S.useState(t),[R,L]=S.useState(!1),[F,V]=S.useState(!1),[O,Y]=S.useState(!1),[K,X]=S.useState(!1),[B,$]=S.useState(null),[z,H]=S.useState(void 0),[ge,de]=S.useState(void 0),{state:ee,dispatch:je,seed:Te,prepend:q,pushUser:M,onEvent:Z,reset:ne}=Hl(),Q=S.useRef(A);S.useEffect(()=>{Q.current=A},[A]);const le=S.useRef(!1),Be=S.useRef([]),Ye=S.useRef(null),qe=S.useRef(null),Ce=S.useRef(new Map),_e=S.useRef(A),Qe=S.useRef(!1),Ue=S.useRef(null),ot=S.useCallback((N,b)=>new Promise((j,D)=>{const U=async()=>{le.current=!0;try{await N(),j()}catch(G){D(G)}finally{le.current=!1;const G=Be.current.shift();G&&G().catch(()=>{})}};le.current?Be.current.push(U):U().catch(G=>{D(G)})}),[]),lt=S.useRef(I.length),[ie,ue]=S.useState(!1),we=S.useRef(!1);S.useEffect(()=>{lt.current=I.length},[I.length]);const pe=S.useCallback(async()=>{const N=lt.current>0;N||L(!0);try{const b=await l.listThreads();S.startTransition(()=>{k(j=>{const D=ve=>ve.map(me=>`${me.threadId}:${me.updatedAt??""}:${me.messageCount??""}`).join("|"),U=li(j);return D(U)===D(b)||b.length===0&&U.length>0&&!we.current?j:ai(b)})}),we.current||(we.current=!0,ue(!0))}catch(b){i==null||i(String(b)),console.error("[ChatSessionProvider] Failed to refresh threads:",b)}finally{N||L(!1)}},[l,i]),xe=S.useRef(!1),Re=S.useRef(null),Me=S.useRef(null),Pe=S.useRef(""),st=S.useCallback((N,b)=>{if(!ir())return;Me.current!==null&&(window.clearTimeout(Me.current),Me.current=null);const j=N.map(U=>`${U.threadId}:${U.updatedAt??""}:${U.messageCount??""}`).join("|");if(N.length===0){try{oi(C)}catch{}Pe.current="";return}if(j===Pe.current)return;const D=()=>{try{const U=N.slice(0,ni);ii(C,U),Pe.current=j}catch{}finally{Me.current=null}};if(b!=null&&b.immediate){D();return}Me.current=window.setTimeout(()=>{tc(D)},bo)},[C]),mt=S.useCallback((N,b,j)=>{const D=Array.isArray(N==null?void 0:N.messages)?N.messages:[],U=j??(N==null?void 0:N.threadId)??Q.current;if(b==="replace"){if(U){const G={threadId:U,messages:D.slice(),hasMore:!!(N!=null&&N.hasMore),nextCursor:(N==null?void 0:N.nextCursor)??null,checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null};Ce.current.set(U,G),_e.current=U}Te(D,{checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null})}else if(b==="prepend"&&D.length&&U){const G=Ce.current.get(U),ve=(G==null?void 0:G.messages)??[],me=new Set,he=[...D,...ve].filter(Ge=>{const Xe=Ge==null?void 0:Ge.id;return Xe?me.has(Xe)?!1:(me.add(Xe),!0):!0}),He={threadId:U,messages:he,hasMore:(N==null?void 0:N.hasMore)??(G==null?void 0:G.hasMore)??!1,nextCursor:(N==null?void 0:N.nextCursor)??(G==null?void 0:G.nextCursor)??null,checkpointId:(G==null?void 0:G.checkpointId)??(N==null?void 0:N.checkpointId)??null,checkpointNs:(G==null?void 0:G.checkpointNs)??(N==null?void 0:N.checkpointNs)??null};Ce.current.set(U,He),q(D)}else b==="prepend"&&D.length&&q(D);b==="replace"?($((N==null?void 0:N.nextCursor)??null),Y(!!(N!=null&&N.hasMore)),H((N==null?void 0:N.checkpointId)??void 0),de((N==null?void 0:N.checkpointNs)??void 0)):($(G=>(N==null?void 0:N.nextCursor)??G??null),Y(G=>(N==null?void 0:N.hasMore)!==void 0?!!(N!=null&&N.hasMore):G),H(G=>(N==null?void 0:N.checkpointId)??G??void 0),de(G=>(N==null?void 0:N.checkpointNs)??G??void 0))},[q,Te]),cn=S.useCallback(N=>{Te(N.messages,{checkpointId:N.checkpointId,checkpointNs:N.checkpointNs}),$(N.nextCursor),Y(N.hasMore),H(N.checkpointId??void 0),de(N.checkpointNs??void 0),_e.current=N.threadId},[Te]),un=S.useCallback(N=>{N&&(Ce.current.delete(N),x(N),_e.current===N&&(_e.current=null))},[x]),dn=S.useCallback(()=>{const N=Q.current;N&&un(N),ne([]),Y(!1),X(!1),$(null),H(void 0),de(void 0)},[un,ne]),Rn=S.useCallback(({from:N,to:b})=>{const j=Q.current;j&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${b}) for thread ${j}`)},[]),er=S.useCallback(N=>{const b=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:b,title:N.title,created:N.created,currentThreads:I.length});const j={threadId:b,title:N.title||`Thread ${b.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};Q.current!==b&&(!Q.current&&ee.messages.length<=1&&(qe.current=b),_(b)),S.startTransition(()=>{k(D=>{const U=D.byId[b];return U?U.title===j.title&&U.updatedAt===j.updatedAt&&U.messageCount===j.messageCount?D:{byId:{...D.byId,[b]:j},order:D.order}:{byId:{...D.byId,[b]:j},order:[b,...D.order]}})})},[ee.messages.length]),{startStream:yr,stop:Pn,isStreaming:xn,error:Yt,setAuthToken:vn}=Tg({baseUrl:d,onThreadInfo:er,onMessageEvent:Z,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:Rn});S.useEffect(()=>{xe.current=xn},[xn]),S.useEffect(()=>{if(!ir())return;Me.current!==null&&(window.clearTimeout(Me.current),Me.current=null);const N=I.map(j=>`${j.threadId}:${j.updatedAt??""}:${j.messageCount??""}`).join("|");if(I.length===0){try{oi(C)}catch{}Pe.current="";return}if(N===Pe.current)return;const b=()=>{try{const j=I.slice(0,ni);ii(C,j),Pe.current=N}catch{}finally{Me.current=null}};return Me.current=window.setTimeout(()=>{tc(b),Me.current=null},bo),()=>{Me.current!==null&&(window.clearTimeout(Me.current),Me.current=null)}},[I,st]),S.useEffect(()=>{var D;const N=l.getAuthToken();vn(N);const b=U=>{const G=si(f,U);Ue.current!==G&&(Ue.current=G,Qe.current=!1),E(G);const ve=rc(G);S.startTransition(()=>{k(ai(ve))}),Qe.current||(Qe.current=!0,pe().catch(()=>{}))};b(N);const j=(D=l.onTokenChange)==null?void 0:D.call(l,U=>{vn(U),y(),b(U)});return()=>{j==null||j()}},[l,f,vn,y,pe]);const On=S.useCallback(async N=>{const b=`temp-${Date.now()}`,j={threadId:b,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(D=>({byId:{...D.byId,[b]:j},order:[b,...D.order]})),_(b);try{const D=await l.createThread(N),U=typeof D=="string"?D:D.threadId;return k(G=>{const ve=G.byId[b];if(!ve)return G;const me={...G.byId};delete me[b],me[U]={...ve,threadId:U};const he=G.order.map(He=>He===b?U:He);return{byId:me,order:he}}),_(U),setTimeout(()=>pe(),10),U}catch(D){throw k(U=>{if(!U.byId[b])return U;const G={...U.byId};delete G[b];const ve=U.order.filter(me=>me!==b);return{byId:G,order:ve}}),_(null),D}},[l,pe]),tr=S.useCallback(async N=>{await l.deleteThread(N);let b=null;k(j=>{if(!j.byId[N])return j;const D={...j.byId};delete D[N];const U=j.order.filter(ve=>ve!==N),G={byId:D,order:U};return b=li(G),G}),b&&st(b,{immediate:!0}),un(N),Q.current===N&&(qe.current=N,_(null),Q.current=null,_e.current=null,dn()),await pe()},[l,dn,un,pe,st]),Sr=S.useCallback(async(N,b)=>{try{await l.updateThread(N,b),k(j=>{const D=j.byId[N];return D?{byId:{...j.byId,[N]:{...D,title:b}},order:j.order}:j})}catch(j){throw await pe(),j}},[l,pe]),It=S.useCallback(async(N,b,j,D=!1)=>{await ot(async()=>{if(qe.current===N&&!D){qe.current=null;return}if(Ye.current===N&&!D)return;_(he=>he===N?he:N),Q.current=N;const U=!D&&!b&&!j;let G=!1;if(U){const he=Ce.current.get(N);if(he)cn(he),G=!0;else{const He=v(N);He&&(Ce.current.set(N,He),cn(He),G=!0)}}const ve=D||!G||!!b||!!j,me=async he=>{he&&V(!0),Ye.current=N;try{const He=await l.getMessages({threadId:N,checkpointId:b,checkpointNs:j});mt(He,"replace",N)}catch(He){throw(!G||D||he)&&(i==null||i(String(He))),He}finally{Ye.current=null,he&&V(!1)}};ve?await me(!0):U&&G&&me(!1).catch(he=>{console.warn("[ChatSessionProvider] Background refresh failed:",he)})},`loadThread-${N}`)},[l,cn,mt,ot,i]),Cr=S.useCallback(async()=>{await ot(async()=>{const N=Q.current;N&&un(N),qe.current=null,_(null),Q.current=null,_e.current=null,dn(),H(void 0),de(void 0);try{localStorage.removeItem("lastThreadId")}catch(b){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",b)}},"clearCurrentThread")},[dn,un,ot]),oe=S.useCallback(async N=>{const b=await l.listCheckpoints(N);return hg(b,N)},[l]),be=S.useCallback(async(N,b)=>{if(!Q.current)throw new Error("No active thread");await It(Q.current,N,b??void 0,!0)},[It]),Fe=S.useCallback(async()=>{if(!Q.current)throw new Error("No active thread");await It(Q.current,void 0,void 0,!0)},[It]),et=S.useCallback(async N=>{if(!Q.current)throw new Error("No active thread");if(K||!O)return;const b=B;if(b){X(!0);try{const j=Q.current,D=await l.getMessages({threadId:j,checkpointId:z,checkpointNs:ge,limit:(N==null?void 0:N.limit)??Eg,beforeId:b});mt(D,"prepend",j??void 0)}finally{X(!1)}}},[l,mt,O,z,ge,B,K]),bt=S.useCallback(async(N,b)=>{var dt;const j=Q.current;!j&&!(b!=null&&b.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const D=(b==null?void 0:b.attachments)||[],{contentParts:U,filesInfo:G}=await mg(l,D),ve=[...U];N&&N.trim()&&ve.push({type:"text",text:N.trim()});const me={id:((dt=crypto.randomUUID)==null?void 0:dt.call(crypto))||`user-${Date.now()}`,role:"user",content:ve,createdAt:new Date().toISOString(),checkpointId:(b==null?void 0:b.checkpointId)??ee.lastCheckpointId??void 0,checkpointNs:(b==null?void 0:b.checkpointNs)??ee.lastCheckpointNs??void 0};M(me);const he={...me,content:ve},He={...(b==null?void 0:b.payloadExtras)??{}},Ge=D.length>0,Xe={...j?{threadId:j}:{},payload:{messages:[he],files_info:G,...o&&Ge&&s?{active_agent:s}:{},...He},checkpointId:(b==null?void 0:b.checkpointId)??ee.lastCheckpointId??void 0,checkpointNs:(b==null?void 0:b.checkpointNs)??ee.lastCheckpointNs??void 0,nodeFilter:b==null?void 0:b.nodeFilter,config:b==null?void 0:b.config};yr(Xe,{onError:yt=>{console.warn("[ChatSessionProvider] Stream error:",yt)},onOpen:({threadId:yt,created:fn})=>{!Q.current&&yt&&(ee.messages.length<=1&&(qe.current=yt),_(yt))},onGap:Rn})},[l,o,s,Rn,ee.lastCheckpointId,ee.lastCheckpointNs,ee.messages.length,M,yr]),Mt=S.useCallback(async(N,b,j)=>{var U,G;const D=Q.current;if(!D)throw new Error("No active thread to handle interrupt");try{const ve=b?j??!0:!1;try{je({type:"interrupt_response",payload:{interruptId:N}})}catch(yt){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",yt)}const me=`${d}/runs/resume`,he=(U=l.getAuthToken)==null?void 0:U.call(l),He=await fetch(me,{method:"POST",headers:{"Content-Type":"application/json",...he?{Authorization:`Bearer ${he}`}:{}},body:JSON.stringify({thread_id:D,value:ve})});if(!He.ok)throw new Error(`Resume failed with status ${He.status}`);const Ge=(G=He.body)==null?void 0:G.getReader();if(!Ge)throw new Error("No response body for resume stream");const Xe=new TextDecoder;let dt="";for(;;){const{done:yt,value:fn}=await Ge.read();if(yt)break;dt+=Xe.decode(fn,{stream:!0});const ht=dt.split(`
|
|
39
|
-
`);dt=ht.pop()||"";for(const Er of ht)if(Er.startsWith("data: ")){const Va=Er.slice(6);try{const so=JSON.parse(Va);je({type:"event",payload:{ev:so}})}catch(so){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",so)}}}}catch(ve){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,ve),ve}},[l,je,It,d]);S.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[A,a]),S.useEffect(()=>((async()=>{try{if(pe().catch(b=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",b),i==null||i(String(b))}),!r&&!t)try{const b=localStorage.getItem("lastThreadId");b&&(_(b),n&&await It(b))}catch(b){console.warn("[ChatSessionProvider] Failed to restore last thread:",b)}else t&&n&&await It(t)}catch(b){console.error("[ChatSessionProvider] Initialization failed:",b),i==null||i(String(b))}})(),()=>{}),[]),S.useEffect(()=>{const N=Q.current;if(!N||_e.current!==N)return;const b={threadId:N,messages:ee.messages.slice(),hasMore:O,nextCursor:B,checkpointId:ee.lastCheckpointId??null,checkpointNs:ee.lastCheckpointNs??null},j=Ce.current.get(N);(!j||j.messages.length!==b.messages.length||j.messages.some((U,G)=>{var ve;return(U==null?void 0:U.id)!==((ve=b.messages[G])==null?void 0:ve.id)})||(j==null?void 0:j.hasMore)!==b.hasMore||(j==null?void 0:j.nextCursor)!==b.nextCursor||(j==null?void 0:j.checkpointId)!==b.checkpointId||(j==null?void 0:j.checkpointNs)!==b.checkpointNs)&&(Ce.current.set(N,b),Re.current&&window.clearTimeout(Re.current),Re.current=window.setTimeout(()=>{try{g(b,100)}catch(U){console.warn("[ChatSessionProvider] Failed to persist thread payload:",U)}},bo))},[O,B,ee.lastCheckpointId,ee.lastCheckpointNs,ee.messages]);const nr=S.useMemo(()=>({threads:I,currentThreadId:A,isLoadingThreads:R,isLoadingThread:F,setCurrentThreadId:_,createThread:On,deleteThread:tr,renameThread:Sr,refreshThreads:pe,loadThread:It,clearCurrentThread:Cr,listCheckpoints:oe,navigateToCheckpoint:be,returnToLatest:Fe}),[Cr,On,A,tr,F,R,oe,It,be,pe,Sr,Fe,I]),Tr=S.useMemo(()=>({messages:ee.messages,assemblingId:ee.assemblingId,lastUserMessage:null,hasMoreHistory:O,isLoadingHistory:K,send:bt,stop:Pn,loadOlderMessages:et,clearMessages:dn,handleInterrupt:Mt}),[dn,Mt,O,K,et,ee.assemblingId,ee.messages,bt,Pn]),kr=S.useMemo(()=>({isStreaming:xn,error:Yt,streamingAssistantId:ee.assemblingId,lastCheckpointId:ee.lastCheckpointId??null,lastCheckpointNs:ee.lastCheckpointNs??null}),[xn,ee.assemblingId,ee.lastCheckpointId,ee.lastCheckpointNs,Yt]);return c.jsx(kg.Provider,{value:!0,children:c.jsx(ec.Provider,{value:kr,children:c.jsx(Zl.Provider,{value:nr,children:c.jsx(Ql.Provider,{value:Tr,children:e})})})})}function yo(){const e=S.useContext(Zl);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ci(){const e=S.useContext(Ql);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function oc(){const e=S.useContext(ec);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function So({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 c.jsx(fg,{apiConfig:t,children:c.jsx(Rg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function te(...e){return Bp.twMerge(zp.clsx(e))}const Pg=io.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"}}),We=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Mn.Slot:"button";return c.jsx(i,{className:te(Pg({variant:t,size:n,className:e})),ref:s,...o})});We.displayName="Button";const sc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:te("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}));sc.displayName="Textarea";function Og({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=S.useState(e),[w,v]=S.useTransition(),g=S.useRef(null);S.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const y=S.useCallback(async A=>{A&&A.preventDefault();const _=(h??"").trim();!_&&!f||v(()=>{try{const R=i(_);R&&typeof R.then=="function"?R.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),C=S.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=S.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),y()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[y,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void y(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(sc,{ref:g,value:h,onChange:C,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(We,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(re.Square,{size:16})}):c.jsx(We,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(re.Send,{size:16})})})]})})}const Mg=S.memo(Og),Co=0,bn=1,ar=2,ic=4;function ac(e){return()=>e}function Dg(e){e()}function lc(e,t){return n=>e(t(n))}function cc(e,t){return()=>e(t)}function Lg(e,t){return n=>e(t,n)}function ui(e){return e!==void 0}function Fg(...e){return()=>{e.map(Dg)}}function lr(){}function To(e,t){return t(e),e}function $g(e,t){return t(e)}function tt(...e){return e}function Ke(e,t){return e(bn,t)}function De(e,t){e(Co,t)}function di(e){e(ar)}function at(e){return e(ic)}function fe(e,t){return Ke(e,Lg(t,Co))}function Ut(e,t){const n=e(bn,r=>{n(),t(r)});return n}function uc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function dc(e,t){return e===t}function nt(e=dc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ee(e){return t=>n=>{e(n)&&t(n)}}function se(e){return t=>lc(t,e)}function Jt(e){return t=>()=>{t(e)}}function W(e,...t){const n=zg(...t);return(r,o)=>{switch(r){case ar:di(e);return;case bn:return Ke(e,n(o))}}}function Zt(e,t){return n=>r=>{n(t=e(t,r))}}function $n(e){return t=>n=>{e>0?e--:t(n)}}function pn(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);Ke(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function zg(...e){return t=>e.reduceRight($g,t)}function Bg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case bn:return s?n===s?void 0:(r(),n=s,t=Ke(e,s),t):(r(),lr);case ar:r(),n=null;return}}}function J(e){let t=e;const n=ze();return(r,o)=>{switch(r){case Co:t=o;break;case bn:{o(t);break}case ic:return t}return n(r,o)}}function xt(e,t){return To(J(t),n=>fe(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case Co:e.slice().forEach(r=>{r(n)});return;case ar:e.splice(0,e.length);return;case bn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function jt(e){return To(ze(),t=>fe(e,t))}function Ve(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Hg(),singleton:n}}const Hg=()=>Symbol();function Ug(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 ct(...e){const t=ze(),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);Ke(s,l=>{n[i]=l,r=r|a,r===o&&De(t,n)})}),function(s,i){switch(s){case ar:{di(t);return}case bn:return r===o&&i(n),Ke(t,i)}}}function ke(e,t=dc){return W(e,nt(t))}function fi(...e){return function(t,n){switch(t){case ar:return;case bn:return Fg(...e.map(r=>Ke(r,n)))}}}var Et=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Et||{});const Wg={0:"debug",3:"error",1:"log",2:"warn"},Vg=()=>typeof globalThis>"u"?window:globalThis,yn=Ve(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=Vg().VIRTUOSO_LOG_LEVEL)!=null?o:at(e);r>=s&&console[Wg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function zn(e,t,n){return hi(e,t,n).callbackRef}function hi(e,t,n){const r=S.useRef(null);let o=i=>{};const s=S.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 Kg(e,t,n,r,o,s,i,a,l){const u=S.useCallback(d=>{const f=qg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?fc("column-gap",getComputedStyle(d).columnGap,o):fc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return hi(u,n,l)}function qg(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),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Et.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function fc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}function hc(e,t,n){const r=S.useRef(null),o=S.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=hi(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const St=Ve(()=>{const e=ze(),t=ze(),n=J(0),r=ze(),o=J(0),s=ze(),i=ze(),a=J(0),l=J(0),u=J(0),d=J(0),f=ze(),h=ze(),p=J(!1),w=J(!1),v=J(!1);return fe(W(e,se(({scrollTop:g})=>g)),t),fe(W(e,se(({scrollHeight:g})=>g)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Or={lvl:0};function pc(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 Je(e){return e===Or}function Mr(e,t){if(!Je(e))return t===e.k?e.v:t<e.k?Mr(e.l,t):Mr(e.r,t)}function Wt(e,t,n="k"){if(Je(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Wt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Wt(e.l,t,n)}function _t(e,t,n){return Je(e)?xc(t,n,1):t===e.k?ut(e,{k:t,v:n}):t<e.k?vc(ut(e,{l:_t(e.l,t,n)})):vc(ut(e,{r:_t(e.r,t,n)}))}function cr(){return Or}function ko(e,t,n){if(Je(e))return[];const r=Wt(e,t)[0];return Gg(mi(e,r,n))}function pi(e,t){if(Je(e))return Or;const{k:n,l:r,r:o}=e;if(t===n){if(Je(r))return o;if(Je(o))return r;{const[s,i]=gc(r);return Eo(ut(e,{k:s,l:mc(r),v:i}))}}else return t<n?Eo(ut(e,{l:pi(r,t)})):Eo(ut(e,{r:pi(o,t)}))}function Bn(e){return Je(e)?[]:[...Bn(e.l),{k:e.k,v:e.v},...Bn(e.r)]}function mi(e,t,n){if(Je(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(mi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(mi(s,t,n))),a}function Eo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(gi(t))return wc(ut(e,{lvl:n-1}));if(!Je(t)&&!Je(t.r))return ut(t.r,{l:ut(t,{r:t.r.l}),lvl:n,r:ut(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(gi(e))return xi(ut(e,{lvl:n-1}));if(!Je(r)&&!Je(r.l)){const o=r.l,s=gi(o)?r.lvl-1:r.lvl;return ut(o,{l:ut(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:xi(ut(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ut(e,t){return xc(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 mc(e){return Je(e.r)?e.l:Eo(ut(e,{r:mc(e.r)}))}function gi(e){return Je(e)||e.lvl>e.r.lvl}function gc(e){return Je(e.r)?[e.k,e.v]:gc(e.r)}function xc(e,t,n,r=Or,o=Or){return{k:e,l:r,lvl:n,r:o,v:t}}function vc(e){return xi(wc(e))}function wc(e){const{l:t}=e;return!Je(t)&&t.lvl===e.lvl?ut(t,{r:ut(e,{l:t.r})}):e}function xi(e){const{lvl:t,r:n}=e;return!Je(n)&&!Je(n.r)&&n.lvl===t&&n.r.lvl===t?ut(n,{l:ut(e,{r:n.l}),lvl:t+1}):e}function Gg(e){return pc(e,({k:t,v:n})=>({index:t,value:n}))}function bc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Dr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const vi=Ve(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function yc(e,t,n){return e[Io(e,t,n)]}function Io(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 Yg(e,t,n,r){const o=Io(e,t,r),s=Io(e,n,r,o);return e.slice(o,s+1)}function Sn(e,t){return Math.round(e.getBoundingClientRect()[t])}function No(e){return!Je(e.groupOffsetTree)}function wi({index:e},t){return t===e?0:t<e?-1:1}function Xg(){return{groupIndices:[],groupOffsetTree:cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:cr()}}function Jg(e,t){let n=Je(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Je(e)){e=_t(e,0,s);continue}const a=ko(e,i-1,o+1);if(a.some(ox(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=pi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=_t(e,o+1,h));u&&(e=_t(e,i,s))}return[e,n]}function Zg(e){return typeof e.groupIndex<"u"}function Qg({offset:e},t){return t===e?0:t<e?-1:1}function Lr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=yc(t,e,wi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Sc(e,t){if(!No(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Cc(e,t,n){if(Zg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Sc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function ex(e,t,n,r=0){return r>0&&(t=Math.max(t,yc(e,r,wi).offset)),pc(Yg(e,t,n,Qg),rx)}function tx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Et.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Je(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>_t(_t(w,v,h),v+1,p),i)}else[i,a]=Jg(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=bi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>_t(h,p,Lr(p,f,o)),cr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function nx(e){return Bn(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 Tc(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 bi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Io(o,t-1,wi),a=o[l].offset;const u=Wt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Wt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of ko(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function rx(e){return{index:e.index,value:e}}function ox(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 sx={offsetHeight:"height",offsetWidth:"width"},Qt=Ve(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=xt(r,0),s=ze(),i=ze(),a=J(0),l=J([]),u=J(void 0),d=J(void 0),f=J((T,k)=>Sn(T,sx[k])),h=J(void 0),p=J(0),w=Xg(),v=xt(W(n,Le(l,e,p),Zt(tx,w),nt()),w),g=xt(W(l,nt(),Zt((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),se(({prev:T})=>T)),[]);fe(W(l,Ee(T=>T.length>0),Le(v,p),se(([T,k,I])=>{const A=T.reduce((_,R,L)=>_t(_,R,Lr(R,k.offsetTree,I)||L),cr());return{...k,groupIndices:T,groupOffsetTree:A}})),v),fe(W(r,Le(v),Ee(([T,{lastIndex:k}])=>T<k),se(([T,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:T}])),n),fe(u,d);const x=xt(W(u,se(T=>T===void 0)),!0);fe(W(d,Ee(T=>T!==void 0&&Je(at(v).sizeTree)),se(T=>[{endIndex:0,size:T,startIndex:0}])),n);const y=jt(W(n,Le(v),Zt(({sizes:T},[k,I])=>({changed:I!==T,sizes:I}),{changed:!1,sizes:w}),se(T=>T.changed)));Ke(W(a,Zt((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),se(T=>T.diff)),T=>{const{groupIndices:k}=at(v);if(T>0)De(t,!0),De(s,T+Tc(T,k));else if(T<0){const I=at(g);I.length>0&&(T-=Tc(-T,I)),De(i,T)}}),Ke(W(a,Le(e)),([T,k])=>{T<0&&k("`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},Et.ERROR)});const C=jt(s);fe(W(s,Le(v),se(([T,k])=>{const I=k.groupIndices.length>0,A=[],_=k.lastSize;if(I){const R=Mr(k.sizeTree,0);let L=0,F=0;for(;L<T;){const O=k.groupIndices[F],Y=k.groupIndices.length===F+1?1/0:k.groupIndices[F+1]-O-1;A.push({endIndex:O,size:R,startIndex:O}),A.push({endIndex:O+1+Y-1,size:_,startIndex:O+1}),F++,L+=Y+1}const V=Bn(k.sizeTree);return L!==T&&V.shift(),V.reduce((O,{k:Y,v:K})=>{let X=O.ranges;return O.prevSize!==0&&(X=[...O.ranges,{endIndex:Y+T-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:Y+T,prevSize:K,ranges:X}},{prevIndex:T,prevSize:0,ranges:A}).ranges}return Bn(k.sizeTree).reduce((R,{k:L,v:F})=>({prevIndex:L+T,prevSize:F,ranges:[...R.ranges,{endIndex:L+T-1,size:R.prevSize,startIndex:R.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const E=jt(W(i,Le(v,p),se(([T,{offsetTree:k},I])=>{const A=-T;return Lr(A,k,I)})));return fe(W(i,Le(v,p),se(([T,k,I])=>{if(k.groupIndices.length>0){if(Je(k.sizeTree))return k;let A=cr();const _=at(g);let R=0,L=0,F=0;for(;R<-T;){F=_[L];const V=_[L+1]-F-1;L++,R+=V+1}if(A=Bn(k.sizeTree).reduce((V,{k:O,v:Y})=>_t(V,Math.max(0,O+T),Y),A),R!==-T){const V=Mr(k.sizeTree,F);A=_t(A,0,V);const O=Wt(k.sizeTree,-T+1)[1];A=_t(A,1,O)}return{...k,sizeTree:A,...bi(k.offsetTree,0,A,I)}}else{const A=Bn(k.sizeTree).reduce((_,{k:R,v:L})=>_t(_,Math.max(0,R+T),L),cr());return{...k,sizeTree:A,...bi(k.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:y,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},tt(yn,vi),{singleton:!0});function ix(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const kc=Ve(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=jt(W(s,se(ix)));return fe(W(a,se(l=>l.totalCount)),n),fe(W(a,se(l=>l.groupIndices)),e),fe(W(ct(o,t,r),Ee(([l,u])=>No(u)),se(([l,u,d])=>Wt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),nt(),se(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},tt(Qt,St)),Cn=Ve(([{log:e}])=>{const t=J(!1),n=jt(W(t,Ee(r=>r),nt()));return Ke(t,r=>{r&&at(e)("props updated",{},Et.DEBUG)}),{didMount:n,propsReady:t}},tt(yn),{singleton:!0}),ax=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Ec(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ax)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Fr=Ve(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=ze(),w=ze(),v=J(0);let g=null,x=null,y=null;function C(){g&&(g(),g=null),y&&(y(),y=null),x&&(clearTimeout(x),x=null),De(l,!1)}return fe(W(p,Le(n,f,r,v,a,i,h),Le(e,s,o),se(([[E,T,k,I,A,_,R,L],F,V,O])=>{const Y=Ec(E),{align:K,behavior:X,offset:B}=Y,$=I-1,z=Cc(Y,T,$);let H=Lr(z,T.offsetTree,F)+_;K==="end"?(H+=V+Wt(T.sizeTree,z)[1]-k+O,z===$&&(H+=R)):K==="center"?H+=(V+Wt(T.sizeTree,z)[1]-k+O)/2:H-=A,B&&(H+=B);const ge=de=>{C(),de?(L("retrying to scroll to",{location:E},Et.DEBUG),De(p,E)):(De(w,!0),L("list did not change, scroll successful",{},Et.DEBUG))};if(C(),X==="smooth"){let de=!1;y=Ke(t,ee=>{de=de||ee}),g=Ut(d,()=>{ge(de)})}else g=Ut(W(t,lx(150)),ge);return x=setTimeout(()=>{C()},1200),De(l,!0),L("scrolling from index to",{behavior:X,index:z,top:H},Et.DEBUG),{behavior:X,top:H}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},tt(Qt,St,yn),{singleton:!0});function lx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function yi(e,t){e==0?t():requestAnimationFrame(()=>{yi(e-1,t)})}function Si(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const $r=Ve(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=J(!0),l=J(0),u=J(!0);return fe(W(i,Le(l),Ee(([d,f])=>!!f),Jt(!1)),a),fe(W(i,Le(l),Ee(([d,f])=>!!f),Jt(!1)),u),Ke(W(ct(t,i),Le(a,n,e,u),Ee(([[,d],f,{sizeTree:h},p,w])=>d&&(!Je(h)||ui(p))&&!f&&!w),Le(l)),([,d])=>{Ut(o,()=>{De(u,!0)}),yi(4,()=>{Ut(r,()=>{De(a,!0)}),De(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},tt(Qt,St,Fr,Cn),{singleton:!0});function Ic(e,t){return Math.abs(e-t)<1.01}const zr="up",Br="down",cx="none",ux={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},dx=0,Hr=Ve(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=ze(),u=ze(),d=J(4),f=J(dx),h=xt(W(fi(W(ke(o),$n(1),Jt(!0)),W(ke(o),$n(1),Jt(!1),uc(100))),nt()),!1),p=xt(W(fi(W(n,Jt(!0)),W(n,Jt(!1),uc(200))),nt()),!1);fe(W(ct(ke(o),ke(f)),se(([y,C])=>y<=C),nt()),a),fe(W(a,pn(50)),u);const w=jt(W(ct(r,ke(s),ke(t),ke(e),ke(d)),Zt((y,[{scrollHeight:C,scrollTop:E},T,k,I,A])=>{const _=E+T-C>-A,R={scrollHeight:C,scrollTop:E,viewportHeight:T};if(_){let F,V;return E>y.state.scrollTop?(F="SCROLLED_DOWN",V=y.state.scrollTop-E):(F="SIZE_DECREASED",V=y.state.scrollTop-E||y.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:V,state:R}}let L;return R.scrollHeight>y.state.scrollHeight?L="SIZE_INCREASED":T<y.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":E<y.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:R}},ux),nt((y,C)=>y&&y.atBottom===C.atBottom))),v=xt(W(r,Zt((y,{scrollHeight:C,scrollTop:E,viewportHeight:T})=>{if(Ic(y.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:E};{const k=C-(E+T)<1;return y.scrollTop!==E&&k?{changed:!0,jump:y.scrollTop-E,scrollHeight:C,scrollTop:E}:{changed:!0,jump:0,scrollHeight:C,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ee(y=>y.changed),se(y=>y.jump)),0);fe(W(w,se(y=>y.atBottom)),i),fe(W(i,pn(50)),l);const g=J(Br);fe(W(r,se(({scrollTop:y})=>y),nt(),Zt((y,C)=>at(p)?{direction:y.direction,prevScrollTop:C}:{direction:C<y.prevScrollTop?zr:Br,prevScrollTop:C},{direction:Br,prevScrollTop:0}),se(y=>y.direction)),g),fe(W(r,pn(50),Jt(cx)),g);const x=J(0);return fe(W(h,Ee(y=>!y),Jt(0)),x),fe(W(o,pn(100),Le(h),Ee(([y,C])=>!!C),Zt(([y,C],[E])=>[C,E],[0,0]),se(([y,C])=>C-y)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},tt(St)),Ao="top",jo="bottom",Nc="none";function Ac(e,t,n){return typeof e=="number"?n===zr&&t===Ao||n===Br&&t===jo?e:0:n===zr?t===Ao?e.main:e.reverse:t===jo?e.main:e.reverse}function jc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Ci=Ve(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=J(0),a=J(0),l=J(0),u=xt(W(ct(ke(r),ke(o),ke(n),ke(s,Dr),ke(l),ke(i),ke(t),ke(e),ke(a)),se(([d,f,h,[p,w],v,g,x,y,C])=>{const E=d-y,T=g+x,k=Math.max(h-E,0);let I=Nc;const A=jc(C,Ao),_=jc(C,jo);return p-=y,p+=h+x,w+=h+x,w-=y,p>d+T-A&&(I=zr),w<d-k+f+_&&(I=Br),I!==Nc?[Math.max(E-h-Ac(v,Ao,I)-A,0),E-k-x+f+Ac(v,jo,I)+_]:null}),Ee(d=>d!=null),nt(Dr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},tt(St),{singleton:!0});function fx(e,t,n){if(No(t)){const r=Sc(e,t);return[{index:Wt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ti={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function _o(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:Rc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:Rc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function _c(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=Si(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return _o(u,[],a,o,n,r)}function Rc(e,t,n){if(e.length===0)return[];if(!No(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ko(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Hn=Ve(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=J([]),g=J(0),x=ze();fe(s.topItemsIndexes,v);const y=xt(W(ct(p,w,ke(l,Dr),ke(o),ke(r),ke(u),d,ke(v),ke(t),ke(n),e),Ee(([k,I,,A,,,,,,,_])=>{const R=_&&_.length!==A;return k&&!I&&!R}),se(([,,[k,I],A,_,R,L,F,V,O,Y])=>{const K=_,{offsetTree:X,sizeTree:B}=K,$=at(g);if(A===0)return{...Ti,totalCount:A};if(k===0&&I===0)return $===0?{...Ti,totalCount:A}:_c($,R,_,V,O,Y||[]);if(Je(B))return $>0?null:_o(fx(Si(R,A),K,Y),[],A,O,K,V);const z=[];if(F.length>0){const je=F[0],Te=F[F.length-1];let q=0;for(const M of ko(B,je,Te)){const Z=M.value,ne=Math.max(M.start,je),Q=Math.min(M.end,Te);for(let le=ne;le<=Q;le++)z.push({data:Y==null?void 0:Y[le],index:le,offset:q,size:Z}),q+=Z}}if(!L)return _o([],z,A,O,K,V);const H=F.length>0?F[F.length-1]+1:0,ge=ex(X,k,I,H);if(ge.length===0)return null;const de=A-1,ee=To([],je=>{for(const Te of ge){const q=Te.value;let M=q.offset,Z=Te.start;const ne=q.size;if(q.offset<k){Z+=Math.floor((k-q.offset+O)/(ne+O));const le=Z-Te.start;M+=le*ne+le*O}Z<H&&(M+=(H-Z)*ne,Z=H);const Q=Math.min(Te.end,de);for(let le=Z;le<=Q&&!(M>=I);le++)je.push({data:Y==null?void 0:Y[le],index:le,offset:M,size:ne}),M+=ne+O}});return _o(ee,z,A,O,K,V)}),Ee(k=>k!==null),nt()),Ti);fe(W(e,Ee(ui),se(k=>k==null?void 0:k.length)),o),fe(W(y,se(k=>k.topListHeight)),f),fe(f,a),fe(W(y,se(k=>[k.top,k.bottom])),i),fe(W(y,se(k=>k.items)),x);const C=jt(W(y,Ee(({items:k})=>k.length>0),Le(o,e),Ee(([{items:k},I])=>k[k.length-1].originalIndex===I-1),se(([,k,I])=>[k-1,I]),nt(Dr),se(([k])=>k))),E=jt(W(y,pn(200),Ee(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),se(({items:k})=>k[0].index),nt())),T=jt(W(y,Ee(({items:k})=>k.length>0),se(({items:k})=>{let I=0,A=k.length-1;for(;k[I].type==="group"&&I<A;)I++;for(;k[A].type==="group"&&A>I;)A--;return{endIndex:k[A].index,startIndex:k[I].index}}),nt(bc)));return{endReached:C,initialItemCount:g,itemsRendered:x,listState:y,rangeChanged:T,startReached:E,topItemsIndexes:v,...h}},tt(Qt,kc,Ci,$r,Fr,Hr,Cn,vi),{singleton:!0}),Pc=Ve(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=xt(W(ct(n,e,r,t,o),se(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return fe(ke(i),s),{totalListHeight:i,totalListHeightChanged:s}},tt(St,Hn),{singleton:!0}),hx=Ve(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=xt(W(ct(n,e,t),Ee(([o])=>o),se(([,o,s])=>Math.max(0,o-s)),pn(0),nt()),0);return{alignToBottom:n,paddingTopAddition:r}},tt(St,Pc),{singleton:!0}),Oc=Ve(()=>({context:J(null)})),px=({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,Mc=Ve(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=ze();return fe(W(d,Le(t,l,n,s,o,r,a),Le(e),se(([[f,h,p,w,v,g,x,y],C])=>{const{align:E,behavior:T,calculateViewLocation:k=px,done:I,...A}=f,_=Cc(f,h,w-1),R=Lr(_,h.offsetTree,C)+v+g,L=R+Wt(h.sizeTree,_)[1],F=y+g,V=y+p-x,O=k({itemBottom:L,itemTop:R,locationParams:{align:E,behavior:T,...A},viewportBottom:V,viewportTop:F});return O?I&&Ut(W(i,Ee(Y=>!Y),$n(at(i)?1:2)),I):I&&I(),O}),Ee(f=>f!==null)),u),{scrollIntoView:d}},tt(Qt,St,Fr,Hn,yn),{singleton:!0});function Dc(e){return e?e==="smooth"?"smooth":"auto":!1}const mx=(e,t)=>typeof e=="function"?Dc(e(t)):t&&Dc(e),gx=Ve(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=J(!1),v=ze();let g=null;function x(T){De(i,{align:"end",behavior:T,index:"LAST"})}Ke(W(ct(W(ke(t),$n(1)),l),Le(ke(w),s,a,f),se(([[T,k],I,A,_,R])=>{let L=k&&_,F="auto";return L&&(F=mx(I,A||R),L=L&&!!F),{followOutputBehavior:F,shouldFollow:L,totalCount:T}}),Ee(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:k})=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("following output to ",{totalCount:k},Et.DEBUG),x(T)}):g=Ut(e,()=>{at(d)("following output to ",{totalCount:k},Et.DEBUG),x(T),g=null})});function y(T){const k=Ut(o,I=>{T&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(at(d)("scrolling to bottom due to increased size",{},Et.DEBUG),x("auto"))});setTimeout(k,100)}Ke(W(ct(ke(w),t,u),Ee(([T,,k])=>T&&k),Zt(({value:T},[,k])=>({refreshed:T===k,value:k}),{refreshed:!1,value:0}),Ee(({refreshed:T})=>T),Le(w,t)),([,T])=>{at(a)&&y(T!==!1)}),Ke(v,()=>{y(at(w)!==!1)}),Ke(ct(ke(w),o),([T,k])=>{T&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=J(null),E=ze();return fe(fi(W(ke(r),se(T=>{var k;return(k=T==null?void 0:T.length)!=null?k:0})),W(ke(t))),E),Ke(W(ct(W(E,$n(1)),l),Le(ke(C),a,f,h),se(([[T,k],I,A,_,R])=>k&&A&&(I==null?void 0:I({context:R,totalCount:T,scrollingInProgress:_}))),Ee(T=>!!T),pn(0)),T=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("scrolling into view",{}),De(p,T)}):g=Ut(e,()=>{at(d)("scrolling into view",{}),De(p,T),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:C}},tt(Qt,Hr,Fr,$r,Cn,yn,St,Oc,Mc)),xx=Ve(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(W(a,Le(s),Ee(([,l])=>l!==0),Le(o,r,t,n,e),se(([[,l],u,d,f,h,p=[]])=>_c(l,u,d,f,h,p))),i),{}),tt(Qt,$r,Hn,Cn),{singleton:!0}),vx=Ve(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return Ke(W(e,Le(r),Ee(([,o])=>o!==0),se(([,o])=>({top:o}))),o=>{Ut(W(n,$n(1),Ee(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{De(t,o)})})}),{initialScrollTop:r}},tt(Cn,St,Hn),{singleton:!0}),Lc=Ve(([{scrollVelocity:e}])=>{const t=J(!1),n=ze(),r=J(!1);return fe(W(e,Le(r,t,n),Ee(([o,s])=>!!s),se(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),nt()),t),Ke(W(ct(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}},tt(Hr),{singleton:!0}),ki=Ve(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=J(!1),i=J(void 0);return fe(W(ct(n,r),se(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),fe(W(t,Le(r),se(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},tt(St)),wx=Ve(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=ze(),d=J(void 0),f=J(null),h=J(null);return fe(a,f),fe(l,h),Ke(W(u,Le(t,r,i,f,h,n)),([p,w,v,g,x,y,C])=>{const E=nx(w.sizeTree);g&&x!==null&&y!==null&&(v=x.scrollTop-y.offsetTop),v-=C,p({ranges:E,scrollTop:v})}),fe(W(d,Ee(ui),se(bx)),o),fe(W(s,Le(d),Ee(([,p])=>p!==void 0),nt(),se(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},tt(Qt,St,$r,Cn,ki));function bx(e){return{align:"start",index:0,offset:e.scrollTop}}const yx=Ve(([{topItemsIndexes:e}])=>{const t=J(0);return fe(W(t,Ee(n=>n>=0),se(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},tt(Hn));function Fc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Sx=Fc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Cx=Ve(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=jt(W(l,Le(i),Zt(([,x,y,C],[{bottom:E,items:T,offsetBottom:k,totalCount:I},A])=>{const _=E+k;let R=0;return y===I&&x.length>0&&T.length>0&&(T[0].originalIndex===0&&x[0].originalIndex===0||(R=_-C,R!==0&&(R+=A))),[R,T,I,_]},[0,[],0,0]),Ee(([x])=>x!==0),Le(r,a,n,o,p,w),Ee(([,x,y,C,,,E])=>!E&&!C&&x!==0&&y===zr),se(([[x],,,,,y])=>(y("Upward scrolling compensation",{amount:x},Et.DEBUG),x))));function g(x){x>0?(De(t,{behavior:"auto",top:-x}),De(e,0)):(De(e,0),De(t,{behavior:"auto",top:-x}))}return Ke(W(v,Le(e,s)),([x,y,C])=>{C&&Sx()?De(e,y-x):g(-x)}),Ke(W(ct(xt(s,!1),e,w),Ee(([x,y,C])=>!x&&!C&&y!==0),se(([x,y])=>y),pn(1)),g),fe(W(f,se(x=>({top:-x}))),t),Ke(W(u,Le(h,d),se(([x,{groupIndices:y,lastSize:C,sizeTree:E},T])=>{function k(I){return I*(C+T)}if(y.length===0)return k(x);{let I=0;const A=Mr(E,0);let _=0,R=0;for(;_<x;){_++,I+=A;let L=y.length===R+1?1/0:y[R+1]-y[R]-1;_+L>x&&(I-=A,L=x-_+1),_+=L,I+=k(L),R++}return I}})),x=>{De(e,x),requestAnimationFrame(()=>{De(t,{top:x}),requestAnimationFrame(()=>{De(e,0),De(w,!1)})})}),{deviation:e}},tt(St,Hr,Hn,Qt,yn,vi)),Tx=Ve(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),tt(Ci,xx,Cn,Lc,Pc,vx,hx,ki,Mc,yn,Oc)),$c=Ve(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:y,topItemsIndexes:C,...E},{scrollToIndex:T},k,{topItemCount:I},{groupCounts:A},_])=>(fe(E.rangeChanged,_.scrollSeekRangeChanged),fe(W(_.windowViewportRect,se(R=>R.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:y,scrollToIndex:T,statefulTotalCount:u,trackItemSizes:f,...E,..._,...v,sizes:l,...g}),tt(Qt,$r,St,wx,gx,Hn,Fr,Cx,yx,kc,Tx));function kx(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 Ro=typeof document<"u"?S.useLayoutEffect:S.useEffect;function zc(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=S.createContext({});function l(g,x){g.propsReady&&De(g.propsReady,!1);for(const y of r){const C=g[t.required[y]];De(C,x[y])}for(const y of o)if(y in x){const C=g[t.optional[y]];De(C,x[y])}g.propsReady&&De(g.propsReady,!0)}function u(g){return s.reduce((x,y)=>(x[y]=C=>{const E=g[t.methods[y]];De(E,C)},x),{})}function d(g){return i.reduce((x,y)=>(x[y]=Bg(g[t.events[y]]),x),{})}const f=S.forwardRef((g,x)=>{const{children:y,...C}=g,[E]=S.useState(()=>To(Ug(e),I=>{l(I,C)})),[T]=S.useState(cc(d,E));Ro(()=>{for(const I of i)I in C&&Ke(T[I],C[I]);return()=>{Object.values(T).map(di)}},[C,T,E]),Ro(()=>{l(E,C)}),S.useImperativeHandle(x,ac(u(E)));const k=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(k,{...kx([...r,...o,...i],C),children:y}):y})}),h=g=>{const x=S.useContext(a);return S.useCallback(y=>{De(x[g],y)},[x,g])},p=g=>{const x=S.useContext(a)[g],y=S.useCallback(C=>Ke(x,C),[x]);return S.useSyncExternalStore(y,()=>at(x),()=>at(x))},w=g=>{const x=S.useContext(a)[g],[y,C]=S.useState(cc(at,x));return Ro(()=>Ke(x,E=>{E!==y&&C(ac(E))}),[x,y]),y},v=S.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const y=S.useContext(a)[g];Ro(()=>Ke(y,x),[x,y])},useEmitterValue:v,usePublisher:h}}const Bc=S.createContext(void 0),Hc=S.createContext(void 0),Uc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function Ei(e){return"self"in e}function Ex(e){return"body"in e}function Wc(e,t,n,r=lr,o,s){const i=S.useRef(null),a=S.useRef(null),l=S.useRef(null),u=S.useCallback(h=>{let p,w,v;const g=h.target;if(Ex(g)||Ei(g)){const y=Ei(g)?g:g.defaultView;v=s?y.scrollX:y.scrollY,p=s?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight,w=s?y.innerWidth:y.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Ls.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);S.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;Ei(p)?(g=Math.max(Sn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=Sn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const y=g-v;if(h.top=Math.ceil(Math.max(Math.min(y,h.top),0)),Ic(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ii="-webkit-sticky",Vc="sticky",Ni=Fc(()=>{if(typeof document>"u")return Vc;const e=document.createElement("div");return e.style.position=Ii,e.style.position===Ii?Ii:Vc});function Ai(e){return e}const Ix=Ve(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(Ai),o=J("div"),s=J(lr),i=(a,l=null)=>xt(W(n,se(u=>u[a]),nt()),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")}}),Nx=Ve(([e,t])=>({...e,...t}),tt($c,Ix)),Ax=({height:e})=>c.jsx("div",{style:{height:e}}),jx={overflowAnchor:"none",position:Ni(),zIndex:1},Kc={overflowAnchor:"none"},_x={...Kc,display:"inline-block",height:"100%"},qc=S.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Lt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Lt("windowScrollContainerState"),i=Lt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),u=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),h=Ae("itemSize"),p=Ae("log"),w=Lt("gap"),v=Ae("horizontalDirection"),{callbackRef:g}=Kg(n,h,f,e?lr:a,p,w,o,v,Ae("skipAnimationFrameInResizeObserver")),[x,y]=S.useState(0);ji("deviation",O=>{x!==O&&y(O)});const C=Ae("EmptyPlaceholder"),E=Ae("ScrollSeekPlaceholder")||Ax,T=Ae("ListComponent"),k=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),_=Ae("isSeeking"),R=Ae("groupIndices").length>0,L=Ae("alignToBottom"),F=Ae("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?c.jsx(C,{...vt(C,u)}):c.jsx(T,{...vt(T,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(O=>{const Y=O.originalIndex,K=A(Y+t.firstItemIndex,O.data,u);return _?S.createElement(E,{...vt(E,u),height:O.size,index:O.index,key:K,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?S.createElement(I,{...vt(I,u),"data-index":Y,"data-item-index":O.index,"data-known-size":O.size,key:K,style:jx},d(O.index,u)):S.createElement(k,{...vt(k,u),...Mx(k,O.data),"data-index":Y,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:K,style:v?_x:Kc},R?l(O.index,O.groupIndex,O.data,u):l(O.index,O.data,u))})})}),Rx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Px={outline:"none",overflowX:"auto",position:"relative"},Po=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Ox={position:Ni(),top:0,width:"100%",zIndex:1};function vt(e,t){if(typeof e!="string")return{context:t}}function Mx(e,t){return{item:typeof e=="string"?void 0:t}}const Dx=S.memo(function(){const e=Ae("HeaderComponent"),t=Lt("headerHeight"),n=Ae("HeaderFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),Lx=S.memo(function(){const e=Ae("FooterComponent"),t=Lt("footerHeight"),n=Ae("HeaderFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null});function Gc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Wc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Px:Rx,...o},tabIndex:0,...i,...vt(l,s),children:r})})}function Yc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Wc(a,u,l,w,h);return Uc(()=>{var y;return g.current=h||((y=p.current)==null?void 0:y.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...vt(l,s),children:r})})}const Fx=({children:e})=>{const t=S.useContext(Bc),n=Lt("viewportHeight"),r=Lt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=S.useMemo(()=>lc(n,l=>Sn(l,s?"width":"height")),[n,s]),a=zn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Po(o),children:e})},$x=({children:e})=>{const t=S.useContext(Bc),n=Lt("windowViewportRect"),r=Lt("fixedItemHeight"),o=Ae("customScrollParent"),s=hc(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Po(i),children:e})},zx=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...Ox,marginTop:`${n}px`},o=Ae("context");return c.jsx(t,{style:r,...vt(t,o),children:e})},Bx=S.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return c.jsxs(r||t?Wx:Ux,{...e,context:o,children:[n&&c.jsx(zx,{children:c.jsx(qc,{showTopList:!0})}),c.jsxs(r||t?$x:Fx,{children:[c.jsx(Dx,{}),c.jsx(qc,{}),c.jsx(Lx,{})]})]})}),{Component:Hx,useEmitter:ji,useEmitterValue:Ae,usePublisher:Lt}=zc(Nx,{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"}},Bx),Ux=Gc({useEmitter:ji,useEmitterValue:Ae,usePublisher:Lt}),Wx=Yc({useEmitter:ji,useEmitterValue:Ae,usePublisher:Lt}),Vx=Hx;tt($c,Ve(()=>{const e=J(u=>c.jsxs("td",{children:["Item $",u]})),t=J(null),n=J(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=J(null),o=J(null),s=J({}),i=J(Ai),a=J(lr),l=(u,d=null)=>xt(W(s,se(f=>f[u]),nt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Ni();const Xc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Kx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Jc,floor:Oo,max:Ur,min:_i,round:Zc}=Math;function Qc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function qx(e){return{...Kx,items:e}}function Mo(e,t){return e&&e.width===t.width&&e.height===t.height}function Gx(e,t){return e&&e.column===t.column&&e.row===t.row}const Yx=Ve(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:y,windowScrollTo:C,windowViewportRect:E},T])=>{const k=J(0),I=J(0),A=J(Xc),_=J({height:0,width:0}),R=J({height:0,width:0}),L=ze(),F=ze(),V=J(0),O=J(null),Y=J({column:0,row:0}),K=ze(),X=ze(),B=J(!1),$=J(0),z=J(!0),H=J(!1),ge=J(!1);Ke(W(w,Le($),Ee(([M,Z])=>!!Z)),()=>{De(z,!1)}),Ke(W(ct(w,z,R,_,$,H),Ee(([M,Z,ne,Q,,le])=>M&&!Z&&ne.height!==0&&Q.height!==0&&!le)),([,,,,M])=>{De(H,!0),yi(1,()=>{De(L,M)}),Ut(W(u),()=>{De(t,[0,0]),De(z,!0)})}),fe(W(X,Ee(M=>M!=null&&M.scrollTop>0),Jt(0)),I),Ke(W(w,Le(X),Ee(([,M])=>M!=null)),([,M])=>{M&&(De(_,M.viewport),De(R,M.item),De(Y,M.gap),M.scrollTop>0&&(De(B,!0),Ut(W(u,$n(1)),Z=>{De(B,!1)}),De(l,{top:M.scrollTop})))}),fe(W(_,se(({height:M})=>M)),f),fe(W(ct(ke(_,Mo),ke(R,Mo),ke(Y,(M,Z)=>M&&M.column===Z.column&&M.row===Z.row),ke(u)),se(([M,Z,ne,Q])=>({gap:ne,item:Z,scrollTop:Q,viewport:M}))),K),fe(W(ct(ke(k),r,ke(Y,Gx),ke(R,Mo),ke(_,Mo),ke(O),ke(I),ke(B),ke(z),ke($)),Ee(([,,,,,,,M])=>!M),se(([M,[Z,ne],Q,le,Be,Ye,qe,,Ce,_e])=>{const{column:Qe,row:Ue}=Q,{height:ot,width:lt}=le,{width:ie}=Be;if(qe===0&&(M===0||ie===0))return Xc;if(lt===0){const mt=Si(_e,M),cn=mt+Math.max(qe-1,0);return qx(Qc(mt,cn,Ye))}const ue=eu(ie,lt,Qe);let we,pe;Ce?Z===0&&ne===0&&qe>0?(we=0,pe=qe-1):(we=ue*Oo((Z+Ue)/(ot+Ue)),pe=ue*Jc((ne+Ue)/(ot+Ue))-1,pe=_i(M-1,Ur(pe,ue-1)),we=_i(pe,Ur(0,we))):(we=0,pe=-1);const xe=Qc(we,pe,Ye),{bottom:Re,top:Me}=tu(Be,Q,le,xe),Pe=Jc(M/ue),st=Pe*ot+(Pe-1)*Ue-Re;return{bottom:Re,itemHeight:ot,items:xe,itemWidth:lt,offsetBottom:st,offsetTop:Me,top:Me}})),A),fe(W(O,Ee(M=>M!==null),se(M=>M.length)),k),fe(W(ct(_,R,A,Y),Ee(([M,Z,{items:ne}])=>ne.length>0&&Z.height!==0&&M.height!==0),se(([M,Z,{items:ne},Q])=>{const{bottom:le,top:Be}=tu(M,Q,Z,ne);return[Be,le]}),nt(Dr)),t);const de=J(!1);fe(W(u,Le(de),se(([M,Z])=>Z||M!==0)),de);const ee=jt(W(ct(A,k),Ee(([{items:M}])=>M.length>0),Le(de),Ee(([[M,Z],ne])=>{const Q=M.items[M.items.length-1].index===Z-1;return(ne||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===Z)&&Q}),se(([[,M]])=>M-1),nt())),je=jt(W(ke(A),Ee(({items:M})=>M.length>0&&M[0].index===0),Jt(0),nt())),Te=jt(W(ke(A),Le(B),Ee(([{items:M},Z])=>M.length>0&&!Z),se(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),nt(bc),pn(0)));fe(Te,p.scrollSeekRangeChanged),fe(W(L,Le(_,R,k,Y),se(([M,Z,ne,Q,le])=>{const Be=Ec(M),{align:Ye,behavior:qe,offset:Ce}=Be;let _e=Be.index;_e==="LAST"&&(_e=Q-1),_e=Ur(0,_e,_i(Q-1,_e));let Qe=Ri(Z,le,ne,_e);return Ye==="end"?Qe=Zc(Qe-Z.height+ne.height):Ye==="center"&&(Qe=Zc(Qe-Z.height/2+ne.height/2)),Ce&&(Qe+=Ce),{behavior:qe,top:Qe}})),l);const q=xt(W(A,se(M=>M.offsetBottom+M.bottom)),0);return fe(W(E,se(M=>({height:M.visibleHeight,width:M.visibleWidth}))),_),{customScrollParent:g,data:O,deviation:V,footerHeight:o,gap:Y,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:R,overscan:n,restoreStateFrom:X,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:y,windowScrollTo:C,windowViewportRect:E,...p,gridState:A,horizontalDirection:ge,initialTopMostItemIndex:$,totalListHeight:q,...h,endReached:ee,propsReady:v,rangeChanged:Te,startReached:je,stateChanged:K,stateRestoreInProgress:B,...T}},tt(Ci,St,Hr,Lc,Cn,ki,yn));function eu(e,t,n){return Ur(1,Oo((e+n)/(Oo(t)+n)))}function tu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ri(e,t,n,r[0].index);return{bottom:Ri(e,t,n,r[r.length-1].index)+o,top:s}}function Ri(e,t,n,r){const o=eu(e.width,n.width,t.column),s=Oo(r/o),i=s*n.height+Ur(0,s-1)*t.row;return i>0?i+t.row:i}const Xx=Ve(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(Ai),i=J("div"),a=J(lr),l=(f,h=null)=>xt(W(t,se(p=>p[f]),nt()),h),u=J(!1),d=J(!1);return fe(ke(d),u),{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:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Jx=Ve(([e,t])=>({...e,...t}),tt(Yx,Xx)),Zx=S.memo(function(){const e=rt("gridState"),t=rt("listClassName"),n=rt("itemClassName"),r=rt("itemContent"),o=rt("computeItemKey"),s=rt("isSeeking"),i=Ft("scrollHeight"),a=rt("ItemComponent"),l=rt("ListComponent"),u=rt("ScrollSeekPlaceholder"),d=rt("context"),f=Ft("itemDimensions"),h=Ft("gap"),p=rt("log"),w=rt("stateRestoreInProgress"),v=Ft("reportReadyState"),g=zn(S.useMemo(()=>x=>{const y=x.parentElement.parentElement.scrollHeight;i(y);const C=x.firstChild;if(C){const{height:E,width:T}=C.getBoundingClientRect();f({height:E,width:T})}h({column:ru("column-gap",getComputedStyle(x).columnGap,p),row:ru("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Uc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...vt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const y=o(x.index,x.data,d);return s?c.jsx(u,{...vt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},y):S.createElement(a,{...vt(a,d),className:n,"data-index":x.index,key:y},r(x.index,x.data,d))})})}),Qx=S.memo(function(){const e=rt("HeaderComponent"),t=Ft("headerHeight"),n=rt("headerFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),ev=S.memo(function(){const e=rt("FooterComponent"),t=Ft("footerHeight"),n=rt("headerFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),tv=({children:e})=>{const t=S.useContext(Hc),n=Ft("itemDimensions"),r=Ft("viewportDimensions"),o=zn(S.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return S.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Po(!1),children:e})},nv=({children:e})=>{const t=S.useContext(Hc),n=Ft("windowViewportRect"),r=Ft("itemDimensions"),o=rt("customScrollParent"),s=hc(n,o,!1);return S.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Po(!1),children:e})},rv=S.memo(function({...e}){const t=rt("useWindowScroll"),n=rt("customScrollParent"),r=n||t?sv:ov,o=n||t?nv:tv,s=rt("context");return c.jsx(r,{...e,...vt(r,s),children:c.jsxs(o,{children:[c.jsx(Qx,{}),c.jsx(Zx,{}),c.jsx(ev,{})]})})}),{useEmitter:nu,useEmitterValue:rt,usePublisher:Ft}=zc(Jx,{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"}},rv),ov=Gc({useEmitter:nu,useEmitterValue:rt,usePublisher:Ft}),sv=Yc({useEmitter:nu,useEmitterValue:rt,usePublisher:Ft});function ru(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}const iv=io.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 Pi({className:e,variant:t,...n}){return c.jsx("div",{className:te(iv({variant:t}),e),...n})}function ce(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function av(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function en(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,lv(o,...t)]}function lv(...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:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ft=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},cv=m[" useInsertionEffect ".trim().toString()]||ft;function Un({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=uv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=dv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function uv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return cv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function dv(e){return typeof e=="function"}function ou(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Oi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=ou(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():ou(e[o],null)}}}}function $e(...e){return m.useCallback(Oi(...e),e)}var fv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ie=fv.reduce((e,t)=>{const n=Mn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function su(e,t){e&&ao.flushSync(()=>e.dispatchEvent(t))}function hv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Rt=e=>{const{present:t,children:n}=e,r=pv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=$e(r.ref,mv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Rt.displayName="Presence";function pv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=hv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Do(r.current);s.current=a==="mounted"?u:"none"},[a]),ft(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Do(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),ft(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=Do(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Do(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Do(e){return(e==null?void 0:e.animationName)||"none"}function mv(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 gv=m[" useId ".trim().toString()]||(()=>{}),xv=0;function tn(e){const[t,n]=m.useState(gv());return ft(()=>{n(r=>r??String(xv++))},[e]),e||(t?`radix-${t}`:"")}var Lo="Collapsible",[vv,tT]=en(Lo),[wv,Mi]=vv(Lo),iu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Un({prop:r,defaultProp:o??!1,onChange:i,caller:Lo});return c.jsx(wv,{scope:n,disabled:s,contentId:tn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ie.div,{"data-state":Li(l),"data-disabled":s?"":void 0,...a,ref:t})})});iu.displayName=Lo;var au="CollapsibleTrigger",lu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Mi(au,n);return c.jsx(Ie.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Li(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ce(e.onClick,o.onOpenToggle)})});lu.displayName=au;var Di="CollapsibleContent",bv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mi(Di,e.__scopeCollapsible);return c.jsx(Rt,{present:n||o.open,children:({present:s})=>c.jsx(yv,{...r,ref:t,present:s})})});bv.displayName=Di;var yv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Mi(Di,n),[a,l]=m.useState(r),u=m.useRef(null),d=$e(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const y=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(y)},[]),ft(()=>{const y=u.current;if(y){x.current=x.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const C=y.getBoundingClientRect();f.current=C.height,p.current=C.width,g.current||(y.style.transitionDuration=x.current.transitionDuration,y.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Ie.div,{"data-state":Li(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function Li(e){return e?"open":"closed"}var Sv=iu;const cu=Sv,uu=lu,Wr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Wr.displayName="Card";const Vr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));Vr.displayName="CardHeader";const Kr=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));Kr.displayName="CardTitle";const du=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));du.displayName="CardDescription";const Fo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));Fo.displayName="CardContent";const fu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));fu.displayName="CardFooter";function hu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Wn=hu();function Cv(e){Wn=e}const pu=/[&<>"']/,Tv=new RegExp(pu.source,"g"),mu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,kv=new RegExp(mu.source,"g"),Ev={"&":"&","<":"<",">":">",'"':""","'":"'"},gu=e=>Ev[e];function wt(e,t){if(t){if(pu.test(e))return e.replace(Tv,gu)}else if(mu.test(e))return e.replace(kv,gu);return e}const Iv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function xu(e){return e.replace(Iv,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const Nv=/(^|[^\[])\^/g;function Ze(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Nv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Av=/[^\w:]/g,jv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function vu(e,t,n){if(e){let r;try{r=decodeURIComponent(xu(n)).replace(Av,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!jv.test(n)&&(n=Ov(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const $o={},_v=/^[^:]+:\/*[^/]*$/,Rv=/^([^:]+:)[\s\S]*$/,Pv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Ov(e,t){$o[" "+e]||(_v.test(e)?$o[" "+e]=e+"/":$o[" "+e]=Bo(e,"/",!0)),e=$o[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Rv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Pv,"$1")+t:e+t}const zo={exec:function(){}};function wu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Bo(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function Mv(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function Dv(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function bu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function yu(e,t,n,r){const o=t.href,s=t.title?wt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:wt(i)}}function Lv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const ue=K.slice(0,ie);K=K.slice(ie+2);const we=Cg(ue);if(!we)continue;let pe;try{pe=JSON.parse(we)}catch{console.debug("[use-chat] malformed SSE:",we.slice(0,200));continue}const xe=Sg(pe)?pe.data:pe;Be=Date.now();const Re=xe.seq;if(Re!==void 0){if(Re<=Z){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Re,lastProcessedSeq:Z,type:xe.type});continue}Z>0&&Re>Z+1&&(($=F==null?void 0:F.onGap)==null||$.call(F,{from:Z,to:Re})),Z=Re,T.current=Re,g(Re)}if(console.debug("[use-chat] received event",{seq:xe.seq,type:xe.type,preview:(()=>{var Me;try{return xe.type==="message_delta"?{deltaTypes:(Me=xe.delta)==null?void 0:Me.map(Pe=>Pe.type),textLen:(xe.delta||[]).filter(Pe=>Pe.type==="text").map(Pe=>String(Pe.text||"").length)}:xe.content||xe.delta?{hasContent:!0}:{}}catch(Pe){return{err:String(Pe)}}})()}),L==null||L(xe),xe.type==="token"&&e.autoAppendAssistant!==!1)M.push(xe.content),le();else if(xe.type==="message_delta"){const Me=xe.delta.filter(Pe=>Pe.type==="text").map(Pe=>Pe.text).join("");Me&&e.autoAppendAssistant!==!1&&(M.push(Me),le())}else xe.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(ne!==null&&cancelAnimationFrame(ne),Q(),xe.type==="checkpoint"?w(xe.checkpointId):xe.type==="error"&&d(xe.message))}}Q()}catch(Ce){if(Ce.name!=="AbortError"){const _e=Ce.message||String(Ce);d(_e),(z=F==null?void 0:F.onError)==null||z.call(F,_e)}}finally{try{await je.cancel()}catch{}finally{(H=je.releaseLock)==null||H.call(je)}ne!==null&&typeof window<"u"&&window.cancelAnimationFrame(ne),clearInterval(Ye),l(!1),y(!1),C.current=null,T.current=0,g(0)}}catch(de){if(de.name!=="AbortError"){const ee=de.message||String(de);d(ee),(ge=F==null?void 0:F.onError)==null||ge.call(F,ee)}}finally{l(!1),y(!1),C.current=null,T.current=0,g(0)}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return S.useEffect(()=>()=>{var R;E.current=!1,(R=C.current)==null||R.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:v,connected:x,stream:_,stop:I,clear:A,setToken:k}}function Sg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Cg(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 Tg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=S.useRef(null),i=S.useCallback(p=>{const w=p.seq??null;if(w!==null){const v=s.current;if(v!==null){if(w<=v)return;w>v+1&&(o==null||o({from:v,to:w}))}s.current=w}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(gg(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Jl({baseUrl:e,token:null}),h=S.useCallback((p,w)=>{s.current=null,a(p,i,{onOpen:w==null?void 0:w.onOpen,onError:v=>{var g;(g=w==null?void 0:w.onError)==null||g.call(w,v)},onGap:(w==null?void 0:w.onGap)??o})},[i,o,a]);return S.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Zl=S.createContext(null),Ql=S.createContext(null),ec=S.createContext(null),kg=S.createContext(!1),Eg=20,Ig="cachedThreads",Ng="v1",bo=300,ni=200;function tc(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,bo)}function ir(){return typeof window<"u"&&typeof window.localStorage<"u"}function ri(e){if(!ir())return null;try{return window.localStorage.getItem(e)}catch{return null}}function nc(e,t){if(ir())try{window.localStorage.setItem(e,t)}catch{}}function oi(e){if(ir())try{window.localStorage.removeItem(e)}catch{}}function Ag(){const e=ri(Ig);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 jg(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 si(e,t){return`cachedThreads:v1:${e}:${jg(t||"anon")}`}function _g(e){const t=ri(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 ii(e,t){try{nc(e,JSON.stringify(t))}catch{}}function rc(e){const t=_g(e);if(t.length>0)return t;const n=Ag();if(n.length>0)try{ii(e,n.slice(0,ni))}catch{}return n}function ai(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 li(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Rg({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:u}=Qs(),d=S.useMemo(()=>hn(u),[u]),f=S.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=S.useMemo(()=>`threadPayload:${Ng}:${f}:`,[f]),p=S.useCallback(N=>`${h}${N}`,[h]),w=S.useCallback(N=>{if(!N||typeof N!="object")return null;const b=N;return typeof b.threadId!="string"||!Array.isArray(b.messages)?null:{threadId:b.threadId,messages:b.messages,hasMore:!!b.hasMore,nextCursor:b.nextCursor??null,checkpointId:b.checkpointId??null,checkpointNs:b.checkpointNs??null}},[]),v=S.useCallback(N=>{const b=ri(p(N));if(!b)return null;try{const j=JSON.parse(b);return w(j)}catch{return null}},[p,w]),g=S.useCallback((N,b=100)=>{const j={...N,messages:Array.isArray(N.messages)?N.messages.slice(-b):[]};try{nc(p(N.threadId),JSON.stringify(j))}catch{}},[p]),x=S.useCallback(N=>{oi(p(N))},[p]),y=S.useCallback(()=>{if(ir())try{const N=h;for(let b=0;b<window.localStorage.length;b++){const j=window.localStorage.key(b);j&&j.startsWith(N)&&window.localStorage.removeItem(j)}}catch{}},[h]),[C,E]=S.useState(()=>{var N;return si(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[T,k]=S.useState(()=>{var b;const N=rc(si(f,(b=l.getAuthToken)==null?void 0:b.call(l)));return ai(N)}),I=S.useMemo(()=>li(T),[T]),[A,_]=S.useState(t),[R,L]=S.useState(!1),[F,V]=S.useState(!1),[O,Y]=S.useState(!1),[q,X]=S.useState(!1),[B,$]=S.useState(null),[z,H]=S.useState(void 0),[ge,de]=S.useState(void 0),{state:ee,dispatch:je,seed:Te,prepend:K,pushUser:M,onEvent:Z,reset:ne}=Hl(),Q=S.useRef(A);S.useEffect(()=>{Q.current=A},[A]);const le=S.useRef(!1),Be=S.useRef([]),Ye=S.useRef(null),Ke=S.useRef(null),Ce=S.useRef(new Map),_e=S.useRef(A),Qe=S.useRef(!1),Ue=S.useRef(null),ot=S.useCallback((N,b)=>new Promise((j,D)=>{const U=async()=>{le.current=!0;try{await N(),j()}catch(G){D(G)}finally{le.current=!1;const G=Be.current.shift();G&&G().catch(()=>{})}};le.current?Be.current.push(U):U().catch(G=>{D(G)})}),[]),lt=S.useRef(I.length),[ie,ue]=S.useState(!1),we=S.useRef(!1);S.useEffect(()=>{lt.current=I.length},[I.length]);const pe=S.useCallback(async()=>{const N=lt.current>0;N||L(!0);try{const b=await l.listThreads();S.startTransition(()=>{k(j=>{const D=ve=>ve.map(me=>`${me.threadId}:${me.updatedAt??""}:${me.messageCount??""}`).join("|"),U=li(j);return D(U)===D(b)||b.length===0&&U.length>0&&!we.current?j:ai(b)})}),we.current||(we.current=!0,ue(!0))}catch(b){i==null||i(String(b)),console.error("[ChatSessionProvider] Failed to refresh threads:",b)}finally{N||L(!1)}},[l,i]),xe=S.useRef(!1),Re=S.useRef(null),Me=S.useRef(null),Pe=S.useRef(""),st=S.useCallback((N,b)=>{if(!ir())return;Me.current!==null&&(window.clearTimeout(Me.current),Me.current=null);const j=N.map(U=>`${U.threadId}:${U.updatedAt??""}:${U.messageCount??""}`).join("|");if(N.length===0){try{oi(C)}catch{}Pe.current="";return}if(j===Pe.current)return;const D=()=>{try{const U=N.slice(0,ni);ii(C,U),Pe.current=j}catch{}finally{Me.current=null}};if(b!=null&&b.immediate){D();return}Me.current=window.setTimeout(()=>{tc(D)},bo)},[C]),mt=S.useCallback((N,b,j)=>{const D=Array.isArray(N==null?void 0:N.messages)?N.messages:[],U=j??(N==null?void 0:N.threadId)??Q.current;if(b==="replace"){if(U){const G={threadId:U,messages:D.slice(),hasMore:!!(N!=null&&N.hasMore),nextCursor:(N==null?void 0:N.nextCursor)??null,checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null};Ce.current.set(U,G),_e.current=U}Te(D,{checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null})}else if(b==="prepend"&&D.length&&U){const G=Ce.current.get(U),ve=(G==null?void 0:G.messages)??[],me=new Set,he=[...D,...ve].filter(Ge=>{const Xe=Ge==null?void 0:Ge.id;return Xe?me.has(Xe)?!1:(me.add(Xe),!0):!0}),He={threadId:U,messages:he,hasMore:(N==null?void 0:N.hasMore)??(G==null?void 0:G.hasMore)??!1,nextCursor:(N==null?void 0:N.nextCursor)??(G==null?void 0:G.nextCursor)??null,checkpointId:(G==null?void 0:G.checkpointId)??(N==null?void 0:N.checkpointId)??null,checkpointNs:(G==null?void 0:G.checkpointNs)??(N==null?void 0:N.checkpointNs)??null};Ce.current.set(U,He),K(D)}else b==="prepend"&&D.length&&K(D);b==="replace"?($((N==null?void 0:N.nextCursor)??null),Y(!!(N!=null&&N.hasMore)),H((N==null?void 0:N.checkpointId)??void 0),de((N==null?void 0:N.checkpointNs)??void 0)):($(G=>(N==null?void 0:N.nextCursor)??G??null),Y(G=>(N==null?void 0:N.hasMore)!==void 0?!!(N!=null&&N.hasMore):G),H(G=>(N==null?void 0:N.checkpointId)??G??void 0),de(G=>(N==null?void 0:N.checkpointNs)??G??void 0))},[K,Te]),cn=S.useCallback(N=>{Te(N.messages,{checkpointId:N.checkpointId,checkpointNs:N.checkpointNs}),$(N.nextCursor),Y(N.hasMore),H(N.checkpointId??void 0),de(N.checkpointNs??void 0),_e.current=N.threadId},[Te]),un=S.useCallback(N=>{N&&(Ce.current.delete(N),x(N),_e.current===N&&(_e.current=null))},[x]),dn=S.useCallback(()=>{const N=Q.current;N&&un(N),ne([]),Y(!1),X(!1),$(null),H(void 0),de(void 0)},[un,ne]),Rn=S.useCallback(({from:N,to:b})=>{const j=Q.current;j&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${b}) for thread ${j}`)},[]),er=S.useCallback(N=>{const b=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:b,title:N.title,created:N.created,currentThreads:I.length});const j={threadId:b,title:N.title||`Thread ${b.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};Q.current!==b&&(!Q.current&&ee.messages.length<=1&&(Ke.current=b),_(b)),S.startTransition(()=>{k(D=>{const U=D.byId[b];return U?U.title===j.title&&U.updatedAt===j.updatedAt&&U.messageCount===j.messageCount?D:{byId:{...D.byId,[b]:j},order:D.order}:{byId:{...D.byId,[b]:j},order:[b,...D.order]}})})},[ee.messages.length]),{startStream:yr,stop:Pn,isStreaming:xn,error:Yt,setAuthToken:vn}=Tg({baseUrl:d,onThreadInfo:er,onMessageEvent:Z,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:Rn});S.useEffect(()=>{xe.current=xn},[xn]),S.useEffect(()=>{if(!ir())return;Me.current!==null&&(window.clearTimeout(Me.current),Me.current=null);const N=I.map(j=>`${j.threadId}:${j.updatedAt??""}:${j.messageCount??""}`).join("|");if(I.length===0){try{oi(C)}catch{}Pe.current="";return}if(N===Pe.current)return;const b=()=>{try{const j=I.slice(0,ni);ii(C,j),Pe.current=N}catch{}finally{Me.current=null}};return Me.current=window.setTimeout(()=>{tc(b),Me.current=null},bo),()=>{Me.current!==null&&(window.clearTimeout(Me.current),Me.current=null)}},[I,st]),S.useEffect(()=>{var D;const N=l.getAuthToken();vn(N);const b=U=>{const G=si(f,U);Ue.current!==G&&(Ue.current=G,Qe.current=!1),E(G);const ve=rc(G);S.startTransition(()=>{k(ai(ve))}),Qe.current||(Qe.current=!0,pe().catch(()=>{}))};b(N);const j=(D=l.onTokenChange)==null?void 0:D.call(l,U=>{vn(U),y(),b(U)});return()=>{j==null||j()}},[l,f,vn,y,pe]);const On=S.useCallback(async N=>{const b=`temp-${Date.now()}`,j={threadId:b,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(D=>({byId:{...D.byId,[b]:j},order:[b,...D.order]})),_(b);try{const D=await l.createThread(N),U=typeof D=="string"?D:D.threadId;return k(G=>{const ve=G.byId[b];if(!ve)return G;const me={...G.byId};delete me[b],me[U]={...ve,threadId:U};const he=G.order.map(He=>He===b?U:He);return{byId:me,order:he}}),_(U),setTimeout(()=>pe(),10),U}catch(D){throw k(U=>{if(!U.byId[b])return U;const G={...U.byId};delete G[b];const ve=U.order.filter(me=>me!==b);return{byId:G,order:ve}}),_(null),D}},[l,pe]),tr=S.useCallback(async N=>{await l.deleteThread(N);let b=null;k(j=>{if(!j.byId[N])return j;const D={...j.byId};delete D[N];const U=j.order.filter(ve=>ve!==N),G={byId:D,order:U};return b=li(G),G}),b&&st(b,{immediate:!0}),un(N),Q.current===N&&(Ke.current=N,_(null),Q.current=null,_e.current=null,dn()),await pe()},[l,dn,un,pe,st]),Sr=S.useCallback(async(N,b)=>{try{await l.updateThread(N,b),k(j=>{const D=j.byId[N];return D?{byId:{...j.byId,[N]:{...D,title:b}},order:j.order}:j})}catch(j){throw await pe(),j}},[l,pe]),It=S.useCallback(async(N,b,j,D=!1)=>{await ot(async()=>{if(Ke.current===N&&!D){Ke.current=null;return}if(Ye.current===N&&!D)return;_(he=>he===N?he:N),Q.current=N;const U=!D&&!b&&!j;let G=!1;if(U){const he=Ce.current.get(N);if(he)cn(he),G=!0;else{const He=v(N);He&&(Ce.current.set(N,He),cn(He),G=!0)}}const ve=D||!G||!!b||!!j,me=async he=>{he&&V(!0),Ye.current=N;try{const He=await l.getMessages({threadId:N,checkpointId:b,checkpointNs:j});mt(He,"replace",N)}catch(He){throw(!G||D||he)&&(i==null||i(String(He))),He}finally{Ye.current=null,he&&V(!1)}};ve?await me(!0):U&&G&&me(!1).catch(he=>{console.warn("[ChatSessionProvider] Background refresh failed:",he)})},`loadThread-${N}`)},[l,cn,mt,ot,i]),Cr=S.useCallback(async()=>{await ot(async()=>{const N=Q.current;N&&un(N),Ke.current=null,_(null),Q.current=null,_e.current=null,dn(),H(void 0),de(void 0);try{localStorage.removeItem("lastThreadId")}catch(b){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",b)}},"clearCurrentThread")},[dn,un,ot]),oe=S.useCallback(async N=>{const b=await l.listCheckpoints(N);return hg(b,N)},[l]),be=S.useCallback(async(N,b)=>{if(!Q.current)throw new Error("No active thread");await It(Q.current,N,b??void 0,!0)},[It]),Fe=S.useCallback(async()=>{if(!Q.current)throw new Error("No active thread");await It(Q.current,void 0,void 0,!0)},[It]),et=S.useCallback(async N=>{if(!Q.current)throw new Error("No active thread");if(q||!O)return;const b=B;if(b){X(!0);try{const j=Q.current,D=await l.getMessages({threadId:j,checkpointId:z,checkpointNs:ge,limit:(N==null?void 0:N.limit)??Eg,beforeId:b});mt(D,"prepend",j??void 0)}finally{X(!1)}}},[l,mt,O,z,ge,B,q]),bt=S.useCallback(async(N,b)=>{var dt;const j=Q.current;!j&&!(b!=null&&b.payloadExtras)&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const D=(b==null?void 0:b.attachments)||[],{contentParts:U,filesInfo:G}=await mg(l,D),ve=[...U];N&&N.trim()&&ve.push({type:"text",text:N.trim()});const me={id:((dt=crypto.randomUUID)==null?void 0:dt.call(crypto))||`user-${Date.now()}`,role:"user",content:ve,createdAt:new Date().toISOString(),checkpointId:(b==null?void 0:b.checkpointId)??ee.lastCheckpointId??void 0,checkpointNs:(b==null?void 0:b.checkpointNs)??ee.lastCheckpointNs??void 0};M(me);const he={...me,content:ve},He={...(b==null?void 0:b.payloadExtras)??{}},Ge=D.length>0,Xe={...j?{threadId:j}:{},payload:{messages:[he],files_info:G,...o&&Ge&&s?{active_agent:s}:{},...He},checkpointId:(b==null?void 0:b.checkpointId)??ee.lastCheckpointId??void 0,checkpointNs:(b==null?void 0:b.checkpointNs)??ee.lastCheckpointNs??void 0,nodeFilter:b==null?void 0:b.nodeFilter,config:b==null?void 0:b.config};yr(Xe,{onError:yt=>{console.warn("[ChatSessionProvider] Stream error:",yt)},onOpen:({threadId:yt,created:fn})=>{!Q.current&&yt&&(ee.messages.length<=1&&(Ke.current=yt),_(yt))},onGap:Rn})},[l,o,s,Rn,ee.lastCheckpointId,ee.lastCheckpointNs,ee.messages.length,M,yr]),Mt=S.useCallback(async(N,b,j)=>{var U,G;const D=Q.current;if(!D)throw new Error("No active thread to handle interrupt");try{const ve=b?j??!0:!1;try{je({type:"interrupt_response",payload:{interruptId:N}})}catch(yt){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",yt)}const me=`${d}/runs/resume`,he=(U=l.getAuthToken)==null?void 0:U.call(l),He=await fetch(me,{method:"POST",headers:{"Content-Type":"application/json",...he?{Authorization:`Bearer ${he}`}:{}},body:JSON.stringify({thread_id:D,value:ve})});if(!He.ok)throw new Error(`Resume failed with status ${He.status}`);const Ge=(G=He.body)==null?void 0:G.getReader();if(!Ge)throw new Error("No response body for resume stream");const Xe=new TextDecoder;let dt="";for(;;){const{done:yt,value:fn}=await Ge.read();if(yt)break;dt+=Xe.decode(fn,{stream:!0});const ht=dt.split(`
|
|
39
|
+
`);dt=ht.pop()||"";for(const Er of ht)if(Er.startsWith("data: ")){const Va=Er.slice(6);try{const so=JSON.parse(Va);je({type:"event",payload:{ev:so}})}catch(so){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",so)}}}}catch(ve){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,ve),ve}},[l,je,It,d]);S.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[A,a]),S.useEffect(()=>((async()=>{try{if(pe().catch(b=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",b),i==null||i(String(b))}),!r&&!t)try{const b=localStorage.getItem("lastThreadId");b&&(_(b),n&&await It(b))}catch(b){console.warn("[ChatSessionProvider] Failed to restore last thread:",b)}else t&&n&&await It(t)}catch(b){console.error("[ChatSessionProvider] Initialization failed:",b),i==null||i(String(b))}})(),()=>{}),[]),S.useEffect(()=>{const N=Q.current;if(!N||_e.current!==N)return;const b={threadId:N,messages:ee.messages.slice(),hasMore:O,nextCursor:B,checkpointId:ee.lastCheckpointId??null,checkpointNs:ee.lastCheckpointNs??null},j=Ce.current.get(N);(!j||j.messages.length!==b.messages.length||j.messages.some((U,G)=>{var ve;return(U==null?void 0:U.id)!==((ve=b.messages[G])==null?void 0:ve.id)})||(j==null?void 0:j.hasMore)!==b.hasMore||(j==null?void 0:j.nextCursor)!==b.nextCursor||(j==null?void 0:j.checkpointId)!==b.checkpointId||(j==null?void 0:j.checkpointNs)!==b.checkpointNs)&&(Ce.current.set(N,b),Re.current&&window.clearTimeout(Re.current),Re.current=window.setTimeout(()=>{try{g(b,100)}catch(U){console.warn("[ChatSessionProvider] Failed to persist thread payload:",U)}},bo))},[O,B,ee.lastCheckpointId,ee.lastCheckpointNs,ee.messages]);const nr=S.useMemo(()=>({threads:I,currentThreadId:A,isLoadingThreads:R,isLoadingThread:F,setCurrentThreadId:_,createThread:On,deleteThread:tr,renameThread:Sr,refreshThreads:pe,loadThread:It,clearCurrentThread:Cr,listCheckpoints:oe,navigateToCheckpoint:be,returnToLatest:Fe}),[Cr,On,A,tr,F,R,oe,It,be,pe,Sr,Fe,I]),Tr=S.useMemo(()=>({messages:ee.messages,assemblingId:ee.assemblingId,lastUserMessage:null,hasMoreHistory:O,isLoadingHistory:q,send:bt,stop:Pn,loadOlderMessages:et,clearMessages:dn,handleInterrupt:Mt}),[dn,Mt,O,q,et,ee.assemblingId,ee.messages,bt,Pn]),kr=S.useMemo(()=>({isStreaming:xn,error:Yt,streamingAssistantId:ee.assemblingId,lastCheckpointId:ee.lastCheckpointId??null,lastCheckpointNs:ee.lastCheckpointNs??null}),[xn,ee.assemblingId,ee.lastCheckpointId,ee.lastCheckpointNs,Yt]);return c.jsx(kg.Provider,{value:!0,children:c.jsx(ec.Provider,{value:kr,children:c.jsx(Zl.Provider,{value:nr,children:c.jsx(Ql.Provider,{value:Tr,children:e})})})})}function yo(){const e=S.useContext(Zl);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ci(){const e=S.useContext(Ql);if(!e)throw new Error("useMessages must be used within ChatSessionProvider");return e}function oc(){const e=S.useContext(ec);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function So({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 c.jsx(fg,{apiConfig:t,children:c.jsx(Rg,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function te(...e){return Bp.twMerge(zp.clsx(e))}const Pg=io.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"}}),We=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Mn.Slot:"button";return c.jsx(i,{className:te(Pg({variant:t,size:n,className:e})),ref:s,...o})});We.displayName="Button";const sc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:te("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}));sc.displayName="Textarea";function Og({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=S.useState(e),[w,v]=S.useTransition(),g=S.useRef(null);S.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const x=S.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);S.useEffect(()=>{x()},[x]);const y=S.useCallback(async A=>{A&&A.preventDefault();const _=(h??"").trim();!_&&!f||v(()=>{try{const R=i(_);R&&typeof R.then=="function"?R.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),C=S.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),E=S.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),y()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[y,t,a]),I=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void y(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(sc,{ref:g,value:h,onChange:C,onKeyDown:E,placeholder:t?"Edit your message...":n,className:I,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(We,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(re.Square,{size:16})}):c.jsx(We,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||w,children:c.jsx(re.Send,{size:16})})})]})})}const Mg=S.memo(Og),Co=0,bn=1,ar=2,ic=4;function ac(e){return()=>e}function Dg(e){e()}function lc(e,t){return n=>e(t(n))}function cc(e,t){return()=>e(t)}function Lg(e,t){return n=>e(t,n)}function ui(e){return e!==void 0}function Fg(...e){return()=>{e.map(Dg)}}function lr(){}function To(e,t){return t(e),e}function $g(e,t){return t(e)}function tt(...e){return e}function qe(e,t){return e(bn,t)}function De(e,t){e(Co,t)}function di(e){e(ar)}function at(e){return e(ic)}function fe(e,t){return qe(e,Lg(t,Co))}function Ut(e,t){const n=e(bn,r=>{n(),t(r)});return n}function uc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function dc(e,t){return e===t}function nt(e=dc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ee(e){return t=>n=>{e(n)&&t(n)}}function se(e){return t=>lc(t,e)}function Jt(e){return t=>()=>{t(e)}}function W(e,...t){const n=zg(...t);return(r,o)=>{switch(r){case ar:di(e);return;case bn:return qe(e,n(o))}}}function Zt(e,t){return n=>r=>{n(t=e(t,r))}}function $n(e){return t=>n=>{e>0?e--:t(n)}}function pn(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 u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function zg(...e){return t=>e.reduceRight($g,t)}function Bg(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case bn:return s?n===s?void 0:(r(),n=s,t=qe(e,s),t):(r(),lr);case ar:r(),n=null;return}}}function J(e){let t=e;const n=ze();return(r,o)=>{switch(r){case Co:t=o;break;case bn:{o(t);break}case ic:return t}return n(r,o)}}function xt(e,t){return To(J(t),n=>fe(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case Co:e.slice().forEach(r=>{r(n)});return;case ar:e.splice(0,e.length);return;case bn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function jt(e){return To(ze(),t=>fe(e,t))}function Ve(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Hg(),singleton:n}}const Hg=()=>Symbol();function Ug(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 ct(...e){const t=ze(),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&&De(t,n)})}),function(s,i){switch(s){case ar:{di(t);return}case bn:return r===o&&i(n),qe(t,i)}}}function ke(e,t=dc){return W(e,nt(t))}function fi(...e){return function(t,n){switch(t){case ar:return;case bn:return Fg(...e.map(r=>qe(r,n)))}}}var Et=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Et||{});const Wg={0:"debug",3:"error",1:"log",2:"warn"},Vg=()=>typeof globalThis>"u"?window:globalThis,yn=Ve(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=Vg().VIRTUOSO_LOG_LEVEL)!=null?o:at(e);r>=s&&console[Wg[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function zn(e,t,n){return hi(e,t,n).callbackRef}function hi(e,t,n){const r=S.useRef(null);let o=i=>{};const s=S.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 qg(e,t,n,r,o,s,i,a,l){const u=S.useCallback(d=>{const f=Kg(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let w;p&&(w=h.ownerDocument.defaultView);const v=i?a?i.scrollLeft:i.scrollTop:p?a?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?w.innerWidth:w.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(v,0),viewportHeight:x}),s==null||s(a?fc("column-gap",getComputedStyle(d).columnGap,o):fc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return hi(u,n,l)}function Kg(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),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Et.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function fc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}function hc(e,t,n){const r=S.useRef(null),o=S.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),w=u.top-p.top;h=p.height-Math.max(0,w),f=w+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=hi(o,!0,n),a=S.useCallback(()=>{o(i.current)},[o,i]);return S.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const St=Ve(()=>{const e=ze(),t=ze(),n=J(0),r=ze(),o=J(0),s=ze(),i=ze(),a=J(0),l=J(0),u=J(0),d=J(0),f=ze(),h=ze(),p=J(!1),w=J(!1),v=J(!1);return fe(W(e,se(({scrollTop:g})=>g)),t),fe(W(e,se(({scrollHeight:g})=>g)),i),fe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:w,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:v,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Or={lvl:0};function pc(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 Je(e){return e===Or}function Mr(e,t){if(!Je(e))return t===e.k?e.v:t<e.k?Mr(e.l,t):Mr(e.r,t)}function Wt(e,t,n="k"){if(Je(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Wt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Wt(e.l,t,n)}function _t(e,t,n){return Je(e)?xc(t,n,1):t===e.k?ut(e,{k:t,v:n}):t<e.k?vc(ut(e,{l:_t(e.l,t,n)})):vc(ut(e,{r:_t(e.r,t,n)}))}function cr(){return Or}function ko(e,t,n){if(Je(e))return[];const r=Wt(e,t)[0];return Gg(mi(e,r,n))}function pi(e,t){if(Je(e))return Or;const{k:n,l:r,r:o}=e;if(t===n){if(Je(r))return o;if(Je(o))return r;{const[s,i]=gc(r);return Eo(ut(e,{k:s,l:mc(r),v:i}))}}else return t<n?Eo(ut(e,{l:pi(r,t)})):Eo(ut(e,{r:pi(o,t)}))}function Bn(e){return Je(e)?[]:[...Bn(e.l),{k:e.k,v:e.v},...Bn(e.r)]}function mi(e,t,n){if(Je(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(mi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(mi(s,t,n))),a}function Eo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(gi(t))return wc(ut(e,{lvl:n-1}));if(!Je(t)&&!Je(t.r))return ut(t.r,{l:ut(t,{r:t.r.l}),lvl:n,r:ut(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(gi(e))return xi(ut(e,{lvl:n-1}));if(!Je(r)&&!Je(r.l)){const o=r.l,s=gi(o)?r.lvl-1:r.lvl;return ut(o,{l:ut(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:xi(ut(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ut(e,t){return xc(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 mc(e){return Je(e.r)?e.l:Eo(ut(e,{r:mc(e.r)}))}function gi(e){return Je(e)||e.lvl>e.r.lvl}function gc(e){return Je(e.r)?[e.k,e.v]:gc(e.r)}function xc(e,t,n,r=Or,o=Or){return{k:e,l:r,lvl:n,r:o,v:t}}function vc(e){return xi(wc(e))}function wc(e){const{l:t}=e;return!Je(t)&&t.lvl===e.lvl?ut(t,{r:ut(e,{l:t.r})}):e}function xi(e){const{lvl:t,r:n}=e;return!Je(n)&&!Je(n.r)&&n.lvl===t&&n.r.lvl===t?ut(n,{l:ut(e,{r:n.l}),lvl:t+1}):e}function Gg(e){return pc(e,({k:t,v:n})=>({index:t,value:n}))}function bc(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Dr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const vi=Ve(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function yc(e,t,n){return e[Io(e,t,n)]}function Io(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 Yg(e,t,n,r){const o=Io(e,t,r),s=Io(e,n,r,o);return e.slice(o,s+1)}function Sn(e,t){return Math.round(e.getBoundingClientRect()[t])}function No(e){return!Je(e.groupOffsetTree)}function wi({index:e},t){return t===e?0:t<e?-1:1}function Xg(){return{groupIndices:[],groupOffsetTree:cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:cr()}}function Jg(e,t){let n=Je(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Je(e)){e=_t(e,0,s);continue}const a=ko(e,i-1,o+1);if(a.some(ox(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=pi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=_t(e,o+1,h));u&&(e=_t(e,i,s))}return[e,n]}function Zg(e){return typeof e.groupIndex<"u"}function Qg({offset:e},t){return t===e?0:t<e?-1:1}function Lr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=yc(t,e,wi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Sc(e,t){if(!No(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Cc(e,t,n){if(Zg(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Sc(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function ex(e,t,n,r=0){return r>0&&(t=Math.max(t,yc(e,r,wi).offset)),pc(Yg(e,t,n,Qg),rx)}function tx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Et.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Je(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((w,v)=>_t(_t(w,v,h),v+1,p),i)}else[i,a]=Jg(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=bi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>_t(h,p,Lr(p,f,o)),cr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function nx(e){return Bn(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 Tc(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 bi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Io(o,t-1,wi),a=o[l].offset;const u=Wt(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===Wt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of ko(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function rx(e){return{index:e.index,value:e}}function ox(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 sx={offsetHeight:"height",offsetWidth:"width"},Qt=Ve(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=xt(r,0),s=ze(),i=ze(),a=J(0),l=J([]),u=J(void 0),d=J(void 0),f=J((T,k)=>Sn(T,sx[k])),h=J(void 0),p=J(0),w=Xg(),v=xt(W(n,Le(l,e,p),Zt(tx,w),nt()),w),g=xt(W(l,nt(),Zt((T,k)=>({current:k,prev:T.current}),{current:[],prev:[]}),se(({prev:T})=>T)),[]);fe(W(l,Ee(T=>T.length>0),Le(v,p),se(([T,k,I])=>{const A=T.reduce((_,R,L)=>_t(_,R,Lr(R,k.offsetTree,I)||L),cr());return{...k,groupIndices:T,groupOffsetTree:A}})),v),fe(W(r,Le(v),Ee(([T,{lastIndex:k}])=>T<k),se(([T,{lastIndex:k,lastSize:I}])=>[{endIndex:k,size:I,startIndex:T}])),n),fe(u,d);const x=xt(W(u,se(T=>T===void 0)),!0);fe(W(d,Ee(T=>T!==void 0&&Je(at(v).sizeTree)),se(T=>[{endIndex:0,size:T,startIndex:0}])),n);const y=jt(W(n,Le(v),Zt(({sizes:T},[k,I])=>({changed:I!==T,sizes:I}),{changed:!1,sizes:w}),se(T=>T.changed)));qe(W(a,Zt((T,k)=>({diff:T.prev-k,prev:k}),{diff:0,prev:0}),se(T=>T.diff)),T=>{const{groupIndices:k}=at(v);if(T>0)De(t,!0),De(s,T+Tc(T,k));else if(T<0){const I=at(g);I.length>0&&(T-=Tc(-T,I)),De(i,T)}}),qe(W(a,Le(e)),([T,k])=>{T<0&&k("`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},Et.ERROR)});const C=jt(s);fe(W(s,Le(v),se(([T,k])=>{const I=k.groupIndices.length>0,A=[],_=k.lastSize;if(I){const R=Mr(k.sizeTree,0);let L=0,F=0;for(;L<T;){const O=k.groupIndices[F],Y=k.groupIndices.length===F+1?1/0:k.groupIndices[F+1]-O-1;A.push({endIndex:O,size:R,startIndex:O}),A.push({endIndex:O+1+Y-1,size:_,startIndex:O+1}),F++,L+=Y+1}const V=Bn(k.sizeTree);return L!==T&&V.shift(),V.reduce((O,{k:Y,v:q})=>{let X=O.ranges;return O.prevSize!==0&&(X=[...O.ranges,{endIndex:Y+T-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:Y+T,prevSize:q,ranges:X}},{prevIndex:T,prevSize:0,ranges:A}).ranges}return Bn(k.sizeTree).reduce((R,{k:L,v:F})=>({prevIndex:L+T,prevSize:F,ranges:[...R.ranges,{endIndex:L+T-1,size:R.prevSize,startIndex:R.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const E=jt(W(i,Le(v,p),se(([T,{offsetTree:k},I])=>{const A=-T;return Lr(A,k,I)})));return fe(W(i,Le(v,p),se(([T,k,I])=>{if(k.groupIndices.length>0){if(Je(k.sizeTree))return k;let A=cr();const _=at(g);let R=0,L=0,F=0;for(;R<-T;){F=_[L];const V=_[L+1]-F-1;L++,R+=V+1}if(A=Bn(k.sizeTree).reduce((V,{k:O,v:Y})=>_t(V,Math.max(0,O+T),Y),A),R!==-T){const V=Mr(k.sizeTree,F);A=_t(A,0,V);const O=Wt(k.sizeTree,-T+1)[1];A=_t(A,1,O)}return{...k,sizeTree:A,...bi(k.offsetTree,0,A,I)}}else{const A=Bn(k.sizeTree).reduce((_,{k:R,v:L})=>_t(_,Math.max(0,R+T),L),cr());return{...k,sizeTree:A,...bi(k.offsetTree,0,A,I)}}})),v),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:y,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},tt(yn,vi),{singleton:!0});function ix(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const kc=Ve(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=jt(W(s,se(ix)));return fe(W(a,se(l=>l.totalCount)),n),fe(W(a,se(l=>l.groupIndices)),e),fe(W(ct(o,t,r),Ee(([l,u])=>No(u)),se(([l,u,d])=>Wt(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),nt(),se(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},tt(Qt,St)),Cn=Ve(([{log:e}])=>{const t=J(!1),n=jt(W(t,Ee(r=>r),nt()));return qe(t,r=>{r&&at(e)("props updated",{},Et.DEBUG)}),{didMount:n,propsReady:t}},tt(yn),{singleton:!0}),ax=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Ec(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ax)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Fr=Ve(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=ze(),w=ze(),v=J(0);let g=null,x=null,y=null;function C(){g&&(g(),g=null),y&&(y(),y=null),x&&(clearTimeout(x),x=null),De(l,!1)}return fe(W(p,Le(n,f,r,v,a,i,h),Le(e,s,o),se(([[E,T,k,I,A,_,R,L],F,V,O])=>{const Y=Ec(E),{align:q,behavior:X,offset:B}=Y,$=I-1,z=Cc(Y,T,$);let H=Lr(z,T.offsetTree,F)+_;q==="end"?(H+=V+Wt(T.sizeTree,z)[1]-k+O,z===$&&(H+=R)):q==="center"?H+=(V+Wt(T.sizeTree,z)[1]-k+O)/2:H-=A,B&&(H+=B);const ge=de=>{C(),de?(L("retrying to scroll to",{location:E},Et.DEBUG),De(p,E)):(De(w,!0),L("list did not change, scroll successful",{},Et.DEBUG))};if(C(),X==="smooth"){let de=!1;y=qe(t,ee=>{de=de||ee}),g=Ut(d,()=>{ge(de)})}else g=Ut(W(t,lx(150)),ge);return x=setTimeout(()=>{C()},1200),De(l,!0),L("scrolling from index to",{behavior:X,index:z,top:H},Et.DEBUG),{behavior:X,top:H}})),u),{scrollTargetReached:w,scrollToIndex:p,topListHeight:v}},tt(Qt,St,yn),{singleton:!0});function lx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function yi(e,t){e==0?t():requestAnimationFrame(()=>{yi(e-1,t)})}function Si(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const $r=Ve(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=J(!0),l=J(0),u=J(!0);return fe(W(i,Le(l),Ee(([d,f])=>!!f),Jt(!1)),a),fe(W(i,Le(l),Ee(([d,f])=>!!f),Jt(!1)),u),qe(W(ct(t,i),Le(a,n,e,u),Ee(([[,d],f,{sizeTree:h},p,w])=>d&&(!Je(h)||ui(p))&&!f&&!w),Le(l)),([,d])=>{Ut(o,()=>{De(u,!0)}),yi(4,()=>{Ut(r,()=>{De(a,!0)}),De(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},tt(Qt,St,Fr,Cn),{singleton:!0});function Ic(e,t){return Math.abs(e-t)<1.01}const zr="up",Br="down",cx="none",ux={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},dx=0,Hr=Ve(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=ze(),u=ze(),d=J(4),f=J(dx),h=xt(W(fi(W(ke(o),$n(1),Jt(!0)),W(ke(o),$n(1),Jt(!1),uc(100))),nt()),!1),p=xt(W(fi(W(n,Jt(!0)),W(n,Jt(!1),uc(200))),nt()),!1);fe(W(ct(ke(o),ke(f)),se(([y,C])=>y<=C),nt()),a),fe(W(a,pn(50)),u);const w=jt(W(ct(r,ke(s),ke(t),ke(e),ke(d)),Zt((y,[{scrollHeight:C,scrollTop:E},T,k,I,A])=>{const _=E+T-C>-A,R={scrollHeight:C,scrollTop:E,viewportHeight:T};if(_){let F,V;return E>y.state.scrollTop?(F="SCROLLED_DOWN",V=y.state.scrollTop-E):(F="SIZE_DECREASED",V=y.state.scrollTop-E||y.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:V,state:R}}let L;return R.scrollHeight>y.state.scrollHeight?L="SIZE_INCREASED":T<y.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":E<y.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:R}},ux),nt((y,C)=>y&&y.atBottom===C.atBottom))),v=xt(W(r,Zt((y,{scrollHeight:C,scrollTop:E,viewportHeight:T})=>{if(Ic(y.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:E};{const k=C-(E+T)<1;return y.scrollTop!==E&&k?{changed:!0,jump:y.scrollTop-E,scrollHeight:C,scrollTop:E}:{changed:!0,jump:0,scrollHeight:C,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ee(y=>y.changed),se(y=>y.jump)),0);fe(W(w,se(y=>y.atBottom)),i),fe(W(i,pn(50)),l);const g=J(Br);fe(W(r,se(({scrollTop:y})=>y),nt(),Zt((y,C)=>at(p)?{direction:y.direction,prevScrollTop:C}:{direction:C<y.prevScrollTop?zr:Br,prevScrollTop:C},{direction:Br,prevScrollTop:0}),se(y=>y.direction)),g),fe(W(r,pn(50),Jt(cx)),g);const x=J(0);return fe(W(h,Ee(y=>!y),Jt(0)),x),fe(W(o,pn(100),Le(h),Ee(([y,C])=>!!C),Zt(([y,C],[E])=>[C,E],[0,0]),se(([y,C])=>C-y)),x),{atBottomState:w,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:v,scrollDirection:g,scrollVelocity:x}},tt(St)),Ao="top",jo="bottom",Nc="none";function Ac(e,t,n){return typeof e=="number"?n===zr&&t===Ao||n===Br&&t===jo?e:0:n===zr?t===Ao?e.main:e.reverse:t===jo?e.main:e.reverse}function jc(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Ci=Ve(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=J(0),a=J(0),l=J(0),u=xt(W(ct(ke(r),ke(o),ke(n),ke(s,Dr),ke(l),ke(i),ke(t),ke(e),ke(a)),se(([d,f,h,[p,w],v,g,x,y,C])=>{const E=d-y,T=g+x,k=Math.max(h-E,0);let I=Nc;const A=jc(C,Ao),_=jc(C,jo);return p-=y,p+=h+x,w+=h+x,w-=y,p>d+T-A&&(I=zr),w<d-k+f+_&&(I=Br),I!==Nc?[Math.max(E-h-Ac(v,Ao,I)-A,0),E-k-x+f+Ac(v,jo,I)+_]:null}),Ee(d=>d!=null),nt(Dr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},tt(St),{singleton:!0});function fx(e,t,n){if(No(t)){const r=Sc(e,t);return[{index:Wt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ti={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function _o(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const v=e[e.length-1];d=v.offset+v.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,w=h-d;return{bottom:d,firstItemIndex:s,items:Rc(e,o,s),offsetBottom:w,offsetTop:u,top:p,topItems:Rc(t,o,s),topListHeight:t.reduce((v,g)=>g.size+v,0),totalCount:n}}function _c(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=Si(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return _o(u,[],a,o,n,r)}function Rc(e,t,n){if(e.length===0)return[];if(!No(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ko(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const Hn=Ve(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:w}])=>{const v=J([]),g=J(0),x=ze();fe(s.topItemsIndexes,v);const y=xt(W(ct(p,w,ke(l,Dr),ke(o),ke(r),ke(u),d,ke(v),ke(t),ke(n),e),Ee(([k,I,,A,,,,,,,_])=>{const R=_&&_.length!==A;return k&&!I&&!R}),se(([,,[k,I],A,_,R,L,F,V,O,Y])=>{const q=_,{offsetTree:X,sizeTree:B}=q,$=at(g);if(A===0)return{...Ti,totalCount:A};if(k===0&&I===0)return $===0?{...Ti,totalCount:A}:_c($,R,_,V,O,Y||[]);if(Je(B))return $>0?null:_o(fx(Si(R,A),q,Y),[],A,O,q,V);const z=[];if(F.length>0){const je=F[0],Te=F[F.length-1];let K=0;for(const M of ko(B,je,Te)){const Z=M.value,ne=Math.max(M.start,je),Q=Math.min(M.end,Te);for(let le=ne;le<=Q;le++)z.push({data:Y==null?void 0:Y[le],index:le,offset:K,size:Z}),K+=Z}}if(!L)return _o([],z,A,O,q,V);const H=F.length>0?F[F.length-1]+1:0,ge=ex(X,k,I,H);if(ge.length===0)return null;const de=A-1,ee=To([],je=>{for(const Te of ge){const K=Te.value;let M=K.offset,Z=Te.start;const ne=K.size;if(K.offset<k){Z+=Math.floor((k-K.offset+O)/(ne+O));const le=Z-Te.start;M+=le*ne+le*O}Z<H&&(M+=(H-Z)*ne,Z=H);const Q=Math.min(Te.end,de);for(let le=Z;le<=Q&&!(M>=I);le++)je.push({data:Y==null?void 0:Y[le],index:le,offset:M,size:ne}),M+=ne+O}});return _o(ee,z,A,O,q,V)}),Ee(k=>k!==null),nt()),Ti);fe(W(e,Ee(ui),se(k=>k==null?void 0:k.length)),o),fe(W(y,se(k=>k.topListHeight)),f),fe(f,a),fe(W(y,se(k=>[k.top,k.bottom])),i),fe(W(y,se(k=>k.items)),x);const C=jt(W(y,Ee(({items:k})=>k.length>0),Le(o,e),Ee(([{items:k},I])=>k[k.length-1].originalIndex===I-1),se(([,k,I])=>[k-1,I]),nt(Dr),se(([k])=>k))),E=jt(W(y,pn(200),Ee(({items:k,topItems:I})=>k.length>0&&k[0].originalIndex===I.length),se(({items:k})=>k[0].index),nt())),T=jt(W(y,Ee(({items:k})=>k.length>0),se(({items:k})=>{let I=0,A=k.length-1;for(;k[I].type==="group"&&I<A;)I++;for(;k[A].type==="group"&&A>I;)A--;return{endIndex:k[A].index,startIndex:k[I].index}}),nt(bc)));return{endReached:C,initialItemCount:g,itemsRendered:x,listState:y,rangeChanged:T,startReached:E,topItemsIndexes:v,...h}},tt(Qt,kc,Ci,$r,Fr,Hr,Cn,vi),{singleton:!0}),Pc=Ve(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=xt(W(ct(n,e,r,t,o),se(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return fe(ke(i),s),{totalListHeight:i,totalListHeightChanged:s}},tt(St,Hn),{singleton:!0}),hx=Ve(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=xt(W(ct(n,e,t),Ee(([o])=>o),se(([,o,s])=>Math.max(0,o-s)),pn(0),nt()),0);return{alignToBottom:n,paddingTopAddition:r}},tt(St,Pc),{singleton:!0}),Oc=Ve(()=>({context:J(null)})),px=({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,Mc=Ve(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=ze();return fe(W(d,Le(t,l,n,s,o,r,a),Le(e),se(([[f,h,p,w,v,g,x,y],C])=>{const{align:E,behavior:T,calculateViewLocation:k=px,done:I,...A}=f,_=Cc(f,h,w-1),R=Lr(_,h.offsetTree,C)+v+g,L=R+Wt(h.sizeTree,_)[1],F=y+g,V=y+p-x,O=k({itemBottom:L,itemTop:R,locationParams:{align:E,behavior:T,...A},viewportBottom:V,viewportTop:F});return O?I&&Ut(W(i,Ee(Y=>!Y),$n(at(i)?1:2)),I):I&&I(),O}),Ee(f=>f!==null)),u),{scrollIntoView:d}},tt(Qt,St,Fr,Hn,yn),{singleton:!0});function Dc(e){return e?e==="smooth"?"smooth":"auto":!1}const mx=(e,t)=>typeof e=="function"?Dc(e(t)):t&&Dc(e),gx=Ve(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const w=J(!1),v=ze();let g=null;function x(T){De(i,{align:"end",behavior:T,index:"LAST"})}qe(W(ct(W(ke(t),$n(1)),l),Le(ke(w),s,a,f),se(([[T,k],I,A,_,R])=>{let L=k&&_,F="auto";return L&&(F=mx(I,A||R),L=L&&!!F),{followOutputBehavior:F,shouldFollow:L,totalCount:T}}),Ee(({shouldFollow:T})=>T)),({followOutputBehavior:T,totalCount:k})=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("following output to ",{totalCount:k},Et.DEBUG),x(T)}):g=Ut(e,()=>{at(d)("following output to ",{totalCount:k},Et.DEBUG),x(T),g=null})});function y(T){const k=Ut(o,I=>{T&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(at(d)("scrolling to bottom due to increased size",{},Et.DEBUG),x("auto"))});setTimeout(k,100)}qe(W(ct(ke(w),t,u),Ee(([T,,k])=>T&&k),Zt(({value:T},[,k])=>({refreshed:T===k,value:k}),{refreshed:!1,value:0}),Ee(({refreshed:T})=>T),Le(w,t)),([,T])=>{at(a)&&y(T!==!1)}),qe(v,()=>{y(at(w)!==!1)}),qe(ct(ke(w),o),([T,k])=>{T&&!k.atBottom&&k.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=J(null),E=ze();return fe(fi(W(ke(r),se(T=>{var k;return(k=T==null?void 0:T.length)!=null?k:0})),W(ke(t))),E),qe(W(ct(W(E,$n(1)),l),Le(ke(C),a,f,h),se(([[T,k],I,A,_,R])=>k&&A&&(I==null?void 0:I({context:R,totalCount:T,scrollingInProgress:_}))),Ee(T=>!!T),pn(0)),T=>{g&&(g(),g=null),at(n)?requestAnimationFrame(()=>{at(d)("scrolling into view",{}),De(p,T)}):g=Ut(e,()=>{at(d)("scrolling into view",{}),De(p,T),g=null})}),{autoscrollToBottom:v,followOutput:w,scrollIntoViewOnChange:C}},tt(Qt,Hr,Fr,$r,Cn,yn,St,Oc,Mc)),xx=Ve(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(W(a,Le(s),Ee(([,l])=>l!==0),Le(o,r,t,n,e),se(([[,l],u,d,f,h,p=[]])=>_c(l,u,d,f,h,p))),i),{}),tt(Qt,$r,Hn,Cn),{singleton:!0}),vx=Ve(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return qe(W(e,Le(r),Ee(([,o])=>o!==0),se(([,o])=>({top:o}))),o=>{Ut(W(n,$n(1),Ee(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{De(t,o)})})}),{initialScrollTop:r}},tt(Cn,St,Hn),{singleton:!0}),Lc=Ve(([{scrollVelocity:e}])=>{const t=J(!1),n=ze(),r=J(!1);return fe(W(e,Le(r,t,n),Ee(([o,s])=>!!s),se(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),nt()),t),qe(W(ct(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}},tt(Hr),{singleton:!0}),ki=Ve(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=J(!1),i=J(void 0);return fe(W(ct(n,r),se(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),fe(W(t,Le(r),se(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},tt(St)),wx=Ve(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=ze(),d=J(void 0),f=J(null),h=J(null);return fe(a,f),fe(l,h),qe(W(u,Le(t,r,i,f,h,n)),([p,w,v,g,x,y,C])=>{const E=nx(w.sizeTree);g&&x!==null&&y!==null&&(v=x.scrollTop-y.offsetTop),v-=C,p({ranges:E,scrollTop:v})}),fe(W(d,Ee(ui),se(bx)),o),fe(W(s,Le(d),Ee(([,p])=>p!==void 0),nt(),se(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},tt(Qt,St,$r,Cn,ki));function bx(e){return{align:"start",index:0,offset:e.scrollTop}}const yx=Ve(([{topItemsIndexes:e}])=>{const t=J(0);return fe(W(t,Ee(n=>n>=0),se(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},tt(Hn));function Fc(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Sx=Fc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Cx=Ve(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:w}])=>{const v=jt(W(l,Le(i),Zt(([,x,y,C],[{bottom:E,items:T,offsetBottom:k,totalCount:I},A])=>{const _=E+k;let R=0;return y===I&&x.length>0&&T.length>0&&(T[0].originalIndex===0&&x[0].originalIndex===0||(R=_-C,R!==0&&(R+=A))),[R,T,I,_]},[0,[],0,0]),Ee(([x])=>x!==0),Le(r,a,n,o,p,w),Ee(([,x,y,C,,,E])=>!E&&!C&&x!==0&&y===zr),se(([[x],,,,,y])=>(y("Upward scrolling compensation",{amount:x},Et.DEBUG),x))));function g(x){x>0?(De(t,{behavior:"auto",top:-x}),De(e,0)):(De(e,0),De(t,{behavior:"auto",top:-x}))}return qe(W(v,Le(e,s)),([x,y,C])=>{C&&Sx()?De(e,y-x):g(-x)}),qe(W(ct(xt(s,!1),e,w),Ee(([x,y,C])=>!x&&!C&&y!==0),se(([x,y])=>y),pn(1)),g),fe(W(f,se(x=>({top:-x}))),t),qe(W(u,Le(h,d),se(([x,{groupIndices:y,lastSize:C,sizeTree:E},T])=>{function k(I){return I*(C+T)}if(y.length===0)return k(x);{let I=0;const A=Mr(E,0);let _=0,R=0;for(;_<x;){_++,I+=A;let L=y.length===R+1?1/0:y[R+1]-y[R]-1;_+L>x&&(I-=A,L=x-_+1),_+=L,I+=k(L),R++}return I}})),x=>{De(e,x),requestAnimationFrame(()=>{De(t,{top:x}),requestAnimationFrame(()=>{De(e,0),De(w,!1)})})}),{deviation:e}},tt(St,Hr,Hn,Qt,yn,vi)),Tx=Ve(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),tt(Ci,xx,Cn,Lc,Pc,vx,hx,ki,Mc,yn,Oc)),$c=Ve(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w},v,g,x,{listState:y,topItemsIndexes:C,...E},{scrollToIndex:T},k,{topItemCount:I},{groupCounts:A},_])=>(fe(E.rangeChanged,_.scrollSeekRangeChanged),fe(W(_.windowViewportRect,se(R=>R.visibleHeight)),v.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:w,sizeRanges:a,topItemCount:I,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:y,scrollToIndex:T,statefulTotalCount:u,trackItemSizes:f,...E,..._,...v,sizes:l,...g}),tt(Qt,$r,St,wx,gx,Hn,Fr,Cx,yx,kc,Tx));function kx(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 Ro=typeof document<"u"?S.useLayoutEffect:S.useEffect;function zc(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=S.createContext({});function l(g,x){g.propsReady&&De(g.propsReady,!1);for(const y of r){const C=g[t.required[y]];De(C,x[y])}for(const y of o)if(y in x){const C=g[t.optional[y]];De(C,x[y])}g.propsReady&&De(g.propsReady,!0)}function u(g){return s.reduce((x,y)=>(x[y]=C=>{const E=g[t.methods[y]];De(E,C)},x),{})}function d(g){return i.reduce((x,y)=>(x[y]=Bg(g[t.events[y]]),x),{})}const f=S.forwardRef((g,x)=>{const{children:y,...C}=g,[E]=S.useState(()=>To(Ug(e),I=>{l(I,C)})),[T]=S.useState(cc(d,E));Ro(()=>{for(const I of i)I in C&&qe(T[I],C[I]);return()=>{Object.values(T).map(di)}},[C,T,E]),Ro(()=>{l(E,C)}),S.useImperativeHandle(x,ac(u(E)));const k=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(k,{...kx([...r,...o,...i],C),children:y}):y})}),h=g=>{const x=S.useContext(a);return S.useCallback(y=>{De(x[g],y)},[x,g])},p=g=>{const x=S.useContext(a)[g],y=S.useCallback(C=>qe(x,C),[x]);return S.useSyncExternalStore(y,()=>at(x),()=>at(x))},w=g=>{const x=S.useContext(a)[g],[y,C]=S.useState(cc(at,x));return Ro(()=>qe(x,E=>{E!==y&&C(ac(E))}),[x,y]),y},v=S.version.startsWith("18")?p:w;return{Component:f,useEmitter:(g,x)=>{const y=S.useContext(a)[g];Ro(()=>qe(y,x),[x,y])},useEmitterValue:v,usePublisher:h}}const Bc=S.createContext(void 0),Hc=S.createContext(void 0),Uc=typeof document<"u"?S.useLayoutEffect:S.useEffect;function Ei(e){return"self"in e}function Ex(e){return"body"in e}function Wc(e,t,n,r=lr,o,s){const i=S.useRef(null),a=S.useRef(null),l=S.useRef(null),u=S.useCallback(h=>{let p,w,v;const g=h.target;if(Ex(g)||Ei(g)){const y=Ei(g)?g:g.defaultView;v=s?y.scrollX:y.scrollY,p=s?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight,w=s?y.innerWidth:y.innerHeight}else v=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,w=s?g.offsetWidth:g.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(v,0),viewportHeight:w})};h.suppressFlushSync?x():Ls.flushSync(x),a.current!==null&&(v===a.current||v<=0||v===p-w)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);S.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const w=h.behavior==="smooth";let v,g,x;Ei(p)?(g=Math.max(Sn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),v=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],v=Sn(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const y=g-v;if(h.top=Math.ceil(Math.max(Math.min(y,h.top),0)),Ic(v,g)||h.top===x){e({scrollHeight:g,scrollTop:x,viewportHeight:v}),w&&t(!0);return}w?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ii="-webkit-sticky",Vc="sticky",Ni=Fc(()=>{if(typeof document>"u")return Vc;const e=document.createElement("div");return e.style.position=Ii,e.style.position===Ii?Ii:Vc});function Ai(e){return e}const Ix=Ve(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(Ai),o=J("div"),s=J(lr),i=(a,l=null)=>xt(W(n,se(u=>u[a]),nt()),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")}}),Nx=Ve(([e,t])=>({...e,...t}),tt($c,Ix)),Ax=({height:e})=>c.jsx("div",{style:{height:e}}),jx={overflowAnchor:"none",position:Ni(),zIndex:1},qc={overflowAnchor:"none"},_x={...qc,display:"inline-block",height:"100%"},Kc=S.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Lt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Lt("windowScrollContainerState"),i=Lt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),u=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),h=Ae("itemSize"),p=Ae("log"),w=Lt("gap"),v=Ae("horizontalDirection"),{callbackRef:g}=qg(n,h,f,e?lr:a,p,w,o,v,Ae("skipAnimationFrameInResizeObserver")),[x,y]=S.useState(0);ji("deviation",O=>{x!==O&&y(O)});const C=Ae("EmptyPlaceholder"),E=Ae("ScrollSeekPlaceholder")||Ax,T=Ae("ListComponent"),k=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),_=Ae("isSeeking"),R=Ae("groupIndices").length>0,L=Ae("alignToBottom"),F=Ae("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...v?{display:"inline-block",height:"100%",marginLeft:x!==0?x:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?c.jsx(C,{...vt(C,u)}):c.jsx(T,{...vt(T,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(O=>{const Y=O.originalIndex,q=A(Y+t.firstItemIndex,O.data,u);return _?S.createElement(E,{...vt(E,u),height:O.size,index:O.index,key:q,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?S.createElement(I,{...vt(I,u),"data-index":Y,"data-item-index":O.index,"data-known-size":O.size,key:q,style:jx},d(O.index,u)):S.createElement(k,{...vt(k,u),...Mx(k,O.data),"data-index":Y,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:q,style:v?_x:qc},R?l(O.index,O.groupIndex,O.data,u):l(O.index,O.data,u))})})}),Rx={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Px={outline:"none",overflowX:"auto",position:"relative"},Po=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Ox={position:Ni(),top:0,width:"100%",zIndex:1};function vt(e,t){if(typeof e!="string")return{context:t}}function Mx(e,t){return{item:typeof e=="string"?void 0:t}}const Dx=S.memo(function(){const e=Ae("HeaderComponent"),t=Lt("headerHeight"),n=Ae("HeaderFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),Lx=S.memo(function(){const e=Ae("FooterComponent"),t=Lt("footerHeight"),n=Ae("HeaderFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null});function Gc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:w}=Wc(a,u,l,d,void 0,f);return e("scrollTo",w),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?Px:Rx,...o},tabIndex:0,...i,...vt(l,s),children:r})})}function Yc({useEmitter:e,useEmitterValue:t,usePublisher:n}){return S.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=S.useRef(null),w=t("scrollerRef"),{scrollByCallback:v,scrollerRef:g,scrollToCallback:x}=Wc(a,u,l,w,h);return Uc(()=>{var y;return g.current=h||((y=p.current)==null?void 0:y.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",x),e("scrollBy",v),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...vt(l,s),children:r})})}const Fx=({children:e})=>{const t=S.useContext(Bc),n=Lt("viewportHeight"),r=Lt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=S.useMemo(()=>lc(n,l=>Sn(l,s?"width":"height")),[n,s]),a=zn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return S.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:Po(o),children:e})},$x=({children:e})=>{const t=S.useContext(Bc),n=Lt("windowViewportRect"),r=Lt("fixedItemHeight"),o=Ae("customScrollParent"),s=hc(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return S.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:Po(i),children:e})},zx=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...Ox,marginTop:`${n}px`},o=Ae("context");return c.jsx(t,{style:r,...vt(t,o),children:e})},Bx=S.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return c.jsxs(r||t?Wx:Ux,{...e,context:o,children:[n&&c.jsx(zx,{children:c.jsx(Kc,{showTopList:!0})}),c.jsxs(r||t?$x:Fx,{children:[c.jsx(Dx,{}),c.jsx(Kc,{}),c.jsx(Lx,{})]})]})}),{Component:Hx,useEmitter:ji,useEmitterValue:Ae,usePublisher:Lt}=zc(Nx,{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"}},Bx),Ux=Gc({useEmitter:ji,useEmitterValue:Ae,usePublisher:Lt}),Wx=Yc({useEmitter:ji,useEmitterValue:Ae,usePublisher:Lt}),Vx=Hx;tt($c,Ve(()=>{const e=J(u=>c.jsxs("td",{children:["Item $",u]})),t=J(null),n=J(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=J(null),o=J(null),s=J({}),i=J(Ai),a=J(lr),l=(u,d=null)=>xt(W(s,se(f=>f[u]),nt()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Ni();const Xc={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},qx={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Jc,floor:Oo,max:Ur,min:_i,round:Zc}=Math;function Qc(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Kx(e){return{...qx,items:e}}function Mo(e,t){return e&&e.width===t.width&&e.height===t.height}function Gx(e,t){return e&&e.column===t.column&&e.row===t.row}const Yx=Ve(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:w,propsReady:v},{customScrollParent:g,useWindowScroll:x,windowScrollContainerState:y,windowScrollTo:C,windowViewportRect:E},T])=>{const k=J(0),I=J(0),A=J(Xc),_=J({height:0,width:0}),R=J({height:0,width:0}),L=ze(),F=ze(),V=J(0),O=J(null),Y=J({column:0,row:0}),q=ze(),X=ze(),B=J(!1),$=J(0),z=J(!0),H=J(!1),ge=J(!1);qe(W(w,Le($),Ee(([M,Z])=>!!Z)),()=>{De(z,!1)}),qe(W(ct(w,z,R,_,$,H),Ee(([M,Z,ne,Q,,le])=>M&&!Z&&ne.height!==0&&Q.height!==0&&!le)),([,,,,M])=>{De(H,!0),yi(1,()=>{De(L,M)}),Ut(W(u),()=>{De(t,[0,0]),De(z,!0)})}),fe(W(X,Ee(M=>M!=null&&M.scrollTop>0),Jt(0)),I),qe(W(w,Le(X),Ee(([,M])=>M!=null)),([,M])=>{M&&(De(_,M.viewport),De(R,M.item),De(Y,M.gap),M.scrollTop>0&&(De(B,!0),Ut(W(u,$n(1)),Z=>{De(B,!1)}),De(l,{top:M.scrollTop})))}),fe(W(_,se(({height:M})=>M)),f),fe(W(ct(ke(_,Mo),ke(R,Mo),ke(Y,(M,Z)=>M&&M.column===Z.column&&M.row===Z.row),ke(u)),se(([M,Z,ne,Q])=>({gap:ne,item:Z,scrollTop:Q,viewport:M}))),q),fe(W(ct(ke(k),r,ke(Y,Gx),ke(R,Mo),ke(_,Mo),ke(O),ke(I),ke(B),ke(z),ke($)),Ee(([,,,,,,,M])=>!M),se(([M,[Z,ne],Q,le,Be,Ye,Ke,,Ce,_e])=>{const{column:Qe,row:Ue}=Q,{height:ot,width:lt}=le,{width:ie}=Be;if(Ke===0&&(M===0||ie===0))return Xc;if(lt===0){const mt=Si(_e,M),cn=mt+Math.max(Ke-1,0);return Kx(Qc(mt,cn,Ye))}const ue=eu(ie,lt,Qe);let we,pe;Ce?Z===0&&ne===0&&Ke>0?(we=0,pe=Ke-1):(we=ue*Oo((Z+Ue)/(ot+Ue)),pe=ue*Jc((ne+Ue)/(ot+Ue))-1,pe=_i(M-1,Ur(pe,ue-1)),we=_i(pe,Ur(0,we))):(we=0,pe=-1);const xe=Qc(we,pe,Ye),{bottom:Re,top:Me}=tu(Be,Q,le,xe),Pe=Jc(M/ue),st=Pe*ot+(Pe-1)*Ue-Re;return{bottom:Re,itemHeight:ot,items:xe,itemWidth:lt,offsetBottom:st,offsetTop:Me,top:Me}})),A),fe(W(O,Ee(M=>M!==null),se(M=>M.length)),k),fe(W(ct(_,R,A,Y),Ee(([M,Z,{items:ne}])=>ne.length>0&&Z.height!==0&&M.height!==0),se(([M,Z,{items:ne},Q])=>{const{bottom:le,top:Be}=tu(M,Q,Z,ne);return[Be,le]}),nt(Dr)),t);const de=J(!1);fe(W(u,Le(de),se(([M,Z])=>Z||M!==0)),de);const ee=jt(W(ct(A,k),Ee(([{items:M}])=>M.length>0),Le(de),Ee(([[M,Z],ne])=>{const Q=M.items[M.items.length-1].index===Z-1;return(ne||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===Z)&&Q}),se(([[,M]])=>M-1),nt())),je=jt(W(ke(A),Ee(({items:M})=>M.length>0&&M[0].index===0),Jt(0),nt())),Te=jt(W(ke(A),Le(B),Ee(([{items:M},Z])=>M.length>0&&!Z),se(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),nt(bc),pn(0)));fe(Te,p.scrollSeekRangeChanged),fe(W(L,Le(_,R,k,Y),se(([M,Z,ne,Q,le])=>{const Be=Ec(M),{align:Ye,behavior:Ke,offset:Ce}=Be;let _e=Be.index;_e==="LAST"&&(_e=Q-1),_e=Ur(0,_e,_i(Q-1,_e));let Qe=Ri(Z,le,ne,_e);return Ye==="end"?Qe=Zc(Qe-Z.height+ne.height):Ye==="center"&&(Qe=Zc(Qe-Z.height/2+ne.height/2)),Ce&&(Qe+=Ce),{behavior:Ke,top:Qe}})),l);const K=xt(W(A,se(M=>M.offsetBottom+M.bottom)),0);return fe(W(E,se(M=>({height:M.visibleHeight,width:M.visibleWidth}))),_),{customScrollParent:g,data:O,deviation:V,footerHeight:o,gap:Y,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:R,overscan:n,restoreStateFrom:X,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:L,scrollTop:u,smoothScrollTargetReached:d,totalCount:k,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:y,windowScrollTo:C,windowViewportRect:E,...p,gridState:A,horizontalDirection:ge,initialTopMostItemIndex:$,totalListHeight:K,...h,endReached:ee,propsReady:v,rangeChanged:Te,startReached:je,stateChanged:q,stateRestoreInProgress:B,...T}},tt(Ci,St,Hr,Lc,Cn,ki,yn));function eu(e,t,n){return Ur(1,Oo((e+n)/(Oo(t)+n)))}function tu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ri(e,t,n,r[0].index);return{bottom:Ri(e,t,n,r[r.length-1].index)+o,top:s}}function Ri(e,t,n,r){const o=eu(e.width,n.width,t.column),s=Oo(r/o),i=s*n.height+Ur(0,s-1)*t.row;return i>0?i+t.row:i}const Xx=Ve(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(Ai),i=J("div"),a=J(lr),l=(f,h=null)=>xt(W(t,se(p=>p[f]),nt()),h),u=J(!1),d=J(!1);return fe(ke(d),u),{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:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Jx=Ve(([e,t])=>({...e,...t}),tt(Yx,Xx)),Zx=S.memo(function(){const e=rt("gridState"),t=rt("listClassName"),n=rt("itemClassName"),r=rt("itemContent"),o=rt("computeItemKey"),s=rt("isSeeking"),i=Ft("scrollHeight"),a=rt("ItemComponent"),l=rt("ListComponent"),u=rt("ScrollSeekPlaceholder"),d=rt("context"),f=Ft("itemDimensions"),h=Ft("gap"),p=rt("log"),w=rt("stateRestoreInProgress"),v=Ft("reportReadyState"),g=zn(S.useMemo(()=>x=>{const y=x.parentElement.parentElement.scrollHeight;i(y);const C=x.firstChild;if(C){const{height:E,width:T}=C.getBoundingClientRect();f({height:E,width:T})}h({column:ru("column-gap",getComputedStyle(x).columnGap,p),row:ru("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return Uc(()=>{e.itemHeight>0&&e.itemWidth>0&&v(!0)},[e]),w?null:c.jsx(l,{className:t,ref:g,...vt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const y=o(x.index,x.data,d);return s?c.jsx(u,{...vt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},y):S.createElement(a,{...vt(a,d),className:n,"data-index":x.index,key:y},r(x.index,x.data,d))})})}),Qx=S.memo(function(){const e=rt("HeaderComponent"),t=Ft("headerHeight"),n=rt("headerFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),ev=S.memo(function(){const e=rt("FooterComponent"),t=Ft("footerHeight"),n=rt("headerFooterTag"),r=zn(S.useMemo(()=>s=>{t(Sn(s,"height"))},[t]),!0,!1),o=rt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...vt(e,o)})}):null}),tv=({children:e})=>{const t=S.useContext(Hc),n=Ft("itemDimensions"),r=Ft("viewportDimensions"),o=zn(S.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return S.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:Po(!1),children:e})},nv=({children:e})=>{const t=S.useContext(Hc),n=Ft("windowViewportRect"),r=Ft("itemDimensions"),o=rt("customScrollParent"),s=hc(n,o,!1);return S.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:Po(!1),children:e})},rv=S.memo(function({...e}){const t=rt("useWindowScroll"),n=rt("customScrollParent"),r=n||t?sv:ov,o=n||t?nv:tv,s=rt("context");return c.jsx(r,{...e,...vt(r,s),children:c.jsxs(o,{children:[c.jsx(Qx,{}),c.jsx(Zx,{}),c.jsx(ev,{})]})})}),{useEmitter:nu,useEmitterValue:rt,usePublisher:Ft}=zc(Jx,{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"}},rv),ov=Gc({useEmitter:nu,useEmitterValue:rt,usePublisher:Ft}),sv=Yc({useEmitter:nu,useEmitterValue:rt,usePublisher:Ft});function ru(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Et.WARN),t==="normal"?0:parseInt(t??"0",10)}const iv=io.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 Pi({className:e,variant:t,...n}){return c.jsx("div",{className:te(iv({variant:t}),e),...n})}function ce(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function av(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function en(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...w}=f,v=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=m.useMemo(()=>w,Object.values(w));return c.jsx(v.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var v;const p=((v=h==null?void 0:h[e])==null?void 0:v[l])||a,w=m.useContext(p);if(w)return w;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,lv(o,...t)]}function lv(...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:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var ft=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},cv=m[" useInsertionEffect ".trim().toString()]||ft;function Un({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=uv({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=dv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function uv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return cv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function dv(e){return typeof e=="function"}function ou(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Oi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=ou(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():ou(e[o],null)}}}}function $e(...e){return m.useCallback(Oi(...e),e)}var fv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ie=fv.reduce((e,t)=>{const n=Mn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function su(e,t){e&&ao.flushSync(()=>e.dispatchEvent(t))}function hv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Rt=e=>{const{present:t,children:n}=e,r=pv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=$e(r.ref,mv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Rt.displayName="Presence";function pv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=hv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=Do(r.current);s.current=a==="mounted"?u:"none"},[a]),ft(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=Do(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),ft(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const v=Do(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&v&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=Do(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function Do(e){return(e==null?void 0:e.animationName)||"none"}function mv(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 gv=m[" useId ".trim().toString()]||(()=>{}),xv=0;function tn(e){const[t,n]=m.useState(gv());return ft(()=>{n(r=>r??String(xv++))},[e]),e||(t?`radix-${t}`:"")}var Lo="Collapsible",[vv,tT]=en(Lo),[wv,Mi]=vv(Lo),iu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=Un({prop:r,defaultProp:o??!1,onChange:i,caller:Lo});return c.jsx(wv,{scope:n,disabled:s,contentId:tn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ie.div,{"data-state":Li(l),"data-disabled":s?"":void 0,...a,ref:t})})});iu.displayName=Lo;var au="CollapsibleTrigger",lu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Mi(au,n);return c.jsx(Ie.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Li(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ce(e.onClick,o.onOpenToggle)})});lu.displayName=au;var Di="CollapsibleContent",bv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Mi(Di,e.__scopeCollapsible);return c.jsx(Rt,{present:n||o.open,children:({present:s})=>c.jsx(yv,{...r,ref:t,present:s})})});bv.displayName=Di;var yv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Mi(Di,n),[a,l]=m.useState(r),u=m.useRef(null),d=$e(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),w=p.current,v=i.open||a,g=m.useRef(v),x=m.useRef(void 0);return m.useEffect(()=>{const y=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(y)},[]),ft(()=>{const y=u.current;if(y){x.current=x.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const C=y.getBoundingClientRect();f.current=C.height,p.current=C.width,g.current||(y.style.transitionDuration=x.current.transitionDuration,y.style.animationName=x.current.animationName),l(r)}},[i.open,r]),c.jsx(Ie.div,{"data-state":Li(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!v,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":w?`${w}px`:void 0,...e.style},children:v&&o})});function Li(e){return e?"open":"closed"}var Sv=iu;const cu=Sv,uu=lu,Wr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Wr.displayName="Card";const Vr=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));Vr.displayName="CardHeader";const qr=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));qr.displayName="CardTitle";const du=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));du.displayName="CardDescription";const Fo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));Fo.displayName="CardContent";const fu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));fu.displayName="CardFooter";function hu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Wn=hu();function Cv(e){Wn=e}const pu=/[&<>"']/,Tv=new RegExp(pu.source,"g"),mu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,kv=new RegExp(mu.source,"g"),Ev={"&":"&","<":"<",">":">",'"':""","'":"'"},gu=e=>Ev[e];function wt(e,t){if(t){if(pu.test(e))return e.replace(Tv,gu)}else if(mu.test(e))return e.replace(kv,gu);return e}const Iv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function xu(e){return e.replace(Iv,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const Nv=/(^|[^\[])\^/g;function Ze(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Nv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Av=/[^\w:]/g,jv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function vu(e,t,n){if(e){let r;try{r=decodeURIComponent(xu(n)).replace(Av,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!jv.test(n)&&(n=Ov(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const $o={},_v=/^[^:]+:\/*[^/]*$/,Rv=/^([^:]+:)[\s\S]*$/,Pv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Ov(e,t){$o[" "+e]||(_v.test(e)?$o[" "+e]=e+"/":$o[" "+e]=Bo(e,"/",!0)),e=$o[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Rv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Pv,"$1")+t:e+t}const zo={exec:function(){}};function wu(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Bo(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function Mv(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function Dv(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function bu(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function yu(e,t,n,r){const o=t.href,s=t.title?wt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:wt(i)}}function Lv(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
40
40
|
`).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
|
|
41
41
|
`)}class Fi{constructor(t){this.options=t||Wn}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Bo(r,`
|
|
42
42
|
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Lv(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=Bo(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,w,v=n[1].trim();const g=v.length>1,x={type:"list",raw:"",ordered:g,start:g?+v.slice(0,-1):"",loose:!1,items:[]};v=g?`\\d{1,9}\\${v.slice(-1)}`:`\\${v}`,this.options.pedantic&&(v=g?v:"[*+-]");const y=new RegExp(`^( {0,3}${v})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(w=!1,!(!(n=y.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
@@ -81,7 +81,7 @@ ${t}</tr>
|
|
|
81
81
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
82
82
|
`}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=vu(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=vu(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 Cu{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 Tu{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 kn{constructor(t){this.options=t||Wn,this.options.renderer=this.options.renderer||new $i,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Cu,this.slugger=new Tu}static parse(t,n){return new kn(n).parse(t)}static parseInline(t,n){return new kn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,u,d,f,h,p,w,v,g,x,y,C,E,T,k;const I=t.length;for(o=0;o<I;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(k=this.options.extensions.renderers[p.type].call({parser:this},p),k!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=k||"";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,xu(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(u=p.rows[s],d="",l=u.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(w=p.ordered,v=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)y=p.items[s],C=y.checked,E=y.task,x="",y.task&&(T=this.renderer.checkbox(C),g?y.tokens.length>0&&y.tokens[0].type==="paragraph"?(y.tokens[0].text=T+" "+y.tokens[0].text,y.tokens[0].tokens&&y.tokens[0].tokens.length>0&&y.tokens[0].tokens[0].type==="text"&&(y.tokens[0].tokens[0].text=T+" "+y.tokens[0].tokens[0].text)):y.tokens.unshift({type:"text",text:T}):x+=T),x+=this.parse(y.tokens,g),h+=this.renderer.listitem(x,E,C);r+=this.renderer.list(h,w,v);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<I&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
83
83
|
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}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 Ho{constructor(t){this.options=t||Wn}preprocess(t){return t}postprocess(t){return t}}Fp(Ho,"passThroughHooks",new Set(["preprocess","postprocess"]));function $v(e,t,n){return r=>{if(r.message+=`
|
|
84
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+wt(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 ku(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=$v(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(Dv(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 u=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 u();let d=0;Se.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();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 ku(Tn.lex,kn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},Cv(Se.defaults),Se},Se.getDefaults=hu,Se.defaults=Wn,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 $i;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 Fi;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 Ho;for(const s in n.hooks){const i=o[s];Ho.passThroughHooks.has(s)?o[s]=a=>{if(Se.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));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=ku(Tn.lexInline,kn.parseInline),Se.Parser=kn,Se.parser=kn.parse,Se.Renderer=$i,Se.TextRenderer=Cu,Se.Lexer=Tn,Se.lexer=Tn.lex,Se.Tokenizer=Fi,Se.Slugger=Tu,Se.Hooks=Ho,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,kn.parse,Tn.lex;function zi({content:e,className:t="",allowHtml:n=!1}){const r=S.useMemo(()=>{try{if(!n){const o=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return Se.parse(o)}return Se.parse(e)}catch(o){return console.error("[MarkdownContent] parse error",o),`<pre>Error rendering markdown: ${String(o)}</pre>`}},[e,n]);return c.jsx("div",{className:te("markdown prose max-w-none break-words dark:prose-invert",t),dangerouslySetInnerHTML:{__html:r}})}async function Eu(e,t){return await Nt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Iu(e,t){return await(await Eu(`/files/${e}/view`,t)).text()}async function zv(e,t){const n=await Eu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Nt(`/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 Bv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Nt("/files",{params:r})}const Hv=1,Uv=1e6;let Bi=0;function Wv(){return Bi=(Bi+1)%Number.MAX_SAFE_INTEGER,Bi.toString()}const Hi=new Map,Nu=e=>{if(Hi.has(e))return;const t=setTimeout(()=>{Hi.delete(e),qr({type:"REMOVE_TOAST",toastId:e})},Uv);Hi.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?Nu(n):e.toasts.forEach(r=>{Nu(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)}}},Uo=[];let Wo={toasts:[]};function qr(e){Wo=Vv(Wo,e),Uo.forEach(t=>{t(Wo)})}function Kv({...e}){const t=Wv(),n=o=>qr({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>qr({type:"DISMISS_TOAST",toastId:t});return qr({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ui(){const[e,t]=m.useState(Wo);return m.useEffect(()=>(Uo.push(t),()=>{const n=Uo.indexOf(t);n>-1&&Uo.splice(n,1)}),[e]),{...e,toast:Kv,dismiss:n=>qr({type:"DISMISS_TOAST",toastId:n})}}function pt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function qv(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Gv="DismissableLayer",Wi="dismissableLayer.update",Yv="dismissableLayer.pointerDownOutside",Xv="dismissableLayer.focusOutside",Au,ju=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Vo=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(ju),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=$e(t,I=>f(I)),v=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(g),y=d?v.indexOf(d):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,E=y>=x,T=Qv(I=>{const A=I.target,_=[...u.branches].some(R=>R.contains(A));!E||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),k=ew(I=>{const A=I.target;[...u.branches].some(R=>R.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return qv(I=>{y===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(Au=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),_u(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=Au)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),_u())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Wi,I),()=>document.removeEventListener(Wi,I)},[]),c.jsx(Ie.div,{...l,ref:w,style:{pointerEvents:C?E?"auto":"none":void 0,...e.style},onFocusCapture:ce(e.onFocusCapture,k.onFocusCapture),onBlurCapture:ce(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:ce(e.onPointerDownCapture,T.onPointerDownCapture)})});Vo.displayName=Gv;var Jv="DismissableLayerBranch",Zv=m.forwardRef((e,t)=>{const n=m.useContext(ju),r=m.useRef(null),o=$e(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Ie.div,{...e,ref:o})});Zv.displayName=Jv;function Qv(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Ru(Yv,n,u,{discrete:!0})};const u={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 ew(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Ru(Xv,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 _u(){const e=new CustomEvent(Wi);document.dispatchEvent(e)}function Ru(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?su(o,s):o.dispatchEvent(s)}var Vi="focusScope.autoFocusOnMount",Ki="focusScope.autoFocusOnUnmount",Pu={bubbles:!1,cancelable:!0},tw="FocusScope",Ko=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=pt(o),d=pt(s),f=m.useRef(null),h=$e(t,v=>l(v)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let v=function(C){if(p.paused||!a)return;const E=C.target;a.contains(E)?f.current=E:En(f.current,{select:!0})},g=function(C){if(p.paused||!a)return;const E=C.relatedTarget;E!==null&&(a.contains(E)||En(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const T of C)T.removedNodes.length>0&&En(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",g);const y=new MutationObserver(x);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",g),y.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){Du.add(p);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(Vi,Pu);a.addEventListener(Vi,u),a.dispatchEvent(x),x.defaultPrevented||(nw(aw(Ou(a)),{select:!0}),document.activeElement===v&&En(a))}return()=>{a.removeEventListener(Vi,u),setTimeout(()=>{const x=new CustomEvent(Ki,Pu);a.addEventListener(Ki,d),a.dispatchEvent(x),x.defaultPrevented||En(v??document.body,{select:!0}),a.removeEventListener(Ki,d),Du.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(v=>{if(!n&&!r||p.paused)return;const g=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(g&&x){const y=v.currentTarget,[C,E]=rw(y);C&&E?!v.shiftKey&&x===E?(v.preventDefault(),n&&En(C,{select:!0})):v.shiftKey&&x===C&&(v.preventDefault(),n&&En(E,{select:!0})):x===y&&v.preventDefault()}},[n,r,p.paused]);return c.jsx(Ie.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});Ko.displayName=tw;function nw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(En(r,{select:t}),document.activeElement!==n)return}function rw(e){const t=Ou(e),n=Mu(t,e),r=Mu(t.reverse(),e);return[n,r]}function Ou(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 Mu(e,t){for(const n of e)if(!ow(n,{upTo:t}))return n}function ow(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 sw(e){return e instanceof HTMLInputElement&&"select"in e}function En(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&sw(e)&&t&&e.select()}}var Du=iw();function iw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Lu(e,t),e.unshift(t)},remove(t){var n;e=Lu(e,t),(n=e[0])==null||n.resume()}}}function Lu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function aw(e){return e.filter(t=>t.tagName!=="A")}var lw="Portal",qo=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);ft(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ls.createPortal(c.jsx(Ie.div,{...r,ref:t}),i):null});qo.displayName=lw;var qi=0;function Gi(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Fu()),document.body.insertAdjacentElement("beforeend",e[1]??Fu()),qi++,()=>{qi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),qi--}},[])}function Fu(){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 nn=function(){return nn=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},nn.apply(this,arguments)};function $u(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 cw(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 Go="right-scroll-bar-position",Yo="width-before-scroll-bar",uw="with-scroll-bars-hidden",dw="--removed-body-scroll-bar-size";function Yi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function fw(e,t){var n=S.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 hw=typeof window<"u"?m.useLayoutEffect:m.useEffect,zu=new WeakMap;function pw(e,t){var n=fw(null,function(r){return e.forEach(function(o){return Yi(o,r)})});return hw(function(){var r=zu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Yi(a,null)}),s.forEach(function(a){o.has(a)||Yi(a,i)})}zu.set(n,e)},[e]),n}function mw(e){return e}function gw(e,t){t===void 0&&(t=mw);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function xw(e){e===void 0&&(e={});var t=gw(null);return t.options=nn({async:!0,ssr:!1},e),t}var Bu=function(e){var t=e.sideCar,n=$u(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,nn({},n))};Bu.isSideCarExport=!0;function vw(e,t){return e.useMedium(t),Bu}var Hu=xw(),Xi=function(){},Xo=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Xi,onWheelCapture:Xi,onTouchMoveCapture:Xi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,v=e.inert,g=e.allowPinchZoom,x=e.as,y=x===void 0?"div":x,C=e.gapMode,E=$u(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=h,k=pw([n,t]),I=nn(nn({},E),o);return m.createElement(m.Fragment,null,d&&m.createElement(T,{sideCar:Hu,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:v,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:C}),i?m.cloneElement(m.Children.only(a),nn(nn({},I),{ref:k})):m.createElement(y,nn({},I,{className:l,ref:k}),a))});Xo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Xo.classNames={fullWidth:Yo,zeroRight:Go};var ww=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ww();return t&&e.setAttribute("nonce",t),e}function yw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Sw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Cw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=bw())&&(yw(t,n),Sw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Tw=function(){var e=Cw();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Uu=function(){var e=Tw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},kw={left:0,top:0,right:0,gap:0},Ji=function(e){return parseInt(e||"",10)||0},Ew=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[Ji(n),Ji(r),Ji(o)]},Iw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kw;var t=Ew(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])}},Nw=Uu(),ur="data-scroll-locked",Aw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
84
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+wt(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 ku(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=$v(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(Dv(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 u=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 u();let d=0;Se.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();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 ku(Tn.lex,kn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},Cv(Se.defaults),Se},Se.getDefaults=hu,Se.defaults=Wn,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 $i;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 Fi;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 Ho;for(const s in n.hooks){const i=o[s];Ho.passThroughHooks.has(s)?o[s]=a=>{if(Se.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));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=ku(Tn.lexInline,kn.parseInline),Se.Parser=kn,Se.parser=kn.parse,Se.Renderer=$i,Se.TextRenderer=Cu,Se.Lexer=Tn,Se.lexer=Tn.lex,Se.Tokenizer=Fi,Se.Slugger=Tu,Se.Hooks=Ho,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,kn.parse,Tn.lex;function zi({content:e,className:t="",allowHtml:n=!1,style:r}){const o=S.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>Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=S.useMemo(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return c.jsx("div",{className:te("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function Eu(e,t){return await Nt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Iu(e,t){return await(await Eu(`/files/${e}/view`,t)).text()}async function zv(e,t){const n=await Eu(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Nt(`/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 Bv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Nt("/files",{params:r})}const Hv=1,Uv=1e6;let Bi=0;function Wv(){return Bi=(Bi+1)%Number.MAX_SAFE_INTEGER,Bi.toString()}const Hi=new Map,Nu=e=>{if(Hi.has(e))return;const t=setTimeout(()=>{Hi.delete(e),Kr({type:"REMOVE_TOAST",toastId:e})},Uv);Hi.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?Nu(n):e.toasts.forEach(r=>{Nu(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)}}},Uo=[];let Wo={toasts:[]};function Kr(e){Wo=Vv(Wo,e),Uo.forEach(t=>{t(Wo)})}function qv({...e}){const t=Wv(),n=o=>Kr({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Kr({type:"DISMISS_TOAST",toastId:t});return Kr({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ui(){const[e,t]=m.useState(Wo);return m.useEffect(()=>(Uo.push(t),()=>{const n=Uo.indexOf(t);n>-1&&Uo.splice(n,1)}),[e]),{...e,toast:qv,dismiss:n=>Kr({type:"DISMISS_TOAST",toastId:n})}}function pt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Kv(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Gv="DismissableLayer",Wi="dismissableLayer.update",Yv="dismissableLayer.pointerDownOutside",Xv="dismissableLayer.focusOutside",Au,ju=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Vo=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(ju),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),w=$e(t,I=>f(I)),v=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(g),y=d?v.indexOf(d):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,E=y>=x,T=Qv(I=>{const A=I.target,_=[...u.branches].some(R=>R.contains(A));!E||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),k=ew(I=>{const A=I.target;[...u.branches].some(R=>R.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return Kv(I=>{y===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(Au=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),_u(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=Au)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),_u())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Wi,I),()=>document.removeEventListener(Wi,I)},[]),c.jsx(Ie.div,{...l,ref:w,style:{pointerEvents:C?E?"auto":"none":void 0,...e.style},onFocusCapture:ce(e.onFocusCapture,k.onFocusCapture),onBlurCapture:ce(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:ce(e.onPointerDownCapture,T.onPointerDownCapture)})});Vo.displayName=Gv;var Jv="DismissableLayerBranch",Zv=m.forwardRef((e,t)=>{const n=m.useContext(ju),r=m.useRef(null),o=$e(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Ie.div,{...e,ref:o})});Zv.displayName=Jv;function Qv(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Ru(Yv,n,u,{discrete:!0})};const u={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 ew(e,t=globalThis==null?void 0:globalThis.document){const n=pt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Ru(Xv,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 _u(){const e=new CustomEvent(Wi);document.dispatchEvent(e)}function Ru(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?su(o,s):o.dispatchEvent(s)}var Vi="focusScope.autoFocusOnMount",qi="focusScope.autoFocusOnUnmount",Pu={bubbles:!1,cancelable:!0},tw="FocusScope",qo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=pt(o),d=pt(s),f=m.useRef(null),h=$e(t,v=>l(v)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let v=function(C){if(p.paused||!a)return;const E=C.target;a.contains(E)?f.current=E:En(f.current,{select:!0})},g=function(C){if(p.paused||!a)return;const E=C.relatedTarget;E!==null&&(a.contains(E)||En(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const T of C)T.removedNodes.length>0&&En(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",g);const y=new MutationObserver(x);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",g),y.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){Du.add(p);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(Vi,Pu);a.addEventListener(Vi,u),a.dispatchEvent(x),x.defaultPrevented||(nw(aw(Ou(a)),{select:!0}),document.activeElement===v&&En(a))}return()=>{a.removeEventListener(Vi,u),setTimeout(()=>{const x=new CustomEvent(qi,Pu);a.addEventListener(qi,d),a.dispatchEvent(x),x.defaultPrevented||En(v??document.body,{select:!0}),a.removeEventListener(qi,d),Du.remove(p)},0)}}},[a,u,d,p]);const w=m.useCallback(v=>{if(!n&&!r||p.paused)return;const g=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(g&&x){const y=v.currentTarget,[C,E]=rw(y);C&&E?!v.shiftKey&&x===E?(v.preventDefault(),n&&En(C,{select:!0})):v.shiftKey&&x===C&&(v.preventDefault(),n&&En(E,{select:!0})):x===y&&v.preventDefault()}},[n,r,p.paused]);return c.jsx(Ie.div,{tabIndex:-1,...i,ref:h,onKeyDown:w})});qo.displayName=tw;function nw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(En(r,{select:t}),document.activeElement!==n)return}function rw(e){const t=Ou(e),n=Mu(t,e),r=Mu(t.reverse(),e);return[n,r]}function Ou(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 Mu(e,t){for(const n of e)if(!ow(n,{upTo:t}))return n}function ow(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 sw(e){return e instanceof HTMLInputElement&&"select"in e}function En(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&sw(e)&&t&&e.select()}}var Du=iw();function iw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Lu(e,t),e.unshift(t)},remove(t){var n;e=Lu(e,t),(n=e[0])==null||n.resume()}}}function Lu(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function aw(e){return e.filter(t=>t.tagName!=="A")}var lw="Portal",Ko=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);ft(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ls.createPortal(c.jsx(Ie.div,{...r,ref:t}),i):null});Ko.displayName=lw;var Ki=0;function Gi(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Fu()),document.body.insertAdjacentElement("beforeend",e[1]??Fu()),Ki++,()=>{Ki===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ki--}},[])}function Fu(){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 nn=function(){return nn=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},nn.apply(this,arguments)};function $u(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 cw(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 Go="right-scroll-bar-position",Yo="width-before-scroll-bar",uw="with-scroll-bars-hidden",dw="--removed-body-scroll-bar-size";function Yi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function fw(e,t){var n=S.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 hw=typeof window<"u"?m.useLayoutEffect:m.useEffect,zu=new WeakMap;function pw(e,t){var n=fw(null,function(r){return e.forEach(function(o){return Yi(o,r)})});return hw(function(){var r=zu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Yi(a,null)}),s.forEach(function(a){o.has(a)||Yi(a,i)})}zu.set(n,e)},[e]),n}function mw(e){return e}function gw(e,t){t===void 0&&(t=mw);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function xw(e){e===void 0&&(e={});var t=gw(null);return t.options=nn({async:!0,ssr:!1},e),t}var Bu=function(e){var t=e.sideCar,n=$u(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,nn({},n))};Bu.isSideCarExport=!0;function vw(e,t){return e.useMedium(t),Bu}var Hu=xw(),Xi=function(){},Xo=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Xi,onWheelCapture:Xi,onTouchMoveCapture:Xi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,w=e.noIsolation,v=e.inert,g=e.allowPinchZoom,x=e.as,y=x===void 0?"div":x,C=e.gapMode,E=$u(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=h,k=pw([n,t]),I=nn(nn({},E),o);return m.createElement(m.Fragment,null,d&&m.createElement(T,{sideCar:Hu,removeScrollBar:u,shards:f,noRelative:p,noIsolation:w,inert:v,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:C}),i?m.cloneElement(m.Children.only(a),nn(nn({},I),{ref:k})):m.createElement(y,nn({},I,{className:l,ref:k}),a))});Xo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Xo.classNames={fullWidth:Yo,zeroRight:Go};var ww=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bw(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ww();return t&&e.setAttribute("nonce",t),e}function yw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Sw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Cw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=bw())&&(yw(t,n),Sw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Tw=function(){var e=Cw();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Uu=function(){var e=Tw(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},kw={left:0,top:0,right:0,gap:0},Ji=function(e){return parseInt(e||"",10)||0},Ew=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[Ji(n),Ji(r),Ji(o)]},Iw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kw;var t=Ew(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])}},Nw=Uu(),ur="data-scroll-locked",Aw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
85
85
|
.`.concat(uw,` {
|
|
86
86
|
overflow: hidden `).concat(r,`;
|
|
87
87
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -118,18 +118,18 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
118
118
|
body[`).concat(ur,`] {
|
|
119
119
|
`).concat(dw,": ").concat(a,`px;
|
|
120
120
|
}
|
|
121
|
-
`)},Wu=function(){var e=parseInt(document.body.getAttribute(ur)||"0",10);return isFinite(e)?e:0},jw=function(){m.useEffect(function(){return document.body.setAttribute(ur,(Wu()+1).toString()),function(){var e=Wu()-1;e<=0?document.body.removeAttribute(ur):document.body.setAttribute(ur,e.toString())}},[])},_w=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;jw();var s=m.useMemo(function(){return Iw(o)},[o]);return m.createElement(Nw,{styles:Aw(s,!t,o,n?"":"!important")})},Zi=!1;if(typeof window<"u")try{var Jo=Object.defineProperty({},"passive",{get:function(){return Zi=!0,!0}});window.addEventListener("test",Jo,Jo),window.removeEventListener("test",Jo,Jo)}catch{Zi=!1}var dr=Zi?{passive:!1}:!1,Rw=function(e){return e.tagName==="TEXTAREA"},Vu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Rw(e)&&n[t]==="visible")},Pw=function(e){return Vu(e,"overflowY")},Ow=function(e){return Vu(e,"overflowX")},
|
|
121
|
+
`)},Wu=function(){var e=parseInt(document.body.getAttribute(ur)||"0",10);return isFinite(e)?e:0},jw=function(){m.useEffect(function(){return document.body.setAttribute(ur,(Wu()+1).toString()),function(){var e=Wu()-1;e<=0?document.body.removeAttribute(ur):document.body.setAttribute(ur,e.toString())}},[])},_w=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;jw();var s=m.useMemo(function(){return Iw(o)},[o]);return m.createElement(Nw,{styles:Aw(s,!t,o,n?"":"!important")})},Zi=!1;if(typeof window<"u")try{var Jo=Object.defineProperty({},"passive",{get:function(){return Zi=!0,!0}});window.addEventListener("test",Jo,Jo),window.removeEventListener("test",Jo,Jo)}catch{Zi=!1}var dr=Zi?{passive:!1}:!1,Rw=function(e){return e.tagName==="TEXTAREA"},Vu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Rw(e)&&n[t]==="visible")},Pw=function(e){return Vu(e,"overflowY")},Ow=function(e){return Vu(e,"overflowX")},qu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Ku(e,r);if(o){var s=Gu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Mw=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Dw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Ku=function(e,t){return e==="v"?Pw(t):Ow(t)},Gu=function(e,t){return e==="v"?Mw(t):Dw(t)},Lw=function(e,t){return e==="h"&&t==="rtl"?-1:1},Fw=function(e,t,n,r,o){var s=Lw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),u=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Gu(e,a),w=p[0],v=p[1],g=p[2],x=v-g-s*w;(w||x)&&Ku(e,a)&&(f+=x,h+=w);var y=a.parentNode;a=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(u=!0),u},Zo=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Yu=function(e){return[e.deltaX,e.deltaY]},Xu=function(e){return e&&"current"in e?e.current:e},$w=function(e,t){return e[0]===t[0]&&e[1]===t[1]},zw=function(e){return`
|
|
122
122
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
123
123
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
124
|
-
`)},Bw=0,fr=[];function Hw(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Bw++)[0],s=m.useState(Uu)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var v=cw([e.lockRef.current],(e.shards||[]).map(Xu),!0).filter(Boolean);return v.forEach(function(g){return g.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),v.forEach(function(g){return g.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(v,g){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!i.current.allowPinchZoom;var x=Zo(v),y=n.current,C="deltaX"in v?v.deltaX:y[0]-x[0],E="deltaY"in v?v.deltaY:y[1]-x[1],T,k=v.target,I=Math.abs(C)>Math.abs(E)?"h":"v";if("touches"in v&&I==="h"&&k.type==="range")return!1;var A=
|
|
124
|
+
`)},Bw=0,fr=[];function Hw(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Bw++)[0],s=m.useState(Uu)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var v=cw([e.lockRef.current],(e.shards||[]).map(Xu),!0).filter(Boolean);return v.forEach(function(g){return g.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),v.forEach(function(g){return g.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(v,g){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!i.current.allowPinchZoom;var x=Zo(v),y=n.current,C="deltaX"in v?v.deltaX:y[0]-x[0],E="deltaY"in v?v.deltaY:y[1]-x[1],T,k=v.target,I=Math.abs(C)>Math.abs(E)?"h":"v";if("touches"in v&&I==="h"&&k.type==="range")return!1;var A=qu(I,k);if(!A)return!0;if(A?T=I:(T=I==="v"?"h":"v",A=qu(I,k)),!A)return!1;if(!r.current&&"changedTouches"in v&&(C||E)&&(r.current=T),!T)return!0;var _=r.current||T;return Fw(_,g,v,_==="h"?C:E)},[]),l=m.useCallback(function(v){var g=v;if(!(!fr.length||fr[fr.length-1]!==s)){var x="deltaY"in g?Yu(g):Zo(g),y=t.current.filter(function(T){return T.name===g.type&&(T.target===g.target||g.target===T.shadowParent)&&$w(T.delta,x)})[0];if(y&&y.should){g.cancelable&&g.preventDefault();return}if(!y){var C=(i.current.shards||[]).map(Xu).filter(Boolean).filter(function(T){return T.contains(g.target)}),E=C.length>0?a(g,C[0]):!i.current.noIsolation;E&&g.cancelable&&g.preventDefault()}}},[]),u=m.useCallback(function(v,g,x,y){var C={name:v,delta:g,target:x,should:y,shadowParent:Uw(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(E){return E!==C})},1)},[]),d=m.useCallback(function(v){n.current=Zo(v),r.current=void 0},[]),f=m.useCallback(function(v){u(v.type,Yu(v),v.target,a(v,e.lockRef.current))},[]),h=m.useCallback(function(v){u(v.type,Zo(v),v.target,a(v,e.lockRef.current))},[]);m.useEffect(function(){return fr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,dr),document.addEventListener("touchmove",l,dr),document.addEventListener("touchstart",d,dr),function(){fr=fr.filter(function(v){return v!==s}),document.removeEventListener("wheel",l,dr),document.removeEventListener("touchmove",l,dr),document.removeEventListener("touchstart",d,dr)}},[]);var p=e.removeScrollBar,w=e.inert;return m.createElement(m.Fragment,null,w?m.createElement(s,{styles:zw(o)}):null,p?m.createElement(_w,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Uw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Ww=vw(Hu,Hw);var Qo=m.forwardRef(function(e,t){return m.createElement(Xo,nn({},e,{ref:t,sideCar:Ww}))});Qo.classNames=Xo.classNames;var Vw=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},hr=new WeakMap,es=new WeakMap,ts={},Qi=0,Ju=function(e){return e&&(e.host||Ju(e.parentNode))},qw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Ju(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})},Kw=function(e,t,n,r){var o=qw(t,Array.isArray(e)?e:[e]);ts[n]||(ts[n]=new WeakMap);var s=ts[n],i=[],a=new Set,l=new Set(o),u=function(f){!f||a.has(f)||(a.add(f),u(f.parentNode))};o.forEach(u);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),w=p!==null&&p!=="false",v=(hr.get(h)||0)+1,g=(s.get(h)||0)+1;hr.set(h,v),s.set(h,g),i.push(h),v===1&&w&&es.set(h,!0),g===1&&h.setAttribute(n,"true"),w||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),Qi++,function(){i.forEach(function(f){var h=hr.get(f)-1,p=s.get(f)-1;hr.set(f,h),s.set(f,p),h||(es.has(f)||f.removeAttribute(r),es.delete(f)),p||f.removeAttribute(n)}),Qi--,Qi||(hr=new WeakMap,hr=new WeakMap,es=new WeakMap,ts={})}},ea=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Vw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Kw(r,o,n,"aria-hidden")):function(){return null}},ns="Dialog",[Zu,nT]=en(ns),[Gw,Vt]=Zu(ns),Qu=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[u,d]=Un({prop:r,defaultProp:o??!1,onChange:s,caller:ns});return c.jsx(Gw,{scope:t,triggerRef:a,contentRef:l,contentId:tn(),titleId:tn(),descriptionId:tn(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Qu.displayName=ns;var ed="DialogTrigger",td=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Vt(ed,n),s=$e(t,o.triggerRef);return c.jsx(Ie.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ra(o.open),...r,ref:s,onClick:ce(e.onClick,o.onOpenToggle)})});td.displayName=ed;var ta="DialogPortal",[Yw,nd]=Zu(ta,{forceMount:void 0}),rd=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Vt(ta,t);return c.jsx(Yw,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Rt,{present:n||s.open,children:c.jsx(Ko,{asChild:!0,container:o,children:i})}))})};rd.displayName=ta;var rs="DialogOverlay",od=m.forwardRef((e,t)=>{const n=nd(rs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Vt(rs,e.__scopeDialog);return s.modal?c.jsx(Rt,{present:r||s.open,children:c.jsx(Jw,{...o,ref:t})}):null});od.displayName=rs;var Xw=Mn.createSlot("DialogOverlay.RemoveScroll"),Jw=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Vt(rs,n);return c.jsx(Qo,{as:Xw,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(Ie.div,{"data-state":ra(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Vn="DialogContent",sd=m.forwardRef((e,t)=>{const n=nd(Vn,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Vt(Vn,e.__scopeDialog);return c.jsx(Rt,{present:r||s.open,children:s.modal?c.jsx(Zw,{...o,ref:t}):c.jsx(Qw,{...o,ref:t})})});sd.displayName=Vn;var Zw=m.forwardRef((e,t)=>{const n=Vt(Vn,e.__scopeDialog),r=m.useRef(null),o=$e(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return ea(s)},[]),c.jsx(id,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ce(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ce(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault())})}),Qw=m.forwardRef((e,t)=>{const n=Vt(Vn,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(id,{...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,u;(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;((u=n.triggerRef.current)==null?void 0:u.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),id=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Vt(Vn,n),l=m.useRef(null),u=$e(t,l);return Gi(),c.jsxs(c.Fragment,{children:[c.jsx(qo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(Vo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ra(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(eb,{titleId:a.titleId}),c.jsx(nb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),na="DialogTitle",ad=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Vt(na,n);return c.jsx(Ie.h2,{id:o.titleId,...r,ref:t})});ad.displayName=na;var ld="DialogDescription",cd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Vt(ld,n);return c.jsx(Ie.p,{id:o.descriptionId,...r,ref:t})});cd.displayName=ld;var ud="DialogClose",dd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Vt(ud,n);return c.jsx(Ie.button,{type:"button",...r,ref:t,onClick:ce(e.onClick,()=>o.onOpenChange(!1))})});dd.displayName=ud;function ra(e){return e?"open":"closed"}var fd="DialogTitleWarning",[rT,hd]=av(fd,{contentName:Vn,titleName:na,docsSlug:"dialog"}),eb=({titleId:e})=>{const t=hd(fd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
125
125
|
|
|
126
126
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
127
127
|
|
|
128
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},tb="DialogDescriptionWarning",nb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hd(tb).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},pd=Qu,rb=td,md=rd,os=od,ss=sd,
|
|
129
|
-
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function fb(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function hb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Td(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function pb({className:e}){const[t,n]=S.useState(0);return S.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const kd=S.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:p={},onEdit:w,onRegenerate:v,onCancelEdit:g,onCopy:x}){const[y,C]=S.useState(!1),[E,T]=S.useState("collapsed"),[k,I]=S.useState(!1),{currentThreadId:A}=yo(),{handleInterrupt:_}=ci(),{toast:R}=Ui(),[L,F]=S.useState({}),[V,O]=S.useState(!1),[Y,
|
|
130
|
-
… [truncated ${
|
|
131
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[L[ue]?c.jsx(re.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,L[ue]?" (processing)":""]})]},ue)}return ie.type==="interrupt"?c.jsx(xb,{interruptPart:ie,onApprove:Ce,onReject:_e},ue):null},[le,L,Ce,_e,B,f,h,k,X]),Ue=S.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(re.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),ot=S.useCallback(()=>{const ie=ge.trim().length>0||ee.length>0||je.length>0||Te.length>0;if(!$&&!ie&&!r)return Ue();if(t.model==="reflection"){const ue=ge.trim(),we=yd(ue);if(we&&typeof we=="object")return c.jsx(vb,{data:we})}if($&&de.name==="get_issues"){const ue=t.content.find(xe=>xe.type==="tool_end"),we=(ue==null?void 0:ue.output)??
|
|
132
|
-
… [truncated ${xe.length-qn} chars]`:xe,Me=E==="expanded";return c.jsxs(cu,{open:Me,onOpenChange:Pe=>T(Pe?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Pi,{variant:"outline",children:(we.name??"tool")+(we.toolCallId?` • ${we.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Me?Re:Re.slice(0,d)+(Re.length>d?"...":"")})}),c.jsx(uu,{asChild:!0,children:c.jsx(We,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Me?c.jsxs(c.Fragment,{children:[" ",c.jsx(re.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(re.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},we.toolCallId??pe)})})}if(!$){const ue=c.jsx("div",{className:"space-y-2",children:t.content.map((we,pe)=>c.jsx(Qe,{part:we,i:pe},pe))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[ue,c.jsx(pb,{className:H})]}):ue}},[ge,ee.length,je.length,Te.length,r,t.model,$,de.name,q,E,u,Ue,H]),lt=S.useMemo(()=>hb(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:te(Ye(),p.container),children:c.jsxs("div",{className:te(qe(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",X&&"mb-1 pb-1",H,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[Be(),a&<&&c.jsx("span",{className:te("font-medium",X?"text-xs":"text-sm"),children:lt}),$&&de.name&&c.jsxs(Pi,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer",H,"border border-current/40",X&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E!=="collapsed",onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),T(ue=>ue==="collapsed"?"preview":"collapsed"))},onClick:()=>T(ie=>ie==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:de.name}),c.jsx("span",{className:"inline-flex items-center",children:E!=="collapsed"?c.jsx(re.ChevronUp,{className:"h-3 w-3"}):c.jsx(re.ChevronDown,{className:"h-3 w-3"})})]}),$&&!de.name&&c.jsx(We,{variant:"ghost",size:"sm",className:te("h-6 px-1",H,"hover:bg-foreground/10"),onClick:()=>T(ie=>ie==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",E!=="collapsed"?c.jsx(re.ChevronUp,{className:"h-3 w-3"}):c.jsx(re.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:te("text-xs opacity-60",H,X&&"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&&c.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Z($?"visible":"all"),className:te("h-6 w-6 p-0 hover:bg-foreground/10",H,X&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(re.Copy,{className:te(y?"text-success":H,X?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Z("all"),className:te("h-6 px-1 text-xs hover:bg-foreground/10",H),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),B==="user"&&w&&c.jsx(We,{variant:"ghost",size:"sm",onClick:ne,className:te("h-6 w-6 p-0 hover:bg-foreground/10",H,X&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(re.Edit,{className:te(H,X?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&v&&c.jsx(We,{variant:"ghost",size:"sm",onClick:Q,className:te("h-6 w-6 p-0 hover:bg-foreground/10",H,X&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(re.RotateCcw,{className:te(H,X?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:ot()}),$&&E==="expanded"&&(de.toolCallId||de.name)&&c.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",X&&"text-xs"),children:[de.name&&c.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&c.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Z(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",X&&"h-5 w-5"),children:c.jsx(re.Copy,{className:te(y?"text-success":"text-current",X?"h-3 w-3":"h-4 w-4")})}),B==="user"&&w&&c.jsx(We,{variant:"ghost",size:"sm",onClick:ne,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",X&&"h-5 w-5"),children:c.jsx(re.Edit,{className:te("text-current",X?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&v&&c.jsx(We,{variant:"ghost",size:"sm",onClick:Q,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",X&&"h-5 w-5"),children:c.jsx(re.RotateCcw,{className:te("text-current",X?"h-3 w-3":"h-4 w-4")})})]})]})}),Y&&c.jsx(ab,{isOpen:V,onClose:()=>{O(!1),K(null)},fileId:Y.id,fileName:Y.name,mimeType:Y.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Td(e.message)===Td(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),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)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function mb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:as,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oa(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:as,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:as,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:gb(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oa(e)})}function gb(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(Gr(e))})}catch{return String(e)}}function xb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(Wr,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(Vr,{className:"pb-3",children:[c.jsx(Kr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(du,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(fu,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(We,{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",children:"Reject"}),c.jsx(We,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function vb({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function wb({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:as,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const Ed=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,sa=S.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:g,onAtBottom:x},y)=>{const C=S.useRef(null),E=S.useRef(null),T=S.useRef(!1),[k,I]=S.useState(!0),A=S.useCallback(L=>{I(L),g&&g(!L),x&&x(L)},[g,x]),_=S.useMemo(()=>{if(a)return async()=>{if(!T.current){T.current=!0;try{await a()}finally{T.current=!1}}}},[a]),R=S.useMemo(()=>!w||v?!1:k?"auto":!1,[k,w,v]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Vx,{ref:L=>{C.current=L},scrollerRef:L=>{E.current=L instanceof HTMLDivElement?L:null},data:e,followOutput:R,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_&&_()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(L,F)=>Ed(F,L),itemContent:(L,F)=>{const V=Ed(F,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(kd,{message:F,messageIndex:L,isStreamingMessage:t&&n===F.id,streamingDebounceMs:r,isEditing:i===F.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(L),onCancelEdit:d})})}})})});sa.displayName="MessageList";const ls=1e4;function bb(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,`
|
|
128
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},tb="DialogDescriptionWarning",nb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hd(tb).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},pd=Qu,rb=td,md=rd,os=od,ss=sd,qn=ad,is=cd,gd=dd;const ob=pd,sb=md,xd=m.forwardRef(({className:e,...t},n)=>c.jsx(os,{ref:n,className:te("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}));xd.displayName=os.displayName;const vd=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const u=l.type;if(u===qn||(u==null?void 0:u.displayName)===qn.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return c.jsxs(sb,{children:[c.jsx(xd,{}),c.jsxs(ss,{ref:r,className:te("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&c.jsx(qn,{className:"sr-only",children:"Dialog"}),t,c.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-accent data-[state=open]:text-muted-foreground",children:[c.jsx(re.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});vd.displayName=ss.displayName;const wd=({className:e,...t})=>c.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});wd.displayName="DialogHeader";const bd=m.forwardRef(({className:e,...t},n)=>c.jsx(qn,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));bd.displayName=qn.displayName;const ib=m.forwardRef(({className:e,...t},n)=>c.jsx(is,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));ib.displayName=is.displayName;function ab({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=S.useState(!1),[a,l]=S.useState(null),[u,d]=S.useState(null),{toast:f}=Ui(),h=S.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Iu(n);l(x)}catch(x){console.error("Failed to load file:",x),d(x instanceof Error?x.message:"Failed to load file")}finally{i(!1)}}},[n]);S.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await zv(n),f({title:"Download started",description:`Downloading ${r}`})}catch(x){console.error("Failed to download file:",x),f({title:"Download failed",description:String(x),variant:"destructive"})}},w=async()=>{if(n)try{const x=await Iu(n),y=new Blob([x],{type:o}),C=URL.createObjectURL(y);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},v=()=>s?c.jsxs("div",{className:"flex items-center justify-center py-12",children:[c.jsx(re.Loader,{className:"h-8 w-8 animate-spin mr-3"}),c.jsx("span",{children:"Loading file..."})]}):u?c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),c.jsx("p",{className:"text-red-600 mb-4",children:u}),c.jsx(We,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?c.jsx("div",{className:"flex justify-center",children:c.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?c.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:c.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?c.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(re.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),c.jsx("p",{className:"text-lg font-medium mb-2",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>o.startsWith("image/")?c.jsx(re.Image,{className:"h-5 w-5"}):c.jsx(re.FileText,{className:"h-5 w-5"});return c.jsx(ob,{open:e,onOpenChange:t,children:c.jsxs(vd,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(wd,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[g(),c.jsxs("div",{children:[c.jsx(bd,{className:"text-left",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(We,{variant:"outline",size:"sm",onClick:w,className:"flex items-center gap-2",children:[c.jsx(re.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(We,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(re.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:v()})]})})}function yd(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 Sd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Gr(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Gr).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(Sd(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=Gr(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 oa(e){if(typeof e=="string")return e;if(Sd(e))return"";try{const t=Gr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Cd(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return Cd(e.output)}const t=String(e),n={desirability:[],feasibility:[],viability:[],other:[]};let r=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(i=>{const a=r.toLowerCase().indexOf(i);return a===-1?Number.MAX_SAFE_INTEGER:a}));o!==Number.MAX_SAFE_INTEGER&&(r=r.slice(o));for(const i of Object.keys(n)){const l=new RegExp(i+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const u=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let f=null;for(;(f=d.exec(u))!==null;){const h=f[1],p=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(h),w=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(h),v=p?p[2].trim():"",g=w?w[2].trim():"";n[i].push({title:v,description:g})}}return Object.values(n).some(i=>i.length>0)?n:null}const as="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",Kn=1e5;function lb(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function cb(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function ub(e){const t=e.filter(r=>r.type==="tool_call");return e.filter(r=>r.type==="tool_end").map(r=>{var o;return{name:(o=t.find(s=>s.id===r.toolCallId))==null?void 0:o.name,toolCallId:r.toolCallId,output:r.output}})}function db(e){const t=(r,o=Kn)=>{try{const s=Gr(r),i=typeof s=="string"?s:JSON.stringify(s??"");return i.length<=o?i:i.slice(0,o)+`
|
|
129
|
+
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function fb(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function hb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Td(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function pb({className:e}){const[t,n]=S.useState(0);return S.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const kd=S.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:p={},onEdit:w,onRegenerate:v,onCancelEdit:g,onCopy:x}){const[y,C]=S.useState(!1),[E,T]=S.useState("collapsed"),[k,I]=S.useState(!1),{currentThreadId:A}=yo(),{handleInterrupt:_}=ci(),{toast:R}=Ui(),[L,F]=S.useState({}),[V,O]=S.useState(!1),[Y,q]=S.useState(null),X=l==="phone"||l==="half-screen",B=t.role,$=B==="tool",z=!(r&&B!=="user"),H=S.useMemo(()=>{switch(B){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))]"}},[B]),ge=S.useMemo(()=>lb(t.content),[t.content]),de=S.useMemo(()=>cb(t.content),[t.content]),ee=S.useMemo(()=>t.content.filter(ie=>ie.type==="image_url"),[t.content]),je=S.useMemo(()=>t.content.filter(ie=>ie.type==="file"),[t.content]),Te=S.useMemo(()=>t.content.filter(ie=>ie.type==="interrupt"),[t.content]),K=S.useMemo(()=>db(t.content),[t.content]);S.useMemo(()=>fb(t.content),[t.content]);const M=S.useMemo(()=>K.length<=Kn?K:`${K.slice(0,Kn)}
|
|
130
|
+
… [truncated ${K.length-Kn} chars]`,[K]),Z=S.useCallback(async(ie="all")=>{const we=ie==="visible"&&$?M:$?K:ge;async function pe(xe){try{await navigator.clipboard.writeText(xe)}catch{try{const Re=document.createElement("textarea");Re.value=xe,Re.setAttribute("readonly",""),Re.style.position="absolute",Re.style.left="-9999px",document.body.appendChild(Re),Re.select(),document.execCommand("copy"),document.body.removeChild(Re)}catch(Re){throw console.error("Failed to copy:",Re),Re}}}try{await pe(we),C(!0),setTimeout(()=>C(!1),2e3),x==null||x(we)}catch(xe){console.error("Failed to copy:",xe)}},[$,K,ge,M,x]),ne=S.useCallback(()=>{if(!w)return;const ie=$?K:ge;w(t.id,ie)},[w,t.id,$,K,ge]),Q=S.useCallback(()=>{v==null||v(n)},[v,n]),le=S.useCallback(async(ie,ue,we)=>{if(!z){ie.preventDefault();return}if(L[we]){ie.preventDefault();return}try{const pe=String(ue.url??""),xe=pe.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(xe){ie.preventDefault();const Re=xe[1],Me=ue.name||`file_${Re}`,Pe=ue.mimeType||"application/octet-stream";q({id:Re,name:Me,mimeType:Pe}),O(!0);return}if(pe.startsWith("data:")){ie.preventDefault(),F(Pe=>({...Pe,[we]:!0}));const Re=`${ue.name}_${ue.size}_${Date.now()}`,Me=R({title:"Fetching file...",description:"",open:!0});try{const Pe=await Bv(A??void 0);if(!Pe||!Array.isArray(Pe))throw new Error("Invalid file list response");const st=Pe.find(mt=>!mt||typeof mt!="object"||!((mt.filename??"")===(ue.name??""))?!1:typeof ue.size=="number"&&typeof mt.size=="number"?mt.size===ue.size:!0);if(!(st!=null&&st.id))throw new Error(`File "${ue.name}" is not yet available on the server`);if(!st.id||!st.filename)throw new Error("Invalid file data received from server");q({id:st.id,name:ue.name||st.filename||`file_${st.id}`,mimeType:ue.mimeType||st.mime_type||"application/octet-stream"}),O(!0),Me.update({id:Me.id,title:"Success",description:`Opened ${ue.name}`,open:!0})}catch(Pe){console.error("Failed to fetch server file:",Pe);const st=Pe instanceof Error?Pe.message:"Unknown error occurred";Me.update({id:Me.id,title:"Failed",description:st}),R({title:"Failed to fetch file",description:st,open:!0})}finally{F(Pe=>({...Pe,[we]:!1}))}}}catch(pe){console.error("File click error:",pe),F(xe=>({...xe,[we]:!1}))}},[z,L,R,A]),Be=S.useCallback(()=>{const ue=te(X?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",H);switch(B){case"user":return c.jsx(re.User,{className:ue});case"assistant":return c.jsx(re.Bot,{className:ue});case"tool":return c.jsx(re.Wrench,{className:ue});default:return c.jsx(re.Bot,{className:ue})}},[X,H,B]),Ye=S.useCallback(()=>{const ie="group relative mb-4 flex w-full";switch(B){case"user":return te(ie,"justify-end");case"assistant":case"tool":case"system":return te(ie,"justify-start");default:return ie}},[B]),Ke=S.useCallback(()=>{const ie=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",X&&"px-3 py-2 text-sm");switch(B){case"user":return te(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 te(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 te(ie,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(ie,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(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")}},[X,B]),Ce=S.useCallback(async ie=>{try{const ue=ie.id||`interrupt-${Date.now()}`;await _(ue,!0)}catch(ue){console.error("Failed to approve interrupt:",ue)}},[_]),_e=S.useCallback(async ie=>{try{const ue=ie.id||`interrupt-${Date.now()}`;await _(ue,!1)}catch(ue){console.error("Failed to reject interrupt:",ue)}},[_]),Qe=S.useCallback(({part:ie,i:ue})=>{if(ie.type==="text"){const we=ie.text??"",pe=we.trim(),xe=yd(pe);return xe&&B!=="tool"?c.jsx(mb,{data:xe},ue):B==="user"&&f&&pe.length>h?c.jsxs(cu,{open:k,onOpenChange:I,children:[c.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",X&&"text-xs"),children:k?c.jsx(zi,{content:pe,allowHtml:!1}):c.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",X&&"text-xs"),children:[pe.substring(0,h),"..."]})}),c.jsx(uu,{asChild:!0,children:c.jsx(We,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:k?c.jsxs(c.Fragment,{children:[c.jsx(re.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(re.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",pe.length-h," chars)"]})})})]},ue):c.jsx(zi,{content:we,allowHtml:!1},ue)}if(ie.type==="image_url"){const we=ie;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:we.url,alt:we.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},ue)}if(ie.type==="file"){const we=ie,pe=we.name||"file";return c.jsxs("a",{href:we.url,onClick:xe=>le(xe,we,ue),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
131
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[L[ue]?c.jsx(re.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,L[ue]?" (processing)":""]})]},ue)}return ie.type==="interrupt"?c.jsx(xb,{interruptPart:ie,onApprove:Ce,onReject:_e},ue):null},[le,L,Ce,_e,B,f,h,k,X]),Ue=S.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(re.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),ot=S.useCallback(()=>{const ie=ge.trim().length>0||ee.length>0||je.length>0||Te.length>0;if(!$&&!ie&&!r)return Ue();if(t.model==="reflection"){const ue=ge.trim(),we=yd(ue);if(we&&typeof we=="object")return c.jsx(vb,{data:we})}if($&&de.name==="get_issues"){const ue=t.content.find(xe=>xe.type==="tool_end"),we=(ue==null?void 0:ue.output)??K,pe=Cd(we);if(pe)return c.jsx(wb,{issues:pe})}if($){const ue=ub(t.content);if(ue.length>0)return c.jsx("div",{className:"space-y-2",children:ue.map((we,pe)=>{const xe=typeof we.output=="string"?we.output:oa(we.output),Re=xe.length>Kn?`${xe.slice(0,Kn)}
|
|
132
|
+
… [truncated ${xe.length-Kn} chars]`:xe,Me=E==="expanded";return c.jsxs(cu,{open:Me,onOpenChange:Pe=>T(Pe?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(Pi,{variant:"outline",children:(we.name??"tool")+(we.toolCallId?` • ${we.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Me?Re:Re.slice(0,d)+(Re.length>d?"...":"")})}),c.jsx(uu,{asChild:!0,children:c.jsx(We,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Me?c.jsxs(c.Fragment,{children:[" ",c.jsx(re.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(re.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},we.toolCallId??pe)})})}if(!$){const ue=c.jsx("div",{className:"space-y-2",children:t.content.map((we,pe)=>c.jsx(Qe,{part:we,i:pe},pe))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[ue,c.jsx(pb,{className:H})]}):ue}},[ge,ee.length,je.length,Te.length,r,t.model,$,de.name,K,E,u,Ue,H]),lt=S.useMemo(()=>hb(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:te(Ye(),p.container),children:c.jsxs("div",{className:te(Ke(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",X&&"mb-1 pb-1",H,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[Be(),a&<&&c.jsx("span",{className:te("font-medium",X?"text-xs":"text-sm"),children:lt}),$&&de.name&&c.jsxs(Pi,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer",H,"border border-current/40",X&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E!=="collapsed",onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),T(ue=>ue==="collapsed"?"preview":"collapsed"))},onClick:()=>T(ie=>ie==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:de.name}),c.jsx("span",{className:"inline-flex items-center",children:E!=="collapsed"?c.jsx(re.ChevronUp,{className:"h-3 w-3"}):c.jsx(re.ChevronDown,{className:"h-3 w-3"})})]}),$&&!de.name&&c.jsx(We,{variant:"ghost",size:"sm",className:te("h-6 px-1",H,"hover:bg-foreground/10"),onClick:()=>T(ie=>ie==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",E!=="collapsed"?c.jsx(re.ChevronUp,{className:"h-3 w-3"}):c.jsx(re.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:te("text-xs opacity-60",H,X&&"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&&c.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Z($?"visible":"all"),className:te("h-6 w-6 p-0 hover:bg-foreground/10",H,X&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(re.Copy,{className:te(y?"text-success":H,X?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Z("all"),className:te("h-6 px-1 text-xs hover:bg-foreground/10",H),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),B==="user"&&w&&c.jsx(We,{variant:"ghost",size:"sm",onClick:ne,className:te("h-6 w-6 p-0 hover:bg-foreground/10",H,X&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(re.Edit,{className:te(H,X?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&v&&c.jsx(We,{variant:"ghost",size:"sm",onClick:Q,className:te("h-6 w-6 p-0 hover:bg-foreground/10",H,X&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(re.RotateCcw,{className:te(H,X?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:ot()}),$&&E==="expanded"&&(de.toolCallId||de.name)&&c.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",X&&"text-xs"),children:[de.name&&c.jsxs("div",{children:["Function: ",de.name]}),de.toolCallId&&c.jsxs("div",{children:["Call ID: ",de.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Z(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",X&&"h-5 w-5"),children:c.jsx(re.Copy,{className:te(y?"text-success":"text-current",X?"h-3 w-3":"h-4 w-4")})}),B==="user"&&w&&c.jsx(We,{variant:"ghost",size:"sm",onClick:ne,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",X&&"h-5 w-5"),children:c.jsx(re.Edit,{className:te("text-current",X?"h-3 w-3":"h-4 w-4")})}),B==="assistant"&&v&&c.jsx(We,{variant:"ghost",size:"sm",onClick:Q,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",X&&"h-5 w-5"),children:c.jsx(re.RotateCcw,{className:te("text-current",X?"h-3 w-3":"h-4 w-4")})})]})]})}),Y&&c.jsx(ab,{isOpen:V,onClose:()=>{O(!1),q(null)},fileId:Y.id,fileName:Y.name,mimeType:Y.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Td(e.message)===Td(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(w=>e[w]===t[w]),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)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function mb({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:as,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oa(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:as,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:as,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:gb(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oa(e)})}function gb(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(Gr(e))})}catch{return String(e)}}function xb({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(Wr,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(Vr,{className:"pb-3",children:[c.jsx(qr,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(du,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(fu,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(We,{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",children:"Reject"}),c.jsx(We,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function vb({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function wb({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:as,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const Ed=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,sa=S.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:w=!0,isNavigatingCheckpoint:v=!1,onScrollAway:g,onAtBottom:x},y)=>{const C=S.useRef(null),E=S.useRef(null),T=S.useRef(!1),[k,I]=S.useState(!0),A=S.useCallback(L=>{I(L),g&&g(!L),x&&x(L)},[g,x]),_=S.useMemo(()=>{if(a)return async()=>{if(!T.current){T.current=!0;try{await a()}finally{T.current=!1}}}},[a]),R=S.useMemo(()=>!w||v?!1:k?"auto":!1,[k,w,v]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Vx,{ref:L=>{C.current=L},scrollerRef:L=>{E.current=L instanceof HTMLDivElement?L:null},data:e,followOutput:R,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_&&_()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(L,F)=>Ed(F,L),itemContent:(L,F)=>{const V=Ed(F,L);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(kd,{message:F,messageIndex:L,isStreamingMessage:t&&n===F.id,streamingDebounceMs:r,isEditing:i===F.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(L),onCancelEdit:d})})}})})});sa.displayName="MessageList";const ls=1e4;function bb(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,`
|
|
133
133
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
134
134
|
|
|
135
135
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -137,4 +137,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
137
137
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
138
138
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
139
139
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
140
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function yb(e,t=ls){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function Sb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),yb(t),bb(t)}function ia(e){const t=e+"CollectionProvider",[n,r]=en(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:g,children:x}=v,y=S.useRef(null),C=S.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:C,collectionRef:y,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Mn.createSlot(a),u=S.forwardRef((v,g)=>{const{scope:x,children:y}=v,C=s(a,x),E=$e(g,C.collectionRef);return c.jsx(l,{ref:E,children:y})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Mn.createSlot(d),p=S.forwardRef((v,g)=>{const{scope:x,children:y,...C}=v,E=S.useRef(null),T=$e(g,E),k=s(d,x);return S.useEffect(()=>(k.itemMap.set(E,{ref:E,...C}),()=>void k.itemMap.delete(E))),c.jsx(h,{[f]:"",ref:T,children:y})});p.displayName=d;function w(v){const g=s(e+"CollectionConsumer",v);return S.useCallback(()=>{const y=g.collectionRef.current;if(!y)return[];const C=Array.from(y.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((k,I)=>C.indexOf(k.ref.current)-C.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var Cb=m.createContext(void 0);function cs(e){const t=m.useContext(Cb);return e||t||"ltr"}const Tb=["top","right","bottom","left"],In=Math.min,Pt=Math.max,us=Math.round,ds=Math.floor,rn=e=>({x:e,y:e}),kb={left:"right",right:"left",bottom:"top",top:"bottom"},Eb={start:"end",end:"start"};function aa(e,t,n){return Pt(e,In(t,n))}function mn(e,t){return typeof e=="function"?e(t):e}function gn(e){return e.split("-")[0]}function pr(e){return e.split("-")[1]}function la(e){return e==="x"?"y":"x"}function ca(e){return e==="y"?"height":"width"}const Ib=new Set(["top","bottom"]);function on(e){return Ib.has(gn(e))?"y":"x"}function ua(e){return la(on(e))}function Nb(e,t,n){n===void 0&&(n=!1);const r=pr(e),o=ua(e),s=ca(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=fs(i)),[i,fs(i)]}function Ab(e){const t=fs(e);return[da(e),t,da(t)]}function da(e){return e.replace(/start|end/g,t=>Eb[t])}const Id=["left","right"],Nd=["right","left"],jb=["top","bottom"],_b=["bottom","top"];function Rb(e,t,n){switch(e){case"top":case"bottom":return n?t?Nd:Id:t?Id:Nd;case"left":case"right":return t?jb:_b;default:return[]}}function Pb(e,t,n,r){const o=pr(e);let s=Rb(gn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(da)))),s}function fs(e){return e.replace(/left|right|bottom|top/g,t=>kb[t])}function Ob(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ad(e){return typeof e!="number"?Ob(e):{top:e,right:e,bottom:e,left:e}}function hs(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function jd(e,t,n){let{reference:r,floating:o}=e;const s=on(t),i=ua(t),a=ca(i),l=gn(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(pr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Mb=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 u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=jd(u,r,l),h=r,p={},w=0;for(let v=0;v<a.length;v++){const{name:g,fn:x}=a[v],{x:y,y:C,data:E,reset:T}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=y??d,f=C??f,p={...p,[g]:{...p[g],...E}},T&&w<=50&&(w++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(u=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=jd(u,h,l)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Yr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=mn(t,e),w=Ad(p),g=a[h?f==="floating"?"reference":"floating":f],x=hs(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),y=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},T=hs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:C,strategy:l}):y);return{top:(x.top-T.top+w.top)/E.y,bottom:(T.bottom-x.bottom+w.bottom)/E.y,left:(x.left-T.left+w.left)/E.x,right:(T.right-x.right+w.right)/E.x}}const Db=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:u,padding:d=0}=mn(e,t)||{};if(u==null)return{};const f=Ad(d),h={x:n,y:r},p=ua(o),w=ca(p),v=await i.getDimensions(u),g=p==="y",x=g?"top":"left",y=g?"bottom":"right",C=g?"clientHeight":"clientWidth",E=s.reference[w]+s.reference[p]-h[p]-s.floating[w],T=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=k?k[C]:0;(!I||!await(i.isElement==null?void 0:i.isElement(k)))&&(I=a.floating[C]||s.floating[w]);const A=E/2-T/2,_=I/2-v[w]/2-1,R=In(f[x],_),L=In(f[y],_),F=R,V=I-v[w]-L,O=I/2-v[w]/2+A,Y=aa(F,O,V),K=!l.arrow&&pr(o)!=null&&O!==Y&&s.reference[w]/2-(O<F?R:L)-v[w]/2<0,X=K?O<F?O-F:O-V:0;return{[p]:h[p]+X,data:{[p]:Y,centerOffset:O-Y-X,...K&&{alignmentOffset:X}},reset:K}}}),Lb=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:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...g}=mn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=gn(o),y=on(a),C=gn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(u.floating)),T=h||(C||!v?[fs(a)]:Ab(a)),k=w!=="none";!h&&k&&T.push(...Pb(a,v,w,E));const I=[a,...T],A=await Yr(t,g),_=[];let R=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(A[x]),f){const O=Nb(o,i,E);_.push(A[O[0]],A[O[1]])}if(R=[...R,{placement:o,overflows:_}],!_.every(O=>O<=0)){var L,F;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,Y=I[O];if(Y&&(!(f==="alignment"?y!==on(Y):!1)||R.every(B=>on(B.placement)===y?B.overflows[0]>0:!0)))return{data:{index:O,overflows:R},reset:{placement:Y}};let K=(F=R.filter(X=>X.overflows[0]<=0).sort((X,B)=>X.overflows[1]-B.overflows[1])[0])==null?void 0:F.placement;if(!K)switch(p){case"bestFit":{var V;const X=(V=R.filter(B=>{if(k){const $=on(B.placement);return $===y||$==="y"}return!0}).map(B=>[B.placement,B.overflows.filter($=>$>0).reduce(($,z)=>$+z,0)]).sort((B,$)=>B[1]-$[1])[0])==null?void 0:V[0];X&&(K=X);break}case"initialPlacement":K=a;break}if(o!==K)return{reset:{placement:K}}}return{}}}};function _d(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Rd(e){return Tb.some(t=>e[t]>=0)}const Fb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=mn(e,t);switch(r){case"referenceHidden":{const s=await Yr(t,{...o,elementContext:"reference"}),i=_d(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Rd(i)}}}case"escaped":{const s=await Yr(t,{...o,altBoundary:!0}),i=_d(s,n.floating);return{data:{escapedOffsets:i,escaped:Rd(i)}}}default:return{}}}}},Pd=new Set(["left","top"]);async function $b(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=gn(n),a=pr(n),l=on(n)==="y",u=Pd.has(i)?-1:1,d=s&&l?-1:1,f=mn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const zb=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 $b(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}}}}},Bb=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:g=>{let{x,y}=g;return{x,y}}},...l}=mn(e,t),u={x:n,y:r},d=await Yr(t,l),f=on(gn(o)),h=la(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",y=p+d[g],C=p-d[x];p=aa(y,p,C)}if(i){const g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",y=w+d[g],C=w-d[x];w=aa(y,w,C)}const v=a.fn({...t,[h]:p,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},Hb=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:u=!0}=mn(e,t),d={x:n,y:r},f=on(o),h=la(f);let p=d[h],w=d[f];const v=mn(a,t),g=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const C=h==="y"?"height":"width",E=s.reference[h]-s.floating[C]+g.mainAxis,T=s.reference[h]+s.reference[C]-g.mainAxis;p<E?p=E:p>T&&(p=T)}if(u){var x,y;const C=h==="y"?"width":"height",E=Pd.has(gn(o)),T=s.reference[f]-s.floating[C]+(E&&((x=i.offset)==null?void 0:x[f])||0)+(E?0:g.crossAxis),k=s.reference[f]+s.reference[C]+(E?0:((y=i.offset)==null?void 0:y[f])||0)-(E?g.crossAxis:0);w<T?w=T:w>k&&(w=k)}return{[h]:p,[f]:w}}}},Ub=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=()=>{},...u}=mn(e,t),d=await Yr(t,u),f=gn(o),h=pr(o),p=on(o)==="y",{width:w,height:v}=s.floating;let g,x;f==="top"||f==="bottom"?(g=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,g=h==="end"?"top":"bottom");const y=v-d.top-d.bottom,C=w-d.left-d.right,E=In(v-d[g],y),T=In(w-d[x],C),k=!t.middlewareData.shift;let I=E,A=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=y),k&&!h){const R=Pt(d.left,0),L=Pt(d.right,0),F=Pt(d.top,0),V=Pt(d.bottom,0);p?A=w-2*(R!==0||L!==0?R+L:Pt(d.left,d.right)):I=v-2*(F!==0||V!==0?F+V:Pt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const _=await i.getDimensions(a.floating);return w!==_.width||v!==_.height?{reset:{rects:!0}}:{}}}};function ps(){return typeof window<"u"}function mr(e){return Od(e)?(e.nodeName||"").toLowerCase():"#document"}function Ot(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function sn(e){var t;return(t=(Od(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Od(e){return ps()?e instanceof Node||e instanceof Ot(e).Node:!1}function Kt(e){return ps()?e instanceof Element||e instanceof Ot(e).Element:!1}function an(e){return ps()?e instanceof HTMLElement||e instanceof Ot(e).HTMLElement:!1}function Md(e){return!ps()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ot(e).ShadowRoot}const Wb=new Set(["inline","contents"]);function Xr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=qt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Wb.has(o)}const Vb=new Set(["table","td","th"]);function Kb(e){return Vb.has(mr(e))}const qb=[":popover-open",":modal"];function ms(e){return qb.some(t=>{try{return e.matches(t)}catch{return!1}})}const Gb=["transform","translate","scale","rotate","perspective"],Yb=["transform","translate","scale","rotate","perspective","filter"],Xb=["paint","layout","strict","content"];function fa(e){const t=ha(),n=Kt(e)?qt(e):e;return Gb.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)||Yb.some(r=>(n.willChange||"").includes(r))||Xb.some(r=>(n.contain||"").includes(r))}function Jb(e){let t=Nn(e);for(;an(t)&&!gr(t);){if(fa(t))return t;if(ms(t))return null;t=Nn(t)}return null}function ha(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Zb=new Set(["html","body","#document"]);function gr(e){return Zb.has(mr(e))}function qt(e){return Ot(e).getComputedStyle(e)}function gs(e){return Kt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Nn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Md(e)&&e.host||sn(e);return Md(t)?t.host:t}function Dd(e){const t=Nn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:an(t)&&Xr(t)?t:Dd(t)}function Jr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Dd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ot(o);if(s){const a=pa(i);return t.concat(i,i.visualViewport||[],Xr(o)?o:[],a&&n?Jr(a):[])}return t.concat(o,Jr(o,[],n))}function pa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Ld(e){const t=qt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=an(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 ma(e){return Kt(e)?e:e.contextElement}function xr(e){const t=ma(e);if(!an(t))return rn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Ld(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 Qb=rn(0);function Fd(e){const t=Ot(e);return!ha()||!t.visualViewport?Qb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ey(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ot(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ma(e);let i=rn(1);t&&(r?Kt(r)&&(i=xr(r)):i=xr(e));const a=ey(s,n,r)?Fd(s):rn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ot(s),p=r&&Kt(r)?Ot(r):r;let w=h,v=pa(w);for(;v&&r&&p!==w;){const g=xr(v),x=v.getBoundingClientRect(),y=qt(v),C=x.left+(v.clientLeft+parseFloat(y.paddingLeft))*g.x,E=x.top+(v.clientTop+parseFloat(y.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=C,u+=E,w=Ot(v),v=pa(w)}}return hs({width:d,height:f,x:l,y:u})}function xs(e,t){const n=gs(e).scrollLeft;return t?t.left+n:Gn(sn(e)).left+n}function $d(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 ty(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=sn(r),a=t?ms(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=rn(1);const d=rn(0),f=an(r);if((f||!f&&!s)&&((mr(r)!=="body"||Xr(i))&&(l=gs(r)),an(r))){const p=Gn(r);u=xr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?$d(i,l):rn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function ny(e){return Array.from(e.getClientRects())}function ry(e){const t=sn(e),n=gs(e),r=e.ownerDocument.body,o=Pt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Pt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+xs(e);const a=-n.scrollTop;return qt(r).direction==="rtl"&&(i+=Pt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const zd=25;function oy(e,t){const n=Ot(e),r=sn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=ha();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=xs(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,w=Math.abs(r.clientWidth-f.clientWidth-p);w<=zd&&(s-=w)}else u<=zd&&(s+=u);return{width:s,height:i,x:a,y:l}}const sy=new Set(["absolute","fixed"]);function iy(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=an(e)?xr(e):rn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function Bd(e,t,n){let r;if(t==="viewport")r=oy(e,n);else if(t==="document")r=ry(sn(e));else if(Kt(t))r=iy(t,n);else{const o=Fd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return hs(r)}function Hd(e,t){const n=Nn(e);return n===t||!Kt(n)||gr(n)?!1:qt(n).position==="fixed"||Hd(n,t)}function ay(e,t){const n=t.get(e);if(n)return n;let r=Jr(e,[],!1).filter(a=>Kt(a)&&mr(a)!=="body"),o=null;const s=qt(e).position==="fixed";let i=s?Nn(e):e;for(;Kt(i)&&!gr(i);){const a=qt(i),l=fa(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&sy.has(o.position)||Xr(i)&&!l&&Hd(e,i))?r=r.filter(d=>d!==i):o=a,i=Nn(i)}return t.set(e,r),r}function ly(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?ms(t)?[]:ay(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=Bd(t,d,o);return u.top=Pt(f.top,u.top),u.right=In(f.right,u.right),u.bottom=In(f.bottom,u.bottom),u.left=Pt(f.left,u.left),u},Bd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function cy(e){const{width:t,height:n}=Ld(e);return{width:t,height:n}}function uy(e,t,n){const r=an(t),o=sn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=rn(0);function u(){l.x=xs(o)}if(r||!r&&!s)if((mr(t)!=="body"||Xr(o))&&(a=gs(t)),r){const p=Gn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?$d(o,a):rn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function ga(e){return qt(e).position==="static"}function Ud(e,t){if(!an(e)||qt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return sn(e)===n&&(n=n.ownerDocument.body),n}function Wd(e,t){const n=Ot(e);if(ms(e))return n;if(!an(e)){let o=Nn(e);for(;o&&!gr(o);){if(Kt(o)&&!ga(o))return o;o=Nn(o)}return n}let r=Ud(e,t);for(;r&&Kb(r)&&ga(r);)r=Ud(r,t);return r&&gr(r)&&ga(r)&&!fa(r)?n:r||Jb(e)||n}const dy=async function(e){const t=this.getOffsetParent||Wd,n=this.getDimensions,r=await n(e.floating);return{reference:uy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function fy(e){return qt(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ty,getDocumentElement:sn,getClippingRect:ly,getOffsetParent:Wd,getElementRects:dy,getClientRects:ny,getDimensions:cy,getScale:xr,isElement:Kt,isRTL:fy};function Vd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function py(e,t){let n=null,r;const o=sn(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 u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=ds(f),v=ds(o.clientWidth-(d+h)),g=ds(o.clientHeight-(f+p)),x=ds(d),C={rootMargin:-w+"px "+-v+"px "+-g+"px "+-x+"px",threshold:Pt(0,In(1,l))||1};let E=!0;function T(k){const I=k[0].intersectionRatio;if(I!==l){if(!E)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Vd(u,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(T,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,C)}n.observe(e)}return i(!0),s}function my(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,u=ma(e),d=o||s?[...u?Jr(u):[],...Jr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?py(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[y]=x;y&&y.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,v=l?Gn(e):null;l&&g();function g(){const x=Gn(e);v&&!Vd(v,x)&&n(),v=x,w=requestAnimationFrame(g)}return n(),()=>{var x;d.forEach(y=>{o&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const gy=zb,xy=Bb,vy=Lb,wy=Ub,by=Fb,Kd=Db,yy=Hb,Sy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Mb(e,t,{...o,platform:s})};var Cy=typeof document<"u",Ty=function(){},vs=Cy?S.useLayoutEffect:Ty;function ws(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(!ws(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)&&!ws(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function qd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Gd(e,t){const n=qd(e);return Math.round(t*n)/n}function xa(e){const t=m.useRef(e);return vs(()=>{t.current=e}),t}function ky(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:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);ws(h,r)||p(r);const[w,v]=m.useState(null),[g,x]=m.useState(null),y=m.useCallback(B=>{B!==k.current&&(k.current=B,v(B))},[]),C=m.useCallback(B=>{B!==I.current&&(I.current=B,x(B))},[]),E=s||w,T=i||g,k=m.useRef(null),I=m.useRef(null),A=m.useRef(d),_=l!=null,R=xa(l),L=xa(o),F=xa(u),V=m.useCallback(()=>{if(!k.current||!I.current)return;const B={placement:t,strategy:n,middleware:h};L.current&&(B.platform=L.current),Sy(k.current,I.current,B).then($=>{const z={...$,isPositioned:F.current!==!1};O.current&&!ws(A.current,z)&&(A.current=z,ao.flushSync(()=>{f(z)}))})},[h,t,n,L,F]);vs(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[u]);const O=m.useRef(!1);vs(()=>(O.current=!0,()=>{O.current=!1}),[]),vs(()=>{if(E&&(k.current=E),T&&(I.current=T),E&&T){if(R.current)return R.current(E,T,V);V()}},[E,T,V,R,_]);const Y=m.useMemo(()=>({reference:k,floating:I,setReference:y,setFloating:C}),[y,C]),K=m.useMemo(()=>({reference:E,floating:T}),[E,T]),X=m.useMemo(()=>{const B={position:n,left:0,top:0};if(!K.floating)return B;const $=Gd(K.floating,d.x),z=Gd(K.floating,d.y);return a?{...B,transform:"translate("+$+"px, "+z+"px)",...qd(K.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:z}},[n,a,K.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:Y,elements:K,floatingStyles:X}),[d,V,Y,K,X])}const Ey=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?Kd({element:r.current,padding:o}).fn(n):{}:r?Kd({element:r,padding:o}).fn(n):{}}}},Iy=(e,t)=>({...gy(e),options:[e,t]}),Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...vy(e),options:[e,t]}),_y=(e,t)=>({...wy(e),options:[e,t]}),Ry=(e,t)=>({...by(e),options:[e,t]}),Py=(e,t)=>({...Ey(e),options:[e,t]});var Oy="Arrow",Yd=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Ie.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Yd.displayName=Oy;var My=Yd;function Xd(e){const[t,n]=m.useState(void 0);return ft(()=>{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,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.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 va="Popper",[Jd,bs]=en(va),[Dy,Zd]=Jd(va),Qd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(Dy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Qd.displayName=va;var ef="PopperAnchor",tf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Zd(ef,n),i=m.useRef(null),a=$e(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Ie.div,{...o,ref:a})});tf.displayName=ef;var wa="PopperContent",[Ly,Fy]=Jd(wa),nf=m.forwardRef((e,t)=>{var q,M,Z,ne,Q,le;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...v}=e,g=Zd(wa,n),[x,y]=m.useState(null),C=$e(t,Be=>y(Be)),[E,T]=m.useState(null),k=Xd(E),I=(k==null?void 0:k.width)??0,A=(k==null?void 0:k.height)??0,_=r+(s!=="center"?"-"+s:""),R=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(u)?u:[u],F=L.length>0,V={padding:R,boundary:L.filter(zy),altBoundary:F},{refs:O,floatingStyles:Y,placement:K,isPositioned:X,middlewareData:B}=ky({strategy:"fixed",placement:_,whileElementsMounted:(...Be)=>my(...Be,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[Iy({mainAxis:o+A,alignmentAxis:i}),l&&Ny({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Ay():void 0,...V}),l&&jy({...V}),_y({...V,apply:({elements:Be,rects:Ye,availableWidth:qe,availableHeight:Ce})=>{const{width:_e,height:Qe}=Ye.reference,Ue=Be.floating.style;Ue.setProperty("--radix-popper-available-width",`${qe}px`),Ue.setProperty("--radix-popper-available-height",`${Ce}px`),Ue.setProperty("--radix-popper-anchor-width",`${_e}px`),Ue.setProperty("--radix-popper-anchor-height",`${Qe}px`)}}),E&&Py({element:E,padding:a}),By({arrowWidth:I,arrowHeight:A}),h&&Ry({strategy:"referenceHidden",...V})]}),[$,z]=sf(K),H=pt(w);ft(()=>{X&&(H==null||H())},[X,H]);const ge=(q=B.arrow)==null?void 0:q.x,de=(M=B.arrow)==null?void 0:M.y,ee=((Z=B.arrow)==null?void 0:Z.centerOffset)!==0,[je,Te]=m.useState();return ft(()=>{x&&Te(window.getComputedStyle(x).zIndex)},[x]),c.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...Y,transform:X?Y.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:je,"--radix-popper-transform-origin":[(ne=B.transformOrigin)==null?void 0:ne.x,(Q=B.transformOrigin)==null?void 0:Q.y].join(" "),...((le=B.hide)==null?void 0:le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(Ly,{scope:n,placedSide:$,onArrowChange:T,arrowX:ge,arrowY:de,shouldHideArrow:ee,children:c.jsx(Ie.div,{"data-side":$,"data-align":z,...v,ref:C,style:{...v.style,animation:X?void 0:"none"}})})})});nf.displayName=wa;var rf="PopperArrow",$y={top:"bottom",right:"left",bottom:"top",left:"right"},of=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Fy(rf,r),i=$y[s.placedSide];return c.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:c.jsx(My,{...o,ref:n,style:{...o.style,display:"block"}})})});of.displayName=rf;function zy(e){return e!==null}var By=e=>({name:"transformOrigin",options:e,fn(t){var g,x,y;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=sf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((y=o.arrow)==null?void 0:y.y)??0)+l/2;let w="",v="";return u==="bottom"?(w=i?f:`${h}px`,v=`${-l}px`):u==="top"?(w=i?f:`${h}px`,v=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,v=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,v=i?f:`${p}px`),{data:{x:w,y:v}}}});function sf(e){const[t,n="center"]=e.split("-");return[t,n]}var af=Qd,lf=tf,cf=nf,uf=of,ba="rovingFocusGroup.onEntryFocus",Hy={bubbles:!1,cancelable:!0},Zr="RovingFocusGroup",[ya,df,Uy]=ia(Zr),[Wy,ff]=en(Zr,[Uy]),[Vy,Ky]=Wy(Zr),hf=m.forwardRef((e,t)=>c.jsx(ya.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(ya.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(qy,{...e,ref:t})})}));hf.displayName=Zr;var qy=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=$e(t,h),w=cs(s),[v,g]=Un({prop:i,defaultProp:a??null,onChange:l,caller:Zr}),[x,y]=m.useState(!1),C=pt(u),E=df(n),T=m.useRef(!1),[k,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ba,C),()=>A.removeEventListener(ba,C)},[C]),c.jsx(Vy,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>y(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(Ie.div,{tabIndex:x||k===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ce(e.onMouseDown,()=>{T.current=!0}),onFocus:ce(e.onFocus,A=>{const _=!T.current;if(A.target===A.currentTarget&&_&&!x){const R=new CustomEvent(ba,Hy);if(A.currentTarget.dispatchEvent(R),!R.defaultPrevented){const L=E().filter(K=>K.focusable),F=L.find(K=>K.active),V=L.find(K=>K.id===v),Y=[F,V,...L].filter(Boolean).map(K=>K.ref.current);gf(Y,d)}}T.current=!1}),onBlur:ce(e.onBlur,()=>y(!1))})})}),pf="RovingFocusGroupItem",mf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=tn(),u=s||l,d=Ky(pf,n),f=d.currentTabStopId===u,h=df(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:v}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(ya.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Ie.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ce(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ce(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ce(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const x=Xy(g,d.orientation,d.dir);if(x!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let C=h().filter(E=>E.focusable).map(E=>E.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const E=C.indexOf(g.currentTarget);C=d.loop?Jy(C,E+1):C.slice(E+1)}setTimeout(()=>gf(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});mf.displayName=pf;var Gy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Yy(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Xy(e,t,n){const r=Yy(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Gy[r]}function gf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Jy(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zy=hf,Qy=mf,Sa=["Enter"," "],e0=["ArrowDown","PageUp","Home"],xf=["ArrowUp","PageDown","End"],t0=[...e0,...xf],n0={ltr:[...Sa,"ArrowRight"],rtl:[...Sa,"ArrowLeft"]},r0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Qr="Menu",[eo,o0,s0]=ia(Qr),[Yn,vf]=en(Qr,[s0,bs,ff]),ys=bs(),wf=ff(),[i0,Xn]=Yn(Qr),[a0,to]=Yn(Qr),bf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ys(t),[l,u]=m.useState(null),d=m.useRef(!1),f=pt(s),h=cs(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx(af,{...a,children:c.jsx(i0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(a0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};bf.displayName=Qr;var l0="MenuAnchor",Ca=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ys(n);return c.jsx(lf,{...o,...r,ref:t})});Ca.displayName=l0;var Ta="MenuPortal",[c0,yf]=Yn(Ta,{forceMount:void 0}),Sf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(Ta,t);return c.jsx(c0,{scope:t,forceMount:n,children:c.jsx(Rt,{present:n||s.open,children:c.jsx(qo,{asChild:!0,container:o,children:r})})})};Sf.displayName=Ta;var $t="MenuContent",[u0,ka]=Yn($t),Cf=m.forwardRef((e,t)=>{const n=yf($t,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn($t,e.__scopeMenu),i=to($t,e.__scopeMenu);return c.jsx(eo.Provider,{scope:e.__scopeMenu,children:c.jsx(Rt,{present:r||s.open,children:c.jsx(eo.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(d0,{...o,ref:t}):c.jsx(f0,{...o,ref:t})})})})}),d0=m.forwardRef((e,t)=>{const n=Xn($t,e.__scopeMenu),r=m.useRef(null),o=$e(t,r);return m.useEffect(()=>{const s=r.current;if(s)return ea(s)},[]),c.jsx(Ea,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),f0=m.forwardRef((e,t)=>{const n=Xn($t,e.__scopeMenu);return c.jsx(Ea,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),h0=Mn.createSlot("MenuContent.ScrollLock"),Ea=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...v}=e,g=Xn($t,n),x=to($t,n),y=ys(n),C=wf(n),E=o0(n),[T,k]=m.useState(null),I=m.useRef(null),A=$e(t,I,g.onContentChange),_=m.useRef(0),R=m.useRef(""),L=m.useRef(0),F=m.useRef(null),V=m.useRef("right"),O=m.useRef(0),Y=w?Qo:m.Fragment,K=w?{as:h0,allowPinchZoom:!0}:void 0,X=$=>{var q,M;const z=R.current+$,H=E().filter(Z=>!Z.disabled),ge=document.activeElement,de=(q=H.find(Z=>Z.ref.current===ge))==null?void 0:q.textValue,ee=H.map(Z=>Z.textValue),je=k0(ee,z,de),Te=(M=H.find(Z=>Z.textValue===je))==null?void 0:M.ref.current;(function Z(ne){R.current=ne,window.clearTimeout(_.current),ne!==""&&(_.current=window.setTimeout(()=>Z(""),1e3))})(z),Te&&setTimeout(()=>Te.focus())};m.useEffect(()=>()=>window.clearTimeout(_.current),[]),Gi();const B=m.useCallback($=>{var H,ge;return V.current===((H=F.current)==null?void 0:H.side)&&I0($,(ge=F.current)==null?void 0:ge.area)},[]);return c.jsx(u0,{scope:n,searchRef:R,onItemEnter:m.useCallback($=>{B($)&&$.preventDefault()},[B]),onItemLeave:m.useCallback($=>{var z;B($)||((z=I.current)==null||z.focus(),k(null))},[B]),onTriggerLeave:m.useCallback($=>{B($)&&$.preventDefault()},[B]),pointerGraceTimerRef:L,onPointerGraceIntentChange:m.useCallback($=>{F.current=$},[]),children:c.jsx(Y,{...K,children:c.jsx(Ko,{asChild:!0,trapped:o,onMountAutoFocus:ce(s,$=>{var z;$.preventDefault(),(z=I.current)==null||z.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(Vo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(Zy,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:k,onEntryFocus:ce(l,$=>{x.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(cf,{role:"menu","aria-orientation":"vertical","data-state":zf(g.open),"data-radix-menu-content":"",dir:x.dir,...y,...v,ref:A,style:{outline:"none",...v.style},onKeyDown:ce(v.onKeyDown,$=>{const H=$.target.closest("[data-radix-menu-content]")===$.currentTarget,ge=$.ctrlKey||$.altKey||$.metaKey,de=$.key.length===1;H&&($.key==="Tab"&&$.preventDefault(),!ge&&de&&X($.key));const ee=I.current;if($.target!==ee||!t0.includes($.key))return;$.preventDefault();const Te=E().filter(q=>!q.disabled).map(q=>q.ref.current);xf.includes($.key)&&Te.reverse(),C0(Te)}),onBlur:ce(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(_.current),R.current="")}),onPointerMove:ce(e.onPointerMove,ro($=>{const z=$.target,H=O.current!==$.clientX;if($.currentTarget.contains(z)&&H){const ge=$.clientX>O.current?"right":"left";V.current=ge,O.current=$.clientX}}))})})})})})})});Cf.displayName=$t;var p0="MenuGroup",Ia=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ie.div,{role:"group",...r,ref:t})});Ia.displayName=p0;var m0="MenuLabel",Tf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ie.div,{...r,ref:t})});Tf.displayName=m0;var Ss="MenuItem",kf="menu.itemSelect",Cs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=to(Ss,e.__scopeMenu),a=ka(Ss,e.__scopeMenu),l=$e(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(kf,{bubbles:!0,cancelable:!0});f.addEventListener(kf,p=>r==null?void 0:r(p),{once:!0}),su(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Ef,{...o,ref:l,disabled:n,onClick:ce(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ce(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ce(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Sa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Cs.displayName=Ss;var Ef=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ka(Ss,n),a=wf(n),l=m.useRef(null),u=$e(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(eo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(Qy,{asChild:!0,...a,focusable:!r,children:c.jsx(Ie.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ce(e.onPointerMove,ro(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ce(e.onPointerLeave,ro(w=>i.onItemLeave(w))),onFocus:ce(e.onFocus,()=>f(!0)),onBlur:ce(e.onBlur,()=>f(!1))})})})}),g0="MenuCheckboxItem",If=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(Rf,{scope:e.__scopeMenu,checked:n,children:c.jsx(Cs,{role:"menuitemcheckbox","aria-checked":Ts(n)?"mixed":n,...o,ref:t,"data-state":Aa(n),onSelect:ce(o.onSelect,()=>r==null?void 0:r(Ts(n)?!0:!n),{checkForDefaultPrevented:!1})})})});If.displayName=g0;var Nf="MenuRadioGroup",[x0,v0]=Yn(Nf,{value:void 0,onValueChange:()=>{}}),Af=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=pt(r);return c.jsx(x0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(Ia,{...o,ref:t})})});Af.displayName=Nf;var jf="MenuRadioItem",_f=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=v0(jf,e.__scopeMenu),s=n===o.value;return c.jsx(Rf,{scope:e.__scopeMenu,checked:s,children:c.jsx(Cs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Aa(s),onSelect:ce(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});_f.displayName=jf;var Na="MenuItemIndicator",[Rf,w0]=Yn(Na,{checked:!1}),Pf=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=w0(Na,n);return c.jsx(Rt,{present:r||Ts(s.checked)||s.checked===!0,children:c.jsx(Ie.span,{...o,ref:t,"data-state":Aa(s.checked)})})});Pf.displayName=Na;var b0="MenuSeparator",Of=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ie.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Of.displayName=b0;var y0="MenuArrow",Mf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ys(n);return c.jsx(uf,{...o,...r,ref:t})});Mf.displayName=y0;var S0="MenuSub",[oT,Df]=Yn(S0),no="MenuSubTrigger",Lf=m.forwardRef((e,t)=>{const n=Xn(no,e.__scopeMenu),r=to(no,e.__scopeMenu),o=Df(no,e.__scopeMenu),s=ka(no,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(Ca,{asChild:!0,...u,children:c.jsx(Ef,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":zf(n.open),...e,ref:Oi(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:ce(e.onPointerMove,ro(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ce(e.onPointerLeave,ro(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,g=v==="right",x=g?-5:5,y=h[g?"left":"right"],C=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:y,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:y,y:h.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ce(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||n0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Lf.displayName=no;var Ff="MenuSubContent",$f=m.forwardRef((e,t)=>{const n=yf($t,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn($t,e.__scopeMenu),i=to($t,e.__scopeMenu),a=Df(Ff,e.__scopeMenu),l=m.useRef(null),u=$e(t,l);return c.jsx(eo.Provider,{scope:e.__scopeMenu,children:c.jsx(Rt,{present:r||s.open,children:c.jsx(eo.Slot,{scope:e.__scopeMenu,children:c.jsx(Ea,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ce(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ce(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ce(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=r0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});$f.displayName=Ff;function zf(e){return e?"open":"closed"}function Ts(e){return e==="indeterminate"}function Aa(e){return Ts(e)?"indeterminate":e?"checked":"unchecked"}function C0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function T0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function k0(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=T0(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function E0(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],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function I0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return E0(n,t)}function ro(e){return t=>t.pointerType==="mouse"?e(t):void 0}var N0=bf,A0=Ca,j0=Sf,_0=Cf,R0=Ia,P0=Tf,O0=Cs,M0=If,D0=Af,L0=_f,F0=Pf,$0=Of,z0=Mf,B0=Lf,H0=$f,ks="DropdownMenu",[U0,sT]=en(ks,[vf]),Ct=vf(),[W0,Bf]=U0(ks),Hf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ct(t),u=m.useRef(null),[d,f]=Un({prop:o,defaultProp:s??!1,onChange:i,caller:ks});return c.jsx(W0,{scope:t,triggerId:tn(),triggerRef:u,contentId:tn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(N0,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Hf.displayName=ks;var Uf="DropdownMenuTrigger",Wf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Bf(Uf,n),i=Ct(n);return c.jsx(A0,{asChild:!0,...i,children:c.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:Oi(t,s.triggerRef),onPointerDown:ce(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ce(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Wf.displayName=Uf;var V0="DropdownMenuPortal",Vf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ct(t);return c.jsx(j0,{...r,...n})};Vf.displayName=V0;var Kf="DropdownMenuContent",qf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bf(Kf,n),s=Ct(n),i=m.useRef(!1);return c.jsx(_0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ce(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ce(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});qf.displayName=Kf;var K0="DropdownMenuGroup",q0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(R0,{...o,...r,ref:t})});q0.displayName=K0;var G0="DropdownMenuLabel",Gf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(P0,{...o,...r,ref:t})});Gf.displayName=G0;var Y0="DropdownMenuItem",Yf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(O0,{...o,...r,ref:t})});Yf.displayName=Y0;var X0="DropdownMenuCheckboxItem",Xf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(M0,{...o,...r,ref:t})});Xf.displayName=X0;var J0="DropdownMenuRadioGroup",Z0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(D0,{...o,...r,ref:t})});Z0.displayName=J0;var Q0="DropdownMenuRadioItem",Jf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(L0,{...o,...r,ref:t})});Jf.displayName=Q0;var eS="DropdownMenuItemIndicator",Zf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(F0,{...o,...r,ref:t})});Zf.displayName=eS;var tS="DropdownMenuSeparator",Qf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx($0,{...o,...r,ref:t})});Qf.displayName=tS;var nS="DropdownMenuArrow",rS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(z0,{...o,...r,ref:t})});rS.displayName=nS;var oS="DropdownMenuSubTrigger",eh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(B0,{...o,...r,ref:t})});eh.displayName=oS;var sS="DropdownMenuSubContent",th=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(H0,{...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)"}})});th.displayName=sS;var iS=Hf,aS=Wf,lS=Vf,nh=qf,rh=Gf,oh=Yf,sh=Xf,ih=Jf,ah=Zf,lh=Qf,ch=eh,uh=th;const cS=iS,uS=aS,dS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(ch,{ref:o,className:te("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,c.jsx(re.ChevronRight,{className:"ml-auto h-4 w-4"})]}));dS.displayName=ch.displayName;const fS=m.forwardRef(({className:e,...t},n)=>c.jsx(uh,{ref:n,className:te("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}));fS.displayName=uh.displayName;const dh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(lS,{children:c.jsx(nh,{ref:r,sideOffset:t,className:te("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})}));dh.displayName=nh.displayName;const ja=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(oh,{ref:r,className:te("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}));ja.displayName=oh.displayName;const hS=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(sh,{ref:o,className:te("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(ah,{children:c.jsx(re.Check,{className:"h-4 w-4"})})}),t]}));hS.displayName=sh.displayName;const pS=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(ih,{ref:r,className:te("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(ah,{children:c.jsx(re.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));pS.displayName=ih.displayName;const mS=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(rh,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));mS.displayName=rh.displayName;const gS=m.forwardRef(({className:e,...t},n)=>c.jsx(lh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));gS.displayName=lh.displayName;function Es({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:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=Qs(),{currentThreadId:v,isLoadingThread:g,listCheckpoints:x,navigateToCheckpoint:y,returnToLatest:C}=yo(),{messages:E,hasMoreHistory:T,isLoadingHistory:k,send:I,stop:A,loadOlderMessages:_}=ci(),{isStreaming:R,error:L,streamingAssistantId:F,lastCheckpointId:V,lastCheckpointNs:O}=oc(),[Y,K]=S.useState(null),[X,B]=S.useState(""),[$,z]=S.useState(null),[H,ge]=S.useState([]),[de,ee]=S.useState(0),[je,Te]=S.useState(0),[q,M]=S.useState(!1),[Z,ne]=S.useState(null),[Q,le]=S.useState(null),[Be,Ye]=S.useState(!1),[qe,Ce]=S.useState(null),[_e,Qe]=S.useState([]),[Ue,ot]=S.useState(null),[lt,ie]=S.useState(null),[ue,we]=S.useState(!1),pe=S.useRef(null),xe=S.useRef(null),Re=S.useRef(null),Me=S.useCallback(()=>{pe.current&&(pe.current.value=""),xe.current&&(xe.current.value=""),ee(oe=>oe+1),Te(oe=>oe+1)},[]),Pe=S.useRef(!1);S.useEffect(()=>{Pe.current&&!R&&(ge([]),Me()),Pe.current=R},[R,Me]);const[st,mt]=S.useState("desktop");S.useEffect(()=>{const oe=()=>{const be=window.innerWidth;mt(be<640?"phone":be<1024?"tablet":"desktop")};return oe(),window.addEventListener("resize",oe),()=>window.removeEventListener("resize",oe)},[]),S.useEffect(()=>{let oe=!1;if(!v){Qe([]),ot(null),ie(null),Re.current=null;return}const be={threadId:v,checkpointId:V??null,checkpointNs:O??null},Fe=Re.current;if(!(Fe&&Fe.threadId===be.threadId&&Fe.checkpointId===be.checkpointId&&Fe.checkpointNs===be.checkpointNs))return x(v).then(et=>{var kr;if(oe)return;const bt=((et==null?void 0:et.checkpoints)??[]).slice().sort((N,b)=>new Date(b.createdAt).getTime()-new Date(N.createdAt).getTime());Qe(bt);const Mt=Ue,nr=Mt&&bt.some(N=>N.checkpointId===Mt)?Mt:((kr=bt[0])==null?void 0:kr.checkpointId)??null;let Tr=null;if(nr){const N=bt.find(b=>b.checkpointId===nr);Tr=(N==null?void 0:N.checkpointNs)??null}ot(nr),ie(Tr),Re.current=be}).catch(et=>{console.error("ChatInterface - listCheckpoints error:",et),oe||(Qe([]),Re.current=null)}),()=>{oe=!0}},[v,V,O,Ue,x]),S.useEffect(()=>{V&&(ot(V),ie(O??null))},[V,O]);const cn=S.useCallback(async()=>{if(!(!T||k))try{await _()}catch(oe){console.warn("loadOlderMessages failed",oe)}},[T,k,_]);S.useEffect(()=>{(async()=>{if(!w.baseUrl){Ce(null);return}try{const be=await w.getAgent("default");Ce(be.uiDefaultMessage||null)}catch(be){console.warn("Failed to fetch default message:",be),Ce(null)}})()},[w]),S.useEffect(()=>{L&&!Be&&(p==null||p(L))},[L,Be,p]);const un=oe=>{if(oe.length>ls)return`Message too long (${oe.length}/${ls} characters)`;try{return Sb(oe),null}catch(be){return(be==null?void 0:be.message)||"Invalid message"}},dn=async oe=>{const be=oe.trim();if(!(!be&&H.length===0)){if(be){const Fe=un(be);if(Fe){z(Fe);return}}try{await I(be||"",{checkpointId:Ue??V??void 0,checkpointNs:lt??O??void 0,payloadExtras:Y?{edit:!0,originalMessageId:Y}:void 0,attachments:H}),f==null||f(be),z(null),ge([]),Me(),K(null),B("")}catch(Fe){const et=(Fe==null?void 0:Fe.message)||"Failed to send message";z(et),p==null||p(et)}}},Rn=S.useCallback((oe,be)=>{u&&(K(oe),B(be),z(null))},[u]),er=S.useCallback(()=>{K(null),B(""),z(null)},[]),yr=S.useCallback((oe,be)=>{Rn(oe,be)},[Rn]),Pn=S.useCallback(oe=>{const be=Fe=>{const et=Fe.content||[],bt=et.filter(Mt=>Mt.type==="text").map(Mt=>Mt.text).join("");if(bt)return bt;try{return JSON.stringify(et,null,2)}catch{return String(et)}};for(let Fe=oe-1;Fe>=0;Fe--)if(E[Fe].role==="user"){const et=be(E[Fe]);et&&I(et,{checkpointId:Ue??V??void 0,checkpointNs:lt??O??void 0});break}},[E,I,Ue,lt,V,O]),xn=oe=>{const be=Array.from(oe.target.files||[]);ge(Fe=>[...Fe,...be]),oe.target.value=""},Yt=oe=>{ge(be=>{const Fe=be.filter((et,bt)=>oe!==bt);return Fe.length===0&&Me(),Fe})},vn=async oe=>{const be=(oe.target.files||[])[0];if(be){ne(null),le(null),M(!0);try{await I("",{checkpointId:Ue??V??void 0,checkpointNs:lt??O??void 0,attachments:[be]});const Fe=`Uploaded ${be.name} - processing through chat stream`;le(Fe)}catch(Fe){const et=Fe instanceof Error?Fe.message:"Failed to upload Excel file";console.error("Excel upload failed",Fe),ne(et),p==null||p(et)}finally{M(!1),oe.target.value="",Me()}}},On=oe=>{if(!oe)return"Unknown";const be=Date.parse(oe);return Number.isNaN(be)?oe:new Date(be).toLocaleString()},tr=async oe=>{if(v){we(!0);try{if(!oe){await C(),ot(null),ie(null);return}const be=_e.find(et=>et.checkpointId===oe),Fe=(be==null?void 0:be.checkpointNs)??null;await y(oe,Fe),ot(oe),ie(Fe)}finally{we(!1)}}},Sr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,It=`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 ${d.messagesArea||""}`,Cr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Sr,children:[!!L&&!Be&&c.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:[c.jsx("span",{children:L}),c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Ye(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(re.X,{size:16})})]}),v&&_e.length>0&&c.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:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.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:Ue??"",onChange:oe=>{const be=oe.target.value||null;tr(be)},children:[c.jsx("option",{value:"",children:"Latest"}),_e.map(oe=>c.jsxs("option",{value:oe.checkpointId,children:[On(oe.createdAt),oe.preview?` — ${oe.preview.slice(0,40)}`:""]},oe.checkpointId))]})]}),c.jsxs("div",{className:`relative ${It}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(sa,{className:"h-full",style:{height:"100%"},messages:E,isStreaming:R,streamingAssistantId:F,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:st,enableMessageEditing:u,editingMessageId:Y,onStartReached:()=>{cn()},onEdit:yr,onRegenerate:Pn,onCancelEdit:er,emptyMessage:qe??void 0,isNavigatingCheckpoint:ue}),g&&c.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:[c.jsx(re.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:Cr,children:[Y&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(re.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(We,{variant:"ghost",size:"sm",onClick:er,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(re.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:pe,type:"file",multiple:!0,onChange:oe=>xn(oe),className:"hidden"},de),H.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:H.map((oe,be)=>c.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:[c.jsx(re.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:oe.name}),c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Yt(be),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 ${oe.name}`,children:c.jsx(re.X,{size:12})})]},be))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:xe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vn,className:"hidden"},je),q&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(re.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Q&&!q&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Q}),Z&&!q&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Z})]})]}),$&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:$}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(cS,{children:[c.jsx(uS,{asChild:!0,children:c.jsx(We,{type:"button",size:"icon",variant:"outline",disabled:R,title:"More input actions",className:d.moreButton||"",children:c.jsx(re.Plus,{size:16})})}),c.jsxs(dh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(ja,{onClick:()=>{var oe;return(oe=pe.current)==null?void 0:oe.click()},className:"cursor-pointer",children:[c.jsx(re.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(ja,{onClick:()=>{var oe;q||(oe=xe.current)==null||oe.click()},className:`cursor-pointer ${q?"opacity-60 pointer-events-none":""}`,children:[c.jsx(re.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Mg,{initialValue:X,editingMessageId:Y,placeholder:Y?"Edit your message...":t,isStreaming:R,disabled:!1,maxLength:ls,onSend:dn,onCancelEdit:er,onStop:A,allowEmptySend:H.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${Y?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${$?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const Is=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:te("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}));Is.displayName="Input";function _a(e,[t,n]){return Math.min(n,Math.max(t,e))}function xS(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ra="ScrollArea",[fh,iT]=en(Ra),[vS,zt]=fh(Ra),hh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[v,g]=m.useState(null),[x,y]=m.useState(0),[C,E]=m.useState(0),[T,k]=m.useState(!1),[I,A]=m.useState(!1),_=$e(t,L=>l(L)),R=cs(o);return c.jsx(vS,{scope:n,type:r,dir:R,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:T,onScrollbarXEnabledChange:k,scrollbarY:v,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:y,onCornerHeightChange:E,children:c.jsx(Ie.div,{dir:R,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});hh.displayName=Ra;var ph="ScrollAreaViewport",mh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=zt(ph,n),a=m.useRef(null),l=$e(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.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}),c.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:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});mh.displayName=ph;var ln="ScrollAreaScrollbar",Pa=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zt(ln,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(wS,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(bS,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(gh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Oa,{...r,ref:t}):null});Pa.displayName=ln;var wS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zt(ln,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Rt,{present:n||s,children:c.jsx(gh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),bS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zt(ln,e.__scopeScrollArea),s=e.orientation==="horizontal",i=_s(()=>l("SCROLL_END"),100),[a,l]=xS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Rt,{present:n||a!=="hidden",children:c.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ce(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ce(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),gh=m.forwardRef((e,t)=>{const n=zt(ln,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=_s(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return vr(n.viewport,l),vr(n.content,l),c.jsx(Rt,{present:r||s,children:c.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=zt(ln,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=yh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return ES(h,i.current,a,p)}return n==="horizontal"?c.jsx(yS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Sh(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"?c.jsx(SS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Sh(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}),yS=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=zt(ln,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=$e(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(vh,{"data-orientation":"horizontal",...o,ref:u,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":js(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:As(i.paddingLeft),paddingEnd:As(i.paddingRight)}})}})}),SS=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=zt(ln,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=$e(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(vh,{"data-orientation":"vertical",...o,ref:u,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":js(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:As(i.paddingTop),paddingEnd:As(i.paddingBottom)}})}})}),[CS,xh]=fh(ln),vh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=zt(ln,n),[w,v]=m.useState(null),g=$e(t,_=>v(_)),x=m.useRef(null),y=m.useRef(""),C=p.viewport,E=r.content-r.viewport,T=pt(d),k=pt(l),I=_s(f,10);function A(_){if(x.current){const R=_.clientX-x.current.left,L=_.clientY-x.current.top;u({x:R,y:L})}}return m.useEffect(()=>{const _=R=>{const L=R.target;(w==null?void 0:w.contains(L))&&T(R,E)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[C,w,E,T]),m.useEffect(k,[r,k]),vr(w,I),vr(p.content,I),c.jsx(CS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:pt(s),onThumbPointerUp:pt(i),onThumbPositionChange:k,onThumbPointerDown:pt(a),children:c.jsx(Ie.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ce(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=w.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(_))}),onPointerMove:ce(e.onPointerMove,A),onPointerUp:ce(e.onPointerUp,_=>{const R=_.target;R.hasPointerCapture(_.pointerId)&&R.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=y.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Ns="ScrollAreaThumb",wh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=xh(Ns,e.__scopeScrollArea);return c.jsx(Rt,{present:n||o.hasThumb,children:c.jsx(TS,{ref:t,...r})})}),TS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=zt(Ns,n),i=xh(Ns,n),{onThumbPositionChange:a}=i,l=$e(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=_s(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=IS(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.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:ce(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),w=f.clientX-p.left,v=f.clientY-p.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:ce(e.onPointerUp,i.onThumbPointerUp)})});wh.displayName=Ns;var Ma="ScrollAreaCorner",bh=m.forwardRef((e,t)=>{const n=zt(Ma,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(kS,{...e,ref:t}):null});bh.displayName=Ma;var kS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=zt(Ma,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return vr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),vr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.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 As(e){return e?parseInt(e,10):0}function yh(e,t){const n=e/t;return isNaN(n)?0:n}function js(e){const t=yh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function ES(e,t,n,r="ltr"){const o=js(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ch([l,u],f)(e)}function Sh(e,t,n="ltr"){const r=js(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],u=_a(e,l);return Ch([0,i],[0,a])(u)}function Ch(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 Th(e,t){return e>0&&e<t}var IS=(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 _s(e,t){const n=pt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function vr(e,t){const n=pt(t);ft(()=>{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 kh=hh,NS=mh,AS=bh;const Eh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(kh,{ref:r,className:te("relative overflow-hidden",e),...n,children:[c.jsx(NS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(Ih,{}),c.jsx(AS,{})]}));Eh.displayName=kh.displayName;const Ih=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Pa,{ref:r,orientation:t,className:te("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:c.jsx(wh,{className:"relative flex-1 rounded-full bg-border"})}));Ih.displayName=Pa.displayName;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{loadThread:f,threads:h,currentThreadId:p,createThread:w,deleteThread:v,renameThread:g,isLoadingThreads:x}=yo(),[y,C]=S.useState(Array.isArray(h)?h:[]),E=S.useRef(y.length>0),[T,k]=S.useState(null),[I,A]=S.useState(""),[_,R]=S.useState(!1);S.useEffect(()=>{const z=Array.isArray(h)?h:[];if(z.length>0){E.current=!0,C(z);return}x||(E.current=!1,C(z))},[h,x]);const L=async z=>{try{await f(z),a==null||a(z),l==null||l(z)}catch(H){console.error("Failed to select thread:",H)}},F=async()=>{try{R(!0);const z=await w();u==null||u(z),a==null||a(z)}catch(z){console.error("Failed to create thread:",z)}finally{R(!1)}},V=async(z,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?"))try{await v(z),d==null||d(z)}catch(ge){console.error("Failed to delete thread:",ge)}},O=(z,H)=>{H.stopPropagation(),k(z.threadId),A(z.title||`Thread ${z.threadId.slice(0,8)}`)},Y=async z=>{if(I.trim())try{await g(z,I.trim()),k(null),A("")}catch(H){console.error("Failed to update title:",H)}},K=()=>{k(null),A("")},X=(z,H)=>{z.key==="Enter"?Y(H):z.key==="Escape"&&K()},B=z=>{if(!z)return"";try{const H=new Date(z),de=new Date().getTime()-H.getTime(),ee=Math.floor(de/(1e3*60*60*24));return ee===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ee===1?"Yesterday":ee<7?`${ee} days ago`:H.toLocaleDateString()}catch{return""}},$=z=>z.title||`Thread ${z.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.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:c.jsx(We,{onClick:F,disabled:_||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:_?"Creating...":"New Chat",children:c.jsx(re.MessageSquarePlus,{size:20})})}),c.jsx(Eh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(re.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):y.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(re.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):y.slice().sort((z,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(z.updatedAt||z.createdAt||"").getTime()).map(z=>c.jsxs("div",{onClick:()=>L(z.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===z.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:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:T===z.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[c.jsx(Is,{value:I,onChange:H=>A(H.target.value),onKeyDown:H=>X(H,z.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Y(z.threadId),className:"h-6 w-6 p-0",children:c.jsx(re.Check,{size:12})}),c.jsx(We,{variant:"ghost",size:"sm",onClick:K,className:"h-6 w-6 p-0",children:c.jsx(re.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:$(z)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(re.Calendar,{size:10}),c.jsx("span",{children:B(z.updatedAt||z.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&T!==z.threadId&&c.jsx(We,{variant:"ghost",size:"sm",onClick:H=>O(z,H),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(re.Edit3,{size:12})}),n&&c.jsx(We,{variant:"ghost",size:"sm",onClick:H=>V(z.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(re.Trash2,{size:12})})]})]}),i===z.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},z.threadId))})})]})}function wr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function jS(e){if(typeof e!="string")return;const t=e.trim();if(t)return hn(t)}function Nh(){const e=[wr("__API_BASE_URL__"),wr("__CHAT_API_BASE_URL__"),wr("__CHAT_API_URL__")];for(const t of e){const n=jS(t);if(n)return n}}function Ah(){const e=[wr("__API_AUTH_TOKEN__"),wr("__CHAT_API_KEY__"),wr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function jh(...e){for(const t of e)if(typeof t=="string"&&t.trim())return hn(t);return hn()}function _h(){const e={},t=Nh(),n=Ah();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Rh(){const e=_h(),t=wn.getAuthToken(),n=Nh();return{apiBaseUrl:jh(e.baseUrl,wn.baseUrl,n),apiKey:t||e.apiKey||Ah()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Ph="chat-settings";function _S(){try{const e=localStorage.getItem(Ph);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function RS(e){try{const t={...e,apiBaseUrl:hn(e.apiBaseUrl)};localStorage.setItem(Ph,JSON.stringify(t)),t.apiKey&&wn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function PS(){const e=Rh(),t=_S(),n=wn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:jh(wn.baseUrl,r,e.apiBaseUrl)}}function OS(e){wn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),RS(e)}var MS="Label",Oh=m.forwardRef((e,t)=>c.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())}}));Oh.displayName=MS;var Mh=Oh;const DS=io.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Bt=m.forwardRef(({className:e,...t},n)=>c.jsx(Mh,{ref:n,className:te(DS(),e),...t}));Bt.displayName=Mh.displayName;function Dh(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Rs="Switch",[LS,aT]=en(Rs),[FS,$S]=LS(Rs),Lh=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=$e(t,C=>p(C)),v=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[x,y]=Un({prop:o,defaultProp:s??!1,onChange:u,caller:Rs});return c.jsxs(FS,{scope:n,checked:x,disabled:a,children:[c.jsx(Ie.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Bh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:ce(e.onClick,C=>{y(E=>!E),g&&(v.current=C.isPropagationStopped(),v.current||C.stopPropagation())})}),g&&c.jsx(zh,{control:h,bubbles:!v.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Lh.displayName=Rs;var Fh="SwitchThumb",$h=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=$S(Fh,n);return c.jsx(Ie.span,{"data-state":Bh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$h.displayName=Fh;var zS="SwitchBubbleInput",zh=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=$e(i,s),l=Dh(n),u=Xd(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});zh.displayName=zS;function Bh(e){return e?"checked":"unchecked"}var Hh=Lh,BS=$h;const An=m.forwardRef(({className:e,...t},n)=>c.jsx(Hh,{className:te("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:c.jsx(BS,{className:te("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")})}));An.displayName=Hh.displayName;var Uh=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"}),HS="VisuallyHidden",US=m.forwardRef((e,t)=>c.jsx(Ie.span,{...e,ref:t,style:{...Uh,...e.style}}));US.displayName=HS;var WS=[" ","Enter","ArrowUp","ArrowDown"],VS=[" ","Enter"],Jn="Select",[Ps,Os,KS]=ia(Jn),[br,lT]=en(Jn,[KS,bs]),Ms=bs(),[qS,jn]=br(Jn),[GS,YS]=br(Jn),Wh=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,v=Ms(t),[g,x]=m.useState(null),[y,C]=m.useState(null),[E,T]=m.useState(!1),k=cs(u),[I,A]=Un({prop:r,defaultProp:o??!1,onChange:s,caller:Jn}),[_,R]=Un({prop:i,defaultProp:a,onChange:l,caller:Jn}),L=m.useRef(null),F=g?w||!!g.closest("form"):!0,[V,O]=m.useState(new Set),Y=Array.from(V).map(K=>K.props.value).join(";");return c.jsx(af,{...v,children:c.jsxs(qS,{required:p,scope:t,trigger:g,onTriggerChange:x,valueNode:y,onValueNodeChange:C,valueNodeHasChildren:E,onValueNodeHasChildrenChange:T,contentId:tn(),value:_,onValueChange:R,open:I,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Ps.Provider,{scope:t,children:c.jsx(GS,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(K=>{O(X=>new Set(X).add(K))},[]),onNativeOptionRemove:m.useCallback(K=>{O(X=>{const B=new Set(X);return B.delete(K),B})},[]),children:n})}),F?c.jsxs(pp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:K=>R(K.target.value),disabled:h,form:w,children:[_===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},Y):null]})})};Wh.displayName=Jn;var Vh="SelectTrigger",Kh=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ms(n),i=jn(Vh,n),a=i.disabled||r,l=$e(t,i.onTriggerChange),u=Os(n),d=m.useRef("touch"),[f,h,p]=gp(v=>{const g=u().filter(C=>!C.disabled),x=g.find(C=>C.value===i.value),y=xp(g,v,x);y!==void 0&&i.onValueChange(y.value)}),w=v=>{a||(i.onOpenChange(!0),p()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return c.jsx(lf,{asChild:!0,...s,children:c.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":mp(i.value)?"":void 0,...o,ref:l,onClick:ce(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:ce(o.onPointerDown,v=>{d.current=v.pointerType;const g=v.target;g.hasPointerCapture(v.pointerId)&&g.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:ce(o.onKeyDown,v=>{const g=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(g&&v.key===" ")&&WS.includes(v.key)&&(w(),v.preventDefault())})})})});Kh.displayName=Vh;var qh="SelectValue",Gh=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=jn(qh,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=$e(t,l.onValueNodeChange);return ft(()=>{u(d)},[u,d]),c.jsx(Ie.span,{...a,ref:f,style:{pointerEvents:"none"},children:mp(l.value)?c.jsx(c.Fragment,{children:i}):s})});Gh.displayName=qh;var XS="SelectIcon",Yh=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Ie.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Yh.displayName=XS;var JS="SelectPortal",Xh=e=>c.jsx(qo,{asChild:!0,...e});Xh.displayName=JS;var Zn="SelectContent",Jh=m.forwardRef((e,t)=>{const n=jn(Zn,e.__scopeSelect),[r,o]=m.useState();if(ft(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ao.createPortal(c.jsx(Zh,{scope:e.__scopeSelect,children:c.jsx(Ps.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Qh,{...e,ref:t})});Jh.displayName=Zn;var Gt=10,[Zh,_n]=br(Zn),ZS="SelectContentImpl",QS=Mn.createSlot("SelectContent.RemoveScroll"),Qh=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g,...x}=e,y=jn(Zn,n),[C,E]=m.useState(null),[T,k]=m.useState(null),I=$e(t,q=>E(q)),[A,_]=m.useState(null),[R,L]=m.useState(null),F=Os(n),[V,O]=m.useState(!1),Y=m.useRef(!1);m.useEffect(()=>{if(C)return ea(C)},[C]),Gi();const K=m.useCallback(q=>{const[M,...Z]=F().map(le=>le.ref.current),[ne]=Z.slice(-1),Q=document.activeElement;for(const le of q)if(le===Q||(le==null||le.scrollIntoView({block:"nearest"}),le===M&&T&&(T.scrollTop=0),le===ne&&T&&(T.scrollTop=T.scrollHeight),le==null||le.focus(),document.activeElement!==Q))return},[F,T]),X=m.useCallback(()=>K([A,C]),[K,A,C]);m.useEffect(()=>{V&&X()},[V,X]);const{onOpenChange:B,triggerPointerDownPosRef:$}=y;m.useEffect(()=>{if(C){let q={x:0,y:0};const M=ne=>{var Q,le;q={x:Math.abs(Math.round(ne.pageX)-(((Q=$.current)==null?void 0:Q.x)??0)),y:Math.abs(Math.round(ne.pageY)-(((le=$.current)==null?void 0:le.y)??0))}},Z=ne=>{q.x<=10&&q.y<=10?ne.preventDefault():C.contains(ne.target)||B(!1),document.removeEventListener("pointermove",M),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",Z,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",Z,{capture:!0})}}},[C,B,$]),m.useEffect(()=>{const q=()=>B(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[B]);const[z,H]=gp(q=>{const M=F().filter(Q=>!Q.disabled),Z=M.find(Q=>Q.ref.current===document.activeElement),ne=xp(M,q,Z);ne&&setTimeout(()=>ne.ref.current.focus())}),ge=m.useCallback((q,M,Z)=>{const ne=!Y.current&&!Z;(y.value!==void 0&&y.value===M||ne)&&(_(q),ne&&(Y.current=!0))},[y.value]),de=m.useCallback(()=>C==null?void 0:C.focus(),[C]),ee=m.useCallback((q,M,Z)=>{const ne=!Y.current&&!Z;(y.value!==void 0&&y.value===M||ne)&&L(q)},[y.value]),je=r==="popper"?La:ep,Te=je===La?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g}:{};return c.jsx(Zh,{scope:n,content:C,viewport:T,onViewportChange:k,itemRefCallback:ge,selectedItem:A,onItemLeave:de,itemTextRefCallback:ee,focusSelectedItem:X,selectedItemText:R,position:r,isPositioned:V,searchRef:z,children:c.jsx(Qo,{as:QS,allowPinchZoom:!0,children:c.jsx(Ko,{asChild:!0,trapped:y.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ce(o,q=>{var M;(M=y.trigger)==null||M.focus({preventScroll:!0}),q.preventDefault()}),children:c.jsx(Vo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>y.onOpenChange(!1),children:c.jsx(je,{role:"listbox",id:y.contentId,"data-state":y.open?"open":"closed",dir:y.dir,onContextMenu:q=>q.preventDefault(),...x,...Te,onPlaced:()=>O(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ce(x.onKeyDown,q=>{const M=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!M&&q.key.length===1&&H(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let ne=F().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);if(["ArrowUp","End"].includes(q.key)&&(ne=ne.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const Q=q.target,le=ne.indexOf(Q);ne=ne.slice(le+1)}setTimeout(()=>K(ne)),q.preventDefault()}})})})})})})});Qh.displayName=ZS;var eC="SelectItemAlignedPosition",ep=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=jn(Zn,n),i=_n(Zn,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=$e(t,I=>d(I)),h=Os(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:v,selectedItem:g,selectedItemText:x,focusSelectedItem:y}=i,C=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&g&&x){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),R=x.getBoundingClientRect();if(s.dir!=="rtl"){const Q=R.left-A.left,le=_.left-Q,Be=I.left-le,Ye=I.width+Be,qe=Math.max(Ye,A.width),Ce=window.innerWidth-Gt,_e=_a(le,[Gt,Math.max(Gt,Ce-qe)]);a.style.minWidth=Ye+"px",a.style.left=_e+"px"}else{const Q=A.right-R.right,le=window.innerWidth-_.right-Q,Be=window.innerWidth-I.right-le,Ye=I.width+Be,qe=Math.max(Ye,A.width),Ce=window.innerWidth-Gt,_e=_a(le,[Gt,Math.max(Gt,Ce-qe)]);a.style.minWidth=Ye+"px",a.style.right=_e+"px"}const L=h(),F=window.innerHeight-Gt*2,V=v.scrollHeight,O=window.getComputedStyle(u),Y=parseInt(O.borderTopWidth,10),K=parseInt(O.paddingTop,10),X=parseInt(O.borderBottomWidth,10),B=parseInt(O.paddingBottom,10),$=Y+K+V+B+X,z=Math.min(g.offsetHeight*5,$),H=window.getComputedStyle(v),ge=parseInt(H.paddingTop,10),de=parseInt(H.paddingBottom,10),ee=I.top+I.height/2-Gt,je=F-ee,Te=g.offsetHeight/2,q=g.offsetTop+Te,M=Y+K+q,Z=$-M;if(M<=ee){const Q=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const le=u.clientHeight-v.offsetTop-v.offsetHeight,Be=Math.max(je,Te+(Q?de:0)+le+X),Ye=M+Be;a.style.height=Ye+"px"}else{const Q=L.length>0&&g===L[0].ref.current;a.style.top="0px";const Be=Math.max(ee,Y+v.offsetTop+(Q?ge:0)+Te)+Z;a.style.height=Be+"px",v.scrollTop=M-ee+v.offsetTop}a.style.margin=`${Gt}px 0`,a.style.minHeight=z+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,g,x,s.dir,r]);ft(()=>C(),[C]);const[E,T]=m.useState();ft(()=>{u&&T(window.getComputedStyle(u).zIndex)},[u]);const k=m.useCallback(I=>{I&&w.current===!0&&(C(),y==null||y(),w.current=!1)},[C,y]);return c.jsx(nC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:k,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:c.jsx(Ie.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ep.displayName=eC;var tC="SelectPopperPosition",La=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Gt,...s}=e,i=Ms(n);return c.jsx(cf,{...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)"}})});La.displayName=tC;var[nC,Fa]=br(Zn,{}),$a="SelectViewport",tp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=_n($a,n),i=Fa($a,n),a=$e(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Ps.Slot,{scope:n,children:c.jsx(Ie.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ce(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const w=window.innerHeight-Gt*2,v=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),x=Math.max(v,g);if(x<w){const y=x+p,C=Math.min(w,y),E=y-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=E>0?E:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});tp.displayName=$a;var np="SelectGroup",[rC,oC]=br(np),sC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=tn();return c.jsx(rC,{scope:n,id:o,children:c.jsx(Ie.div,{role:"group","aria-labelledby":o,...r,ref:t})})});sC.displayName=np;var rp="SelectLabel",op=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=oC(rp,n);return c.jsx(Ie.div,{id:o.id,...r,ref:t})});op.displayName=rp;var Ds="SelectItem",[iC,sp]=br(Ds),ip=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=jn(Ds,n),l=_n(Ds,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=$e(t,y=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,y,r,o)}),v=tn(),g=m.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(iC,{scope:n,value:r,disabled:o,textId:v,isSelected:u,onItemTextChange:m.useCallback(y=>{f(C=>C||((y==null?void 0:y.textContent)??"").trim())},[]),children:c.jsx(Ps.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Ie.div,{role:"option","aria-labelledby":v,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus:ce(i.onFocus,()=>p(!0)),onBlur:ce(i.onBlur,()=>p(!1)),onClick:ce(i.onClick,()=>{g.current!=="mouse"&&x()}),onPointerUp:ce(i.onPointerUp,()=>{g.current==="mouse"&&x()}),onPointerDown:ce(i.onPointerDown,y=>{g.current=y.pointerType}),onPointerMove:ce(i.onPointerMove,y=>{var C;g.current=y.pointerType,o?(C=l.onItemLeave)==null||C.call(l):g.current==="mouse"&&y.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ce(i.onPointerLeave,y=>{var C;y.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:ce(i.onKeyDown,y=>{var E;((E=l.searchRef)==null?void 0:E.current)!==""&&y.key===" "||(VS.includes(y.key)&&x(),y.key===" "&&y.preventDefault())})})})})});ip.displayName=Ds;var oo="SelectItemText",ap=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=jn(oo,n),a=_n(oo,n),l=sp(oo,n),u=YS(oo,n),[d,f]=m.useState(null),h=$e(t,x=>f(x),l.onItemTextChange,x=>{var y;return(y=a.itemTextRefCallback)==null?void 0:y.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:v,onNativeOptionRemove:g}=u;return ft(()=>(v(w),()=>g(w)),[v,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(Ie.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ao.createPortal(s.children,i.valueNode):null]})});ap.displayName=oo;var lp="SelectItemIndicator",cp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return sp(lp,n).isSelected?c.jsx(Ie.span,{"aria-hidden":!0,...r,ref:t}):null});cp.displayName=lp;var za="SelectScrollUpButton",up=m.forwardRef((e,t)=>{const n=_n(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=m.useState(!1),i=$e(t,r.onScrollButtonChange);return ft(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(fp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});up.displayName=za;var Ba="SelectScrollDownButton",dp=m.forwardRef((e,t)=>{const n=_n(Ba,e.__scopeSelect),r=Fa(Ba,e.__scopeSelect),[o,s]=m.useState(!1),i=$e(t,r.onScrollButtonChange);return ft(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(fp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});dp.displayName=Ba;var fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=_n("SelectScrollButton",n),i=m.useRef(null),a=Os(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),ft(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(Ie.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ce(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ce(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ce(o.onPointerLeave,()=>{l()})})}),aC="SelectSeparator",hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Ie.div,{"aria-hidden":!0,...r,ref:t})});hp.displayName=aC;var Ha="SelectArrow",lC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ms(n),s=jn(Ha,n),i=_n(Ha,n);return s.open&&i.position==="popper"?c.jsx(uf,{...o,...r,ref:t}):null});lC.displayName=Ha;var cC="SelectBubbleInput",pp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=$e(r,o),i=Dh(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Ie.select,{...n,style:{...Uh,...n.style},ref:s,defaultValue:t})});pp.displayName=cC;function mp(e){return e===""||e===void 0}function gp(e){const t=pt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function xp(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=uC(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function uC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var dC=Wh,vp=Kh,fC=Gh,hC=Yh,pC=Xh,wp=Jh,mC=tp,bp=op,yp=ip,gC=ap,xC=cp,Sp=up,Cp=dp,Tp=hp;const kp=dC,Ep=fC,Ua=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(vp,{ref:r,className:te("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,c.jsx(hC,{asChild:!0,children:c.jsx(re.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ua.displayName=vp.displayName;const Ip=m.forwardRef(({className:e,...t},n)=>c.jsx(Sp,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(re.ChevronUp,{className:"h-4 w-4"})}));Ip.displayName=Sp.displayName;const Np=m.forwardRef(({className:e,...t},n)=>c.jsx(Cp,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(re.ChevronDown,{className:"h-4 w-4"})}));Np.displayName=Cp.displayName;const Wa=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(pC,{children:c.jsxs(wp,{ref:o,className:te("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:[c.jsx(Ip,{}),c.jsx(mC,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(Np,{})]})}));Wa.displayName=wp.displayName;const vC=m.forwardRef(({className:e,...t},n)=>c.jsx(bp,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));vC.displayName=bp.displayName;const Qn=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(yp,{ref:r,className:te("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(xC,{children:c.jsx(re.Check,{className:"h-4 w-4"})})}),c.jsx(gC,{children:t})]}));Qn.displayName=yp.displayName;const wC=m.forwardRef(({className:e,...t},n)=>c.jsx(Tp,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));wC.displayName=Tp.displayName;var bC="Separator",Ap="horizontal",yC=["horizontal","vertical"],jp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ap,...o}=e,s=SC(r)?r:Ap,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Ie.div,{"data-orientation":s,...a,...o,ref:t})});jp.displayName=bC;function SC(e){return yC.includes(e)}var _p=jp;const Rp=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(_p,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Rp.displayName=_p.displayName;const CC=pd,TC=rb,kC=md,Pp=m.forwardRef(({className:e,...t},n)=>c.jsx(os,{className:te("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}));Pp.displayName=os.displayName;const EC=io.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"}}),Op=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(kC,{children:[c.jsx(Pp,{}),c.jsxs(ss,{ref:o,className:te(EC({side:e}),t),...r,children:[n,c.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:[c.jsx(re.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Op.displayName=ss.displayName;const Mp=({className:e,...t})=>c.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Mp.displayName="SheetHeader";const Dp=m.forwardRef(({className:e,...t},n)=>c.jsx(Kn,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Dp.displayName=Kn.displayName;const Lp=m.forwardRef(({className:e,...t},n)=>c.jsx(is,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Lp.displayName=is.displayName;const IC={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 NC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=S.useState(!1),[s,i]=S.useState(!1),[a,l]=S.useState(e),[u,d]=S.useState(!1),{toast:f}=Ui();S.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),S.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(IC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(e),d(!1),o(!1)},v=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(CC,{open:r,onOpenChange:o,children:[c.jsx(TC,{asChild:!0,children:c.jsxs(We,{variant:"outline",size:"sm",className:n,children:[c.jsx(re.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Pi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(Op,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(Mp,{children:[c.jsx(Dp,{children:"Chat Settings"}),c.jsx(Lp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(Wr,{children:[c.jsx(Vr,{className:"pb-3",children:c.jsxs(Kr,{className:"text-lg flex items-center gap-2",children:[c.jsx(re.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Fo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Is,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(x=>({...x,api:{...x.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(We,{variant:"outline",onClick:v,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(An,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(x=>({...x,api:{...x.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Is,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(x=>({...x,api:{...x.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(We,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(re.EyeOff,{className:"h-4 w-4"}):c.jsx(re.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(Wr,{children:[c.jsx(Vr,{className:"pb-3",children:c.jsxs(Kr,{className:"text-lg flex items-center gap-2",children:[c.jsx(re.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Fo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(kp,{value:a.ui.layout,onValueChange:g=>l(x=>({...x,ui:{...x.ui,layout:g}})),children:[c.jsx(Ua,{children:c.jsx(Ep,{})}),c.jsxs(Wa,{children:[c.jsx(Qn,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(Qn,{value:"fullscreen",children:"Fullscreen"}),c.jsx(Qn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"theme",children:"Theme"}),c.jsxs(kp,{value:a.ui.theme,onValueChange:g=>l(x=>({...x,ui:{...x.ui,theme:g}})),children:[c.jsx(Ua,{children:c.jsx(Ep,{})}),c.jsxs(Wa,{children:[c.jsx(Qn,{value:"light",children:"Light"}),c.jsx(Qn,{value:"dark",children:"Dark"}),c.jsx(Qn,{value:"system",children:"System"})]})]})]}),c.jsx(Rp,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(An,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(An,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(An,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(Wr,{children:[c.jsx(Vr,{className:"pb-3",children:c.jsxs(Kr,{className:"text-lg flex items-center gap-2",children:[c.jsx(re.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Fo,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Bt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(An,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Bt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(An,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Bt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(An,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(We,{variant:"outline",onClick:p,children:[c.jsx(re.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(We,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(We,{onClick:h,disabled:!u,children:[c.jsx(re.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function AC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=S.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(So,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Es,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(So,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Es,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(So,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Es,{onError:s.onError,enableFileUpload:!0})})]})})}Ne.ChatApi=zl,Ne.ChatInterface=Es,Ne.ChatProviders=So,Ne.ChatSettings=NC,Ne.MarkdownContent=zi,Ne.MessageComponent=kd,Ne.MessageList=sa,Ne.ThreadManager=Da,Ne.applySettings=OS,Ne.chatApiClient=wn,Ne.default=AC,Ne.del=$l,Ne.get=Nt,Ne.getChatToken=Dl,Ne.getCurrentSettings=PS,Ne.getDefaultApiConfig=_h,Ne.getDefaultChatSettings=Rh,Ne.onChatTokenChanged=Ll,Ne.post=Zs,Ne.put=Fl,Ne.setChatToken=Js,Ne.useApi=Qs,Ne.useChatStream=Jl,Ne.useMessages=ci,Ne.useMessagesReducer=Hl,Ne.useStream=oc,Ne.useThreads=yo,Object.defineProperties(Ne,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
140
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function yb(e,t=ls){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function Sb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),yb(t),bb(t)}function ia(e){const t=e+"CollectionProvider",[n,r]=en(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:g,children:x}=v,y=S.useRef(null),C=S.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:C,collectionRef:y,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Mn.createSlot(a),u=S.forwardRef((v,g)=>{const{scope:x,children:y}=v,C=s(a,x),E=$e(g,C.collectionRef);return c.jsx(l,{ref:E,children:y})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Mn.createSlot(d),p=S.forwardRef((v,g)=>{const{scope:x,children:y,...C}=v,E=S.useRef(null),T=$e(g,E),k=s(d,x);return S.useEffect(()=>(k.itemMap.set(E,{ref:E,...C}),()=>void k.itemMap.delete(E))),c.jsx(h,{[f]:"",ref:T,children:y})});p.displayName=d;function w(v){const g=s(e+"CollectionConsumer",v);return S.useCallback(()=>{const y=g.collectionRef.current;if(!y)return[];const C=Array.from(y.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((k,I)=>C.indexOf(k.ref.current)-C.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},w,r]}var Cb=m.createContext(void 0);function cs(e){const t=m.useContext(Cb);return e||t||"ltr"}const Tb=["top","right","bottom","left"],In=Math.min,Pt=Math.max,us=Math.round,ds=Math.floor,rn=e=>({x:e,y:e}),kb={left:"right",right:"left",bottom:"top",top:"bottom"},Eb={start:"end",end:"start"};function aa(e,t,n){return Pt(e,In(t,n))}function mn(e,t){return typeof e=="function"?e(t):e}function gn(e){return e.split("-")[0]}function pr(e){return e.split("-")[1]}function la(e){return e==="x"?"y":"x"}function ca(e){return e==="y"?"height":"width"}const Ib=new Set(["top","bottom"]);function on(e){return Ib.has(gn(e))?"y":"x"}function ua(e){return la(on(e))}function Nb(e,t,n){n===void 0&&(n=!1);const r=pr(e),o=ua(e),s=ca(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=fs(i)),[i,fs(i)]}function Ab(e){const t=fs(e);return[da(e),t,da(t)]}function da(e){return e.replace(/start|end/g,t=>Eb[t])}const Id=["left","right"],Nd=["right","left"],jb=["top","bottom"],_b=["bottom","top"];function Rb(e,t,n){switch(e){case"top":case"bottom":return n?t?Nd:Id:t?Id:Nd;case"left":case"right":return t?jb:_b;default:return[]}}function Pb(e,t,n,r){const o=pr(e);let s=Rb(gn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(da)))),s}function fs(e){return e.replace(/left|right|bottom|top/g,t=>kb[t])}function Ob(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ad(e){return typeof e!="number"?Ob(e):{top:e,right:e,bottom:e,left:e}}function hs(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function jd(e,t,n){let{reference:r,floating:o}=e;const s=on(t),i=ua(t),a=ca(i),l=gn(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(pr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Mb=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 u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=jd(u,r,l),h=r,p={},w=0;for(let v=0;v<a.length;v++){const{name:g,fn:x}=a[v],{x:y,y:C,data:E,reset:T}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=y??d,f=C??f,p={...p,[g]:{...p[g],...E}},T&&w<=50&&(w++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(u=T.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):T.rects),{x:d,y:f}=jd(u,h,l)),v=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Yr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=mn(t,e),w=Ad(p),g=a[h?f==="floating"?"reference":"floating":f],x=hs(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),y=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},T=hs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:C,strategy:l}):y);return{top:(x.top-T.top+w.top)/E.y,bottom:(T.bottom-x.bottom+w.bottom)/E.y,left:(x.left-T.left+w.left)/E.x,right:(T.right-x.right+w.right)/E.x}}const Db=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:u,padding:d=0}=mn(e,t)||{};if(u==null)return{};const f=Ad(d),h={x:n,y:r},p=ua(o),w=ca(p),v=await i.getDimensions(u),g=p==="y",x=g?"top":"left",y=g?"bottom":"right",C=g?"clientHeight":"clientWidth",E=s.reference[w]+s.reference[p]-h[p]-s.floating[w],T=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=k?k[C]:0;(!I||!await(i.isElement==null?void 0:i.isElement(k)))&&(I=a.floating[C]||s.floating[w]);const A=E/2-T/2,_=I/2-v[w]/2-1,R=In(f[x],_),L=In(f[y],_),F=R,V=I-v[w]-L,O=I/2-v[w]/2+A,Y=aa(F,O,V),q=!l.arrow&&pr(o)!=null&&O!==Y&&s.reference[w]/2-(O<F?R:L)-v[w]/2<0,X=q?O<F?O-F:O-V:0;return{[p]:h[p]+X,data:{[p]:Y,centerOffset:O-Y-X,...q&&{alignmentOffset:X}},reset:q}}}),Lb=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:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...g}=mn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=gn(o),y=on(a),C=gn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(u.floating)),T=h||(C||!v?[fs(a)]:Ab(a)),k=w!=="none";!h&&k&&T.push(...Pb(a,v,w,E));const I=[a,...T],A=await Yr(t,g),_=[];let R=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(A[x]),f){const O=Nb(o,i,E);_.push(A[O[0]],A[O[1]])}if(R=[...R,{placement:o,overflows:_}],!_.every(O=>O<=0)){var L,F;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,Y=I[O];if(Y&&(!(f==="alignment"?y!==on(Y):!1)||R.every(B=>on(B.placement)===y?B.overflows[0]>0:!0)))return{data:{index:O,overflows:R},reset:{placement:Y}};let q=(F=R.filter(X=>X.overflows[0]<=0).sort((X,B)=>X.overflows[1]-B.overflows[1])[0])==null?void 0:F.placement;if(!q)switch(p){case"bestFit":{var V;const X=(V=R.filter(B=>{if(k){const $=on(B.placement);return $===y||$==="y"}return!0}).map(B=>[B.placement,B.overflows.filter($=>$>0).reduce(($,z)=>$+z,0)]).sort((B,$)=>B[1]-$[1])[0])==null?void 0:V[0];X&&(q=X);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function _d(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Rd(e){return Tb.some(t=>e[t]>=0)}const Fb=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=mn(e,t);switch(r){case"referenceHidden":{const s=await Yr(t,{...o,elementContext:"reference"}),i=_d(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Rd(i)}}}case"escaped":{const s=await Yr(t,{...o,altBoundary:!0}),i=_d(s,n.floating);return{data:{escapedOffsets:i,escaped:Rd(i)}}}default:return{}}}}},Pd=new Set(["left","top"]);async function $b(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=gn(n),a=pr(n),l=on(n)==="y",u=Pd.has(i)?-1:1,d=s&&l?-1:1,f=mn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:w}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof w=="number"&&(p=a==="end"?w*-1:w),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const zb=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 $b(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}}}}},Bb=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:g=>{let{x,y}=g;return{x,y}}},...l}=mn(e,t),u={x:n,y:r},d=await Yr(t,l),f=on(gn(o)),h=la(f);let p=u[h],w=u[f];if(s){const g=h==="y"?"top":"left",x=h==="y"?"bottom":"right",y=p+d[g],C=p-d[x];p=aa(y,p,C)}if(i){const g=f==="y"?"top":"left",x=f==="y"?"bottom":"right",y=w+d[g],C=w-d[x];w=aa(y,w,C)}const v=a.fn({...t,[h]:p,[f]:w});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[h]:s,[f]:i}}}}}},Hb=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:u=!0}=mn(e,t),d={x:n,y:r},f=on(o),h=la(f);let p=d[h],w=d[f];const v=mn(a,t),g=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const C=h==="y"?"height":"width",E=s.reference[h]-s.floating[C]+g.mainAxis,T=s.reference[h]+s.reference[C]-g.mainAxis;p<E?p=E:p>T&&(p=T)}if(u){var x,y;const C=h==="y"?"width":"height",E=Pd.has(gn(o)),T=s.reference[f]-s.floating[C]+(E&&((x=i.offset)==null?void 0:x[f])||0)+(E?0:g.crossAxis),k=s.reference[f]+s.reference[C]+(E?0:((y=i.offset)==null?void 0:y[f])||0)-(E?g.crossAxis:0);w<T?w=T:w>k&&(w=k)}return{[h]:p,[f]:w}}}},Ub=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=()=>{},...u}=mn(e,t),d=await Yr(t,u),f=gn(o),h=pr(o),p=on(o)==="y",{width:w,height:v}=s.floating;let g,x;f==="top"||f==="bottom"?(g=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,g=h==="end"?"top":"bottom");const y=v-d.top-d.bottom,C=w-d.left-d.right,E=In(v-d[g],y),T=In(w-d[x],C),k=!t.middlewareData.shift;let I=E,A=T;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=y),k&&!h){const R=Pt(d.left,0),L=Pt(d.right,0),F=Pt(d.top,0),V=Pt(d.bottom,0);p?A=w-2*(R!==0||L!==0?R+L:Pt(d.left,d.right)):I=v-2*(F!==0||V!==0?F+V:Pt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const _=await i.getDimensions(a.floating);return w!==_.width||v!==_.height?{reset:{rects:!0}}:{}}}};function ps(){return typeof window<"u"}function mr(e){return Od(e)?(e.nodeName||"").toLowerCase():"#document"}function Ot(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function sn(e){var t;return(t=(Od(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Od(e){return ps()?e instanceof Node||e instanceof Ot(e).Node:!1}function qt(e){return ps()?e instanceof Element||e instanceof Ot(e).Element:!1}function an(e){return ps()?e instanceof HTMLElement||e instanceof Ot(e).HTMLElement:!1}function Md(e){return!ps()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ot(e).ShadowRoot}const Wb=new Set(["inline","contents"]);function Xr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Kt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Wb.has(o)}const Vb=new Set(["table","td","th"]);function qb(e){return Vb.has(mr(e))}const Kb=[":popover-open",":modal"];function ms(e){return Kb.some(t=>{try{return e.matches(t)}catch{return!1}})}const Gb=["transform","translate","scale","rotate","perspective"],Yb=["transform","translate","scale","rotate","perspective","filter"],Xb=["paint","layout","strict","content"];function fa(e){const t=ha(),n=qt(e)?Kt(e):e;return Gb.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)||Yb.some(r=>(n.willChange||"").includes(r))||Xb.some(r=>(n.contain||"").includes(r))}function Jb(e){let t=Nn(e);for(;an(t)&&!gr(t);){if(fa(t))return t;if(ms(t))return null;t=Nn(t)}return null}function ha(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Zb=new Set(["html","body","#document"]);function gr(e){return Zb.has(mr(e))}function Kt(e){return Ot(e).getComputedStyle(e)}function gs(e){return qt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Nn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Md(e)&&e.host||sn(e);return Md(t)?t.host:t}function Dd(e){const t=Nn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:an(t)&&Xr(t)?t:Dd(t)}function Jr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Dd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ot(o);if(s){const a=pa(i);return t.concat(i,i.visualViewport||[],Xr(o)?o:[],a&&n?Jr(a):[])}return t.concat(o,Jr(o,[],n))}function pa(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Ld(e){const t=Kt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=an(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 ma(e){return qt(e)?e:e.contextElement}function xr(e){const t=ma(e);if(!an(t))return rn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Ld(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 Qb=rn(0);function Fd(e){const t=Ot(e);return!ha()||!t.visualViewport?Qb:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ey(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ot(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ma(e);let i=rn(1);t&&(r?qt(r)&&(i=xr(r)):i=xr(e));const a=ey(s,n,r)?Fd(s):rn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Ot(s),p=r&&qt(r)?Ot(r):r;let w=h,v=pa(w);for(;v&&r&&p!==w;){const g=xr(v),x=v.getBoundingClientRect(),y=Kt(v),C=x.left+(v.clientLeft+parseFloat(y.paddingLeft))*g.x,E=x.top+(v.clientTop+parseFloat(y.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=C,u+=E,w=Ot(v),v=pa(w)}}return hs({width:d,height:f,x:l,y:u})}function xs(e,t){const n=gs(e).scrollLeft;return t?t.left+n:Gn(sn(e)).left+n}function $d(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 ty(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=sn(r),a=t?ms(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=rn(1);const d=rn(0),f=an(r);if((f||!f&&!s)&&((mr(r)!=="body"||Xr(i))&&(l=gs(r)),an(r))){const p=Gn(r);u=xr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?$d(i,l):rn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function ny(e){return Array.from(e.getClientRects())}function ry(e){const t=sn(e),n=gs(e),r=e.ownerDocument.body,o=Pt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Pt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+xs(e);const a=-n.scrollTop;return Kt(r).direction==="rtl"&&(i+=Pt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const zd=25;function oy(e,t){const n=Ot(e),r=sn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=ha();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=xs(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,w=Math.abs(r.clientWidth-f.clientWidth-p);w<=zd&&(s-=w)}else u<=zd&&(s+=u);return{width:s,height:i,x:a,y:l}}const sy=new Set(["absolute","fixed"]);function iy(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=an(e)?xr(e):rn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function Bd(e,t,n){let r;if(t==="viewport")r=oy(e,n);else if(t==="document")r=ry(sn(e));else if(qt(t))r=iy(t,n);else{const o=Fd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return hs(r)}function Hd(e,t){const n=Nn(e);return n===t||!qt(n)||gr(n)?!1:Kt(n).position==="fixed"||Hd(n,t)}function ay(e,t){const n=t.get(e);if(n)return n;let r=Jr(e,[],!1).filter(a=>qt(a)&&mr(a)!=="body"),o=null;const s=Kt(e).position==="fixed";let i=s?Nn(e):e;for(;qt(i)&&!gr(i);){const a=Kt(i),l=fa(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&sy.has(o.position)||Xr(i)&&!l&&Hd(e,i))?r=r.filter(d=>d!==i):o=a,i=Nn(i)}return t.set(e,r),r}function ly(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?ms(t)?[]:ay(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=Bd(t,d,o);return u.top=Pt(f.top,u.top),u.right=In(f.right,u.right),u.bottom=In(f.bottom,u.bottom),u.left=Pt(f.left,u.left),u},Bd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function cy(e){const{width:t,height:n}=Ld(e);return{width:t,height:n}}function uy(e,t,n){const r=an(t),o=sn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=rn(0);function u(){l.x=xs(o)}if(r||!r&&!s)if((mr(t)!=="body"||Xr(o))&&(a=gs(t)),r){const p=Gn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?$d(o,a):rn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function ga(e){return Kt(e).position==="static"}function Ud(e,t){if(!an(e)||Kt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return sn(e)===n&&(n=n.ownerDocument.body),n}function Wd(e,t){const n=Ot(e);if(ms(e))return n;if(!an(e)){let o=Nn(e);for(;o&&!gr(o);){if(qt(o)&&!ga(o))return o;o=Nn(o)}return n}let r=Ud(e,t);for(;r&&qb(r)&&ga(r);)r=Ud(r,t);return r&&gr(r)&&ga(r)&&!fa(r)?n:r||Jb(e)||n}const dy=async function(e){const t=this.getOffsetParent||Wd,n=this.getDimensions,r=await n(e.floating);return{reference:uy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function fy(e){return Kt(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ty,getDocumentElement:sn,getClippingRect:ly,getOffsetParent:Wd,getElementRects:dy,getClientRects:ny,getDimensions:cy,getScale:xr,isElement:qt,isRTL:fy};function Vd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function py(e,t){let n=null,r;const o=sn(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 u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const w=ds(f),v=ds(o.clientWidth-(d+h)),g=ds(o.clientHeight-(f+p)),x=ds(d),C={rootMargin:-w+"px "+-v+"px "+-g+"px "+-x+"px",threshold:Pt(0,In(1,l))||1};let E=!0;function T(k){const I=k[0].intersectionRatio;if(I!==l){if(!E)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Vd(u,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(T,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(T,C)}n.observe(e)}return i(!0),s}function my(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,u=ma(e),d=o||s?[...u?Jr(u):[],...Jr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?py(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[y]=x;y&&y.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let w,v=l?Gn(e):null;l&&g();function g(){const x=Gn(e);v&&!Vd(v,x)&&n(),v=x,w=requestAnimationFrame(g)}return n(),()=>{var x;d.forEach(y=>{o&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(w)}}const gy=zb,xy=Bb,vy=Lb,wy=Ub,by=Fb,qd=Db,yy=Hb,Sy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Mb(e,t,{...o,platform:s})};var Cy=typeof document<"u",Ty=function(){},vs=Cy?S.useLayoutEffect:Ty;function ws(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(!ws(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)&&!ws(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Kd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Gd(e,t){const n=Kd(e);return Math.round(t*n)/n}function xa(e){const t=m.useRef(e);return vs(()=>{t.current=e}),t}function ky(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:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);ws(h,r)||p(r);const[w,v]=m.useState(null),[g,x]=m.useState(null),y=m.useCallback(B=>{B!==k.current&&(k.current=B,v(B))},[]),C=m.useCallback(B=>{B!==I.current&&(I.current=B,x(B))},[]),E=s||w,T=i||g,k=m.useRef(null),I=m.useRef(null),A=m.useRef(d),_=l!=null,R=xa(l),L=xa(o),F=xa(u),V=m.useCallback(()=>{if(!k.current||!I.current)return;const B={placement:t,strategy:n,middleware:h};L.current&&(B.platform=L.current),Sy(k.current,I.current,B).then($=>{const z={...$,isPositioned:F.current!==!1};O.current&&!ws(A.current,z)&&(A.current=z,ao.flushSync(()=>{f(z)}))})},[h,t,n,L,F]);vs(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[u]);const O=m.useRef(!1);vs(()=>(O.current=!0,()=>{O.current=!1}),[]),vs(()=>{if(E&&(k.current=E),T&&(I.current=T),E&&T){if(R.current)return R.current(E,T,V);V()}},[E,T,V,R,_]);const Y=m.useMemo(()=>({reference:k,floating:I,setReference:y,setFloating:C}),[y,C]),q=m.useMemo(()=>({reference:E,floating:T}),[E,T]),X=m.useMemo(()=>{const B={position:n,left:0,top:0};if(!q.floating)return B;const $=Gd(q.floating,d.x),z=Gd(q.floating,d.y);return a?{...B,transform:"translate("+$+"px, "+z+"px)",...Kd(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:z}},[n,a,q.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:Y,elements:q,floatingStyles:X}),[d,V,Y,q,X])}const Ey=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?qd({element:r.current,padding:o}).fn(n):{}:r?qd({element:r,padding:o}).fn(n):{}}}},Iy=(e,t)=>({...gy(e),options:[e,t]}),Ny=(e,t)=>({...xy(e),options:[e,t]}),Ay=(e,t)=>({...yy(e),options:[e,t]}),jy=(e,t)=>({...vy(e),options:[e,t]}),_y=(e,t)=>({...wy(e),options:[e,t]}),Ry=(e,t)=>({...by(e),options:[e,t]}),Py=(e,t)=>({...Ey(e),options:[e,t]});var Oy="Arrow",Yd=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Ie.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Yd.displayName=Oy;var My=Yd;function Xd(e){const[t,n]=m.useState(void 0);return ft(()=>{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,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.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 va="Popper",[Jd,bs]=en(va),[Dy,Zd]=Jd(va),Qd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(Dy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Qd.displayName=va;var ef="PopperAnchor",tf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Zd(ef,n),i=m.useRef(null),a=$e(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Ie.div,{...o,ref:a})});tf.displayName=ef;var wa="PopperContent",[Ly,Fy]=Jd(wa),nf=m.forwardRef((e,t)=>{var K,M,Z,ne,Q,le;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:w,...v}=e,g=Zd(wa,n),[x,y]=m.useState(null),C=$e(t,Be=>y(Be)),[E,T]=m.useState(null),k=Xd(E),I=(k==null?void 0:k.width)??0,A=(k==null?void 0:k.height)??0,_=r+(s!=="center"?"-"+s:""),R=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(u)?u:[u],F=L.length>0,V={padding:R,boundary:L.filter(zy),altBoundary:F},{refs:O,floatingStyles:Y,placement:q,isPositioned:X,middlewareData:B}=ky({strategy:"fixed",placement:_,whileElementsMounted:(...Be)=>my(...Be,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[Iy({mainAxis:o+A,alignmentAxis:i}),l&&Ny({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Ay():void 0,...V}),l&&jy({...V}),_y({...V,apply:({elements:Be,rects:Ye,availableWidth:Ke,availableHeight:Ce})=>{const{width:_e,height:Qe}=Ye.reference,Ue=Be.floating.style;Ue.setProperty("--radix-popper-available-width",`${Ke}px`),Ue.setProperty("--radix-popper-available-height",`${Ce}px`),Ue.setProperty("--radix-popper-anchor-width",`${_e}px`),Ue.setProperty("--radix-popper-anchor-height",`${Qe}px`)}}),E&&Py({element:E,padding:a}),By({arrowWidth:I,arrowHeight:A}),h&&Ry({strategy:"referenceHidden",...V})]}),[$,z]=sf(q),H=pt(w);ft(()=>{X&&(H==null||H())},[X,H]);const ge=(K=B.arrow)==null?void 0:K.x,de=(M=B.arrow)==null?void 0:M.y,ee=((Z=B.arrow)==null?void 0:Z.centerOffset)!==0,[je,Te]=m.useState();return ft(()=>{x&&Te(window.getComputedStyle(x).zIndex)},[x]),c.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...Y,transform:X?Y.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:je,"--radix-popper-transform-origin":[(ne=B.transformOrigin)==null?void 0:ne.x,(Q=B.transformOrigin)==null?void 0:Q.y].join(" "),...((le=B.hide)==null?void 0:le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(Ly,{scope:n,placedSide:$,onArrowChange:T,arrowX:ge,arrowY:de,shouldHideArrow:ee,children:c.jsx(Ie.div,{"data-side":$,"data-align":z,...v,ref:C,style:{...v.style,animation:X?void 0:"none"}})})})});nf.displayName=wa;var rf="PopperArrow",$y={top:"bottom",right:"left",bottom:"top",left:"right"},of=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Fy(rf,r),i=$y[s.placedSide];return c.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:c.jsx(My,{...o,ref:n,style:{...o.style,display:"block"}})})});of.displayName=rf;function zy(e){return e!==null}var By=e=>({name:"transformOrigin",options:e,fn(t){var g,x,y;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=sf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((y=o.arrow)==null?void 0:y.y)??0)+l/2;let w="",v="";return u==="bottom"?(w=i?f:`${h}px`,v=`${-l}px`):u==="top"?(w=i?f:`${h}px`,v=`${r.floating.height+l}px`):u==="right"?(w=`${-l}px`,v=i?f:`${p}px`):u==="left"&&(w=`${r.floating.width+l}px`,v=i?f:`${p}px`),{data:{x:w,y:v}}}});function sf(e){const[t,n="center"]=e.split("-");return[t,n]}var af=Qd,lf=tf,cf=nf,uf=of,ba="rovingFocusGroup.onEntryFocus",Hy={bubbles:!1,cancelable:!0},Zr="RovingFocusGroup",[ya,df,Uy]=ia(Zr),[Wy,ff]=en(Zr,[Uy]),[Vy,qy]=Wy(Zr),hf=m.forwardRef((e,t)=>c.jsx(ya.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(ya.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ky,{...e,ref:t})})}));hf.displayName=Zr;var Ky=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=$e(t,h),w=cs(s),[v,g]=Un({prop:i,defaultProp:a??null,onChange:l,caller:Zr}),[x,y]=m.useState(!1),C=pt(u),E=df(n),T=m.useRef(!1),[k,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ba,C),()=>A.removeEventListener(ba,C)},[C]),c.jsx(Vy,{scope:n,orientation:r,dir:w,loop:o,currentTabStopId:v,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>y(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(Ie.div,{tabIndex:x||k===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ce(e.onMouseDown,()=>{T.current=!0}),onFocus:ce(e.onFocus,A=>{const _=!T.current;if(A.target===A.currentTarget&&_&&!x){const R=new CustomEvent(ba,Hy);if(A.currentTarget.dispatchEvent(R),!R.defaultPrevented){const L=E().filter(q=>q.focusable),F=L.find(q=>q.active),V=L.find(q=>q.id===v),Y=[F,V,...L].filter(Boolean).map(q=>q.ref.current);gf(Y,d)}}T.current=!1}),onBlur:ce(e.onBlur,()=>y(!1))})})}),pf="RovingFocusGroupItem",mf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=tn(),u=s||l,d=qy(pf,n),f=d.currentTabStopId===u,h=df(n),{onFocusableItemAdd:p,onFocusableItemRemove:w,currentTabStopId:v}=d;return m.useEffect(()=>{if(r)return p(),()=>w()},[r,p,w]),c.jsx(ya.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Ie.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ce(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ce(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ce(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const x=Xy(g,d.orientation,d.dir);if(x!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let C=h().filter(E=>E.focusable).map(E=>E.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const E=C.indexOf(g.currentTarget);C=d.loop?Jy(C,E+1):C.slice(E+1)}setTimeout(()=>gf(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:v!=null}):i})})});mf.displayName=pf;var Gy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Yy(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Xy(e,t,n){const r=Yy(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Gy[r]}function gf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Jy(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Zy=hf,Qy=mf,Sa=["Enter"," "],e0=["ArrowDown","PageUp","Home"],xf=["ArrowUp","PageDown","End"],t0=[...e0,...xf],n0={ltr:[...Sa,"ArrowRight"],rtl:[...Sa,"ArrowLeft"]},r0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Qr="Menu",[eo,o0,s0]=ia(Qr),[Yn,vf]=en(Qr,[s0,bs,ff]),ys=bs(),wf=ff(),[i0,Xn]=Yn(Qr),[a0,to]=Yn(Qr),bf=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ys(t),[l,u]=m.useState(null),d=m.useRef(!1),f=pt(s),h=cs(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",w,{capture:!0,once:!0}),document.addEventListener("pointermove",w,{capture:!0,once:!0})},w=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",w,{capture:!0}),document.removeEventListener("pointermove",w,{capture:!0})}},[]),c.jsx(af,{...a,children:c.jsx(i0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(a0,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};bf.displayName=Qr;var l0="MenuAnchor",Ca=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ys(n);return c.jsx(lf,{...o,...r,ref:t})});Ca.displayName=l0;var Ta="MenuPortal",[c0,yf]=Yn(Ta,{forceMount:void 0}),Sf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(Ta,t);return c.jsx(c0,{scope:t,forceMount:n,children:c.jsx(Rt,{present:n||s.open,children:c.jsx(Ko,{asChild:!0,container:o,children:r})})})};Sf.displayName=Ta;var $t="MenuContent",[u0,ka]=Yn($t),Cf=m.forwardRef((e,t)=>{const n=yf($t,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn($t,e.__scopeMenu),i=to($t,e.__scopeMenu);return c.jsx(eo.Provider,{scope:e.__scopeMenu,children:c.jsx(Rt,{present:r||s.open,children:c.jsx(eo.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(d0,{...o,ref:t}):c.jsx(f0,{...o,ref:t})})})})}),d0=m.forwardRef((e,t)=>{const n=Xn($t,e.__scopeMenu),r=m.useRef(null),o=$e(t,r);return m.useEffect(()=>{const s=r.current;if(s)return ea(s)},[]),c.jsx(Ea,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ce(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),f0=m.forwardRef((e,t)=>{const n=Xn($t,e.__scopeMenu);return c.jsx(Ea,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),h0=Mn.createSlot("MenuContent.ScrollLock"),Ea=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:w,...v}=e,g=Xn($t,n),x=to($t,n),y=ys(n),C=wf(n),E=o0(n),[T,k]=m.useState(null),I=m.useRef(null),A=$e(t,I,g.onContentChange),_=m.useRef(0),R=m.useRef(""),L=m.useRef(0),F=m.useRef(null),V=m.useRef("right"),O=m.useRef(0),Y=w?Qo:m.Fragment,q=w?{as:h0,allowPinchZoom:!0}:void 0,X=$=>{var K,M;const z=R.current+$,H=E().filter(Z=>!Z.disabled),ge=document.activeElement,de=(K=H.find(Z=>Z.ref.current===ge))==null?void 0:K.textValue,ee=H.map(Z=>Z.textValue),je=k0(ee,z,de),Te=(M=H.find(Z=>Z.textValue===je))==null?void 0:M.ref.current;(function Z(ne){R.current=ne,window.clearTimeout(_.current),ne!==""&&(_.current=window.setTimeout(()=>Z(""),1e3))})(z),Te&&setTimeout(()=>Te.focus())};m.useEffect(()=>()=>window.clearTimeout(_.current),[]),Gi();const B=m.useCallback($=>{var H,ge;return V.current===((H=F.current)==null?void 0:H.side)&&I0($,(ge=F.current)==null?void 0:ge.area)},[]);return c.jsx(u0,{scope:n,searchRef:R,onItemEnter:m.useCallback($=>{B($)&&$.preventDefault()},[B]),onItemLeave:m.useCallback($=>{var z;B($)||((z=I.current)==null||z.focus(),k(null))},[B]),onTriggerLeave:m.useCallback($=>{B($)&&$.preventDefault()},[B]),pointerGraceTimerRef:L,onPointerGraceIntentChange:m.useCallback($=>{F.current=$},[]),children:c.jsx(Y,{...q,children:c.jsx(qo,{asChild:!0,trapped:o,onMountAutoFocus:ce(s,$=>{var z;$.preventDefault(),(z=I.current)==null||z.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(Vo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(Zy,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:k,onEntryFocus:ce(l,$=>{x.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(cf,{role:"menu","aria-orientation":"vertical","data-state":zf(g.open),"data-radix-menu-content":"",dir:x.dir,...y,...v,ref:A,style:{outline:"none",...v.style},onKeyDown:ce(v.onKeyDown,$=>{const H=$.target.closest("[data-radix-menu-content]")===$.currentTarget,ge=$.ctrlKey||$.altKey||$.metaKey,de=$.key.length===1;H&&($.key==="Tab"&&$.preventDefault(),!ge&&de&&X($.key));const ee=I.current;if($.target!==ee||!t0.includes($.key))return;$.preventDefault();const Te=E().filter(K=>!K.disabled).map(K=>K.ref.current);xf.includes($.key)&&Te.reverse(),C0(Te)}),onBlur:ce(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(_.current),R.current="")}),onPointerMove:ce(e.onPointerMove,ro($=>{const z=$.target,H=O.current!==$.clientX;if($.currentTarget.contains(z)&&H){const ge=$.clientX>O.current?"right":"left";V.current=ge,O.current=$.clientX}}))})})})})})})});Cf.displayName=$t;var p0="MenuGroup",Ia=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ie.div,{role:"group",...r,ref:t})});Ia.displayName=p0;var m0="MenuLabel",Tf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ie.div,{...r,ref:t})});Tf.displayName=m0;var Ss="MenuItem",kf="menu.itemSelect",Cs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=to(Ss,e.__scopeMenu),a=ka(Ss,e.__scopeMenu),l=$e(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(kf,{bubbles:!0,cancelable:!0});f.addEventListener(kf,p=>r==null?void 0:r(p),{once:!0}),su(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(Ef,{...o,ref:l,disabled:n,onClick:ce(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ce(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ce(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Sa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Cs.displayName=Ss;var Ef=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ka(Ss,n),a=wf(n),l=m.useRef(null),u=$e(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const w=l.current;w&&p((w.textContent??"").trim())},[s.children]),c.jsx(eo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(Qy,{asChild:!0,...a,focusable:!r,children:c.jsx(Ie.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ce(e.onPointerMove,ro(w=>{r?i.onItemLeave(w):(i.onItemEnter(w),w.defaultPrevented||w.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ce(e.onPointerLeave,ro(w=>i.onItemLeave(w))),onFocus:ce(e.onFocus,()=>f(!0)),onBlur:ce(e.onBlur,()=>f(!1))})})})}),g0="MenuCheckboxItem",If=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(Rf,{scope:e.__scopeMenu,checked:n,children:c.jsx(Cs,{role:"menuitemcheckbox","aria-checked":Ts(n)?"mixed":n,...o,ref:t,"data-state":Aa(n),onSelect:ce(o.onSelect,()=>r==null?void 0:r(Ts(n)?!0:!n),{checkForDefaultPrevented:!1})})})});If.displayName=g0;var Nf="MenuRadioGroup",[x0,v0]=Yn(Nf,{value:void 0,onValueChange:()=>{}}),Af=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=pt(r);return c.jsx(x0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(Ia,{...o,ref:t})})});Af.displayName=Nf;var jf="MenuRadioItem",_f=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=v0(jf,e.__scopeMenu),s=n===o.value;return c.jsx(Rf,{scope:e.__scopeMenu,checked:s,children:c.jsx(Cs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Aa(s),onSelect:ce(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});_f.displayName=jf;var Na="MenuItemIndicator",[Rf,w0]=Yn(Na,{checked:!1}),Pf=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=w0(Na,n);return c.jsx(Rt,{present:r||Ts(s.checked)||s.checked===!0,children:c.jsx(Ie.span,{...o,ref:t,"data-state":Aa(s.checked)})})});Pf.displayName=Na;var b0="MenuSeparator",Of=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ie.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Of.displayName=b0;var y0="MenuArrow",Mf=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ys(n);return c.jsx(uf,{...o,...r,ref:t})});Mf.displayName=y0;var S0="MenuSub",[oT,Df]=Yn(S0),no="MenuSubTrigger",Lf=m.forwardRef((e,t)=>{const n=Xn(no,e.__scopeMenu),r=to(no,e.__scopeMenu),o=Df(no,e.__scopeMenu),s=ka(no,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(Ca,{asChild:!0,...u,children:c.jsx(Ef,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":zf(n.open),...e,ref:Oi(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:ce(e.onPointerMove,ro(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ce(e.onPointerLeave,ro(f=>{var p,w;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const v=(w=n.content)==null?void 0:w.dataset.side,g=v==="right",x=g?-5:5,y=h[g?"left":"right"],C=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:y,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:y,y:h.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ce(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||n0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Lf.displayName=no;var Ff="MenuSubContent",$f=m.forwardRef((e,t)=>{const n=yf($t,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn($t,e.__scopeMenu),i=to($t,e.__scopeMenu),a=Df(Ff,e.__scopeMenu),l=m.useRef(null),u=$e(t,l);return c.jsx(eo.Provider,{scope:e.__scopeMenu,children:c.jsx(Rt,{present:r||s.open,children:c.jsx(eo.Slot,{scope:e.__scopeMenu,children:c.jsx(Ea,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ce(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ce(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ce(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=r0[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});$f.displayName=Ff;function zf(e){return e?"open":"closed"}function Ts(e){return e==="indeterminate"}function Aa(e){return Ts(e)?"indeterminate":e?"checked":"unchecked"}function C0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function T0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function k0(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=T0(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function E0(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],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function I0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return E0(n,t)}function ro(e){return t=>t.pointerType==="mouse"?e(t):void 0}var N0=bf,A0=Ca,j0=Sf,_0=Cf,R0=Ia,P0=Tf,O0=Cs,M0=If,D0=Af,L0=_f,F0=Pf,$0=Of,z0=Mf,B0=Lf,H0=$f,ks="DropdownMenu",[U0,sT]=en(ks,[vf]),Ct=vf(),[W0,Bf]=U0(ks),Hf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ct(t),u=m.useRef(null),[d,f]=Un({prop:o,defaultProp:s??!1,onChange:i,caller:ks});return c.jsx(W0,{scope:t,triggerId:tn(),triggerRef:u,contentId:tn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(N0,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Hf.displayName=ks;var Uf="DropdownMenuTrigger",Wf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Bf(Uf,n),i=Ct(n);return c.jsx(A0,{asChild:!0,...i,children:c.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:Oi(t,s.triggerRef),onPointerDown:ce(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ce(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Wf.displayName=Uf;var V0="DropdownMenuPortal",Vf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ct(t);return c.jsx(j0,{...r,...n})};Vf.displayName=V0;var qf="DropdownMenuContent",Kf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bf(qf,n),s=Ct(n),i=m.useRef(!1);return c.jsx(_0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ce(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ce(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Kf.displayName=qf;var q0="DropdownMenuGroup",K0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(R0,{...o,...r,ref:t})});K0.displayName=q0;var G0="DropdownMenuLabel",Gf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(P0,{...o,...r,ref:t})});Gf.displayName=G0;var Y0="DropdownMenuItem",Yf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(O0,{...o,...r,ref:t})});Yf.displayName=Y0;var X0="DropdownMenuCheckboxItem",Xf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(M0,{...o,...r,ref:t})});Xf.displayName=X0;var J0="DropdownMenuRadioGroup",Z0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(D0,{...o,...r,ref:t})});Z0.displayName=J0;var Q0="DropdownMenuRadioItem",Jf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(L0,{...o,...r,ref:t})});Jf.displayName=Q0;var eS="DropdownMenuItemIndicator",Zf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(F0,{...o,...r,ref:t})});Zf.displayName=eS;var tS="DropdownMenuSeparator",Qf=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx($0,{...o,...r,ref:t})});Qf.displayName=tS;var nS="DropdownMenuArrow",rS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(z0,{...o,...r,ref:t})});rS.displayName=nS;var oS="DropdownMenuSubTrigger",eh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(B0,{...o,...r,ref:t})});eh.displayName=oS;var sS="DropdownMenuSubContent",th=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return c.jsx(H0,{...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)"}})});th.displayName=sS;var iS=Hf,aS=Wf,lS=Vf,nh=Kf,rh=Gf,oh=Yf,sh=Xf,ih=Jf,ah=Zf,lh=Qf,ch=eh,uh=th;const cS=iS,uS=aS,dS=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(ch,{ref:o,className:te("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,c.jsx(re.ChevronRight,{className:"ml-auto h-4 w-4"})]}));dS.displayName=ch.displayName;const fS=m.forwardRef(({className:e,...t},n)=>c.jsx(uh,{ref:n,className:te("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}));fS.displayName=uh.displayName;const dh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(lS,{children:c.jsx(nh,{ref:r,sideOffset:t,className:te("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})}));dh.displayName=nh.displayName;const ja=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(oh,{ref:r,className:te("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}));ja.displayName=oh.displayName;const hS=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(sh,{ref:o,className:te("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(ah,{children:c.jsx(re.Check,{className:"h-4 w-4"})})}),t]}));hS.displayName=sh.displayName;const pS=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(ih,{ref:r,className:te("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(ah,{children:c.jsx(re.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));pS.displayName=ih.displayName;const mS=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(rh,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));mS.displayName=rh.displayName;const gS=m.forwardRef(({className:e,...t},n)=>c.jsx(lh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));gS.displayName=lh.displayName;function Es({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:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:w}=Qs(),{currentThreadId:v,isLoadingThread:g,listCheckpoints:x,navigateToCheckpoint:y,returnToLatest:C}=yo(),{messages:E,hasMoreHistory:T,isLoadingHistory:k,send:I,stop:A,loadOlderMessages:_}=ci(),{isStreaming:R,error:L,streamingAssistantId:F,lastCheckpointId:V,lastCheckpointNs:O}=oc(),[Y,q]=S.useState(null),[X,B]=S.useState(""),[$,z]=S.useState(null),[H,ge]=S.useState([]),[de,ee]=S.useState(0),[je,Te]=S.useState(0),[K,M]=S.useState(!1),[Z,ne]=S.useState(null),[Q,le]=S.useState(null),[Be,Ye]=S.useState(!1),[Ke,Ce]=S.useState(null),[_e,Qe]=S.useState([]),[Ue,ot]=S.useState(null),[lt,ie]=S.useState(null),[ue,we]=S.useState(!1),pe=S.useRef(null),xe=S.useRef(null),Re=S.useRef(null),Me=S.useCallback(()=>{pe.current&&(pe.current.value=""),xe.current&&(xe.current.value=""),ee(oe=>oe+1),Te(oe=>oe+1)},[]),Pe=S.useRef(!1);S.useEffect(()=>{Pe.current&&!R&&(ge([]),Me()),Pe.current=R},[R,Me]);const[st,mt]=S.useState("desktop");S.useEffect(()=>{const oe=()=>{const be=window.innerWidth;mt(be<640?"phone":be<1024?"tablet":"desktop")};return oe(),window.addEventListener("resize",oe),()=>window.removeEventListener("resize",oe)},[]),S.useEffect(()=>{let oe=!1;if(!v){Qe([]),ot(null),ie(null),Re.current=null;return}const be={threadId:v,checkpointId:V??null,checkpointNs:O??null},Fe=Re.current;if(!(Fe&&Fe.threadId===be.threadId&&Fe.checkpointId===be.checkpointId&&Fe.checkpointNs===be.checkpointNs))return x(v).then(et=>{var kr;if(oe)return;const bt=((et==null?void 0:et.checkpoints)??[]).slice().sort((N,b)=>new Date(b.createdAt).getTime()-new Date(N.createdAt).getTime());Qe(bt);const Mt=Ue,nr=Mt&&bt.some(N=>N.checkpointId===Mt)?Mt:((kr=bt[0])==null?void 0:kr.checkpointId)??null;let Tr=null;if(nr){const N=bt.find(b=>b.checkpointId===nr);Tr=(N==null?void 0:N.checkpointNs)??null}ot(nr),ie(Tr),Re.current=be}).catch(et=>{console.error("ChatInterface - listCheckpoints error:",et),oe||(Qe([]),Re.current=null)}),()=>{oe=!0}},[v,V,O,Ue,x]),S.useEffect(()=>{V&&(ot(V),ie(O??null))},[V,O]);const cn=S.useCallback(async()=>{if(!(!T||k))try{await _()}catch(oe){console.warn("loadOlderMessages failed",oe)}},[T,k,_]);S.useEffect(()=>{(async()=>{if(!w.baseUrl){Ce(null);return}try{const be=await w.getAgent("default");Ce(be.uiDefaultMessage||null)}catch(be){console.warn("Failed to fetch default message:",be),Ce(null)}})()},[w]),S.useEffect(()=>{L&&!Be&&(p==null||p(L))},[L,Be,p]);const un=oe=>{if(oe.length>ls)return`Message too long (${oe.length}/${ls} characters)`;try{return Sb(oe),null}catch(be){return(be==null?void 0:be.message)||"Invalid message"}},dn=async oe=>{const be=oe.trim();if(!(!be&&H.length===0)){if(be){const Fe=un(be);if(Fe){z(Fe);return}}try{await I(be||"",{checkpointId:Ue??V??void 0,checkpointNs:lt??O??void 0,payloadExtras:Y?{edit:!0,originalMessageId:Y}:void 0,attachments:H}),f==null||f(be),z(null),ge([]),Me(),q(null),B("")}catch(Fe){const et=(Fe==null?void 0:Fe.message)||"Failed to send message";z(et),p==null||p(et)}}},Rn=S.useCallback((oe,be)=>{u&&(q(oe),B(be),z(null))},[u]),er=S.useCallback(()=>{q(null),B(""),z(null)},[]),yr=S.useCallback((oe,be)=>{Rn(oe,be)},[Rn]),Pn=S.useCallback(oe=>{const be=Fe=>{const et=Fe.content||[],bt=et.filter(Mt=>Mt.type==="text").map(Mt=>Mt.text).join("");if(bt)return bt;try{return JSON.stringify(et,null,2)}catch{return String(et)}};for(let Fe=oe-1;Fe>=0;Fe--)if(E[Fe].role==="user"){const et=be(E[Fe]);et&&I(et,{checkpointId:Ue??V??void 0,checkpointNs:lt??O??void 0});break}},[E,I,Ue,lt,V,O]),xn=oe=>{const be=Array.from(oe.target.files||[]);ge(Fe=>[...Fe,...be]),oe.target.value=""},Yt=oe=>{ge(be=>{const Fe=be.filter((et,bt)=>oe!==bt);return Fe.length===0&&Me(),Fe})},vn=async oe=>{const be=(oe.target.files||[])[0];if(be){ne(null),le(null),M(!0);try{await I("",{checkpointId:Ue??V??void 0,checkpointNs:lt??O??void 0,attachments:[be]});const Fe=`Uploaded ${be.name} - processing through chat stream`;le(Fe)}catch(Fe){const et=Fe instanceof Error?Fe.message:"Failed to upload Excel file";console.error("Excel upload failed",Fe),ne(et),p==null||p(et)}finally{M(!1),oe.target.value="",Me()}}},On=oe=>{if(!oe)return"Unknown";const be=Date.parse(oe);return Number.isNaN(be)?oe:new Date(be).toLocaleString()},tr=async oe=>{if(v){we(!0);try{if(!oe){await C(),ot(null),ie(null);return}const be=_e.find(et=>et.checkpointId===oe),Fe=(be==null?void 0:be.checkpointNs)??null;await y(oe,Fe),ot(oe),ie(Fe)}finally{we(!1)}}},Sr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,It=`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 ${d.messagesArea||""}`,Cr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Sr,children:[!!L&&!Be&&c.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:[c.jsx("span",{children:L}),c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Ye(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(re.X,{size:16})})]}),v&&_e.length>0&&c.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:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.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:Ue??"",onChange:oe=>{const be=oe.target.value||null;tr(be)},children:[c.jsx("option",{value:"",children:"Latest"}),_e.map(oe=>c.jsxs("option",{value:oe.checkpointId,children:[On(oe.createdAt),oe.preview?` — ${oe.preview.slice(0,40)}`:""]},oe.checkpointId))]})]}),c.jsxs("div",{className:`relative ${It}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(sa,{className:"h-full",style:{height:"100%"},messages:E,isStreaming:R,streamingAssistantId:F,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:st,enableMessageEditing:u,editingMessageId:Y,onStartReached:()=>{cn()},onEdit:yr,onRegenerate:Pn,onCancelEdit:er,emptyMessage:Ke??void 0,isNavigatingCheckpoint:ue}),g&&c.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:[c.jsx(re.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:Cr,children:[Y&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(re.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(We,{variant:"ghost",size:"sm",onClick:er,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(re.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:pe,type:"file",multiple:!0,onChange:oe=>xn(oe),className:"hidden"},de),H.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:H.map((oe,be)=>c.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:[c.jsx(re.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:oe.name}),c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Yt(be),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 ${oe.name}`,children:c.jsx(re.X,{size:12})})]},be))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:xe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vn,className:"hidden"},je),K&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(re.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Q&&!K&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Q}),Z&&!K&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Z})]})]}),$&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:$}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(cS,{children:[c.jsx(uS,{asChild:!0,children:c.jsx(We,{type:"button",size:"icon",variant:"outline",disabled:R,title:"More input actions",className:d.moreButton||"",children:c.jsx(re.Plus,{size:16})})}),c.jsxs(dh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(ja,{onClick:()=>{var oe;return(oe=pe.current)==null?void 0:oe.click()},className:"cursor-pointer",children:[c.jsx(re.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(ja,{onClick:()=>{var oe;K||(oe=xe.current)==null||oe.click()},className:`cursor-pointer ${K?"opacity-60 pointer-events-none":""}`,children:[c.jsx(re.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Mg,{initialValue:X,editingMessageId:Y,placeholder:Y?"Edit your message...":t,isStreaming:R,disabled:!1,maxLength:ls,onSend:dn,onCancelEdit:er,onStop:A,allowEmptySend:H.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${Y?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${$?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const Is=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:te("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}));Is.displayName="Input";function _a(e,[t,n]){return Math.min(n,Math.max(t,e))}function xS(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Ra="ScrollArea",[fh,iT]=en(Ra),[vS,zt]=fh(Ra),hh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,w]=m.useState(null),[v,g]=m.useState(null),[x,y]=m.useState(0),[C,E]=m.useState(0),[T,k]=m.useState(!1),[I,A]=m.useState(!1),_=$e(t,L=>l(L)),R=cs(o);return c.jsx(vS,{scope:n,type:r,dir:R,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:w,scrollbarXEnabled:T,onScrollbarXEnabledChange:k,scrollbarY:v,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:y,onCornerHeightChange:E,children:c.jsx(Ie.div,{dir:R,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});hh.displayName=Ra;var ph="ScrollAreaViewport",mh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=zt(ph,n),a=m.useRef(null),l=$e(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.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}),c.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:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});mh.displayName=ph;var ln="ScrollAreaScrollbar",Pa=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zt(ln,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(wS,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(bS,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(gh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(Oa,{...r,ref:t}):null});Pa.displayName=ln;var wS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zt(ln,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Rt,{present:n||s,children:c.jsx(gh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),bS=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=zt(ln,e.__scopeScrollArea),s=e.orientation==="horizontal",i=_s(()=>l("SCROLL_END"),100),[a,l]=xS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Rt,{present:n||a!=="hidden",children:c.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ce(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ce(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),gh=m.forwardRef((e,t)=>{const n=zt(ln,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=_s(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return vr(n.viewport,l),vr(n.content,l),c.jsx(Rt,{present:r||s,children:c.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=zt(ln,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=yh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return ES(h,i.current,a,p)}return n==="horizontal"?c.jsx(yS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Sh(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"?c.jsx(SS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Sh(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}),yS=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=zt(ln,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=$e(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(vh,{"data-orientation":"horizontal",...o,ref:u,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":js(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:As(i.paddingLeft),paddingEnd:As(i.paddingRight)}})}})}),SS=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=zt(ln,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=$e(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(vh,{"data-orientation":"vertical",...o,ref:u,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":js(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:As(i.paddingTop),paddingEnd:As(i.paddingBottom)}})}})}),[CS,xh]=fh(ln),vh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=zt(ln,n),[w,v]=m.useState(null),g=$e(t,_=>v(_)),x=m.useRef(null),y=m.useRef(""),C=p.viewport,E=r.content-r.viewport,T=pt(d),k=pt(l),I=_s(f,10);function A(_){if(x.current){const R=_.clientX-x.current.left,L=_.clientY-x.current.top;u({x:R,y:L})}}return m.useEffect(()=>{const _=R=>{const L=R.target;(w==null?void 0:w.contains(L))&&T(R,E)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[C,w,E,T]),m.useEffect(k,[r,k]),vr(w,I),vr(p.content,I),c.jsx(CS,{scope:n,scrollbar:w,hasThumb:o,onThumbChange:pt(s),onThumbPointerUp:pt(i),onThumbPositionChange:k,onThumbPointerDown:pt(a),children:c.jsx(Ie.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ce(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=w.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(_))}),onPointerMove:ce(e.onPointerMove,A),onPointerUp:ce(e.onPointerUp,_=>{const R=_.target;R.hasPointerCapture(_.pointerId)&&R.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=y.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),Ns="ScrollAreaThumb",wh=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=xh(Ns,e.__scopeScrollArea);return c.jsx(Rt,{present:n||o.hasThumb,children:c.jsx(TS,{ref:t,...r})})}),TS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=zt(Ns,n),i=xh(Ns,n),{onThumbPositionChange:a}=i,l=$e(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=_s(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=IS(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.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:ce(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),w=f.clientX-p.left,v=f.clientY-p.top;i.onThumbPointerDown({x:w,y:v})}),onPointerUp:ce(e.onPointerUp,i.onThumbPointerUp)})});wh.displayName=Ns;var Ma="ScrollAreaCorner",bh=m.forwardRef((e,t)=>{const n=zt(Ma,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(kS,{...e,ref:t}):null});bh.displayName=Ma;var kS=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=zt(Ma,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return vr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),vr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.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 As(e){return e?parseInt(e,10):0}function yh(e,t){const n=e/t;return isNaN(n)?0:n}function js(e){const t=yh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function ES(e,t,n,r="ltr"){const o=js(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ch([l,u],f)(e)}function Sh(e,t,n="ltr"){const r=js(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],u=_a(e,l);return Ch([0,i],[0,a])(u)}function Ch(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 Th(e,t){return e>0&&e<t}var IS=(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 _s(e,t){const n=pt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function vr(e,t){const n=pt(t);ft(()=>{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 kh=hh,NS=mh,AS=bh;const Eh=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(kh,{ref:r,className:te("relative overflow-hidden",e),...n,children:[c.jsx(NS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(Ih,{}),c.jsx(AS,{})]}));Eh.displayName=kh.displayName;const Ih=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Pa,{ref:r,orientation:t,className:te("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:c.jsx(wh,{className:"relative flex-1 rounded-full bg-border"})}));Ih.displayName=Pa.displayName;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{loadThread:f,threads:h,currentThreadId:p,createThread:w,deleteThread:v,renameThread:g,isLoadingThreads:x}=yo(),[y,C]=S.useState(Array.isArray(h)?h:[]),E=S.useRef(y.length>0),[T,k]=S.useState(null),[I,A]=S.useState(""),[_,R]=S.useState(!1);S.useEffect(()=>{const z=Array.isArray(h)?h:[];if(z.length>0){E.current=!0,C(z);return}x||(E.current=!1,C(z))},[h,x]);const L=async z=>{try{await f(z),a==null||a(z),l==null||l(z)}catch(H){console.error("Failed to select thread:",H)}},F=async()=>{try{R(!0);const z=await w();u==null||u(z),a==null||a(z)}catch(z){console.error("Failed to create thread:",z)}finally{R(!1)}},V=async(z,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?"))try{await v(z),d==null||d(z)}catch(ge){console.error("Failed to delete thread:",ge)}},O=(z,H)=>{H.stopPropagation(),k(z.threadId),A(z.title||`Thread ${z.threadId.slice(0,8)}`)},Y=async z=>{if(I.trim())try{await g(z,I.trim()),k(null),A("")}catch(H){console.error("Failed to update title:",H)}},q=()=>{k(null),A("")},X=(z,H)=>{z.key==="Enter"?Y(H):z.key==="Escape"&&q()},B=z=>{if(!z)return"";try{const H=new Date(z),de=new Date().getTime()-H.getTime(),ee=Math.floor(de/(1e3*60*60*24));return ee===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ee===1?"Yesterday":ee<7?`${ee} days ago`:H.toLocaleDateString()}catch{return""}},$=z=>z.title||`Thread ${z.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.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:c.jsx(We,{onClick:F,disabled:_||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:_?"Creating...":"New Chat",children:c.jsx(re.MessageSquarePlus,{size:20})})}),c.jsx(Eh,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(re.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):y.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(re.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):y.slice().sort((z,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(z.updatedAt||z.createdAt||"").getTime()).map(z=>c.jsxs("div",{onClick:()=>L(z.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===z.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:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:T===z.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[c.jsx(Is,{value:I,onChange:H=>A(H.target.value),onKeyDown:H=>X(H,z.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(We,{variant:"ghost",size:"sm",onClick:()=>Y(z.threadId),className:"h-6 w-6 p-0",children:c.jsx(re.Check,{size:12})}),c.jsx(We,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:c.jsx(re.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:$(z)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(re.Calendar,{size:10}),c.jsx("span",{children:B(z.updatedAt||z.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&T!==z.threadId&&c.jsx(We,{variant:"ghost",size:"sm",onClick:H=>O(z,H),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(re.Edit3,{size:12})}),n&&c.jsx(We,{variant:"ghost",size:"sm",onClick:H=>V(z.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(re.Trash2,{size:12})})]})]}),i===z.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},z.threadId))})})]})}function wr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function jS(e){if(typeof e!="string")return;const t=e.trim();if(t)return hn(t)}function Nh(){const e=[wr("__API_BASE_URL__"),wr("__CHAT_API_BASE_URL__"),wr("__CHAT_API_URL__")];for(const t of e){const n=jS(t);if(n)return n}}function Ah(){const e=[wr("__API_AUTH_TOKEN__"),wr("__CHAT_API_KEY__"),wr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function jh(...e){for(const t of e)if(typeof t=="string"&&t.trim())return hn(t);return hn()}function _h(){const e={},t=Nh(),n=Ah();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Rh(){const e=_h(),t=wn.getAuthToken(),n=Nh();return{apiBaseUrl:jh(e.baseUrl,wn.baseUrl,n),apiKey:t||e.apiKey||Ah()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Ph="chat-settings";function _S(){try{const e=localStorage.getItem(Ph);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function RS(e){try{const t={...e,apiBaseUrl:hn(e.apiBaseUrl)};localStorage.setItem(Ph,JSON.stringify(t)),t.apiKey&&wn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function PS(){const e=Rh(),t=_S(),n=wn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:jh(wn.baseUrl,r,e.apiBaseUrl)}}function OS(e){wn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),RS(e)}var MS="Label",Oh=m.forwardRef((e,t)=>c.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())}}));Oh.displayName=MS;var Mh=Oh;const DS=io.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Bt=m.forwardRef(({className:e,...t},n)=>c.jsx(Mh,{ref:n,className:te(DS(),e),...t}));Bt.displayName=Mh.displayName;function Dh(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Rs="Switch",[LS,aT]=en(Rs),[FS,$S]=LS(Rs),Lh=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),w=$e(t,C=>p(C)),v=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[x,y]=Un({prop:o,defaultProp:s??!1,onChange:u,caller:Rs});return c.jsxs(FS,{scope:n,checked:x,disabled:a,children:[c.jsx(Ie.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Bh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:w,onClick:ce(e.onClick,C=>{y(E=>!E),g&&(v.current=C.isPropagationStopped(),v.current||C.stopPropagation())})}),g&&c.jsx(zh,{control:h,bubbles:!v.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Lh.displayName=Rs;var Fh="SwitchThumb",$h=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=$S(Fh,n);return c.jsx(Ie.span,{"data-state":Bh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$h.displayName=Fh;var zS="SwitchBubbleInput",zh=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=$e(i,s),l=Dh(n),u=Xd(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const w=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(w)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});zh.displayName=zS;function Bh(e){return e?"checked":"unchecked"}var Hh=Lh,BS=$h;const An=m.forwardRef(({className:e,...t},n)=>c.jsx(Hh,{className:te("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:c.jsx(BS,{className:te("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")})}));An.displayName=Hh.displayName;var Uh=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"}),HS="VisuallyHidden",US=m.forwardRef((e,t)=>c.jsx(Ie.span,{...e,ref:t,style:{...Uh,...e.style}}));US.displayName=HS;var WS=[" ","Enter","ArrowUp","ArrowDown"],VS=[" ","Enter"],Jn="Select",[Ps,Os,qS]=ia(Jn),[br,lT]=en(Jn,[qS,bs]),Ms=bs(),[KS,jn]=br(Jn),[GS,YS]=br(Jn),Wh=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:w}=e,v=Ms(t),[g,x]=m.useState(null),[y,C]=m.useState(null),[E,T]=m.useState(!1),k=cs(u),[I,A]=Un({prop:r,defaultProp:o??!1,onChange:s,caller:Jn}),[_,R]=Un({prop:i,defaultProp:a,onChange:l,caller:Jn}),L=m.useRef(null),F=g?w||!!g.closest("form"):!0,[V,O]=m.useState(new Set),Y=Array.from(V).map(q=>q.props.value).join(";");return c.jsx(af,{...v,children:c.jsxs(KS,{required:p,scope:t,trigger:g,onTriggerChange:x,valueNode:y,onValueNodeChange:C,valueNodeHasChildren:E,onValueNodeHasChildrenChange:T,contentId:tn(),value:_,onValueChange:R,open:I,onOpenChange:A,dir:k,triggerPointerDownPosRef:L,disabled:h,children:[c.jsx(Ps.Provider,{scope:t,children:c.jsx(GS,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(q=>{O(X=>new Set(X).add(q))},[]),onNativeOptionRemove:m.useCallback(q=>{O(X=>{const B=new Set(X);return B.delete(q),B})},[]),children:n})}),F?c.jsxs(pp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:q=>R(q.target.value),disabled:h,form:w,children:[_===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},Y):null]})})};Wh.displayName=Jn;var Vh="SelectTrigger",qh=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ms(n),i=jn(Vh,n),a=i.disabled||r,l=$e(t,i.onTriggerChange),u=Os(n),d=m.useRef("touch"),[f,h,p]=gp(v=>{const g=u().filter(C=>!C.disabled),x=g.find(C=>C.value===i.value),y=xp(g,v,x);y!==void 0&&i.onValueChange(y.value)}),w=v=>{a||(i.onOpenChange(!0),p()),v&&(i.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return c.jsx(lf,{asChild:!0,...s,children:c.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":mp(i.value)?"":void 0,...o,ref:l,onClick:ce(o.onClick,v=>{v.currentTarget.focus(),d.current!=="mouse"&&w(v)}),onPointerDown:ce(o.onPointerDown,v=>{d.current=v.pointerType;const g=v.target;g.hasPointerCapture(v.pointerId)&&g.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(w(v),v.preventDefault())}),onKeyDown:ce(o.onKeyDown,v=>{const g=f.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&h(v.key),!(g&&v.key===" ")&&WS.includes(v.key)&&(w(),v.preventDefault())})})})});qh.displayName=Vh;var Kh="SelectValue",Gh=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=jn(Kh,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=$e(t,l.onValueNodeChange);return ft(()=>{u(d)},[u,d]),c.jsx(Ie.span,{...a,ref:f,style:{pointerEvents:"none"},children:mp(l.value)?c.jsx(c.Fragment,{children:i}):s})});Gh.displayName=Kh;var XS="SelectIcon",Yh=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Ie.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Yh.displayName=XS;var JS="SelectPortal",Xh=e=>c.jsx(Ko,{asChild:!0,...e});Xh.displayName=JS;var Zn="SelectContent",Jh=m.forwardRef((e,t)=>{const n=jn(Zn,e.__scopeSelect),[r,o]=m.useState();if(ft(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ao.createPortal(c.jsx(Zh,{scope:e.__scopeSelect,children:c.jsx(Ps.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Qh,{...e,ref:t})});Jh.displayName=Zn;var Gt=10,[Zh,_n]=br(Zn),ZS="SelectContentImpl",QS=Mn.createSlot("SelectContent.RemoveScroll"),Qh=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g,...x}=e,y=jn(Zn,n),[C,E]=m.useState(null),[T,k]=m.useState(null),I=$e(t,K=>E(K)),[A,_]=m.useState(null),[R,L]=m.useState(null),F=Os(n),[V,O]=m.useState(!1),Y=m.useRef(!1);m.useEffect(()=>{if(C)return ea(C)},[C]),Gi();const q=m.useCallback(K=>{const[M,...Z]=F().map(le=>le.ref.current),[ne]=Z.slice(-1),Q=document.activeElement;for(const le of K)if(le===Q||(le==null||le.scrollIntoView({block:"nearest"}),le===M&&T&&(T.scrollTop=0),le===ne&&T&&(T.scrollTop=T.scrollHeight),le==null||le.focus(),document.activeElement!==Q))return},[F,T]),X=m.useCallback(()=>q([A,C]),[q,A,C]);m.useEffect(()=>{V&&X()},[V,X]);const{onOpenChange:B,triggerPointerDownPosRef:$}=y;m.useEffect(()=>{if(C){let K={x:0,y:0};const M=ne=>{var Q,le;K={x:Math.abs(Math.round(ne.pageX)-(((Q=$.current)==null?void 0:Q.x)??0)),y:Math.abs(Math.round(ne.pageY)-(((le=$.current)==null?void 0:le.y)??0))}},Z=ne=>{K.x<=10&&K.y<=10?ne.preventDefault():C.contains(ne.target)||B(!1),document.removeEventListener("pointermove",M),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",M),document.addEventListener("pointerup",Z,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",Z,{capture:!0})}}},[C,B,$]),m.useEffect(()=>{const K=()=>B(!1);return window.addEventListener("blur",K),window.addEventListener("resize",K),()=>{window.removeEventListener("blur",K),window.removeEventListener("resize",K)}},[B]);const[z,H]=gp(K=>{const M=F().filter(Q=>!Q.disabled),Z=M.find(Q=>Q.ref.current===document.activeElement),ne=xp(M,K,Z);ne&&setTimeout(()=>ne.ref.current.focus())}),ge=m.useCallback((K,M,Z)=>{const ne=!Y.current&&!Z;(y.value!==void 0&&y.value===M||ne)&&(_(K),ne&&(Y.current=!0))},[y.value]),de=m.useCallback(()=>C==null?void 0:C.focus(),[C]),ee=m.useCallback((K,M,Z)=>{const ne=!Y.current&&!Z;(y.value!==void 0&&y.value===M||ne)&&L(K)},[y.value]),je=r==="popper"?La:ep,Te=je===La?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:w,hideWhenDetached:v,avoidCollisions:g}:{};return c.jsx(Zh,{scope:n,content:C,viewport:T,onViewportChange:k,itemRefCallback:ge,selectedItem:A,onItemLeave:de,itemTextRefCallback:ee,focusSelectedItem:X,selectedItemText:R,position:r,isPositioned:V,searchRef:z,children:c.jsx(Qo,{as:QS,allowPinchZoom:!0,children:c.jsx(qo,{asChild:!0,trapped:y.open,onMountAutoFocus:K=>{K.preventDefault()},onUnmountAutoFocus:ce(o,K=>{var M;(M=y.trigger)==null||M.focus({preventScroll:!0}),K.preventDefault()}),children:c.jsx(Vo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:K=>K.preventDefault(),onDismiss:()=>y.onOpenChange(!1),children:c.jsx(je,{role:"listbox",id:y.contentId,"data-state":y.open?"open":"closed",dir:y.dir,onContextMenu:K=>K.preventDefault(),...x,...Te,onPlaced:()=>O(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:ce(x.onKeyDown,K=>{const M=K.ctrlKey||K.altKey||K.metaKey;if(K.key==="Tab"&&K.preventDefault(),!M&&K.key.length===1&&H(K.key),["ArrowUp","ArrowDown","Home","End"].includes(K.key)){let ne=F().filter(Q=>!Q.disabled).map(Q=>Q.ref.current);if(["ArrowUp","End"].includes(K.key)&&(ne=ne.slice().reverse()),["ArrowUp","ArrowDown"].includes(K.key)){const Q=K.target,le=ne.indexOf(Q);ne=ne.slice(le+1)}setTimeout(()=>q(ne)),K.preventDefault()}})})})})})})});Qh.displayName=ZS;var eC="SelectItemAlignedPosition",ep=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=jn(Zn,n),i=_n(Zn,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=$e(t,I=>d(I)),h=Os(n),p=m.useRef(!1),w=m.useRef(!0),{viewport:v,selectedItem:g,selectedItemText:x,focusSelectedItem:y}=i,C=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&v&&g&&x){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),R=x.getBoundingClientRect();if(s.dir!=="rtl"){const Q=R.left-A.left,le=_.left-Q,Be=I.left-le,Ye=I.width+Be,Ke=Math.max(Ye,A.width),Ce=window.innerWidth-Gt,_e=_a(le,[Gt,Math.max(Gt,Ce-Ke)]);a.style.minWidth=Ye+"px",a.style.left=_e+"px"}else{const Q=A.right-R.right,le=window.innerWidth-_.right-Q,Be=window.innerWidth-I.right-le,Ye=I.width+Be,Ke=Math.max(Ye,A.width),Ce=window.innerWidth-Gt,_e=_a(le,[Gt,Math.max(Gt,Ce-Ke)]);a.style.minWidth=Ye+"px",a.style.right=_e+"px"}const L=h(),F=window.innerHeight-Gt*2,V=v.scrollHeight,O=window.getComputedStyle(u),Y=parseInt(O.borderTopWidth,10),q=parseInt(O.paddingTop,10),X=parseInt(O.borderBottomWidth,10),B=parseInt(O.paddingBottom,10),$=Y+q+V+B+X,z=Math.min(g.offsetHeight*5,$),H=window.getComputedStyle(v),ge=parseInt(H.paddingTop,10),de=parseInt(H.paddingBottom,10),ee=I.top+I.height/2-Gt,je=F-ee,Te=g.offsetHeight/2,K=g.offsetTop+Te,M=Y+q+K,Z=$-M;if(M<=ee){const Q=L.length>0&&g===L[L.length-1].ref.current;a.style.bottom="0px";const le=u.clientHeight-v.offsetTop-v.offsetHeight,Be=Math.max(je,Te+(Q?de:0)+le+X),Ye=M+Be;a.style.height=Ye+"px"}else{const Q=L.length>0&&g===L[0].ref.current;a.style.top="0px";const Be=Math.max(ee,Y+v.offsetTop+(Q?ge:0)+Te)+Z;a.style.height=Be+"px",v.scrollTop=M-ee+v.offsetTop}a.style.margin=`${Gt}px 0`,a.style.minHeight=z+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,v,g,x,s.dir,r]);ft(()=>C(),[C]);const[E,T]=m.useState();ft(()=>{u&&T(window.getComputedStyle(u).zIndex)},[u]);const k=m.useCallback(I=>{I&&w.current===!0&&(C(),y==null||y(),w.current=!1)},[C,y]);return c.jsx(nC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:k,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:c.jsx(Ie.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ep.displayName=eC;var tC="SelectPopperPosition",La=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Gt,...s}=e,i=Ms(n);return c.jsx(cf,{...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)"}})});La.displayName=tC;var[nC,Fa]=br(Zn,{}),$a="SelectViewport",tp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=_n($a,n),i=Fa($a,n),a=$e(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Ps.Slot,{scope:n,children:c.jsx(Ie.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ce(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const w=window.innerHeight-Gt*2,v=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),x=Math.max(v,g);if(x<w){const y=x+p,C=Math.min(w,y),E=y-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=E>0?E:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});tp.displayName=$a;var np="SelectGroup",[rC,oC]=br(np),sC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=tn();return c.jsx(rC,{scope:n,id:o,children:c.jsx(Ie.div,{role:"group","aria-labelledby":o,...r,ref:t})})});sC.displayName=np;var rp="SelectLabel",op=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=oC(rp,n);return c.jsx(Ie.div,{id:o.id,...r,ref:t})});op.displayName=rp;var Ds="SelectItem",[iC,sp]=br(Ds),ip=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=jn(Ds,n),l=_n(Ds,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),w=$e(t,y=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,y,r,o)}),v=tn(),g=m.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(iC,{scope:n,value:r,disabled:o,textId:v,isSelected:u,onItemTextChange:m.useCallback(y=>{f(C=>C||((y==null?void 0:y.textContent)??"").trim())},[]),children:c.jsx(Ps.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Ie.div,{role:"option","aria-labelledby":v,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:w,onFocus:ce(i.onFocus,()=>p(!0)),onBlur:ce(i.onBlur,()=>p(!1)),onClick:ce(i.onClick,()=>{g.current!=="mouse"&&x()}),onPointerUp:ce(i.onPointerUp,()=>{g.current==="mouse"&&x()}),onPointerDown:ce(i.onPointerDown,y=>{g.current=y.pointerType}),onPointerMove:ce(i.onPointerMove,y=>{var C;g.current=y.pointerType,o?(C=l.onItemLeave)==null||C.call(l):g.current==="mouse"&&y.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ce(i.onPointerLeave,y=>{var C;y.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:ce(i.onKeyDown,y=>{var E;((E=l.searchRef)==null?void 0:E.current)!==""&&y.key===" "||(VS.includes(y.key)&&x(),y.key===" "&&y.preventDefault())})})})})});ip.displayName=Ds;var oo="SelectItemText",ap=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=jn(oo,n),a=_n(oo,n),l=sp(oo,n),u=YS(oo,n),[d,f]=m.useState(null),h=$e(t,x=>f(x),l.onItemTextChange,x=>{var y;return(y=a.itemTextRefCallback)==null?void 0:y.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,w=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:v,onNativeOptionRemove:g}=u;return ft(()=>(v(w),()=>g(w)),[v,g,w]),c.jsxs(c.Fragment,{children:[c.jsx(Ie.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ao.createPortal(s.children,i.valueNode):null]})});ap.displayName=oo;var lp="SelectItemIndicator",cp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return sp(lp,n).isSelected?c.jsx(Ie.span,{"aria-hidden":!0,...r,ref:t}):null});cp.displayName=lp;var za="SelectScrollUpButton",up=m.forwardRef((e,t)=>{const n=_n(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=m.useState(!1),i=$e(t,r.onScrollButtonChange);return ft(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(fp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});up.displayName=za;var Ba="SelectScrollDownButton",dp=m.forwardRef((e,t)=>{const n=_n(Ba,e.__scopeSelect),r=Fa(Ba,e.__scopeSelect),[o,s]=m.useState(!1),i=$e(t,r.onScrollButtonChange);return ft(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(fp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});dp.displayName=Ba;var fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=_n("SelectScrollButton",n),i=m.useRef(null),a=Os(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),ft(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(Ie.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ce(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ce(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ce(o.onPointerLeave,()=>{l()})})}),aC="SelectSeparator",hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Ie.div,{"aria-hidden":!0,...r,ref:t})});hp.displayName=aC;var Ha="SelectArrow",lC=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ms(n),s=jn(Ha,n),i=_n(Ha,n);return s.open&&i.position==="popper"?c.jsx(uf,{...o,...r,ref:t}):null});lC.displayName=Ha;var cC="SelectBubbleInput",pp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=$e(r,o),i=Dh(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Ie.select,{...n,style:{...Uh,...n.style},ref:s,defaultValue:t})});pp.displayName=cC;function mp(e){return e===""||e===void 0}function gp(e){const t=pt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function xp(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=uC(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function uC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var dC=Wh,vp=qh,fC=Gh,hC=Yh,pC=Xh,wp=Jh,mC=tp,bp=op,yp=ip,gC=ap,xC=cp,Sp=up,Cp=dp,Tp=hp;const kp=dC,Ep=fC,Ua=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(vp,{ref:r,className:te("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,c.jsx(hC,{asChild:!0,children:c.jsx(re.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ua.displayName=vp.displayName;const Ip=m.forwardRef(({className:e,...t},n)=>c.jsx(Sp,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(re.ChevronUp,{className:"h-4 w-4"})}));Ip.displayName=Sp.displayName;const Np=m.forwardRef(({className:e,...t},n)=>c.jsx(Cp,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(re.ChevronDown,{className:"h-4 w-4"})}));Np.displayName=Cp.displayName;const Wa=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(pC,{children:c.jsxs(wp,{ref:o,className:te("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:[c.jsx(Ip,{}),c.jsx(mC,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(Np,{})]})}));Wa.displayName=wp.displayName;const vC=m.forwardRef(({className:e,...t},n)=>c.jsx(bp,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));vC.displayName=bp.displayName;const Qn=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(yp,{ref:r,className:te("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(xC,{children:c.jsx(re.Check,{className:"h-4 w-4"})})}),c.jsx(gC,{children:t})]}));Qn.displayName=yp.displayName;const wC=m.forwardRef(({className:e,...t},n)=>c.jsx(Tp,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));wC.displayName=Tp.displayName;var bC="Separator",Ap="horizontal",yC=["horizontal","vertical"],jp=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ap,...o}=e,s=SC(r)?r:Ap,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Ie.div,{"data-orientation":s,...a,...o,ref:t})});jp.displayName=bC;function SC(e){return yC.includes(e)}var _p=jp;const Rp=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(_p,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Rp.displayName=_p.displayName;const CC=pd,TC=rb,kC=md,Pp=m.forwardRef(({className:e,...t},n)=>c.jsx(os,{className:te("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}));Pp.displayName=os.displayName;const EC=io.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"}}),Op=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(kC,{children:[c.jsx(Pp,{}),c.jsxs(ss,{ref:o,className:te(EC({side:e}),t),...r,children:[n,c.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:[c.jsx(re.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Op.displayName=ss.displayName;const Mp=({className:e,...t})=>c.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Mp.displayName="SheetHeader";const Dp=m.forwardRef(({className:e,...t},n)=>c.jsx(qn,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Dp.displayName=qn.displayName;const Lp=m.forwardRef(({className:e,...t},n)=>c.jsx(is,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Lp.displayName=is.displayName;const IC={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 NC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=S.useState(!1),[s,i]=S.useState(!1),[a,l]=S.useState(e),[u,d]=S.useState(!1),{toast:f}=Ui();S.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),S.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(IC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},w=()=>{l(e),d(!1),o(!1)},v=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(CC,{open:r,onOpenChange:o,children:[c.jsx(TC,{asChild:!0,children:c.jsxs(We,{variant:"outline",size:"sm",className:n,children:[c.jsx(re.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Pi,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(Op,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(Mp,{children:[c.jsx(Dp,{children:"Chat Settings"}),c.jsx(Lp,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(Wr,{children:[c.jsx(Vr,{className:"pb-3",children:c.jsxs(qr,{className:"text-lg flex items-center gap-2",children:[c.jsx(re.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(Fo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Is,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(x=>({...x,api:{...x.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(We,{variant:"outline",onClick:v,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(An,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(x=>({...x,api:{...x.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Is,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(x=>({...x,api:{...x.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(We,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(re.EyeOff,{className:"h-4 w-4"}):c.jsx(re.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(Wr,{children:[c.jsx(Vr,{className:"pb-3",children:c.jsxs(qr,{className:"text-lg flex items-center gap-2",children:[c.jsx(re.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(Fo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(kp,{value:a.ui.layout,onValueChange:g=>l(x=>({...x,ui:{...x.ui,layout:g}})),children:[c.jsx(Ua,{children:c.jsx(Ep,{})}),c.jsxs(Wa,{children:[c.jsx(Qn,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(Qn,{value:"fullscreen",children:"Fullscreen"}),c.jsx(Qn,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Bt,{htmlFor:"theme",children:"Theme"}),c.jsxs(kp,{value:a.ui.theme,onValueChange:g=>l(x=>({...x,ui:{...x.ui,theme:g}})),children:[c.jsx(Ua,{children:c.jsx(Ep,{})}),c.jsxs(Wa,{children:[c.jsx(Qn,{value:"light",children:"Light"}),c.jsx(Qn,{value:"dark",children:"Dark"}),c.jsx(Qn,{value:"system",children:"System"})]})]})]}),c.jsx(Rp,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(An,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(An,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Bt,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(An,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(x=>({...x,ui:{...x.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(Wr,{children:[c.jsx(Vr,{className:"pb-3",children:c.jsxs(qr,{className:"text-lg flex items-center gap-2",children:[c.jsx(re.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(Fo,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Bt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(An,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Bt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(An,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Bt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(An,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(We,{variant:"outline",onClick:p,children:[c.jsx(re.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(We,{variant:"outline",onClick:w,children:"Cancel"}),c.jsxs(We,{onClick:h,disabled:!u,children:[c.jsx(re.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function AC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=S.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(So,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Es,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(So,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Es,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(So,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Es,{onError:s.onError,enableFileUpload:!0})})]})})}Ne.ChatApi=zl,Ne.ChatInterface=Es,Ne.ChatProviders=So,Ne.ChatSettings=NC,Ne.MarkdownContent=zi,Ne.MessageComponent=kd,Ne.MessageList=sa,Ne.ThreadManager=Da,Ne.applySettings=OS,Ne.chatApiClient=wn,Ne.default=AC,Ne.del=$l,Ne.get=Nt,Ne.getChatToken=Dl,Ne.getCurrentSettings=PS,Ne.getDefaultApiConfig=_h,Ne.getDefaultChatSettings=Rh,Ne.onChatTokenChanged=Ll,Ne.post=Zs,Ne.put=Fl,Ne.setChatToken=Js,Ne.useApi=Qs,Ne.useChatStream=Jl,Ne.useMessages=ci,Ne.useMessagesReducer=Hl,Ne.useStream=oc,Ne.useThreads=yo,Object.defineProperties(Ne,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|