teodor-new-chat-ui 4.3.387 → 4.3.389

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(ke,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):(ke=typeof globalThis<"u"?globalThis:ke||self,w(ke.NewChatUI={},ke.React,ke.LucideReact,ke.reactSlot,ke.classVarianceAuthority,ke.clsx,ke.tailwindMerge,ke.ReactDOM))})(this,function(ke,w,ae,Wn,bo,_m,Mm,si){"use strict";var tI=Object.defineProperty;var nI=(ke,w,ae)=>w in ke?tI(ke,w,{enumerable:!0,configurable:!0,writable:!0,value:ae}):ke[w]=ae;var Am=(ke,w,ae)=>nI(ke,typeof w!="symbol"?w+"":w,ae);var ii=typeof document<"u"?document.currentScript:null;function gl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const m=gl(w),wo=gl(si);var ai={exports:{}},Mr={};/**
1
+ (function(Ce,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):(Ce=typeof globalThis<"u"?globalThis:Ce||self,w(Ce.NewChatUI={},Ce.React,Ce.LucideReact,Ce.reactSlot,Ce.classVarianceAuthority,Ce.clsx,Ce.tailwindMerge,Ce.ReactDOM))})(this,function(Ce,w,ae,Wn,bo,_m,Mm,si){"use strict";var eE=Object.defineProperty;var tE=(Ce,w,ae)=>w in Ce?eE(Ce,w,{enumerable:!0,configurable:!0,writable:!0,value:ae}):Ce[w]=ae;var Am=(Ce,w,ae)=>tE(Ce,typeof w!="symbol"?w+"":w,ae);var ii=typeof document<"u"?document.currentScript:null;function gl(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const m=gl(w),wo=gl(si);var ai={exports:{}},_r={};/**
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 xl;function Rm(){if(xl)return Mr;xl=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,u){var d,f={},h=null,p=null;u!==void 0&&(h=""+u),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return Mr.Fragment=n,Mr.jsx=i,Mr.jsxs=i,Mr}var Rr={};/**
9
+ */var xl;function Rm(){if(xl)return _r;xl=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,u){var d,f={},h=null,p=null;u!==void 0&&(h=""+u),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return _r.Fragment=n,_r.jsx=i,_r.jsxs=i,_r}var Mr={};/**
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 yl;function Pm(){return yl||(yl=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"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),y=Symbol.iterator,g="@@iterator";function v(N){if(N===null||typeof N!="object")return null;var re=y&&N[y]||N[g];return typeof re=="function"?re:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(N){{for(var re=arguments.length,ce=new Array(re>1?re-1:0),Ne=1;Ne<re;Ne++)ce[Ne-1]=arguments[Ne];k("error",N,ce)}}function k(N,re,ce){{var Ne=x.ReactDebugCurrentFrame,Qe=Ne.getStackAddendum();Qe!==""&&(re+="%s",ce=ce.concat([Qe]));var st=ce.map(function(Ue){return String(Ue)});st.unshift("Warning: "+re),Function.prototype.apply.call(console[N],console,st)}}var T=!1,S=!1,C=!1,I=!1,A=!1,R;R=Symbol.for("react.module.reference");function D(N){return!!(typeof N=="string"||typeof N=="function"||N===r||N===s||A||N===o||N===u||N===d||I||N===p||T||S||C||typeof N=="object"&&N!==null&&(N.$$typeof===h||N.$$typeof===f||N.$$typeof===i||N.$$typeof===a||N.$$typeof===l||N.$$typeof===R||N.getModuleId!==void 0))}function B(N,re,ce){var Ne=N.displayName;if(Ne)return Ne;var Qe=re.displayName||re.name||"";return Qe!==""?ce+"("+Qe+")":ce}function X(N){return N.displayName||"Context"}function G(N){if(N==null)return null;if(typeof N.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof N=="function")return N.displayName||N.name||null;if(typeof N=="string")return N;switch(N){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof N=="object")switch(N.$$typeof){case a:var re=N;return X(re)+".Consumer";case i:var ce=N;return X(ce._context)+".Provider";case l:return B(N,N.render,"ForwardRef");case f:var Ne=N.displayName||null;return Ne!==null?Ne:G(N.type)||"Memo";case h:{var Qe=N,st=Qe._payload,Ue=Qe._init;try{return G(Ue(st))}catch{return null}}}return null}var M=Object.assign,U=0,E,P,L,_,q,Y,j;function J(){}J.__reactDisabledLog=!0;function V(){{if(U===0){E=console.log,P=console.info,L=console.warn,_=console.error,q=console.group,Y=console.groupCollapsed,j=console.groupEnd;var N={configurable:!0,enumerable:!0,value:J,writable:!0};Object.defineProperties(console,{info:N,log:N,warn:N,error:N,group:N,groupCollapsed:N,groupEnd:N})}U++}}function H(){{if(U--,U===0){var N={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},N,{value:E}),info:M({},N,{value:P}),warn:M({},N,{value:L}),error:M({},N,{value:_}),group:M({},N,{value:q}),groupCollapsed:M({},N,{value:Y}),groupEnd:M({},N,{value:j})})}U<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ee=x.ReactCurrentDispatcher,W;function O(N,re,ce){{if(W===void 0)try{throw Error()}catch(Qe){var Ne=Qe.stack.trim().match(/\n( *(at )?)/);W=Ne&&Ne[1]||""}return`
18
- `+W+N}}var K=!1,z;{var ne=typeof WeakMap=="function"?WeakMap:Map;z=new ne}function Q(N,re){if(!N||K)return"";{var ce=z.get(N);if(ce!==void 0)return ce}var Ne;K=!0;var Qe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var st;st=ee.current,ee.current=null,V();try{if(re){var Ue=function(){throw Error()};if(Object.defineProperty(Ue.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Ue,[])}catch(Ye){Ne=Ye}Reflect.construct(N,[],Ue)}else{try{Ue.call()}catch(Ye){Ne=Ye}N.call(Ue.prototype)}}else{try{throw Error()}catch(Ye){Ne=Ye}N()}}catch(Ye){if(Ye&&Ne&&typeof Ye.stack=="string"){for(var Fe=Ye.stack.split(`
19
- `),Mt=Ne.stack.split(`
20
- `),gt=Fe.length-1,yt=Mt.length-1;gt>=1&&yt>=0&&Fe[gt]!==Mt[yt];)yt--;for(;gt>=1&&yt>=0;gt--,yt--)if(Fe[gt]!==Mt[yt]){if(gt!==1||yt!==1)do if(gt--,yt--,yt<0||Fe[gt]!==Mt[yt]){var me=`
21
- `+Fe[gt].replace(" at new "," at ");return N.displayName&&me.includes("<anonymous>")&&(me=me.replace("<anonymous>",N.displayName)),typeof N=="function"&&z.set(N,me),me}while(gt>=1&&yt>=0);break}}}finally{K=!1,ee.current=st,H(),Error.prepareStackTrace=Qe}var Ce=N?N.displayName||N.name:"",je=Ce?O(Ce):"";return typeof N=="function"&&z.set(N,je),je}function ge(N,re,ce){return Q(N,!1)}function le(N){var re=N.prototype;return!!(re&&re.isReactComponent)}function oe(N,re,ce){if(N==null)return"";if(typeof N=="function")return Q(N,le(N));if(typeof N=="string")return O(N);switch(N){case u:return O("Suspense");case d:return O("SuspenseList")}if(typeof N=="object")switch(N.$$typeof){case l:return ge(N.render);case f:return oe(N.type,re,ce);case h:{var Ne=N,Qe=Ne._payload,st=Ne._init;try{return oe(st(Qe),re,ce)}catch{}}}return""}var pe=Object.prototype.hasOwnProperty,be={},Me=x.ReactDebugCurrentFrame;function Ie(N){if(N){var re=N._owner,ce=oe(N.type,N._source,re?re.type:null);Me.setExtraStackFrame(ce)}else Me.setExtraStackFrame(null)}function De(N,re,ce,Ne,Qe){{var st=Function.call.bind(pe);for(var Ue in N)if(st(N,Ue)){var Fe=void 0;try{if(typeof N[Ue]!="function"){var Mt=Error((Ne||"React class")+": "+ce+" type `"+Ue+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof N[Ue]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Mt.name="Invariant Violation",Mt}Fe=N[Ue](re,Ue,Ne,ce,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(gt){Fe=gt}Fe&&!(Fe instanceof Error)&&(Ie(Qe),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).",Ne||"React class",ce,Ue,typeof Fe),Ie(null)),Fe instanceof Error&&!(Fe.message in be)&&(be[Fe.message]=!0,Ie(Qe),b("Failed %s type: %s",ce,Fe.message),Ie(null))}}}var et=Array.isArray;function rt(N){return et(N)}function He(N){{var re=typeof Symbol=="function"&&Symbol.toStringTag,ce=re&&N[Symbol.toStringTag]||N.constructor.name||"Object";return ce}}function Je(N){try{return ot(N),!1}catch{return!0}}function ot(N){return""+N}function St(N){if(Je(N))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",He(N)),ot(N)}var dt=x.ReactCurrentOwner,Tt={key:!0,ref:!0,__self:!0,__source:!0},mt,Ee;function Ke(N){if(pe.call(N,"ref")){var re=Object.getOwnPropertyDescriptor(N,"ref").get;if(re&&re.isReactWarning)return!1}return N.ref!==void 0}function xt(N){if(pe.call(N,"key")){var re=Object.getOwnPropertyDescriptor(N,"key").get;if(re&&re.isReactWarning)return!1}return N.key!==void 0}function It(N,re){typeof N.ref=="string"&&dt.current}function Le(N,re){{var ce=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)",re))};ce.isReactWarning=!0,Object.defineProperty(N,"key",{get:ce,configurable:!0})}}function _t(N,re){{var ce=function(){Ee||(Ee=!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)",re))};ce.isReactWarning=!0,Object.defineProperty(N,"ref",{get:ce,configurable:!0})}}var Ge=function(N,re,ce,Ne,Qe,st,Ue){var Fe={$$typeof:t,type:N,key:re,ref:ce,props:Ue,_owner:st};return Fe._store={},Object.defineProperty(Fe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Fe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Ne}),Object.defineProperty(Fe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Qe}),Object.freeze&&(Object.freeze(Fe.props),Object.freeze(Fe)),Fe};function Be(N,re,ce,Ne,Qe){{var st,Ue={},Fe=null,Mt=null;ce!==void 0&&(St(ce),Fe=""+ce),xt(re)&&(St(re.key),Fe=""+re.key),Ke(re)&&(Mt=re.ref,It(re,Qe));for(st in re)pe.call(re,st)&&!Tt.hasOwnProperty(st)&&(Ue[st]=re[st]);if(N&&N.defaultProps){var gt=N.defaultProps;for(st in gt)Ue[st]===void 0&&(Ue[st]=gt[st])}if(Fe||Mt){var yt=typeof N=="function"?N.displayName||N.name||"Unknown":N;Fe&&Le(Ue,yt),Mt&&_t(Ue,yt)}return Ge(N,Fe,Mt,Qe,Ne,dt.current,Ue)}}var lt=x.ReactCurrentOwner,Et=x.ReactDebugCurrentFrame;function qe(N){if(N){var re=N._owner,ce=oe(N.type,N._source,re?re.type:null);Et.setExtraStackFrame(ce)}else Et.setExtraStackFrame(null)}var Z;Z=!1;function $(N){return typeof N=="object"&&N!==null&&N.$$typeof===t}function he(){{if(lt.current){var N=G(lt.current.type);if(N)return`
17
+ */var yl;function Pm(){return yl||(yl=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"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),y=Symbol.iterator,g="@@iterator";function v(I){if(I===null||typeof I!="object")return null;var ee=y&&I[y]||I[g];return typeof ee=="function"?ee:null}var x=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(I){{for(var ee=arguments.length,ce=new Array(ee>1?ee-1:0),Ee=1;Ee<ee;Ee++)ce[Ee-1]=arguments[Ee];C("error",I,ce)}}function C(I,ee,ce){{var Ee=x.ReactDebugCurrentFrame,Qe=Ee.getStackAddendum();Qe!==""&&(ee+="%s",ce=ce.concat([Qe]));var rt=ce.map(function(Be){return String(Be)});rt.unshift("Warning: "+ee),Function.prototype.apply.call(console[I],console,rt)}}var k=!1,S=!1,T=!1,E=!1,A=!1,P;P=Symbol.for("react.module.reference");function $(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||A||I===o||I===u||I===d||E||I===p||k||S||T||typeof I=="object"&&I!==null&&(I.$$typeof===h||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===P||I.getModuleId!==void 0))}function B(I,ee,ce){var Ee=I.displayName;if(Ee)return Ee;var Qe=ee.displayName||ee.name||"";return Qe!==""?ce+"("+Qe+")":ce}function V(I){return I.displayName||"Context"}function G(I){if(I==null)return null;if(typeof I.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var ee=I;return V(ee)+".Consumer";case i:var ce=I;return V(ce._context)+".Provider";case l:return B(I,I.render,"ForwardRef");case f:var Ee=I.displayName||null;return Ee!==null?Ee:G(I.type)||"Memo";case h:{var Qe=I,rt=Qe._payload,Be=Qe._init;try{return G(Be(rt))}catch{return null}}}return null}var O=Object.assign,U=0,N,D,M,j,H,W,R;function K(){}K.__reactDisabledLog=!0;function ie(){{if(U===0){N=console.log,D=console.info,M=console.warn,j=console.error,H=console.group,W=console.groupCollapsed,R=console.groupEnd;var I={configurable:!0,enumerable:!0,value:K,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}U++}}function Q(){{if(U--,U===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},I,{value:N}),info:O({},I,{value:D}),warn:O({},I,{value:M}),error:O({},I,{value:j}),group:O({},I,{value:H}),groupCollapsed:O({},I,{value:W}),groupEnd:O({},I,{value:R})})}U<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var oe=x.ReactCurrentDispatcher,Y;function L(I,ee,ce){{if(Y===void 0)try{throw Error()}catch(Qe){var Ee=Qe.stack.trim().match(/\n( *(at )?)/);Y=Ee&&Ee[1]||""}return`
18
+ `+Y+I}}var q=!1,z;{var Z=typeof WeakMap=="function"?WeakMap:Map;z=new Z}function X(I,ee){if(!I||q)return"";{var ce=z.get(I);if(ce!==void 0)return ce}var Ee;q=!0;var Qe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var rt;rt=oe.current,oe.current=null,ie();try{if(ee){var Be=function(){throw Error()};if(Object.defineProperty(Be.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Be,[])}catch(Ge){Ee=Ge}Reflect.construct(I,[],Be)}else{try{Be.call()}catch(Ge){Ee=Ge}I.call(Be.prototype)}}else{try{throw Error()}catch(Ge){Ee=Ge}I()}}catch(Ge){if(Ge&&Ee&&typeof Ge.stack=="string"){for(var Fe=Ge.stack.split(`
19
+ `),_t=Ee.stack.split(`
20
+ `),mt=Fe.length-1,xt=_t.length-1;mt>=1&&xt>=0&&Fe[mt]!==_t[xt];)xt--;for(;mt>=1&&xt>=0;mt--,xt--)if(Fe[mt]!==_t[xt]){if(mt!==1||xt!==1)do if(mt--,xt--,xt<0||Fe[mt]!==_t[xt]){var me=`
21
+ `+Fe[mt].replace(" at new "," at ");return I.displayName&&me.includes("<anonymous>")&&(me=me.replace("<anonymous>",I.displayName)),typeof I=="function"&&z.set(I,me),me}while(mt>=1&&xt>=0);break}}}finally{q=!1,oe.current=rt,Q(),Error.prepareStackTrace=Qe}var Se=I?I.displayName||I.name:"",Ae=Se?L(Se):"";return typeof I=="function"&&z.set(I,Ae),Ae}function ge(I,ee,ce){return X(I,!1)}function le(I){var ee=I.prototype;return!!(ee&&ee.isReactComponent)}function te(I,ee,ce){if(I==null)return"";if(typeof I=="function")return X(I,le(I));if(typeof I=="string")return L(I);switch(I){case u:return L("Suspense");case d:return L("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return ge(I.render);case f:return te(I.type,ee,ce);case h:{var Ee=I,Qe=Ee._payload,rt=Ee._init;try{return te(rt(Qe),ee,ce)}catch{}}}return""}var fe=Object.prototype.hasOwnProperty,ye={},Me=x.ReactDebugCurrentFrame;function Ne(I){if(I){var ee=I._owner,ce=te(I.type,I._source,ee?ee.type:null);Me.setExtraStackFrame(ce)}else Me.setExtraStackFrame(null)}function $e(I,ee,ce,Ee,Qe){{var rt=Function.call.bind(fe);for(var Be in I)if(rt(I,Be)){var Fe=void 0;try{if(typeof I[Be]!="function"){var _t=Error((Ee||"React class")+": "+ce+" type `"+Be+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[Be]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw _t.name="Invariant Violation",_t}Fe=I[Be](ee,Be,Ee,ce,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Fe=mt}Fe&&!(Fe instanceof Error)&&(Ne(Qe),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).",Ee||"React class",ce,Be,typeof Fe),Ne(null)),Fe instanceof Error&&!(Fe.message in ye)&&(ye[Fe.message]=!0,Ne(Qe),b("Failed %s type: %s",ce,Fe.message),Ne(null))}}}var Xe=Array.isArray;function nt(I){return Xe(I)}function Ve(I){{var ee=typeof Symbol=="function"&&Symbol.toStringTag,ce=ee&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ce}}function qe(I){try{return ot(I),!1}catch{return!0}}function ot(I){return""+I}function kt(I){if(qe(I))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ve(I)),ot(I)}var lt=x.ReactCurrentOwner,ke={key:!0,ref:!0,__self:!0,__source:!0},Oe,at;function pt(I){if(fe.call(I,"ref")){var ee=Object.getOwnPropertyDescriptor(I,"ref").get;if(ee&&ee.isReactWarning)return!1}return I.ref!==void 0}function Et(I){if(fe.call(I,"key")){var ee=Object.getOwnPropertyDescriptor(I,"key").get;if(ee&&ee.isReactWarning)return!1}return I.key!==void 0}function Ct(I,ee){typeof I.ref=="string"&&lt.current}function Le(I,ee){{var ce=function(){Oe||(Oe=!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)",ee))};ce.isReactWarning=!0,Object.defineProperty(I,"key",{get:ce,configurable:!0})}}function Vt(I,ee){{var ce=function(){at||(at=!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)",ee))};ce.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ce,configurable:!0})}}var Je=function(I,ee,ce,Ee,Qe,rt,Be){var Fe={$$typeof:t,type:I,key:ee,ref:ce,props:Be,_owner:rt};return Fe._store={},Object.defineProperty(Fe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Fe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Ee}),Object.defineProperty(Fe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Qe}),Object.freeze&&(Object.freeze(Fe.props),Object.freeze(Fe)),Fe};function Ke(I,ee,ce,Ee,Qe){{var rt,Be={},Fe=null,_t=null;ce!==void 0&&(kt(ce),Fe=""+ce),Et(ee)&&(kt(ee.key),Fe=""+ee.key),pt(ee)&&(_t=ee.ref,Ct(ee,Qe));for(rt in ee)fe.call(ee,rt)&&!ke.hasOwnProperty(rt)&&(Be[rt]=ee[rt]);if(I&&I.defaultProps){var mt=I.defaultProps;for(rt in mt)Be[rt]===void 0&&(Be[rt]=mt[rt])}if(Fe||_t){var xt=typeof I=="function"?I.displayName||I.name||"Unknown":I;Fe&&Le(Be,xt),_t&&Vt(Be,xt)}return Je(I,Fe,_t,Qe,Ee,lt.current,Be)}}var dt=x.ReactCurrentOwner,bt=x.ReactDebugCurrentFrame;function He(I){if(I){var ee=I._owner,ce=te(I.type,I._source,ee?ee.type:null);bt.setExtraStackFrame(ce)}else bt.setExtraStackFrame(null)}var Tt;Tt=!1;function _(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function se(){{if(dt.current){var I=G(dt.current.type);if(I)return`
22
22
 
23
- Check the render method of \``+N+"`."}return""}}function we(N){return""}var $e={};function ze(N){{var re=he();if(!re){var ce=typeof N=="string"?N:N.displayName||N.name;ce&&(re=`
23
+ Check the render method of \``+I+"`."}return""}}function pe(I){return""}var We={};function Pe(I){{var ee=se();if(!ee){var ce=typeof I=="string"?I:I.displayName||I.name;ce&&(ee=`
24
24
 
25
- Check the top-level render call using <`+ce+">.")}return re}}function pt(N,re){{if(!N._store||N._store.validated||N.key!=null)return;N._store.validated=!0;var ce=ze(re);if($e[ce])return;$e[ce]=!0;var Ne="";N&&N._owner&&N._owner!==lt.current&&(Ne=" It was passed a child from "+G(N._owner.type)+"."),qe(N),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ce,Ne),qe(null)}}function Ze(N,re){{if(typeof N!="object")return;if(rt(N))for(var ce=0;ce<N.length;ce++){var Ne=N[ce];$(Ne)&&pt(Ne,re)}else if($(N))N._store&&(N._store.validated=!0);else if(N){var Qe=v(N);if(typeof Qe=="function"&&Qe!==N.entries)for(var st=Qe.call(N),Ue;!(Ue=st.next()).done;)$(Ue.value)&&pt(Ue.value,re)}}}function Ct(N){{var re=N.type;if(re==null||typeof re=="string")return;var ce;if(typeof re=="function")ce=re.propTypes;else if(typeof re=="object"&&(re.$$typeof===l||re.$$typeof===f))ce=re.propTypes;else return;if(ce){var Ne=G(re);De(ce,N.props,"prop",Ne,N)}else if(re.PropTypes!==void 0&&!Z){Z=!0;var Qe=G(re);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Qe||"Unknown")}typeof re.getDefaultProps=="function"&&!re.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function cr(N){{for(var re=Object.keys(N.props),ce=0;ce<re.length;ce++){var Ne=re[ce];if(Ne!=="children"&&Ne!=="key"){qe(N),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ne),qe(null);break}}N.ref!==null&&(qe(N),b("Invalid attribute `ref` supplied to `React.Fragment`."),qe(null))}}var vo={};function ri(N,re,ce,Ne,Qe,st){{var Ue=D(N);if(!Ue){var Fe="";(N===void 0||typeof N=="object"&&N!==null&&Object.keys(N).length===0)&&(Fe+=" 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 Mt=we();Mt?Fe+=Mt:Fe+=he();var gt;N===null?gt="null":rt(N)?gt="array":N!==void 0&&N.$$typeof===t?(gt="<"+(G(N.type)||"Unknown")+" />",Fe=" Did you accidentally export a JSX literal instead of a component?"):gt=typeof N,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",gt,Fe)}var yt=Be(N,re,ce,Qe,st);if(yt==null)return yt;if(Ue){var me=re.children;if(me!==void 0)if(Ne)if(rt(me)){for(var Ce=0;Ce<me.length;Ce++)Ze(me[Ce],N);Object.freeze&&Object.freeze(me)}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 Ze(me,N)}if(pe.call(re,"key")){var je=G(N),Ye=Object.keys(re).filter(function(eI){return eI!=="key"}),Hn=Ye.length>0?"{key: someKey, "+Ye.join(": ..., ")+": ...}":"{key: someKey}";if(!vo[je+Hn]){var on=Ye.length>0?"{"+Ye.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+ce+">.")}return ee}}function gt(I,ee){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ce=Pe(ee);if(We[ce])return;We[ce]=!0;var Ee="";I&&I._owner&&I._owner!==dt.current&&(Ee=" It was passed a child from "+G(I._owner.type)+"."),He(I),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ce,Ee),He(null)}}function Ze(I,ee){{if(typeof I!="object")return;if(nt(I))for(var ce=0;ce<I.length;ce++){var Ee=I[ce];_(Ee)&&gt(Ee,ee)}else if(_(I))I._store&&(I._store.validated=!0);else if(I){var Qe=v(I);if(typeof Qe=="function"&&Qe!==I.entries)for(var rt=Qe.call(I),Be;!(Be=rt.next()).done;)_(Be.value)&&gt(Be.value,ee)}}}function jt(I){{var ee=I.type;if(ee==null||typeof ee=="string")return;var ce;if(typeof ee=="function")ce=ee.propTypes;else if(typeof ee=="object"&&(ee.$$typeof===l||ee.$$typeof===f))ce=ee.propTypes;else return;if(ce){var Ee=G(ee);$e(ce,I.props,"prop",Ee,I)}else if(ee.PropTypes!==void 0&&!Tt){Tt=!0;var Qe=G(ee);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Qe||"Unknown")}typeof ee.getDefaultProps=="function"&&!ee.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function yo(I){{for(var ee=Object.keys(I.props),ce=0;ce<ee.length;ce++){var Ee=ee[ce];if(Ee!=="children"&&Ee!=="key"){He(I),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ee),He(null);break}}I.ref!==null&&(He(I),b("Invalid attribute `ref` supplied to `React.Fragment`."),He(null))}}var vo={};function ri(I,ee,ce,Ee,Qe,rt){{var Be=$(I);if(!Be){var Fe="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(Fe+=" 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 _t=pe();_t?Fe+=_t:Fe+=se();var mt;I===null?mt="null":nt(I)?mt="array":I!==void 0&&I.$$typeof===t?(mt="<"+(G(I.type)||"Unknown")+" />",Fe=" Did you accidentally export a JSX literal instead of a component?"):mt=typeof I,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,Fe)}var xt=Ke(I,ee,ce,Qe,rt);if(xt==null)return xt;if(Be){var me=ee.children;if(me!==void 0)if(Ee)if(nt(me)){for(var Se=0;Se<me.length;Se++)Ze(me[Se],I);Object.freeze&&Object.freeze(me)}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 Ze(me,I)}if(fe.call(ee,"key")){var Ae=G(I),Ge=Object.keys(ee).filter(function(Qk){return Qk!=="key"}),Hn=Ge.length>0?"{key: someKey, "+Ge.join(": ..., ")+": ...}":"{key: someKey}";if(!vo[Ae+Hn]){var on=Ge.length>0?"{"+Ge.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,je,on,je),vo[je+Hn]=!0}}return N===r?cr(yt):Ct(yt),yt}}function hl(N,re,ce){return ri(N,re,ce,!0)}function pl(N,re,ce){return ri(N,re,ce,!1)}var ml=pl,oi=hl;Rr.Fragment=r,Rr.jsx=ml,Rr.jsxs=oi}()),Rr}process.env.NODE_ENV==="production"?ai.exports=Rm():ai.exports=Pm();var c=ai.exports;function vl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Om}=Object.prototype,{getPrototypeOf:li}=Object,{iterator:So,toStringTag:bl}=Symbol,Co=(e=>t=>{const n=Om.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),sn=e=>(e=e.toLowerCase(),t=>Co(t)===e),ko=e=>t=>typeof t===e,{isArray:ur}=Array,dr=ko("undefined");function Pr(e){return e!==null&&!dr(e)&&e.constructor!==null&&!dr(e.constructor)&&Ut(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const wl=sn("ArrayBuffer");function Dm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&wl(e.buffer),t}const Lm=ko("string"),Ut=ko("function"),Sl=ko("number"),Or=e=>e!==null&&typeof e=="object",$m=e=>e===!0||e===!1,To=e=>{if(Co(e)!=="object")return!1;const t=li(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(bl in e)&&!(So in e)},Fm=e=>{if(!Or(e)||Pr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Bm=sn("Date"),zm=sn("File"),Um=sn("Blob"),Hm=sn("FileList"),Wm=e=>Or(e)&&Ut(e.pipe),Vm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Ut(e.append)&&((t=Co(e))==="formdata"||t==="object"&&Ut(e.toString)&&e.toString()==="[object FormData]"))},Km=sn("URLSearchParams"),[qm,Gm,Ym,Xm]=["ReadableStream","Request","Response","Headers"].map(sn),Jm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Dr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),ur(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Pr(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 Cl(e,t){if(Pr(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,kl=e=>!dr(e)&&e!==Vn;function ci(){const{caseless:e,skipUndefined:t}=kl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Cl(n,s)||s;To(n[i])&&To(o)?n[i]=ci(n[i],o):To(o)?n[i]=ci({},o):ur(o)?n[i]=o.slice():(!t||!dr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Dr(arguments[o],r);return n}const Zm=(e,t,n,{allOwnKeys:r}={})=>(Dr(t,(o,s)=>{n&&Ut(o)?e[s]=vl(o,n):e[s]=o},{allOwnKeys:r}),e),Qm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),eg=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},tg=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&li(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},ng=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},rg=e=>{if(!e)return null;if(ur(e))return e;let t=e.length;if(!Sl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},og=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&li(Uint8Array)),sg=(e,t)=>{const r=(e&&e[So]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ag=sn("HTMLFormElement"),lg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),cg=sn("RegExp"),Il=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Dr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},ug=e=>{Il(e,(t,n)=>{if(Ut(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Ut(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},dg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ur(e)?r(e):r(String(e).split(t)),n},fg=()=>{},hg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function pg(e){return!!(e&&Ut(e.append)&&e[bl]==="FormData"&&e[So])}const mg=e=>{const t=new Array(10),n=(r,o)=>{if(Or(r)){if(t.indexOf(r)>=0)return;if(Pr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=ur(r)?[]:{};return Dr(r,(i,a)=>{const l=n(i,o+1);!dr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},gg=sn("AsyncFunction"),xg=e=>e&&(Or(e)||Ut(e))&&Ut(e.then)&&Ut(e.catch),El=((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",Ut(Vn.postMessage)),yg=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||El,F={isArray:ur,isArrayBuffer:wl,isBuffer:Pr,isFormData:Vm,isArrayBufferView:Dm,isString:Lm,isNumber:Sl,isBoolean:$m,isObject:Or,isPlainObject:To,isEmptyObject:Fm,isReadableStream:qm,isRequest:Gm,isResponse:Ym,isHeaders:Xm,isUndefined:dr,isDate:Bm,isFile:zm,isBlob:Um,isRegExp:cg,isFunction:Ut,isStream:Wm,isURLSearchParams:Km,isTypedArray:og,isFileList:Hm,forEach:Dr,merge:ci,extend:Zm,trim:Jm,stripBOM:Qm,inherits:eg,toFlatObject:tg,kindOf:Co,kindOfTest:sn,endsWith:ng,toArray:rg,forEachEntry:sg,matchAll:ig,isHTMLForm:ag,hasOwnProperty:Tl,hasOwnProp:Tl,reduceDescriptors:Il,freezeMethods:ug,toObjectSet:dg,toCamelCase:lg,noop:fg,toFiniteNumber:hg,findKey:Cl,global:Vn,isContextDefined:kl,isSpecCompliantForm:pg,toJSONObject:mg,isAsyncFn:gg,isThenable:xg,setImmediate:El,asap:yg,isIterable:e=>e!=null&&Ut(e[So])};function Re(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}F.inherits(Re,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:F.toJSONObject(this.config),code:this.code,status:this.status}}});const Nl=Re.prototype,Al={};["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=>{Al[e]={value:e}}),Object.defineProperties(Re,Al),Object.defineProperty(Nl,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(Nl);F.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Re.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const vg=null;function ui(e){return F.isPlainObject(e)||F.isArray(e)}function jl(e){return F.endsWith(e,"[]")?e.slice(0,-2):e}function _l(e,t,n){return e?e.concat(t).map(function(o,s){return o=jl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function bg(e){return F.isArray(e)&&!e.some(ui)}const wg=F.toFlatObject(F,{},null,function(t){return/^is[A-Z]/.test(t)});function Io(e,t,n){if(!F.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=F.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,v){return!F.isUndefined(v[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&F.isSpecCompliantForm(t);if(!F.isFunction(o))throw new TypeError("visitor must be a function");function u(y){if(y===null)return"";if(F.isDate(y))return y.toISOString();if(F.isBoolean(y))return y.toString();if(!l&&F.isBlob(y))throw new Re("Blob is not supported. Use a Buffer instead.");return F.isArrayBuffer(y)||F.isTypedArray(y)?l&&typeof Blob=="function"?new Blob([y]):Buffer.from(y):y}function d(y,g,v){let x=y;if(y&&!v&&typeof y=="object"){if(F.endsWith(g,"{}"))g=r?g:g.slice(0,-2),y=JSON.stringify(y);else if(F.isArray(y)&&bg(y)||(F.isFileList(y)||F.endsWith(g,"[]"))&&(x=F.toArray(y)))return g=jl(g),x.forEach(function(k,T){!(F.isUndefined(k)||k===null)&&t.append(i===!0?_l([g],T,s):i===null?g:g+"[]",u(k))}),!1}return ui(y)?!0:(t.append(_l(v,g,s),u(y)),!1)}const f=[],h=Object.assign(wg,{defaultVisitor:d,convertValue:u,isVisitable:ui});function p(y,g){if(!F.isUndefined(y)){if(f.indexOf(y)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(y),F.forEach(y,function(x,b){(!(F.isUndefined(x)||x===null)&&o.call(t,x,F.isString(b)?b.trim():b,g,h))===!0&&p(x,g?g.concat(b):[b])}),f.pop()}}if(!F.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Ml(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function di(e,t){this._pairs=[],e&&Io(e,this,t)}const Rl=di.prototype;Rl.append=function(t,n){this._pairs.push([t,n])},Rl.toString=function(t){const n=t?function(r){return t.call(this,r,Ml)}:Ml;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Sg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Pl(e,t,n){if(!t)return e;const r=n&&n.encode||Sg;F.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=F.isURLSearchParams(t)?t.toString():new di(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Ol{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){F.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Cg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:di,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},fi=typeof window<"u"&&typeof document<"u",hi=typeof navigator=="object"&&navigator||void 0,kg=fi&&(!hi||["ReactNative","NativeScript","NS"].indexOf(hi.product)<0),Tg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Ig=fi&&window.location.href||"http://localhost",Rt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:fi,hasStandardBrowserEnv:kg,hasStandardBrowserWebWorkerEnv:Tg,navigator:hi,origin:Ig},Symbol.toStringTag,{value:"Module"})),...Cg};function Eg(e,t){return Io(e,new Rt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Rt.isNode&&F.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Ng(e){return F.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ag(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Ll(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&&F.isArray(o)?o.length:i,l?(F.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!F.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&F.isArray(o[i])&&(o[i]=Ag(o[i])),!a)}if(F.isFormData(e)&&F.isFunction(e.entries)){const n={};return F.forEachEntry(e,(r,o)=>{t(Ng(r),o,n,0)}),n}return null}function jg(e,t,n){if(F.isString(e))try{return(t||JSON.parse)(e),F.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Lr={transitional:Dl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=F.isObject(t);if(s&&F.isHTMLForm(t)&&(t=new FormData(t)),F.isFormData(t))return o?JSON.stringify(Ll(t)):t;if(F.isArrayBuffer(t)||F.isBuffer(t)||F.isStream(t)||F.isFile(t)||F.isBlob(t)||F.isReadableStream(t))return t;if(F.isArrayBufferView(t))return t.buffer;if(F.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 Eg(t,this.formSerializer).toString();if((a=F.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Io(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),jg(t)):t}],transformResponse:[function(t){const n=this.transitional||Lr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(F.isResponse(t)||F.isReadableStream(t))return t;if(t&&F.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Re.from(a,Re.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Rt.classes.FormData,Blob:Rt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};F.forEach(["delete","get","head","post","put","patch"],e=>{Lr.headers[e]={}});const _g=F.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"]),Mg=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]&&_g[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},$l=Symbol("internals");function $r(e){return e&&String(e).trim().toLowerCase()}function Eo(e){return e===!1||e==null?e:F.isArray(e)?e.map(Eo):String(e)}function Rg(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 Pg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function pi(e,t,n,r,o){if(F.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!F.isString(t)){if(F.isString(r))return t.indexOf(r)!==-1;if(F.isRegExp(r))return r.test(t)}}function Og(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Dg(e,t){const n=F.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 Ht=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=$r(l);if(!d)throw new Error("header name must be a non-empty string");const f=F.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||l]=Eo(a))}const i=(a,l)=>F.forEach(a,(u,d)=>s(u,d,l));if(F.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(F.isString(t)&&(t=t.trim())&&!Pg(t))i(Mg(t),n);else if(F.isObject(t)&&F.isIterable(t)){let a={},l,u;for(const d of t){if(!F.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(l=a[u])?F.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=$r(t),t){const r=F.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Rg(o);if(F.isFunction(n))return n.call(this,o,r);if(F.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=$r(t),t){const r=F.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||pi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=$r(i),i){const a=F.findKey(r,i);a&&(!n||pi(r,r[a],a,n))&&(delete r[a],o=!0)}}return F.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||pi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return F.forEach(this,(o,s)=>{const i=F.findKey(r,s);if(i){n[i]=Eo(o),delete n[s];return}const a=t?Og(s):String(s).trim();a!==s&&delete n[s],n[a]=Eo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return F.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&F.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[$l]=this[$l]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=$r(i);r[a]||(Dg(o,i),r[a]=!0)}return F.isArray(t)?t.forEach(s):s(t),this}};Ht.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),F.reduceDescriptors(Ht.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),F.freezeMethods(Ht);function mi(e,t){const n=this||Lr,r=t||n,o=Ht.from(r.headers);let s=r.data;return F.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Fl(e){return!!(e&&e.__CANCEL__)}function fr(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}F.inherits(fr,Re,{__CANCEL__:!0});function Bl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Re("Request failed with status code "+n.status,[Re.ERR_BAD_REQUEST,Re.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Lg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function $g(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function Fg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const No=(e,t,n=3)=>{let r=0;const o=$g(50,250);return Fg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},zl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ul=e=>(...t)=>F.asap(()=>e(...t)),Bg=Rt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Rt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Rt.origin),Rt.navigator&&/(msie|trident)/i.test(Rt.navigator.userAgent)):()=>!0,zg=Rt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];F.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),F.isString(r)&&i.push("path="+r),F.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 Ug(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Hg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Hl(e,t,n){let r=!Ug(t);return e&&(r||n==!1)?Hg(e,t):t}const Wl=e=>e instanceof Ht?{...e}:e;function Kn(e,t){t=t||{};const n={};function r(u,d,f,h){return F.isPlainObject(u)&&F.isPlainObject(d)?F.merge.call({caseless:h},u,d):F.isPlainObject(d)?F.merge({},d):F.isArray(d)?d.slice():d}function o(u,d,f,h){if(F.isUndefined(d)){if(!F.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!F.isUndefined(d))return r(void 0,d)}function i(u,d){if(F.isUndefined(d)){if(!F.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o(Wl(u),Wl(d),f,!0)};return F.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);F.isUndefined(h)&&f!==a||(n[d]=h)}),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=Ht.from(i),t.url=Pl(Hl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),F.isFormData(n)){if(Rt.hasStandardBrowserEnv||Rt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(F.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(Rt.hasStandardBrowserEnv&&(r&&F.isFunction(r)&&(r=r(t)),r||r!==!1&&Bg(t.url))){const l=o&&s&&zg.read(s);l&&i.set(o,l)}return t},Wg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Vl(e);let s=o.data;const i=Ht.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,y;function g(){p&&p(),y&&y(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let v=new XMLHttpRequest;v.open(o.method.toUpperCase(),o.url,!0),v.timeout=o.timeout;function x(){if(!v)return;const k=Ht.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:k,config:e,request:v};Bl(function(I){n(I),g()},function(I){r(I),g()},S),v=null}"onloadend"in v?v.onloadend=x:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(x)},v.onabort=function(){v&&(r(new Re("Request aborted",Re.ECONNABORTED,e,v)),v=null)},v.onerror=function(T){const S=T&&T.message?T.message:"Network Error",C=new Re(S,Re.ERR_NETWORK,e,v);C.event=T||null,r(C),v=null},v.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||Dl;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new Re(T,S.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,v)),v=null},s===void 0&&i.setContentType(null),"setRequestHeader"in v&&F.forEach(i.toJSON(),function(T,S){v.setRequestHeader(S,T)}),F.isUndefined(o.withCredentials)||(v.withCredentials=!!o.withCredentials),a&&a!=="json"&&(v.responseType=o.responseType),u&&([h,y]=No(u,!0),v.addEventListener("progress",h)),l&&v.upload&&([f,p]=No(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=k=>{v&&(r(!k||k.type?new fr(null,e,v):k),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Lg(o.url);if(b&&Rt.protocols.indexOf(b)===-1){r(new Re("Unsupported protocol "+b+":",Re.ERR_BAD_REQUEST,e));return}v.send(s||null)})},Vg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Re?d:new fr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Re(`timeout ${t} of ms exceeded`,Re.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>F.asap(a),l}},Kg=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},qg=async function*(e,t){for await(const n of Gg(e))yield*Kg(n,t)},Gg=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Kl=(e,t,n,r)=>{const o=qg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},ql=64*1024,{isFunction:Ao}=F,Yg=(({Request:e,Response:t})=>({Request:e,Response:t}))(F.global),{ReadableStream:Gl,TextEncoder:Yl}=F.global,Xl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Xg=e=>{e=F.merge.call({skipUndefined:!0},Yg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Ao(t):typeof fetch=="function",s=Ao(n),i=Ao(r);if(!o)return!1;const a=o&&Ao(Gl),l=o&&(typeof Yl=="function"?(y=>g=>y.encode(g))(new Yl):async y=>new Uint8Array(await new n(y).arrayBuffer())),u=s&&a&&Xl(()=>{let y=!1;const g=new n(Rt.origin,{body:new Gl,method:"POST",get duplex(){return y=!0,"half"}}).headers.has("Content-Type");return y&&!g}),d=i&&a&&Xl(()=>F.isReadableStream(new r("").body)),f={stream:d&&(y=>y.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(y=>{!f[y]&&(f[y]=(g,v)=>{let x=g&&g[y];if(x)return x.call(g);throw new Re(`Response type '${y}' is not supported`,Re.ERR_NOT_SUPPORT,v)})});const h=async y=>{if(y==null)return 0;if(F.isBlob(y))return y.size;if(F.isSpecCompliantForm(y))return(await new n(Rt.origin,{method:"POST",body:y}).arrayBuffer()).byteLength;if(F.isArrayBufferView(y)||F.isArrayBuffer(y))return y.byteLength;if(F.isURLSearchParams(y)&&(y=y+""),F.isString(y))return(await l(y)).byteLength},p=async(y,g)=>{const v=F.toFiniteNumber(y.getContentLength());return v??h(g)};return async y=>{let{url:g,method:v,data:x,signal:b,cancelToken:k,timeout:T,onDownloadProgress:S,onUploadProgress:C,responseType:I,headers:A,withCredentials:R="same-origin",fetchOptions:D}=Vl(y),B=t||fetch;I=I?(I+"").toLowerCase():"text";let X=Vg([b,k&&k.toAbortSignal()],T),G=null;const M=X&&X.unsubscribe&&(()=>{X.unsubscribe()});let U;try{if(C&&u&&v!=="get"&&v!=="head"&&(U=await p(A,x))!==0){let Y=new n(g,{method:"POST",body:x,duplex:"half"}),j;if(F.isFormData(x)&&(j=Y.headers.get("content-type"))&&A.setContentType(j),Y.body){const[J,V]=zl(U,No(Ul(C)));x=Kl(Y.body,ql,J,V)}}F.isString(R)||(R=R?"include":"omit");const E=s&&"credentials"in n.prototype,P={...D,signal:X,method:v.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:E?R:void 0};G=s&&new n(g,P);let L=await(s?B(G,D):B(g,P));const _=d&&(I==="stream"||I==="response");if(d&&(S||_&&M)){const Y={};["status","statusText","headers"].forEach(H=>{Y[H]=L[H]});const j=F.toFiniteNumber(L.headers.get("content-length")),[J,V]=S&&zl(j,No(Ul(S),!0))||[];L=new r(Kl(L.body,ql,J,()=>{V&&V(),M&&M()}),Y)}I=I||"text";let q=await f[F.findKey(f,I)||"text"](L,y);return!_&&M&&M(),await new Promise((Y,j)=>{Bl(Y,j,{data:q,headers:Ht.from(L.headers),status:L.status,statusText:L.statusText,config:y,request:G})})}catch(E){throw M&&M(),E&&E.name==="TypeError"&&/Load failed|fetch/i.test(E.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,y,G),{cause:E.cause||E}):Re.from(E,E&&E.code,y,G)}}},Jg=new Map,Jl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Jg;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Xg(t)),d=u;return u};Jl();const gi={http:vg,xhr:Wg,fetch:{get:Jl}};F.forEach(gi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Zl=e=>`- ${e}`,Zg=e=>F.isFunction(e)||e===null||e===!1,Ql={getAdapter:(e,t)=>{e=F.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Zg(r)&&(o=gi[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(F.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
30
+ <%s key={someKey} {...props} />`,Hn,Ae,on,Ae),vo[Ae+Hn]=!0}}return I===r?yo(xt):jt(xt),xt}}function hl(I,ee,ce){return ri(I,ee,ce,!0)}function pl(I,ee,ce){return ri(I,ee,ce,!1)}var ml=pl,oi=hl;Mr.Fragment=r,Mr.jsx=ml,Mr.jsxs=oi}()),Mr}process.env.NODE_ENV==="production"?ai.exports=Rm():ai.exports=Pm();var c=ai.exports;function vl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Om}=Object.prototype,{getPrototypeOf:li}=Object,{iterator:So,toStringTag:bl}=Symbol,Co=(e=>t=>{const n=Om.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),sn=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:cr}=Array,ur=To("undefined");function Rr(e){return e!==null&&!ur(e)&&e.constructor!==null&&!ur(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const wl=sn("ArrayBuffer");function Dm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&wl(e.buffer),t}const Lm=To("string"),zt=To("function"),Sl=To("number"),Pr=e=>e!==null&&typeof e=="object",$m=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=li(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(bl in e)&&!(So in e)},Fm=e=>{if(!Pr(e)||Rr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Bm=sn("Date"),zm=sn("File"),Um=sn("Blob"),Hm=sn("FileList"),Wm=e=>Pr(e)&&zt(e.pipe),Vm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=Co(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},Km=sn("URLSearchParams"),[qm,Gm,Ym,Xm]=["ReadableStream","Request","Response","Headers"].map(sn),Jm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Or(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(Rr(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 Cl(e,t){if(Rr(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,Tl=e=>!ur(e)&&e!==Vn;function ci(){const{caseless:e,skipUndefined:t}=Tl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Cl(n,s)||s;ko(n[i])&&ko(o)?n[i]=ci(n[i],o):ko(o)?n[i]=ci({},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]&&Or(arguments[o],r);return n}const Zm=(e,t,n,{allOwnKeys:r}={})=>(Or(t,(o,s)=>{n&&zt(o)?e[s]=vl(o,n):e[s]=o},{allOwnKeys:r}),e),Qm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),eg=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},tg=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&li(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},ng=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},rg=e=>{if(!e)return null;if(cr(e))return e;let t=e.length;if(!Sl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},og=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&li(Uint8Array)),sg=(e,t)=>{const r=(e&&e[So]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},ig=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ag=sn("HTMLFormElement"),lg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),kl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),cg=sn("RegExp"),El=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Or(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},ug=e=>{El(e,(t,n)=>{if(zt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(zt(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},dg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return cr(e)?r(e):r(String(e).split(t)),n},fg=()=>{},hg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function pg(e){return!!(e&&zt(e.append)&&e[bl]==="FormData"&&e[So])}const mg=e=>{const t=new Array(10),n=(r,o)=>{if(Pr(r)){if(t.indexOf(r)>=0)return;if(Rr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=cr(r)?[]:{};return Or(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)},gg=sn("AsyncFunction"),xg=e=>e&&(Pr(e)||zt(e))&&zt(e.then)&&zt(e.catch),Il=((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",zt(Vn.postMessage)),yg=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||Il,F={isArray:cr,isArrayBuffer:wl,isBuffer:Rr,isFormData:Vm,isArrayBufferView:Dm,isString:Lm,isNumber:Sl,isBoolean:$m,isObject:Pr,isPlainObject:ko,isEmptyObject:Fm,isReadableStream:qm,isRequest:Gm,isResponse:Ym,isHeaders:Xm,isUndefined:ur,isDate:Bm,isFile:zm,isBlob:Um,isRegExp:cg,isFunction:zt,isStream:Wm,isURLSearchParams:Km,isTypedArray:og,isFileList:Hm,forEach:Or,merge:ci,extend:Zm,trim:Jm,stripBOM:Qm,inherits:eg,toFlatObject:tg,kindOf:Co,kindOfTest:sn,endsWith:ng,toArray:rg,forEachEntry:sg,matchAll:ig,isHTMLForm:ag,hasOwnProperty:kl,hasOwnProp:kl,reduceDescriptors:El,freezeMethods:ug,toObjectSet:dg,toCamelCase:lg,noop:fg,toFiniteNumber:hg,findKey:Cl,global:Vn,isContextDefined:Tl,isSpecCompliantForm:pg,toJSONObject:mg,isAsyncFn:gg,isThenable:xg,setImmediate:Il,asap:yg,isIterable:e=>e!=null&&zt(e[So])};function _e(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}F.inherits(_e,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:F.toJSONObject(this.config),code:this.code,status:this.status}}});const Nl=_e.prototype,Al={};["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=>{Al[e]={value:e}}),Object.defineProperties(_e,Al),Object.defineProperty(Nl,"isAxiosError",{value:!0}),_e.from=(e,t,n,r,o,s)=>{const i=Object.create(Nl);F.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return _e.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const vg=null;function ui(e){return F.isPlainObject(e)||F.isArray(e)}function jl(e){return F.endsWith(e,"[]")?e.slice(0,-2):e}function _l(e,t,n){return e?e.concat(t).map(function(o,s){return o=jl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function bg(e){return F.isArray(e)&&!e.some(ui)}const wg=F.toFlatObject(F,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!F.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=F.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,v){return!F.isUndefined(v[g])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&F.isSpecCompliantForm(t);if(!F.isFunction(o))throw new TypeError("visitor must be a function");function u(y){if(y===null)return"";if(F.isDate(y))return y.toISOString();if(F.isBoolean(y))return y.toString();if(!l&&F.isBlob(y))throw new _e("Blob is not supported. Use a Buffer instead.");return F.isArrayBuffer(y)||F.isTypedArray(y)?l&&typeof Blob=="function"?new Blob([y]):Buffer.from(y):y}function d(y,g,v){let x=y;if(y&&!v&&typeof y=="object"){if(F.endsWith(g,"{}"))g=r?g:g.slice(0,-2),y=JSON.stringify(y);else if(F.isArray(y)&&bg(y)||(F.isFileList(y)||F.endsWith(g,"[]"))&&(x=F.toArray(y)))return g=jl(g),x.forEach(function(C,k){!(F.isUndefined(C)||C===null)&&t.append(i===!0?_l([g],k,s):i===null?g:g+"[]",u(C))}),!1}return ui(y)?!0:(t.append(_l(v,g,s),u(y)),!1)}const f=[],h=Object.assign(wg,{defaultVisitor:d,convertValue:u,isVisitable:ui});function p(y,g){if(!F.isUndefined(y)){if(f.indexOf(y)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(y),F.forEach(y,function(x,b){(!(F.isUndefined(x)||x===null)&&o.call(t,x,F.isString(b)?b.trim():b,g,h))===!0&&p(x,g?g.concat(b):[b])}),f.pop()}}if(!F.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Ml(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function di(e,t){this._pairs=[],e&&Eo(e,this,t)}const Rl=di.prototype;Rl.append=function(t,n){this._pairs.push([t,n])},Rl.toString=function(t){const n=t?function(r){return t.call(this,r,Ml)}:Ml;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Sg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Pl(e,t,n){if(!t)return e;const r=n&&n.encode||Sg;F.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=F.isURLSearchParams(t)?t.toString():new di(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Ol{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){F.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Cg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:di,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},fi=typeof window<"u"&&typeof document<"u",hi=typeof navigator=="object"&&navigator||void 0,Tg=fi&&(!hi||["ReactNative","NativeScript","NS"].indexOf(hi.product)<0),kg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Eg=fi&&window.location.href||"http://localhost",Mt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:fi,hasStandardBrowserEnv:Tg,hasStandardBrowserWebWorkerEnv:kg,navigator:hi,origin:Eg},Symbol.toStringTag,{value:"Module"})),...Cg};function Ig(e,t){return Eo(e,new Mt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Mt.isNode&&F.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Ng(e){return F.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ag(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function Ll(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&&F.isArray(o)?o.length:i,l?(F.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!F.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&F.isArray(o[i])&&(o[i]=Ag(o[i])),!a)}if(F.isFormData(e)&&F.isFunction(e.entries)){const n={};return F.forEachEntry(e,(r,o)=>{t(Ng(r),o,n,0)}),n}return null}function jg(e,t,n){if(F.isString(e))try{return(t||JSON.parse)(e),F.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Dr={transitional:Dl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=F.isObject(t);if(s&&F.isHTMLForm(t)&&(t=new FormData(t)),F.isFormData(t))return o?JSON.stringify(Ll(t)):t;if(F.isArrayBuffer(t)||F.isBuffer(t)||F.isStream(t)||F.isFile(t)||F.isBlob(t)||F.isReadableStream(t))return t;if(F.isArrayBufferView(t))return t.buffer;if(F.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Ig(t,this.formSerializer).toString();if((a=F.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),jg(t)):t}],transformResponse:[function(t){const n=this.transitional||Dr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(F.isResponse(t)||F.isReadableStream(t))return t;if(t&&F.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?_e.from(a,_e.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Mt.classes.FormData,Blob:Mt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};F.forEach(["delete","get","head","post","put","patch"],e=>{Dr.headers[e]={}});const _g=F.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"]),Mg=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]&&_g[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},$l=Symbol("internals");function Lr(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:F.isArray(e)?e.map(Io):String(e)}function Rg(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 Pg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function pi(e,t,n,r,o){if(F.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!F.isString(t)){if(F.isString(r))return t.indexOf(r)!==-1;if(F.isRegExp(r))return r.test(t)}}function Og(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Dg(e,t){const n=F.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 Ut=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=Lr(l);if(!d)throw new Error("header name must be a non-empty string");const f=F.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||l]=Io(a))}const i=(a,l)=>F.forEach(a,(u,d)=>s(u,d,l));if(F.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(F.isString(t)&&(t=t.trim())&&!Pg(t))i(Mg(t),n);else if(F.isObject(t)&&F.isIterable(t)){let a={},l,u;for(const d of t){if(!F.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(l=a[u])?F.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=Lr(t),t){const r=F.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Rg(o);if(F.isFunction(n))return n.call(this,o,r);if(F.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Lr(t),t){const r=F.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||pi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Lr(i),i){const a=F.findKey(r,i);a&&(!n||pi(r,r[a],a,n))&&(delete r[a],o=!0)}}return F.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||pi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return F.forEach(this,(o,s)=>{const i=F.findKey(r,s);if(i){n[i]=Io(o),delete n[s];return}const a=t?Og(s):String(s).trim();a!==s&&delete n[s],n[a]=Io(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return F.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&F.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[$l]=this[$l]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Lr(i);r[a]||(Dg(o,i),r[a]=!0)}return F.isArray(t)?t.forEach(s):s(t),this}};Ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),F.reduceDescriptors(Ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),F.freezeMethods(Ut);function mi(e,t){const n=this||Dr,r=t||n,o=Ut.from(r.headers);let s=r.data;return F.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Fl(e){return!!(e&&e.__CANCEL__)}function dr(e,t,n){_e.call(this,e??"canceled",_e.ERR_CANCELED,t,n),this.name="CanceledError"}F.inherits(dr,_e,{__CANCEL__:!0});function Bl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new _e("Request failed with status code "+n.status,[_e.ERR_BAD_REQUEST,_e.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Lg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function $g(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function Fg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const No=(e,t,n=3)=>{let r=0;const o=$g(50,250);return Fg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},zl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ul=e=>(...t)=>F.asap(()=>e(...t)),Bg=Mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Mt.origin),Mt.navigator&&/(msie|trident)/i.test(Mt.navigator.userAgent)):()=>!0,zg=Mt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];F.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),F.isString(r)&&i.push("path="+r),F.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 Ug(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Hg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Hl(e,t,n){let r=!Ug(t);return e&&(r||n==!1)?Hg(e,t):t}const Wl=e=>e instanceof Ut?{...e}:e;function Kn(e,t){t=t||{};const n={};function r(u,d,f,h){return F.isPlainObject(u)&&F.isPlainObject(d)?F.merge.call({caseless:h},u,d):F.isPlainObject(d)?F.merge({},d):F.isArray(d)?d.slice():d}function o(u,d,f,h){if(F.isUndefined(d)){if(!F.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!F.isUndefined(d))return r(void 0,d)}function i(u,d){if(F.isUndefined(d)){if(!F.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o(Wl(u),Wl(d),f,!0)};return F.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);F.isUndefined(h)&&f!==a||(n[d]=h)}),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=Ut.from(i),t.url=Pl(Hl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),F.isFormData(n)){if(Mt.hasStandardBrowserEnv||Mt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(F.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(Mt.hasStandardBrowserEnv&&(r&&F.isFunction(r)&&(r=r(t)),r||r!==!1&&Bg(t.url))){const l=o&&s&&zg.read(s);l&&i.set(o,l)}return t},Wg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Vl(e);let s=o.data;const i=Ut.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,y;function g(){p&&p(),y&&y(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let v=new XMLHttpRequest;v.open(o.method.toUpperCase(),o.url,!0),v.timeout=o.timeout;function x(){if(!v)return;const C=Ut.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:C,config:e,request:v};Bl(function(E){n(E),g()},function(E){r(E),g()},S),v=null}"onloadend"in v?v.onloadend=x:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(x)},v.onabort=function(){v&&(r(new _e("Request aborted",_e.ECONNABORTED,e,v)),v=null)},v.onerror=function(k){const S=k&&k.message?k.message:"Network Error",T=new _e(S,_e.ERR_NETWORK,e,v);T.event=k||null,r(T),v=null},v.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||Dl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new _e(k,S.clarifyTimeoutError?_e.ETIMEDOUT:_e.ECONNABORTED,e,v)),v=null},s===void 0&&i.setContentType(null),"setRequestHeader"in v&&F.forEach(i.toJSON(),function(k,S){v.setRequestHeader(S,k)}),F.isUndefined(o.withCredentials)||(v.withCredentials=!!o.withCredentials),a&&a!=="json"&&(v.responseType=o.responseType),u&&([h,y]=No(u,!0),v.addEventListener("progress",h)),l&&v.upload&&([f,p]=No(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{v&&(r(!C||C.type?new dr(null,e,v):C),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Lg(o.url);if(b&&Mt.protocols.indexOf(b)===-1){r(new _e("Unsupported protocol "+b+":",_e.ERR_BAD_REQUEST,e));return}v.send(s||null)})},Vg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof _e?d:new dr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new _e(`timeout ${t} of ms exceeded`,_e.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>F.asap(a),l}},Kg=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},qg=async function*(e,t){for await(const n of Gg(e))yield*Kg(n,t)},Gg=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Kl=(e,t,n,r)=>{const o=qg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},ql=64*1024,{isFunction:Ao}=F,Yg=(({Request:e,Response:t})=>({Request:e,Response:t}))(F.global),{ReadableStream:Gl,TextEncoder:Yl}=F.global,Xl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Xg=e=>{e=F.merge.call({skipUndefined:!0},Yg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Ao(t):typeof fetch=="function",s=Ao(n),i=Ao(r);if(!o)return!1;const a=o&&Ao(Gl),l=o&&(typeof Yl=="function"?(y=>g=>y.encode(g))(new Yl):async y=>new Uint8Array(await new n(y).arrayBuffer())),u=s&&a&&Xl(()=>{let y=!1;const g=new n(Mt.origin,{body:new Gl,method:"POST",get duplex(){return y=!0,"half"}}).headers.has("Content-Type");return y&&!g}),d=i&&a&&Xl(()=>F.isReadableStream(new r("").body)),f={stream:d&&(y=>y.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(y=>{!f[y]&&(f[y]=(g,v)=>{let x=g&&g[y];if(x)return x.call(g);throw new _e(`Response type '${y}' is not supported`,_e.ERR_NOT_SUPPORT,v)})});const h=async y=>{if(y==null)return 0;if(F.isBlob(y))return y.size;if(F.isSpecCompliantForm(y))return(await new n(Mt.origin,{method:"POST",body:y}).arrayBuffer()).byteLength;if(F.isArrayBufferView(y)||F.isArrayBuffer(y))return y.byteLength;if(F.isURLSearchParams(y)&&(y=y+""),F.isString(y))return(await l(y)).byteLength},p=async(y,g)=>{const v=F.toFiniteNumber(y.getContentLength());return v??h(g)};return async y=>{let{url:g,method:v,data:x,signal:b,cancelToken:C,timeout:k,onDownloadProgress:S,onUploadProgress:T,responseType:E,headers:A,withCredentials:P="same-origin",fetchOptions:$}=Vl(y),B=t||fetch;E=E?(E+"").toLowerCase():"text";let V=Vg([b,C&&C.toAbortSignal()],k),G=null;const O=V&&V.unsubscribe&&(()=>{V.unsubscribe()});let U;try{if(T&&u&&v!=="get"&&v!=="head"&&(U=await p(A,x))!==0){let W=new n(g,{method:"POST",body:x,duplex:"half"}),R;if(F.isFormData(x)&&(R=W.headers.get("content-type"))&&A.setContentType(R),W.body){const[K,ie]=zl(U,No(Ul(T)));x=Kl(W.body,ql,K,ie)}}F.isString(P)||(P=P?"include":"omit");const N=s&&"credentials"in n.prototype,D={...$,signal:V,method:v.toUpperCase(),headers:A.normalize().toJSON(),body:x,duplex:"half",credentials:N?P:void 0};G=s&&new n(g,D);let M=await(s?B(G,$):B(g,D));const j=d&&(E==="stream"||E==="response");if(d&&(S||j&&O)){const W={};["status","statusText","headers"].forEach(Q=>{W[Q]=M[Q]});const R=F.toFiniteNumber(M.headers.get("content-length")),[K,ie]=S&&zl(R,No(Ul(S),!0))||[];M=new r(Kl(M.body,ql,K,()=>{ie&&ie(),O&&O()}),W)}E=E||"text";let H=await f[F.findKey(f,E)||"text"](M,y);return!j&&O&&O(),await new Promise((W,R)=>{Bl(W,R,{data:H,headers:Ut.from(M.headers),status:M.status,statusText:M.statusText,config:y,request:G})})}catch(N){throw O&&O(),N&&N.name==="TypeError"&&/Load failed|fetch/i.test(N.message)?Object.assign(new _e("Network Error",_e.ERR_NETWORK,y,G),{cause:N.cause||N}):_e.from(N,N&&N.code,y,G)}}},Jg=new Map,Jl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Jg;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Xg(t)),d=u;return u};Jl();const gi={http:vg,xhr:Wg,fetch:{get:Jl}};F.forEach(gi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Zl=e=>`- ${e}`,Zg=e=>F.isFunction(e)||e===null||e===!1,Ql={getAdapter:(e,t)=>{e=F.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Zg(r)&&(o=gi[(a=String(r)).toLowerCase()],o===void 0))throw new _e(`Unknown adapter '${a}'`);if(o&&(F.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
33
  `+i.map(Zl).join(`
34
- `):" "+Zl(i[0]):"as no adapter specified";throw new Re("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:gi};function xi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new fr(null,e)}function ec(e){return xi(e),e.headers=Ht.from(e.headers),e.data=mi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ql.getAdapter(e.adapter||Lr.adapter,e)(e).then(function(r){return xi(e),r.data=mi.call(e,e.transformResponse,r),r.headers=Ht.from(r.headers),r},function(r){return Fl(r)||(xi(e),r&&r.response&&(r.response.data=mi.call(e,e.transformResponse,r.response),r.response.headers=Ht.from(r.response.headers))),Promise.reject(r)})}const tc="1.12.2",jo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{jo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const nc={};jo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+tc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Re(o(i," has been removed"+(n?" in "+n:"")),Re.ERR_DEPRECATED);return n&&!nc[i]&&(nc[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}},jo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Qg(e,t,n){if(typeof e!="object")throw new Re("options must be an object",Re.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Re("option "+s+" must be "+l,Re.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Re("Unknown option "+s,Re.ERR_BAD_OPTION)}}const _o={assertOptions:Qg,validators:jo},hn=_o.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Ol,response:new Ol}}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&&_o.assertOptions(r,{silentJSONParsing:hn.transitional(hn.boolean),forcedJSONParsing:hn.transitional(hn.boolean),clarifyTimeoutError:hn.transitional(hn.boolean)},!1),o!=null&&(F.isFunction(o)?n.paramsSerializer={serialize:o}:_o.assertOptions(o,{encode:hn.function,serialize:hn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),_o.assertOptions(n,{baseUrl:hn.spelling("baseURL"),withXsrfToken:hn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&F.merge(s.common,s[n.method]);s&&F.forEach(["delete","get","head","post","put","patch","common"],y=>{delete s[y]}),n.headers=Ht.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(l=l&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const u=[];this.interceptors.response.forEach(function(g){u.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const y=[ec.bind(this),void 0];for(y.unshift(...a),y.push(...u),h=y.length,d=Promise.resolve(n);f<h;)d=d.then(y[f++],y[f++]);return d}h=a.length;let p=n;for(;f<h;){const y=a[f++],g=a[f++];try{p=y(p)}catch(v){g.call(this,v);break}}try{d=ec.call(this,p)}catch(y){return Promise.reject(y)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=Hl(t.baseURL,t.url,t.allowAbsoluteUrls);return Pl(n,t.params,t.paramsSerializer)}};F.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}))}}),F.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 ex=class jm{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 fr(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 jm(function(o){t=o}),cancel:t}}};function tx(e){return function(n){return e.apply(null,n)}}function nx(e){return F.isObject(e)&&e.isAxiosError===!0}const yi={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(yi).forEach(([e,t])=>{yi[t]=e});function rc(e){const t=new qn(e),n=vl(qn.prototype.request,t);return F.extend(n,qn.prototype,t,{allOwnKeys:!0}),F.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return rc(Kn(e,o))},n}const vt=rc(Lr);vt.Axios=qn,vt.CanceledError=fr,vt.CancelToken=ex,vt.isCancel=Fl,vt.VERSION=tc,vt.toFormData=Io,vt.AxiosError=Re,vt.Cancel=vt.CanceledError,vt.all=function(t){return Promise.all(t)},vt.spread=tx,vt.isAxiosError=nx,vt.mergeConfig=Kn,vt.AxiosHeaders=Ht,vt.formToJSON=e=>Ll(F.isHTMLForm(e)?new FormData(e):e),vt.getAdapter=Ql.getAdapter,vt.HttpStatusCode=yi,vt.default=vt;const{Axios:cI,AxiosError:uI,CanceledError:dI,isCancel:fI,CancelToken:hI,VERSION:pI,all:mI,Cancel:gI,isAxiosError:xI,spread:yI,toFormData:vI,AxiosHeaders:bI,HttpStatusCode:wI,formToJSON:SI,getAdapter:CI,mergeConfig:kI}=vt,oc=typeof window<"u"?window.__API_BASE_URL__:void 0,sc=oc?Cn(oc):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 Mo=null;const vi=new Set;function ic(){return Mo}function Ro(e){Mo=e,vi.forEach(t=>t(e))}function ac(e){return vi.add(e),()=>vi.delete(e)}const rx=3e4,ox=9e4,Wt=vt.create({...sc?{baseURL:sc}:{},timeout:rx,withCredentials:!0});Wt.interceptors.request.use(e=>(Mo&&(e.headers.Authorization=`Bearer ${Mo}`),e)),Wt.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),Ro(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 Vt(e,t){return Wt.defaults.baseURL?(await Wt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Po(e,t,n){return Wt.defaults.baseURL?(await Wt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function lc(e,t,n){return Wt.defaults.baseURL?(await Wt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function bi(e,t){return Wt.defaults.baseURL?(await Wt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Pt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class cc{get baseUrl(){const t=Wt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(Wt.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&Ro(t.authToken)}getAuthToken(){return ic()}setAuthToken(t){Ro(t)}onTokenChange(t){return ac(t)}async listThreads(){const t=await Vt("/threads"),n=Pt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Vt("/threads/shared"),n=Pt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSmartOrgUsers(){const t=Wt.defaults.baseURL?Wt.defaults.baseURL.replace(/\/chat\/?$/,""):"/api",n=await Vt("/auth/users",{baseURL:t}),r=Pt(n);return(r==null?void 0:r.users)??[]}async createThread(t){const r=await Po("/threads",t?{title:t}:void 0);return Pt(r)}async updateThread(t,n){const r=await lc(`/threads/${t}`,{title:n});return Pt(r)}async deleteThread(t){const n=await bi(`/threads/${t}`);return Pt(n)}async shareThread(t,n){const r=await Po(`/threads/${t}/share`,{shared_with_user_id:n});return Pt(r)}async threadInfo(t){const n=await Vt(`/threads/${t}/info`);return Pt(n)}async listAgents(){const t=await Vt("/agents"),n=Pt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Vt(`/agents/${t}`);return Pt(n)}async getAgentSchema(t){const n=await Vt(`/agents/${t}/schema`);return Pt(n)}async getState(t){const n=await Vt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Pt(n)}async getStateHistory(t){const n=await Vt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:ox});return Pt(n)}async cancelRun(t){const n=await Po("/runs/cancel",{threadId:t});return Pt(n)}async listCheckpointSummaries(t){const n=await Vt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Pt(n);return(r==null?void 0:r.items)??[]}async unshareThread(t,n){const r=await bi(`/threads/${t}/share/${n}`);return Pt(r)}}const Nn=new cc,uc=w.createContext(null);function sx({children:e,apiConfig:t}){const n=Nn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(uc.Provider,{value:r,children:e})}function wi(){const e=w.useContext(uc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function ix(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 ax(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await ix(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const dc=120;function lx(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>dc?`${n.slice(0,dc-3)}…`:n:""}function fc(e){return lx(e.content)||""}function cx(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=fc(n);r&&t.set(n.id,r)}return t}function ux(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=fc(o);s&&t.set(r.checkpointId,s)}}return t}const dx={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Si(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 fx(e,t){return`${e??""}::${t??""}`}function hr(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(!Si(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=px(t),i=hc(r,0),a=mx(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function hc(e,t){if(!Si(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(R=>!!R&&typeof R=="object").map(R=>({...R})):a===null?null:void 0,u=r.map((R,D)=>kx(R,D)).filter(R=>!!R),d=$t(e.config),f=$t(d==null?void 0:d.configurable),h=ft(f,["checkpoint_id","checkpointId"]),p=ft(f,["checkpoint_ns","checkpointNs"]),y=$t(e==null?void 0:e.parentConfig),g=$t(y==null?void 0:y.configurable),v=ft(g,["checkpoint_id","checkpointId"])??null,x=ft(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,k=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),T=u.slice().reverse().find(R=>R.role==="user")??null,S=$t(e==null?void 0:e.metadata),C=ft(S,["branch_label","branchLabel"]),I=ft(g,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:u,checkpointId:h??null,checkpointNs:p??null,nextCursor:v,nextCursorNs:x,interrupt:hx(a,u,t),createdAt:k,parentId:I??null,branchLabel:C??null,lastUserMessageId:(T==null?void 0:T.id)??null,hasMessages:u.length>0,messagesLen:u.length,metadata:S??null,config:d??null,parentConfig:y??null,next:A??null,tasks:l??null,values:i??null}}function hx(e,t,n){const r=Sx(e,n);return r||wx(t,n)}function px(e){const t=new Map;e.forEach((o,s)=>{if(!Si(o))return;const i=hc(o,s);if(!(i!=null&&i.checkpointId))return;const a=fx(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,yx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>mc(s.createdAt??"")-mc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function mx(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ft(i,["label"])??ft(i,["branch_label","branchLabel"])??ft(i,["description"])??"User input",l=xx(i,["step"]),u=ft(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,h=o.lastUserMessageId??f,p=gx(o.next);t.push({id:s,label:a,messageId:h,step:l,source:u??null,createdAt:d,next:p??void 0,parentConfig:o.parentConfig??null})}return t}function gx(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 xx(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 yx(e,t){return{...e,metadata:Oo(e.metadata,t.metadata)??null,config:Oo(e.config,t.config)??null,parentConfig:Oo(e.parentConfig,t.parentConfig)??null,next:vx(e.next,t.next)??null,tasks:bx(e.tasks,t.tasks)??null,values:Oo(e.values,t.values)??null}}function Oo(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 vx(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 bx(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 wx(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 Sx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Cx(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=Fr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Fr(r.state,`${o}-state`);if(s)return s}}return null}function Cx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,u,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,y=typeof l=="string"&&l.trim()?l:Array.isArray(u)&&typeof u[0]=="string"?String(u[0]):"task",g=Array.isArray(d)?d:void 0,v=h.length?h[h.length-1]:void 0;return{id:p,name:y,interrupts:g,state:v!==void 0?v:f}}const n=$t(e);if(!n)return null;const r=ft(n,["id","thread_id","taskId"])??t,o=ft(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 Fr(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=pc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Fr(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=Fr(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 u=Fr(l,t,n+1,r);if(u)return u}}return null}function pc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ft(n,["type","event","kind"]),o=ft(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=pc(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 mc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function kx(e,t){if(!e||typeof e!="object")return null;const n=e,r=$t(e)??{},o=$t(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=dx[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}`,u=$t(o.additional_kwargs)??$t(o.additionalKwargs),d=$t(o.response_metadata)??$t(o.responseMetadata),f=ft(u,["createdAt","created_at"])??ft(o,["created_at","createdAt"]),h=ft(u,["checkpointId","checkpoint_id"]),p=ft(u,["checkpointNs","checkpoint_ns"]),y=Tx(o.content),g={id:l,role:i,content:y};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),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const v=Nx($t(o.artifact??r.artifact??o.artifacts??r.artifacts));v&&(g.artifact=v);const x=Mx(u,["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 k=Ix((u==null?void 0:u.tool_calls)??o.tool_calls);if(k.length&&(g.content=[...g.content,...k]),i==="tool"){const T=Ex(o,g.content);T&&(g.content=T)}return g}function Tx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>gc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=gc(e);return t?[t]:[]}return[]}function gc(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=ft(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=ft(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 xc(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=ft(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 xc(e,t){var s;const n=ft(e,["id","call_id"])??t,r=ft(e,["name"])??ft($t(e.function),["name"]);if(!n||!r)return null;const o=_x(e.args??e.arguments??((s=$t(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Ix(e){return Array.isArray(e)?e.map((t,n)=>xc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Ex(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 Nx(e){if(!e)return;const t=Ax(e.plots);return{...e,...t.length>0&&{plots:t}}}function Ax(e){return Array.isArray(e)?e.map(t=>jx(t)).filter(t=>!!t):[]}function jx(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 _x(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 $t(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Mx(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}const yc="aiNav:tool-progress";function Ci(){return typeof window<"u"&&typeof window.localStorage<"u"}function vc(e){return`${yc}:${e}`}function Rx(e,t,n){if(!Ci()||!e)return;const r=vc(e);if(!t.length){window.localStorage.removeItem(r);return}const o={messageId:e,entries:t,updatedAt:Date.now(),...n??{}};try{window.localStorage.setItem(r,JSON.stringify(o))}catch{}}function Px(e){if(!Ci()||!e)return;const t=vc(e),n=window.localStorage.getItem(t);if(n)try{const r=JSON.parse(n);return!(r!=null&&r.entries)||!Array.isArray(r.entries)?void 0:r.entries}catch{window.localStorage.removeItem(t);return}}function bc(){if(!Ci())return;const e=[];for(let t=0;t<window.localStorage.length;t+=1){const n=window.localStorage.key(t);n!=null&&n.startsWith(yc)&&e.push(n)}for(const t of e)window.localStorage.removeItem(t)}function Ox({api:e,seed:t,prepend:n,onError:r,currentThreadId:o,initialThreadId:s=null,initialCheckpointId:i=null,initialCheckpointNs:a=null,autoLoadInitial:l=!0,isStreaming:u,getMessages:d}){const[f,h]=w.useState([]),[p,y]=w.useState([]),[g,v]=w.useState(!1),[x,b]=w.useState(null),[k,T]=w.useState(!1),[S,C]=w.useState(!1),[I,A]=w.useState(!1),[R,D]=w.useState(null),B=w.useRef(o),X=w.useRef(null),G=w.useRef(null),M=w.useRef(null),U=w.useRef(null),E=w.useRef(!1),P=w.useRef(null),L=w.useRef(new Map);w.useEffect(()=>{B.current=o},[o]);const _=w.useCallback(async z=>{var Q,ge;if(!z.threadId)return;const ne=z.threadId;(Q=z.onStart)==null||Q.call(z),z.setLoading(!0);try{await z.action(ne)}catch(le){if(B.current===ne){const oe=String(le);(ge=z.handleError)==null||ge.call(z,oe),r==null||r(oe)}throw le}finally{z.setLoading(!1)}},[r]),q=w.useCallback(async(z,ne)=>{if(!z)return;const Q=`${z}:${ne??"latest"}`,ge=L.current.get(Q);if(ge)return ge;const le=_({threadId:z,setLoading:T,onStart:()=>D(null),handleError:oe=>D(oe),action:async oe=>{const pe=await e.getStateHistory({threadId:oe,checkpointId:ne??void 0});if(B.current!==oe){console.log(`[useThreadHistoryState] Thread changed during load (was ${oe}, now ${B.current}), discarding stale data`);return}const{checkpoints:be,timeline:Me}=hr(pe),Ie=be.find(De=>De.messages&&De.messages.length>0)??(ne?be.find(De=>De.checkpointId===ne):null)??be[0];t((Ie==null?void 0:Ie.messages)??[],{checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null}),y(Me),h(be),v(!!(Ie!=null&&Ie.nextCursor)),b((Ie==null?void 0:Ie.nextCursor)??null)}});L.current.set(Q,le);try{await le}finally{L.current.delete(Q)}return B.current===z&&(P.current=Q),le},[e,t,_]),Y=w.useCallback(async(z,ne,Q)=>{Q!=null&&Q.clearProgress&&bc(),U.current=z;try{await q(z,ne)}finally{U.current===z&&(U.current=null)}},[q]),j=w.useCallback(z=>{G.current=z},[]),J=w.useCallback(z=>{M.current=z},[]),V=w.useCallback(z=>{const ne=z.threadId??B.current;if(!ne||B.current&&B.current!==ne)return;const{checkpoints:Q,timeline:ge}=hr(z);if(!Q.length)return;const le=Q.find(oe=>oe.messages&&oe.messages.length>0)??Q.find(oe=>!!oe.checkpointId)??Q[0];t((le==null?void 0:le.messages)??[],{checkpointId:(le==null?void 0:le.checkpointId)??null,checkpointNs:(le==null?void 0:le.checkpointNs)??null}),y(ge),h(Q),v(!!(le!=null&&le.nextCursor)),b((le==null?void 0:le.nextCursor)??null),P.current=`${ne}:latest`,G.current=null,M.current=null},[t]),H=w.useCallback(async(z,ne)=>{bc();const Q=B.current;await _({threadId:Q,setLoading:A,action:async ge=>{const le=await e.getStateHistory({threadId:ge,checkpointId:z,checkpointNs:ne??void 0});if(B.current!==ge){console.log(`[useThreadHistoryState] Thread changed during checkpoint navigation (was ${ge}, now ${B.current}), discarding stale data`);return}const{checkpoints:oe,timeline:pe}=hr(le),be=oe.find(Me=>Me.checkpointId===z&&(ne?Me.checkpointNs===ne:!0));if(!be){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:z,checkpointNs:ne});return}y(pe),h(oe),t(be.messages??[],{checkpointId:be.checkpointId??null,checkpointNs:be.checkpointNs??null})}}).catch(()=>{})},[e,t,_]),ee=w.useCallback((z,ne)=>{t(d(),{checkpointId:z??null,checkpointNs:ne??null})},[d,t]),W=w.useCallback(async()=>{B.current&&await Y(B.current)},[Y]),O=w.useCallback(async()=>{const z=B.current;!z||!x||await _({threadId:z,setLoading:C,action:async ne=>{const Q=await e.getStateHistory({threadId:ne,checkpointId:x});if(B.current!==ne)return;const{checkpoints:ge}=hr(Q);if(ge.length>0){const le=ge[ge.length-1];n((le==null?void 0:le.messages)??[]),v(!!(le!=null&&le.nextCursor)),b((le==null?void 0:le.nextCursor)??null)}}}).catch(()=>{})},[e,x,r,n,_]);w.useEffect(()=>{if(!l||!o||k||u)return;if(G.current===o){G.current=null,X.current=o;return}if(M.current===o){X.current=o;return}if(U.current===o){U.current=null,X.current=o;return}if(X.current===o)return;X.current=o;const z=!E.current&&!!i&&o===s;let ne;z&&i?(ne=i,E.current=!0,console.log("[useThreadHistoryState] Loading thread with checkpoint:",ne,a?`(ns: ${a})`:"")):console.log("[useThreadHistoryState] Loading thread with latest checkpoint");const Q=`${o}:${ne??"latest"}`;P.current!==Q&&Y(o,ne)},[l,o,i,a,s,k,u,Y]);const K=w.useCallback(()=>{h([]),y([]),v(!1),b(null),T(!1),C(!1),A(!1),D(null),G.current=null,M.current=null,X.current=null,P.current=null,U.current=null},[]);return{threadCheckpoints:f,threadTimeline:p,isLoadingThread:k,isHistoryLoading:S,isLoadingCheckpoint:I,threadStateError:R,hasMoreHistory:g,loadThread:Y,navigateToCheckpoint:H,loadOlderMessages:O,setCurrentCheckpointId:ee,returnToLatest:W,handleStateHistoryEvent:V,markSkipNextLoad:j,markStreamPendingThread:J,resetHistoryState:K}}const Dx=["detail","message","error","description","title"];function Do(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Do(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of Dx){const r=Do(t[n]);if(r)return r}if("errors"in t){const n=Do(t.errors);if(n)return n}}return null}function Lx(e){if(!e)return"Request failed";const t=e.response,n=Do(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function $x({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=w.useState([]),[a,l]=w.useState(t),[u,d]=w.useState(!1),[f,h]=w.useState(null),[p,y]=w.useState([]),[g,v]=w.useState(!1),[,x]=w.useState(null),[b,k]=w.useState([]),[T,S]=w.useState(!1),[,C]=w.useState(null),[I,A]=w.useState(null),[R,D]=w.useState(!1),B=w.useRef(a),X=w.useRef(new Map);w.useEffect(()=>{B.current=a},[a]);const G=w.useCallback(async()=>{d(!0),h(null);try{const V=await e.listThreads();i(V??[])}catch(V){const H=String(V);h(H),n==null||n(H)}finally{d(!1)}},[e,n]),M=w.useCallback(async()=>{v(!0),x(null);try{const V=await e.listSharedThreads();y(V??[])}catch(V){const H=String(V);x(H),n==null||n(H)}finally{v(!1)}},[e,n]),U=w.useCallback(async()=>{S(!0),C(null);try{const V=await e.listSmartOrgUsers();k(V??[])}catch(V){const H=String(V);C(H),n==null||n(H)}finally{S(!1)}},[e,n]);w.useEffect(()=>{G(),U()},[U,G]),w.useEffect(()=>{M()},[M]),w.useEffect(()=>{r==null||r(a)},[a,r]);const E=w.useCallback(async V=>{try{const H=await e.createThread(V);return l(H.threadId),await G(),H.threadId}catch(H){const ee=String(H);return n==null||n(ee),null}},[e,n,G]),P=w.useCallback(async V=>{const H=s;i(W=>W.filter(O=>O.threadId!==V));const ee=new AbortController;X.current.set(V,ee);try{await e.deleteThread(V),B.current===V&&(l(null),o==null||o())}catch(W){i(H);const O=String(W);n==null||n(O)}finally{X.current.delete(V)}},[e,o,n,s]),L=w.useCallback(async(V,H)=>{try{await e.updateThread(V,H),await G()}catch(ee){n==null||n(String(ee))}},[e,n,G]),_=w.useCallback(async(V,H)=>{D(!0),A("Sharing thread…");try{await e.shareThread(V,H),await M(),A("Shared successfully")}catch(ee){const W=Lx(ee);throw n==null||n(W),A(`Failed to share: ${W}`),new Error(W)}finally{D(!1)}},[e,n,M]),q=w.useCallback(async(V,H)=>{try{await e.unshareThread(V,H),await M()}catch(ee){const W=String(ee);throw n==null||n(W),ee}},[e,n,M]),Y=w.useMemo(()=>({createThread:E,deleteThread:P,renameThread:L,refreshThreads:G,refreshSharedThreads:M,refreshSmartOrgUsers:U,shareThread:_,unshareThread:q}),[E,P,L,G,M,U,_,q]),j=w.useCallback(V=>{if(!(V!=null&&V.threadId))return;const H={threadId:V.threadId,title:V.title||`Thread ${V.threadId.slice(0,8)}`,createdAt:V.createdAt||new Date().toISOString(),updatedAt:V.updatedAt||new Date().toISOString(),messageCount:V.messageCount??1};i(ee=>{let W=!1;const O=ee.map(K=>K.threadId===H.threadId?(W=!0,console.debug("[useThreadsState] thread_info: updating existing thread",H.threadId),{...K,title:H.title??K.title,updatedAt:H.updatedAt??K.updatedAt,messageCount:H.messageCount??K.messageCount}):K);return W?O:(console.debug("[useThreadsState] thread_info: adding thread to list",H.threadId),[H,...ee])})},[]),J=w.useCallback(()=>A(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:B,setCurrentThreadId:l,isLoadingThreads:u,threadsError:f,sharedThreads:p,isLoadingSharedThreads:g,smartOrgUsers:b,isLoadingSmartOrgUsers:T,actions:Y,addThreadFromEvent:j,shareInFlight:R,shareStatus:I,clearShareStatus:J}}const Nt=[];for(let e=0;e<256;++e)Nt.push((e+256).toString(16).slice(1));function Fx(e,t=0){return(Nt[e[t+0]]+Nt[e[t+1]]+Nt[e[t+2]]+Nt[e[t+3]]+"-"+Nt[e[t+4]]+Nt[e[t+5]]+"-"+Nt[e[t+6]]+Nt[e[t+7]]+"-"+Nt[e[t+8]]+Nt[e[t+9]]+"-"+Nt[e[t+10]]+Nt[e[t+11]]+Nt[e[t+12]]+Nt[e[t+13]]+Nt[e[t+14]]+Nt[e[t+15]]).toLowerCase()}let ki;const Bx=new Uint8Array(16);function zx(){if(!ki){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ki=crypto.getRandomValues.bind(crypto)}return ki(Bx)}const wc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ux(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??zx();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,Fx(r)}function Hx(e,t,n){return wc.randomUUID&&!e?wc.randomUUID():Ux(e)}function Ti(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 Lo(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Sc(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 Cc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function kc(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 Wx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Jx(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 Vx(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 $o(e,t,n){const r=e.findIndex(u=>u.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:Hx(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),Rx(o.id,a,{checkpointId:o.checkpointId??null,checkpointNs:o.checkpointNs??null}),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function Ic(e,t){return e.includes(t)?e:[...e,t]}function Kx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function pr(e,t){let n=!1;const r={},o=e.map(s=>{const i=Zx(s);if(i.length)return r[s.id]=i,s;const a=t[s.id]??Px(s.id);if(a!=null&&a.length){const l=[...a];r[s.id]=l,n=!0;const u={...s.additionalKwargs??{},toolProgress:l};return{...s,additionalKwargs:u}}return s});return{messages:n?o:e,toolTimelines:r}}function Ec(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function qx(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??Ec(e);let l="",u=e.slice();if(s){const f=Gx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",y={...h,text:p+l};u=[...u.slice(0,u.length-1),y]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function Nc(e){return e.replace(/\s+/g," ").trim()}function Gx(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=Nc(e),o=Nc(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 Yx(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 Lo(e,r,s)}return e}function Xx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Jx(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 Zx(e){const t=e.additionalKwargs??{};return Array.isArray(t.toolProgress)?[...t.toolProgress]:[]}const Qx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],messagesStreamMeta:{},pendingInterrupt:null,toolTimelines:{}};function ey(e,t){var n;switch(t.type){case"reset":return{messages:Ti(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],pendingInterrupt:null,toolTimelines:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r]}}}return{...e,messages:[...e.messages,r]}}case"seed":{const r=Ti(t.payload.messages),{messages:o,toolTimelines:s}=pr(r,e.toolTimelines),i={...e,messages:o,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[],toolTimelines:s};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(i.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(i.lastCheckpointNs=t.payload.checkpointNs??null),i}case"prepend":{const r=Ti(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(u=>u.id)),s=r.filter(u=>!o.has(u.id));if(!s.length)return e;const i=[...s,...e.messages],{messages:a,toolTimelines:l}=pr(i,e.toolTimelines);return{...e,messages:a,toolTimelines:l}}case"event":return jc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>jc(o,s),e):e}case"interrupt_response":return{...e,messages:Sc(e.messages),pendingInterrupt:null};default:return e}}function Ac(e=[]){const[t,n]=w.useReducer(ey,{...Qx,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 u=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,f)=>n({type:"user_message",payload:{message:d,editingMessageId:f}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function jc(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=Xx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message.delta"){const i=e.assemblingId??Cc(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(k=>k.id===i&&k.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Ec(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:y,changed:g}=qx(u.content,t.delta,f,h);if(!g)return e;const v={...u,content:p},x=Lo(a,l,v),b={...d,[i]:y};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??Cc(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=kc(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 u=i.length?i:a?[a]:[],d=u[0]??`${l}-${Date.now()}`,f={type:"tool_call",id:d,name:l,args:t.args},h={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,metadata:{args:t.args}},p=e.toolStreamingMessageId;if(!p){const b={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...Vx(void 0,u.length?u:[d],l,t.args),toolStreaming:!0}},k=Wx(b,u.length?u:[d]),T=[...e.messages,b],S=$o(T,b.id,h),{messages:C,toolTimelines:I}=pr(S,e.toolTimelines);return{...e,messages:C,toolIndex:Tc(e.toolIndex,b.id,k),toolStreamingMessageId:b.id,toolStreamingStack:Ic(e.toolStreamingStack??[],a??d),toolTimelines:I}}const y=$o(e.messages,p,h),{messages:g,toolTimelines:v}=pr(y,e.toolTimelines);return{...e,messages:g,toolIndex:Tc(e.toolIndex,p,u),toolStreamingStack:Ic(e.toolStreamingStack??[],a??d),toolTimelines:v}}if(t.type==="tool.end"){const i=kc(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??[],u=l[0]??null,d=Kx(l,a),f=d[0]?e.toolIndex[d[0]]:null,h=e.toolStreamingMessageId,p=u===a,y=t.name??((s=e.messages.find(S=>S.id===h))==null?void 0:s.name)??"tool",g=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),v={type:"tool.end",toolId:a,toolName:y,content:g==null?void 0:g.slice(0,200)};let x=e.messages;if(h&&(x=$o(x,h,v)),p&&h){const S=x.findIndex(C=>C.id===h);if(S>=0){const C=x[S],A={type:"text",text:(()=>{if(typeof t.output=="string"){const D=t.output.trim();try{return D}catch{return D}}return JSON.stringify(t.output??"")})()},R={...C,content:[A],artifact:t.artifact??C.artifact,additionalKwargs:{...C.additionalKwargs??{}}};x=Lo(x,S,R)}}const b=d,{messages:k,toolTimelines:T}=pr(x,e.toolTimelines);return{...e,messages:k,toolTimelines:T,toolStreamingMessageId:p?f:h,toolStreamingStack:b}}if(t.type==="tool.progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"tool.progress",content:t.content??null},l=$o(e.messages,i,a),u=l.findIndex(v=>v.id===i);if(u===-1)return e;const d=l[u],f={...d.additionalKwargs??{},toolStreaming:!0},h={...d,additionalKwargs:f},p=Lo(l,u,h),{messages:y,toolTimelines:g}=pr(p,e.toolTimelines);return{...e,messages:y,toolTimelines:g}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Yx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}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=hr(t),a=i.interrupt,l=i.latest,u=a===null?Sc(e.messages):e.messages;return{...e,messages:u,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 _c(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),[u,d]=w.useState(null),[f,h]=w.useState(""),[p,y]=w.useState(null),[g,v]=w.useState(0),[x,b]=w.useState(!1),k=w.useRef(null),T=w.useRef(!0),S=w.useRef(0),C=w.useRef(null),I=w.useRef(null),A=w.useRef(null),R=w.useRef(null),D=w.useCallback(M=>{o(M)},[]),B=w.useCallback(()=>{h(""),y(null),d(null),I.current=null,A.current=null,R.current=null},[]),X=w.useCallback(()=>{var M;console.debug("[use-chat] stop() invoked - aborting stream"),(M=k.current)==null||M.abort(),k.current=null,C.current=null,l(!1),b(!1),S.current=0,v(0)},[]),G=w.useCallback((M,U,E)=>{k.current&&(k.current.abort(),k.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),y(null),I.current=null,A.current=null,R.current=null;const P=new AbortController;k.current=P;let L=null,_=null,q=!1;return C.current={threadId:M.threadId??null,headers:{}},(async()=>{var j,J,V,H,ee,W,O,K,z,ne,Q,ge,le,oe,pe,be,Me,Ie;const Y=De=>{var et;try{const rt=JSON.parse(JSON.stringify(De));return(et=rt==null?void 0:rt.payload)!=null&&et.files_info&&Array.isArray(rt.payload.files_info)&&(rt.payload.files_info=rt.payload.files_info.map(He=>({...He,data:He!=null&&He.data?`<base64 ${String(He.data).length} chars>`:He==null?void 0:He.data}))),rt}catch{return De}};try{let De={};try{if(r)De={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Be=window.__AUTH_TOKEN__,lt=((j=window.localStorage)==null?void 0:j.getItem("authToken"))||null;let Et=null;try{const Z=(J=window.localStorage)==null?void 0:J.getItem("chat-settings");Z&&(Et=((V=JSON.parse(Z))==null?void 0:V.apiKey)||null)}catch{}const qe=Be||lt||Et||null;qe&&(De={Authorization:`Bearer ${qe}`})}}catch{}console.debug("[use-chat] POST",t+n,Y(M));let et={};if(typeof window<"u")try{const Ge=(H=window.localStorage)==null?void 0:H.getItem("authSessionId");Ge&&(et={"X-Session-Id":Ge})}catch{}const rt={...De,...et,...s.current},He={"Content-Type":"application/json",Accept:"text/event-stream",...rt},Je=await fetch(t+n,{method:"POST",headers:He,body:JSON.stringify(M),signal:P.signal,credentials:i});if(C.current&&(C.current.headers=rt),!Je.ok||!Je.body){const Ge=await Je.text().catch(()=>"");console.debug("[use-chat] non-OK response",Je.status,Ge==null?void 0:Ge.slice(0,500));const Be=`stream ${Je.status}${Ge?": "+Ge:""}`;throw(ee=E==null?void 0:E.onConnectionError)==null||ee.call(E,Be),q=!0,L="error",_=Be,new Error(Be)}b(!0);const ot=Je.body.getReader(),St=new TextDecoder;let dt="",Tt=[];S.current=0,v(0);let mt=0,Ee=null;const Ke=()=>{if(Tt.length){const Ge=Tt.join("");Tt=[],T.current&&h(Be=>Be+Ge)}Ee=null},xt=()=>{typeof window<"u"&&Ee==null&&(Ee=requestAnimationFrame(Ke))};let It=Date.now();const Le=setInterval(()=>{var Ge;if(Date.now()-It>18e5){const Be="Stream idle timeout";d(Be),L="error",_=Be,P.abort(),(Ge=E==null?void 0:E.onError)==null||Ge.call(E,Be)}},5e3),_t=1024*1024;try{const Ge=Je.headers.get("X-Thread-Id")||Je.headers.get("x-thread-id"),Be=Je.headers.get("X-Thread-Created")||Je.headers.get("x-thread-created"),lt=Ge??null,Et=String(Be??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:lt}),(W=E==null?void 0:E.onOpen)==null||W.call(E,{threadId:lt,created:Et});;){const{value:qe,done:Z}=await ot.read();if(Z)break;dt+=St.decode(qe,{stream:!0}),dt.length>_t&&(dt="",console.warn("Stream buffer reset: exceeded 1MB"));let $;for(;($=dt.indexOf(`
34
+ `):" "+Zl(i[0]):"as no adapter specified";throw new _e("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:gi};function xi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dr(null,e)}function ec(e){return xi(e),e.headers=Ut.from(e.headers),e.data=mi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ql.getAdapter(e.adapter||Dr.adapter,e)(e).then(function(r){return xi(e),r.data=mi.call(e,e.transformResponse,r),r.headers=Ut.from(r.headers),r},function(r){return Fl(r)||(xi(e),r&&r.response&&(r.response.data=mi.call(e,e.transformResponse,r.response),r.response.headers=Ut.from(r.response.headers))),Promise.reject(r)})}const tc="1.12.2",jo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{jo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const nc={};jo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+tc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new _e(o(i," has been removed"+(n?" in "+n:"")),_e.ERR_DEPRECATED);return n&&!nc[i]&&(nc[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}},jo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Qg(e,t,n){if(typeof e!="object")throw new _e("options must be an object",_e.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new _e("option "+s+" must be "+l,_e.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new _e("Unknown option "+s,_e.ERR_BAD_OPTION)}}const _o={assertOptions:Qg,validators:jo},hn=_o.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Ol,response:new Ol}}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&&_o.assertOptions(r,{silentJSONParsing:hn.transitional(hn.boolean),forcedJSONParsing:hn.transitional(hn.boolean),clarifyTimeoutError:hn.transitional(hn.boolean)},!1),o!=null&&(F.isFunction(o)?n.paramsSerializer={serialize:o}:_o.assertOptions(o,{encode:hn.function,serialize:hn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),_o.assertOptions(n,{baseUrl:hn.spelling("baseURL"),withXsrfToken:hn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&F.merge(s.common,s[n.method]);s&&F.forEach(["delete","get","head","post","put","patch","common"],y=>{delete s[y]}),n.headers=Ut.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 u=[];this.interceptors.response.forEach(function(g){u.push(g.fulfilled,g.rejected)});let d,f=0,h;if(!l){const y=[ec.bind(this),void 0];for(y.unshift(...a),y.push(...u),h=y.length,d=Promise.resolve(n);f<h;)d=d.then(y[f++],y[f++]);return d}h=a.length;let p=n;for(;f<h;){const y=a[f++],g=a[f++];try{p=y(p)}catch(v){g.call(this,v);break}}try{d=ec.call(this,p)}catch(y){return Promise.reject(y)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=Hl(t.baseURL,t.url,t.allowAbsoluteUrls);return Pl(n,t.params,t.paramsSerializer)}};F.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}))}}),F.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 ex=class jm{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 jm(function(o){t=o}),cancel:t}}};function tx(e){return function(n){return e.apply(null,n)}}function nx(e){return F.isObject(e)&&e.isAxiosError===!0}const yi={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(yi).forEach(([e,t])=>{yi[t]=e});function rc(e){const t=new qn(e),n=vl(qn.prototype.request,t);return F.extend(n,qn.prototype,t,{allOwnKeys:!0}),F.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return rc(Kn(e,o))},n}const yt=rc(Dr);yt.Axios=qn,yt.CanceledError=dr,yt.CancelToken=ex,yt.isCancel=Fl,yt.VERSION=tc,yt.toFormData=Eo,yt.AxiosError=_e,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=tx,yt.isAxiosError=nx,yt.mergeConfig=Kn,yt.AxiosHeaders=Ut,yt.formToJSON=e=>Ll(F.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Ql.getAdapter,yt.HttpStatusCode=yi,yt.default=yt;const{Axios:lE,AxiosError:cE,CanceledError:uE,isCancel:dE,CancelToken:fE,VERSION:hE,all:pE,Cancel:mE,isAxiosError:gE,spread:xE,toFormData:yE,AxiosHeaders:vE,HttpStatusCode:bE,formToJSON:wE,getAdapter:SE,mergeConfig:CE}=yt,oc=typeof window<"u"?window.__API_BASE_URL__:void 0,sc=oc?Cn(oc):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 Mo=null;const vi=new Set;function ic(){return Mo}function Ro(e){Mo=e,vi.forEach(t=>t(e))}function ac(e){return vi.add(e),()=>vi.delete(e)}const rx=3e4,ox=9e4,Jt=yt.create({...sc?{baseURL:sc}:{},timeout:rx,withCredentials:!0});Jt.interceptors.request.use(e=>(Mo&&(e.headers.Authorization=`Bearer ${Mo}`),e)),Jt.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),Ro(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 Kt(e,t){return Jt.defaults.baseURL?(await Jt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Po(e,t,n){return Jt.defaults.baseURL?(await Jt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function lc(e,t,n){return Jt.defaults.baseURL?(await Jt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function bi(e,t){return Jt.defaults.baseURL?(await Jt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Dt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class cc{get baseUrl(){const t=Jt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(Jt.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&Ro(t.authToken)}getAuthToken(){return ic()}setAuthToken(t){Ro(t)}onTokenChange(t){return ac(t)}async listThreads(){const t=await Kt("/threads"),n=Dt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Kt("/threads/shared"),n=Dt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Po("/threads",t?{title:t}:void 0);return Dt(r)}async updateThread(t,n){const r=await lc(`/threads/${t}`,{title:n});return Dt(r)}async deleteThread(t){const n=await bi(`/threads/${t}`);return Dt(n)}async shareThread(t,n){const r=await Po(`/threads/${t}/share`,{shared_with_user_id:n});return Dt(r)}async threadInfo(t){const n=await Kt(`/threads/${t}/info`);return Dt(n)}async listAgents(){const t=await Kt("/agents"),n=Dt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Kt(`/agents/${t}`);return Dt(n)}async getAgentSchema(t){const n=await Kt(`/agents/${t}/schema`);return Dt(n)}async getState(t){const n=await Kt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Dt(n)}async getStateHistory(t){const n=await Kt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:ox});return Dt(n)}async cancelRun(t){const n=await Po("/runs/cancel",{threadId:t});return Dt(n)}async listCheckpointSummaries(t){const n=await Kt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Dt(n);return(r==null?void 0:r.items)??[]}async unshareThread(t,n){const r=await bi(`/threads/${t}/share/${n}`);return Dt(r)}}const Nn=new cc,uc=w.createContext(null);function sx({children:e,apiConfig:t}){const n=Nn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(uc.Provider,{value:r,children:e})}function wi(){const e=w.useContext(uc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function ix(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 ax(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await ix(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const dc=120;function lx(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>dc?`${n.slice(0,dc-3)}…`:n:""}function fc(e){return lx(e.content)||""}function cx(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const r=fc(n);r&&t.set(n.id,r)}return t}function ux(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=fc(o);s&&t.set(r.checkpointId,s)}}return t}const dx={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Si(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 fx(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(!Si(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=px(t),i=hc(r,0),a=mx(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function hc(e,t){if(!Si(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(P=>!!P&&typeof P=="object").map(P=>({...P})):a===null?null:void 0,u=r.map((P,$)=>Tx(P,$)).filter(P=>!!P),d=Lt(e.config),f=Lt(d==null?void 0:d.configurable),h=ft(f,["checkpoint_id","checkpointId"]),p=ft(f,["checkpoint_ns","checkpointNs"]),y=Lt(e==null?void 0:e.parentConfig),g=Lt(y==null?void 0:y.configurable),v=ft(g,["checkpoint_id","checkpointId"])??null,x=ft(g,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,C=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=u.slice().reverse().find(P=>P.role==="user")??null,S=Lt(e==null?void 0:e.metadata),T=ft(S,["branch_label","branchLabel"]),E=ft(g,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:u,checkpointId:h??null,checkpointNs:p??null,nextCursor:v,nextCursorNs:x,interrupt:hx(a,u,t),createdAt:C,parentId:E??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:u.length>0,messagesLen:u.length,metadata:S??null,config:d??null,parentConfig:y??null,next:A??null,tasks:l??null,values:i??null}}function hx(e,t,n){const r=Sx(e,n);return r||wx(t,n)}function px(e){const t=new Map;e.forEach((o,s)=>{if(!Si(o))return;const i=hc(o,s);if(!(i!=null&&i.checkpointId))return;const a=fx(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,yx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>mc(s.createdAt??"")-mc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function mx(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ft(i,["label"])??ft(i,["branch_label","branchLabel"])??ft(i,["description"])??"User input",l=xx(i,["step"]),u=ft(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,h=o.lastUserMessageId??f,p=gx(o.next);t.push({id:s,label:a,messageId:h,step:l,source:u??null,createdAt:d,next:p??void 0,parentConfig:o.parentConfig??null})}return t}function gx(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 xx(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 yx(e,t){return{...e,metadata:Oo(e.metadata,t.metadata)??null,config:Oo(e.config,t.config)??null,parentConfig:Oo(e.parentConfig,t.parentConfig)??null,next:vx(e.next,t.next)??null,tasks:bx(e.tasks,t.tasks)??null,values:Oo(e.values,t.values)??null}}function Oo(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 vx(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 bx(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 wx(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 Sx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Cx(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=$r(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=$r(r.state,`${o}-state`);if(s)return s}}return null}function Cx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,u,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,y=typeof l=="string"&&l.trim()?l:Array.isArray(u)&&typeof u[0]=="string"?String(u[0]):"task",g=Array.isArray(d)?d:void 0,v=h.length?h[h.length-1]:void 0;return{id:p,name:y,interrupts:g,state:v!==void 0?v:f}}const n=Lt(e);if(!n)return null;const r=ft(n,["id","thread_id","taskId"])??t,o=ft(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 $r(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=pc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=$r(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=$r(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 u=$r(l,t,n+1,r);if(u)return u}}return null}function pc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ft(n,["type","event","kind"]),o=ft(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=pc(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 mc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Tx(e,t){if(!e||typeof e!="object")return null;const n=e,r=Lt(e)??{},o=Lt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=dx[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}`,u=Lt(o.additional_kwargs)??Lt(o.additionalKwargs),d=Lt(o.response_metadata)??Lt(o.responseMetadata),f=ft(u,["createdAt","created_at"])??ft(o,["created_at","createdAt"]),h=ft(u,["checkpointId","checkpoint_id"]),p=ft(u,["checkpointNs","checkpoint_ns"]),y=kx(o.content),g={id:l,role:i,content:y};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),h&&(g.checkpointId=h),p&&(g.checkpointNs=p);const v=Nx(Lt(o.artifact??r.artifact??o.artifacts??r.artifacts));v&&(g.artifact=v);const x=d?{...d}:void 0;x&&Object.keys(x).length&&(g.responseMetadata=x);const b=Ex((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(g.content=[...g.content,...b]),i==="tool"){const C=Ix(o,g.content);C&&(g.content=C)}return g}function kx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>gc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=gc(e);return t?[t]:[]}return[]}function gc(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=ft(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=ft(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 xc(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=ft(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 xc(e,t){var s;const n=ft(e,["id","call_id"])??t,r=ft(e,["name"])??ft(Lt(e.function),["name"]);if(!n||!r)return null;const o=_x(e.args??e.arguments??((s=Lt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Ex(e){return Array.isArray(e)?e.map((t,n)=>xc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Ix(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 Nx(e){if(!e)return;const t=Ax(e.plots);return{...e,...t.length>0&&{plots:t}}}function Ax(e){return Array.isArray(e)?e.map(t=>jx(t)).filter(t=>!!t):[]}function jx(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 _x(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 Lt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}const yc="aiNav:tool-progress";function Ci(){return typeof window<"u"&&typeof window.localStorage<"u"}function vc(e){return`${yc}:${e}`}function Mx(e,t,n){if(!Ci()||!e)return;const r=vc(e);if(!t.length){window.localStorage.removeItem(r);return}const o={messageId:e,entries:t,updatedAt:Date.now(),...n??{}};try{window.localStorage.setItem(r,JSON.stringify(o))}catch{}}function Rx(e){if(!Ci()||!e)return;const t=vc(e),n=window.localStorage.getItem(t);if(n)try{const r=JSON.parse(n);return!(r!=null&&r.entries)||!Array.isArray(r.entries)?void 0:r.entries}catch{window.localStorage.removeItem(t);return}}function bc(){if(!Ci())return;const e=[];for(let t=0;t<window.localStorage.length;t+=1){const n=window.localStorage.key(t);n!=null&&n.startsWith(yc)&&e.push(n)}for(const t of e)window.localStorage.removeItem(t)}function Px({api:e,seed:t,prepend:n,onError:r,currentThreadId:o,initialThreadId:s=null,initialCheckpointId:i=null,initialCheckpointNs:a=null,autoLoadInitial:l=!0,isStreaming:u,getMessages:d}){const[f,h]=w.useState([]),[p,y]=w.useState([]),[g,v]=w.useState(!1),[x,b]=w.useState(null),[C,k]=w.useState(!1),[S,T]=w.useState(!1),[E,A]=w.useState(!1),[P,$]=w.useState(null),B=w.useRef(o),V=w.useRef(null),G=w.useRef(null),O=w.useRef(null),U=w.useRef(null),N=w.useRef(!1),D=w.useRef(null),M=w.useRef(new Map);w.useEffect(()=>{B.current=o},[o]);const j=w.useCallback(async z=>{var X,ge;if(!z.threadId)return;const Z=z.threadId;(X=z.onStart)==null||X.call(z),z.setLoading(!0);try{await z.action(Z)}catch(le){if(B.current===Z){const te=String(le);(ge=z.handleError)==null||ge.call(z,te),r==null||r(te)}throw le}finally{z.setLoading(!1)}},[r]),H=w.useCallback(async(z,Z)=>{if(!z)return;const X=`${z}:${Z??"latest"}`,ge=M.current.get(X);if(ge)return ge;const le=j({threadId:z,setLoading:k,onStart:()=>$(null),handleError:te=>$(te),action:async te=>{const fe=await e.getStateHistory({threadId:te,checkpointId:Z??void 0});if(B.current!==te){console.log(`[useThreadHistoryState] Thread changed during load (was ${te}, now ${B.current}), discarding stale data`);return}const{checkpoints:ye,timeline:Me}=fr(fe),Ne=ye.find($e=>$e.messages&&$e.messages.length>0)??(Z?ye.find($e=>$e.checkpointId===Z):null)??ye[0];t((Ne==null?void 0:Ne.messages)??[],{checkpointId:(Ne==null?void 0:Ne.checkpointId)??null,checkpointNs:(Ne==null?void 0:Ne.checkpointNs)??null}),y(Me),h(ye),v(!!(Ne!=null&&Ne.nextCursor)),b((Ne==null?void 0:Ne.nextCursor)??null)}});M.current.set(X,le);try{await le}finally{M.current.delete(X)}return B.current===z&&(D.current=X),le},[e,t,j]),W=w.useCallback(async(z,Z,X)=>{X!=null&&X.clearProgress&&bc(),U.current=z;try{await H(z,Z)}finally{U.current===z&&(U.current=null)}},[H]),R=w.useCallback(z=>{G.current=z},[]),K=w.useCallback(z=>{O.current=z},[]),ie=w.useCallback(z=>{const Z=z.threadId??B.current;if(!Z||B.current&&B.current!==Z)return;const{checkpoints:X,timeline:ge}=fr(z);if(!X.length)return;const le=X.find(te=>te.messages&&te.messages.length>0)??X.find(te=>!!te.checkpointId)??X[0];t((le==null?void 0:le.messages)??[],{checkpointId:(le==null?void 0:le.checkpointId)??null,checkpointNs:(le==null?void 0:le.checkpointNs)??null}),y(ge),h(X),v(!!(le!=null&&le.nextCursor)),b((le==null?void 0:le.nextCursor)??null),D.current=`${Z}:latest`,G.current=null,O.current=null},[t]),Q=w.useCallback(async(z,Z)=>{bc();const X=B.current;await j({threadId:X,setLoading:A,action:async ge=>{const le=await e.getStateHistory({threadId:ge,checkpointId:z,checkpointNs:Z??void 0});if(B.current!==ge){console.log(`[useThreadHistoryState] Thread changed during checkpoint navigation (was ${ge}, now ${B.current}), discarding stale data`);return}const{checkpoints:te,timeline:fe}=fr(le),ye=te.find(Me=>Me.checkpointId===z&&(Z?Me.checkpointNs===Z:!0));if(!ye){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:z,checkpointNs:Z});return}y(fe),h(te),t(ye.messages??[],{checkpointId:ye.checkpointId??null,checkpointNs:ye.checkpointNs??null})}}).catch(()=>{})},[e,t,j]),oe=w.useCallback((z,Z)=>{t(d(),{checkpointId:z??null,checkpointNs:Z??null})},[d,t]),Y=w.useCallback(async()=>{B.current&&await W(B.current)},[W]),L=w.useCallback(async()=>{const z=B.current;!z||!x||await j({threadId:z,setLoading:T,action:async Z=>{const X=await e.getStateHistory({threadId:Z,checkpointId:x});if(B.current!==Z)return;const{checkpoints:ge}=fr(X);if(ge.length>0){const le=ge[ge.length-1];n((le==null?void 0:le.messages)??[]),v(!!(le!=null&&le.nextCursor)),b((le==null?void 0:le.nextCursor)??null)}}}).catch(()=>{})},[e,x,r,n,j]);w.useEffect(()=>{if(!l||!o||C||u)return;if(G.current===o){G.current=null,V.current=o;return}if(O.current===o){V.current=o;return}if(U.current===o){U.current=null,V.current=o;return}if(V.current===o)return;V.current=o;const z=!N.current&&!!i&&o===s;let Z;z&&i?(Z=i,N.current=!0,console.log("[useThreadHistoryState] Loading thread with checkpoint:",Z,a?`(ns: ${a})`:"")):console.log("[useThreadHistoryState] Loading thread with latest checkpoint");const X=`${o}:${Z??"latest"}`;D.current!==X&&W(o,Z)},[l,o,i,a,s,C,u,W]);const q=w.useCallback(()=>{h([]),y([]),v(!1),b(null),k(!1),T(!1),A(!1),$(null),G.current=null,O.current=null,V.current=null,D.current=null,U.current=null},[]);return{threadCheckpoints:f,threadTimeline:p,isLoadingThread:C,isHistoryLoading:S,isLoadingCheckpoint:E,threadStateError:P,hasMoreHistory:g,loadThread:W,navigateToCheckpoint:Q,loadOlderMessages:L,setCurrentCheckpointId:oe,returnToLatest:Y,handleStateHistoryEvent:ie,markSkipNextLoad:R,markStreamPendingThread:K,resetHistoryState:q}}const Ox=["detail","message","error","description","title"];function Do(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Do(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of Ox){const r=Do(t[n]);if(r)return r}if("errors"in t){const n=Do(t.errors);if(n)return n}}return null}function Dx(e){if(!e)return"Request failed";const t=e.response,n=Do(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function Lx({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=w.useState([]),[a,l]=w.useState(t),[u,d]=w.useState(!1),[f,h]=w.useState(null),[p,y]=w.useState([]),[g,v]=w.useState(!1),[,x]=w.useState(null),[b,C]=w.useState(null),[k,S]=w.useState(!1),T=w.useRef(a),E=w.useRef(new Map);w.useEffect(()=>{T.current=a},[a]);const A=w.useCallback(async()=>{d(!0),h(null);try{const M=await e.listThreads();i(M??[])}catch(M){const j=String(M);h(j),n==null||n(j)}finally{d(!1)}},[e,n]),P=w.useCallback(async()=>{v(!0),x(null);try{const M=await e.listSharedThreads();y(M??[])}catch(M){const j=String(M);x(j),n==null||n(j)}finally{v(!1)}},[e,n]);w.useEffect(()=>{A()},[A]),w.useEffect(()=>{P()},[P]),w.useEffect(()=>{r==null||r(a)},[a,r]);const $=w.useCallback(async M=>{try{const j=await e.createThread(M);return l(j.threadId),await A(),j.threadId}catch(j){const H=String(j);return n==null||n(H),null}},[e,n,A]),B=w.useCallback(async M=>{const j=s;i(W=>W.filter(R=>R.threadId!==M));const H=new AbortController;E.current.set(M,H);try{await e.deleteThread(M),T.current===M&&(l(null),o==null||o())}catch(W){i(j);const R=String(W);n==null||n(R)}finally{E.current.delete(M)}},[e,o,n,s]),V=w.useCallback(async(M,j)=>{try{await e.updateThread(M,j),await A()}catch(H){n==null||n(String(H))}},[e,n,A]),G=w.useCallback(async(M,j)=>{S(!0),C("Sharing thread…");try{await e.shareThread(M,j),await P(),C("Shared successfully")}catch(H){const W=Dx(H);throw n==null||n(W),C(`Failed to share: ${W}`),new Error(W)}finally{S(!1)}},[e,n,P]),O=w.useCallback(async(M,j)=>{try{await e.unshareThread(M,j),await P()}catch(H){const W=String(H);throw n==null||n(W),H}},[e,n,P]),U=w.useMemo(()=>({createThread:$,deleteThread:B,renameThread:V,refreshThreads:A,refreshSharedThreads:P,shareThread:G,unshareThread:O}),[$,B,V,A,P,G,O]),N=w.useCallback(M=>{if(!(M!=null&&M.threadId))return;const j={threadId:M.threadId,title:M.title||`Thread ${M.threadId.slice(0,8)}`,createdAt:M.createdAt||new Date().toISOString(),updatedAt:M.updatedAt||new Date().toISOString(),messageCount:M.messageCount??1};i(H=>{let W=!1;const R=H.map(K=>K.threadId===j.threadId?(W=!0,console.debug("[useThreadsState] thread_info: updating existing thread",j.threadId),{...K,title:j.title??K.title,updatedAt:j.updatedAt??K.updatedAt,messageCount:j.messageCount??K.messageCount}):K);return W?R:(console.debug("[useThreadsState] thread_info: adding thread to list",j.threadId),[j,...H])})},[]),D=w.useCallback(()=>C(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:T,setCurrentThreadId:l,isLoadingThreads:u,threadsError:f,sharedThreads:p,isLoadingSharedThreads:g,actions:U,addThreadFromEvent:N,shareInFlight:k,shareStatus:b,clearShareStatus:D}}const It=[];for(let e=0;e<256;++e)It.push((e+256).toString(16).slice(1));function $x(e,t=0){return(It[e[t+0]]+It[e[t+1]]+It[e[t+2]]+It[e[t+3]]+"-"+It[e[t+4]]+It[e[t+5]]+"-"+It[e[t+6]]+It[e[t+7]]+"-"+It[e[t+8]]+It[e[t+9]]+"-"+It[e[t+10]]+It[e[t+11]]+It[e[t+12]]+It[e[t+13]]+It[e[t+14]]+It[e[t+15]]).toLowerCase()}let Ti;const Fx=new Uint8Array(16);function Bx(){if(!Ti){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ti=crypto.getRandomValues.bind(crypto)}return Ti(Fx)}const wc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function zx(e,t,n){var o;e=e||{};const r=e.random??((o=e.rng)==null?void 0:o.call(e))??Bx();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,$x(r)}function Ux(e,t,n){return wc.randomUUID&&!e?wc.randomUUID():zx(e)}function ki(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 Lo(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Sc(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 Cc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Tc(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 Hx(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Xx(e);for(const o of r)n.add(o);return Array.from(n)}function kc(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 Wx(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 $o(e,t,n){const r=e.findIndex(u=>u.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:Ux(),idx:a.length+1,timestamp:new Date().toISOString(),...n};return a.push(l),Mx(o.id,a,{checkpointId:o.checkpointId??null,checkpointNs:o.checkpointNs??null}),i.toolProgress=a,s[r]={...o,additionalKwargs:i},s}function Ec(e,t){return e.includes(t)?e:[...e,t]}function Vx(e,t){const n=[...e],r=n.lastIndexOf(t);return r!==-1&&n.splice(r,1),n}function hr(e,t){let n=!1;const r={},o=e.map(s=>{const i=Jx(s);if(i.length)return r[s.id]=i,s;const a=t[s.id]??Rx(s.id);if(a!=null&&a.length){const l=[...a];r[s.id]=l,n=!0;const u={...s.additionalKwargs??{},toolProgress:l};return{...s,additionalKwargs:u}}return s});return{messages:n?o:e,toolTimelines:r}}function Ic(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Kx(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Ic(e);let l="",u=e.slice();if(s){const f=qx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",y={...h,text:p+l};u=[...u.slice(0,u.length-1),y]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function Nc(e){return e.replace(/\s+/g," ").trim()}function qx(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=Nc(e),o=Nc(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 Gx(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 Lo(e,r,s)}return e}function Yx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Xx(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 Jx(e){const t=e.additionalKwargs??{};return Array.isArray(t.toolProgress)?[...t.toolProgress]:[]}const Zx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],messagesStreamMeta:{},pendingInterrupt:null,toolTimelines:{}};function Qx(e,t){var n;switch(t.type){case"reset":return{messages:ki(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},toolStreamingMessageId:null,toolStreamingStack:[],pendingInterrupt:null,toolTimelines:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r]}}}return{...e,messages:[...e.messages,r]}}case"seed":{const r=ki(t.payload.messages),{messages:o,toolTimelines:s}=hr(r,e.toolTimelines),i={...e,messages:o,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null,toolStreamingMessageId:null,toolStreamingStack:[],toolTimelines:s};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(i.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(i.lastCheckpointNs=t.payload.checkpointNs??null),i}case"prepend":{const r=ki(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(u=>u.id)),s=r.filter(u=>!o.has(u.id));if(!s.length)return e;const i=[...s,...e.messages],{messages:a,toolTimelines:l}=hr(i,e.toolTimelines);return{...e,messages:a,toolTimelines:l}}case"event":return jc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>jc(o,s),e):e}case"interrupt_response":return{...e,messages:Sc(e.messages),pendingInterrupt:null};default:return e}}function Ac(e=[]){const[t,n]=w.useReducer(Qx,{...Zx,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 u=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,f)=>n({type:"user_message",payload:{message:d,editingMessageId:f}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function jc(e,t){var n,r,o,s;if(t.type==="message.start"&&t.role==="assistant"){const i=t.id,a=Yx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message.delta"){const i=e.assemblingId??Cc(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(C=>C.id===i&&C.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Ic(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:y,changed:g}=Kx(u.content,t.delta,f,h);if(!g)return e;const v={...u,content:p},x=Lo(a,l,v),b={...d,[i]:y};return{...e,messages:x,messagesStreamMeta:b}}if(t.type==="message.end"){const i=e.assemblingId??Cc(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool.start"){const i=Tc(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 u=i.length?i:a?[a]:[],d=u[0]??`${l}-${Date.now()}`,f={type:"tool_call",id:d,name:l,args:t.args},h={type:e.toolStreamingMessageId?"tool.call":"tool.start",toolId:a??d,toolName:l,metadata:{args:t.args}},p=e.toolStreamingMessageId;if(!p){const b={id:`tool-${d}`,role:"tool",name:l,createdAt:new Date().toISOString(),content:[f],additionalKwargs:{...Wx(void 0,u.length?u:[d],l,t.args),toolStreaming:!0}},C=Hx(b,u.length?u:[d]),k=[...e.messages,b],S=$o(k,b.id,h),{messages:T,toolTimelines:E}=hr(S,e.toolTimelines);return{...e,messages:T,toolIndex:kc(e.toolIndex,b.id,C),toolStreamingMessageId:b.id,toolStreamingStack:Ec(e.toolStreamingStack??[],a??d),toolTimelines:E}}const y=$o(e.messages,p,h),{messages:g,toolTimelines:v}=hr(y,e.toolTimelines);return{...e,messages:g,toolIndex:kc(e.toolIndex,p,u),toolStreamingStack:Ec(e.toolStreamingStack??[],a??d),toolTimelines:v}}if(t.type==="tool.end"){const i=Tc(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??[],u=l[0]??null,d=Vx(l,a),f=d[0]?e.toolIndex[d[0]]:null,h=e.toolStreamingMessageId,p=u===a,y=t.name??((s=e.messages.find(S=>S.id===h))==null?void 0:s.name)??"tool",g=typeof t.output=="string"?t.output.trim():JSON.stringify(t.output??""),v={type:"tool.end",toolId:a,toolName:y,content:g==null?void 0:g.slice(0,200)};let x=e.messages;if(h&&(x=$o(x,h,v)),p&&h){const S=x.findIndex(T=>T.id===h);if(S>=0){const T=x[S],A={type:"text",text:(()=>{if(typeof t.output=="string"){const $=t.output.trim();try{return $}catch{return $}}return JSON.stringify(t.output??"")})()},P={...T,content:[A],artifact:t.artifact??T.artifact,additionalKwargs:{...T.additionalKwargs??{}}};x=Lo(x,S,P)}}const b=d,{messages:C,toolTimelines:k}=hr(x,e.toolTimelines);return{...e,messages:C,toolTimelines:k,toolStreamingMessageId:p?f:h,toolStreamingStack:b}}if(t.type==="tool.progress"){const i=e.toolStreamingMessageId;if(!i)return e;const a={type:"tool.progress",content:t.content??null},l=$o(e.messages,i,a),u=l.findIndex(v=>v.id===i);if(u===-1)return e;const d=l[u],f={...d.additionalKwargs??{},toolStreaming:!0},h={...d,additionalKwargs:f},p=Lo(l,u,h),{messages:y,toolTimelines:g}=hr(p,e.toolTimelines);return{...e,messages:y,toolTimelines:g}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=Gx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}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,u=a===null?Sc(e.messages):e.messages;return{...e,messages:u,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 _c(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),[u,d]=w.useState(null),[f,h]=w.useState(""),[p,y]=w.useState(null),[g,v]=w.useState(0),[x,b]=w.useState(!1),C=w.useRef(null),k=w.useRef(!0),S=w.useRef(0),T=w.useRef(null),E=w.useRef(null),A=w.useRef(null),P=w.useRef(null),$=w.useCallback(O=>{o(O)},[]),B=w.useCallback(()=>{h(""),y(null),d(null),E.current=null,A.current=null,P.current=null},[]),V=w.useCallback(()=>{var O;console.debug("[use-chat] stop() invoked - aborting stream"),(O=C.current)==null||O.abort(),C.current=null,T.current=null,l(!1),b(!1),S.current=0,v(0)},[]),G=w.useCallback((O,U,N)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),y(null),E.current=null,A.current=null,P.current=null;const D=new AbortController;C.current=D;let M=null,j=null,H=!1;return T.current={threadId:O.threadId??null,headers:{}},(async()=>{var R,K,ie,Q,oe,Y,L,q,z,Z,X,ge,le,te,fe,ye,Me,Ne;const W=$e=>{var Xe;try{const nt=JSON.parse(JSON.stringify($e));return(Xe=nt==null?void 0:nt.payload)!=null&&Xe.files_info&&Array.isArray(nt.payload.files_info)&&(nt.payload.files_info=nt.payload.files_info.map(Ve=>({...Ve,data:Ve!=null&&Ve.data?`<base64 ${String(Ve.data).length} chars>`:Ve==null?void 0:Ve.data}))),nt}catch{return $e}};try{let $e={};try{if(r)$e={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ke=window.__AUTH_TOKEN__,dt=((R=window.localStorage)==null?void 0:R.getItem("authToken"))||null;let bt=null;try{const Tt=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");Tt&&(bt=((ie=JSON.parse(Tt))==null?void 0:ie.apiKey)||null)}catch{}const He=Ke||dt||bt||null;He&&($e={Authorization:`Bearer ${He}`})}}catch{}console.debug("[use-chat] POST",t+n,W(O));let Xe={};if(typeof window<"u")try{const Je=(Q=window.localStorage)==null?void 0:Q.getItem("authSessionId");Je&&(Xe={"X-Session-Id":Je})}catch{}const nt={...$e,...Xe,...s.current},Ve={"Content-Type":"application/json",Accept:"text/event-stream",...nt},qe=await fetch(t+n,{method:"POST",headers:Ve,body:JSON.stringify(O),signal:D.signal,credentials:i});if(T.current&&(T.current.headers=nt),!qe.ok||!qe.body){const Je=await qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",qe.status,Je==null?void 0:Je.slice(0,500));const Ke=`stream ${qe.status}${Je?": "+Je:""}`;throw(oe=N==null?void 0:N.onConnectionError)==null||oe.call(N,Ke),H=!0,M="error",j=Ke,new Error(Ke)}b(!0);const ot=qe.body.getReader(),kt=new TextDecoder;let lt="",ke=[];S.current=0,v(0);let Oe=0,at=null;const pt=()=>{if(ke.length){const Je=ke.join("");ke=[],k.current&&h(Ke=>Ke+Je)}at=null},Et=()=>{typeof window<"u"&&at==null&&(at=requestAnimationFrame(pt))};let Ct=Date.now();const Le=setInterval(()=>{var Je;if(Date.now()-Ct>18e5){const Ke="Stream idle timeout";d(Ke),M="error",j=Ke,D.abort(),(Je=N==null?void 0:N.onError)==null||Je.call(N,Ke)}},5e3),Vt=1024*1024;try{const Je=qe.headers.get("X-Thread-Id")||qe.headers.get("x-thread-id"),Ke=qe.headers.get("X-Thread-Created")||qe.headers.get("x-thread-created"),dt=Je??null,bt=String(Ke??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:dt}),(Y=N==null?void 0:N.onOpen)==null||Y.call(N,{threadId:dt,created:bt});;){const{value:He,done:Tt}=await ot.read();if(Tt)break;lt+=kt.decode(He,{stream:!0}),lt.length>Vt&&(lt="",console.warn("Stream buffer reset: exceeded 1MB"));let _;for(;(_=lt.indexOf(`
36
36
 
37
- `))>=0;){const he=dt.slice(0,$);dt=dt.slice($+2);const we=ny(he);if(!we)continue;let $e;try{$e=JSON.parse(we)}catch{console.debug("[use-chat] malformed SSE:",we.slice(0,200));continue}const ze=ty($e)?$e.data:$e;It=Date.now();const pt=ze.seq;if(pt!==void 0){if(pt<=mt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:pt,lastProcessedSeq:mt,type:ze.type});continue}mt>0&&pt>mt+1&&((O=E==null?void 0:E.onGap)==null||O.call(E,{from:mt,to:pt})),mt=pt,S.current=pt,v(pt)}if(ze.type==="checkpoint")I.current=ze.checkpointId??null,A.current=ze.checkpointNs??null,y(ze.checkpointId??null);else if(ze.type==="state_history"){R.current=ze;try{const Ct=hr(ze).latest;Ct&&(I.current=Ct.checkpointId??null,A.current=Ct.checkpointNs??null,y(Ct.checkpointId??null))}catch(Ze){console.warn("[use-chat] Failed to hydrate state_history payload",Ze)}}try{U==null||U(ze)}catch(Ze){console.error("[use-chat] Error in onEvent callback:",Ze,"for event:",ze.type)}if(ze.type==="message.delta"){const Ze=ze.delta.filter(Ct=>Ct.type==="text").map(Ct=>Ct.text).join("");Ze&&e.autoAppendAssistant!==!1&&(Tt.push(Ze),xt())}else if(ze.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(K=E==null?void 0:E.onHeartbeat)==null||K.call(E,ze)}catch(Ze){console.warn("[use-chat] heartbeat callback failed",Ze)}}else if(Ee!==null&&cancelAnimationFrame(Ee),Ke(),ze.type==="checkpoint")y(ze.checkpointId);else if(ze.type==="error"){const Ze=ze;if(d(Ze.message),L="error",_=Ze.message,Ze.error_type==="auth_error"||Ze.code==="TOKEN_EXPIRED"||((z=Ze.message)==null?void 0:z.includes("token"))||((ne=Ze.message)==null?void 0:ne.includes("401"))||((Q=Ze.message)==null?void 0:Q.includes("unauthorized"))||((ge=Ze.message)==null?void 0:ge.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Ze.message);try{(le=E==null?void 0:E.onAuthError)==null||le.call(E,Ze.message)}catch(cr){console.warn("[use-chat] onAuthError handler failed",cr)}P.abort()}}}}Ke(),L===null&&!P.signal.aborted&&(L="complete")}catch(Ge){if(Ge.name==="AbortError")L=L??"aborted";else{const Be=Ge.message||String(Ge);L="error",_=Be,d(Be),(oe=E==null?void 0:E.onError)==null||oe.call(E,Be)}}finally{try{await ot.cancel()}catch{}finally{(pe=ot.releaseLock)==null||pe.call(ot)}Ee!==null&&typeof window<"u"&&window.cancelAnimationFrame(Ee),clearInterval(Le)}}catch(De){if(De.name==="AbortError")L=L??"aborted";else{const et=De.message||String(De);L="error",_=et,d(et),(be=E==null?void 0:E.onError)==null||be.call(E,et),q||((Me=E==null?void 0:E.onConnectionError)==null||Me.call(E,et),q=!0)}}finally{const De=S.current,et=I.current,rt=A.current,He=R.current,Je=L??(P.signal.aborted?"aborted":_?"error":"complete");try{(Ie=E==null?void 0:E.onClosed)==null||Ie.call(E,{reason:Je,lastSeq:De,lastCheckpointId:et,lastCheckpointNs:rt,lastStateHistory:He,error:_})}catch(ot){console.warn("[use-chat] onClosed callback failed",ot)}l(!1),b(!1),k.current=null,S.current=0,v(0),C.current=null}})(),{close:()=>P.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var M;T.current=!1,(M=k.current)==null||M.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:g,connected:x,stream:G,stop:X,clear:B,setToken:D}}function ty(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function ny(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 ry=["message.start","message.delta","message.end"],oy=["tool.start","tool.end","tool.progress"],sy=["thread_info","checkpoint"],iy=["error","interrupt","heartbeat","state_history","cancelled"],ay=[...ry,...oy,...sy,...iy],ly=new Set(ay);function cy(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return ly.has(t)}const Mc=200;function uy({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:u,onToolEvent:d}){const f=w.useRef(null),h=w.useRef(null),p=w.useRef(new Map),y=w.useRef(null),g=w.useRef(null),v=w.useCallback(E=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(E)}catch{}try{return JSON.parse(JSON.stringify(E))}catch{return E}},[]),x=w.useCallback((E,P)=>{if(!E)return;const L=p.current.get(E)??[],_=v(P),q=L.length>=Mc?[...L.slice(L.length-Mc+1),_]:[...L,_];p.current.set(E,q)},[v]),b=w.useCallback(E=>{E&&p.current.set(E,[])},[]),k=w.useCallback(E=>{const P=E??h.current;if(!P)return;const L=p.current.get(P);L!=null&&L.length&&L.forEach(_=>{try{n(_)}catch(q){console.error("[useChatStreamingService] Failed to replay buffered event",q)}})},[n]),T=w.useCallback(E=>{h.current=E.threadId,y.current&&(y.current.threadIdGuess=E.threadId),g.current=E,b(E.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",E);try{t(E)}catch(P){console.error("[useChatStreamingService] Error in onThreadInfo handler:",P)}},[b,t]),S=w.useCallback(E=>{try{u==null||u(E)}catch(P){console.error("[useChatStreamingService] Error in onHeartbeat handler:",P)}},[u]),C=w.useCallback(E=>{var _,q,Y,j;const P=E;if(P.error_type==="auth_error"||P.code==="TOKEN_EXPIRED"||((_=P.message)==null?void 0:_.includes("token"))||((q=P.message)==null?void 0:q.includes("401"))||((Y=P.message)==null?void 0:Y.includes("unauthorized"))||((j=P.message)==null?void 0:j.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",P.message);try{l==null||l(P.message)}catch(J){console.warn("[useChatStreamingService] onAuthError handler failed",J)}}},[l]),I=w.useMemo(()=>({thread_info:E=>(T(E),!0),heartbeat:E=>(S(E),!0),error:E=>(C(E),!1)}),[T,S,C]),A=w.useCallback(E=>{var q;const P=E.seq??null;if(P!==null){const Y=f.current;if(Y!==null){if(P<=Y)return;P>Y+1&&(s==null||s({from:Y,to:P}))}f.current=P}const L=I[E.type];if(L&&L(E))return;const _=E.threadId??(E.type==="state_history"?E.threadId:void 0)??h.current??((q=y.current)==null?void 0:q.threadIdGuess)??null;if(E.type==="state_history"){h.current=_??h.current;try{r==null||r(E)}catch(Y){console.error("[useChatStreamingService] onStateHistory handler failed",Y)}}if(cy(E)){(E.type==="tool.start"||E.type==="tool.end")&&(d==null||d(E)),E.type==="checkpoint"||E.type==="state_history"?b(_??null):x(_??null,E);try{n(E)}catch(Y){console.error("[useChatStreamingService] Error in onMessageEvent handler:",Y)}return}try{o==null||o(E)}catch(Y){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",Y)}},[x,b,n,s,r,o,I]),{stream:R,stop:D,isStreaming:B,error:X,setToken:G}=_c({baseUrl:e,token:void 0}),M=w.useCallback((E,P)=>{f.current=null,g.current=null,h.current=E.threadId??null,y.current={request:E,callbacks:P,manualStop:!1,threadIdGuess:E.threadId??null},R(E,A,{onOpen:P==null?void 0:P.onOpen,onError:L=>{var _;(_=P==null?void 0:P.onError)==null||_.call(P,L)},onGap:(P==null?void 0:P.onGap)??s,onConnectionError:L=>{var _;a==null||a(L),(_=P==null?void 0:P.onConnectionError)==null||_.call(P,L)},onAuthError:L=>{var _;l==null||l(L),(_=P==null?void 0:P.onAuthError)==null||_.call(P,L)},onHeartbeat:L=>{var _;try{u==null||u(L)}catch(q){console.warn("[useChatStreamingService] onHeartbeat handler failed",q)}try{(_=P==null?void 0:P.onHeartbeat)==null||_.call(P,L)}catch(q){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",q)}},onClosed:L=>{var j,J,V,H;const _=((j=y.current)==null?void 0:j.manualStop)??!1,q=h.current??((J=y.current)==null?void 0:J.threadIdGuess)??((V=L.lastStateHistory)==null?void 0:V.threadId)??null;(L.reason==="complete"||L.reason==="aborted"&&_)&&b(q);const Y={...L,threadId:q,threadInfo:g.current,manualStop:_};try{i==null||i(Y)}catch(ee){console.warn("[useChatStreamingService] onStreamClosed handler failed",ee)}try{(H=P==null?void 0:P.onClosed)==null||H.call(P,Y)}catch(ee){console.warn("[useChatStreamingService] downstream onClosed handler failed",ee)}y.current&&(y.current=null)}})},[b,A,l,a,u,s,i,R]),U=w.useCallback(()=>{y.current&&(y.current.manualStop=!0),D()},[D]);return w.useMemo(()=>({startStream:M,stop:U,isStreaming:B,error:X,setAuthToken:G,replayBufferedEvents:k}),[M,U,B,X,G,k])}const Rc=w.createContext(null),Pc=w.createContext(null),Oc=w.createContext(null);w.createContext(!1);function dy({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l,onToolEnd:u}){const{api:d,baseUrl:f}=wi(),h=w.useMemo(()=>Cn(f),[f]),{state:p,seed:y,prepend:g,pushUser:v,onEvent:x}=Ac(),{threads:b,currentThreadId:k,setCurrentThreadId:T,currentThreadIdRef:S,isLoadingThreads:C,threadsError:I,sharedThreads:A,isLoadingSharedThreads:R,smartOrgUsers:D,isLoadingSmartOrgUsers:B,actions:X,addThreadFromEvent:G,shareInFlight:M,shareStatus:U,clearShareStatus:E}=$x({api:d,initialThreadId:t,onError:s,onThreadChange:a,onCurrentThreadDeleted:()=>y([],{})}),[P,L]=w.useState(!1),_=w.useCallback(()=>p.messages,[p.messages]),{threadCheckpoints:q,threadTimeline:Y,isLoadingThread:j,isHistoryLoading:J,isLoadingCheckpoint:V,threadStateError:H,hasMoreHistory:ee,loadThread:W,navigateToCheckpoint:O,loadOlderMessages:K,setCurrentCheckpointId:z,returnToLatest:ne,handleStateHistoryEvent:Q,markSkipNextLoad:ge,markStreamPendingThread:le,resetHistoryState:oe}=Ox({api:d,seed:y,prepend:g,onError:s,currentThreadId:k,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:P,getMessages:_}),pe=w.useMemo(()=>ux(q),[q]),be=w.useCallback(Ee=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",Ee.threadId),G(Ee),S.current!==Ee.threadId&&((Ee.created??!S.current)&&ge(Ee.threadId),le(Ee.threadId),console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),T(Ee.threadId))},[G,ge,le]),{startStream:Me,stop:Ie,isStreaming:De,error:et,setAuthToken:rt}=uy({baseUrl:h,onThreadInfo:be,onMessageEvent:x,onStateHistory:Q,onUnhandledEvent:Ee=>{console.warn("[ChatSessionProvider] Unhandled event:",Ee.type)},onAuthError:i,onConnectionError:l,onToolEvent:Ee=>{Ee.type==="tool.end"&&(u==null||u(Ee))}});w.useEffect(()=>{L(De)},[De]);const He=w.useCallback(async()=>{y([],{}),T(null),Ie(),oe();try{await d.getAgent("default")}catch(Ee){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",Ee)}},[y,Ie,d,oe]),Je=w.useCallback(async(Ee,Ke,xt)=>{const It=S.current;if(!It)throw new Error("No active thread to handle interrupt");const Le=Ke?xt??!0:!1;try{const _t={threadId:It,checkpointId:p.lastCheckpointId??void 0,checkpointNs:p.lastCheckpointNs??void 0,command:{kind:"resume",value:Le}};Me(_t)}catch(_t){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${Ee}:`,_t),_t}},[p.lastCheckpointId,p.lastCheckpointNs,Me]),ot=w.useCallback(async(Ee,Ke)=>{let xt=S.current;const It=(Ee==null?void 0:Ee.text)??"",Le=(Ee==null?void 0:Ee.attachments)??[],_t=(It==null?void 0:It.trim())??"",Ge={...(Ee==null?void 0:Ee.payload)??{}},Be=Array.isArray(Ge.messages)?Ge.messages:void 0;Be&&delete Ge.messages;const lt=!!(Be&&Be.length);if(!xt&&!_t&&Le.length===0&&!lt)return;if(!xt){const Ct=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),cr=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);xt=`${Ct}${cr}`,ge(xt),T(xt)}const{contentParts:Et,filesInfo:qe}=await ax(d,Le),Z=[...Et];_t&&Z.push({type:"text",text:It});const $=Ke==null?void 0:Ke.originalMessageId,he=!!(Ke!=null&&Ke.edit&&$),we=!lt&&Z.length>0;let $e=null;we&&($e={id:he?$:`msg-${Date.now()}`,role:"user",content:Z,createdAt:new Date().toISOString()},he?v($e,$):v($e));const ze=lt?Be:$e?[$e]:[],pt={...Ge,...qe.length?{files_info:qe}:{}};ze.length?pt.messages=ze:"messages"in pt||(pt.messages=[]);const Ze={threadId:xt,payload:pt,checkpointId:(Ke==null?void 0:Ke.checkpointId)??p.lastCheckpointId??void 0,checkpointNs:(Ke==null?void 0:Ke.checkpointNs)??p.lastCheckpointNs??void 0,edit:!!(Ke!=null&&Ke.edit),timelineCheckpoints:Y};Me(Ze)},[d,v,p,Me,Y]),St=w.useMemo(()=>({threads:b,currentThreadId:k,setCurrentThreadId:T,isLoading:C,error:I,sharedThreads:A,isLoadingSharedThreads:R,smartOrgUsers:D,isLoadingSmartOrgUsers:B,actions:X,shareInFlight:M,shareStatus:U,clearShareStatus:E}),[b,k,T,C,I,A,R,D,B,X,M,U,E]),dt=w.useMemo(()=>{const Ee=p.assemblingId??null;return Ee?{assemblingMessageId:Ee}:null},[p.assemblingId]),Tt=w.useMemo(()=>({threadId:k,messages:p.messages,interrupt:null,checkpoint:{id:p.lastCheckpointId??null,namespace:p.lastCheckpointNs??null},checkpoints:q,timelineCheckpoints:Y,metadata:dt,isLoading:j,isHistoryLoading:J,isLoadingCheckpoint:V,error:H,hasMore:ee,loadOlder:K,clearState:He,navigateToCheckpoint:O,setCurrentCheckpointId:z,returnToLatest:ne,loadThread:W,clearThread:He,respondToInterrupt:Je,messagePreviews:pe}),[k,p,q,Y,j,J,V,H,ee,K,He,O,z,ne,W,Je,pe,dt]),mt=w.useMemo(()=>({isStreaming:De,error:et,connectionState:De?"connected":"idle",submit:ot,send:ot,stop:Ie,setAuthToken:rt}),[De,et,ot,Ie,rt]);return c.jsx(Rc.Provider,{value:St,children:c.jsx(Pc.Provider,{value:Tt,children:c.jsx(Oc.Provider,{value:mt,children:e})})})}function Fo(){const e=w.useContext(Rc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Bo(){const e=w.useContext(Pc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Dc(){const e=w.useContext(Oc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function zo({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:u,onToolEnd:d}){return c.jsx(sx,{apiConfig:t,children:c.jsx(dy,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:u,onToolEnd:d,children:e})})}function se(...e){return Mm.twMerge(_m.clsx(e))}const fy=bo.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"}}),tt=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return c.jsx(i,{className:se(fy({variant:t,size:n,className:e})),ref:s,...o})});tt.displayName="Button";const Lc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:se("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}));Lc.displayName="Textarea";function $c({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:u,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const y=i!==void 0,[g,v]=w.useState(e),x=(y?i:g)??"",[b,k]=w.useTransition(),T=w.useRef(null),S=w.useRef(0),C=w.useRef(null);w.useEffect(()=>{y||(v(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,y]);const I=w.useCallback(()=>{const U=T.current;U&&(U.style.height="auto",U.style.height=`${U.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,x]);const A=w.useCallback((U,{fromUser:E})=>{y||v(U),E&&(a==null||a(U))},[y,a]),R=w.useCallback(async U=>{U&&U.preventDefault();const E=(x??"").trim();if(!E&&!p)return;const P=++S.current;C.current={id:P,shouldClear:!0},k(()=>{var L,_,q;try{const Y=l(E);Y&&typeof Y.then=="function"?Y.then(()=>{var j,J;((j=C.current)==null?void 0:j.id)===P&&C.current.shouldClear&&(y||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((J=C.current)==null?void 0:J.id)===P&&(C.current=null)}).catch(()=>{var j;((j=C.current)==null?void 0:j.id)===P&&(C.current=null)}):(((L=C.current)==null?void 0:L.id)===P&&C.current.shouldClear&&(y||(v(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((_=C.current)==null?void 0:_.id)===P&&(C.current=null))}catch{((q=C.current)==null?void 0:q.id)===P&&(C.current=null)}})},[x,l,p,y,a]),D=w.useCallback(U=>{const E=U.target.value;A(E,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[A]),B=w.useCallback(U=>{U.key==="Enter"&&!U.shiftKey?(U.preventDefault(),R()):U.key==="Escape"&&t&&(U.preventDefault(),u==null||u())},[R,t,u]),M=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return c.jsx("form",{onSubmit:U=>void R(U),className:`w-full ${f}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Lc,{ref:T,value:x,onChange:D,onKeyDown:B,placeholder:t?"Edit your message...":n,className:M,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(tt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:c.jsx(ae.Square,{size:16})}):c.jsx(tt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||b,children:c.jsx(ae.Send,{size:16})})})]})})}const hy=w.memo($c);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 Fc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function An(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Fc(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():Fc(e[o],null)}}}}function We(...e){return m.useCallback(An(...e),e)}function py(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function kn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...y}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,v=m.useMemo(()=>y,Object.values(y));return c.jsx(g.Provider,{value:v,children:p})};u.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,y=m.useContext(p);if(y)return y;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,my(o,...t)]}function my(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var At=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},gy=m[" useInsertionEffect ".trim().toString()]||At;function mr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=xy({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=yy(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function xy({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return gy(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function yy(e){return typeof e=="function"}var vy=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=vy.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bc(e,t){e&&wo.flushSync(()=>e.dispatchEvent(t))}function Ii(e){const t=e+"CollectionProvider",[n,r]=kn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:v,children:x}=g,b=w.useRef(null),k=w.useRef(new Map).current;return c.jsx(o,{scope:v,itemMap:k,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Wn.createSlot(a),u=w.forwardRef((g,v)=>{const{scope:x,children:b}=g,k=s(a,x),T=We(v,k.collectionRef);return c.jsx(l,{ref:T,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Wn.createSlot(d),p=w.forwardRef((g,v)=>{const{scope:x,children:b,...k}=g,T=w.useRef(null),S=We(v,T),C=s(d,x);return w.useEffect(()=>(C.itemMap.set(T,{ref:T,...k}),()=>void C.itemMap.delete(T))),c.jsx(h,{[f]:"",ref:S,children:b})});p.displayName=d;function y(g){const v=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=v.collectionRef.current;if(!b)return[];const k=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(v.itemMap.values()).sort((C,I)=>k.indexOf(C.ref.current)-k.indexOf(I.ref.current))},[v.collectionRef,v.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},y,r]}var by=m.createContext(void 0);function Uo(e){const t=m.useContext(by);return e||t||"ltr"}function jt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function wy(e,t=globalThis==null?void 0:globalThis.document){const n=jt(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Sy="DismissableLayer",Ei="dismissableLayer.update",Cy="dismissableLayer.pointerDownOutside",ky="dismissableLayer.focusOutside",zc,Uc=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ho=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(Uc),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),y=We(t,I=>f(I)),g=Array.from(u.layers),[v]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(v),b=d?g.indexOf(d):-1,k=u.layersWithOutsidePointerEventsDisabled.size>0,T=b>=x,S=Ey(I=>{const A=I.target,R=[...u.branches].some(D=>D.contains(A));!T||R||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),C=Ny(I=>{const A=I.target;[...u.branches].some(D=>D.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return wy(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(zc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),Hc(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=zc)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),Hc())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Ei,I),()=>document.removeEventListener(Ei,I)},[]),c.jsx(Se.div,{...l,ref:y,style:{pointerEvents:k?T?"auto":"none":void 0,...e.style},onFocusCapture:fe(e.onFocusCapture,C.onFocusCapture),onBlurCapture:fe(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:fe(e.onPointerDownCapture,S.onPointerDownCapture)})});Ho.displayName=Sy;var Ty="DismissableLayerBranch",Iy=m.forwardRef((e,t)=>{const n=m.useContext(Uc),r=m.useRef(null),o=We(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Se.div,{...e,ref:o})});Iy.displayName=Ty;function Ey(e,t=globalThis==null?void 0:globalThis.document){const n=jt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Wc(Cy,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Ny(e,t=globalThis==null?void 0:globalThis.document){const n=jt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Wc(ky,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 Hc(){const e=new CustomEvent(Ei);document.dispatchEvent(e)}function Wc(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?Bc(o,s):o.dispatchEvent(s)}var Ni=0;function Ai(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Vc()),document.body.insertAdjacentElement("beforeend",e[1]??Vc()),Ni++,()=>{Ni===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ni--}},[])}function Vc(){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 ji="focusScope.autoFocusOnMount",_i="focusScope.autoFocusOnUnmount",Kc={bubbles:!1,cancelable:!0},Ay="FocusScope",Wo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=jt(o),d=jt(s),f=m.useRef(null),h=We(t,g=>l(g)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let g=function(k){if(p.paused||!a)return;const T=k.target;a.contains(T)?f.current=T:jn(f.current,{select:!0})},v=function(k){if(p.paused||!a)return;const T=k.relatedTarget;T!==null&&(a.contains(T)||jn(f.current,{select:!0}))},x=function(k){if(document.activeElement===document.body)for(const S of k)S.removedNodes.length>0&&jn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",v);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",v),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){Yc.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(ji,Kc);a.addEventListener(ji,u),a.dispatchEvent(x),x.defaultPrevented||(jy(Oy(qc(a)),{select:!0}),document.activeElement===g&&jn(a))}return()=>{a.removeEventListener(ji,u),setTimeout(()=>{const x=new CustomEvent(_i,Kc);a.addEventListener(_i,d),a.dispatchEvent(x),x.defaultPrevented||jn(g??document.body,{select:!0}),a.removeEventListener(_i,d),Yc.remove(p)},0)}}},[a,u,d,p]);const y=m.useCallback(g=>{if(!n&&!r||p.paused)return;const v=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(v&&x){const b=g.currentTarget,[k,T]=_y(b);k&&T?!g.shiftKey&&x===T?(g.preventDefault(),n&&jn(k,{select:!0})):g.shiftKey&&x===k&&(g.preventDefault(),n&&jn(T,{select:!0})):x===b&&g.preventDefault()}},[n,r,p.paused]);return c.jsx(Se.div,{tabIndex:-1,...i,ref:h,onKeyDown:y})});Wo.displayName=Ay;function jy(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(jn(r,{select:t}),document.activeElement!==n)return}function _y(e){const t=qc(e),n=Gc(t,e),r=Gc(t.reverse(),e);return[n,r]}function qc(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 Gc(e,t){for(const n of e)if(!My(n,{upTo:t}))return n}function My(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 Ry(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&&Ry(e)&&t&&e.select()}}var Yc=Py();function Py(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Xc(e,t),e.unshift(t)},remove(t){var n;e=Xc(e,t),(n=e[0])==null||n.resume()}}}function Xc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Oy(e){return e.filter(t=>t.tagName!=="A")}var Dy=m[" useId ".trim().toString()]||(()=>{}),Ly=0;function Ft(e){const[t,n]=m.useState(Dy());return At(()=>{n(r=>r??String(Ly++))},[e]),t?`radix-${t}`:""}const $y=["top","right","bottom","left"],_n=Math.min,Gt=Math.max,Vo=Math.round,Ko=Math.floor,pn=e=>({x:e,y:e}),Fy={left:"right",right:"left",bottom:"top",top:"bottom"},By={start:"end",end:"start"};function Mi(e,t,n){return Gt(e,_n(t,n))}function Tn(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function gr(e){return e.split("-")[1]}function Ri(e){return e==="x"?"y":"x"}function Pi(e){return e==="y"?"height":"width"}const zy=new Set(["top","bottom"]);function mn(e){return zy.has(In(e))?"y":"x"}function Oi(e){return Ri(mn(e))}function Uy(e,t,n){n===void 0&&(n=!1);const r=gr(e),o=Oi(e),s=Pi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=qo(i)),[i,qo(i)]}function Hy(e){const t=qo(e);return[Di(e),t,Di(t)]}function Di(e){return e.replace(/start|end/g,t=>By[t])}const Jc=["left","right"],Zc=["right","left"],Wy=["top","bottom"],Vy=["bottom","top"];function Ky(e,t,n){switch(e){case"top":case"bottom":return n?t?Zc:Jc:t?Jc:Zc;case"left":case"right":return t?Wy:Vy;default:return[]}}function qy(e,t,n,r){const o=gr(e);let s=Ky(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Di)))),s}function qo(e){return e.replace(/left|right|bottom|top/g,t=>Fy[t])}function Gy(e){return{top:0,right:0,bottom:0,left:0,...e}}function Qc(e){return typeof e!="number"?Gy(e):{top:e,right:e,bottom:e,left:e}}function Go(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 eu(e,t,n){let{reference:r,floating:o}=e;const s=mn(t),i=Oi(t),a=Pi(i),l=In(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(gr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Yy=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=eu(u,r,l),h=r,p={},y=0;for(let g=0;g<a.length;g++){const{name:v,fn:x}=a[g],{x:b,y:k,data:T,reset:S}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=k??f,p={...p,[v]:{...p[v],...T}},S&&y<=50&&(y++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(u=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:d,y:f}=eu(u,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Br(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Tn(t,e),y=Qc(p),v=a[h?f==="floating"?"reference":"floating":f],x=Go(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),T=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},S=Go(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:k,strategy:l}):b);return{top:(x.top-S.top+y.top)/T.y,bottom:(S.bottom-x.bottom+y.bottom)/T.y,left:(x.left-S.left+y.left)/T.x,right:(S.right-x.right+y.right)/T.x}}const Xy=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=Tn(e,t)||{};if(u==null)return{};const f=Qc(d),h={x:n,y:r},p=Oi(o),y=Pi(p),g=await i.getDimensions(u),v=p==="y",x=v?"top":"left",b=v?"bottom":"right",k=v?"clientHeight":"clientWidth",T=s.reference[y]+s.reference[p]-h[p]-s.floating[y],S=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=C?C[k]:0;(!I||!await(i.isElement==null?void 0:i.isElement(C)))&&(I=a.floating[k]||s.floating[y]);const A=T/2-S/2,R=I/2-g[y]/2-1,D=_n(f[x],R),B=_n(f[b],R),X=D,G=I-g[y]-B,M=I/2-g[y]/2+A,U=Mi(X,M,G),E=!l.arrow&&gr(o)!=null&&M!==U&&s.reference[y]/2-(M<X?D:B)-g[y]/2<0,P=E?M<X?M-X:M-G:0;return{[p]:h[p]+P,data:{[p]:U,centerOffset:M-U-P,...E&&{alignmentOffset:P}},reset:E}}}),Jy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:g=!0,...v}=Tn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=In(o),b=mn(a),k=In(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(u.floating)),S=h||(k||!g?[qo(a)]:Hy(a)),C=y!=="none";!h&&C&&S.push(...qy(a,g,y,T));const I=[a,...S],A=await Br(t,v),R=[];let D=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[x]),f){const M=Uy(o,i,T);R.push(A[M[0]],A[M[1]])}if(D=[...D,{placement:o,overflows:R}],!R.every(M=>M<=0)){var B,X;const M=(((B=s.flip)==null?void 0:B.index)||0)+1,U=I[M];if(U&&(!(f==="alignment"?b!==mn(U):!1)||D.every(L=>mn(L.placement)===b?L.overflows[0]>0:!0)))return{data:{index:M,overflows:D},reset:{placement:U}};let E=(X=D.filter(P=>P.overflows[0]<=0).sort((P,L)=>P.overflows[1]-L.overflows[1])[0])==null?void 0:X.placement;if(!E)switch(p){case"bestFit":{var G;const P=(G=D.filter(L=>{if(C){const _=mn(L.placement);return _===b||_==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(_=>_>0).reduce((_,q)=>_+q,0)]).sort((L,_)=>L[1]-_[1])[0])==null?void 0:G[0];P&&(E=P);break}case"initialPlacement":E=a;break}if(o!==E)return{reset:{placement:E}}}return{}}}};function tu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nu(e){return $y.some(t=>e[t]>=0)}const Zy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Tn(e,t);switch(r){case"referenceHidden":{const s=await Br(t,{...o,elementContext:"reference"}),i=tu(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nu(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=tu(s,n.floating);return{data:{escapedOffsets:i,escaped:nu(i)}}}default:return{}}}}},ru=new Set(["left","top"]);async function Qy(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=gr(n),l=mn(n)==="y",u=ru.has(i)?-1:1,d=s&&l?-1:1,f=Tn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:y}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof y=="number"&&(p=a==="end"?y*-1:y),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const ev=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 Qy(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}}}}},tv=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x,y:b}=v;return{x,y:b}}},...l}=Tn(e,t),u={x:n,y:r},d=await Br(t,l),f=mn(In(o)),h=Ri(f);let p=u[h],y=u[f];if(s){const v=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[v],k=p-d[x];p=Mi(b,p,k)}if(i){const v=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=y+d[v],k=y-d[x];y=Mi(b,y,k)}const g=a.fn({...t,[h]:p,[f]:y});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},nv=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=Tn(e,t),d={x:n,y:r},f=mn(o),h=Ri(f);let p=d[h],y=d[f];const g=Tn(a,t),v=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const k=h==="y"?"height":"width",T=s.reference[h]-s.floating[k]+v.mainAxis,S=s.reference[h]+s.reference[k]-v.mainAxis;p<T?p=T:p>S&&(p=S)}if(u){var x,b;const k=h==="y"?"width":"height",T=ru.has(In(o)),S=s.reference[f]-s.floating[k]+(T&&((x=i.offset)==null?void 0:x[f])||0)+(T?0:v.crossAxis),C=s.reference[f]+s.reference[k]+(T?0:((b=i.offset)==null?void 0:b[f])||0)-(T?v.crossAxis:0);y<S?y=S:y>C&&(y=C)}return{[h]:p,[f]:y}}}},rv=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=Tn(e,t),d=await Br(t,u),f=In(o),h=gr(o),p=mn(o)==="y",{width:y,height:g}=s.floating;let v,x;f==="top"||f==="bottom"?(v=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,v=h==="end"?"top":"bottom");const b=g-d.top-d.bottom,k=y-d.left-d.right,T=_n(g-d[v],b),S=_n(y-d[x],k),C=!t.middlewareData.shift;let I=T,A=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),C&&!h){const D=Gt(d.left,0),B=Gt(d.right,0),X=Gt(d.top,0),G=Gt(d.bottom,0);p?A=y-2*(D!==0||B!==0?D+B:Gt(d.left,d.right)):I=g-2*(X!==0||G!==0?X+G:Gt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const R=await i.getDimensions(a.floating);return y!==R.width||g!==R.height?{reset:{rects:!0}}:{}}}};function Yo(){return typeof window<"u"}function xr(e){return ou(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function gn(e){var t;return(t=(ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function ou(e){return Yo()?e instanceof Node||e instanceof Yt(e).Node:!1}function an(e){return Yo()?e instanceof Element||e instanceof Yt(e).Element:!1}function xn(e){return Yo()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function su(e){return!Yo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const ov=new Set(["inline","contents"]);function zr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=ln(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!ov.has(o)}const sv=new Set(["table","td","th"]);function iv(e){return sv.has(xr(e))}const av=[":popover-open",":modal"];function Xo(e){return av.some(t=>{try{return e.matches(t)}catch{return!1}})}const lv=["transform","translate","scale","rotate","perspective"],cv=["transform","translate","scale","rotate","perspective","filter"],uv=["paint","layout","strict","content"];function Li(e){const t=$i(),n=an(e)?ln(e):e;return lv.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)||cv.some(r=>(n.willChange||"").includes(r))||uv.some(r=>(n.contain||"").includes(r))}function dv(e){let t=Mn(e);for(;xn(t)&&!yr(t);){if(Li(t))return t;if(Xo(t))return null;t=Mn(t)}return null}function $i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const fv=new Set(["html","body","#document"]);function yr(e){return fv.has(xr(e))}function ln(e){return Yt(e).getComputedStyle(e)}function Jo(e){return an(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Mn(e){if(xr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||su(e)&&e.host||gn(e);return su(t)?t.host:t}function iu(e){const t=Mn(e);return yr(t)?e.ownerDocument?e.ownerDocument.body:e.body:xn(t)&&zr(t)?t:iu(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=iu(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Fi(i);return t.concat(i,i.visualViewport||[],zr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Fi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function au(e){const t=ln(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=xn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Vo(n)!==s||Vo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Bi(e){return an(e)?e:e.contextElement}function vr(e){const t=Bi(e);if(!xn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=au(t);let i=(s?Vo(n.width):n.width)/r,a=(s?Vo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const hv=pn(0);function lu(e){const t=Yt(e);return!$i()||!t.visualViewport?hv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function pv(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Bi(e);let i=pn(1);t&&(r?an(r)&&(i=vr(r)):i=vr(e));const a=pv(s,n,r)?lu(s):pn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Yt(s),p=r&&an(r)?Yt(r):r;let y=h,g=Fi(y);for(;g&&r&&p!==y;){const v=vr(g),x=g.getBoundingClientRect(),b=ln(g),k=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*v.x,T=x.top+(g.clientTop+parseFloat(b.paddingTop))*v.y;l*=v.x,u*=v.y,d*=v.x,f*=v.y,l+=k,u+=T,y=Yt(g),g=Fi(y)}}return Go({width:d,height:f,x:l,y:u})}function Zo(e,t){const n=Jo(e).scrollLeft;return t?t.left+n:Gn(gn(e)).left+n}function cu(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Zo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function mv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=gn(r),a=t?Xo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=pn(1);const d=pn(0),f=xn(r);if((f||!f&&!s)&&((xr(r)!=="body"||zr(i))&&(l=Jo(r)),xn(r))){const p=Gn(r);u=vr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?cu(i,l):pn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function gv(e){return Array.from(e.getClientRects())}function xv(e){const t=gn(e),n=Jo(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Zo(e);const a=-n.scrollTop;return ln(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const uu=25;function yv(e,t){const n=Yt(e),r=gn(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=$i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Zo(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,y=Math.abs(r.clientWidth-f.clientWidth-p);y<=uu&&(s-=y)}else u<=uu&&(s+=u);return{width:s,height:i,x:a,y:l}}const vv=new Set(["absolute","fixed"]);function bv(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=xn(e)?vr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function du(e,t,n){let r;if(t==="viewport")r=yv(e,n);else if(t==="document")r=xv(gn(e));else if(an(t))r=bv(t,n);else{const o=lu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Go(r)}function fu(e,t){const n=Mn(e);return n===t||!an(n)||yr(n)?!1:ln(n).position==="fixed"||fu(n,t)}function wv(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>an(a)&&xr(a)!=="body"),o=null;const s=ln(e).position==="fixed";let i=s?Mn(e):e;for(;an(i)&&!yr(i);){const a=ln(i),l=Li(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&vv.has(o.position)||zr(i)&&!l&&fu(e,i))?r=r.filter(d=>d!==i):o=a,i=Mn(i)}return t.set(e,r),r}function Sv(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Xo(t)?[]:wv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=du(t,d,o);return u.top=Gt(f.top,u.top),u.right=_n(f.right,u.right),u.bottom=_n(f.bottom,u.bottom),u.left=Gt(f.left,u.left),u},du(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Cv(e){const{width:t,height:n}=au(e);return{width:t,height:n}}function kv(e,t,n){const r=xn(t),o=gn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function u(){l.x=Zo(o)}if(r||!r&&!s)if((xr(t)!=="body"||zr(o))&&(a=Jo(t)),r){const p=Gn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?cu(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function zi(e){return ln(e).position==="static"}function hu(e,t){if(!xn(e)||ln(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return gn(e)===n&&(n=n.ownerDocument.body),n}function pu(e,t){const n=Yt(e);if(Xo(e))return n;if(!xn(e)){let o=Mn(e);for(;o&&!yr(o);){if(an(o)&&!zi(o))return o;o=Mn(o)}return n}let r=hu(e,t);for(;r&&iv(r)&&zi(r);)r=hu(r,t);return r&&yr(r)&&zi(r)&&!Li(r)?n:r||dv(e)||n}const Tv=async function(e){const t=this.getOffsetParent||pu,n=this.getDimensions,r=await n(e.floating);return{reference:kv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Iv(e){return ln(e).direction==="rtl"}const Ev={convertOffsetParentRelativeRectToViewportRelativeRect:mv,getDocumentElement:gn,getClippingRect:Sv,getOffsetParent:pu,getElementRects:Tv,getClientRects:gv,getDimensions:Cv,getScale:vr,isElement:an,isRTL:Iv};function mu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Nv(e,t){let n=null,r;const o=gn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const y=Ko(f),g=Ko(o.clientWidth-(d+h)),v=Ko(o.clientHeight-(f+p)),x=Ko(d),k={rootMargin:-y+"px "+-g+"px "+-v+"px "+-x+"px",threshold:Gt(0,_n(1,l))||1};let T=!0;function S(C){const I=C[0].intersectionRatio;if(I!==l){if(!T)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!mu(u,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(S,{...k,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,k)}n.observe(e)}return i(!0),s}function Av(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Bi(e),d=o||s?[...u?Ur(u):[],...Ur(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?Nv(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var k;(k=p)==null||k.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let y,g=l?Gn(e):null;l&&v();function v(){const x=Gn(e);g&&!mu(g,x)&&n(),g=x,y=requestAnimationFrame(v)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(y)}}const jv=ev,_v=tv,Mv=Jy,Rv=rv,Pv=Zy,gu=Xy,Ov=nv,Dv=(e,t,n)=>{const r=new Map,o={platform:Ev,...n},s={...o.platform,_c:r};return Yy(e,t,{...o,platform:s})};var Lv=typeof document<"u",$v=function(){},Qo=Lv?w.useLayoutEffect:$v;function es(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(!es(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)&&!es(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function xu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function yu(e,t){const n=xu(e);return Math.round(t*n)/n}function Ui(e){const t=m.useRef(e);return Qo(()=>{t.current=e}),t}function Fv(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);es(h,r)||p(r);const[y,g]=m.useState(null),[v,x]=m.useState(null),b=m.useCallback(L=>{L!==C.current&&(C.current=L,g(L))},[]),k=m.useCallback(L=>{L!==I.current&&(I.current=L,x(L))},[]),T=s||y,S=i||v,C=m.useRef(null),I=m.useRef(null),A=m.useRef(d),R=l!=null,D=Ui(l),B=Ui(o),X=Ui(u),G=m.useCallback(()=>{if(!C.current||!I.current)return;const L={placement:t,strategy:n,middleware:h};B.current&&(L.platform=B.current),Dv(C.current,I.current,L).then(_=>{const q={..._,isPositioned:X.current!==!1};M.current&&!es(A.current,q)&&(A.current=q,wo.flushSync(()=>{f(q)}))})},[h,t,n,B,X]);Qo(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(L=>({...L,isPositioned:!1})))},[u]);const M=m.useRef(!1);Qo(()=>(M.current=!0,()=>{M.current=!1}),[]),Qo(()=>{if(T&&(C.current=T),S&&(I.current=S),T&&S){if(D.current)return D.current(T,S,G);G()}},[T,S,G,D,R]);const U=m.useMemo(()=>({reference:C,floating:I,setReference:b,setFloating:k}),[b,k]),E=m.useMemo(()=>({reference:T,floating:S}),[T,S]),P=m.useMemo(()=>{const L={position:n,left:0,top:0};if(!E.floating)return L;const _=yu(E.floating,d.x),q=yu(E.floating,d.y);return a?{...L,transform:"translate("+_+"px, "+q+"px)",...xu(E.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:_,top:q}},[n,a,E.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:G,refs:U,elements:E,floatingStyles:P}),[d,G,U,E,P])}const Bv=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?gu({element:r.current,padding:o}).fn(n):{}:r?gu({element:r,padding:o}).fn(n):{}}}},zv=(e,t)=>({...jv(e),options:[e,t]}),Uv=(e,t)=>({..._v(e),options:[e,t]}),Hv=(e,t)=>({...Ov(e),options:[e,t]}),Wv=(e,t)=>({...Mv(e),options:[e,t]}),Vv=(e,t)=>({...Rv(e),options:[e,t]}),Kv=(e,t)=>({...Pv(e),options:[e,t]}),qv=(e,t)=>({...Bv(e),options:[e,t]});var Gv="Arrow",vu=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Se.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});vu.displayName=Gv;var Yv=vu;function bu(e){const[t,n]=m.useState(void 0);return At(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Hi="Popper",[wu,ts]=kn(Hi),[Xv,Su]=wu(Hi),Cu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(Xv,{scope:t,anchor:r,onAnchorChange:o,children:n})};Cu.displayName=Hi;var ku="PopperAnchor",Tu=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Su(ku,n),i=m.useRef(null),a=We(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Se.div,{...o,ref:a})});Tu.displayName=ku;var Wi="PopperContent",[Jv,Zv]=wu(Wi),Iu=m.forwardRef((e,t)=>{var W,O,K,z,ne,Q;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:y,...g}=e,v=Su(Wi,n),[x,b]=m.useState(null),k=We(t,ge=>b(ge)),[T,S]=m.useState(null),C=bu(T),I=(C==null?void 0:C.width)??0,A=(C==null?void 0:C.height)??0,R=r+(s!=="center"?"-"+s:""),D=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(u)?u:[u],X=B.length>0,G={padding:D,boundary:B.filter(eb),altBoundary:X},{refs:M,floatingStyles:U,placement:E,isPositioned:P,middlewareData:L}=Fv({strategy:"fixed",placement:R,whileElementsMounted:(...ge)=>Av(...ge,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[zv({mainAxis:o+A,alignmentAxis:i}),l&&Uv({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Hv():void 0,...G}),l&&Wv({...G}),Vv({...G,apply:({elements:ge,rects:le,availableWidth:oe,availableHeight:pe})=>{const{width:be,height:Me}=le.reference,Ie=ge.floating.style;Ie.setProperty("--radix-popper-available-width",`${oe}px`),Ie.setProperty("--radix-popper-available-height",`${pe}px`),Ie.setProperty("--radix-popper-anchor-width",`${be}px`),Ie.setProperty("--radix-popper-anchor-height",`${Me}px`)}}),T&&qv({element:T,padding:a}),tb({arrowWidth:I,arrowHeight:A}),h&&Kv({strategy:"referenceHidden",...G})]}),[_,q]=Au(E),Y=jt(y);At(()=>{P&&(Y==null||Y())},[P,Y]);const j=(W=L.arrow)==null?void 0:W.x,J=(O=L.arrow)==null?void 0:O.y,V=((K=L.arrow)==null?void 0:K.centerOffset)!==0,[H,ee]=m.useState();return At(()=>{x&&ee(window.getComputedStyle(x).zIndex)},[x]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:P?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:H,"--radix-popper-transform-origin":[(z=L.transformOrigin)==null?void 0:z.x,(ne=L.transformOrigin)==null?void 0:ne.y].join(" "),...((Q=L.hide)==null?void 0:Q.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(Jv,{scope:n,placedSide:_,onArrowChange:S,arrowX:j,arrowY:J,shouldHideArrow:V,children:c.jsx(Se.div,{"data-side":_,"data-align":q,...g,ref:k,style:{...g.style,animation:P?void 0:"none"}})})})});Iu.displayName=Wi;var Eu="PopperArrow",Qv={top:"bottom",right:"left",bottom:"top",left:"right"},Nu=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Zv(Eu,r),i=Qv[s.placedSide];return c.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:c.jsx(Yv,{...o,ref:n,style:{...o.style,display:"block"}})})});Nu.displayName=Eu;function eb(e){return e!==null}var tb=e=>({name:"transformOrigin",options:e,fn(t){var v,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((v=o.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Au(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let y="",g="";return u==="bottom"?(y=i?f:`${h}px`,g=`${-l}px`):u==="top"?(y=i?f:`${h}px`,g=`${r.floating.height+l}px`):u==="right"?(y=`${-l}px`,g=i?f:`${p}px`):u==="left"&&(y=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:y,y:g}}}});function Au(e){const[t,n="center"]=e.split("-");return[t,n]}var ju=Cu,_u=Tu,Mu=Iu,Ru=Nu,nb="Portal",ns=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);At(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?si.createPortal(c.jsx(Se.div,{...r,ref:t}),i):null});ns.displayName=nb;function rb(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Zt=e=>{const{present:t,children:n}=e,r=ob(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=We(r.ref,sb(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Zt.displayName="Presence";function ob(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=rb(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=rs(r.current);s.current=a==="mounted"?u:"none"},[a]),At(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=rs(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),At(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const g=rs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},h=p=>{p.target===t&&(s.current=rs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function rs(e){return(e==null?void 0:e.animationName)||"none"}function sb(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 Vi="rovingFocusGroup.onEntryFocus",ib={bubbles:!1,cancelable:!0},Hr="RovingFocusGroup",[Ki,Pu,ab]=Ii(Hr),[lb,Ou]=kn(Hr,[ab]),[cb,ub]=lb(Hr),Du=m.forwardRef((e,t)=>c.jsx(Ki.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ki.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(db,{...e,ref:t})})}));Du.displayName=Hr;var db=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=We(t,h),y=Uo(s),[g,v]=mr({prop:i,defaultProp:a??null,onChange:l,caller:Hr}),[x,b]=m.useState(!1),k=jt(u),T=Pu(n),S=m.useRef(!1),[C,I]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Vi,k),()=>A.removeEventListener(Vi,k)},[k]),c.jsx(cb,{scope:n,orientation:r,dir:y,loop:o,currentTabStopId:g,onItemFocus:m.useCallback(A=>v(A),[v]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>I(A=>A-1),[]),children:c.jsx(Se.div,{tabIndex:x||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:fe(e.onMouseDown,()=>{S.current=!0}),onFocus:fe(e.onFocus,A=>{const R=!S.current;if(A.target===A.currentTarget&&R&&!x){const D=new CustomEvent(Vi,ib);if(A.currentTarget.dispatchEvent(D),!D.defaultPrevented){const B=T().filter(E=>E.focusable),X=B.find(E=>E.active),G=B.find(E=>E.id===g),U=[X,G,...B].filter(Boolean).map(E=>E.ref.current);Fu(U,d)}}S.current=!1}),onBlur:fe(e.onBlur,()=>b(!1))})})}),Lu="RovingFocusGroupItem",$u=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Ft(),u=s||l,d=ub(Lu,n),f=d.currentTabStopId===u,h=Pu(n),{onFocusableItemAdd:p,onFocusableItemRemove:y,currentTabStopId:g}=d;return m.useEffect(()=>{if(r)return p(),()=>y()},[r,p,y]),c.jsx(Ki.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Se.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:fe(e.onMouseDown,v=>{r?d.onItemFocus(u):v.preventDefault()}),onFocus:fe(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:fe(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const x=pb(v,d.orientation,d.dir);if(x!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let k=h().filter(T=>T.focusable).map(T=>T.ref.current);if(x==="last")k.reverse();else if(x==="prev"||x==="next"){x==="prev"&&k.reverse();const T=k.indexOf(v.currentTarget);k=d.loop?mb(k,T+1):k.slice(T+1)}setTimeout(()=>Fu(k))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});$u.displayName=Lu;var fb={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function hb(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pb(e,t,n){const r=hb(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fb[r]}function Fu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function mb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var gb=Du,xb=$u,yb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},br=new WeakMap,os=new WeakMap,ss={},qi=0,Bu=function(e){return e&&(e.host||Bu(e.parentNode))},vb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Bu(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})},bb=function(e,t,n,r){var o=vb(t,Array.isArray(e)?e:[e]);ss[n]||(ss[n]=new WeakMap);var s=ss[n],i=[],a=new Set,l=new Set(o),u=function(f){!f||a.has(f)||(a.add(f),u(f.parentNode))};o.forEach(u);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),y=p!==null&&p!=="false",g=(br.get(h)||0)+1,v=(s.get(h)||0)+1;br.set(h,g),s.set(h,v),i.push(h),g===1&&y&&os.set(h,!0),v===1&&h.setAttribute(n,"true"),y||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),qi++,function(){i.forEach(function(f){var h=br.get(f)-1,p=s.get(f)-1;br.set(f,h),s.set(f,p),h||(os.has(f)||f.removeAttribute(r),os.delete(f)),p||f.removeAttribute(n)}),qi--,qi||(br=new WeakMap,br=new WeakMap,os=new WeakMap,ss={})}},Gi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=yb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),bb(r,o,n,"aria-hidden")):function(){return null}},yn=function(){return yn=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},yn.apply(this,arguments)};function zu(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 wb(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 is="right-scroll-bar-position",as="width-before-scroll-bar",Sb="with-scroll-bars-hidden",Cb="--removed-body-scroll-bar-size";function Yi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function kb(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 Tb=typeof window<"u"?m.useLayoutEffect:m.useEffect,Uu=new WeakMap;function Ib(e,t){var n=kb(null,function(r){return e.forEach(function(o){return Yi(o,r)})});return Tb(function(){var r=Uu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Yi(a,null)}),s.forEach(function(a){o.has(a)||Yi(a,i)})}Uu.set(n,e)},[e]),n}function Eb(e){return e}function Nb(e,t){t===void 0&&(t=Eb);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function Ab(e){e===void 0&&(e={});var t=Nb(null);return t.options=yn({async:!0,ssr:!1},e),t}var Hu=function(e){var t=e.sideCar,n=zu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,yn({},n))};Hu.isSideCarExport=!0;function jb(e,t){return e.useMedium(t),Hu}var Wu=Ab(),Xi=function(){},ls=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Xi,onWheelCapture:Xi,onTouchMoveCapture:Xi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,y=e.noIsolation,g=e.inert,v=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,k=e.gapMode,T=zu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,C=Ib([n,t]),I=yn(yn({},T),o);return m.createElement(m.Fragment,null,d&&m.createElement(S,{sideCar:Wu,removeScrollBar:u,shards:f,noRelative:p,noIsolation:y,inert:g,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:k}),i?m.cloneElement(m.Children.only(a),yn(yn({},I),{ref:C})):m.createElement(b,yn({},I,{className:l,ref:C}),a))});ls.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ls.classNames={fullWidth:as,zeroRight:is};var _b=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Mb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=_b();return t&&e.setAttribute("nonce",t),e}function Rb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Pb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Ob=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Mb())&&(Rb(t,n),Pb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Db=function(){var e=Ob();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Vu=function(){var e=Db(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Lb={left:0,top:0,right:0,gap:0},Ji=function(e){return parseInt(e||"",10)||0},$b=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Ji(n),Ji(r),Ji(o)]},Fb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Lb;var t=$b(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])}},Bb=Vu(),wr="data-scroll-locked",zb=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(Sb,` {
37
+ `))>=0;){const se=lt.slice(0,_);lt=lt.slice(_+2);const pe=ty(se);if(!pe)continue;let We;try{We=JSON.parse(pe)}catch{console.debug("[use-chat] malformed SSE:",pe.slice(0,200));continue}const Pe=ey(We)?We.data:We;Ct=Date.now();const gt=Pe.seq;if(gt!==void 0){if(gt<=Oe){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:gt,lastProcessedSeq:Oe,type:Pe.type});continue}Oe>0&&gt>Oe+1&&((L=N==null?void 0:N.onGap)==null||L.call(N,{from:Oe,to:gt})),Oe=gt,S.current=gt,v(gt)}if(Pe.type==="checkpoint")E.current=Pe.checkpointId??null,A.current=Pe.checkpointNs??null,y(Pe.checkpointId??null);else if(Pe.type==="state_history"){P.current=Pe;try{const jt=fr(Pe).latest;jt&&(E.current=jt.checkpointId??null,A.current=jt.checkpointNs??null,y(jt.checkpointId??null))}catch(Ze){console.warn("[use-chat] Failed to hydrate state_history payload",Ze)}}try{U==null||U(Pe)}catch(Ze){console.error("[use-chat] Error in onEvent callback:",Ze,"for event:",Pe.type)}if(Pe.type==="message.delta"){const Ze=Pe.delta.filter(jt=>jt.type==="text").map(jt=>jt.text).join("");Ze&&e.autoAppendAssistant!==!1&&(ke.push(Ze),Et())}else if(Pe.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(q=N==null?void 0:N.onHeartbeat)==null||q.call(N,Pe)}catch(Ze){console.warn("[use-chat] heartbeat callback failed",Ze)}}else if(at!==null&&cancelAnimationFrame(at),pt(),Pe.type==="checkpoint")y(Pe.checkpointId);else if(Pe.type==="error"){const Ze=Pe;if(d(Ze.message),M="error",j=Ze.message,Ze.error_type==="auth_error"||Ze.code==="TOKEN_EXPIRED"||((z=Ze.message)==null?void 0:z.includes("token"))||((Z=Ze.message)==null?void 0:Z.includes("401"))||((X=Ze.message)==null?void 0:X.includes("unauthorized"))||((ge=Ze.message)==null?void 0:ge.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Ze.message);try{(le=N==null?void 0:N.onAuthError)==null||le.call(N,Ze.message)}catch(yo){console.warn("[use-chat] onAuthError handler failed",yo)}D.abort()}}}}pt(),M===null&&!D.signal.aborted&&(M="complete")}catch(Je){if(Je.name==="AbortError")M=M??"aborted";else{const Ke=Je.message||String(Je);M="error",j=Ke,d(Ke),(te=N==null?void 0:N.onError)==null||te.call(N,Ke)}}finally{try{await ot.cancel()}catch{}finally{(fe=ot.releaseLock)==null||fe.call(ot)}at!==null&&typeof window<"u"&&window.cancelAnimationFrame(at),clearInterval(Le)}}catch($e){if($e.name==="AbortError")M=M??"aborted";else{const Xe=$e.message||String($e);M="error",j=Xe,d(Xe),(ye=N==null?void 0:N.onError)==null||ye.call(N,Xe),H||((Me=N==null?void 0:N.onConnectionError)==null||Me.call(N,Xe),H=!0)}}finally{const $e=S.current,Xe=E.current,nt=A.current,Ve=P.current,qe=M??(D.signal.aborted?"aborted":j?"error":"complete");try{(Ne=N==null?void 0:N.onClosed)==null||Ne.call(N,{reason:qe,lastSeq:$e,lastCheckpointId:Xe,lastCheckpointNs:nt,lastStateHistory:Ve,error:j})}catch(ot){console.warn("[use-chat] onClosed callback failed",ot)}l(!1),b(!1),C.current=null,S.current=0,v(0),T.current=null}})(),{close:()=>D.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var O;k.current=!1,(O=C.current)==null||O.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:g,connected:x,stream:G,stop:V,clear:B,setToken:$}}function ey(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function ty(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 ny=["message.start","message.delta","message.end"],ry=["tool.start","tool.end","tool.progress"],oy=["thread_info","checkpoint"],sy=["error","interrupt","heartbeat","state_history","cancelled"],iy=[...ny,...ry,...oy,...sy],ay=new Set(iy);function ly(e){if(typeof e!="object"||e===null||typeof e.type!="string")return!1;const t=e.type;return ay.has(t)}const Mc=200;function cy({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:u,onToolEvent:d}){const f=w.useRef(null),h=w.useRef(null),p=w.useRef(new Map),y=w.useRef(null),g=w.useRef(null),v=w.useCallback(N=>{try{const D=globalThis.structuredClone;if(typeof D=="function")return D(N)}catch{}try{return JSON.parse(JSON.stringify(N))}catch{return N}},[]),x=w.useCallback((N,D)=>{if(!N)return;const M=p.current.get(N)??[],j=v(D),H=M.length>=Mc?[...M.slice(M.length-Mc+1),j]:[...M,j];p.current.set(N,H)},[v]),b=w.useCallback(N=>{N&&p.current.set(N,[])},[]),C=w.useCallback(N=>{const D=N??h.current;if(!D)return;const M=p.current.get(D);M!=null&&M.length&&M.forEach(j=>{try{n(j)}catch(H){console.error("[useChatStreamingService] Failed to replay buffered event",H)}})},[n]),k=w.useCallback(N=>{h.current=N.threadId,y.current&&(y.current.threadIdGuess=N.threadId),g.current=N,b(N.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",N);try{t(N)}catch(D){console.error("[useChatStreamingService] Error in onThreadInfo handler:",D)}},[b,t]),S=w.useCallback(N=>{try{u==null||u(N)}catch(D){console.error("[useChatStreamingService] Error in onHeartbeat handler:",D)}},[u]),T=w.useCallback(N=>{var j,H,W,R;const D=N;if(D.error_type==="auth_error"||D.code==="TOKEN_EXPIRED"||((j=D.message)==null?void 0:j.includes("token"))||((H=D.message)==null?void 0:H.includes("401"))||((W=D.message)==null?void 0:W.includes("unauthorized"))||((R=D.message)==null?void 0:R.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",D.message);try{l==null||l(D.message)}catch(K){console.warn("[useChatStreamingService] onAuthError handler failed",K)}}},[l]),E=w.useMemo(()=>({thread_info:N=>(k(N),!0),heartbeat:N=>(S(N),!0),error:N=>(T(N),!1)}),[k,S,T]),A=w.useCallback(N=>{var H;const D=N.seq??null;if(D!==null){const W=f.current;if(W!==null){if(D<=W)return;D>W+1&&(s==null||s({from:W,to:D}))}f.current=D}const M=E[N.type];if(M&&M(N))return;const j=N.threadId??(N.type==="state_history"?N.threadId:void 0)??h.current??((H=y.current)==null?void 0:H.threadIdGuess)??null;if(N.type==="state_history"){h.current=j??h.current;try{r==null||r(N)}catch(W){console.error("[useChatStreamingService] onStateHistory handler failed",W)}}if(ly(N)){(N.type==="tool.start"||N.type==="tool.end")&&(d==null||d(N)),N.type==="checkpoint"||N.type==="state_history"?b(j??null):x(j??null,N);try{n(N)}catch(W){console.error("[useChatStreamingService] Error in onMessageEvent handler:",W)}return}try{o==null||o(N)}catch(W){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",W)}},[x,b,n,s,r,o,E]),{stream:P,stop:$,isStreaming:B,error:V,setToken:G}=_c({baseUrl:e,token:void 0}),O=w.useCallback((N,D)=>{f.current=null,g.current=null,h.current=N.threadId??null,y.current={request:N,callbacks:D,manualStop:!1,threadIdGuess:N.threadId??null},P(N,A,{onOpen:D==null?void 0:D.onOpen,onError:M=>{var j;(j=D==null?void 0:D.onError)==null||j.call(D,M)},onGap:(D==null?void 0:D.onGap)??s,onConnectionError:M=>{var j;a==null||a(M),(j=D==null?void 0:D.onConnectionError)==null||j.call(D,M)},onAuthError:M=>{var j;l==null||l(M),(j=D==null?void 0:D.onAuthError)==null||j.call(D,M)},onHeartbeat:M=>{var j;try{u==null||u(M)}catch(H){console.warn("[useChatStreamingService] onHeartbeat handler failed",H)}try{(j=D==null?void 0:D.onHeartbeat)==null||j.call(D,M)}catch(H){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",H)}},onClosed:M=>{var R,K,ie,Q;const j=((R=y.current)==null?void 0:R.manualStop)??!1,H=h.current??((K=y.current)==null?void 0:K.threadIdGuess)??((ie=M.lastStateHistory)==null?void 0:ie.threadId)??null;(M.reason==="complete"||M.reason==="aborted"&&j)&&b(H);const W={...M,threadId:H,threadInfo:g.current,manualStop:j};try{i==null||i(W)}catch(oe){console.warn("[useChatStreamingService] onStreamClosed handler failed",oe)}try{(Q=D==null?void 0:D.onClosed)==null||Q.call(D,W)}catch(oe){console.warn("[useChatStreamingService] downstream onClosed handler failed",oe)}y.current&&(y.current=null)}})},[b,A,l,a,u,s,i,P]),U=w.useCallback(()=>{y.current&&(y.current.manualStop=!0),$()},[$]);return w.useMemo(()=>({startStream:O,stop:U,isStreaming:B,error:V,setAuthToken:G,replayBufferedEvents:C}),[O,U,B,V,G,C])}const Rc=w.createContext(null),Pc=w.createContext(null),Oc=w.createContext(null);w.createContext(!1);function uy({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:l,onToolEnd:u}){const{api:d,baseUrl:f}=wi(),h=w.useMemo(()=>Cn(f),[f]),{state:p,seed:y,prepend:g,pushUser:v,onEvent:x}=Ac(),{threads:b,currentThreadId:C,setCurrentThreadId:k,currentThreadIdRef:S,isLoadingThreads:T,threadsError:E,sharedThreads:A,isLoadingSharedThreads:P,actions:$,addThreadFromEvent:B,shareInFlight:V,shareStatus:G,clearShareStatus:O}=Lx({api:d,initialThreadId:t,onError:s,onThreadChange:a,onCurrentThreadDeleted:()=>y([],{})}),[U,N]=w.useState(!1),D=w.useCallback(()=>p.messages,[p.messages]),{threadCheckpoints:M,threadTimeline:j,isLoadingThread:H,isHistoryLoading:W,isLoadingCheckpoint:R,threadStateError:K,hasMoreHistory:ie,loadThread:Q,navigateToCheckpoint:oe,loadOlderMessages:Y,setCurrentCheckpointId:L,returnToLatest:q,handleStateHistoryEvent:z,markSkipNextLoad:Z,markStreamPendingThread:X,resetHistoryState:ge}=Px({api:d,seed:y,prepend:g,onError:s,currentThreadId:C,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:U,getMessages:D}),le=w.useMemo(()=>ux(M),[M]),te=w.useCallback(ke=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",ke.threadId),B(ke),S.current!==ke.threadId&&((ke.created??!S.current)&&Z(ke.threadId),X(ke.threadId),console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),k(ke.threadId))},[B,Z,X]),{startStream:fe,stop:ye,isStreaming:Me,error:Ne,setAuthToken:$e}=cy({baseUrl:h,onThreadInfo:te,onMessageEvent:x,onStateHistory:z,onUnhandledEvent:ke=>{console.warn("[ChatSessionProvider] Unhandled event:",ke.type)},onAuthError:i,onConnectionError:l,onToolEvent:ke=>{ke.type==="tool.end"&&(u==null||u(ke))}});w.useEffect(()=>{N(Me)},[Me]);const Xe=w.useCallback(async()=>{y([],{}),k(null),ye(),ge();try{await d.getAgent("default")}catch(ke){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",ke)}},[y,ye,d,ge]),nt=w.useCallback(async(ke,Oe,at)=>{const pt=S.current;if(!pt)throw new Error("No active thread to handle interrupt");const Et=Oe?at??!0:!1;try{const Ct={threadId:pt,checkpointId:p.lastCheckpointId??void 0,checkpointNs:p.lastCheckpointNs??void 0,command:{kind:"resume",value:Et}};fe(Ct)}catch(Ct){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${ke}:`,Ct),Ct}},[p.lastCheckpointId,p.lastCheckpointNs,fe]),Ve=w.useCallback(async(ke,Oe)=>{let at=S.current;const pt=(ke==null?void 0:ke.text)??"",Et=(ke==null?void 0:ke.attachments)??[],Ct=(pt==null?void 0:pt.trim())??"",Le={...(ke==null?void 0:ke.payload)??{}},Vt=Array.isArray(Le.messages)?Le.messages:void 0;Vt&&delete Le.messages;const Je=!!(Vt&&Vt.length);if(!at&&!Ct&&Et.length===0&&!Je)return;if(!at){const gt=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),Ze=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);at=`${gt}${Ze}`,Z(at),k(at)}const{contentParts:Ke,filesInfo:dt}=await ax(d,Et),bt=[...Ke];Ct&&bt.push({type:"text",text:pt});const He=Oe==null?void 0:Oe.originalMessageId,Tt=!!(Oe!=null&&Oe.edit&&He),_=!Je&&bt.length>0;let se=null;_&&(se={id:Tt?He:`msg-${Date.now()}`,role:"user",content:bt,createdAt:new Date().toISOString()},Tt?v(se,He):v(se));const pe=Je?Vt:se?[se]:[],We={...Le,...dt.length?{files_info:dt}:{}};pe.length?We.messages=pe:"messages"in We||(We.messages=[]);const Pe={threadId:at,payload:We,checkpointId:(Oe==null?void 0:Oe.checkpointId)??p.lastCheckpointId??void 0,checkpointNs:(Oe==null?void 0:Oe.checkpointNs)??p.lastCheckpointNs??void 0,edit:!!(Oe!=null&&Oe.edit),timelineCheckpoints:j};fe(Pe)},[d,v,p,fe,j]),qe=w.useMemo(()=>({threads:b,currentThreadId:C,setCurrentThreadId:k,isLoading:T,error:E,sharedThreads:A,isLoadingSharedThreads:P,actions:$,shareInFlight:V,shareStatus:G,clearShareStatus:O}),[b,C,k,T,E,A,P,$,V,G,O]),ot=w.useMemo(()=>{const ke=p.assemblingId??null;return ke?{assemblingMessageId:ke}:null},[p.assemblingId]),kt=w.useMemo(()=>({threadId:C,messages:p.messages,interrupt:null,checkpoint:{id:p.lastCheckpointId??null,namespace:p.lastCheckpointNs??null},checkpoints:M,timelineCheckpoints:j,metadata:ot,isLoading:H,isHistoryLoading:W,isLoadingCheckpoint:R,error:K,hasMore:ie,loadOlder:Y,clearState:Xe,navigateToCheckpoint:oe,setCurrentCheckpointId:L,returnToLatest:q,loadThread:Q,clearThread:Xe,respondToInterrupt:nt,messagePreviews:le}),[C,p,M,j,H,W,R,K,ie,Y,Xe,oe,L,q,Q,nt,le,ot]),lt=w.useMemo(()=>({isStreaming:Me,error:Ne,connectionState:Me?"connected":"idle",submit:Ve,send:Ve,stop:ye,setAuthToken:$e}),[Me,Ne,Ve,ye,$e]);return c.jsx(Rc.Provider,{value:qe,children:c.jsx(Pc.Provider,{value:kt,children:c.jsx(Oc.Provider,{value:lt,children:e})})})}function Fo(){const e=w.useContext(Rc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Bo(){const e=w.useContext(Pc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Dc(){const e=w.useContext(Oc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function zo({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:l,onThreadChange:u,onToolEnd:d}){return c.jsx(sx,{apiConfig:t,children:c.jsx(uy,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:a,onAuthError:l,onConnectionError:i,onThreadChange:u,onToolEnd:d,children:e})})}function ne(...e){return Mm.twMerge(_m.clsx(e))}const dy=bo.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"}}),et=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return c.jsx(i,{className:ne(dy({variant:t,size:n,className:e})),ref:s,...o})});et.displayName="Button";const Lc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:ne("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}));Lc.displayName="Textarea";function $c({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:u,onStop:d,className:f="",textareaClassName:h="",allowEmptySend:p=!1}){const y=i!==void 0,[g,v]=w.useState(e),x=(y?i:g)??"",[b,C]=w.useTransition(),k=w.useRef(null),S=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{y||(v(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,y]);const E=w.useCallback(()=>{const U=k.current;U&&(U.style.height="auto",U.style.height=`${U.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,x]);const A=w.useCallback((U,{fromUser:N})=>{y||v(U),N&&(a==null||a(U))},[y,a]),P=w.useCallback(async U=>{U&&U.preventDefault();const N=(x??"").trim();if(!N&&!p)return;const D=++S.current;T.current={id:D,shouldClear:!0},C(()=>{var M,j,H;try{const W=l(N);W&&typeof W.then=="function"?W.then(()=>{var R,K;((R=T.current)==null?void 0:R.id)===D&&T.current.shouldClear&&(y||(v(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((K=T.current)==null?void 0:K.id)===D&&(T.current=null)}).catch(()=>{var R;((R=T.current)==null?void 0:R.id)===D&&(T.current=null)}):(((M=T.current)==null?void 0:M.id)===D&&T.current.shouldClear&&(y||(v(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((j=T.current)==null?void 0:j.id)===D&&(T.current=null))}catch{((H=T.current)==null?void 0:H.id)===D&&(T.current=null)}})},[x,l,p,y,a]),$=w.useCallback(U=>{const N=U.target.value;A(N,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),B=w.useCallback(U=>{U.key==="Enter"&&!U.shiftKey?(U.preventDefault(),P()):U.key==="Escape"&&t&&(U.preventDefault(),u==null||u())},[P,t,u]),O=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return c.jsx("form",{onSubmit:U=>void P(U),className:`w-full ${f}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Lc,{ref:k,value:x,onChange:$,onKeyDown:B,placeholder:t?"Edit your message...":n,className:O,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(et,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:c.jsx(ae.Square,{size:16})}):c.jsx(et,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!x.trim()&&!p||b,children:c.jsx(ae.Send,{size:16})})})]})})}const fy=w.memo($c);function he(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 Fc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function An(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Fc(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():Fc(e[o],null)}}}}function ze(...e){return m.useCallback(An(...e),e)}function hy(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var x;const{scope:h,children:p,...y}=f,g=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,v=m.useMemo(()=>y,Object.values(y));return c.jsx(g.Provider,{value:v,children:p})};u.displayName=s+"Provider";function d(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[l])||a,y=m.useContext(p);if(y)return y;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,py(o,...t)]}function py(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Nt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},my=m[" useInsertionEffect ".trim().toString()]||Nt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=gy({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=xy(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function gy({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return my(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function xy(e){return typeof e=="function"}var yy=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],we=yy.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bc(e,t){e&&wo.flushSync(()=>e.dispatchEvent(t))}function Ei(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:v,children:x}=g,b=w.useRef(null),C=w.useRef(new Map).current;return c.jsx(o,{scope:v,itemMap:C,collectionRef:b,children:x})};i.displayName=t;const a=e+"CollectionSlot",l=Wn.createSlot(a),u=w.forwardRef((g,v)=>{const{scope:x,children:b}=g,C=s(a,x),k=ze(v,C.collectionRef);return c.jsx(l,{ref:k,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=Wn.createSlot(d),p=w.forwardRef((g,v)=>{const{scope:x,children:b,...C}=g,k=w.useRef(null),S=ze(v,k),T=s(d,x);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...C}),()=>void T.itemMap.delete(k))),c.jsx(h,{[f]:"",ref:S,children:b})});p.displayName=d;function y(g){const v=s(e+"CollectionConsumer",g);return w.useCallback(()=>{const b=v.collectionRef.current;if(!b)return[];const C=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(v.itemMap.values()).sort((T,E)=>C.indexOf(T.ref.current)-C.indexOf(E.ref.current))},[v.collectionRef,v.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},y,r]}var vy=m.createContext(void 0);function Uo(e){const t=m.useContext(vy);return e||t||"ltr"}function At(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function by(e,t=globalThis==null?void 0:globalThis.document){const n=At(e);m.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var wy="DismissableLayer",Ii="dismissableLayer.update",Sy="dismissableLayer.pointerDownOutside",Cy="dismissableLayer.focusOutside",zc,Uc=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ho=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(Uc),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),y=ze(t,E=>f(E)),g=Array.from(u.layers),[v]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=g.indexOf(v),b=d?g.indexOf(d):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,k=b>=x,S=Ey(E=>{const A=E.target,P=[...u.branches].some($=>$.contains(A));!k||P||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),T=Iy(E=>{const A=E.target;[...u.branches].some($=>$.contains(A))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return by(E=>{b===u.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(zc=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),Hc(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=zc)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),Hc())},[d,u]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(Ii,E),()=>document.removeEventListener(Ii,E)},[]),c.jsx(we.div,{...l,ref:y,style:{pointerEvents:C?k?"auto":"none":void 0,...e.style},onFocusCapture:he(e.onFocusCapture,T.onFocusCapture),onBlurCapture:he(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:he(e.onPointerDownCapture,S.onPointerDownCapture)})});Ho.displayName=wy;var Ty="DismissableLayerBranch",ky=m.forwardRef((e,t)=>{const n=m.useContext(Uc),r=m.useRef(null),o=ze(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(we.div,{...e,ref:o})});ky.displayName=Ty;function Ey(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Wc(Sy,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Iy(e,t=globalThis==null?void 0:globalThis.document){const n=At(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&Wc(Cy,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 Hc(){const e=new CustomEvent(Ii);document.dispatchEvent(e)}function Wc(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?Bc(o,s):o.dispatchEvent(s)}var Ni=0;function Ai(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Vc()),document.body.insertAdjacentElement("beforeend",e[1]??Vc()),Ni++,()=>{Ni===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ni--}},[])}function Vc(){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 ji="focusScope.autoFocusOnMount",_i="focusScope.autoFocusOnUnmount",Kc={bubbles:!1,cancelable:!0},Ny="FocusScope",Wo=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=At(o),d=At(s),f=m.useRef(null),h=ze(t,g=>l(g)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let g=function(C){if(p.paused||!a)return;const k=C.target;a.contains(k)?f.current=k:jn(f.current,{select:!0})},v=function(C){if(p.paused||!a)return;const k=C.relatedTarget;k!==null&&(a.contains(k)||jn(f.current,{select:!0}))},x=function(C){if(document.activeElement===document.body)for(const S of C)S.removedNodes.length>0&&jn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",v);const b=new MutationObserver(x);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",v),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){Yc.add(p);const g=document.activeElement;if(!a.contains(g)){const x=new CustomEvent(ji,Kc);a.addEventListener(ji,u),a.dispatchEvent(x),x.defaultPrevented||(Ay(Py(qc(a)),{select:!0}),document.activeElement===g&&jn(a))}return()=>{a.removeEventListener(ji,u),setTimeout(()=>{const x=new CustomEvent(_i,Kc);a.addEventListener(_i,d),a.dispatchEvent(x),x.defaultPrevented||jn(g??document.body,{select:!0}),a.removeEventListener(_i,d),Yc.remove(p)},0)}}},[a,u,d,p]);const y=m.useCallback(g=>{if(!n&&!r||p.paused)return;const v=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,x=document.activeElement;if(v&&x){const b=g.currentTarget,[C,k]=jy(b);C&&k?!g.shiftKey&&x===k?(g.preventDefault(),n&&jn(C,{select:!0})):g.shiftKey&&x===C&&(g.preventDefault(),n&&jn(k,{select:!0})):x===b&&g.preventDefault()}},[n,r,p.paused]);return c.jsx(we.div,{tabIndex:-1,...i,ref:h,onKeyDown:y})});Wo.displayName=Ny;function Ay(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(jn(r,{select:t}),document.activeElement!==n)return}function jy(e){const t=qc(e),n=Gc(t,e),r=Gc(t.reverse(),e);return[n,r]}function qc(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 Gc(e,t){for(const n of e)if(!_y(n,{upTo:t}))return n}function _y(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 My(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&&My(e)&&t&&e.select()}}var Yc=Ry();function Ry(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Xc(e,t),e.unshift(t)},remove(t){var n;e=Xc(e,t),(n=e[0])==null||n.resume()}}}function Xc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Py(e){return e.filter(t=>t.tagName!=="A")}var Oy=m[" useId ".trim().toString()]||(()=>{}),Dy=0;function $t(e){const[t,n]=m.useState(Oy());return Nt(()=>{n(r=>r??String(Dy++))},[e]),t?`radix-${t}`:""}const Ly=["top","right","bottom","left"],_n=Math.min,qt=Math.max,Vo=Math.round,Ko=Math.floor,pn=e=>({x:e,y:e}),$y={left:"right",right:"left",bottom:"top",top:"bottom"},Fy={start:"end",end:"start"};function Mi(e,t,n){return qt(e,_n(t,n))}function kn(e,t){return typeof e=="function"?e(t):e}function En(e){return e.split("-")[0]}function mr(e){return e.split("-")[1]}function Ri(e){return e==="x"?"y":"x"}function Pi(e){return e==="y"?"height":"width"}const By=new Set(["top","bottom"]);function mn(e){return By.has(En(e))?"y":"x"}function Oi(e){return Ri(mn(e))}function zy(e,t,n){n===void 0&&(n=!1);const r=mr(e),o=Oi(e),s=Pi(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=qo(i)),[i,qo(i)]}function Uy(e){const t=qo(e);return[Di(e),t,Di(t)]}function Di(e){return e.replace(/start|end/g,t=>Fy[t])}const Jc=["left","right"],Zc=["right","left"],Hy=["top","bottom"],Wy=["bottom","top"];function Vy(e,t,n){switch(e){case"top":case"bottom":return n?t?Zc:Jc:t?Jc:Zc;case"left":case"right":return t?Hy:Wy;default:return[]}}function Ky(e,t,n,r){const o=mr(e);let s=Vy(En(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Di)))),s}function qo(e){return e.replace(/left|right|bottom|top/g,t=>$y[t])}function qy(e){return{top:0,right:0,bottom:0,left:0,...e}}function Qc(e){return typeof e!="number"?qy(e):{top:e,right:e,bottom:e,left:e}}function Go(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 eu(e,t,n){let{reference:r,floating:o}=e;const s=mn(t),i=Oi(t),a=Pi(i),l=En(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(mr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Gy=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=eu(u,r,l),h=r,p={},y=0;for(let g=0;g<a.length;g++){const{name:v,fn:x}=a[g],{x:b,y:C,data:k,reset:S}=await x({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=C??f,p={...p,[v]:{...p[v],...k}},S&&y<=50&&(y++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(u=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:d,y:f}=eu(u,h,l)),g=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Fr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=kn(t,e),y=Qc(p),v=a[h?f==="floating"?"reference":"floating":f],x=Go(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},S=Go(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(x.top-S.top+y.top)/k.y,bottom:(S.bottom-x.bottom+y.bottom)/k.y,left:(x.left-S.left+y.left)/k.x,right:(S.right-x.right+y.right)/k.x}}const Yy=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=kn(e,t)||{};if(u==null)return{};const f=Qc(d),h={x:n,y:r},p=Oi(o),y=Pi(p),g=await i.getDimensions(u),v=p==="y",x=v?"top":"left",b=v?"bottom":"right",C=v?"clientHeight":"clientWidth",k=s.reference[y]+s.reference[p]-h[p]-s.floating[y],S=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=T?T[C]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[C]||s.floating[y]);const A=k/2-S/2,P=E/2-g[y]/2-1,$=_n(f[x],P),B=_n(f[b],P),V=$,G=E-g[y]-B,O=E/2-g[y]/2+A,U=Mi(V,O,G),N=!l.arrow&&mr(o)!=null&&O!==U&&s.reference[y]/2-(O<V?$:B)-g[y]/2<0,D=N?O<V?O-V:O-G:0;return{[p]:h[p]+D,data:{[p]:U,centerOffset:O-U-D,...N&&{alignmentOffset:D}},reset:N}}}),Xy=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:g=!0,...v}=kn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=En(o),b=mn(a),C=En(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(u.floating)),S=h||(C||!g?[qo(a)]:Uy(a)),T=y!=="none";!h&&T&&S.push(...Ky(a,g,y,k));const E=[a,...S],A=await Fr(t,v),P=[];let $=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&P.push(A[x]),f){const O=zy(o,i,k);P.push(A[O[0]],A[O[1]])}if($=[...$,{placement:o,overflows:P}],!P.every(O=>O<=0)){var B,V;const O=(((B=s.flip)==null?void 0:B.index)||0)+1,U=E[O];if(U&&(!(f==="alignment"?b!==mn(U):!1)||$.every(M=>mn(M.placement)===b?M.overflows[0]>0:!0)))return{data:{index:O,overflows:$},reset:{placement:U}};let N=(V=$.filter(D=>D.overflows[0]<=0).sort((D,M)=>D.overflows[1]-M.overflows[1])[0])==null?void 0:V.placement;if(!N)switch(p){case"bestFit":{var G;const D=(G=$.filter(M=>{if(T){const j=mn(M.placement);return j===b||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,H)=>j+H,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:G[0];D&&(N=D);break}case"initialPlacement":N=a;break}if(o!==N)return{reset:{placement:N}}}return{}}}};function tu(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nu(e){return Ly.some(t=>e[t]>=0)}const Jy=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 Fr(t,{...o,elementContext:"reference"}),i=tu(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nu(i)}}}case"escaped":{const s=await Fr(t,{...o,altBoundary:!0}),i=tu(s,n.floating);return{data:{escapedOffsets:i,escaped:nu(i)}}}default:return{}}}}},ru=new Set(["left","top"]);async function Zy(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=mr(n),l=mn(n)==="y",u=ru.has(i)?-1:1,d=s&&l?-1:1,f=kn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:y}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof y=="number"&&(p=a==="end"?y*-1:y),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const Qy=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 Zy(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}}}}},ev=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x,y:b}=v;return{x,y:b}}},...l}=kn(e,t),u={x:n,y:r},d=await Fr(t,l),f=mn(En(o)),h=Ri(f);let p=u[h],y=u[f];if(s){const v=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=p+d[v],C=p-d[x];p=Mi(b,p,C)}if(i){const v=f==="y"?"top":"left",x=f==="y"?"bottom":"right",b=y+d[v],C=y-d[x];y=Mi(b,y,C)}const g=a.fn({...t,[h]:p,[f]:y});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},tv=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=kn(e,t),d={x:n,y:r},f=mn(o),h=Ri(f);let p=d[h],y=d[f];const g=kn(a,t),v=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=h==="y"?"height":"width",k=s.reference[h]-s.floating[C]+v.mainAxis,S=s.reference[h]+s.reference[C]-v.mainAxis;p<k?p=k:p>S&&(p=S)}if(u){var x,b;const C=h==="y"?"width":"height",k=ru.has(En(o)),S=s.reference[f]-s.floating[C]+(k&&((x=i.offset)==null?void 0:x[f])||0)+(k?0:v.crossAxis),T=s.reference[f]+s.reference[C]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?v.crossAxis:0);y<S?y=S:y>T&&(y=T)}return{[h]:p,[f]:y}}}},nv=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=kn(e,t),d=await Fr(t,u),f=En(o),h=mr(o),p=mn(o)==="y",{width:y,height:g}=s.floating;let v,x;f==="top"||f==="bottom"?(v=f,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=f,v=h==="end"?"top":"bottom");const b=g-d.top-d.bottom,C=y-d.left-d.right,k=_n(g-d[v],b),S=_n(y-d[x],C),T=!t.middlewareData.shift;let E=k,A=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!h){const $=qt(d.left,0),B=qt(d.right,0),V=qt(d.top,0),G=qt(d.bottom,0);p?A=y-2*($!==0||B!==0?$+B:qt(d.left,d.right)):E=g-2*(V!==0||G!==0?V+G:qt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:E});const P=await i.getDimensions(a.floating);return y!==P.width||g!==P.height?{reset:{rects:!0}}:{}}}};function Yo(){return typeof window<"u"}function gr(e){return ou(e)?(e.nodeName||"").toLowerCase():"#document"}function Gt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function gn(e){var t;return(t=(ou(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function ou(e){return Yo()?e instanceof Node||e instanceof Gt(e).Node:!1}function an(e){return Yo()?e instanceof Element||e instanceof Gt(e).Element:!1}function xn(e){return Yo()?e instanceof HTMLElement||e instanceof Gt(e).HTMLElement:!1}function su(e){return!Yo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Gt(e).ShadowRoot}const rv=new Set(["inline","contents"]);function Br(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=ln(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!rv.has(o)}const ov=new Set(["table","td","th"]);function sv(e){return ov.has(gr(e))}const iv=[":popover-open",":modal"];function Xo(e){return iv.some(t=>{try{return e.matches(t)}catch{return!1}})}const av=["transform","translate","scale","rotate","perspective"],lv=["transform","translate","scale","rotate","perspective","filter"],cv=["paint","layout","strict","content"];function Li(e){const t=$i(),n=an(e)?ln(e):e;return av.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)||lv.some(r=>(n.willChange||"").includes(r))||cv.some(r=>(n.contain||"").includes(r))}function uv(e){let t=Mn(e);for(;xn(t)&&!xr(t);){if(Li(t))return t;if(Xo(t))return null;t=Mn(t)}return null}function $i(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const dv=new Set(["html","body","#document"]);function xr(e){return dv.has(gr(e))}function ln(e){return Gt(e).getComputedStyle(e)}function Jo(e){return an(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Mn(e){if(gr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||su(e)&&e.host||gn(e);return su(t)?t.host:t}function iu(e){const t=Mn(e);return xr(t)?e.ownerDocument?e.ownerDocument.body:e.body:xn(t)&&Br(t)?t:iu(t)}function zr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=iu(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Gt(o);if(s){const a=Fi(i);return t.concat(i,i.visualViewport||[],Br(o)?o:[],a&&n?zr(a):[])}return t.concat(o,zr(o,[],n))}function Fi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function au(e){const t=ln(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=xn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Vo(n)!==s||Vo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Bi(e){return an(e)?e:e.contextElement}function yr(e){const t=Bi(e);if(!xn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=au(t);let i=(s?Vo(n.width):n.width)/r,a=(s?Vo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const fv=pn(0);function lu(e){const t=Gt(e);return!$i()||!t.visualViewport?fv:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function hv(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Gt(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Bi(e);let i=pn(1);t&&(r?an(r)&&(i=yr(r)):i=yr(e));const a=hv(s,n,r)?lu(s):pn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Gt(s),p=r&&an(r)?Gt(r):r;let y=h,g=Fi(y);for(;g&&r&&p!==y;){const v=yr(g),x=g.getBoundingClientRect(),b=ln(g),C=x.left+(g.clientLeft+parseFloat(b.paddingLeft))*v.x,k=x.top+(g.clientTop+parseFloat(b.paddingTop))*v.y;l*=v.x,u*=v.y,d*=v.x,f*=v.y,l+=C,u+=k,y=Gt(g),g=Fi(y)}}return Go({width:d,height:f,x:l,y:u})}function Zo(e,t){const n=Jo(e).scrollLeft;return t?t.left+n:Gn(gn(e)).left+n}function cu(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Zo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function pv(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=gn(r),a=t?Xo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=pn(1);const d=pn(0),f=xn(r);if((f||!f&&!s)&&((gr(r)!=="body"||Br(i))&&(l=Jo(r)),xn(r))){const p=Gn(r);u=yr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?cu(i,l):pn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function mv(e){return Array.from(e.getClientRects())}function gv(e){const t=gn(e),n=Jo(e),r=e.ownerDocument.body,o=qt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=qt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Zo(e);const a=-n.scrollTop;return ln(r).direction==="rtl"&&(i+=qt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const uu=25;function xv(e,t){const n=Gt(e),r=gn(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=$i();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Zo(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,y=Math.abs(r.clientWidth-f.clientWidth-p);y<=uu&&(s-=y)}else u<=uu&&(s+=u);return{width:s,height:i,x:a,y:l}}const yv=new Set(["absolute","fixed"]);function vv(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=xn(e)?yr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function du(e,t,n){let r;if(t==="viewport")r=xv(e,n);else if(t==="document")r=gv(gn(e));else if(an(t))r=vv(t,n);else{const o=lu(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Go(r)}function fu(e,t){const n=Mn(e);return n===t||!an(n)||xr(n)?!1:ln(n).position==="fixed"||fu(n,t)}function bv(e,t){const n=t.get(e);if(n)return n;let r=zr(e,[],!1).filter(a=>an(a)&&gr(a)!=="body"),o=null;const s=ln(e).position==="fixed";let i=s?Mn(e):e;for(;an(i)&&!xr(i);){const a=ln(i),l=Li(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&yv.has(o.position)||Br(i)&&!l&&fu(e,i))?r=r.filter(d=>d!==i):o=a,i=Mn(i)}return t.set(e,r),r}function wv(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Xo(t)?[]:bv(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=du(t,d,o);return u.top=qt(f.top,u.top),u.right=_n(f.right,u.right),u.bottom=_n(f.bottom,u.bottom),u.left=qt(f.left,u.left),u},du(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Sv(e){const{width:t,height:n}=au(e);return{width:t,height:n}}function Cv(e,t,n){const r=xn(t),o=gn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function u(){l.x=Zo(o)}if(r||!r&&!s)if((gr(t)!=="body"||Br(o))&&(a=Jo(t)),r){const p=Gn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?cu(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function zi(e){return ln(e).position==="static"}function hu(e,t){if(!xn(e)||ln(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return gn(e)===n&&(n=n.ownerDocument.body),n}function pu(e,t){const n=Gt(e);if(Xo(e))return n;if(!xn(e)){let o=Mn(e);for(;o&&!xr(o);){if(an(o)&&!zi(o))return o;o=Mn(o)}return n}let r=hu(e,t);for(;r&&sv(r)&&zi(r);)r=hu(r,t);return r&&xr(r)&&zi(r)&&!Li(r)?n:r||uv(e)||n}const Tv=async function(e){const t=this.getOffsetParent||pu,n=this.getDimensions,r=await n(e.floating);return{reference:Cv(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function kv(e){return ln(e).direction==="rtl"}const Ev={convertOffsetParentRelativeRectToViewportRelativeRect:pv,getDocumentElement:gn,getClippingRect:wv,getOffsetParent:pu,getElementRects:Tv,getClientRects:mv,getDimensions:Sv,getScale:yr,isElement:an,isRTL:kv};function mu(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Iv(e,t){let n=null,r;const o=gn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const y=Ko(f),g=Ko(o.clientWidth-(d+h)),v=Ko(o.clientHeight-(f+p)),x=Ko(d),C={rootMargin:-y+"px "+-g+"px "+-v+"px "+-x+"px",threshold:qt(0,_n(1,l))||1};let k=!0;function S(T){const E=T[0].intersectionRatio;if(E!==l){if(!k)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!mu(u,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(S,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,C)}n.observe(e)}return i(!0),s}function Nv(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Bi(e),d=o||s?[...u?zr(u):[],...zr(t)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const f=u&&a?Iv(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(x=>{let[b]=x;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let y,g=l?Gn(e):null;l&&v();function v(){const x=Gn(e);g&&!mu(g,x)&&n(),g=x,y=requestAnimationFrame(v)}return n(),()=>{var x;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(x=p)==null||x.disconnect(),p=null,l&&cancelAnimationFrame(y)}}const Av=Qy,jv=ev,_v=Xy,Mv=nv,Rv=Jy,gu=Yy,Pv=tv,Ov=(e,t,n)=>{const r=new Map,o={platform:Ev,...n},s={...o.platform,_c:r};return Gy(e,t,{...o,platform:s})};var Dv=typeof document<"u",Lv=function(){},Qo=Dv?w.useLayoutEffect:Lv;function es(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(!es(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)&&!es(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function xu(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function yu(e,t){const n=xu(e);return Math.round(t*n)/n}function Ui(e){const t=m.useRef(e);return Qo(()=>{t.current=e}),t}function $v(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);es(h,r)||p(r);const[y,g]=m.useState(null),[v,x]=m.useState(null),b=m.useCallback(M=>{M!==T.current&&(T.current=M,g(M))},[]),C=m.useCallback(M=>{M!==E.current&&(E.current=M,x(M))},[]),k=s||y,S=i||v,T=m.useRef(null),E=m.useRef(null),A=m.useRef(d),P=l!=null,$=Ui(l),B=Ui(o),V=Ui(u),G=m.useCallback(()=>{if(!T.current||!E.current)return;const M={placement:t,strategy:n,middleware:h};B.current&&(M.platform=B.current),Ov(T.current,E.current,M).then(j=>{const H={...j,isPositioned:V.current!==!1};O.current&&!es(A.current,H)&&(A.current=H,wo.flushSync(()=>{f(H)}))})},[h,t,n,B,V]);Qo(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(M=>({...M,isPositioned:!1})))},[u]);const O=m.useRef(!1);Qo(()=>(O.current=!0,()=>{O.current=!1}),[]),Qo(()=>{if(k&&(T.current=k),S&&(E.current=S),k&&S){if($.current)return $.current(k,S,G);G()}},[k,S,G,$,P]);const U=m.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:C}),[b,C]),N=m.useMemo(()=>({reference:k,floating:S}),[k,S]),D=m.useMemo(()=>{const M={position:n,left:0,top:0};if(!N.floating)return M;const j=yu(N.floating,d.x),H=yu(N.floating,d.y);return a?{...M,transform:"translate("+j+"px, "+H+"px)",...xu(N.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:j,top:H}},[n,a,N.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:G,refs:U,elements:N,floatingStyles:D}),[d,G,U,N,D])}const Fv=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?gu({element:r.current,padding:o}).fn(n):{}:r?gu({element:r,padding:o}).fn(n):{}}}},Bv=(e,t)=>({...Av(e),options:[e,t]}),zv=(e,t)=>({...jv(e),options:[e,t]}),Uv=(e,t)=>({...Pv(e),options:[e,t]}),Hv=(e,t)=>({..._v(e),options:[e,t]}),Wv=(e,t)=>({...Mv(e),options:[e,t]}),Vv=(e,t)=>({...Rv(e),options:[e,t]}),Kv=(e,t)=>({...Fv(e),options:[e,t]});var qv="Arrow",vu=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(we.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});vu.displayName=qv;var Gv=vu;function bu(e){const[t,n]=m.useState(void 0);return Nt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Hi="Popper",[wu,ts]=Tn(Hi),[Yv,Su]=wu(Hi),Cu=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(Yv,{scope:t,anchor:r,onAnchorChange:o,children:n})};Cu.displayName=Hi;var Tu="PopperAnchor",ku=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Su(Tu,n),i=m.useRef(null),a=ze(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(we.div,{...o,ref:a})});ku.displayName=Tu;var Wi="PopperContent",[Xv,Jv]=wu(Wi),Eu=m.forwardRef((e,t)=>{var Y,L,q,z,Z,X;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:y,...g}=e,v=Su(Wi,n),[x,b]=m.useState(null),C=ze(t,ge=>b(ge)),[k,S]=m.useState(null),T=bu(k),E=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,P=r+(s!=="center"?"-"+s:""),$=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},B=Array.isArray(u)?u:[u],V=B.length>0,G={padding:$,boundary:B.filter(Qv),altBoundary:V},{refs:O,floatingStyles:U,placement:N,isPositioned:D,middlewareData:M}=$v({strategy:"fixed",placement:P,whileElementsMounted:(...ge)=>Nv(...ge,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[Bv({mainAxis:o+A,alignmentAxis:i}),l&&zv({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Uv():void 0,...G}),l&&Hv({...G}),Wv({...G,apply:({elements:ge,rects:le,availableWidth:te,availableHeight:fe})=>{const{width:ye,height:Me}=le.reference,Ne=ge.floating.style;Ne.setProperty("--radix-popper-available-width",`${te}px`),Ne.setProperty("--radix-popper-available-height",`${fe}px`),Ne.setProperty("--radix-popper-anchor-width",`${ye}px`),Ne.setProperty("--radix-popper-anchor-height",`${Me}px`)}}),k&&Kv({element:k,padding:a}),eb({arrowWidth:E,arrowHeight:A}),h&&Vv({strategy:"referenceHidden",...G})]}),[j,H]=Au(N),W=At(y);Nt(()=>{D&&(W==null||W())},[D,W]);const R=(Y=M.arrow)==null?void 0:Y.x,K=(L=M.arrow)==null?void 0:L.y,ie=((q=M.arrow)==null?void 0:q.centerOffset)!==0,[Q,oe]=m.useState();return Nt(()=>{x&&oe(window.getComputedStyle(x).zIndex)},[x]),c.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:D?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Q,"--radix-popper-transform-origin":[(z=M.transformOrigin)==null?void 0:z.x,(Z=M.transformOrigin)==null?void 0:Z.y].join(" "),...((X=M.hide)==null?void 0:X.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(Xv,{scope:n,placedSide:j,onArrowChange:S,arrowX:R,arrowY:K,shouldHideArrow:ie,children:c.jsx(we.div,{"data-side":j,"data-align":H,...g,ref:C,style:{...g.style,animation:D?void 0:"none"}})})})});Eu.displayName=Wi;var Iu="PopperArrow",Zv={top:"bottom",right:"left",bottom:"top",left:"right"},Nu=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Jv(Iu,r),i=Zv[s.placedSide];return c.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:c.jsx(Gv,{...o,ref:n,style:{...o.style,display:"block"}})})});Nu.displayName=Iu;function Qv(e){return e!==null}var eb=e=>({name:"transformOrigin",options:e,fn(t){var v,x,b;const{placement:n,rects:r,middlewareData:o}=t,i=((v=o.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Au(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((x=o.arrow)==null?void 0:x.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let y="",g="";return u==="bottom"?(y=i?f:`${h}px`,g=`${-l}px`):u==="top"?(y=i?f:`${h}px`,g=`${r.floating.height+l}px`):u==="right"?(y=`${-l}px`,g=i?f:`${p}px`):u==="left"&&(y=`${r.floating.width+l}px`,g=i?f:`${p}px`),{data:{x:y,y:g}}}});function Au(e){const[t,n="center"]=e.split("-");return[t,n]}var ju=Cu,_u=ku,Mu=Eu,Ru=Nu,tb="Portal",ns=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);Nt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?si.createPortal(c.jsx(we.div,{...r,ref:t}),i):null});ns.displayName=tb;function nb(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Zt=e=>{const{present:t,children:n}=e,r=rb(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=ze(r.ref,ob(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Zt.displayName="Presence";function rb(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=nb(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=rs(r.current);s.current=a==="mounted"?u:"none"},[a]),Nt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=rs(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Nt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const g=rs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},h=p=>{p.target===t&&(s.current=rs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function rs(e){return(e==null?void 0:e.animationName)||"none"}function ob(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 Vi="rovingFocusGroup.onEntryFocus",sb={bubbles:!1,cancelable:!0},Ur="RovingFocusGroup",[Ki,Pu,ib]=Ei(Ur),[ab,Ou]=Tn(Ur,[ib]),[lb,cb]=ab(Ur),Du=m.forwardRef((e,t)=>c.jsx(Ki.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ki.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(ub,{...e,ref:t})})}));Du.displayName=Ur;var ub=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=ze(t,h),y=Uo(s),[g,v]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Ur}),[x,b]=m.useState(!1),C=At(u),k=Pu(n),S=m.useRef(!1),[T,E]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Vi,C),()=>A.removeEventListener(Vi,C)},[C]),c.jsx(lb,{scope:n,orientation:r,dir:y,loop:o,currentTabStopId:g,onItemFocus:m.useCallback(A=>v(A),[v]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>E(A=>A-1),[]),children:c.jsx(we.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:he(e.onMouseDown,()=>{S.current=!0}),onFocus:he(e.onFocus,A=>{const P=!S.current;if(A.target===A.currentTarget&&P&&!x){const $=new CustomEvent(Vi,sb);if(A.currentTarget.dispatchEvent($),!$.defaultPrevented){const B=k().filter(N=>N.focusable),V=B.find(N=>N.active),G=B.find(N=>N.id===g),U=[V,G,...B].filter(Boolean).map(N=>N.ref.current);Fu(U,d)}}S.current=!1}),onBlur:he(e.onBlur,()=>b(!1))})})}),Lu="RovingFocusGroupItem",$u=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=$t(),u=s||l,d=cb(Lu,n),f=d.currentTabStopId===u,h=Pu(n),{onFocusableItemAdd:p,onFocusableItemRemove:y,currentTabStopId:g}=d;return m.useEffect(()=>{if(r)return p(),()=>y()},[r,p,y]),c.jsx(Ki.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(we.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:he(e.onMouseDown,v=>{r?d.onItemFocus(u):v.preventDefault()}),onFocus:he(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:he(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const x=hb(v,d.orientation,d.dir);if(x!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let C=h().filter(k=>k.focusable).map(k=>k.ref.current);if(x==="last")C.reverse();else if(x==="prev"||x==="next"){x==="prev"&&C.reverse();const k=C.indexOf(v.currentTarget);C=d.loop?pb(C,k+1):C.slice(k+1)}setTimeout(()=>Fu(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});$u.displayName=Lu;var db={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function fb(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function hb(e,t,n){const r=fb(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return db[r]}function Fu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function pb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var mb=Du,gb=$u,xb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},vr=new WeakMap,os=new WeakMap,ss={},qi=0,Bu=function(e){return e&&(e.host||Bu(e.parentNode))},yb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Bu(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})},vb=function(e,t,n,r){var o=yb(t,Array.isArray(e)?e:[e]);ss[n]||(ss[n]=new WeakMap);var s=ss[n],i=[],a=new Set,l=new Set(o),u=function(f){!f||a.has(f)||(a.add(f),u(f.parentNode))};o.forEach(u);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),y=p!==null&&p!=="false",g=(vr.get(h)||0)+1,v=(s.get(h)||0)+1;vr.set(h,g),s.set(h,v),i.push(h),g===1&&y&&os.set(h,!0),v===1&&h.setAttribute(n,"true"),y||h.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),a.clear(),qi++,function(){i.forEach(function(f){var h=vr.get(f)-1,p=s.get(f)-1;vr.set(f,h),s.set(f,p),h||(os.has(f)||f.removeAttribute(r),os.delete(f)),p||f.removeAttribute(n)}),qi--,qi||(vr=new WeakMap,vr=new WeakMap,os=new WeakMap,ss={})}},Gi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=xb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),vb(r,o,n,"aria-hidden")):function(){return null}},yn=function(){return yn=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},yn.apply(this,arguments)};function zu(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 bb(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 is="right-scroll-bar-position",as="width-before-scroll-bar",wb="with-scroll-bars-hidden",Sb="--removed-body-scroll-bar-size";function Yi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Cb(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 Tb=typeof window<"u"?m.useLayoutEffect:m.useEffect,Uu=new WeakMap;function kb(e,t){var n=Cb(null,function(r){return e.forEach(function(o){return Yi(o,r)})});return Tb(function(){var r=Uu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Yi(a,null)}),s.forEach(function(a){o.has(a)||Yi(a,i)})}Uu.set(n,e)},[e]),n}function Eb(e){return e}function Ib(e,t){t===void 0&&(t=Eb);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function Nb(e){e===void 0&&(e={});var t=Ib(null);return t.options=yn({async:!0,ssr:!1},e),t}var Hu=function(e){var t=e.sideCar,n=zu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return m.createElement(r,yn({},n))};Hu.isSideCarExport=!0;function Ab(e,t){return e.useMedium(t),Hu}var Wu=Nb(),Xi=function(){},ls=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Xi,onWheelCapture:Xi,onTouchMoveCapture:Xi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,y=e.noIsolation,g=e.inert,v=e.allowPinchZoom,x=e.as,b=x===void 0?"div":x,C=e.gapMode,k=zu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,T=kb([n,t]),E=yn(yn({},k),o);return m.createElement(m.Fragment,null,d&&m.createElement(S,{sideCar:Wu,removeScrollBar:u,shards:f,noRelative:p,noIsolation:y,inert:g,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:C}),i?m.cloneElement(m.Children.only(a),yn(yn({},E),{ref:T})):m.createElement(b,yn({},E,{className:l,ref:T}),a))});ls.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ls.classNames={fullWidth:as,zeroRight:is};var jb=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function _b(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=jb();return t&&e.setAttribute("nonce",t),e}function Mb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Rb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Pb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=_b())&&(Mb(t,n),Rb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ob=function(){var e=Pb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Vu=function(){var e=Ob(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Db={left:0,top:0,right:0,gap:0},Ji=function(e){return parseInt(e||"",10)||0},Lb=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Ji(n),Ji(r),Ji(o)]},$b=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Db;var t=Lb(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])}},Fb=Vu(),br="data-scroll-locked",Bb=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(wb,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(wr,`] {
43
+ body[`).concat(br,`] {
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(wr,`] {
73
- `).concat(Cb,": ").concat(a,`px;
72
+ body[`).concat(br,`] {
73
+ `).concat(Sb,": ").concat(a,`px;
74
74
  }
75
- `)},Ku=function(){var e=parseInt(document.body.getAttribute(wr)||"0",10);return isFinite(e)?e:0},Ub=function(){m.useEffect(function(){return document.body.setAttribute(wr,(Ku()+1).toString()),function(){var e=Ku()-1;e<=0?document.body.removeAttribute(wr):document.body.setAttribute(wr,e.toString())}},[])},Hb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Ub();var s=m.useMemo(function(){return Fb(o)},[o]);return m.createElement(Bb,{styles:zb(s,!t,o,n?"":"!important")})},Zi=!1;if(typeof window<"u")try{var cs=Object.defineProperty({},"passive",{get:function(){return Zi=!0,!0}});window.addEventListener("test",cs,cs),window.removeEventListener("test",cs,cs)}catch{Zi=!1}var Sr=Zi?{passive:!1}:!1,Wb=function(e){return e.tagName==="TEXTAREA"},qu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Wb(e)&&n[t]==="visible")},Vb=function(e){return qu(e,"overflowY")},Kb=function(e){return qu(e,"overflowX")},Gu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Yu(e,r);if(o){var s=Xu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},qb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Gb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Yu=function(e,t){return e==="v"?Vb(t):Kb(t)},Xu=function(e,t){return e==="v"?qb(t):Gb(t)},Yb=function(e,t){return e==="h"&&t==="rtl"?-1:1},Xb=function(e,t,n,r,o){var s=Yb(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),u=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Xu(e,a),y=p[0],g=p[1],v=p[2],x=g-v-s*y;(y||x)&&Yu(e,a)&&(f+=x,h+=y);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(h)<1)&&(u=!0),u},us=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ju=function(e){return[e.deltaX,e.deltaY]},Zu=function(e){return e&&"current"in e?e.current:e},Jb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Zb=function(e){return`
75
+ `)},Ku=function(){var e=parseInt(document.body.getAttribute(br)||"0",10);return isFinite(e)?e:0},zb=function(){m.useEffect(function(){return document.body.setAttribute(br,(Ku()+1).toString()),function(){var e=Ku()-1;e<=0?document.body.removeAttribute(br):document.body.setAttribute(br,e.toString())}},[])},Ub=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;zb();var s=m.useMemo(function(){return $b(o)},[o]);return m.createElement(Fb,{styles:Bb(s,!t,o,n?"":"!important")})},Zi=!1;if(typeof window<"u")try{var cs=Object.defineProperty({},"passive",{get:function(){return Zi=!0,!0}});window.addEventListener("test",cs,cs),window.removeEventListener("test",cs,cs)}catch{Zi=!1}var wr=Zi?{passive:!1}:!1,Hb=function(e){return e.tagName==="TEXTAREA"},qu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Hb(e)&&n[t]==="visible")},Wb=function(e){return qu(e,"overflowY")},Vb=function(e){return qu(e,"overflowX")},Gu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Yu(e,r);if(o){var s=Xu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Kb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},qb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Yu=function(e,t){return e==="v"?Wb(t):Vb(t)},Xu=function(e,t){return e==="v"?Kb(t):qb(t)},Gb=function(e,t){return e==="h"&&t==="rtl"?-1:1},Yb=function(e,t,n,r,o){var s=Gb(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),u=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Xu(e,a),y=p[0],g=p[1],v=p[2],x=g-v-s*y;(y||x)&&Yu(e,a)&&(f+=x,h+=y);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(h)<1)&&(u=!0),u},us=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ju=function(e){return[e.deltaX,e.deltaY]},Zu=function(e){return e&&"current"in e?e.current:e},Xb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Jb=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},Qb=0,Cr=[];function ew(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Qb++)[0],s=m.useState(Vu)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=wb([e.lockRef.current],(e.shards||[]).map(Zu),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(g,v){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=us(g),b=n.current,k="deltaX"in g?g.deltaX:b[0]-x[0],T="deltaY"in g?g.deltaY:b[1]-x[1],S,C=g.target,I=Math.abs(k)>Math.abs(T)?"h":"v";if("touches"in g&&I==="h"&&C.type==="range")return!1;var A=Gu(I,C);if(!A)return!0;if(A?S=I:(S=I==="v"?"h":"v",A=Gu(I,C)),!A)return!1;if(!r.current&&"changedTouches"in g&&(k||T)&&(r.current=S),!S)return!0;var R=r.current||S;return Xb(R,v,g,R==="h"?k:T)},[]),l=m.useCallback(function(g){var v=g;if(!(!Cr.length||Cr[Cr.length-1]!==s)){var x="deltaY"in v?Ju(v):us(v),b=t.current.filter(function(S){return S.name===v.type&&(S.target===v.target||v.target===S.shadowParent)&&Jb(S.delta,x)})[0];if(b&&b.should){v.cancelable&&v.preventDefault();return}if(!b){var k=(i.current.shards||[]).map(Zu).filter(Boolean).filter(function(S){return S.contains(v.target)}),T=k.length>0?a(v,k[0]):!i.current.noIsolation;T&&v.cancelable&&v.preventDefault()}}},[]),u=m.useCallback(function(g,v,x,b){var k={name:g,delta:v,target:x,should:b,shadowParent:tw(x)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(T){return T!==k})},1)},[]),d=m.useCallback(function(g){n.current=us(g),r.current=void 0},[]),f=m.useCallback(function(g){u(g.type,Ju(g),g.target,a(g,e.lockRef.current))},[]),h=m.useCallback(function(g){u(g.type,us(g),g.target,a(g,e.lockRef.current))},[]);m.useEffect(function(){return Cr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Sr),document.addEventListener("touchmove",l,Sr),document.addEventListener("touchstart",d,Sr),function(){Cr=Cr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Sr),document.removeEventListener("touchmove",l,Sr),document.removeEventListener("touchstart",d,Sr)}},[]);var p=e.removeScrollBar,y=e.inert;return m.createElement(m.Fragment,null,y?m.createElement(s,{styles:Zb(o)}):null,p?m.createElement(Hb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function tw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const nw=jb(Wu,ew);var ds=m.forwardRef(function(e,t){return m.createElement(ls,yn({},e,{ref:t,sideCar:nw}))});ds.classNames=ls.classNames;var Qi=["Enter"," "],rw=["ArrowDown","PageUp","Home"],Qu=["ArrowUp","PageDown","End"],ow=[...rw,...Qu],sw={ltr:[...Qi,"ArrowRight"],rtl:[...Qi,"ArrowLeft"]},iw={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Wr="Menu",[Vr,aw,lw]=Ii(Wr),[Yn,ed]=kn(Wr,[lw,ts,Ou]),fs=ts(),td=Ou(),[cw,Xn]=Yn(Wr),[uw,Kr]=Yn(Wr),nd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=fs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=jt(s),h=Uo(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),c.jsx(ju,{...a,children:c.jsx(cw,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(uw,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};nd.displayName=Wr;var dw="MenuAnchor",ea=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=fs(n);return c.jsx(_u,{...o,...r,ref:t})});ea.displayName=dw;var ta="MenuPortal",[fw,rd]=Yn(ta,{forceMount:void 0}),od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(ta,t);return c.jsx(fw,{scope:t,forceMount:n,children:c.jsx(Zt,{present:n||s.open,children:c.jsx(ns,{asChild:!0,container:o,children:r})})})};od.displayName=ta;var Qt="MenuContent",[hw,na]=Yn(Qt),sd=m.forwardRef((e,t)=>{const n=rd(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Qt,e.__scopeMenu),i=Kr(Qt,e.__scopeMenu);return c.jsx(Vr.Provider,{scope:e.__scopeMenu,children:c.jsx(Zt,{present:r||s.open,children:c.jsx(Vr.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(pw,{...o,ref:t}):c.jsx(mw,{...o,ref:t})})})})}),pw=m.forwardRef((e,t)=>{const n=Xn(Qt,e.__scopeMenu),r=m.useRef(null),o=We(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Gi(s)},[]),c.jsx(ra,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),mw=m.forwardRef((e,t)=>{const n=Xn(Qt,e.__scopeMenu);return c.jsx(ra,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),gw=Wn.createSlot("MenuContent.ScrollLock"),ra=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:y,...g}=e,v=Xn(Qt,n),x=Kr(Qt,n),b=fs(n),k=td(n),T=aw(n),[S,C]=m.useState(null),I=m.useRef(null),A=We(t,I,v.onContentChange),R=m.useRef(0),D=m.useRef(""),B=m.useRef(0),X=m.useRef(null),G=m.useRef("right"),M=m.useRef(0),U=y?ds:m.Fragment,E=y?{as:gw,allowPinchZoom:!0}:void 0,P=_=>{var W,O;const q=D.current+_,Y=T().filter(K=>!K.disabled),j=document.activeElement,J=(W=Y.find(K=>K.ref.current===j))==null?void 0:W.textValue,V=Y.map(K=>K.textValue),H=Nw(V,q,J),ee=(O=Y.find(K=>K.textValue===H))==null?void 0:O.ref.current;(function K(z){D.current=z,window.clearTimeout(R.current),z!==""&&(R.current=window.setTimeout(()=>K(""),1e3))})(q),ee&&setTimeout(()=>ee.focus())};m.useEffect(()=>()=>window.clearTimeout(R.current),[]),Ai();const L=m.useCallback(_=>{var Y,j;return G.current===((Y=X.current)==null?void 0:Y.side)&&jw(_,(j=X.current)==null?void 0:j.area)},[]);return c.jsx(hw,{scope:n,searchRef:D,onItemEnter:m.useCallback(_=>{L(_)&&_.preventDefault()},[L]),onItemLeave:m.useCallback(_=>{var q;L(_)||((q=I.current)==null||q.focus(),C(null))},[L]),onTriggerLeave:m.useCallback(_=>{L(_)&&_.preventDefault()},[L]),pointerGraceTimerRef:B,onPointerGraceIntentChange:m.useCallback(_=>{X.current=_},[]),children:c.jsx(U,{...E,children:c.jsx(Wo,{asChild:!0,trapped:o,onMountAutoFocus:fe(s,_=>{var q;_.preventDefault(),(q=I.current)==null||q.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(Ho,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(gb,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:fe(l,_=>{x.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Mu,{role:"menu","aria-orientation":"vertical","data-state":Sd(v.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,_=>{const Y=_.target.closest("[data-radix-menu-content]")===_.currentTarget,j=_.ctrlKey||_.altKey||_.metaKey,J=_.key.length===1;Y&&(_.key==="Tab"&&_.preventDefault(),!j&&J&&P(_.key));const V=I.current;if(_.target!==V||!ow.includes(_.key))return;_.preventDefault();const ee=T().filter(W=>!W.disabled).map(W=>W.ref.current);Qu.includes(_.key)&&ee.reverse(),Iw(ee)}),onBlur:fe(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(R.current),D.current="")}),onPointerMove:fe(e.onPointerMove,Gr(_=>{const q=_.target,Y=M.current!==_.clientX;if(_.currentTarget.contains(q)&&Y){const j=_.clientX>M.current?"right":"left";G.current=j,M.current=_.clientX}}))})})})})})})});sd.displayName=Qt;var xw="MenuGroup",oa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{role:"group",...r,ref:t})});oa.displayName=xw;var yw="MenuLabel",id=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{...r,ref:t})});id.displayName=yw;var hs="MenuItem",ad="menu.itemSelect",ps=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Kr(hs,e.__scopeMenu),a=na(hs,e.__scopeMenu),l=We(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ad,{bubbles:!0,cancelable:!0});f.addEventListener(ad,p=>r==null?void 0:r(p),{once:!0}),Bc(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(ld,{...o,ref:l,disabled:n,onClick:fe(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:fe(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:fe(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Qi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ps.displayName=hs;var ld=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=na(hs,n),a=td(n),l=m.useRef(null),u=We(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const y=l.current;y&&p((y.textContent??"").trim())},[s.children]),c.jsx(Vr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(xb,{asChild:!0,...a,focusable:!r,children:c.jsx(Se.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:fe(e.onPointerMove,Gr(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:fe(e.onPointerLeave,Gr(y=>i.onItemLeave(y))),onFocus:fe(e.onFocus,()=>f(!0)),onBlur:fe(e.onBlur,()=>f(!1))})})})}),vw="MenuCheckboxItem",cd=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(pd,{scope:e.__scopeMenu,checked:n,children:c.jsx(ps,{role:"menuitemcheckbox","aria-checked":ms(n)?"mixed":n,...o,ref:t,"data-state":ia(n),onSelect:fe(o.onSelect,()=>r==null?void 0:r(ms(n)?!0:!n),{checkForDefaultPrevented:!1})})})});cd.displayName=vw;var ud="MenuRadioGroup",[bw,ww]=Yn(ud,{value:void 0,onValueChange:()=>{}}),dd=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=jt(r);return c.jsx(bw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(oa,{...o,ref:t})})});dd.displayName=ud;var fd="MenuRadioItem",hd=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=ww(fd,e.__scopeMenu),s=n===o.value;return c.jsx(pd,{scope:e.__scopeMenu,checked:s,children:c.jsx(ps,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":ia(s),onSelect:fe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hd.displayName=fd;var sa="MenuItemIndicator",[pd,Sw]=Yn(sa,{checked:!1}),md=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=Sw(sa,n);return c.jsx(Zt,{present:r||ms(s.checked)||s.checked===!0,children:c.jsx(Se.span,{...o,ref:t,"data-state":ia(s.checked)})})});md.displayName=sa;var Cw="MenuSeparator",gd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Se.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gd.displayName=Cw;var kw="MenuArrow",xd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=fs(n);return c.jsx(Ru,{...o,...r,ref:t})});xd.displayName=kw;var Tw="MenuSub",[II,yd]=Yn(Tw),qr="MenuSubTrigger",vd=m.forwardRef((e,t)=>{const n=Xn(qr,e.__scopeMenu),r=Kr(qr,e.__scopeMenu),o=yd(qr,e.__scopeMenu),s=na(qr,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(ea,{asChild:!0,...u,children:c.jsx(ld,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sd(n.open),...e,ref:An(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:fe(e.onPointerMove,Gr(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,Gr(f=>{var p,y;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(y=n.content)==null?void 0:y.dataset.side,v=g==="right",x=v?-5:5,b=h[v?"left":"right"],k=h[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:k,y:h.top},{x:k,y:h.bottom},{x:b,y:h.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 p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||sw[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});vd.displayName=qr;var bd="MenuSubContent",wd=m.forwardRef((e,t)=>{const n=rd(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Qt,e.__scopeMenu),i=Kr(Qt,e.__scopeMenu),a=yd(bd,e.__scopeMenu),l=m.useRef(null),u=We(t,l);return c.jsx(Vr.Provider,{scope:e.__scopeMenu,children:c.jsx(Zt,{present:r||s.open,children:c.jsx(Vr.Slot,{scope:e.__scopeMenu,children:c.jsx(ra,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside: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 p;const f=d.currentTarget.contains(d.target),h=iw[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});wd.displayName=bd;function Sd(e){return e?"open":"closed"}function ms(e){return e==="indeterminate"}function ia(e){return ms(e)?"indeterminate":e?"checked":"unchecked"}function Iw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Ew(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Nw(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Ew(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Aw(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function jw(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Aw(n,t)}function Gr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var _w=nd,Mw=ea,Rw=od,Pw=sd,Ow=oa,Dw=id,Lw=ps,$w=cd,Fw=dd,Bw=hd,zw=md,Uw=gd,Hw=xd,Ww=vd,Vw=wd,gs="DropdownMenu",[Kw,EI]=kn(gs,[ed]),Bt=ed(),[qw,Cd]=Kw(gs),kd=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Bt(t),u=m.useRef(null),[d,f]=mr({prop:o,defaultProp:s??!1,onChange:i,caller:gs});return c.jsx(qw,{scope:t,triggerId:Ft(),triggerRef:u,contentId:Ft(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(_w,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};kd.displayName=gs;var Td="DropdownMenuTrigger",Id=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Cd(Td,n),i=Bt(n);return c.jsx(Mw,{asChild:!0,...i,children:c.jsx(Se.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:An(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())})})})});Id.displayName=Td;var Gw="DropdownMenuPortal",Ed=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Bt(t);return c.jsx(Rw,{...r,...n})};Ed.displayName=Gw;var Nd="DropdownMenuContent",Ad=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Cd(Nd,n),s=Bt(n),i=m.useRef(!1);return c.jsx(Pw,{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,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Ad.displayName=Nd;var Yw="DropdownMenuGroup",Xw=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Ow,{...o,...r,ref:t})});Xw.displayName=Yw;var Jw="DropdownMenuLabel",jd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Dw,{...o,...r,ref:t})});jd.displayName=Jw;var Zw="DropdownMenuItem",_d=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Lw,{...o,...r,ref:t})});_d.displayName=Zw;var Qw="DropdownMenuCheckboxItem",Md=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx($w,{...o,...r,ref:t})});Md.displayName=Qw;var e0="DropdownMenuRadioGroup",t0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Fw,{...o,...r,ref:t})});t0.displayName=e0;var n0="DropdownMenuRadioItem",Rd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Bw,{...o,...r,ref:t})});Rd.displayName=n0;var r0="DropdownMenuItemIndicator",Pd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(zw,{...o,...r,ref:t})});Pd.displayName=r0;var o0="DropdownMenuSeparator",Od=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Uw,{...o,...r,ref:t})});Od.displayName=o0;var s0="DropdownMenuArrow",i0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Hw,{...o,...r,ref:t})});i0.displayName=s0;var a0="DropdownMenuSubTrigger",Dd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Ww,{...o,...r,ref:t})});Dd.displayName=a0;var l0="DropdownMenuSubContent",Ld=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(Vw,{...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)"}})});Ld.displayName=l0;var c0=kd,u0=Id,d0=Ed,$d=Ad,Fd=jd,Bd=_d,zd=Md,Ud=Rd,Hd=Pd,Wd=Od,Vd=Dd,Kd=Ld;const aa=c0,la=u0,f0=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Vd,{ref:o,className:se("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,c.jsx(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));f0.displayName=Vd.displayName;const h0=m.forwardRef(({className:e,...t},n)=>c.jsx(Kd,{ref:n,className:se("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}));h0.displayName=Kd.displayName;const xs=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(d0,{children:c.jsx($d,{ref:r,sideOffset:t,className:se("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})}));xs.displayName=$d.displayName;const Jn=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Bd,{ref:r,className:se("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}));Jn.displayName=Bd.displayName;const p0=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(zd,{ref:o,className:se("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Hd,{children:c.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));p0.displayName=zd.displayName;const m0=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Ud,{ref:r,className:se("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Hd,{children:c.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));m0.displayName=Ud.displayName;const g0=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Fd,{ref:r,className:se("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));g0.displayName=Fd.displayName;const x0=m.forwardRef(({className:e,...t},n)=>c.jsx(Wd,{ref:n,className:se("-mx-1 my-1 h-px bg-muted",e),...t}));x0.displayName=Wd.displayName;function y0(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 v0(e){const t=new Map,n=y0(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 b0(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 ys(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function w0(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function S0(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 C0(e){const t=Array.isArray(e)?e.map(r=>{const o=S0(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ys(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ys(r.metadata,"step"),i=ys(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 k0(e){const t=w.useMemo(()=>C0(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 h=f.checkpointId??null;if(!h)continue;const p=ys(f.metadata,"step"),y=w0(f.metadata,"source"),g={id:h,step:p,source:y,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(h,g),p!==null&&y){const v=`${p}:${y}`,x=a.get(v)??[];x.push(g),a.set(v,x)}}const u=v0(t);for(const[f,h]of i.entries()){const p=u.get(f);p?l.set(f,{...h,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount,isLatestAttempt:p.isLatestAttempt,baseUserMessageId:p.baseUserMessageId??null}):l.set(f,{...h,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}const d=b0(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const vs=1e4;function T0(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
+ `)},Zb=0,Sr=[];function Qb(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(Zb++)[0],s=m.useState(Vu)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=bb([e.lockRef.current],(e.shards||[]).map(Zu),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(g,v){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var x=us(g),b=n.current,C="deltaX"in g?g.deltaX:b[0]-x[0],k="deltaY"in g?g.deltaY:b[1]-x[1],S,T=g.target,E=Math.abs(C)>Math.abs(k)?"h":"v";if("touches"in g&&E==="h"&&T.type==="range")return!1;var A=Gu(E,T);if(!A)return!0;if(A?S=E:(S=E==="v"?"h":"v",A=Gu(E,T)),!A)return!1;if(!r.current&&"changedTouches"in g&&(C||k)&&(r.current=S),!S)return!0;var P=r.current||S;return Yb(P,v,g,P==="h"?C:k)},[]),l=m.useCallback(function(g){var v=g;if(!(!Sr.length||Sr[Sr.length-1]!==s)){var x="deltaY"in v?Ju(v):us(v),b=t.current.filter(function(S){return S.name===v.type&&(S.target===v.target||v.target===S.shadowParent)&&Xb(S.delta,x)})[0];if(b&&b.should){v.cancelable&&v.preventDefault();return}if(!b){var C=(i.current.shards||[]).map(Zu).filter(Boolean).filter(function(S){return S.contains(v.target)}),k=C.length>0?a(v,C[0]):!i.current.noIsolation;k&&v.cancelable&&v.preventDefault()}}},[]),u=m.useCallback(function(g,v,x,b){var C={name:g,delta:v,target:x,should:b,shadowParent:ew(x)};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(k){return k!==C})},1)},[]),d=m.useCallback(function(g){n.current=us(g),r.current=void 0},[]),f=m.useCallback(function(g){u(g.type,Ju(g),g.target,a(g,e.lockRef.current))},[]),h=m.useCallback(function(g){u(g.type,us(g),g.target,a(g,e.lockRef.current))},[]);m.useEffect(function(){return Sr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,wr),document.addEventListener("touchmove",l,wr),document.addEventListener("touchstart",d,wr),function(){Sr=Sr.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,wr),document.removeEventListener("touchmove",l,wr),document.removeEventListener("touchstart",d,wr)}},[]);var p=e.removeScrollBar,y=e.inert;return m.createElement(m.Fragment,null,y?m.createElement(s,{styles:Jb(o)}):null,p?m.createElement(Ub,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ew(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const tw=Ab(Wu,Qb);var ds=m.forwardRef(function(e,t){return m.createElement(ls,yn({},e,{ref:t,sideCar:tw}))});ds.classNames=ls.classNames;var Qi=["Enter"," "],nw=["ArrowDown","PageUp","Home"],Qu=["ArrowUp","PageDown","End"],rw=[...nw,...Qu],ow={ltr:[...Qi,"ArrowRight"],rtl:[...Qi,"ArrowLeft"]},sw={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Hr="Menu",[Wr,iw,aw]=Ei(Hr),[Yn,ed]=Tn(Hr,[aw,ts,Ou]),fs=ts(),td=Ou(),[lw,Xn]=Yn(Hr),[cw,Vr]=Yn(Hr),nd=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=fs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=At(s),h=Uo(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),c.jsx(ju,{...a,children:c.jsx(lw,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(cw,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};nd.displayName=Hr;var uw="MenuAnchor",ea=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=fs(n);return c.jsx(_u,{...o,...r,ref:t})});ea.displayName=uw;var ta="MenuPortal",[dw,rd]=Yn(ta,{forceMount:void 0}),od=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(ta,t);return c.jsx(dw,{scope:t,forceMount:n,children:c.jsx(Zt,{present:n||s.open,children:c.jsx(ns,{asChild:!0,container:o,children:r})})})};od.displayName=ta;var Qt="MenuContent",[fw,na]=Yn(Qt),sd=m.forwardRef((e,t)=>{const n=rd(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Qt,e.__scopeMenu),i=Vr(Qt,e.__scopeMenu);return c.jsx(Wr.Provider,{scope:e.__scopeMenu,children:c.jsx(Zt,{present:r||s.open,children:c.jsx(Wr.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(hw,{...o,ref:t}):c.jsx(pw,{...o,ref:t})})})})}),hw=m.forwardRef((e,t)=>{const n=Xn(Qt,e.__scopeMenu),r=m.useRef(null),o=ze(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Gi(s)},[]),c.jsx(ra,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:he(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),pw=m.forwardRef((e,t)=>{const n=Xn(Qt,e.__scopeMenu);return c.jsx(ra,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),mw=Wn.createSlot("MenuContent.ScrollLock"),ra=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:y,...g}=e,v=Xn(Qt,n),x=Vr(Qt,n),b=fs(n),C=td(n),k=iw(n),[S,T]=m.useState(null),E=m.useRef(null),A=ze(t,E,v.onContentChange),P=m.useRef(0),$=m.useRef(""),B=m.useRef(0),V=m.useRef(null),G=m.useRef("right"),O=m.useRef(0),U=y?ds:m.Fragment,N=y?{as:mw,allowPinchZoom:!0}:void 0,D=j=>{var Y,L;const H=$.current+j,W=k().filter(q=>!q.disabled),R=document.activeElement,K=(Y=W.find(q=>q.ref.current===R))==null?void 0:Y.textValue,ie=W.map(q=>q.textValue),Q=Iw(ie,H,K),oe=(L=W.find(q=>q.textValue===Q))==null?void 0:L.ref.current;(function q(z){$.current=z,window.clearTimeout(P.current),z!==""&&(P.current=window.setTimeout(()=>q(""),1e3))})(H),oe&&setTimeout(()=>oe.focus())};m.useEffect(()=>()=>window.clearTimeout(P.current),[]),Ai();const M=m.useCallback(j=>{var W,R;return G.current===((W=V.current)==null?void 0:W.side)&&Aw(j,(R=V.current)==null?void 0:R.area)},[]);return c.jsx(fw,{scope:n,searchRef:$,onItemEnter:m.useCallback(j=>{M(j)&&j.preventDefault()},[M]),onItemLeave:m.useCallback(j=>{var H;M(j)||((H=E.current)==null||H.focus(),T(null))},[M]),onTriggerLeave:m.useCallback(j=>{M(j)&&j.preventDefault()},[M]),pointerGraceTimerRef:B,onPointerGraceIntentChange:m.useCallback(j=>{V.current=j},[]),children:c.jsx(U,{...N,children:c.jsx(Wo,{asChild:!0,trapped:o,onMountAutoFocus:he(s,j=>{var H;j.preventDefault(),(H=E.current)==null||H.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(Ho,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(mb,{asChild:!0,...C,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:T,onEntryFocus:he(l,j=>{x.isUsingKeyboardRef.current||j.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Mu,{role:"menu","aria-orientation":"vertical","data-state":Sd(v.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:he(g.onKeyDown,j=>{const W=j.target.closest("[data-radix-menu-content]")===j.currentTarget,R=j.ctrlKey||j.altKey||j.metaKey,K=j.key.length===1;W&&(j.key==="Tab"&&j.preventDefault(),!R&&K&&D(j.key));const ie=E.current;if(j.target!==ie||!rw.includes(j.key))return;j.preventDefault();const oe=k().filter(Y=>!Y.disabled).map(Y=>Y.ref.current);Qu.includes(j.key)&&oe.reverse(),kw(oe)}),onBlur:he(e.onBlur,j=>{j.currentTarget.contains(j.target)||(window.clearTimeout(P.current),$.current="")}),onPointerMove:he(e.onPointerMove,qr(j=>{const H=j.target,W=O.current!==j.clientX;if(j.currentTarget.contains(H)&&W){const R=j.clientX>O.current?"right":"left";G.current=R,O.current=j.clientX}}))})})})})})})});sd.displayName=Qt;var gw="MenuGroup",oa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(we.div,{role:"group",...r,ref:t})});oa.displayName=gw;var xw="MenuLabel",id=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(we.div,{...r,ref:t})});id.displayName=xw;var hs="MenuItem",ad="menu.itemSelect",ps=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Vr(hs,e.__scopeMenu),a=na(hs,e.__scopeMenu),l=ze(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ad,{bubbles:!0,cancelable:!0});f.addEventListener(ad,p=>r==null?void 0:r(p),{once:!0}),Bc(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(ld,{...o,ref:l,disabled:n,onClick:he(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:he(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:he(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Qi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ps.displayName=hs;var ld=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=na(hs,n),a=td(n),l=m.useRef(null),u=ze(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const y=l.current;y&&p((y.textContent??"").trim())},[s.children]),c.jsx(Wr.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(gb,{asChild:!0,...a,focusable:!r,children:c.jsx(we.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:he(e.onPointerMove,qr(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:he(e.onPointerLeave,qr(y=>i.onItemLeave(y))),onFocus:he(e.onFocus,()=>f(!0)),onBlur:he(e.onBlur,()=>f(!1))})})})}),yw="MenuCheckboxItem",cd=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(pd,{scope:e.__scopeMenu,checked:n,children:c.jsx(ps,{role:"menuitemcheckbox","aria-checked":ms(n)?"mixed":n,...o,ref:t,"data-state":ia(n),onSelect:he(o.onSelect,()=>r==null?void 0:r(ms(n)?!0:!n),{checkForDefaultPrevented:!1})})})});cd.displayName=yw;var ud="MenuRadioGroup",[vw,bw]=Yn(ud,{value:void 0,onValueChange:()=>{}}),dd=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=At(r);return c.jsx(vw,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(oa,{...o,ref:t})})});dd.displayName=ud;var fd="MenuRadioItem",hd=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=bw(fd,e.__scopeMenu),s=n===o.value;return c.jsx(pd,{scope:e.__scopeMenu,checked:s,children:c.jsx(ps,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":ia(s),onSelect:he(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hd.displayName=fd;var sa="MenuItemIndicator",[pd,ww]=Yn(sa,{checked:!1}),md=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=ww(sa,n);return c.jsx(Zt,{present:r||ms(s.checked)||s.checked===!0,children:c.jsx(we.span,{...o,ref:t,"data-state":ia(s.checked)})})});md.displayName=sa;var Sw="MenuSeparator",gd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(we.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gd.displayName=Sw;var Cw="MenuArrow",xd=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=fs(n);return c.jsx(Ru,{...o,...r,ref:t})});xd.displayName=Cw;var Tw="MenuSub",[kE,yd]=Yn(Tw),Kr="MenuSubTrigger",vd=m.forwardRef((e,t)=>{const n=Xn(Kr,e.__scopeMenu),r=Vr(Kr,e.__scopeMenu),o=yd(Kr,e.__scopeMenu),s=na(Kr,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(ea,{asChild:!0,...u,children:c.jsx(ld,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sd(n.open),...e,ref:An(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:he(e.onPointerMove,qr(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:he(e.onPointerLeave,qr(f=>{var p,y;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(y=n.content)==null?void 0:y.dataset.side,v=g==="right",x=v?-5:5,b=h[v?"left":"right"],C=h[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+x,y:f.clientY},{x:b,y:h.top},{x:C,y:h.top},{x:C,y:h.bottom},{x:b,y:h.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:he(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||ow[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});vd.displayName=Kr;var bd="MenuSubContent",wd=m.forwardRef((e,t)=>{const n=rd(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Qt,e.__scopeMenu),i=Vr(Qt,e.__scopeMenu),a=yd(bd,e.__scopeMenu),l=m.useRef(null),u=ze(t,l);return c.jsx(Wr.Provider,{scope:e.__scopeMenu,children:c.jsx(Zt,{present:r||s.open,children:c.jsx(Wr.Slot,{scope:e.__scopeMenu,children:c.jsx(ra,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:he(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:he(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:he(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=sw[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});wd.displayName=bd;function Sd(e){return e?"open":"closed"}function ms(e){return e==="indeterminate"}function ia(e){return ms(e)?"indeterminate":e?"checked":"unchecked"}function kw(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Ew(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Iw(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Ew(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Nw(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function Aw(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Nw(n,t)}function qr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var jw=nd,_w=ea,Mw=od,Rw=sd,Pw=oa,Ow=id,Dw=ps,Lw=cd,$w=dd,Fw=hd,Bw=md,zw=gd,Uw=xd,Hw=vd,Ww=wd,gs="DropdownMenu",[Vw,EE]=Tn(gs,[ed]),Ft=ed(),[Kw,Cd]=Vw(gs),Td=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ft(t),u=m.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:gs});return c.jsx(Kw,{scope:t,triggerId:$t(),triggerRef:u,contentId:$t(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(jw,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Td.displayName=gs;var kd="DropdownMenuTrigger",Ed=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Cd(kd,n),i=Ft(n);return c.jsx(_w,{asChild:!0,...i,children:c.jsx(we.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:An(t,s.triggerRef),onPointerDown:he(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:he(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ed.displayName=kd;var qw="DropdownMenuPortal",Id=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ft(t);return c.jsx(Mw,{...r,...n})};Id.displayName=qw;var Nd="DropdownMenuContent",Ad=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Cd(Nd,n),s=Ft(n),i=m.useRef(!1);return c.jsx(Rw,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:he(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:he(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Ad.displayName=Nd;var Gw="DropdownMenuGroup",Yw=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Pw,{...o,...r,ref:t})});Yw.displayName=Gw;var Xw="DropdownMenuLabel",jd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Ow,{...o,...r,ref:t})});jd.displayName=Xw;var Jw="DropdownMenuItem",_d=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Dw,{...o,...r,ref:t})});_d.displayName=Jw;var Zw="DropdownMenuCheckboxItem",Md=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Lw,{...o,...r,ref:t})});Md.displayName=Zw;var Qw="DropdownMenuRadioGroup",e0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx($w,{...o,...r,ref:t})});e0.displayName=Qw;var t0="DropdownMenuRadioItem",Rd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Fw,{...o,...r,ref:t})});Rd.displayName=t0;var n0="DropdownMenuItemIndicator",Pd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Bw,{...o,...r,ref:t})});Pd.displayName=n0;var r0="DropdownMenuSeparator",Od=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(zw,{...o,...r,ref:t})});Od.displayName=r0;var o0="DropdownMenuArrow",s0=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Uw,{...o,...r,ref:t})});s0.displayName=o0;var i0="DropdownMenuSubTrigger",Dd=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Hw,{...o,...r,ref:t})});Dd.displayName=i0;var a0="DropdownMenuSubContent",Ld=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ft(n);return c.jsx(Ww,{...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)"}})});Ld.displayName=a0;var l0=Td,c0=Ed,u0=Id,$d=Ad,Fd=jd,Bd=_d,zd=Md,Ud=Rd,Hd=Pd,Wd=Od,Vd=Dd,Kd=Ld;const aa=l0,la=c0,d0=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Vd,{ref:o,className:ne("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,c.jsx(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));d0.displayName=Vd.displayName;const f0=m.forwardRef(({className:e,...t},n)=>c.jsx(Kd,{ref:n,className:ne("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}));f0.displayName=Kd.displayName;const xs=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(u0,{children:c.jsx($d,{ref:r,sideOffset:t,className:ne("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})}));xs.displayName=$d.displayName;const Jn=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Bd,{ref:r,className:ne("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}));Jn.displayName=Bd.displayName;const h0=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(zd,{ref:o,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Hd,{children:c.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));h0.displayName=zd.displayName;const p0=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Ud,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Hd,{children:c.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));p0.displayName=Ud.displayName;const m0=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Fd,{ref:r,className:ne("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));m0.displayName=Fd.displayName;const g0=m.forwardRef(({className:e,...t},n)=>c.jsx(Wd,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));g0.displayName=Wd.displayName;function x0(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 y0(e){const t=new Map,n=x0(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 v0(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 ys(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function b0(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function w0(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 S0(e){const t=Array.isArray(e)?e.map(r=>{const o=w0(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ys(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ys(r.metadata,"step"),i=ys(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 C0(e){const t=w.useMemo(()=>S0(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 h=f.checkpointId??null;if(!h)continue;const p=ys(f.metadata,"step"),y=b0(f.metadata,"source"),g={id:h,step:p,source:y,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(h,g),p!==null&&y){const v=`${p}:${y}`,x=a.get(v)??[];x.push(g),a.set(v,x)}}const u=y0(t);for(const[f,h]of i.entries()){const p=u.get(f);p?l.set(f,{...h,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount,isLatestAttempt:p.isLatestAttempt,baseUserMessageId:p.baseUserMessageId??null}):l.set(f,{...h,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}const d=v0(l);return{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const vs=1e4;function T0(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,25 +83,25 @@ 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 I0(e,t=vs){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 E0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),I0(t),T0(t)}const bs=0,Rn=1,kr=2,qd=4;function Gd(e){return()=>e}function N0(e){e()}function Yd(e,t){return n=>e(t(n))}function Xd(e,t){return()=>e(t)}function A0(e,t){return n=>e(t,n)}function ca(e){return e!==void 0}function j0(...e){return()=>{e.map(N0)}}function Tr(){}function ws(e,t){return t(e),e}function _0(e,t){return t(e)}function ct(...e){return e}function nt(e,t){return e(Rn,t)}function Pe(e,t){e(bs,t)}function ua(e){e(kr)}function bt(e){return e(qd)}function xe(e,t){return nt(e,A0(t,bs))}function cn(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Jd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Zd(e,t){return e===t}function ut(e=Zd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function ue(e){return t=>Yd(t,e)}function vn(e){return t=>()=>{t(e)}}function te(e,...t){const n=M0(...t);return(r,o)=>{switch(r){case kr:ua(e);return;case Rn:return nt(e,n(o))}}}function bn(e,t){return n=>r=>{n(t=e(t,r))}}function Zn(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);nt(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function M0(...e){return t=>e.reduceRight(_0,t)}function R0(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=nt(e,s),t):(r(),Tr);case kr:r(),n=null;return}}}function ie(e){let t=e;const n=Ve();return(r,o)=>{switch(r){case bs:t=o;break;case Rn:{o(t);break}case qd:return t}return n(r,o)}}function Ot(e,t){return ws(ie(t),n=>xe(e,n))}function Ve(){const e=[];return(t,n)=>{switch(t){case bs:e.slice().forEach(r=>{r(n)});return;case kr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Xt(e){return ws(Ve(),t=>xe(e,t))}function Xe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:P0(),singleton:n}}const P0=()=>Symbol();function O0(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=Ve(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);nt(s,l=>{n[i]=l,r=r|a,r===o&&Pe(t,n)})}),function(s,i){switch(s){case kr:{ua(t);return}case Rn:return r===o&&i(n),nt(t,i)}}}function Te(e,t=Zd){return te(e,ut(t))}function da(...e){return function(t,n){switch(t){case kr:return;case Rn:return j0(...e.map(r=>nt(r,n)))}}}var Kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Kt||{});const D0={0:"debug",3:"error",1:"log",2:"warn"},L0=()=>typeof globalThis>"u"?window:globalThis,Pn=Xe(()=>{const e=ie(3);return{log:ie((t,n,r=1)=>{var o;const s=(o=L0().VIRTUOSO_LOG_LEVEL)!=null?o:bt(e);r>=s&&console[D0[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 fa(e,t,n).callbackRef}function fa(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 $0(e,t,n,r,o,s,i,a,l){const u=w.useCallback(d=>{const f=F0(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let y;p&&(y=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?y.scrollX||y.document.documentElement.scrollLeft:y.scrollY||y.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:p?a?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?y.innerWidth:y.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Qd("column-gap",getComputedStyle(d).columnGap,o):Qd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return fa(u,n,l)}function F0(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Kt.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Qd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function ef(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),y=u.top-p.top;h=p.height-Math.max(0,y),f=y+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=fa(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const zt=Xe(()=>{const e=Ve(),t=Ve(),n=ie(0),r=Ve(),o=ie(0),s=Ve(),i=Ve(),a=ie(0),l=ie(0),u=ie(0),d=ie(0),f=Ve(),h=Ve(),p=ie(!1),y=ie(!1),g=ie(!1);return xe(te(e,ue(({scrollTop:v})=>v)),t),xe(te(e,ue(({scrollHeight:v})=>v)),i),xe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:y,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Yr={lvl:0};function tf(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 it(e){return e===Yr}function Xr(e,t){if(!it(e))return t===e.k?e.v:t<e.k?Xr(e.l,t):Xr(e.r,t)}function un(e,t,n="k"){if(it(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=un(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return un(e.l,t,n)}function Jt(e,t,n){return it(e)?of(t,n,1):t===e.k?kt(e,{k:t,v:n}):t<e.k?sf(kt(e,{l:Jt(e.l,t,n)})):sf(kt(e,{r:Jt(e.r,t,n)}))}function Ir(){return Yr}function Ss(e,t,n){if(it(e))return[];const r=un(e,t)[0];return B0(pa(e,r,n))}function ha(e,t){if(it(e))return Yr;const{k:n,l:r,r:o}=e;if(t===n){if(it(r))return o;if(it(o))return r;{const[s,i]=rf(r);return Cs(kt(e,{k:s,l:nf(r),v:i}))}}else return t<n?Cs(kt(e,{l:ha(r,t)})):Cs(kt(e,{r:ha(o,t)}))}function er(e){return it(e)?[]:[...er(e.l),{k:e.k,v:e.v},...er(e.r)]}function pa(e,t,n){if(it(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(pa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(pa(s,t,n))),a}function Cs(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(ma(t))return af(kt(e,{lvl:n-1}));if(!it(t)&&!it(t.r))return kt(t.r,{l:kt(t,{r:t.r.l}),lvl:n,r:kt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ma(e))return ga(kt(e,{lvl:n-1}));if(!it(r)&&!it(r.l)){const o=r.l,s=ma(o)?r.lvl-1:r.lvl;return kt(o,{l:kt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ga(kt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function kt(e,t){return of(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 nf(e){return it(e.r)?e.l:Cs(kt(e,{r:nf(e.r)}))}function ma(e){return it(e)||e.lvl>e.r.lvl}function rf(e){return it(e.r)?[e.k,e.v]:rf(e.r)}function of(e,t,n,r=Yr,o=Yr){return{k:e,l:r,lvl:n,r:o,v:t}}function sf(e){return ga(af(e))}function af(e){const{l:t}=e;return!it(t)&&t.lvl===e.lvl?kt(t,{r:kt(e,{l:t.r})}):e}function ga(e){const{lvl:t,r:n}=e;return!it(n)&&!it(n.r)&&n.lvl===t&&n.r.lvl===t?kt(n,{l:kt(e,{r:n.l}),lvl:t+1}):e}function B0(e){return tf(e,({k:t,v:n})=>({index:t,value:n}))}function lf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Jr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const xa=Xe(()=>({recalcInProgress:ie(!1)}),[],{singleton:!0});function cf(e,t,n){return e[ks(e,t,n)]}function ks(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 z0(e,t,n,r){const o=ks(e,t,r),s=ks(e,n,r,o);return e.slice(o,s+1)}function On(e,t){return Math.round(e.getBoundingClientRect()[t])}function Ts(e){return!it(e.groupOffsetTree)}function ya({index:e},t){return t===e?0:t<e?-1:1}function U0(){return{groupIndices:[],groupOffsetTree:Ir(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Ir()}}function H0(e,t){let n=it(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),it(e)){e=Jt(e,0,s);continue}const a=Ss(e,i-1,o+1);if(a.some(X0(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ha(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Jt(e,o+1,h));u&&(e=Jt(e,i,s))}return[e,n]}function W0(e){return typeof e.groupIndex<"u"}function V0({offset:e},t){return t===e?0:t<e?-1:1}function Zr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=cf(t,e,ya),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function uf(e,t){if(!Ts(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function df(e,t,n){if(W0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=uf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function K0(e,t,n,r=0){return r>0&&(t=Math.max(t,cf(e,r,ya).offset)),tf(z0(e,t,n,V0),Y0)}function q0(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&it(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((y,g)=>Jt(Jt(y,g,h),g+1,p),i)}else[i,a]=H0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=va(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Jt(h,p,Zr(p,f,o)),Ir()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function G0(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 ff(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 va(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ks(o,t-1,ya),a=o[l].offset;const u=un(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===un(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Ss(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Y0(e){return{index:e.index,value:e}}function X0(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 J0={offsetHeight:"height",offsetWidth:"width"},wn=Xe(([{log:e},{recalcInProgress:t}])=>{const n=Ve(),r=Ve(),o=Ot(r,0),s=Ve(),i=Ve(),a=ie(0),l=ie([]),u=ie(void 0),d=ie(void 0),f=ie((S,C)=>On(S,J0[C])),h=ie(void 0),p=ie(0),y=U0(),g=Ot(te(n,Oe(l,e,p),bn(q0,y),ut()),y),v=Ot(te(l,ut(),bn((S,C)=>({current:C,prev:S.current}),{current:[],prev:[]}),ue(({prev:S})=>S)),[]);xe(te(l,Ae(S=>S.length>0),Oe(g,p),ue(([S,C,I])=>{const A=S.reduce((R,D,B)=>Jt(R,D,Zr(D,C.offsetTree,I)||B),Ir());return{...C,groupIndices:S,groupOffsetTree:A}})),g),xe(te(r,Oe(g),Ae(([S,{lastIndex:C}])=>S<C),ue(([S,{lastIndex:C,lastSize:I}])=>[{endIndex:C,size:I,startIndex:S}])),n),xe(u,d);const x=Ot(te(u,ue(S=>S===void 0)),!0);xe(te(d,Ae(S=>S!==void 0&&it(bt(g).sizeTree)),ue(S=>[{endIndex:0,size:S,startIndex:0}])),n);const b=Xt(te(n,Oe(g),bn(({sizes:S},[C,I])=>({changed:I!==S,sizes:I}),{changed:!1,sizes:y}),ue(S=>S.changed)));nt(te(a,bn((S,C)=>({diff:S.prev-C,prev:C}),{diff:0,prev:0}),ue(S=>S.diff)),S=>{const{groupIndices:C}=bt(g);if(S>0)Pe(t,!0),Pe(s,S+ff(S,C));else if(S<0){const I=bt(v);I.length>0&&(S-=ff(-S,I)),Pe(i,S)}}),nt(te(a,Oe(e)),([S,C])=>{S<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Kt.ERROR)});const k=Xt(s);xe(te(s,Oe(g),ue(([S,C])=>{const I=C.groupIndices.length>0,A=[],R=C.lastSize;if(I){const D=Xr(C.sizeTree,0);let B=0,X=0;for(;B<S;){const M=C.groupIndices[X],U=C.groupIndices.length===X+1?1/0:C.groupIndices[X+1]-M-1;A.push({endIndex:M,size:D,startIndex:M}),A.push({endIndex:M+1+U-1,size:R,startIndex:M+1}),X++,B+=U+1}const G=er(C.sizeTree);return B!==S&&G.shift(),G.reduce((M,{k:U,v:E})=>{let P=M.ranges;return M.prevSize!==0&&(P=[...M.ranges,{endIndex:U+S-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:U+S,prevSize:E,ranges:P}},{prevIndex:S,prevSize:0,ranges:A}).ranges}return er(C.sizeTree).reduce((D,{k:B,v:X})=>({prevIndex:B+S,prevSize:X,ranges:[...D.ranges,{endIndex:B+S-1,size:D.prevSize,startIndex:D.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const T=Xt(te(i,Oe(g,p),ue(([S,{offsetTree:C},I])=>{const A=-S;return Zr(A,C,I)})));return xe(te(i,Oe(g,p),ue(([S,C,I])=>{if(C.groupIndices.length>0){if(it(C.sizeTree))return C;let A=Ir();const R=bt(v);let D=0,B=0,X=0;for(;D<-S;){X=R[B];const G=R[B+1]-X-1;B++,D+=G+1}if(A=er(C.sizeTree).reduce((G,{k:M,v:U})=>Jt(G,Math.max(0,M+S),U),A),D!==-S){const G=Xr(C.sizeTree,X);A=Jt(A,0,G);const M=un(C.sizeTree,-S+1)[1];A=Jt(A,1,M)}return{...C,sizeTree:A,...va(C.offsetTree,0,A,I)}}else{const A=er(C.sizeTree).reduce((R,{k:D,v:B})=>Jt(R,Math.max(0,D+S),B),Ir());return{...C,sizeTree:A,...va(C.offsetTree,0,A,I)}}})),g),{beforeUnshiftWith:k,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},ct(Pn,xa),{singleton:!0});function Z0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const hf=Xe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ve(),i=Ve(),a=Xt(te(s,ue(Z0)));return xe(te(a,ue(l=>l.totalCount)),n),xe(te(a,ue(l=>l.groupIndices)),e),xe(te(wt(o,t,r),Ae(([l,u])=>Ts(u)),ue(([l,u,d])=>un(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),ue(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(wn,zt)),Dn=Xe(([{log:e}])=>{const t=ie(!1),n=Xt(te(t,Ae(r=>r),ut()));return nt(t,r=>{r&&bt(e)("props updated",{},Kt.DEBUG)}),{didMount:n,propsReady:t}},ct(Pn),{singleton:!0}),Q0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function pf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Q0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Qr=Xe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ve(),y=Ve(),g=ie(0);let v=null,x=null,b=null;function k(){v&&(v(),v=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Pe(l,!1)}return xe(te(p,Oe(n,f,r,g,a,i,h),Oe(e,s,o),ue(([[T,S,C,I,A,R,D,B],X,G,M])=>{const U=pf(T),{align:E,behavior:P,offset:L}=U,_=I-1,q=df(U,S,_);let Y=Zr(q,S.offsetTree,X)+R;E==="end"?(Y+=G+un(S.sizeTree,q)[1]-C+M,q===_&&(Y+=D)):E==="center"?Y+=(G+un(S.sizeTree,q)[1]-C+M)/2:Y-=A,L&&(Y+=L);const j=J=>{k(),J?(B("retrying to scroll to",{location:T},Kt.DEBUG),Pe(p,T)):(Pe(y,!0),B("list did not change, scroll successful",{},Kt.DEBUG))};if(k(),P==="smooth"){let J=!1;b=nt(t,V=>{J=J||V}),v=cn(d,()=>{j(J)})}else v=cn(te(t,eS(150)),j);return x=setTimeout(()=>{k()},1200),Pe(l,!0),B("scrolling from index to",{behavior:P,index:q,top:Y},Kt.DEBUG),{behavior:P,top:Y}})),u),{scrollTargetReached:y,scrollToIndex:p,topListHeight:g}},ct(wn,zt,Pn),{singleton:!0});function eS(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ba(e,t){e==0?t():requestAnimationFrame(()=>{ba(e-1,t)})}function wa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const eo=Xe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ie(!0),l=ie(0),u=ie(!0);return xe(te(i,Oe(l),Ae(([d,f])=>!!f),vn(!1)),a),xe(te(i,Oe(l),Ae(([d,f])=>!!f),vn(!1)),u),nt(te(wt(t,i),Oe(a,n,e,u),Ae(([[,d],f,{sizeTree:h},p,y])=>d&&(!it(h)||ca(p))&&!f&&!y),Oe(l)),([,d])=>{cn(o,()=>{Pe(u,!0)}),ba(4,()=>{cn(r,()=>{Pe(a,!0)}),Pe(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(wn,zt,Qr,Dn),{singleton:!0});function mf(e,t){return Math.abs(e-t)<1.01}const to="up",no="down",tS="none",nS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},rS=0,ro=Xe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ie(!1),a=ie(!0),l=Ve(),u=Ve(),d=ie(4),f=ie(rS),h=Ot(te(da(te(Te(o),Zn(1),vn(!0)),te(Te(o),Zn(1),vn(!1),Jd(100))),ut()),!1),p=Ot(te(da(te(n,vn(!0)),te(n,vn(!1),Jd(200))),ut()),!1);xe(te(wt(Te(o),Te(f)),ue(([b,k])=>b<=k),ut()),a),xe(te(a,En(50)),u);const y=Xt(te(wt(r,Te(s),Te(t),Te(e),Te(d)),bn((b,[{scrollHeight:k,scrollTop:T},S,C,I,A])=>{const R=T+S-k>-A,D={scrollHeight:k,scrollTop:T,viewportHeight:S};if(R){let X,G;return T>b.state.scrollTop?(X="SCROLLED_DOWN",G=b.state.scrollTop-T):(X="SIZE_DECREASED",G=b.state.scrollTop-T||b.scrollTopDelta),{atBottom:!0,atBottomBecause:X,scrollTopDelta:G,state:D}}let B;return D.scrollHeight>b.state.scrollHeight?B="SIZE_INCREASED":S<b.state.viewportHeight?B="VIEWPORT_HEIGHT_DECREASING":T<b.state.scrollTop?B="SCROLLING_UPWARDS":B="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:B,state:D}},nS),ut((b,k)=>b&&b.atBottom===k.atBottom))),g=Ot(te(r,bn((b,{scrollHeight:k,scrollTop:T,viewportHeight:S})=>{if(mf(b.scrollHeight,k))return{changed:!1,jump:0,scrollHeight:k,scrollTop:T};{const C=k-(T+S)<1;return b.scrollTop!==T&&C?{changed:!0,jump:b.scrollTop-T,scrollHeight:k,scrollTop:T}:{changed:!0,jump:0,scrollHeight:k,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(b=>b.changed),ue(b=>b.jump)),0);xe(te(y,ue(b=>b.atBottom)),i),xe(te(i,En(50)),l);const v=ie(no);xe(te(r,ue(({scrollTop:b})=>b),ut(),bn((b,k)=>bt(p)?{direction:b.direction,prevScrollTop:k}:{direction:k<b.prevScrollTop?to:no,prevScrollTop:k},{direction:no,prevScrollTop:0}),ue(b=>b.direction)),v),xe(te(r,En(50),vn(tS)),v);const x=ie(0);return xe(te(h,Ae(b=>!b),vn(0)),x),xe(te(o,En(100),Oe(h),Ae(([b,k])=>!!k),bn(([b,k],[T])=>[k,T],[0,0]),ue(([b,k])=>k-b)),x),{atBottomState:y,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:v,scrollVelocity:x}},ct(zt)),Is="top",Es="bottom",gf="none";function xf(e,t,n){return typeof e=="number"?n===to&&t===Is||n===no&&t===Es?e:0:n===to?t===Is?e.main:e.reverse:t===Es?e.main:e.reverse}function yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Sa=Xe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ve(),i=ie(0),a=ie(0),l=ie(0),u=Ot(te(wt(Te(r),Te(o),Te(n),Te(s,Jr),Te(l),Te(i),Te(t),Te(e),Te(a)),ue(([d,f,h,[p,y],g,v,x,b,k])=>{const T=d-b,S=v+x,C=Math.max(h-T,0);let I=gf;const A=yf(k,Is),R=yf(k,Es);return p-=b,p+=h+x,y+=h+x,y-=b,p>d+S-A&&(I=to),y<d-C+f+R&&(I=no),I!==gf?[Math.max(T-h-xf(g,Is,I)-A,0),T-C-x+f+xf(g,Es,I)+R]:null}),Ae(d=>d!=null),ut(Jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},ct(zt),{singleton:!0});function oS(e,t,n){if(Ts(t)){const r=uf(e,t);return[{index:un(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ca={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ns(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,y=h-d;return{bottom:d,firstItemIndex:s,items:bf(e,o,s),offsetBottom:y,offsetTop:u,top:p,topItems:bf(t,o,s),topListHeight:t.reduce((g,v)=>v.size+g,0),totalCount:n}}function vf(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=wa(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Ns(u,[],a,o,n,r)}function bf(e,t,n){if(e.length===0)return[];if(!Ts(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Ss(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const tr=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:y}])=>{const g=ie([]),v=ie(0),x=Ve();xe(s.topItemsIndexes,g);const b=Ot(te(wt(p,y,Te(l,Jr),Te(o),Te(r),Te(u),d,Te(g),Te(t),Te(n),e),Ae(([C,I,,A,,,,,,,R])=>{const D=R&&R.length!==A;return C&&!I&&!D}),ue(([,,[C,I],A,R,D,B,X,G,M,U])=>{const E=R,{offsetTree:P,sizeTree:L}=E,_=bt(v);if(A===0)return{...Ca,totalCount:A};if(C===0&&I===0)return _===0?{...Ca,totalCount:A}:vf(_,D,R,G,M,U||[]);if(it(L))return _>0?null:Ns(oS(wa(D,A),E,U),[],A,M,E,G);const q=[];if(X.length>0){const H=X[0],ee=X[X.length-1];let W=0;for(const O of Ss(L,H,ee)){const K=O.value,z=Math.max(O.start,H),ne=Math.min(O.end,ee);for(let Q=z;Q<=ne;Q++)q.push({data:U==null?void 0:U[Q],index:Q,offset:W,size:K}),W+=K}}if(!B)return Ns([],q,A,M,E,G);const Y=X.length>0?X[X.length-1]+1:0,j=K0(P,C,I,Y);if(j.length===0)return null;const J=A-1,V=ws([],H=>{for(const ee of j){const W=ee.value;let O=W.offset,K=ee.start;const z=W.size;if(W.offset<C){K+=Math.floor((C-W.offset+M)/(z+M));const Q=K-ee.start;O+=Q*z+Q*M}K<Y&&(O+=(Y-K)*z,K=Y);const ne=Math.min(ee.end,J);for(let Q=K;Q<=ne&&!(O>=I);Q++)H.push({data:U==null?void 0:U[Q],index:Q,offset:O,size:z}),O+=z+M}});return Ns(V,q,A,M,E,G)}),Ae(C=>C!==null),ut()),Ca);xe(te(e,Ae(ca),ue(C=>C==null?void 0:C.length)),o),xe(te(b,ue(C=>C.topListHeight)),f),xe(f,a),xe(te(b,ue(C=>[C.top,C.bottom])),i),xe(te(b,ue(C=>C.items)),x);const k=Xt(te(b,Ae(({items:C})=>C.length>0),Oe(o,e),Ae(([{items:C},I])=>C[C.length-1].originalIndex===I-1),ue(([,C,I])=>[C-1,I]),ut(Jr),ue(([C])=>C))),T=Xt(te(b,En(200),Ae(({items:C,topItems:I})=>C.length>0&&C[0].originalIndex===I.length),ue(({items:C})=>C[0].index),ut())),S=Xt(te(b,Ae(({items:C})=>C.length>0),ue(({items:C})=>{let I=0,A=C.length-1;for(;C[I].type==="group"&&I<A;)I++;for(;C[A].type==="group"&&A>I;)A--;return{endIndex:C[A].index,startIndex:C[I].index}}),ut(lf)));return{endReached:k,initialItemCount:v,itemsRendered:x,listState:b,rangeChanged:S,startReached:T,topItemsIndexes:g,...h}},ct(wn,hf,Sa,eo,Qr,ro,Dn,xa),{singleton:!0}),wf=Xe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ve(),i=Ot(te(wt(n,e,r,t,o),ue(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return xe(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(zt,tr),{singleton:!0}),sS=Xe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ie(!1),r=Ot(te(wt(n,e,t),Ae(([o])=>o),ue(([,o,s])=>Math.max(0,o-s)),En(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(zt,wf),{singleton:!0}),Sf=Xe(()=>({context:ie(null)})),iS=({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,Cf=Xe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ve();return xe(te(d,Oe(t,l,n,s,o,r,a),Oe(e),ue(([[f,h,p,y,g,v,x,b],k])=>{const{align:T,behavior:S,calculateViewLocation:C=iS,done:I,...A}=f,R=df(f,h,y-1),D=Zr(R,h.offsetTree,k)+g+v,B=D+un(h.sizeTree,R)[1],X=b+v,G=b+p-x,M=C({itemBottom:B,itemTop:D,locationParams:{align:T,behavior:S,...A},viewportBottom:G,viewportTop:X});return M?I&&cn(te(i,Ae(U=>!U),Zn(bt(i)?1:2)),I):I&&I(),M}),Ae(f=>f!==null)),u),{scrollIntoView:d}},ct(wn,zt,Qr,tr,Pn),{singleton:!0});function kf(e){return e?e==="smooth"?"smooth":"auto":!1}const aS=(e,t)=>typeof e=="function"?kf(e(t)):t&&kf(e),lS=Xe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const y=ie(!1),g=Ve();let v=null;function x(S){Pe(i,{align:"end",behavior:S,index:"LAST"})}nt(te(wt(te(Te(t),Zn(1)),l),Oe(Te(y),s,a,f),ue(([[S,C],I,A,R,D])=>{let B=C&&R,X="auto";return B&&(X=aS(I,A||D),B=B&&!!X),{followOutputBehavior:X,shouldFollow:B,totalCount:S}}),Ae(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:C})=>{v&&(v(),v=null),bt(n)?requestAnimationFrame(()=>{bt(d)("following output to ",{totalCount:C},Kt.DEBUG),x(S)}):v=cn(e,()=>{bt(d)("following output to ",{totalCount:C},Kt.DEBUG),x(S),v=null})});function b(S){const C=cn(o,I=>{S&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(bt(d)("scrolling to bottom due to increased size",{},Kt.DEBUG),x("auto"))});setTimeout(C,100)}nt(te(wt(Te(y),t,u),Ae(([S,,C])=>S&&C),bn(({value:S},[,C])=>({refreshed:S===C,value:C}),{refreshed:!1,value:0}),Ae(({refreshed:S})=>S),Oe(y,t)),([,S])=>{bt(a)&&b(S!==!1)}),nt(g,()=>{b(bt(y)!==!1)}),nt(wt(Te(y),o),([S,C])=>{S&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const k=ie(null),T=Ve();return xe(da(te(Te(r),ue(S=>{var C;return(C=S==null?void 0:S.length)!=null?C:0})),te(Te(t))),T),nt(te(wt(te(T,Zn(1)),l),Oe(Te(k),a,f,h),ue(([[S,C],I,A,R,D])=>C&&A&&(I==null?void 0:I({context:D,totalCount:S,scrollingInProgress:R}))),Ae(S=>!!S),En(0)),S=>{v&&(v(),v=null),bt(n)?requestAnimationFrame(()=>{bt(d)("scrolling into view",{}),Pe(p,S)}):v=cn(e,()=>{bt(d)("scrolling into view",{}),Pe(p,S),v=null})}),{autoscrollToBottom:g,followOutput:y,scrollIntoViewOnChange:k}},ct(wn,ro,Qr,eo,Dn,Pn,zt,Sf,Cf)),cS=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(xe(te(a,Oe(s),Ae(([,l])=>l!==0),Oe(o,r,t,n,e),ue(([[,l],u,d,f,h,p=[]])=>vf(l,u,d,f,h,p))),i),{}),ct(wn,eo,tr,Dn),{singleton:!0}),uS=Xe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ie(0);return nt(te(e,Oe(r),Ae(([,o])=>o!==0),ue(([,o])=>({top:o}))),o=>{cn(te(n,Zn(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Pe(t,o)})})}),{initialScrollTop:r}},ct(Dn,zt,tr),{singleton:!0}),Tf=Xe(([{scrollVelocity:e}])=>{const t=ie(!1),n=Ve(),r=ie(!1);return xe(te(e,Oe(r,t,n),Ae(([o,s])=>!!s),ue(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),ut()),t),nt(te(wt(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}},ct(ro),{singleton:!0}),ka=Xe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ve(),r=Ve(),o=Ve(),s=ie(!1),i=ie(void 0);return xe(te(wt(n,r),ue(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),xe(te(t,Oe(r),ue(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(zt)),dS=Xe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ve(),d=ie(void 0),f=ie(null),h=ie(null);return xe(a,f),xe(l,h),nt(te(u,Oe(t,r,i,f,h,n)),([p,y,g,v,x,b,k])=>{const T=G0(y.sizeTree);v&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=k,p({ranges:T,scrollTop:g})}),xe(te(d,Ae(ca),ue(fS)),o),xe(te(s,Oe(d),Ae(([,p])=>p!==void 0),ut(),ue(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},ct(wn,zt,eo,Dn,ka));function fS(e){return{align:"start",index:0,offset:e.scrollTop}}const hS=Xe(([{topItemsIndexes:e}])=>{const t=ie(0);return xe(te(t,Ae(n=>n>=0),ue(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(tr));function If(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const pS=If(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),mS=Xe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:y}])=>{const g=Xt(te(l,Oe(i),bn(([,x,b,k],[{bottom:T,items:S,offsetBottom:C,totalCount:I},A])=>{const R=T+C;let D=0;return b===I&&x.length>0&&S.length>0&&(S[0].originalIndex===0&&x[0].originalIndex===0||(D=R-k,D!==0&&(D+=A))),[D,S,I,R]},[0,[],0,0]),Ae(([x])=>x!==0),Oe(r,a,n,o,p,y),Ae(([,x,b,k,,,T])=>!T&&!k&&x!==0&&b===to),ue(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Kt.DEBUG),x))));function v(x){x>0?(Pe(t,{behavior:"auto",top:-x}),Pe(e,0)):(Pe(e,0),Pe(t,{behavior:"auto",top:-x}))}return nt(te(g,Oe(e,s)),([x,b,k])=>{k&&pS()?Pe(e,b-x):v(-x)}),nt(te(wt(Ot(s,!1),e,y),Ae(([x,b,k])=>!x&&!k&&b!==0),ue(([x,b])=>b),En(1)),v),xe(te(f,ue(x=>({top:-x}))),t),nt(te(u,Oe(h,d),ue(([x,{groupIndices:b,lastSize:k,sizeTree:T},S])=>{function C(I){return I*(k+S)}if(b.length===0)return C(x);{let I=0;const A=Xr(T,0);let R=0,D=0;for(;R<x;){R++,I+=A;let B=b.length===D+1?1/0:b[D+1]-b[D]-1;R+B>x&&(I-=A,B=x-R+1),R+=B,I+=C(B),D++}return I}})),x=>{Pe(e,x),requestAnimationFrame(()=>{Pe(t,{top:x}),requestAnimationFrame(()=>{Pe(e,0),Pe(y,!1)})})}),{deviation:e}},ct(zt,ro,tr,wn,Pn,xa)),gS=Xe(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),ct(Sa,cS,Dn,Tf,wf,uS,sS,ka,Cf,Pn,Sf)),Ef=Xe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:y},g,v,x,{listState:b,topItemsIndexes:k,...T},{scrollToIndex:S},C,{topItemCount:I},{groupCounts:A},R])=>(xe(T.rangeChanged,R.scrollSeekRangeChanged),xe(te(R.windowViewportRect,ue(D=>D.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:y,sizeRanges:a,topItemCount:I,topItemsIndexes:k,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:S,statefulTotalCount:u,trackItemSizes:f,...T,...R,...g,sizes:l,...v}),ct(wn,eo,zt,dS,lS,tr,Qr,mS,hS,hf,gS));function xS(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const As=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Nf(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(v,x){v.propsReady&&Pe(v.propsReady,!1);for(const b of r){const k=v[t.required[b]];Pe(k,x[b])}for(const b of o)if(b in x){const k=v[t.optional[b]];Pe(k,x[b])}v.propsReady&&Pe(v.propsReady,!0)}function u(v){return s.reduce((x,b)=>(x[b]=k=>{const T=v[t.methods[b]];Pe(T,k)},x),{})}function d(v){return i.reduce((x,b)=>(x[b]=R0(v[t.events[b]]),x),{})}const f=w.forwardRef((v,x)=>{const{children:b,...k}=v,[T]=w.useState(()=>ws(O0(e),I=>{l(I,k)})),[S]=w.useState(Xd(d,T));As(()=>{for(const I of i)I in k&&nt(S[I],k[I]);return()=>{Object.values(S).map(ua)}},[k,S,T]),As(()=>{l(T,k)}),w.useImperativeHandle(x,Gd(u(T)));const C=n;return c.jsx(a.Provider,{value:T,children:n?c.jsx(C,{...xS([...r,...o,...i],k),children:b}):b})}),h=v=>{const x=w.useContext(a);return w.useCallback(b=>{Pe(x[v],b)},[x,v])},p=v=>{const x=w.useContext(a)[v],b=w.useCallback(k=>nt(x,k),[x]);return w.useSyncExternalStore(b,()=>bt(x),()=>bt(x))},y=v=>{const x=w.useContext(a)[v],[b,k]=w.useState(Xd(bt,x));return As(()=>nt(x,T=>{T!==b&&k(Gd(T))}),[x,b]),b},g=w.version.startsWith("18")?p:y;return{Component:f,useEmitter:(v,x)=>{const b=w.useContext(a)[v];As(()=>nt(b,x),[x,b])},useEmitterValue:g,usePublisher:h}}const Af=w.createContext(void 0),jf=w.createContext(void 0),_f=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Ta(e){return"self"in e}function yS(e){return"body"in e}function Mf(e,t,n,r=Tr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),u=w.useCallback(h=>{let p,y,g;const v=h.target;if(yS(v)||Ta(v)){const b=Ta(v)?v:v.defaultView;g=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,y=s?b.innerWidth:b.innerHeight}else g=s?v.scrollLeft:v.scrollTop,p=s?v.scrollWidth:v.scrollHeight,y=s?v.offsetWidth:v.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:y})};h.suppressFlushSync?x():si.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-y)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const y=h.behavior==="smooth";let g,v,x;Ta(p)?(v=Math.max(On(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(v=p[s?"scrollWidth":"scrollHeight"],g=On(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=v-g;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),mf(g,v)||h.top===x){e({scrollHeight:v,scrollTop:x,viewportHeight:g}),y&&t(!0);return}y?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ia="-webkit-sticky",Rf="sticky",Ea=If(()=>{if(typeof document>"u")return Rf;const e=document.createElement("div");return e.style.position=Ia,e.style.position===Ia?Ia:Rf});function Na(e){return e}const vS=Xe(()=>{const e=ie(a=>`Item ${a}`),t=ie(a=>`Group ${a}`),n=ie({}),r=ie(Na),o=ie("div"),s=ie(Tr),i=(a,l=null)=>Ot(te(n,ue(u=>u[a]),ut()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),bS=Xe(([e,t])=>({...e,...t}),ct(Ef,vS)),wS=({height:e})=>c.jsx("div",{style:{height:e}}),SS={overflowAnchor:"none",position:Ea(),zIndex:1},Pf={overflowAnchor:"none"},CS={...Pf,display:"inline-block",height:"100%"},Of=w.memo(function({showTopList:e=!1}){const t=_e("listState"),n=en("sizeRanges"),r=_e("useWindowScroll"),o=_e("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=_e("itemContent"),u=_e("context"),d=_e("groupContent"),f=_e("trackItemSizes"),h=_e("itemSize"),p=_e("log"),y=en("gap"),g=_e("horizontalDirection"),{callbackRef:v}=$0(n,h,f,e?Tr:a,p,y,o,g,_e("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);Aa("deviation",M=>{x!==M&&b(M)});const k=_e("EmptyPlaceholder"),T=_e("ScrollSeekPlaceholder")||wS,S=_e("ListComponent"),C=_e("ItemComponent"),I=_e("GroupComponent"),A=_e("computeItemKey"),R=_e("isSeeking"),D=_e("groupIndices").length>0,B=_e("alignToBottom"),X=_e("initialItemFinalLocationReached"),G=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},...X?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&k?c.jsx(k,{...Dt(k,u)}):c.jsx(S,{...Dt(S,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:G,children:(e?t.topItems:t.items).map(M=>{const U=M.originalIndex,E=A(U+t.firstItemIndex,M.data,u);return R?w.createElement(T,{...Dt(T,u),height:M.size,index:M.index,key:E,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?w.createElement(I,{...Dt(I,u),"data-index":U,"data-item-index":M.index,"data-known-size":M.size,key:E,style:SS},d(M.index,u)):w.createElement(C,{...Dt(C,u),...ES(C,M.data),"data-index":U,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:E,style:g?CS:Pf},D?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),kS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},TS={outline:"none",overflowX:"auto",position:"relative"},js=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),IS={position:Ea(),top:0,width:"100%",zIndex:1};function Dt(e,t){if(typeof e!="string")return{context:t}}function ES(e,t){return{item:typeof e=="string"?void 0:t}}const NS=w.memo(function(){const e=_e("HeaderComponent"),t=en("headerHeight"),n=_e("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Dt(e,o)})}):null}),AS=w.memo(function(){const e=_e("FooterComponent"),t=en("footerHeight"),n=_e("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Dt(e,o)})}):null});function Df({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:y}=Mf(a,u,l,d,void 0,f);return e("scrollTo",y),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?TS:kS,...o},tabIndex:0,...i,...Dt(l,s),children:r})})}function Lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),y=t("scrollerRef"),{scrollByCallback:g,scrollerRef:v,scrollToCallback:x}=Mf(a,u,l,y,h);return _f(()=>{var b;return v.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",x),e("scrollBy",g),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Dt(l,s),children:r})})}const jS=({children:e})=>{const t=w.useContext(Af),n=en("viewportHeight"),r=en("fixedItemHeight"),o=_e("alignToBottom"),s=_e("horizontalDirection"),i=w.useMemo(()=>Yd(n,l=>On(l,s?"width":"height")),[n,s]),a=Qn(i,!0,_e("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:js(o),children:e})},_S=({children:e})=>{const t=w.useContext(Af),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=_e("customScrollParent"),s=ef(n,o,_e("skipAnimationFrameInResizeObserver")),i=_e("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:js(i),children:e})},MS=({children:e})=>{const t=_e("TopItemListComponent")||"div",n=_e("headerHeight"),r={...IS,marginTop:`${n}px`},o=_e("context");return c.jsx(t,{style:r,...Dt(t,o),children:e})},RS=w.memo(function(e){const t=_e("useWindowScroll"),n=_e("topItemsIndexes").length>0,r=_e("customScrollParent"),o=_e("context");return c.jsxs(r||t?DS:OS,{...e,context:o,children:[n&&c.jsx(MS,{children:c.jsx(Of,{showTopList:!0})}),c.jsxs(r||t?_S:jS,{children:[c.jsx(NS,{}),c.jsx(Of,{}),c.jsx(AS,{})]})]})}),{Component:PS,useEmitter:Aa,useEmitterValue:_e,usePublisher:en}=Nf(bS,{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"}},RS),OS=Df({useEmitter:Aa,useEmitterValue:_e,usePublisher:en}),DS=Lf({useEmitter:Aa,useEmitterValue:_e,usePublisher:en}),LS=PS;ct(Ef,Xe(()=>{const e=ie(u=>c.jsxs("td",{children:["Item $",u]})),t=ie(null),n=ie(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=ie(null),o=ie(null),s=ie({}),i=ie(Na),a=ie(Tr),l=(u,d=null)=>Ot(te(s,ue(f=>f[u]),ut()),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")}})),Ea();const $f={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},$S={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ff,floor:_s,max:oo,min:ja,round:Bf}=Math;function zf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function FS(e){return{...$S,items:e}}function Ms(e,t){return e&&e.width===t.width&&e.height===t.height}function BS(e,t){return e&&e.column===t.column&&e.row===t.row}const zS=Xe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:y,propsReady:g},{customScrollParent:v,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:k,windowViewportRect:T},S])=>{const C=ie(0),I=ie(0),A=ie($f),R=ie({height:0,width:0}),D=ie({height:0,width:0}),B=Ve(),X=Ve(),G=ie(0),M=ie(null),U=ie({column:0,row:0}),E=Ve(),P=Ve(),L=ie(!1),_=ie(0),q=ie(!0),Y=ie(!1),j=ie(!1);nt(te(y,Oe(_),Ae(([O,K])=>!!K)),()=>{Pe(q,!1)}),nt(te(wt(y,q,D,R,_,Y),Ae(([O,K,z,ne,,Q])=>O&&!K&&z.height!==0&&ne.height!==0&&!Q)),([,,,,O])=>{Pe(Y,!0),ba(1,()=>{Pe(B,O)}),cn(te(u),()=>{Pe(t,[0,0]),Pe(q,!0)})}),xe(te(P,Ae(O=>O!=null&&O.scrollTop>0),vn(0)),I),nt(te(y,Oe(P),Ae(([,O])=>O!=null)),([,O])=>{O&&(Pe(R,O.viewport),Pe(D,O.item),Pe(U,O.gap),O.scrollTop>0&&(Pe(L,!0),cn(te(u,Zn(1)),K=>{Pe(L,!1)}),Pe(l,{top:O.scrollTop})))}),xe(te(R,ue(({height:O})=>O)),f),xe(te(wt(Te(R,Ms),Te(D,Ms),Te(U,(O,K)=>O&&O.column===K.column&&O.row===K.row),Te(u)),ue(([O,K,z,ne])=>({gap:z,item:K,scrollTop:ne,viewport:O}))),E),xe(te(wt(Te(C),r,Te(U,BS),Te(D,Ms),Te(R,Ms),Te(M),Te(I),Te(L),Te(q),Te(_)),Ae(([,,,,,,,O])=>!O),ue(([O,[K,z],ne,Q,ge,le,oe,,pe,be])=>{const{column:Me,row:Ie}=ne,{height:De,width:et}=Q,{width:rt}=ge;if(oe===0&&(O===0||rt===0))return $f;if(et===0){const Ke=wa(be,O),xt=Ke+Math.max(oe-1,0);return FS(zf(Ke,xt,le))}const He=Uf(rt,et,Me);let Je,ot;pe?K===0&&z===0&&oe>0?(Je=0,ot=oe-1):(Je=He*_s((K+Ie)/(De+Ie)),ot=He*Ff((z+Ie)/(De+Ie))-1,ot=ja(O-1,oo(ot,He-1)),Je=ja(ot,oo(0,Je))):(Je=0,ot=-1);const St=zf(Je,ot,le),{bottom:dt,top:Tt}=Hf(ge,ne,Q,St),mt=Ff(O/He),Ee=mt*De+(mt-1)*Ie-dt;return{bottom:dt,itemHeight:De,items:St,itemWidth:et,offsetBottom:Ee,offsetTop:Tt,top:Tt}})),A),xe(te(M,Ae(O=>O!==null),ue(O=>O.length)),C),xe(te(wt(R,D,A,U),Ae(([O,K,{items:z}])=>z.length>0&&K.height!==0&&O.height!==0),ue(([O,K,{items:z},ne])=>{const{bottom:Q,top:ge}=Hf(O,ne,K,z);return[ge,Q]}),ut(Jr)),t);const J=ie(!1);xe(te(u,Oe(J),ue(([O,K])=>K||O!==0)),J);const V=Xt(te(wt(A,C),Ae(([{items:O}])=>O.length>0),Oe(J),Ae(([[O,K],z])=>{const ne=O.items[O.items.length-1].index===K-1;return(z||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===K)&&ne}),ue(([[,O]])=>O-1),ut())),H=Xt(te(Te(A),Ae(({items:O})=>O.length>0&&O[0].index===0),vn(0),ut())),ee=Xt(te(Te(A),Oe(L),Ae(([{items:O},K])=>O.length>0&&!K),ue(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),ut(lf),En(0)));xe(ee,p.scrollSeekRangeChanged),xe(te(B,Oe(R,D,C,U),ue(([O,K,z,ne,Q])=>{const ge=pf(O),{align:le,behavior:oe,offset:pe}=ge;let be=ge.index;be==="LAST"&&(be=ne-1),be=oo(0,be,ja(ne-1,be));let Me=_a(K,Q,z,be);return le==="end"?Me=Bf(Me-K.height+z.height):le==="center"&&(Me=Bf(Me-K.height/2+z.height/2)),pe&&(Me+=pe),{behavior:oe,top:Me}})),l);const W=Ot(te(A,ue(O=>O.offsetBottom+O.bottom)),0);return xe(te(T,ue(O=>({height:O.visibleHeight,width:O.visibleWidth}))),R),{customScrollParent:v,data:M,deviation:G,footerHeight:o,gap:U,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:D,overscan:n,restoreStateFrom:P,scrollBy:i,scrollContainerState:a,scrollHeight:X,scrollTo:l,scrollToIndex:B,scrollTop:u,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:x,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:k,windowViewportRect:T,...p,gridState:A,horizontalDirection:j,initialTopMostItemIndex:_,totalListHeight:W,...h,endReached:V,propsReady:g,rangeChanged:ee,startReached:H,stateChanged:E,stateRestoreInProgress:L,...S}},ct(Sa,zt,ro,Tf,Dn,ka,Pn));function Uf(e,t,n){return oo(1,_s((e+n)/(_s(t)+n)))}function Hf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=_a(e,t,n,r[0].index);return{bottom:_a(e,t,n,r[r.length-1].index)+o,top:s}}function _a(e,t,n,r){const o=Uf(e.width,n.width,t.column),s=_s(r/o),i=s*n.height+oo(0,s-1)*t.row;return i>0?i+t.row:i}const US=Xe(()=>{const e=ie(f=>`Item ${f}`),t=ie({}),n=ie(null),r=ie("virtuoso-grid-item"),o=ie("virtuoso-grid-list"),s=ie(Na),i=ie("div"),a=ie(Tr),l=(f,h=null)=>Ot(te(t,ue(p=>p[f]),ut()),h),u=ie(!1),d=ie(!1);return xe(Te(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),HS=Xe(([e,t])=>({...e,...t}),ct(zS,US)),WS=w.memo(function(){const e=ht("gridState"),t=ht("listClassName"),n=ht("itemClassName"),r=ht("itemContent"),o=ht("computeItemKey"),s=ht("isSeeking"),i=tn("scrollHeight"),a=ht("ItemComponent"),l=ht("ListComponent"),u=ht("ScrollSeekPlaceholder"),d=ht("context"),f=tn("itemDimensions"),h=tn("gap"),p=ht("log"),y=ht("stateRestoreInProgress"),g=tn("reportReadyState"),v=Qn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const k=x.firstChild;if(k){const{height:T,width:S}=k.getBoundingClientRect();f({height:T,width:S})}h({column:Vf("column-gap",getComputedStyle(x).columnGap,p),row:Vf("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return _f(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),y?null:c.jsx(l,{className:t,ref:v,...Dt(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?c.jsx(u,{...Dt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...Dt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),VS=w.memo(function(){const e=ht("HeaderComponent"),t=tn("headerHeight"),n=ht("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ht("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Dt(e,o)})}):null}),KS=w.memo(function(){const e=ht("FooterComponent"),t=tn("footerHeight"),n=ht("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ht("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Dt(e,o)})}):null}),qS=({children:e})=>{const t=w.useContext(jf),n=tn("itemDimensions"),r=tn("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]),c.jsx("div",{ref:o,style:js(!1),children:e})},GS=({children:e})=>{const t=w.useContext(jf),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=ht("customScrollParent"),s=ef(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]),c.jsx("div",{ref:s,style:js(!1),children:e})},YS=w.memo(function({...e}){const t=ht("useWindowScroll"),n=ht("customScrollParent"),r=n||t?JS:XS,o=n||t?GS:qS,s=ht("context");return c.jsx(r,{...e,...Dt(r,s),children:c.jsxs(o,{children:[c.jsx(VS,{}),c.jsx(WS,{}),c.jsx(KS,{})]})})}),{useEmitter:Wf,useEmitterValue:ht,usePublisher:tn}=Nf(HS,{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"}},YS),XS=Df({useEmitter:Wf,useEmitterValue:ht,usePublisher:tn}),JS=Lf({useEmitter:Wf,useEmitterValue:ht,usePublisher:tn});function Vf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Kt.WARN),t==="normal"?0:parseInt(t??"0",10)}const ZS=bo.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 Kf({className:e,variant:t,...n}){return c.jsx("div",{className:se(ZS({variant:t}),e),...n})}function Ma(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 qf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function so(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(so).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(qf(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=so(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 io(e){if(typeof e=="string")return e;if(qf(e))return"";try{const t=so(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function QS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function eC(e){const t=io(e);return typeof e=="string"&&QS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Rs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ma(t);if(n!==null)return Rs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Rs(e.content):e}function tC(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Gf(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 Ps(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function nC(e){const t=r=>{try{const o=so(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 rC(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Yf(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 oC(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function sC(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function iC({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=oC(n),i=o?`data:${s};base64,${e}`:t,a=sC(r),l=a.length?a.join(" / "):void 0,u=l?`${l} artifact`:"artifact image";return{src:i,alt:u,label:l}}function aC(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 iC({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Xf(e,t){return await Vt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Jf(e,t){return await(await Xf(`/files/${e}/view`,t)).text()}async function lC(e,t){const n=await Xf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Vt(`/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 cC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Vt("/files",{params:r})}var Os="Dialog",[Zf,AI]=kn(Os),[uC,dn]=Zf(Os),Qf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[u,d]=mr({prop:r,defaultProp:o??!1,onChange:s,caller:Os});return c.jsx(uC,{scope:t,triggerRef:a,contentRef:l,contentId:Ft(),titleId:Ft(),descriptionId:Ft(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Qf.displayName=Os;var eh="DialogTrigger",th=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(eh,n),s=We(t,o.triggerRef);return c.jsx(Se.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Oa(o.open),...r,ref:s,onClick:fe(e.onClick,o.onOpenToggle)})});th.displayName=eh;var Ra="DialogPortal",[dC,nh]=Zf(Ra,{forceMount:void 0}),rh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=dn(Ra,t);return c.jsx(dC,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Zt,{present:n||s.open,children:c.jsx(ns,{asChild:!0,container:o,children:i})}))})};rh.displayName=Ra;var Ds="DialogOverlay",oh=m.forwardRef((e,t)=>{const n=nh(Ds,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=dn(Ds,e.__scopeDialog);return s.modal?c.jsx(Zt,{present:r||s.open,children:c.jsx(hC,{...o,ref:t})}):null});oh.displayName=Ds;var fC=Wn.createSlot("DialogOverlay.RemoveScroll"),hC=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(Ds,n);return c.jsx(ds,{as:fC,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(Se.div,{"data-state":Oa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",sh=m.forwardRef((e,t)=>{const n=nh(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=dn(nr,e.__scopeDialog);return c.jsx(Zt,{present:r||s.open,children:s.modal?c.jsx(pC,{...o,ref:t}):c.jsx(mC,{...o,ref:t})})});sh.displayName=nr;var pC=m.forwardRef((e,t)=>{const n=dn(nr,e.__scopeDialog),r=m.useRef(null),o=We(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Gi(s)},[]),c.jsx(ih,{...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())})}),mC=m.forwardRef((e,t)=>{const n=dn(nr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(ih,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,u;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),ih=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=dn(nr,n),l=m.useRef(null),u=We(t,l);return Ai(),c.jsxs(c.Fragment,{children:[c.jsx(Wo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(Ho,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Oa(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(gC,{titleId:a.titleId}),c.jsx(yC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Pa="DialogTitle",ah=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(Pa,n);return c.jsx(Se.h2,{id:o.titleId,...r,ref:t})});ah.displayName=Pa;var lh="DialogDescription",ch=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(lh,n);return c.jsx(Se.p,{id:o.descriptionId,...r,ref:t})});ch.displayName=lh;var uh="DialogClose",dh=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(uh,n);return c.jsx(Se.button,{type:"button",...r,ref:t,onClick:fe(e.onClick,()=>o.onOpenChange(!1))})});dh.displayName=uh;function Oa(e){return e?"open":"closed"}var fh="DialogTitleWarning",[jI,hh]=py(fh,{contentName:nr,titleName:Pa,docsSlug:"dialog"}),gC=({titleId:e})=>{const t=hh(fh),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 k0(e,t=vs){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 E0(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),k0(t),T0(t)}const bs=0,Rn=1,Cr=2,qd=4;function Gd(e){return()=>e}function I0(e){e()}function Yd(e,t){return n=>e(t(n))}function Xd(e,t){return()=>e(t)}function N0(e,t){return n=>e(t,n)}function ca(e){return e!==void 0}function A0(...e){return()=>{e.map(I0)}}function Tr(){}function ws(e,t){return t(e),e}function j0(e,t){return t(e)}function ct(...e){return e}function tt(e,t){return e(Rn,t)}function Re(e,t){e(bs,t)}function ua(e){e(Cr)}function vt(e){return e(qd)}function xe(e,t){return tt(e,N0(t,bs))}function cn(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Jd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Zd(e,t){return e===t}function ut(e=Zd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ie(e){return t=>n=>{e(n)&&t(n)}}function ue(e){return t=>Yd(t,e)}function vn(e){return t=>()=>{t(e)}}function J(e,...t){const n=_0(...t);return(r,o)=>{switch(r){case Cr:ua(e);return;case Rn:return tt(e,n(o))}}}function bn(e,t){return n=>r=>{n(t=e(t,r))}}function Zn(e){return t=>n=>{e>0?e--:t(n)}}function In(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function De(...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);tt(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function _0(...e){return t=>e.reduceRight(j0,t)}function M0(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=tt(e,s),t):(r(),Tr);case Cr:r(),n=null;return}}}function re(e){let t=e;const n=Ue();return(r,o)=>{switch(r){case bs:t=o;break;case Rn:{o(t);break}case qd:return t}return n(r,o)}}function Rt(e,t){return ws(re(t),n=>xe(e,n))}function Ue(){const e=[];return(t,n)=>{switch(t){case bs:e.slice().forEach(r=>{r(n)});return;case Cr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Yt(e){return ws(Ue(),t=>xe(e,t))}function Ye(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:R0(),singleton:n}}const R0=()=>Symbol();function P0(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=Ue(),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);tt(s,l=>{n[i]=l,r=r|a,r===o&&Re(t,n)})}),function(s,i){switch(s){case Cr:{ua(t);return}case Rn:return r===o&&i(n),tt(t,i)}}}function Te(e,t=Zd){return J(e,ut(t))}function da(...e){return function(t,n){switch(t){case Cr:return;case Rn:return A0(...e.map(r=>tt(r,n)))}}}var Ht=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ht||{});const O0={0:"debug",3:"error",1:"log",2:"warn"},D0=()=>typeof globalThis>"u"?window:globalThis,Pn=Ye(()=>{const e=re(3);return{log:re((t,n,r=1)=>{var o;const s=(o=D0().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[O0[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 fa(e,t,n).callbackRef}function fa(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 L0(e,t,n,r,o,s,i,a,l){const u=w.useCallback(d=>{const f=$0(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let y;p&&(y=h.ownerDocument.defaultView);const g=i?a?i.scrollLeft:i.scrollTop:p?a?y.scrollX||y.document.documentElement.scrollLeft:y.scrollY||y.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:p?a?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,x=i?a?i.offsetWidth:i.offsetHeight:p?a?y.innerWidth:y.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(g,0),viewportHeight:x}),s==null||s(a?Qd("column-gap",getComputedStyle(d).columnGap,o):Qd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return fa(u,n,l)}function $0(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ht.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Qd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ht.WARN),t==="normal"?0:parseInt(t??"0",10)}function ef(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),y=u.top-p.top;h=p.height-Math.max(0,y),f=y+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=fa(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const Bt=Ye(()=>{const e=Ue(),t=Ue(),n=re(0),r=Ue(),o=re(0),s=Ue(),i=Ue(),a=re(0),l=re(0),u=re(0),d=re(0),f=Ue(),h=Ue(),p=re(!1),y=re(!1),g=re(!1);return xe(J(e,ue(({scrollTop:v})=>v)),t),xe(J(e,ue(({scrollHeight:v})=>v)),i),xe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:y,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Gr={lvl:0};function tf(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function st(e){return e===Gr}function Yr(e,t){if(!st(e))return t===e.k?e.v:t<e.k?Yr(e.l,t):Yr(e.r,t)}function un(e,t,n="k"){if(st(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=un(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return un(e.l,t,n)}function Xt(e,t,n){return st(e)?of(t,n,1):t===e.k?St(e,{k:t,v:n}):t<e.k?sf(St(e,{l:Xt(e.l,t,n)})):sf(St(e,{r:Xt(e.r,t,n)}))}function kr(){return Gr}function Ss(e,t,n){if(st(e))return[];const r=un(e,t)[0];return F0(pa(e,r,n))}function ha(e,t){if(st(e))return Gr;const{k:n,l:r,r:o}=e;if(t===n){if(st(r))return o;if(st(o))return r;{const[s,i]=rf(r);return Cs(St(e,{k:s,l:nf(r),v:i}))}}else return t<n?Cs(St(e,{l:ha(r,t)})):Cs(St(e,{r:ha(o,t)}))}function er(e){return st(e)?[]:[...er(e.l),{k:e.k,v:e.v},...er(e.r)]}function pa(e,t,n){if(st(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(pa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(pa(s,t,n))),a}function Cs(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(ma(t))return af(St(e,{lvl:n-1}));if(!st(t)&&!st(t.r))return St(t.r,{l:St(t,{r:t.r.l}),lvl:n,r:St(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ma(e))return ga(St(e,{lvl:n-1}));if(!st(r)&&!st(r.l)){const o=r.l,s=ma(o)?r.lvl-1:r.lvl;return St(o,{l:St(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ga(St(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function St(e,t){return of(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 nf(e){return st(e.r)?e.l:Cs(St(e,{r:nf(e.r)}))}function ma(e){return st(e)||e.lvl>e.r.lvl}function rf(e){return st(e.r)?[e.k,e.v]:rf(e.r)}function of(e,t,n,r=Gr,o=Gr){return{k:e,l:r,lvl:n,r:o,v:t}}function sf(e){return ga(af(e))}function af(e){const{l:t}=e;return!st(t)&&t.lvl===e.lvl?St(t,{r:St(e,{l:t.r})}):e}function ga(e){const{lvl:t,r:n}=e;return!st(n)&&!st(n.r)&&n.lvl===t&&n.r.lvl===t?St(n,{l:St(e,{r:n.l}),lvl:t+1}):e}function F0(e){return tf(e,({k:t,v:n})=>({index:t,value:n}))}function lf(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Xr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const xa=Ye(()=>({recalcInProgress:re(!1)}),[],{singleton:!0});function cf(e,t,n){return e[Ts(e,t,n)]}function Ts(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 B0(e,t,n,r){const o=Ts(e,t,r),s=Ts(e,n,r,o);return e.slice(o,s+1)}function On(e,t){return Math.round(e.getBoundingClientRect()[t])}function ks(e){return!st(e.groupOffsetTree)}function ya({index:e},t){return t===e?0:t<e?-1:1}function z0(){return{groupIndices:[],groupOffsetTree:kr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:kr()}}function U0(e,t){let n=st(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),st(e)){e=Xt(e,0,s);continue}const a=Ss(e,i-1,o+1);if(a.some(Y0(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ha(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Xt(e,o+1,h));u&&(e=Xt(e,i,s))}return[e,n]}function H0(e){return typeof e.groupIndex<"u"}function W0({offset:e},t){return t===e?0:t<e?-1:1}function Jr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=cf(t,e,ya),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function uf(e,t){if(!ks(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function df(e,t,n){if(H0(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=uf(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function V0(e,t,n,r=0){return r>0&&(t=Math.max(t,cf(e,r,ya).offset)),tf(B0(e,t,n,W0),G0)}function K0(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ht.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&st(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((y,g)=>Xt(Xt(y,g,h),g+1,p),i)}else[i,a]=U0(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=va(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Xt(h,p,Jr(p,f,o)),kr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function q0(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 ff(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 va(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Ts(o,t-1,ya),a=o[l].offset;const u=un(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===un(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Ss(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function G0(e){return{index:e.index,value:e}}function Y0(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 X0={offsetHeight:"height",offsetWidth:"width"},wn=Ye(([{log:e},{recalcInProgress:t}])=>{const n=Ue(),r=Ue(),o=Rt(r,0),s=Ue(),i=Ue(),a=re(0),l=re([]),u=re(void 0),d=re(void 0),f=re((S,T)=>On(S,X0[T])),h=re(void 0),p=re(0),y=z0(),g=Rt(J(n,De(l,e,p),bn(K0,y),ut()),y),v=Rt(J(l,ut(),bn((S,T)=>({current:T,prev:S.current}),{current:[],prev:[]}),ue(({prev:S})=>S)),[]);xe(J(l,Ie(S=>S.length>0),De(g,p),ue(([S,T,E])=>{const A=S.reduce((P,$,B)=>Xt(P,$,Jr($,T.offsetTree,E)||B),kr());return{...T,groupIndices:S,groupOffsetTree:A}})),g),xe(J(r,De(g),Ie(([S,{lastIndex:T}])=>S<T),ue(([S,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:S}])),n),xe(u,d);const x=Rt(J(u,ue(S=>S===void 0)),!0);xe(J(d,Ie(S=>S!==void 0&&st(vt(g).sizeTree)),ue(S=>[{endIndex:0,size:S,startIndex:0}])),n);const b=Yt(J(n,De(g),bn(({sizes:S},[T,E])=>({changed:E!==S,sizes:E}),{changed:!1,sizes:y}),ue(S=>S.changed)));tt(J(a,bn((S,T)=>({diff:S.prev-T,prev:T}),{diff:0,prev:0}),ue(S=>S.diff)),S=>{const{groupIndices:T}=vt(g);if(S>0)Re(t,!0),Re(s,S+ff(S,T));else if(S<0){const E=vt(v);E.length>0&&(S-=ff(-S,E)),Re(i,S)}}),tt(J(a,De(e)),([S,T])=>{S<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},Ht.ERROR)});const C=Yt(s);xe(J(s,De(g),ue(([S,T])=>{const E=T.groupIndices.length>0,A=[],P=T.lastSize;if(E){const $=Yr(T.sizeTree,0);let B=0,V=0;for(;B<S;){const O=T.groupIndices[V],U=T.groupIndices.length===V+1?1/0:T.groupIndices[V+1]-O-1;A.push({endIndex:O,size:$,startIndex:O}),A.push({endIndex:O+1+U-1,size:P,startIndex:O+1}),V++,B+=U+1}const G=er(T.sizeTree);return B!==S&&G.shift(),G.reduce((O,{k:U,v:N})=>{let D=O.ranges;return O.prevSize!==0&&(D=[...O.ranges,{endIndex:U+S-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:U+S,prevSize:N,ranges:D}},{prevIndex:S,prevSize:0,ranges:A}).ranges}return er(T.sizeTree).reduce(($,{k:B,v:V})=>({prevIndex:B+S,prevSize:V,ranges:[...$.ranges,{endIndex:B+S-1,size:$.prevSize,startIndex:$.prevIndex}]}),{prevIndex:0,prevSize:P,ranges:[]}).ranges})),n);const k=Yt(J(i,De(g,p),ue(([S,{offsetTree:T},E])=>{const A=-S;return Jr(A,T,E)})));return xe(J(i,De(g,p),ue(([S,T,E])=>{if(T.groupIndices.length>0){if(st(T.sizeTree))return T;let A=kr();const P=vt(v);let $=0,B=0,V=0;for(;$<-S;){V=P[B];const G=P[B+1]-V-1;B++,$+=G+1}if(A=er(T.sizeTree).reduce((G,{k:O,v:U})=>Xt(G,Math.max(0,O+S),U),A),$!==-S){const G=Yr(T.sizeTree,V);A=Xt(A,0,G);const O=un(T.sizeTree,-S+1)[1];A=Xt(A,1,O)}return{...T,sizeTree:A,...va(T.offsetTree,0,A,E)}}else{const A=er(T.sizeTree).reduce((P,{k:$,v:B})=>Xt(P,Math.max(0,$+S),B),kr());return{...T,sizeTree:A,...va(T.offsetTree,0,A,E)}}})),g),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:x,unshiftWith:s}},ct(Pn,xa),{singleton:!0});function J0(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const hf=Ye(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ue(),i=Ue(),a=Yt(J(s,ue(J0)));return xe(J(a,ue(l=>l.totalCount)),n),xe(J(a,ue(l=>l.groupIndices)),e),xe(J(wt(o,t,r),Ie(([l,u])=>ks(u)),ue(([l,u,d])=>un(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),ue(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(wn,Bt)),Dn=Ye(([{log:e}])=>{const t=re(!1),n=Yt(J(t,Ie(r=>r),ut()));return tt(t,r=>{r&&vt(e)("props updated",{},Ht.DEBUG)}),{didMount:n,propsReady:t}},ct(Pn),{singleton:!0}),Z0=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function pf(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Z0)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Zr=Ye(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ue(),y=Ue(),g=re(0);let v=null,x=null,b=null;function C(){v&&(v(),v=null),b&&(b(),b=null),x&&(clearTimeout(x),x=null),Re(l,!1)}return xe(J(p,De(n,f,r,g,a,i,h),De(e,s,o),ue(([[k,S,T,E,A,P,$,B],V,G,O])=>{const U=pf(k),{align:N,behavior:D,offset:M}=U,j=E-1,H=df(U,S,j);let W=Jr(H,S.offsetTree,V)+P;N==="end"?(W+=G+un(S.sizeTree,H)[1]-T+O,H===j&&(W+=$)):N==="center"?W+=(G+un(S.sizeTree,H)[1]-T+O)/2:W-=A,M&&(W+=M);const R=K=>{C(),K?(B("retrying to scroll to",{location:k},Ht.DEBUG),Re(p,k)):(Re(y,!0),B("list did not change, scroll successful",{},Ht.DEBUG))};if(C(),D==="smooth"){let K=!1;b=tt(t,ie=>{K=K||ie}),v=cn(d,()=>{R(K)})}else v=cn(J(t,Q0(150)),R);return x=setTimeout(()=>{C()},1200),Re(l,!0),B("scrolling from index to",{behavior:D,index:H,top:W},Ht.DEBUG),{behavior:D,top:W}})),u),{scrollTargetReached:y,scrollToIndex:p,topListHeight:g}},ct(wn,Bt,Pn),{singleton:!0});function Q0(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ba(e,t){e==0?t():requestAnimationFrame(()=>{ba(e-1,t)})}function wa(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Qr=Ye(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=re(!0),l=re(0),u=re(!0);return xe(J(i,De(l),Ie(([d,f])=>!!f),vn(!1)),a),xe(J(i,De(l),Ie(([d,f])=>!!f),vn(!1)),u),tt(J(wt(t,i),De(a,n,e,u),Ie(([[,d],f,{sizeTree:h},p,y])=>d&&(!st(h)||ca(p))&&!f&&!y),De(l)),([,d])=>{cn(o,()=>{Re(u,!0)}),ba(4,()=>{cn(r,()=>{Re(a,!0)}),Re(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(wn,Bt,Zr,Dn),{singleton:!0});function mf(e,t){return Math.abs(e-t)<1.01}const eo="up",to="down",eS="none",tS={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},nS=0,no=Ye(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=re(!1),a=re(!0),l=Ue(),u=Ue(),d=re(4),f=re(nS),h=Rt(J(da(J(Te(o),Zn(1),vn(!0)),J(Te(o),Zn(1),vn(!1),Jd(100))),ut()),!1),p=Rt(J(da(J(n,vn(!0)),J(n,vn(!1),Jd(200))),ut()),!1);xe(J(wt(Te(o),Te(f)),ue(([b,C])=>b<=C),ut()),a),xe(J(a,In(50)),u);const y=Yt(J(wt(r,Te(s),Te(t),Te(e),Te(d)),bn((b,[{scrollHeight:C,scrollTop:k},S,T,E,A])=>{const P=k+S-C>-A,$={scrollHeight:C,scrollTop:k,viewportHeight:S};if(P){let V,G;return k>b.state.scrollTop?(V="SCROLLED_DOWN",G=b.state.scrollTop-k):(V="SIZE_DECREASED",G=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:V,scrollTopDelta:G,state:$}}let B;return $.scrollHeight>b.state.scrollHeight?B="SIZE_INCREASED":S<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:$}},tS),ut((b,C)=>b&&b.atBottom===C.atBottom))),g=Rt(J(r,bn((b,{scrollHeight:C,scrollTop:k,viewportHeight:S})=>{if(mf(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:k};{const T=C-(k+S)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:C,scrollTop:k}:{changed:!0,jump:0,scrollHeight:C,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ie(b=>b.changed),ue(b=>b.jump)),0);xe(J(y,ue(b=>b.atBottom)),i),xe(J(i,In(50)),l);const v=re(to);xe(J(r,ue(({scrollTop:b})=>b),ut(),bn((b,C)=>vt(p)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?eo:to,prevScrollTop:C},{direction:to,prevScrollTop:0}),ue(b=>b.direction)),v),xe(J(r,In(50),vn(eS)),v);const x=re(0);return xe(J(h,Ie(b=>!b),vn(0)),x),xe(J(o,In(100),De(h),Ie(([b,C])=>!!C),bn(([b,C],[k])=>[C,k],[0,0]),ue(([b,C])=>C-b)),x),{atBottomState:y,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:v,scrollVelocity:x}},ct(Bt)),Es="top",Is="bottom",gf="none";function xf(e,t,n){return typeof e=="number"?n===eo&&t===Es||n===to&&t===Is?e:0:n===eo?t===Es?e.main:e.reverse:t===Is?e.main:e.reverse}function yf(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Sa=Ye(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ue(),i=re(0),a=re(0),l=re(0),u=Rt(J(wt(Te(r),Te(o),Te(n),Te(s,Xr),Te(l),Te(i),Te(t),Te(e),Te(a)),ue(([d,f,h,[p,y],g,v,x,b,C])=>{const k=d-b,S=v+x,T=Math.max(h-k,0);let E=gf;const A=yf(C,Es),P=yf(C,Is);return p-=b,p+=h+x,y+=h+x,y-=b,p>d+S-A&&(E=eo),y<d-T+f+P&&(E=to),E!==gf?[Math.max(k-h-xf(g,Es,E)-A,0),k-T-x+f+xf(g,Is,E)+P]:null}),Ie(d=>d!=null),ut(Xr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},ct(Bt),{singleton:!0});function rS(e,t,n){if(ks(t)){const r=uf(e,t);return[{index:un(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ca={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ns(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const g=e[e.length-1];d=g.offset+g.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,y=h-d;return{bottom:d,firstItemIndex:s,items:bf(e,o,s),offsetBottom:y,offsetTop:u,top:p,topItems:bf(t,o,s),topListHeight:t.reduce((g,v)=>v.size+g,0),totalCount:n}}function vf(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=wa(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Ns(u,[],a,o,n,r)}function bf(e,t,n){if(e.length===0)return[];if(!ks(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Ss(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const tr=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:y}])=>{const g=re([]),v=re(0),x=Ue();xe(s.topItemsIndexes,g);const b=Rt(J(wt(p,y,Te(l,Xr),Te(o),Te(r),Te(u),d,Te(g),Te(t),Te(n),e),Ie(([T,E,,A,,,,,,,P])=>{const $=P&&P.length!==A;return T&&!E&&!$}),ue(([,,[T,E],A,P,$,B,V,G,O,U])=>{const N=P,{offsetTree:D,sizeTree:M}=N,j=vt(v);if(A===0)return{...Ca,totalCount:A};if(T===0&&E===0)return j===0?{...Ca,totalCount:A}:vf(j,$,P,G,O,U||[]);if(st(M))return j>0?null:Ns(rS(wa($,A),N,U),[],A,O,N,G);const H=[];if(V.length>0){const Q=V[0],oe=V[V.length-1];let Y=0;for(const L of Ss(M,Q,oe)){const q=L.value,z=Math.max(L.start,Q),Z=Math.min(L.end,oe);for(let X=z;X<=Z;X++)H.push({data:U==null?void 0:U[X],index:X,offset:Y,size:q}),Y+=q}}if(!B)return Ns([],H,A,O,N,G);const W=V.length>0?V[V.length-1]+1:0,R=V0(D,T,E,W);if(R.length===0)return null;const K=A-1,ie=ws([],Q=>{for(const oe of R){const Y=oe.value;let L=Y.offset,q=oe.start;const z=Y.size;if(Y.offset<T){q+=Math.floor((T-Y.offset+O)/(z+O));const X=q-oe.start;L+=X*z+X*O}q<W&&(L+=(W-q)*z,q=W);const Z=Math.min(oe.end,K);for(let X=q;X<=Z&&!(L>=E);X++)Q.push({data:U==null?void 0:U[X],index:X,offset:L,size:z}),L+=z+O}});return Ns(ie,H,A,O,N,G)}),Ie(T=>T!==null),ut()),Ca);xe(J(e,Ie(ca),ue(T=>T==null?void 0:T.length)),o),xe(J(b,ue(T=>T.topListHeight)),f),xe(f,a),xe(J(b,ue(T=>[T.top,T.bottom])),i),xe(J(b,ue(T=>T.items)),x);const C=Yt(J(b,Ie(({items:T})=>T.length>0),De(o,e),Ie(([{items:T},E])=>T[T.length-1].originalIndex===E-1),ue(([,T,E])=>[T-1,E]),ut(Xr),ue(([T])=>T))),k=Yt(J(b,In(200),Ie(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),ue(({items:T})=>T[0].index),ut())),S=Yt(J(b,Ie(({items:T})=>T.length>0),ue(({items:T})=>{let E=0,A=T.length-1;for(;T[E].type==="group"&&E<A;)E++;for(;T[A].type==="group"&&A>E;)A--;return{endIndex:T[A].index,startIndex:T[E].index}}),ut(lf)));return{endReached:C,initialItemCount:v,itemsRendered:x,listState:b,rangeChanged:S,startReached:k,topItemsIndexes:g,...h}},ct(wn,hf,Sa,Qr,Zr,no,Dn,xa),{singleton:!0}),wf=Ye(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ue(),i=Rt(J(wt(n,e,r,t,o),ue(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return xe(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Bt,tr),{singleton:!0}),oS=Ye(([{viewportHeight:e},{totalListHeight:t}])=>{const n=re(!1),r=Rt(J(wt(n,e,t),Ie(([o])=>o),ue(([,o,s])=>Math.max(0,o-s)),In(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Bt,wf),{singleton:!0}),Sf=Ye(()=>({context:re(null)})),sS=({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,Cf=Ye(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ue();return xe(J(d,De(t,l,n,s,o,r,a),De(e),ue(([[f,h,p,y,g,v,x,b],C])=>{const{align:k,behavior:S,calculateViewLocation:T=sS,done:E,...A}=f,P=df(f,h,y-1),$=Jr(P,h.offsetTree,C)+g+v,B=$+un(h.sizeTree,P)[1],V=b+v,G=b+p-x,O=T({itemBottom:B,itemTop:$,locationParams:{align:k,behavior:S,...A},viewportBottom:G,viewportTop:V});return O?E&&cn(J(i,Ie(U=>!U),Zn(vt(i)?1:2)),E):E&&E(),O}),Ie(f=>f!==null)),u),{scrollIntoView:d}},ct(wn,Bt,Zr,tr,Pn),{singleton:!0});function Tf(e){return e?e==="smooth"?"smooth":"auto":!1}const iS=(e,t)=>typeof e=="function"?Tf(e(t)):t&&Tf(e),aS=Ye(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const y=re(!1),g=Ue();let v=null;function x(S){Re(i,{align:"end",behavior:S,index:"LAST"})}tt(J(wt(J(Te(t),Zn(1)),l),De(Te(y),s,a,f),ue(([[S,T],E,A,P,$])=>{let B=T&&P,V="auto";return B&&(V=iS(E,A||$),B=B&&!!V),{followOutputBehavior:V,shouldFollow:B,totalCount:S}}),Ie(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:T})=>{v&&(v(),v=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Ht.DEBUG),x(S)}):v=cn(e,()=>{vt(d)("following output to ",{totalCount:T},Ht.DEBUG),x(S),v=null})});function b(S){const T=cn(o,E=>{S&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(vt(d)("scrolling to bottom due to increased size",{},Ht.DEBUG),x("auto"))});setTimeout(T,100)}tt(J(wt(Te(y),t,u),Ie(([S,,T])=>S&&T),bn(({value:S},[,T])=>({refreshed:S===T,value:T}),{refreshed:!1,value:0}),Ie(({refreshed:S})=>S),De(y,t)),([,S])=>{vt(a)&&b(S!==!1)}),tt(g,()=>{b(vt(y)!==!1)}),tt(wt(Te(y),o),([S,T])=>{S&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&x("auto")});const C=re(null),k=Ue();return xe(da(J(Te(r),ue(S=>{var T;return(T=S==null?void 0:S.length)!=null?T:0})),J(Te(t))),k),tt(J(wt(J(k,Zn(1)),l),De(Te(C),a,f,h),ue(([[S,T],E,A,P,$])=>T&&A&&(E==null?void 0:E({context:$,totalCount:S,scrollingInProgress:P}))),Ie(S=>!!S),In(0)),S=>{v&&(v(),v=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Re(p,S)}):v=cn(e,()=>{vt(d)("scrolling into view",{}),Re(p,S),v=null})}),{autoscrollToBottom:g,followOutput:y,scrollIntoViewOnChange:C}},ct(wn,no,Zr,Qr,Dn,Pn,Bt,Sf,Cf)),lS=Ye(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(xe(J(a,De(s),Ie(([,l])=>l!==0),De(o,r,t,n,e),ue(([[,l],u,d,f,h,p=[]])=>vf(l,u,d,f,h,p))),i),{}),ct(wn,Qr,tr,Dn),{singleton:!0}),cS=Ye(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=re(0);return tt(J(e,De(r),Ie(([,o])=>o!==0),ue(([,o])=>({top:o}))),o=>{cn(J(n,Zn(1),Ie(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Re(t,o)})})}),{initialScrollTop:r}},ct(Dn,Bt,tr),{singleton:!0}),kf=Ye(([{scrollVelocity:e}])=>{const t=re(!1),n=Ue(),r=re(!1);return xe(J(e,De(r,t,n),Ie(([o,s])=>!!s),ue(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),ut()),t),tt(J(wt(t,e,n),De(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(no),{singleton:!0}),Ta=Ye(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ue(),r=Ue(),o=Ue(),s=re(!1),i=re(void 0);return xe(J(wt(n,r),ue(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),xe(J(t,De(r),ue(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Bt)),uS=Ye(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ue(),d=re(void 0),f=re(null),h=re(null);return xe(a,f),xe(l,h),tt(J(u,De(t,r,i,f,h,n)),([p,y,g,v,x,b,C])=>{const k=q0(y.sizeTree);v&&x!==null&&b!==null&&(g=x.scrollTop-b.offsetTop),g-=C,p({ranges:k,scrollTop:g})}),xe(J(d,Ie(ca),ue(dS)),o),xe(J(s,De(d),Ie(([,p])=>p!==void 0),ut(),ue(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},ct(wn,Bt,Qr,Dn,Ta));function dS(e){return{align:"start",index:0,offset:e.scrollTop}}const fS=Ye(([{topItemsIndexes:e}])=>{const t=re(0);return xe(J(t,Ie(n=>n>=0),ue(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(tr));function Ef(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const hS=Ef(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),pS=Ye(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:y}])=>{const g=Yt(J(l,De(i),bn(([,x,b,C],[{bottom:k,items:S,offsetBottom:T,totalCount:E},A])=>{const P=k+T;let $=0;return b===E&&x.length>0&&S.length>0&&(S[0].originalIndex===0&&x[0].originalIndex===0||($=P-C,$!==0&&($+=A))),[$,S,E,P]},[0,[],0,0]),Ie(([x])=>x!==0),De(r,a,n,o,p,y),Ie(([,x,b,C,,,k])=>!k&&!C&&x!==0&&b===eo),ue(([[x],,,,,b])=>(b("Upward scrolling compensation",{amount:x},Ht.DEBUG),x))));function v(x){x>0?(Re(t,{behavior:"auto",top:-x}),Re(e,0)):(Re(e,0),Re(t,{behavior:"auto",top:-x}))}return tt(J(g,De(e,s)),([x,b,C])=>{C&&hS()?Re(e,b-x):v(-x)}),tt(J(wt(Rt(s,!1),e,y),Ie(([x,b,C])=>!x&&!C&&b!==0),ue(([x,b])=>b),In(1)),v),xe(J(f,ue(x=>({top:-x}))),t),tt(J(u,De(h,d),ue(([x,{groupIndices:b,lastSize:C,sizeTree:k},S])=>{function T(E){return E*(C+S)}if(b.length===0)return T(x);{let E=0;const A=Yr(k,0);let P=0,$=0;for(;P<x;){P++,E+=A;let B=b.length===$+1?1/0:b[$+1]-b[$]-1;P+B>x&&(E-=A,B=x-P+1),P+=B,E+=T(B),$++}return E}})),x=>{Re(e,x),requestAnimationFrame(()=>{Re(t,{top:x}),requestAnimationFrame(()=>{Re(e,0),Re(y,!1)})})}),{deviation:e}},ct(Bt,no,tr,wn,Pn,xa)),mS=Ye(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),ct(Sa,lS,Dn,kf,wf,cS,oS,Ta,Cf,Pn,Sf)),If=Ye(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:y},g,v,x,{listState:b,topItemsIndexes:C,...k},{scrollToIndex:S},T,{topItemCount:E},{groupCounts:A},P])=>(xe(k.rangeChanged,P.scrollSeekRangeChanged),xe(J(P.windowViewportRect,ue($=>$.visibleHeight)),g.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:y,sizeRanges:a,topItemCount:E,topItemsIndexes:C,totalCount:d,...x,groupIndices:s,itemSize:i,listState:b,scrollToIndex:S,statefulTotalCount:u,trackItemSizes:f,...k,...P,...g,sizes:l,...v}),ct(wn,Qr,Bt,uS,aS,tr,Zr,pS,fS,hf,mS));function gS(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const As=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Nf(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(v,x){v.propsReady&&Re(v.propsReady,!1);for(const b of r){const C=v[t.required[b]];Re(C,x[b])}for(const b of o)if(b in x){const C=v[t.optional[b]];Re(C,x[b])}v.propsReady&&Re(v.propsReady,!0)}function u(v){return s.reduce((x,b)=>(x[b]=C=>{const k=v[t.methods[b]];Re(k,C)},x),{})}function d(v){return i.reduce((x,b)=>(x[b]=M0(v[t.events[b]]),x),{})}const f=w.forwardRef((v,x)=>{const{children:b,...C}=v,[k]=w.useState(()=>ws(P0(e),E=>{l(E,C)})),[S]=w.useState(Xd(d,k));As(()=>{for(const E of i)E in C&&tt(S[E],C[E]);return()=>{Object.values(S).map(ua)}},[C,S,k]),As(()=>{l(k,C)}),w.useImperativeHandle(x,Gd(u(k)));const T=n;return c.jsx(a.Provider,{value:k,children:n?c.jsx(T,{...gS([...r,...o,...i],C),children:b}):b})}),h=v=>{const x=w.useContext(a);return w.useCallback(b=>{Re(x[v],b)},[x,v])},p=v=>{const x=w.useContext(a)[v],b=w.useCallback(C=>tt(x,C),[x]);return w.useSyncExternalStore(b,()=>vt(x),()=>vt(x))},y=v=>{const x=w.useContext(a)[v],[b,C]=w.useState(Xd(vt,x));return As(()=>tt(x,k=>{k!==b&&C(Gd(k))}),[x,b]),b},g=w.version.startsWith("18")?p:y;return{Component:f,useEmitter:(v,x)=>{const b=w.useContext(a)[v];As(()=>tt(b,x),[x,b])},useEmitterValue:g,usePublisher:h}}const Af=w.createContext(void 0),jf=w.createContext(void 0),_f=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ka(e){return"self"in e}function xS(e){return"body"in e}function Mf(e,t,n,r=Tr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),u=w.useCallback(h=>{let p,y,g;const v=h.target;if(xS(v)||ka(v)){const b=ka(v)?v:v.defaultView;g=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,y=s?b.innerWidth:b.innerHeight}else g=s?v.scrollLeft:v.scrollTop,p=s?v.scrollWidth:v.scrollHeight,y=s?v.offsetWidth:v.offsetHeight;const x=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:y})};h.suppressFlushSync?x():si.flushSync(x),a.current!==null&&(g===a.current||g<=0||g===p-y)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const y=h.behavior==="smooth";let g,v,x;ka(p)?(v=Math.max(On(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,x=s?window.scrollX:window.scrollY):(v=p[s?"scrollWidth":"scrollHeight"],g=On(p,s?"width":"height"),x=p[s?"scrollLeft":"scrollTop"]);const b=v-g;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),mf(g,v)||h.top===x){e({scrollHeight:v,scrollTop:x,viewportHeight:g}),y&&t(!0);return}y?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ea="-webkit-sticky",Rf="sticky",Ia=Ef(()=>{if(typeof document>"u")return Rf;const e=document.createElement("div");return e.style.position=Ea,e.style.position===Ea?Ea:Rf});function Na(e){return e}const yS=Ye(()=>{const e=re(a=>`Item ${a}`),t=re(a=>`Group ${a}`),n=re({}),r=re(Na),o=re("div"),s=re(Tr),i=(a,l=null)=>Rt(J(n,ue(u=>u[a]),ut()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),vS=Ye(([e,t])=>({...e,...t}),ct(If,yS)),bS=({height:e})=>c.jsx("div",{style:{height:e}}),wS={overflowAnchor:"none",position:Ia(),zIndex:1},Pf={overflowAnchor:"none"},SS={...Pf,display:"inline-block",height:"100%"},Of=w.memo(function({showTopList:e=!1}){const t=je("listState"),n=en("sizeRanges"),r=je("useWindowScroll"),o=je("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=je("itemContent"),u=je("context"),d=je("groupContent"),f=je("trackItemSizes"),h=je("itemSize"),p=je("log"),y=en("gap"),g=je("horizontalDirection"),{callbackRef:v}=L0(n,h,f,e?Tr:a,p,y,o,g,je("skipAnimationFrameInResizeObserver")),[x,b]=w.useState(0);Aa("deviation",O=>{x!==O&&b(O)});const C=je("EmptyPlaceholder"),k=je("ScrollSeekPlaceholder")||bS,S=je("ListComponent"),T=je("ItemComponent"),E=je("GroupComponent"),A=je("computeItemKey"),P=je("isSeeking"),$=je("groupIndices").length>0,B=je("alignToBottom"),V=je("initialItemFinalLocationReached"),G=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},...V?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?c.jsx(C,{...Pt(C,u)}):c.jsx(S,{...Pt(S,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:G,children:(e?t.topItems:t.items).map(O=>{const U=O.originalIndex,N=A(U+t.firstItemIndex,O.data,u);return P?w.createElement(k,{...Pt(k,u),height:O.size,index:O.index,key:N,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?w.createElement(E,{...Pt(E,u),"data-index":U,"data-item-index":O.index,"data-known-size":O.size,key:N,style:wS},d(O.index,u)):w.createElement(T,{...Pt(T,u),...ES(T,O.data),"data-index":U,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:N,style:g?SS:Pf},$?l(O.index,O.groupIndex,O.data,u):l(O.index,O.data,u))})})}),CS={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},TS={outline:"none",overflowX:"auto",position:"relative"},js=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),kS={position:Ia(),top:0,width:"100%",zIndex:1};function Pt(e,t){if(typeof e!="string")return{context:t}}function ES(e,t){return{item:typeof e=="string"?void 0:t}}const IS=w.memo(function(){const e=je("HeaderComponent"),t=en("headerHeight"),n=je("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Pt(e,o)})}):null}),NS=w.memo(function(){const e=je("FooterComponent"),t=en("footerHeight"),n=je("HeaderFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,je("skipAnimationFrameInResizeObserver")),o=je("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Pt(e,o)})}):null});function Df({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:y}=Mf(a,u,l,d,void 0,f);return e("scrollTo",y),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?TS:CS,...o},tabIndex:0,...i,...Pt(l,s),children:r})})}function Lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),y=t("scrollerRef"),{scrollByCallback:g,scrollerRef:v,scrollToCallback:x}=Mf(a,u,l,y,h);return _f(()=>{var b;return v.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",x),e("scrollBy",g),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Pt(l,s),children:r})})}const AS=({children:e})=>{const t=w.useContext(Af),n=en("viewportHeight"),r=en("fixedItemHeight"),o=je("alignToBottom"),s=je("horizontalDirection"),i=w.useMemo(()=>Yd(n,l=>On(l,s?"width":"height")),[n,s]),a=Qn(i,!0,je("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:js(o),children:e})},jS=({children:e})=>{const t=w.useContext(Af),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=je("customScrollParent"),s=ef(n,o,je("skipAnimationFrameInResizeObserver")),i=je("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:js(i),children:e})},_S=({children:e})=>{const t=je("TopItemListComponent")||"div",n=je("headerHeight"),r={...kS,marginTop:`${n}px`},o=je("context");return c.jsx(t,{style:r,...Pt(t,o),children:e})},MS=w.memo(function(e){const t=je("useWindowScroll"),n=je("topItemsIndexes").length>0,r=je("customScrollParent"),o=je("context");return c.jsxs(r||t?OS:PS,{...e,context:o,children:[n&&c.jsx(_S,{children:c.jsx(Of,{showTopList:!0})}),c.jsxs(r||t?jS:AS,{children:[c.jsx(IS,{}),c.jsx(Of,{}),c.jsx(NS,{})]})]})}),{Component:RS,useEmitter:Aa,useEmitterValue:je,usePublisher:en}=Nf(vS,{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"}},MS),PS=Df({useEmitter:Aa,useEmitterValue:je,usePublisher:en}),OS=Lf({useEmitter:Aa,useEmitterValue:je,usePublisher:en}),DS=RS;ct(If,Ye(()=>{const e=re(u=>c.jsxs("td",{children:["Item $",u]})),t=re(null),n=re(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=re(null),o=re(null),s=re({}),i=re(Na),a=re(Tr),l=(u,d=null)=>Rt(J(s,ue(f=>f[u]),ut()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Ia();const $f={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},LS={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ff,floor:_s,max:ro,min:ja,round:Bf}=Math;function zf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function $S(e){return{...LS,items:e}}function Ms(e,t){return e&&e.width===t.width&&e.height===t.height}function FS(e,t){return e&&e.column===t.column&&e.row===t.row}const BS=Ye(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:y,propsReady:g},{customScrollParent:v,useWindowScroll:x,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k},S])=>{const T=re(0),E=re(0),A=re($f),P=re({height:0,width:0}),$=re({height:0,width:0}),B=Ue(),V=Ue(),G=re(0),O=re(null),U=re({column:0,row:0}),N=Ue(),D=Ue(),M=re(!1),j=re(0),H=re(!0),W=re(!1),R=re(!1);tt(J(y,De(j),Ie(([L,q])=>!!q)),()=>{Re(H,!1)}),tt(J(wt(y,H,$,P,j,W),Ie(([L,q,z,Z,,X])=>L&&!q&&z.height!==0&&Z.height!==0&&!X)),([,,,,L])=>{Re(W,!0),ba(1,()=>{Re(B,L)}),cn(J(u),()=>{Re(t,[0,0]),Re(H,!0)})}),xe(J(D,Ie(L=>L!=null&&L.scrollTop>0),vn(0)),E),tt(J(y,De(D),Ie(([,L])=>L!=null)),([,L])=>{L&&(Re(P,L.viewport),Re($,L.item),Re(U,L.gap),L.scrollTop>0&&(Re(M,!0),cn(J(u,Zn(1)),q=>{Re(M,!1)}),Re(l,{top:L.scrollTop})))}),xe(J(P,ue(({height:L})=>L)),f),xe(J(wt(Te(P,Ms),Te($,Ms),Te(U,(L,q)=>L&&L.column===q.column&&L.row===q.row),Te(u)),ue(([L,q,z,Z])=>({gap:z,item:q,scrollTop:Z,viewport:L}))),N),xe(J(wt(Te(T),r,Te(U,FS),Te($,Ms),Te(P,Ms),Te(O),Te(E),Te(M),Te(H),Te(j)),Ie(([,,,,,,,L])=>!L),ue(([L,[q,z],Z,X,ge,le,te,,fe,ye])=>{const{column:Me,row:Ne}=Z,{height:$e,width:Xe}=X,{width:nt}=ge;if(te===0&&(L===0||nt===0))return $f;if(Xe===0){const pt=wa(ye,L),Et=pt+Math.max(te-1,0);return $S(zf(pt,Et,le))}const Ve=Uf(nt,Xe,Me);let qe,ot;fe?q===0&&z===0&&te>0?(qe=0,ot=te-1):(qe=Ve*_s((q+Ne)/($e+Ne)),ot=Ve*Ff((z+Ne)/($e+Ne))-1,ot=ja(L-1,ro(ot,Ve-1)),qe=ja(ot,ro(0,qe))):(qe=0,ot=-1);const kt=zf(qe,ot,le),{bottom:lt,top:ke}=Hf(ge,Z,X,kt),Oe=Ff(L/Ve),at=Oe*$e+(Oe-1)*Ne-lt;return{bottom:lt,itemHeight:$e,items:kt,itemWidth:Xe,offsetBottom:at,offsetTop:ke,top:ke}})),A),xe(J(O,Ie(L=>L!==null),ue(L=>L.length)),T),xe(J(wt(P,$,A,U),Ie(([L,q,{items:z}])=>z.length>0&&q.height!==0&&L.height!==0),ue(([L,q,{items:z},Z])=>{const{bottom:X,top:ge}=Hf(L,Z,q,z);return[ge,X]}),ut(Xr)),t);const K=re(!1);xe(J(u,De(K),ue(([L,q])=>q||L!==0)),K);const ie=Yt(J(wt(A,T),Ie(([{items:L}])=>L.length>0),De(K),Ie(([[L,q],z])=>{const Z=L.items[L.items.length-1].index===q-1;return(z||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===q)&&Z}),ue(([[,L]])=>L-1),ut())),Q=Yt(J(Te(A),Ie(({items:L})=>L.length>0&&L[0].index===0),vn(0),ut())),oe=Yt(J(Te(A),De(M),Ie(([{items:L},q])=>L.length>0&&!q),ue(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),ut(lf),In(0)));xe(oe,p.scrollSeekRangeChanged),xe(J(B,De(P,$,T,U),ue(([L,q,z,Z,X])=>{const ge=pf(L),{align:le,behavior:te,offset:fe}=ge;let ye=ge.index;ye==="LAST"&&(ye=Z-1),ye=ro(0,ye,ja(Z-1,ye));let Me=_a(q,X,z,ye);return le==="end"?Me=Bf(Me-q.height+z.height):le==="center"&&(Me=Bf(Me-q.height/2+z.height/2)),fe&&(Me+=fe),{behavior:te,top:Me}})),l);const Y=Rt(J(A,ue(L=>L.offsetBottom+L.bottom)),0);return xe(J(k,ue(L=>({height:L.visibleHeight,width:L.visibleWidth}))),P),{customScrollParent:v,data:O,deviation:G,footerHeight:o,gap:U,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:$,overscan:n,restoreStateFrom:D,scrollBy:i,scrollContainerState:a,scrollHeight:V,scrollTo:l,scrollToIndex:B,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:x,viewportDimensions:P,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:k,...p,gridState:A,horizontalDirection:R,initialTopMostItemIndex:j,totalListHeight:Y,...h,endReached:ie,propsReady:g,rangeChanged:oe,startReached:Q,stateChanged:N,stateRestoreInProgress:M,...S}},ct(Sa,Bt,no,kf,Dn,Ta,Pn));function Uf(e,t,n){return ro(1,_s((e+n)/(_s(t)+n)))}function Hf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=_a(e,t,n,r[0].index);return{bottom:_a(e,t,n,r[r.length-1].index)+o,top:s}}function _a(e,t,n,r){const o=Uf(e.width,n.width,t.column),s=_s(r/o),i=s*n.height+ro(0,s-1)*t.row;return i>0?i+t.row:i}const zS=Ye(()=>{const e=re(f=>`Item ${f}`),t=re({}),n=re(null),r=re("virtuoso-grid-item"),o=re("virtuoso-grid-list"),s=re(Na),i=re("div"),a=re(Tr),l=(f,h=null)=>Rt(J(t,ue(p=>p[f]),ut()),h),u=re(!1),d=re(!1);return xe(Te(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),US=Ye(([e,t])=>({...e,...t}),ct(BS,zS)),HS=w.memo(function(){const e=ht("gridState"),t=ht("listClassName"),n=ht("itemClassName"),r=ht("itemContent"),o=ht("computeItemKey"),s=ht("isSeeking"),i=tn("scrollHeight"),a=ht("ItemComponent"),l=ht("ListComponent"),u=ht("ScrollSeekPlaceholder"),d=ht("context"),f=tn("itemDimensions"),h=tn("gap"),p=ht("log"),y=ht("stateRestoreInProgress"),g=tn("reportReadyState"),v=Qn(w.useMemo(()=>x=>{const b=x.parentElement.parentElement.scrollHeight;i(b);const C=x.firstChild;if(C){const{height:k,width:S}=C.getBoundingClientRect();f({height:k,width:S})}h({column:Vf("column-gap",getComputedStyle(x).columnGap,p),row:Vf("row-gap",getComputedStyle(x).rowGap,p)})},[i,f,h,p]),!0,!1);return _f(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),y?null:c.jsx(l,{className:t,ref:v,...Pt(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?c.jsx(u,{...Pt(u,d),height:e.itemHeight,index:x.index,width:e.itemWidth},b):w.createElement(a,{...Pt(a,d),className:n,"data-index":x.index,key:b},r(x.index,x.data,d))})})}),WS=w.memo(function(){const e=ht("HeaderComponent"),t=tn("headerHeight"),n=ht("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ht("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Pt(e,o)})}):null}),VS=w.memo(function(){const e=ht("FooterComponent"),t=tn("footerHeight"),n=ht("headerFooterTag"),r=Qn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ht("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Pt(e,o)})}):null}),KS=({children:e})=>{const t=w.useContext(jf),n=tn("itemDimensions"),r=tn("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]),c.jsx("div",{ref:o,style:js(!1),children:e})},qS=({children:e})=>{const t=w.useContext(jf),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=ht("customScrollParent"),s=ef(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]),c.jsx("div",{ref:s,style:js(!1),children:e})},GS=w.memo(function({...e}){const t=ht("useWindowScroll"),n=ht("customScrollParent"),r=n||t?XS:YS,o=n||t?qS:KS,s=ht("context");return c.jsx(r,{...e,...Pt(r,s),children:c.jsxs(o,{children:[c.jsx(WS,{}),c.jsx(HS,{}),c.jsx(VS,{})]})})}),{useEmitter:Wf,useEmitterValue:ht,usePublisher:tn}=Nf(US,{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"}},GS),YS=Df({useEmitter:Wf,useEmitterValue:ht,usePublisher:tn}),XS=Lf({useEmitter:Wf,useEmitterValue:ht,usePublisher:tn});function Vf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ht.WARN),t==="normal"?0:parseInt(t??"0",10)}const JS=bo.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 Kf({className:e,variant:t,...n}){return c.jsx("div",{className:ne(JS({variant:t}),e),...n})}function Ma(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 qf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function oo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(oo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(qf(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=oo(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 so(e){if(typeof e=="string")return e;if(qf(e))return"";try{const t=oo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function ZS(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function QS(e){const t=so(e);return typeof e=="string"&&ZS(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Rs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ma(t);if(n!==null)return Rs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Rs(e.content):e}function eC(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Gf(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 Ps(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function tC(e){const t=r=>{try{const o=oo(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 nC(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Yf(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 rC(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function oC(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function sC({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=rC(n),i=o?`data:${s};base64,${e}`:t,a=oC(r),l=a.length?a.join(" / "):void 0,u=l?`${l} artifact`:"artifact image";return{src:i,alt:u,label:l}}function iC(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 sC({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Xf(e,t){return await Kt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Jf(e,t){return await(await Xf(`/files/${e}/view`,t)).text()}async function aC(e,t){const n=await Xf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Kt(`/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 lC(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Kt("/files",{params:r})}var Os="Dialog",[Zf,NE]=Tn(Os),[cC,dn]=Zf(Os),Qf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[u,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:Os});return c.jsx(cC,{scope:t,triggerRef:a,contentRef:l,contentId:$t(),titleId:$t(),descriptionId:$t(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Qf.displayName=Os;var eh="DialogTrigger",th=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(eh,n),s=ze(t,o.triggerRef);return c.jsx(we.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Oa(o.open),...r,ref:s,onClick:he(e.onClick,o.onOpenToggle)})});th.displayName=eh;var Ra="DialogPortal",[uC,nh]=Zf(Ra,{forceMount:void 0}),rh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=dn(Ra,t);return c.jsx(uC,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Zt,{present:n||s.open,children:c.jsx(ns,{asChild:!0,container:o,children:i})}))})};rh.displayName=Ra;var Ds="DialogOverlay",oh=m.forwardRef((e,t)=>{const n=nh(Ds,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=dn(Ds,e.__scopeDialog);return s.modal?c.jsx(Zt,{present:r||s.open,children:c.jsx(fC,{...o,ref:t})}):null});oh.displayName=Ds;var dC=Wn.createSlot("DialogOverlay.RemoveScroll"),fC=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(Ds,n);return c.jsx(ds,{as:dC,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(we.div,{"data-state":Oa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",sh=m.forwardRef((e,t)=>{const n=nh(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=dn(nr,e.__scopeDialog);return c.jsx(Zt,{present:r||s.open,children:s.modal?c.jsx(hC,{...o,ref:t}):c.jsx(pC,{...o,ref:t})})});sh.displayName=nr;var hC=m.forwardRef((e,t)=>{const n=dn(nr,e.__scopeDialog),r=m.useRef(null),o=ze(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Gi(s)},[]),c.jsx(ih,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:he(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:he(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:he(e.onFocusOutside,s=>s.preventDefault())})}),pC=m.forwardRef((e,t)=>{const n=dn(nr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(ih,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,u;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),ih=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=dn(nr,n),l=m.useRef(null),u=ze(t,l);return Ai(),c.jsxs(c.Fragment,{children:[c.jsx(Wo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(Ho,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Oa(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(mC,{titleId:a.titleId}),c.jsx(xC,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Pa="DialogTitle",ah=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(Pa,n);return c.jsx(we.h2,{id:o.titleId,...r,ref:t})});ah.displayName=Pa;var lh="DialogDescription",ch=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(lh,n);return c.jsx(we.p,{id:o.descriptionId,...r,ref:t})});ch.displayName=lh;var uh="DialogClose",dh=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=dn(uh,n);return c.jsx(we.button,{type:"button",...r,ref:t,onClick:he(e.onClick,()=>o.onOpenChange(!1))})});dh.displayName=uh;function Oa(e){return e?"open":"closed"}var fh="DialogTitleWarning",[AE,hh]=hy(fh,{contentName:nr,titleName:Pa,docsSlug:"dialog"}),mC=({titleId:e})=>{const t=hh(fh),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 m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},xC="DialogDescriptionWarning",yC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hh(xC).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Da=Qf,vC=th,La=rh,ao=oh,lo=sh,rr=ah,Ls=ch,ph=dh;const mh=Da,bC=La,gh=m.forwardRef(({className:e,...t},n)=>c.jsx(ao,{ref:n,className:se("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}));gh.displayName=ao.displayName;const $a=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const u=l.type;if(u===rr||(u==null?void 0:u.displayName)===rr.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return c.jsxs(bC,{children:[c.jsx(gh,{}),c.jsxs(lo,{ref:r,className:se("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&c.jsx(rr,{className:"sr-only",children:"Dialog"}),t,c.jsxs(ph,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[c.jsx(ae.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});$a.displayName=lo.displayName;const Fa=({className:e,...t})=>c.jsx("div",{className:se("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Fa.displayName="DialogHeader";const Ba=m.forwardRef(({className:e,...t},n)=>c.jsx(rr,{ref:n,className:se("text-lg font-semibold leading-none tracking-tight",e),...t}));Ba.displayName=rr.displayName;const wC=m.forwardRef(({className:e,...t},n)=>c.jsx(Ls,{ref:n,className:se("text-sm text-muted-foreground",e),...t}));wC.displayName=Ls.displayName;const SC=1,CC=1e6;let za=0;function kC(){return za=(za+1)%Number.MAX_SAFE_INTEGER,za.toString()}const Ua=new Map,xh=e=>{if(Ua.has(e))return;const t=setTimeout(()=>{Ua.delete(e),co({type:"REMOVE_TOAST",toastId:e})},CC);Ua.set(e,t)},TC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,SC)};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?xh(n):e.toasts.forEach(r=>{xh(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 Fs={toasts:[]};function co(e){Fs=TC(Fs,e),$s.forEach(t=>{t(Fs)})}function IC({...e}){const t=kC(),n=o=>co({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>co({type:"DISMISS_TOAST",toastId:t});return co({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ha(){const[e,t]=m.useState(Fs);return m.useEffect(()=>($s.push(t),()=>{const n=$s.indexOf(t);n>-1&&$s.splice(n,1)}),[e]),{...e,toast:IC,dismiss:n=>co({type:"DISMISS_TOAST",toastId:n})}}function EC({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[u,d]=w.useState(null),{toast:f}=Ha(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Jf(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&&h()},[e,n,h]);const p=async()=>{if(n)try{await lC(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"})}},y=async()=>{if(n)try{const x=await Jf(n),b=new Blob([x],{type:o}),k=URL.createObjectURL(b);window.open(k,"_blank"),URL.revokeObjectURL(k)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?c.jsxs("div",{className:"flex items-center justify-center py-12",children:[c.jsx(ae.Loader,{className:"h-8 w-8 animate-spin mr-3"}),c.jsx("span",{children:"Loading file..."})]}):u?c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),c.jsx("p",{className:"text-red-600 mb-4",children:u}),c.jsx(tt,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?c.jsx("div",{className:"flex justify-center",children:c.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?c.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:c.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?c.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(ae.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),c.jsx("p",{className:"text-lg font-medium mb-2",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),v=()=>o.startsWith("image/")?c.jsx(ae.Image,{className:"h-5 w-5"}):c.jsx(ae.FileText,{className:"h-5 w-5"});return c.jsx(mh,{open:e,onOpenChange:t,children:c.jsxs($a,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(Fa,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[v(),c.jsxs("div",{children:[c.jsx(Ba,{className:"text-left",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(tt,{variant:"outline",size:"sm",onClick:y,className:"flex items-center gap-2",children:[c.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(tt,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function yh(){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=yh();function NC(e){or=e}const vh=/[&<>"']/,AC=new RegExp(vh.source,"g"),bh=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,jC=new RegExp(bh.source,"g"),_C={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},wh=e=>_C[e];function Lt(e,t){if(t){if(vh.test(e))return e.replace(AC,wh)}else if(bh.test(e))return e.replace(jC,wh);return e}const MC=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Sh(e){return e.replace(MC,(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 RC=/(^|[^\[])\^/g;function at(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(RC,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const PC=/[^\w:]/g,OC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Ch(e,t,n){if(e){let r;try{r=decodeURIComponent(Sh(n)).replace(PC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!OC.test(n)&&(n=FC(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Bs={},DC=/^[^:]+:\/*[^/]*$/,LC=/^([^:]+:)[\s\S]*$/,$C=/^([^:]+:\/*[^/]*)[\s\S]*$/;function FC(e,t){Bs[" "+e]||(DC.test(e)?Bs[" "+e]=e+"/":Bs[" "+e]=Us(e,"/",!0)),e=Bs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(LC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace($C,"$1")+t:e+t}const zs={exec:function(){}};function kh(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Us(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 BC(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 zC(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 Th(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Ih(e,t,n,r){const o=t.href,s=t.title?Lt(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:Lt(i)}}function UC(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 m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},gC="DialogDescriptionWarning",xC=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hh(gC).contentName}}.`;return m.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Da=Qf,yC=th,La=rh,io=oh,ao=sh,rr=ah,Ls=ch,ph=dh;const mh=Da,vC=La,gh=m.forwardRef(({className:e,...t},n)=>c.jsx(io,{ref:n,className:ne("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}));gh.displayName=io.displayName;const $a=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const u=l.type;if(u===rr||(u==null?void 0:u.displayName)===rr.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return c.jsxs(vC,{children:[c.jsx(gh,{}),c.jsxs(ao,{ref:r,className:ne("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&c.jsx(rr,{className:"sr-only",children:"Dialog"}),t,c.jsxs(ph,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[c.jsx(ae.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});$a.displayName=ao.displayName;const Fa=({className:e,...t})=>c.jsx("div",{className:ne("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Fa.displayName="DialogHeader";const Ba=m.forwardRef(({className:e,...t},n)=>c.jsx(rr,{ref:n,className:ne("text-lg font-semibold leading-none tracking-tight",e),...t}));Ba.displayName=rr.displayName;const bC=m.forwardRef(({className:e,...t},n)=>c.jsx(Ls,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));bC.displayName=Ls.displayName;const wC=1,SC=1e6;let za=0;function CC(){return za=(za+1)%Number.MAX_SAFE_INTEGER,za.toString()}const Ua=new Map,xh=e=>{if(Ua.has(e))return;const t=setTimeout(()=>{Ua.delete(e),lo({type:"REMOVE_TOAST",toastId:e})},SC);Ua.set(e,t)},TC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,wC)};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?xh(n):e.toasts.forEach(r=>{xh(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 Fs={toasts:[]};function lo(e){Fs=TC(Fs,e),$s.forEach(t=>{t(Fs)})}function kC({...e}){const t=CC(),n=o=>lo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>lo({type:"DISMISS_TOAST",toastId:t});return lo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ha(){const[e,t]=m.useState(Fs);return m.useEffect(()=>($s.push(t),()=>{const n=$s.indexOf(t);n>-1&&$s.splice(n,1)}),[e]),{...e,toast:kC,dismiss:n=>lo({type:"DISMISS_TOAST",toastId:n})}}function EC({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[u,d]=w.useState(null),{toast:f}=Ha(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const x=await Jf(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&&h()},[e,n,h]);const p=async()=>{if(n)try{await aC(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"})}},y=async()=>{if(n)try{const x=await Jf(n),b=new Blob([x],{type:o}),C=URL.createObjectURL(b);window.open(C,"_blank"),URL.revokeObjectURL(C)}catch(x){console.error("Failed to open file externally:",x),f({title:"Failed to open file",description:String(x),variant:"destructive"})}},g=()=>s?c.jsxs("div",{className:"flex items-center justify-center py-12",children:[c.jsx(ae.Loader,{className:"h-8 w-8 animate-spin mr-3"}),c.jsx("span",{children:"Loading file..."})]}):u?c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),c.jsx("p",{className:"text-red-600 mb-4",children:u}),c.jsx(et,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?c.jsx("div",{className:"flex justify-center",children:c.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?c.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:c.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?c.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(ae.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),c.jsx("p",{className:"text-lg font-medium mb-2",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),v=()=>o.startsWith("image/")?c.jsx(ae.Image,{className:"h-5 w-5"}):c.jsx(ae.FileText,{className:"h-5 w-5"});return c.jsx(mh,{open:e,onOpenChange:t,children:c.jsxs($a,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(Fa,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[v(),c.jsxs("div",{children:[c.jsx(Ba,{className:"text-left",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(et,{variant:"outline",size:"sm",onClick:y,className:"flex items-center gap-2",children:[c.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(et,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:g()})]})})}function yh(){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=yh();function IC(e){or=e}const vh=/[&<>"']/,NC=new RegExp(vh.source,"g"),bh=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,AC=new RegExp(bh.source,"g"),jC={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},wh=e=>jC[e];function Ot(e,t){if(t){if(vh.test(e))return e.replace(NC,wh)}else if(bh.test(e))return e.replace(AC,wh);return e}const _C=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Sh(e){return e.replace(_C,(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 MC=/(^|[^\[])\^/g;function it(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(MC,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const RC=/[^\w:]/g,PC=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Ch(e,t,n){if(e){let r;try{r=decodeURIComponent(Sh(n)).replace(RC,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!PC.test(n)&&(n=$C(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Bs={},OC=/^[^:]+:\/*[^/]*$/,DC=/^([^:]+:)[\s\S]*$/,LC=/^([^:]+:\/*[^/]*)[\s\S]*$/;function $C(e,t){Bs[" "+e]||(OC.test(e)?Bs[" "+e]=e+"/":Bs[" "+e]=Us(e,"/",!0)),e=Bs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(DC,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(LC,"$1")+t:e+t}const zs={exec:function(){}};function Th(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Us(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 FC(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 BC(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 kh(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function Eh(e,t,n,r){const o=t.href,s=t.title?Ot(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:Ot(i)}}function zC(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
93
  `)}class Wa{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:Us(r,`
94
- `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=UC(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=Us(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,y,g=n[1].trim();const v=g.length>1,x={type:"list",raw:"",ordered:v,start:v?+g.slice(0,-1):"",loose:!1,items:[]};g=v?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=v?g:"[*+-]");const b=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(y=!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
- `,1)[0].replace(/^\t+/,T=>" ".repeat(3*T.length)),f=t.split(`
94
+ `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=zC(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=Us(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,y,g=n[1].trim();const v=g.length>1,x={type:"list",raw:"",ordered:v,start:v?+g.slice(0,-1):"",loose:!1,items:[]};g=v?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=v?g:"[*+-]");const b=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(y=!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
+ `,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
96
96
  `,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
97
- `,t=t.substring(f.length+1),y=!0),!y){const T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),S=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
98
- `,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(C.test(f)||I.test(f)||T.test(f)||S.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
99
- `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||C.test(d)||I.test(d)||S.test(d))break;p+=`
97
+ `,t=t.substring(f.length+1),y=!0),!y){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),S=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
98
+ `,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||E.test(f)||k.test(f)||S.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
99
+ `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||E.test(d)||S.test(d))break;p+=`
100
100
  `+f}!l&&!f.trim()&&(l=!0),r+=h+`
101
- `,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(u?x.loose=!0:/\n *\n *$/.test(r)&&(u=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const k=x.items.length;for(a=0;a<k;a++)if(this.lexer.state.top=!1,x.items[a].tokens=this.lexer.blockTokens(x.items[a].text,[]),!x.loose){const T=x.items[a].tokens.filter(C=>C.type==="space"),S=T.length>0&&T.some(C=>/\n.*\n/.test(C.raw));x.loose=S}if(x.loose)for(a=0;a<k;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]):Lt(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:kh(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
- `):[]};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]=kh(r.rows[s],r.header.length).map(u=>({text:u}));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:Lt(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]):Lt(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=Us(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=BC(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)),Ih(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 Ih(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,u=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]){u+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(u-=l,u>0)continue;l=Math.min(l,l+u+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const y=h.slice(1,-1);return{type:"em",raw:h,text:y,tokens:this.lexer.inlineTokens(y)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Lt(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=Lt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Lt(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=Lt(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=Lt(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]):Lt(r[0]):r[0]:o=Lt(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:zs,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=at(ve.def).replace("label",ve._label).replace("title",ve._title).getRegex(),ve.bullet=/(?:[*+-]|\d{1,9}[.)])/,ve.listItemStart=at(/^( *)(bull) */).replace("bull",ve.bullet).getRegex(),ve.list=at(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=at(ve.html,"i").replace("comment",ve._comment).replace("tag",ve._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ve.paragraph=at(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=at(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=at(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=at(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:at(`^ *(?: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:zs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:at(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 de={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:zs,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:zs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};de._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",de.punctuation=at(de.punctuation).replace(/punctuation/g,de._punctuation).getRegex(),de.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,de.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,de._comment=at(ve._comment).replace("(?:-->|$)","-->").getRegex(),de.emStrong.lDelim=at(de.emStrong.lDelim).replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimAst=at(de.emStrong.rDelimAst,"g").replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimUnd=at(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=at(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=at(de.tag).replace("comment",de._comment).replace("attribute",de._attribute).getRegex(),de._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,de._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,de._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,de.link=at(de.link).replace("label",de._label).replace("href",de._href).replace("title",de._title).getRegex(),de.reflink=at(de.reflink).replace("label",de._label).replace("ref",ve._label).getRegex(),de.nolink=at(de.nolink).replace("ref",ve._label).getRegex(),de.reflinkSearch=at(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:at(/^!?\[(label)\]\((.*?)\)/).replace("label",de._label).getRegex(),reflink:at(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",de._label).getRegex()},de.gfm={...de.normal,escape:at(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=at(de.gfm.url,"i").replace("email",de.gfm._extended_email).getRegex(),de.breaks={...de.gfm,br:at(de.br).replace("{2,}","*").getRegex(),text:at(de.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function HC(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 Eh(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||or,this.options.tokenizer=this.options.tokenizer||new Wa,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:de.normal};this.options.pedantic?(n.block=ve.pedantic,n.inline=de.pedantic):this.options.gfm&&(n.block=ve.gfm,this.options.breaks?n.inline=de.breaks:n.inline=de.gfm),this.tokenizer.rules=n}static get rules(){return{block:ve,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,`
101
+ `,t=t.substring(h.length+1),d=f.slice(i)}}x.loose||(u?x.loose=!0:/\n *\n *$/.test(r)&&(u=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),x.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),x.raw+=r}x.items[x.items.length-1].raw=r.trimRight(),x.items[x.items.length-1].text=p.trimRight(),x.raw=x.raw.trimRight();const C=x.items.length;for(a=0;a<C;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"),S=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));x.loose=S}if(x.loose)for(a=0;a<C;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]):Ot(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:Th(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
+ `):[]};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]=Th(r.rows[s],r.header.length).map(u=>({text:u}));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:Ot(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]):Ot(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=Us(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=FC(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)),Eh(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 Eh(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,u=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]){u+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(u-=l,u>0)continue;l=Math.min(l,l+u+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const y=h.slice(1,-1);return{type:"em",raw:h,text:y,tokens:this.lexer.inlineTokens(y)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Ot(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=Ot(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Ot(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=Ot(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=Ot(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]):Ot(r[0]):r[0]:o=Ot(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const be={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:zs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};be._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,be._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,be.def=it(be.def).replace("label",be._label).replace("title",be._title).getRegex(),be.bullet=/(?:[*+-]|\d{1,9}[.)])/,be.listItemStart=it(/^( *)(bull) */).replace("bull",be.bullet).getRegex(),be.list=it(be.list).replace(/bull/g,be.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+be.def.source+")").getRegex(),be._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",be._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,be.html=it(be.html,"i").replace("comment",be._comment).replace("tag",be._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),be.paragraph=it(be._paragraph).replace("hr",be.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",be._tag).getRegex(),be.blockquote=it(be.blockquote).replace("paragraph",be.paragraph).getRegex(),be.normal={...be},be.gfm={...be.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},be.gfm.table=it(be.gfm.table).replace("hr",be.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",be._tag).getRegex(),be.gfm.paragraph=it(be._paragraph).replace("hr",be.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",be.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",be._tag).getRegex(),be.pedantic={...be.normal,html:it(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",be._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:zs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:it(be.normal._paragraph).replace("hr",be.hr).replace("heading",` *#{1,6} *[^
104
+ ]`).replace("lheading",be.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const de={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:zs,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:zs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};de._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",de.punctuation=it(de.punctuation).replace(/punctuation/g,de._punctuation).getRegex(),de.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,de.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,de._comment=it(be._comment).replace("(?:-->|$)","-->").getRegex(),de.emStrong.lDelim=it(de.emStrong.lDelim).replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimAst=it(de.emStrong.rDelimAst,"g").replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimUnd=it(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=it(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=it(de.tag).replace("comment",de._comment).replace("attribute",de._attribute).getRegex(),de._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,de._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,de._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,de.link=it(de.link).replace("label",de._label).replace("href",de._href).replace("title",de._title).getRegex(),de.reflink=it(de.reflink).replace("label",de._label).replace("ref",be._label).getRegex(),de.nolink=it(de.nolink).replace("ref",be._label).getRegex(),de.reflinkSearch=it(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:it(/^!?\[(label)\]\((.*?)\)/).replace("label",de._label).getRegex(),reflink:it(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",de._label).getRegex()},de.gfm={...de.normal,escape:it(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=it(de.gfm.url,"i").replace("email",de.gfm._extended_email).getRegex(),de.breaks={...de.gfm,br:it(de.br).replace("{2,}","*").getRegex(),text:it(de.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function UC(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 Ih(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||or,this.options.tokenizer=this.options.tokenizer||new Wa,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:be.normal,inline:de.normal};this.options.pedantic?(n.block=be.pedantic,n.inline=de.pedantic):this.options.gfm&&(n.block=be.gfm,this.options.breaks?n.inline=de.breaks:n.inline=de.gfm),this.tokenizer.rules=n}static get rules(){return{block:be,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,`
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,u)=>l+" ".repeat(u.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,u;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)+"["+Th("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)+"["+Th("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||(u=""),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,u)){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,Eh)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,Eh))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,HC)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(u=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 Va{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+Lt(o)+'">'+(r?t:Lt(t,!0))+`</code></pre>
116
- `:"<pre><code>"+(r?t:Lt(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,u;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)+"["+kh("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)+"["+kh("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||(u=""),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,u)){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,Ih)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,Ih))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,UC)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(u=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 Va{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+Ot(o)+'">'+(r?t:Ot(t,!0))+`</code></pre>
116
+ `:"<pre><code>"+(r?t:Ot(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=Ch(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=Ch(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 Nh{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 Ah{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||or,this.options.renderer=this.options.renderer||new Va,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Nh,this.slugger=new Ah}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,u,d,f,h,p,y,g,v,x,b,k,T,S,C;const I=t.length;for(o=0;o<I;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Sh(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(u=p.rows[s],d="",l=u.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(y=p.ordered,g=p.start,v=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],k=b.checked,T=b.task,x="",b.task&&(S=this.renderer.checkbox(k),v?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=S+" "+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=S+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:S}):x+=S),x+=this.parse(b.tokens,v),h+=this.renderer.listitem(x,T,k);r+=this.renderer.list(h,y,g);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<I&&t[o+1].type==="text";)p=t[++o],h+=`
135
- `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Hs{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}Am(Hs,"passThroughHooks",new Set(["preprocess","postprocess"]));function WC(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>"+Lt(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 jh(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ye.defaults,...s};const i=WC(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(zC(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&ye.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;ye.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ye.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&&ye.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ye(e,t,n){return jh(Ln.lex,$n.parse)(e,t,n)}ye.options=ye.setOptions=function(e){return ye.defaults={...ye.defaults,...e},NC(ye.defaults),ye},ye.getDefaults=yh,ye.defaults=or,ye.use=function(...e){const t=ye.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ye.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=ye.defaults.renderer||new Va;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=ye.defaults.tokenizer||new Wa;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=ye.defaults.hooks||new Hs;for(const s in n.hooks){const i=o[s];Hs.passThroughHooks.has(s)?o[s]=a=>{if(ye.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ye.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}}ye.setOptions(r)})},ye.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ye,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ye.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ye.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ye.walkTokens(r.items,t));break}default:ye.defaults.extensions&&ye.defaults.extensions.childTokens&&ye.defaults.extensions.childTokens[r.type]?ye.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ye.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ye.walkTokens(r.tokens,t)))}return n},ye.parseInline=jh(Ln.lexInline,$n.parseInline),ye.Parser=$n,ye.parser=$n.parse,ye.Renderer=Va,ye.TextRenderer=Nh,ye.Lexer=Ln,ye.lexer=Ln.lex,ye.Tokenizer=Wa,ye.Slugger=Ah,ye.Hooks=Hs,ye.parse=ye,ye.options,ye.setOptions,ye.use,ye.walkTokens,ye.parseInline,$n.parse,Ln.lex;function uo({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 ye.parse=="function"?ye.parse(i):ye(i)}return typeof ye.parse=="function"?ye.parse(e):ye(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 c.jsx("div",{className:se("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 VC={MODE:"library"};function KC(){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:ii&&ii.tagName.toUpperCase()==="SCRIPT"&&ii.src||new URL("index.umd.js",document.baseURI).href}<"u"?VC: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 qC(){return!KC()}function GC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function YC(){return qC()||GC()}function XC({preview:e,idx:t}){return w.useEffect(()=>{YC()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),c.jsxs("div",{className:"space-y-2",children:[e.label&&c.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),c.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:c.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})}})})]})}function JC({artifact:e}){const[t,n]=w.useState("bg-yellow-500/20 text-yellow-700 dark:text-yellow-300"),[r,o]=w.useState(c.jsx(ae.Clock,{className:"w-4 h-4"})),[s,i]=w.useState("Processing");return w.useEffect(()=>{switch(e.status||"processing"){case"completed":n("bg-green-500/20 text-green-700 dark:text-green-300"),o(c.jsx(ae.CheckCircle,{className:"w-4 h-4"})),i("Completed");break;case"failed":n("bg-red-500/20 text-red-700 dark:text-red-300"),o(c.jsx(ae.ExternalLink,{className:"w-4 h-4 rotate-45"})),i("Failed");break;case"pending":n("bg-blue-500/20 text-blue-700 dark:text-blue-300"),o(c.jsx(ae.Clock,{className:"w-4 h-4"})),i("Pending");break;default:n("bg-yellow-500/20 text-yellow-700 dark:text-yellow-300"),o(c.jsx(ae.Clock,{className:"w-4 h-4"})),i("Processing")}},[e.status]),c.jsxs("div",{className:"rounded-lg border border-blue-200 dark:border-blue-900/50 bg-blue-50 dark:bg-blue-950/20 p-4 space-y-3",children:[c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"mt-1 flex-shrink-0",children:c.jsx(ae.Search,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100",children:"Research Task"}),c.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300 mt-1",children:["Task ID: ",c.jsxs("code",{className:"font-mono text-xs bg-blue-100 dark:bg-blue-900/30 px-2 py-1 rounded",children:[e.task_id.slice(0,8),"..."]})]})]})]}),c.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-sm font-medium ${t}`,children:[r,c.jsx("span",{children:s})]}),e.query&&c.jsxs("div",{className:"text-sm text-blue-800 dark:text-blue-200 bg-white dark:bg-blue-900/30 rounded px-3 py-2",children:[c.jsx("p",{className:"font-medium text-xs text-blue-600 dark:text-blue-400 mb-1",children:"Query:"}),c.jsx("p",{className:"line-clamp-2",children:e.query})]}),e.progress_url&&c.jsx("div",{className:"pt-2",children:c.jsxs("a",{href:e.progress_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white dark:bg-blue-700 dark:hover:bg-blue-600 rounded-md text-sm font-medium transition-colors",children:[c.jsx("span",{children:"Monitor Progress"}),c.jsx(ae.ExternalLink,{className:"w-3.5 h-3.5"})]})}),e.createdAt&&c.jsxs("p",{className:"text-xs text-blue-600 dark:text-blue-400",children:["Started: ",new Date(e.createdAt).toLocaleTimeString()]})]})}function ZC({artifact:e,idx:t=0}){if((e==null?void 0:e.type)==="research_task_info")return c.jsx(JC,{artifact:{type:"research_task_info",task_id:e.task_id,progress_url:e.progress_url,query:e.query,status:e.status,createdAt:e.createdAt}});const n=w.useMemo(()=>e?(Array.isArray(e.plots)?e.plots:[]).map(o=>aC(o)).filter(o=>o!==null):[],[e]);return n.length>0?c.jsx("div",{className:"space-y-2",children:n.map((r,o)=>c.jsx(XC,{preview:r,idx:o},`${t}-plot-${o}`))}):e&&typeof e=="object"?c.jsx("div",{className:"rounded-lg border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/20 p-4",children:c.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Unknown artifact type: ",c.jsx("code",{className:"font-mono",children:e.type||"unknown"})]})}):null}const fo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:se("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));fo.displayName="Card";const ho=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:se("flex flex-col space-y-1.5 p-6",e),...t}));ho.displayName="CardHeader";const po=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:se("text-2xl font-semibold leading-none tracking-tight",e),...t}));po.displayName="CardTitle";const _h=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:se("text-sm text-muted-foreground",e),...t}));_h.displayName="CardDescription";const mo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:se("p-6 pt-0",e),...t}));mo.displayName="CardContent";const Mh=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:se("flex items-center p-6 pt-0",e),...t}));Mh.displayName="CardFooter";function QC({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=c.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const u=io(s);a=c.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:u})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return c.jsxs(fo,{className:se("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:[c.jsxs(ho,{className:"pb-3",children:[c.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),c.jsx(_h,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&c.jsx(mo,{className:"pt-0 pb-3",children:a}),c.jsx(Mh,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(tt,{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"}),c.jsx(tt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const ek="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 Rh({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:ek,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:io(e)}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:io(e)})}function tk({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=w.useMemo(()=>{const a=e.additionalKwargs??{};return Array.isArray(a.toolProgress)?[...a.toolProgress]:[]},[e]),s=r.some(a=>a.type==="tool.start"||a.type==="tool.call"||a.type==="message.start")?`Running ${n}…`:void 0;return t||r.length>0?c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[t&&c.jsx(ae.Loader,{className:"h-3 w-3 animate-spin"}),c.jsx("span",{children:s??`Running ${n}…`})]}),r.length>0&&c.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:r.map((a,l)=>{var u;return c.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[c.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[c.jsx("span",{children:((u=a.type)==null?void 0:u.replace(/\./g," "))??"progress"}),c.jsx("span",{children:a.idx??l+1})]}),a.content&&c.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:a.content}),c.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof a.factsFound=="number"&&c.jsxs("span",{children:["Facts found: ",a.factsFound]}),typeof a.isSufficient=="boolean"&&c.jsxs("span",{children:["Research ",a.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${n}-${l}`)})})]}):null}function nk({message:e,viewMode:t,isStreaming:n=!1}){const o=Gf(e).name||"tool",s=l=>{if(l==null)return null;const u=typeof l=="string"?Ma(l)??l:l;if(u&&typeof u=="object")return c.jsx(Rh,{data:u});const d=typeof u=="string"?u:(()=>{try{return io(u)}catch{return String(u??"")}})();return c.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:d})},i=l=>{if(l==null)return null;const{content:u,isMarkdown:d}=eC(l);return d?c.jsx(uo,{content:u,className:"text-current"}):s(l)},a=()=>{const l=e.content.find(f=>f.type!=="tool_call");if(!l)return c.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:c.jsxs("span",{children:["Running ",o,"…"]})});if(l.type==="text"){const h=(l.text??"").trim();if(!h)return null;const p=Rs(h);return i(p)}const u=so(l),d=Rs(u);return i(d)};return c.jsxs("div",{className:"space-y-2",children:[c.jsx(tk,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function rk(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ha(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,u]=w.useState(!1),d=w.useCallback(()=>{u(!1),a(null)},[]),f=w.useCallback(p=>{a(p),u(!0)},[]),h=w.useCallback(async(p,y,g)=>{var v,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const b=String(y.url??""),k=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(k){p.preventDefault();const T=k[1],S=y.name||`file_${T}`,C=y.mimeType||"application/octet-stream";f({id:T,name:S,mimeType:C});return}if(b.startsWith("data:")){p.preventDefault(),s(S=>({...S,[g]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const S=await cC(n??void 0);if(!S||!Array.isArray(S))throw new Error("Invalid file list response");const C=S.find(I=>!I||typeof I!="object"||!((I.filename??"")===(y.name??""))?!1:typeof y.size=="number"&&typeof I.size=="number"?I.size===y.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${y.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:y.name||C.filename||`file_${C.id}`,mimeType:y.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${y.name}`,open:!0})}catch(S){console.error("Failed to fetch server file:",S);const C=S instanceof Error?S.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(S=>({...S,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(k=>({...k,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function ok({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return c.jsxs("div",{className:"flex flex-col gap-1",children:[c.jsx("div",{className:se("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?c.jsx(uo,{content:e,allowHtml:!1}):c.jsxs("pre",{className:se("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,"..."]})}),c.jsx(tt,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?c.jsxs(c.Fragment,{children:[c.jsx(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function sk({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:se("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function Ph(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ws=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:u=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:h=!0,customStyles:p={},onEdit:y,onRegenerate:g,onCancelEdit:v,onCopy:x,activeInterrupt:b,disableInterruptActions:k=!1,onInterruptActionStart:T,onInterruptActionEnd:S,checkpointCandidates:C=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:R=null,messageParentCheckpointId:D=null}){const[B,X]=w.useState(!1),[G,M]=w.useState("preview"),[U,E]=w.useState(!1),{currentThreadId:P}=Fo(),{respondToInterrupt:L}=Bo(),_=l==="phone"||l==="half-screen",q=t.role,Y=q==="tool",j=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),J=!!j,V=!(r&&q!=="user"),{uploadingFiles:H,handleFileClick:ee,fileViewerOpen:W,currentFileInfo:O,closeFileViewer:K}=rk({allowFileOpen:V,currentThreadId:P}),z=w.useMemo(()=>{switch(q){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))]"}},[q]),ne=w.useMemo(()=>{if(j)return"";const $=t.content;return Array.isArray($)?tC($):""},[j,t]),Q=w.useMemo(()=>{if(j)return{};const $=t.content;return Array.isArray($)?Gf(t):{}},[j,t]),ge=w.useMemo(()=>Y?!!(t.additionalKwargs??{}).toolStreaming:!1,[Y,t]),le=w.useMemo(()=>{if(j)return[];const $=t.content;return Array.isArray($)?$.filter(he=>he.type==="image_url"):[]},[j,t]),oe=w.useMemo(()=>{if(j)return[];const $=t.content;return Array.isArray($)?$.filter(he=>he.type==="file"):[]},[j,t]),pe=w.useMemo(()=>{if(j)return[];const $=t.content;return Array.isArray($)?$.filter(he=>he.type==="interrupt"):[]},[j,t]),be=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Me=Ps(be),Ie=b==null?void 0:b.value,De=w.useMemo(()=>{if(j)return"";const $=t.content;return Array.isArray($)?nC($):""},[j,t]),et=w.useMemo(()=>j||!h?null:t.artifact||null,[j,t,h]),rt=w.useCallback(async()=>{const $=Y?De:ne;async function he(we){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(we);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const $e=new Blob([we],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":$e})]);return}throw new Error("Clipboard API not supported in this context.")}try{await he($),X(!0),setTimeout(()=>X(!1),2e3),x==null||x($)}catch(we){console.error("Failed to copy:",we)}},[Y,De,ne,x]),He=w.useCallback(()=>{if(!y)return;const $=Y?De:ne,he="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};y(t.id,$,he)},[y,t.id,Y,De,ne,t]),Je=w.useCallback(()=>{g==null||g(n)},[g,n]),ot=w.useCallback(()=>{const he=se(_?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",z);switch(q){case"user":return c.jsx(ae.User,{className:he});case"assistant":return c.jsx(ae.Bot,{className:he});case"tool":return c.jsx(ae.Wrench,{className:he});default:return c.jsx(ae.Bot,{className:he})}},[_,z,q]),St=w.useCallback(()=>{const $="group relative mb-4 flex w-full";switch(q){case"user":return se($,"justify-end");case"assistant":case"tool":case"system":return se($,"justify-start");default:return $}},[q]),dt=w.useCallback(()=>{const $=se("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",_&&"px-3 py-2 text-sm");if(J)return se($,"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(q){case"user":return se($,"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 se($,"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 se($,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return se($,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return se($,"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")}},[_,J,q]),Tt=w.useCallback(async $=>{if(k)return;const he=Ps(($==null?void 0:$.id)??($==null?void 0:$.interrupt_id));if(!he){console.warn("Interrupt part missing id",$);return}try{T==null||T(),await L(he,!0)}catch(we){console.error("Failed to approve interrupt:",we)}finally{S==null||S()}},[k,S,T,L]),mt=w.useCallback(async $=>{if(k)return;const he=Ps(($==null?void 0:$.id)??($==null?void 0:$.interrupt_id));if(!he){console.warn("Interrupt part missing id",$);return}try{T==null||T(),await L(he,!1)}catch(we){console.error("Failed to reject interrupt:",we)}finally{S==null||S()}},[k,S,T,L]),Ee=w.useCallback(({part:$,i:he})=>{if($.type==="text"){const we=$.text??"",$e=we.trim(),ze=Ma($e);return ze&&q!=="tool"?c.jsx(Rh,{data:ze},he):q==="user"&&u&&$e.length>d?c.jsx(ok,{text:$e,expanded:U,onExpandedChange:E,previewLength:d,isCompact:_},he):c.jsx(uo,{content:we,allowHtml:!1},he)}if($.type==="image_url"){const we=$;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:we.url,alt:we.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},he)}if($.type==="file"){const we=$,$e=we.name||"file";return c.jsxs("a",{href:we.url,onClick:ze=>ee(ze.nativeEvent,we,he),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:[H[he]?c.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[$e,H[he]?" (processing)":""]})]},he)}if($.type==="interrupt"){const we=$,$e=Ps((we==null?void 0:we.id)??(we==null?void 0:we.interrupt_id)),ze=!!(Me&&$e&&$e===Me),pt=ze?Ie??(we==null?void 0:we.value):we==null?void 0:we.value,Ze=$e?{...we,id:$e,interrupt_id:$e}:we;return c.jsx(QC,{interruptPart:Ze,onApprove:Tt,onReject:mt,disabled:k,isActive:ze,payload:pt},he)}return null},[ee,H,Tt,mt,q,u,d,U,_,Me,Ie,b,k,pe]),Ke=w.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),xt=w.useCallback(()=>{const $=ne.trim().length>0||le.length>0||oe.length>0||pe.length>0;if(!Y&&oe.length>0&&!r)return Ke();if(!Y&&!$&&!r)return null;if(Y)return!f&&et?null:f?c.jsx(nk,{message:t,viewMode:G,isStreaming:ge},t.id):null;if(!Y&&!j){const he=t,we=c.jsx("div",{className:"space-y-2",children:he.content.map(($e,ze)=>c.jsx(Ee,{part:$e,i:ze},ze))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[we,c.jsx(sk,{className:z})]}):we}},[ne,le.length,oe.length,pe.length,r,Y,G,f,et,Ke,z]),It=w.useMemo(()=>j?"Assistant":rC(t),[j,t]),Le=w.useMemo(()=>j?[]:Array.isArray(C)?C:[],[C,j]),_t=w.useMemo(()=>{var $;return Le.length?R&&Le.some(he=>he.id===R)?R:(($=Le[0])==null?void 0:$.id)??null:null},[R,Le]),Be=w.useMemo(()=>!Le.length||!I?null:Le.some($=>$.id===I)?I:null,[I,Le])??_t,lt=q==="user"&&Le.length>0&&typeof A=="function",Et=w.useCallback(($,he=!1)=>{if(!A)return;const we=($==null?void 0:$.id)??null,$e=($==null?void 0:$.parentId)??D??null;A(we,$e,he)},[D,A]),qe=w.useMemo(()=>Be?Le.findIndex($=>$.id===Be):-1,[Be,Le]),Z=w.useMemo(()=>qe<0?null:Le[qe]??null,[qe,Le]);return Y&&!f&&!et?null:J&&j?c.jsx("div",{className:se(St(),p.container),children:c.jsxs("div",{className:se(dt(),p.content),children:[c.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[c.jsx(ae.Bot,{className:se("h-4 w-4",z)}),a&&c.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),c.jsx(uo,{content:j.content,className:"text-current"})]})}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:se(St(),p.container),children:c.jsxs("div",{className:se(dt(),p.content),children:[(i||a||Y)&&c.jsxs("div",{className:se("flex items-center justify-between mb-2 pb-2 border-b border-current/10",_&&"mb-1 pb-1",z,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[ot(),a&&It&&c.jsx("span",{className:se("font-medium",_?"text-xs":"text-sm"),children:It}),Y&&c.jsxs(Kf,{variant:"outline",className:se("text-xs flex items-center gap-1 cursor-pointer select-none",z,"border border-current/40",_&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":G==="expanded",onClick:()=>M($=>$==="expanded"?"preview":"expanded"),onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),M(he=>he==="expanded"?"preview":"expanded"))},children:[c.jsx("span",{children:Q.name??"Tool Output"}),Q.toolCallId&&c.jsx("span",{className:"opacity-70",children:Q.toolCallId.slice(0,8)}),G==="expanded"?c.jsx(ae.ChevronUp,{className:"h-3 w-3"}):c.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[lt&&Z&&qe>=0&&c.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{type:"button",className:se("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",qe<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(qe>=Le.length-1)return;const $=Le[qe+1];$&&Et($)},"aria-label":"Older checkpoint (back in time)",disabled:qe>=Le.length-1,children:c.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),c.jsx("div",{className:"flex items-center gap-2",children:c.jsxs("span",{className:"whitespace-nowrap",children:[Le.length-qe," / ",Le.length]})}),c.jsx("button",{type:"button",className:se("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",qe>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(qe<=0))if(qe===1)Et(null,!0);else{const $=Le[qe-1];$&&Et($,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:qe<=0,children:c.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&c.jsx("time",{className:se("text-xs opacity-60",z,_&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:se("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx("div",{className:"relative",children:c.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>rt(),className:se("h-6 w-6 p-0 hover:bg-foreground/10",z,_&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:c.jsx(ae.Copy,{className:se(B?"text-success":z,_?"h-3 w-3":"h-4 w-4")})})}),q==="user"&&y&&c.jsx(tt,{variant:"ghost",size:"sm",onClick:He,className:se("h-6 w-6 p-0 hover:bg-foreground/10",z,_&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(ae.Edit,{className:se(z,_?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&g&&c.jsx(tt,{variant:"ghost",size:"sm",onClick:Je,className:se("h-6 w-6 p-0 hover:bg-foreground/10",z,_&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(ae.RotateCcw,{className:se(z,_?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsxs("div",{className:"relative",children:[xt(),h&&et&&c.jsx("div",{className:"mt-3",children:c.jsx(ZC,{artifact:et,idx:0})})]}),Y&&G==="expanded"&&(Q.toolCallId||Q.name)&&c.jsxs("div",{className:se("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",_&&"text-xs"),children:[Q.name&&c.jsxs("div",{children:["Function: ",Q.name]}),Q.toolCallId&&c.jsxs("div",{children:["Call ID: ",Q.toolCallId]})]}),!(i||a||Y)&&s&&!o&&c.jsxs("div",{className:se("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>rt(),className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:c.jsx(ae.Copy,{className:se(B?"text-success":"text-current",_?"h-3 w-3":"h-4 w-4")})}),q==="user"&&y&&c.jsx(tt,{variant:"ghost",size:"sm",onClick:He,className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:c.jsx(ae.Edit,{className:se("text-current",_?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&g&&c.jsx(tt,{variant:"ghost",size:"sm",onClick:Je,className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:c.jsx(ae.RotateCcw,{className:se("text-current",_?"h-3 w-3":"h-4 w-4")})})]})]})}),O&&c.jsx(EC,{isOpen:W,onClose:K,fileId:O.id,fileName:O.name,mimeType:O.mimeType})]})},(e,t)=>{var l,u,d,f,h,p,y,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Yf(e.message)===Yf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(v=>e[v]===t[v]),s=((l=e.customStyles)==null?void 0:l.container)===((u=t.customStyles)==null?void 0:u.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((h=e.customStyles)==null?void 0:h.actions)===((p=t.customStyles)==null?void 0:p.actions)&&((y=e.customStyles)==null?void 0:y.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=Ph(e.message),a=Ph(t.message);return i.length===a.length});Ws.displayName="MessageComponent";function ik(e,t){return w.useMemo(()=>{var d,f,h,p,y;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,u=null;if(!n&&e){const g=e,v=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=v&&t.checkpointMetaById?t.checkpointMetaById.get(v)??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 k=a!==null&&l?`${a}:${l}`:null;if(k&&((d=t.checkpointIndexByKey)!=null&&d.has(k))?r=t.checkpointIndexByKey.get(k)??[]:v&&x&&(r=[x]),o=v??((f=r[0])==null?void 0:f.id)??null,u=v?((h=t.attemptMetaById)==null?void 0:h.get(v))??null:null,!u&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const T=t.userMessageIdToAttempts.get(e.id);if(T&&T.length>0){const S=T[0].checkpointId;u=((p=t.attemptMetaById)==null?void 0:p.get(S))??null,u&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,T.length,"versions")}}if(!u&&r.length>0&&t.attemptMetaById){const T=t.attemptMetaById.get(r[0].id);T&&(u=T)}if(u&&u.attemptCount>1&&t.attemptMetaById){const T=u.baseUserMessageId;if(T){const S=[];for(const[C,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===T){const A=(y=t.checkpointMetaById)==null?void 0:y.get(C);A&&S.push(A)}S.length>0&&(r=S)}}if(u&&u.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const T=[];for(const[S,C]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(S);I&&I.attemptCount===u.attemptCount&&I.baseUserMessageId===u.baseUserMessageId&&T.push(C)}T.sort((S,C)=>{const I=S.createdAt?Date.parse(S.createdAt):0;return(C.createdAt?Date.parse(C.createdAt):0)-I}),T.length>0&&(r=T,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:u.attemptCount,candidateIds:r.map(S=>S.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:u,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const Oh=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Dh=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:u,onRegenerate:d,onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:y,onInterruptActionEnd:g,showToolMessages:v,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:k,attemptMetaById:T,userMessageIdToAttempts:S,activeCheckpointId:C,onSelectCheckpoint:I}){const A=Oh(t,n),R="type"in t&&t.type==="default_message",B=!!t.__syntheticStreaming,{checkpointCandidates:X,defaultCheckpointId:G,attemptMeta:M}=ik(t,{checkpointMetaById:b,checkpointIndexByKey:k,attemptMetaById:T,userMessageIdToAttempts:S}),U=t&&!R?t.additionalKwargs??{}:{},E=t&&!R?t.responseMetadata??{}:{},P=(()=>{if(typeof U.parentCheckpointId=="string")return U.parentCheckpointId;if(typeof E.parentCheckpointId=="string")return E.parentCheckpointId})();return c.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Ws,{message:t,messageIndex:n,isStreamingMessage:B||r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:u,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:y,onInterruptActionEnd:g,showToolMessages:v,showArtifactPreviews:x,checkpointCandidates:X,activeCheckpointId:C??null,onSelectCheckpoint:I,defaultCheckpointId:G,messageParentCheckpointId:P,attemptMeta:M})})});Dh.displayName="MessageRow";const Ka=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:y=!0,isNavigatingCheckpoint:g=!1,onScrollAway:v,onAtBottom:x,activeInterrupt:b,disableInterruptActions:k=!1,onInterruptActionStart:T,onInterruptActionEnd:S,showToolMessages:C=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:X,onSelectCheckpoint:G,createSyntheticThinkingMessage:M=!0},U)=>{const E=w.useRef(null),P=w.useRef(null),L=w.useRef(!1),_=w.useRef(!1),[q,Y]=w.useState(!0),j=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(pe=>pe&&pe.type==="interrupt"&&(pe.id??pe.interrupt_id)===b.id)):!1,[b,e]),J=w.useMemo(()=>{if(!b||j)return null;const oe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let pe;const be=b.value;if(be&&typeof be=="object"&&!Array.isArray(be)){const Me=be.title;typeof Me=="string"&&Me.trim()&&(pe=Me.trim())}return{id:`interrupt-${oe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:oe,value:be,title:pe}]}},[b,j]),V=w.useMemo(()=>J?[...e,J]:e,[e,J]),H=w.useMemo(()=>!M||!t?V:!V.some(pe=>pe.role==="assistant")&&V.length>0?[...V,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString(),__syntheticStreaming:!0}]:V,[V,t,M]),ee=w.useMemo(()=>C?H:H.filter(oe=>(oe==null?void 0:oe.role)!=="tool"),[H,C]),W=w.useCallback(oe=>{Y(oe),v&&v(!oe),x&&x(oe)},[v,x]),O=w.useMemo(()=>{if(a)return async()=>{if(!L.current){L.current=!0;try{await a()}finally{L.current=!1}}}},[a]),K=w.useMemo(()=>!y||g?!1:q?"auto":!1,[q,y,g]),z=w.useMemo(()=>{if(typeof p!="string")return null;const oe=p.trim();return oe?{id:"default-message",role:"assistant",type:"default_message",content:oe,createdAt:new Date().toISOString()}:null},[p]),ne=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Q=()=>z?c.jsx("div",{className:"p-6 h-full overflow-y-auto",children:c.jsx("div",{className:"w-full max-w-full",children:c.jsx(Ws,{message:z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):c.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),ge=ee.length,le=ge>0;return w.useEffect(()=>{var oe,pe;if(ge===0){_.current=!1;return}if(!_.current)if(_.current=!0,E.current&&ee.length>0){const be=ee.length-1;(pe=(oe=E.current).scrollToIndex)==null||pe.call(oe,{index:be,align:"end",behavior:"auto"})}else P.current&&(P.current.scrollTop=P.current.scrollHeight)},[ge,ee.length]),w.useImperativeHandle(U,()=>({scrollToLatest:()=>{var oe,pe;if(E.current&&ee.length>0){const be=ee.length-1;(pe=(oe=E.current).scrollToIndex)==null||pe.call(oe,{index:be,align:"end",behavior:"auto"})}else P.current&&(P.current.scrollTop=P.current.scrollHeight)},scrollToTop:()=>{var oe,pe;E.current&&ee.length>0?(pe=(oe=E.current).scrollToIndex)==null||pe.call(oe,{index:0,align:"start",behavior:"auto"}):P.current&&(P.current.scrollTop=0)}}),[ee]),c.jsx("div",{className:ne,style:h,children:c.jsx("div",{className:"relative flex-1 min-h-0",children:le?c.jsx(LS,{ref:oe=>{E.current=oe},scrollerRef:oe=>{P.current=oe instanceof HTMLDivElement?oe:null},data:ee,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{O&&O()},atBottomStateChange:W,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(oe,pe)=>Oh(pe,oe),itemContent:(oe,pe)=>c.jsx(Dh,{message:pe,index:oe,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:u,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:k,onInterruptActionStart:T,onInterruptActionEnd:S,showToolMessages:C,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:X,onSelectCheckpoint:G})}):Q()})})});Ka.displayName="MessageList";const Lh={value:""};function Vs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:h={},onMessageSent:p,onExcelUploadSuccess:y,onError:g}){const{api:v}=wi(),{currentThreadId:x}=Fo(),{threadId:b,messages:k,isHistoryLoading:T,isLoading:S,navigateToCheckpoint:C,returnToLatest:I,checkpoint:A,checkpoints:R,interrupt:D,metadata:B,timelineCheckpoints:X,messagePreviews:G}=Bo(),{isStreaming:M,error:U,connectionState:E,submit:P,stop:L}=Dc(),_=b??x??null,q=(A==null?void 0:A.id)??null,Y=(A==null?void 0:A.namespace)??null,j=(B==null?void 0:B.assemblingMessageId)??null,J=D,[V,H]=w.useState(!1);w.useEffect(()=>{J||H(!1)},[J]);const ee=w.useCallback(()=>{H(!0)},[]),W=w.useCallback(()=>{H(!1)},[]),O=!!J||V,[K,z]=w.useState(null),[ne,Q]=w.useState(""),[ge,le]=w.useState(null),[oe,pe]=w.useState(null),[be,Me]=w.useState([]),[Ie,De]=w.useState(0),[et,rt]=w.useState(0),[He,Je]=w.useState(!1),[ot,St]=w.useState(null),[dt,Tt]=w.useState(null),[mt,Ee]=w.useState(!1),[Ke,xt]=w.useState(null),It=w.useRef(!1),[Le,_t]=w.useState(()=>Lh.value),Ge=w.useRef(Le),Be=w.useRef(null),lt=w.useCallback(me=>{Lh.value=me,_t(me)},[]),[Et,qe]=w.useState(!1),Z=w.useRef(null),{checkpointMetaById:$,checkpointIndexByKey:he,attemptMetaById:we,userMessageIdToAttempts:$e}=k0(R),ze=X??[],pt=w.useRef(null),Ze=w.useRef(null),Ct=w.useCallback(()=>{pt.current&&(pt.current.value=""),Ze.current&&(Ze.current.value=""),De(me=>me+1),rt(me=>me+1)},[]),cr=w.useCallback(me=>{lt(me)},[lt]),vo=w.useRef(!1);w.useEffect(()=>{vo.current&&!M&&(Me([]),Ct()),vo.current=M},[M,Ct]);const[ri,hl]=w.useState("desktop");w.useEffect(()=>{const me=()=>{const Ce=window.innerWidth;hl(Ce<640?"phone":Ce<1024?"tablet":"desktop")};return me(),window.addEventListener("resize",me),()=>window.removeEventListener("resize",me)},[]),w.useEffect(()=>{It.current=!1},[_]),w.useEffect(()=>{Ge.current=Le},[Le]),w.useEffect(()=>{if(!K){Be.current=null;return}Be.current===null&&(Be.current=Ge.current),lt(ne??"")},[ne,K,lt]),w.useEffect(()=>{(async()=>{if(!v.baseUrl){xt(null);return}try{const je=(await v.getAgent("default")).uiDefaultMessage||"";xt(je||null)}catch(Ce){console.warn("Failed to fetch default message:",Ce),xt(null)}})()},[v.baseUrl]),w.useEffect(()=>{U&&!mt&&(g==null||g(U))},[U,mt,g]);const pl=me=>{if(me.length>vs)return`Message too long (${me.length}/${vs} characters)`;try{return E0(me),null}catch(Ce){return(Ce==null?void 0:Ce.message)||"Invalid message"}},ml=async me=>{const Ce=me.trim();if(!(!Ce&&be.length===0)){if(Ce){const je=pl(Ce);if(je){pe(je);return}}try{const je=K?(ge==null?void 0:ge.checkpointId)??q??void 0:q??void 0,Ye=K?(ge==null?void 0:ge.checkpointNs)??Y??void 0:Y??void 0;await P({text:Ce||"",attachments:be},{checkpointId:je,checkpointNs:Ye,edit:!!K,originalMessageId:K??void 0}),p==null||p(Ce),lt(""),pe(null),Me([]),Ct(),z(null),Q(""),le(null)}catch(je){const Ye=(je==null?void 0:je.message)||"Failed to send message";pe(Ye),g==null||g(Ye)}}},oi=w.useCallback((me,Ce,je)=>{u&&(Be.current=Le,z(me),Q(Ce),lt(Ce),pe(null),le({checkpointId:(je==null?void 0:je.checkpointId)??null,checkpointNs:(je==null?void 0:je.checkpointNs)??null}))},[Le,u,lt]),N=w.useCallback(()=>{z(null),Q(""),le(null),pe(null),lt(Be.current??Le),Be.current=null},[Le,lt]),re=w.useCallback((me,Ce,je)=>{oi(me,Ce,je)},[oi]),ce=w.useCallback(me=>{let Ce=null;for(let on=me-1;on>=0;on--)if(k[on].role==="user"){Ce=k[on];break}if(!Ce)return;const je=Array.isArray(Ce.content)?Ce.content:[],Hn=je.filter(on=>(on==null?void 0:on.type)==="text").map(on=>on.text).join("")||(()=>{try{return JSON.stringify(je,null,2)}catch{return String(je)}})();Hn&&P({text:Hn},{checkpointId:q??void 0,checkpointNs:Y??void 0,edit:!0,originalMessageId:Ce.id})},[k,P,q,Y]),Ne=me=>{const Ce=Array.from(me.target.files||[]);Me(je=>[...je,...Ce]),me.target.value=""},Qe=me=>{Me(Ce=>{const je=Ce.filter((Ye,Hn)=>me!==Hn);return je.length===0&&Ct(),je})},st=async me=>{const Ce=(me.target.files||[])[0];if(Ce){St(null),Tt(null),Je(!0);try{await P({attachments:[Ce]},{checkpointId:q??void 0,checkpointNs:Y??void 0});const je=`Uploaded ${Ce.name} - processing through chat stream`;Tt(je)}catch(je){const Ye=je instanceof Error?je.message:"Failed to upload Excel file";console.error("Excel upload failed",je),St(Ye),g==null||g(Ye)}finally{Je(!1),me.target.value="",Ct()}}},Ue=async me=>{if(x){qe(!0);try{if(!me){await I(),requestAnimationFrame(()=>{var Ye;(Ye=Z.current)==null||Ye.scrollToLatest()});return}const Ce=R.find(Ye=>Ye.checkpointId===me),je=(Ce==null?void 0:Ce.checkpointNs)??null;await C(me,je),requestAnimationFrame(()=>{var Ye;(Ye=Z.current)==null||Ye.scrollToTop()})}finally{qe(!1)}}},Fe=w.useCallback(async(me,Ce,je)=>{await Ue(je?null:me)},[Ue]),Mt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${h.container||""}`,gt=`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 ${h.messagesArea||""}`,yt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${h.inputArea||""}`;return c.jsxs("div",{className:Mt,children:[!!U&&!mt&&c.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[c.jsx("span",{children:U}),c.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>Ee(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(ae.X,{size:16})})]}),c.jsxs("div",{className:`relative ${gt}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Ka,{ref:Z,className:"h-full",style:{height:"100%"},messages:k,isStreaming:M,streamingAssistantId:j,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ri,enableMessageEditing:u,editingMessageId:K,onEdit:re,onRegenerate:ce,onCancelEdit:N,emptyMessage:Ke??void 0,isNavigatingCheckpoint:Et,activeInterrupt:J,disableInterruptActions:V,onInterruptActionStart:ee,onInterruptActionEnd:W,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:$,checkpointIndexByKey:he,attemptMetaById:we,userMessageIdToAttempts:$e,activeCheckpointId:q,onSelectCheckpoint:Fe,timelineCheckpoints:ze,messagePreviews:G,createSyntheticThinkingMessage:!0}),(E==="reconnecting"||E==="connecting")&&c.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:c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(ae.Loader2,{className:"h-3 w-3 animate-spin"}),E==="reconnecting"?"Reconnecting…":"Connecting…"]})}),E==="error"&&c.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"}),S&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(T||Et)&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),c.jsxs("div",{className:yt,children:[K&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ae.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(tt,{variant:"ghost",size:"sm",onClick:N,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(ae.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:pt,type:"file",multiple:!0,onChange:me=>Ne(me),className:"hidden"},Ie),be.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:be.map((me,Ce)=>c.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[c.jsx(ae.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:me.name}),c.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>Qe(Ce),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 ${me.name}`,children:c.jsx(ae.X,{size:12})})]},Ce))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:Ze,type:"file",accept:".xls,.xlsx,.xlsm",onChange:st,className:"hidden"},et),He&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),dt&&!He&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:dt}),ot&&!He&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:ot})]})]}),oe&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:oe}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(aa,{children:[c.jsx(la,{asChild:!0,children:c.jsx(tt,{type:"button",size:"icon",variant:"outline",disabled:M||O,title:"More input actions",className:h.moreButton||"",children:c.jsx(ae.Plus,{size:16})})}),c.jsxs(xs,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(Jn,{onClick:()=>{var me;return(me=pt.current)==null?void 0:me.click()},className:"cursor-pointer",children:[c.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(Jn,{onClick:()=>{var me;He||(me=Ze.current)==null||me.click()},className:`cursor-pointer ${He?"opacity-60 pointer-events-none":""}`,children:[c.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(hy,{initialValue:ne,editingMessageId:K,value:Le,onValueChange:cr,placeholder:K?"Edit your message...":t,isStreaming:M,disabled:O,maxLength:vs,onSend:ml,onCancelEdit:N,onStop:L,allowEmptySend:be.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${K?"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":""} ${h.textarea||""}`})})]})]})]})}var $h=1,ak=.9,lk=.8,ck=.17,qa=.1,Ga=.999,uk=.9999,dk=.99,fk=/[\\\/_+.#"@\[\(\{&]/,hk=/[\\\/_+.#"@\[\(\{&]/g,pk=/[\s-]/,Fh=/[\s-]/g;function Ya(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?$h:dk;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),u=n.indexOf(l,o),d=0,f,h,p,y;u>=0;)f=Ya(e,t,n,r,u+1,s+1,i),f>d&&(u===o?f*=$h:fk.test(e.charAt(u-1))?(f*=lk,p=e.slice(o,u-1).match(hk),p&&o>0&&(f*=Math.pow(Ga,p.length))):pk.test(e.charAt(u-1))?(f*=ak,y=e.slice(o,u-1).match(Fh),y&&o>0&&(f*=Math.pow(Ga,y.length))):(f*=ck,o>0&&(f*=Math.pow(Ga,u-o))),e.charAt(u)!==t.charAt(s)&&(f*=uk)),(f<qa&&n.charAt(u-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(u-1)!==r.charAt(s))&&(h=Ya(e,t,n,r,u+1,s+2,i),h*qa>f&&(f=h*qa)),f>d&&(d=f),u=n.indexOf(l,u+1);return i[a]=d,d}function Bh(e){return e.toLowerCase().replace(Fh," ")}function mk(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Ya(e,t,Bh(e),Bh(t),0,0,{})}var go='[cmdk-group=""]',Xa='[cmdk-group-items=""]',gk='[cmdk-group-heading=""]',zh='[cmdk-item=""]',Uh=`${zh}:not([aria-disabled="true"])`,Ja="cmdk-item-select",Er="data-value",xk=(e,t,n)=>mk(e,t,n),Hh=m.createContext(void 0),xo=()=>m.useContext(Hh),Wh=m.createContext(void 0),Za=()=>m.useContext(Wh),Vh=m.createContext(void 0),Kh=m.forwardRef((e,t)=>{let n=Nr(()=>{var j,J;return{search:"",value:(J=(j=e.value)!=null?j:e.defaultValue)!=null?J:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Nr(()=>new Set),o=Nr(()=>new Map),s=Nr(()=>new Map),i=Nr(()=>new Set),a=qh(e),{label:l,children:u,value:d,onValueChange:f,filter:h,shouldFilter:p,loop:y,disablePointerSelection:g=!1,vimBindings:v=!0,...x}=e,b=Ft(),k=Ft(),T=Ft(),S=m.useRef(null),C=Nk();sr(()=>{if(d!==void 0){let j=d.trim();n.current.value=j,I.emit()}},[d]),sr(()=>{C(6,G)},[]);let I=m.useMemo(()=>({subscribe:j=>(i.current.add(j),()=>i.current.delete(j)),snapshot:()=>n.current,setState:(j,J,V)=>{var H,ee,W,O;if(!Object.is(n.current[j],J)){if(n.current[j]=J,j==="search")X(),D(),C(1,B);else if(j==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let K=document.getElementById(T);K?K.focus():(H=document.getElementById(b))==null||H.focus()}if(C(7,()=>{var K;n.current.selectedItemId=(K=M())==null?void 0:K.id,I.emit()}),V||C(5,G),((ee=a.current)==null?void 0:ee.value)!==void 0){let K=J??"";(O=(W=a.current).onValueChange)==null||O.call(W,K);return}}I.emit()}},emit:()=>{i.current.forEach(j=>j())}}),[]),A=m.useMemo(()=>({value:(j,J,V)=>{var H;J!==((H=s.current.get(j))==null?void 0:H.value)&&(s.current.set(j,{value:J,keywords:V}),n.current.filtered.items.set(j,R(J,V)),C(2,()=>{D(),I.emit()}))},item:(j,J)=>(r.current.add(j),J&&(o.current.has(J)?o.current.get(J).add(j):o.current.set(J,new Set([j]))),C(3,()=>{X(),D(),n.current.value||B(),I.emit()}),()=>{s.current.delete(j),r.current.delete(j),n.current.filtered.items.delete(j);let V=M();C(4,()=>{X(),(V==null?void 0:V.getAttribute("id"))===j&&B(),I.emit()})}),group:j=>(o.current.has(j)||o.current.set(j,new Set),()=>{s.current.delete(j),o.current.delete(j)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:b,inputId:T,labelId:k,listInnerRef:S}),[]);function R(j,J){var V,H;let ee=(H=(V=a.current)==null?void 0:V.filter)!=null?H:xk;return j?ee(j,n.current.search,J):0}function D(){if(!n.current.search||a.current.shouldFilter===!1)return;let j=n.current.filtered.items,J=[];n.current.filtered.groups.forEach(H=>{let ee=o.current.get(H),W=0;ee.forEach(O=>{let K=j.get(O);W=Math.max(K,W)}),J.push([H,W])});let V=S.current;U().sort((H,ee)=>{var W,O;let K=H.getAttribute("id"),z=ee.getAttribute("id");return((W=j.get(z))!=null?W:0)-((O=j.get(K))!=null?O:0)}).forEach(H=>{let ee=H.closest(Xa);ee?ee.appendChild(H.parentElement===ee?H:H.closest(`${Xa} > *`)):V.appendChild(H.parentElement===V?H:H.closest(`${Xa} > *`))}),J.sort((H,ee)=>ee[1]-H[1]).forEach(H=>{var ee;let W=(ee=S.current)==null?void 0:ee.querySelector(`${go}[${Er}="${encodeURIComponent(H[0])}"]`);W==null||W.parentElement.appendChild(W)})}function B(){let j=U().find(V=>V.getAttribute("aria-disabled")!=="true"),J=j==null?void 0:j.getAttribute(Er);I.setState("value",J||void 0)}function X(){var j,J,V,H;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let ee=0;for(let W of r.current){let O=(J=(j=s.current.get(W))==null?void 0:j.value)!=null?J:"",K=(H=(V=s.current.get(W))==null?void 0:V.keywords)!=null?H:[],z=R(O,K);n.current.filtered.items.set(W,z),z>0&&ee++}for(let[W,O]of o.current)for(let K of O)if(n.current.filtered.items.get(K)>0){n.current.filtered.groups.add(W);break}n.current.filtered.count=ee}function G(){var j,J,V;let H=M();H&&(((j=H.parentElement)==null?void 0:j.firstChild)===H&&((V=(J=H.closest(go))==null?void 0:J.querySelector(gk))==null||V.scrollIntoView({block:"nearest"})),H.scrollIntoView({block:"nearest"}))}function M(){var j;return(j=S.current)==null?void 0:j.querySelector(`${zh}[aria-selected="true"]`)}function U(){var j;return Array.from(((j=S.current)==null?void 0:j.querySelectorAll(Uh))||[])}function E(j){let J=U()[j];J&&I.setState("value",J.getAttribute(Er))}function P(j){var J;let V=M(),H=U(),ee=H.findIndex(O=>O===V),W=H[ee+j];(J=a.current)!=null&&J.loop&&(W=ee+j<0?H[H.length-1]:ee+j===H.length?H[0]:H[ee+j]),W&&I.setState("value",W.getAttribute(Er))}function L(j){let J=M(),V=J==null?void 0:J.closest(go),H;for(;V&&!H;)V=j>0?Ik(V,go):Ek(V,go),H=V==null?void 0:V.querySelector(Uh);H?I.setState("value",H.getAttribute(Er)):P(j)}let _=()=>E(U().length-1),q=j=>{j.preventDefault(),j.metaKey?_():j.altKey?L(1):P(1)},Y=j=>{j.preventDefault(),j.metaKey?E(0):j.altKey?L(-1):P(-1)};return m.createElement(Se.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:j=>{var J;(J=x.onKeyDown)==null||J.call(x,j);let V=j.nativeEvent.isComposing||j.keyCode===229;if(!(j.defaultPrevented||V))switch(j.key){case"n":case"j":{v&&j.ctrlKey&&q(j);break}case"ArrowDown":{q(j);break}case"p":case"k":{v&&j.ctrlKey&&Y(j);break}case"ArrowUp":{Y(j);break}case"Home":{j.preventDefault(),E(0);break}case"End":{j.preventDefault(),_();break}case"Enter":{j.preventDefault();let H=M();if(H){let ee=new Event(Ja);H.dispatchEvent(ee)}}}}},m.createElement("label",{"cmdk-label":"",htmlFor:A.inputId,id:A.labelId,style:jk},l),Ks(e,j=>m.createElement(Wh.Provider,{value:I},m.createElement(Hh.Provider,{value:A},j))))}),yk=m.forwardRef((e,t)=>{var n,r;let o=Ft(),s=m.useRef(null),i=m.useContext(Vh),a=xo(),l=qh(e),u=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;sr(()=>{if(!u)return a.item(o,i==null?void 0:i.id)},[u]);let d=Gh(o,s,[e.value,e.children,s],e.keywords),f=Za(),h=Fn(C=>C.value&&C.value===d.current),p=Fn(C=>u||a.filter()===!1?!0:C.search?C.filtered.items.get(o)>0:!0);m.useEffect(()=>{let C=s.current;if(!(!C||e.disabled))return C.addEventListener(Ja,y),()=>C.removeEventListener(Ja,y)},[p,e.onSelect,e.disabled]);function y(){var C,I;g(),(I=(C=l.current).onSelect)==null||I.call(C,d.current)}function g(){f.setState("value",d.current,!0)}if(!p)return null;let{disabled:v,value:x,onSelect:b,forceMount:k,keywords:T,...S}=e;return m.createElement(Se.div,{ref:An(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!v,"aria-selected":!!h,"data-disabled":!!v,"data-selected":!!h,onPointerMove:v||a.getDisablePointerSelection()?void 0:g,onClick:v?void 0:y},e.children)}),vk=m.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=Ft(),a=m.useRef(null),l=m.useRef(null),u=Ft(),d=xo(),f=Fn(p=>o||d.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);sr(()=>d.group(i),[]),Gh(i,a,[e.value,e.heading,l]);let h=m.useMemo(()=>({id:i,forceMount:o}),[o]);return m.createElement(Se.div,{ref:An(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&m.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:u},n),Ks(e,p=>m.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?u:void 0},m.createElement(Vh.Provider,{value:h},p))))}),bk=m.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=m.useRef(null),s=Fn(i=>!i.search);return!n&&!s?null:m.createElement(Se.div,{ref:An(o,t),...r,"cmdk-separator":"",role:"separator"})}),wk=m.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=Za(),i=Fn(u=>u.search),a=Fn(u=>u.selectedItemId),l=xo();return m.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),m.createElement(Se.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:u=>{o||s.setState("search",u.target.value),n==null||n(u.target.value)}})}),Sk=m.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=m.useRef(null),i=m.useRef(null),a=Fn(u=>u.selectedItemId),l=xo();return m.useEffect(()=>{if(i.current&&s.current){let u=i.current,d=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=u.offsetHeight;d.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(u),()=>{cancelAnimationFrame(f),h.unobserve(u)}}},[]),m.createElement(Se.div,{ref:An(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Ks(e,u=>m.createElement("div",{ref:An(i,l.listInnerRef),"cmdk-list-sizer":""},u)))}),Ck=m.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return m.createElement(Da,{open:n,onOpenChange:r},m.createElement(La,{container:i},m.createElement(ao,{"cmdk-overlay":"",className:o}),m.createElement(lo,{"aria-label":e.label,"cmdk-dialog":"",className:s},m.createElement(Kh,{ref:t,...a}))))}),kk=m.forwardRef((e,t)=>Fn(n=>n.filtered.count===0)?m.createElement(Se.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Tk=m.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return m.createElement(Se.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Ks(e,i=>m.createElement("div",{"aria-hidden":!0},i)))}),qt=Object.assign(Kh,{List:Sk,Item:yk,Input:wk,Group:vk,Separator:bk,Dialog:Ck,Empty:kk,Loading:Tk});function Ik(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Ek(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function qh(e){let t=m.useRef(e);return sr(()=>{t.current=e}),t}var sr=typeof window>"u"?m.useEffect:m.useLayoutEffect;function Nr(e){let t=m.useRef();return t.current===void 0&&(t.current=e()),t}function Fn(e){let t=Za(),n=()=>e(t.snapshot());return m.useSyncExternalStore(t.subscribe,n,n)}function Gh(e,t,n,r=[]){let o=m.useRef(),s=xo();return sr(()=>{var i;let a=(()=>{var u;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(u=d.current.textContent)==null?void 0:u.trim():o.current}})(),l=r.map(u=>u.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(Er,a),o.current=a}),o}var Nk=()=>{let[e,t]=m.useState(),n=Nr(()=>new Map);return sr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function Ak(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Ks({asChild:e,children:t},n){return e&&m.isValidElement(t)?m.cloneElement(Ak(t),{ref:t.ref},n(t.props.children)):n(t)}var jk={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Yh=m.forwardRef(({className:e,...t},n)=>c.jsx(qt,{ref:n,className:se("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));Yh.displayName=qt.displayName;const Xh=m.forwardRef(({className:e,...t},n)=>c.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[c.jsx(ae.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),c.jsx(qt.Input,{ref:n,className:se("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Xh.displayName=qt.Input.displayName;const Jh=m.forwardRef(({className:e,...t},n)=>c.jsx(qt.List,{ref:n,className:se("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));Jh.displayName=qt.List.displayName;const Zh=m.forwardRef((e,t)=>c.jsx(qt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));Zh.displayName=qt.Empty.displayName;const Qh=m.forwardRef(({className:e,...t},n)=>c.jsx(qt.Group,{ref:n,className:se("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));Qh.displayName=qt.Group.displayName;const _k=m.forwardRef(({className:e,...t},n)=>c.jsx(qt.Separator,{ref:n,className:se("-mx-1 h-px bg-border",e),...t}));_k.displayName=qt.Separator.displayName;const ep=m.forwardRef(({className:e,...t},n)=>c.jsx(qt.Item,{ref:n,className:se("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));ep.displayName=qt.Item.displayName;function Qa(e,[t,n]){return Math.min(n,Math.max(t,e))}function Mk(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var el="ScrollArea",[tp,_I]=kn(el),[Rk,nn]=tp(el),np=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,y]=m.useState(null),[g,v]=m.useState(null),[x,b]=m.useState(0),[k,T]=m.useState(0),[S,C]=m.useState(!1),[I,A]=m.useState(!1),R=We(t,B=>l(B)),D=Uo(o);return c.jsx(Rk,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:y,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:g,onScrollbarYChange:v,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:T,children:c.jsx(Se.div,{dir:D,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":k+"px",...e.style}})})});np.displayName=el;var rp="ScrollAreaViewport",op=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=nn(rp,n),a=m.useRef(null),l=We(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),c.jsx(Se.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});op.displayName=rp;var Sn="ScrollAreaScrollbar",tl=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(Pk,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(Ok,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(sp,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(nl,{...r,ref:t}):null});tl.displayName=Sn;var Pk=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Zt,{present:n||s,children:c.jsx(sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),Ok=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Xs(()=>l("SCROLL_END"),100),[a,l]=Mk("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Zt,{present:n||a!=="hidden",children:c.jsx(nl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),sp=m.forwardRef((e,t)=>{const n=nn(Sn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Xs(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Ar(n.viewport,l),Ar(n.content,l),c.jsx(Zt,{present:r||s,children:c.jsx(nl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),nl=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=nn(Sn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=up(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return zk(h,i.current,a,p)}return n==="horizontal"?c.jsx(Dk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=dp(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(Lk,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=dp(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),Dk=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=We(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ap,{"data-orientation":"horizontal",...o,ref:u,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),hp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Gs(i.paddingLeft),paddingEnd:Gs(i.paddingRight)}})}})}),Lk=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=We(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ap,{"data-orientation":"vertical",...o,ref:u,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),hp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Gs(i.paddingTop),paddingEnd:Gs(i.paddingBottom)}})}})}),[$k,ip]=tp(Sn),ap=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=nn(Sn,n),[y,g]=m.useState(null),v=We(t,R=>g(R)),x=m.useRef(null),b=m.useRef(""),k=p.viewport,T=r.content-r.viewport,S=jt(d),C=jt(l),I=Xs(f,10);function A(R){if(x.current){const D=R.clientX-x.current.left,B=R.clientY-x.current.top;u({x:D,y:B})}}return m.useEffect(()=>{const R=D=>{const B=D.target;(y==null?void 0:y.contains(B))&&S(D,T)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[k,y,T,S]),m.useEffect(C,[r,C]),Ar(y,I),Ar(p.content,I),c.jsx($k,{scope:n,scrollbar:y,hasThumb:o,onThumbChange:jt(s),onThumbPointerUp:jt(i),onThumbPositionChange:C,onThumbPointerDown:jt(a),children:c.jsx(Se.div,{...h,ref:v,style:{position:"absolute",...h.style},onPointerDown:fe(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),x.current=y.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:fe(e.onPointerMove,A),onPointerUp:fe(e.onPointerUp,R=>{const D=R.target;D.hasPointerCapture(R.pointerId)&&D.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),qs="ScrollAreaThumb",lp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ip(qs,e.__scopeScrollArea);return c.jsx(Zt,{present:n||o.hasThumb,children:c.jsx(Fk,{ref:t,...r})})}),Fk=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=nn(qs,n),i=ip(qs,n),{onThumbPositionChange:a}=i,l=We(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Xs(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=Uk(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Se.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 p=f.target.getBoundingClientRect(),y=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:y,y:g})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});lp.displayName=qs;var rl="ScrollAreaCorner",cp=m.forwardRef((e,t)=>{const n=nn(rl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(Bk,{...e,ref:t}):null});cp.displayName=rl;var Bk=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=nn(rl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Se.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 Gs(e){return e?parseInt(e,10):0}function up(e,t){const n=e/t;return isNaN(n)?0:n}function Ys(e){const t=up(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function zk(e,t,n,r="ltr"){const o=Ys(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return fp([l,u],f)(e)}function dp(e,t,n="ltr"){const r=Ys(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=Qa(e,l);return fp([0,i],[0,a])(u)}function fp(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 hp(e,t){return e>0&&e<t}var Uk=(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 Xs(e,t){const n=jt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ar(e,t){const n=jt(t);At(()=>{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 pp=np,Hk=op,Wk=cp;const mp=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(pp,{ref:r,className:se("relative overflow-hidden",e),...n,children:[c.jsx(Hk,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(gp,{}),c.jsx(Wk,{})]}));mp.displayName=pp.displayName;const gp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(tl,{ref:r,orientation:t,className:se("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:c.jsx(lp,{className:"relative flex-1 rounded-full bg-border"})}));gp.displayName=tl.displayName;const Js=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:se("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}));Js.displayName="Input";const Vk="group relative p-3 rounded-lg cursor-pointer transition-colors border text-gray-900 dark:text-slate-100",Kk="bg-slate-700 border-slate-600 hover:bg-slate-600",qk="bg-slate-600 border-slate-500";function Gk({thread:e,isActive:t,editingThreadId:n,editingTitle:r,onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:u,onDelete:d,showEditTitle:f,showDeleteButton:h,formatDate:p,getDisplayThreadTitle:y,secondaryLine:g,itemClassName:v,activeItemClassName:x}){const b=n===e.threadId,k=t?`${x??qk}`:`${v??Kk}`,T=S=>{S.stopPropagation(),o(e.threadId)};return c.jsxs("div",{onClick:T,className:`${Vk} ${k}`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:b?c.jsxs("div",{className:"flex items-center gap-2",onClick:S=>S.stopPropagation(),children:[c.jsx(Js,{value:r,onChange:S=>i(S.target.value),onKeyDown:S=>{S.key==="Enter"?a(e.threadId):S.key==="Escape"&&l()},className:"h-6 text-sm",autoFocus:!0}),c.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>a(e.threadId),className:"h-6 w-6 p-0",children:c.jsx(ae.Check,{size:12})}),c.jsx(tt,{variant:"ghost",size:"sm",onClick:l,className:"h-6 w-6 p-0",children:c.jsx(ae.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:y(e)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(ae.Calendar,{size:10}),c.jsx("span",{children:p(e.updatedAt||e.createdAt)})]}),g&&c.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:g})]})}),c.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:c.jsxs(aa,{children:[c.jsx(la,{asChild:!0,children:c.jsx(tt,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:c.jsx(ae.MoreHorizontal,{size:12})})}),c.jsxs(xs,{align:"end",sideOffset:6,className:"w-44",children:[c.jsxs(Jn,{onClick:S=>{S.preventDefault(),u(e.threadId)},children:[c.jsx(ae.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),f&&n!==e.threadId&&c.jsxs(Jn,{onClick:S=>{S.preventDefault(),s(e,S)},children:[c.jsx(ae.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),h&&d&&c.jsxs(Jn,{className:"text-red-400 hover:text-red-300",onClick:S=>{S.preventDefault(),d(e.threadId,S)},children:[c.jsx(ae.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),t&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]})}const xp=25,yp="thread-manager-view",Yk=e=>e==="default"||e==="shared",Xk=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(yp);if(Yk(e))return e}catch{}return null};function Jk({defaultView:e}={}){const[t,n]=w.useState(()=>Xk()??e??"default");w.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(yp,t)}catch{}},[t]);const r=w.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const Zk=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function ol({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d,view:f,defaultView:h,onViewChange:p,viewOptions:y,viewState:g,showHeader:v=!0}){const{threads:x,sharedThreads:b,currentThreadId:k,setCurrentThreadId:T,isLoading:S,isLoadingSharedThreads:C,smartOrgUsers:I,isLoadingSmartOrgUsers:A,actions:R,shareInFlight:D,shareStatus:B,clearShareStatus:X}=Fo(),{createThread:G,deleteThread:M,renameThread:U,shareThread:E}=R,{loadThread:P}=Bo(),L=i??k,[_,q]=w.useState(Array.isArray(x)?x:[]),Y=w.useRef(_.length>0),j=w.useRef(null),J=w.useRef(0),[V,H]=w.useState(null),[ee,W]=w.useState(""),[O,K]=w.useState(!1),[z,ne]=w.useState(!1),[Q,ge]=w.useState(null),[le,oe]=w.useState(""),pe=y&&y.length>0?y:Zk,be=Jk({defaultView:h}),Me=g??be,Ie=f??Me.view,De=w.useCallback(Z=>{f||Me.setView(Z),p==null||p(Z)},[f,p,Me]),et=pe.find(Z=>Z.key===Ie)??pe[0],rt=Z=>{ge(Z),oe(""),ne(!0)},He=()=>{ne(!1),ge(null),oe(""),X()},Je=w.useCallback(async Z=>{if(!Q||D)return;const $=Z.user_id??Z.id??Z.username??Z.email;if($)try{await E(Q,$),setTimeout(()=>He(),600)}catch(he){console.error("Failed to share thread:",he)}},[He,D,Q,E]),ot=w.useMemo(()=>{const Z=le.trim().toLowerCase();return Z?I.filter($=>`${$.username??""} ${$.user_id??""} ${$.email??""} ${$.name??""}`.toLowerCase().includes(Z)):I},[I,le]),St=Ie==="shared",dt=St?b:_,Tt=St?C:S,mt=St?"No shared conversations yet":"No conversations yet",Ee=Z=>{const $=Z.sharedAt?` • ${lt(Z.sharedAt)}`:"";return`Shared by ${Z.sharedByUserId}${$}`},Ke=Z=>"sharedByUserId"in Z;w.useEffect(()=>{const Z=Array.isArray(x)?x:[];if(Z.length>0){Y.current=!0,q(Z);return}S||(Y.current=!1,q(Z))},[x,S]),w.useEffect(()=>{if(!j.current)return;const Z=j.current.querySelector("[data-radix-scroll-area-viewport]");if(!Z)return;let $=null,he=null;return $=requestAnimationFrame(()=>{he=requestAnimationFrame(()=>{Z.scrollTop=J.current})}),()=>{$!==null&&cancelAnimationFrame($),he!==null&&cancelAnimationFrame(he)}},[_]);const xt=async Z=>{try{T(Z),await P(Z,void 0,{clearProgress:!0}),a==null||a(Z),l==null||l(Z)}catch($){console.error("Failed to select thread:",$)}},It=async()=>{try{K(!0);const Z=await G();Z&&(u==null||u(Z),a==null||a(Z))}catch(Z){console.error("Failed to create thread:",Z)}finally{K(!1)}},Le=async(Z,$)=>{if($.stopPropagation(),!!confirm("Delete this thread?")){if(j.current){const he=j.current.querySelector("[data-radix-scroll-area-viewport]");he&&(J.current=he.scrollTop)}try{await M(Z),d==null||d(Z)}catch(he){console.error("Failed to delete thread:",he)}}},_t=(Z,$)=>{$.stopPropagation(),H(Z.threadId),W(Z.title||`Thread ${Z.threadId.slice(0,8)}`)},Ge=async Z=>{if(ee.trim())try{await U(Z,ee.trim()),H(null),W("")}catch($){console.error("Failed to update title:",$)}},Be=()=>{H(null),W("")},lt=Z=>{if(!Z)return"";try{const $=new Date(Z),we=new Date().getTime()-$.getTime(),$e=Math.floor(we/(1e3*60*60*24));return $e===0?$.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$e===1?"Yesterday":$e<7?`${$e} days ago`:$.toLocaleDateString()}catch{return""}},Et=Z=>Z.title||`Thread ${Z.threadId.slice(0,8)}`,qe=Z=>{const $=Et(Z);return $.length<=xp?$:`${$.slice(0,xp)}...`};return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[v&&c.jsxs("div",{className:s.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&c.jsx("div",{className:"flex justify-end",children:c.jsxs(tt,{onClick:It,disabled:O||S,className:s.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:O?"Creating...":"New Chat",children:[c.jsx(ae.Edit3,{size:16}),c.jsx("span",{children:"New chat"})]})}),c.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[c.jsx("span",{children:"Current View"}),c.jsxs(aa,{children:[c.jsx(la,{asChild:!0,children:c.jsx(tt,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:et.label})}),c.jsx(xs,{align:"start",sideOffset:6,className:"w-40",children:pe.map(Z=>c.jsxs(Jn,{className:"justify-between text-[12px]",onClick:$=>{$.preventDefault(),De(Z.key)},children:[c.jsx("span",{children:Z.label}),Ie===Z.key&&c.jsx(ae.Check,{className:"h-3 w-3"})]},Z.key))})]})]})]}),c.jsx(mp,{ref:j,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:Tt?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(ae.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):dt.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(ae.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:mt})]}):dt.slice().sort((Z,$)=>new Date($.updatedAt||$.createdAt||"").getTime()-new Date(Z.updatedAt||Z.createdAt||"").getTime()).map(Z=>c.jsx(Gk,{thread:Z,isActive:L===Z.threadId,editingThreadId:V,editingTitle:ee,onSelect:xt,onStartEditing:_t,onEditingTitleChange:$=>W($),onSaveEditing:Ge,onCancelEditing:Be,onShare:()=>rt(Z.threadId),onDelete:Le,showEditTitle:r,showDeleteButton:n,formatDate:lt,getDisplayThreadTitle:qe,secondaryLine:St&&Ke(Z)?Ee(Z):void 0,itemClassName:s.threadItem,activeItemClassName:s.activeThread},Z.threadId))})}),c.jsx(mh,{open:z,onOpenChange:Z=>!Z&&He(),children:c.jsxs($a,{className:"max-w-md p-0",children:[c.jsx(Fa,{children:c.jsx(Ba,{children:"Share thread"})}),c.jsxs(Yh,{children:[c.jsx(Xh,{autoFocus:!0,value:le,onValueChange:Z=>oe(Z),placeholder:"Search for users (name, email, id)..."}),c.jsxs(Jh,{children:[B&&c.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[D&&c.jsx(ae.Loader2,{className:"h-3 w-3 animate-spin"}),c.jsx("span",{className:B.startsWith("Failed")?"text-red-500":B.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:B})]}),c.jsx(Zh,{children:A?c.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading users…"]}):"No matching users found"}),c.jsx(Qh,{heading:"Users",children:ot.map(Z=>{const $=Z.username??Z.user_id??Z.email??"Unknown user",he=[Z.email,Z.user_id].filter(Boolean).join(" • "),we=Z.user_id??Z.id??Z.username??Z.email??$;return c.jsx(ep,{onSelect:()=>Je(Z),children:c.jsxs("div",{className:"flex flex-col items-start text-sm",children:[c.jsx("span",{className:"font-medium",children:$}),he&&c.jsx("span",{className:"text-xs text-muted-foreground",children:he})]})},we)})})]})]})]})})]})}const Qk=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,u=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const h=["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 c.jsxs("div",{className:h,onMouseEnter:s,onMouseLeave:i,children:[c.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[c.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:c.jsx("span",{children:"Timeline"})}),c.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),c.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:u.map(p=>{const y=d===p.id,g=(r==null?void 0:r.get(p.id))??null;return c.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(p.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${y?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[c.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${y?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:c.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${y?"bg-primary":"bg-border"}`})}),c.jsxs("span",{className:"flex-1",children:[c.jsx("span",{className:"block font-medium leading-tight",children:p.label||"User input"}),c.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[p.step!==null?`STEP ${p.step}`:"STEP —",p.next?` - ${p.next}`:""]}),g&&c.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},p.id)})})]}),n&&c.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 jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function eT(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function vp(){const e=[jr("__API_BASE_URL__"),jr("__CHAT_API_BASE_URL__"),jr("__CHAT_API_URL__")];for(const t of e){const n=eT(t);if(n)return n}}function bp(){const e=[jr("__API_AUTH_TOKEN__"),jr("__CHAT_API_KEY__"),jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function wp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Sp(){const e={},t=vp(),n=bp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Cp(){const e=Sp(),t=Nn.getAuthToken(),n=vp();return{apiBaseUrl:wp(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||bp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const kp="chat-settings";function tT(){try{const e=localStorage.getItem(kp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function nT(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem(kp,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function rT(){const e=Cp(),t=tT(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:wp(Nn.baseUrl,r,e.apiBaseUrl)}}function oT(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),nT(e)}var sT="Label",Tp=m.forwardRef((e,t)=>c.jsx(Se.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())}}));Tp.displayName=sT;var Ip=Tp;const iT=bo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),rn=m.forwardRef(({className:e,...t},n)=>c.jsx(Ip,{ref:n,className:se(iT(),e),...t}));rn.displayName=Ip.displayName;function Ep(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Np=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"}),aT="VisuallyHidden",lT=m.forwardRef((e,t)=>c.jsx(Se.span,{...e,ref:t,style:{...Np,...e.style}}));lT.displayName=aT;var cT=[" ","Enter","ArrowUp","ArrowDown"],uT=[" ","Enter"],ir="Select",[Zs,Qs,dT]=Ii(ir),[_r,MI]=kn(ir,[dT,ts]),ei=ts(),[fT,Bn]=_r(ir),[hT,pT]=_r(ir),Ap=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:y}=e,g=ei(t),[v,x]=m.useState(null),[b,k]=m.useState(null),[T,S]=m.useState(!1),C=Uo(u),[I,A]=mr({prop:r,defaultProp:o??!1,onChange:s,caller:ir}),[R,D]=mr({prop:i,defaultProp:a,onChange:l,caller:ir}),B=m.useRef(null),X=v?y||!!v.closest("form"):!0,[G,M]=m.useState(new Set),U=Array.from(G).map(E=>E.props.value).join(";");return c.jsx(ju,{...g,children:c.jsxs(fT,{required:p,scope:t,trigger:v,onTriggerChange:x,valueNode:b,onValueNodeChange:k,valueNodeHasChildren:T,onValueNodeHasChildrenChange:S,contentId:Ft(),value:R,onValueChange:D,open:I,onOpenChange:A,dir:C,triggerPointerDownPosRef:B,disabled:h,children:[c.jsx(Zs.Provider,{scope:t,children:c.jsx(hT,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(E=>{M(P=>new Set(P).add(E))},[]),onNativeOptionRemove:m.useCallback(E=>{M(P=>{const L=new Set(P);return L.delete(E),L})},[]),children:n})}),X?c.jsxs(Qp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:E=>D(E.target.value),disabled:h,form:y,children:[R===void 0?c.jsx("option",{value:""}):null,Array.from(G)]},U):null]})})};Ap.displayName=ir;var jp="SelectTrigger",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ei(n),i=Bn(jp,n),a=i.disabled||r,l=We(t,i.onTriggerChange),u=Qs(n),d=m.useRef("touch"),[f,h,p]=tm(g=>{const v=u().filter(k=>!k.disabled),x=v.find(k=>k.value===i.value),b=nm(v,g,x);b!==void 0&&i.onValueChange(b.value)}),y=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return c.jsx(_u,{asChild:!0,...s,children:c.jsx(Se.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":em(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&y(g)}),onPointerDown:fe(o.onPointerDown,g=>{d.current=g.pointerType;const v=g.target;v.hasPointerCapture(g.pointerId)&&v.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(y(g),g.preventDefault())}),onKeyDown:fe(o.onKeyDown,g=>{const v=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(v&&g.key===" ")&&cT.includes(g.key)&&(y(),g.preventDefault())})})})});_p.displayName=jp;var Mp="SelectValue",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Mp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=We(t,l.onValueNodeChange);return At(()=>{u(d)},[u,d]),c.jsx(Se.span,{...a,ref:f,style:{pointerEvents:"none"},children:em(l.value)?c.jsx(c.Fragment,{children:i}):s})});Rp.displayName=Mp;var mT="SelectIcon",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Se.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Pp.displayName=mT;var gT="SelectPortal",Op=e=>c.jsx(ns,{asChild:!0,...e});Op.displayName=gT;var ar="SelectContent",Dp=m.forwardRef((e,t)=>{const n=Bn(ar,e.__scopeSelect),[r,o]=m.useState();if(At(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?wo.createPortal(c.jsx(Lp,{scope:e.__scopeSelect,children:c.jsx(Zs.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx($p,{...e,ref:t})});Dp.displayName=ar;var fn=10,[Lp,zn]=_r(ar),xT="SelectContentImpl",yT=Wn.createSlot("SelectContent.RemoveScroll"),$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:y,hideWhenDetached:g,avoidCollisions:v,...x}=e,b=Bn(ar,n),[k,T]=m.useState(null),[S,C]=m.useState(null),I=We(t,W=>T(W)),[A,R]=m.useState(null),[D,B]=m.useState(null),X=Qs(n),[G,M]=m.useState(!1),U=m.useRef(!1);m.useEffect(()=>{if(k)return Gi(k)},[k]),Ai();const E=m.useCallback(W=>{const[O,...K]=X().map(Q=>Q.ref.current),[z]=K.slice(-1),ne=document.activeElement;for(const Q of W)if(Q===ne||(Q==null||Q.scrollIntoView({block:"nearest"}),Q===O&&S&&(S.scrollTop=0),Q===z&&S&&(S.scrollTop=S.scrollHeight),Q==null||Q.focus(),document.activeElement!==ne))return},[X,S]),P=m.useCallback(()=>E([A,k]),[E,A,k]);m.useEffect(()=>{G&&P()},[G,P]);const{onOpenChange:L,triggerPointerDownPosRef:_}=b;m.useEffect(()=>{if(k){let W={x:0,y:0};const O=z=>{var ne,Q;W={x:Math.abs(Math.round(z.pageX)-(((ne=_.current)==null?void 0:ne.x)??0)),y:Math.abs(Math.round(z.pageY)-(((Q=_.current)==null?void 0:Q.y)??0))}},K=z=>{W.x<=10&&W.y<=10?z.preventDefault():k.contains(z.target)||L(!1),document.removeEventListener("pointermove",O),_.current=null};return _.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",K,{capture:!0})}}},[k,L,_]),m.useEffect(()=>{const W=()=>L(!1);return window.addEventListener("blur",W),window.addEventListener("resize",W),()=>{window.removeEventListener("blur",W),window.removeEventListener("resize",W)}},[L]);const[q,Y]=tm(W=>{const O=X().filter(ne=>!ne.disabled),K=O.find(ne=>ne.ref.current===document.activeElement),z=nm(O,W,K);z&&setTimeout(()=>z.ref.current.focus())}),j=m.useCallback((W,O,K)=>{const z=!U.current&&!K;(b.value!==void 0&&b.value===O||z)&&(R(W),z&&(U.current=!0))},[b.value]),J=m.useCallback(()=>k==null?void 0:k.focus(),[k]),V=m.useCallback((W,O,K)=>{const z=!U.current&&!K;(b.value!==void 0&&b.value===O||z)&&B(W)},[b.value]),H=r==="popper"?sl:Fp,ee=H===sl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:y,hideWhenDetached:g,avoidCollisions:v}:{};return c.jsx(Lp,{scope:n,content:k,viewport:S,onViewportChange:C,itemRefCallback:j,selectedItem:A,onItemLeave:J,itemTextRefCallback:V,focusSelectedItem:P,selectedItemText:D,position:r,isPositioned:G,searchRef:q,children:c.jsx(ds,{as:yT,allowPinchZoom:!0,children:c.jsx(Wo,{asChild:!0,trapped:b.open,onMountAutoFocus:W=>{W.preventDefault()},onUnmountAutoFocus:fe(o,W=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),W.preventDefault()}),children:c.jsx(Ho,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:W=>W.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(H,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:W=>W.preventDefault(),...x,...ee,onPlaced:()=>M(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:fe(x.onKeyDown,W=>{const O=W.ctrlKey||W.altKey||W.metaKey;if(W.key==="Tab"&&W.preventDefault(),!O&&W.key.length===1&&Y(W.key),["ArrowUp","ArrowDown","Home","End"].includes(W.key)){let z=X().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);if(["ArrowUp","End"].includes(W.key)&&(z=z.slice().reverse()),["ArrowUp","ArrowDown"].includes(W.key)){const ne=W.target,Q=z.indexOf(ne);z=z.slice(Q+1)}setTimeout(()=>E(z)),W.preventDefault()}})})})})})})});$p.displayName=xT;var vT="SelectItemAlignedPosition",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ar,n),i=zn(ar,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=We(t,I=>d(I)),h=Qs(n),p=m.useRef(!1),y=m.useRef(!0),{viewport:g,selectedItem:v,selectedItemText:x,focusSelectedItem:b}=i,k=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&g&&v&&x){const I=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const ne=D.left-A.left,Q=R.left-ne,ge=I.left-Q,le=I.width+ge,oe=Math.max(le,A.width),pe=window.innerWidth-fn,be=Qa(Q,[fn,Math.max(fn,pe-oe)]);a.style.minWidth=le+"px",a.style.left=be+"px"}else{const ne=A.right-D.right,Q=window.innerWidth-R.right-ne,ge=window.innerWidth-I.right-Q,le=I.width+ge,oe=Math.max(le,A.width),pe=window.innerWidth-fn,be=Qa(Q,[fn,Math.max(fn,pe-oe)]);a.style.minWidth=le+"px",a.style.right=be+"px"}const B=h(),X=window.innerHeight-fn*2,G=g.scrollHeight,M=window.getComputedStyle(u),U=parseInt(M.borderTopWidth,10),E=parseInt(M.paddingTop,10),P=parseInt(M.borderBottomWidth,10),L=parseInt(M.paddingBottom,10),_=U+E+G+L+P,q=Math.min(v.offsetHeight*5,_),Y=window.getComputedStyle(g),j=parseInt(Y.paddingTop,10),J=parseInt(Y.paddingBottom,10),V=I.top+I.height/2-fn,H=X-V,ee=v.offsetHeight/2,W=v.offsetTop+ee,O=U+E+W,K=_-O;if(O<=V){const ne=B.length>0&&v===B[B.length-1].ref.current;a.style.bottom="0px";const Q=u.clientHeight-g.offsetTop-g.offsetHeight,ge=Math.max(H,ee+(ne?J:0)+Q+P),le=O+ge;a.style.height=le+"px"}else{const ne=B.length>0&&v===B[0].ref.current;a.style.top="0px";const ge=Math.max(V,U+g.offsetTop+(ne?j:0)+ee)+K;a.style.height=ge+"px",g.scrollTop=O-V+g.offsetTop}a.style.margin=`${fn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=X+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,g,v,x,s.dir,r]);At(()=>k(),[k]);const[T,S]=m.useState();At(()=>{u&&S(window.getComputedStyle(u).zIndex)},[u]);const C=m.useCallback(I=>{I&&y.current===!0&&(k(),b==null||b(),y.current=!1)},[k,b]);return c.jsx(wT,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:c.jsx(Se.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fp.displayName=vT;var bT="SelectPopperPosition",sl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=fn,...s}=e,i=ei(n);return c.jsx(Mu,{...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)"}})});sl.displayName=bT;var[wT,il]=_r(ar,{}),al="SelectViewport",Bp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn(al,n),i=il(al,n),a=We(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(Zs.Slot,{scope:n,children:c.jsx(Se.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const y=window.innerHeight-fn*2,g=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),x=Math.max(g,v);if(x<y){const b=x+p,k=Math.min(y,b),T=b-k;f.style.height=k+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Bp.displayName=al;var zp="SelectGroup",[ST,CT]=_r(zp),kT=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ft();return c.jsx(ST,{scope:n,id:o,children:c.jsx(Se.div,{role:"group","aria-labelledby":o,...r,ref:t})})});kT.displayName=zp;var Up="SelectLabel",Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=CT(Up,n);return c.jsx(Se.div,{id:o.id,...r,ref:t})});Hp.displayName=Up;var ti="SelectItem",[TT,Wp]=_r(ti),Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(ti,n),l=zn(ti,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),y=We(t,b=>{var k;return(k=l.itemRefCallback)==null?void 0:k.call(l,b,r,o)}),g=Ft(),v=m.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(TT,{scope:n,value:r,disabled:o,textId:g,isSelected:u,onItemTextChange:m.useCallback(b=>{f(k=>k||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Se.div,{role:"option","aria-labelledby":g,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:y,onFocus:fe(i.onFocus,()=>p(!0)),onBlur:fe(i.onBlur,()=>p(!1)),onClick:fe(i.onClick,()=>{v.current!=="mouse"&&x()}),onPointerUp:fe(i.onPointerUp,()=>{v.current==="mouse"&&x()}),onPointerDown:fe(i.onPointerDown,b=>{v.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var k;v.current=b.pointerType,o?(k=l.onItemLeave)==null||k.call(l):v.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var k;b.currentTarget===document.activeElement&&((k=l.onItemLeave)==null||k.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&b.key===" "||(uT.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Vp.displayName=ti;var yo="SelectItemText",Kp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(yo,n),a=zn(yo,n),l=Wp(yo,n),u=pT(yo,n),[d,f]=m.useState(null),h=We(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,y=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:v}=u;return At(()=>(g(y),()=>v(y)),[g,v,y]),c.jsxs(c.Fragment,{children:[c.jsx(Se.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?wo.createPortal(s.children,i.valueNode):null]})});Kp.displayName=yo;var qp="SelectItemIndicator",Gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Wp(qp,n).isSelected?c.jsx(Se.span,{"aria-hidden":!0,...r,ref:t}):null});Gp.displayName=qp;var ll="SelectScrollUpButton",Yp=m.forwardRef((e,t)=>{const n=zn(ll,e.__scopeSelect),r=il(ll,e.__scopeSelect),[o,s]=m.useState(!1),i=We(t,r.onScrollButtonChange);return At(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Jp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Yp.displayName=ll;var cl="SelectScrollDownButton",Xp=m.forwardRef((e,t)=>{const n=zn(cl,e.__scopeSelect),r=il(cl,e.__scopeSelect),[o,s]=m.useState(!1),i=We(t,r.onScrollButtonChange);return At(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Jp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Xp.displayName=cl;var Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=m.useRef(null),a=Qs(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),At(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(Se.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 u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),IT="SelectSeparator",Zp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Se.div,{"aria-hidden":!0,...r,ref:t})});Zp.displayName=IT;var ul="SelectArrow",ET=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ei(n),s=Bn(ul,n),i=zn(ul,n);return s.open&&i.position==="popper"?c.jsx(Ru,{...o,...r,ref:t}):null});ET.displayName=ul;var NT="SelectBubbleInput",Qp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=We(r,o),i=Ep(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Se.select,{...n,style:{...Np,...n.style},ref:s,defaultValue:t})});Qp.displayName=NT;function em(e){return e===""||e===void 0}function tm(e){const t=jt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function nm(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=AT(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function AT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var jT=Ap,rm=_p,_T=Rp,MT=Pp,RT=Op,om=Dp,PT=Bp,sm=Hp,im=Vp,OT=Kp,DT=Gp,am=Yp,lm=Xp,cm=Zp;const um=jT,dm=_T,dl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(rm,{ref:r,className:se("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(MT,{asChild:!0,children:c.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));dl.displayName=rm.displayName;const fm=m.forwardRef(({className:e,...t},n)=>c.jsx(am,{ref:n,className:se("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const hm=m.forwardRef(({className:e,...t},n)=>c.jsx(lm,{ref:n,className:se("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));hm.displayName=lm.displayName;const fl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(RT,{children:c.jsxs(om,{ref:o,className:se("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(fm,{}),c.jsx(PT,{className:se("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(hm,{})]})}));fl.displayName=om.displayName;const LT=m.forwardRef(({className:e,...t},n)=>c.jsx(sm,{ref:n,className:se("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));LT.displayName=sm.displayName;const lr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(im,{ref:r,className:se("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(DT,{children:c.jsx(ae.Check,{className:"h-4 w-4"})})}),c.jsx(OT,{children:t})]}));lr.displayName=im.displayName;const $T=m.forwardRef(({className:e,...t},n)=>c.jsx(cm,{ref:n,className:se("-mx-1 my-1 h-px bg-muted",e),...t}));$T.displayName=cm.displayName;var FT="Separator",pm="horizontal",BT=["horizontal","vertical"],mm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=pm,...o}=e,s=zT(r)?r:pm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Se.div,{"data-orientation":s,...a,...o,ref:t})});mm.displayName=FT;function zT(e){return BT.includes(e)}var gm=mm;const xm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(gm,{ref:o,decorative:n,orientation:t,className:se("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));xm.displayName=gm.displayName;const UT=Da,HT=vC,WT=La,ym=m.forwardRef(({className:e,...t},n)=>c.jsx(ao,{className:se("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}));ym.displayName=ao.displayName;const VT=bo.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"}}),vm=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(WT,{children:[c.jsx(ym,{}),c.jsxs(lo,{ref:o,className:se(VT({side:e}),t),...r,children:[n,c.jsxs(ph,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(ae.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));vm.displayName=lo.displayName;const bm=({className:e,...t})=>c.jsx("div",{className:se("flex flex-col space-y-2 text-center sm:text-left",e),...t});bm.displayName="SheetHeader";const wm=m.forwardRef(({className:e,...t},n)=>c.jsx(rr,{ref:n,className:se("text-lg font-semibold text-foreground",e),...t}));wm.displayName=rr.displayName;const Sm=m.forwardRef(({className:e,...t},n)=>c.jsx(Ls,{ref:n,className:se("text-sm text-muted-foreground",e),...t}));Sm.displayName=Ls.displayName;var ni="Switch",[KT,RI]=kn(ni),[qT,GT]=KT(ni),Cm=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),y=We(t,k=>p(k)),g=m.useRef(!1),v=h?d||!!h.closest("form"):!0,[x,b]=mr({prop:o,defaultProp:s??!1,onChange:u,caller:ni});return c.jsxs(qT,{scope:n,checked:x,disabled:a,children:[c.jsx(Se.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Em(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:y,onClick:fe(e.onClick,k=>{b(T=>!T),v&&(g.current=k.isPropagationStopped(),g.current||k.stopPropagation())})}),v&&c.jsx(Im,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Cm.displayName=ni;var km="SwitchThumb",Tm=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=GT(km,n);return c.jsx(Se.span,{"data-state":Em(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Tm.displayName=km;var YT="SwitchBubbleInput",Im=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=We(i,s),l=Ep(n),u=bu(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const y=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(y)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Im.displayName=YT;function Em(e){return e?"checked":"unchecked"}var Nm=Cm,XT=Tm;const Un=m.forwardRef(({className:e,...t},n)=>c.jsx(Nm,{className:se("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(XT,{className:se("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=Nm.displayName;const JT={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 ZT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[u,d]=w.useState(!1),{toast:f}=Ha();w.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);d(v)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(JT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},y=()=>{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 c.jsxs(UT,{open:r,onOpenChange:o,children:[c.jsx(HT,{asChild:!0,children:c.jsxs(tt,{variant:"outline",size:"sm",className:n,children:[c.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Kf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(vm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(bm,{children:[c.jsx(wm,{children:"Chat Settings"}),c.jsx(Sm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(fo,{children:[c.jsx(ho,{className:"pb-3",children:c.jsxs(po,{className:"text-lg flex items-center gap-2",children:[c.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(mo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Js,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(x=>({...x,api:{...x.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(tt,{variant:"outline",onClick:g,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(x=>({...x,api:{...x.api,enableAuth:v}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Js,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(x=>({...x,api:{...x.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(tt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(ae.EyeOff,{className:"h-4 w-4"}):c.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(fo,{children:[c.jsx(ho,{className:"pb-3",children:c.jsxs(po,{className:"text-lg flex items-center gap-2",children:[c.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(mo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(um,{value:a.ui.layout,onValueChange:v=>l(x=>({...x,ui:{...x.ui,layout:v}})),children:[c.jsx(dl,{children:c.jsx(dm,{})}),c.jsxs(fl,{children:[c.jsx(lr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(lr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(lr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"theme",children:"Theme"}),c.jsxs(um,{value:a.ui.theme,onValueChange:v=>l(x=>({...x,ui:{...x.ui,theme:v}})),children:[c.jsx(dl,{children:c.jsx(dm,{})}),c.jsxs(fl,{children:[c.jsx(lr,{value:"light",children:"Light"}),c.jsx(lr,{value:"dark",children:"Dark"}),c.jsx(lr,{value:"system",children:"System"})]})]})]}),c.jsx(xm,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showTimestamps:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showAgentNames:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,compactMessages:v}}))})]})]})]})]}),c.jsxs(fo,{children:[c.jsx(ho,{className:"pb-3",children:c.jsxs(po,{className:"text-lg flex items-center gap-2",children:[c.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(mo,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(rn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,autoSave:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(rn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(rn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:v}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(tt,{variant:"outline",onClick:p,children:[c.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(tt,{variant:"outline",onClick:y,children:"Cancel"}),c.jsxs(tt,{onClick:h,disabled:!u,children:[c.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function QT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=w.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(zo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Vs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(zo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ol,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Vs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(zo,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ol,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Vs,{onError:s.onError,enableFileUpload:!0})})]})})}ke.ChatApi=cc,ke.ChatInput=$c,ke.ChatInterface=Vs,ke.ChatProviders=zo,ke.ChatSettings=ZT,ke.MarkdownContent=uo,ke.MessageComponent=Ws,ke.MessageList=Ka,ke.ThreadManager=ol,ke.TimelineColumn=Qk,ke.applySettings=oT,ke.buildMessagePreviewMap=cx,ke.chatApiClient=Nn,ke.default=QT,ke.del=bi,ke.get=Vt,ke.getChatToken=ic,ke.getCurrentSettings=rT,ke.getDefaultApiConfig=Sp,ke.getDefaultChatSettings=Cp,ke.onChatTokenChanged=ac,ke.post=Po,ke.put=lc,ke.setChatToken=Ro,ke.useApi=wi,ke.useChatStream=_c,ke.useMessagesReducer=Ac,ke.useStream=Dc,ke.useThreadState=Bo,ke.useThreads=Fo,Object.defineProperties(ke,{__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=Ch(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=Ch(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 Nh{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 Ah{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||or,this.options.renderer=this.options.renderer||new Va,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Nh,this.slugger=new Ah}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,u,d,f,h,p,y,g,v,x,b,C,k,S,T;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(T=this.options.extensions.renderers[p.type].call({parser:this},p),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=T||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Sh(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(u=p.rows[s],d="",l=u.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(y=p.ordered,g=p.start,v=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],C=b.checked,k=b.task,x="",b.task&&(S=this.renderer.checkbox(C),v?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=S+" "+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=S+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:S}):x+=S),x+=this.parse(b.tokens,v),h+=this.renderer.listitem(x,k,C);r+=this.renderer.list(h,y,g);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
135
+ `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Hs{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}Am(Hs,"passThroughHooks",new Set(["preprocess","postprocess"]));function HC(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>"+Ot(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 jh(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ve.defaults,...s};const i=HC(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(BC(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&ve.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;ve.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ve.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&&ve.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ve(e,t,n){return jh(Ln.lex,$n.parse)(e,t,n)}ve.options=ve.setOptions=function(e){return ve.defaults={...ve.defaults,...e},IC(ve.defaults),ve},ve.getDefaults=yh,ve.defaults=or,ve.use=function(...e){const t=ve.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ve.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=ve.defaults.renderer||new Va;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=ve.defaults.tokenizer||new Wa;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=ve.defaults.hooks||new Hs;for(const s in n.hooks){const i=o[s];Hs.passThroughHooks.has(s)?o[s]=a=>{if(ve.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=ve.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}}ve.setOptions(r)})},ve.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ve,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ve.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ve.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ve.walkTokens(r.items,t));break}default:ve.defaults.extensions&&ve.defaults.extensions.childTokens&&ve.defaults.extensions.childTokens[r.type]?ve.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ve.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ve.walkTokens(r.tokens,t)))}return n},ve.parseInline=jh(Ln.lexInline,$n.parseInline),ve.Parser=$n,ve.parser=$n.parse,ve.Renderer=Va,ve.TextRenderer=Nh,ve.Lexer=Ln,ve.lexer=Ln.lex,ve.Tokenizer=Wa,ve.Slugger=Ah,ve.Hooks=Hs,ve.parse=ve,ve.options,ve.setOptions,ve.use,ve.walkTokens,ve.parseInline,$n.parse,Ln.lex;function co({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 ve.parse=="function"?ve.parse(i):ve(i)}return typeof ve.parse=="function"?ve.parse(e):ve(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 c.jsx("div",{className:ne("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 WC={MODE:"library"};function VC(){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:ii&&ii.tagName.toUpperCase()==="SCRIPT"&&ii.src||new URL("index.umd.js",document.baseURI).href}<"u"?WC: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 KC(){return!VC()}function qC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function GC(){return KC()||qC()}function YC({preview:e,idx:t}){return w.useEffect(()=>{GC()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),c.jsxs("div",{className:"space-y-2",children:[e.label&&c.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),c.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:c.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})}})})]})}function XC({artifact:e}){const[t,n]=w.useState("bg-yellow-500/20 text-yellow-700 dark:text-yellow-300"),[r,o]=w.useState(c.jsx(ae.Clock,{className:"w-4 h-4"})),[s,i]=w.useState("Processing");return w.useEffect(()=>{switch(e.status||"processing"){case"completed":n("bg-green-500/20 text-green-700 dark:text-green-300"),o(c.jsx(ae.CheckCircle,{className:"w-4 h-4"})),i("Completed");break;case"failed":n("bg-red-500/20 text-red-700 dark:text-red-300"),o(c.jsx(ae.ExternalLink,{className:"w-4 h-4 rotate-45"})),i("Failed");break;case"pending":n("bg-blue-500/20 text-blue-700 dark:text-blue-300"),o(c.jsx(ae.Clock,{className:"w-4 h-4"})),i("Pending");break;default:n("bg-yellow-500/20 text-yellow-700 dark:text-yellow-300"),o(c.jsx(ae.Clock,{className:"w-4 h-4"})),i("Processing")}},[e.status]),c.jsxs("div",{className:"rounded-lg border border-blue-200 dark:border-blue-900/50 bg-blue-50 dark:bg-blue-950/20 p-4 space-y-3",children:[c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"mt-1 flex-shrink-0",children:c.jsx(ae.Search,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100",children:"Research Task"}),c.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300 mt-1",children:["Task ID: ",c.jsxs("code",{className:"font-mono text-xs bg-blue-100 dark:bg-blue-900/30 px-2 py-1 rounded",children:[e.task_id.slice(0,8),"..."]})]})]})]}),c.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-sm font-medium ${t}`,children:[r,c.jsx("span",{children:s})]}),e.query&&c.jsxs("div",{className:"text-sm text-blue-800 dark:text-blue-200 bg-white dark:bg-blue-900/30 rounded px-3 py-2",children:[c.jsx("p",{className:"font-medium text-xs text-blue-600 dark:text-blue-400 mb-1",children:"Query:"}),c.jsx("p",{className:"line-clamp-2",children:e.query})]}),e.progress_url&&c.jsx("div",{className:"pt-2",children:c.jsxs("a",{href:e.progress_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white dark:bg-blue-700 dark:hover:bg-blue-600 rounded-md text-sm font-medium transition-colors",children:[c.jsx("span",{children:"Monitor Progress"}),c.jsx(ae.ExternalLink,{className:"w-3.5 h-3.5"})]})}),e.createdAt&&c.jsxs("p",{className:"text-xs text-blue-600 dark:text-blue-400",children:["Started: ",new Date(e.createdAt).toLocaleTimeString()]})]})}function JC({artifact:e,idx:t=0}){if((e==null?void 0:e.type)==="research_task_info")return c.jsx(XC,{artifact:{type:"research_task_info",task_id:e.task_id,progress_url:e.progress_url,query:e.query,status:e.status,createdAt:e.createdAt}});const n=w.useMemo(()=>e?(Array.isArray(e.plots)?e.plots:[]).map(o=>iC(o)).filter(o=>o!==null):[],[e]);return n.length>0?c.jsx("div",{className:"space-y-2",children:n.map((r,o)=>c.jsx(YC,{preview:r,idx:o},`${t}-plot-${o}`))}):e&&typeof e=="object"?c.jsx("div",{className:"rounded-lg border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/20 p-4",children:c.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Unknown artifact type: ",c.jsx("code",{className:"font-mono",children:e.type||"unknown"})]})}):null}const uo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ne("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));uo.displayName="Card";const fo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ne("flex flex-col space-y-1.5 p-6",e),...t}));fo.displayName="CardHeader";const ho=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:ne("text-2xl font-semibold leading-none tracking-tight",e),...t}));ho.displayName="CardTitle";const _h=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));_h.displayName="CardDescription";const po=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ne("p-6 pt-0",e),...t}));po.displayName="CardContent";const Mh=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ne("flex items-center p-6 pt-0",e),...t}));Mh.displayName="CardFooter";function ZC({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=c.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const u=so(s);a=c.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:u})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return c.jsxs(uo,{className:ne("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:[c.jsxs(fo,{className:"pb-3",children:[c.jsx(ho,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),c.jsx(_h,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&c.jsx(po,{className:"pt-0 pb-3",children:a}),c.jsx(Mh,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(et,{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"}),c.jsx(et,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const QC="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 Rh({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:QC,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:so(e)}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:so(e)})}function eT({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=w.useMemo(()=>{const a=e.additionalKwargs??{};return Array.isArray(a.toolProgress)?[...a.toolProgress]:[]},[e]),s=r.some(a=>a.type==="tool.start"||a.type==="tool.call"||a.type==="message.start")?`Running ${n}…`:void 0;return t||r.length>0?c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[t&&c.jsx(ae.Loader,{className:"h-3 w-3 animate-spin"}),c.jsx("span",{children:s??`Running ${n}…`})]}),r.length>0&&c.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:r.map((a,l)=>{var u;return c.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[c.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[c.jsx("span",{children:((u=a.type)==null?void 0:u.replace(/\./g," "))??"progress"}),c.jsx("span",{children:a.idx??l+1})]}),a.content&&c.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:a.content}),c.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof a.factsFound=="number"&&c.jsxs("span",{children:["Facts found: ",a.factsFound]}),typeof a.isSufficient=="boolean"&&c.jsxs("span",{children:["Research ",a.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${n}-${l}`)})})]}):null}function tT({message:e,viewMode:t,isStreaming:n=!1}){const o=Gf(e).name||"tool",s=l=>{if(l==null)return null;const u=typeof l=="string"?Ma(l)??l:l;if(u&&typeof u=="object")return c.jsx(Rh,{data:u});const d=typeof u=="string"?u:(()=>{try{return so(u)}catch{return String(u??"")}})();return c.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:d})},i=l=>{if(l==null)return null;const{content:u,isMarkdown:d}=QS(l);return d?c.jsx(co,{content:u,className:"text-current"}):s(l)},a=()=>{const l=e.content.find(f=>f.type!=="tool_call");if(!l)return c.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:c.jsxs("span",{children:["Running ",o,"…"]})});if(l.type==="text"){const h=(l.text??"").trim();if(!h)return null;const p=Rs(h);return i(p)}const u=oo(l),d=Rs(u);return i(d)};return c.jsxs("div",{className:"space-y-2",children:[c.jsx(eT,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function nT(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ha(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,u]=w.useState(!1),d=w.useCallback(()=>{u(!1),a(null)},[]),f=w.useCallback(p=>{a(p),u(!0)},[]),h=w.useCallback(async(p,y,g)=>{var v,x;if(!t){p.preventDefault();return}if(o[g]){p.preventDefault();return}try{const b=String(y.url??""),C=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(C){p.preventDefault();const k=C[1],S=y.name||`file_${k}`,T=y.mimeType||"application/octet-stream";f({id:k,name:S,mimeType:T});return}if(b.startsWith("data:")){p.preventDefault(),s(S=>({...S,[g]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const S=await lC(n??void 0);if(!S||!Array.isArray(S))throw new Error("Invalid file list response");const T=S.find(E=>!E||typeof E!="object"||!((E.filename??"")===(y.name??""))?!1:typeof y.size=="number"&&typeof E.size=="number"?E.size===y.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${y.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:y.name||T.filename||`file_${T.id}`,mimeType:y.mimeType||T.mime_type||"application/octet-stream"}),(v=k.update)==null||v.call(k,{id:k.id,title:"Success",description:`Opened ${y.name}`,open:!0})}catch(S){console.error("Failed to fetch server file:",S);const T=S instanceof Error?S.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(S=>({...S,[g]:!1}))}}}catch(b){console.error("File click error:",b),s(C=>({...C,[g]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function rT({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return c.jsxs("div",{className:"flex flex-col gap-1",children:[c.jsx("div",{className:ne("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?c.jsx(co,{content:e,allowHtml:!1}):c.jsxs("pre",{className:ne("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,"..."]})}),c.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?c.jsxs(c.Fragment,{children:[c.jsx(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function oT({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:ne("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function Ph(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ws=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:u=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:h=!0,customStyles:p={},onEdit:y,onRegenerate:g,onCancelEdit:v,onCopy:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:S,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:A,defaultCheckpointId:P=null,messageParentCheckpointId:$=null}){const[B,V]=w.useState(!1),[G,O]=w.useState("preview"),[U,N]=w.useState(!1),{currentThreadId:D}=Fo(),{respondToInterrupt:M}=Bo(),j=l==="phone"||l==="half-screen",H=t.role,W=H==="tool",R=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),K=!!R,ie=!(r&&H!=="user"),{uploadingFiles:Q,handleFileClick:oe,fileViewerOpen:Y,currentFileInfo:L,closeFileViewer:q}=nT({allowFileOpen:ie,currentThreadId:D}),z=w.useMemo(()=>{switch(H){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))]"}},[H]),Z=w.useMemo(()=>{if(R)return"";const _=t.content;return Array.isArray(_)?eC(_):""},[R,t]),X=w.useMemo(()=>{if(R)return{};const _=t.content;return Array.isArray(_)?Gf(t):{}},[R,t]),ge=w.useMemo(()=>W?!!(t.additionalKwargs??{}).toolStreaming:!1,[W,t]),le=w.useMemo(()=>{if(R)return[];const _=t.content;return Array.isArray(_)?_.filter(se=>se.type==="image_url"):[]},[R,t]),te=w.useMemo(()=>{if(R)return[];const _=t.content;return Array.isArray(_)?_.filter(se=>se.type==="file"):[]},[R,t]),fe=w.useMemo(()=>{if(R)return[];const _=t.content;return Array.isArray(_)?_.filter(se=>se.type==="interrupt"):[]},[R,t]),ye=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Me=Ps(ye),Ne=b==null?void 0:b.value,$e=w.useMemo(()=>{if(R)return"";const _=t.content;return Array.isArray(_)?tC(_):""},[R,t]),Xe=w.useMemo(()=>R||!h?null:t.artifact||null,[R,t,h]),nt=w.useCallback(async()=>{const _=W?$e:Z;async function se(pe){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(pe);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const We=new Blob([pe],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":We})]);return}throw new Error("Clipboard API not supported in this context.")}try{await se(_),V(!0),setTimeout(()=>V(!1),2e3),x==null||x(_)}catch(pe){console.error("Failed to copy:",pe)}},[W,$e,Z,x]),Ve=w.useCallback(()=>{if(!y)return;const _=W?$e:Z,se="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};y(t.id,_,se)},[y,t.id,W,$e,Z,t]),qe=w.useCallback(()=>{g==null||g(n)},[g,n]),ot=w.useCallback(()=>{const se=ne(j?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",z);switch(H){case"user":return c.jsx(ae.User,{className:se});case"assistant":return c.jsx(ae.Bot,{className:se});case"tool":return c.jsx(ae.Wrench,{className:se});default:return c.jsx(ae.Bot,{className:se})}},[j,z,H]),kt=w.useCallback(()=>{const _="group relative mb-4 flex w-full";switch(H){case"user":return ne(_,"justify-end");case"assistant":case"tool":case"system":return ne(_,"justify-start");default:return _}},[H]),lt=w.useCallback(()=>{const _=ne("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",j&&"px-3 py-2 text-sm");if(K)return ne(_,"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(H){case"user":return ne(_,"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 ne(_,"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 ne(_,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ne(_,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ne(_,"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")}},[j,K,H]),ke=w.useCallback(async _=>{if(C)return;const se=Ps((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!se){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await M(se,!0)}catch(pe){console.error("Failed to approve interrupt:",pe)}finally{S==null||S()}},[C,S,k,M]),Oe=w.useCallback(async _=>{if(C)return;const se=Ps((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!se){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await M(se,!1)}catch(pe){console.error("Failed to reject interrupt:",pe)}finally{S==null||S()}},[C,S,k,M]),at=w.useCallback(({part:_,i:se})=>{if(_.type==="text"){const pe=_.text??"",We=pe.trim(),Pe=Ma(We);return Pe&&H!=="tool"?c.jsx(Rh,{data:Pe},se):H==="user"&&u&&We.length>d?c.jsx(rT,{text:We,expanded:U,onExpandedChange:N,previewLength:d,isCompact:j},se):c.jsx(co,{content:pe,allowHtml:!1},se)}if(_.type==="image_url"){const pe=_;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:pe.url,alt:pe.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},se)}if(_.type==="file"){const pe=_,We=pe.name||"file";return c.jsxs("a",{href:pe.url,onClick:Pe=>oe(Pe.nativeEvent,pe,se),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[se]?c.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[We,Q[se]?" (processing)":""]})]},se)}if(_.type==="interrupt"){const pe=_,We=Ps((pe==null?void 0:pe.id)??(pe==null?void 0:pe.interrupt_id)),Pe=!!(Me&&We&&We===Me),gt=Pe?Ne??(pe==null?void 0:pe.value):pe==null?void 0:pe.value,Ze=We?{...pe,id:We,interrupt_id:We}:pe;return c.jsx(ZC,{interruptPart:Ze,onApprove:ke,onReject:Oe,disabled:C,isActive:Pe,payload:gt},se)}return null},[oe,Q,ke,Oe,H,u,d,U,j,Me,Ne,b,C,fe]),pt=w.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Et=w.useCallback(()=>{const _=Z.trim().length>0||le.length>0||te.length>0||fe.length>0;if(!W&&te.length>0&&!r)return pt();if(!W&&!_&&!r)return null;if(W)return!f&&Xe?null:f?c.jsx(tT,{message:t,viewMode:G,isStreaming:ge},t.id):null;if(!W&&!R){const se=t,pe=c.jsx("div",{className:"space-y-2",children:se.content.map((We,Pe)=>c.jsx(at,{part:We,i:Pe},Pe))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[pe,c.jsx(oT,{className:z})]}):pe}},[Z,le.length,te.length,fe.length,r,W,G,f,Xe,pt,z]),Ct=w.useMemo(()=>R?"Assistant":nC(t),[R,t]),Le=w.useMemo(()=>R?[]:Array.isArray(T)?T:[],[T,R]),Vt=w.useMemo(()=>{var _;return Le.length?P&&Le.some(se=>se.id===P)?P:((_=Le[0])==null?void 0:_.id)??null:null},[P,Le]),Ke=w.useMemo(()=>!Le.length||!E?null:Le.some(_=>_.id===E)?E:null,[E,Le])??Vt,dt=H==="user"&&Le.length>0&&typeof A=="function",bt=w.useCallback((_,se=!1)=>{if(!A)return;const pe=(_==null?void 0:_.id)??null,We=(_==null?void 0:_.parentId)??$??null;A(pe,We,se)},[$,A]),He=w.useMemo(()=>Ke?Le.findIndex(_=>_.id===Ke):-1,[Ke,Le]),Tt=w.useMemo(()=>He<0?null:Le[He]??null,[He,Le]);return W&&!f&&!Xe?null:K&&R?c.jsx("div",{className:ne(kt(),p.container),children:c.jsxs("div",{className:ne(lt(),p.content),children:[c.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[c.jsx(ae.Bot,{className:ne("h-4 w-4",z)}),a&&c.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),c.jsx(co,{content:R.content,className:"text-current"})]})}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:ne(kt(),p.container),children:c.jsxs("div",{className:ne(lt(),p.content),children:[(i||a||W)&&c.jsxs("div",{className:ne("flex items-center justify-between mb-2 pb-2 border-b border-current/10",j&&"mb-1 pb-1",z,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[ot(),a&&Ct&&c.jsx("span",{className:ne("font-medium",j?"text-xs":"text-sm"),children:Ct}),W&&c.jsxs(Kf,{variant:"outline",className:ne("text-xs flex items-center gap-1 cursor-pointer select-none",z,"border border-current/40",j&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":G==="expanded",onClick:()=>O(_=>_==="expanded"?"preview":"expanded"),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),O(se=>se==="expanded"?"preview":"expanded"))},children:[c.jsx("span",{children:X.name??"Tool Output"}),X.toolCallId&&c.jsx("span",{className:"opacity-70",children:X.toolCallId.slice(0,8)}),G==="expanded"?c.jsx(ae.ChevronUp,{className:"h-3 w-3"}):c.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[dt&&Tt&&He>=0&&c.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",He<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(He>=Le.length-1)return;const _=Le[He+1];_&&bt(_)},"aria-label":"Older checkpoint (back in time)",disabled:He>=Le.length-1,children:c.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),c.jsx("div",{className:"flex items-center gap-2",children:c.jsxs("span",{className:"whitespace-nowrap",children:[Le.length-He," / ",Le.length]})}),c.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",He>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(He<=0))if(He===1)bt(null,!0);else{const _=Le[He-1];_&&bt(_,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:He<=0,children:c.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&c.jsx("time",{className:ne("text-xs opacity-60",z,j&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:ne("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx("div",{className:"relative",children:c.jsx(et,{variant:"ghost",size:"sm",onClick:()=>nt(),className:ne("h-6 w-6 p-0 hover:bg-foreground/10",z,j&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:c.jsx(ae.Copy,{className:ne(B?"text-success":z,j?"h-3 w-3":"h-4 w-4")})})}),H==="user"&&y&&c.jsx(et,{variant:"ghost",size:"sm",onClick:Ve,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",z,j&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(ae.Edit,{className:ne(z,j?"h-3 w-3":"h-4 w-4")})}),H==="assistant"&&g&&c.jsx(et,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",z,j&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(ae.RotateCcw,{className:ne(z,j?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsxs("div",{className:"relative",children:[Et(),h&&Xe&&c.jsx("div",{className:"mt-3",children:c.jsx(JC,{artifact:Xe,idx:0})})]}),W&&G==="expanded"&&(X.toolCallId||X.name)&&c.jsxs("div",{className:ne("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",j&&"text-xs"),children:[X.name&&c.jsxs("div",{children:["Function: ",X.name]}),X.toolCallId&&c.jsxs("div",{children:["Call ID: ",X.toolCallId]})]}),!(i||a||W)&&s&&!o&&c.jsxs("div",{className:ne("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(et,{variant:"ghost",size:"sm",onClick:()=>nt(),className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",j&&"h-5 w-5"),children:c.jsx(ae.Copy,{className:ne(B?"text-success":"text-current",j?"h-3 w-3":"h-4 w-4")})}),H==="user"&&y&&c.jsx(et,{variant:"ghost",size:"sm",onClick:Ve,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",j&&"h-5 w-5"),children:c.jsx(ae.Edit,{className:ne("text-current",j?"h-3 w-3":"h-4 w-4")})}),H==="assistant"&&g&&c.jsx(et,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",j&&"h-5 w-5"),children:c.jsx(ae.RotateCcw,{className:ne("text-current",j?"h-3 w-3":"h-4 w-4")})})]})]})}),L&&c.jsx(EC,{isOpen:Y,onClose:q,fileId:L.id,fileName:L.name,mimeType:L.mimeType})]})},(e,t)=>{var l,u,d,f,h,p,y,g;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Yf(e.message)===Yf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(v=>e[v]===t[v]),s=((l=e.customStyles)==null?void 0:l.container)===((u=t.customStyles)==null?void 0:u.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((h=e.customStyles)==null?void 0:h.actions)===((p=t.customStyles)==null?void 0:p.actions)&&((y=e.customStyles)==null?void 0:y.header)===((g=t.customStyles)==null?void 0:g.header);if(!o||!s)return!1;const i=Ph(e.message),a=Ph(t.message);return i.length===a.length});Ws.displayName="MessageComponent";function sT(e,t){return w.useMemo(()=>{var d,f,h,p,y;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,u=null;if(!n&&e){const g=e,v=g.checkpointId??null;s=g.additionalKwargs??{},i=g.responseMetadata??{};const x=v&&t.checkpointMetaById?t.checkpointMetaById.get(v)??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 C=a!==null&&l?`${a}:${l}`:null;if(C&&((d=t.checkpointIndexByKey)!=null&&d.has(C))?r=t.checkpointIndexByKey.get(C)??[]:v&&x&&(r=[x]),o=v??((f=r[0])==null?void 0:f.id)??null,u=v?((h=t.attemptMetaById)==null?void 0:h.get(v))??null:null,!u&&(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 S=k[0].checkpointId;u=((p=t.attemptMetaById)==null?void 0:p.get(S))??null,u&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!u&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(u=k)}if(u&&u.attemptCount>1&&t.attemptMetaById){const k=u.baseUserMessageId;if(k){const S=[];for(const[T,E]of t.attemptMetaById.entries())if(E.baseUserMessageId===k){const A=(y=t.checkpointMetaById)==null?void 0:y.get(T);A&&S.push(A)}S.length>0&&(r=S)}}if(u&&u.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[S,T]of t.checkpointMetaById.entries()){const E=t.attemptMetaById.get(S);E&&E.attemptCount===u.attemptCount&&E.baseUserMessageId===u.baseUserMessageId&&k.push(T)}k.sort((S,T)=>{const E=S.createdAt?Date.parse(S.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-E}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:u.attemptCount,candidateIds:r.map(S=>S.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:u,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const Oh=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Dh=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:u,onRegenerate:d,onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:y,onInterruptActionEnd:g,showToolMessages:v,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:S,activeCheckpointId:T,onSelectCheckpoint:E}){const A=Oh(t,n),P="type"in t&&t.type==="default_message",B=!!t.__syntheticStreaming,{checkpointCandidates:V,defaultCheckpointId:G,attemptMeta:O}=sT(t,{checkpointMetaById:b,checkpointIndexByKey:C,attemptMetaById:k,userMessageIdToAttempts:S}),U=t&&!P?t.additionalKwargs??{}:{},N=t&&!P?t.responseMetadata??{}:{},D=(()=>{if(typeof U.parentCheckpointId=="string")return U.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return c.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(Ws,{message:t,messageIndex:n,isStreamingMessage:B||r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:u,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:h,disableInterruptActions:p,onInterruptActionStart:y,onInterruptActionEnd:g,showToolMessages:v,showArtifactPreviews:x,checkpointCandidates:V,activeCheckpointId:T??null,onSelectCheckpoint:E,defaultCheckpointId:G,messageParentCheckpointId:D,attemptMeta:O})})});Dh.displayName="MessageRow";const Ka=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:y=!0,isNavigatingCheckpoint:g=!1,onScrollAway:v,onAtBottom:x,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:k,onInterruptActionEnd:S,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:A,checkpointIndexByKey:P,attemptMetaById:$,userMessageIdToAttempts:B,activeCheckpointId:V,onSelectCheckpoint:G,createSyntheticThinkingMessage:O=!0},U)=>{const N=w.useRef(null),D=w.useRef(null),M=w.useRef(!1),j=w.useRef(!1),[H,W]=w.useState(!0),R=w.useMemo(()=>b?e.some(te=>"type"in te&&te.type==="default_message"?!1:Array.isArray(te==null?void 0:te.content)&&te.content.some(fe=>fe&&fe.type==="interrupt"&&(fe.id??fe.interrupt_id)===b.id)):!1,[b,e]),K=w.useMemo(()=>{if(!b||R)return null;const te=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let fe;const ye=b.value;if(ye&&typeof ye=="object"&&!Array.isArray(ye)){const Me=ye.title;typeof Me=="string"&&Me.trim()&&(fe=Me.trim())}return{id:`interrupt-${te}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:te,value:ye,title:fe}]}},[b,R]),ie=w.useMemo(()=>K?[...e,K]:e,[e,K]),Q=w.useMemo(()=>!O||!t?ie:!ie.some(fe=>fe.role==="assistant")&&ie.length>0?[...ie,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString(),__syntheticStreaming:!0}]:ie,[ie,t,O]),oe=w.useMemo(()=>T?Q:Q.filter(te=>(te==null?void 0:te.role)!=="tool"),[Q,T]),Y=w.useCallback(te=>{W(te),v&&v(!te),x&&x(te)},[v,x]),L=w.useMemo(()=>{if(a)return async()=>{if(!M.current){M.current=!0;try{await a()}finally{M.current=!1}}}},[a]),q=w.useMemo(()=>!y||g?!1:H?"auto":!1,[H,y,g]),z=w.useMemo(()=>{if(typeof p!="string")return null;const te=p.trim();return te?{id:"default-message",role:"assistant",type:"default_message",content:te,createdAt:new Date().toISOString()}:null},[p]),Z=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),X=()=>z?c.jsx("div",{className:"p-6 h-full overflow-y-auto",children:c.jsx("div",{className:"w-full max-w-full",children:c.jsx(Ws,{message:z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):c.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:p??"No messages yet. Start a conversation!"}),ge=oe.length,le=ge>0;return w.useEffect(()=>{var te,fe;if(ge===0){j.current=!1;return}if(!j.current)if(j.current=!0,N.current&&oe.length>0){const ye=oe.length-1;(fe=(te=N.current).scrollToIndex)==null||fe.call(te,{index:ye,align:"end",behavior:"auto"})}else D.current&&(D.current.scrollTop=D.current.scrollHeight)},[ge,oe.length]),w.useImperativeHandle(U,()=>({scrollToLatest:()=>{var te,fe;if(N.current&&oe.length>0){const ye=oe.length-1;(fe=(te=N.current).scrollToIndex)==null||fe.call(te,{index:ye,align:"end",behavior:"auto"})}else D.current&&(D.current.scrollTop=D.current.scrollHeight)},scrollToTop:()=>{var te,fe;N.current&&oe.length>0?(fe=(te=N.current).scrollToIndex)==null||fe.call(te,{index:0,align:"start",behavior:"auto"}):D.current&&(D.current.scrollTop=0)}}),[oe]),c.jsx("div",{className:Z,style:h,children:c.jsx("div",{className:"relative flex-1 min-h-0",children:le?c.jsx(DS,{ref:te=>{N.current=te},scrollerRef:te=>{D.current=te instanceof HTMLDivElement?te:null},data:oe,followOutput:q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{L&&L()},atBottomStateChange:Y,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(te,fe)=>Oh(fe,te),itemContent:(te,fe)=>c.jsx(Dh,{message:fe,index:te,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:u,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:C,onInterruptActionStart:k,onInterruptActionEnd:S,showToolMessages:T,showArtifactPreviews:E,checkpointMetaById:A,checkpointIndexByKey:P,attemptMetaById:$,userMessageIdToAttempts:B,activeCheckpointId:V,onSelectCheckpoint:G})}):X()})})});Ka.displayName="MessageList";const Lh={value:""};function Vs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:h={},onMessageSent:p,onExcelUploadSuccess:y,onError:g}){const{api:v}=wi(),{currentThreadId:x}=Fo(),{threadId:b,messages:C,isHistoryLoading:k,isLoading:S,navigateToCheckpoint:T,returnToLatest:E,checkpoint:A,checkpoints:P,interrupt:$,metadata:B,timelineCheckpoints:V,messagePreviews:G}=Bo(),{isStreaming:O,error:U,connectionState:N,submit:D,stop:M}=Dc(),j=b??x??null,H=(A==null?void 0:A.id)??null,W=(A==null?void 0:A.namespace)??null,R=(B==null?void 0:B.assemblingMessageId)??null,K=$,[ie,Q]=w.useState(!1);w.useEffect(()=>{K||Q(!1)},[K]);const oe=w.useCallback(()=>{Q(!0)},[]),Y=w.useCallback(()=>{Q(!1)},[]),L=!!K||ie,[q,z]=w.useState(null),[Z,X]=w.useState(""),[ge,le]=w.useState(null),[te,fe]=w.useState(null),[ye,Me]=w.useState([]),[Ne,$e]=w.useState(0),[Xe,nt]=w.useState(0),[Ve,qe]=w.useState(!1),[ot,kt]=w.useState(null),[lt,ke]=w.useState(null),[Oe,at]=w.useState(!1),[pt,Et]=w.useState(null),Ct=w.useRef(!1),[Le,Vt]=w.useState(()=>Lh.value),Je=w.useRef(Le),Ke=w.useRef(null),dt=w.useCallback(me=>{Lh.value=me,Vt(me)},[]),[bt,He]=w.useState(!1),Tt=w.useRef(null),{checkpointMetaById:_,checkpointIndexByKey:se,attemptMetaById:pe,userMessageIdToAttempts:We}=C0(P),Pe=V??[],gt=w.useRef(null),Ze=w.useRef(null),jt=w.useCallback(()=>{gt.current&&(gt.current.value=""),Ze.current&&(Ze.current.value=""),$e(me=>me+1),nt(me=>me+1)},[]),yo=w.useCallback(me=>{dt(me)},[dt]),vo=w.useRef(!1);w.useEffect(()=>{vo.current&&!O&&(Me([]),jt()),vo.current=O},[O,jt]);const[ri,hl]=w.useState("desktop");w.useEffect(()=>{const me=()=>{const Se=window.innerWidth;hl(Se<640?"phone":Se<1024?"tablet":"desktop")};return me(),window.addEventListener("resize",me),()=>window.removeEventListener("resize",me)},[]),w.useEffect(()=>{Ct.current=!1},[j]),w.useEffect(()=>{Je.current=Le},[Le]),w.useEffect(()=>{if(!q){Ke.current=null;return}Ke.current===null&&(Ke.current=Je.current),dt(Z??"")},[Z,q,dt]),w.useEffect(()=>{(async()=>{if(!v.baseUrl){Et(null);return}try{const Ae=(await v.getAgent("default")).uiDefaultMessage||"";Et(Ae||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Et(null)}})()},[v.baseUrl]),w.useEffect(()=>{U&&!Oe&&(g==null||g(U))},[U,Oe,g]);const pl=me=>{if(me.length>vs)return`Message too long (${me.length}/${vs} characters)`;try{return E0(me),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},ml=async me=>{const Se=me.trim();if(!(!Se&&ye.length===0)){if(Se){const Ae=pl(Se);if(Ae){fe(Ae);return}}try{const Ae=q?(ge==null?void 0:ge.checkpointId)??H??void 0:H??void 0,Ge=q?(ge==null?void 0:ge.checkpointNs)??W??void 0:W??void 0;await D({text:Se||"",attachments:ye},{checkpointId:Ae,checkpointNs:Ge,edit:!!q,originalMessageId:q??void 0}),p==null||p(Se),dt(""),fe(null),Me([]),jt(),z(null),X(""),le(null)}catch(Ae){const Ge=(Ae==null?void 0:Ae.message)||"Failed to send message";fe(Ge),g==null||g(Ge)}}},oi=w.useCallback((me,Se,Ae)=>{u&&(Ke.current=Le,z(me),X(Se),dt(Se),fe(null),le({checkpointId:(Ae==null?void 0:Ae.checkpointId)??null,checkpointNs:(Ae==null?void 0:Ae.checkpointNs)??null}))},[Le,u,dt]),I=w.useCallback(()=>{z(null),X(""),le(null),fe(null),dt(Ke.current??Le),Ke.current=null},[Le,dt]),ee=w.useCallback((me,Se,Ae)=>{oi(me,Se,Ae)},[oi]),ce=w.useCallback(me=>{let Se=null;for(let on=me-1;on>=0;on--)if(C[on].role==="user"){Se=C[on];break}if(!Se)return;const Ae=Array.isArray(Se.content)?Se.content:[],Hn=Ae.filter(on=>(on==null?void 0:on.type)==="text").map(on=>on.text).join("")||(()=>{try{return JSON.stringify(Ae,null,2)}catch{return String(Ae)}})();Hn&&D({text:Hn},{checkpointId:H??void 0,checkpointNs:W??void 0,edit:!0,originalMessageId:Se.id})},[C,D,H,W]),Ee=me=>{const Se=Array.from(me.target.files||[]);Me(Ae=>[...Ae,...Se]),me.target.value=""},Qe=me=>{Me(Se=>{const Ae=Se.filter((Ge,Hn)=>me!==Hn);return Ae.length===0&&jt(),Ae})},rt=async me=>{const Se=(me.target.files||[])[0];if(Se){kt(null),ke(null),qe(!0);try{await D({attachments:[Se]},{checkpointId:H??void 0,checkpointNs:W??void 0});const Ae=`Uploaded ${Se.name} - processing through chat stream`;ke(Ae)}catch(Ae){const Ge=Ae instanceof Error?Ae.message:"Failed to upload Excel file";console.error("Excel upload failed",Ae),kt(Ge),g==null||g(Ge)}finally{qe(!1),me.target.value="",jt()}}},Be=async me=>{if(x){He(!0);try{if(!me){await E(),requestAnimationFrame(()=>{var Ge;(Ge=Tt.current)==null||Ge.scrollToLatest()});return}const Se=P.find(Ge=>Ge.checkpointId===me),Ae=(Se==null?void 0:Se.checkpointNs)??null;await T(me,Ae),requestAnimationFrame(()=>{var Ge;(Ge=Tt.current)==null||Ge.scrollToTop()})}finally{He(!1)}}},Fe=w.useCallback(async(me,Se,Ae)=>{await Be(Ae?null:me)},[Be]),_t=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${h.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 ${h.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${h.inputArea||""}`;return c.jsxs("div",{className:_t,children:[!!U&&!Oe&&c.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[c.jsx("span",{children:U}),c.jsx(et,{variant:"ghost",size:"sm",onClick:()=>at(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(ae.X,{size:16})})]}),c.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Ka,{ref:Tt,className:"h-full",style:{height:"100%"},messages:C,isStreaming:O,streamingAssistantId:R,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ri,enableMessageEditing:u,editingMessageId:q,onEdit:ee,onRegenerate:ce,onCancelEdit:I,emptyMessage:pt??void 0,isNavigatingCheckpoint:bt,activeInterrupt:K,disableInterruptActions:ie,onInterruptActionStart:oe,onInterruptActionEnd:Y,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:_,checkpointIndexByKey:se,attemptMetaById:pe,userMessageIdToAttempts:We,activeCheckpointId:H,onSelectCheckpoint:Fe,timelineCheckpoints:Pe,messagePreviews:G,createSyntheticThinkingMessage:!0}),(N==="reconnecting"||N==="connecting")&&c.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:c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(ae.Loader2,{className:"h-3 w-3 animate-spin"}),N==="reconnecting"?"Reconnecting…":"Connecting…"]})}),N==="error"&&c.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"}),S&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||bt)&&c.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),c.jsxs("div",{className:xt,children:[q&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ae.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(et,{variant:"ghost",size:"sm",onClick:I,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(ae.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:gt,type:"file",multiple:!0,onChange:me=>Ee(me),className:"hidden"},Ne),ye.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:ye.map((me,Se)=>c.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[c.jsx(ae.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:me.name}),c.jsx(et,{variant:"ghost",size:"sm",onClick:()=>Qe(Se),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 ${me.name}`,children:c.jsx(ae.X,{size:12})})]},Se))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:Ze,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},Xe),Ve&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),lt&&!Ve&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:lt}),ot&&!Ve&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:ot})]})]}),te&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:te}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(aa,{children:[c.jsx(la,{asChild:!0,children:c.jsx(et,{type:"button",size:"icon",variant:"outline",disabled:O||L,title:"More input actions",className:h.moreButton||"",children:c.jsx(ae.Plus,{size:16})})}),c.jsxs(xs,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(Jn,{onClick:()=>{var me;return(me=gt.current)==null?void 0:me.click()},className:"cursor-pointer",children:[c.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(Jn,{onClick:()=>{var me;Ve||(me=Ze.current)==null||me.click()},className:`cursor-pointer ${Ve?"opacity-60 pointer-events-none":""}`,children:[c.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(fy,{initialValue:Z,editingMessageId:q,value:Le,onValueChange:yo,placeholder:q?"Edit your message...":t,isStreaming:O,disabled:L,maxLength:vs,onSend:ml,onCancelEdit:I,onStop:M,allowEmptySend:ye.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":""} ${te?"border-red-400":""} ${h.textarea||""}`})})]})]})]})}var $h=1,iT=.9,aT=.8,lT=.17,qa=.1,Ga=.999,cT=.9999,uT=.99,dT=/[\\\/_+.#"@\[\(\{&]/,fT=/[\\\/_+.#"@\[\(\{&]/g,hT=/[\s-]/,Fh=/[\s-]/g;function Ya(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?$h:uT;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),u=n.indexOf(l,o),d=0,f,h,p,y;u>=0;)f=Ya(e,t,n,r,u+1,s+1,i),f>d&&(u===o?f*=$h:dT.test(e.charAt(u-1))?(f*=aT,p=e.slice(o,u-1).match(fT),p&&o>0&&(f*=Math.pow(Ga,p.length))):hT.test(e.charAt(u-1))?(f*=iT,y=e.slice(o,u-1).match(Fh),y&&o>0&&(f*=Math.pow(Ga,y.length))):(f*=lT,o>0&&(f*=Math.pow(Ga,u-o))),e.charAt(u)!==t.charAt(s)&&(f*=cT)),(f<qa&&n.charAt(u-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(u-1)!==r.charAt(s))&&(h=Ya(e,t,n,r,u+1,s+2,i),h*qa>f&&(f=h*qa)),f>d&&(d=f),u=n.indexOf(l,u+1);return i[a]=d,d}function Bh(e){return e.toLowerCase().replace(Fh," ")}function pT(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Ya(e,t,Bh(e),Bh(t),0,0,{})}var mo='[cmdk-group=""]',Xa='[cmdk-group-items=""]',mT='[cmdk-group-heading=""]',zh='[cmdk-item=""]',Uh=`${zh}:not([aria-disabled="true"])`,Ja="cmdk-item-select",Er="data-value",gT=(e,t,n)=>pT(e,t,n),Hh=m.createContext(void 0),go=()=>m.useContext(Hh),Wh=m.createContext(void 0),Za=()=>m.useContext(Wh),Vh=m.createContext(void 0),Kh=m.forwardRef((e,t)=>{let n=Ir(()=>{var R,K;return{search:"",value:(K=(R=e.value)!=null?R:e.defaultValue)!=null?K:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Ir(()=>new Set),o=Ir(()=>new Map),s=Ir(()=>new Map),i=Ir(()=>new Set),a=qh(e),{label:l,children:u,value:d,onValueChange:f,filter:h,shouldFilter:p,loop:y,disablePointerSelection:g=!1,vimBindings:v=!0,...x}=e,b=$t(),C=$t(),k=$t(),S=m.useRef(null),T=IT();sr(()=>{if(d!==void 0){let R=d.trim();n.current.value=R,E.emit()}},[d]),sr(()=>{T(6,G)},[]);let E=m.useMemo(()=>({subscribe:R=>(i.current.add(R),()=>i.current.delete(R)),snapshot:()=>n.current,setState:(R,K,ie)=>{var Q,oe,Y,L;if(!Object.is(n.current[R],K)){if(n.current[R]=K,R==="search")V(),$(),T(1,B);else if(R==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let q=document.getElementById(k);q?q.focus():(Q=document.getElementById(b))==null||Q.focus()}if(T(7,()=>{var q;n.current.selectedItemId=(q=O())==null?void 0:q.id,E.emit()}),ie||T(5,G),((oe=a.current)==null?void 0:oe.value)!==void 0){let q=K??"";(L=(Y=a.current).onValueChange)==null||L.call(Y,q);return}}E.emit()}},emit:()=>{i.current.forEach(R=>R())}}),[]),A=m.useMemo(()=>({value:(R,K,ie)=>{var Q;K!==((Q=s.current.get(R))==null?void 0:Q.value)&&(s.current.set(R,{value:K,keywords:ie}),n.current.filtered.items.set(R,P(K,ie)),T(2,()=>{$(),E.emit()}))},item:(R,K)=>(r.current.add(R),K&&(o.current.has(K)?o.current.get(K).add(R):o.current.set(K,new Set([R]))),T(3,()=>{V(),$(),n.current.value||B(),E.emit()}),()=>{s.current.delete(R),r.current.delete(R),n.current.filtered.items.delete(R);let ie=O();T(4,()=>{V(),(ie==null?void 0:ie.getAttribute("id"))===R&&B(),E.emit()})}),group:R=>(o.current.has(R)||o.current.set(R,new Set),()=>{s.current.delete(R),o.current.delete(R)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:b,inputId:k,labelId:C,listInnerRef:S}),[]);function P(R,K){var ie,Q;let oe=(Q=(ie=a.current)==null?void 0:ie.filter)!=null?Q:gT;return R?oe(R,n.current.search,K):0}function $(){if(!n.current.search||a.current.shouldFilter===!1)return;let R=n.current.filtered.items,K=[];n.current.filtered.groups.forEach(Q=>{let oe=o.current.get(Q),Y=0;oe.forEach(L=>{let q=R.get(L);Y=Math.max(q,Y)}),K.push([Q,Y])});let ie=S.current;U().sort((Q,oe)=>{var Y,L;let q=Q.getAttribute("id"),z=oe.getAttribute("id");return((Y=R.get(z))!=null?Y:0)-((L=R.get(q))!=null?L:0)}).forEach(Q=>{let oe=Q.closest(Xa);oe?oe.appendChild(Q.parentElement===oe?Q:Q.closest(`${Xa} > *`)):ie.appendChild(Q.parentElement===ie?Q:Q.closest(`${Xa} > *`))}),K.sort((Q,oe)=>oe[1]-Q[1]).forEach(Q=>{var oe;let Y=(oe=S.current)==null?void 0:oe.querySelector(`${mo}[${Er}="${encodeURIComponent(Q[0])}"]`);Y==null||Y.parentElement.appendChild(Y)})}function B(){let R=U().find(ie=>ie.getAttribute("aria-disabled")!=="true"),K=R==null?void 0:R.getAttribute(Er);E.setState("value",K||void 0)}function V(){var R,K,ie,Q;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let oe=0;for(let Y of r.current){let L=(K=(R=s.current.get(Y))==null?void 0:R.value)!=null?K:"",q=(Q=(ie=s.current.get(Y))==null?void 0:ie.keywords)!=null?Q:[],z=P(L,q);n.current.filtered.items.set(Y,z),z>0&&oe++}for(let[Y,L]of o.current)for(let q of L)if(n.current.filtered.items.get(q)>0){n.current.filtered.groups.add(Y);break}n.current.filtered.count=oe}function G(){var R,K,ie;let Q=O();Q&&(((R=Q.parentElement)==null?void 0:R.firstChild)===Q&&((ie=(K=Q.closest(mo))==null?void 0:K.querySelector(mT))==null||ie.scrollIntoView({block:"nearest"})),Q.scrollIntoView({block:"nearest"}))}function O(){var R;return(R=S.current)==null?void 0:R.querySelector(`${zh}[aria-selected="true"]`)}function U(){var R;return Array.from(((R=S.current)==null?void 0:R.querySelectorAll(Uh))||[])}function N(R){let K=U()[R];K&&E.setState("value",K.getAttribute(Er))}function D(R){var K;let ie=O(),Q=U(),oe=Q.findIndex(L=>L===ie),Y=Q[oe+R];(K=a.current)!=null&&K.loop&&(Y=oe+R<0?Q[Q.length-1]:oe+R===Q.length?Q[0]:Q[oe+R]),Y&&E.setState("value",Y.getAttribute(Er))}function M(R){let K=O(),ie=K==null?void 0:K.closest(mo),Q;for(;ie&&!Q;)ie=R>0?kT(ie,mo):ET(ie,mo),Q=ie==null?void 0:ie.querySelector(Uh);Q?E.setState("value",Q.getAttribute(Er)):D(R)}let j=()=>N(U().length-1),H=R=>{R.preventDefault(),R.metaKey?j():R.altKey?M(1):D(1)},W=R=>{R.preventDefault(),R.metaKey?N(0):R.altKey?M(-1):D(-1)};return m.createElement(we.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:R=>{var K;(K=x.onKeyDown)==null||K.call(x,R);let ie=R.nativeEvent.isComposing||R.keyCode===229;if(!(R.defaultPrevented||ie))switch(R.key){case"n":case"j":{v&&R.ctrlKey&&H(R);break}case"ArrowDown":{H(R);break}case"p":case"k":{v&&R.ctrlKey&&W(R);break}case"ArrowUp":{W(R);break}case"Home":{R.preventDefault(),N(0);break}case"End":{R.preventDefault(),j();break}case"Enter":{R.preventDefault();let Q=O();if(Q){let oe=new Event(Ja);Q.dispatchEvent(oe)}}}}},m.createElement("label",{"cmdk-label":"",htmlFor:A.inputId,id:A.labelId,style:AT},l),Ks(e,R=>m.createElement(Wh.Provider,{value:E},m.createElement(Hh.Provider,{value:A},R))))}),xT=m.forwardRef((e,t)=>{var n,r;let o=$t(),s=m.useRef(null),i=m.useContext(Vh),a=go(),l=qh(e),u=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;sr(()=>{if(!u)return a.item(o,i==null?void 0:i.id)},[u]);let d=Gh(o,s,[e.value,e.children,s],e.keywords),f=Za(),h=Fn(T=>T.value&&T.value===d.current),p=Fn(T=>u||a.filter()===!1?!0:T.search?T.filtered.items.get(o)>0:!0);m.useEffect(()=>{let T=s.current;if(!(!T||e.disabled))return T.addEventListener(Ja,y),()=>T.removeEventListener(Ja,y)},[p,e.onSelect,e.disabled]);function y(){var T,E;g(),(E=(T=l.current).onSelect)==null||E.call(T,d.current)}function g(){f.setState("value",d.current,!0)}if(!p)return null;let{disabled:v,value:x,onSelect:b,forceMount:C,keywords:k,...S}=e;return m.createElement(we.div,{ref:An(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!v,"aria-selected":!!h,"data-disabled":!!v,"data-selected":!!h,onPointerMove:v||a.getDisablePointerSelection()?void 0:g,onClick:v?void 0:y},e.children)}),yT=m.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=$t(),a=m.useRef(null),l=m.useRef(null),u=$t(),d=go(),f=Fn(p=>o||d.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);sr(()=>d.group(i),[]),Gh(i,a,[e.value,e.heading,l]);let h=m.useMemo(()=>({id:i,forceMount:o}),[o]);return m.createElement(we.div,{ref:An(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&m.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:u},n),Ks(e,p=>m.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?u:void 0},m.createElement(Vh.Provider,{value:h},p))))}),vT=m.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=m.useRef(null),s=Fn(i=>!i.search);return!n&&!s?null:m.createElement(we.div,{ref:An(o,t),...r,"cmdk-separator":"",role:"separator"})}),bT=m.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=Za(),i=Fn(u=>u.search),a=Fn(u=>u.selectedItemId),l=go();return m.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),m.createElement(we.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:u=>{o||s.setState("search",u.target.value),n==null||n(u.target.value)}})}),wT=m.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=m.useRef(null),i=m.useRef(null),a=Fn(u=>u.selectedItemId),l=go();return m.useEffect(()=>{if(i.current&&s.current){let u=i.current,d=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=u.offsetHeight;d.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(u),()=>{cancelAnimationFrame(f),h.unobserve(u)}}},[]),m.createElement(we.div,{ref:An(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Ks(e,u=>m.createElement("div",{ref:An(i,l.listInnerRef),"cmdk-list-sizer":""},u)))}),ST=m.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return m.createElement(Da,{open:n,onOpenChange:r},m.createElement(La,{container:i},m.createElement(io,{"cmdk-overlay":"",className:o}),m.createElement(ao,{"aria-label":e.label,"cmdk-dialog":"",className:s},m.createElement(Kh,{ref:t,...a}))))}),CT=m.forwardRef((e,t)=>Fn(n=>n.filtered.count===0)?m.createElement(we.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),TT=m.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return m.createElement(we.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Ks(e,i=>m.createElement("div",{"aria-hidden":!0},i)))}),Wt=Object.assign(Kh,{List:wT,Item:xT,Input:bT,Group:yT,Separator:vT,Dialog:ST,Empty:CT,Loading:TT});function kT(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function ET(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function qh(e){let t=m.useRef(e);return sr(()=>{t.current=e}),t}var sr=typeof window>"u"?m.useEffect:m.useLayoutEffect;function Ir(e){let t=m.useRef();return t.current===void 0&&(t.current=e()),t}function Fn(e){let t=Za(),n=()=>e(t.snapshot());return m.useSyncExternalStore(t.subscribe,n,n)}function Gh(e,t,n,r=[]){let o=m.useRef(),s=go();return sr(()=>{var i;let a=(()=>{var u;for(let d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?(u=d.current.textContent)==null?void 0:u.trim():o.current}})(),l=r.map(u=>u.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(Er,a),o.current=a}),o}var IT=()=>{let[e,t]=m.useState(),n=Ir(()=>new Map);return sr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function NT(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Ks({asChild:e,children:t},n){return e&&m.isValidElement(t)?m.cloneElement(NT(t),{ref:t.ref},n(t.props.children)):n(t)}var AT={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Yh=m.forwardRef(({className:e,...t},n)=>c.jsx(Wt,{ref:n,className:ne("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));Yh.displayName=Wt.displayName;const Xh=m.forwardRef(({className:e,...t},n)=>c.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[c.jsx(ae.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),c.jsx(Wt.Input,{ref:n,className:ne("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Xh.displayName=Wt.Input.displayName;const Jh=m.forwardRef(({className:e,...t},n)=>c.jsx(Wt.List,{ref:n,className:ne("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));Jh.displayName=Wt.List.displayName;const Zh=m.forwardRef((e,t)=>c.jsx(Wt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));Zh.displayName=Wt.Empty.displayName;const Qh=m.forwardRef(({className:e,...t},n)=>c.jsx(Wt.Group,{ref:n,className:ne("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));Qh.displayName=Wt.Group.displayName;const jT=m.forwardRef(({className:e,...t},n)=>c.jsx(Wt.Separator,{ref:n,className:ne("-mx-1 h-px bg-border",e),...t}));jT.displayName=Wt.Separator.displayName;const ep=m.forwardRef(({className:e,...t},n)=>c.jsx(Wt.Item,{ref:n,className:ne("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));ep.displayName=Wt.Item.displayName;function Qa(e,[t,n]){return Math.min(n,Math.max(t,e))}function _T(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var el="ScrollArea",[tp,jE]=Tn(el),[MT,nn]=tp(el),np=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,y]=m.useState(null),[g,v]=m.useState(null),[x,b]=m.useState(0),[C,k]=m.useState(0),[S,T]=m.useState(!1),[E,A]=m.useState(!1),P=ze(t,B=>l(B)),$=Uo(o);return c.jsx(MT,{scope:n,type:r,dir:$,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:y,scrollbarXEnabled:S,onScrollbarXEnabledChange:T,scrollbarY:g,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:c.jsx(we.div,{dir:$,...i,ref:P,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});np.displayName=el;var rp="ScrollAreaViewport",op=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=nn(rp,n),a=m.useRef(null),l=ze(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),c.jsx(we.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});op.displayName=rp;var Sn="ScrollAreaScrollbar",tl=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(RT,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(PT,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(sp,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(nl,{...r,ref:t}):null});tl.displayName=Sn;var RT=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Zt,{present:n||s,children:c.jsx(sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),PT=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(Sn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Xs(()=>l("SCROLL_END"),100),[a,l]=_T("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Zt,{present:n||a!=="hidden",children:c.jsx(nl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:he(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:he(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),sp=m.forwardRef((e,t)=>{const n=nn(Sn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=Xs(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Nr(n.viewport,l),Nr(n.content,l),c.jsx(Zt,{present:r||s,children:c.jsx(nl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),nl=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=nn(Sn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=up(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return BT(h,i.current,a,p)}return n==="horizontal"?c.jsx(OT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=dp(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?c.jsx(DT,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=dp(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),OT=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=ze(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ap,{"data-orientation":"horizontal",...o,ref:u,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),hp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Gs(i.paddingLeft),paddingEnd:Gs(i.paddingRight)}})}})}),DT=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(Sn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=ze(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ap,{"data-orientation":"vertical",...o,ref:u,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ys(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),hp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Gs(i.paddingTop),paddingEnd:Gs(i.paddingBottom)}})}})}),[LT,ip]=tp(Sn),ap=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=nn(Sn,n),[y,g]=m.useState(null),v=ze(t,P=>g(P)),x=m.useRef(null),b=m.useRef(""),C=p.viewport,k=r.content-r.viewport,S=At(d),T=At(l),E=Xs(f,10);function A(P){if(x.current){const $=P.clientX-x.current.left,B=P.clientY-x.current.top;u({x:$,y:B})}}return m.useEffect(()=>{const P=$=>{const B=$.target;(y==null?void 0:y.contains(B))&&S($,k)};return document.addEventListener("wheel",P,{passive:!1}),()=>document.removeEventListener("wheel",P,{passive:!1})},[C,y,k,S]),m.useEffect(T,[r,T]),Nr(y,E),Nr(p.content,E),c.jsx(LT,{scope:n,scrollbar:y,hasThumb:o,onThumbChange:At(s),onThumbPointerUp:At(i),onThumbPositionChange:T,onThumbPointerDown:At(a),children:c.jsx(we.div,{...h,ref:v,style:{position:"absolute",...h.style},onPointerDown:he(e.onPointerDown,P=>{P.button===0&&(P.target.setPointerCapture(P.pointerId),x.current=y.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(P))}),onPointerMove:he(e.onPointerMove,A),onPointerUp:he(e.onPointerUp,P=>{const $=P.target;$.hasPointerCapture(P.pointerId)&&$.releasePointerCapture(P.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),x.current=null})})})}),qs="ScrollAreaThumb",lp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ip(qs,e.__scopeScrollArea);return c.jsx(Zt,{present:n||o.hasThumb,children:c.jsx($T,{ref:t,...r})})}),$T=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=nn(qs,n),i=ip(qs,n),{onThumbPositionChange:a}=i,l=ze(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=Xs(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=zT(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(we.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:he(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),y=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:y,y:g})}),onPointerUp:he(e.onPointerUp,i.onThumbPointerUp)})});lp.displayName=qs;var rl="ScrollAreaCorner",cp=m.forwardRef((e,t)=>{const n=nn(rl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(FT,{...e,ref:t}):null});cp.displayName=rl;var FT=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=nn(rl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Nr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Nr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(we.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 Gs(e){return e?parseInt(e,10):0}function up(e,t){const n=e/t;return isNaN(n)?0:n}function Ys(e){const t=up(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function BT(e,t,n,r="ltr"){const o=Ys(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return fp([l,u],f)(e)}function dp(e,t,n="ltr"){const r=Ys(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=Qa(e,l);return fp([0,i],[0,a])(u)}function fp(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 hp(e,t){return e>0&&e<t}var zT=(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 Xs(e,t){const n=At(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Nr(e,t){const n=At(t);Nt(()=>{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 pp=np,UT=op,HT=cp;const mp=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(pp,{ref:r,className:ne("relative overflow-hidden",e),...n,children:[c.jsx(UT,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(gp,{}),c.jsx(HT,{})]}));mp.displayName=pp.displayName;const gp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(tl,{ref:r,orientation:t,className:ne("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:c.jsx(lp,{className:"relative flex-1 rounded-full bg-border"})}));gp.displayName=tl.displayName;const Js=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:ne("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}));Js.displayName="Input";const WT="group relative p-3 rounded-lg cursor-pointer transition-colors border text-gray-900 dark:text-slate-100",VT="bg-slate-700 border-slate-600 hover:bg-slate-600",KT="bg-slate-600 border-slate-500";function qT({thread:e,isActive:t,editingThreadId:n,editingTitle:r,onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:u,onDelete:d,showEditTitle:f,showDeleteButton:h,formatDate:p,getDisplayThreadTitle:y,secondaryLine:g,itemClassName:v,activeItemClassName:x}){const b=n===e.threadId,C=t?`${x??KT}`:`${v??VT}`,k=S=>{S.stopPropagation(),o(e.threadId)};return c.jsxs("div",{onClick:k,className:`${WT} ${C}`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:b?c.jsxs("div",{className:"flex items-center gap-2",onClick:S=>S.stopPropagation(),children:[c.jsx(Js,{value:r,onChange:S=>i(S.target.value),onKeyDown:S=>{S.key==="Enter"?a(e.threadId):S.key==="Escape"&&l()},className:"h-6 text-sm",autoFocus:!0}),c.jsx(et,{variant:"ghost",size:"sm",onClick:()=>a(e.threadId),className:"h-6 w-6 p-0",children:c.jsx(ae.Check,{size:12})}),c.jsx(et,{variant:"ghost",size:"sm",onClick:l,className:"h-6 w-6 p-0",children:c.jsx(ae.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:y(e)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(ae.Calendar,{size:10}),c.jsx("span",{children:p(e.updatedAt||e.createdAt)})]}),g&&c.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:g})]})}),c.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:c.jsxs(aa,{children:[c.jsx(la,{asChild:!0,children:c.jsx(et,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:c.jsx(ae.MoreHorizontal,{size:12})})}),c.jsxs(xs,{align:"end",sideOffset:6,className:"w-44",children:[c.jsxs(Jn,{onClick:S=>{S.preventDefault(),u(e.threadId)},children:[c.jsx(ae.Share2,{className:"mr-2 h-4 w-4"}),"Share thread"]}),f&&n!==e.threadId&&c.jsxs(Jn,{onClick:S=>{S.preventDefault(),s(e,S)},children:[c.jsx(ae.Edit3,{className:"mr-2 h-4 w-4"}),"Rename"]}),h&&d&&c.jsxs(Jn,{className:"text-red-400 hover:text-red-300",onClick:S=>{S.preventDefault(),d(e.threadId,S)},children:[c.jsx(ae.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})})]}),t&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]})}const xp=25,yp="thread-manager-view",GT=e=>e==="default"||e==="shared",YT=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(yp);if(GT(e))return e}catch{}return null};function XT({defaultView:e}={}){const[t,n]=w.useState(()=>YT()??e??"default");w.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(yp,t)}catch{}},[t]);const r=w.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const JT=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function ol({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d,view:f,defaultView:h,onViewChange:p,viewOptions:y,viewState:g,showHeader:v=!0,shareTargets:x,isLoadingShareTargets:b,shareTargetFilter:C}){const{threads:k,sharedThreads:S,currentThreadId:T,setCurrentThreadId:E,isLoading:A,isLoadingSharedThreads:P,actions:$,shareInFlight:B,shareStatus:V,clearShareStatus:G}=Fo(),{createThread:O,deleteThread:U,renameThread:N,shareThread:D}=$,{loadThread:M}=Bo(),j=i??T,[H,W]=w.useState(Array.isArray(k)?k:[]),R=w.useRef(H.length>0),K=w.useRef(null),ie=w.useRef(0),[Q,oe]=w.useState(null),[Y,L]=w.useState(""),[q,z]=w.useState(!1),[Z,X]=w.useState(!1),[ge,le]=w.useState(null),[te,fe]=w.useState(""),ye=y&&y.length>0?y:JT,Me=XT({defaultView:h}),Ne=g??Me,$e=f??Ne.view,Xe=w.useCallback(_=>{f||Ne.setView(_),p==null||p(_)},[f,p,Ne]),nt=ye.find(_=>_.key===$e)??ye[0],Ve=_=>{le(_),fe(""),X(!0)},qe=()=>{X(!1),le(null),fe(""),G()},ot=w.useCallback(async _=>{if(!(!ge||B)&&_.id)try{await D(ge,_.id),setTimeout(()=>qe(),600)}catch(se){console.error("Failed to share thread:",se)}},[qe,B,ge,D]),kt=w.useMemo(()=>{const _=x??[],se=te.trim().toLowerCase();return se?C?_.filter(pe=>C(pe,se)):_.filter(pe=>`${pe.label} ${pe.secondaryLabel??""}`.toLowerCase().includes(se)):_},[x,te,C]),lt=$e==="shared",ke=lt?S:H,Oe=lt?P:A,at=lt?"No shared conversations yet":"No conversations yet",pt=_=>{const se=_.sharedAt?` • ${bt(_.sharedAt)}`:"";return`Shared by ${_.sharedByUserId}${se}`},Et=_=>"sharedByUserId"in _;w.useEffect(()=>{const _=Array.isArray(k)?k:[];if(_.length>0){R.current=!0,W(_);return}A||(R.current=!1,W(_))},[k,A]),w.useEffect(()=>{if(!K.current)return;const _=K.current.querySelector("[data-radix-scroll-area-viewport]");if(!_)return;let se=null,pe=null;return se=requestAnimationFrame(()=>{pe=requestAnimationFrame(()=>{_.scrollTop=ie.current})}),()=>{se!==null&&cancelAnimationFrame(se),pe!==null&&cancelAnimationFrame(pe)}},[H]);const Ct=async _=>{try{E(_),await M(_,void 0,{clearProgress:!0}),a==null||a(_),l==null||l(_)}catch(se){console.error("Failed to select thread:",se)}},Le=async()=>{try{z(!0);const _=await O();_&&(u==null||u(_),a==null||a(_))}catch(_){console.error("Failed to create thread:",_)}finally{z(!1)}},Vt=async(_,se)=>{if(se.stopPropagation(),!!confirm("Delete this thread?")){if(K.current){const pe=K.current.querySelector("[data-radix-scroll-area-viewport]");pe&&(ie.current=pe.scrollTop)}try{await U(_),d==null||d(_)}catch(pe){console.error("Failed to delete thread:",pe)}}},Je=(_,se)=>{se.stopPropagation(),oe(_.threadId),L(_.title||`Thread ${_.threadId.slice(0,8)}`)},Ke=async _=>{if(Y.trim())try{await N(_,Y.trim()),oe(null),L("")}catch(se){console.error("Failed to update title:",se)}},dt=()=>{oe(null),L("")},bt=_=>{if(!_)return"";try{const se=new Date(_),We=new Date().getTime()-se.getTime(),Pe=Math.floor(We/(1e3*60*60*24));return Pe===0?se.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Pe===1?"Yesterday":Pe<7?`${Pe} days ago`:se.toLocaleDateString()}catch{return""}},He=_=>_.title||`Thread ${_.threadId.slice(0,8)}`,Tt=_=>{const se=He(_);return se.length<=xp?se:`${se.slice(0,xp)}...`};return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[v&&c.jsxs("div",{className:s.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&c.jsx("div",{className:"flex justify-end",children:c.jsxs(et,{onClick:Le,disabled:q||A,className:s.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:q?"Creating...":"New Chat",children:[c.jsx(ae.Edit3,{size:16}),c.jsx("span",{children:"New chat"})]})}),c.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[c.jsx("span",{children:"Current View"}),c.jsxs(aa,{children:[c.jsx(la,{asChild:!0,children:c.jsx(et,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:nt.label})}),c.jsx(xs,{align:"start",sideOffset:6,className:"w-40",children:ye.map(_=>c.jsxs(Jn,{className:"justify-between text-[12px]",onClick:se=>{se.preventDefault(),Xe(_.key)},children:[c.jsx("span",{children:_.label}),$e===_.key&&c.jsx(ae.Check,{className:"h-3 w-3"})]},_.key))})]})]})]}),c.jsx(mp,{ref:K,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:Oe?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(ae.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):ke.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(ae.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:at})]}):ke.slice().sort((_,se)=>new Date(se.updatedAt||se.createdAt||"").getTime()-new Date(_.updatedAt||_.createdAt||"").getTime()).map(_=>c.jsx(qT,{thread:_,isActive:j===_.threadId,editingThreadId:Q,editingTitle:Y,onSelect:Ct,onStartEditing:Je,onEditingTitleChange:se=>L(se),onSaveEditing:Ke,onCancelEditing:dt,onShare:()=>Ve(_.threadId),onDelete:Vt,showEditTitle:r,showDeleteButton:n,formatDate:bt,getDisplayThreadTitle:Tt,secondaryLine:lt&&Et(_)?pt(_):void 0,itemClassName:s.threadItem,activeItemClassName:s.activeThread},_.threadId))})}),c.jsx(mh,{open:Z,onOpenChange:_=>!_&&qe(),children:c.jsxs($a,{className:"max-w-md p-0",children:[c.jsx(Fa,{children:c.jsx(Ba,{children:"Share thread"})}),c.jsxs(Yh,{children:[c.jsx(Xh,{autoFocus:!0,value:te,onValueChange:_=>fe(_),placeholder:"Search for recipients..."}),c.jsxs(Jh,{children:[V&&c.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[B&&c.jsx(ae.Loader2,{className:"h-3 w-3 animate-spin"}),c.jsx("span",{className:V.startsWith("Failed")?"text-red-500":V.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:V})]}),c.jsx(Zh,{children:b?c.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading recipients…"]}):"No matching recipients found"}),kt.length>0&&c.jsx(Qh,{heading:"Recipients",children:kt.map(_=>c.jsx(ep,{onSelect:()=>ot(_),children:c.jsxs("div",{className:"flex flex-col items-start text-sm",children:[c.jsx("span",{className:"font-medium",children:_.label}),_.secondaryLabel&&c.jsx("span",{className:"text-xs text-muted-foreground",children:_.secondaryLabel})]})},_.id))})]})]})]})})]})}const ZT=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,u=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const h=["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 c.jsxs("div",{className:h,onMouseEnter:s,onMouseLeave:i,children:[c.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[c.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:c.jsx("span",{children:"Timeline"})}),c.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),c.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:u.map(p=>{const y=d===p.id,g=(r==null?void 0:r.get(p.id))??null;return c.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(p.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${y?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[c.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${y?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:c.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${y?"bg-primary":"bg-border"}`})}),c.jsxs("span",{className:"flex-1",children:[c.jsx("span",{className:"block font-medium leading-tight",children:p.label||"User input"}),c.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[p.step!==null?`STEP ${p.step}`:"STEP —",p.next?` - ${p.next}`:""]}),g&&c.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:g,children:g})]})]},p.id)})})]}),n&&c.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 Ar(e){if(!(typeof globalThis>"u"))return globalThis[e]}function QT(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function vp(){const e=[Ar("__API_BASE_URL__"),Ar("__CHAT_API_BASE_URL__"),Ar("__CHAT_API_URL__")];for(const t of e){const n=QT(t);if(n)return n}}function bp(){const e=[Ar("__API_AUTH_TOKEN__"),Ar("__CHAT_API_KEY__"),Ar("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function wp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Sp(){const e={},t=vp(),n=bp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Cp(){const e=Sp(),t=Nn.getAuthToken(),n=vp();return{apiBaseUrl:wp(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||bp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Tp="chat-settings";function ek(){try{const e=localStorage.getItem(Tp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function tk(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem(Tp,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function nk(){const e=Cp(),t=ek(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:wp(Nn.baseUrl,r,e.apiBaseUrl)}}function rk(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),tk(e)}var ok="Label",kp=m.forwardRef((e,t)=>c.jsx(we.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));kp.displayName=ok;var Ep=kp;const sk=bo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),rn=m.forwardRef(({className:e,...t},n)=>c.jsx(Ep,{ref:n,className:ne(sk(),e),...t}));rn.displayName=Ep.displayName;function Ip(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Np=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),ik="VisuallyHidden",ak=m.forwardRef((e,t)=>c.jsx(we.span,{...e,ref:t,style:{...Np,...e.style}}));ak.displayName=ik;var lk=[" ","Enter","ArrowUp","ArrowDown"],ck=[" ","Enter"],ir="Select",[Zs,Qs,uk]=Ei(ir),[jr,_E]=Tn(ir,[uk,ts]),ei=ts(),[dk,Bn]=jr(ir),[fk,hk]=jr(ir),Ap=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:y}=e,g=ei(t),[v,x]=m.useState(null),[b,C]=m.useState(null),[k,S]=m.useState(!1),T=Uo(u),[E,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:ir}),[P,$]=pr({prop:i,defaultProp:a,onChange:l,caller:ir}),B=m.useRef(null),V=v?y||!!v.closest("form"):!0,[G,O]=m.useState(new Set),U=Array.from(G).map(N=>N.props.value).join(";");return c.jsx(ju,{...g,children:c.jsxs(dk,{required:p,scope:t,trigger:v,onTriggerChange:x,valueNode:b,onValueNodeChange:C,valueNodeHasChildren:k,onValueNodeHasChildrenChange:S,contentId:$t(),value:P,onValueChange:$,open:E,onOpenChange:A,dir:T,triggerPointerDownPosRef:B,disabled:h,children:[c.jsx(Zs.Provider,{scope:t,children:c.jsx(fk,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(N=>{O(D=>new Set(D).add(N))},[]),onNativeOptionRemove:m.useCallback(N=>{O(D=>{const M=new Set(D);return M.delete(N),M})},[]),children:n})}),V?c.jsxs(Qp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:P,onChange:N=>$(N.target.value),disabled:h,form:y,children:[P===void 0?c.jsx("option",{value:""}):null,Array.from(G)]},U):null]})})};Ap.displayName=ir;var jp="SelectTrigger",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=ei(n),i=Bn(jp,n),a=i.disabled||r,l=ze(t,i.onTriggerChange),u=Qs(n),d=m.useRef("touch"),[f,h,p]=tm(g=>{const v=u().filter(C=>!C.disabled),x=v.find(C=>C.value===i.value),b=nm(v,g,x);b!==void 0&&i.onValueChange(b.value)}),y=g=>{a||(i.onOpenChange(!0),p()),g&&(i.triggerPointerDownPosRef.current={x:Math.round(g.pageX),y:Math.round(g.pageY)})};return c.jsx(_u,{asChild:!0,...s,children:c.jsx(we.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":em(i.value)?"":void 0,...o,ref:l,onClick:he(o.onClick,g=>{g.currentTarget.focus(),d.current!=="mouse"&&y(g)}),onPointerDown:he(o.onPointerDown,g=>{d.current=g.pointerType;const v=g.target;v.hasPointerCapture(g.pointerId)&&v.releasePointerCapture(g.pointerId),g.button===0&&g.ctrlKey===!1&&g.pointerType==="mouse"&&(y(g),g.preventDefault())}),onKeyDown:he(o.onKeyDown,g=>{const v=f.current!=="";!(g.ctrlKey||g.altKey||g.metaKey)&&g.key.length===1&&h(g.key),!(v&&g.key===" ")&&lk.includes(g.key)&&(y(),g.preventDefault())})})})});_p.displayName=jp;var Mp="SelectValue",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Mp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=ze(t,l.onValueNodeChange);return Nt(()=>{u(d)},[u,d]),c.jsx(we.span,{...a,ref:f,style:{pointerEvents:"none"},children:em(l.value)?c.jsx(c.Fragment,{children:i}):s})});Rp.displayName=Mp;var pk="SelectIcon",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(we.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Pp.displayName=pk;var mk="SelectPortal",Op=e=>c.jsx(ns,{asChild:!0,...e});Op.displayName=mk;var ar="SelectContent",Dp=m.forwardRef((e,t)=>{const n=Bn(ar,e.__scopeSelect),[r,o]=m.useState();if(Nt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?wo.createPortal(c.jsx(Lp,{scope:e.__scopeSelect,children:c.jsx(Zs.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx($p,{...e,ref:t})});Dp.displayName=ar;var fn=10,[Lp,zn]=jr(ar),gk="SelectContentImpl",xk=Wn.createSlot("SelectContent.RemoveScroll"),$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:y,hideWhenDetached:g,avoidCollisions:v,...x}=e,b=Bn(ar,n),[C,k]=m.useState(null),[S,T]=m.useState(null),E=ze(t,Y=>k(Y)),[A,P]=m.useState(null),[$,B]=m.useState(null),V=Qs(n),[G,O]=m.useState(!1),U=m.useRef(!1);m.useEffect(()=>{if(C)return Gi(C)},[C]),Ai();const N=m.useCallback(Y=>{const[L,...q]=V().map(X=>X.ref.current),[z]=q.slice(-1),Z=document.activeElement;for(const X of Y)if(X===Z||(X==null||X.scrollIntoView({block:"nearest"}),X===L&&S&&(S.scrollTop=0),X===z&&S&&(S.scrollTop=S.scrollHeight),X==null||X.focus(),document.activeElement!==Z))return},[V,S]),D=m.useCallback(()=>N([A,C]),[N,A,C]);m.useEffect(()=>{G&&D()},[G,D]);const{onOpenChange:M,triggerPointerDownPosRef:j}=b;m.useEffect(()=>{if(C){let Y={x:0,y:0};const L=z=>{var Z,X;Y={x:Math.abs(Math.round(z.pageX)-(((Z=j.current)==null?void 0:Z.x)??0)),y:Math.abs(Math.round(z.pageY)-(((X=j.current)==null?void 0:X.y)??0))}},q=z=>{Y.x<=10&&Y.y<=10?z.preventDefault():C.contains(z.target)||M(!1),document.removeEventListener("pointermove",L),j.current=null};return j.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",q,{capture:!0})}}},[C,M,j]),m.useEffect(()=>{const Y=()=>M(!1);return window.addEventListener("blur",Y),window.addEventListener("resize",Y),()=>{window.removeEventListener("blur",Y),window.removeEventListener("resize",Y)}},[M]);const[H,W]=tm(Y=>{const L=V().filter(Z=>!Z.disabled),q=L.find(Z=>Z.ref.current===document.activeElement),z=nm(L,Y,q);z&&setTimeout(()=>z.ref.current.focus())}),R=m.useCallback((Y,L,q)=>{const z=!U.current&&!q;(b.value!==void 0&&b.value===L||z)&&(P(Y),z&&(U.current=!0))},[b.value]),K=m.useCallback(()=>C==null?void 0:C.focus(),[C]),ie=m.useCallback((Y,L,q)=>{const z=!U.current&&!q;(b.value!==void 0&&b.value===L||z)&&B(Y)},[b.value]),Q=r==="popper"?sl:Fp,oe=Q===sl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:y,hideWhenDetached:g,avoidCollisions:v}:{};return c.jsx(Lp,{scope:n,content:C,viewport:S,onViewportChange:T,itemRefCallback:R,selectedItem:A,onItemLeave:K,itemTextRefCallback:ie,focusSelectedItem:D,selectedItemText:$,position:r,isPositioned:G,searchRef:H,children:c.jsx(ds,{as:xk,allowPinchZoom:!0,children:c.jsx(Wo,{asChild:!0,trapped:b.open,onMountAutoFocus:Y=>{Y.preventDefault()},onUnmountAutoFocus:he(o,Y=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),Y.preventDefault()}),children:c.jsx(Ho,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Y=>Y.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(Q,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Y=>Y.preventDefault(),...x,...oe,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:he(x.onKeyDown,Y=>{const L=Y.ctrlKey||Y.altKey||Y.metaKey;if(Y.key==="Tab"&&Y.preventDefault(),!L&&Y.key.length===1&&W(Y.key),["ArrowUp","ArrowDown","Home","End"].includes(Y.key)){let z=V().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);if(["ArrowUp","End"].includes(Y.key)&&(z=z.slice().reverse()),["ArrowUp","ArrowDown"].includes(Y.key)){const Z=Y.target,X=z.indexOf(Z);z=z.slice(X+1)}setTimeout(()=>N(z)),Y.preventDefault()}})})})})})})});$p.displayName=gk;var yk="SelectItemAlignedPosition",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ar,n),i=zn(ar,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=ze(t,E=>d(E)),h=Qs(n),p=m.useRef(!1),y=m.useRef(!0),{viewport:g,selectedItem:v,selectedItemText:x,focusSelectedItem:b}=i,C=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&g&&v&&x){const E=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),P=s.valueNode.getBoundingClientRect(),$=x.getBoundingClientRect();if(s.dir!=="rtl"){const Z=$.left-A.left,X=P.left-Z,ge=E.left-X,le=E.width+ge,te=Math.max(le,A.width),fe=window.innerWidth-fn,ye=Qa(X,[fn,Math.max(fn,fe-te)]);a.style.minWidth=le+"px",a.style.left=ye+"px"}else{const Z=A.right-$.right,X=window.innerWidth-P.right-Z,ge=window.innerWidth-E.right-X,le=E.width+ge,te=Math.max(le,A.width),fe=window.innerWidth-fn,ye=Qa(X,[fn,Math.max(fn,fe-te)]);a.style.minWidth=le+"px",a.style.right=ye+"px"}const B=h(),V=window.innerHeight-fn*2,G=g.scrollHeight,O=window.getComputedStyle(u),U=parseInt(O.borderTopWidth,10),N=parseInt(O.paddingTop,10),D=parseInt(O.borderBottomWidth,10),M=parseInt(O.paddingBottom,10),j=U+N+G+M+D,H=Math.min(v.offsetHeight*5,j),W=window.getComputedStyle(g),R=parseInt(W.paddingTop,10),K=parseInt(W.paddingBottom,10),ie=E.top+E.height/2-fn,Q=V-ie,oe=v.offsetHeight/2,Y=v.offsetTop+oe,L=U+N+Y,q=j-L;if(L<=ie){const Z=B.length>0&&v===B[B.length-1].ref.current;a.style.bottom="0px";const X=u.clientHeight-g.offsetTop-g.offsetHeight,ge=Math.max(Q,oe+(Z?K:0)+X+D),le=L+ge;a.style.height=le+"px"}else{const Z=B.length>0&&v===B[0].ref.current;a.style.top="0px";const ge=Math.max(ie,U+g.offsetTop+(Z?R:0)+oe)+q;a.style.height=ge+"px",g.scrollTop=L-ie+g.offsetTop}a.style.margin=`${fn}px 0`,a.style.minHeight=H+"px",a.style.maxHeight=V+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,g,v,x,s.dir,r]);Nt(()=>C(),[C]);const[k,S]=m.useState();Nt(()=>{u&&S(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(E=>{E&&y.current===!0&&(C(),b==null||b(),y.current=!1)},[C,b]);return c.jsx(bk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:c.jsx(we.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fp.displayName=yk;var vk="SelectPopperPosition",sl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=fn,...s}=e,i=ei(n);return c.jsx(Mu,{...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)"}})});sl.displayName=vk;var[bk,il]=jr(ar,{}),al="SelectViewport",Bp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn(al,n),i=il(al,n),a=ze(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(Zs.Slot,{scope:n,children:c.jsx(we.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:he(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const y=window.innerHeight-fn*2,g=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),x=Math.max(g,v);if(x<y){const b=x+p,C=Math.min(y,b),k=b-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Bp.displayName=al;var zp="SelectGroup",[wk,Sk]=jr(zp),Ck=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=$t();return c.jsx(wk,{scope:n,id:o,children:c.jsx(we.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Ck.displayName=zp;var Up="SelectLabel",Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sk(Up,n);return c.jsx(we.div,{id:o.id,...r,ref:t})});Hp.displayName=Up;var ti="SelectItem",[Tk,Wp]=jr(ti),Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(ti,n),l=zn(ti,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),y=ze(t,b=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,b,r,o)}),g=$t(),v=m.useRef("touch"),x=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(Tk,{scope:n,value:r,disabled:o,textId:g,isSelected:u,onItemTextChange:m.useCallback(b=>{f(C=>C||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(Zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(we.div,{role:"option","aria-labelledby":g,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:y,onFocus:he(i.onFocus,()=>p(!0)),onBlur:he(i.onBlur,()=>p(!1)),onClick:he(i.onClick,()=>{v.current!=="mouse"&&x()}),onPointerUp:he(i.onPointerUp,()=>{v.current==="mouse"&&x()}),onPointerDown:he(i.onPointerDown,b=>{v.current=b.pointerType}),onPointerMove:he(i.onPointerMove,b=>{var C;v.current=b.pointerType,o?(C=l.onItemLeave)==null||C.call(l):v.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:he(i.onPointerLeave,b=>{var C;b.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:he(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(ck.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});Vp.displayName=ti;var xo="SelectItemText",Kp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(xo,n),a=zn(xo,n),l=Wp(xo,n),u=hk(xo,n),[d,f]=m.useState(null),h=ze(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),p=d==null?void 0:d.textContent,y=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:g,onNativeOptionRemove:v}=u;return Nt(()=>(g(y),()=>v(y)),[g,v,y]),c.jsxs(c.Fragment,{children:[c.jsx(we.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?wo.createPortal(s.children,i.valueNode):null]})});Kp.displayName=xo;var qp="SelectItemIndicator",Gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Wp(qp,n).isSelected?c.jsx(we.span,{"aria-hidden":!0,...r,ref:t}):null});Gp.displayName=qp;var ll="SelectScrollUpButton",Yp=m.forwardRef((e,t)=>{const n=zn(ll,e.__scopeSelect),r=il(ll,e.__scopeSelect),[o,s]=m.useState(!1),i=ze(t,r.onScrollButtonChange);return Nt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Jp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Yp.displayName=ll;var cl="SelectScrollDownButton",Xp=m.forwardRef((e,t)=>{const n=zn(cl,e.__scopeSelect),r=il(cl,e.__scopeSelect),[o,s]=m.useState(!1),i=ze(t,r.onScrollButtonChange);return Nt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Jp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Xp.displayName=cl;var Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=m.useRef(null),a=Qs(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),Nt(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(we.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:he(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:he(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:he(o.onPointerLeave,()=>{l()})})}),kk="SelectSeparator",Zp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(we.div,{"aria-hidden":!0,...r,ref:t})});Zp.displayName=kk;var ul="SelectArrow",Ek=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=ei(n),s=Bn(ul,n),i=zn(ul,n);return s.open&&i.position==="popper"?c.jsx(Ru,{...o,...r,ref:t}):null});Ek.displayName=ul;var Ik="SelectBubbleInput",Qp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=ze(r,o),i=Ip(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(we.select,{...n,style:{...Np,...n.style},ref:s,defaultValue:t})});Qp.displayName=Ik;function em(e){return e===""||e===void 0}function tm(e){const t=At(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function nm(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=Nk(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Nk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ak=Ap,rm=_p,jk=Rp,_k=Pp,Mk=Op,om=Dp,Rk=Bp,sm=Hp,im=Vp,Pk=Kp,Ok=Gp,am=Yp,lm=Xp,cm=Zp;const um=Ak,dm=jk,dl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(rm,{ref:r,className:ne("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(_k,{asChild:!0,children:c.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));dl.displayName=rm.displayName;const fm=m.forwardRef(({className:e,...t},n)=>c.jsx(am,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const hm=m.forwardRef(({className:e,...t},n)=>c.jsx(lm,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));hm.displayName=lm.displayName;const fl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(Mk,{children:c.jsxs(om,{ref:o,className:ne("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(fm,{}),c.jsx(Rk,{className:ne("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(hm,{})]})}));fl.displayName=om.displayName;const Dk=m.forwardRef(({className:e,...t},n)=>c.jsx(sm,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Dk.displayName=sm.displayName;const lr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(im,{ref:r,className:ne("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Ok,{children:c.jsx(ae.Check,{className:"h-4 w-4"})})}),c.jsx(Pk,{children:t})]}));lr.displayName=im.displayName;const Lk=m.forwardRef(({className:e,...t},n)=>c.jsx(cm,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));Lk.displayName=cm.displayName;var $k="Separator",pm="horizontal",Fk=["horizontal","vertical"],mm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=pm,...o}=e,s=Bk(r)?r:pm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(we.div,{"data-orientation":s,...a,...o,ref:t})});mm.displayName=$k;function Bk(e){return Fk.includes(e)}var gm=mm;const xm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(gm,{ref:o,decorative:n,orientation:t,className:ne("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));xm.displayName=gm.displayName;const zk=Da,Uk=yC,Hk=La,ym=m.forwardRef(({className:e,...t},n)=>c.jsx(io,{className:ne("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}));ym.displayName=io.displayName;const Wk=bo.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"}}),vm=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(Hk,{children:[c.jsx(ym,{}),c.jsxs(ao,{ref:o,className:ne(Wk({side:e}),t),...r,children:[n,c.jsxs(ph,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(ae.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));vm.displayName=ao.displayName;const bm=({className:e,...t})=>c.jsx("div",{className:ne("flex flex-col space-y-2 text-center sm:text-left",e),...t});bm.displayName="SheetHeader";const wm=m.forwardRef(({className:e,...t},n)=>c.jsx(rr,{ref:n,className:ne("text-lg font-semibold text-foreground",e),...t}));wm.displayName=rr.displayName;const Sm=m.forwardRef(({className:e,...t},n)=>c.jsx(Ls,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));Sm.displayName=Ls.displayName;var ni="Switch",[Vk,ME]=Tn(ni),[Kk,qk]=Vk(ni),Cm=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),y=ze(t,C=>p(C)),g=m.useRef(!1),v=h?d||!!h.closest("form"):!0,[x,b]=pr({prop:o,defaultProp:s??!1,onChange:u,caller:ni});return c.jsxs(Kk,{scope:n,checked:x,disabled:a,children:[c.jsx(we.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":Im(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:y,onClick:he(e.onClick,C=>{b(k=>!k),v&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})}),v&&c.jsx(Em,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Cm.displayName=ni;var Tm="SwitchThumb",km=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=qk(Tm,n);return c.jsx(we.span,{"data-state":Im(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});km.displayName=Tm;var Gk="SwitchBubbleInput",Em=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=ze(i,s),l=Ip(n),u=bu(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const y=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(y)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Em.displayName=Gk;function Im(e){return e?"checked":"unchecked"}var Nm=Cm,Yk=km;const Un=m.forwardRef(({className:e,...t},n)=>c.jsx(Nm,{className:ne("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(Yk,{className:ne("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=Nm.displayName;const Xk={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 Jk({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[u,d]=w.useState(!1),{toast:f}=Ha();w.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);d(v)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(Xk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},y=()=>{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 c.jsxs(zk,{open:r,onOpenChange:o,children:[c.jsx(Uk,{asChild:!0,children:c.jsxs(et,{variant:"outline",size:"sm",className:n,children:[c.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Kf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(vm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(bm,{children:[c.jsx(wm,{children:"Chat Settings"}),c.jsx(Sm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(uo,{children:[c.jsx(fo,{className:"pb-3",children:c.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[c.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(po,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Js,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(x=>({...x,api:{...x.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(et,{variant:"outline",onClick:g,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(x=>({...x,api:{...x.api,enableAuth:v}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Js,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(x=>({...x,api:{...x.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(et,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(ae.EyeOff,{className:"h-4 w-4"}):c.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(uo,{children:[c.jsx(fo,{className:"pb-3",children:c.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[c.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(po,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(um,{value:a.ui.layout,onValueChange:v=>l(x=>({...x,ui:{...x.ui,layout:v}})),children:[c.jsx(dl,{children:c.jsx(dm,{})}),c.jsxs(fl,{children:[c.jsx(lr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(lr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(lr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(rn,{htmlFor:"theme",children:"Theme"}),c.jsxs(um,{value:a.ui.theme,onValueChange:v=>l(x=>({...x,ui:{...x.ui,theme:v}})),children:[c.jsx(dl,{children:c.jsx(dm,{})}),c.jsxs(fl,{children:[c.jsx(lr,{value:"light",children:"Light"}),c.jsx(lr,{value:"dark",children:"Dark"}),c.jsx(lr,{value:"system",children:"System"})]})]})]}),c.jsx(xm,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showTimestamps:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,showAgentNames:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(rn,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(x=>({...x,ui:{...x.ui,compactMessages:v}}))})]})]})]})]}),c.jsxs(uo,{children:[c.jsx(fo,{className:"pb-3",children:c.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[c.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(po,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(rn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,autoSave:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(rn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:v}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(rn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:v}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(et,{variant:"outline",onClick:p,children:[c.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(et,{variant:"outline",onClick:y,children:"Cancel"}),c.jsxs(et,{onClick:h,disabled:!u,children:[c.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function Zk({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),l=w.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(zo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Vs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(zo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ol,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Vs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(zo,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ol,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Vs,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=cc,Ce.ChatInput=$c,Ce.ChatInterface=Vs,Ce.ChatProviders=zo,Ce.ChatSettings=Jk,Ce.MarkdownContent=co,Ce.MessageComponent=Ws,Ce.MessageList=Ka,Ce.ThreadManager=ol,Ce.TimelineColumn=ZT,Ce.applySettings=rk,Ce.buildMessagePreviewMap=cx,Ce.chatApiClient=Nn,Ce.default=Zk,Ce.del=bi,Ce.get=Kt,Ce.getChatToken=ic,Ce.getCurrentSettings=nk,Ce.getDefaultApiConfig=Sp,Ce.getDefaultChatSettings=Cp,Ce.onChatTokenChanged=ac,Ce.post=Po,Ce.put=lc,Ce.setChatToken=Ro,Ce.useApi=wi,Ce.useChatStream=_c,Ce.useMessagesReducer=Ac,Ce.useStream=Dc,Ce.useThreadState=Bo,Ce.useThreads=Fo,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});