teodor-new-chat-ui 4.3.350 → 4.3.352

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(Se,w){typeof exports=="object"&&typeof module<"u"?w(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"],w):(Se=typeof globalThis<"u"?globalThis:Se||self,w(Se.NewChatUI={},Se.React,Se.LucideReact,Se.reactSlot,Se.classVarianceAuthority,Se.clsx,Se.tailwindMerge,Se.ReactDOM))})(this,function(Se,w,le,Wn,po,Wh,Vh,Gs){"use strict";var AT=Object.defineProperty;var _T=(Se,w,le)=>w in Se?AT(Se,w,{enumerable:!0,configurable:!0,writable:!0,value:le}):Se[w]=le;var Uh=(Se,w,le)=>_T(Se,typeof w!="symbol"?w+"":w,le);var Ys=typeof document<"u"?document.currentScript:null;function Wa(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 v=Wa(w),ho=Wa(Gs);var Xs={exports:{}},Ar={};/**
1
+ (function(Se,w){typeof exports=="object"&&typeof module<"u"?w(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"],w):(Se=typeof globalThis<"u"?globalThis:Se||self,w(Se.NewChatUI={},Se.React,Se.LucideReact,Se.reactSlot,Se.classVarianceAuthority,Se.clsx,Se.tailwindMerge,Se.ReactDOM))})(this,function(Se,w,le,Vn,po,Wh,Vh,Gs){"use strict";var NT=Object.defineProperty;var _T=(Se,w,le)=>w in Se?NT(Se,w,{enumerable:!0,configurable:!0,writable:!0,value:le}):Se[w]=le;var Uh=(Se,w,le)=>_T(Se,typeof w!="symbol"?w+"":w,le);var Ys=typeof document<"u"?document.currentScript:null;function Wa(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 v=Wa(w),ho=Wa(Gs);var Xs={exports:{}},Nr={};/**
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 Va;function Kh(){if(Va)return Ar;Va=1;var e=w,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,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=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:p,ref:h,props:f,_owner:o.current}}return Ar.Fragment=n,Ar.jsx=i,Ar.jsxs=i,Ar}var _r={};/**
9
+ */var Va;function Kh(){if(Va)return Nr;Va=1;var e=w,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,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=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:p,ref:h,props:f,_owner:o.current}}return Nr.Fragment=n,Nr.jsx=i,Nr.jsxs=i,Nr}var _r={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,33 +14,33 @@
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 Ka;function qh(){return Ka||(Ka=1,process.env.NODE_ENV!=="production"&&function(){var e=w,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"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),m=Symbol.iterator,g="@@iterator";function y(E){if(E===null||typeof E!="object")return null;var V=m&&E[m]||E[g];return typeof V=="function"?V:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var V=arguments.length,ae=new Array(V>1?V-1:0),be=1;be<V;be++)ae[be-1]=arguments[be];S("error",E,ae)}}function S(E,V,ae){{var be=x.ReactDebugCurrentFrame,Ge=be.getStackAddendum();Ge!==""&&(V+="%s",ae=ae.concat([Ge]));var tt=ae.map(function($e){return String($e)});tt.unshift("Warning: "+V),Function.prototype.apply.call(console[E],console,tt)}}var k=!1,C=!1,T=!1,I=!1,N=!1,_;_=Symbol.for("react.module.reference");function L(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||N||E===o||E===c||E===d||I||E===h||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===p||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===_||E.getModuleId!==void 0))}function R(E,V,ae){var be=E.displayName;if(be)return be;var Ge=V.displayName||V.name||"";return Ge!==""?ae+"("+Ge+")":ae}function O(E){return E.displayName||"Context"}function F(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var V=E;return O(V)+".Consumer";case i:var ae=E;return O(ae._context)+".Provider";case l:return R(E,E.render,"ForwardRef");case f:var be=E.displayName||null;return be!==null?be:F(E.type)||"Memo";case p:{var Ge=E,tt=Ge._payload,$e=Ge._init;try{return F($e(tt))}catch{return null}}}return null}var A=Object.assign,B=0,j,K,z,M,G,X,se;function ve(){}ve.__reactDisabledLog=!0;function Ie(){{if(B===0){j=console.log,K=console.info,z=console.warn,M=console.error,G=console.group,X=console.groupCollapsed,se=console.groupEnd;var E={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}B++}}function Y(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},E,{value:j}),info:A({},E,{value:K}),warn:A({},E,{value:z}),error:A({},E,{value:M}),group:A({},E,{value:G}),groupCollapsed:A({},E,{value:X}),groupEnd:A({},E,{value:se})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=x.ReactCurrentDispatcher,J;function $(E,V,ae){{if(J===void 0)try{throw Error()}catch(Ge){var be=Ge.stack.trim().match(/\n( *(at )?)/);J=be&&be[1]||""}return`
18
- `+J+E}}var q=!1,Z;{var ue=typeof WeakMap=="function"?WeakMap:Map;Z=new ue}function ie(E,V){if(!E||q)return"";{var ae=Z.get(E);if(ae!==void 0)return ae}var be;q=!0;var Ge=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var tt;tt=U.current,U.current=null,Ie();try{if(V){var $e=function(){throw Error()};if(Object.defineProperty($e.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct($e,[])}catch(Ve){be=Ve}Reflect.construct(E,[],$e)}else{try{$e.call()}catch(Ve){be=Ve}E.call($e.prototype)}}else{try{throw Error()}catch(Ve){be=Ve}E()}}catch(Ve){if(Ve&&be&&typeof Ve.stack=="string"){for(var Le=Ve.stack.split(`
19
- `),It=be.stack.split(`
20
- `),ft=Le.length-1,xt=It.length-1;ft>=1&&xt>=0&&Le[ft]!==It[xt];)xt--;for(;ft>=1&&xt>=0;ft--,xt--)if(Le[ft]!==It[xt]){if(ft!==1||xt!==1)do if(ft--,xt--,xt<0||Le[ft]!==It[xt]){var pe=`
21
- `+Le[ft].replace(" at new "," at ");return E.displayName&&pe.includes("<anonymous>")&&(pe=pe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Z.set(E,pe),pe}while(ft>=1&&xt>=0);break}}}finally{q=!1,U.current=tt,Y(),Error.prepareStackTrace=Ge}var we=E?E.displayName||E.name:"",Ee=we?$(we):"";return typeof E=="function"&&Z.set(E,Ee),Ee}function _e(E,V,ae){return ie(E,!1)}function He(E){var V=E.prototype;return!!(V&&V.isReactComponent)}function oe(E,V,ae){if(E==null)return"";if(typeof E=="function")return ie(E,He(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return _e(E.render);case f:return oe(E.type,V,ae);case p:{var be=E,Ge=be._payload,tt=be._init;try{return oe(tt(Ge),V,ae)}catch{}}}return""}var xe=Object.prototype.hasOwnProperty,Re={},Ye=x.ReactDebugCurrentFrame;function nt(E){if(E){var V=E._owner,ae=oe(E.type,E._source,V?V.type:null);Ye.setExtraStackFrame(ae)}else Ye.setExtraStackFrame(null)}function Xe(E,V,ae,be,Ge){{var tt=Function.call.bind(xe);for(var $e in E)if(tt(E,$e)){var Le=void 0;try{if(typeof E[$e]!="function"){var It=Error((be||"React class")+": "+ae+" type `"+$e+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[$e]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw It.name="Invariant Violation",It}Le=E[$e](V,$e,be,ae,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ft){Le=ft}Le&&!(Le instanceof Error)&&(nt(Ge),b("%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).",be||"React class",ae,$e,typeof Le),nt(null)),Le instanceof Error&&!(Le.message in Re)&&(Re[Le.message]=!0,nt(Ge),b("Failed %s type: %s",ae,Le.message),nt(null))}}}var qe=Array.isArray;function it(E){return qe(E)}function Je(E){{var V=typeof Symbol=="function"&&Symbol.toStringTag,ae=V&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ae}}function et(E){try{return at(E),!1}catch{return!0}}function at(E){return""+E}function jt(E){if(et(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Je(E)),at(E)}var pt=x.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0},mt,St;function Mt(E){if(xe.call(E,"ref")){var V=Object.getOwnPropertyDescriptor(E,"ref").get;if(V&&V.isReactWarning)return!1}return E.ref!==void 0}function Bt(E){if(xe.call(E,"key")){var V=Object.getOwnPropertyDescriptor(E,"key").get;if(V&&V.isReactWarning)return!1}return E.key!==void 0}function Vt(E,V){typeof E.ref=="string"&&pt.current}function ze(E,V){{var ae=function(){mt||(mt=!0,b("%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)",V))};ae.isReactWarning=!0,Object.defineProperty(E,"key",{get:ae,configurable:!0})}}function dn(E,V){{var ae=function(){St||(St=!0,b("%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)",V))};ae.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ae,configurable:!0})}}var rt=function(E,V,ae,be,Ge,tt,$e){var Le={$$typeof:t,type:E,key:V,ref:ae,props:$e,_owner:tt};return Le._store={},Object.defineProperty(Le._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Le,"_self",{configurable:!1,enumerable:!1,writable:!1,value:be}),Object.defineProperty(Le,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ge}),Object.freeze&&(Object.freeze(Le.props),Object.freeze(Le)),Le};function We(E,V,ae,be,Ge){{var tt,$e={},Le=null,It=null;ae!==void 0&&(jt(ae),Le=""+ae),Bt(V)&&(jt(V.key),Le=""+V.key),Mt(V)&&(It=V.ref,Vt(V,Ge));for(tt in V)xe.call(V,tt)&&!ht.hasOwnProperty(tt)&&($e[tt]=V[tt]);if(E&&E.defaultProps){var ft=E.defaultProps;for(tt in ft)$e[tt]===void 0&&($e[tt]=ft[tt])}if(Le||It){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Le&&ze($e,xt),It&&dn($e,xt)}return rt(E,Le,It,Ge,be,pt.current,$e)}}var gt=x.ReactCurrentOwner,Rt=x.ReactDebugCurrentFrame;function H(E){if(E){var V=E._owner,ae=oe(E.type,E._source,V?V.type:null);Rt.setExtraStackFrame(ae)}else Rt.setExtraStackFrame(null)}var re;re=!1;function D(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function Q(){{if(gt.current){var E=F(gt.current.type);if(E)return`
17
+ */var Ka;function qh(){return Ka||(Ka=1,process.env.NODE_ENV!=="production"&&function(){var e=w,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"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),m=Symbol.iterator,g="@@iterator";function y(E){if(E===null||typeof E!="object")return null;var W=m&&E[m]||E[g];return typeof W=="function"?W:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var W=arguments.length,ae=new Array(W>1?W-1:0),be=1;be<W;be++)ae[be-1]=arguments[be];S("error",E,ae)}}function S(E,W,ae){{var be=x.ReactDebugCurrentFrame,Be=be.getStackAddendum();Be!==""&&(W+="%s",ae=ae.concat([Be]));var nt=ae.map(function(De){return String(De)});nt.unshift("Warning: "+W),Function.prototype.apply.call(console[E],console,nt)}}var k=!1,C=!1,T=!1,I=!1,N=!1,_;_=Symbol.for("react.module.reference");function L(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||N||E===o||E===c||E===d||I||E===h||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===p||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===_||E.getModuleId!==void 0))}function B(E,W,ae){var be=E.displayName;if(be)return be;var Be=W.displayName||W.name||"";return Be!==""?ae+"("+Be+")":ae}function G(E){return E.displayName||"Context"}function V(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var W=E;return G(W)+".Consumer";case i:var ae=E;return G(ae._context)+".Provider";case l:return B(E,E.render,"ForwardRef");case f:var be=E.displayName||null;return be!==null?be:V(E.type)||"Memo";case p:{var Be=E,nt=Be._payload,De=Be._init;try{return V(De(nt))}catch{return null}}}return null}var R=Object.assign,M=0,A,F,D,P,z,X,ne;function ye(){}ye.__reactDisabledLog=!0;function Te(){{if(M===0){A=console.log,F=console.info,D=console.warn,P=console.error,z=console.group,X=console.groupCollapsed,ne=console.groupEnd;var E={configurable:!0,enumerable:!0,value:ye,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}M++}}function q(){{if(M--,M===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:R({},E,{value:A}),info:R({},E,{value:F}),warn:R({},E,{value:D}),error:R({},E,{value:P}),group:R({},E,{value:z}),groupCollapsed:R({},E,{value:X}),groupEnd:R({},E,{value:ne})})}M<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=x.ReactCurrentDispatcher,J;function $(E,W,ae){{if(J===void 0)try{throw Error()}catch(Be){var be=Be.stack.trim().match(/\n( *(at )?)/);J=be&&be[1]||""}return`
18
+ `+J+E}}var Y=!1,Z;{var de=typeof WeakMap=="function"?WeakMap:Map;Z=new de}function oe(E,W){if(!E||Y)return"";{var ae=Z.get(E);if(ae!==void 0)return ae}var be;Y=!0;var Be=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var nt;nt=U.current,U.current=null,Te();try{if(W){var De=function(){throw Error()};if(Object.defineProperty(De.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(De,[])}catch(Ue){be=Ue}Reflect.construct(E,[],De)}else{try{De.call()}catch(Ue){be=Ue}E.call(De.prototype)}}else{try{throw Error()}catch(Ue){be=Ue}E()}}catch(Ue){if(Ue&&be&&typeof Ue.stack=="string"){for(var Oe=Ue.stack.split(`
19
+ `),Et=be.stack.split(`
20
+ `),mt=Oe.length-1,xt=Et.length-1;mt>=1&&xt>=0&&Oe[mt]!==Et[xt];)xt--;for(;mt>=1&&xt>=0;mt--,xt--)if(Oe[mt]!==Et[xt]){if(mt!==1||xt!==1)do if(mt--,xt--,xt<0||Oe[mt]!==Et[xt]){var he=`
21
+ `+Oe[mt].replace(" at new "," at ");return E.displayName&&he.includes("<anonymous>")&&(he=he.replace("<anonymous>",E.displayName)),typeof E=="function"&&Z.set(E,he),he}while(mt>=1&&xt>=0);break}}}finally{Y=!1,U.current=nt,q(),Error.prepareStackTrace=Be}var we=E?E.displayName||E.name:"",Ie=we?$(we):"";return typeof E=="function"&&Z.set(E,Ie),Ie}function _e(E,W,ae){return oe(E,!1)}function ze(E){var W=E.prototype;return!!(W&&W.isReactComponent)}function se(E,W,ae){if(E==null)return"";if(typeof E=="function")return oe(E,ze(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return _e(E.render);case f:return se(E.type,W,ae);case p:{var be=E,Be=be._payload,nt=be._init;try{return se(nt(Be),W,ae)}catch{}}}return""}var me=Object.prototype.hasOwnProperty,Re={},Ve=x.ReactDebugCurrentFrame;function ut(E){if(E){var W=E._owner,ae=se(E.type,E._source,W?W.type:null);Ve.setExtraStackFrame(ae)}else Ve.setExtraStackFrame(null)}function Ke(E,W,ae,be,Be){{var nt=Function.call.bind(me);for(var De in E)if(nt(E,De)){var Oe=void 0;try{if(typeof E[De]!="function"){var Et=Error((be||"React class")+": "+ae+" type `"+De+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[De]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Et.name="Invariant Violation",Et}Oe=E[De](W,De,be,ae,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Oe=mt}Oe&&!(Oe instanceof Error)&&(ut(Be),b("%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).",be||"React class",ae,De,typeof Oe),ut(null)),Oe instanceof Error&&!(Oe.message in Re)&&(Re[Oe.message]=!0,ut(Be),b("Failed %s type: %s",ae,Oe.message),ut(null))}}}var qe=Array.isArray;function Qe(E){return qe(E)}function Ge(E){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ae=W&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ae}}function et(E){try{return st(E),!1}catch{return!0}}function st(E){return""+E}function Mt(E){if(et(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(E)),st(E)}var gt=x.ReactCurrentOwner,Ct={key:!0,ref:!0,__self:!0,__source:!0},it,St;function Rt(E){if(me.call(E,"ref")){var W=Object.getOwnPropertyDescriptor(E,"ref").get;if(W&&W.isReactWarning)return!1}return E.ref!==void 0}function zt(E){if(me.call(E,"key")){var W=Object.getOwnPropertyDescriptor(E,"key").get;if(W&&W.isReactWarning)return!1}return E.key!==void 0}function nn(E,W){typeof E.ref=="string"&&gt.current}function Le(E,W){{var ae=function(){it||(it=!0,b("%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)",W))};ae.isReactWarning=!0,Object.defineProperty(E,"key",{get:ae,configurable:!0})}}function Sn(E,W){{var ae=function(){St||(St=!0,b("%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)",W))};ae.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ae,configurable:!0})}}var tt=function(E,W,ae,be,Be,nt,De){var Oe={$$typeof:t,type:E,key:W,ref:ae,props:De,_owner:nt};return Oe._store={},Object.defineProperty(Oe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Oe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:be}),Object.defineProperty(Oe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Be}),Object.freeze&&(Object.freeze(Oe.props),Object.freeze(Oe)),Oe};function We(E,W,ae,be,Be){{var nt,De={},Oe=null,Et=null;ae!==void 0&&(Mt(ae),Oe=""+ae),zt(W)&&(Mt(W.key),Oe=""+W.key),Rt(W)&&(Et=W.ref,nn(W,Be));for(nt in W)me.call(W,nt)&&!Ct.hasOwnProperty(nt)&&(De[nt]=W[nt]);if(E&&E.defaultProps){var mt=E.defaultProps;for(nt in mt)De[nt]===void 0&&(De[nt]=mt[nt])}if(Oe||Et){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Oe&&Le(De,xt),Et&&Sn(De,xt)}return tt(E,Oe,Et,Be,be,gt.current,De)}}var pt=x.ReactCurrentOwner,Pt=x.ReactDebugCurrentFrame;function Ye(E){if(E){var W=E._owner,ae=se(E.type,E._source,W?W.type:null);Pt.setExtraStackFrame(ae)}else Pt.setExtraStackFrame(null)}var H;H=!1;function j(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function Q(){{if(pt.current){var E=V(pt.current.type);if(E)return`
22
22
 
23
- Check the render method of \``+E+"`."}return""}}function ne(E){return""}var me={};function ke(E){{var V=Q();if(!V){var ae=typeof E=="string"?E:E.displayName||E.name;ae&&(V=`
23
+ Check the render method of \``+E+"`."}return""}}function re(E){return""}var ie={};function ce(E){{var W=Q();if(!W){var ae=typeof E=="string"?E:E.displayName||E.name;ae&&(W=`
24
24
 
25
- Check the top-level render call using <`+ae+">.")}return V}}function Pe(E,V){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ae=ke(V);if(me[ae])return;me[ae]=!0;var be="";E&&E._owner&&E._owner!==gt.current&&(be=" It was passed a child from "+F(E._owner.type)+"."),H(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ae,be),H(null)}}function De(E,V){{if(typeof E!="object")return;if(it(E))for(var ae=0;ae<E.length;ae++){var be=E[ae];D(be)&&Pe(be,V)}else if(D(E))E._store&&(E._store.validated=!0);else if(E){var Ge=y(E);if(typeof Ge=="function"&&Ge!==E.entries)for(var tt=Ge.call(E),$e;!($e=tt.next()).done;)D($e.value)&&Pe($e.value,V)}}}function Ue(E){{var V=E.type;if(V==null||typeof V=="string")return;var ae;if(typeof V=="function")ae=V.propTypes;else if(typeof V=="object"&&(V.$$typeof===l||V.$$typeof===f))ae=V.propTypes;else return;if(ae){var be=F(V);Xe(ae,E.props,"prop",be,E)}else if(V.PropTypes!==void 0&&!re){re=!0;var Ge=F(V);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ge||"Unknown")}typeof V.getDefaultProps=="function"&&!V.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Kt(E){{for(var V=Object.keys(E.props),ae=0;ae<V.length;ae++){var be=V[ae];if(be!=="children"&&be!=="key"){H(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",be),H(null);break}}E.ref!==null&&(H(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),H(null))}}var Nn={};function ar(E,V,ae,be,Ge,tt){{var $e=L(E);if(!$e){var Le="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(Le+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var It=ne();It?Le+=It:Le+=Q();var ft;E===null?ft="null":it(E)?ft="array":E!==void 0&&E.$$typeof===t?(ft="<"+(F(E.type)||"Unknown")+" />",Le=" Did you accidentally export a JSX literal instead of a component?"):ft=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ft,Le)}var xt=We(E,V,ae,Ge,tt);if(xt==null)return xt;if($e){var pe=V.children;if(pe!==void 0)if(be)if(it(pe)){for(var we=0;we<pe.length;we++)De(pe[we],E);Object.freeze&&Object.freeze(pe)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else De(pe,E)}if(xe.call(V,"key")){var Ee=F(E),Ve=Object.keys(V).filter(function(NT){return NT!=="key"}),Hn=Ve.length>0?"{key: someKey, "+Ve.join(": ..., ")+": ...}":"{key: someKey}";if(!Nn[Ee+Hn]){var nn=Ve.length>0?"{"+Ve.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+ae+">.")}return W}}function Xe(E,W){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ae=ce(W);if(ie[ae])return;ie[ae]=!0;var be="";E&&E._owner&&E._owner!==pt.current&&(be=" It was passed a child from "+V(E._owner.type)+"."),Ye(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ae,be),Ye(null)}}function Ee(E,W){{if(typeof E!="object")return;if(Qe(E))for(var ae=0;ae<E.length;ae++){var be=E[ae];j(be)&&Xe(be,W)}else if(j(E))E._store&&(E._store.validated=!0);else if(E){var Be=y(E);if(typeof Be=="function"&&Be!==E.entries)for(var nt=Be.call(E),De;!(De=nt.next()).done;)j(De.value)&&Xe(De.value,W)}}}function at(E){{var W=E.type;if(W==null||typeof W=="string")return;var ae;if(typeof W=="function")ae=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))ae=W.propTypes;else return;if(ae){var be=V(W);Ke(ae,E.props,"prop",be,E)}else if(W.PropTypes!==void 0&&!H){H=!0;var Be=V(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Be||"Unknown")}typeof W.getDefaultProps=="function"&&!W.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ht(E){{for(var W=Object.keys(E.props),ae=0;ae<W.length;ae++){var be=W[ae];if(be!=="children"&&be!=="key"){Ye(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",be),Ye(null);break}}E.ref!==null&&(Ye(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),Ye(null))}}var Kt={};function Hn(E,W,ae,be,Be,nt){{var De=L(E);if(!De){var Oe="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(Oe+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Et=re();Et?Oe+=Et:Oe+=Q();var mt;E===null?mt="null":Qe(E)?mt="array":E!==void 0&&E.$$typeof===t?(mt="<"+(V(E.type)||"Unknown")+" />",Oe=" Did you accidentally export a JSX literal instead of a component?"):mt=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",mt,Oe)}var xt=We(E,W,ae,Be,nt);if(xt==null)return xt;if(De){var he=W.children;if(he!==void 0)if(be)if(Qe(he)){for(var we=0;we<he.length;we++)Ee(he[we],E);Object.freeze&&Object.freeze(he)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ee(he,E)}if(me.call(W,"key")){var Ie=V(E),Ue=Object.keys(W).filter(function(AT){return AT!=="key"}),Wn=Ue.length>0?"{key: someKey, "+Ue.join(": ..., ")+": ...}":"{key: someKey}";if(!Kt[Ie+Wn]){var rn=Ue.length>0?"{"+Ue.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
26
26
  let props = %s;
27
27
  <%s {...props} />
28
28
  React keys must be passed directly to JSX without using spread:
29
29
  let props = %s;
30
- <%s key={someKey} {...props} />`,Hn,Ee,nn,Ee),Nn[Ee+Hn]=!0}}return E===r?Kt(xt):Ue(xt),xt}}function Nr(E,V,ae){return ar(E,V,ae,!0)}function fo(E,V,ae){return ar(E,V,ae,!1)}var Un=fo,lr=Nr;_r.Fragment=r,_r.jsx=Un,_r.jsxs=lr}()),_r}process.env.NODE_ENV==="production"?Xs.exports=Kh():Xs.exports=qh();var u=Xs.exports;function qa(e,t){return function(){return e.apply(t,arguments)}}const{toString:Gh}=Object.prototype,{getPrototypeOf:Js}=Object,{iterator:mo,toStringTag:Ga}=Symbol,go=(e=>t=>{const n=Gh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),rn=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:cr}=Array,ur=xo("undefined");function jr(e){return e!==null&&!ur(e)&&e.constructor!==null&&!ur(e.constructor)&&Lt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ya=rn("ArrayBuffer");function Yh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ya(e.buffer),t}const Xh=xo("string"),Lt=xo("function"),Xa=xo("number"),Mr=e=>e!==null&&typeof e=="object",Jh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Js(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ga in e)&&!(mo in e)},Zh=e=>{if(!Mr(e)||jr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Qh=rn("Date"),em=rn("File"),tm=rn("Blob"),nm=rn("FileList"),rm=e=>Mr(e)&&Lt(e.pipe),om=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Lt(e.append)&&((t=go(e))==="formdata"||t==="object"&&Lt(e.toString)&&e.toString()==="[object FormData]"))},sm=rn("URLSearchParams"),[im,am,lm,cm]=["ReadableStream","Request","Response","Headers"].map(rn),um=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Rr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),cr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(jr(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 Ja(e,t){if(jr(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 Vn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Za=e=>!ur(e)&&e!==Vn;function Zs(){const{caseless:e,skipUndefined:t}=Za(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ja(n,s)||s;yo(n[i])&&yo(o)?n[i]=Zs(n[i],o):yo(o)?n[i]=Zs({},o):cr(o)?n[i]=o.slice():(!t||!ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Rr(arguments[o],r);return n}const dm=(e,t,n,{allOwnKeys:r}={})=>(Rr(t,(o,s)=>{n&&Lt(o)?e[s]=qa(o,n):e[s]=o},{allOwnKeys:r}),e),fm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),pm=(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)},hm=(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&&Js(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},mm=(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},gm=e=>{if(!e)return null;if(cr(e))return e;let t=e.length;if(!Xa(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},xm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Js(Uint8Array)),ym=(e,t)=>{const r=(e&&e[mo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},vm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},bm=rn("HTMLFormElement"),wm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Qa=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Sm=rn("RegExp"),el=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Rr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Cm=e=>{el(e,(t,n)=>{if(Lt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Lt(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+"'")})}})},Tm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return cr(e)?r(e):r(String(e).split(t)),n},km=()=>{},Im=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Em(e){return!!(e&&Lt(e.append)&&e[Ga]==="FormData"&&e[mo])}const Nm=e=>{const t=new Array(10),n=(r,o)=>{if(Mr(r)){if(t.indexOf(r)>=0)return;if(jr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=cr(r)?[]:{};return Rr(r,(i,a)=>{const l=n(i,o+1);!ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Am=rn("AsyncFunction"),_m=e=>e&&(Mr(e)||Lt(e))&&Lt(e.then)&&Lt(e.catch),tl=((e,t)=>e?setImmediate:t?((n,r)=>(Vn.addEventListener("message",({source:o,data:s})=>{o===Vn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Vn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Lt(Vn.postMessage)),jm=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||tl,P={isArray:cr,isArrayBuffer:Ya,isBuffer:jr,isFormData:om,isArrayBufferView:Yh,isString:Xh,isNumber:Xa,isBoolean:Jh,isObject:Mr,isPlainObject:yo,isEmptyObject:Zh,isReadableStream:im,isRequest:am,isResponse:lm,isHeaders:cm,isUndefined:ur,isDate:Qh,isFile:em,isBlob:tm,isRegExp:Sm,isFunction:Lt,isStream:rm,isURLSearchParams:sm,isTypedArray:xm,isFileList:nm,forEach:Rr,merge:Zs,extend:dm,trim:um,stripBOM:fm,inherits:pm,toFlatObject:hm,kindOf:go,kindOfTest:rn,endsWith:mm,toArray:gm,forEachEntry:ym,matchAll:vm,isHTMLForm:bm,hasOwnProperty:Qa,hasOwnProp:Qa,reduceDescriptors:el,freezeMethods:Cm,toObjectSet:Tm,toCamelCase:wm,noop:km,toFiniteNumber:Im,findKey:Ja,global:Vn,isContextDefined:Za,isSpecCompliantForm:Em,toJSONObject:Nm,isAsyncFn:Am,isThenable:_m,setImmediate:tl,asap:jm,isIterable:e=>e!=null&&Lt(e[mo])};function je(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(je,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 nl=je.prototype,rl={};["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=>{rl[e]={value:e}}),Object.defineProperties(je,rl),Object.defineProperty(nl,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(nl);P.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return je.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 Mm=null;function Qs(e){return P.isPlainObject(e)||P.isArray(e)}function ol(e){return P.endsWith(e,"[]")?e.slice(0,-2):e}function sl(e,t,n){return e?e.concat(t).map(function(o,s){return o=ol(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Rm(e){return P.isArray(e)&&!e.some(Qs)}const Pm=P.toFlatObject(P,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(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(g,y){return!P.isUndefined(y[g])});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 c(m){if(m===null)return"";if(P.isDate(m))return m.toISOString();if(P.isBoolean(m))return m.toString();if(!l&&P.isBlob(m))throw new je("Blob is not supported. Use a Buffer instead.");return P.isArrayBuffer(m)||P.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(P.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(P.isArray(m)&&Rm(m)||(P.isFileList(m)||P.endsWith(g,"[]"))&&(x=P.toArray(m)))return g=ol(g),x.forEach(function(S,k){!(P.isUndefined(S)||S===null)&&t.append(i===!0?sl([g],k,s):i===null?g:g+"[]",c(S))}),!1}return Qs(m)?!0:(t.append(sl(y,g,s),c(m)),!1)}const f=[],p=Object.assign(Pm,{defaultVisitor:d,convertValue:c,isVisitable:Qs});function h(m,g){if(!P.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),P.forEach(m,function(x,b){(!(P.isUndefined(x)||x===null)&&o.call(t,x,P.isString(b)?b.trim():b,g,p))===!0&&h(x,g?g.concat(b):[b])}),f.pop()}}if(!P.isObject(e))throw new TypeError("data must be an object");return h(e),t}function il(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ei(e,t){this._pairs=[],e&&vo(e,this,t)}const al=ei.prototype;al.append=function(t,n){this._pairs.push([t,n])},al.toString=function(t){const n=t?function(r){return t.call(this,r,il)}:il;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Om(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ll(e,t,n){if(!t)return e;const r=n&&n.encode||Om;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 ei(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class cl{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 ul={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Dm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ei,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ti=typeof window<"u"&&typeof document<"u",ni=typeof navigator=="object"&&navigator||void 0,Lm=ti&&(!ni||["ReactNative","NativeScript","NS"].indexOf(ni.product)<0),$m=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Fm=ti&&window.location.href||"http://localhost",Et={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ti,hasStandardBrowserEnv:Lm,hasStandardBrowserWebWorkerEnv:$m,navigator:ni,origin:Fm},Symbol.toStringTag,{value:"Module"})),...Dm};function Bm(e,t){return vo(e,new Et.classes.URLSearchParams,{visitor:function(n,r,o,s){return Et.isNode&&P.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function zm(e){return P.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Um(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 dl(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]=Um(o[i])),!a)}if(P.isFormData(e)&&P.isFunction(e.entries)){const n={};return P.forEachEntry(e,(r,o)=>{t(zm(r),o,n,0)}),n}return null}function Hm(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 Pr={transitional:ul,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(dl(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 Bm(t,this.formSerializer).toString();if((a=P.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Hm(t)):t}],transformResponse:[function(t){const n=this.transitional||Pr.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"?je.from(a,je.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:Et.classes.FormData,Blob:Et.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=>{Pr.headers[e]={}});const Wm=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"]),Vm=e=>{const t={};let n,r,o;return e&&e.split(`
31
- `).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Wm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},fl=Symbol("internals");function Or(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:P.isArray(e)?e.map(bo):String(e)}function Km(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 qm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ri(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 Gm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Ym(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 $t=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Or(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||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=bo(a))}const i=(a,l)=>P.forEach(a,(c,d)=>s(c,d,l));if(P.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(P.isString(t)&&(t=t.trim())&&!qm(t))i(Vm(t),n);else if(P.isObject(t)&&P.isIterable(t)){let a={},l,c;for(const d of t){if(!P.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?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=Or(t),t){const r=P.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Km(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=Or(t),t){const r=P.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ri(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Or(i),i){const a=P.findKey(r,i);a&&(!n||ri(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||ri(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]=bo(o),delete n[s];return}const a=t?Gm(s):String(s).trim();a!==s&&delete n[s],n[a]=bo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return 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[fl]=this[fl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Or(i);r[a]||(Ym(o,i),r[a]=!0)}return P.isArray(t)?t.forEach(s):s(t),this}};$t.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),P.reduceDescriptors($t.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),P.freezeMethods($t);function oi(e,t){const n=this||Pr,r=t||n,o=$t.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 pl(e){return!!(e&&e.__CANCEL__)}function dr(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}P.inherits(dr,je,{__CANCEL__:!0});function hl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new je("Request failed with status code "+n.status,[je.ERR_BAD_REQUEST,je.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Xm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Jm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function Zm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Jm(50,250);return Zm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},ml=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},gl=e=>(...t)=>P.asap(()=>e(...t)),Qm=Et.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Et.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Et.origin),Et.navigator&&/(msie|trident)/i.test(Et.navigator.userAgent)):()=>!0,eg=Et.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 tg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ng(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function xl(e,t,n){let r=!tg(t);return e&&(r||n==!1)?ng(e,t):t}const yl=e=>e instanceof $t?{...e}:e;function Kn(e,t){t=t||{};const n={};function r(c,d,f,p){return P.isPlainObject(c)&&P.isPlainObject(d)?P.merge.call({caseless:p},c,d):P.isPlainObject(d)?P.merge({},d):P.isArray(d)?d.slice():d}function o(c,d,f,p){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!P.isUndefined(d))return r(void 0,d)}function i(c,d){if(P.isUndefined(d)){if(!P.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(yl(c),yl(d),f,!0)};return P.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);P.isUndefined(p)&&f!==a||(n[d]=p)}),n}const vl=e=>{const t=Kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=$t.from(i),t.url=ll(xl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),P.isFormData(n)){if(Et.hasStandardBrowserEnv||Et.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(P.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Et.hasStandardBrowserEnv&&(r&&P.isFunction(r)&&(r=r(t)),r||r!==!1&&Qm(t.url))){const l=o&&s&&eg.read(s);l&&i.set(o,l)}return t},rg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=vl(e);let s=o.data;const i=$t.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,m;function g(){h&&h(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const S=$t.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};hl(function(I){n(I),g()},function(I){r(I),g()},C),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},y.onabort=function(){y&&(r(new je("Request aborted",je.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new je(C,je.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||ul;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new je(k,C.clarifyTimeoutError?je.ETIMEDOUT:je.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&P.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),P.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,m]=wo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new dr(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Xm(o.url);if(b&&Et.protocols.indexOf(b)===-1){r(new je("Unsupported protocol "+b+":",je.ERR_BAD_REQUEST,e));return}y.send(s||null)})},og=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof je?d:new dr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new je(`timeout ${t} of ms exceeded`,je.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>P.asap(a),l}},sg=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},ig=async function*(e,t){for await(const n of ag(e))yield*sg(n,t)},ag=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()}},bl=(e,t,n,r)=>{const o=ig(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},wl=64*1024,{isFunction:So}=P,lg=(({Request:e,Response:t})=>({Request:e,Response:t}))(P.global),{ReadableStream:Sl,TextEncoder:Cl}=P.global,Tl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},cg=e=>{e=P.merge.call({skipUndefined:!0},lg,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Sl),l=o&&(typeof Cl=="function"?(m=>g=>m.encode(g))(new Cl):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Tl(()=>{let m=!1;const g=new n(Et.origin,{body:new Sl,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Tl(()=>P.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new je(`Response type '${m}' is not supported`,je.ERR_NOT_SUPPORT,y)})});const p=async m=>{if(m==null)return 0;if(P.isBlob(m))return m.size;if(P.isSpecCompliantForm(m))return(await new n(Et.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(P.isArrayBufferView(m)||P.isArrayBuffer(m))return m.byteLength;if(P.isURLSearchParams(m)&&(m=m+""),P.isString(m))return(await l(m)).byteLength},h=async(m,g)=>{const y=P.toFiniteNumber(m.getContentLength());return y??p(g)};return async m=>{let{url:g,method:y,data:x,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:N,withCredentials:_="same-origin",fetchOptions:L}=vl(m),R=t||fetch;I=I?(I+"").toLowerCase():"text";let O=og([b,S&&S.toAbortSignal()],k),F=null;const A=O&&O.unsubscribe&&(()=>{O.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await h(N,x))!==0){let X=new n(g,{method:"POST",body:x,duplex:"half"}),se;if(P.isFormData(x)&&(se=X.headers.get("content-type"))&&N.setContentType(se),X.body){const[ve,Ie]=ml(B,wo(gl(T)));x=bl(X.body,wl,ve,Ie)}}P.isString(_)||(_=_?"include":"omit");const j=s&&"credentials"in n.prototype,K={...L,signal:O,method:y.toUpperCase(),headers:N.normalize().toJSON(),body:x,duplex:"half",credentials:j?_:void 0};F=s&&new n(g,K);let z=await(s?R(F,L):R(g,K));const M=d&&(I==="stream"||I==="response");if(d&&(C||M&&A)){const X={};["status","statusText","headers"].forEach(Y=>{X[Y]=z[Y]});const se=P.toFiniteNumber(z.headers.get("content-length")),[ve,Ie]=C&&ml(se,wo(gl(C),!0))||[];z=new r(bl(z.body,wl,ve,()=>{Ie&&Ie(),A&&A()}),X)}I=I||"text";let G=await f[P.findKey(f,I)||"text"](z,m);return!M&&A&&A(),await new Promise((X,se)=>{hl(X,se,{data:G,headers:$t.from(z.headers),status:z.status,statusText:z.statusText,config:m,request:F})})}catch(j){throw A&&A(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,m,F),{cause:j.cause||j}):je.from(j,j&&j.code,m,F)}}},ug=new Map,kl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=ug;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:cg(t)),d=c;return c};kl();const si={http:Mm,xhr:rg,fetch:{get:kl}};P.forEach(si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Il=e=>`- ${e}`,dg=e=>P.isFunction(e)||e===null||e===!1,El={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,!dg(r)&&(o=si[(a=String(r)).toLowerCase()],o===void 0))throw new je(`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,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
30
+ <%s key={someKey} {...props} />`,Wn,Ie,rn,Ie),Kt[Ie+Wn]=!0}}return E===r?ht(xt):at(xt),xt}}function Er(E,W,ae){return Hn(E,W,ae,!0)}function Ar(E,W,ae){return Hn(E,W,ae,!1)}var fo=Ar,Nn=Er;_r.Fragment=r,_r.jsx=fo,_r.jsxs=Nn}()),_r}process.env.NODE_ENV==="production"?Xs.exports=Kh():Xs.exports=qh();var u=Xs.exports;function qa(e,t){return function(){return e.apply(t,arguments)}}const{toString:Gh}=Object.prototype,{getPrototypeOf:Js}=Object,{iterator:mo,toStringTag:Ga}=Symbol,go=(e=>t=>{const n=Gh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=xo("undefined");function jr(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ya=on("ArrayBuffer");function Yh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ya(e.buffer),t}const Xh=xo("string"),$t=xo("function"),Xa=xo("number"),Mr=e=>e!==null&&typeof e=="object",Jh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Js(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ga in e)&&!(mo in e)},Zh=e=>{if(!Mr(e)||jr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Qh=on("Date"),em=on("File"),tm=on("Blob"),nm=on("FileList"),rm=e=>Mr(e)&&$t(e.pipe),om=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=go(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},sm=on("URLSearchParams"),[im,am,lm,cm]=["ReadableStream","Request","Response","Headers"].map(on),um=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Rr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),lr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(jr(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 Ja(e,t){if(jr(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 Kn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Za=e=>!cr(e)&&e!==Kn;function Zs(){const{caseless:e,skipUndefined:t}=Za(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ja(n,s)||s;yo(n[i])&&yo(o)?n[i]=Zs(n[i],o):yo(o)?n[i]=Zs({},o):lr(o)?n[i]=o.slice():(!t||!cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Rr(arguments[o],r);return n}const dm=(e,t,n,{allOwnKeys:r}={})=>(Rr(t,(o,s)=>{n&&$t(o)?e[s]=qa(o,n):e[s]=o},{allOwnKeys:r}),e),fm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),pm=(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)},hm=(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&&Js(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},mm=(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},gm=e=>{if(!e)return null;if(lr(e))return e;let t=e.length;if(!Xa(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},xm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Js(Uint8Array)),ym=(e,t)=>{const r=(e&&e[mo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},vm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},bm=on("HTMLFormElement"),wm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Qa=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Sm=on("RegExp"),el=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Rr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Cm=e=>{el(e,(t,n)=>{if($t(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if($t(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+"'")})}})},Tm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},km=()=>{},Im=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Em(e){return!!(e&&$t(e.append)&&e[Ga]==="FormData"&&e[mo])}const Am=e=>{const t=new Array(10),n=(r,o)=>{if(Mr(r)){if(t.indexOf(r)>=0)return;if(jr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Rr(r,(i,a)=>{const l=n(i,o+1);!cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Nm=on("AsyncFunction"),_m=e=>e&&(Mr(e)||$t(e))&&$t(e.then)&&$t(e.catch),tl=((e,t)=>e?setImmediate:t?((n,r)=>(Kn.addEventListener("message",({source:o,data:s})=>{o===Kn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Kn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Kn.postMessage)),jm=typeof queueMicrotask<"u"?queueMicrotask.bind(Kn):typeof process<"u"&&process.nextTick||tl,O={isArray:lr,isArrayBuffer:Ya,isBuffer:jr,isFormData:om,isArrayBufferView:Yh,isString:Xh,isNumber:Xa,isBoolean:Jh,isObject:Mr,isPlainObject:yo,isEmptyObject:Zh,isReadableStream:im,isRequest:am,isResponse:lm,isHeaders:cm,isUndefined:cr,isDate:Qh,isFile:em,isBlob:tm,isRegExp:Sm,isFunction:$t,isStream:rm,isURLSearchParams:sm,isTypedArray:xm,isFileList:nm,forEach:Rr,merge:Zs,extend:dm,trim:um,stripBOM:fm,inherits:pm,toFlatObject:hm,kindOf:go,kindOfTest:on,endsWith:mm,toArray:gm,forEachEntry:ym,matchAll:vm,isHTMLForm:bm,hasOwnProperty:Qa,hasOwnProp:Qa,reduceDescriptors:el,freezeMethods:Cm,toObjectSet:Tm,toCamelCase:wm,noop:km,toFiniteNumber:Im,findKey:Ja,global:Kn,isContextDefined:Za,isSpecCompliantForm:Em,toJSONObject:Am,isAsyncFn:Nm,isThenable:_m,setImmediate:tl,asap:jm,isIterable:e=>e!=null&&$t(e[mo])};function je(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(je,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const nl=je.prototype,rl={};["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=>{rl[e]={value:e}}),Object.defineProperties(je,rl),Object.defineProperty(nl,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(nl);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return je.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 Mm=null;function Qs(e){return O.isPlainObject(e)||O.isArray(e)}function ol(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function sl(e,t,n){return e?e.concat(t).map(function(o,s){return o=ol(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Rm(e){return O.isArray(e)&&!e.some(Qs)}const Pm=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,y){return!O.isUndefined(y[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(m){if(m===null)return"";if(O.isDate(m))return m.toISOString();if(O.isBoolean(m))return m.toString();if(!l&&O.isBlob(m))throw new je("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(m)||O.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function d(m,g,y){let x=m;if(m&&!y&&typeof m=="object"){if(O.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(O.isArray(m)&&Rm(m)||(O.isFileList(m)||O.endsWith(g,"[]"))&&(x=O.toArray(m)))return g=ol(g),x.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?sl([g],k,s):i===null?g:g+"[]",c(S))}),!1}return Qs(m)?!0:(t.append(sl(y,g,s),c(m)),!1)}const f=[],p=Object.assign(Pm,{defaultVisitor:d,convertValue:c,isVisitable:Qs});function h(m,g){if(!O.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),O.forEach(m,function(x,b){(!(O.isUndefined(x)||x===null)&&o.call(t,x,O.isString(b)?b.trim():b,g,p))===!0&&h(x,g?g.concat(b):[b])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return h(e),t}function il(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ei(e,t){this._pairs=[],e&&vo(e,this,t)}const al=ei.prototype;al.append=function(t,n){this._pairs.push([t,n])},al.toString=function(t){const n=t?function(r){return t.call(this,r,il)}:il;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Om(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ll(e,t,n){if(!t)return e;const r=n&&n.encode||Om;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new ei(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class cl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const ul={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Dm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ei,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ti=typeof window<"u"&&typeof document<"u",ni=typeof navigator=="object"&&navigator||void 0,Lm=ti&&(!ni||["ReactNative","NativeScript","NS"].indexOf(ni.product)<0),$m=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Fm=ti&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ti,hasStandardBrowserEnv:Lm,hasStandardBrowserWebWorkerEnv:$m,navigator:ni,origin:Fm},Symbol.toStringTag,{value:"Module"})),...Dm};function Bm(e,t){return vo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function zm(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Um(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 dl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Um(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(zm(r),o,n,0)}),n}return null}function Hm(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Pr={transitional:ul,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(dl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Bm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Hm(t)):t}],transformResponse:[function(t){const n=this.transitional||Pr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?je.from(a,je.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:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Pr.headers[e]={}});const Wm=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Vm=e=>{const t={};let n,r,o;return e&&e.split(`
31
+ `).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Wm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},fl=Symbol("internals");function Or(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:O.isArray(e)?e.map(bo):String(e)}function Km(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 qm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ri(e,t,n,r,o){if(O.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!O.isString(t)){if(O.isString(r))return t.indexOf(r)!==-1;if(O.isRegExp(r))return r.test(t)}}function Gm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Ym(e,t){const n=O.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Ft=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Or(l);if(!d)throw new Error("header name must be a non-empty string");const f=O.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=bo(a))}const i=(a,l)=>O.forEach(a,(c,d)=>s(c,d,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!qm(t))i(Vm(t),n);else if(O.isObject(t)&&O.isIterable(t)){let a={},l,c;for(const d of t){if(!O.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?O.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Or(t),t){const r=O.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Km(o);if(O.isFunction(n))return n.call(this,o,r);if(O.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Or(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ri(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Or(i),i){const a=O.findKey(r,i);a&&(!n||ri(r,r[a],a,n))&&(delete r[a],o=!0)}}return O.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||ri(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return O.forEach(this,(o,s)=>{const i=O.findKey(r,s);if(i){n[i]=bo(o),delete n[s];return}const a=t?Gm(s):String(s).trim();a!==s&&delete n[s],n[a]=bo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
32
+ `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[fl]=this[fl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Or(i);r[a]||(Ym(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function oi(e,t){const n=this||Pr,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function pl(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(ur,je,{__CANCEL__:!0});function hl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new je("Request failed with status code "+n.status,[je.ERR_BAD_REQUEST,je.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Xm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Jm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function Zm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Jm(50,250);return Zm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},ml=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},gl=e=>(...t)=>O.asap(()=>e(...t)),Qm=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,eg=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function tg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ng(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function xl(e,t,n){let r=!tg(t);return e&&(r||n==!1)?ng(e,t):t}const yl=e=>e instanceof Ft?{...e}:e;function qn(e,t){t=t||{};const n={};function r(c,d,f,p){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:p},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,p){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(yl(c),yl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);O.isUndefined(p)&&f!==a||(n[d]=p)}),n}const vl=e=>{const t=qn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=ll(xl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(At.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&Qm(t.url))){const l=o&&s&&eg.read(s);l&&i.set(o,l)}return t},rg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=vl(e);let s=o.data;const i=Ft.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,m;function g(){h&&h(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function x(){if(!y)return;const S=Ft.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};hl(function(I){n(I),g()},function(I){r(I),g()},C),y=null}"onloadend"in y?y.onloadend=x:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(x)},y.onabort=function(){y&&(r(new je("Request aborted",je.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new je(C,je.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||ul;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new je(k,C.clarifyTimeoutError?je.ETIMEDOUT:je.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&O.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,m]=wo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ur(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Xm(o.url);if(b&&At.protocols.indexOf(b)===-1){r(new je("Unsupported protocol "+b+":",je.ERR_BAD_REQUEST,e));return}y.send(s||null)})},og=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof je?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new je(`timeout ${t} of ms exceeded`,je.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>O.asap(a),l}},sg=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},ig=async function*(e,t){for await(const n of ag(e))yield*sg(n,t)},ag=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()}},bl=(e,t,n,r)=>{const o=ig(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},wl=64*1024,{isFunction:So}=O,lg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Sl,TextEncoder:Cl}=O.global,Tl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},cg=e=>{e=O.merge.call({skipUndefined:!0},lg,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Sl),l=o&&(typeof Cl=="function"?(m=>g=>m.encode(g))(new Cl):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Tl(()=>{let m=!1;const g=new n(At.origin,{body:new Sl,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),d=i&&a&&Tl(()=>O.isReadableStream(new r("").body)),f={stream:d&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,y)=>{let x=g&&g[m];if(x)return x.call(g);throw new je(`Response type '${m}' is not supported`,je.ERR_NOT_SUPPORT,y)})});const p=async m=>{if(m==null)return 0;if(O.isBlob(m))return m.size;if(O.isSpecCompliantForm(m))return(await new n(At.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(O.isArrayBufferView(m)||O.isArrayBuffer(m))return m.byteLength;if(O.isURLSearchParams(m)&&(m=m+""),O.isString(m))return(await l(m)).byteLength},h=async(m,g)=>{const y=O.toFiniteNumber(m.getContentLength());return y??p(g)};return async m=>{let{url:g,method:y,data:x,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:N,withCredentials:_="same-origin",fetchOptions:L}=vl(m),B=t||fetch;I=I?(I+"").toLowerCase():"text";let G=og([b,S&&S.toAbortSignal()],k),V=null;const R=G&&G.unsubscribe&&(()=>{G.unsubscribe()});let M;try{if(T&&c&&y!=="get"&&y!=="head"&&(M=await h(N,x))!==0){let X=new n(g,{method:"POST",body:x,duplex:"half"}),ne;if(O.isFormData(x)&&(ne=X.headers.get("content-type"))&&N.setContentType(ne),X.body){const[ye,Te]=ml(M,wo(gl(T)));x=bl(X.body,wl,ye,Te)}}O.isString(_)||(_=_?"include":"omit");const A=s&&"credentials"in n.prototype,F={...L,signal:G,method:y.toUpperCase(),headers:N.normalize().toJSON(),body:x,duplex:"half",credentials:A?_:void 0};V=s&&new n(g,F);let D=await(s?B(V,L):B(g,F));const P=d&&(I==="stream"||I==="response");if(d&&(C||P&&R)){const X={};["status","statusText","headers"].forEach(q=>{X[q]=D[q]});const ne=O.toFiniteNumber(D.headers.get("content-length")),[ye,Te]=C&&ml(ne,wo(gl(C),!0))||[];D=new r(bl(D.body,wl,ye,()=>{Te&&Te(),R&&R()}),X)}I=I||"text";let z=await f[O.findKey(f,I)||"text"](D,m);return!P&&R&&R(),await new Promise((X,ne)=>{hl(X,ne,{data:z,headers:Ft.from(D.headers),status:D.status,statusText:D.statusText,config:m,request:V})})}catch(A){throw R&&R(),A&&A.name==="TypeError"&&/Load failed|fetch/i.test(A.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,m,V),{cause:A.cause||A}):je.from(A,A&&A.code,m,V)}}},ug=new Map,kl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=ug;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:cg(t)),d=c;return c};kl();const si={http:Mm,xhr:rg,fetch:{get:kl}};O.forEach(si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Il=e=>`- ${e}`,dg=e=>O.isFunction(e)||e===null||e===!1,El={getAdapter:(e,t)=>{e=O.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!dg(r)&&(o=si[(a=String(r)).toLowerCase()],o===void 0))throw new je(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
33
  `+i.map(Il).join(`
34
- `):" "+Il(i[0]):"as no adapter specified";throw new je("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:si};function ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dr(null,e)}function Nl(e){return ii(e),e.headers=$t.from(e.headers),e.data=oi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),El.getAdapter(e.adapter||Pr.adapter,e)(e).then(function(r){return ii(e),r.data=oi.call(e,e.transformResponse,r),r.headers=$t.from(r.headers),r},function(r){return pl(r)||(ii(e),r&&r.response&&(r.response.data=oi.call(e,e.transformResponse,r.response),r.response.headers=$t.from(r.response.headers))),Promise.reject(r)})}const Al="1.12.2",Co={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Co[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const _l={};Co.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Al+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new je(o(i," has been removed"+(n?" in "+n:"")),je.ERR_DEPRECATED);return n&&!_l[i]&&(_l[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}},Co.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function fg(e,t,n){if(typeof e!="object")throw new je("options must be an object",je.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 je("option "+s+" must be "+l,je.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new je("Unknown option "+s,je.ERR_BAD_OPTION)}}const To={assertOptions:fg,validators:Co},fn=To.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new cl,response:new cl}}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=Kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(P.isFunction(o)?n.paramsSerializer={serialize:o}:To.assertOptions(o,{encode:fn.function,serialize:fn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),To.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.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"],m=>{delete s[m]}),n.headers=$t.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,p;if(!l){const m=[Nl.bind(this),void 0];for(m.unshift(...a),m.push(...c),p=m.length,d=Promise.resolve(n);f<p;)d=d.then(m[f++],m[f++]);return d}p=a.length;let h=n;for(;f<p;){const m=a[f++],g=a[f++];try{h=m(h)}catch(y){g.call(this,y);break}}try{d=Nl.call(this,h)}catch(m){return Promise.reject(m)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=xl(t.baseURL,t.url,t.allowAbsoluteUrls);return ll(n,t.params,t.paramsSerializer)}};P.forEach(["delete","get","head","options"],function(t){qn.prototype[t]=function(n,r){return this.request(Kn(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(Kn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}qn.prototype[t]=n(),qn.prototype[t+"Form"]=n(!0)});let pg=class Hh{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 dr(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 Hh(function(o){t=o}),cancel:t}}};function hg(e){return function(n){return e.apply(null,n)}}function mg(e){return P.isObject(e)&&e.isAxiosError===!0}const ai={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ai).forEach(([e,t])=>{ai[t]=e});function jl(e){const t=new qn(e),n=qa(qn.prototype.request,t);return P.extend(n,qn.prototype,t,{allOwnKeys:!0}),P.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return jl(Kn(e,o))},n}const yt=jl(Pr);yt.Axios=qn,yt.CanceledError=dr,yt.CancelToken=pg,yt.isCancel=pl,yt.VERSION=Al,yt.toFormData=vo,yt.AxiosError=je,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=hg,yt.isAxiosError=mg,yt.mergeConfig=Kn,yt.AxiosHeaders=$t,yt.formToJSON=e=>dl(P.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=El.getAdapter,yt.HttpStatusCode=ai,yt.default=yt;const{Axios:LT,AxiosError:$T,CanceledError:FT,isCancel:BT,CancelToken:zT,VERSION:UT,all:HT,Cancel:WT,isAxiosError:VT,spread:KT,toFormData:qT,AxiosHeaders:GT,HttpStatusCode:YT,formToJSON:XT,getAdapter:JT,mergeConfig:ZT}=yt,Ml=typeof window<"u"?window.__API_BASE_URL__:void 0,Rl=Ml?Sn(Ml):void 0;function Sn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const li=new Set;function Pl(){return ko}function Io(e){ko=e,li.forEach(t=>t(e))}function Ol(e){return li.add(e),()=>li.delete(e)}const gg=3e4,xg=9e4,qt=yt.create({...Rl?{baseURL:Rl}:{},timeout:gg,withCredentials:!0});qt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),qt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Gt(e,t){return qt.defaults.baseURL?(await qt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ci(e,t,n){return qt.defaults.baseURL?(await qt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Dl(e,t,n){return qt.defaults.baseURL?(await qt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ll(e,t){return qt.defaults.baseURL?(await qt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Yt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class $l{get baseUrl(){const t=qt.defaults.baseURL;return t?Sn(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=Sn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Pl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ol(t)}async listThreads(){const t=await Gt("/threads"),n=Yt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ci("/threads",t?{title:t}:void 0);return Yt(r)}async updateThread(t,n){const r=await Dl(`/threads/${t}`,{title:n});return Yt(r)}async deleteThread(t){const n=await Ll(`/threads/${t}`);return Yt(n)}async threadInfo(t){const n=await Gt(`/threads/${t}/info`);return Yt(n)}async listAgents(){const t=await Gt("/agents"),n=Yt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Gt(`/agents/${t}`);return Yt(n)}async getAgentSchema(t){const n=await Gt(`/agents/${t}/schema`);return Yt(n)}async getState(t){const n=await Gt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Yt(n)}async getStateHistory(t){const n=await Gt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:xg});return Yt(n)}async cancelRun(t){const n=await ci("/runs/cancel",{threadId:t});return Yt(n)}async listCheckpointSummaries(t){const n=await Gt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Yt(n);return(r==null?void 0:r.items)??[]}}const An=new $l,Fl=w.createContext(null);function yg({children:e,apiConfig:t}){const n=An;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Fl.Provider,{value:r,children:e})}function ui(){const e=w.useContext(Fl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function vg(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 bg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await vg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const wg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function di(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Sg(e,t){return`${e??""}::${t??""}`}function fr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!di(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Tg(t),i=Bl(r,0),a=kg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Bl(e,t){if(!di(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,L)=>Pg(_,L)).filter(_=>!!_),d=Pt(e.config),f=Pt(d==null?void 0:d.configurable),p=ut(f,["checkpoint_id","checkpointId"]),h=ut(f,["checkpoint_ns","checkpointNs"]),m=Pt(e==null?void 0:e.parentConfig),g=Pt(m==null?void 0:m.configurable),y=ut(g,["checkpoint_id","checkpointId"])??null,x=ut(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(_=>_.role==="user")??null,C=Pt(e==null?void 0:e.metadata),T=ut(C,["branch_label","branchLabel"]),I=ut(g,["checkpoint_id","checkpointId"]),N=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:x,interrupt:Cg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:m??null,next:N??null,tasks:l??null,values:i??null}}function Cg(e,t,n){const r=Mg(e,n);return r||jg(t,n)}function Tg(e){const t=new Map;e.forEach((o,s)=>{if(!di(o))return;const i=Bl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Sg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ng(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Ul(s.createdAt??"")-Ul(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function kg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ut(i,["label"])??ut(i,["branch_label","branchLabel"])??ut(i,["description"])??"User input",l=Eg(i,["step"]),c=ut(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Ig(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0,parentConfig:o.parentConfig??null})}return t}function Ig(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function Eg(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ng(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:Ag(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Ag(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function jg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Mg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Rg(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Dr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Dr(r.state,`${o}-state`);if(s)return s}}return null}function Rg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:m,interrupts:g,state:y!==void 0?y:f}}const n=Pt(e);if(!n)return null;const r=ut(n,["id","thread_id","taskId"])??t,o=ut(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Dr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=zl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Dr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Dr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Dr(l,t,n+1,r);if(c)return c}}return null}function zl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ut(n,["type","event","kind"]),o=ut(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=zl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Ul(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Pg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Pt(e)??{},o=Pt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=wg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Pt(o.additional_kwargs)??Pt(o.additionalKwargs),d=Pt(o.response_metadata)??Pt(o.responseMetadata),f=ut(c,["createdAt","created_at"])??ut(o,["created_at","createdAt"]),p=ut(c,["checkpointId","checkpoint_id"]),h=ut(c,["checkpointNs","checkpoint_ns"]),m=Og(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),p&&(g.checkpointId=p),h&&(g.checkpointNs=h);const y=$g(Pt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(g.artifact=y);const x=Ug(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(g.additionalKwargs=x),b&&Object.keys(b).length&&(g.responseMetadata=b);const S=Dg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(g.content=[...g.content,...S]),i==="tool"){const k=Lg(o,g.content);k&&(g.content=k)}return g}function Og(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Hl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Hl(e);return t?[t]:[]}return[]}function Hl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ut(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ut(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Wl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=ut(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Wl(e,t){var s;const n=ut(e,["id","call_id"])??t,r=ut(e,["name"])??ut(Pt(e.function),["name"]);if(!n||!r)return null;const o=zg(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Dg(e){return Array.isArray(e)?e.map((t,n)=>Wl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Lg(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function $g(e){return e?{plots:Fg(e.plots)}:void 0}function Fg(e){return Array.isArray(e)?e.map(t=>Bg(t)).filter(t=>!!t):[]}function Bg(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function zg(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Pt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ut(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Ug(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}const Vl=120;function Hg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Vl?`${n.slice(0,Vl-3)}…`:n:""}function Kl(e){return Hg(e.content)||""}function Wg(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=Kl(n);r&&t.set(n.id,r)}return t}function Vg(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=Kl(o);s&&t.set(r.checkpointId,s)}}return t}function ql(e={}){const t=w.useMemo(()=>Sn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,p]=w.useState(""),[h,m]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),N=w.useRef(null),_=w.useRef(null),L=w.useCallback(A=>{o(A)},[]),R=w.useCallback(()=>{p(""),m(null),d(null),I.current=null,N.current=null,_.current=null},[]),O=w.useCallback(()=>{var A;console.debug("[use-chat] stop() invoked - aborting stream"),(A=S.current)==null||A.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),F=w.useCallback((A,B,j)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),m(null),I.current=null,N.current=null,_.current=null;const K=new AbortController;S.current=K;let z=null,M=null,G=!1;return T.current={threadId:A.threadId??null,headers:{}},(async()=>{var se,ve,Ie,Y,U,J,$,q,Z,ue,ie,_e,He,oe,xe,Re,Ye,nt;const X=Xe=>{var qe;try{const it=JSON.parse(JSON.stringify(Xe));return(qe=it==null?void 0:it.payload)!=null&&qe.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(Je=>({...Je,data:Je!=null&&Je.data?`<base64 ${String(Je.data).length} chars>`:Je==null?void 0:Je.data}))),it}catch{return Xe}};try{let Xe={};try{if(r)Xe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,gt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let Rt=null;try{const re=(ve=window.localStorage)==null?void 0:ve.getItem("chat-settings");re&&(Rt=((Ie=JSON.parse(re))==null?void 0:Ie.apiKey)||null)}catch{}const H=We||gt||Rt||null;H&&(Xe={Authorization:`Bearer ${H}`})}}catch{}console.debug("[use-chat] POST",t+n,X(A));let qe={};if(typeof window<"u")try{const rt=(Y=window.localStorage)==null?void 0:Y.getItem("authSessionId");rt&&(qe={"X-Session-Id":rt})}catch{}const it={...Xe,...qe,...s.current},Je={"Content-Type":"application/json",Accept:"text/event-stream",...it},et=await fetch(t+n,{method:"POST",headers:Je,body:JSON.stringify(A),signal:K.signal,credentials:i});if(T.current&&(T.current.headers=it),!et.ok||!et.body){const rt=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,rt==null?void 0:rt.slice(0,500));const We=`stream ${et.status}${rt?": "+rt:""}`;throw(U=j==null?void 0:j.onConnectionError)==null||U.call(j,We),G=!0,z="error",M=We,new Error(We)}b(!0);const at=et.body.getReader(),jt=new TextDecoder;let pt="",ht=[];C.current=0,y(0);let mt=0,St=null;const Mt=()=>{if(ht.length){const rt=ht.join("");ht=[],k.current&&p(We=>We+rt)}St=null},Bt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Mt))};let Vt=Date.now();const ze=setInterval(()=>{var rt;if(Date.now()-Vt>18e5){const We="Stream idle timeout";d(We),z="error",M=We,K.abort(),(rt=j==null?void 0:j.onError)==null||rt.call(j,We)}},5e3),dn=1024*1024;try{const rt=et.headers.get("X-Thread-Id")||et.headers.get("x-thread-id"),We=et.headers.get("X-Thread-Created")||et.headers.get("x-thread-created"),gt=rt??null,Rt=String(We??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:gt}),(J=j==null?void 0:j.onOpen)==null||J.call(j,{threadId:gt,created:Rt});;){const{value:H,done:re}=await at.read();if(re)break;pt+=jt.decode(H,{stream:!0}),pt.length>dn&&(pt="",console.warn("Stream buffer reset: exceeded 1MB"));let D;for(;(D=pt.indexOf(`
34
+ `):" "+Il(i[0]):"as no adapter specified";throw new je("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:si};function ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ur(null,e)}function Al(e){return ii(e),e.headers=Ft.from(e.headers),e.data=oi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),El.getAdapter(e.adapter||Pr.adapter,e)(e).then(function(r){return ii(e),r.data=oi.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return pl(r)||(ii(e),r&&r.response&&(r.response.data=oi.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const Nl="1.12.2",Co={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Co[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const _l={};Co.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Nl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new je(o(i," has been removed"+(n?" in "+n:"")),je.ERR_DEPRECATED);return n&&!_l[i]&&(_l[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}},Co.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function fg(e,t,n){if(typeof e!="object")throw new je("options must be an object",je.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 je("option "+s+" must be "+l,je.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new je("Unknown option "+s,je.ERR_BAD_OPTION)}}const To={assertOptions:fg,validators:Co},fn=To.validators;let Gn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new cl,response:new cl}}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=qn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:To.assertOptions(o,{encode:fn.function,serialize:fn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),To.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ft.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const c=[];this.interceptors.response.forEach(function(g){c.push(g.fulfilled,g.rejected)});let d,f=0,p;if(!l){const m=[Al.bind(this),void 0];for(m.unshift(...a),m.push(...c),p=m.length,d=Promise.resolve(n);f<p;)d=d.then(m[f++],m[f++]);return d}p=a.length;let h=n;for(;f<p;){const m=a[f++],g=a[f++];try{h=m(h)}catch(y){g.call(this,y);break}}try{d=Al.call(this,h)}catch(m){return Promise.reject(m)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=qn(this.defaults,t);const n=xl(t.baseURL,t.url,t.allowAbsoluteUrls);return ll(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Gn.prototype[t]=function(n,r){return this.request(qn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(qn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Gn.prototype[t]=n(),Gn.prototype[t+"Form"]=n(!0)});let pg=class Hh{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 ur(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 Hh(function(o){t=o}),cancel:t}}};function hg(e){return function(n){return e.apply(null,n)}}function mg(e){return O.isObject(e)&&e.isAxiosError===!0}const ai={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ai).forEach(([e,t])=>{ai[t]=e});function jl(e){const t=new Gn(e),n=qa(Gn.prototype.request,t);return O.extend(n,Gn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return jl(qn(e,o))},n}const yt=jl(Pr);yt.Axios=Gn,yt.CanceledError=ur,yt.CancelToken=pg,yt.isCancel=pl,yt.VERSION=Nl,yt.toFormData=vo,yt.AxiosError=je,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=hg,yt.isAxiosError=mg,yt.mergeConfig=qn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>dl(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=El.getAdapter,yt.HttpStatusCode=ai,yt.default=yt;const{Axios:LT,AxiosError:$T,CanceledError:FT,isCancel:BT,CancelToken:zT,VERSION:UT,all:HT,Cancel:WT,isAxiosError:VT,spread:KT,toFormData:qT,AxiosHeaders:GT,HttpStatusCode:YT,formToJSON:XT,getAdapter:JT,mergeConfig:ZT}=yt,Ml=typeof window<"u"?window.__API_BASE_URL__:void 0,Rl=Ml?Cn(Ml):void 0;function Cn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const li=new Set;function Pl(){return ko}function Io(e){ko=e,li.forEach(t=>t(e))}function Ol(e){return li.add(e),()=>li.delete(e)}const gg=3e4,xg=9e4,qt=yt.create({...Rl?{baseURL:Rl}:{},timeout:gg,withCredentials:!0});qt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),qt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Gt(e,t){return qt.defaults.baseURL?(await qt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ci(e,t,n){return qt.defaults.baseURL?(await qt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Dl(e,t,n){return qt.defaults.baseURL?(await qt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ll(e,t){return qt.defaults.baseURL?(await qt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Yt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class $l{get baseUrl(){const t=qt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Pl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ol(t)}async listThreads(){const t=await Gt("/threads"),n=Yt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ci("/threads",t?{title:t}:void 0);return Yt(r)}async updateThread(t,n){const r=await Dl(`/threads/${t}`,{title:n});return Yt(r)}async deleteThread(t){const n=await Ll(`/threads/${t}`);return Yt(n)}async threadInfo(t){const n=await Gt(`/threads/${t}/info`);return Yt(n)}async listAgents(){const t=await Gt("/agents"),n=Yt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Gt(`/agents/${t}`);return Yt(n)}async getAgentSchema(t){const n=await Gt(`/agents/${t}/schema`);return Yt(n)}async getState(t){const n=await Gt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Yt(n)}async getStateHistory(t){const n=await Gt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:xg});return Yt(n)}async cancelRun(t){const n=await ci("/runs/cancel",{threadId:t});return Yt(n)}async listCheckpointSummaries(t){const n=await Gt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Yt(n);return(r==null?void 0:r.items)??[]}}const _n=new $l,Fl=w.createContext(null);function yg({children:e,apiConfig:t}){const n=_n;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Fl.Provider,{value:r,children:e})}function ui(){const e=w.useContext(Fl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function vg(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 bg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await vg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const wg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function di(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Sg(e,t){return`${e??""}::${t??""}`}function dr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!di(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Tg(t),i=Bl(r,0),a=kg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Bl(e,t){if(!di(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,L)=>Pg(_,L)).filter(_=>!!_),d=Ot(e.config),f=Ot(d==null?void 0:d.configurable),p=dt(f,["checkpoint_id","checkpointId"]),h=dt(f,["checkpoint_ns","checkpointNs"]),m=Ot(e==null?void 0:e.parentConfig),g=Ot(m==null?void 0:m.configurable),y=dt(g,["checkpoint_id","checkpointId"])??null,x=dt(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(_=>_.role==="user")??null,C=Ot(e==null?void 0:e.metadata),T=dt(C,["branch_label","branchLabel"]),I=dt(g,["checkpoint_id","checkpointId"]),N=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:x,interrupt:Cg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:m??null,next:N??null,tasks:l??null,values:i??null}}function Cg(e,t,n){const r=Mg(e,n);return r||jg(t,n)}function Tg(e){const t=new Map;e.forEach((o,s)=>{if(!di(o))return;const i=Bl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Sg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ag(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Ul(s.createdAt??"")-Ul(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function kg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=Eg(i,["step"]),c=dt(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Ig(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0,parentConfig:o.parentConfig??null})}return t}function Ig(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function Eg(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ag(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:Ng(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Ng(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function jg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function Mg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Rg(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Dr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Dr(r.state,`${o}-state`);if(s)return s}}return null}function Rg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,m=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",g=Array.isArray(d)?d:void 0,y=p.length?p[p.length-1]:void 0;return{id:h,name:m,interrupts:g,state:y!==void 0?y:f}}const n=Ot(e);if(!n)return null;const r=dt(n,["id","thread_id","taskId"])??t,o=dt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Dr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=zl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Dr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Dr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Dr(l,t,n+1,r);if(c)return c}}return null}function zl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=zl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Ul(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Pg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ot(e)??{},o=Ot(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=wg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Ot(o.additional_kwargs)??Ot(o.additionalKwargs),d=Ot(o.response_metadata)??Ot(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),p=dt(c,["checkpointId","checkpoint_id"]),h=dt(c,["checkpointNs","checkpoint_ns"]),m=Og(o.content),g={id:l,role:i,content:m};f&&(g.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(g.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(g.model=String(d.model_name)),!g.model&&typeof o.model=="string"&&(g.model=o.model),p&&(g.checkpointId=p),h&&(g.checkpointNs=h);const y=$g(Ot(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(g.artifact=y);const x=Ug(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;x&&Object.keys(x).length&&(g.additionalKwargs=x),b&&Object.keys(b).length&&(g.responseMetadata=b);const S=Dg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(g.content=[...g.content,...S]),i==="tool"){const k=Lg(o,g.content);k&&(g.content=k)}return g}function Og(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Hl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Hl(e);return t?[t]:[]}return[]}function Hl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=dt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=dt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Wl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=dt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Wl(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Ot(e.function),["name"]);if(!n||!r)return null;const o=zg(e.args??e.arguments??((s=Ot(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Dg(e){return Array.isArray(e)?e.map((t,n)=>Wl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Lg(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function $g(e){return e?{plots:Fg(e.plots)}:void 0}function Fg(e){return Array.isArray(e)?e.map(t=>Bg(t)).filter(t=>!!t):[]}function Bg(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function zg(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Ot(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Ug(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}const Vl=120;function Hg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>Vl?`${n.slice(0,Vl-3)}…`:n:""}function Kl(e){return Hg(e.content)||""}function Wg(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=Kl(n);r&&t.set(n.id,r)}return t}function Vg(e){var n;const t=new Map;for(const r of e){if(!r.checkpointId)continue;const o=(n=r.messages)==null?void 0:n.find(s=>s.role==="user");if(o){const s=Kl(o);s&&t.set(r.checkpointId,s)}}return t}function ql(e={}){const t=w.useMemo(()=>Cn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,p]=w.useState(""),[h,m]=w.useState(null),[g,y]=w.useState(0),[x,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),N=w.useRef(null),_=w.useRef(null),L=w.useCallback(R=>{o(R)},[]),B=w.useCallback(()=>{p(""),m(null),d(null),I.current=null,N.current=null,_.current=null},[]),G=w.useCallback(()=>{var R;console.debug("[use-chat] stop() invoked - aborting stream"),(R=S.current)==null||R.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),V=w.useCallback((R,M,A)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),m(null),I.current=null,N.current=null,_.current=null;const F=new AbortController;S.current=F;let D=null,P=null,z=!1;return T.current={threadId:R.threadId??null,headers:{}},(async()=>{var ne,ye,Te,q,U,J,$,Y,Z,de,oe,_e,ze,se,me,Re,Ve,ut;const X=Ke=>{var qe;try{const Qe=JSON.parse(JSON.stringify(Ke));return(qe=Qe==null?void 0:Qe.payload)!=null&&qe.files_info&&Array.isArray(Qe.payload.files_info)&&(Qe.payload.files_info=Qe.payload.files_info.map(Ge=>({...Ge,data:Ge!=null&&Ge.data?`<base64 ${String(Ge.data).length} chars>`:Ge==null?void 0:Ge.data}))),Qe}catch{return Ke}};try{let Ke={};try{if(r)Ke={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const We=window.__AUTH_TOKEN__,pt=((ne=window.localStorage)==null?void 0:ne.getItem("authToken"))||null;let Pt=null;try{const H=(ye=window.localStorage)==null?void 0:ye.getItem("chat-settings");H&&(Pt=((Te=JSON.parse(H))==null?void 0:Te.apiKey)||null)}catch{}const Ye=We||pt||Pt||null;Ye&&(Ke={Authorization:`Bearer ${Ye}`})}}catch{}console.debug("[use-chat] POST",t+n,X(R));let qe={};if(typeof window<"u")try{const tt=(q=window.localStorage)==null?void 0:q.getItem("authSessionId");tt&&(qe={"X-Session-Id":tt})}catch{}const Qe={...Ke,...qe,...s.current},Ge={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},et=await fetch(t+n,{method:"POST",headers:Ge,body:JSON.stringify(R),signal:F.signal,credentials:i});if(T.current&&(T.current.headers=Qe),!et.ok||!et.body){const tt=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,tt==null?void 0:tt.slice(0,500));const We=`stream ${et.status}${tt?": "+tt:""}`;throw(U=A==null?void 0:A.onConnectionError)==null||U.call(A,We),z=!0,D="error",P=We,new Error(We)}b(!0);const st=et.body.getReader(),Mt=new TextDecoder;let gt="",Ct=[];C.current=0,y(0);let it=0,St=null;const Rt=()=>{if(Ct.length){const tt=Ct.join("");Ct=[],k.current&&p(We=>We+tt)}St=null},zt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Rt))};let nn=Date.now();const Le=setInterval(()=>{var tt;if(Date.now()-nn>18e5){const We="Stream idle timeout";d(We),D="error",P=We,F.abort(),(tt=A==null?void 0:A.onError)==null||tt.call(A,We)}},5e3),Sn=1024*1024;try{const tt=et.headers.get("X-Thread-Id")||et.headers.get("x-thread-id"),We=et.headers.get("X-Thread-Created")||et.headers.get("x-thread-created"),pt=tt??null,Pt=String(We??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(J=A==null?void 0:A.onOpen)==null||J.call(A,{threadId:pt,created:Pt});;){const{value:Ye,done:H}=await st.read();if(H)break;gt+=Mt.decode(Ye,{stream:!0}),gt.length>Sn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let j;for(;(j=gt.indexOf(`
36
36
 
37
- `))>=0;){const Q=pt.slice(0,D);pt=pt.slice(D+2);const ne=qg(Q);if(!ne)continue;let me;try{me=JSON.parse(ne)}catch{console.debug("[use-chat] malformed SSE:",ne.slice(0,200));continue}const ke=Kg(me)?me.data:me;Vt=Date.now();const Pe=ke.seq;if(Pe!==void 0){if(Pe<=mt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Pe,lastProcessedSeq:mt,type:ke.type});continue}mt>0&&Pe>mt+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:mt,to:Pe})),mt=Pe,C.current=Pe,y(Pe)}if(ke.type==="checkpoint")I.current=ke.checkpointId??null,N.current=ke.checkpointNs??null,m(ke.checkpointId??null);else if(ke.type==="state_history"){_.current=ke;try{const Ue=fr(ke).latest;Ue&&(I.current=Ue.checkpointId??null,N.current=Ue.checkpointNs??null,m(Ue.checkpointId??null))}catch(De){console.warn("[use-chat] Failed to hydrate state_history payload",De)}}try{B==null||B(ke)}catch(De){console.error("[use-chat] Error in onEvent callback:",De,"for event:",ke.type)}if(ke.type==="message.delta"){const De=ke.delta.filter(Ue=>Ue.type==="text").map(Ue=>Ue.text).join("");De&&e.autoAppendAssistant!==!1&&(ht.push(De),Bt())}else if(ke.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(q=j==null?void 0:j.onHeartbeat)==null||q.call(j,ke)}catch(De){console.warn("[use-chat] heartbeat callback failed",De)}}else if(St!==null&&cancelAnimationFrame(St),Mt(),ke.type==="checkpoint")m(ke.checkpointId);else if(ke.type==="error"){const De=ke;if(d(De.message),z="error",M=De.message,De.error_type==="auth_error"||De.code==="TOKEN_EXPIRED"||((Z=De.message)==null?void 0:Z.includes("token"))||((ue=De.message)==null?void 0:ue.includes("401"))||((ie=De.message)==null?void 0:ie.includes("unauthorized"))||((_e=De.message)==null?void 0:_e.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",De.message);try{(He=j==null?void 0:j.onAuthError)==null||He.call(j,De.message)}catch(Kt){console.warn("[use-chat] onAuthError handler failed",Kt)}K.abort()}}}}Mt(),z===null&&!K.signal.aborted&&(z="complete")}catch(rt){if(rt.name==="AbortError")z=z??"aborted";else{const We=rt.message||String(rt);z="error",M=We,d(We),(oe=j==null?void 0:j.onError)==null||oe.call(j,We)}}finally{try{await at.cancel()}catch{}finally{(xe=at.releaseLock)==null||xe.call(at)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(ze)}}catch(Xe){if(Xe.name==="AbortError")z=z??"aborted";else{const qe=Xe.message||String(Xe);z="error",M=qe,d(qe),(Re=j==null?void 0:j.onError)==null||Re.call(j,qe),G||((Ye=j==null?void 0:j.onConnectionError)==null||Ye.call(j,qe),G=!0)}}finally{const Xe=C.current,qe=I.current,it=N.current,Je=_.current,et=z??(K.signal.aborted?"aborted":M?"error":"complete");try{(nt=j==null?void 0:j.onClosed)==null||nt.call(j,{reason:et,lastSeq:Xe,lastCheckpointId:qe,lastCheckpointNs:it,lastStateHistory:Je,error:M})}catch(at){console.warn("[use-chat] onClosed callback failed",at)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>K.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var A;k.current=!1,(A=S.current)==null||A.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:g,connected:x,stream:F,stop:O,clear:R,setToken:L}}function Kg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function qg(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
- `)}const Gg=["message.start","message.delta","message.end","progress"],Yg=["tool.start","tool.end"],Xg=["thread_info","checkpoint","branch"],Jg=["error","interrupt","heartbeat","state_history","cancelled"],Zg=[...Gg,...Yg,...Xg,...Jg],Qg=new Set(Zg);function ex(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return Qg.has(t)}const Gl=200;function tx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),m=w.useRef(null),g=w.useCallback(R=>{try{const O=globalThis.structuredClone;if(typeof O=="function")return O(R)}catch{}try{return JSON.parse(JSON.stringify(R))}catch{return R}},[]),y=w.useCallback((R,O)=>{if(!R)return;const F=p.current.get(R)??[],A=g(O),B=F.length>=Gl?[...F.slice(F.length-Gl+1),A]:[...F,A];p.current.set(R,B)},[g]),x=w.useCallback(R=>{R&&p.current.set(R,[])},[]),b=w.useCallback(R=>{const O=R??f.current;if(!O)return;const F=p.current.get(O);F!=null&&F.length&&F.forEach(A=>{try{n(A)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),S=w.useCallback(R=>{var A,B,j,K,z;const O=R.seq??null;if(O!==null){const M=d.current;if(M!==null){if(O<=M)return;O>M+1&&(s==null||s({from:M,to:O}))}d.current=O}if(R.type==="thread_info"){f.current=R.threadId,h.current&&(h.current.threadIdGuess=R.threadId),m.current=R,x(R.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",R);try{t(R)}catch(M){console.error("[useChatStreamingService] Error in onThreadInfo handler:",M)}return}if(R.type==="heartbeat"){try{c==null||c(R)}catch(M){console.error("[useChatStreamingService] Error in onHeartbeat handler:",M)}return}if(R.type==="error"){const M=R;if(M.error_type==="auth_error"||M.code==="TOKEN_EXPIRED"||((A=M.message)==null?void 0:A.includes("token"))||((B=M.message)==null?void 0:B.includes("401"))||((j=M.message)==null?void 0:j.includes("unauthorized"))||((K=M.message)==null?void 0:K.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",M.message);try{l==null||l(M.message)}catch(X){console.warn("[useChatStreamingService] onAuthError handler failed",X)}}}const F=R.threadId??(R.type==="state_history"?R.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.threadIdGuess)??null;if(R.type==="state_history"){f.current=F??f.current;try{r==null||r(R)}catch(M){console.error("[useChatStreamingService] onStateHistory handler failed",M)}}if(ex(R)){R.type==="checkpoint"||R.type==="state_history"?x(F??null):y(F??null,R);try{n(R)}catch(M){console.error("[useChatStreamingService] Error in onMessageEvent handler:",M)}return}try{o==null||o(R)}catch(M){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",M)}},[y,x,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:N}=ql({baseUrl:e,token:void 0}),_=w.useCallback((R,O)=>{d.current=null,m.current=null,f.current=R.threadId??null,h.current={request:R,callbacks:O,manualStop:!1,threadIdGuess:R.threadId??null},k(R,S,{onOpen:O==null?void 0:O.onOpen,onError:F=>{var A;(A=O==null?void 0:O.onError)==null||A.call(O,F)},onGap:(O==null?void 0:O.onGap)??s,onConnectionError:F=>{var A;a==null||a(F),(A=O==null?void 0:O.onConnectionError)==null||A.call(O,F)},onAuthError:F=>{var A;l==null||l(F),(A=O==null?void 0:O.onAuthError)==null||A.call(O,F)},onHeartbeat:F=>{var A;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(A=O==null?void 0:O.onHeartbeat)==null||A.call(O,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var K,z,M,G;const A=((K=h.current)==null?void 0:K.manualStop)??!1,B=f.current??((z=h.current)==null?void 0:z.threadIdGuess)??((M=F.lastStateHistory)==null?void 0:M.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&A)&&x(B);const j={...F,threadId:B,threadInfo:m.current,manualStop:A};try{i==null||i(j)}catch(X){console.warn("[useChatStreamingService] onStreamClosed handler failed",X)}try{(G=O==null?void 0:O.onClosed)==null||G.call(O,j)}catch(X){console.warn("[useChatStreamingService] downstream onClosed handler failed",X)}h.current&&(h.current=null)}})},[x,S,l,a,c,s,i,k]),L=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:_,stop:L,isStreaming:T,error:I,setAuthToken:N,replayBufferedEvents:b}),[_,L,T,I,N,b])}const Ct=[];for(let e=0;e<256;++e)Ct.push((e+256).toString(16).slice(1));function nx(e,t=0){return(Ct[e[t+0]]+Ct[e[t+1]]+Ct[e[t+2]]+Ct[e[t+3]]+"-"+Ct[e[t+4]]+Ct[e[t+5]]+"-"+Ct[e[t+6]]+Ct[e[t+7]]+"-"+Ct[e[t+8]]+Ct[e[t+9]]+"-"+Ct[e[t+10]]+Ct[e[t+11]]+Ct[e[t+12]]+Ct[e[t+13]]+Ct[e[t+14]]+Ct[e[t+15]]).toLowerCase()}let fi;const rx=new Uint8Array(16);function ox(){if(!fi){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");fi=crypto.getRandomValues.bind(crypto)}return fi(rx)}const Yl={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function sx(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??ox();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,nx(r)}function ix(e,t,n){return Yl.randomUUID&&!e?Yl.randomUUID():sx(e)}const ax={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function lx(e,t){var n;switch(t.type){case"reset":return{messages:pi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,pendingInterrupt:null};case"seed":{const r=pi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[]};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=pi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Jl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Jl(o,s),e):e}case"interrupt_response":return{...e,messages:Zl(e.messages),pendingInterrupt:null};default:return e}}function Xl(e=[]){const[t,n]=w.useReducer(lx,{...ax,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.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=w.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=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Jl(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=gx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const c={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,c]}}if(t.type==="message.delta"){const i=e.assemblingId??Ql(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:rc(c.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof f.lastSeq=="number"&&p<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:f.lastSeq}),e;const{newParts:h,newMeta:m,changed:g}=px(c.content,t.delta,f,p);if(!g)return e;const y={...c,content:h},x=No(a,l,y),b={...d,[i]:m};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??Ql(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(c=>c.id===i&&c.role==="assistant");if(l>=0){const c=a[l];if(!((n=c.content)==null?void 0:n.some(f=>{var p;return(f==null?void 0:f.type)==="text"&&((p=f.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=c.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=ec(t),a=i[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),l=t.name??t.tool??"tool";!a&&i.length===0&&i.push(`${l}-${Date.now()}`);const c=i.length?i:a?[a]:[],d=c[0]??`${l}-${Date.now()}`,f={type:"tool_call",id:d,name:l,args:t.args},p={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,title:`Invoking ${l}`,metadata:{args:t.args}},h=e.toolStreamingMessageId;if(!h){const y={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...ux(void 0,c.length?c:[d],l,t.args),toolStreaming:!0}},x=dx(y,c.length?c:[d]),b=[...e.messages,y],S=Ao(b,y.id,p);return{...e,messages:S,toolIndex:tc(e.toolIndex,y.id,x),toolStreamingMessageId:y.id,toolStreamingStack:nc(e.toolStreamingStack??[],a??d)}}const m=Ao(e.messages,h,p);return{...e,messages:m,toolIndex:tc(e.toolIndex,h,c),toolStreamingStack:nc(e.toolStreamingStack??[],a??d)}}if(t.type==="tool.end"){const i=ec(t);if(!i.length&&!(typeof t.id=="string"&&t.id))return e;const a=i[0]??(typeof t.id=="string"?t.id:null);if(!a)return e;const l=e.toolStreamingStack??[],c=l[0]??null,d=fx(l,a),f=d[0]?e.toolIndex[d[0]]:null,p=e.toolStreamingMessageId,h=c===a,m=t.name??((s=e.messages.find(S=>S.id===p))==null?void 0:s.name)??"tool",g=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),y={type:"tool.end",toolId:a,toolName:m,title:`${m} completed`,content:g==null?void 0:g.slice(0,200)};let x=e.messages;if(p&&(x=Ao(x,p,y)),h&&p){const S=x.findIndex(k=>k.id===p);if(S>=0){const k=x[S],T={type:"text",text:(()=>{if(typeof t.output=="string"){const N=t.output.trim();try{return N}catch{return N}}return JSON.stringify(t.output??"")})()},I={...k,content:[T],artifact:t.artifact??k.artifact,additionalKwargs:{...k.additionalKwargs??{}}};x=No(x,S,I)}}return{...e,messages:x,toolStreamingMessageId:h?f:p,toolStreamingStack:d}}if(t.type==="progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"progress",content:t.content??null},l=Ao(e.messages,i,a),c=l.findIndex(m=>m.id===i);if(c===-1)return e;const d=l[c],f={...d.additionalKwargs??{},toolStreaming:!0},p={...d,additionalKwargs:f},h=No(l,c,p);return{...e,messages:h}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=mx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="state_history"){const i=fr(t),a=i.interrupt,l=i.latest,c=a===null?Zl(e.messages):e.messages;return{...e,messages:c,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function pi(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function No(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Zl(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Ql(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function ec(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function cx(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function ux(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};for(const l of t)s(l);const i=Array.from(o),a={};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function dx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=cx(e);for(const o of r)n.add(o);return Array.from(n)}function tc(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function Ao(e,t,n){const r=e.findIndex(c=>c.id===t);if(r===-1)return e;const o=e[r],s=[...e],i={...o.additionalKwargs??{}},a=Array.isArray(i.toolProgress)?[...i.toolProgress]:[],l={id:ix(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function nc(e,t){return e.includes(t)?e:[...e,t]}function fx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function rc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function px(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??rc(e);let l="",c=e.slice();if(s){const f=hx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",m={...p,text:h+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function oc(e){return e.replace(/\s+/g," ").trim()}function hx(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=oc(e),o=oc(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 mx(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 No(e,r,s)}return e}function gx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const sc=w.createContext(null),ic=w.createContext(null),ac=w.createContext(null);w.createContext(!1);function xx({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l}){const{api:c,baseUrl:d}=ui(),f=w.useMemo(()=>Sn(d),[d]),[p,h]=w.useState([]),[m,g]=w.useState(t),[y,x]=w.useState(!1),[b,S]=w.useState(null),[k,C]=w.useState(!1),[T,I]=w.useState(null),{state:N,seed:_,prepend:L,pushUser:R,onEvent:O}=Xl(),[F,A]=w.useState(!1),[B,j]=w.useState(!1),[K,z]=w.useState(null),[M,G]=w.useState([]),[X,se]=w.useState([]),[ve,Ie]=w.useState(!1),Y=w.useMemo(()=>Vg(M),[M]),U=w.useRef(m),J=w.useRef(null),$=w.useRef(null),q=w.useRef(null),Z=w.useRef(null),ue=w.useRef(!1),ie=w.useRef(null),_e=w.useRef(new Map),He=w.useRef(new Map);w.useEffect(()=>{U.current=m},[m]);const oe=w.useCallback(async()=>{x(!0),S(null);try{const H=await c.listThreads();h(H??[])}catch(H){const re=String(H);S(re),s==null||s(re)}finally{x(!1)}},[c,s]),xe=w.useCallback(H=>{if(!(H!=null&&H.threadId))return;const re={threadId:H.threadId,title:H.title||`Thread ${H.threadId.slice(0,8)}`,createdAt:H.createdAt||new Date().toISOString(),updatedAt:H.updatedAt||new Date().toISOString(),messageCount:H.messageCount??1};h(D=>{let Q=!1;const ne=D.map(me=>me.threadId===re.threadId?(Q=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",re.threadId),{...me,title:re.title??me.title,updatedAt:re.updatedAt??me.updatedAt,messageCount:re.messageCount??me.messageCount}):me);return Q?ne:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",re.threadId),[re,...D])})},[]),Re=w.useCallback(H=>{const re=H.threadId??U.current;if(!re||U.current&&U.current!==re)return;const{checkpoints:D,timeline:Q}=fr(H);if(!D.length)return;const ne=D.find(me=>me.messages&&me.messages.length>0)??D.find(me=>!!me.checkpointId)??D[0];_((ne==null?void 0:ne.messages)??[],{checkpointId:(ne==null?void 0:ne.checkpointId)??null,checkpointNs:(ne==null?void 0:ne.checkpointNs)??null}),se(Q),G(D),A(!!(ne!=null&&ne.nextCursor)),z((ne==null?void 0:ne.nextCursor)??null),ie.current=`${re}:latest`,$.current=null,q.current=null},[_]),Ye=w.useCallback(H=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",H.threadId),xe(H),U.current!==H.threadId&&((H.created??!U.current)&&($.current=H.threadId),q.current=H.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),g(H.threadId))},[xe]),{startStream:nt,stop:Xe,isStreaming:qe,error:it,setAuthToken:Je}=tx({baseUrl:f,onThreadInfo:Ye,onMessageEvent:O,onStateHistory:Re,onUnhandledEvent:H=>{console.warn("[ChatSessionProvider] Unhandled event:",H.type)},onAuthError:i,onConnectionError:l}),et=w.useCallback(async H=>{try{const re=await c.createThread(H);return g(re.threadId),await oe(),re.threadId}catch(re){return s==null||s(String(re)),null}},[c,oe,s]),at=w.useCallback(async H=>{const re=p;h(Q=>Q.filter(ne=>ne.threadId!==H));const D=new AbortController;He.current.set(H,D);try{await c.deleteThread(H),U.current===H&&(g(null),_([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",H)}catch(Q){console.error("[ChatSessionProvider] Delete failed, restoring thread:",H,Q),h(re),s==null||s(`Failed to delete thread: ${String(Q)}`)}finally{He.current.delete(H)}},[p,c,_,s]),jt=w.useCallback(async(H,re)=>{try{await c.updateThread(H,re),await oe()}catch(D){s==null||s(String(D))}},[c,oe,s]),pt=w.useCallback(async(H,re)=>{if(!H)return;const D=`${H}:${re??"latest"}`,Q=_e.current.get(D);if(Q)return Q;const ne=(async()=>{const me=H;C(!0),I(null);try{const ke=await c.getStateHistory({threadId:me,checkpointId:re||void 0});if(U.current!==me){console.log(`[ChatSessionProvider] Thread changed during load (was ${me}, now ${U.current}), discarding stale data`);return}const{checkpoints:Pe,timeline:De}=fr(ke),Ue=Pe.find(Kt=>Kt.messages&&Kt.messages.length>0)??(re?Pe.find(Kt=>Kt.checkpointId===re):null)??Pe[0];_((Ue==null?void 0:Ue.messages)??[],{checkpointId:(Ue==null?void 0:Ue.checkpointId)??null,checkpointNs:(Ue==null?void 0:Ue.checkpointNs)??null}),se(De),G(Pe),A(!!(Ue!=null&&Ue.nextCursor)),z((Ue==null?void 0:Ue.nextCursor)??null)}catch(ke){if(U.current===me){const Pe=String(ke);I(Pe),s==null||s(Pe)}}finally{C(!1)}})();_e.current.set(D,ne);try{await ne}finally{_e.current.delete(D)}return U.current===H&&(ie.current=D),ne},[c,_,s]),ht=w.useCallback(async(H,re)=>{Z.current=H;try{await pt(H,re)}finally{Z.current===H&&(Z.current=null)}},[pt]);w.useEffect(()=>{if(!o||!m||k||qe)return;if($.current===m){$.current=null,J.current=m;return}if(q.current===m){J.current=m;return}if(Z.current===m){Z.current=null,J.current=m;return}if(J.current===m)return;J.current=m;const H=!ue.current&&!!n&&m===t;let re;H&&n?(re=n,ue.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",re,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const D=`${m}:${re??"latest"}`;ie.current!==D&&ht(m,re)},[o,m,n,r,t,k,qe,ht]);const mt=w.useCallback(async(H,re)=>{const D=U.current;if(!D)return;const Q=D;Ie(!0);try{const ne=await c.getStateHistory({threadId:Q,checkpointId:H,checkpointNs:re??void 0});if(U.current!==Q){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${Q}, now ${U.current}), discarding stale data`);return}const{checkpoints:me,timeline:ke}=fr(ne),Pe=me.find(De=>De.checkpointId===H&&(re?De.checkpointNs===re:!0));if(!Pe){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:H,checkpointNs:re});return}se(ke),G(me),_(Pe.messages??[],{checkpointId:Pe.checkpointId??null,checkpointNs:Pe.checkpointNs??null})}catch(ne){U.current===Q&&(s==null||s(String(ne)))}finally{Ie(!1)}},[c,_,s]),St=w.useCallback((H,re)=>{_(N.messages,{checkpointId:H??null,checkpointNs:re??null})},[_,N.messages]),Mt=w.useCallback(async()=>{U.current&&await ht(U.current)},[ht]),Bt=w.useCallback(async()=>{if(!U.current||!K)return;const H=U.current;j(!0);try{const re=await c.getStateHistory({threadId:H,checkpointId:K});if(U.current!==H)return;const{checkpoints:D}=fr(re);if(D.length>0){const Q=D[D.length-1];L((Q==null?void 0:Q.messages)??[]),A(!!(Q!=null&&Q.nextCursor)),z((Q==null?void 0:Q.nextCursor)??null)}}catch(re){U.current===H&&(s==null||s(String(re)))}finally{j(!1)}},[c,K,L,s]),Vt=w.useCallback(async()=>{_([],{}),g(null),Xe(),G([]),se([]),A(!1),z(null),C(!1),Ie(!1),j(!1),I(null);try{await c.getAgent("default")}catch(H){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",H)}},[_,Xe,c]),ze=w.useCallback(async(H,re,D)=>{const Q=U.current;if(!Q)throw new Error("No active thread to handle interrupt");const ne=re?D??!0:!1;try{const me={threadId:Q,checkpointId:N.lastCheckpointId??void 0,checkpointNs:N.lastCheckpointNs??void 0,command:{kind:"resume",value:ne}};nt(me)}catch(me){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${H}:`,me),me}},[N.lastCheckpointId,N.lastCheckpointNs,nt]);w.useEffect(()=>{oe()},[oe]),w.useEffect(()=>{a==null||a(m)},[m,a]);const dn=w.useCallback(async(H,re)=>{let D=U.current;const Q=(H==null?void 0:H.text)??"",ne=(H==null?void 0:H.attachments)??[],me=(Q==null?void 0:Q.trim())??"",ke={...(H==null?void 0:H.payload)??{}},Pe=Array.isArray(ke.messages)?ke.messages:void 0;Pe&&delete ke.messages;const De=!!(Pe&&Pe.length);if(!D&&!me&&ne.length===0&&!De)return;if(!D){const ae=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);D=`${ae}${be}`,$.current=D,g(D)}const{contentParts:Ue,filesInfo:Kt}=await bg(c,ne),Nn=[...Ue];me&&Nn.push({type:"text",text:Q});const ar=re==null?void 0:re.originalMessageId,Nr=!!(re!=null&&re.edit&&ar),fo=!De&&Nn.length>0;let Un=null;fo&&(Un={id:Nr?ar:`msg-${Date.now()}`,role:"user",content:Nn,createdAt:new Date().toISOString()},Nr||R(Un));const lr=De?Pe:Un?[Un]:[],E={...ke,...Kt.length?{files_info:Kt}:{}};lr.length?E.messages=lr:"messages"in E||(E.messages=[]);const V={threadId:D,payload:E,checkpointId:(re==null?void 0:re.checkpointId)??N.lastCheckpointId??void 0,checkpointNs:(re==null?void 0:re.checkpointNs)??N.lastCheckpointNs??void 0,edit:!!(re!=null&&re.edit),timelineCheckpoints:X};nt(V)},[c,R,N,nt,X]),rt=w.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:g,isLoading:y,error:b,actions:{createThread:et,deleteThread:at,renameThread:jt,refreshThreads:oe}}),[p,m,y,b,et,at,jt,oe]),We=w.useMemo(()=>{const H=N.assemblingId??null;return H?{assemblingMessageId:H}:null},[N.assemblingId]),gt=w.useMemo(()=>({threadId:m,messages:N.messages,interrupt:null,checkpoint:{id:N.lastCheckpointId??null,namespace:N.lastCheckpointNs??null},checkpoints:M,timelineCheckpoints:X,metadata:We,isLoading:k,isHistoryLoading:B,isLoadingCheckpoint:ve,error:T,hasMore:F,loadOlder:Bt,clearState:Vt,navigateToCheckpoint:mt,setCurrentCheckpointId:St,returnToLatest:Mt,loadThread:ht,clearThread:Vt,respondToInterrupt:ze,messagePreviews:Y}),[m,N,M,X,k,B,ve,T,F,Bt,Vt,mt,St,Mt,ht,ze,Y,We]),Rt=w.useMemo(()=>({isStreaming:qe,error:it,connectionState:qe?"connected":"idle",submit:dn,send:dn,stop:Xe,setAuthToken:Je}),[qe,it,dn,Xe,Je]);return u.jsx(sc.Provider,{value:rt,children:u.jsx(ic.Provider,{value:gt,children:u.jsx(ac.Provider,{value:Rt,children:e})})})}function _o(){const e=w.useContext(sc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(ic);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function lc(){const e=w.useContext(ac);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Mo({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(yg,{apiConfig:t,children:u.jsx(xx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function te(...e){return Vh.twMerge(Wh.clsx(e))}const yx=po.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ze=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return u.jsx(i,{className:te(yx({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";const cc=v.forwardRef(({className:e,...t},n)=>u.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}));cc.displayName="Textarea";function uc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[g,y]=w.useState(e),x=(m?i:g)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{m||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,x]);const N=w.useCallback((B,{fromUser:j})=>{m||y(B),j&&(a==null||a(B))},[m,a]),_=w.useCallback(async B=>{B&&B.preventDefault();const j=(x??"").trim();if(!j&&!h)return;const K=++C.current;T.current={id:K,shouldClear:!0},S(()=>{var z,M,G;try{const X=l(j);X&&typeof X.then=="function"?X.then(()=>{var se,ve;((se=T.current)==null?void 0:se.id)===K&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ve=T.current)==null?void 0:ve.id)===K&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===K&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===K&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((M=T.current)==null?void 0:M.id)===K&&(T.current=null))}catch{((G=T.current)==null?void 0:G.id)===K&&(T.current=null)}})},[x,l,h,m,a]),L=w.useCallback(B=>{const j=B.target.value;N(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),R=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),_()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[_,t,c]),A=`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))]":""} ${p}`;return u.jsx("form",{onSubmit:B=>void _(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(cc,{ref:k,value:x,onChange:L,onKeyDown:R,placeholder:t?"Edit your message...":n,className:A,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Ze,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(le.Square,{size:16})}):u.jsx(Ze,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!h||b,children:u.jsx(le.Send,{size:16})})})]})})}const vx=w.memo(uc);function fe(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 dc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function hi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=dc(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():dc(e[o],null)}}}}function Fe(...e){return v.useCallback(hi(...e),e)}function bx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Cn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:p,children:h,...m}=f,g=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var g;const h=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,wx(o,...t)]}function wx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Sx=v[" useInsertionEffect ".trim().toString()]||Tt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Cx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=Tx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function Cx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Sx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Tx(e){return typeof e=="function"}var kx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ae=kx.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function fc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function mi(e){const t=e+"CollectionProvider",[n,r]=Cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Wn.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,S=s(a,x),k=Fe(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Wn.createSlot(d),h=w.forwardRef((g,y)=>{const{scope:x,children:b,...S}=g,k=w.useRef(null),C=Fe(y,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:b})});h.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var Ix=v.createContext(void 0);function Ro(e){const t=v.useContext(Ix);return e||t||"ltr"}function kt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Ex(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);v.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 Nx="DismissableLayer",gi="dismissableLayer.update",Ax="dismissableLayer.pointerDownOutside",_x="dismissableLayer.focusOutside",pc,hc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(hc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=Fe(t,I=>f(I)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),b=d?g.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,C=Rx(I=>{const N=I.target,_=[...c.branches].some(L=>L.contains(N));!k||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=Px(I=>{const N=I.target;[...c.branches].some(L=>L.contains(N))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return Ex(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(pc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),mc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=pc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),mc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(gi,I),()=>document.removeEventListener(gi,I)},[]),u.jsx(Ae.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:fe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:fe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:fe(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=Nx;var jx="DismissableLayerBranch",Mx=v.forwardRef((e,t)=>{const n=v.useContext(hc),r=v.useRef(null),o=Fe(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ae.div,{...e,ref:o})});Mx.displayName=jx;function Rx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){gc(Ax,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Px(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&gc(_x,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 mc(){const e=new CustomEvent(gi);document.dispatchEvent(e)}function gc(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?fc(o,s):o.dispatchEvent(s)}var xi=0;function yi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??xc()),document.body.insertAdjacentElement("beforeend",e[1]??xc()),xi++,()=>{xi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),xi--}},[])}function xc(){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 vi="focusScope.autoFocusOnMount",bi="focusScope.autoFocusOnUnmount",yc={bubbles:!1,cancelable:!0},Ox="FocusScope",Oo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=kt(o),d=kt(s),f=v.useRef(null),p=Fe(t,g=>l(g)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:_n(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||_n(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&_n(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){wc.add(h);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(vi,yc);a.addEventListener(vi,c),a.dispatchEvent(x),x.defaultPrevented||(Dx(zx(vc(a)),{select:!0}),document.activeElement===g&&_n(a))}return()=>{a.removeEventListener(vi,c),setTimeout(()=>{const x=new CustomEvent(bi,yc);a.addEventListener(bi,d),a.dispatchEvent(x),x.defaultPrevented||_n(g??document.body,{select:!0}),a.removeEventListener(bi,d),wc.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(g=>{if(!n&&!r||h.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const b=g.currentTarget,[S,k]=Lx(b);S&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&_n(S,{select:!0})):g.shiftKey&&x===S&&(g.preventDefault(),n&&_n(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,h.paused]);return u.jsx(Ae.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});Oo.displayName=Ox;function Dx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(_n(r,{select:t}),document.activeElement!==n)return}function Lx(e){const t=vc(e),n=bc(t,e),r=bc(t.reverse(),e);return[n,r]}function vc(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 bc(e,t){for(const n of e)if(!$x(n,{upTo:t}))return n}function $x(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 Fx(e){return e instanceof HTMLInputElement&&"select"in e}function _n(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Fx(e)&&t&&e.select()}}var wc=Bx();function Bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Sc(e,t),e.unshift(t)},remove(t){var n;e=Sc(e,t),(n=e[0])==null||n.resume()}}}function Sc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function zx(e){return e.filter(t=>t.tagName!=="A")}var Ux=v[" useId ".trim().toString()]||(()=>{}),Hx=0;function Tn(e){const[t,n]=v.useState(Ux());return Tt(()=>{n(r=>r??String(Hx++))},[e]),t?`radix-${t}`:""}const Wx=["top","right","bottom","left"],jn=Math.min,zt=Math.max,Do=Math.round,Lo=Math.floor,pn=e=>({x:e,y:e}),Vx={left:"right",right:"left",bottom:"top",top:"bottom"},Kx={start:"end",end:"start"};function wi(e,t,n){return zt(e,jn(t,n))}function kn(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Si(e){return e==="x"?"y":"x"}function Ci(e){return e==="y"?"height":"width"}const qx=new Set(["top","bottom"]);function hn(e){return qx.has(In(e))?"y":"x"}function Ti(e){return Si(hn(e))}function Gx(e,t,n){n===void 0&&(n=!1);const r=hr(e),o=Ti(e),s=Ci(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=$o(i)),[i,$o(i)]}function Yx(e){const t=$o(e);return[ki(e),t,ki(t)]}function ki(e){return e.replace(/start|end/g,t=>Kx[t])}const Cc=["left","right"],Tc=["right","left"],Xx=["top","bottom"],Jx=["bottom","top"];function Zx(e,t,n){switch(e){case"top":case"bottom":return n?t?Tc:Cc:t?Cc:Tc;case"left":case"right":return t?Xx:Jx;default:return[]}}function Qx(e,t,n,r){const o=hr(e);let s=Zx(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ki)))),s}function $o(e){return e.replace(/left|right|bottom|top/g,t=>Vx[t])}function ey(e){return{top:0,right:0,bottom:0,left:0,...e}}function kc(e){return typeof e!="number"?ey(e):{top:e,right:e,bottom:e,left:e}}function Fo(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 Ic(e,t,n){let{reference:r,floating:o}=e;const s=hn(t),i=Ti(t),a=Ci(i),l=In(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(hr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const ty=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Ic(c,r,l),p=r,h={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:b,y:S,data:k,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,h={...h,[y]:{...h[y],...k}},C&&m<=50&&(m++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Ic(c,p,l)),g=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=kn(t,e),m=kc(h),y=a[p?f==="floating"?"reference":"floating":f],x=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(x.top-C.top+m.top)/k.y,bottom:(C.bottom-x.bottom+m.bottom)/k.y,left:(x.left-C.left+m.left)/k.x,right:(C.right-x.right+m.right)/k.x}}const ny=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=kn(e,t)||{};if(c==null)return{};const f=kc(d),p={x:n,y:r},h=Ti(o),m=Ci(h),g=await i.getDimensions(c),y=h==="y",x=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[m]);const N=k/2-C/2,_=I/2-g[m]/2-1,L=jn(f[x],_),R=jn(f[b],_),O=L,F=I-g[m]-R,A=I/2-g[m]/2+N,B=wi(O,A,F),j=!l.arrow&&hr(o)!=null&&A!==B&&s.reference[m]/2-(A<O?L:R)-g[m]/2<0,K=j?A<O?A-O:A-F:0;return{[h]:p[h]+K,data:{[h]:B,centerOffset:A-B-K,...j&&{alignmentOffset:K}},reset:j}}}),ry=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=kn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=In(o),b=hn(a),S=In(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!g?[$o(a)]:Yx(a)),T=m!=="none";!p&&T&&C.push(...Qx(a,g,m,k));const I=[a,...C],N=await Lr(t,y),_=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const A=Gx(o,i,k);_.push(N[A[0]],N[A[1]])}if(L=[...L,{placement:o,overflows:_}],!_.every(A=>A<=0)){var R,O;const A=(((R=s.flip)==null?void 0:R.index)||0)+1,B=I[A];if(B&&(!(f==="alignment"?b!==hn(B):!1)||L.every(z=>hn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:A,overflows:L},reset:{placement:B}};let j=(O=L.filter(K=>K.overflows[0]<=0).sort((K,z)=>K.overflows[1]-z.overflows[1])[0])==null?void 0:O.placement;if(!j)switch(h){case"bestFit":{var F;const K=(F=L.filter(z=>{if(T){const M=hn(z.placement);return M===b||M==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(M=>M>0).reduce((M,G)=>M+G,0)]).sort((z,M)=>z[1]-M[1])[0])==null?void 0:F[0];K&&(j=K);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function Ec(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Nc(e){return Wx.some(t=>e[t]>=0)}const oy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=kn(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ec(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Nc(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ec(s,n.floating);return{data:{escapedOffsets:i,escaped:Nc(i)}}}default:return{}}}}},Ac=new Set(["left","top"]);async function sy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=In(n),a=hr(n),l=hn(n)==="y",c=Ac.has(i)?-1:1,d=s&&l?-1:1,f=kn(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const iy=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 sy(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}}}}},ay=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:y=>{let{x,y:b}=y;return{x,y:b}}},...l}=kn(e,t),c={x:n,y:r},d=await Lr(t,l),f=hn(In(o)),p=Si(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=h+d[y],S=h-d[x];h=wi(b,h,S)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=m+d[y],S=m-d[x];m=wi(b,m,S)}const g=a.fn({...t,[p]:h,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:s,[f]:i}}}}}},ly=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=kn(e,t),d={x:n,y:r},f=hn(o),p=Si(f);let h=d[p],m=d[f];const g=kn(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var x,b;const S=p==="y"?"width":"height",k=Ac.has(In(o)),C=s.reference[f]-s.floating[S]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);m<C?m=C:m>T&&(m=T)}return{[p]:h,[f]:m}}}},cy=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=kn(e,t),d=await Lr(t,c),f=In(o),p=hr(o),h=hn(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=p==="end"?"top":"bottom");const b=g-d.top-d.bottom,S=m-d.left-d.right,k=jn(g-d[y],b),C=jn(m-d[x],S),T=!t.middlewareData.shift;let I=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!p){const L=zt(d.left,0),R=zt(d.right,0),O=zt(d.top,0),F=zt(d.bottom,0);h?N=m-2*(L!==0||R!==0?L+R:zt(d.left,d.right)):I=g-2*(O!==0||F!==0?O+F:zt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:I});const _=await i.getDimensions(a.floating);return m!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function Bo(){return typeof window<"u"}function mr(e){return _c(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(_c(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function _c(e){return Bo()?e instanceof Node||e instanceof Ut(e).Node:!1}function on(e){return Bo()?e instanceof Element||e instanceof Ut(e).Element:!1}function gn(e){return Bo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function jc(e){return!Bo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const uy=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=sn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!uy.has(o)}const dy=new Set(["table","td","th"]);function fy(e){return dy.has(mr(e))}const py=[":popover-open",":modal"];function zo(e){return py.some(t=>{try{return e.matches(t)}catch{return!1}})}const hy=["transform","translate","scale","rotate","perspective"],my=["transform","translate","scale","rotate","perspective","filter"],gy=["paint","layout","strict","content"];function Ii(e){const t=Ei(),n=on(e)?sn(e):e;return hy.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)||my.some(r=>(n.willChange||"").includes(r))||gy.some(r=>(n.contain||"").includes(r))}function xy(e){let t=Mn(e);for(;gn(t)&&!gr(t);){if(Ii(t))return t;if(zo(t))return null;t=Mn(t)}return null}function Ei(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const yy=new Set(["html","body","#document"]);function gr(e){return yy.has(mr(e))}function sn(e){return Ut(e).getComputedStyle(e)}function Uo(e){return on(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Mn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||jc(e)&&e.host||mn(e);return jc(t)?t.host:t}function Mc(e){const t=Mn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&$r(t)?t:Mc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Mc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ut(o);if(s){const a=Ni(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function Ni(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rc(e){const t=sn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=gn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Do(n)!==s||Do(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ai(e){return on(e)?e:e.contextElement}function xr(e){const t=Ai(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const vy=pn(0);function Pc(e){const t=Ut(e);return!Ei()||!t.visualViewport?vy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function by(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ut(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ai(e);let i=pn(1);t&&(r?on(r)&&(i=xr(r)):i=xr(e));const a=by(s,n,r)?Pc(s):pn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Ut(s),h=r&&on(r)?Ut(r):r;let m=p,g=Ni(m);for(;g&&r&&h!==m;){const y=xr(g),x=g.getBoundingClientRect(),b=sn(g),S=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Ut(g),g=Ni(m)}}return Fo({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Uo(e).scrollLeft;return t?t.left+n:Gn(mn(e)).left+n}function Oc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ho(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function wy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pn(1);const d=pn(0),f=gn(r);if((f||!f&&!s)&&((mr(r)!=="body"||$r(i))&&(l=Uo(r)),gn(r))){const h=Gn(r);c=xr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Oc(i,l):pn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function Sy(e){return Array.from(e.getClientRects())}function Cy(e){const t=mn(e),n=Uo(e),r=e.ownerDocument.body,o=zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ho(e);const a=-n.scrollTop;return sn(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Dc=25;function Ty(e,t){const n=Ut(e),r=mn(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=Ei();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ho(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Dc&&(s-=m)}else c<=Dc&&(s+=c);return{width:s,height:i,x:a,y:l}}const ky=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=gn(e)?xr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Lc(e,t,n){let r;if(t==="viewport")r=Ty(e,n);else if(t==="document")r=Cy(mn(e));else if(on(t))r=Iy(t,n);else{const o=Pc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function $c(e,t){const n=Mn(e);return n===t||!on(n)||gr(n)?!1:sn(n).position==="fixed"||$c(n,t)}function Ey(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>on(a)&&mr(a)!=="body"),o=null;const s=sn(e).position==="fixed";let i=s?Mn(e):e;for(;on(i)&&!gr(i);){const a=sn(i),l=Ii(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&ky.has(o.position)||$r(i)&&!l&&$c(e,i))?r=r.filter(d=>d!==i):o=a,i=Mn(i)}return t.set(e,r),r}function Ny(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:Ey(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Lc(t,d,o);return c.top=zt(f.top,c.top),c.right=jn(f.right,c.right),c.bottom=jn(f.bottom,c.bottom),c.left=zt(f.left,c.left),c},Lc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Ay(e){const{width:t,height:n}=Rc(e);return{width:t,height:n}}function _y(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((mr(t)!=="body"||$r(o))&&(a=Uo(t)),r){const h=Gn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Oc(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function _i(e){return sn(e).position==="static"}function Fc(e,t){if(!gn(e)||sn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function Bc(e,t){const n=Ut(e);if(zo(e))return n;if(!gn(e)){let o=Mn(e);for(;o&&!gr(o);){if(on(o)&&!_i(o))return o;o=Mn(o)}return n}let r=Fc(e,t);for(;r&&fy(r)&&_i(r);)r=Fc(r,t);return r&&gr(r)&&_i(r)&&!Ii(r)?n:r||xy(e)||n}const jy=async function(e){const t=this.getOffsetParent||Bc,n=this.getDimensions,r=await n(e.floating);return{reference:_y(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function My(e){return sn(e).direction==="rtl"}const Ry={convertOffsetParentRelativeRectToViewportRelativeRect:wy,getDocumentElement:mn,getClippingRect:Ny,getOffsetParent:Bc,getElementRects:jy,getClientRects:Sy,getDimensions:Ay,getScale:xr,isElement:on,isRTL:My};function zc(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=mn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Lo(f),g=Lo(o.clientWidth-(d+p)),y=Lo(o.clientHeight-(f+h)),x=Lo(d),S={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:zt(0,jn(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!zc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Oy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ai(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Py(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(x=>{let[b]=x;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,g=l?Gn(e):null;l&&y();function y(){const x=Gn(e);g&&!zc(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=h)==null||x.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const Dy=iy,Ly=ay,$y=ry,Fy=cy,By=oy,Uc=ny,zy=ly,Uy=(e,t,n)=>{const r=new Map,o={platform:Ry,...n},s={...o.platform,_c:r};return ty(e,t,{...o,platform:s})};var Hy=typeof document<"u",Wy=function(){},Wo=Hy?w.useLayoutEffect:Wy;function Vo(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(!Vo(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)&&!Vo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Hc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wc(e,t){const n=Hc(e);return Math.round(t*n)/n}function ji(e){const t=v.useRef(e);return Wo(()=>{t.current=e}),t}function Vy(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Vo(p,r)||h(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,g(z))},[]),S=v.useCallback(z=>{z!==I.current&&(I.current=z,x(z))},[]),k=s||m,C=i||y,T=v.useRef(null),I=v.useRef(null),N=v.useRef(d),_=l!=null,L=ji(l),R=ji(o),O=ji(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};R.current&&(z.platform=R.current),Uy(T.current,I.current,z).then(M=>{const G={...M,isPositioned:O.current!==!1};A.current&&!Vo(N.current,G)&&(N.current=G,ho.flushSync(()=>{f(G)}))})},[p,t,n,R,O]);Wo(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const A=v.useRef(!1);Wo(()=>(A.current=!0,()=>{A.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,F);F()}},[k,C,F,L,_]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),j=v.useMemo(()=>({reference:k,floating:C}),[k,C]),K=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!j.floating)return z;const M=Wc(j.floating,d.x),G=Wc(j.floating,d.y);return a?{...z,transform:"translate("+M+"px, "+G+"px)",...Hc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:M,top:G}},[n,a,j.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:j,floatingStyles:K}),[d,F,B,j,K])}const Ky=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?Uc({element:r.current,padding:o}).fn(n):{}:r?Uc({element:r,padding:o}).fn(n):{}}}},qy=(e,t)=>({...Dy(e),options:[e,t]}),Gy=(e,t)=>({...Ly(e),options:[e,t]}),Yy=(e,t)=>({...zy(e),options:[e,t]}),Xy=(e,t)=>({...$y(e),options:[e,t]}),Jy=(e,t)=>({...Fy(e),options:[e,t]}),Zy=(e,t)=>({...By(e),options:[e,t]}),Qy=(e,t)=>({...Ky(e),options:[e,t]});var ev="Arrow",Vc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ae.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Vc.displayName=ev;var tv=Vc;function Kc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Mi="Popper",[qc,Ko]=Cn(Mi),[nv,Gc]=qc(Mi),Yc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(nv,{scope:t,anchor:r,onAnchorChange:o,children:n})};Yc.displayName=Mi;var Xc="PopperAnchor",Jc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Gc(Xc,n),i=v.useRef(null),a=Fe(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Ae.div,{...o,ref:a})});Jc.displayName=Xc;var Ri="PopperContent",[rv,ov]=qc(Ri),Zc=v.forwardRef((e,t)=>{var J,$,q,Z,ue,ie;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...g}=e,y=Gc(Ri,n),[x,b]=v.useState(null),S=Fe(t,_e=>b(_e)),[k,C]=v.useState(null),T=Kc(k),I=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},R=Array.isArray(c)?c:[c],O=R.length>0,F={padding:L,boundary:R.filter(iv),altBoundary:O},{refs:A,floatingStyles:B,placement:j,isPositioned:K,middlewareData:z}=Vy({strategy:"fixed",placement:_,whileElementsMounted:(..._e)=>Oy(..._e,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[qy({mainAxis:o+N,alignmentAxis:i}),l&&Gy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Yy():void 0,...F}),l&&Xy({...F}),Jy({...F,apply:({elements:_e,rects:He,availableWidth:oe,availableHeight:xe})=>{const{width:Re,height:Ye}=He.reference,nt=_e.floating.style;nt.setProperty("--radix-popper-available-width",`${oe}px`),nt.setProperty("--radix-popper-available-height",`${xe}px`),nt.setProperty("--radix-popper-anchor-width",`${Re}px`),nt.setProperty("--radix-popper-anchor-height",`${Ye}px`)}}),k&&Qy({element:k,padding:a}),av({arrowWidth:I,arrowHeight:N}),p&&Zy({strategy:"referenceHidden",...F})]}),[M,G]=tu(j),X=kt(m);Tt(()=>{K&&(X==null||X())},[K,X]);const se=(J=z.arrow)==null?void 0:J.x,ve=($=z.arrow)==null?void 0:$.y,Ie=((q=z.arrow)==null?void 0:q.centerOffset)!==0,[Y,U]=v.useState();return Tt(()=>{x&&U(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:A.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:K?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Y,"--radix-popper-transform-origin":[(Z=z.transformOrigin)==null?void 0:Z.x,(ue=z.transformOrigin)==null?void 0:ue.y].join(" "),...((ie=z.hide)==null?void 0:ie.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(rv,{scope:n,placedSide:M,onArrowChange:C,arrowX:se,arrowY:ve,shouldHideArrow:Ie,children:u.jsx(Ae.div,{"data-side":M,"data-align":G,...g,ref:S,style:{...g.style,animation:K?void 0:"none"}})})})});Zc.displayName=Ri;var Qc="PopperArrow",sv={top:"bottom",right:"left",bottom:"top",left:"right"},eu=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=ov(Qc,r),i=sv[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(tv,{...o,ref:n,style:{...o.style,display:"block"}})})});eu.displayName=Qc;function iv(e){return e!==null}var av=e=>({name:"transformOrigin",options:e,fn(t){var y,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=tu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,h=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${p}px`,g=`${-l}px`):c==="top"?(m=i?f:`${p}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${h}px`),{data:{x:m,y:g}}}});function tu(e){const[t,n="center"]=e.split("-");return[t,n]}var nu=Yc,ru=Jc,ou=Zc,su=eu,lv="Portal",qo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Gs.createPortal(u.jsx(Ae.div,{...r,ref:t}),i):null});qo.displayName=lv;function cv(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Xt=e=>{const{present:t,children:n}=e,r=uv(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Fe(r.ref,dv(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Xt.displayName="Presence";function uv(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=cv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Go(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const g=Go(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Go(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function dv(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 Pi="rovingFocusGroup.onEntryFocus",fv={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Oi,iu,pv]=mi(Br),[hv,au]=Cn(Br,[pv]),[mv,gv]=hv(Br),lu=v.forwardRef((e,t)=>u.jsx(Oi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(xv,{...e,ref:t})})}));lu.displayName=Br;var xv=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Fe(t,p),m=Ro(s),[g,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[x,b]=v.useState(!1),S=kt(c),k=iu(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const N=p.current;if(N)return N.addEventListener(Pi,S),()=>N.removeEventListener(Pi,S)},[S]),u.jsx(mv,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(N=>y(N),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(N=>N+1),[]),onFocusableItemRemove:v.useCallback(()=>I(N=>N-1),[]),children:u.jsx(Ae.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:fe(e.onMouseDown,()=>{C.current=!0}),onFocus:fe(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const L=new CustomEvent(Pi,fv);if(N.currentTarget.dispatchEvent(L),!L.defaultPrevented){const R=k().filter(j=>j.focusable),O=R.find(j=>j.active),F=R.find(j=>j.id===g),B=[O,F,...R].filter(Boolean).map(j=>j.ref.current);du(B,d)}}C.current=!1}),onBlur:fe(e.onBlur,()=>b(!1))})})}),cu="RovingFocusGroupItem",uu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Tn(),c=s||l,d=gv(cu,n),f=d.currentTabStopId===c,p=iu(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx(Oi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ae.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:fe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:fe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:fe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=bv(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?wv(S,k+1):S.slice(k+1)}setTimeout(()=>du(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});uu.displayName=cu;var yv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function vv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function bv(e,t,n){const r=vv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return yv[r]}function du(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function wv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Sv=lu,Cv=uu,Tv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Yo=new WeakMap,Xo={},Di=0,fu=function(e){return e&&(e.host||fu(e.parentNode))},kv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=fu(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})},Iv=function(e,t,n,r){var o=kv(t,Array.isArray(e)?e:[e]);Xo[n]||(Xo[n]=new WeakMap);var s=Xo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",g=(yr.get(p)||0)+1,y=(s.get(p)||0)+1;yr.set(p,g),s.set(p,y),i.push(p),g===1&&m&&Yo.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",p,x)}})};return d(t),a.clear(),Di++,function(){i.forEach(function(f){var p=yr.get(f)-1,h=s.get(f)-1;yr.set(f,p),s.set(f,h),p||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),h||f.removeAttribute(n)}),Di--,Di||(yr=new WeakMap,yr=new WeakMap,Yo=new WeakMap,Xo={})}},Li=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Tv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Iv(r,o,n,"aria-hidden")):function(){return null}},xn=function(){return xn=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},xn.apply(this,arguments)};function pu(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 Ev(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 Jo="right-scroll-bar-position",Zo="width-before-scroll-bar",Nv="with-scroll-bars-hidden",Av="--removed-body-scroll-bar-size";function $i(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function _v(e,t){var n=w.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 jv=typeof window<"u"?v.useLayoutEffect:v.useEffect,hu=new WeakMap;function Mv(e,t){var n=_v(null,function(r){return e.forEach(function(o){return $i(o,r)})});return jv(function(){var r=hu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||$i(a,null)}),s.forEach(function(a){o.has(a)||$i(a,i)})}hu.set(n,e)},[e]),n}function Rv(e){return e}function Pv(e,t){t===void 0&&(t=Rv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Ov(e){e===void 0&&(e={});var t=Pv(null);return t.options=xn({async:!0,ssr:!1},e),t}var mu=function(e){var t=e.sideCar,n=pu(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 v.createElement(r,xn({},n))};mu.isSideCarExport=!0;function Dv(e,t){return e.useMedium(t),mu}var gu=Ov(),Fi=function(){},Qo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Fi,onWheelCapture:Fi,onTouchMoveCapture:Fi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=pu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=Mv([n,t]),I=xn(xn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:gu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),xn(xn({},I),{ref:T})):v.createElement(b,xn({},I,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var Lv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function $v(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Lv();return t&&e.setAttribute("nonce",t),e}function Fv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var zv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=$v())&&(Fv(t,n),Bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Uv=function(){var e=zv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},xu=function(){var e=Uv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Hv={left:0,top:0,right:0,gap:0},Bi=function(e){return parseInt(e||"",10)||0},Wv=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[Bi(n),Bi(r),Bi(o)]},Vv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Hv;var t=Wv(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])}},Kv=xu(),vr="data-scroll-locked",qv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
39
- .`.concat(Nv,` {
37
+ `))>=0;){const Q=gt.slice(0,j);gt=gt.slice(j+2);const re=qg(Q);if(!re)continue;let ie;try{ie=JSON.parse(re)}catch{console.debug("[use-chat] malformed SSE:",re.slice(0,200));continue}const ce=Kg(ie)?ie.data:ie;nn=Date.now();const Xe=ce.seq;if(Xe!==void 0){if(Xe<=it){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Xe,lastProcessedSeq:it,type:ce.type});continue}it>0&&Xe>it+1&&(($=A==null?void 0:A.onGap)==null||$.call(A,{from:it,to:Xe})),it=Xe,C.current=Xe,y(Xe)}if(ce.type==="checkpoint")I.current=ce.checkpointId??null,N.current=ce.checkpointNs??null,m(ce.checkpointId??null);else if(ce.type==="state_history"){_.current=ce;try{const at=dr(ce).latest;at&&(I.current=at.checkpointId??null,N.current=at.checkpointNs??null,m(at.checkpointId??null))}catch(Ee){console.warn("[use-chat] Failed to hydrate state_history payload",Ee)}}try{M==null||M(ce)}catch(Ee){console.error("[use-chat] Error in onEvent callback:",Ee,"for event:",ce.type)}if(ce.type==="message.delta"){const Ee=ce.delta.filter(at=>at.type==="text").map(at=>at.text).join("");Ee&&e.autoAppendAssistant!==!1&&(Ct.push(Ee),zt())}else if(ce.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(Y=A==null?void 0:A.onHeartbeat)==null||Y.call(A,ce)}catch(Ee){console.warn("[use-chat] heartbeat callback failed",Ee)}}else if(St!==null&&cancelAnimationFrame(St),Rt(),ce.type==="checkpoint")m(ce.checkpointId);else if(ce.type==="error"){const Ee=ce;if(d(Ee.message),D="error",P=Ee.message,Ee.error_type==="auth_error"||Ee.code==="TOKEN_EXPIRED"||((Z=Ee.message)==null?void 0:Z.includes("token"))||((de=Ee.message)==null?void 0:de.includes("401"))||((oe=Ee.message)==null?void 0:oe.includes("unauthorized"))||((_e=Ee.message)==null?void 0:_e.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Ee.message);try{(ze=A==null?void 0:A.onAuthError)==null||ze.call(A,Ee.message)}catch(ht){console.warn("[use-chat] onAuthError handler failed",ht)}F.abort()}}}}Rt(),D===null&&!F.signal.aborted&&(D="complete")}catch(tt){if(tt.name==="AbortError")D=D??"aborted";else{const We=tt.message||String(tt);D="error",P=We,d(We),(se=A==null?void 0:A.onError)==null||se.call(A,We)}}finally{try{await st.cancel()}catch{}finally{(me=st.releaseLock)==null||me.call(st)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(Le)}}catch(Ke){if(Ke.name==="AbortError")D=D??"aborted";else{const qe=Ke.message||String(Ke);D="error",P=qe,d(qe),(Re=A==null?void 0:A.onError)==null||Re.call(A,qe),z||((Ve=A==null?void 0:A.onConnectionError)==null||Ve.call(A,qe),z=!0)}}finally{const Ke=C.current,qe=I.current,Qe=N.current,Ge=_.current,et=D??(F.signal.aborted?"aborted":P?"error":"complete");try{(ut=A==null?void 0:A.onClosed)==null||ut.call(A,{reason:et,lastSeq:Ke,lastCheckpointId:qe,lastCheckpointNs:Qe,lastStateHistory:Ge,error:P})}catch(st){console.warn("[use-chat] onClosed callback failed",st)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>F.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var R;k.current=!1,(R=S.current)==null||R.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:g,connected:x,stream:V,stop:G,clear:B,setToken:L}}function Kg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function qg(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
+ `)}const Gg=["message.start","message.delta","message.end","progress"],Yg=["tool.start","tool.end"],Xg=["thread_info","checkpoint","branch"],Jg=["error","interrupt","heartbeat","state_history","cancelled"],Zg=[...Gg,...Yg,...Xg,...Jg],Qg=new Set(Zg);function ex(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return Qg.has(t)}const Gl=200;function tx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),m=w.useRef(null),g=w.useCallback(M=>{try{const A=globalThis.structuredClone;if(typeof A=="function")return A(M)}catch{}try{return JSON.parse(JSON.stringify(M))}catch{return M}},[]),y=w.useCallback((M,A)=>{if(!M)return;const F=p.current.get(M)??[],D=g(A),P=F.length>=Gl?[...F.slice(F.length-Gl+1),D]:[...F,D];p.current.set(M,P)},[g]),x=w.useCallback(M=>{M&&p.current.set(M,[])},[]),b=w.useCallback(M=>{const A=M??f.current;if(!A)return;const F=p.current.get(A);F!=null&&F.length&&F.forEach(D=>{try{n(D)}catch(P){console.error("[useChatStreamingService] Failed to replay buffered event",P)}})},[n]),S=w.useCallback(M=>{f.current=M.threadId,h.current&&(h.current.threadIdGuess=M.threadId),m.current=M,x(M.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",M);try{t(M)}catch(A){console.error("[useChatStreamingService] Error in onThreadInfo handler:",A)}},[x,t]),k=w.useCallback(M=>{try{c==null||c(M)}catch(A){console.error("[useChatStreamingService] Error in onHeartbeat handler:",A)}},[c]),C=w.useCallback(M=>{var D,P,z,X;const A=M;if(A.error_type==="auth_error"||A.code==="TOKEN_EXPIRED"||((D=A.message)==null?void 0:D.includes("token"))||((P=A.message)==null?void 0:P.includes("401"))||((z=A.message)==null?void 0:z.includes("unauthorized"))||((X=A.message)==null?void 0:X.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",A.message);try{l==null||l(A.message)}catch(ne){console.warn("[useChatStreamingService] onAuthError handler failed",ne)}}},[l]),T=w.useMemo(()=>({thread_info:M=>(S(M),!0),heartbeat:M=>(k(M),!0),error:M=>(C(M),!1)}),[S,k,C]),I=w.useCallback(M=>{var P;const A=M.seq??null;if(A!==null){const z=d.current;if(z!==null){if(A<=z)return;A>z+1&&(s==null||s({from:z,to:A}))}d.current=A}const F=T[M.type];if(F&&F(M))return;const D=M.threadId??(M.type==="state_history"?M.threadId:void 0)??f.current??((P=h.current)==null?void 0:P.threadIdGuess)??null;if(M.type==="state_history"){f.current=D??f.current;try{r==null||r(M)}catch(z){console.error("[useChatStreamingService] onStateHistory handler failed",z)}}if(ex(M)){M.type==="checkpoint"||M.type==="state_history"?x(D??null):y(D??null,M);try{n(M)}catch(z){console.error("[useChatStreamingService] Error in onMessageEvent handler:",z)}return}try{o==null||o(M)}catch(z){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",z)}},[y,x,n,s,r,o,T]),{stream:N,stop:_,isStreaming:L,error:B,setToken:G}=ql({baseUrl:e,token:void 0}),V=w.useCallback((M,A)=>{d.current=null,m.current=null,f.current=M.threadId??null,h.current={request:M,callbacks:A,manualStop:!1,threadIdGuess:M.threadId??null},N(M,I,{onOpen:A==null?void 0:A.onOpen,onError:F=>{var D;(D=A==null?void 0:A.onError)==null||D.call(A,F)},onGap:(A==null?void 0:A.onGap)??s,onConnectionError:F=>{var D;a==null||a(F),(D=A==null?void 0:A.onConnectionError)==null||D.call(A,F)},onAuthError:F=>{var D;l==null||l(F),(D=A==null?void 0:A.onAuthError)==null||D.call(A,F)},onHeartbeat:F=>{var D;try{c==null||c(F)}catch(P){console.warn("[useChatStreamingService] onHeartbeat handler failed",P)}try{(D=A==null?void 0:A.onHeartbeat)==null||D.call(A,F)}catch(P){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",P)}},onClosed:F=>{var X,ne,ye,Te;const D=((X=h.current)==null?void 0:X.manualStop)??!1,P=f.current??((ne=h.current)==null?void 0:ne.threadIdGuess)??((ye=F.lastStateHistory)==null?void 0:ye.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&D)&&x(P);const z={...F,threadId:P,threadInfo:m.current,manualStop:D};try{i==null||i(z)}catch(q){console.warn("[useChatStreamingService] onStreamClosed handler failed",q)}try{(Te=A==null?void 0:A.onClosed)==null||Te.call(A,z)}catch(q){console.warn("[useChatStreamingService] downstream onClosed handler failed",q)}h.current&&(h.current=null)}})},[x,I,l,a,c,s,i,N]),R=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),_()},[_]);return w.useMemo(()=>({startStream:V,stop:R,isStreaming:L,error:B,setAuthToken:G,replayBufferedEvents:b}),[V,R,L,B,G,b])}const Tt=[];for(let e=0;e<256;++e)Tt.push((e+256).toString(16).slice(1));function nx(e,t=0){return(Tt[e[t+0]]+Tt[e[t+1]]+Tt[e[t+2]]+Tt[e[t+3]]+"-"+Tt[e[t+4]]+Tt[e[t+5]]+"-"+Tt[e[t+6]]+Tt[e[t+7]]+"-"+Tt[e[t+8]]+Tt[e[t+9]]+"-"+Tt[e[t+10]]+Tt[e[t+11]]+Tt[e[t+12]]+Tt[e[t+13]]+Tt[e[t+14]]+Tt[e[t+15]]).toLowerCase()}let fi;const rx=new Uint8Array(16);function ox(){if(!fi){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");fi=crypto.getRandomValues.bind(crypto)}return fi(rx)}const Yl={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function sx(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??ox();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,nx(r)}function ix(e,t,n){return Yl.randomUUID&&!e?Yl.randomUUID():sx(e)}const ax={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function lx(e,t){var n;switch(t.type){case"reset":return{messages:pi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],lastBranch:null,pendingInterrupt:null};case"seed":{const r=pi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[]};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=pi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Jl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Jl(o,s),e):e}case"interrupt_response":return{...e,messages:Zl(e.messages),pendingInterrupt:null};default:return e}}function Xl(e=[]){const[t,n]=w.useReducer(lx,{...ax,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.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=w.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=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Jl(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=gx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const c={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,c]}}if(t.type==="message.delta"){const i=e.assemblingId??Ql(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const c=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:rc(c.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof f.lastSeq=="number"&&p<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:f.lastSeq}),e;const{newParts:h,newMeta:m,changed:g}=px(c.content,t.delta,f,p);if(!g)return e;const y={...c,content:h},x=Ao(a,l,y),b={...d,[i]:m};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??Ql(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(c=>c.id===i&&c.role==="assistant");if(l>=0){const c=a[l];if(!((n=c.content)==null?void 0:n.some(f=>{var p;return(f==null?void 0:f.type)==="text"&&((p=f.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:c.id,contentTypes:(r=c.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=c.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=ec(t),a=i[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),l=t.name??t.tool??"tool";!a&&i.length===0&&i.push(`${l}-${Date.now()}`);const c=i.length?i:a?[a]:[],d=c[0]??`${l}-${Date.now()}`,f={type:"tool_call",id:d,name:l,args:t.args},p={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,title:`Invoking ${l}`,metadata:{args:t.args}},h=e.toolStreamingMessageId;if(!h){const y={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...ux(void 0,c.length?c:[d],l,t.args),toolStreaming:!0}},x=dx(y,c.length?c:[d]),b=[...e.messages,y],S=No(b,y.id,p);return{...e,messages:S,toolIndex:tc(e.toolIndex,y.id,x),toolStreamingMessageId:y.id,toolStreamingStack:nc(e.toolStreamingStack??[],a??d)}}const m=No(e.messages,h,p);return{...e,messages:m,toolIndex:tc(e.toolIndex,h,c),toolStreamingStack:nc(e.toolStreamingStack??[],a??d)}}if(t.type==="tool.end"){const i=ec(t);if(!i.length&&!(typeof t.id=="string"&&t.id))return e;const a=i[0]??(typeof t.id=="string"?t.id:null);if(!a)return e;const l=e.toolStreamingStack??[],c=l[0]??null,d=fx(l,a),f=d[0]?e.toolIndex[d[0]]:null,p=e.toolStreamingMessageId,h=c===a,m=t.name??((s=e.messages.find(S=>S.id===p))==null?void 0:s.name)??"tool",g=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),y={type:"tool.end",toolId:a,toolName:m,title:`${m} completed`,content:g==null?void 0:g.slice(0,200)};let x=e.messages;if(p&&(x=No(x,p,y)),h&&p){const S=x.findIndex(k=>k.id===p);if(S>=0){const k=x[S],T={type:"text",text:(()=>{if(typeof t.output=="string"){const N=t.output.trim();try{return N}catch{return N}}return JSON.stringify(t.output??"")})()},I={...k,content:[T],artifact:t.artifact??k.artifact,additionalKwargs:{...k.additionalKwargs??{}}};x=Ao(x,S,I)}}return{...e,messages:x,toolStreamingMessageId:h?f:p,toolStreamingStack:d}}if(t.type==="progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"progress",content:t.content??null},l=No(e.messages,i,a),c=l.findIndex(m=>m.id===i);if(c===-1)return e;const d=l[c],f={...d.additionalKwargs??{},toolStreaming:!0},p={...d,additionalKwargs:f},h=Ao(l,c,p);return{...e,messages:h}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=mx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="state_history"){const i=dr(t),a=i.interrupt,l=i.latest,c=a===null?Zl(e.messages):e.messages;return{...e,messages:c,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function pi(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Ao(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Zl(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Ql(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function ec(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function cx(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function ux(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};for(const l of t)s(l);const i=Array.from(o),a={};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function dx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=cx(e);for(const o of r)n.add(o);return Array.from(n)}function tc(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function No(e,t,n){const r=e.findIndex(c=>c.id===t);if(r===-1)return e;const o=e[r],s=[...e],i={...o.additionalKwargs??{}},a=Array.isArray(i.toolProgress)?[...i.toolProgress]:[],l={id:ix(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function nc(e,t){return e.includes(t)?e:[...e,t]}function fx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function rc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function px(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??rc(e);let l="",c=e.slice();if(s){const f=hx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",m={...p,text:h+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function oc(e){return e.replace(/\s+/g," ").trim()}function hx(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=oc(e),o=oc(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 mx(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 Ao(e,r,s)}return e}function gx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const sc=w.createContext(null),ic=w.createContext(null),ac=w.createContext(null);w.createContext(!1);function xx({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l}){const{api:c,baseUrl:d}=ui(),f=w.useMemo(()=>Cn(d),[d]),[p,h]=w.useState([]),[m,g]=w.useState(t),[y,x]=w.useState(!1),[b,S]=w.useState(null),[k,C]=w.useState(!1),[T,I]=w.useState(null),{state:N,seed:_,prepend:L,pushUser:B,onEvent:G}=Xl(),[V,R]=w.useState(!1),[M,A]=w.useState(!1),[F,D]=w.useState(null),[P,z]=w.useState([]),[X,ne]=w.useState([]),[ye,Te]=w.useState(!1),q=w.useMemo(()=>Vg(P),[P]),U=w.useRef(m),J=w.useRef(null),$=w.useRef(null),Y=w.useRef(null),Z=w.useRef(null),de=w.useRef(!1),oe=w.useRef(null),_e=w.useRef(new Map),ze=w.useRef(new Map);w.useEffect(()=>{U.current=m},[m]);const se=w.useCallback(async H=>{var Q,re;if(!H.threadId)return;const j=H.threadId;(Q=H.onStart)==null||Q.call(H),H.setLoading(!0);try{await H.action(j)}catch(ie){if(U.current===j){const ce=String(ie);(re=H.handleError)==null||re.call(H,ce),s==null||s(ce)}throw ie}finally{H.setLoading(!1)}},[s]),me=w.useCallback(async()=>{x(!0),S(null);try{const H=await c.listThreads();h(H??[])}catch(H){const j=String(H);S(j),s==null||s(j)}finally{x(!1)}},[c,s]),Re=w.useCallback(H=>{if(!(H!=null&&H.threadId))return;const j={threadId:H.threadId,title:H.title||`Thread ${H.threadId.slice(0,8)}`,createdAt:H.createdAt||new Date().toISOString(),updatedAt:H.updatedAt||new Date().toISOString(),messageCount:H.messageCount??1};h(Q=>{let re=!1;const ie=Q.map(ce=>ce.threadId===j.threadId?(re=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",j.threadId),{...ce,title:j.title??ce.title,updatedAt:j.updatedAt??ce.updatedAt,messageCount:j.messageCount??ce.messageCount}):ce);return re?ie:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",j.threadId),[j,...Q])})},[]),Ve=w.useCallback(H=>{const j=H.threadId??U.current;if(!j||U.current&&U.current!==j)return;const{checkpoints:Q,timeline:re}=dr(H);if(!Q.length)return;const ie=Q.find(ce=>ce.messages&&ce.messages.length>0)??Q.find(ce=>!!ce.checkpointId)??Q[0];_((ie==null?void 0:ie.messages)??[],{checkpointId:(ie==null?void 0:ie.checkpointId)??null,checkpointNs:(ie==null?void 0:ie.checkpointNs)??null}),ne(re),z(Q),R(!!(ie!=null&&ie.nextCursor)),D((ie==null?void 0:ie.nextCursor)??null),oe.current=`${j}:latest`,$.current=null,Y.current=null},[_]),ut=w.useCallback(H=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",H.threadId),Re(H),U.current!==H.threadId&&((H.created??!U.current)&&($.current=H.threadId),Y.current=H.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),g(H.threadId))},[Re]),{startStream:Ke,stop:qe,isStreaming:Qe,error:Ge,setAuthToken:et}=tx({baseUrl:f,onThreadInfo:ut,onMessageEvent:G,onStateHistory:Ve,onUnhandledEvent:H=>{console.warn("[ChatSessionProvider] Unhandled event:",H.type)},onAuthError:i,onConnectionError:l}),st=w.useCallback(async H=>{try{const j=await c.createThread(H);return g(j.threadId),await me(),j.threadId}catch(j){return s==null||s(String(j)),null}},[c,me,s]),Mt=w.useCallback(async H=>{const j=p;h(re=>re.filter(ie=>ie.threadId!==H));const Q=new AbortController;ze.current.set(H,Q);try{await c.deleteThread(H),U.current===H&&(g(null),_([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",H)}catch(re){console.error("[ChatSessionProvider] Delete failed, restoring thread:",H,re),h(j),s==null||s(`Failed to delete thread: ${String(re)}`)}finally{ze.current.delete(H)}},[p,c,_,s]),gt=w.useCallback(async(H,j)=>{try{await c.updateThread(H,j),await me()}catch(Q){s==null||s(String(Q))}},[c,me,s]),Ct=w.useCallback(async(H,j)=>{if(!H)return;const Q=`${H}:${j??"latest"}`,re=_e.current.get(Q);if(re)return re;const ie=se({threadId:H,setLoading:C,onStart:()=>I(null),handleError:ce=>I(ce),action:async ce=>{const Xe=await c.getStateHistory({threadId:ce,checkpointId:j||void 0});if(U.current!==ce){console.log(`[ChatSessionProvider] Thread changed during load (was ${ce}, now ${U.current}), discarding stale data`);return}const{checkpoints:Ee,timeline:at}=dr(Xe),ht=Ee.find(Kt=>Kt.messages&&Kt.messages.length>0)??(j?Ee.find(Kt=>Kt.checkpointId===j):null)??Ee[0];_((ht==null?void 0:ht.messages)??[],{checkpointId:(ht==null?void 0:ht.checkpointId)??null,checkpointNs:(ht==null?void 0:ht.checkpointNs)??null}),ne(at),z(Ee),R(!!(ht!=null&&ht.nextCursor)),D((ht==null?void 0:ht.nextCursor)??null)}});_e.current.set(Q,ie);try{await ie}finally{_e.current.delete(Q)}return U.current===H&&(oe.current=Q),ie},[c,_,s,se]),it=w.useCallback(async(H,j)=>{Z.current=H;try{await Ct(H,j)}finally{Z.current===H&&(Z.current=null)}},[Ct]);w.useEffect(()=>{if(!o||!m||k||Qe)return;if($.current===m){$.current=null,J.current=m;return}if(Y.current===m){J.current=m;return}if(Z.current===m){Z.current=null,J.current=m;return}if(J.current===m)return;J.current=m;const H=!de.current&&!!n&&m===t;let j;H&&n?(j=n,de.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",j,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const Q=`${m}:${j??"latest"}`;oe.current!==Q&&it(m,j)},[o,m,n,r,t,k,Qe,it]);const St=w.useCallback(async(H,j)=>{const Q=U.current;await se({threadId:Q,setLoading:Te,action:async re=>{const ie=await c.getStateHistory({threadId:re,checkpointId:H,checkpointNs:j??void 0});if(U.current!==re){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${re}, now ${U.current}), discarding stale data`);return}const{checkpoints:ce,timeline:Xe}=dr(ie),Ee=ce.find(at=>at.checkpointId===H&&(j?at.checkpointNs===j:!0));if(!Ee){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:H,checkpointNs:j});return}ne(Xe),z(ce),_(Ee.messages??[],{checkpointId:Ee.checkpointId??null,checkpointNs:Ee.checkpointNs??null})}}).catch(()=>{})},[c,_,s,se]),Rt=w.useCallback((H,j)=>{_(N.messages,{checkpointId:H??null,checkpointNs:j??null})},[_,N.messages]),zt=w.useCallback(async()=>{U.current&&await it(U.current)},[it]),nn=w.useCallback(async()=>{const H=U.current;!H||!F||await se({threadId:H,setLoading:A,action:async j=>{const Q=await c.getStateHistory({threadId:j,checkpointId:F});if(U.current!==j)return;const{checkpoints:re}=dr(Q);if(re.length>0){const ie=re[re.length-1];L((ie==null?void 0:ie.messages)??[]),R(!!(ie!=null&&ie.nextCursor)),D((ie==null?void 0:ie.nextCursor)??null)}}}).catch(()=>{})},[c,F,L,s,se]),Le=w.useCallback(async()=>{_([],{}),g(null),qe(),z([]),ne([]),R(!1),D(null),C(!1),Te(!1),A(!1),I(null);try{await c.getAgent("default")}catch(H){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",H)}},[_,qe,c]),Sn=w.useCallback(async(H,j,Q)=>{const re=U.current;if(!re)throw new Error("No active thread to handle interrupt");const ie=j?Q??!0:!1;try{const ce={threadId:re,checkpointId:N.lastCheckpointId??void 0,checkpointNs:N.lastCheckpointNs??void 0,command:{kind:"resume",value:ie}};Ke(ce)}catch(ce){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${H}:`,ce),ce}},[N.lastCheckpointId,N.lastCheckpointNs,Ke]);w.useEffect(()=>{me()},[me]),w.useEffect(()=>{a==null||a(m)},[m,a]);const tt=w.useCallback(async(H,j)=>{let Q=U.current;const re=(H==null?void 0:H.text)??"",ie=(H==null?void 0:H.attachments)??[],ce=(re==null?void 0:re.trim())??"",Xe={...(H==null?void 0:H.payload)??{}},Ee=Array.isArray(Xe.messages)?Xe.messages:void 0;Ee&&delete Xe.messages;const at=!!(Ee&&Ee.length);if(!Q&&!ce&&ie.length===0&&!at)return;if(!Q){const be=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),Be=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);Q=`${be}${Be}`,$.current=Q,g(Q)}const{contentParts:ht,filesInfo:Kt}=await bg(c,ie),Hn=[...ht];ce&&Hn.push({type:"text",text:re});const Er=j==null?void 0:j.originalMessageId,Ar=!!(j!=null&&j.edit&&Er),fo=!at&&Hn.length>0;let Nn=null;fo&&(Nn={id:Ar?Er:`msg-${Date.now()}`,role:"user",content:Hn,createdAt:new Date().toISOString()},Ar||B(Nn));const E=at?Ee:Nn?[Nn]:[],W={...Xe,...Kt.length?{files_info:Kt}:{}};E.length?W.messages=E:"messages"in W||(W.messages=[]);const ae={threadId:Q,payload:W,checkpointId:(j==null?void 0:j.checkpointId)??N.lastCheckpointId??void 0,checkpointNs:(j==null?void 0:j.checkpointNs)??N.lastCheckpointNs??void 0,edit:!!(j!=null&&j.edit),timelineCheckpoints:X};Ke(ae)},[c,B,N,Ke,X]),We=w.useMemo(()=>({threads:p,currentThreadId:m,setCurrentThreadId:g,isLoading:y,error:b,actions:{createThread:st,deleteThread:Mt,renameThread:gt,refreshThreads:me}}),[p,m,y,b,st,Mt,gt,me]),pt=w.useMemo(()=>{const H=N.assemblingId??null;return H?{assemblingMessageId:H}:null},[N.assemblingId]),Pt=w.useMemo(()=>({threadId:m,messages:N.messages,interrupt:null,checkpoint:{id:N.lastCheckpointId??null,namespace:N.lastCheckpointNs??null},checkpoints:P,timelineCheckpoints:X,metadata:pt,isLoading:k,isHistoryLoading:M,isLoadingCheckpoint:ye,error:T,hasMore:V,loadOlder:nn,clearState:Le,navigateToCheckpoint:St,setCurrentCheckpointId:Rt,returnToLatest:zt,loadThread:it,clearThread:Le,respondToInterrupt:Sn,messagePreviews:q}),[m,N,P,X,k,M,ye,T,V,nn,Le,St,Rt,zt,it,Sn,q,pt]),Ye=w.useMemo(()=>({isStreaming:Qe,error:Ge,connectionState:Qe?"connected":"idle",submit:tt,send:tt,stop:qe,setAuthToken:et}),[Qe,Ge,tt,qe,et]);return u.jsx(sc.Provider,{value:We,children:u.jsx(ic.Provider,{value:Pt,children:u.jsx(ac.Provider,{value:Ye,children:e})})})}function _o(){const e=w.useContext(sc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(ic);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function lc(){const e=w.useContext(ac);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Mo({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(yg,{apiConfig:t,children:u.jsx(xx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:c,children:e})})}function te(...e){return Vh.twMerge(Wh.clsx(e))}const yx=po.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"}}),Je=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Vn.Slot:"button";return u.jsx(i,{className:te(yx({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const cc=v.forwardRef(({className:e,...t},n)=>u.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}));cc.displayName="Textarea";function uc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const m=i!==void 0,[g,y]=w.useState(e),x=(m?i:g)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{m||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,m]);const I=w.useCallback(()=>{const M=k.current;M&&(M.style.height="auto",M.style.height=`${M.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,x]);const N=w.useCallback((M,{fromUser:A})=>{m||y(M),A&&(a==null||a(M))},[m,a]),_=w.useCallback(async M=>{M&&M.preventDefault();const A=(x??"").trim();if(!A&&!h)return;const F=++C.current;T.current={id:F,shouldClear:!0},S(()=>{var D,P,z;try{const X=l(A);X&&typeof X.then=="function"?X.then(()=>{var ne,ye;((ne=T.current)==null?void 0:ne.id)===F&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ye=T.current)==null?void 0:ye.id)===F&&(T.current=null)}).catch(()=>{var ne;((ne=T.current)==null?void 0:ne.id)===F&&(T.current=null)}):(((D=T.current)==null?void 0:D.id)===F&&T.current.shouldClear&&(m||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((P=T.current)==null?void 0:P.id)===F&&(T.current=null))}catch{((z=T.current)==null?void 0:z.id)===F&&(T.current=null)}})},[x,l,h,m,a]),L=w.useCallback(M=>{const A=M.target.value;N(A,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),B=w.useCallback(M=>{M.key==="Enter"&&!M.shiftKey?(M.preventDefault(),_()):M.key==="Escape"&&t&&(M.preventDefault(),c==null||c())},[_,t,c]),R=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:M=>void _(M),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(cc,{ref:k,value:x,onChange:L,onKeyDown:B,placeholder:t?"Edit your message...":n,className:R,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Je,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(le.Square,{size:16})}):u.jsx(Je,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!h||b,children:u.jsx(le.Send,{size:16})})})]})})}const vx=w.memo(uc);function pe(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 dc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function hi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=dc(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():dc(e[o],null)}}}}function $e(...e){return v.useCallback(hi(...e),e)}function bx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var x;const{scope:p,children:h,...m}=f,g=((x=p==null?void 0:p[e])==null?void 0:x[l])||a,y=v.useMemo(()=>m,Object.values(m));return u.jsx(g.Provider,{value:y,children:h})};c.displayName=s+"Provider";function d(f,p){var g;const h=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,m=v.useContext(h);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,wx(o,...t)]}function wx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var kt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Sx=v[" useInsertionEffect ".trim().toString()]||kt;function fr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Cx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=Tx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function Cx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Sx(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function Tx(e){return typeof e=="function"}var kx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=kx.reduce((e,t)=>{const n=Vn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function fc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function mi(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:y,children:x}=g,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Vn.createSlot(a),c=w.forwardRef((g,y)=>{const{scope:x,children:b}=g,S=s(a,x),k=$e(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Vn.createSlot(d),h=w.forwardRef((g,y)=>{const{scope:x,children:b,...S}=g,k=w.useRef(null),C=$e(y,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:b})});h.displayName=d;function m(g){const y=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},m,r]}var Ix=v.createContext(void 0);function Ro(e){const t=v.useContext(Ix);return e||t||"ltr"}function It(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Ex(e,t=globalThis==null?void 0:globalThis.document){const n=It(e);v.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 Ax="DismissableLayer",gi="dismissableLayer.update",Nx="dismissableLayer.pointerDownOutside",_x="dismissableLayer.focusOutside",pc,hc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(hc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),m=$e(t,I=>f(I)),g=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(y),b=d?g.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,C=Rx(I=>{const N=I.target,_=[...c.branches].some(L=>L.contains(N));!k||_||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=Px(I=>{const N=I.target;[...c.branches].some(L=>L.contains(N))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return Ex(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(pc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),mc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=pc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),mc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(gi,I),()=>document.removeEventListener(gi,I)},[]),u.jsx(Ne.div,{...l,ref:m,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:pe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:pe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:pe(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=Ax;var jx="DismissableLayerBranch",Mx=v.forwardRef((e,t)=>{const n=v.useContext(hc),r=v.useRef(null),o=$e(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ne.div,{...e,ref:o})});Mx.displayName=jx;function Rx(e,t=globalThis==null?void 0:globalThis.document){const n=It(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){gc(Nx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Px(e,t=globalThis==null?void 0:globalThis.document){const n=It(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&gc(_x,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 mc(){const e=new CustomEvent(gi);document.dispatchEvent(e)}function gc(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?fc(o,s):o.dispatchEvent(s)}var xi=0;function yi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??xc()),document.body.insertAdjacentElement("beforeend",e[1]??xc()),xi++,()=>{xi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),xi--}},[])}function xc(){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 vi="focusScope.autoFocusOnMount",bi="focusScope.autoFocusOnUnmount",yc={bubbles:!1,cancelable:!0},Ox="FocusScope",Oo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=It(o),d=It(s),f=v.useRef(null),p=$e(t,g=>l(g)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let g=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:jn(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||jn(f.current,{select:!0}))},x=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&jn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",y);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){wc.add(h);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(vi,yc);a.addEventListener(vi,c),a.dispatchEvent(x),x.defaultPrevented||(Dx(zx(vc(a)),{select:!0}),document.activeElement===g&&jn(a))}return()=>{a.removeEventListener(vi,c),setTimeout(()=>{const x=new CustomEvent(bi,yc);a.addEventListener(bi,d),a.dispatchEvent(x),x.defaultPrevented||jn(g??document.body,{select:!0}),a.removeEventListener(bi,d),wc.remove(h)},0)}}},[a,c,d,h]);const m=v.useCallback(g=>{if(!n&&!r||h.paused)return;const y=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(y&&x){const b=g.currentTarget,[S,k]=Lx(b);S&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&jn(S,{select:!0})):g.shiftKey&&x===S&&(g.preventDefault(),n&&jn(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,h.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});Oo.displayName=Ox;function Dx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(jn(r,{select:t}),document.activeElement!==n)return}function Lx(e){const t=vc(e),n=bc(t,e),r=bc(t.reverse(),e);return[n,r]}function vc(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 bc(e,t){for(const n of e)if(!$x(n,{upTo:t}))return n}function $x(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 Fx(e){return e instanceof HTMLInputElement&&"select"in e}function jn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Fx(e)&&t&&e.select()}}var wc=Bx();function Bx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Sc(e,t),e.unshift(t)},remove(t){var n;e=Sc(e,t),(n=e[0])==null||n.resume()}}}function Sc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function zx(e){return e.filter(t=>t.tagName!=="A")}var Ux=v[" useId ".trim().toString()]||(()=>{}),Hx=0;function kn(e){const[t,n]=v.useState(Ux());return kt(()=>{n(r=>r??String(Hx++))},[e]),t?`radix-${t}`:""}const Wx=["top","right","bottom","left"],Mn=Math.min,Ut=Math.max,Do=Math.round,Lo=Math.floor,pn=e=>({x:e,y:e}),Vx={left:"right",right:"left",bottom:"top",top:"bottom"},Kx={start:"end",end:"start"};function wi(e,t,n){return Ut(e,Mn(t,n))}function In(e,t){return typeof e=="function"?e(t):e}function En(e){return e.split("-")[0]}function pr(e){return e.split("-")[1]}function Si(e){return e==="x"?"y":"x"}function Ci(e){return e==="y"?"height":"width"}const qx=new Set(["top","bottom"]);function hn(e){return qx.has(En(e))?"y":"x"}function Ti(e){return Si(hn(e))}function Gx(e,t,n){n===void 0&&(n=!1);const r=pr(e),o=Ti(e),s=Ci(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=$o(i)),[i,$o(i)]}function Yx(e){const t=$o(e);return[ki(e),t,ki(t)]}function ki(e){return e.replace(/start|end/g,t=>Kx[t])}const Cc=["left","right"],Tc=["right","left"],Xx=["top","bottom"],Jx=["bottom","top"];function Zx(e,t,n){switch(e){case"top":case"bottom":return n?t?Tc:Cc:t?Cc:Tc;case"left":case"right":return t?Xx:Jx;default:return[]}}function Qx(e,t,n,r){const o=pr(e);let s=Zx(En(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ki)))),s}function $o(e){return e.replace(/left|right|bottom|top/g,t=>Vx[t])}function ey(e){return{top:0,right:0,bottom:0,left:0,...e}}function kc(e){return typeof e!="number"?ey(e):{top:e,right:e,bottom:e,left:e}}function Fo(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 Ic(e,t,n){let{reference:r,floating:o}=e;const s=hn(t),i=Ti(t),a=Ci(i),l=En(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(pr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const ty=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Ic(c,r,l),p=r,h={},m=0;for(let g=0;g<a.length;g++){const{name:y,fn:x}=a[g],{x:b,y:S,data:k,reset:C}=await x({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,h={...h,[y]:{...h[y],...k}},C&&m<=50&&(m++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Ic(c,p,l)),g=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=In(t,e),m=kc(h),y=a[p?f==="floating"?"reference":"floating":f],x=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(x.top-C.top+m.top)/k.y,bottom:(C.bottom-x.bottom+m.bottom)/k.y,left:(x.left-C.left+m.left)/k.x,right:(C.right-x.right+m.right)/k.x}}const ny=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=In(e,t)||{};if(c==null)return{};const f=kc(d),p={x:n,y:r},h=Ti(o),m=Ci(h),g=await i.getDimensions(c),y=h==="y",x=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",k=s.reference[m]+s.reference[h]-p[h]-s.floating[m],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[m]);const N=k/2-C/2,_=I/2-g[m]/2-1,L=Mn(f[x],_),B=Mn(f[b],_),G=L,V=I-g[m]-B,R=I/2-g[m]/2+N,M=wi(G,R,V),A=!l.arrow&&pr(o)!=null&&R!==M&&s.reference[m]/2-(R<G?L:B)-g[m]/2<0,F=A?R<G?R-G:R-V:0;return{[h]:p[h]+F,data:{[h]:M,centerOffset:R-M-F,...A&&{alignmentOffset:F}},reset:A}}}),ry=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=In(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=En(o),b=hn(a),S=En(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!g?[$o(a)]:Yx(a)),T=m!=="none";!p&&T&&C.push(...Qx(a,g,m,k));const I=[a,...C],N=await Lr(t,y),_=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[x]),f){const R=Gx(o,i,k);_.push(N[R[0]],N[R[1]])}if(L=[...L,{placement:o,overflows:_}],!_.every(R=>R<=0)){var B,G;const R=(((B=s.flip)==null?void 0:B.index)||0)+1,M=I[R];if(M&&(!(f==="alignment"?b!==hn(M):!1)||L.every(D=>hn(D.placement)===b?D.overflows[0]>0:!0)))return{data:{index:R,overflows:L},reset:{placement:M}};let A=(G=L.filter(F=>F.overflows[0]<=0).sort((F,D)=>F.overflows[1]-D.overflows[1])[0])==null?void 0:G.placement;if(!A)switch(h){case"bestFit":{var V;const F=(V=L.filter(D=>{if(T){const P=hn(D.placement);return P===b||P==="y"}return!0}).map(D=>[D.placement,D.overflows.filter(P=>P>0).reduce((P,z)=>P+z,0)]).sort((D,P)=>D[1]-P[1])[0])==null?void 0:V[0];F&&(A=F);break}case"initialPlacement":A=a;break}if(o!==A)return{reset:{placement:A}}}return{}}}};function Ec(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ac(e){return Wx.some(t=>e[t]>=0)}const oy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=In(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ec(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ac(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ec(s,n.floating);return{data:{escapedOffsets:i,escaped:Ac(i)}}}default:return{}}}}},Nc=new Set(["left","top"]);async function sy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=En(n),a=pr(n),l=hn(n)==="y",c=Nc.has(i)?-1:1,d=s&&l?-1:1,f=In(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(h=a==="end"?m*-1:m),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const iy=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 sy(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}}}}},ay=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:y=>{let{x,y:b}=y;return{x,y:b}}},...l}=In(e,t),c={x:n,y:r},d=await Lr(t,l),f=hn(En(o)),p=Si(f);let h=c[p],m=c[f];if(s){const y=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=h+d[y],S=h-d[x];h=wi(b,h,S)}if(i){const y=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=m+d[y],S=m-d[x];m=wi(b,m,S)}const g=a.fn({...t,[p]:h,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:s,[f]:i}}}}}},ly=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=In(e,t),d={x:n,y:r},f=hn(o),p=Si(f);let h=d[p],m=d[f];const g=In(a,t),y=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var x,b;const S=p==="y"?"width":"height",k=Nc.has(En(o)),C=s.reference[f]-s.floating[S]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);m<C?m=C:m>T&&(m=T)}return{[p]:h,[f]:m}}}},cy=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=In(e,t),d=await Lr(t,c),f=En(o),p=pr(o),h=hn(o)==="y",{width:m,height:g}=s.floating;let y,x;f==="top"||f==="bottom"?(y=f,x=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,y=p==="end"?"top":"bottom");const b=g-d.top-d.bottom,S=m-d.left-d.right,k=Mn(g-d[y],b),C=Mn(m-d[x],S),T=!t.middlewareData.shift;let I=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!p){const L=Ut(d.left,0),B=Ut(d.right,0),G=Ut(d.top,0),V=Ut(d.bottom,0);h?N=m-2*(L!==0||B!==0?L+B:Ut(d.left,d.right)):I=g-2*(G!==0||V!==0?G+V:Ut(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:I});const _=await i.getDimensions(a.floating);return m!==_.width||g!==_.height?{reset:{rects:!0}}:{}}}};function Bo(){return typeof window<"u"}function hr(e){return _c(e)?(e.nodeName||"").toLowerCase():"#document"}function Ht(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(_c(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function _c(e){return Bo()?e instanceof Node||e instanceof Ht(e).Node:!1}function sn(e){return Bo()?e instanceof Element||e instanceof Ht(e).Element:!1}function gn(e){return Bo()?e instanceof HTMLElement||e instanceof Ht(e).HTMLElement:!1}function jc(e){return!Bo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ht(e).ShadowRoot}const uy=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=an(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!uy.has(o)}const dy=new Set(["table","td","th"]);function fy(e){return dy.has(hr(e))}const py=[":popover-open",":modal"];function zo(e){return py.some(t=>{try{return e.matches(t)}catch{return!1}})}const hy=["transform","translate","scale","rotate","perspective"],my=["transform","translate","scale","rotate","perspective","filter"],gy=["paint","layout","strict","content"];function Ii(e){const t=Ei(),n=sn(e)?an(e):e;return hy.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)||my.some(r=>(n.willChange||"").includes(r))||gy.some(r=>(n.contain||"").includes(r))}function xy(e){let t=Rn(e);for(;gn(t)&&!mr(t);){if(Ii(t))return t;if(zo(t))return null;t=Rn(t)}return null}function Ei(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const yy=new Set(["html","body","#document"]);function mr(e){return yy.has(hr(e))}function an(e){return Ht(e).getComputedStyle(e)}function Uo(e){return sn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Rn(e){if(hr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||jc(e)&&e.host||mn(e);return jc(t)?t.host:t}function Mc(e){const t=Rn(e);return mr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&$r(t)?t:Mc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Mc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ht(o);if(s){const a=Ai(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function Ai(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rc(e){const t=an(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=gn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Do(n)!==s||Do(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ni(e){return sn(e)?e:e.contextElement}function gr(e){const t=Ni(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const vy=pn(0);function Pc(e){const t=Ht(e);return!Ei()||!t.visualViewport?vy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function by(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ht(e)?!1:t}function Yn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ni(e);let i=pn(1);t&&(r?sn(r)&&(i=gr(r)):i=gr(e));const a=by(s,n,r)?Pc(s):pn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Ht(s),h=r&&sn(r)?Ht(r):r;let m=p,g=Ai(m);for(;g&&r&&h!==m;){const y=gr(g),x=g.getBoundingClientRect(),b=an(g),S=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,m=Ht(g),g=Ai(m)}}return Fo({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Uo(e).scrollLeft;return t?t.left+n:Yn(mn(e)).left+n}function Oc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ho(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function wy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pn(1);const d=pn(0),f=gn(r);if((f||!f&&!s)&&((hr(r)!=="body"||$r(i))&&(l=Uo(r)),gn(r))){const h=Yn(r);c=gr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Oc(i,l):pn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function Sy(e){return Array.from(e.getClientRects())}function Cy(e){const t=mn(e),n=Uo(e),r=e.ownerDocument.body,o=Ut(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ut(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ho(e);const a=-n.scrollTop;return an(r).direction==="rtl"&&(i+=Ut(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Dc=25;function Ty(e,t){const n=Ht(e),r=mn(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=Ei();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ho(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-h);m<=Dc&&(s-=m)}else c<=Dc&&(s+=c);return{width:s,height:i,x:a,y:l}}const ky=new Set(["absolute","fixed"]);function Iy(e,t){const n=Yn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=gn(e)?gr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Lc(e,t,n){let r;if(t==="viewport")r=Ty(e,n);else if(t==="document")r=Cy(mn(e));else if(sn(t))r=Iy(t,n);else{const o=Pc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function $c(e,t){const n=Rn(e);return n===t||!sn(n)||mr(n)?!1:an(n).position==="fixed"||$c(n,t)}function Ey(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>sn(a)&&hr(a)!=="body"),o=null;const s=an(e).position==="fixed";let i=s?Rn(e):e;for(;sn(i)&&!mr(i);){const a=an(i),l=Ii(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&ky.has(o.position)||$r(i)&&!l&&$c(e,i))?r=r.filter(d=>d!==i):o=a,i=Rn(i)}return t.set(e,r),r}function Ay(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:Ey(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Lc(t,d,o);return c.top=Ut(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Ut(f.left,c.left),c},Lc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Ny(e){const{width:t,height:n}=Rc(e);return{width:t,height:n}}function _y(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Yn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((hr(t)!=="body"||$r(o))&&(a=Uo(t)),r){const h=Yn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Oc(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function _i(e){return an(e).position==="static"}function Fc(e,t){if(!gn(e)||an(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function Bc(e,t){const n=Ht(e);if(zo(e))return n;if(!gn(e)){let o=Rn(e);for(;o&&!mr(o);){if(sn(o)&&!_i(o))return o;o=Rn(o)}return n}let r=Fc(e,t);for(;r&&fy(r)&&_i(r);)r=Fc(r,t);return r&&mr(r)&&_i(r)&&!Ii(r)?n:r||xy(e)||n}const jy=async function(e){const t=this.getOffsetParent||Bc,n=this.getDimensions,r=await n(e.floating);return{reference:_y(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function My(e){return an(e).direction==="rtl"}const Ry={convertOffsetParentRelativeRectToViewportRelativeRect:wy,getDocumentElement:mn,getClippingRect:Ay,getOffsetParent:Bc,getElementRects:jy,getClientRects:Sy,getDimensions:Ny,getScale:gr,isElement:sn,isRTL:My};function zc(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=mn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const m=Lo(f),g=Lo(o.clientWidth-(d+p)),y=Lo(o.clientHeight-(f+h)),x=Lo(d),S={rootMargin:-m+"px "+-g+"px "+-y+"px "+-x+"px",threshold:Ut(0,Mn(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!zc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Oy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ni(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=c&&a?Py(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(x=>{let[b]=x;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let m,g=l?Yn(e):null;l&&y();function y(){const x=Yn(e);g&&!zc(g,x)&&n(),g=x,m=requestAnimationFrame(y)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=h)==null||x.disconnect(),h=null,l&&cancelAnimationFrame(m)}}const Dy=iy,Ly=ay,$y=ry,Fy=cy,By=oy,Uc=ny,zy=ly,Uy=(e,t,n)=>{const r=new Map,o={platform:Ry,...n},s={...o.platform,_c:r};return ty(e,t,{...o,platform:s})};var Hy=typeof document<"u",Wy=function(){},Wo=Hy?w.useLayoutEffect:Wy;function Vo(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(!Vo(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)&&!Vo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Hc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wc(e,t){const n=Hc(e);return Math.round(t*n)/n}function ji(e){const t=v.useRef(e);return Wo(()=>{t.current=e}),t}function Vy(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Vo(p,r)||h(r);const[m,g]=v.useState(null),[y,x]=v.useState(null),b=v.useCallback(D=>{D!==T.current&&(T.current=D,g(D))},[]),S=v.useCallback(D=>{D!==I.current&&(I.current=D,x(D))},[]),k=s||m,C=i||y,T=v.useRef(null),I=v.useRef(null),N=v.useRef(d),_=l!=null,L=ji(l),B=ji(o),G=ji(c),V=v.useCallback(()=>{if(!T.current||!I.current)return;const D={placement:t,strategy:n,middleware:p};B.current&&(D.platform=B.current),Uy(T.current,I.current,D).then(P=>{const z={...P,isPositioned:G.current!==!1};R.current&&!Vo(N.current,z)&&(N.current=z,ho.flushSync(()=>{f(z)}))})},[p,t,n,B,G]);Wo(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(D=>({...D,isPositioned:!1})))},[c]);const R=v.useRef(!1);Wo(()=>(R.current=!0,()=>{R.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,V);V()}},[k,C,V,L,_]);const M=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),A=v.useMemo(()=>({reference:k,floating:C}),[k,C]),F=v.useMemo(()=>{const D={position:n,left:0,top:0};if(!A.floating)return D;const P=Wc(A.floating,d.x),z=Wc(A.floating,d.y);return a?{...D,transform:"translate("+P+"px, "+z+"px)",...Hc(A.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:P,top:z}},[n,a,A.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:V,refs:M,elements:A,floatingStyles:F}),[d,V,M,A,F])}const Ky=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?Uc({element:r.current,padding:o}).fn(n):{}:r?Uc({element:r,padding:o}).fn(n):{}}}},qy=(e,t)=>({...Dy(e),options:[e,t]}),Gy=(e,t)=>({...Ly(e),options:[e,t]}),Yy=(e,t)=>({...zy(e),options:[e,t]}),Xy=(e,t)=>({...$y(e),options:[e,t]}),Jy=(e,t)=>({...Fy(e),options:[e,t]}),Zy=(e,t)=>({...By(e),options:[e,t]}),Qy=(e,t)=>({...Ky(e),options:[e,t]});var ev="Arrow",Vc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ne.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Vc.displayName=ev;var tv=Vc;function Kc(e){const[t,n]=v.useState(void 0);return kt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Mi="Popper",[qc,Ko]=Tn(Mi),[nv,Gc]=qc(Mi),Yc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(nv,{scope:t,anchor:r,onAnchorChange:o,children:n})};Yc.displayName=Mi;var Xc="PopperAnchor",Jc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Gc(Xc,n),i=v.useRef(null),a=$e(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Ne.div,{...o,ref:a})});Jc.displayName=Xc;var Ri="PopperContent",[rv,ov]=qc(Ri),Zc=v.forwardRef((e,t)=>{var J,$,Y,Z,de,oe;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:m,...g}=e,y=Gc(Ri,n),[x,b]=v.useState(null),S=$e(t,_e=>b(_e)),[k,C]=v.useState(null),T=Kc(k),I=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(c)?c:[c],G=B.length>0,V={padding:L,boundary:B.filter(iv),altBoundary:G},{refs:R,floatingStyles:M,placement:A,isPositioned:F,middlewareData:D}=Vy({strategy:"fixed",placement:_,whileElementsMounted:(..._e)=>Oy(..._e,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[qy({mainAxis:o+N,alignmentAxis:i}),l&&Gy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Yy():void 0,...V}),l&&Xy({...V}),Jy({...V,apply:({elements:_e,rects:ze,availableWidth:se,availableHeight:me})=>{const{width:Re,height:Ve}=ze.reference,ut=_e.floating.style;ut.setProperty("--radix-popper-available-width",`${se}px`),ut.setProperty("--radix-popper-available-height",`${me}px`),ut.setProperty("--radix-popper-anchor-width",`${Re}px`),ut.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),k&&Qy({element:k,padding:a}),av({arrowWidth:I,arrowHeight:N}),p&&Zy({strategy:"referenceHidden",...V})]}),[P,z]=tu(A),X=It(m);kt(()=>{F&&(X==null||X())},[F,X]);const ne=(J=D.arrow)==null?void 0:J.x,ye=($=D.arrow)==null?void 0:$.y,Te=((Y=D.arrow)==null?void 0:Y.centerOffset)!==0,[q,U]=v.useState();return kt(()=>{x&&U(window.getComputedStyle(x).zIndex)},[x]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...M,transform:F?M.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:q,"--radix-popper-transform-origin":[(Z=D.transformOrigin)==null?void 0:Z.x,(de=D.transformOrigin)==null?void 0:de.y].join(" "),...((oe=D.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(rv,{scope:n,placedSide:P,onArrowChange:C,arrowX:ne,arrowY:ye,shouldHideArrow:Te,children:u.jsx(Ne.div,{"data-side":P,"data-align":z,...g,ref:S,style:{...g.style,animation:F?void 0:"none"}})})})});Zc.displayName=Ri;var Qc="PopperArrow",sv={top:"bottom",right:"left",bottom:"top",left:"right"},eu=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=ov(Qc,r),i=sv[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(tv,{...o,ref:n,style:{...o.style,display:"block"}})})});eu.displayName=Qc;function iv(e){return e!==null}var av=e=>({name:"transformOrigin",options:e,fn(t){var y,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=tu(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,h=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let m="",g="";return c==="bottom"?(m=i?f:`${p}px`,g=`${-l}px`):c==="top"?(m=i?f:`${p}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?f:`${h}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?f:`${h}px`),{data:{x:m,y:g}}}});function tu(e){const[t,n="center"]=e.split("-");return[t,n]}var nu=Yc,ru=Jc,ou=Zc,su=eu,lv="Portal",qo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Gs.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});qo.displayName=lv;function cv(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Xt=e=>{const{present:t,children:n}=e,r=uv(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=$e(r.ref,dv(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Xt.displayName="Presence";function uv(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=cv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),kt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Go(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),kt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const g=Go(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&g&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Go(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function dv(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 Pi="rovingFocusGroup.onEntryFocus",fv={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Oi,iu,pv]=mi(Br),[hv,au]=Tn(Br,[pv]),[mv,gv]=hv(Br),lu=v.forwardRef((e,t)=>u.jsx(Oi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(xv,{...e,ref:t})})}));lu.displayName=Br;var xv=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=$e(t,p),m=Ro(s),[g,y]=fr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[x,b]=v.useState(!1),S=It(c),k=iu(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const N=p.current;if(N)return N.addEventListener(Pi,S),()=>N.removeEventListener(Pi,S)},[S]),u.jsx(mv,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:v.useCallback(N=>y(N),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(N=>N+1),[]),onFocusableItemRemove:v.useCallback(()=>I(N=>N-1),[]),children:u.jsx(Ne.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:pe(e.onMouseDown,()=>{C.current=!0}),onFocus:pe(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!x){const L=new CustomEvent(Pi,fv);if(N.currentTarget.dispatchEvent(L),!L.defaultPrevented){const B=k().filter(A=>A.focusable),G=B.find(A=>A.active),V=B.find(A=>A.id===g),M=[G,V,...B].filter(Boolean).map(A=>A.ref.current);du(M,d)}}C.current=!1}),onBlur:pe(e.onBlur,()=>b(!1))})})}),cu="RovingFocusGroupItem",uu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=kn(),c=s||l,d=gv(cu,n),f=d.currentTabStopId===c,p=iu(n),{onFocusableItemAdd:h,onFocusableItemRemove:m,currentTabStopId:g}=d;return v.useEffect(()=>{if(r)return h(),()=>m()},[r,h,m]),u.jsx(Oi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:pe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:pe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:pe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const x=bv(y,d.orientation,d.dir);if(x!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")S.reverse();else if(x==="prev"||x==="next"){x==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?wv(S,k+1):S.slice(k+1)}setTimeout(()=>du(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});uu.displayName=cu;var yv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function vv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function bv(e,t,n){const r=vv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return yv[r]}function du(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function wv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Sv=lu,Cv=uu,Tv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},xr=new WeakMap,Yo=new WeakMap,Xo={},Di=0,fu=function(e){return e&&(e.host||fu(e.parentNode))},kv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=fu(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})},Iv=function(e,t,n,r){var o=kv(t,Array.isArray(e)?e:[e]);Xo[n]||(Xo[n]=new WeakMap);var s=Xo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),m=h!==null&&h!=="false",g=(xr.get(p)||0)+1,y=(s.get(p)||0)+1;xr.set(p,g),s.set(p,y),i.push(p),g===1&&m&&Yo.set(p,!0),y===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",p,x)}})};return d(t),a.clear(),Di++,function(){i.forEach(function(f){var p=xr.get(f)-1,h=s.get(f)-1;xr.set(f,p),s.set(f,h),p||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),h||f.removeAttribute(n)}),Di--,Di||(xr=new WeakMap,xr=new WeakMap,Yo=new WeakMap,Xo={})}},Li=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Tv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Iv(r,o,n,"aria-hidden")):function(){return null}},xn=function(){return xn=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},xn.apply(this,arguments)};function pu(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 Ev(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 Jo="right-scroll-bar-position",Zo="width-before-scroll-bar",Av="with-scroll-bars-hidden",Nv="--removed-body-scroll-bar-size";function $i(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function _v(e,t){var n=w.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 jv=typeof window<"u"?v.useLayoutEffect:v.useEffect,hu=new WeakMap;function Mv(e,t){var n=_v(null,function(r){return e.forEach(function(o){return $i(o,r)})});return jv(function(){var r=hu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||$i(a,null)}),s.forEach(function(a){o.has(a)||$i(a,i)})}hu.set(n,e)},[e]),n}function Rv(e){return e}function Pv(e,t){t===void 0&&(t=Rv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Ov(e){e===void 0&&(e={});var t=Pv(null);return t.options=xn({async:!0,ssr:!1},e),t}var mu=function(e){var t=e.sideCar,n=pu(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 v.createElement(r,xn({},n))};mu.isSideCarExport=!0;function Dv(e,t){return e.useMedium(t),mu}var gu=Ov(),Fi=function(){},Qo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Fi,onWheelCapture:Fi,onTouchMoveCapture:Fi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,m=e.noIsolation,g=e.inert,y=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,S=e.gapMode,k=pu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=Mv([n,t]),I=xn(xn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:gu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),xn(xn({},I),{ref:T})):v.createElement(b,xn({},I,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var Lv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function $v(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Lv();return t&&e.setAttribute("nonce",t),e}function Fv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Bv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var zv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=$v())&&(Fv(t,n),Bv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Uv=function(){var e=zv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},xu=function(){var e=Uv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Hv={left:0,top:0,right:0,gap:0},Bi=function(e){return parseInt(e||"",10)||0},Wv=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[Bi(n),Bi(r),Bi(o)]},Vv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Hv;var t=Wv(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])}},Kv=xu(),yr="data-scroll-locked",qv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
39
+ .`.concat(Av,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(vr,`] {
43
+ body[`).concat(yr,`] {
44
44
  overflow: hidden `).concat(r,`;
45
45
  overscroll-behavior: contain;
46
46
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -69,13 +69,13 @@ React keys must be passed directly to JSX without using spread:
69
69
  margin-right: 0 `).concat(r,`;
70
70
  }
71
71
 
72
- body[`).concat(vr,`] {
73
- `).concat(Av,": ").concat(a,`px;
72
+ body[`).concat(yr,`] {
73
+ `).concat(Nv,": ").concat(a,`px;
74
74
  }
75
- `)},yu=function(){var e=parseInt(document.body.getAttribute(vr)||"0",10);return isFinite(e)?e:0},Gv=function(){v.useEffect(function(){return document.body.setAttribute(vr,(yu()+1).toString()),function(){var e=yu()-1;e<=0?document.body.removeAttribute(vr):document.body.setAttribute(vr,e.toString())}},[])},Yv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Gv();var s=v.useMemo(function(){return Vv(o)},[o]);return v.createElement(Kv,{styles:qv(s,!t,o,n?"":"!important")})},zi=!1;if(typeof window<"u")try{var es=Object.defineProperty({},"passive",{get:function(){return zi=!0,!0}});window.addEventListener("test",es,es),window.removeEventListener("test",es,es)}catch{zi=!1}var br=zi?{passive:!1}:!1,Xv=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&&!Xv(e)&&n[t]==="visible")},Jv=function(e){return vu(e,"overflowY")},Zv=function(e){return vu(e,"overflowX")},bu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=wu(e,r);if(o){var s=Su(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Qv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},eb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},wu=function(e,t){return e==="v"?Jv(t):Zv(t)},Su=function(e,t){return e==="v"?Qv(t):eb(t)},tb=function(e,t){return e==="h"&&t==="rtl"?-1:1},nb=function(e,t,n,r,o){var s=tb(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,p=0;do{if(!a)break;var h=Su(e,a),m=h[0],g=h[1],y=h[2],x=g-y-s*m;(m||x)&&wu(e,a)&&(f+=x,p+=m);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cu=function(e){return[e.deltaX,e.deltaY]},Tu=function(e){return e&&"current"in e?e.current:e},rb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},ob=function(e){return`
75
+ `)},yu=function(){var e=parseInt(document.body.getAttribute(yr)||"0",10);return isFinite(e)?e:0},Gv=function(){v.useEffect(function(){return document.body.setAttribute(yr,(yu()+1).toString()),function(){var e=yu()-1;e<=0?document.body.removeAttribute(yr):document.body.setAttribute(yr,e.toString())}},[])},Yv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Gv();var s=v.useMemo(function(){return Vv(o)},[o]);return v.createElement(Kv,{styles:qv(s,!t,o,n?"":"!important")})},zi=!1;if(typeof window<"u")try{var es=Object.defineProperty({},"passive",{get:function(){return zi=!0,!0}});window.addEventListener("test",es,es),window.removeEventListener("test",es,es)}catch{zi=!1}var vr=zi?{passive:!1}:!1,Xv=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&&!Xv(e)&&n[t]==="visible")},Jv=function(e){return vu(e,"overflowY")},Zv=function(e){return vu(e,"overflowX")},bu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=wu(e,r);if(o){var s=Su(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Qv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},eb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},wu=function(e,t){return e==="v"?Jv(t):Zv(t)},Su=function(e,t){return e==="v"?Qv(t):eb(t)},tb=function(e,t){return e==="h"&&t==="rtl"?-1:1},nb=function(e,t,n,r,o){var s=tb(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,p=0;do{if(!a)break;var h=Su(e,a),m=h[0],g=h[1],y=h[2],x=g-y-s*m;(m||x)&&wu(e,a)&&(f+=x,p+=m);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cu=function(e){return[e.deltaX,e.deltaY]},Tu=function(e){return e&&"current"in e?e.current:e},rb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},ob=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},sb=0,wr=[];function ib(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(sb++)[0],s=v.useState(xu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=Ev([e.lockRef.current],(e.shards||[]).map(Tu),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=ts(g),b=n.current,S="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],C,T=g.target,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in g&&I==="h"&&T.type==="range")return!1;var N=bu(I,T);if(!N)return!0;if(N?C=I:(C=I==="v"?"h":"v",N=bu(I,T)),!N)return!1;if(!r.current&&"changedTouches"in g&&(S||k)&&(r.current=C),!C)return!0;var _=r.current||C;return nb(_,y,g,_==="h"?S:k)},[]),l=v.useCallback(function(g){var y=g;if(!(!wr.length||wr[wr.length-1]!==s)){var x="deltaY"in y?Cu(y):ts(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&rb(C.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Tu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,b){var S={name:g,delta:y,target:x,should:b,shadowParent:ab(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(g){n.current=ts(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Cu(g),g.target,a(g,e.lockRef.current))},[]),p=v.useCallback(function(g){c(g.type,ts(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,br),document.addEventListener("touchmove",l,br),document.addEventListener("touchstart",d,br),function(){wr=wr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,br),document.removeEventListener("touchmove",l,br),document.removeEventListener("touchstart",d,br)}},[]);var h=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:ob(o)}):null,h?v.createElement(Yv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ab(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const lb=Dv(gu,ib);var ns=v.forwardRef(function(e,t){return v.createElement(Qo,xn({},e,{ref:t,sideCar:lb}))});ns.classNames=Qo.classNames;var Ui=["Enter"," "],cb=["ArrowDown","PageUp","Home"],ku=["ArrowUp","PageDown","End"],ub=[...cb,...ku],db={ltr:[...Ui,"ArrowRight"],rtl:[...Ui,"ArrowLeft"]},fb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,pb,hb]=mi(zr),[Yn,Iu]=Cn(zr,[hb,Ko,au]),rs=Ko(),Eu=au(),[mb,Xn]=Yn(zr),[gb,Hr]=Yn(zr),Nu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),p=Ro(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(nu,{...a,children:u.jsx(mb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(gb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Nu.displayName=zr;var xb="MenuAnchor",Hi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(ru,{...o,...r,ref:t})});Hi.displayName=xb;var Wi="MenuPortal",[yb,Au]=Yn(Wi,{forceMount:void 0}),_u=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(Wi,t);return u.jsx(yb,{scope:t,forceMount:n,children:u.jsx(Xt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};_u.displayName=Wi;var Jt="MenuContent",[vb,Vi]=Yn(Jt),ju=v.forwardRef((e,t)=>{const n=Au(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Jt,e.__scopeMenu),i=Hr(Jt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(bb,{...o,ref:t}):u.jsx(wb,{...o,ref:t})})})})}),bb=v.forwardRef((e,t)=>{const n=Xn(Jt,e.__scopeMenu),r=v.useRef(null),o=Fe(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Li(s)},[]),u.jsx(Ki,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),wb=v.forwardRef((e,t)=>{const n=Xn(Jt,e.__scopeMenu);return u.jsx(Ki,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Sb=Wn.createSlot("MenuContent.ScrollLock"),Ki=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:m,...g}=e,y=Xn(Jt,n),x=Hr(Jt,n),b=rs(n),S=Eu(n),k=pb(n),[C,T]=v.useState(null),I=v.useRef(null),N=Fe(t,I,y.onContentChange),_=v.useRef(0),L=v.useRef(""),R=v.useRef(0),O=v.useRef(null),F=v.useRef("right"),A=v.useRef(0),B=m?ns:v.Fragment,j=m?{as:Sb,allowPinchZoom:!0}:void 0,K=M=>{var J,$;const G=L.current+M,X=k().filter(q=>!q.disabled),se=document.activeElement,ve=(J=X.find(q=>q.ref.current===se))==null?void 0:J.textValue,Ie=X.map(q=>q.textValue),Y=Pb(Ie,G,ve),U=($=X.find(q=>q.textValue===Y))==null?void 0:$.ref.current;(function q(Z){L.current=Z,window.clearTimeout(_.current),Z!==""&&(_.current=window.setTimeout(()=>q(""),1e3))})(G),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),yi();const z=v.useCallback(M=>{var X,se;return F.current===((X=O.current)==null?void 0:X.side)&&Db(M,(se=O.current)==null?void 0:se.area)},[]);return u.jsx(vb,{scope:n,searchRef:L,onItemEnter:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),onItemLeave:v.useCallback(M=>{var G;z(M)||((G=I.current)==null||G.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(M=>{z(M)&&M.preventDefault()},[z]),pointerGraceTimerRef:R,onPointerGraceIntentChange:v.useCallback(M=>{O.current=M},[]),children:u.jsx(B,{...j,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:fe(s,M=>{var G;M.preventDefault(),(G=I.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(Sv,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:fe(l,M=>{x.isUsingKeyboardRef.current||M.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ou,{role:"menu","aria-orientation":"vertical","data-state":Gu(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:N,style:{outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,M=>{const X=M.target.closest("[data-radix-menu-content]")===M.currentTarget,se=M.ctrlKey||M.altKey||M.metaKey,ve=M.key.length===1;X&&(M.key==="Tab"&&M.preventDefault(),!se&&ve&&K(M.key));const Ie=I.current;if(M.target!==Ie||!ub.includes(M.key))return;M.preventDefault();const U=k().filter(J=>!J.disabled).map(J=>J.ref.current);ku.includes(M.key)&&U.reverse(),Mb(U)}),onBlur:fe(e.onBlur,M=>{M.currentTarget.contains(M.target)||(window.clearTimeout(_.current),L.current="")}),onPointerMove:fe(e.onPointerMove,Vr(M=>{const G=M.target,X=A.current!==M.clientX;if(M.currentTarget.contains(G)&&X){const se=M.clientX>A.current?"right":"left";F.current=se,A.current=M.clientX}}))})})})})})})});ju.displayName=Jt;var Cb="MenuGroup",qi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ae.div,{role:"group",...r,ref:t})});qi.displayName=Cb;var Tb="MenuLabel",Mu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ae.div,{...r,ref:t})});Mu.displayName=Tb;var os="MenuItem",Ru="menu.itemSelect",ss=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(os,e.__scopeMenu),a=Vi(os,e.__scopeMenu),l=Fe(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Ru,{bubbles:!0,cancelable:!0});f.addEventListener(Ru,h=>r==null?void 0:r(h),{once:!0}),fc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Pu,{...o,ref:l,disabled:n,onClick:fe(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:fe(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:fe(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Ui.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Pu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Vi(os,n),a=Eu(n),l=v.useRef(null),c=Fe(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&h((m.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(Cv,{asChild:!0,...a,focusable:!r,children:u.jsx(Ae.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:fe(e.onPointerMove,Vr(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:fe(e.onPointerLeave,Vr(m=>i.onItemLeave(m))),onFocus:fe(e.onFocus,()=>f(!0)),onBlur:fe(e.onBlur,()=>f(!1))})})})}),kb="MenuCheckboxItem",Ou=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Bu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Yi(n),onSelect:fe(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ou.displayName=kb;var Du="MenuRadioGroup",[Ib,Eb]=Yn(Du,{value:void 0,onValueChange:()=>{}}),Lu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(Ib,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(qi,{...o,ref:t})})});Lu.displayName=Du;var $u="MenuRadioItem",Fu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Eb($u,e.__scopeMenu),s=n===o.value;return u.jsx(Bu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Yi(s),onSelect:fe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Fu.displayName=$u;var Gi="MenuItemIndicator",[Bu,Nb]=Yn(Gi,{checked:!1}),zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Nb(Gi,n);return u.jsx(Xt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(Ae.span,{...o,ref:t,"data-state":Yi(s.checked)})})});zu.displayName=Gi;var Ab="MenuSeparator",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Uu.displayName=Ab;var _b="MenuArrow",Hu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(su,{...o,...r,ref:t})});Hu.displayName=_b;var jb="MenuSub",[ek,Wu]=Yn(jb),Wr="MenuSubTrigger",Vu=v.forwardRef((e,t)=>{const n=Xn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Wu(Wr,e.__scopeMenu),s=Vi(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Hi,{asChild:!0,...c,children:u.jsx(Pu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Gu(n.open),...e,ref:hi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:fe(e.onPointerMove,Vr(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:fe(e.onPointerLeave,Vr(f=>{var h,m;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,b=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:b,y:p.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:fe(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||db[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Vu.displayName=Wr;var Ku="MenuSubContent",qu=v.forwardRef((e,t)=>{const n=Au(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Jt,e.__scopeMenu),i=Hr(Jt,e.__scopeMenu),a=Wu(Ku,e.__scopeMenu),l=v.useRef(null),c=Fe(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(Ki,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:fe(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:fe(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:fe(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=fb[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});qu.displayName=Ku;function Gu(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Yi(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function Mb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Rb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Pb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Rb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Ob(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function Db(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Ob(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Lb=Nu,$b=Hi,Fb=_u,Bb=ju,zb=qi,Ub=Mu,Hb=ss,Wb=Ou,Vb=Lu,Kb=Fu,qb=zu,Gb=Uu,Yb=Hu,Xb=Vu,Jb=qu,as="DropdownMenu",[Zb,tk]=Cn(as,[Iu]),Ot=Iu(),[Qb,Yu]=Zb(as),Xu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Qb,{scope:t,triggerId:Tn(),triggerRef:c,contentId:Tn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(Lb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Xu.displayName=as;var Ju="DropdownMenuTrigger",Zu=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Yu(Ju,n),i=Ot(n);return u.jsx($b,{asChild:!0,...i,children:u.jsx(Ae.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:hi(t,s.triggerRef),onPointerDown:fe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:fe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Zu.displayName=Ju;var ew="DropdownMenuPortal",Qu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return u.jsx(Fb,{...r,...n})};Qu.displayName=ew;var ed="DropdownMenuContent",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Yu(ed,n),s=Ot(n),i=v.useRef(!1);return u.jsx(Bb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:fe(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:fe(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});td.displayName=ed;var tw="DropdownMenuGroup",nw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(zb,{...o,...r,ref:t})});nw.displayName=tw;var rw="DropdownMenuLabel",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ub,{...o,...r,ref:t})});nd.displayName=rw;var ow="DropdownMenuItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Hb,{...o,...r,ref:t})});rd.displayName=ow;var sw="DropdownMenuCheckboxItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Wb,{...o,...r,ref:t})});od.displayName=sw;var iw="DropdownMenuRadioGroup",aw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Vb,{...o,...r,ref:t})});aw.displayName=iw;var lw="DropdownMenuRadioItem",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Kb,{...o,...r,ref:t})});sd.displayName=lw;var cw="DropdownMenuItemIndicator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(qb,{...o,...r,ref:t})});id.displayName=cw;var uw="DropdownMenuSeparator",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Gb,{...o,...r,ref:t})});ad.displayName=uw;var dw="DropdownMenuArrow",fw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Yb,{...o,...r,ref:t})});fw.displayName=dw;var pw="DropdownMenuSubTrigger",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Xb,{...o,...r,ref:t})});ld.displayName=pw;var hw="DropdownMenuSubContent",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Jb,{...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)"}})});cd.displayName=hw;var mw=Xu,gw=Zu,xw=Qu,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd;const yw=mw,vw=gw,bw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(xd,{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,u.jsx(le.ChevronRight,{className:"ml-auto h-4 w-4"})]}));bw.displayName=xd.displayName;const ww=v.forwardRef(({className:e,...t},n)=>u.jsx(yd,{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}));ww.displayName=yd.displayName;const vd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(xw,{children:u.jsx(ud,{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})}));vd.displayName=ud.displayName;const Xi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(fd,{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}));Xi.displayName=fd.displayName;const Sw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(pd,{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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(md,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));Sw.displayName=pd.displayName;const Cw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hd,{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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(md,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Cw.displayName=hd.displayName;const Tw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Tw.displayName=dd.displayName;const kw=v.forwardRef(({className:e,...t},n)=>u.jsx(gd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));kw.displayName=gd.displayName;function Iw(e){const t=new Map;for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s)}}return t}function Ew(e){const t=new Map,n=Iw(e),r=Array.from(n.entries());for(const[o,s]of r)if(s.length===1){const i=s[0];i.checkpointId&&t.set(i.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:o})}else{const i=[...s].sort((a,l)=>Date.parse(l.createdAt??"0")-Date.parse(a.createdAt??"0"));i.forEach((a,l)=>{a.checkpointId&&t.set(a.checkpointId,{attemptIndex:l,attemptCount:i.length,isLatestAttempt:l===i.length-1,baseUserMessageId:o})})}return t}function Nw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function ls(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function Aw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function _w(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function jw(e){const t=Array.isArray(e)?e.map(r=>{const o=_w(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ls(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ls(r.metadata,"step"),i=ls(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function Mw(e){const t=w.useMemo(()=>jw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const p=f.checkpointId??null;if(!p)continue;const h=ls(f.metadata,"step"),m=Aw(f.metadata,"source"),g={id:p,step:h,source:m,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,g),h!==null&&m){const y=`${h}:${m}`,x=a.get(y)??[];x.push(g),a.set(y,x)}}const c=Ew(t);for(const[f,p]of i.entries()){const h=c.get(f);h?l.set(f,{...p,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount,isLatestAttempt:h.isLatestAttempt,baseUserMessageId:h.baseUserMessageId??null}):l.set(f,{...p,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}const d=Nw(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const cs=1e4;function Rw(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,`
78
+ `)},sb=0,br=[];function ib(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(sb++)[0],s=v.useState(xu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=Ev([e.lockRef.current],(e.shards||[]).map(Tu),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=ts(g),b=n.current,S="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],C,T=g.target,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in g&&I==="h"&&T.type==="range")return!1;var N=bu(I,T);if(!N)return!0;if(N?C=I:(C=I==="v"?"h":"v",N=bu(I,T)),!N)return!1;if(!r.current&&"changedTouches"in g&&(S||k)&&(r.current=C),!C)return!0;var _=r.current||C;return nb(_,y,g,_==="h"?S:k)},[]),l=v.useCallback(function(g){var y=g;if(!(!br.length||br[br.length-1]!==s)){var x="deltaY"in y?Cu(y):ts(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&rb(C.delta,x)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Tu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(g,y,x,b){var S={name:g,delta:y,target:x,should:b,shadowParent:ab(x)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(g){n.current=ts(g),r.current=void 0},[]),f=v.useCallback(function(g){c(g.type,Cu(g),g.target,a(g,e.lockRef.current))},[]),p=v.useCallback(function(g){c(g.type,ts(g),g.target,a(g,e.lockRef.current))},[]);v.useEffect(function(){return br.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,vr),document.addEventListener("touchmove",l,vr),document.addEventListener("touchstart",d,vr),function(){br=br.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,vr),document.removeEventListener("touchmove",l,vr),document.removeEventListener("touchstart",d,vr)}},[]);var h=e.removeScrollBar,m=e.inert;return v.createElement(v.Fragment,null,m?v.createElement(s,{styles:ob(o)}):null,h?v.createElement(Yv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ab(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const lb=Dv(gu,ib);var ns=v.forwardRef(function(e,t){return v.createElement(Qo,xn({},e,{ref:t,sideCar:lb}))});ns.classNames=Qo.classNames;var Ui=["Enter"," "],cb=["ArrowDown","PageUp","Home"],ku=["ArrowUp","PageDown","End"],ub=[...cb,...ku],db={ltr:[...Ui,"ArrowRight"],rtl:[...Ui,"ArrowLeft"]},fb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,pb,hb]=mi(zr),[Xn,Iu]=Tn(zr,[hb,Ko,au]),rs=Ko(),Eu=au(),[mb,Jn]=Xn(zr),[gb,Hr]=Xn(zr),Au=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=It(s),p=Ro(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),u.jsx(nu,{...a,children:u.jsx(mb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(gb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Au.displayName=zr;var xb="MenuAnchor",Hi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(ru,{...o,...r,ref:t})});Hi.displayName=xb;var Wi="MenuPortal",[yb,Nu]=Xn(Wi,{forceMount:void 0}),_u=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Jn(Wi,t);return u.jsx(yb,{scope:t,forceMount:n,children:u.jsx(Xt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};_u.displayName=Wi;var Jt="MenuContent",[vb,Vi]=Xn(Jt),ju=v.forwardRef((e,t)=>{const n=Nu(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Jn(Jt,e.__scopeMenu),i=Hr(Jt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(bb,{...o,ref:t}):u.jsx(wb,{...o,ref:t})})})})}),bb=v.forwardRef((e,t)=>{const n=Jn(Jt,e.__scopeMenu),r=v.useRef(null),o=$e(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Li(s)},[]),u.jsx(Ki,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:pe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),wb=v.forwardRef((e,t)=>{const n=Jn(Jt,e.__scopeMenu);return u.jsx(Ki,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Sb=Vn.createSlot("MenuContent.ScrollLock"),Ki=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:m,...g}=e,y=Jn(Jt,n),x=Hr(Jt,n),b=rs(n),S=Eu(n),k=pb(n),[C,T]=v.useState(null),I=v.useRef(null),N=$e(t,I,y.onContentChange),_=v.useRef(0),L=v.useRef(""),B=v.useRef(0),G=v.useRef(null),V=v.useRef("right"),R=v.useRef(0),M=m?ns:v.Fragment,A=m?{as:Sb,allowPinchZoom:!0}:void 0,F=P=>{var J,$;const z=L.current+P,X=k().filter(Y=>!Y.disabled),ne=document.activeElement,ye=(J=X.find(Y=>Y.ref.current===ne))==null?void 0:J.textValue,Te=X.map(Y=>Y.textValue),q=Pb(Te,z,ye),U=($=X.find(Y=>Y.textValue===q))==null?void 0:$.ref.current;(function Y(Z){L.current=Z,window.clearTimeout(_.current),Z!==""&&(_.current=window.setTimeout(()=>Y(""),1e3))})(z),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),yi();const D=v.useCallback(P=>{var X,ne;return V.current===((X=G.current)==null?void 0:X.side)&&Db(P,(ne=G.current)==null?void 0:ne.area)},[]);return u.jsx(vb,{scope:n,searchRef:L,onItemEnter:v.useCallback(P=>{D(P)&&P.preventDefault()},[D]),onItemLeave:v.useCallback(P=>{var z;D(P)||((z=I.current)==null||z.focus(),T(null))},[D]),onTriggerLeave:v.useCallback(P=>{D(P)&&P.preventDefault()},[D]),pointerGraceTimerRef:B,onPointerGraceIntentChange:v.useCallback(P=>{G.current=P},[]),children:u.jsx(M,{...A,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:pe(s,P=>{var z;P.preventDefault(),(z=I.current)==null||z.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(Sv,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:pe(l,P=>{x.isUsingKeyboardRef.current||P.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ou,{role:"menu","aria-orientation":"vertical","data-state":Gu(y.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:N,style:{outline:"none",...g.style},onKeyDown:pe(g.onKeyDown,P=>{const X=P.target.closest("[data-radix-menu-content]")===P.currentTarget,ne=P.ctrlKey||P.altKey||P.metaKey,ye=P.key.length===1;X&&(P.key==="Tab"&&P.preventDefault(),!ne&&ye&&F(P.key));const Te=I.current;if(P.target!==Te||!ub.includes(P.key))return;P.preventDefault();const U=k().filter(J=>!J.disabled).map(J=>J.ref.current);ku.includes(P.key)&&U.reverse(),Mb(U)}),onBlur:pe(e.onBlur,P=>{P.currentTarget.contains(P.target)||(window.clearTimeout(_.current),L.current="")}),onPointerMove:pe(e.onPointerMove,Vr(P=>{const z=P.target,X=R.current!==P.clientX;if(P.currentTarget.contains(z)&&X){const ne=P.clientX>R.current?"right":"left";V.current=ne,R.current=P.clientX}}))})})})})})})});ju.displayName=Jt;var Cb="MenuGroup",qi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});qi.displayName=Cb;var Tb="MenuLabel",Mu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});Mu.displayName=Tb;var os="MenuItem",Ru="menu.itemSelect",ss=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(os,e.__scopeMenu),a=Vi(os,e.__scopeMenu),l=$e(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Ru,{bubbles:!0,cancelable:!0});f.addEventListener(Ru,h=>r==null?void 0:r(h),{once:!0}),fc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Pu,{...o,ref:l,disabled:n,onClick:pe(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:pe(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:pe(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Ui.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Pu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Vi(os,n),a=Eu(n),l=v.useRef(null),c=$e(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const m=l.current;m&&h((m.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(Cv,{asChild:!0,...a,focusable:!r,children:u.jsx(Ne.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:pe(e.onPointerMove,Vr(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:pe(e.onPointerLeave,Vr(m=>i.onItemLeave(m))),onFocus:pe(e.onFocus,()=>f(!0)),onBlur:pe(e.onBlur,()=>f(!1))})})})}),kb="MenuCheckboxItem",Ou=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Bu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Yi(n),onSelect:pe(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ou.displayName=kb;var Du="MenuRadioGroup",[Ib,Eb]=Xn(Du,{value:void 0,onValueChange:()=>{}}),Lu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=It(r);return u.jsx(Ib,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(qi,{...o,ref:t})})});Lu.displayName=Du;var $u="MenuRadioItem",Fu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=Eb($u,e.__scopeMenu),s=n===o.value;return u.jsx(Bu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Yi(s),onSelect:pe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Fu.displayName=$u;var Gi="MenuItemIndicator",[Bu,Ab]=Xn(Gi,{checked:!1}),zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Ab(Gi,n);return u.jsx(Xt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":Yi(s.checked)})})});zu.displayName=Gi;var Nb="MenuSeparator",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Uu.displayName=Nb;var _b="MenuArrow",Hu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(su,{...o,...r,ref:t})});Hu.displayName=_b;var jb="MenuSub",[ek,Wu]=Xn(jb),Wr="MenuSubTrigger",Vu=v.forwardRef((e,t)=>{const n=Jn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Wu(Wr,e.__scopeMenu),s=Vi(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Hi,{asChild:!0,...c,children:u.jsx(Pu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Gu(n.open),...e,ref:hi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:pe(e.onPointerMove,Vr(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:pe(e.onPointerLeave,Vr(f=>{var h,m;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const g=(m=n.content)==null?void 0:m.dataset.side,y=g==="right",x=y?-5:5,b=p[y?"left":"right"],S=p[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:b,y:p.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:pe(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||db[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Vu.displayName=Wr;var Ku="MenuSubContent",qu=v.forwardRef((e,t)=>{const n=Nu(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Jn(Jt,e.__scopeMenu),i=Hr(Jt,e.__scopeMenu),a=Wu(Ku,e.__scopeMenu),l=v.useRef(null),c=$e(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(Ki,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:pe(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:pe(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:pe(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=fb[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});qu.displayName=Ku;function Gu(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Yi(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function Mb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Rb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Pb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Rb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Ob(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function Db(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Ob(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Lb=Au,$b=Hi,Fb=_u,Bb=ju,zb=qi,Ub=Mu,Hb=ss,Wb=Ou,Vb=Lu,Kb=Fu,qb=zu,Gb=Uu,Yb=Hu,Xb=Vu,Jb=qu,as="DropdownMenu",[Zb,tk]=Tn(as,[Iu]),Dt=Iu(),[Qb,Yu]=Zb(as),Xu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Dt(t),c=v.useRef(null),[d,f]=fr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Qb,{scope:t,triggerId:kn(),triggerRef:c,contentId:kn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(Lb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Xu.displayName=as;var Ju="DropdownMenuTrigger",Zu=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Yu(Ju,n),i=Dt(n);return u.jsx($b,{asChild:!0,...i,children:u.jsx(Ne.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:hi(t,s.triggerRef),onPointerDown:pe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:pe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Zu.displayName=Ju;var ew="DropdownMenuPortal",Qu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Dt(t);return u.jsx(Fb,{...r,...n})};Qu.displayName=ew;var ed="DropdownMenuContent",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Yu(ed,n),s=Dt(n),i=v.useRef(!1);return u.jsx(Bb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:pe(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:pe(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});td.displayName=ed;var tw="DropdownMenuGroup",nw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(zb,{...o,...r,ref:t})});nw.displayName=tw;var rw="DropdownMenuLabel",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Ub,{...o,...r,ref:t})});nd.displayName=rw;var ow="DropdownMenuItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Hb,{...o,...r,ref:t})});rd.displayName=ow;var sw="DropdownMenuCheckboxItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Wb,{...o,...r,ref:t})});od.displayName=sw;var iw="DropdownMenuRadioGroup",aw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Vb,{...o,...r,ref:t})});aw.displayName=iw;var lw="DropdownMenuRadioItem",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Kb,{...o,...r,ref:t})});sd.displayName=lw;var cw="DropdownMenuItemIndicator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(qb,{...o,...r,ref:t})});id.displayName=cw;var uw="DropdownMenuSeparator",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Gb,{...o,...r,ref:t})});ad.displayName=uw;var dw="DropdownMenuArrow",fw=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Yb,{...o,...r,ref:t})});fw.displayName=dw;var pw="DropdownMenuSubTrigger",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Xb,{...o,...r,ref:t})});ld.displayName=pw;var hw="DropdownMenuSubContent",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Jb,{...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)"}})});cd.displayName=hw;var mw=Xu,gw=Zu,xw=Qu,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd;const yw=mw,vw=gw,bw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(xd,{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,u.jsx(le.ChevronRight,{className:"ml-auto h-4 w-4"})]}));bw.displayName=xd.displayName;const ww=v.forwardRef(({className:e,...t},n)=>u.jsx(yd,{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}));ww.displayName=yd.displayName;const vd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(xw,{children:u.jsx(ud,{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})}));vd.displayName=ud.displayName;const Xi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(fd,{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}));Xi.displayName=fd.displayName;const Sw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(pd,{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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(md,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));Sw.displayName=pd.displayName;const Cw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hd,{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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(md,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Cw.displayName=hd.displayName;const Tw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Tw.displayName=dd.displayName;const kw=v.forwardRef(({className:e,...t},n)=>u.jsx(gd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));kw.displayName=gd.displayName;function Iw(e){const t=new Map;for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s)}}return t}function Ew(e){const t=new Map,n=Iw(e),r=Array.from(n.entries());for(const[o,s]of r)if(s.length===1){const i=s[0];i.checkpointId&&t.set(i.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:o})}else{const i=[...s].sort((a,l)=>Date.parse(l.createdAt??"0")-Date.parse(a.createdAt??"0"));i.forEach((a,l)=>{a.checkpointId&&t.set(a.checkpointId,{attemptIndex:l,attemptCount:i.length,isLatestAttempt:l===i.length-1,baseUserMessageId:o})})}return t}function Aw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function ls(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function Nw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function _w(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function jw(e){const t=Array.isArray(e)?e.map(r=>{const o=_w(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ls(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ls(r.metadata,"step"),i=ls(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function Mw(e){const t=w.useMemo(()=>jw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const p=f.checkpointId??null;if(!p)continue;const h=ls(f.metadata,"step"),m=Nw(f.metadata,"source"),g={id:p,step:h,source:m,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,g),h!==null&&m){const y=`${h}:${m}`,x=a.get(y)??[];x.push(g),a.set(y,x)}}const c=Ew(t);for(const[f,p]of i.entries()){const h=c.get(f);h?l.set(f,{...p,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount,isLatestAttempt:h.isLatestAttempt,baseUserMessageId:h.baseUserMessageId??null}):l.set(f,{...p,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}const d=Aw(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const cs=1e4;function Rw(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,`
79
79
  `).replace(/<p>(.*?)<\/p>/gi,`$1
80
80
 
81
81
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
@@ -83,14 +83,14 @@ React keys must be passed directly to JSX without using spread:
83
83
  `).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
84
84
  `).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
85
85
  `).replace(/<li>(.*?)<\/li>/gi,`- $1
86
- `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function Pw(e,t=cs){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 Ow(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Pw(t),Rw(t)}const us=0,Rn=1,Sr=2,bd=4;function wd(e){return()=>e}function Dw(e){e()}function Sd(e,t){return n=>e(t(n))}function Cd(e,t){return()=>e(t)}function Lw(e,t){return n=>e(t,n)}function Ji(e){return e!==void 0}function $w(...e){return()=>{e.map(Dw)}}function Cr(){}function ds(e,t){return t(e),e}function Fw(e,t){return t(e)}function lt(...e){return e}function Qe(e,t){return e(Rn,t)}function Me(e,t){e(us,t)}function Zi(e){e(Sr)}function vt(e){return e(bd)}function he(e,t){return Qe(e,Lw(t,us))}function an(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Td(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function kd(e,t){return e===t}function ct(e=kd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function ce(e){return t=>Sd(t,e)}function yn(e){return t=>()=>{t(e)}}function W(e,...t){const n=Bw(...t);return(r,o)=>{switch(r){case Sr:Zi(e);return;case Rn:return Qe(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Jn(e){return t=>n=>{e>0?e--:t(n)}}function En(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Oe(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Qe(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Bw(...e){return t=>e.reduceRight(Fw,t)}function zw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Rn:return s?n===s?void 0:(r(),n=s,t=Qe(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=Be();return(r,o)=>{switch(r){case us:t=o;break;case Rn:{o(t);break}case bd:return t}return n(r,o)}}function Nt(e,t){return ds(ee(t),n=>he(e,n))}function Be(){const e=[];return(t,n)=>{switch(t){case us:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return ds(Be(),t=>he(e,t))}function Ke(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Uw(),singleton:n}}const Uw=()=>Symbol();function Hw(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 bt(...e){const t=Be(),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&&Me(t,n)})}),function(s,i){switch(s){case Sr:{Zi(t);return}case Rn:return r===o&&i(n),Qe(t,i)}}}function Ce(e,t=kd){return W(e,ct(t))}function Qi(...e){return function(t,n){switch(t){case Sr:return;case Rn:return $w(...e.map(r=>Qe(r,n)))}}}var Ft=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ft||{});const Ww={0:"debug",3:"error",1:"log",2:"warn"},Vw=()=>typeof globalThis>"u"?window:globalThis,Pn=Ke(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Vw().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Ww[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 ea(e,t,n).callbackRef}function ea(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.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 Kw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=qw(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let m;h&&(m=p.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:h?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:h?a?m.innerWidth:m.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Id("column-gap",getComputedStyle(d).columnGap,o):Id("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ea(c,n,l)}function qw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ft.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Id(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ed(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),m=c.top-h.top;p=h.height-Math.max(0,m),f=m+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ea(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=Ke(()=>{const e=Be(),t=Be(),n=ee(0),r=Be(),o=ee(0),s=Be(),i=Be(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Be(),p=Be(),h=ee(!1),m=ee(!1),g=ee(!1);return he(W(e,ce(({scrollTop:y})=>y)),t),he(W(e,ce(({scrollHeight:y})=>y)),i),he(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Nd(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 ot(e){return e===Kr}function qr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function ln(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=ln(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return ln(e.l,t,n)}function Wt(e,t,n){return ot(e)?jd(t,n,1):t===e.k?wt(e,{k:t,v:n}):t<e.k?Md(wt(e,{l:Wt(e.l,t,n)})):Md(wt(e,{r:Wt(e.r,t,n)}))}function Tr(){return Kr}function fs(e,t,n){if(ot(e))return[];const r=ln(e,t)[0];return Gw(na(e,r,n))}function ta(e,t){if(ot(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=_d(r);return ps(wt(e,{k:s,l:Ad(r),v:i}))}}else return t<n?ps(wt(e,{l:ta(r,t)})):ps(wt(e,{r:ta(o,t)}))}function Qn(e){return ot(e)?[]:[...Qn(e.l),{k:e.k,v:e.v},...Qn(e.r)]}function na(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(na(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(na(s,t,n))),a}function ps(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(ra(t))return Rd(wt(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return wt(t.r,{l:wt(t,{r:t.r.l}),lvl:n,r:wt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ra(e))return oa(wt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=ra(o)?r.lvl-1:r.lvl;return wt(o,{l:wt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oa(wt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function wt(e,t){return jd(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 Ad(e){return ot(e.r)?e.l:ps(wt(e,{r:Ad(e.r)}))}function ra(e){return ot(e)||e.lvl>e.r.lvl}function _d(e){return ot(e.r)?[e.k,e.v]:_d(e.r)}function jd(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function Md(e){return oa(Rd(e))}function Rd(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?wt(t,{r:wt(e,{l:t.r})}):e}function oa(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?wt(n,{l:wt(e,{r:n.l}),lvl:t+1}):e}function Gw(e){return Nd(e,({k:t,v:n})=>({index:t,value:n}))}function Pd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const sa=Ke(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Od(e,t,n){return e[hs(e,t,n)]}function hs(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 Yw(e,t,n,r){const o=hs(e,t,r),s=hs(e,n,r,o);return e.slice(o,s+1)}function On(e,t){return Math.round(e.getBoundingClientRect()[t])}function ms(e){return!ot(e.groupOffsetTree)}function ia({index:e},t){return t===e?0:t<e?-1:1}function Xw(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Jw(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Wt(e,0,s);continue}const a=fs(e,i-1,o+1);if(a.some(o0(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ta(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Wt(e,o+1,p));c&&(e=Wt(e,i,s))}return[e,n]}function Zw(e){return typeof e.groupIndex<"u"}function Qw({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Od(t,e,ia),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Dd(e,t){if(!ms(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ld(e,t,n){if(Zw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Dd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function e0(e,t,n,r=0){return r>0&&(t=Math.max(t,Od(e,r,ia).offset)),Nd(Yw(e,t,n,Qw),r0)}function t0(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ft.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((m,g)=>Wt(Wt(m,g,p),g+1,h),i)}else[i,a]=Jw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=aa(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Wt(p,h,Yr(h,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function n0(e){return Qn(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 $d(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 aa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=hs(o,t-1,ia),a=o[l].offset;const c=ln(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===ln(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of fs(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function r0(e){return{index:e.index,value:e}}function o0(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 s0={offsetHeight:"height",offsetWidth:"width"},bn=Ke(([{log:e},{recalcInProgress:t}])=>{const n=Be(),r=Be(),o=Nt(r,0),s=Be(),i=Be(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>On(C,s0[T])),p=ee(void 0),h=ee(0),m=Xw(),g=Nt(W(n,Oe(l,e,h),vn(t0,m),ct()),m),y=Nt(W(l,ct(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ce(({prev:C})=>C)),[]);he(W(l,Te(C=>C.length>0),Oe(g,h),ce(([C,T,I])=>{const N=C.reduce((_,L,R)=>Wt(_,L,Yr(L,T.offsetTree,I)||R),Tr());return{...T,groupIndices:C,groupOffsetTree:N}})),g),he(W(r,Oe(g),Te(([C,{lastIndex:T}])=>C<T),ce(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const x=Nt(W(c,ce(C=>C===void 0)),!0);he(W(d,Te(C=>C!==void 0&&ot(vt(g).sizeTree)),ce(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(W(n,Oe(g),vn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:m}),ce(C=>C.changed)));Qe(W(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ce(C=>C.diff)),C=>{const{groupIndices:T}=vt(g);if(C>0)Me(t,!0),Me(s,C+$d(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=$d(-C,I)),Me(i,C)}}),Qe(W(a,Oe(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Ft.ERROR)});const S=Ht(s);he(W(s,Oe(g),ce(([C,T])=>{const I=T.groupIndices.length>0,N=[],_=T.lastSize;if(I){const L=qr(T.sizeTree,0);let R=0,O=0;for(;R<C;){const A=T.groupIndices[O],B=T.groupIndices.length===O+1?1/0:T.groupIndices[O+1]-A-1;N.push({endIndex:A,size:L,startIndex:A}),N.push({endIndex:A+1+B-1,size:_,startIndex:A+1}),O++,R+=B+1}const F=Qn(T.sizeTree);return R!==C&&F.shift(),F.reduce((A,{k:B,v:j})=>{let K=A.ranges;return A.prevSize!==0&&(K=[...A.ranges,{endIndex:B+C-1,size:A.prevSize,startIndex:A.prevIndex}]),{prevIndex:B+C,prevSize:j,ranges:K}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Qn(T.sizeTree).reduce((L,{k:R,v:O})=>({prevIndex:R+C,prevSize:O,ranges:[...L.ranges,{endIndex:R+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Ht(W(i,Oe(g,h),ce(([C,{offsetTree:T},I])=>{const N=-C;return Yr(N,T,I)})));return he(W(i,Oe(g,h),ce(([C,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let N=Tr();const _=vt(y);let L=0,R=0,O=0;for(;L<-C;){O=_[R];const F=_[R+1]-O-1;R++,L+=F+1}if(N=Qn(T.sizeTree).reduce((F,{k:A,v:B})=>Wt(F,Math.max(0,A+C),B),N),L!==-C){const F=qr(T.sizeTree,O);N=Wt(N,0,F);const A=ln(T.sizeTree,-C+1)[1];N=Wt(N,1,A)}return{...T,sizeTree:N,...aa(T.offsetTree,0,N,I)}}else{const N=Qn(T.sizeTree).reduce((_,{k:L,v:R})=>Wt(_,Math.max(0,L+C),R),Tr());return{...T,sizeTree:N,...aa(T.offsetTree,0,N,I)}}})),g),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},lt(Pn,sa),{singleton:!0});function i0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Fd=Ke(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Be(),i=Be(),a=Ht(W(s,ce(i0)));return he(W(a,ce(l=>l.totalCount)),n),he(W(a,ce(l=>l.groupIndices)),e),he(W(bt(o,t,r),Te(([l,c])=>ms(c)),ce(([l,c,d])=>ln(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ce(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(bn,Dt)),Dn=Ke(([{log:e}])=>{const t=ee(!1),n=Ht(W(t,Te(r=>r),ct()));return Qe(t,r=>{r&&vt(e)("props updated",{},Ft.DEBUG)}),{didMount:n,propsReady:t}},lt(Pn),{singleton:!0}),a0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Bd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!a0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Xr=Ke(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=Be(),m=Be(),g=ee(0);let y=null,x=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Me(l,!1)}return he(W(h,Oe(n,f,r,g,a,i,p),Oe(e,s,o),ce(([[k,C,T,I,N,_,L,R],O,F,A])=>{const B=Bd(k),{align:j,behavior:K,offset:z}=B,M=I-1,G=Ld(B,C,M);let X=Yr(G,C.offsetTree,O)+_;j==="end"?(X+=F+ln(C.sizeTree,G)[1]-T+A,G===M&&(X+=L)):j==="center"?X+=(F+ln(C.sizeTree,G)[1]-T+A)/2:X-=N,z&&(X+=z);const se=ve=>{S(),ve?(R("retrying to scroll to",{location:k},Ft.DEBUG),Me(h,k)):(Me(m,!0),R("list did not change, scroll successful",{},Ft.DEBUG))};if(S(),K==="smooth"){let ve=!1;b=Qe(t,Ie=>{ve=ve||Ie}),y=an(d,()=>{se(ve)})}else y=an(W(t,l0(150)),se);return x=setTimeout(()=>{S()},1200),Me(l,!0),R("scrolling from index to",{behavior:K,index:G,top:X},Ft.DEBUG),{behavior:K,top:X}})),c),{scrollTargetReached:m,scrollToIndex:h,topListHeight:g}},lt(bn,Dt,Pn),{singleton:!0});function l0(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function la(e,t){e==0?t():requestAnimationFrame(()=>{la(e-1,t)})}function ca(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=Ke(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return he(W(i,Oe(l),Te(([d,f])=>!!f),yn(!1)),a),he(W(i,Oe(l),Te(([d,f])=>!!f),yn(!1)),c),Qe(W(bt(t,i),Oe(a,n,e,c),Te(([[,d],f,{sizeTree:p},h,m])=>d&&(!ot(p)||Ji(h))&&!f&&!m),Oe(l)),([,d])=>{an(o,()=>{Me(c,!0)}),la(4,()=>{an(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(bn,Dt,Xr,Dn),{singleton:!0});function zd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",c0="none",u0={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},d0=0,eo=Ke(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Be(),c=Be(),d=ee(4),f=ee(d0),p=Nt(W(Qi(W(Ce(o),Jn(1),yn(!0)),W(Ce(o),Jn(1),yn(!1),Td(100))),ct()),!1),h=Nt(W(Qi(W(n,yn(!0)),W(n,yn(!1),Td(200))),ct()),!1);he(W(bt(Ce(o),Ce(f)),ce(([b,S])=>b<=S),ct()),a),he(W(a,En(50)),c);const m=Ht(W(bt(r,Ce(s),Ce(t),Ce(e),Ce(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,I,N])=>{const _=k+C-S>-N,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let O,F;return k>b.state.scrollTop?(O="SCROLLED_DOWN",F=b.state.scrollTop-k):(O="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:O,scrollTopDelta:F,state:L}}let R;return L.scrollHeight>b.state.scrollHeight?R="SIZE_INCREASED":C<b.state.viewportHeight?R="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?R="SCROLLING_UPWARDS":R="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:R,state:L}},u0),ct((b,S)=>b&&b.atBottom===S.atBottom))),g=Nt(W(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(zd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(b=>b.changed),ce(b=>b.jump)),0);he(W(m,ce(b=>b.atBottom)),i),he(W(i,En(50)),l);const y=ee(Qr);he(W(r,ce(({scrollTop:b})=>b),ct(),vn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Zr:Qr,prevScrollTop:S},{direction:Qr,prevScrollTop:0}),ce(b=>b.direction)),y),he(W(r,En(50),yn(c0)),y);const x=ee(0);return he(W(p,Te(b=>!b),yn(0)),x),he(W(o,En(100),Oe(p),Te(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),ce(([b,S])=>S-b)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},lt(Dt)),gs="top",xs="bottom",Ud="none";function Hd(e,t,n){return typeof e=="number"?n===Zr&&t===gs||n===Qr&&t===xs?e:0:n===Zr?t===gs?e.main:e.reverse:t===xs?e.main:e.reverse}function Wd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ua=Ke(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Be(),i=ee(0),a=ee(0),l=ee(0),c=Nt(W(bt(Ce(r),Ce(o),Ce(n),Ce(s,Gr),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),ce(([d,f,p,[h,m],g,y,x,b,S])=>{const k=d-b,C=y+x,T=Math.max(p-k,0);let I=Ud;const N=Wd(S,gs),_=Wd(S,xs);return h-=b,h+=p+x,m+=p+x,m-=b,h>d+C-N&&(I=Zr),m<d-T+f+_&&(I=Qr),I!==Ud?[Math.max(k-p-Hd(g,gs,I)-N,0),k-T-x+f+Hd(g,xs,I)+_]:null}),Te(d=>d!=null),ct(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Dt),{singleton:!0});function f0(e,t,n){if(ms(t)){const r=Dd(e,t);return[{index:ln(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 da={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ys(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,m=p-d;return{bottom:d,firstItemIndex:s,items:Kd(e,o,s),offsetBottom:m,offsetTop:c,top:h,topItems:Kd(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Vd(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=ca(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ys(c,[],a,o,n,r)}function Kd(e,t,n){if(e.length===0)return[];if(!ms(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=fs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const er=Ke(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:m}])=>{const g=ee([]),y=ee(0),x=Be();he(s.topItemsIndexes,g);const b=Nt(W(bt(h,m,Ce(l,Gr),Ce(o),Ce(r),Ce(c),d,Ce(g),Ce(t),Ce(n),e),Te(([T,I,,N,,,,,,,_])=>{const L=_&&_.length!==N;return T&&!I&&!L}),ce(([,,[T,I],N,_,L,R,O,F,A,B])=>{const j=_,{offsetTree:K,sizeTree:z}=j,M=vt(y);if(N===0)return{...da,totalCount:N};if(T===0&&I===0)return M===0?{...da,totalCount:N}:Vd(M,L,_,F,A,B||[]);if(ot(z))return M>0?null:ys(f0(ca(L,N),j,B),[],N,A,j,F);const G=[];if(O.length>0){const Y=O[0],U=O[O.length-1];let J=0;for(const $ of fs(z,Y,U)){const q=$.value,Z=Math.max($.start,Y),ue=Math.min($.end,U);for(let ie=Z;ie<=ue;ie++)G.push({data:B==null?void 0:B[ie],index:ie,offset:J,size:q}),J+=q}}if(!R)return ys([],G,N,A,j,F);const X=O.length>0?O[O.length-1]+1:0,se=e0(K,T,I,X);if(se.length===0)return null;const ve=N-1,Ie=ds([],Y=>{for(const U of se){const J=U.value;let $=J.offset,q=U.start;const Z=J.size;if(J.offset<T){q+=Math.floor((T-J.offset+A)/(Z+A));const ie=q-U.start;$+=ie*Z+ie*A}q<X&&($+=(X-q)*Z,q=X);const ue=Math.min(U.end,ve);for(let ie=q;ie<=ue&&!($>=I);ie++)Y.push({data:B==null?void 0:B[ie],index:ie,offset:$,size:Z}),$+=Z+A}});return ys(Ie,G,N,A,j,F)}),Te(T=>T!==null),ct()),da);he(W(e,Te(Ji),ce(T=>T==null?void 0:T.length)),o),he(W(b,ce(T=>T.topListHeight)),f),he(f,a),he(W(b,ce(T=>[T.top,T.bottom])),i),he(W(b,ce(T=>T.items)),x);const S=Ht(W(b,Te(({items:T})=>T.length>0),Oe(o,e),Te(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ce(([,T,I])=>[T-1,I]),ct(Gr),ce(([T])=>T))),k=Ht(W(b,En(200),Te(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ce(({items:T})=>T[0].index),ct())),C=Ht(W(b,Te(({items:T})=>T.length>0),ce(({items:T})=>{let I=0,N=T.length-1;for(;T[I].type==="group"&&I<N;)I++;for(;T[N].type==="group"&&N>I;)N--;return{endIndex:T[N].index,startIndex:T[I].index}}),ct(Pd)));return{endReached:S,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:g,...p}},lt(bn,Fd,ua,Jr,Xr,eo,Dn,sa),{singleton:!0}),qd=Ke(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Be(),i=Nt(W(bt(n,e,r,t,o),ce(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Dt,er),{singleton:!0}),p0=Ke(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(W(bt(n,e,t),Te(([o])=>o),ce(([,o,s])=>Math.max(0,o-s)),En(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Dt,qd),{singleton:!0}),Gd=Ke(()=>({context:ee(null)})),h0=({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,Yd=Ke(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Be();return he(W(d,Oe(t,l,n,s,o,r,a),Oe(e),ce(([[f,p,h,m,g,y,x,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=h0,done:I,...N}=f,_=Ld(f,p,m-1),L=Yr(_,p.offsetTree,S)+g+y,R=L+ln(p.sizeTree,_)[1],O=b+y,F=b+h-x,A=T({itemBottom:R,itemTop:L,locationParams:{align:k,behavior:C,...N},viewportBottom:F,viewportTop:O});return A?I&&an(W(i,Te(B=>!B),Jn(vt(i)?1:2)),I):I&&I(),A}),Te(f=>f!==null)),c),{scrollIntoView:d}},lt(bn,Dt,Xr,er,Pn),{singleton:!0});function Xd(e){return e?e==="smooth"?"smooth":"auto":!1}const m0=(e,t)=>typeof e=="function"?Xd(e(t)):t&&Xd(e),g0=Ke(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const m=ee(!1),g=Be();let y=null;function x(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Qe(W(bt(W(Ce(t),Jn(1)),l),Oe(Ce(m),s,a,f),ce(([[C,T],I,N,_,L])=>{let R=T&&_,O="auto";return R&&(O=m0(I,N||L),R=R&&!!O),{followOutputBehavior:O,shouldFollow:R,totalCount:C}}),Te(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Ft.DEBUG),x(C)}):y=an(e,()=>{vt(d)("following output to ",{totalCount:T},Ft.DEBUG),x(C),y=null})});function b(C){const T=an(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Ft.DEBUG),x("auto"))});setTimeout(T,100)}Qe(W(bt(Ce(m),t,c),Te(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Te(({refreshed:C})=>C),Oe(m,t)),([,C])=>{vt(a)&&b(C!==!1)}),Qe(g,()=>{b(vt(m)!==!1)}),Qe(bt(Ce(m),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=ee(null),k=Be();return he(Qi(W(Ce(r),ce(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),W(Ce(t))),k),Qe(W(bt(W(k,Jn(1)),l),Oe(Ce(S),a,f,p),ce(([[C,T],I,N,_,L])=>T&&N&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:_}))),Te(C=>!!C),En(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=an(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:S}},lt(bn,eo,Xr,Jr,Dn,Pn,Dt,Gd,Yd)),x0=Ke(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(W(a,Oe(s),Te(([,l])=>l!==0),Oe(o,r,t,n,e),ce(([[,l],c,d,f,p,h=[]])=>Vd(l,c,d,f,p,h))),i),{}),lt(bn,Jr,er,Dn),{singleton:!0}),y0=Ke(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Qe(W(e,Oe(r),Te(([,o])=>o!==0),ce(([,o])=>({top:o}))),o=>{an(W(n,Jn(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},lt(Dn,Dt,er),{singleton:!0}),Jd=Ke(([{scrollVelocity:e}])=>{const t=ee(!1),n=Be(),r=ee(!1);return he(W(e,Oe(r,t,n),Te(([o,s])=>!!s),ce(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Qe(W(bt(t,e,n),Oe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(eo),{singleton:!0}),fa=Ke(([{scrollContainerState:e,scrollTo:t}])=>{const n=Be(),r=Be(),o=Be(),s=ee(!1),i=ee(void 0);return he(W(bt(n,r),ce(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(W(t,Oe(r),ce(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Dt)),v0=Ke(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Be(),d=ee(void 0),f=ee(null),p=ee(null);return he(a,f),he(l,p),Qe(W(c,Oe(t,r,i,f,p,n)),([h,m,g,y,x,b,S])=>{const k=n0(m.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=S,h({ranges:k,scrollTop:g})}),he(W(d,Te(Ji),ce(b0)),o),he(W(s,Oe(d),Te(([,h])=>h!==void 0),ct(),ce(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(bn,Dt,Jr,Dn,fa));function b0(e){return{align:"start",index:0,offset:e.scrollTop}}const w0=Ke(([{topItemsIndexes:e}])=>{const t=ee(0);return he(W(t,Te(n=>n>=0),ce(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(er));function Zd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const S0=Zd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),C0=Ke(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:m}])=>{const g=Ht(W(l,Oe(i),vn(([,x,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},N])=>{const _=k+T;let L=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(L=_-S,L!==0&&(L+=N))),[L,C,I,_]},[0,[],0,0]),Te(([x])=>x!==0),Oe(r,a,n,o,h,m),Te(([,x,b,S,,,k])=>!k&&!S&&x!==0&&b===Zr),ce(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Ft.DEBUG),x))));function y(x){x>0?(Me(t,{behavior:"auto",top:-x}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-x}))}return Qe(W(g,Oe(e,s)),([x,b,S])=>{S&&S0()?Me(e,b-x):y(-x)}),Qe(W(bt(Nt(s,!1),e,m),Te(([x,b,S])=>!x&&!S&&b!==0),ce(([x,b])=>b),En(1)),y),he(W(f,ce(x=>({top:-x}))),t),Qe(W(c,Oe(p,d),ce(([x,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(x);{let I=0;const N=qr(k,0);let _=0,L=0;for(;_<x;){_++,I+=N;let R=b.length===L+1?1/0:b[L+1]-b[L]-1;_+R>x&&(I-=N,R=x-_+1),_+=R,I+=T(R),L++}return I}})),x=>{Me(e,x),requestAnimationFrame(()=>{Me(t,{top:x}),requestAnimationFrame(()=>{Me(e,0),Me(m,!1)})})}),{deviation:e}},lt(Dt,eo,er,bn,Pn,sa)),T0=Ke(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(ua,x0,Dn,Jd,qd,y0,p0,fa,Yd,Pn,Gd)),Qd=Ke(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m},g,y,x,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:N},_])=>(he(k.rangeChanged,_.scrollSeekRangeChanged),he(W(_.windowViewportRect,ce(L=>L.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,..._,...g,sizes:l,...y}),lt(bn,Jr,Dt,v0,g0,er,Xr,C0,w0,Fd,T0));function k0(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 vs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ef(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=w.createContext({});function l(y,x){y.propsReady&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,x[b])}for(const b of o)if(b in x){const S=y[t.optional[b]];Me(S,x[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=S=>{const k=y[t.methods[b]];Me(k,S)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=zw(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...S}=y,[k]=w.useState(()=>ds(Hw(e),I=>{l(I,S)})),[C]=w.useState(Cd(d,k));vs(()=>{for(const I of i)I in S&&Qe(C[I],S[I]);return()=>{Object.values(C).map(Zi)}},[S,C,k]),vs(()=>{l(k,S)}),w.useImperativeHandle(x,wd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...k0([...r,...o,...i],S),children:b}):b})}),p=y=>{const x=w.useContext(a);return w.useCallback(b=>{Me(x[y],b)},[x,y])},h=y=>{const x=w.useContext(a)[y],b=w.useCallback(S=>Qe(x,S),[x]);return w.useSyncExternalStore(b,()=>vt(x),()=>vt(x))},m=y=>{const x=w.useContext(a)[y],[b,S]=w.useState(Cd(vt,x));return vs(()=>Qe(x,k=>{k!==b&&S(wd(k))}),[x,b]),b},g=w.version.startsWith("18")?h:m;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];vs(()=>Qe(b,x),[x,b])},useEmitterValue:g,usePublisher:p}}const tf=w.createContext(void 0),nf=w.createContext(void 0),rf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function pa(e){return"self"in e}function I0(e){return"body"in e}function of(e,t,n,r=Cr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,m,g;const y=p.target;if(I0(y)||pa(y)){const b=pa(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,m=s?b.innerWidth:b.innerHeight}else g=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:h,scrollTop:Math.max(g,0),viewportHeight:m})};p.suppressFlushSync?x():Gs.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===h-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const m=p.behavior==="smooth";let g,y,x;pa(h)?(y=Math.max(On(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),g=s?h.innerWidth:h.innerHeight,x=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],g=On(h,s?"width":"height"),x=h[s?"scrollLeft":"scrollTop"]);const b=y-g;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),zd(g,y)||p.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ha="-webkit-sticky",sf="sticky",ma=Zd(()=>{if(typeof document>"u")return sf;const e=document.createElement("div");return e.style.position=ha,e.style.position===ha?ha:sf});function ga(e){return e}const E0=Ke(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ga),o=ee("div"),s=ee(Cr),i=(a,l=null)=>Nt(W(n,ce(c=>c[a]),ct()),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")}}),N0=Ke(([e,t])=>({...e,...t}),lt(Qd,E0)),A0=({height:e})=>u.jsx("div",{style:{height:e}}),_0={overflowAnchor:"none",position:ma(),zIndex:1},af={overflowAnchor:"none"},j0={...af,display:"inline-block",height:"100%"},lf=w.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=Zt("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=Zt("windowScrollContainerState"),i=Zt("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),c=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),p=Ne("itemSize"),h=Ne("log"),m=Zt("gap"),g=Ne("horizontalDirection"),{callbackRef:y}=Kw(n,p,f,e?Cr:a,h,m,o,g,Ne("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);xa("deviation",A=>{x!==A&&b(A)});const S=Ne("EmptyPlaceholder"),k=Ne("ScrollSeekPlaceholder")||A0,C=Ne("ListComponent"),T=Ne("ItemComponent"),I=Ne("GroupComponent"),N=Ne("computeItemKey"),_=Ne("isSeeking"),L=Ne("groupIndices").length>0,R=Ne("alignToBottom"),O=Ne("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:R?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:R?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...O?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...At(S,c)}):u.jsx(C,{...At(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(A=>{const B=A.originalIndex,j=N(B+t.firstItemIndex,A.data,c);return _?w.createElement(k,{...At(k,c),height:A.size,index:A.index,key:j,type:A.type||"item",...A.type==="group"?{}:{groupIndex:A.groupIndex}}):A.type==="group"?w.createElement(I,{...At(I,c),"data-index":B,"data-item-index":A.index,"data-known-size":A.size,key:j,style:_0},d(A.index,c)):w.createElement(T,{...At(T,c),...O0(T,A.data),"data-index":B,"data-item-group-index":A.groupIndex,"data-item-index":A.index,"data-known-size":A.size,key:j,style:g?j0:af},L?l(A.index,A.groupIndex,A.data,c):l(A.index,A.data,c))})})}),M0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},R0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),P0={position:ma(),top:0,width:"100%",zIndex:1};function At(e,t){if(typeof e!="string")return{context:t}}function O0(e,t){return{item:typeof e=="string"?void 0:t}}const D0=w.memo(function(){const e=Ne("HeaderComponent"),t=Zt("headerHeight"),n=Ne("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null}),L0=w.memo(function(){const e=Ne("FooterComponent"),t=Zt("footerHeight"),n=Ne("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null});function cf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:m}=of(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?R0:M0,...o},tabIndex:0,...i,...At(l,s),children:r})})}function uf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=w.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=of(a,c,l,m,p);return rf(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...At(l,s),children:r})})}const $0=({children:e})=>{const t=w.useContext(tf),n=Zt("viewportHeight"),r=Zt("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=w.useMemo(()=>Sd(n,l=>On(l,s?"width":"height")),[n,s]),a=Zn(i,!0,Ne("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:bs(o),children:e})},F0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("fixedItemHeight"),o=Ne("customScrollParent"),s=Ed(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:bs(i),children:e})},B0=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...P0,marginTop:`${n}px`},o=Ne("context");return u.jsx(t,{style:r,...At(t,o),children:e})},z0=w.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return u.jsxs(r||t?W0:H0,{...e,context:o,children:[n&&u.jsx(B0,{children:u.jsx(lf,{showTopList:!0})}),u.jsxs(r||t?F0:$0,{children:[u.jsx(D0,{}),u.jsx(lf,{}),u.jsx(L0,{})]})]})}),{Component:U0,useEmitter:xa,useEmitterValue:Ne,usePublisher:Zt}=ef(N0,{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"}},z0),H0=cf({useEmitter:xa,useEmitterValue:Ne,usePublisher:Zt}),W0=uf({useEmitter:xa,useEmitterValue:Ne,usePublisher:Zt}),V0=U0;lt(Qd,Ke(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ga),a=ee(Cr),l=(c,d=null)=>Nt(W(s,ce(f=>f[c]),ct()),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")}})),ma();const df={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},K0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:ff,floor:ws,max:to,min:ya,round:pf}=Math;function hf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function q0(e){return{...K0,items:e}}function Ss(e,t){return e&&e.width===t.width&&e.height===t.height}function G0(e,t){return e&&e.column===t.column&&e.row===t.row}const Y0=Ke(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),I=ee(0),N=ee(df),_=ee({height:0,width:0}),L=ee({height:0,width:0}),R=Be(),O=Be(),F=ee(0),A=ee(null),B=ee({column:0,row:0}),j=Be(),K=Be(),z=ee(!1),M=ee(0),G=ee(!0),X=ee(!1),se=ee(!1);Qe(W(m,Oe(M),Te(([$,q])=>!!q)),()=>{Me(G,!1)}),Qe(W(bt(m,G,L,_,M,X),Te(([$,q,Z,ue,,ie])=>$&&!q&&Z.height!==0&&ue.height!==0&&!ie)),([,,,,$])=>{Me(X,!0),la(1,()=>{Me(R,$)}),an(W(c),()=>{Me(t,[0,0]),Me(G,!0)})}),he(W(K,Te($=>$!=null&&$.scrollTop>0),yn(0)),I),Qe(W(m,Oe(K),Te(([,$])=>$!=null)),([,$])=>{$&&(Me(_,$.viewport),Me(L,$.item),Me(B,$.gap),$.scrollTop>0&&(Me(z,!0),an(W(c,Jn(1)),q=>{Me(z,!1)}),Me(l,{top:$.scrollTop})))}),he(W(_,ce(({height:$})=>$)),f),he(W(bt(Ce(_,Ss),Ce(L,Ss),Ce(B,($,q)=>$&&$.column===q.column&&$.row===q.row),Ce(c)),ce(([$,q,Z,ue])=>({gap:Z,item:q,scrollTop:ue,viewport:$}))),j),he(W(bt(Ce(T),r,Ce(B,G0),Ce(L,Ss),Ce(_,Ss),Ce(A),Ce(I),Ce(z),Ce(G),Ce(M)),Te(([,,,,,,,$])=>!$),ce(([$,[q,Z],ue,ie,_e,He,oe,,xe,Re])=>{const{column:Ye,row:nt}=ue,{height:Xe,width:qe}=ie,{width:it}=_e;if(oe===0&&($===0||it===0))return df;if(qe===0){const Mt=ca(Re,$),Bt=Mt+Math.max(oe-1,0);return q0(hf(Mt,Bt,He))}const Je=mf(it,qe,Ye);let et,at;xe?q===0&&Z===0&&oe>0?(et=0,at=oe-1):(et=Je*ws((q+nt)/(Xe+nt)),at=Je*ff((Z+nt)/(Xe+nt))-1,at=ya($-1,to(at,Je-1)),et=ya(at,to(0,et))):(et=0,at=-1);const jt=hf(et,at,He),{bottom:pt,top:ht}=gf(_e,ue,ie,jt),mt=ff($/Je),St=mt*Xe+(mt-1)*nt-pt;return{bottom:pt,itemHeight:Xe,items:jt,itemWidth:qe,offsetBottom:St,offsetTop:ht,top:ht}})),N),he(W(A,Te($=>$!==null),ce($=>$.length)),T),he(W(bt(_,L,N,B),Te(([$,q,{items:Z}])=>Z.length>0&&q.height!==0&&$.height!==0),ce(([$,q,{items:Z},ue])=>{const{bottom:ie,top:_e}=gf($,ue,q,Z);return[_e,ie]}),ct(Gr)),t);const ve=ee(!1);he(W(c,Oe(ve),ce(([$,q])=>q||$!==0)),ve);const Ie=Ht(W(bt(N,T),Te(([{items:$}])=>$.length>0),Oe(ve),Te(([[$,q],Z])=>{const ue=$.items[$.items.length-1].index===q-1;return(Z||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===q)&&ue}),ce(([[,$]])=>$-1),ct())),Y=Ht(W(Ce(N),Te(({items:$})=>$.length>0&&$[0].index===0),yn(0),ct())),U=Ht(W(Ce(N),Oe(z),Te(([{items:$},q])=>$.length>0&&!q),ce(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Pd),En(0)));he(U,h.scrollSeekRangeChanged),he(W(R,Oe(_,L,T,B),ce(([$,q,Z,ue,ie])=>{const _e=Bd($),{align:He,behavior:oe,offset:xe}=_e;let Re=_e.index;Re==="LAST"&&(Re=ue-1),Re=to(0,Re,ya(ue-1,Re));let Ye=va(q,ie,Z,Re);return He==="end"?Ye=pf(Ye-q.height+Z.height):He==="center"&&(Ye=pf(Ye-q.height/2+Z.height/2)),xe&&(Ye+=xe),{behavior:oe,top:Ye}})),l);const J=Nt(W(N,ce($=>$.offsetBottom+$.bottom)),0);return he(W(k,ce($=>({height:$.visibleHeight,width:$.visibleWidth}))),_),{customScrollParent:y,data:A,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:O,scrollTo:l,scrollToIndex:R,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:N,horizontalDirection:se,initialTopMostItemIndex:M,totalListHeight:J,...p,endReached:Ie,propsReady:g,rangeChanged:U,startReached:Y,stateChanged:j,stateRestoreInProgress:z,...C}},lt(ua,Dt,eo,Jd,Dn,fa,Pn));function mf(e,t,n){return to(1,ws((e+n)/(ws(t)+n)))}function gf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=va(e,t,n,r[0].index);return{bottom:va(e,t,n,r[r.length-1].index)+o,top:s}}function va(e,t,n,r){const o=mf(e.width,n.width,t.column),s=ws(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const X0=Ke(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ga),i=ee("div"),a=ee(Cr),l=(f,p=null)=>Nt(W(t,ce(h=>h[f]),ct()),p),c=ee(!1),d=ee(!1);return he(Ce(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),J0=Ke(([e,t])=>({...e,...t}),lt(Y0,X0)),Z0=w.memo(function(){const e=dt("gridState"),t=dt("listClassName"),n=dt("itemClassName"),r=dt("itemContent"),o=dt("computeItemKey"),s=dt("isSeeking"),i=Qt("scrollHeight"),a=dt("ItemComponent"),l=dt("ListComponent"),c=dt("ScrollSeekPlaceholder"),d=dt("context"),f=Qt("itemDimensions"),p=Qt("gap"),h=dt("log"),m=dt("stateRestoreInProgress"),g=Qt("reportReadyState"),y=Zn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:yf("column-gap",getComputedStyle(x).columnGap,h),row:yf("row-gap",getComputedStyle(x).rowGap,h)})},[i,f,p,h]),!0,!1);return rf(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,...At(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?u.jsx(c,{...At(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...At(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),Q0=w.memo(function(){const e=dt("HeaderComponent"),t=Qt("headerHeight"),n=dt("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null}),eS=w.memo(function(){const e=dt("FooterComponent"),t=Qt("footerHeight"),n=dt("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...At(e,o)})}):null}),tS=({children:e})=>{const t=w.useContext(nf),n=Qt("itemDimensions"),r=Qt("viewportDimensions"),o=Zn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:bs(!1),children:e})},nS=({children:e})=>{const t=w.useContext(nf),n=Qt("windowViewportRect"),r=Qt("itemDimensions"),o=dt("customScrollParent"),s=Ed(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:bs(!1),children:e})},rS=w.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?sS:oS,o=n||t?nS:tS,s=dt("context");return u.jsx(r,{...e,...At(r,s),children:u.jsxs(o,{children:[u.jsx(Q0,{}),u.jsx(Z0,{}),u.jsx(eS,{})]})})}),{useEmitter:xf,useEmitterValue:dt,usePublisher:Qt}=ef(J0,{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"}},rS),oS=cf({useEmitter:xf,useEmitterValue:dt,usePublisher:Qt}),sS=uf({useEmitter:xf,useEmitterValue:dt,usePublisher:Qt});function yf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}const iS=po.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 vf({className:e,variant:t,...n}){return u.jsx("div",{className:te(iS({variant:t}),e),...n})}function ba(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 bf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(bf(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=no(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 ro(e){if(typeof e=="string")return e;if(bf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function aS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function lS(e){const t=ro(e);return typeof e=="string"&&aS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Cs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=ba(t);if(n!==null)return Cs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Cs(e.content):e}function cS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function wf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Ts(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function uS(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
87
- `)):t(e)}function dS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Sf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function fS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function pS(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function hS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=fS(n),i=o?`data:${s};base64,${e}`:t,a=pS(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function mS(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return hS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Cf(e,t){return await Gt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Tf(e,t){return await(await Cf(`/files/${e}/view`,t)).text()}async function gS(e,t){const n=await Cf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Gt(`/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 xS(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Gt("/files",{params:r})}var ks="Dialog",[kf,rk]=Cn(ks),[yS,cn]=kf(ks),If=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:ks});return u.jsx(yS,{scope:t,triggerRef:a,contentRef:l,contentId:Tn(),titleId:Tn(),descriptionId:Tn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};If.displayName=ks;var Ef="DialogTrigger",Nf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Ef,n),s=Fe(t,o.triggerRef);return u.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ca(o.open),...r,ref:s,onClick:fe(e.onClick,o.onOpenToggle)})});Nf.displayName=Ef;var wa="DialogPortal",[vS,Af]=kf(wa,{forceMount:void 0}),_f=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=cn(wa,t);return u.jsx(vS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Xt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:i})}))})};_f.displayName=wa;var Is="DialogOverlay",jf=v.forwardRef((e,t)=>{const n=Af(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(Is,e.__scopeDialog);return s.modal?u.jsx(Xt,{present:r||s.open,children:u.jsx(wS,{...o,ref:t})}):null});jf.displayName=Is;var bS=Wn.createSlot("DialogOverlay.RemoveScroll"),wS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Is,n);return u.jsx(ns,{as:bS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ae.div,{"data-state":Ca(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),tr="DialogContent",Mf=v.forwardRef((e,t)=>{const n=Af(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(tr,e.__scopeDialog);return u.jsx(Xt,{present:r||s.open,children:s.modal?u.jsx(SS,{...o,ref:t}):u.jsx(CS,{...o,ref:t})})});Mf.displayName=tr;var SS=v.forwardRef((e,t)=>{const n=cn(tr,e.__scopeDialog),r=v.useRef(null),o=Fe(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Li(s)},[]),u.jsx(Rf,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:fe(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:fe(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault())})}),CS=v.forwardRef((e,t)=>{const n=cn(tr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Rf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Rf=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=cn(tr,n),l=v.useRef(null),c=Fe(t,l);return yi(),u.jsxs(u.Fragment,{children:[u.jsx(Oo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Po,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ca(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(TS,{titleId:a.titleId}),u.jsx(IS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Sa="DialogTitle",Pf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Sa,n);return u.jsx(Ae.h2,{id:o.titleId,...r,ref:t})});Pf.displayName=Sa;var Of="DialogDescription",Df=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Of,n);return u.jsx(Ae.p,{id:o.descriptionId,...r,ref:t})});Df.displayName=Of;var Lf="DialogClose",$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Lf,n);return u.jsx(Ae.button,{type:"button",...r,ref:t,onClick:fe(e.onClick,()=>o.onOpenChange(!1))})});$f.displayName=Lf;function Ca(e){return e?"open":"closed"}var Ff="DialogTitleWarning",[ok,Bf]=bx(Ff,{contentName:tr,titleName:Sa,docsSlug:"dialog"}),TS=({titleId:e})=>{const t=Bf(Ff),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
86
+ `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function Pw(e,t=cs){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 Ow(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Pw(t),Rw(t)}const us=0,Pn=1,wr=2,bd=4;function wd(e){return()=>e}function Dw(e){e()}function Sd(e,t){return n=>e(t(n))}function Cd(e,t){return()=>e(t)}function Lw(e,t){return n=>e(t,n)}function Ji(e){return e!==void 0}function $w(...e){return()=>{e.map(Dw)}}function Sr(){}function ds(e,t){return t(e),e}function Fw(e,t){return t(e)}function lt(...e){return e}function Ze(e,t){return e(Pn,t)}function Me(e,t){e(us,t)}function Zi(e){e(wr)}function vt(e){return e(bd)}function ge(e,t){return Ze(e,Lw(t,us))}function ln(e,t){const n=e(Pn,r=>{n(),t(r)});return n}function Td(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function kd(e,t){return e===t}function ct(e=kd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ue(e){return t=>Sd(t,e)}function yn(e){return t=>()=>{t(e)}}function K(e,...t){const n=Bw(...t);return(r,o)=>{switch(r){case wr:Zi(e);return;case Pn:return Ze(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Zn(e){return t=>n=>{e>0?e--:t(n)}}function An(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Pe(...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);Ze(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Bw(...e){return t=>e.reduceRight(Fw,t)}function zw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Pn:return s?n===s?void 0:(r(),n=s,t=Ze(e,s),t):(r(),Sr);case wr:r(),n=null;return}}}function ee(e){let t=e;const n=Fe();return(r,o)=>{switch(r){case us:t=o;break;case Pn:{o(t);break}case bd:return t}return n(r,o)}}function Nt(e,t){return ds(ee(t),n=>ge(e,n))}function Fe(){const e=[];return(t,n)=>{switch(t){case us:e.slice().forEach(r=>{r(n)});return;case wr:e.splice(0,e.length);return;case Pn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Wt(e){return ds(Fe(),t=>ge(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Uw(),singleton:n}}const Uw=()=>Symbol();function Hw(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 bt(...e){const t=Fe(),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);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case wr:{Zi(t);return}case Pn:return r===o&&i(n),Ze(t,i)}}}function Ce(e,t=kd){return K(e,ct(t))}function Qi(...e){return function(t,n){switch(t){case wr:return;case Pn:return $w(...e.map(r=>Ze(r,n)))}}}var Bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Bt||{});const Ww={0:"debug",3:"error",1:"log",2:"warn"},Vw=()=>typeof globalThis>"u"?window:globalThis,On=He(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Vw().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Ww[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Qn(e,t,n){return ea(e,t,n).callbackRef}function ea(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.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 Kw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=qw(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let m;h&&(m=p.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:h?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:h?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:h?a?m.innerWidth:m.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Id("column-gap",getComputedStyle(d).columnGap,o):Id("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ea(c,n,l)}function qw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Bt.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Id(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ed(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),m=c.top-h.top;p=h.height-Math.max(0,m),f=m+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ea(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Lt=He(()=>{const e=Fe(),t=Fe(),n=ee(0),r=Fe(),o=ee(0),s=Fe(),i=Fe(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Fe(),p=Fe(),h=ee(!1),m=ee(!1),g=ee(!1);return ge(K(e,ue(({scrollTop:y})=>y)),t),ge(K(e,ue(({scrollHeight:y})=>y)),i),ge(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:m,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Kr={lvl:0};function Ad(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 rt(e){return e===Kr}function qr(e,t){if(!rt(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function cn(e,t,n="k"){if(rt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=cn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return cn(e.l,t,n)}function Vt(e,t,n){return rt(e)?jd(t,n,1):t===e.k?wt(e,{k:t,v:n}):t<e.k?Md(wt(e,{l:Vt(e.l,t,n)})):Md(wt(e,{r:Vt(e.r,t,n)}))}function Cr(){return Kr}function fs(e,t,n){if(rt(e))return[];const r=cn(e,t)[0];return Gw(na(e,r,n))}function ta(e,t){if(rt(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(rt(r))return o;if(rt(o))return r;{const[s,i]=_d(r);return ps(wt(e,{k:s,l:Nd(r),v:i}))}}else return t<n?ps(wt(e,{l:ta(r,t)})):ps(wt(e,{r:ta(o,t)}))}function er(e){return rt(e)?[]:[...er(e.l),{k:e.k,v:e.v},...er(e.r)]}function na(e,t,n){if(rt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(na(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(na(s,t,n))),a}function ps(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(ra(t))return Rd(wt(e,{lvl:n-1}));if(!rt(t)&&!rt(t.r))return wt(t.r,{l:wt(t,{r:t.r.l}),lvl:n,r:wt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ra(e))return oa(wt(e,{lvl:n-1}));if(!rt(r)&&!rt(r.l)){const o=r.l,s=ra(o)?r.lvl-1:r.lvl;return wt(o,{l:wt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:oa(wt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function wt(e,t){return jd(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 Nd(e){return rt(e.r)?e.l:ps(wt(e,{r:Nd(e.r)}))}function ra(e){return rt(e)||e.lvl>e.r.lvl}function _d(e){return rt(e.r)?[e.k,e.v]:_d(e.r)}function jd(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function Md(e){return oa(Rd(e))}function Rd(e){const{l:t}=e;return!rt(t)&&t.lvl===e.lvl?wt(t,{r:wt(e,{l:t.r})}):e}function oa(e){const{lvl:t,r:n}=e;return!rt(n)&&!rt(n.r)&&n.lvl===t&&n.r.lvl===t?wt(n,{l:wt(e,{r:n.l}),lvl:t+1}):e}function Gw(e){return Ad(e,({k:t,v:n})=>({index:t,value:n}))}function Pd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const sa=He(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Od(e,t,n){return e[hs(e,t,n)]}function hs(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 Yw(e,t,n,r){const o=hs(e,t,r),s=hs(e,n,r,o);return e.slice(o,s+1)}function Dn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ms(e){return!rt(e.groupOffsetTree)}function ia({index:e},t){return t===e?0:t<e?-1:1}function Xw(){return{groupIndices:[],groupOffsetTree:Cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Cr()}}function Jw(e,t){let n=rt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),rt(e)){e=Vt(e,0,s);continue}const a=fs(e,i-1,o+1);if(a.some(o0(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ta(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Vt(e,o+1,p));c&&(e=Vt(e,i,s))}return[e,n]}function Zw(e){return typeof e.groupIndex<"u"}function Qw({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Od(t,e,ia),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Dd(e,t){if(!ms(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Ld(e,t,n){if(Zw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Dd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function e0(e,t,n,r=0){return r>0&&(t=Math.max(t,Od(e,r,ia).offset)),Ad(Yw(e,t,n,Qw),r0)}function t0(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&rt(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((m,g)=>Vt(Vt(m,g,p),g+1,h),i)}else[i,a]=Jw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=aa(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Vt(p,h,Yr(h,f,o)),Cr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function n0(e){return er(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 $d(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 aa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=hs(o,t-1,ia),a=o[l].offset;const c=cn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===cn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of fs(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function r0(e){return{index:e.index,value:e}}function o0(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 s0={offsetHeight:"height",offsetWidth:"width"},bn=He(([{log:e},{recalcInProgress:t}])=>{const n=Fe(),r=Fe(),o=Nt(r,0),s=Fe(),i=Fe(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Dn(C,s0[T])),p=ee(void 0),h=ee(0),m=Xw(),g=Nt(K(n,Pe(l,e,h),vn(t0,m),ct()),m),y=Nt(K(l,ct(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ue(({prev:C})=>C)),[]);ge(K(l,ke(C=>C.length>0),Pe(g,h),ue(([C,T,I])=>{const N=C.reduce((_,L,B)=>Vt(_,L,Yr(L,T.offsetTree,I)||B),Cr());return{...T,groupIndices:C,groupOffsetTree:N}})),g),ge(K(r,Pe(g),ke(([C,{lastIndex:T}])=>C<T),ue(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),ge(c,d);const x=Nt(K(c,ue(C=>C===void 0)),!0);ge(K(d,ke(C=>C!==void 0&&rt(vt(g).sizeTree)),ue(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Wt(K(n,Pe(g),vn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:m}),ue(C=>C.changed)));Ze(K(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ue(C=>C.diff)),C=>{const{groupIndices:T}=vt(g);if(C>0)Me(t,!0),Me(s,C+$d(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=$d(-C,I)),Me(i,C)}}),Ze(K(a,Pe(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Bt.ERROR)});const S=Wt(s);ge(K(s,Pe(g),ue(([C,T])=>{const I=T.groupIndices.length>0,N=[],_=T.lastSize;if(I){const L=qr(T.sizeTree,0);let B=0,G=0;for(;B<C;){const R=T.groupIndices[G],M=T.groupIndices.length===G+1?1/0:T.groupIndices[G+1]-R-1;N.push({endIndex:R,size:L,startIndex:R}),N.push({endIndex:R+1+M-1,size:_,startIndex:R+1}),G++,B+=M+1}const V=er(T.sizeTree);return B!==C&&V.shift(),V.reduce((R,{k:M,v:A})=>{let F=R.ranges;return R.prevSize!==0&&(F=[...R.ranges,{endIndex:M+C-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:M+C,prevSize:A,ranges:F}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return er(T.sizeTree).reduce((L,{k:B,v:G})=>({prevIndex:B+C,prevSize:G,ranges:[...L.ranges,{endIndex:B+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Wt(K(i,Pe(g,h),ue(([C,{offsetTree:T},I])=>{const N=-C;return Yr(N,T,I)})));return ge(K(i,Pe(g,h),ue(([C,T,I])=>{if(T.groupIndices.length>0){if(rt(T.sizeTree))return T;let N=Cr();const _=vt(y);let L=0,B=0,G=0;for(;L<-C;){G=_[B];const V=_[B+1]-G-1;B++,L+=V+1}if(N=er(T.sizeTree).reduce((V,{k:R,v:M})=>Vt(V,Math.max(0,R+C),M),N),L!==-C){const V=qr(T.sizeTree,G);N=Vt(N,0,V);const R=cn(T.sizeTree,-C+1)[1];N=Vt(N,1,R)}return{...T,sizeTree:N,...aa(T.offsetTree,0,N,I)}}else{const N=er(T.sizeTree).reduce((_,{k:L,v:B})=>Vt(_,Math.max(0,L+C),B),Cr());return{...T,sizeTree:N,...aa(T.offsetTree,0,N,I)}}})),g),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},lt(On,sa),{singleton:!0});function i0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Fd=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Fe(),i=Fe(),a=Wt(K(s,ue(i0)));return ge(K(a,ue(l=>l.totalCount)),n),ge(K(a,ue(l=>l.groupIndices)),e),ge(K(bt(o,t,r),ke(([l,c])=>ms(c)),ue(([l,c,d])=>cn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ue(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(bn,Lt)),Ln=He(([{log:e}])=>{const t=ee(!1),n=Wt(K(t,ke(r=>r),ct()));return Ze(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},lt(On),{singleton:!0}),a0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Bd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!a0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Xr=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=Fe(),m=Fe(),g=ee(0);let y=null,x=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Me(l,!1)}return ge(K(h,Pe(n,f,r,g,a,i,p),Pe(e,s,o),ue(([[k,C,T,I,N,_,L,B],G,V,R])=>{const M=Bd(k),{align:A,behavior:F,offset:D}=M,P=I-1,z=Ld(M,C,P);let X=Yr(z,C.offsetTree,G)+_;A==="end"?(X+=V+cn(C.sizeTree,z)[1]-T+R,z===P&&(X+=L)):A==="center"?X+=(V+cn(C.sizeTree,z)[1]-T+R)/2:X-=N,D&&(X+=D);const ne=ye=>{S(),ye?(B("retrying to scroll to",{location:k},Bt.DEBUG),Me(h,k)):(Me(m,!0),B("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),F==="smooth"){let ye=!1;b=Ze(t,Te=>{ye=ye||Te}),y=ln(d,()=>{ne(ye)})}else y=ln(K(t,l0(150)),ne);return x=setTimeout(()=>{S()},1200),Me(l,!0),B("scrolling from index to",{behavior:F,index:z,top:X},Bt.DEBUG),{behavior:F,top:X}})),c),{scrollTargetReached:m,scrollToIndex:h,topListHeight:g}},lt(bn,Lt,On),{singleton:!0});function l0(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function la(e,t){e==0?t():requestAnimationFrame(()=>{la(e-1,t)})}function ca(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return ge(K(i,Pe(l),ke(([d,f])=>!!f),yn(!1)),a),ge(K(i,Pe(l),ke(([d,f])=>!!f),yn(!1)),c),Ze(K(bt(t,i),Pe(a,n,e,c),ke(([[,d],f,{sizeTree:p},h,m])=>d&&(!rt(p)||Ji(h))&&!f&&!m),Pe(l)),([,d])=>{ln(o,()=>{Me(c,!0)}),la(4,()=>{ln(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(bn,Lt,Xr,Ln),{singleton:!0});function zd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",c0="none",u0={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},d0=0,eo=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Fe(),c=Fe(),d=ee(4),f=ee(d0),p=Nt(K(Qi(K(Ce(o),Zn(1),yn(!0)),K(Ce(o),Zn(1),yn(!1),Td(100))),ct()),!1),h=Nt(K(Qi(K(n,yn(!0)),K(n,yn(!1),Td(200))),ct()),!1);ge(K(bt(Ce(o),Ce(f)),ue(([b,S])=>b<=S),ct()),a),ge(K(a,An(50)),c);const m=Wt(K(bt(r,Ce(s),Ce(t),Ce(e),Ce(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,I,N])=>{const _=k+C-S>-N,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let G,V;return k>b.state.scrollTop?(G="SCROLLED_DOWN",V=b.state.scrollTop-k):(G="SIZE_DECREASED",V=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:G,scrollTopDelta:V,state:L}}let B;return L.scrollHeight>b.state.scrollHeight?B="SIZE_INCREASED":C<b.state.viewportHeight?B="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?B="SCROLLING_UPWARDS":B="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:B,state:L}},u0),ct((b,S)=>b&&b.atBottom===S.atBottom))),g=Nt(K(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(zd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),ue(b=>b.jump)),0);ge(K(m,ue(b=>b.atBottom)),i),ge(K(i,An(50)),l);const y=ee(Qr);ge(K(r,ue(({scrollTop:b})=>b),ct(),vn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Zr:Qr,prevScrollTop:S},{direction:Qr,prevScrollTop:0}),ue(b=>b.direction)),y),ge(K(r,An(50),yn(c0)),y);const x=ee(0);return ge(K(p,ke(b=>!b),yn(0)),x),ge(K(o,An(100),Pe(p),ke(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),ue(([b,S])=>S-b)),x),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:g,scrollDirection:y,scrollVelocity:x}},lt(Lt)),gs="top",xs="bottom",Ud="none";function Hd(e,t,n){return typeof e=="number"?n===Zr&&t===gs||n===Qr&&t===xs?e:0:n===Zr?t===gs?e.main:e.reverse:t===xs?e.main:e.reverse}function Wd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ua=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Fe(),i=ee(0),a=ee(0),l=ee(0),c=Nt(K(bt(Ce(r),Ce(o),Ce(n),Ce(s,Gr),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),ue(([d,f,p,[h,m],g,y,x,b,S])=>{const k=d-b,C=y+x,T=Math.max(p-k,0);let I=Ud;const N=Wd(S,gs),_=Wd(S,xs);return h-=b,h+=p+x,m+=p+x,m-=b,h>d+C-N&&(I=Zr),m<d-T+f+_&&(I=Qr),I!==Ud?[Math.max(k-p-Hd(g,gs,I)-N,0),k-T-x+f+Hd(g,xs,I)+_]:null}),ke(d=>d!=null),ct(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Lt),{singleton:!0});function f0(e,t,n){if(ms(t)){const r=Dd(e,t);return[{index:cn(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 da={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ys(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,m=p-d;return{bottom:d,firstItemIndex:s,items:Kd(e,o,s),offsetBottom:m,offsetTop:c,top:h,topItems:Kd(t,o,s),topListHeight:t.reduce((g,y)=>y.size+g,0),totalCount:n}}function Vd(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=ca(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ys(c,[],a,o,n,r)}function Kd(e,t,n){if(e.length===0)return[];if(!ms(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=fs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const tr=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:m}])=>{const g=ee([]),y=ee(0),x=Fe();ge(s.topItemsIndexes,g);const b=Nt(K(bt(h,m,Ce(l,Gr),Ce(o),Ce(r),Ce(c),d,Ce(g),Ce(t),Ce(n),e),ke(([T,I,,N,,,,,,,_])=>{const L=_&&_.length!==N;return T&&!I&&!L}),ue(([,,[T,I],N,_,L,B,G,V,R,M])=>{const A=_,{offsetTree:F,sizeTree:D}=A,P=vt(y);if(N===0)return{...da,totalCount:N};if(T===0&&I===0)return P===0?{...da,totalCount:N}:Vd(P,L,_,V,R,M||[]);if(rt(D))return P>0?null:ys(f0(ca(L,N),A,M),[],N,R,A,V);const z=[];if(G.length>0){const q=G[0],U=G[G.length-1];let J=0;for(const $ of fs(D,q,U)){const Y=$.value,Z=Math.max($.start,q),de=Math.min($.end,U);for(let oe=Z;oe<=de;oe++)z.push({data:M==null?void 0:M[oe],index:oe,offset:J,size:Y}),J+=Y}}if(!B)return ys([],z,N,R,A,V);const X=G.length>0?G[G.length-1]+1:0,ne=e0(F,T,I,X);if(ne.length===0)return null;const ye=N-1,Te=ds([],q=>{for(const U of ne){const J=U.value;let $=J.offset,Y=U.start;const Z=J.size;if(J.offset<T){Y+=Math.floor((T-J.offset+R)/(Z+R));const oe=Y-U.start;$+=oe*Z+oe*R}Y<X&&($+=(X-Y)*Z,Y=X);const de=Math.min(U.end,ye);for(let oe=Y;oe<=de&&!($>=I);oe++)q.push({data:M==null?void 0:M[oe],index:oe,offset:$,size:Z}),$+=Z+R}});return ys(Te,z,N,R,A,V)}),ke(T=>T!==null),ct()),da);ge(K(e,ke(Ji),ue(T=>T==null?void 0:T.length)),o),ge(K(b,ue(T=>T.topListHeight)),f),ge(f,a),ge(K(b,ue(T=>[T.top,T.bottom])),i),ge(K(b,ue(T=>T.items)),x);const S=Wt(K(b,ke(({items:T})=>T.length>0),Pe(o,e),ke(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ue(([,T,I])=>[T-1,I]),ct(Gr),ue(([T])=>T))),k=Wt(K(b,An(200),ke(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ue(({items:T})=>T[0].index),ct())),C=Wt(K(b,ke(({items:T})=>T.length>0),ue(({items:T})=>{let I=0,N=T.length-1;for(;T[I].type==="group"&&I<N;)I++;for(;T[N].type==="group"&&N>I;)N--;return{endIndex:T[N].index,startIndex:T[I].index}}),ct(Pd)));return{endReached:S,initialItemCount:y,itemsRendered:x,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:g,...p}},lt(bn,Fd,ua,Jr,Xr,eo,Ln,sa),{singleton:!0}),qd=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Fe(),i=Nt(K(bt(n,e,r,t,o),ue(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ge(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Lt,tr),{singleton:!0}),p0=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(K(bt(n,e,t),ke(([o])=>o),ue(([,o,s])=>Math.max(0,o-s)),An(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Lt,qd),{singleton:!0}),Gd=He(()=>({context:ee(null)})),h0=({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,Yd=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Fe();return ge(K(d,Pe(t,l,n,s,o,r,a),Pe(e),ue(([[f,p,h,m,g,y,x,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=h0,done:I,...N}=f,_=Ld(f,p,m-1),L=Yr(_,p.offsetTree,S)+g+y,B=L+cn(p.sizeTree,_)[1],G=b+y,V=b+h-x,R=T({itemBottom:B,itemTop:L,locationParams:{align:k,behavior:C,...N},viewportBottom:V,viewportTop:G});return R?I&&ln(K(i,ke(M=>!M),Zn(vt(i)?1:2)),I):I&&I(),R}),ke(f=>f!==null)),c),{scrollIntoView:d}},lt(bn,Lt,Xr,tr,On),{singleton:!0});function Xd(e){return e?e==="smooth"?"smooth":"auto":!1}const m0=(e,t)=>typeof e=="function"?Xd(e(t)):t&&Xd(e),g0=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const m=ee(!1),g=Fe();let y=null;function x(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Ze(K(bt(K(Ce(t),Zn(1)),l),Pe(Ce(m),s,a,f),ue(([[C,T],I,N,_,L])=>{let B=T&&_,G="auto";return B&&(G=m0(I,N||L),B=B&&!!G),{followOutputBehavior:G,shouldFollow:B,totalCount:C}}),ke(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),x(C)}):y=ln(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),x(C),y=null})});function b(C){const T=ln(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),x("auto"))});setTimeout(T,100)}Ze(K(bt(Ce(m),t,c),ke(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),Pe(m,t)),([,C])=>{vt(a)&&b(C!==!1)}),Ze(g,()=>{b(vt(m)!==!1)}),Ze(bt(Ce(m),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const S=ee(null),k=Fe();return ge(Qi(K(Ce(r),ue(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),K(Ce(t))),k),Ze(K(bt(K(k,Zn(1)),l),Pe(Ce(S),a,f,p),ue(([[C,T],I,N,_,L])=>T&&N&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:_}))),ke(C=>!!C),An(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=ln(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:S}},lt(bn,eo,Xr,Jr,Ln,On,Lt,Gd,Yd)),x0=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(K(a,Pe(s),ke(([,l])=>l!==0),Pe(o,r,t,n,e),ue(([[,l],c,d,f,p,h=[]])=>Vd(l,c,d,f,p,h))),i),{}),lt(bn,Jr,tr,Ln),{singleton:!0}),y0=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Ze(K(e,Pe(r),ke(([,o])=>o!==0),ue(([,o])=>({top:o}))),o=>{ln(K(n,Zn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},lt(Ln,Lt,tr),{singleton:!0}),Jd=He(([{scrollVelocity:e}])=>{const t=ee(!1),n=Fe(),r=ee(!1);return ge(K(e,Pe(r,t,n),ke(([o,s])=>!!s),ue(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Ze(K(bt(t,e,n),Pe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(eo),{singleton:!0}),fa=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=Fe(),r=Fe(),o=Fe(),s=ee(!1),i=ee(void 0);return ge(K(bt(n,r),ue(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ge(K(t,Pe(r),ue(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Lt)),v0=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Fe(),d=ee(void 0),f=ee(null),p=ee(null);return ge(a,f),ge(l,p),Ze(K(c,Pe(t,r,i,f,p,n)),([h,m,g,y,x,b,S])=>{const k=n0(m.sizeTree);y&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=S,h({ranges:k,scrollTop:g})}),ge(K(d,ke(Ji),ue(b0)),o),ge(K(s,Pe(d),ke(([,h])=>h!==void 0),ct(),ue(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(bn,Lt,Jr,Ln,fa));function b0(e){return{align:"start",index:0,offset:e.scrollTop}}const w0=He(([{topItemsIndexes:e}])=>{const t=ee(0);return ge(K(t,ke(n=>n>=0),ue(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(tr));function Zd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const S0=Zd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),C0=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:m}])=>{const g=Wt(K(l,Pe(i),vn(([,x,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},N])=>{const _=k+T;let L=0;return b===I&&x.length>0&&C.length>0&&(C[0].originalIndex===0&&x[0].originalIndex===0||(L=_-S,L!==0&&(L+=N))),[L,C,I,_]},[0,[],0,0]),ke(([x])=>x!==0),Pe(r,a,n,o,h,m),ke(([,x,b,S,,,k])=>!k&&!S&&x!==0&&b===Zr),ue(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Bt.DEBUG),x))));function y(x){x>0?(Me(t,{behavior:"auto",top:-x}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-x}))}return Ze(K(g,Pe(e,s)),([x,b,S])=>{S&&S0()?Me(e,b-x):y(-x)}),Ze(K(bt(Nt(s,!1),e,m),ke(([x,b,S])=>!x&&!S&&b!==0),ue(([x,b])=>b),An(1)),y),ge(K(f,ue(x=>({top:-x}))),t),Ze(K(c,Pe(p,d),ue(([x,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(x);{let I=0;const N=qr(k,0);let _=0,L=0;for(;_<x;){_++,I+=N;let B=b.length===L+1?1/0:b[L+1]-b[L]-1;_+B>x&&(I-=N,B=x-_+1),_+=B,I+=T(B),L++}return I}})),x=>{Me(e,x),requestAnimationFrame(()=>{Me(t,{top:x}),requestAnimationFrame(()=>{Me(e,0),Me(m,!1)})})}),{deviation:e}},lt(Lt,eo,tr,bn,On,sa)),T0=He(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(ua,x0,Ln,Jd,qd,y0,p0,fa,Yd,On,Gd)),Qd=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m},g,y,x,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:N},_])=>(ge(k.rangeChanged,_.scrollSeekRangeChanged),ge(K(_.windowViewportRect,ue(L=>L.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:m,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,..._,...g,sizes:l,...y}),lt(bn,Jr,Lt,v0,g0,tr,Xr,C0,w0,Fd,T0));function k0(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 vs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ef(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=w.createContext({});function l(y,x){y.propsReady&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,x[b])}for(const b of o)if(b in x){const S=y[t.optional[b]];Me(S,x[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((x,b)=>(x[b]=S=>{const k=y[t.methods[b]];Me(k,S)},x),{})}function d(y){return i.reduce((x,b)=>(x[b]=zw(y[t.events[b]]),x),{})}const f=w.forwardRef((y,x)=>{const{children:b,...S}=y,[k]=w.useState(()=>ds(Hw(e),I=>{l(I,S)})),[C]=w.useState(Cd(d,k));vs(()=>{for(const I of i)I in S&&Ze(C[I],S[I]);return()=>{Object.values(C).map(Zi)}},[S,C,k]),vs(()=>{l(k,S)}),w.useImperativeHandle(x,wd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...k0([...r,...o,...i],S),children:b}):b})}),p=y=>{const x=w.useContext(a);return w.useCallback(b=>{Me(x[y],b)},[x,y])},h=y=>{const x=w.useContext(a)[y],b=w.useCallback(S=>Ze(x,S),[x]);return w.useSyncExternalStore(b,()=>vt(x),()=>vt(x))},m=y=>{const x=w.useContext(a)[y],[b,S]=w.useState(Cd(vt,x));return vs(()=>Ze(x,k=>{k!==b&&S(wd(k))}),[x,b]),b},g=w.version.startsWith("18")?h:m;return{Component:f,useEmitter:(y,x)=>{const b=w.useContext(a)[y];vs(()=>Ze(b,x),[x,b])},useEmitterValue:g,usePublisher:p}}const tf=w.createContext(void 0),nf=w.createContext(void 0),rf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function pa(e){return"self"in e}function I0(e){return"body"in e}function of(e,t,n,r=Sr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,m,g;const y=p.target;if(I0(y)||pa(y)){const b=pa(y)?y:y.defaultView;g=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,m=s?b.innerWidth:b.innerHeight}else g=s?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,m=s?y.offsetWidth:y.offsetHeight;const x=()=>{e({scrollHeight:h,scrollTop:Math.max(g,0),viewportHeight:m})};p.suppressFlushSync?x():Gs.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===h-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const m=p.behavior==="smooth";let g,y,x;pa(h)?(y=Math.max(Dn(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),g=s?h.innerWidth:h.innerHeight,x=s?window.scrollX:window.scrollY):(y=h[s?"scrollWidth":"scrollHeight"],g=Dn(h,s?"width":"height"),x=h[s?"scrollLeft":"scrollTop"]);const b=y-g;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),zd(g,y)||p.top===x){e({scrollHeight:y,scrollTop:x,viewportHeight:g}),m&&t(!0);return}m?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ha="-webkit-sticky",sf="sticky",ma=Zd(()=>{if(typeof document>"u")return sf;const e=document.createElement("div");return e.style.position=ha,e.style.position===ha?ha:sf});function ga(e){return e}const E0=He(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ga),o=ee("div"),s=ee(Sr),i=(a,l=null)=>Nt(K(n,ue(c=>c[a]),ct()),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")}}),A0=He(([e,t])=>({...e,...t}),lt(Qd,E0)),N0=({height:e})=>u.jsx("div",{style:{height:e}}),_0={overflowAnchor:"none",position:ma(),zIndex:1},af={overflowAnchor:"none"},j0={...af,display:"inline-block",height:"100%"},lf=w.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Zt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Zt("windowScrollContainerState"),i=Zt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),p=Ae("itemSize"),h=Ae("log"),m=Zt("gap"),g=Ae("horizontalDirection"),{callbackRef:y}=Kw(n,p,f,e?Sr:a,h,m,o,g,Ae("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);xa("deviation",R=>{x!==R&&b(R)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||N0,C=Ae("ListComponent"),T=Ae("ItemComponent"),I=Ae("GroupComponent"),N=Ae("computeItemKey"),_=Ae("isSeeking"),L=Ae("groupIndices").length>0,B=Ae("alignToBottom"),G=Ae("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:x!==0?x:B?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:x!==0?x:B?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...G?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:V,children:(e?t.topItems:t.items).map(R=>{const M=R.originalIndex,A=N(M+t.firstItemIndex,R.data,c);return _?w.createElement(k,{..._t(k,c),height:R.size,index:R.index,key:A,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?w.createElement(I,{..._t(I,c),"data-index":M,"data-item-index":R.index,"data-known-size":R.size,key:A,style:_0},d(R.index,c)):w.createElement(T,{..._t(T,c),...O0(T,R.data),"data-index":M,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:A,style:g?j0:af},L?l(R.index,R.groupIndex,R.data,c):l(R.index,R.data,c))})})}),M0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},R0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),P0={position:ma(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function O0(e,t){return{item:typeof e=="string"?void 0:t}}const D0=w.memo(function(){const e=Ae("HeaderComponent"),t=Zt("headerHeight"),n=Ae("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),L0=w.memo(function(){const e=Ae("FooterComponent"),t=Zt("footerHeight"),n=Ae("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function cf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:m}=of(a,c,l,d,void 0,f);return e("scrollTo",m),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?R0:M0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function uf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=w.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:y,scrollToCallback:x}=of(a,c,l,m,p);return rf(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,p]),e("windowScrollTo",x),e("scrollBy",g),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,..._t(l,s),children:r})})}const $0=({children:e})=>{const t=w.useContext(tf),n=Zt("viewportHeight"),r=Zt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>Sd(n,l=>Dn(l,s?"width":"height")),[n,s]),a=Qn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:bs(o),children:e})},F0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("fixedItemHeight"),o=Ae("customScrollParent"),s=Ed(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:bs(i),children:e})},B0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...P0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},z0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?W0:H0,{...e,context:o,children:[n&&u.jsx(B0,{children:u.jsx(lf,{showTopList:!0})}),u.jsxs(r||t?F0:$0,{children:[u.jsx(D0,{}),u.jsx(lf,{}),u.jsx(L0,{})]})]})}),{Component:U0,useEmitter:xa,useEmitterValue:Ae,usePublisher:Zt}=ef(A0,{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"}},z0),H0=cf({useEmitter:xa,useEmitterValue:Ae,usePublisher:Zt}),W0=uf({useEmitter:xa,useEmitterValue:Ae,usePublisher:Zt}),V0=U0;lt(Qd,He(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ga),a=ee(Sr),l=(c,d=null)=>Nt(K(s,ue(f=>f[c]),ct()),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")}})),ma();const df={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},K0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:ff,floor:ws,max:to,min:ya,round:pf}=Math;function hf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function q0(e){return{...K0,items:e}}function Ss(e,t){return e&&e.width===t.width&&e.height===t.height}function G0(e,t){return e&&e.column===t.column&&e.row===t.row}const Y0=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:m,propsReady:g},{customScrollParent:y,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),I=ee(0),N=ee(df),_=ee({height:0,width:0}),L=ee({height:0,width:0}),B=Fe(),G=Fe(),V=ee(0),R=ee(null),M=ee({column:0,row:0}),A=Fe(),F=Fe(),D=ee(!1),P=ee(0),z=ee(!0),X=ee(!1),ne=ee(!1);Ze(K(m,Pe(P),ke(([$,Y])=>!!Y)),()=>{Me(z,!1)}),Ze(K(bt(m,z,L,_,P,X),ke(([$,Y,Z,de,,oe])=>$&&!Y&&Z.height!==0&&de.height!==0&&!oe)),([,,,,$])=>{Me(X,!0),la(1,()=>{Me(B,$)}),ln(K(c),()=>{Me(t,[0,0]),Me(z,!0)})}),ge(K(F,ke($=>$!=null&&$.scrollTop>0),yn(0)),I),Ze(K(m,Pe(F),ke(([,$])=>$!=null)),([,$])=>{$&&(Me(_,$.viewport),Me(L,$.item),Me(M,$.gap),$.scrollTop>0&&(Me(D,!0),ln(K(c,Zn(1)),Y=>{Me(D,!1)}),Me(l,{top:$.scrollTop})))}),ge(K(_,ue(({height:$})=>$)),f),ge(K(bt(Ce(_,Ss),Ce(L,Ss),Ce(M,($,Y)=>$&&$.column===Y.column&&$.row===Y.row),Ce(c)),ue(([$,Y,Z,de])=>({gap:Z,item:Y,scrollTop:de,viewport:$}))),A),ge(K(bt(Ce(T),r,Ce(M,G0),Ce(L,Ss),Ce(_,Ss),Ce(R),Ce(I),Ce(D),Ce(z),Ce(P)),ke(([,,,,,,,$])=>!$),ue(([$,[Y,Z],de,oe,_e,ze,se,,me,Re])=>{const{column:Ve,row:ut}=de,{height:Ke,width:qe}=oe,{width:Qe}=_e;if(se===0&&($===0||Qe===0))return df;if(qe===0){const Rt=ca(Re,$),zt=Rt+Math.max(se-1,0);return q0(hf(Rt,zt,ze))}const Ge=mf(Qe,qe,Ve);let et,st;me?Y===0&&Z===0&&se>0?(et=0,st=se-1):(et=Ge*ws((Y+ut)/(Ke+ut)),st=Ge*ff((Z+ut)/(Ke+ut))-1,st=ya($-1,to(st,Ge-1)),et=ya(st,to(0,et))):(et=0,st=-1);const Mt=hf(et,st,ze),{bottom:gt,top:Ct}=gf(_e,de,oe,Mt),it=ff($/Ge),St=it*Ke+(it-1)*ut-gt;return{bottom:gt,itemHeight:Ke,items:Mt,itemWidth:qe,offsetBottom:St,offsetTop:Ct,top:Ct}})),N),ge(K(R,ke($=>$!==null),ue($=>$.length)),T),ge(K(bt(_,L,N,M),ke(([$,Y,{items:Z}])=>Z.length>0&&Y.height!==0&&$.height!==0),ue(([$,Y,{items:Z},de])=>{const{bottom:oe,top:_e}=gf($,de,Y,Z);return[_e,oe]}),ct(Gr)),t);const ye=ee(!1);ge(K(c,Pe(ye),ue(([$,Y])=>Y||$!==0)),ye);const Te=Wt(K(bt(N,T),ke(([{items:$}])=>$.length>0),Pe(ye),ke(([[$,Y],Z])=>{const de=$.items[$.items.length-1].index===Y-1;return(Z||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===Y)&&de}),ue(([[,$]])=>$-1),ct())),q=Wt(K(Ce(N),ke(({items:$})=>$.length>0&&$[0].index===0),yn(0),ct())),U=Wt(K(Ce(N),Pe(D),ke(([{items:$},Y])=>$.length>0&&!Y),ue(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Pd),An(0)));ge(U,h.scrollSeekRangeChanged),ge(K(B,Pe(_,L,T,M),ue(([$,Y,Z,de,oe])=>{const _e=Bd($),{align:ze,behavior:se,offset:me}=_e;let Re=_e.index;Re==="LAST"&&(Re=de-1),Re=to(0,Re,ya(de-1,Re));let Ve=va(Y,oe,Z,Re);return ze==="end"?Ve=pf(Ve-Y.height+Z.height):ze==="center"&&(Ve=pf(Ve-Y.height/2+Z.height/2)),me&&(Ve+=me),{behavior:se,top:Ve}})),l);const J=Nt(K(N,ue($=>$.offsetBottom+$.bottom)),0);return ge(K(k,ue($=>({height:$.visibleHeight,width:$.visibleWidth}))),_),{customScrollParent:y,data:R,deviation:V,footerHeight:o,gap:M,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:F,scrollBy:i,scrollContainerState:a,scrollHeight:G,scrollTo:l,scrollToIndex:B,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:N,horizontalDirection:ne,initialTopMostItemIndex:P,totalListHeight:J,...p,endReached:Te,propsReady:g,rangeChanged:U,startReached:q,stateChanged:A,stateRestoreInProgress:D,...C}},lt(ua,Lt,eo,Jd,Ln,fa,On));function mf(e,t,n){return to(1,ws((e+n)/(ws(t)+n)))}function gf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=va(e,t,n,r[0].index);return{bottom:va(e,t,n,r[r.length-1].index)+o,top:s}}function va(e,t,n,r){const o=mf(e.width,n.width,t.column),s=ws(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const X0=He(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ga),i=ee("div"),a=ee(Sr),l=(f,p=null)=>Nt(K(t,ue(h=>h[f]),ct()),p),c=ee(!1),d=ee(!1);return ge(Ce(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),J0=He(([e,t])=>({...e,...t}),lt(Y0,X0)),Z0=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Qt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Qt("itemDimensions"),p=Qt("gap"),h=ft("log"),m=ft("stateRestoreInProgress"),g=Qt("reportReadyState"),y=Qn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const S=x.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:yf("column-gap",getComputedStyle(x).columnGap,h),row:yf("row-gap",getComputedStyle(x).rowGap,h)})},[i,f,p,h]),!0,!1);return rf(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:u.jsx(l,{className:t,ref:y,..._t(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(x=>{const b=o(x.index,x.data,d);return s?u.jsx(c,{..._t(c,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),Q0=w.memo(function(){const e=ft("HeaderComponent"),t=Qt("headerHeight"),n=ft("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),eS=w.memo(function(){const e=ft("FooterComponent"),t=Qt("footerHeight"),n=ft("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),tS=({children:e})=>{const t=w.useContext(nf),n=Qt("itemDimensions"),r=Qt("viewportDimensions"),o=Qn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:bs(!1),children:e})},nS=({children:e})=>{const t=w.useContext(nf),n=Qt("windowViewportRect"),r=Qt("itemDimensions"),o=ft("customScrollParent"),s=Ed(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:bs(!1),children:e})},rS=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?sS:oS,o=n||t?nS:tS,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(Q0,{}),u.jsx(Z0,{}),u.jsx(eS,{})]})})}),{useEmitter:xf,useEmitterValue:ft,usePublisher:Qt}=ef(J0,{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"}},rS),oS=cf({useEmitter:xf,useEmitterValue:ft,usePublisher:Qt}),sS=uf({useEmitter:xf,useEmitterValue:ft,usePublisher:Qt});function yf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const iS=po.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 vf({className:e,variant:t,...n}){return u.jsx("div",{className:te(iS({variant:t}),e),...n})}function ba(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 bf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(bf(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=no(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 ro(e){if(typeof e=="string")return e;if(bf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function aS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function lS(e){const t=ro(e);return typeof e=="string"&&aS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Cs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=ba(t);if(n!==null)return Cs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Cs(e.content):e}function cS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function wf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Ts(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function uS(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
87
+ `)):t(e)}function dS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Sf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function fS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function pS(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function hS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=fS(n),i=o?`data:${s};base64,${e}`:t,a=pS(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function mS(e){var o,s;const t=((o=e.content_base64)==null?void 0:o.trim())||void 0,n=((s=e.url)==null?void 0:s.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return hS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Cf(e,t){return await Gt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Tf(e,t){return await(await Cf(`/files/${e}/view`,t)).text()}async function gS(e,t){const n=await Cf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Gt(`/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 xS(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Gt("/files",{params:r})}var ks="Dialog",[kf,rk]=Tn(ks),[yS,un]=kf(ks),If=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:ks});return u.jsx(yS,{scope:t,triggerRef:a,contentRef:l,contentId:kn(),titleId:kn(),descriptionId:kn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};If.displayName=ks;var Ef="DialogTrigger",Af=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Ef,n),s=$e(t,o.triggerRef);return u.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ca(o.open),...r,ref:s,onClick:pe(e.onClick,o.onOpenToggle)})});Af.displayName=Ef;var wa="DialogPortal",[vS,Nf]=kf(wa,{forceMount:void 0}),_f=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=un(wa,t);return u.jsx(vS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Xt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:i})}))})};_f.displayName=wa;var Is="DialogOverlay",jf=v.forwardRef((e,t)=>{const n=Nf(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(Is,e.__scopeDialog);return s.modal?u.jsx(Xt,{present:r||s.open,children:u.jsx(wS,{...o,ref:t})}):null});jf.displayName=Is;var bS=Vn.createSlot("DialogOverlay.RemoveScroll"),wS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Is,n);return u.jsx(ns,{as:bS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":Ca(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",Mf=v.forwardRef((e,t)=>{const n=Nf(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(nr,e.__scopeDialog);return u.jsx(Xt,{present:r||s.open,children:s.modal?u.jsx(SS,{...o,ref:t}):u.jsx(CS,{...o,ref:t})})});Mf.displayName=nr;var SS=v.forwardRef((e,t)=>{const n=un(nr,e.__scopeDialog),r=v.useRef(null),o=$e(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Li(s)},[]),u.jsx(Rf,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:pe(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:pe(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:pe(e.onFocusOutside,s=>s.preventDefault())})}),CS=v.forwardRef((e,t)=>{const n=un(nr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Rf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Rf=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=un(nr,n),l=v.useRef(null),c=$e(t,l);return yi(),u.jsxs(u.Fragment,{children:[u.jsx(Oo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Po,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ca(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(TS,{titleId:a.titleId}),u.jsx(IS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Sa="DialogTitle",Pf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Sa,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Pf.displayName=Sa;var Of="DialogDescription",Df=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Of,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Df.displayName=Of;var Lf="DialogClose",$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Lf,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:pe(e.onClick,()=>o.onOpenChange(!1))})});$f.displayName=Lf;function Ca(e){return e?"open":"closed"}var Ff="DialogTitleWarning",[ok,Bf]=bx(Ff,{contentName:nr,titleName:Sa,docsSlug:"dialog"}),TS=({titleId:e})=>{const t=Bf(Ff),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
88
88
 
89
89
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
90
90
 
91
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},kS="DialogDescriptionWarning",IS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Bf(kS).contentName}}.`;return v.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},zf=If,ES=Nf,Uf=_f,Es=jf,Ns=Mf,nr=Pf,As=Df,Hf=$f;const NS=zf,AS=Uf,Wf=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{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}));Wf.displayName=Es.displayName;const Vf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===nr||(c==null?void 0:c.displayName)===nr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(AS,{children:[u.jsx(Wf,{}),u.jsxs(Ns,{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&&u.jsx(nr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Hf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Vf.displayName=Ns.displayName;const Kf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Kf.displayName="DialogHeader";const qf=v.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));qf.displayName=nr.displayName;const _S=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));_S.displayName=As.displayName;const jS=1,MS=1e6;let Ta=0;function RS(){return Ta=(Ta+1)%Number.MAX_SAFE_INTEGER,Ta.toString()}const ka=new Map,Gf=e=>{if(ka.has(e))return;const t=setTimeout(()=>{ka.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},MS);ka.set(e,t)},PS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,jS)};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?Gf(n):e.toasts.forEach(r=>{Gf(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)}}},_s=[];let js={toasts:[]};function oo(e){js=PS(js,e),_s.forEach(t=>{t(js)})}function OS({...e}){const t=RS(),n=o=>oo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>oo({type:"DISMISS_TOAST",toastId:t});return oo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ia(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:OS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function DS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Ia(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Tf(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]);w.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await gS(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"})}},m=async()=>{if(n)try{const x=await Tf(n),b=new Blob([x],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(le.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Ze,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(le.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(le.Image,{className:"h-5 w-5"}):u.jsx(le.FileText,{className:"h-5 w-5"});return u.jsx(NS,{open:e,onOpenChange:t,children:u.jsxs(Vf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Kf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(qf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ze,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ze,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(le.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function Yf(){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 rr=Yf();function LS(e){rr=e}const Xf=/[&<>"']/,$S=new RegExp(Xf.source,"g"),Jf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,FS=new RegExp(Jf.source,"g"),BS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Zf=e=>BS[e];function _t(e,t){if(t){if(Xf.test(e))return e.replace($S,Zf)}else if(Jf.test(e))return e.replace(FS,Zf);return e}const zS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Qf(e){return e.replace(zS,(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 US=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(US,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const HS=/[^\w:]/g,WS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ep(e,t,n){if(e){let r;try{r=decodeURIComponent(Qf(n)).replace(HS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!WS.test(n)&&(n=GS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ms={},VS=/^[^:]+:\/*[^/]*$/,KS=/^([^:]+:)[\s\S]*$/,qS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function GS(e,t){Ms[" "+e]||(VS.test(e)?Ms[" "+e]=e+"/":Ms[" "+e]=Ps(e,"/",!0)),e=Ms[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(KS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(qS,"$1")+t:e+t}const Rs={exec:function(){}};function tp(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ps(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 YS(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 XS(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 np(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function rp(e,t,n,r){const o=t.href,s=t.title?_t(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:_t(i)}}function JS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
91
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},kS="DialogDescriptionWarning",IS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Bf(kS).contentName}}.`;return v.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},zf=If,ES=Af,Uf=_f,Es=jf,As=Mf,rr=Pf,Ns=Df,Hf=$f;const AS=zf,NS=Uf,Wf=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{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}));Wf.displayName=Es.displayName;const Vf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===rr||(c==null?void 0:c.displayName)===rr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(NS,{children:[u.jsx(Wf,{}),u.jsxs(As,{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&&u.jsx(rr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Hf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Vf.displayName=As.displayName;const Kf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Kf.displayName="DialogHeader";const qf=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));qf.displayName=rr.displayName;const _S=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));_S.displayName=Ns.displayName;const jS=1,MS=1e6;let Ta=0;function RS(){return Ta=(Ta+1)%Number.MAX_SAFE_INTEGER,Ta.toString()}const ka=new Map,Gf=e=>{if(ka.has(e))return;const t=setTimeout(()=>{ka.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},MS);ka.set(e,t)},PS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,jS)};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?Gf(n):e.toasts.forEach(r=>{Gf(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)}}},_s=[];let js={toasts:[]};function oo(e){js=PS(js,e),_s.forEach(t=>{t(js)})}function OS({...e}){const t=RS(),n=o=>oo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>oo({type:"DISMISS_TOAST",toastId:t});return oo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ia(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:OS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function DS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Ia(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Tf(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]);w.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await gS(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"})}},m=async()=>{if(n)try{const x=await Tf(n),b=new Blob([x],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(le.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Je,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(le.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(le.Image,{className:"h-5 w-5"}):u.jsx(le.FileText,{className:"h-5 w-5"});return u.jsx(AS,{open:e,onOpenChange:t,children:u.jsxs(Vf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Kf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(qf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Je,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Je,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(le.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function Yf(){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 or=Yf();function LS(e){or=e}const Xf=/[&<>"']/,$S=new RegExp(Xf.source,"g"),Jf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,FS=new RegExp(Jf.source,"g"),BS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Zf=e=>BS[e];function jt(e,t){if(t){if(Xf.test(e))return e.replace($S,Zf)}else if(Jf.test(e))return e.replace(FS,Zf);return e}const zS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Qf(e){return e.replace(zS,(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 US=/(^|[^\[])\^/g;function ot(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(US,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const HS=/[^\w:]/g,WS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ep(e,t,n){if(e){let r;try{r=decodeURIComponent(Qf(n)).replace(HS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!WS.test(n)&&(n=GS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ms={},VS=/^[^:]+:\/*[^/]*$/,KS=/^([^:]+:)[\s\S]*$/,qS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function GS(e,t){Ms[" "+e]||(VS.test(e)?Ms[" "+e]=e+"/":Ms[" "+e]=Ps(e,"/",!0)),e=Ms[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(KS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(qS,"$1")+t:e+t}const Rs={exec:function(){}};function tp(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ps(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 YS(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 XS(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 np(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function rp(e,t,n,r){const o=t.href,s=t.title?jt(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:jt(i)}}function JS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
92
92
  `).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(`
93
- `)}class Ea{constructor(t){this.options=t||rr}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:Ps(r,`
93
+ `)}class Ea{constructor(t){this.options=t||or}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:Ps(r,`
94
94
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=JS(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=Ps(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,p,h,m,g=n[1].trim();const y=g.length>1,x={type:"list",raw:"",ordered:y,start:y?+g.slice(0,-1):"",loose:!1,items:[]};g=y?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=y?g:"[*+-]");const b=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
95
95
  `,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
96
96
  `,1)[0],this.options.pedantic?(i=2,h=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,h=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
@@ -98,10 +98,10 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
98
98
  `,1)[0],f=p,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||I.test(f)||k.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())h+=`
99
99
  `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||C.test(d))break;h+=`
100
100
  `+f}!l&&!f.trim()&&(l=!0),r+=p+`
101
- `,t=t.substring(p.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(h),o&&(s=o[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:h}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=h.trimRight(),x.raw=x.raw.trimRight();const S=x.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const k=x.items[a].tokens.filter(T=>T.type==="space"),C=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));x.loose=C}if(x.loose)for(a=0;a<S;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):_t(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:tp(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
101
+ `,t=t.substring(p.length+1),d=f.slice(i)}}x.loose||(c?x.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(h),o&&(s=o[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:h}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=h.trimRight(),x.raw=x.raw.trimRight();const S=x.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const k=x.items[a].tokens.filter(T=>T.type==="space"),C=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));x.loose=C}if(x.loose)for(a=0;a<S;a++)x.items[a].loose=!0;return x}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:tp(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
102
102
  `):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=tp(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
103
- `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:_t(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):_t(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ps(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=YS(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),rp(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return rp(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const p=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const m=p.slice(1,-1);return{type:"em",raw:p,text:m,tokens:this.lexer.inlineTokens(m)}}const h=p.slice(2,-2);return{type:"strong",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=_t(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=_t(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=_t(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=_t(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=_t(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):_t(r[0]):r[0]:o=_t(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ye={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:Rs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ye._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ye._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ye.def=st(ye.def).replace("label",ye._label).replace("title",ye._title).getRegex(),ye.bullet=/(?:[*+-]|\d{1,9}[.)])/,ye.listItemStart=st(/^( *)(bull) */).replace("bull",ye.bullet).getRegex(),ye.list=st(ye.list).replace(/bull/g,ye.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ye.def.source+")").getRegex(),ye._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ye._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ye.html=st(ye.html,"i").replace("comment",ye._comment).replace("tag",ye._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ye.paragraph=st(ye._paragraph).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ye._tag).getRegex(),ye.blockquote=st(ye.blockquote).replace("paragraph",ye.paragraph).getRegex(),ye.normal={...ye},ye.gfm={...ye.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ye.gfm.table=st(ye.gfm.table).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ye._tag).getRegex(),ye.gfm.paragraph=st(ye._paragraph).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ye.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ye._tag).getRegex(),ye.pedantic={...ye.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ye._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Rs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(ye.normal._paragraph).replace("hr",ye.hr).replace("heading",` *#{1,6} *[^
104
- ]`).replace("lheading",ye.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const de={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Rs,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Rs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};de._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",de.punctuation=st(de.punctuation).replace(/punctuation/g,de._punctuation).getRegex(),de.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,de.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,de._comment=st(ye._comment).replace("(?:-->|$)","-->").getRegex(),de.emStrong.lDelim=st(de.emStrong.lDelim).replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimAst=st(de.emStrong.rDelimAst,"g").replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimUnd=st(de.emStrong.rDelimUnd,"g").replace(/punct/g,de._punctuation).getRegex(),de._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,de._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,de._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,de.autolink=st(de.autolink).replace("scheme",de._scheme).replace("email",de._email).getRegex(),de._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,de.tag=st(de.tag).replace("comment",de._comment).replace("attribute",de._attribute).getRegex(),de._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,de._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,de._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,de.link=st(de.link).replace("label",de._label).replace("href",de._href).replace("title",de._title).getRegex(),de.reflink=st(de.reflink).replace("label",de._label).replace("ref",ye._label).getRegex(),de.nolink=st(de.nolink).replace("ref",ye._label).getRegex(),de.reflinkSearch=st(de.reflinkSearch,"g").replace("reflink",de.reflink).replace("nolink",de.nolink).getRegex(),de.normal={...de},de.pedantic={...de.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:st(/^!?\[(label)\]\((.*?)\)/).replace("label",de._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",de._label).getRegex()},de.gfm={...de.normal,escape:st(de.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},de.gfm.url=st(de.gfm.url,"i").replace("email",de.gfm._extended_email).getRegex(),de.breaks={...de.gfm,br:st(de.br).replace("{2,}","*").getRegex(),text:st(de.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function ZS(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}function op(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class Ln{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||rr,this.options.tokenizer=this.options.tokenizer||new Ea,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ye.normal,inline:de.normal};this.options.pedantic?(n.block=ye.pedantic,n.inline=de.pedantic):this.options.gfm&&(n.block=ye.gfm,this.options.breaks?n.inline=de.breaks:n.inline=de.gfm),this.tokenizer.rules=n}static get rules(){return{block:ye,inline:de}}static lex(t,n){return new Ln(n).lex(t)}static lexInline(t,n){return new Ln(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
103
+ `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:jt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ps(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=YS(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),rp(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return rp(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const p=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const m=p.slice(1,-1);return{type:"em",raw:p,text:m,tokens:this.lexer.inlineTokens(m)}}const h=p.slice(2,-2);return{type:"strong",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=jt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=jt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=jt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=jt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=jt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):jt(r[0]):r[0]:o=jt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ve={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:Rs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ve._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ve._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ve.def=ot(ve.def).replace("label",ve._label).replace("title",ve._title).getRegex(),ve.bullet=/(?:[*+-]|\d{1,9}[.)])/,ve.listItemStart=ot(/^( *)(bull) */).replace("bull",ve.bullet).getRegex(),ve.list=ot(ve.list).replace(/bull/g,ve.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ve.def.source+")").getRegex(),ve._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ve._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ve.html=ot(ve.html,"i").replace("comment",ve._comment).replace("tag",ve._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ve.paragraph=ot(ve._paragraph).replace("hr",ve.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ve._tag).getRegex(),ve.blockquote=ot(ve.blockquote).replace("paragraph",ve.paragraph).getRegex(),ve.normal={...ve},ve.gfm={...ve.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ve.gfm.table=ot(ve.gfm.table).replace("hr",ve.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ve._tag).getRegex(),ve.gfm.paragraph=ot(ve._paragraph).replace("hr",ve.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ve.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ve._tag).getRegex(),ve.pedantic={...ve.normal,html:ot(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ve._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Rs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ot(ve.normal._paragraph).replace("hr",ve.hr).replace("heading",` *#{1,6} *[^
104
+ ]`).replace("lheading",ve.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const fe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Rs,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Rs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};fe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",fe.punctuation=ot(fe.punctuation).replace(/punctuation/g,fe._punctuation).getRegex(),fe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,fe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,fe._comment=ot(ve._comment).replace("(?:-->|$)","-->").getRegex(),fe.emStrong.lDelim=ot(fe.emStrong.lDelim).replace(/punct/g,fe._punctuation).getRegex(),fe.emStrong.rDelimAst=ot(fe.emStrong.rDelimAst,"g").replace(/punct/g,fe._punctuation).getRegex(),fe.emStrong.rDelimUnd=ot(fe.emStrong.rDelimUnd,"g").replace(/punct/g,fe._punctuation).getRegex(),fe._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,fe._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,fe._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,fe.autolink=ot(fe.autolink).replace("scheme",fe._scheme).replace("email",fe._email).getRegex(),fe._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,fe.tag=ot(fe.tag).replace("comment",fe._comment).replace("attribute",fe._attribute).getRegex(),fe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,fe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,fe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,fe.link=ot(fe.link).replace("label",fe._label).replace("href",fe._href).replace("title",fe._title).getRegex(),fe.reflink=ot(fe.reflink).replace("label",fe._label).replace("ref",ve._label).getRegex(),fe.nolink=ot(fe.nolink).replace("ref",ve._label).getRegex(),fe.reflinkSearch=ot(fe.reflinkSearch,"g").replace("reflink",fe.reflink).replace("nolink",fe.nolink).getRegex(),fe.normal={...fe},fe.pedantic={...fe.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:ot(/^!?\[(label)\]\((.*?)\)/).replace("label",fe._label).getRegex(),reflink:ot(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",fe._label).getRegex()},fe.gfm={...fe.normal,escape:ot(fe.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},fe.gfm.url=ot(fe.gfm.url,"i").replace("email",fe.gfm._extended_email).getRegex(),fe.breaks={...fe.gfm,br:ot(fe.br).replace("{2,}","*").getRegex(),text:ot(fe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function ZS(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}function op(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class $n{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||or,this.options.tokenizer=this.options.tokenizer||new Ea,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ve.normal,inline:fe.normal};this.options.pedantic?(n.block=ve.pedantic,n.inline=fe.pedantic):this.options.gfm&&(n.block=ve.gfm,this.options.breaks?n.inline=fe.breaks:n.inline=fe.gfm),this.tokenizer.rules=n}static get rules(){return{block:ve,inline:fe}}static lex(t,n){return new $n(n).lex(t)}static lexInline(t,n){return new $n(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
105
105
  `),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
106
106
  `:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
107
107
  `+r.raw,o.text+=`
@@ -111,9 +111,9 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
111
111
  `+r.raw,o.text+=`
112
112
  `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
113
113
  `+r.raw,o.text+=`
114
- `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+np("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(a=this.tokenizer.rules.inline.blockSkip.exec(i))!=null;)i=i.slice(0,a.index)+"["+np("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,op)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,op))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let p;this.options.extensions.startInline.forEach(function(h){p=h.call({lexer:this},f),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,ZS)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class Na{constructor(t){this.options=t||rr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
115
- `,o?'<pre><code class="'+this.options.langPrefix+_t(o)+'">'+(r?t:_t(t,!0))+`</code></pre>
116
- `:"<pre><code>"+(r?t:_t(t,!0))+`</code></pre>
114
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+np("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(a=this.tokenizer.rules.inline.blockSkip.exec(i))!=null;)i=i.slice(0,a.index)+"["+np("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,op)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,op))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let p;this.options.extensions.startInline.forEach(function(h){p=h.call({lexer:this},f),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,ZS)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class Aa{constructor(t){this.options=t||or}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
115
+ `,o?'<pre><code class="'+this.options.langPrefix+jt(o)+'">'+(r?t:jt(t,!0))+`</code></pre>
116
+ `:"<pre><code>"+(r?t:jt(t,!0))+`</code></pre>
117
117
  `}blockquote(t){return`<blockquote>
118
118
  ${t}</blockquote>
119
119
  `}html(t){return t}heading(t,n,r,o){if(this.options.headerIds){const s=this.options.headerPrefix+o.slug(r);return`<h${n} id="${s}">${t}</h${n}>
@@ -131,7 +131,7 @@ ${t}</blockquote>
131
131
  `}tablerow(t){return`<tr>
132
132
  ${t}</tr>
133
133
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
134
- `}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=ep(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=ep(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 sp{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 ip{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 $n{constructor(t){this.options=t||rr,this.options.renderer=this.options.renderer||new Na,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new sp,this.slugger=new ip}static parse(t,n){return new $n(n).parse(t)}static parseInline(t,n){return new $n(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,m,g,y,x,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,Qf(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(m=h.ordered,g=h.start,y=h.loose,a=h.items.length,p="",s=0;s<a;s++)b=h.items[s],S=b.checked,k=b.task,x="",b.task&&(C=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):x+=C),x+=this.parse(b.tokens,y),p+=this.renderer.listitem(x,k,S);r+=this.renderer.list(p,m,g);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<I&&t[o+1].type==="text";)h=t[++o],p+=`
135
- `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Os{constructor(t){this.options=t||rr}preprocess(t){return t}postprocess(t){return t}}Uh(Os,"passThroughHooks",new Set(["preprocess","postprocess"]));function QS(e,t,n){return r=>{if(r.message+=`
136
- Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+_t(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 ap(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ge.defaults,...s};const i=QS(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(XS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&ge.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ge.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ge.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&&ge.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ge(e,t,n){return ap(Ln.lex,$n.parse)(e,t,n)}ge.options=ge.setOptions=function(e){return ge.defaults={...ge.defaults,...e},LS(ge.defaults),ge},ge.getDefaults=Yf,ge.defaults=rr,ge.use=function(...e){const t=ge.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ge.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=ge.defaults.renderer||new Na;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=ge.defaults.tokenizer||new Ea;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=ge.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(ge.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ge.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}}ge.setOptions(r)})},ge.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ge,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ge.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ge.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ge.walkTokens(r.items,t));break}default:ge.defaults.extensions&&ge.defaults.extensions.childTokens&&ge.defaults.extensions.childTokens[r.type]?ge.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ge.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ge.walkTokens(r.tokens,t)))}return n},ge.parseInline=ap(Ln.lexInline,$n.parseInline),ge.Parser=$n,ge.parser=$n.parse,ge.Renderer=Na,ge.TextRenderer=sp,ge.Lexer=Ln,ge.lexer=Ln.lex,ge.Tokenizer=Ea,ge.Slugger=ip,ge.Hooks=Os,ge.parse=ge,ge.options,ge.setOptions,ge.use,ge.walkTokens,ge.parseInline,$n.parse,Ln.lex;function so({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.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 typeof ge.parse=="function"?ge.parse(i):ge(i)}return typeof ge.parse=="function"?ge.parse(e):ge(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const eC={MODE:"library"};function tC(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?eC:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function nC(){return!tC()}function rC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function oC(){return nC()||rC()}function sC({preview:e,idx:t}){return w.useEffect(()=>{oC()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function iC({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const aC="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function up({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:aC,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}function lC({message:e,viewMode:t}){const r=wf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?ba(c)??c:c;if(d&&typeof d=="object")return u.jsx(up,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=lS(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function cC({message:e,viewMode:t,isStreaming:n=!1}){var c;const r=e.name??"tool",o=w.useMemo(()=>{const d=e.additionalKwargs??{};return(Array.isArray(d.toolProgress)?[...d.toolProgress]:[]).slice(-6)},[e]),s=o.filter(d=>d.type==="progress"),i=o.some(d=>d.type==="tool_start"||d.type==="tool_call"||d.type==="message_start"),a=((c=s[s.length-1])==null?void 0:c.title)??(i?`Running ${r}…`:void 0),l=n||i||s.length>0;return u.jsxs("div",{className:"space-y-2",children:[l&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[n&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:a??`Running ${r}…`})]}),s.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:s.map((d,f)=>u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px] uppercase opacity-70",children:[u.jsx("span",{children:d.title??d.step??`Step ${d.idx??f+1}`}),u.jsx("span",{className:"text-[8px] lowercase",children:d.type??"progress"})]}),d.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:d.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof d.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",d.factsFound]}),typeof d.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",d.isSufficient?"sufficient":"needs more data"]})]})]},`progress-${r}-${f}`))})]}),u.jsx(lC,{message:e,viewMode:t})]})}function uC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ia(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,m,g)=>{var y,x;if(!t){h.preventDefault();return}if(o[g]){h.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=m.name||`file_${k}`,T=m.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await xS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof I.size=="number"?I.size===m.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:m.name||T.filename||`file_${T.id}`,mimeType:m.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(x=k.update)==null||x.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function dC({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ze,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function fC({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function dp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ds=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:m,onRegenerate:g,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:L=null}){const[R,O]=w.useState(!1),[F,A]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:K}=_o(),{respondToInterrupt:z}=jo(),M=l==="phone"||l==="half-screen",G=t.role,X=G==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ve=!!se,Ie=!(r&&G!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:q}=uC({allowFileOpen:Ie,currentThreadId:K}),Z=w.useMemo(()=>{switch(G){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))]"}},[G]),ue=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?cS(D):""},[se,t]),ie=w.useMemo(()=>{if(se)return{};const D=t.content;return Array.isArray(D)?wf(t):{}},[se,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),He=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="image_url"):[]},[se,t]),oe=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="file"):[]},[se,t]),xe=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="interrupt"):[]},[se,t]),Re=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ye=Ts(Re),nt=b==null?void 0:b.value,Xe=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?uS(D):""},[se,t]),qe=w.useMemo(()=>{if(se||!p)return[];const Q=t.artifact;if(!Q)return[];const ne=[],me=[...Array.isArray(Q.plots)?Q.plots:[]];for(const ke of me){const Pe=mS(ke);Pe&&ne.push(Pe)}return ne},[se,t,p]),it=w.useCallback(async()=>{const D=X?Xe:ue;async function Q(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const me=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":me})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(D),O(!0),setTimeout(()=>O(!1),2e3),x==null||x(D)}catch(ne){console.error("Failed to copy:",ne)}},[X,Xe,ue,x]),Je=w.useCallback(()=>{if(!m)return;const D=X?Xe:ue,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};m(t.id,D,Q)},[m,t.id,X,Xe,ue,t]),et=w.useCallback(()=>{g==null||g(n)},[g,n]),at=w.useCallback(()=>{const Q=te(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(G){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[M,Z,G]),jt=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(G){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[G]),pt=w.useCallback(()=>{const D=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");if(ve)return te(D,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(G){case"user":return te(D,"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(D,"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(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"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")}},[M,ve,G]),ht=w.useCallback(async D=>{if(S)return;const Q=Ts((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),mt=w.useCallback(async D=>{if(S)return;const Q=Ts((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),St=w.useCallback(({part:D,i:Q})=>{if(D.type==="text"){const ne=D.text??"",me=ne.trim(),ke=ba(me);return ke&&G!=="tool"?u.jsx(up,{data:ke},Q):G==="user"&&c&&me.length>d?u.jsx(dC,{text:me,expanded:B,onExpandedChange:j,previewLength:d,isCompact:M},Q):u.jsx(so,{content:ne,allowHtml:!1},Q)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(D.type==="file"){const ne=D,me=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:ke=>U(ke.nativeEvent,ne,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[me,Y[Q]?" (processing)":""]})]},Q)}if(D.type==="interrupt"){const ne=D,me=Ts((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),ke=!!(Ye&&me&&me===Ye),Pe=ke?nt??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,De=me?{...ne,id:me,interrupt_id:me}:ne;return u.jsx(iC,{interruptPart:De,onApprove:ht,onReject:mt,disabled:S,isActive:ke,payload:Pe},Q)}return null},[U,Y,ht,mt,G,c,d,B,M,Ye,nt,b,S,xe]),Mt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Bt=w.useCallback(()=>{const D=ue.trim().length>0||He.length>0||oe.length>0||xe.length>0;if(!X&&oe.length>0&&!r)return Mt();if(!X&&!D&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(cC,{message:t,viewMode:F,isStreaming:_e},t.id):null;if(!X&&!se){const Q=t,ne=u.jsx("div",{className:"space-y-2",children:Q.content.map((me,ke)=>u.jsx(St,{part:me,i:ke},ke))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(fC,{className:Z})]}):ne}},[ue,He.length,oe.length,xe.length,r,X,F,f,qe.length,Mt,Z]),Vt=w.useMemo(()=>se?"Assistant":dS(t),[se,t]),ze=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),dn=w.useMemo(()=>{var D;return ze.length?_&&ze.some(Q=>Q.id===_)?_:((D=ze[0])==null?void 0:D.id)??null:null},[_,ze]),We=w.useMemo(()=>!ze.length||!I?null:ze.some(D=>D.id===I)?I:null,[I,ze])??dn,gt=G==="user"&&ze.length>0&&typeof N=="function",Rt=w.useCallback((D,Q=!1)=>{if(!N)return;const ne=(D==null?void 0:D.id)??null,me=(D==null?void 0:D.parentId)??L??null;N(ne,me,Q)},[L,N]),H=w.useMemo(()=>We?ze.findIndex(D=>D.id===We):-1,[We,ze]),re=w.useMemo(()=>H<0?null:ze[H]??null,[H,ze]);return X&&!f&&qe.length===0?null:ve&&se?u.jsx("div",{className:te(jt(),h.container),children:u.jsxs("div",{className:te(pt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(jt(),h.container),children:u.jsxs("div",{className:te(pt(),h.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Vt&&u.jsx("span",{className:te("font-medium",M?"text-xs":"text-sm"),children:Vt}),X&&u.jsxs(vf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>A(D=>D==="expanded"?"preview":"expanded"),onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),A(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ie.name??"Tool Output"}),ie.toolCallId&&u.jsx("span",{className:"opacity-70",children:ie.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[gt&&re&&H>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",H<ze.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(H>=ze.length-1)return;const D=ze[H+1];D&&Rt(D)},"aria-label":"Older checkpoint (back in time)",disabled:H>=ze.length-1,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[ze.length-H," / ",ze.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",H>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(H<=0))if(H===1)Rt(null,!0);else{const D=ze[H-1];D&&Rt(D,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:H<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,M&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>it(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(R?"text-success":Z,M?"h-3 w-3":"h-4 w-4")})})}),G==="user"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Je,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,M?"h-3 w-3":"h-4 w-4")})}),G==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Bt(),p&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((D,Q)=>u.jsx(sC,{preview:D,idx:Q},`artifact-${Q}`))})]}),X&&F==="expanded"&&(ie.toolCallId||ie.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[ie.name&&u.jsxs("div",{children:["Function: ",ie.name]}),ie.toolCallId&&u.jsxs("div",{children:["Call ID: ",ie.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>it(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(R?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),G==="user"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Je,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",M?"h-3 w-3":"h-4 w-4")})}),G==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(DS,{isOpen:J,onClose:q,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var l,c,d,f,p,h,m,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Sf(e.message)===Sf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(y=>e[y]===t[y]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((p=e.customStyles)==null?void 0:p.actions)===((h=t.customStyles)==null?void 0:h.actions)&&((m=e.customStyles)==null?void 0:m.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=dp(e.message),a=dp(t.message);return i.length===a.length});Ds.displayName="MessageComponent";function pC(e,t){return w.useMemo(()=>{var d,f,p,h,m;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const g=e,y=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&x&&(r=[x]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const N=(m=t.checkpointMetaById)==null?void 0:m.get(T);N&&C.push(N)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const fp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,pp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const N=fp(t,n),_="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:R,attemptMeta:O}=pC(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!_?t.additionalKwargs??{}:{},A=t&&!_?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof A.parentCheckpointId=="string")return A.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":N,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:R,messageParentCheckpointId:B,attemptMeta:O})})});pp.displayName="MessageRow";const Aa=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:L,userMessageIdToAttempts:R,activeCheckpointId:O,onSelectCheckpoint:F,createSyntheticThinkingMessage:A=!1},B)=>{const j=w.useRef(null),K=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[G,X]=w.useState(!0),se=w.useMemo(()=>b?e.some(oe=>"type"in oe&&oe.type==="default_message"?!1:Array.isArray(oe==null?void 0:oe.content)&&oe.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),ve=w.useMemo(()=>{if(!b||se)return null;const oe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Re=b.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Ye=Re.title;typeof Ye=="string"&&Ye.trim()&&(xe=Ye.trim())}return{id:`interrupt-${oe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:oe,value:Re,title:xe}]}},[b,se]),Ie=w.useMemo(()=>ve?[...e,ve]:e,[e,ve]),Y=w.useMemo(()=>!A||!t?Ie:!Ie.some(xe=>xe.role==="assistant")&&Ie.length>0?[...Ie,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ie,[Ie,t,A]),U=w.useMemo(()=>T?Y:Y.filter(oe=>(oe==null?void 0:oe.role)!=="tool"),[Y,T]),J=w.useCallback(oe=>{X(oe),y&&y(!oe),x&&x(oe)},[y,x]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),q=w.useMemo(()=>!m||g?!1:G?"auto":!1,[G,m,g]),Z=w.useMemo(()=>{if(typeof h!="string")return null;const oe=h.trim();return oe?{id:"default-message",role:"assistant",type:"default_message",content:oe,createdAt:new Date().toISOString()}:null},[h]),ue=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ie=()=>Z?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),_e=U.length,He=_e>0;return w.useEffect(()=>{var oe,xe;if(_e===0){M.current=!1;return}if(!M.current)if(M.current=!0,j.current&&U.length>0){const Re=U.length-1;(xe=(oe=j.current).scrollToIndex)==null||xe.call(oe,{index:Re,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},[_e,U.length]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var oe,xe;if(j.current&&U.length>0){const Re=U.length-1;(xe=(oe=j.current).scrollToIndex)==null||xe.call(oe,{index:Re,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},scrollToTop:()=>{var oe,xe;j.current&&U.length>0?(xe=(oe=j.current).scrollToIndex)==null||xe.call(oe,{index:0,align:"start",behavior:"auto"}):K.current&&(K.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ue,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:He?u.jsx(V0,{ref:oe=>{j.current=oe},scrollerRef:oe=>{K.current=oe instanceof HTMLDivElement?oe:null},data:U,followOutput:q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(oe,xe)=>fp(xe,oe),itemContent:(oe,xe)=>u.jsx(pp,{message:xe,index:oe,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:L,userMessageIdToAttempts:R,activeCheckpointId:O,onSelectCheckpoint:F})}):ie()})})});Aa.displayName="MessageList";const hp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:m,onError:g}){const{api:y}=ui(),{currentThreadId:x}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:N,checkpoints:_,interrupt:L,metadata:R,timelineCheckpoints:O,messagePreviews:F}=jo(),{isStreaming:A,error:B,connectionState:j,submit:K,stop:z}=lc(),M=b??x??null,G=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,se=(R==null?void 0:R.assemblingMessageId)??null,ve=L,[Ie,Y]=w.useState(!1);w.useEffect(()=>{ve||Y(!1)},[ve]);const U=w.useCallback(()=>{Y(!0)},[]),J=w.useCallback(()=>{Y(!1)},[]),$=!!ve||Ie,[q,Z]=w.useState(null),[ue,ie]=w.useState(""),[_e,He]=w.useState(null),[oe,xe]=w.useState(null),[Re,Ye]=w.useState([]),[nt,Xe]=w.useState(0),[qe,it]=w.useState(0),[Je,et]=w.useState(!1),[at,jt]=w.useState(null),[pt,ht]=w.useState(null),[mt,St]=w.useState(!1),[Mt,Bt]=w.useState(null),Vt=w.useRef(!1),[ze,dn]=w.useState(()=>hp.value),rt=w.useRef(ze),We=w.useRef(null),gt=w.useCallback(pe=>{hp.value=pe,dn(pe)},[]),[Rt,H]=w.useState(!1),re=w.useRef(null),{checkpointMetaById:D,checkpointIndexByKey:Q,attemptMetaById:ne,userMessageIdToAttempts:me}=Mw(_),ke=O??[],Pe=w.useRef(null),De=w.useRef(null),Ue=w.useCallback(()=>{Pe.current&&(Pe.current.value=""),De.current&&(De.current.value=""),Xe(pe=>pe+1),it(pe=>pe+1)},[]),Kt=w.useCallback(pe=>{gt(pe)},[gt]),Nn=w.useRef(!1);w.useEffect(()=>{Nn.current&&!A&&(Ye([]),Ue()),Nn.current=A},[A,Ue]);const[ar,Nr]=w.useState("desktop");w.useEffect(()=>{const pe=()=>{const we=window.innerWidth;Nr(we<640?"phone":we<1024?"tablet":"desktop")};return pe(),window.addEventListener("resize",pe),()=>window.removeEventListener("resize",pe)},[]),w.useEffect(()=>{Vt.current=!1},[M]),w.useEffect(()=>{rt.current=ze},[ze]),w.useEffect(()=>{if(!q){We.current=null;return}We.current===null&&(We.current=rt.current),gt(ue??"")},[ue,q,gt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Bt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";Bt(Ee||null)}catch(we){console.warn("Failed to fetch default message:",we),Bt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!mt&&(g==null||g(B))},[B,mt,g]);const fo=pe=>{if(pe.length>cs)return`Message too long (${pe.length}/${cs} characters)`;try{return Ow(pe),null}catch(we){return(we==null?void 0:we.message)||"Invalid message"}},Un=async pe=>{const we=pe.trim();if(!(!we&&Re.length===0)){if(we){const Ee=fo(we);if(Ee){xe(Ee);return}}try{const Ee=q?(_e==null?void 0:_e.checkpointId)??G??void 0:G??void 0,Ve=q?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await K({text:we||"",attachments:Re},{checkpointId:Ee,checkpointNs:Ve,edit:!!q,originalMessageId:q??void 0}),h==null||h(we),gt(""),xe(null),Ye([]),Ue(),Z(null),ie(""),He(null)}catch(Ee){const Ve=(Ee==null?void 0:Ee.message)||"Failed to send message";xe(Ve),g==null||g(Ve)}}},lr=w.useCallback((pe,we,Ee)=>{c&&(We.current=ze,Z(pe),ie(we),gt(we),xe(null),He({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[ze,c,gt]),E=w.useCallback(()=>{Z(null),ie(""),He(null),xe(null),gt(We.current??ze),We.current=null},[ze,gt]),V=w.useCallback((pe,we,Ee)=>{lr(pe,we,Ee)},[lr]),ae=w.useCallback(pe=>{let we=null;for(let nn=pe-1;nn>=0;nn--)if(S[nn].role==="user"){we=S[nn];break}if(!we)return;const Ee=Array.isArray(we.content)?we.content:[],Hn=Ee.filter(nn=>(nn==null?void 0:nn.type)==="text").map(nn=>nn.text).join("")||(()=>{try{return JSON.stringify(Ee,null,2)}catch{return String(Ee)}})();Hn&&K({text:Hn},{checkpointId:G??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:we.id})},[S,K,G,X]),be=pe=>{const we=Array.from(pe.target.files||[]);Ye(Ee=>[...Ee,...we]),pe.target.value=""},Ge=pe=>{Ye(we=>{const Ee=we.filter((Ve,Hn)=>pe!==Hn);return Ee.length===0&&Ue(),Ee})},tt=async pe=>{const we=(pe.target.files||[])[0];if(we){jt(null),ht(null),et(!0);try{await K({attachments:[we]},{checkpointId:G??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${we.name} - processing through chat stream`;ht(Ee)}catch(Ee){const Ve=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),jt(Ve),g==null||g(Ve)}finally{et(!1),pe.target.value="",Ue()}}},$e=async pe=>{if(x){H(!0);try{if(!pe){await I(),requestAnimationFrame(()=>{var Ve;(Ve=re.current)==null||Ve.scrollToLatest()});return}const we=_.find(Ve=>Ve.checkpointId===pe),Ee=(we==null?void 0:we.checkpointNs)??null;await T(pe,Ee),requestAnimationFrame(()=>{var Ve;(Ve=re.current)==null||Ve.scrollToTop()})}finally{H(!1)}}},Le=w.useCallback(async(pe,we,Ee)=>{await $e(Ee?null:pe)},[$e]),It=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,ft=`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 ${p.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:It,children:[!!B&&!mt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${ft}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Aa,{ref:re,className:"h-full",style:{height:"100%"},messages:S,isStreaming:A,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ar,enableMessageEditing:c,editingMessageId:q,onEdit:V,onRegenerate:ae,onCancelEdit:E,emptyMessage:Mt??void 0,isNavigatingCheckpoint:Rt,activeInterrupt:ve,disableInterruptActions:Ie,onInterruptActionStart:U,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:D,checkpointIndexByKey:Q,attemptMetaById:ne,userMessageIdToAttempts:me,activeCheckpointId:G,onSelectCheckpoint:Le,timelineCheckpoints:ke,messagePreviews:F}),(j==="reconnecting"||j==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(le.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Rt)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[q&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Pe,type:"file",multiple:!0,onChange:pe=>be(pe),className:"hidden"},nt),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((pe,we)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:pe.name}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ge(we),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 ${pe.name}`,children:u.jsx(le.X,{size:12})})]},we))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:De,type:"file",accept:".xls,.xlsx,.xlsm",onChange:tt,className:"hidden"},qe),Je&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),pt&&!Je&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:pt}),at&&!Je&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),oe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:oe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(yw,{children:[u.jsx(vw,{asChild:!0,children:u.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:A||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(vd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Xi,{onClick:()=>{var pe;return(pe=Pe.current)==null?void 0:pe.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Xi,{onClick:()=>{var pe;Je||(pe=De.current)==null||pe.click()},className:`cursor-pointer ${Je?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(vx,{initialValue:ue,editingMessageId:q,value:ze,onValueChange:Kt,placeholder:q?"Edit your message...":t,isStreaming:A,disabled:$,maxLength:cs,onSend:Un,onCancelEdit:E,onStop:z,allowEmptySend:Re.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${q?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${oe?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.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}));$s.displayName="Input";function _a(e,[t,n]){return Math.min(n,Math.max(t,e))}function hC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var ja="ScrollArea",[mp,sk]=Cn(ja),[mC,en]=mp(ja),gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,m]=v.useState(null),[g,y]=v.useState(null),[x,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,N]=v.useState(!1),_=Fe(t,R=>l(R)),L=Ro(o);return u.jsx(mC,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ae.div,{dir:L,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});gp.displayName=ja;var xp="ScrollAreaViewport",yp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(xp,n),a=v.useRef(null),l=Fe(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(Ae.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});yp.displayName=xp;var wn="ScrollAreaScrollbar",Ma=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(gC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(xC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(vp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ra,{...r,ref:t}):null});Ma.displayName=wn;var gC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Xt,{present:n||s,children:u.jsx(vp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),xC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=hC("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 v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Xt,{present:n||a!=="hidden",children:u.jsx(Ra,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),vp=v.forwardRef((e,t)=>{const n=en(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Xt,{present:r||s,children:u.jsx(Ra,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ra=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(wn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Tp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return CC(p,i.current,a,h)}return n==="horizontal"?u.jsx(yC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=kp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(vC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=kp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),yC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Fe(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(wp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Ep(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),vC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Fe(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(wp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Ep(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[bC,bp]=mp(wn),wp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=en(wn,n),[m,g]=v.useState(null),y=Fe(t,_=>g(_)),x=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function N(_){if(x.current){const L=_.clientX-x.current.left,R=_.clientY-x.current.top;c({x:L,y:R})}}return v.useEffect(()=>{const _=L=>{const R=L.target;(m==null?void 0:m.contains(R))&&C(L,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,m,k,C]),v.useEffect(T,[r,T]),kr(m,I),kr(h.content,I),u.jsx(bC,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(Ae.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:fe(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:fe(e.onPointerMove,N),onPointerUp:fe(e.onPointerUp,_=>{const L=_.target;L.hasPointerCapture(_.pointerId)&&L.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),Fs="ScrollAreaThumb",Sp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=bp(Fs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(wC,{ref:t,...r})})}),wC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(Fs,n),i=bp(Fs,n),{onThumbPositionChange:a}=i,l=Fe(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=TC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ae.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:fe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),m=f.clientX-h.left,g=f.clientY-h.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});Sp.displayName=Fs;var Pa="ScrollAreaCorner",Cp=v.forwardRef((e,t)=>{const n=en(Pa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(SC,{...e,ref:t}):null});Cp.displayName=Pa;var SC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Pa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ae.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 Bs(e){return e?parseInt(e,10):0}function Tp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Tp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function CC(e,t,n,r="ltr"){const o=zs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ip([l,c],f)(e)}function kp(e,t,n="ltr"){const r=zs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=_a(e,l);return Ip([0,i],[0,a])(c)}function Ip(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 Ep(e,t){return e>0&&e<t}var TC=(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 Us(e,t){const n=kt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function kr(e,t){const n=kt(t);Tt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Np=gp,kC=yp,IC=Cp;const Ap=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Np,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(kC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(_p,{}),u.jsx(IC,{})]}));Ap.displayName=Np.displayName;const _p=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ma,{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:u.jsx(Sp,{className:"relative flex-1 rounded-full bg-border"})}));_p.displayName=Ma.displayName;const jp=25;function Oa({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:m,actions:g}=_o(),{loadThread:y}=jo(),{createThread:x,deleteThread:b,renameThread:S}=g,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),N=w.useRef(0),[_,L]=w.useState(null),[R,O]=w.useState(""),[F,A]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}m||(T.current=!1,C(Y))},[f,m]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,J=null;return U=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{Y.scrollTop=N.current})}),()=>{U!==null&&cancelAnimationFrame(U),J!==null&&cancelAnimationFrame(J)}},[k]);const B=async Y=>{try{h(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{A(!0);const Y=await x();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{A(!1)}},K=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const J=I.current.querySelector("[data-radix-scroll-area-viewport]");J&&(N.current=J.scrollTop)}try{await b(Y),d==null||d(Y)}catch(J){console.error("Failed to delete thread:",J)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),O(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(R.trim())try{await S(Y,R.trim()),L(null),O("")}catch(U){console.error("Failed to update title:",U)}},G=()=>{L(null),O("")},X=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&G()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),q=Math.floor($/(1e3*60*60*24));return q===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:U.toLocaleDateString()}catch{return""}},ve=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ie=Y=>{const U=ve(Y);return U.length<=jp?U:`${U.slice(0,jp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Ze,{onClick:j,disabled:F||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(Ap,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(le.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((Y,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===Y.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:_===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:R,onChange:U=>O(U.target.value),onKeyDown:U=>X(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:G,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ie(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:se(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==Y.threadId&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>K(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(le.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}const EC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const p=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:p,onMouseEnter:s,onMouseLeave:i,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:c.map(h=>{const m=d===h.id,g=(r==null?void 0:r.get(h.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(h.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${m?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${m?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${m?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:h.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[h.step!==null?`STEP ${h.step}`:"STEP —",h.next?` - ${h.next}`:""]}),g&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},h.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function NC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Sn(t)}function Mp(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=NC(t);if(n)return n}}function Rp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Sn(t);return Sn()}function Op(){const e={},t=Mp(),n=Rp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Dp(){const e=Op(),t=An.getAuthToken(),n=Mp();return{apiBaseUrl:Pp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||Rp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Lp="chat-settings";function AC(){try{const e=localStorage.getItem(Lp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function _C(e){try{const t={...e,apiBaseUrl:Sn(e.apiBaseUrl)};localStorage.setItem(Lp,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function jC(){const e=Dp(),t=AC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Pp(An.baseUrl,r,e.apiBaseUrl)}}function MC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),_C(e)}var RC="Label",$p=v.forwardRef((e,t)=>u.jsx(Ae.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())}}));$p.displayName=RC;var Fp=$p;const PC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),tn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fp,{ref:n,className:te(PC(),e),...t}));tn.displayName=Fp.displayName;function Bp(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var zp=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"}),OC="VisuallyHidden",DC=v.forwardRef((e,t)=>u.jsx(Ae.span,{...e,ref:t,style:{...zp,...e.style}}));DC.displayName=OC;var LC=[" ","Enter","ArrowUp","ArrowDown"],$C=[" ","Enter"],or="Select",[Hs,Ws,FC]=mi(or),[Er,ik]=Cn(or,[FC,Ko]),Vs=Ko(),[BC,Fn]=Er(or),[zC,UC]=Er(or),Up=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:m}=e,g=Vs(t),[y,x]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Ro(c),[I,N]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:or}),[_,L]=pr({prop:i,defaultProp:a,onChange:l,caller:or}),R=v.useRef(null),O=y?m||!!y.closest("form"):!0,[F,A]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(nu,{...g,children:u.jsxs(BC,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Tn(),value:_,onValueChange:L,open:I,onOpenChange:N,dir:T,triggerPointerDownPosRef:R,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(zC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{A(K=>new Set(K).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{A(K=>{const z=new Set(K);return z.delete(j),z})},[]),children:n})}),O?u.jsxs(fh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:j=>L(j.target.value),disabled:p,form:m,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Up.displayName=or;var Hp="SelectTrigger",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=Fn(Hp,n),a=i.disabled||r,l=Fe(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,p,h]=hh(g=>{const y=c().filter(S=>!S.disabled),x=y.find(S=>S.value===i.value),b=mh(y,g,x);b!==void 0&&i.onValueChange(b.value)}),m=g=>{a||(i.onOpenChange(!0),h()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ru,{asChild:!0,...s,children:u.jsx(Ae.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":ph(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:fe(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:fe(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&p(g.key),!(y&&g.key===" ")&&LC.includes(g.key)&&(m(),g.preventDefault())})})})});Wp.displayName=Hp;var Vp="SelectValue",Kp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Fn(Vp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Fe(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(Ae.span,{...a,ref:f,style:{pointerEvents:"none"},children:ph(l.value)?u.jsx(u.Fragment,{children:i}):s})});Kp.displayName=Vp;var HC="SelectIcon",qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ae.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});qp.displayName=HC;var WC="SelectPortal",Gp=e=>u.jsx(qo,{asChild:!0,...e});Gp.displayName=WC;var sr="SelectContent",Yp=v.forwardRef((e,t)=>{const n=Fn(sr,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Xp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Jp,{...e,ref:t})});Yp.displayName=sr;var un=10,[Xp,Bn]=Er(sr),VC="SelectContentImpl",KC=Wn.createSlot("SelectContent.RemoveScroll"),Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,b=Fn(sr,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Fe(t,J=>k(J)),[N,_]=v.useState(null),[L,R]=v.useState(null),O=Ws(n),[F,A]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Li(S)},[S]),yi();const j=v.useCallback(J=>{const[$,...q]=O().map(ie=>ie.ref.current),[Z]=q.slice(-1),ue=document.activeElement;for(const ie of J)if(ie===ue||(ie==null||ie.scrollIntoView({block:"nearest"}),ie===$&&C&&(C.scrollTop=0),ie===Z&&C&&(C.scrollTop=C.scrollHeight),ie==null||ie.focus(),document.activeElement!==ue))return},[O,C]),K=v.useCallback(()=>j([N,S]),[j,N,S]);v.useEffect(()=>{F&&K()},[F,K]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let J={x:0,y:0};const $=Z=>{var ue,ie;J={x:Math.abs(Math.round(Z.pageX)-(((ue=M.current)==null?void 0:ue.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((ie=M.current)==null?void 0:ie.y)??0))}},q=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",q,{capture:!0})}}},[S,z,M]),v.useEffect(()=>{const J=()=>z(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[z]);const[G,X]=hh(J=>{const $=O().filter(ue=>!ue.disabled),q=$.find(ue=>ue.ref.current===document.activeElement),Z=mh($,J,q);Z&&setTimeout(()=>Z.ref.current.focus())}),se=v.useCallback((J,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&(_(J),Z&&(B.current=!0))},[b.value]),ve=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ie=v.useCallback((J,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&R(J)},[b.value]),Y=r==="popper"?Da:Zp,U=Y===Da?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(Xp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:N,onItemLeave:ve,itemTextRefCallback:Ie,focusSelectedItem:K,selectedItemText:L,position:r,isPositioned:F,searchRef:G,children:u.jsx(ns,{as:KC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:fe(o,J=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...x,...U,onPlaced:()=>A(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:fe(x.onKeyDown,J=>{const $=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!$&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=O().filter(ue=>!ue.disabled).map(ue=>ue.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const ue=J.target,ie=Z.indexOf(ue);Z=Z.slice(ie+1)}setTimeout(()=>j(Z)),J.preventDefault()}})})})})})})});Jp.displayName=VC;var qC="SelectItemAlignedPosition",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Fn(sr,n),i=Bn(sr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Fe(t,I=>d(I)),p=Ws(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const I=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),L=x.getBoundingClientRect();if(s.dir!=="rtl"){const ue=L.left-N.left,ie=_.left-ue,_e=I.left-ie,He=I.width+_e,oe=Math.max(He,N.width),xe=window.innerWidth-un,Re=_a(ie,[un,Math.max(un,xe-oe)]);a.style.minWidth=He+"px",a.style.left=Re+"px"}else{const ue=N.right-L.right,ie=window.innerWidth-_.right-ue,_e=window.innerWidth-I.right-ie,He=I.width+_e,oe=Math.max(He,N.width),xe=window.innerWidth-un,Re=_a(ie,[un,Math.max(un,xe-oe)]);a.style.minWidth=He+"px",a.style.right=Re+"px"}const R=p(),O=window.innerHeight-un*2,F=g.scrollHeight,A=window.getComputedStyle(c),B=parseInt(A.borderTopWidth,10),j=parseInt(A.paddingTop,10),K=parseInt(A.borderBottomWidth,10),z=parseInt(A.paddingBottom,10),M=B+j+F+z+K,G=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(g),se=parseInt(X.paddingTop,10),ve=parseInt(X.paddingBottom,10),Ie=I.top+I.height/2-un,Y=O-Ie,U=y.offsetHeight/2,J=y.offsetTop+U,$=B+j+J,q=M-$;if($<=Ie){const ue=R.length>0&&y===R[R.length-1].ref.current;a.style.bottom="0px";const ie=c.clientHeight-g.offsetTop-g.offsetHeight,_e=Math.max(Y,U+(ue?ve:0)+ie+K),He=$+_e;a.style.height=He+"px"}else{const ue=R.length>0&&y===R[0].ref.current;a.style.top="0px";const _e=Math.max(Ie,B+g.offsetTop+(ue?se:0)+U)+q;a.style.height=_e+"px",g.scrollTop=$-Ie+g.offsetTop}a.style.margin=`${un}px 0`,a.style.minHeight=G+"px",a.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&m.current===!0&&(S(),b==null||b(),m.current=!1)},[S,b]);return u.jsx(YC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Ae.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Zp.displayName=qC;var GC="SelectPopperPosition",Da=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=un,...s}=e,i=Vs(n);return u.jsx(ou,{...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)"}})});Da.displayName=GC;var[YC,La]=Er(sr,{}),$a="SelectViewport",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Bn($a,n),i=La($a,n),a=Fe(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(Ae.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const m=window.innerHeight-un*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const b=x+h,S=Math.min(m,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Qp.displayName=$a;var eh="SelectGroup",[XC,JC]=Er(eh),ZC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Tn();return u.jsx(XC,{scope:n,id:o,children:u.jsx(Ae.div,{role:"group","aria-labelledby":o,...r,ref:t})})});ZC.displayName=eh;var th="SelectLabel",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=JC(th,n);return u.jsx(Ae.div,{id:o.id,...r,ref:t})});nh.displayName=th;var Ks="SelectItem",[QC,rh]=Er(Ks),oh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Fn(Ks,n),l=Bn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=Fe(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),g=Tn(),y=v.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(QC,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ae.div,{role:"option","aria-labelledby":g,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:fe(i.onFocus,()=>h(!0)),onBlur:fe(i.onBlur,()=>h(!1)),onClick:fe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:fe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:fe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||($C.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});oh.displayName=Ks;var uo="SelectItemText",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Fn(uo,n),a=Bn(uo,n),l=rh(uo,n),c=UC(uo,n),[d,f]=v.useState(null),p=Fe(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),h=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return Tt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Ae.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});sh.displayName=uo;var ih="SelectItemIndicator",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return rh(ih,n).isSelected?u.jsx(Ae.span,{"aria-hidden":!0,...r,ref:t}):null});ah.displayName=ih;var Fa="SelectScrollUpButton",lh=v.forwardRef((e,t)=>{const n=Bn(Fa,e.__scopeSelect),r=La(Fa,e.__scopeSelect),[o,s]=v.useState(!1),i=Fe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(uh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});lh.displayName=Fa;var Ba="SelectScrollDownButton",ch=v.forwardRef((e,t)=>{const n=Bn(Ba,e.__scopeSelect),r=La(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=Fe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(uh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ch.displayName=Ba;var uh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Bn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ae.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:fe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:fe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),eT="SelectSeparator",dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ae.div,{"aria-hidden":!0,...r,ref:t})});dh.displayName=eT;var za="SelectArrow",tT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=Fn(za,n),i=Bn(za,n);return s.open&&i.position==="popper"?u.jsx(su,{...o,...r,ref:t}):null});tT.displayName=za;var nT="SelectBubbleInput",fh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Fe(r,o),i=Bp(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ae.select,{...n,style:{...zp,...n.style},ref:s,defaultValue:t})});fh.displayName=nT;function ph(e){return e===""||e===void 0}function hh(e){const t=kt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function mh(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=rT(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function rT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var oT=Up,gh=Wp,sT=Kp,iT=qp,aT=Gp,xh=Yp,lT=Qp,yh=nh,vh=oh,cT=sh,uT=ah,bh=lh,wh=ch,Sh=dh;const Ch=oT,Th=sT,Ua=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gh,{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,u.jsx(iT,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ua.displayName=gh.displayName;const kh=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));kh.displayName=bh.displayName;const Ih=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));Ih.displayName=wh.displayName;const Ha=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(aT,{children:u.jsxs(xh,{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:[u.jsx(kh,{}),u.jsx(lT,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ih,{})]})}));Ha.displayName=xh.displayName;const dT=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));dT.displayName=yh.displayName;const ir=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vh,{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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(uT,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(cT,{children:t})]}));ir.displayName=vh.displayName;const fT=v.forwardRef(({className:e,...t},n)=>u.jsx(Sh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));fT.displayName=Sh.displayName;var pT="Separator",Eh="horizontal",hT=["horizontal","vertical"],Nh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Eh,...o}=e,s=mT(r)?r:Eh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ae.div,{"data-orientation":s,...a,...o,ref:t})});Nh.displayName=pT;function mT(e){return hT.includes(e)}var Ah=Nh;const _h=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Ah,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));_h.displayName=Ah.displayName;const gT=zf,xT=ES,yT=Uf,jh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{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}));jh.displayName=Es.displayName;const vT=po.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"}}),Mh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(yT,{children:[u.jsx(jh,{}),u.jsxs(Ns,{ref:o,className:te(vT({side:e}),t),...r,children:[n,u.jsxs(Hf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mh.displayName=Ns.displayName;const Rh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Rh.displayName="SheetHeader";const Ph=v.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Ph.displayName=nr.displayName;const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Oh.displayName=As.displayName;var qs="Switch",[bT,ak]=Cn(qs),[wT,ST]=bT(qs),Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),m=Fe(t,S=>h(S)),g=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(wT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ae.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:m,onClick:fe(e.onClick,S=>{b(k=>!k),y&&(g.current=S.isPropagationStopped(),g.current||S.stopPropagation())})}),y&&u.jsx(Fh,{control:p,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Dh.displayName=qs;var Lh="SwitchThumb",$h=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=ST(Lh,n);return u.jsx(Ae.span,{"data-state":Bh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$h.displayName=Lh;var CT="SwitchBubbleInput",Fh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Fe(i,s),l=Bp(n),c=Kc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Fh.displayName=CT;function Bh(e){return e?"checked":"unchecked"}var zh=Dh,TT=$h;const zn=v.forwardRef(({className:e,...t},n)=>u.jsx(zh,{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:u.jsx(TT,{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")})}));zn.displayName=zh.displayName;const kT={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 IT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ia();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(kT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(gT,{open:r,onOpenChange:o,children:[u.jsx(xT,{asChild:!0,children:u.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(vf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Mh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Rh,{children:[u.jsx(Ph,{children:"Chat Settings"}),u.jsx(Oh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ze,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(zn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Ch,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ua,{children:u.jsx(Th,{})}),u.jsxs(Ha,{children:[u.jsx(ir,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ir,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ir,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Ch,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ua,{children:u.jsx(Th,{})}),u.jsxs(Ha,{children:[u.jsx(ir,{value:"light",children:"Light"}),u.jsx(ir,{value:"dark",children:"Dark"}),u.jsx(ir,{value:"system",children:"System"})]})]})]}),u.jsx(_h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(zn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(zn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(zn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(zn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(zn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ze,{variant:"outline",onClick:h,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ze,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(Ze,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function ET({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Mo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Mo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Oa,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Mo,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Oa,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Se.ChatApi=$l,Se.ChatInput=uc,Se.ChatInterface=Ls,Se.ChatProviders=Mo,Se.ChatSettings=IT,Se.MarkdownContent=so,Se.MessageComponent=Ds,Se.MessageList=Aa,Se.ThreadManager=Oa,Se.TimelineColumn=EC,Se.applySettings=MC,Se.buildMessagePreviewMap=Wg,Se.chatApiClient=An,Se.default=ET,Se.del=Ll,Se.get=Gt,Se.getChatToken=Pl,Se.getCurrentSettings=jC,Se.getDefaultApiConfig=Op,Se.getDefaultChatSettings=Dp,Se.onChatTokenChanged=Ol,Se.post=ci,Se.put=Dl,Se.setChatToken=Io,Se.useApi=ui,Se.useChatStream=ql,Se.useMessagesReducer=Xl,Se.useStream=lc,Se.useThreadState=jo,Se.useThreads=_o,Object.defineProperties(Se,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
134
+ `}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=ep(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=ep(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 sp{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 ip{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 Fn{constructor(t){this.options=t||or,this.options.renderer=this.options.renderer||new Aa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new sp,this.slugger=new ip}static parse(t,n){return new Fn(n).parse(t)}static parseInline(t,n){return new Fn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,m,g,y,x,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,Qf(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(m=h.ordered,g=h.start,y=h.loose,a=h.items.length,p="",s=0;s<a;s++)b=h.items[s],S=b.checked,k=b.task,x="",b.task&&(C=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):x+=C),x+=this.parse(b.tokens,y),p+=this.renderer.listitem(x,k,S);r+=this.renderer.list(p,m,g);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<I&&t[o+1].type==="text";)h=t[++o],p+=`
135
+ `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Os{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}Uh(Os,"passThroughHooks",new Set(["preprocess","postprocess"]));function QS(e,t,n){return r=>{if(r.message+=`
136
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(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 ap(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=QS(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(XS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&xe.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;xe.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(xe.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&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return ap($n.lex,Fn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},LS(xe.defaults),xe},xe.getDefaults=Yf,xe.defaults=or,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.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=xe.defaults.renderer||new Aa;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=xe.defaults.tokenizer||new Ea;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=xe.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(xe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=xe.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}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=ap($n.lexInline,Fn.parseInline),xe.Parser=Fn,xe.parser=Fn.parse,xe.Renderer=Aa,xe.TextRenderer=sp,xe.Lexer=$n,xe.lexer=$n.lex,xe.Tokenizer=Ea,xe.Slugger=ip,xe.Hooks=Os,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Fn.parse,$n.lex;function so({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.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 typeof xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const eC={MODE:"library"};function tC(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?eC:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function nC(){return!tC()}function rC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function oC(){return nC()||rC()}function sC({preview:e,idx:t}){return w.useEffect(()=>{oC()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function iC({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const aC="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function up({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:aC,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}function lC({message:e,viewMode:t}){const r=wf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?ba(c)??c:c;if(d&&typeof d=="object")return u.jsx(up,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=lS(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",r,"…"]})});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function cC({message:e,viewMode:t,isStreaming:n=!1}){const r=e.name??"tool",o=w.useMemo(()=>{const c=e.additionalKwargs??{};return(Array.isArray(c.toolProgress)?[...c.toolProgress]:[]).slice(-6)},[e]),s=o.some(c=>c.type==="tool_start"||c.type==="tool_call"||c.type==="message_start"),i=o[o.length-1],a=(i==null?void 0:i.title)??(i==null?void 0:i.step)??(s?`Running ${r}…`:void 0),l=n||o.length>0;return u.jsxs("div",{className:"space-y-2",children:[l&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[n&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:a??`Running ${r}…`})]}),o.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:o.map((c,d)=>u.jsx("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:c.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:c.content})},`progress-${r}-${d}`))})]}),u.jsx(lC,{message:e,viewMode:t})]})}function uC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ia(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,m,g)=>{var y,x;if(!t){h.preventDefault();return}if(o[g]){h.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=m.name||`file_${k}`,T=m.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await xS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof I.size=="number"?I.size===m.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:m.name||T.filename||`file_${T.id}`,mimeType:m.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(x=k.update)==null||x.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function dC({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Je,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function fC({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function dp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ds=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:m,onRegenerate:g,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:L=null}){const[B,G]=w.useState(!1),[V,R]=w.useState("preview"),[M,A]=w.useState(!1),{currentThreadId:F}=_o(),{respondToInterrupt:D}=jo(),P=l==="phone"||l==="half-screen",z=t.role,X=z==="tool",ne=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!ne,Te=!(r&&z!=="user"),{uploadingFiles:q,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:Y}=uC({allowFileOpen:Te,currentThreadId:F}),Z=w.useMemo(()=>{switch(z){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))]"}},[z]),de=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?cS(j):""},[ne,t]),oe=w.useMemo(()=>{if(ne)return{};const j=t.content;return Array.isArray(j)?wf(t):{}},[ne,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),ze=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="image_url"):[]},[ne,t]),se=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="file"):[]},[ne,t]),me=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="interrupt"):[]},[ne,t]),Re=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ve=Ts(Re),ut=b==null?void 0:b.value,Ke=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?uS(j):""},[ne,t]),qe=w.useMemo(()=>{if(ne||!p)return[];const Q=t.artifact;if(!Q)return[];const re=[],ie=[...Array.isArray(Q.plots)?Q.plots:[]];for(const ce of ie){const Xe=mS(ce);Xe&&re.push(Xe)}return re},[ne,t,p]),Qe=w.useCallback(async()=>{const j=X?Ke:de;async function Q(re){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(re);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ie=new Blob([re],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ie})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(j),G(!0),setTimeout(()=>G(!1),2e3),x==null||x(j)}catch(re){console.error("Failed to copy:",re)}},[X,Ke,de,x]),Ge=w.useCallback(()=>{if(!m)return;const j=X?Ke:de,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};m(t.id,j,Q)},[m,t.id,X,Ke,de,t]),et=w.useCallback(()=>{g==null||g(n)},[g,n]),st=w.useCallback(()=>{const Q=te(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(z){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[P,Z,z]),Mt=w.useCallback(()=>{const j="group relative mb-4 flex w-full";switch(z){case"user":return te(j,"justify-end");case"assistant":case"tool":case"system":return te(j,"justify-start");default:return j}},[z]),gt=w.useCallback(()=>{const j=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ye)return te(j,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(z){case"user":return te(j,"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(j,"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(j,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(j,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[P,ye,z]),Ct=w.useCallback(async j=>{if(S)return;const Q=Ts((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await D(Q,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{C==null||C()}},[S,C,k,D]),it=w.useCallback(async j=>{if(S)return;const Q=Ts((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await D(Q,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{C==null||C()}},[S,C,k,D]),St=w.useCallback(({part:j,i:Q})=>{if(j.type==="text"){const re=j.text??"",ie=re.trim(),ce=ba(ie);return ce&&z!=="tool"?u.jsx(up,{data:ce},Q):z==="user"&&c&&ie.length>d?u.jsx(dC,{text:ie,expanded:M,onExpandedChange:A,previewLength:d,isCompact:P},Q):u.jsx(so,{content:re,allowHtml:!1},Q)}if(j.type==="image_url"){const re=j;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:re.url,alt:re.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(j.type==="file"){const re=j,ie=re.name||"file";return u.jsxs("a",{href:re.url,onClick:ce=>U(ce.nativeEvent,re,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[q[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ie,q[Q]?" (processing)":""]})]},Q)}if(j.type==="interrupt"){const re=j,ie=Ts((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id)),ce=!!(Ve&&ie&&ie===Ve),Xe=ce?ut??(re==null?void 0:re.value):re==null?void 0:re.value,Ee=ie?{...re,id:ie,interrupt_id:ie}:re;return u.jsx(iC,{interruptPart:Ee,onApprove:Ct,onReject:it,disabled:S,isActive:ce,payload:Xe},Q)}return null},[U,q,Ct,it,z,c,d,M,P,Ve,ut,b,S,me]),Rt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),zt=w.useCallback(()=>{const j=de.trim().length>0||ze.length>0||se.length>0||me.length>0;if(!X&&se.length>0&&!r)return Rt();if(!X&&!j&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(cC,{message:t,viewMode:V,isStreaming:_e},t.id):null;if(!X&&!ne){const Q=t,re=u.jsx("div",{className:"space-y-2",children:Q.content.map((ie,ce)=>u.jsx(St,{part:ie,i:ce},ce))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[re,u.jsx(fC,{className:Z})]}):re}},[de,ze.length,se.length,me.length,r,X,V,f,qe.length,Rt,Z]),nn=w.useMemo(()=>ne?"Assistant":dS(t),[ne,t]),Le=w.useMemo(()=>ne?[]:Array.isArray(T)?T:[],[T,ne]),Sn=w.useMemo(()=>{var j;return Le.length?_&&Le.some(Q=>Q.id===_)?_:((j=Le[0])==null?void 0:j.id)??null:null},[_,Le]),We=w.useMemo(()=>!Le.length||!I?null:Le.some(j=>j.id===I)?I:null,[I,Le])??Sn,pt=z==="user"&&Le.length>0&&typeof N=="function",Pt=w.useCallback((j,Q=!1)=>{if(!N)return;const re=(j==null?void 0:j.id)??null,ie=(j==null?void 0:j.parentId)??L??null;N(re,ie,Q)},[L,N]),Ye=w.useMemo(()=>We?Le.findIndex(j=>j.id===We):-1,[We,Le]),H=w.useMemo(()=>Ye<0?null:Le[Ye]??null,[Ye,Le]);return X&&!f&&qe.length===0?null:ye&&ne?u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:ne.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),h.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[st(),a&&nn&&u.jsx("span",{className:te("font-medium",P?"text-xs":"text-sm"),children:nn}),X&&u.jsxs(vf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":V==="expanded",onClick:()=>R(j=>j==="expanded"?"preview":"expanded"),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),R(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),V==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[pt&&H&&Ye>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ye<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ye>=Le.length-1)return;const j=Le[Ye+1];j&&Pt(j)},"aria-label":"Older checkpoint (back in time)",disabled:Ye>=Le.length-1,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Le.length-Ye," / ",Le.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ye>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(Ye<=0))if(Ye===1)Pt(null,!0);else{const j=Le[Ye-1];j&&Pt(j,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:Ye<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,P&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(B?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),z==="user"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,P?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[zt(),p&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((j,Q)=>u.jsx(sC,{preview:j,idx:Q},`artifact-${Q}`))})]}),X&&V==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(B?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),z==="user"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",P?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(DS,{isOpen:J,onClose:Y,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var l,c,d,f,p,h,m,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Sf(e.message)===Sf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(y=>e[y]===t[y]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((p=e.customStyles)==null?void 0:p.actions)===((h=t.customStyles)==null?void 0:h.actions)&&((m=e.customStyles)==null?void 0:m.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=dp(e.message),a=dp(t.message);return i.length===a.length});Ds.displayName="MessageComponent";function pC(e,t){return w.useMemo(()=>{var d,f,p,h,m;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const g=e,y=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&x&&(r=[x]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const N=(m=t.checkpointMetaById)==null?void 0:m.get(T);N&&C.push(N)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const fp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,pp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const N=fp(t,n),_="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:B,attemptMeta:G}=pC(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),V=t&&!_?t.additionalKwargs??{}:{},R=t&&!_?t.responseMetadata??{}:{},M=(()=>{if(typeof V.parentCheckpointId=="string")return V.parentCheckpointId;if(typeof R.parentCheckpointId=="string")return R.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":N,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:m,onInterruptActionEnd:g,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:B,messageParentCheckpointId:M,attemptMeta:G})})});pp.displayName="MessageRow";const Na=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:m=!0,isNavigatingCheckpoint:g=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:L,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V,createSyntheticThinkingMessage:R=!1},M)=>{const A=w.useRef(null),F=w.useRef(null),D=w.useRef(!1),P=w.useRef(!1),[z,X]=w.useState(!0),ne=w.useMemo(()=>b?e.some(se=>"type"in se&&se.type==="default_message"?!1:Array.isArray(se==null?void 0:se.content)&&se.content.some(me=>me&&me.type==="interrupt"&&(me.id??me.interrupt_id)===b.id)):!1,[b,e]),ye=w.useMemo(()=>{if(!b||ne)return null;const se=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let me;const Re=b.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Ve=Re.title;typeof Ve=="string"&&Ve.trim()&&(me=Ve.trim())}return{id:`interrupt-${se}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:se,value:Re,title:me}]}},[b,ne]),Te=w.useMemo(()=>ye?[...e,ye]:e,[e,ye]),q=w.useMemo(()=>!R||!t?Te:!Te.some(me=>me.role==="assistant")&&Te.length>0?[...Te,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Te,[Te,t,R]),U=w.useMemo(()=>T?q:q.filter(se=>(se==null?void 0:se.role)!=="tool"),[q,T]),J=w.useCallback(se=>{X(se),y&&y(!se),x&&x(se)},[y,x]),$=w.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),Y=w.useMemo(()=>!m||g?!1:z?"auto":!1,[z,m,g]),Z=w.useMemo(()=>{if(typeof h!="string")return null;const se=h.trim();return se?{id:"default-message",role:"assistant",type:"default_message",content:se,createdAt:new Date().toISOString()}:null},[h]),de=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Z?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),_e=U.length,ze=_e>0;return w.useEffect(()=>{var se,me;if(_e===0){P.current=!1;return}if(!P.current)if(P.current=!0,A.current&&U.length>0){const Re=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Re,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},[_e,U.length]),w.useImperativeHandle(M,()=>({scrollToLatest:()=>{var se,me;if(A.current&&U.length>0){const Re=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Re,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},scrollToTop:()=>{var se,me;A.current&&U.length>0?(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:0,align:"start",behavior:"auto"}):F.current&&(F.current.scrollTop=0)}}),[U]),u.jsx("div",{className:de,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ze?u.jsx(V0,{ref:se=>{A.current=se},scrollerRef:se=>{F.current=se instanceof HTMLDivElement?se:null},data:U,followOutput:Y,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(se,me)=>fp(me,se),itemContent:(se,me)=>u.jsx(pp,{message:me,index:se,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:L,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V})}):oe()})})});Na.displayName="MessageList";const hp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:m,onError:g}){const{api:y}=ui(),{currentThreadId:x}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:N,checkpoints:_,interrupt:L,metadata:B,timelineCheckpoints:G,messagePreviews:V}=jo(),{isStreaming:R,error:M,connectionState:A,submit:F,stop:D}=lc(),P=b??x??null,z=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,ne=(B==null?void 0:B.assemblingMessageId)??null,ye=L,[Te,q]=w.useState(!1);w.useEffect(()=>{ye||q(!1)},[ye]);const U=w.useCallback(()=>{q(!0)},[]),J=w.useCallback(()=>{q(!1)},[]),$=!!ye||Te,[Y,Z]=w.useState(null),[de,oe]=w.useState(""),[_e,ze]=w.useState(null),[se,me]=w.useState(null),[Re,Ve]=w.useState([]),[ut,Ke]=w.useState(0),[qe,Qe]=w.useState(0),[Ge,et]=w.useState(!1),[st,Mt]=w.useState(null),[gt,Ct]=w.useState(null),[it,St]=w.useState(!1),[Rt,zt]=w.useState(null),nn=w.useRef(!1),[Le,Sn]=w.useState(()=>hp.value),tt=w.useRef(Le),We=w.useRef(null),pt=w.useCallback(he=>{hp.value=he,Sn(he)},[]),[Pt,Ye]=w.useState(!1),H=w.useRef(null),{checkpointMetaById:j,checkpointIndexByKey:Q,attemptMetaById:re,userMessageIdToAttempts:ie}=Mw(_),ce=G??[],Xe=w.useRef(null),Ee=w.useRef(null),at=w.useCallback(()=>{Xe.current&&(Xe.current.value=""),Ee.current&&(Ee.current.value=""),Ke(he=>he+1),Qe(he=>he+1)},[]),ht=w.useCallback(he=>{pt(he)},[pt]),Kt=w.useRef(!1);w.useEffect(()=>{Kt.current&&!R&&(Ve([]),at()),Kt.current=R},[R,at]);const[Hn,Er]=w.useState("desktop");w.useEffect(()=>{const he=()=>{const we=window.innerWidth;Er(we<640?"phone":we<1024?"tablet":"desktop")};return he(),window.addEventListener("resize",he),()=>window.removeEventListener("resize",he)},[]),w.useEffect(()=>{nn.current=!1},[P]),w.useEffect(()=>{tt.current=Le},[Le]),w.useEffect(()=>{if(!Y){We.current=null;return}We.current===null&&(We.current=tt.current),pt(de??"")},[de,Y,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){zt(null);return}try{const Ie=(await y.getAgent("default")).uiDefaultMessage||"";zt(Ie||null)}catch(we){console.warn("Failed to fetch default message:",we),zt(null)}})()},[y.baseUrl]),w.useEffect(()=>{M&&!it&&(g==null||g(M))},[M,it,g]);const Ar=he=>{if(he.length>cs)return`Message too long (${he.length}/${cs} characters)`;try{return Ow(he),null}catch(we){return(we==null?void 0:we.message)||"Invalid message"}},fo=async he=>{const we=he.trim();if(!(!we&&Re.length===0)){if(we){const Ie=Ar(we);if(Ie){me(Ie);return}}try{const Ie=Y?(_e==null?void 0:_e.checkpointId)??z??void 0:z??void 0,Ue=Y?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await F({text:we||"",attachments:Re},{checkpointId:Ie,checkpointNs:Ue,edit:!!Y,originalMessageId:Y??void 0}),h==null||h(we),pt(""),me(null),Ve([]),at(),Z(null),oe(""),ze(null)}catch(Ie){const Ue=(Ie==null?void 0:Ie.message)||"Failed to send message";me(Ue),g==null||g(Ue)}}},Nn=w.useCallback((he,we,Ie)=>{c&&(We.current=Le,Z(he),oe(we),pt(we),me(null),ze({checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null}))},[Le,c,pt]),E=w.useCallback(()=>{Z(null),oe(""),ze(null),me(null),pt(We.current??Le),We.current=null},[Le,pt]),W=w.useCallback((he,we,Ie)=>{Nn(he,we,Ie)},[Nn]),ae=w.useCallback(he=>{let we=null;for(let rn=he-1;rn>=0;rn--)if(S[rn].role==="user"){we=S[rn];break}if(!we)return;const Ie=Array.isArray(we.content)?we.content:[],Wn=Ie.filter(rn=>(rn==null?void 0:rn.type)==="text").map(rn=>rn.text).join("")||(()=>{try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}})();Wn&&F({text:Wn},{checkpointId:z??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:we.id})},[S,F,z,X]),be=he=>{const we=Array.from(he.target.files||[]);Ve(Ie=>[...Ie,...we]),he.target.value=""},Be=he=>{Ve(we=>{const Ie=we.filter((Ue,Wn)=>he!==Wn);return Ie.length===0&&at(),Ie})},nt=async he=>{const we=(he.target.files||[])[0];if(we){Mt(null),Ct(null),et(!0);try{await F({attachments:[we]},{checkpointId:z??void 0,checkpointNs:X??void 0});const Ie=`Uploaded ${we.name} - processing through chat stream`;Ct(Ie)}catch(Ie){const Ue=Ie instanceof Error?Ie.message:"Failed to upload Excel file";console.error("Excel upload failed",Ie),Mt(Ue),g==null||g(Ue)}finally{et(!1),he.target.value="",at()}}},De=async he=>{if(x){Ye(!0);try{if(!he){await I(),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToLatest()});return}const we=_.find(Ue=>Ue.checkpointId===he),Ie=(we==null?void 0:we.checkpointNs)??null;await T(he,Ie),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToTop()})}finally{Ye(!1)}}},Oe=w.useCallback(async(he,we,Ie)=>{await De(Ie?null:he)},[De]),Et=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`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 ${p.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:Et,children:[!!M&&!it&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:M}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Na,{ref:H,className:"h-full",style:{height:"100%"},messages:S,isStreaming:R,streamingAssistantId:ne,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Hn,enableMessageEditing:c,editingMessageId:Y,onEdit:W,onRegenerate:ae,onCancelEdit:E,emptyMessage:Rt??void 0,isNavigatingCheckpoint:Pt,activeInterrupt:ye,disableInterruptActions:Te,onInterruptActionStart:U,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:j,checkpointIndexByKey:Q,attemptMetaById:re,userMessageIdToAttempts:ie,activeCheckpointId:z,onSelectCheckpoint:Oe,timelineCheckpoints:ce,messagePreviews:V}),(A==="reconnecting"||A==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(le.Loader2,{className:"h-3 w-3 animate-spin"}),A==="reconnecting"?"Reconnecting…":"Connecting…"]})}),A==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Pt)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[Y&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Xe,type:"file",multiple:!0,onChange:he=>be(he),className:"hidden"},ut),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((he,we)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:he.name}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Be(we),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 ${he.name}`,children:u.jsx(le.X,{size:12})})]},we))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Ee,type:"file",accept:".xls,.xlsx,.xlsm",onChange:nt,className:"hidden"},qe),Ge&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),st&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:st})]})]}),se&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:se}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(yw,{children:[u.jsx(vw,{asChild:!0,children:u.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:R||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(vd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Xi,{onClick:()=>{var he;return(he=Xe.current)==null?void 0:he.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Xi,{onClick:()=>{var he;Ge||(he=Ee.current)==null||he.click()},className:`cursor-pointer ${Ge?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(vx,{initialValue:de,editingMessageId:Y,value:Le,onValueChange:ht,placeholder:Y?"Edit your message...":t,isStreaming:R,disabled:$,maxLength:cs,onSend:fo,onCancelEdit:E,onStop:D,allowEmptySend:Re.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":""} ${se?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.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}));$s.displayName="Input";function _a(e,[t,n]){return Math.min(n,Math.max(t,e))}function hC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var ja="ScrollArea",[mp,sk]=Tn(ja),[mC,en]=mp(ja),gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,m]=v.useState(null),[g,y]=v.useState(null),[x,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,N]=v.useState(!1),_=$e(t,B=>l(B)),L=Ro(o);return u.jsx(mC,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:L,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});gp.displayName=ja;var xp="ScrollAreaViewport",yp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(xp,n),a=v.useRef(null),l=$e(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(Ne.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});yp.displayName=xp;var wn="ScrollAreaScrollbar",Ma=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(gC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(xC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(vp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ra,{...r,ref:t}):null});Ma.displayName=wn;var gC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Xt,{present:n||s,children:u.jsx(vp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),xC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=hC("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 v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Xt,{present:n||a!=="hidden",children:u.jsx(Ra,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:pe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:pe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),vp=v.forwardRef((e,t)=>{const n=en(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Tr(n.viewport,l),Tr(n.content,l),u.jsx(Xt,{present:r||s,children:u.jsx(Ra,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ra=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(wn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Tp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return CC(p,i.current,a,h)}return n==="horizontal"?u.jsx(yC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=kp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(vC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=kp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),yC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=$e(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(wp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Ep(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),vC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=$e(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(wp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Ep(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[bC,bp]=mp(wn),wp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=en(wn,n),[m,g]=v.useState(null),y=$e(t,_=>g(_)),x=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=It(d),T=It(l),I=Us(f,10);function N(_){if(x.current){const L=_.clientX-x.current.left,B=_.clientY-x.current.top;c({x:L,y:B})}}return v.useEffect(()=>{const _=L=>{const B=L.target;(m==null?void 0:m.contains(B))&&C(L,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,m,k,C]),v.useEffect(T,[r,T]),Tr(m,I),Tr(h.content,I),u.jsx(bC,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:It(s),onThumbPointerUp:It(i),onThumbPositionChange:T,onThumbPointerDown:It(a),children:u.jsx(Ne.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:pe(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:pe(e.onPointerMove,N),onPointerUp:pe(e.onPointerUp,_=>{const L=_.target;L.hasPointerCapture(_.pointerId)&&L.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),Fs="ScrollAreaThumb",Sp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=bp(Fs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(wC,{ref:t,...r})})}),wC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(Fs,n),i=bp(Fs,n),{onThumbPositionChange:a}=i,l=$e(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=TC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ne.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:pe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),m=f.clientX-h.left,g=f.clientY-h.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:pe(e.onPointerUp,i.onThumbPointerUp)})});Sp.displayName=Fs;var Pa="ScrollAreaCorner",Cp=v.forwardRef((e,t)=>{const n=en(Pa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(SC,{...e,ref:t}):null});Cp.displayName=Pa;var SC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Pa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Tr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Tr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Bs(e){return e?parseInt(e,10):0}function Tp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Tp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function CC(e,t,n,r="ltr"){const o=zs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ip([l,c],f)(e)}function kp(e,t,n="ltr"){const r=zs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=_a(e,l);return Ip([0,i],[0,a])(c)}function Ip(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 Ep(e,t){return e>0&&e<t}var TC=(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 Us(e,t){const n=It(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Tr(e,t){const n=It(t);kt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Ap=gp,kC=yp,IC=Cp;const Np=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ap,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(kC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(_p,{}),u.jsx(IC,{})]}));Np.displayName=Ap.displayName;const _p=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ma,{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:u.jsx(Sp,{className:"relative flex-1 rounded-full bg-border"})}));_p.displayName=Ma.displayName;const jp=25;function Oa({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:m,actions:g}=_o(),{loadThread:y}=jo(),{createThread:x,deleteThread:b,renameThread:S}=g,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),N=w.useRef(0),[_,L]=w.useState(null),[B,G]=w.useState(""),[V,R]=w.useState(!1);w.useEffect(()=>{const q=Array.isArray(f)?f:[];if(q.length>0){T.current=!0,C(q);return}m||(T.current=!1,C(q))},[f,m]),w.useEffect(()=>{if(!I.current)return;const q=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!q)return;let U=null,J=null;return U=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{q.scrollTop=N.current})}),()=>{U!==null&&cancelAnimationFrame(U),J!==null&&cancelAnimationFrame(J)}},[k]);const M=async q=>{try{h(q),await y(q),a==null||a(q),l==null||l(q)}catch(U){console.error("Failed to select thread:",U)}},A=async()=>{try{R(!0);const q=await x();q&&(c==null||c(q),a==null||a(q))}catch(q){console.error("Failed to create thread:",q)}finally{R(!1)}},F=async(q,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const J=I.current.querySelector("[data-radix-scroll-area-viewport]");J&&(N.current=J.scrollTop)}try{await b(q),d==null||d(q)}catch(J){console.error("Failed to delete thread:",J)}}},D=(q,U)=>{U.stopPropagation(),L(q.threadId),G(q.title||`Thread ${q.threadId.slice(0,8)}`)},P=async q=>{if(B.trim())try{await S(q,B.trim()),L(null),G("")}catch(U){console.error("Failed to update title:",U)}},z=()=>{L(null),G("")},X=(q,U)=>{q.key==="Enter"?P(U):q.key==="Escape"&&z()},ne=q=>{if(!q)return"";try{const U=new Date(q),$=new Date().getTime()-U.getTime(),Y=Math.floor($/(1e3*60*60*24));return Y===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Y===1?"Yesterday":Y<7?`${Y} days ago`:U.toLocaleDateString()}catch{return""}},ye=q=>q.title||`Thread ${q.threadId.slice(0,8)}`,Te=q=>{const U=ye(q);return U.length<=jp?U:`${U.slice(0,jp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Je,{onClick:A,disabled:V||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:V?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(Np,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(le.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((q,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>M(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===q.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:_===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:B,onChange:U=>G(U.target.value),onKeyDown:U=>X(U,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>P(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:z,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Te(q)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:ne(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==q.threadId&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>D(q,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>F(q.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(le.Trash2,{size:12})})]})]}),i===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}const EC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const p=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:p,onMouseEnter:s,onMouseLeave:i,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:c.map(h=>{const m=d===h.id,g=(r==null?void 0:r.get(h.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(h.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${m?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${m?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${m?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:h.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[h.step!==null?`STEP ${h.step}`:"STEP —",h.next?` - ${h.next}`:""]}),g&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},h.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function kr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function AC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function Mp(){const e=[kr("__API_BASE_URL__"),kr("__CHAT_API_BASE_URL__"),kr("__CHAT_API_URL__")];for(const t of e){const n=AC(t);if(n)return n}}function Rp(){const e=[kr("__API_AUTH_TOKEN__"),kr("__CHAT_API_KEY__"),kr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Op(){const e={},t=Mp(),n=Rp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Dp(){const e=Op(),t=_n.getAuthToken(),n=Mp();return{apiBaseUrl:Pp(e.baseUrl,_n.baseUrl,n),apiKey:t||e.apiKey||Rp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Lp="chat-settings";function NC(){try{const e=localStorage.getItem(Lp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function _C(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem(Lp,JSON.stringify(t)),t.apiKey&&_n.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function jC(){const e=Dp(),t=NC(),n=_n.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Pp(_n.baseUrl,r,e.apiBaseUrl)}}function MC(e){_n.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),_C(e)}var RC="Label",$p=v.forwardRef((e,t)=>u.jsx(Ne.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));$p.displayName=RC;var Fp=$p;const PC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),tn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fp,{ref:n,className:te(PC(),e),...t}));tn.displayName=Fp.displayName;function Bp(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var zp=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"}),OC="VisuallyHidden",DC=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...zp,...e.style}}));DC.displayName=OC;var LC=[" ","Enter","ArrowUp","ArrowDown"],$C=[" ","Enter"],sr="Select",[Hs,Ws,FC]=mi(sr),[Ir,ik]=Tn(sr,[FC,Ko]),Vs=Ko(),[BC,Bn]=Ir(sr),[zC,UC]=Ir(sr),Up=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:m}=e,g=Vs(t),[y,x]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Ro(c),[I,N]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:sr}),[_,L]=fr({prop:i,defaultProp:a,onChange:l,caller:sr}),B=v.useRef(null),G=y?m||!!y.closest("form"):!0,[V,R]=v.useState(new Set),M=Array.from(V).map(A=>A.props.value).join(";");return u.jsx(nu,{...g,children:u.jsxs(BC,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:kn(),value:_,onValueChange:L,open:I,onOpenChange:N,dir:T,triggerPointerDownPosRef:B,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(zC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(A=>{R(F=>new Set(F).add(A))},[]),onNativeOptionRemove:v.useCallback(A=>{R(F=>{const D=new Set(F);return D.delete(A),D})},[]),children:n})}),G?u.jsxs(fh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:A=>L(A.target.value),disabled:p,form:m,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},M):null]})})};Up.displayName=sr;var Hp="SelectTrigger",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=Bn(Hp,n),a=i.disabled||r,l=$e(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,p,h]=hh(g=>{const y=c().filter(S=>!S.disabled),x=y.find(S=>S.value===i.value),b=mh(y,g,x);b!==void 0&&i.onValueChange(b.value)}),m=g=>{a||(i.onOpenChange(!0),h()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return u.jsx(ru,{asChild:!0,...s,children:u.jsx(Ne.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":ph(i.value)?"":void 0,...o,ref:l,onClick:pe(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&m(g)}),onPointerDown:pe(o.onPointerDown,g=>{d.current=g.pointerType;const y=g.target;y.hasPointerCapture(g.pointerId)&&y.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(m(g),g.preventDefault())}),onKeyDown:pe(o.onKeyDown,g=>{const y=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&p(g.key),!(y&&g.key===" ")&&LC.includes(g.key)&&(m(),g.preventDefault())})})})});Wp.displayName=Hp;var Vp="SelectValue",Kp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Vp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=$e(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:ph(l.value)?u.jsx(u.Fragment,{children:i}):s})});Kp.displayName=Vp;var HC="SelectIcon",qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});qp.displayName=HC;var WC="SelectPortal",Gp=e=>u.jsx(qo,{asChild:!0,...e});Gp.displayName=WC;var ir="SelectContent",Yp=v.forwardRef((e,t)=>{const n=Bn(ir,e.__scopeSelect),[r,o]=v.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Xp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Jp,{...e,ref:t})});Yp.displayName=ir;var dn=10,[Xp,zn]=Ir(ir),VC="SelectContentImpl",KC=Vn.createSlot("SelectContent.RemoveScroll"),Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:g,avoidCollisions:y,...x}=e,b=Bn(ir,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=$e(t,J=>k(J)),[N,_]=v.useState(null),[L,B]=v.useState(null),G=Ws(n),[V,R]=v.useState(!1),M=v.useRef(!1);v.useEffect(()=>{if(S)return Li(S)},[S]),yi();const A=v.useCallback(J=>{const[$,...Y]=G().map(oe=>oe.ref.current),[Z]=Y.slice(-1),de=document.activeElement;for(const oe of J)if(oe===de||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Z&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==de))return},[G,C]),F=v.useCallback(()=>A([N,S]),[A,N,S]);v.useEffect(()=>{V&&F()},[V,F]);const{onOpenChange:D,triggerPointerDownPosRef:P}=b;v.useEffect(()=>{if(S){let J={x:0,y:0};const $=Z=>{var de,oe;J={x:Math.abs(Math.round(Z.pageX)-(((de=P.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((oe=P.current)==null?void 0:oe.y)??0))}},Y=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||D(!1),document.removeEventListener("pointermove",$),P.current=null};return P.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",Y,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",Y,{capture:!0})}}},[S,D,P]),v.useEffect(()=>{const J=()=>D(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[D]);const[z,X]=hh(J=>{const $=G().filter(de=>!de.disabled),Y=$.find(de=>de.ref.current===document.activeElement),Z=mh($,J,Y);Z&&setTimeout(()=>Z.ref.current.focus())}),ne=v.useCallback((J,$,Y)=>{const Z=!M.current&&!Y;(b.value!==void 0&&b.value===$||Z)&&(_(J),Z&&(M.current=!0))},[b.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Te=v.useCallback((J,$,Y)=>{const Z=!M.current&&!Y;(b.value!==void 0&&b.value===$||Z)&&B(J)},[b.value]),q=r==="popper"?Da:Zp,U=q===Da?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:g,avoidCollisions:y}:{};return u.jsx(Xp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:ne,selectedItem:N,onItemLeave:ye,itemTextRefCallback:Te,focusSelectedItem:F,selectedItemText:L,position:r,isPositioned:V,searchRef:z,children:u.jsx(ns,{as:KC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:pe(o,J=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(q,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...x,...U,onPlaced:()=>R(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:pe(x.onKeyDown,J=>{const $=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!$&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=G().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const de=J.target,oe=Z.indexOf(de);Z=Z.slice(oe+1)}setTimeout(()=>A(Z)),J.preventDefault()}})})})})})})});Jp.displayName=VC;var qC="SelectItemAlignedPosition",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ir,n),i=zn(ir,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=$e(t,I=>d(I)),p=Ws(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:g,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&g&&y&&x){const I=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),L=x.getBoundingClientRect();if(s.dir!=="rtl"){const de=L.left-N.left,oe=_.left-de,_e=I.left-oe,ze=I.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Re=_a(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.left=Re+"px"}else{const de=N.right-L.right,oe=window.innerWidth-_.right-de,_e=window.innerWidth-I.right-oe,ze=I.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Re=_a(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.right=Re+"px"}const B=p(),G=window.innerHeight-dn*2,V=g.scrollHeight,R=window.getComputedStyle(c),M=parseInt(R.borderTopWidth,10),A=parseInt(R.paddingTop,10),F=parseInt(R.borderBottomWidth,10),D=parseInt(R.paddingBottom,10),P=M+A+V+D+F,z=Math.min(y.offsetHeight*5,P),X=window.getComputedStyle(g),ne=parseInt(X.paddingTop,10),ye=parseInt(X.paddingBottom,10),Te=I.top+I.height/2-dn,q=G-Te,U=y.offsetHeight/2,J=y.offsetTop+U,$=M+A+J,Y=P-$;if($<=Te){const de=B.length>0&&y===B[B.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-g.offsetTop-g.offsetHeight,_e=Math.max(q,U+(de?ye:0)+oe+F),ze=$+_e;a.style.height=ze+"px"}else{const de=B.length>0&&y===B[0].ref.current;a.style.top="0px";const _e=Math.max(Te,M+g.offsetTop+(de?ne:0)+U)+Y;a.style.height=_e+"px",g.scrollTop=$-Te+g.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=z+"px",a.style.maxHeight=G+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,g,y,x,s.dir,r]);kt(()=>S(),[S]);const[k,C]=v.useState();kt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&m.current===!0&&(S(),b==null||b(),m.current=!1)},[S,b]);return u.jsx(YC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Zp.displayName=qC;var GC="SelectPopperPosition",Da=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Vs(n);return u.jsx(ou,{...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)"}})});Da.displayName=GC;var[YC,La]=Ir(ir,{}),$a="SelectViewport",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn($a,n),i=La($a,n),a=$e(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:pe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const m=window.innerHeight-dn*2,g=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(g,y);if(x<m){const b=x+h,S=Math.min(m,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Qp.displayName=$a;var eh="SelectGroup",[XC,JC]=Ir(eh),ZC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return u.jsx(XC,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});ZC.displayName=eh;var th="SelectLabel",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=JC(th,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});nh.displayName=th;var Ks="SelectItem",[QC,rh]=Ir(Ks),oh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(Ks,n),l=zn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=$e(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),g=kn(),y=v.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(QC,{scope:n,value:r,disabled:o,textId:g,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.div,{role:"option","aria-labelledby":g,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:pe(i.onFocus,()=>h(!0)),onBlur:pe(i.onBlur,()=>h(!1)),onClick:pe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:pe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:pe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:pe(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:pe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:pe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||($C.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});oh.displayName=Ks;var uo="SelectItemText",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(uo,n),a=zn(uo,n),l=rh(uo,n),c=UC(uo,n),[d,f]=v.useState(null),p=$e(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),h=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:g,onNativeOptionRemove:y}=c;return kt(()=>(g(m),()=>y(m)),[g,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});sh.displayName=uo;var ih="SelectItemIndicator",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return rh(ih,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});ah.displayName=ih;var Fa="SelectScrollUpButton",lh=v.forwardRef((e,t)=>{const n=zn(Fa,e.__scopeSelect),r=La(Fa,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(uh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});lh.displayName=Fa;var Ba="SelectScrollDownButton",ch=v.forwardRef((e,t)=>{const n=zn(Ba,e.__scopeSelect),r=La(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(uh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ch.displayName=Ba;var uh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),kt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:pe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:pe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:pe(o.onPointerLeave,()=>{l()})})}),eT="SelectSeparator",dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});dh.displayName=eT;var za="SelectArrow",tT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=Bn(za,n),i=zn(za,n);return s.open&&i.position==="popper"?u.jsx(su,{...o,...r,ref:t}):null});tT.displayName=za;var nT="SelectBubbleInput",fh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=$e(r,o),i=Bp(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ne.select,{...n,style:{...zp,...n.style},ref:s,defaultValue:t})});fh.displayName=nT;function ph(e){return e===""||e===void 0}function hh(e){const t=It(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function mh(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=rT(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function rT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var oT=Up,gh=Wp,sT=Kp,iT=qp,aT=Gp,xh=Yp,lT=Qp,yh=nh,vh=oh,cT=sh,uT=ah,bh=lh,wh=ch,Sh=dh;const Ch=oT,Th=sT,Ua=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gh,{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,u.jsx(iT,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ua.displayName=gh.displayName;const kh=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));kh.displayName=bh.displayName;const Ih=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));Ih.displayName=wh.displayName;const Ha=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(aT,{children:u.jsxs(xh,{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:[u.jsx(kh,{}),u.jsx(lT,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ih,{})]})}));Ha.displayName=xh.displayName;const dT=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));dT.displayName=yh.displayName;const ar=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vh,{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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(uT,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(cT,{children:t})]}));ar.displayName=vh.displayName;const fT=v.forwardRef(({className:e,...t},n)=>u.jsx(Sh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));fT.displayName=Sh.displayName;var pT="Separator",Eh="horizontal",hT=["horizontal","vertical"],Ah=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Eh,...o}=e,s=mT(r)?r:Eh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});Ah.displayName=pT;function mT(e){return hT.includes(e)}var Nh=Ah;const _h=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Nh,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));_h.displayName=Nh.displayName;const gT=zf,xT=ES,yT=Uf,jh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{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}));jh.displayName=Es.displayName;const vT=po.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"}}),Mh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(yT,{children:[u.jsx(jh,{}),u.jsxs(As,{ref:o,className:te(vT({side:e}),t),...r,children:[n,u.jsxs(Hf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mh.displayName=As.displayName;const Rh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Rh.displayName="SheetHeader";const Ph=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Ph.displayName=rr.displayName;const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Oh.displayName=Ns.displayName;var qs="Switch",[bT,ak]=Tn(qs),[wT,ST]=bT(qs),Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),m=$e(t,S=>h(S)),g=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,b]=fr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(wT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.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:m,onClick:pe(e.onClick,S=>{b(k=>!k),y&&(g.current=S.isPropagationStopped(),g.current||S.stopPropagation())})}),y&&u.jsx(Fh,{control:p,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Dh.displayName=qs;var Lh="SwitchThumb",$h=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=ST(Lh,n);return u.jsx(Ne.span,{"data-state":Bh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$h.displayName=Lh;var CT="SwitchBubbleInput",Fh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=$e(i,s),l=Bp(n),c=Kc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Fh.displayName=CT;function Bh(e){return e?"checked":"unchecked"}var zh=Dh,TT=$h;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(zh,{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:u.jsx(TT,{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")})}));Un.displayName=zh.displayName;const kT={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 IT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ia();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(kT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},g=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(gT,{open:r,onOpenChange:o,children:[u.jsx(xT,{asChild:!0,children:u.jsxs(Je,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(vf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Mh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Rh,{children:[u.jsx(Ph,{children:"Chat Settings"}),u.jsx(Oh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Je,{variant:"outline",onClick:g,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Je,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Ch,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ua,{children:u.jsx(Th,{})}),u.jsxs(Ha,{children:[u.jsx(ar,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ar,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ar,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Ch,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ua,{children:u.jsx(Th,{})}),u.jsxs(Ha,{children:[u.jsx(ar,{value:"light",children:"Light"}),u.jsx(ar,{value:"dark",children:"Dark"}),u.jsx(ar,{value:"system",children:"System"})]})]})]}),u.jsx(_h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Je,{variant:"outline",onClick:h,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Je,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(Je,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function ET({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Mo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Mo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Oa,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Mo,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Oa,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Se.ChatApi=$l,Se.ChatInput=uc,Se.ChatInterface=Ls,Se.ChatProviders=Mo,Se.ChatSettings=IT,Se.MarkdownContent=so,Se.MessageComponent=Ds,Se.MessageList=Na,Se.ThreadManager=Oa,Se.TimelineColumn=EC,Se.applySettings=MC,Se.buildMessagePreviewMap=Wg,Se.chatApiClient=_n,Se.default=ET,Se.del=Ll,Se.get=Gt,Se.getChatToken=Pl,Se.getCurrentSettings=jC,Se.getDefaultApiConfig=Op,Se.getDefaultChatSettings=Dp,Se.onChatTokenChanged=Ol,Se.post=ci,Se.put=Dl,Se.setChatToken=Io,Se.useApi=ui,Se.useChatStream=ql,Se.useMessagesReducer=Xl,Se.useStream=lc,Se.useThreadState=jo,Se.useThreads=_o,Object.defineProperties(Se,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});