teodor-new-chat-ui 4.3.299 → 4.3.301

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(Ee,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):(Ee=typeof globalThis<"u"?globalThis:Ee||self,w(Ee.NewChatUI={},Ee.React,Ee.LucideReact,Ee.reactSlot,Ee.classVarianceAuthority,Ee.clsx,Ee.tailwindMerge,Ee.ReactDOM))})(this,function(Ee,w,le,Un,fo,Vh,Kh,Ks){"use strict";var JC=Object.defineProperty;var ZC=(Ee,w,le)=>w in Ee?JC(Ee,w,{enumerable:!0,configurable:!0,writable:!0,value:le}):Ee[w]=le;var Uh=(Ee,w,le)=>ZC(Ee,typeof w!="symbol"?w+"":w,le);function Ga(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const y=Ga(w),po=Ga(Ks);var qs={exports:{}},Er={};/**
1
+ (function(Ee,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):(Ee=typeof globalThis<"u"?globalThis:Ee||self,w(Ee.NewChatUI={},Ee.React,Ee.LucideReact,Ee.reactSlot,Ee.classVarianceAuthority,Ee.clsx,Ee.tailwindMerge,Ee.ReactDOM))})(this,function(Ee,w,le,Wn,po,Kh,qh,qs){"use strict";var tT=Object.defineProperty;var nT=(Ee,w,le)=>w in Ee?tT(Ee,w,{enumerable:!0,configurable:!0,writable:!0,value:le}):Ee[w]=le;var Wh=(Ee,w,le)=>nT(Ee,typeof w!="symbol"?w+"":w,le);var Gs=typeof document<"u"?document.currentScript:null;function Xa(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const y=Xa(w),ho=Xa(qs);var Ys={exports:{}},Ir={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Ya;function qh(){if(Ya)return Er;Ya=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:p,ref:h,props:f,_owner:o.current}}return Er.Fragment=n,Er.jsx=i,Er.jsxs=i,Er}var Ir={};/**
9
+ */var Ja;function Gh(){if(Ja)return Ir;Ja=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:p,ref:h,props:f,_owner:o.current}}return Ir.Fragment=n,Ir.jsx=i,Ir.jsxs=i,Ir}var Nr={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,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 Xa;function Gh(){return Xa||(Xa=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),x=Symbol.iterator,m="@@iterator";function v(I){if(I===null||typeof I!="object")return null;var W=x&&I[x]||I[m];return typeof W=="function"?W:null}var g=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(I){{for(var W=arguments.length,ue=new Array(W>1?W-1:0),ke=1;ke<W;ke++)ue[ke-1]=arguments[ke];S("error",I,ue)}}function S(I,W,ue){{var ke=g.ReactDebugCurrentFrame,Ze=ke.getStackAddendum();Ze!==""&&(W+="%s",ue=ue.concat([Ze]));var st=ue.map(function(We){return String(We)});st.unshift("Warning: "+W),Function.prototype.apply.call(console[I],console,st)}}var k=!1,C=!1,T=!1,E=!1,N=!1,j;j=Symbol.for("react.module.reference");function $(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||N||I===o||I===c||I===d||E||I===h||k||C||T||typeof I=="object"&&I!==null&&(I.$$typeof===p||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===j||I.getModuleId!==void 0))}function P(I,W,ue){var ke=I.displayName;if(ke)return ke;var Ze=W.displayName||W.name||"";return Ze!==""?ue+"("+Ze+")":ue}function D(I){return I.displayName||"Context"}function F(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 c:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var W=I;return D(W)+".Consumer";case i:var ue=I;return D(ue._context)+".Provider";case l:return P(I,I.render,"ForwardRef");case f:var ke=I.displayName||null;return ke!==null?ke:F(I.type)||"Memo";case p:{var Ze=I,st=Ze._payload,We=Ze._init;try{return F(We(st))}catch{return null}}}return null}var A=Object.assign,z=0,_,K,B,R,Y,X,se;function ve(){}ve.__reactDisabledLog=!0;function Oe(){{if(z===0){_=console.log,K=console.info,B=console.warn,R=console.error,Y=console.group,X=console.groupCollapsed,se=console.groupEnd;var I={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}z++}}function q(){{if(z--,z===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},I,{value:_}),info:A({},I,{value:K}),warn:A({},I,{value:B}),error:A({},I,{value:R}),group:A({},I,{value:Y}),groupCollapsed:A({},I,{value:X}),groupEnd:A({},I,{value:se})})}z<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var H=g.ReactCurrentDispatcher,J;function L(I,W,ue){{if(J===void 0)try{throw Error()}catch(Ze){var ke=Ze.stack.trim().match(/\n( *(at )?)/);J=ke&&ke[1]||""}return`
18
- `+J+I}}var G=!1,Z;{var fe=typeof WeakMap=="function"?WeakMap:Map;Z=new fe}function re(I,W){if(!I||G)return"";{var ue=Z.get(I);if(ue!==void 0)return ue}var ke;G=!0;var Ze=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var st;st=H.current,H.current=null,Oe();try{if(W){var We=function(){throw Error()};if(Object.defineProperty(We.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(We,[])}catch(ae){ke=ae}Reflect.construct(I,[],We)}else{try{We.call()}catch(ae){ke=ae}I.call(We.prototype)}}else{try{throw Error()}catch(ae){ke=ae}I()}}catch(ae){if(ae&&ke&&typeof ae.stack=="string"){for(var Be=ae.stack.split(`
17
+ */var Za;function Yh(){return Za||(Za=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),x=Symbol.iterator,m="@@iterator";function v(I){if(I===null||typeof I!="object")return null;var W=x&&I[x]||I[m];return typeof W=="function"?W:null}var g=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(I){{for(var W=arguments.length,ue=new Array(W>1?W-1:0),ke=1;ke<W;ke++)ue[ke-1]=arguments[ke];S("error",I,ue)}}function S(I,W,ue){{var ke=g.ReactDebugCurrentFrame,Qe=ke.getStackAddendum();Qe!==""&&(W+="%s",ue=ue.concat([Qe]));var it=ue.map(function(We){return String(We)});it.unshift("Warning: "+W),Function.prototype.apply.call(console[I],console,it)}}var k=!1,C=!1,T=!1,E=!1,N=!1,_;_=Symbol.for("react.module.reference");function $(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||N||I===o||I===c||I===d||E||I===h||k||C||T||typeof I=="object"&&I!==null&&(I.$$typeof===p||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===_||I.getModuleId!==void 0))}function P(I,W,ue){var ke=I.displayName;if(ke)return ke;var Qe=W.displayName||W.name||"";return Qe!==""?ue+"("+Qe+")":ue}function D(I){return I.displayName||"Context"}function F(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 c:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var W=I;return D(W)+".Consumer";case i:var ue=I;return D(ue._context)+".Provider";case l:return P(I,I.render,"ForwardRef");case f:var ke=I.displayName||null;return ke!==null?ke:F(I.type)||"Memo";case p:{var Qe=I,it=Qe._payload,We=Qe._init;try{return F(We(it))}catch{return null}}}return null}var A=Object.assign,z=0,j,K,B,R,Y,X,se;function be(){}be.__reactDisabledLog=!0;function Oe(){{if(z===0){j=console.log,K=console.info,B=console.warn,R=console.error,Y=console.group,X=console.groupCollapsed,se=console.groupEnd;var I={configurable:!0,enumerable:!0,value:be,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}z++}}function q(){{if(z--,z===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},I,{value:j}),info:A({},I,{value:K}),warn:A({},I,{value:B}),error:A({},I,{value:R}),group:A({},I,{value:Y}),groupCollapsed:A({},I,{value:X}),groupEnd:A({},I,{value:se})})}z<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var H=g.ReactCurrentDispatcher,J;function L(I,W,ue){{if(J===void 0)try{throw Error()}catch(Qe){var ke=Qe.stack.trim().match(/\n( *(at )?)/);J=ke&&ke[1]||""}return`
18
+ `+J+I}}var G=!1,Z;{var fe=typeof WeakMap=="function"?WeakMap:Map;Z=new fe}function oe(I,W){if(!I||G)return"";{var ue=Z.get(I);if(ue!==void 0)return ue}var ke;G=!0;var Qe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var it;it=H.current,H.current=null,Oe();try{if(W){var We=function(){throw Error()};if(Object.defineProperty(We.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(We,[])}catch(ae){ke=ae}Reflect.construct(I,[],We)}else{try{We.call()}catch(ae){ke=ae}I.call(We.prototype)}}else{try{throw Error()}catch(ae){ke=ae}I()}}catch(ae){if(ae&&ke&&typeof ae.stack=="string"){for(var Be=ae.stack.split(`
19
19
  `),Rt=ke.stack.split(`
20
20
  `),wt=Be.length-1,St=Rt.length-1;wt>=1&&St>=0&&Be[wt]!==Rt[St];)St--;for(;wt>=1&&St>=0;wt--,St--)if(Be[wt]!==Rt[St]){if(wt!==1||St!==1)do if(wt--,St--,St<0||Be[wt]!==Rt[St]){var Ut=`
21
- `+Be[wt].replace(" at new "," at ");return I.displayName&&Ut.includes("<anonymous>")&&(Ut=Ut.replace("<anonymous>",I.displayName)),typeof I=="function"&&Z.set(I,Ut),Ut}while(wt>=1&&St>=0);break}}}finally{G=!1,H.current=st,q(),Error.prepareStackTrace=Ze}var ne=I?I.displayName||I.name:"",he=ne?L(ne):"";return typeof I=="function"&&Z.set(I,he),he}function Ae(I,W,ue){return re(I,!1)}function qe(I){var W=I.prototype;return!!(W&&W.isReactComponent)}function Fe(I,W,ue){if(I==null)return"";if(typeof I=="function")return re(I,qe(I));if(typeof I=="string")return L(I);switch(I){case c:return L("Suspense");case d:return L("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return Ae(I.render);case f:return Fe(I.type,W,ue);case p:{var ke=I,Ze=ke._payload,st=ke._init;try{return Fe(st(Ze),W,ue)}catch{}}}return""}var Je=Object.prototype.hasOwnProperty,ie={},be=g.ReactDebugCurrentFrame;function je(I){if(I){var W=I._owner,ue=Fe(I.type,I._source,W?W.type:null);be.setExtraStackFrame(ue)}else be.setExtraStackFrame(null)}function De(I,W,ue,ke,Ze){{var st=Function.call.bind(Je);for(var We in I)if(st(I,We)){var Be=void 0;try{if(typeof I[We]!="function"){var Rt=Error((ke||"React class")+": "+ue+" type `"+We+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[We]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Rt.name="Invariant Violation",Rt}Be=I[We](W,We,ke,ue,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(wt){Be=wt}Be&&!(Be instanceof Error)&&(je(Ze),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).",ke||"React class",ue,We,typeof Be),je(null)),Be instanceof Error&&!(Be.message in ie)&&(ie[Be.message]=!0,je(Ze),b("Failed %s type: %s",ue,Be.message),je(null))}}}var Ue=Array.isArray;function Ge(I){return Ue(I)}function ze(I){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ue=W&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ue}}function He(I){try{return Qe(I),!1}catch{return!0}}function Qe(I){return""+I}function Et(I){if(He(I))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ze(I)),Qe(I)}var xt=g.ReactCurrentOwner,lt={key:!0,ref:!0,__self:!0,__source:!0},ft,pt;function yt(I){if(Je.call(I,"ref")){var W=Object.getOwnPropertyDescriptor(I,"ref").get;if(W&&W.isReactWarning)return!1}return I.ref!==void 0}function Nt(I){if(Je.call(I,"key")){var W=Object.getOwnPropertyDescriptor(I,"key").get;if(W&&W.isReactWarning)return!1}return I.key!==void 0}function Ye(I,W){typeof I.ref=="string"&&xt.current}function _t(I,W){{var ue=function(){ft||(ft=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};ue.isReactWarning=!0,Object.defineProperty(I,"key",{get:ue,configurable:!0})}}function Sn(I,W){{var ue=function(){pt||(pt=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};ue.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ue,configurable:!0})}}var et=function(I,W,ue,ke,Ze,st,We){var Be={$$typeof:t,type:I,key:W,ref:ue,props:We,_owner:st};return Be._store={},Object.defineProperty(Be._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Be,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ke}),Object.defineProperty(Be,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ze}),Object.freeze&&(Object.freeze(Be.props),Object.freeze(Be)),Be};function ot(I,W,ue,ke,Ze){{var st,We={},Be=null,Rt=null;ue!==void 0&&(Et(ue),Be=""+ue),Nt(W)&&(Et(W.key),Be=""+W.key),yt(W)&&(Rt=W.ref,Ye(W,Ze));for(st in W)Je.call(W,st)&&!lt.hasOwnProperty(st)&&(We[st]=W[st]);if(I&&I.defaultProps){var wt=I.defaultProps;for(st in wt)We[st]===void 0&&(We[st]=wt[st])}if(Be||Rt){var St=typeof I=="function"?I.displayName||I.name||"Unknown":I;Be&&_t(We,St),Rt&&Sn(We,St)}return et(I,Be,Rt,Ze,ke,xt.current,We)}}var bt=g.ReactCurrentOwner,V=g.ReactDebugCurrentFrame;function ce(I){if(I){var W=I._owner,ue=Fe(I.type,I._source,W?W.type:null);V.setExtraStackFrame(ue)}else V.setExtraStackFrame(null)}var Ce;Ce=!1;function M(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function Q(){{if(bt.current){var I=F(bt.current.type);if(I)return`
21
+ `+Be[wt].replace(" at new "," at ");return I.displayName&&Ut.includes("<anonymous>")&&(Ut=Ut.replace("<anonymous>",I.displayName)),typeof I=="function"&&Z.set(I,Ut),Ut}while(wt>=1&&St>=0);break}}}finally{G=!1,H.current=it,q(),Error.prepareStackTrace=Qe}var ne=I?I.displayName||I.name:"",he=ne?L(ne):"";return typeof I=="function"&&Z.set(I,he),he}function Ae(I,W,ue){return oe(I,!1)}function qe(I){var W=I.prototype;return!!(W&&W.isReactComponent)}function Fe(I,W,ue){if(I==null)return"";if(typeof I=="function")return oe(I,qe(I));if(typeof I=="string")return L(I);switch(I){case c:return L("Suspense");case d:return L("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return Ae(I.render);case f:return Fe(I.type,W,ue);case p:{var ke=I,Qe=ke._payload,it=ke._init;try{return Fe(it(Qe),W,ue)}catch{}}}return""}var Ze=Object.prototype.hasOwnProperty,ie={},we=g.ReactDebugCurrentFrame;function _e(I){if(I){var W=I._owner,ue=Fe(I.type,I._source,W?W.type:null);we.setExtraStackFrame(ue)}else we.setExtraStackFrame(null)}function Le(I,W,ue,ke,Qe){{var it=Function.call.bind(Ze);for(var We in I)if(it(I,We)){var Be=void 0;try{if(typeof I[We]!="function"){var Rt=Error((ke||"React class")+": "+ue+" type `"+We+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[We]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Rt.name="Invariant Violation",Rt}Be=I[We](W,We,ke,ue,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(wt){Be=wt}Be&&!(Be instanceof Error)&&(_e(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).",ke||"React class",ue,We,typeof Be),_e(null)),Be instanceof Error&&!(Be.message in ie)&&(ie[Be.message]=!0,_e(Qe),b("Failed %s type: %s",ue,Be.message),_e(null))}}}var Ue=Array.isArray;function Ge(I){return Ue(I)}function ze(I){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ue=W&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ue}}function He(I){try{return et(I),!1}catch{return!0}}function et(I){return""+I}function Et(I){if(He(I))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ze(I)),et(I)}var xt=g.ReactCurrentOwner,ct={key:!0,ref:!0,__self:!0,__source:!0},ft,pt;function yt(I){if(Ze.call(I,"ref")){var W=Object.getOwnPropertyDescriptor(I,"ref").get;if(W&&W.isReactWarning)return!1}return I.ref!==void 0}function Nt(I){if(Ze.call(I,"key")){var W=Object.getOwnPropertyDescriptor(I,"key").get;if(W&&W.isReactWarning)return!1}return I.key!==void 0}function Ye(I,W){typeof I.ref=="string"&&xt.current}function jt(I,W){{var ue=function(){ft||(ft=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};ue.isReactWarning=!0,Object.defineProperty(I,"key",{get:ue,configurable:!0})}}function Sn(I,W){{var ue=function(){pt||(pt=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};ue.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ue,configurable:!0})}}var tt=function(I,W,ue,ke,Qe,it,We){var Be={$$typeof:t,type:I,key:W,ref:ue,props:We,_owner:it};return Be._store={},Object.defineProperty(Be._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Be,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ke}),Object.defineProperty(Be,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Qe}),Object.freeze&&(Object.freeze(Be.props),Object.freeze(Be)),Be};function ot(I,W,ue,ke,Qe){{var it,We={},Be=null,Rt=null;ue!==void 0&&(Et(ue),Be=""+ue),Nt(W)&&(Et(W.key),Be=""+W.key),yt(W)&&(Rt=W.ref,Ye(W,Qe));for(it in W)Ze.call(W,it)&&!ct.hasOwnProperty(it)&&(We[it]=W[it]);if(I&&I.defaultProps){var wt=I.defaultProps;for(it in wt)We[it]===void 0&&(We[it]=wt[it])}if(Be||Rt){var St=typeof I=="function"?I.displayName||I.name||"Unknown":I;Be&&jt(We,St),Rt&&Sn(We,St)}return tt(I,Be,Rt,Qe,ke,xt.current,We)}}var bt=g.ReactCurrentOwner,V=g.ReactDebugCurrentFrame;function ce(I){if(I){var W=I._owner,ue=Fe(I.type,I._source,W?W.type:null);V.setExtraStackFrame(ue)}else V.setExtraStackFrame(null)}var Ce;Ce=!1;function O(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function Q(){{if(bt.current){var I=F(bt.current.type);if(I)return`
22
22
 
23
- Check the render method of \``+I+"`."}return""}}function oe(I){return""}var Le={};function ge(I){{var W=Q();if(!W){var ue=typeof I=="string"?I:I.displayName||I.name;ue&&(W=`
23
+ Check the render method of \``+I+"`."}return""}}function re(I){return""}var Me={};function ge(I){{var W=Q();if(!W){var ue=typeof I=="string"?I:I.displayName||I.name;ue&&(W=`
24
24
 
25
- Check the top-level render call using <`+ue+">.")}return W}}function ct(I,W){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ue=ge(W);if(Le[ue])return;Le[ue]=!0;var ke="";I&&I._owner&&I._owner!==bt.current&&(ke=" It was passed a child from "+F(I._owner.type)+"."),ce(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.',ue,ke),ce(null)}}function we(I,W){{if(typeof I!="object")return;if(Ge(I))for(var ue=0;ue<I.length;ue++){var ke=I[ue];M(ke)&&ct(ke,W)}else if(M(I))I._store&&(I._store.validated=!0);else if(I){var Ze=v(I);if(typeof Ze=="function"&&Ze!==I.entries)for(var st=Ze.call(I),We;!(We=st.next()).done;)M(We.value)&&ct(We.value,W)}}}function tt(I){{var W=I.type;if(W==null||typeof W=="string")return;var ue;if(typeof W=="function")ue=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))ue=W.propTypes;else return;if(ue){var ke=F(W);De(ue,I.props,"prop",ke,I)}else if(W.PropTypes!==void 0&&!Ce){Ce=!0;var Ze=F(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ze||"Unknown")}typeof W.getDefaultProps=="function"&&!W.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function rn(I){{for(var W=Object.keys(I.props),ue=0;ue<W.length;ue++){var ke=W[ue];if(ke!=="children"&&ke!=="key"){ce(I),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ke),ce(null);break}}I.ref!==null&&(ce(I),b("Invalid attribute `ref` supplied to `React.Fragment`."),ce(null))}}var Vs={};function lo(I,W,ue,ke,Ze,st){{var We=$(I);if(!We){var Be="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(Be+=" 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 Rt=oe();Rt?Be+=Rt:Be+=Q();var wt;I===null?wt="null":Ge(I)?wt="array":I!==void 0&&I.$$typeof===t?(wt="<"+(F(I.type)||"Unknown")+" />",Be=" Did you accidentally export a JSX literal instead of a component?"):wt=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",wt,Be)}var St=ot(I,W,ue,Ze,st);if(St==null)return St;if(We){var Ut=W.children;if(Ut!==void 0)if(ke)if(Ge(Ut)){for(var ne=0;ne<Ut.length;ne++)we(Ut[ne],I);Object.freeze&&Object.freeze(Ut)}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 we(Ut,I)}if(Je.call(W,"key")){var he=F(I),ae=Object.keys(W).filter(function(vt){return vt!=="key"}),Re=ae.length>0?"{key: someKey, "+ae.join(": ..., ")+": ...}":"{key: someKey}";if(!Vs[he+Re]){var ht=ae.length>0?"{"+ae.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+ue+">.")}return W}}function Xe(I,W){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ue=ge(W);if(Me[ue])return;Me[ue]=!0;var ke="";I&&I._owner&&I._owner!==bt.current&&(ke=" It was passed a child from "+F(I._owner.type)+"."),ce(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.',ue,ke),ce(null)}}function xe(I,W){{if(typeof I!="object")return;if(Ge(I))for(var ue=0;ue<I.length;ue++){var ke=I[ue];O(ke)&&Xe(ke,W)}else if(O(I))I._store&&(I._store.validated=!0);else if(I){var Qe=v(I);if(typeof Qe=="function"&&Qe!==I.entries)for(var it=Qe.call(I),We;!(We=it.next()).done;)O(We.value)&&Xe(We.value,W)}}}function st(I){{var W=I.type;if(W==null||typeof W=="string")return;var ue;if(typeof W=="function")ue=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))ue=W.propTypes;else return;if(ue){var ke=F(W);Le(ue,I.props,"prop",ke,I)}else if(W.PropTypes!==void 0&&!Ce){Ce=!0;var Qe=F(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Qe||"Unknown")}typeof W.getDefaultProps=="function"&&!W.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function An(I){{for(var W=Object.keys(I.props),ue=0;ue<W.length;ue++){var ke=W[ue];if(ke!=="children"&&ke!=="key"){ce(I),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ke),ce(null);break}}I.ref!==null&&(ce(I),b("Invalid attribute `ref` supplied to `React.Fragment`."),ce(null))}}var Ks={};function co(I,W,ue,ke,Qe,it){{var We=$(I);if(!We){var Be="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(Be+=" 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 Rt=re();Rt?Be+=Rt:Be+=Q();var wt;I===null?wt="null":Ge(I)?wt="array":I!==void 0&&I.$$typeof===t?(wt="<"+(F(I.type)||"Unknown")+" />",Be=" Did you accidentally export a JSX literal instead of a component?"):wt=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",wt,Be)}var St=ot(I,W,ue,Qe,it);if(St==null)return St;if(We){var Ut=W.children;if(Ut!==void 0)if(ke)if(Ge(Ut)){for(var ne=0;ne<Ut.length;ne++)xe(Ut[ne],I);Object.freeze&&Object.freeze(Ut)}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 xe(Ut,I)}if(Ze.call(W,"key")){var he=F(I),ae=Object.keys(W).filter(function(vt){return vt!=="key"}),Re=ae.length>0?"{key: someKey, "+ae.join(": ..., ")+": ...}":"{key: someKey}";if(!Ks[he+Re]){var ht=ae.length>0?"{"+ae.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} />`,Re,he,ht,he),Vs[he+Re]=!0}}return I===r?rn(St):tt(St),St}}function Wa(I,W,ue){return lo(I,W,ue,!0)}function Va(I,W,ue){return lo(I,W,ue,!1)}var Ka=Va,qa=Wa;Ir.Fragment=r,Ir.jsx=Ka,Ir.jsxs=qa}()),Ir}process.env.NODE_ENV==="production"?qs.exports=qh():qs.exports=Gh();var u=qs.exports;function Ja(e,t){return function(){return e.apply(t,arguments)}}const{toString:Yh}=Object.prototype,{getPrototypeOf:Gs}=Object,{iterator:ho,toStringTag:Za}=Symbol,mo=(e=>t=>{const n=Yh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>mo(t)===e),go=e=>t=>typeof t===e,{isArray:ir}=Array,ar=go("undefined");function Nr(e){return e!==null&&!ar(e)&&e.constructor!==null&&!ar(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Qa=on("ArrayBuffer");function Xh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Qa(e.buffer),t}const Jh=go("string"),zt=go("function"),el=go("number"),Ar=e=>e!==null&&typeof e=="object",Zh=e=>e===!0||e===!1,xo=e=>{if(mo(e)!=="object")return!1;const t=Gs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Za in e)&&!(ho in e)},Qh=e=>{if(!Ar(e)||Nr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},em=on("Date"),tm=on("File"),nm=on("Blob"),rm=on("FileList"),om=e=>Ar(e)&&zt(e.pipe),sm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=mo(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},im=on("URLSearchParams"),[am,lm,cm,um]=["ReadableStream","Request","Response","Headers"].map(on),dm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function jr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),ir(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Nr(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 tl(e,t){if(Nr(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 Wn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,nl=e=>!ar(e)&&e!==Wn;function Ys(){const{caseless:e,skipUndefined:t}=nl(this)&&this||{},n={},r=(o,s)=>{const i=e&&tl(n,s)||s;xo(n[i])&&xo(o)?n[i]=Ys(n[i],o):xo(o)?n[i]=Ys({},o):ir(o)?n[i]=o.slice():(!t||!ar(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&jr(arguments[o],r);return n}const fm=(e,t,n,{allOwnKeys:r}={})=>(jr(t,(o,s)=>{n&&zt(o)?e[s]=Ja(o,n):e[s]=o},{allOwnKeys:r}),e),pm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),hm=(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)},mm=(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&&Gs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},gm=(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},xm=e=>{if(!e)return null;if(ir(e))return e;let t=e.length;if(!el(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},ym=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Gs(Uint8Array)),vm=(e,t)=>{const r=(e&&e[ho]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},bm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},wm=on("HTMLFormElement"),Sm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),rl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Cm=on("RegExp"),ol=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};jr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Tm=e=>{ol(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+"'")})}})},km=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ir(e)?r(e):r(String(e).split(t)),n},Em=()=>{},Im=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Nm(e){return!!(e&&zt(e.append)&&e[Za]==="FormData"&&e[ho])}const Am=e=>{const t=new Array(10),n=(r,o)=>{if(Ar(r)){if(t.indexOf(r)>=0)return;if(Nr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=ir(r)?[]:{};return jr(r,(i,a)=>{const l=n(i,o+1);!ar(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},jm=on("AsyncFunction"),_m=e=>e&&(Ar(e)||zt(e))&&zt(e.then)&&zt(e.catch),sl=((e,t)=>e?setImmediate:t?((n,r)=>(Wn.addEventListener("message",({source:o,data:s})=>{o===Wn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Wn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",zt(Wn.postMessage)),Rm=typeof queueMicrotask<"u"?queueMicrotask.bind(Wn):typeof process<"u"&&process.nextTick||sl,O={isArray:ir,isArrayBuffer:Qa,isBuffer:Nr,isFormData:sm,isArrayBufferView:Xh,isString:Jh,isNumber:el,isBoolean:Zh,isObject:Ar,isPlainObject:xo,isEmptyObject:Qh,isReadableStream:am,isRequest:lm,isResponse:cm,isHeaders:um,isUndefined:ar,isDate:em,isFile:tm,isBlob:nm,isRegExp:Cm,isFunction:zt,isStream:om,isURLSearchParams:im,isTypedArray:ym,isFileList:rm,forEach:jr,merge:Ys,extend:fm,trim:dm,stripBOM:pm,inherits:hm,toFlatObject:mm,kindOf:mo,kindOfTest:on,endsWith:gm,toArray:xm,forEachEntry:vm,matchAll:bm,isHTMLForm:wm,hasOwnProperty:rl,hasOwnProp:rl,reduceDescriptors:ol,freezeMethods:Tm,toObjectSet:km,toCamelCase:Sm,noop:Em,toFiniteNumber:Im,findKey:tl,global:Wn,isContextDefined:nl,isSpecCompliantForm:Nm,toJSONObject:Am,isAsyncFn:jm,isThenable:_m,setImmediate:sl,asap:Rm,isIterable:e=>e!=null&&zt(e[ho])};function Pe(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(Pe,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const il=Pe.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(Pe,al),Object.defineProperty(il,"isAxiosError",{value:!0}),Pe.from=(e,t,n,r,o,s)=>{const i=Object.create(il);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Pe.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 Pm=null;function Xs(e){return O.isPlainObject(e)||O.isArray(e)}function ll(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function cl(e,t,n){return e?e.concat(t).map(function(o,s){return o=ll(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Om(e){return O.isArray(e)&&!e.some(Xs)}const Mm=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function yo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,v){return!O.isUndefined(v[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function c(x){if(x===null)return"";if(O.isDate(x))return x.toISOString();if(O.isBoolean(x))return x.toString();if(!l&&O.isBlob(x))throw new Pe("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(x)||O.isTypedArray(x)?l&&typeof Blob=="function"?new Blob([x]):Buffer.from(x):x}function d(x,m,v){let g=x;if(x&&!v&&typeof x=="object"){if(O.endsWith(m,"{}"))m=r?m:m.slice(0,-2),x=JSON.stringify(x);else if(O.isArray(x)&&Om(x)||(O.isFileList(x)||O.endsWith(m,"[]"))&&(g=O.toArray(x)))return m=ll(m),g.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?cl([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Xs(x)?!0:(t.append(cl(v,m,s),c(x)),!1)}const f=[],p=Object.assign(Mm,{defaultVisitor:d,convertValue:c,isVisitable:Xs});function h(x,m){if(!O.isUndefined(x)){if(f.indexOf(x)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(x),O.forEach(x,function(g,b){(!(O.isUndefined(g)||g===null)&&o.call(t,g,O.isString(b)?b.trim():b,m,p))===!0&&h(g,m?m.concat(b):[b])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return h(e),t}function ul(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Js(e,t){this._pairs=[],e&&yo(e,this,t)}const dl=Js.prototype;dl.append=function(t,n){this._pairs.push([t,n])},dl.toString=function(t){const n=t?function(r){return t.call(this,r,ul)}:ul;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Dm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function fl(e,t,n){if(!t)return e;const r=n&&n.encode||Dm;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new Js(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class pl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const hl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Lm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Js,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Zs=typeof window<"u"&&typeof document<"u",Qs=typeof navigator=="object"&&navigator||void 0,$m=Zs&&(!Qs||["ReactNative","NativeScript","NS"].indexOf(Qs.product)<0),Fm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",zm=Zs&&window.location.href||"http://localhost",Pt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Zs,hasStandardBrowserEnv:$m,hasStandardBrowserWebWorkerEnv:Fm,navigator:Qs,origin:zm},Symbol.toStringTag,{value:"Module"})),...Lm};function Bm(e,t){return yo(e,new Pt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Pt.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Hm(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Um(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function ml(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Um(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Hm(r),o,n,0)}),n}return null}function Wm(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const _r={transitional:hl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(ml(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Bm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return yo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Wm(t)):t}],transformResponse:[function(t){const n=this.transitional||_r.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Pe.from(a,Pe.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:Pt.classes.FormData,Blob:Pt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{_r.headers[e]={}});const Vm=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Km=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]&&Vm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},gl=Symbol("internals");function Rr(e){return e&&String(e).trim().toLowerCase()}function vo(e){return e===!1||e==null?e:O.isArray(e)?e.map(vo):String(e)}function qm(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 Gm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ei(e,t,n,r,o){if(O.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!O.isString(t)){if(O.isString(r))return t.indexOf(r)!==-1;if(O.isRegExp(r))return r.test(t)}}function Ym(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Xm(e,t){const n=O.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Bt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Rr(l);if(!d)throw new Error("header name must be a non-empty string");const f=O.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=vo(a))}const i=(a,l)=>O.forEach(a,(c,d)=>s(c,d,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!Gm(t))i(Km(t),n);else if(O.isObject(t)&&O.isIterable(t)){let a={},l,c;for(const d of t){if(!O.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?O.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Rr(t),t){const r=O.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return qm(o);if(O.isFunction(n))return n.call(this,o,r);if(O.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Rr(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ei(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Rr(i),i){const a=O.findKey(r,i);a&&(!n||ei(r,r[a],a,n))&&(delete r[a],o=!0)}}return O.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||ei(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return O.forEach(this,(o,s)=>{const i=O.findKey(r,s);if(i){n[i]=vo(o),delete n[s];return}const a=t?Ym(s):String(s).trim();a!==s&&delete n[s],n[a]=vo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
32
- `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[gl]=this[gl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Rr(i);r[a]||(Xm(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Bt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Bt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Bt);function ti(e,t){const n=this||_r,r=t||n,o=Bt.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function xl(e){return!!(e&&e.__CANCEL__)}function lr(e,t,n){Pe.call(this,e??"canceled",Pe.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(lr,Pe,{__CANCEL__:!0});function yl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Pe("Request failed with status code "+n.status,[Pe.ERR_BAD_REQUEST,Pe.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Jm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Zm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function Qm(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const bo=(e,t,n=3)=>{let r=0;const o=Zm(50,250);return Qm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},vl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},bl=e=>(...t)=>O.asap(()=>e(...t)),eg=Pt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Pt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Pt.origin),Pt.navigator&&/(msie|trident)/i.test(Pt.navigator.userAgent)):()=>!0,tg=Pt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function ng(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function rg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function wl(e,t,n){let r=!ng(t);return e&&(r||n==!1)?rg(e,t):t}const Sl=e=>e instanceof Bt?{...e}:e;function Vn(e,t){t=t||{};const n={};function r(c,d,f,p){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:p},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,p){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(Sl(c),Sl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);O.isUndefined(p)&&f!==a||(n[d]=p)}),n}const Cl=e=>{const t=Vn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Bt.from(i),t.url=fl(wl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(Pt.hasStandardBrowserEnv||Pt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Pt.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&eg(t.url))){const l=o&&s&&tg.read(s);l&&i.set(o,l)}return t},og=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Cl(e);let s=o.data;const i=Bt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,x;function m(){h&&h(),x&&x(),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 g(){if(!v)return;const S=Bt.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:S,config:e,request:v};yl(function(E){n(E),m()},function(E){r(E),m()},C),v=null}"onloadend"in v?v.onloadend=g:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(g)},v.onabort=function(){v&&(r(new Pe("Request aborted",Pe.ECONNABORTED,e,v)),v=null)},v.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Pe(C,Pe.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 C=o.transitional||hl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Pe(k,C.clarifyTimeoutError?Pe.ETIMEDOUT:Pe.ECONNABORTED,e,v)),v=null},s===void 0&&i.setContentType(null),"setRequestHeader"in v&&O.forEach(i.toJSON(),function(k,C){v.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(v.withCredentials=!!o.withCredentials),a&&a!=="json"&&(v.responseType=o.responseType),c&&([p,x]=bo(c,!0),v.addEventListener("progress",p)),l&&v.upload&&([f,h]=bo(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{v&&(r(!S||S.type?new lr(null,e,v):S),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Jm(o.url);if(b&&Pt.protocols.indexOf(b)===-1){r(new Pe("Unsupported protocol "+b+":",Pe.ERR_BAD_REQUEST,e));return}v.send(s||null)})},sg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Pe?d:new lr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Pe(`timeout ${t} of ms exceeded`,Pe.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>O.asap(a),l}},ig=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},ag=async function*(e,t){for await(const n of lg(e))yield*ig(n,t)},lg=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()}},Tl=(e,t,n,r)=>{const o=ag(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},kl=64*1024,{isFunction:wo}=O,cg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:El,TextEncoder:Il}=O.global,Nl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ug=e=>{e=O.merge.call({skipUndefined:!0},cg,e);const{fetch:t,Request:n,Response:r}=e,o=t?wo(t):typeof fetch=="function",s=wo(n),i=wo(r);if(!o)return!1;const a=o&&wo(El),l=o&&(typeof Il=="function"?(x=>m=>x.encode(m))(new Il):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&Nl(()=>{let x=!1;const m=new n(Pt.origin,{body:new El,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&Nl(()=>O.isReadableStream(new r("").body)),f={stream:d&&(x=>x.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(x=>{!f[x]&&(f[x]=(m,v)=>{let g=m&&m[x];if(g)return g.call(m);throw new Pe(`Response type '${x}' is not supported`,Pe.ERR_NOT_SUPPORT,v)})});const p=async x=>{if(x==null)return 0;if(O.isBlob(x))return x.size;if(O.isSpecCompliantForm(x))return(await new n(Pt.origin,{method:"POST",body:x}).arrayBuffer()).byteLength;if(O.isArrayBufferView(x)||O.isArrayBuffer(x))return x.byteLength;if(O.isURLSearchParams(x)&&(x=x+""),O.isString(x))return(await l(x)).byteLength},h=async(x,m)=>{const v=O.toFiniteNumber(x.getContentLength());return v??p(m)};return async x=>{let{url:m,method:v,data:g,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:N,withCredentials:j="same-origin",fetchOptions:$}=Cl(x),P=t||fetch;E=E?(E+"").toLowerCase():"text";let D=sg([b,S&&S.toAbortSignal()],k),F=null;const A=D&&D.unsubscribe&&(()=>{D.unsubscribe()});let z;try{if(T&&c&&v!=="get"&&v!=="head"&&(z=await h(N,g))!==0){let X=new n(m,{method:"POST",body:g,duplex:"half"}),se;if(O.isFormData(g)&&(se=X.headers.get("content-type"))&&N.setContentType(se),X.body){const[ve,Oe]=vl(z,bo(bl(T)));g=Tl(X.body,kl,ve,Oe)}}O.isString(j)||(j=j?"include":"omit");const _=s&&"credentials"in n.prototype,K={...$,signal:D,method:v.toUpperCase(),headers:N.normalize().toJSON(),body:g,duplex:"half",credentials:_?j:void 0};F=s&&new n(m,K);let B=await(s?P(F,$):P(m,K));const R=d&&(E==="stream"||E==="response");if(d&&(C||R&&A)){const X={};["status","statusText","headers"].forEach(q=>{X[q]=B[q]});const se=O.toFiniteNumber(B.headers.get("content-length")),[ve,Oe]=C&&vl(se,bo(bl(C),!0))||[];B=new r(Tl(B.body,kl,ve,()=>{Oe&&Oe(),A&&A()}),X)}E=E||"text";let Y=await f[O.findKey(f,E)||"text"](B,x);return!R&&A&&A(),await new Promise((X,se)=>{yl(X,se,{data:Y,headers:Bt.from(B.headers),status:B.status,statusText:B.statusText,config:x,request:F})})}catch(_){throw A&&A(),_&&_.name==="TypeError"&&/Load failed|fetch/i.test(_.message)?Object.assign(new Pe("Network Error",Pe.ERR_NETWORK,x,F),{cause:_.cause||_}):Pe.from(_,_&&_.code,x,F)}}},dg=new Map,Al=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=dg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ug(t)),d=c;return c};Al();const ni={http:Pm,xhr:og,fetch:{get:Al}};O.forEach(ni,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const jl=e=>`- ${e}`,fg=e=>O.isFunction(e)||e===null||e===!1,_l={getAdapter:(e,t)=>{e=O.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!fg(r)&&(o=ni[(a=String(r)).toLowerCase()],o===void 0))throw new Pe(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
- `+i.map(jl).join(`
34
- `):" "+jl(i[0]):"as no adapter specified";throw new Pe("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:ni};function ri(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new lr(null,e)}function Rl(e){return ri(e),e.headers=Bt.from(e.headers),e.data=ti.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),_l.getAdapter(e.adapter||_r.adapter,e)(e).then(function(r){return ri(e),r.data=ti.call(e,e.transformResponse,r),r.headers=Bt.from(r.headers),r},function(r){return xl(r)||(ri(e),r&&r.response&&(r.response.data=ti.call(e,e.transformResponse,r.response),r.response.headers=Bt.from(r.response.headers))),Promise.reject(r)})}const Pl="1.12.2",So={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{So[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Ol={};So.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Pl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Pe(o(i," has been removed"+(n?" in "+n:"")),Pe.ERR_DEPRECATED);return n&&!Ol[i]&&(Ol[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}},So.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function pg(e,t,n){if(typeof e!="object")throw new Pe("options must be an object",Pe.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 Pe("option "+s+" must be "+l,Pe.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Pe("Unknown option "+s,Pe.ERR_BAD_OPTION)}}const Co={assertOptions:pg,validators:So},fn=Co.validators;let Kn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new pl,response:new pl}}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=Vn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Co.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:Co.assertOptions(o,{encode:fn.function,serialize:fn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Co.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],x=>{delete s[x]}),n.headers=Bt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let d,f=0,p;if(!l){const x=[Rl.bind(this),void 0];for(x.unshift(...a),x.push(...c),p=x.length,d=Promise.resolve(n);f<p;)d=d.then(x[f++],x[f++]);return d}p=a.length;let h=n;for(;f<p;){const x=a[f++],m=a[f++];try{h=x(h)}catch(v){m.call(this,v);break}}try{d=Rl.call(this,h)}catch(x){return Promise.reject(x)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Vn(this.defaults,t);const n=wl(t.baseURL,t.url,t.allowAbsoluteUrls);return fl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Kn.prototype[t]=function(n,r){return this.request(Vn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Vn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Kn.prototype[t]=n(),Kn.prototype[t+"Form"]=n(!0)});let hg=class Wh{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 lr(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 Wh(function(o){t=o}),cancel:t}}};function mg(e){return function(n){return e.apply(null,n)}}function gg(e){return O.isObject(e)&&e.isAxiosError===!0}const oi={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(oi).forEach(([e,t])=>{oi[t]=e});function Ml(e){const t=new Kn(e),n=Ja(Kn.prototype.request,t);return O.extend(n,Kn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ml(Vn(e,o))},n}const Ct=Ml(_r);Ct.Axios=Kn,Ct.CanceledError=lr,Ct.CancelToken=hg,Ct.isCancel=xl,Ct.VERSION=Pl,Ct.toFormData=yo,Ct.AxiosError=Pe,Ct.Cancel=Ct.CanceledError,Ct.all=function(t){return Promise.all(t)},Ct.spread=mg,Ct.isAxiosError=gg,Ct.mergeConfig=Vn,Ct.AxiosHeaders=Bt,Ct.formToJSON=e=>ml(O.isHTMLForm(e)?new FormData(e):e),Ct.getAdapter=_l.getAdapter,Ct.HttpStatusCode=oi,Ct.default=Ct;const{Axios:sT,AxiosError:iT,CanceledError:aT,isCancel:lT,CancelToken:cT,VERSION:uT,all:dT,Cancel:fT,isAxiosError:pT,spread:hT,toFormData:mT,AxiosHeaders:gT,HttpStatusCode:xT,formToJSON:yT,getAdapter:vT,mergeConfig:bT}=Ct,Dl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ll=Dl?Cn(Dl):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 To=null;const si=new Set;function $l(){return To}function ko(e){To=e,si.forEach(t=>t(e))}function Fl(e){return si.add(e),()=>si.delete(e)}const xg=3e4,yg=9e4,Gt=Ct.create({...Ll?{baseURL:Ll}:{},timeout:xg,withCredentials:!0});Gt.interceptors.request.use(e=>(To&&(e.headers.Authorization=`Bearer ${To}`),e)),Gt.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),ko(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 Yt(e,t){return Gt.defaults.baseURL?(await Gt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ii(e,t,n){return Gt.defaults.baseURL?(await Gt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function zl(e,t,n){return Gt.defaults.baseURL?(await Gt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Bl(e,t){return Gt.defaults.baseURL?(await Gt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Xt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Hl{get baseUrl(){const t=Gt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(Gt.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&ko(t.authToken)}getAuthToken(){return $l()}setAuthToken(t){ko(t)}onTokenChange(t){return Fl(t)}async listThreads(){const t=await Yt("/threads"),n=Xt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ii("/threads",t?{title:t}:void 0);return Xt(r)}async updateThread(t,n){const r=await zl(`/threads/${t}`,{title:n});return Xt(r)}async deleteThread(t){const n=await Bl(`/threads/${t}`);return Xt(n)}async threadInfo(t){const n=await Yt(`/threads/${t}/info`);return Xt(n)}async listAgents(){const t=await Yt("/agents"),n=Xt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Yt(`/agents/${t}`);return Xt(n)}async getAgentSchema(t){const n=await Yt(`/agents/${t}/schema`);return Xt(n)}async getState(t){const n=await Yt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Xt(n)}async getStateHistory(t){const n=await Yt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:yg});return Xt(n)}async cancelRun(t){const n=await ii("/runs/cancel",{threadId:t});return Xt(n)}async listCheckpointSummaries(t){const n=await Yt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Xt(n);return(r==null?void 0:r.items)??[]}}const jn=new Hl,Ul=w.createContext(null);function vg({children:e,apiConfig:t}){const n=jn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Ul.Provider,{value:r,children:e})}function ai(){const e=w.useContext(Ul);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function bg(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 wg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await bg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Sg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function li(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 Cg(e,t){return`${e??""}::${t??""}`}function cr(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(!li(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=kg(t),i=Wl(r,0),a=Eg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Wl(e,t){if(!li(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(j=>!!j&&typeof j=="object").map(j=>({...j})):a===null?null:void 0,c=r.map((j,$)=>Mg(j,$)).filter(j=>!!j),d=Ot(e.config),f=Ot(d==null?void 0:d.configurable),p=mt(f,["checkpoint_id","checkpointId"]),h=mt(f,["checkpoint_ns","checkpointNs"]),x=Ot(e==null?void 0:e.parentConfig),m=Ot(x==null?void 0:x.configurable),v=mt(m,["checkpoint_id","checkpointId"])??null,g=mt(m,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString();c[c.length-1];const k=c.slice().reverse().find(j=>j.role==="user")??null,C=Ot(e==null?void 0:e.metadata),T=mt(C,["branch_label","branchLabel"]),E=mt(m,["checkpoint_id","checkpointId"]),N=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:v,nextCursorNs:g,interrupt:Tg(a,c,t),createdAt:S,parentId:E??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:x??null,next:N??null,tasks:l??null,values:i??null}}function Tg(e,t,n){const r=Pg(e,n);return r||Rg(t,n)}function kg(e){const t=new Map;e.forEach((o,s)=>{if(!li(o))return;const i=Wl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Cg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ag(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Kl(s.createdAt??"")-Kl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Eg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=mt(i,["label"])??mt(i,["branch_label","branchLabel"])??mt(i,["description"])??"User input",l=Ng(i,["step"]),c=mt(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Ig(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0})}return t}function Ig(e){if(!Array.isArray(e)||e.length===0)return null;const t=e.map(n=>{if(typeof n=="string")return n.trim();if(n&&typeof n=="object"&&"type"in n){const r=n;if(typeof r.type=="string")return r.type}return null}).filter(n=>!!(n&&n.length));return t.length?t.join(", "):null}function Ng(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ag(e,t){return{...e,metadata:Eo(e.metadata,t.metadata)??null,config:Eo(e.config,t.config)??null,parentConfig:Eo(e.parentConfig,t.parentConfig)??null,next:jg(e.next,t.next)??null,tasks:_g(e.tasks,t.tasks)??null,values:Eo(e.values,t.values)??null}}function Eo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function jg(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function _g(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Rg(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 Pg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Og(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=Pr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Pr(r.state,`${o}-state`);if(s)return s}}return null}function Og(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,x=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",m=Array.isArray(d)?d:void 0,v=p.length?p[p.length-1]:void 0;return{id:h,name:x,interrupts:m,state:v!==void 0?v:f}}const n=Ot(e);if(!n)return null;const r=mt(n,["id","thread_id","taskId"])??t,o=mt(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 Pr(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=Vl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Pr(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=Pr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Pr(l,t,n+1,r);if(c)return c}}return null}function Vl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=mt(n,["type","event","kind"]),o=mt(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=Vl(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 Kl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Mg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ot(e)??{},o=Ot(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Sg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Ot(o.additional_kwargs)??Ot(o.additionalKwargs),d=Ot(o.response_metadata)??Ot(o.responseMetadata),f=mt(c,["createdAt","created_at"])??mt(o,["created_at","createdAt"]),p=mt(c,["checkpointId","checkpoint_id"]),h=mt(c,["checkpointNs","checkpoint_ns"]),x=Dg(o.content),m={id:l,role:i,content:x};f&&(m.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(m.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(m.model=String(d.model_name)),!m.model&&typeof o.model=="string"&&(m.model=o.model),p&&(m.checkpointId=p),h&&(m.checkpointNs=h);const v=Fg(Ot(o.artifact??r.artifact??o.artifacts??r.artifacts));v&&(m.artifact=v);const g=Bg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;g&&Object.keys(g).length&&(m.additionalKwargs=g),b&&Object.keys(b).length&&(m.responseMetadata=b);const S=Lg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=$g(o,m.content);k&&(m.content=k)}return m}function Dg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>ql(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=ql(e);return t?[t]:[]}return[]}function ql(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=mt(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=mt(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 Gl(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=mt(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 Gl(e,t){var s;const n=mt(e,["id","call_id"])??t,r=mt(e,["name"])??mt(Ot(e.function),["name"]);if(!n||!r)return null;const o=zg(e.args??e.arguments??((s=Ot(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Gl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function $g(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 Fg(e){if(!e)return;const t={...e},n=Yl(e.plots);n.length?t.plots=n:delete t.plots;const r=Ot(e.data);if(r){const o={...r},s=Yl(r.plots);s.length?o.plots=s:delete o.plots,t.data=o}return Object.keys(t).length?t:void 0}function Yl(e){return Array.isArray(e)?e.map(t=>t&&typeof t=="object"?{...t}:t).filter(t=>t?typeof t=="string"?t.trim().length>0:!0:!1):[]}function zg(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Ot(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function mt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Bg(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 ur=120;function Hg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>ur?`${n.slice(0,ur-3)}…`:n:""}function Ug(e){var r,o;const t=[(r=e.additionalKwargs)==null?void 0:r.summary,(o=e.responseMetadata)==null?void 0:o.summary];for(const s of t)if(typeof s=="string"&&s.trim()){const i=s.trim();return i.length>ur?`${i.slice(0,ur-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>ur?`${n.slice(0,ur-3)}…`:n:""}function Xl(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=Hg(n.content)||Ug(n);o&&t.set(n.id,o)}return t}function Jl(e={}){const t=w.useMemo(()=>Cn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,p]=w.useState(""),[h,x]=w.useState(null),[m,v]=w.useState(0),[g,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),E=w.useRef(null),N=w.useRef(null),j=w.useRef(null),$=w.useCallback(A=>{o(A)},[]),P=w.useCallback(()=>{p(""),x(null),d(null),E.current=null,N.current=null,j.current=null},[]),D=w.useCallback(()=>{var A;console.debug("[use-chat] stop() invoked - aborting stream"),(A=S.current)==null||A.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,v(0)},[]),F=w.useCallback((A,z,_)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),E.current=null,N.current=null,j.current=null;const K=new AbortController;S.current=K;let B=null,R=null,Y=!1;return T.current={threadId:A.threadId??null,headers:{}},(async()=>{var se,ve,Oe,q,H,J,L,G,Z,fe,re,Ae,qe,Fe,Je,ie,be,je;const X=De=>{var Ue;try{const Ge=JSON.parse(JSON.stringify(De));return(Ue=Ge==null?void 0:Ge.payload)!=null&&Ue.files_info&&Array.isArray(Ge.payload.files_info)&&(Ge.payload.files_info=Ge.payload.files_info.map(ze=>({...ze,data:ze!=null&&ze.data?`<base64 ${String(ze.data).length} chars>`:ze==null?void 0:ze.data}))),Ge}catch{return De}};try{let De={};try{if(r)De={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const ot=window.__AUTH_TOKEN__,bt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let V=null;try{const Ce=(ve=window.localStorage)==null?void 0:ve.getItem("chat-settings");Ce&&(V=((Oe=JSON.parse(Ce))==null?void 0:Oe.apiKey)||null)}catch{}const ce=ot||bt||V||null;ce&&(De={Authorization:`Bearer ${ce}`})}}catch{}console.debug("[use-chat] POST",t+n,X(A));let Ue={};if(typeof window<"u")try{const et=(q=window.localStorage)==null?void 0:q.getItem("authSessionId");et&&(Ue={"X-Session-Id":et})}catch{}const Ge={...De,...Ue,...s.current},ze={"Content-Type":"application/json",Accept:"text/event-stream",...Ge},He=await fetch(t+n,{method:"POST",headers:ze,body:JSON.stringify(A),signal:K.signal,credentials:i});if(T.current&&(T.current.headers=Ge),!He.ok||!He.body){const et=await He.text().catch(()=>"");console.debug("[use-chat] non-OK response",He.status,et==null?void 0:et.slice(0,500));const ot=`stream ${He.status}${et?": "+et:""}`;throw(H=_==null?void 0:_.onConnectionError)==null||H.call(_,ot),Y=!0,B="error",R=ot,new Error(ot)}b(!0);const Qe=He.body.getReader(),Et=new TextDecoder;let xt="",lt=[];C.current=0,v(0);let ft=0,pt=null;const yt=()=>{if(lt.length){const et=lt.join("");lt=[],k.current&&p(ot=>ot+et)}pt=null},Nt=()=>{typeof window<"u"&&pt==null&&(pt=requestAnimationFrame(yt))};let Ye=Date.now();const _t=setInterval(()=>{var et;if(Date.now()-Ye>18e5){const ot="Stream idle timeout";d(ot),B="error",R=ot,K.abort(),(et=_==null?void 0:_.onError)==null||et.call(_,ot)}},5e3),Sn=1024*1024;try{const et=He.headers.get("X-Thread-Id")||He.headers.get("x-thread-id"),ot=He.headers.get("X-Thread-Created")||He.headers.get("x-thread-created"),bt=et??null,V=String(ot??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:bt}),(J=_==null?void 0:_.onOpen)==null||J.call(_,{threadId:bt,created:V});;){const{value:ce,done:Ce}=await Qe.read();if(Ce)break;xt+=Et.decode(ce,{stream:!0}),xt.length>Sn&&(xt="",console.warn("Stream buffer reset: exceeded 1MB"));let M;for(;(M=xt.indexOf(`
30
+ <%s key={someKey} {...props} />`,Re,he,ht,he),Ks[he+Re]=!0}}return I===r?An(St):st(St),St}}function Ka(I,W,ue){return co(I,W,ue,!0)}function qa(I,W,ue){return co(I,W,ue,!1)}var Ga=qa,Ya=Ka;Nr.Fragment=r,Nr.jsx=Ga,Nr.jsxs=Ya}()),Nr}process.env.NODE_ENV==="production"?Ys.exports=Gh():Ys.exports=Yh();var u=Ys.exports;function Qa(e,t){return function(){return e.apply(t,arguments)}}const{toString:Xh}=Object.prototype,{getPrototypeOf:Xs}=Object,{iterator:mo,toStringTag:el}=Symbol,go=(e=>t=>{const n=Xh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:ar}=Array,lr=xo("undefined");function Ar(e){return e!==null&&!lr(e)&&e.constructor!==null&&!lr(e.constructor)&&zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const tl=on("ArrayBuffer");function Jh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&tl(e.buffer),t}const Zh=xo("string"),zt=xo("function"),nl=xo("number"),_r=e=>e!==null&&typeof e=="object",Qh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Xs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(el in e)&&!(mo in e)},em=e=>{if(!_r(e)||Ar(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},tm=on("Date"),nm=on("File"),rm=on("Blob"),om=on("FileList"),sm=e=>_r(e)&&zt(e.pipe),im=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||zt(e.append)&&((t=go(e))==="formdata"||t==="object"&&zt(e.toString)&&e.toString()==="[object FormData]"))},am=on("URLSearchParams"),[lm,cm,um,dm]=["ReadableStream","Request","Response","Headers"].map(on),fm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function jr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),ar(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Ar(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function rl(e,t){if(Ar(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Vn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ol=e=>!lr(e)&&e!==Vn;function Js(){const{caseless:e,skipUndefined:t}=ol(this)&&this||{},n={},r=(o,s)=>{const i=e&&rl(n,s)||s;yo(n[i])&&yo(o)?n[i]=Js(n[i],o):yo(o)?n[i]=Js({},o):ar(o)?n[i]=o.slice():(!t||!lr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&jr(arguments[o],r);return n}const pm=(e,t,n,{allOwnKeys:r}={})=>(jr(t,(o,s)=>{n&&zt(o)?e[s]=Qa(o,n):e[s]=o},{allOwnKeys:r}),e),hm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),mm=(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)},gm=(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&&Xs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},xm=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},ym=e=>{if(!e)return null;if(ar(e))return e;let t=e.length;if(!nl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},vm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Xs(Uint8Array)),bm=(e,t)=>{const r=(e&&e[mo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},wm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Sm=on("HTMLFormElement"),Cm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),sl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Tm=on("RegExp"),il=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};jr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},km=e=>{il(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+"'")})}})},Em=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ar(e)?r(e):r(String(e).split(t)),n},Im=()=>{},Nm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Am(e){return!!(e&&zt(e.append)&&e[el]==="FormData"&&e[mo])}const _m=e=>{const t=new Array(10),n=(r,o)=>{if(_r(r)){if(t.indexOf(r)>=0)return;if(Ar(r))return r;if(!("toJSON"in r)){t[o]=r;const s=ar(r)?[]:{};return jr(r,(i,a)=>{const l=n(i,o+1);!lr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},jm=on("AsyncFunction"),Rm=e=>e&&(_r(e)||zt(e))&&zt(e.then)&&zt(e.catch),al=((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)),Pm=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||al,M={isArray:ar,isArrayBuffer:tl,isBuffer:Ar,isFormData:im,isArrayBufferView:Jh,isString:Zh,isNumber:nl,isBoolean:Qh,isObject:_r,isPlainObject:yo,isEmptyObject:em,isReadableStream:lm,isRequest:cm,isResponse:um,isHeaders:dm,isUndefined:lr,isDate:tm,isFile:nm,isBlob:rm,isRegExp:Tm,isFunction:zt,isStream:sm,isURLSearchParams:am,isTypedArray:vm,isFileList:om,forEach:jr,merge:Js,extend:pm,trim:fm,stripBOM:hm,inherits:mm,toFlatObject:gm,kindOf:go,kindOfTest:on,endsWith:xm,toArray:ym,forEachEntry:bm,matchAll:wm,isHTMLForm:Sm,hasOwnProperty:sl,hasOwnProp:sl,reduceDescriptors:il,freezeMethods:km,toObjectSet:Em,toCamelCase:Cm,noop:Im,toFiniteNumber:Nm,findKey:rl,global:Vn,isContextDefined:ol,isSpecCompliantForm:Am,toJSONObject:_m,isAsyncFn:jm,isThenable:Rm,setImmediate:al,asap:Pm,isIterable:e=>e!=null&&zt(e[mo])};function Pe(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)}M.inherits(Pe,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:M.toJSONObject(this.config),code:this.code,status:this.status}}});const ll=Pe.prototype,cl={};["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=>{cl[e]={value:e}}),Object.defineProperties(Pe,cl),Object.defineProperty(ll,"isAxiosError",{value:!0}),Pe.from=(e,t,n,r,o,s)=>{const i=Object.create(ll);M.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Pe.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 Om=null;function Zs(e){return M.isPlainObject(e)||M.isArray(e)}function ul(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function dl(e,t,n){return e?e.concat(t).map(function(o,s){return o=ul(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Mm(e){return M.isArray(e)&&!e.some(Zs)}const Dm=M.toFlatObject(M,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!M.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=M.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,v){return!M.isUndefined(v[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&M.isSpecCompliantForm(t);if(!M.isFunction(o))throw new TypeError("visitor must be a function");function c(x){if(x===null)return"";if(M.isDate(x))return x.toISOString();if(M.isBoolean(x))return x.toString();if(!l&&M.isBlob(x))throw new Pe("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(x)||M.isTypedArray(x)?l&&typeof Blob=="function"?new Blob([x]):Buffer.from(x):x}function d(x,m,v){let g=x;if(x&&!v&&typeof x=="object"){if(M.endsWith(m,"{}"))m=r?m:m.slice(0,-2),x=JSON.stringify(x);else if(M.isArray(x)&&Mm(x)||(M.isFileList(x)||M.endsWith(m,"[]"))&&(g=M.toArray(x)))return m=ul(m),g.forEach(function(S,k){!(M.isUndefined(S)||S===null)&&t.append(i===!0?dl([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Zs(x)?!0:(t.append(dl(v,m,s),c(x)),!1)}const f=[],p=Object.assign(Dm,{defaultVisitor:d,convertValue:c,isVisitable:Zs});function h(x,m){if(!M.isUndefined(x)){if(f.indexOf(x)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(x),M.forEach(x,function(g,b){(!(M.isUndefined(g)||g===null)&&o.call(t,g,M.isString(b)?b.trim():b,m,p))===!0&&h(g,m?m.concat(b):[b])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return h(e),t}function fl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Qs(e,t){this._pairs=[],e&&vo(e,this,t)}const pl=Qs.prototype;pl.append=function(t,n){this._pairs.push([t,n])},pl.toString=function(t){const n=t?function(r){return t.call(this,r,fl)}:fl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Lm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function hl(e,t,n){if(!t)return e;const r=n&&n.encode||Lm;M.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=M.isURLSearchParams(t)?t.toString():new Qs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class ml{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){M.forEach(this.handlers,function(r){r!==null&&t(r)})}}const gl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},$m={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Qs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ei=typeof window<"u"&&typeof document<"u",ti=typeof navigator=="object"&&navigator||void 0,Fm=ei&&(!ti||["ReactNative","NativeScript","NS"].indexOf(ti.product)<0),zm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Bm=ei&&window.location.href||"http://localhost",Pt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ei,hasStandardBrowserEnv:Fm,hasStandardBrowserWebWorkerEnv:zm,navigator:ti,origin:Bm},Symbol.toStringTag,{value:"Module"})),...$m};function Hm(e,t){return vo(e,new Pt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Pt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Um(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Wm(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 xl(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&&M.isArray(o)?o.length:i,l?(M.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!M.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&M.isArray(o[i])&&(o[i]=Wm(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Um(r),o,n,0)}),n}return null}function Vm(e,t,n){if(M.isString(e))try{return(t||JSON.parse)(e),M.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Rr={transitional:gl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=M.isObject(t);if(s&&M.isHTMLForm(t)&&(t=new FormData(t)),M.isFormData(t))return o?JSON.stringify(xl(t)):t;if(M.isArrayBuffer(t)||M.isBuffer(t)||M.isStream(t)||M.isFile(t)||M.isBlob(t)||M.isReadableStream(t))return t;if(M.isArrayBufferView(t))return t.buffer;if(M.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 Hm(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return vo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Vm(t)):t}],transformResponse:[function(t){const n=this.transitional||Rr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(M.isResponse(t)||M.isReadableStream(t))return t;if(t&&M.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"?Pe.from(a,Pe.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:Pt.classes.FormData,Blob:Pt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};M.forEach(["delete","get","head","post","put","patch"],e=>{Rr.headers[e]={}});const Km=M.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"]),qm=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]&&Km[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},yl=Symbol("internals");function Pr(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:M.isArray(e)?e.map(bo):String(e)}function Gm(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 Ym=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ni(e,t,n,r,o){if(M.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!M.isString(t)){if(M.isString(r))return t.indexOf(r)!==-1;if(M.isRegExp(r))return r.test(t)}}function Xm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Jm(e,t){const n=M.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Bt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Pr(l);if(!d)throw new Error("header name must be a non-empty string");const f=M.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=bo(a))}const i=(a,l)=>M.forEach(a,(c,d)=>s(c,d,l));if(M.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(M.isString(t)&&(t=t.trim())&&!Ym(t))i(qm(t),n);else if(M.isObject(t)&&M.isIterable(t)){let a={},l,c;for(const d of t){if(!M.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?M.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Pr(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Gm(o);if(M.isFunction(n))return n.call(this,o,r);if(M.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Pr(t),t){const r=M.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ni(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Pr(i),i){const a=M.findKey(r,i);a&&(!n||ni(r,r[a],a,n))&&(delete r[a],o=!0)}}return M.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||ni(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return M.forEach(this,(o,s)=>{const i=M.findKey(r,s);if(i){n[i]=bo(o),delete n[s];return}const a=t?Xm(s):String(s).trim();a!==s&&delete n[s],n[a]=bo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return M.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&M.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[yl]=this[yl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Pr(i);r[a]||(Jm(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};Bt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(Bt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(Bt);function ri(e,t){const n=this||Rr,r=t||n,o=Bt.from(r.headers);let s=r.data;return M.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function vl(e){return!!(e&&e.__CANCEL__)}function cr(e,t,n){Pe.call(this,e??"canceled",Pe.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(cr,Pe,{__CANCEL__:!0});function bl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Pe("Request failed with status code "+n.status,[Pe.ERR_BAD_REQUEST,Pe.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Zm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Qm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),d=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,p=0;for(;f!==o;)p+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const h=d&&c-d;return h?Math.round(p*1e3/h):void 0}}function eg(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const wo=(e,t,n=3)=>{let r=0;const o=Qm(50,250);return eg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},wl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Sl=e=>(...t)=>M.asap(()=>e(...t)),tg=Pt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Pt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Pt.origin),Pt.navigator&&/(msie|trident)/i.test(Pt.navigator.userAgent)):()=>!0,ng=Pt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];M.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),M.isString(r)&&i.push("path="+r),M.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 rg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function og(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Cl(e,t,n){let r=!rg(t);return e&&(r||n==!1)?og(e,t):t}const Tl=e=>e instanceof Bt?{...e}:e;function Kn(e,t){t=t||{};const n={};function r(c,d,f,p){return M.isPlainObject(c)&&M.isPlainObject(d)?M.merge.call({caseless:p},c,d):M.isPlainObject(d)?M.merge({},d):M.isArray(d)?d.slice():d}function o(c,d,f,p){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!M.isUndefined(d))return r(void 0,d)}function i(c,d){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(Tl(c),Tl(d),f,!0)};return M.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);M.isUndefined(p)&&f!==a||(n[d]=p)}),n}const kl=e=>{const t=Kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Bt.from(i),t.url=hl(Cl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),M.isFormData(n)){if(Pt.hasStandardBrowserEnv||Pt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(M.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Pt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&tg(t.url))){const l=o&&s&&ng.read(s);l&&i.set(o,l)}return t},sg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=kl(e);let s=o.data;const i=Bt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,p,h,x;function m(){h&&h(),x&&x(),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 g(){if(!v)return;const S=Bt.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:S,config:e,request:v};bl(function(E){n(E),m()},function(E){r(E),m()},C),v=null}"onloadend"in v?v.onloadend=g:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(g)},v.onabort=function(){v&&(r(new Pe("Request aborted",Pe.ECONNABORTED,e,v)),v=null)},v.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new Pe(C,Pe.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 C=o.transitional||gl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new Pe(k,C.clarifyTimeoutError?Pe.ETIMEDOUT:Pe.ECONNABORTED,e,v)),v=null},s===void 0&&i.setContentType(null),"setRequestHeader"in v&&M.forEach(i.toJSON(),function(k,C){v.setRequestHeader(C,k)}),M.isUndefined(o.withCredentials)||(v.withCredentials=!!o.withCredentials),a&&a!=="json"&&(v.responseType=o.responseType),c&&([p,x]=wo(c,!0),v.addEventListener("progress",p)),l&&v.upload&&([f,h]=wo(l),v.upload.addEventListener("progress",f),v.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{v&&(r(!S||S.type?new cr(null,e,v):S),v.abort(),v=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Zm(o.url);if(b&&Pt.protocols.indexOf(b)===-1){r(new Pe("Unsupported protocol "+b+":",Pe.ERR_BAD_REQUEST,e));return}v.send(s||null)})},ig=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const d=c instanceof Error?c:this.reason;r.abort(d instanceof Pe?d:new cr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Pe(`timeout ${t} of ms exceeded`,Pe.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>M.asap(a),l}},ag=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},lg=async function*(e,t){for await(const n of cg(e))yield*ag(n,t)},cg=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()}},El=(e,t,n,r)=>{const o=lg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Il=64*1024,{isFunction:So}=M,ug=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:Nl,TextEncoder:Al}=M.global,_l=(e,...t)=>{try{return!!e(...t)}catch{return!1}},dg=e=>{e=M.merge.call({skipUndefined:!0},ug,e);const{fetch:t,Request:n,Response:r}=e,o=t?So(t):typeof fetch=="function",s=So(n),i=So(r);if(!o)return!1;const a=o&&So(Nl),l=o&&(typeof Al=="function"?(x=>m=>x.encode(m))(new Al):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&_l(()=>{let x=!1;const m=new n(Pt.origin,{body:new Nl,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&_l(()=>M.isReadableStream(new r("").body)),f={stream:d&&(x=>x.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(x=>{!f[x]&&(f[x]=(m,v)=>{let g=m&&m[x];if(g)return g.call(m);throw new Pe(`Response type '${x}' is not supported`,Pe.ERR_NOT_SUPPORT,v)})});const p=async x=>{if(x==null)return 0;if(M.isBlob(x))return x.size;if(M.isSpecCompliantForm(x))return(await new n(Pt.origin,{method:"POST",body:x}).arrayBuffer()).byteLength;if(M.isArrayBufferView(x)||M.isArrayBuffer(x))return x.byteLength;if(M.isURLSearchParams(x)&&(x=x+""),M.isString(x))return(await l(x)).byteLength},h=async(x,m)=>{const v=M.toFiniteNumber(x.getContentLength());return v??p(m)};return async x=>{let{url:m,method:v,data:g,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:N,withCredentials:_="same-origin",fetchOptions:$}=kl(x),P=t||fetch;E=E?(E+"").toLowerCase():"text";let D=ig([b,S&&S.toAbortSignal()],k),F=null;const A=D&&D.unsubscribe&&(()=>{D.unsubscribe()});let z;try{if(T&&c&&v!=="get"&&v!=="head"&&(z=await h(N,g))!==0){let X=new n(m,{method:"POST",body:g,duplex:"half"}),se;if(M.isFormData(g)&&(se=X.headers.get("content-type"))&&N.setContentType(se),X.body){const[be,Oe]=wl(z,wo(Sl(T)));g=El(X.body,Il,be,Oe)}}M.isString(_)||(_=_?"include":"omit");const j=s&&"credentials"in n.prototype,K={...$,signal:D,method:v.toUpperCase(),headers:N.normalize().toJSON(),body:g,duplex:"half",credentials:j?_:void 0};F=s&&new n(m,K);let B=await(s?P(F,$):P(m,K));const R=d&&(E==="stream"||E==="response");if(d&&(C||R&&A)){const X={};["status","statusText","headers"].forEach(q=>{X[q]=B[q]});const se=M.toFiniteNumber(B.headers.get("content-length")),[be,Oe]=C&&wl(se,wo(Sl(C),!0))||[];B=new r(El(B.body,Il,be,()=>{Oe&&Oe(),A&&A()}),X)}E=E||"text";let Y=await f[M.findKey(f,E)||"text"](B,x);return!R&&A&&A(),await new Promise((X,se)=>{bl(X,se,{data:Y,headers:Bt.from(B.headers),status:B.status,statusText:B.statusText,config:x,request:F})})}catch(j){throw A&&A(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new Pe("Network Error",Pe.ERR_NETWORK,x,F),{cause:j.cause||j}):Pe.from(j,j&&j.code,x,F)}}},fg=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,c,d=fg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:dg(t)),d=c;return c};jl();const oi={http:Om,xhr:sg,fetch:{get:jl}};M.forEach(oi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Rl=e=>`- ${e}`,pg=e=>M.isFunction(e)||e===null||e===!1,Pl={getAdapter:(e,t)=>{e=M.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,!pg(r)&&(o=oi[(a=String(r)).toLowerCase()],o===void 0))throw new Pe(`Unknown adapter '${a}'`);if(o&&(M.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
+ `+i.map(Rl).join(`
34
+ `):" "+Rl(i[0]):"as no adapter specified";throw new Pe("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:oi};function si(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new cr(null,e)}function Ol(e){return si(e),e.headers=Bt.from(e.headers),e.data=ri.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Pl.getAdapter(e.adapter||Rr.adapter,e)(e).then(function(r){return si(e),r.data=ri.call(e,e.transformResponse,r),r.headers=Bt.from(r.headers),r},function(r){return vl(r)||(si(e),r&&r.response&&(r.response.data=ri.call(e,e.transformResponse,r.response),r.response.headers=Bt.from(r.response.headers))),Promise.reject(r)})}const Ml="1.12.2",Co={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Co[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Dl={};Co.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Ml+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Pe(o(i," has been removed"+(n?" in "+n:"")),Pe.ERR_DEPRECATED);return n&&!Dl[i]&&(Dl[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},Co.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function hg(e,t,n){if(typeof e!="object")throw new Pe("options must be an object",Pe.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 Pe("option "+s+" must be "+l,Pe.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Pe("Unknown option "+s,Pe.ERR_BAD_OPTION)}}const To={assertOptions:hg,validators:Co},fn=To.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new ml,response:new ml}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
35
+ `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:fn.transitional(fn.boolean),forcedJSONParsing:fn.transitional(fn.boolean),clarifyTimeoutError:fn.transitional(fn.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:To.assertOptions(o,{encode:fn.function,serialize:fn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),To.assertOptions(n,{baseUrl:fn.spelling("baseURL"),withXsrfToken:fn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&M.merge(s.common,s[n.method]);s&&M.forEach(["delete","get","head","post","put","patch","common"],x=>{delete s[x]}),n.headers=Bt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(l=l&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let d,f=0,p;if(!l){const x=[Ol.bind(this),void 0];for(x.unshift(...a),x.push(...c),p=x.length,d=Promise.resolve(n);f<p;)d=d.then(x[f++],x[f++]);return d}p=a.length;let h=n;for(;f<p;){const x=a[f++],m=a[f++];try{h=x(h)}catch(v){m.call(this,v);break}}try{d=Ol.call(this,h)}catch(x){return Promise.reject(x)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=Cl(t.baseURL,t.url,t.allowAbsoluteUrls);return hl(n,t.params,t.paramsSerializer)}};M.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}))}}),M.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 mg=class Vh{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 cr(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 Vh(function(o){t=o}),cancel:t}}};function gg(e){return function(n){return e.apply(null,n)}}function xg(e){return M.isObject(e)&&e.isAxiosError===!0}const ii={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(ii).forEach(([e,t])=>{ii[t]=e});function Ll(e){const t=new qn(e),n=Qa(qn.prototype.request,t);return M.extend(n,qn.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ll(Kn(e,o))},n}const Ct=Ll(Rr);Ct.Axios=qn,Ct.CanceledError=cr,Ct.CancelToken=mg,Ct.isCancel=vl,Ct.VERSION=Ml,Ct.toFormData=vo,Ct.AxiosError=Pe,Ct.Cancel=Ct.CanceledError,Ct.all=function(t){return Promise.all(t)},Ct.spread=gg,Ct.isAxiosError=xg,Ct.mergeConfig=Kn,Ct.AxiosHeaders=Bt,Ct.formToJSON=e=>xl(M.isHTMLForm(e)?new FormData(e):e),Ct.getAdapter=Pl.getAdapter,Ct.HttpStatusCode=ii,Ct.default=Ct;const{Axios:cT,AxiosError:uT,CanceledError:dT,isCancel:fT,CancelToken:pT,VERSION:hT,all:mT,Cancel:gT,isAxiosError:xT,spread:yT,toFormData:vT,AxiosHeaders:bT,HttpStatusCode:wT,formToJSON:ST,getAdapter:CT,mergeConfig:TT}=Ct,$l=typeof window<"u"?window.__API_BASE_URL__:void 0,Fl=$l?Cn($l):void 0;function Cn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const ai=new Set;function zl(){return ko}function Eo(e){ko=e,ai.forEach(t=>t(e))}function Bl(e){return ai.add(e),()=>ai.delete(e)}const yg=3e4,vg=9e4,Gt=Ct.create({...Fl?{baseURL:Fl}:{},timeout:yg,withCredentials:!0});Gt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),Gt.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),Eo(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 Yt(e,t){return Gt.defaults.baseURL?(await Gt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function li(e,t,n){return Gt.defaults.baseURL?(await Gt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Hl(e,t,n){return Gt.defaults.baseURL?(await Gt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ul(e,t){return Gt.defaults.baseURL?(await Gt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Xt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Wl{get baseUrl(){const t=Gt.defaults.baseURL;return t?Cn(String(t)):""}updateConfig(t){t.baseUrl&&(Gt.defaults.baseURL=Cn(String(t.baseUrl))),t.authToken!==void 0&&Eo(t.authToken)}getAuthToken(){return zl()}setAuthToken(t){Eo(t)}onTokenChange(t){return Bl(t)}async listThreads(){const t=await Yt("/threads"),n=Xt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await li("/threads",t?{title:t}:void 0);return Xt(r)}async updateThread(t,n){const r=await Hl(`/threads/${t}`,{title:n});return Xt(r)}async deleteThread(t){const n=await Ul(`/threads/${t}`);return Xt(n)}async threadInfo(t){const n=await Yt(`/threads/${t}/info`);return Xt(n)}async listAgents(){const t=await Yt("/agents"),n=Xt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Yt(`/agents/${t}`);return Xt(n)}async getAgentSchema(t){const n=await Yt(`/agents/${t}/schema`);return Xt(n)}async getState(t){const n=await Yt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Xt(n)}async getStateHistory(t){const n=await Yt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:vg});return Xt(n)}async cancelRun(t){const n=await li("/runs/cancel",{threadId:t});return Xt(n)}async listCheckpointSummaries(t){const n=await Yt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Xt(n);return(r==null?void 0:r.items)??[]}}const jn=new Wl,Vl=w.createContext(null);function bg({children:e,apiConfig:t}){const n=jn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Vl.Provider,{value:r,children:e})}function ci(){const e=w.useContext(Vl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function wg(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 Sg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await wg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Cg={MODE:"library"};function Tg(){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:Gs&&Gs.tagName.toUpperCase()==="SCRIPT"&&Gs.src||new URL("index.umd.js",document.baseURI).href}<"u"?Cg: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 Jt(){return!Tg()}const kg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function ui(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 Eg(e,t){return`${e??""}::${t??""}`}function ur(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(!ui(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Ng(t),i=Kl(r,0),a=Ag(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Kl(e,t){if(!ui(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,$)=>$g(_,$)).filter(_=>!!_),d=Lt(e.config),f=Lt(d==null?void 0:d.configurable),p=mt(f,["checkpoint_id","checkpointId"]),h=mt(f,["checkpoint_ns","checkpointNs"]),x=Lt(e==null?void 0:e.parentConfig),m=Lt(x==null?void 0:x.configurable),v=mt(m,["checkpoint_id","checkpointId"])??null,g=mt(m,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),k=c.slice().reverse().find(_=>_.role==="user")??null,C=Lt(e==null?void 0:e.metadata),T=mt(C,["branch_label","branchLabel"]),E=mt(m,["checkpoint_id","checkpointId"]),N=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:v,nextCursorNs:g,interrupt:Ig(a,c,t),createdAt:S,parentId:E??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:x??null,next:N??null,tasks:l??null,values:i??null}}function Ig(e,t,n){const r=Dg(e,n);return r||Mg(t,n)}function Ng(e){const t=new Map;e.forEach((o,s)=>{if(!ui(o))return;const i=Kl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Eg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Rg(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Gl(s.createdAt??"")-Gl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ag(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=mt(i,["label"])??mt(i,["branch_label","branchLabel"])??mt(i,["description"])??"User input",l=jg(i,["step"]),c=mt(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=_g(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0})}return t}function _g(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 jg(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 Rg(e,t){return{...e,metadata:Io(e.metadata,t.metadata)??null,config:Io(e.config,t.config)??null,parentConfig:Io(e.parentConfig,t.parentConfig)??null,next:Pg(e.next,t.next)??null,tasks:Og(e.tasks,t.tasks)??null,values:Io(e.values,t.values)??null}}function Io(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 Pg(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 Og(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 Mg(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 Dg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Lg(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=Or(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Or(r.state,`${o}-state`);if(s)return s}}return null}function Lg(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...p]=e,h=typeof a=="string"&&a.trim()?a:t,x=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",m=Array.isArray(d)?d:void 0,v=p.length?p[p.length-1]:void 0;return{id:h,name:x,interrupts:m,state:v!==void 0?v:f}}const n=Lt(e);if(!n)return null;const r=mt(n,["id","thread_id","taskId"])??t,o=mt(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 Or(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=ql(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Or(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=Or(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Or(l,t,n+1,r);if(c)return c}}return null}function ql(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=mt(n,["type","event","kind"]),o=mt(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=ql(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 Gl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function $g(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=kg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Lt(o.additional_kwargs)??Lt(o.additionalKwargs),d=Lt(o.response_metadata)??Lt(o.responseMetadata),f=mt(c,["createdAt","created_at"])??mt(o,["created_at","createdAt"]),p=mt(c,["checkpointId","checkpoint_id"]),h=mt(c,["checkpointNs","checkpoint_ns"]),x=Fg(o.content),m={id:l,role:i,content:x};f&&(m.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(m.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(m.model=String(d.model_name)),!m.model&&typeof o.model=="string"&&(m.model=o.model),p&&(m.checkpointId=p),h&&(m.checkpointNs=h),Jt()&&console.debug("[historyUtils.convertHistoryMessage]",{id:l,role:i,hasDataArtifact:!!o.artifact,hasFallbackArtifact:!!r.artifact,dataArtifactType:typeof o.artifact,dataArtifactKeys:o.artifact?Object.keys(o.artifact):[],data_artifact:o.artifact,fallback_artifact:r.artifact});const v=Hg(Lt(o.artifact??r.artifact??o.artifacts??r.artifacts));v&&(m.artifact=v,Jt()&&console.debug("[historyUtils.convertHistoryMessage] Artifact set:",{id:l,artifact:v}));const g=Kg(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),b=d?{...d}:void 0;g&&Object.keys(g).length&&(m.additionalKwargs=g),b&&Object.keys(b).length&&(m.responseMetadata=b);const S=zg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=Bg(o,m.content);k&&(m.content=k)}return m}function Fg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Yl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Yl(e);return t?[t]:[]}return[]}function Yl(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=mt(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=mt(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 Xl(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=mt(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 Xl(e,t){var s;const n=mt(e,["id","call_id"])??t,r=mt(e,["name"])??mt(Lt(e.function),["name"]);if(!n||!r)return null;const o=Vg(e.args??e.arguments??((s=Lt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function zg(e){return Array.isArray(e)?e.map((t,n)=>Xl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Bg(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 Hg(e){if(!e)return;Jt()&&console.debug("[historyUtils] normalizeArtifactCandidate:",{candidateKeys:Object.keys(e),candidate:e,plots:e.plots});const t=Ug(e.plots);if(Jt()&&console.debug("[historyUtils] Normalized plots:",{inputPlots:e.plots,normalizedCount:t.length,normalized:t}),t.length!==0)return{plots:t}}function Ug(e){return Array.isArray(e)?e.map(t=>Wg(t)).filter(t=>!!t):[]}function Wg(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;if(Jt()&&console.debug("[historyUtils.normalizePlotEntry]",{plotKeys:Object.keys(t),hasContent_base64:!!n,content_base64_length:n==null?void 0:n.length,hasUrl:!!r,format:o,plotId:s,artifactId:i,plot:t}),!n&&!r)return Jt()&&console.debug("[historyUtils.normalizePlotEntry] Invalid plot - no base64 or URL:",t),null;const a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),Jt()&&console.debug("[historyUtils.normalizePlotEntry] Normalized:",{normalized:a}),a}function Vg(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 mt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Kg(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 dr=120;function qg(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>dr?`${n.slice(0,dr-3)}…`:n:""}function Gg(e){var r,o;const t=[(r=e.additionalKwargs)==null?void 0:r.summary,(o=e.responseMetadata)==null?void 0:o.summary];for(const s of t)if(typeof s=="string"&&s.trim()){const i=s.trim();return i.length>dr?`${i.slice(0,dr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>dr?`${n.slice(0,dr-3)}…`:n:""}function Jl(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=qg(n.content)||Gg(n);o&&t.set(n.id,o)}return t}function Zl(e={}){const t=w.useMemo(()=>Cn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[c,d]=w.useState(null),[f,p]=w.useState(""),[h,x]=w.useState(null),[m,v]=w.useState(0),[g,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),E=w.useRef(null),N=w.useRef(null),_=w.useRef(null),$=w.useCallback(A=>{o(A)},[]),P=w.useCallback(()=>{p(""),x(null),d(null),E.current=null,N.current=null,_.current=null},[]),D=w.useCallback(()=>{var A;console.debug("[use-chat] stop() invoked - aborting stream"),(A=S.current)==null||A.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,v(0)},[]),F=w.useCallback((A,z,j)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),E.current=null,N.current=null,_.current=null;const K=new AbortController;S.current=K;let B=null,R=null,Y=!1;return T.current={threadId:A.threadId??null,headers:{}},(async()=>{var se,be,Oe,q,H,J,L,G,Z,fe,oe,Ae,qe,Fe,Ze,ie,we,_e;const X=Le=>{var Ue;try{const Ge=JSON.parse(JSON.stringify(Le));return(Ue=Ge==null?void 0:Ge.payload)!=null&&Ue.files_info&&Array.isArray(Ge.payload.files_info)&&(Ge.payload.files_info=Ge.payload.files_info.map(ze=>({...ze,data:ze!=null&&ze.data?`<base64 ${String(ze.data).length} chars>`:ze==null?void 0:ze.data}))),Ge}catch{return Le}};try{let Le={};try{if(r)Le={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const ot=window.__AUTH_TOKEN__,bt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let V=null;try{const Ce=(be=window.localStorage)==null?void 0:be.getItem("chat-settings");Ce&&(V=((Oe=JSON.parse(Ce))==null?void 0:Oe.apiKey)||null)}catch{}const ce=ot||bt||V||null;ce&&(Le={Authorization:`Bearer ${ce}`})}}catch{}console.debug("[use-chat] POST",t+n,X(A));let Ue={};if(typeof window<"u")try{const tt=(q=window.localStorage)==null?void 0:q.getItem("authSessionId");tt&&(Ue={"X-Session-Id":tt})}catch{}const Ge={...Le,...Ue,...s.current},ze={"Content-Type":"application/json",Accept:"text/event-stream",...Ge},He=await fetch(t+n,{method:"POST",headers:ze,body:JSON.stringify(A),signal:K.signal,credentials:i});if(T.current&&(T.current.headers=Ge),!He.ok||!He.body){const tt=await He.text().catch(()=>"");console.debug("[use-chat] non-OK response",He.status,tt==null?void 0:tt.slice(0,500));const ot=`stream ${He.status}${tt?": "+tt:""}`;throw(H=j==null?void 0:j.onConnectionError)==null||H.call(j,ot),Y=!0,B="error",R=ot,new Error(ot)}b(!0);const et=He.body.getReader(),Et=new TextDecoder;let xt="",ct=[];C.current=0,v(0);let ft=0,pt=null;const yt=()=>{if(ct.length){const tt=ct.join("");ct=[],k.current&&p(ot=>ot+tt)}pt=null},Nt=()=>{typeof window<"u"&&pt==null&&(pt=requestAnimationFrame(yt))};let Ye=Date.now();const jt=setInterval(()=>{var tt;if(Date.now()-Ye>18e5){const ot="Stream idle timeout";d(ot),B="error",R=ot,K.abort(),(tt=j==null?void 0:j.onError)==null||tt.call(j,ot)}},5e3),Sn=1024*1024;try{const tt=He.headers.get("X-Thread-Id")||He.headers.get("x-thread-id"),ot=He.headers.get("X-Thread-Created")||He.headers.get("x-thread-created"),bt=tt??null,V=String(ot??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:bt}),(J=j==null?void 0:j.onOpen)==null||J.call(j,{threadId:bt,created:V});;){const{value:ce,done:Ce}=await et.read();if(Ce)break;xt+=Et.decode(ce,{stream:!0}),xt.length>Sn&&(xt="",console.warn("Stream buffer reset: exceeded 1MB"));let O;for(;(O=xt.indexOf(`
36
36
 
37
- `))>=0;){const Q=xt.slice(0,M);xt=xt.slice(M+2);const oe=Vg(Q);if(!oe)continue;let Le;try{Le=JSON.parse(oe)}catch{console.debug("[use-chat] malformed SSE:",oe.slice(0,200));continue}const ge=Wg(Le)?Le.data:Le;Ye=Date.now();const ct=ge.seq;if(ct!==void 0){if(ct<=ft){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ct,lastProcessedSeq:ft,type:ge.type});continue}ft>0&&ct>ft+1&&((L=_==null?void 0:_.onGap)==null||L.call(_,{from:ft,to:ct})),ft=ct,C.current=ct,v(ct)}if(console.debug("[use-chat] received event",{seq:ge.seq,type:ge.type,preview:(()=>{var we;try{return ge.type==="message_delta"?{deltaTypes:(we=ge.delta)==null?void 0:we.map(tt=>tt.type),textLen:(ge.delta||[]).filter(tt=>tt.type==="text").map(tt=>String(tt.text||"").length)}:ge.content||ge.delta?{hasContent:!0}:{}}catch(tt){return{err:String(tt)}}})()}),ge.type==="checkpoint")E.current=ge.checkpointId??null,N.current=ge.checkpointNs??null,x(ge.checkpointId??null);else if(ge.type==="state_history"){j.current=ge;try{const tt=cr(ge).latest;tt&&(E.current=tt.checkpointId??null,N.current=tt.checkpointNs??null,x(tt.checkpointId??null))}catch(we){console.warn("[use-chat] Failed to hydrate state_history payload",we)}}try{z==null||z(ge)}catch(we){console.error("[use-chat] Error in onEvent callback:",we,"for event:",ge.type)}if(ge.type==="token"&&e.autoAppendAssistant!==!1)lt.push(ge.content),Nt();else if(ge.type==="message_delta"){const we=ge.delta.filter(tt=>tt.type==="text").map(tt=>tt.text).join("");we&&e.autoAppendAssistant!==!1&&(lt.push(we),Nt())}else if(ge.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(G=_==null?void 0:_.onHeartbeat)==null||G.call(_,ge)}catch(we){console.warn("[use-chat] heartbeat callback failed",we)}}else if(pt!==null&&cancelAnimationFrame(pt),yt(),ge.type==="checkpoint")x(ge.checkpointId);else if(ge.type==="error"){const we=ge;if(d(we.message),B="error",R=we.message,we.error_type==="auth_error"||we.code==="TOKEN_EXPIRED"||((Z=we.message)==null?void 0:Z.includes("token"))||((fe=we.message)==null?void 0:fe.includes("401"))||((re=we.message)==null?void 0:re.includes("unauthorized"))||((Ae=we.message)==null?void 0:Ae.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",we.message);try{(qe=_==null?void 0:_.onAuthError)==null||qe.call(_,we.message)}catch(rn){console.warn("[use-chat] onAuthError handler failed",rn)}K.abort()}}}}yt(),B===null&&!K.signal.aborted&&(B="complete")}catch(et){if(et.name==="AbortError")B=B??"aborted";else{const ot=et.message||String(et);B="error",R=ot,d(ot),(Fe=_==null?void 0:_.onError)==null||Fe.call(_,ot)}}finally{try{await Qe.cancel()}catch{}finally{(Je=Qe.releaseLock)==null||Je.call(Qe)}pt!==null&&typeof window<"u"&&window.cancelAnimationFrame(pt),clearInterval(_t)}}catch(De){if(De.name==="AbortError")B=B??"aborted";else{const Ue=De.message||String(De);B="error",R=Ue,d(Ue),(ie=_==null?void 0:_.onError)==null||ie.call(_,Ue),Y||((be=_==null?void 0:_.onConnectionError)==null||be.call(_,Ue),Y=!0)}}finally{const De=C.current,Ue=E.current,Ge=N.current,ze=j.current,He=B??(K.signal.aborted?"aborted":R?"error":"complete");try{(je=_==null?void 0:_.onClosed)==null||je.call(_,{reason:He,lastSeq:De,lastCheckpointId:Ue,lastCheckpointNs:Ge,lastStateHistory:ze,error:R})}catch(Qe){console.warn("[use-chat] onClosed callback failed",Qe)}l(!1),b(!1),S.current=null,C.current=0,v(0),T.current=null}})(),{close:()=>K.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var A;k.current=!1,(A=S.current)==null||A.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:m,connected:g,stream:F,stop:D,clear:P,setToken:$}}function Wg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Vg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
38
- `)}function Kg(e){return e.type!=="token"}const qg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Gg(e,t){var n;switch(t.type){case"reset":return{messages:ci(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=ci(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=ci(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Ql(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Ql(o,s),e):e}case"interrupt_response":return{...e,messages:ec(e.messages),pendingInterrupt:null};default:return e}}function Zl(e=[]){const[t,n]=w.useReducer(Gg,{...qg,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function Ql(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Zg(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??tc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:oc(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:x,newMeta:m,changed:v}=Yg(d.content,t.delta,p,h);if(!v)return e;const g={...d,content:x},b=Io(l,c,g),S={...f,[a]:m};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??tc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.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 p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=nc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=rc(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,x=(p==null?void 0:p.id)??`tool-${h}`,m=d[0]??h,v={type:"tool_call",id:m,name:c,args:t.args};if(p){const S=di(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?Io(e.messages,C,k):e.messages,E=No(k,d),N=fi(e.toolIndex,x,E);return{...e,messages:T,toolIndex:N}}const g={id:x,role:"tool",name:c,createdAt:new Date().toISOString(),content:[v],additionalKwargs:di(void 0,d.length?d:[m],c,t.args)},b=No(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:fi(e.toolIndex,x,b)}}if(t.type==="tool_end"){const a=nc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=rc(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,x=No(d,a);let m=t.output;if(typeof t.output=="string")try{const E=t.output.trim();(E.startsWith("{")||E.startsWith("["))&&(m=JSON.parse(E))}catch{m=t.output}const v=t.artifact??(d==null?void 0:d.artifact),g={type:"text",text:typeof m=="string"?m:JSON.stringify(m)},b=(d==null?void 0:d.createdAt)??new Date().toISOString(),S=di(d??void 0,x.length?x:a,f),k={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[g],createdAt:b,artifact:v??void 0,additionalKwargs:S},C=c>=0?Io(e.messages,c,k):[...e.messages,k],T=No(k,a.length?a:x);return{...e,messages:C,toolIndex:fi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Jg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=cr(t),l=a.interrupt,c=a.latest,d=l===null?ec(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function ci(e){return e.filter(t=>{var i;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(a=>{var l;return a&&a.type==="text"&&((l=a.text)==null?void 0:l.trim())}),r=(t.content||[]).some(a=>a&&a.type==="image_url"),o=(i=t.artifact)==null?void 0:i.data,s=!!o&&!!(typeof o.content_base64=="string"&&o.content_base64.trim()||typeof o.url=="string"&&o.url.trim());return!!(n||r||s)})}function Io(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function ec(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 tc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function nc(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 ui(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 di(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=ui(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function No(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=ui(e);for(const o of r)n.add(o);return Array.from(n)}function fi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function rc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(ui(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function oc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Yg(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??oc(e);let l="",c=e.slice();if(s){const f=Xg(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",x={...p,text:h+l};c=[...c.slice(0,c.length-1),x]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function sc(e){return e.replace(/\s+/g," ").trim()}function Xg(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=sc(e),o=sc(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 Jg(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 Io(e,r,s)}return e}function Zg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const ic=200;function Qg({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),x=w.useRef(null),m=w.useCallback(P=>{try{const D=globalThis.structuredClone;if(typeof D=="function")return D(P)}catch{}try{return JSON.parse(JSON.stringify(P))}catch{return P}},[]),v=w.useCallback((P,D)=>{if(!P)return;const F=p.current.get(P)??[],A=m(D),z=F.length>=ic?[...F.slice(F.length-ic+1),A]:[...F,A];p.current.set(P,z)},[m]),g=w.useCallback(P=>{P&&p.current.set(P,[])},[]),b=w.useCallback(P=>{const D=P??f.current;if(!D)return;const F=p.current.get(D);F!=null&&F.length&&F.forEach(A=>{try{n(A)}catch(z){console.error("[useChatStreamingService] Failed to replay buffered event",z)}})},[n]),S=w.useCallback(P=>{var A,z,_,K,B;const D=P.seq??null;if(D!==null){const R=d.current;if(R!==null){if(D<=R)return;D>R+1&&(s==null||s({from:R,to:D}))}d.current=D}if(P.type==="thread_info"){f.current=P.threadId,h.current&&(h.current.threadIdGuess=P.threadId),x.current=P,g(P.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",P);try{t(P)}catch(R){console.error("[useChatStreamingService] Error in onThreadInfo handler:",R)}return}if(P.type==="heartbeat"){try{c==null||c(P)}catch(R){console.error("[useChatStreamingService] Error in onHeartbeat handler:",R)}return}if(P.type==="error"){const R=P;if(R.error_type==="auth_error"||R.code==="TOKEN_EXPIRED"||((A=R.message)==null?void 0:A.includes("token"))||((z=R.message)==null?void 0:z.includes("401"))||((_=R.message)==null?void 0:_.includes("unauthorized"))||((K=R.message)==null?void 0:K.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",R.message);try{l==null||l(R.message)}catch(X){console.warn("[useChatStreamingService] onAuthError handler failed",X)}}}const F=P.threadId??(P.type==="state_history"?P.threadId:void 0)??f.current??((B=h.current)==null?void 0:B.threadIdGuess)??null;if(P.type==="state_history"){f.current=F??f.current;try{r==null||r(P)}catch(R){console.error("[useChatStreamingService] onStateHistory handler failed",R)}}if(Kg(P)){P.type==="checkpoint"||P.type==="state_history"?g(F??null):v(F??null,P);try{n(P)}catch(R){console.error("[useChatStreamingService] Error in onMessageEvent handler:",R)}return}try{o==null||o(P)}catch(R){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",R)}},[v,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:E,setToken:N}=Jl({baseUrl:e,token:void 0}),j=w.useCallback((P,D)=>{d.current=null,x.current=null,f.current=P.threadId??null,h.current={request:P,callbacks:D,manualStop:!1,threadIdGuess:P.threadId??null},k(P,S,{onOpen:D==null?void 0:D.onOpen,onError:F=>{var A;(A=D==null?void 0:D.onError)==null||A.call(D,F)},onGap:(D==null?void 0:D.onGap)??s,onConnectionError:F=>{var A;a==null||a(F),(A=D==null?void 0:D.onConnectionError)==null||A.call(D,F)},onAuthError:F=>{var A;l==null||l(F),(A=D==null?void 0:D.onAuthError)==null||A.call(D,F)},onHeartbeat:F=>{var A;try{c==null||c(F)}catch(z){console.warn("[useChatStreamingService] onHeartbeat handler failed",z)}try{(A=D==null?void 0:D.onHeartbeat)==null||A.call(D,F)}catch(z){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",z)}},onClosed:F=>{var K,B,R,Y;const A=((K=h.current)==null?void 0:K.manualStop)??!1,z=f.current??((B=h.current)==null?void 0:B.threadIdGuess)??((R=F.lastStateHistory)==null?void 0:R.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&A)&&g(z);const _={...F,threadId:z,threadInfo:x.current,manualStop:A};try{i==null||i(_)}catch(X){console.warn("[useChatStreamingService] onStreamClosed handler failed",X)}try{(Y=D==null?void 0:D.onClosed)==null||Y.call(D,_)}catch(X){console.warn("[useChatStreamingService] downstream onClosed handler failed",X)}h.current&&(h.current=null)}})},[g,S,l,a,c,s,i,k]),$=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:j,stop:$,isStreaming:T,error:E,setAuthToken:N,replayBufferedEvents:b}),[j,$,T,E,N,b])}const ac=w.createContext(null),lc=w.createContext(null),cc=w.createContext(null);w.createContext(!1);function ex({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a}){const{api:l,baseUrl:c}=ai(),d=w.useMemo(()=>Cn(c),[c]),[f,p]=w.useState([]),[h,x]=w.useState(t),[m,v]=w.useState(!1),[g,b]=w.useState(null),[S,k]=w.useState(!1),[C,T]=w.useState(null),{state:E,seed:N,prepend:j,pushUser:$,onEvent:P}=Zl(),[D,F]=w.useState(!1),[A,z]=w.useState(!1),[_,K]=w.useState(null),[B,R]=w.useState([]),[Y,X]=w.useState([]),[se,ve]=w.useState(!1),Oe=w.useMemo(()=>B.flatMap(V=>V.messages??[]),[B]),q=w.useMemo(()=>Xl(Oe),[Oe]),H=w.useRef(h),J=w.useRef(null),L=w.useRef(null),G=w.useRef(null),Z=w.useRef(null),fe=w.useRef(!1),re=w.useRef(null),Ae=w.useRef(new Map),qe=w.useRef(new Map);w.useEffect(()=>{H.current=h},[h]);const Fe=w.useCallback(async()=>{v(!0),b(null);try{const V=await l.listThreads();p(V??[])}catch(V){const ce=String(V);b(ce),s==null||s(ce)}finally{v(!1)}},[l,s]),Je=w.useCallback(V=>{if(!(V!=null&&V.threadId))return;const ce={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};p(Ce=>Ce.some(Q=>Q.threadId===ce.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",ce.threadId),Ce):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",ce.threadId),[ce,...Ce]))},[]),ie=w.useCallback(V=>{const ce=V.threadId??H.current;if(!ce||H.current&&H.current!==ce)return;const{checkpoints:Ce,timeline:M}=cr(V);if(!Ce.length)return;const Q=Ce.find(oe=>oe.messages&&oe.messages.length>0)??Ce.find(oe=>!!oe.checkpointId)??Ce[0];N((Q==null?void 0:Q.messages)??[],{checkpointId:(Q==null?void 0:Q.checkpointId)??null,checkpointNs:(Q==null?void 0:Q.checkpointNs)??null}),X(M),R(Ce),F(!!(Q!=null&&Q.nextCursor)),K((Q==null?void 0:Q.nextCursor)??null),re.current=`${ce}:latest`,L.current=null,G.current=null},[N]),be=w.useCallback(V=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",V.threadId),Je(V),H.current!==V.threadId&&((V.created??!H.current)&&(L.current=V.threadId),G.current=V.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(V.threadId))},[Je]),{startStream:je,stop:De,isStreaming:Ue,error:Ge,setAuthToken:ze}=Qg({baseUrl:d,onThreadInfo:be,onMessageEvent:P,onStateHistory:ie,onUnhandledEvent:V=>{console.warn("[ChatSessionProvider] Unhandled event:",V.type)},onAuthError:i}),He=w.useCallback(async V=>{try{const ce=await l.createThread(V);return x(ce.threadId),await Fe(),ce.threadId}catch(ce){return s==null||s(String(ce)),null}},[l,Fe,s]),Qe=w.useCallback(async V=>{const ce=f;p(M=>M.filter(Q=>Q.threadId!==V));const Ce=new AbortController;qe.current.set(V,Ce);try{await l.deleteThread(V),H.current===V&&(x(null),N([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",V)}catch(M){console.error("[ChatSessionProvider] Delete failed, restoring thread:",V,M),p(ce),s==null||s(`Failed to delete thread: ${String(M)}`)}finally{qe.current.delete(V)}},[f,l,N,s]),Et=w.useCallback(async(V,ce)=>{try{await l.updateThread(V,ce),await Fe()}catch(Ce){s==null||s(String(Ce))}},[l,Fe,s]),xt=w.useCallback(async(V,ce)=>{if(!V)return;const Ce=`${V}:${ce??"latest"}`,M=Ae.current.get(Ce);if(M)return M;const Q=(async()=>{const oe=V;k(!0),T(null);try{const Le=await l.getStateHistory({threadId:oe,checkpointId:ce||void 0});if(H.current!==oe){console.log(`[ChatSessionProvider] Thread changed during load (was ${oe}, now ${H.current}), discarding stale data`);return}const{checkpoints:ge,timeline:ct}=cr(Le),we=ge.find(tt=>tt.messages&&tt.messages.length>0)??(ce?ge.find(tt=>tt.checkpointId===ce):null)??ge[0];N((we==null?void 0:we.messages)??[],{checkpointId:(we==null?void 0:we.checkpointId)??null,checkpointNs:(we==null?void 0:we.checkpointNs)??null}),X(ct),R(ge),F(!!(we!=null&&we.nextCursor)),K((we==null?void 0:we.nextCursor)??null)}catch(Le){if(H.current===oe){const ge=String(Le);T(ge),s==null||s(ge)}}finally{k(!1)}})();Ae.current.set(Ce,Q);try{await Q}finally{Ae.current.delete(Ce)}return H.current===V&&(re.current=Ce),Q},[l,N,s]),lt=w.useCallback(async(V,ce)=>{Z.current=V;try{await xt(V,ce)}finally{Z.current===V&&(Z.current=null)}},[xt]);w.useEffect(()=>{if(!o||!h||S||Ue)return;if(L.current===h){L.current=null,J.current=h;return}if(G.current===h){J.current=h;return}if(Z.current===h){Z.current=null,J.current=h;return}if(J.current===h)return;J.current=h;const V=!fe.current&&!!n&&h===t;let ce;V&&n?(ce=n,fe.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",ce,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const Ce=`${h}:${ce??"latest"}`;re.current!==Ce&&lt(h,ce)},[o,h,n,r,t,S,Ue,lt]);const ft=w.useCallback(async(V,ce)=>{const Ce=H.current;if(!Ce)return;const M=Ce;ve(!0);try{const Q=await l.getStateHistory({threadId:M,checkpointId:V,checkpointNs:ce??void 0});if(H.current!==M){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${M}, now ${H.current}), discarding stale data`);return}const{checkpoints:oe,timeline:Le}=cr(Q),ge=oe.find(ct=>ct.checkpointId===V&&(ce?ct.checkpointNs===ce:!0));if(!ge){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:V,checkpointNs:ce});return}X(Le),R(oe),N(ge.messages??[],{checkpointId:ge.checkpointId??null,checkpointNs:ge.checkpointNs??null})}catch(Q){H.current===M&&(s==null||s(String(Q)))}finally{ve(!1)}},[l,N,s]),pt=w.useCallback((V,ce)=>{N(E.messages,{checkpointId:V??null,checkpointNs:ce??null})},[N,E.messages]),yt=w.useCallback(async()=>{H.current&&await lt(H.current)},[lt]),Nt=w.useCallback(async()=>{if(!H.current||!_)return;const V=H.current;z(!0);try{const ce=await l.getStateHistory({threadId:V,checkpointId:_});if(H.current!==V){console.log(`[ChatSessionProvider] Thread changed during history load (was ${V}, now ${H.current}), discarding stale data`);return}const{checkpoints:Ce}=cr(ce);if(Ce.length>0){const M=Ce[Ce.length-1];j((M==null?void 0:M.messages)??[]),F(!!(M!=null&&M.nextCursor)),K((M==null?void 0:M.nextCursor)??null)}}catch(ce){H.current===V&&(s==null||s(String(ce)))}finally{z(!1)}},[l,_,j,s]),Ye=w.useCallback(async()=>{N([],{}),x(null),De(),R([]),X([]),F(!1),K(null),k(!1),ve(!1),z(!1),T(null);try{await l.getAgent("default")}catch(V){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",V)}},[N,De,l]),_t=w.useCallback(async(V,ce,Ce)=>{const M=H.current;if(!M)throw new Error("No active thread to handle interrupt");const Q=ce?Ce??!0:!1;try{const oe={threadId:M,checkpointId:E.lastCheckpointId??void 0,checkpointNs:E.lastCheckpointNs??void 0,command:{kind:"resume",value:Q}};je(oe)}catch(oe){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${V}:`,oe),oe}},[E.lastCheckpointId,E.lastCheckpointNs,je]);w.useEffect(()=>{Fe()},[Fe]),w.useEffect(()=>{a==null||a(h)},[h,a]);const Sn=w.useCallback(async(V,ce)=>{let Ce=H.current;const M=(V==null?void 0:V.text)??"";if(!Ce&&!M)return;if(!Ce&&M){const ct=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),we=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);Ce=`${ct}${we}`,L.current=Ce,x(Ce)}const{contentParts:Q}=await wg(l,(V==null?void 0:V.attachments)??[]),oe=[...Q];M!=null&&M.trim()&&oe.push({type:"text",text:M});const Le={id:`msg-${Date.now()}`,role:"user",content:oe,createdAt:new Date().toISOString()};$(Le);const ge={threadId:Ce,payload:{messages:[Le]},checkpointId:(ce==null?void 0:ce.checkpointId)??E.lastCheckpointId??void 0,checkpointNs:(ce==null?void 0:ce.checkpointNs)??E.lastCheckpointNs??void 0};je(ge)},[l,He,$,E,je]),et=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:He,deleteThread:Qe,renameThread:Et,refreshThreads:Fe}}),[f,h,m,g,He,Qe,Et,Fe]),ot=w.useMemo(()=>({threadId:h,messages:E.messages,interrupt:null,checkpoint:{id:E.lastCheckpointId??null,namespace:E.lastCheckpointNs??null},checkpoints:B,timelineCheckpoints:Y,metadata:null,isLoading:S,isHistoryLoading:A,isLoadingCheckpoint:se,error:C,hasMore:D,loadOlder:Nt,clearState:Ye,navigateToCheckpoint:ft,setCurrentCheckpointId:pt,returnToLatest:yt,loadThread:lt,clearThread:Ye,respondToInterrupt:_t,messagePreviews:q}),[h,E,B,Y,S,A,se,C,D,Nt,Ye,ft,pt,yt,lt,_t,q]),bt=w.useMemo(()=>({isStreaming:Ue,error:Ge,connectionState:Ue?"connected":"idle",submit:Sn,send:Sn,stop:De,setAuthToken:ze}),[Ue,Ge,Sn,De,ze]);return u.jsx(ac.Provider,{value:et,children:u.jsx(lc.Provider,{value:ot,children:u.jsx(cc.Provider,{value:bt,children:e})})})}function Ao(){const e=w.useContext(ac);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(lc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function uc(){const e=w.useContext(cc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function _o({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l}){return u.jsx(vg,{apiConfig:t,children:u.jsx(ex,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function te(...e){return Kh.twMerge(Vh.clsx(e))}const tx=fo.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"}}),nt=y.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Un.Slot:"button";return u.jsx(i,{className:te(tx({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const dc=y.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:te("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));dc.displayName="Textarea";function fc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const x=i!==void 0,[m,v]=w.useState(e),g=(x?i:m)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{x||(v(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,x]);const E=w.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,g]);const N=w.useCallback((z,{fromUser:_})=>{x||v(z),_&&(a==null||a(z))},[x,a]),j=w.useCallback(async z=>{z&&z.preventDefault();const _=(g??"").trim();if(!_&&!h)return;const K=++C.current;T.current={id:K,shouldClear:!0},S(()=>{var B,R,Y;try{const X=l(_);X&&typeof X.then=="function"?X.then(()=>{var se,ve;((se=T.current)==null?void 0:se.id)===K&&T.current.shouldClear&&(x||(v(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ve=T.current)==null?void 0:ve.id)===K&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===K&&(T.current=null)}):(((B=T.current)==null?void 0:B.id)===K&&T.current.shouldClear&&(x||(v(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((R=T.current)==null?void 0:R.id)===K&&(T.current=null))}catch{((Y=T.current)==null?void 0:Y.id)===K&&(T.current=null)}})},[g,l,h,x,a]),$=w.useCallback(z=>{const _=z.target.value;N(_,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),P=w.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),j()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[j,t,c]),A=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:z=>void j(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(dc,{ref:k,value:g,onChange:$,onKeyDown:P,placeholder:t?"Edit your message...":n,className:A,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(le.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||b,children:u.jsx(le.Send,{size:16})})})]})})}const nx=w.memo(fc);function me(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 pc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function pi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=pc(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():pc(e[o],null)}}}}function Ve(...e){return y.useCallback(pi(...e),e)}function rx(e,t){const n=y.createContext(t),r=s=>{const{children:i,...a}=s,l=y.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=y.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=y.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...x}=f,m=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,v=y.useMemo(()=>x,Object.values(x));return u.jsx(m.Provider,{value:v,children:h})};c.displayName=s+"Provider";function d(f,p){var m;const h=((m=p==null?void 0:p[e])==null?void 0:m[l])||a,x=y.useContext(h);if(x)return x;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>y.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return y.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,ox(o,...t)]}function ox(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var At=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},sx=y[" useInsertionEffect ".trim().toString()]||At;function dr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ix({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=y.useRef(e!==void 0);y.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=y.useCallback(d=>{var f;if(a){const p=ax(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function ix({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),o=y.useRef(n),s=y.useRef(t);return sx(()=>{s.current=t},[t]),y.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ax(e){return typeof e=="function"}var lx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=lx.reduce((e,t)=>{const n=Un.createSlot(`Primitive.${t}`),r=y.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function hc(e,t){e&&po.flushSync(()=>e.dispatchEvent(t))}function hi(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:v,children:g}=m,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:v,itemMap:S,collectionRef:b,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Un.createSlot(a),c=w.forwardRef((m,v)=>{const{scope:g,children:b}=m,S=s(a,g),k=Ve(v,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Un.createSlot(d),h=w.forwardRef((m,v)=>{const{scope:g,children:b,...S}=m,k=w.useRef(null),C=Ve(v,k),T=s(d,g);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:b})});h.displayName=d;function x(m){const v=s(e+"CollectionConsumer",m);return w.useCallback(()=>{const b=v.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(v.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[v.collectionRef,v.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},x,r]}var cx=y.createContext(void 0);function Ro(e){const t=y.useContext(cx);return e||t||"ltr"}function jt(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function ux(e,t=globalThis==null?void 0:globalThis.document){const n=jt(e);y.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var dx="DismissableLayer",mi="dismissableLayer.update",fx="dismissableLayer.pointerDownOutside",px="dismissableLayer.focusOutside",mc,gc=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=y.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=y.useContext(gc),[d,f]=y.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=y.useState({}),x=Ve(t,E=>f(E)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=m.indexOf(v),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=g,C=gx(E=>{const N=E.target,j=[...c.branches].some($=>$.contains(N));!k||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),T=xx(E=>{const N=E.target;[...c.branches].some($=>$.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return ux(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),y.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(mc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),xc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=mc)}},[d,p,n,c]),y.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),xc())},[d,c]),y.useEffect(()=>{const E=()=>h({});return document.addEventListener(mi,E),()=>document.removeEventListener(mi,E)},[]),u.jsx(_e.div,{...l,ref:x,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:me(e.onFocusCapture,T.onFocusCapture),onBlurCapture:me(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:me(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=dx;var hx="DismissableLayerBranch",mx=y.forwardRef((e,t)=>{const n=y.useContext(gc),r=y.useRef(null),o=Ve(t,r);return y.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(_e.div,{...e,ref:o})});mx.displayName=hx;function gx(e,t=globalThis==null?void 0:globalThis.document){const n=jt(e),r=y.useRef(!1),o=y.useRef(()=>{});return y.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){yc(fx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function xx(e,t=globalThis==null?void 0:globalThis.document){const n=jt(e),r=y.useRef(!1);return y.useEffect(()=>{const o=s=>{s.target&&!r.current&&yc(px,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 xc(){const e=new CustomEvent(mi);document.dispatchEvent(e)}function yc(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?hc(o,s):o.dispatchEvent(s)}var gi=0;function xi(){y.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??vc()),document.body.insertAdjacentElement("beforeend",e[1]??vc()),gi++,()=>{gi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),gi--}},[])}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 yi="focusScope.autoFocusOnMount",vi="focusScope.autoFocusOnUnmount",bc={bubbles:!1,cancelable:!0},yx="FocusScope",Oo=y.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=y.useState(null),c=jt(o),d=jt(s),f=y.useRef(null),p=Ve(t,m=>l(m)),h=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(r){let m=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:_n(f.current,{select:!0})},v=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||_n(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&_n(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const b=new MutationObserver(g);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),b.disconnect()}}},[r,a,h.paused]),y.useEffect(()=>{if(a){Cc.add(h);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(yi,bc);a.addEventListener(yi,c),a.dispatchEvent(g),g.defaultPrevented||(vx(Tx(wc(a)),{select:!0}),document.activeElement===m&&_n(a))}return()=>{a.removeEventListener(yi,c),setTimeout(()=>{const g=new CustomEvent(vi,bc);a.addEventListener(vi,d),a.dispatchEvent(g),g.defaultPrevented||_n(m??document.body,{select:!0}),a.removeEventListener(vi,d),Cc.remove(h)},0)}}},[a,c,d,h]);const x=y.useCallback(m=>{if(!n&&!r||h.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,g=document.activeElement;if(v&&g){const b=m.currentTarget,[S,k]=bx(b);S&&k?!m.shiftKey&&g===k?(m.preventDefault(),n&&_n(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&_n(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(_e.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Oo.displayName=yx;function vx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(_n(r,{select:t}),document.activeElement!==n)return}function bx(e){const t=wc(e),n=Sc(t,e),r=Sc(t.reverse(),e);return[n,r]}function wc(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 Sc(e,t){for(const n of e)if(!wx(n,{upTo:t}))return n}function wx(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 Sx(e){return e instanceof HTMLInputElement&&"select"in e}function _n(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Sx(e)&&t&&e.select()}}var Cc=Cx();function Cx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Tc(e,t),e.unshift(t)},remove(t){var n;e=Tc(e,t),(n=e[0])==null||n.resume()}}}function Tc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Tx(e){return e.filter(t=>t.tagName!=="A")}var kx=y[" useId ".trim().toString()]||(()=>{}),Ex=0;function kn(e){const[t,n]=y.useState(kx());return At(()=>{n(r=>r??String(Ex++))},[e]),t?`radix-${t}`:""}const Ix=["top","right","bottom","left"],Rn=Math.min,Wt=Math.max,Mo=Math.round,Do=Math.floor,pn=e=>({x:e,y:e}),Nx={left:"right",right:"left",bottom:"top",top:"bottom"},Ax={start:"end",end:"start"};function bi(e,t,n){return Wt(e,Rn(t,n))}function En(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function fr(e){return e.split("-")[1]}function wi(e){return e==="x"?"y":"x"}function Si(e){return e==="y"?"height":"width"}const jx=new Set(["top","bottom"]);function hn(e){return jx.has(In(e))?"y":"x"}function Ci(e){return wi(hn(e))}function _x(e,t,n){n===void 0&&(n=!1);const r=fr(e),o=Ci(e),s=Si(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Lo(i)),[i,Lo(i)]}function Rx(e){const t=Lo(e);return[Ti(e),t,Ti(t)]}function Ti(e){return e.replace(/start|end/g,t=>Ax[t])}const kc=["left","right"],Ec=["right","left"],Px=["top","bottom"],Ox=["bottom","top"];function Mx(e,t,n){switch(e){case"top":case"bottom":return n?t?Ec:kc:t?kc:Ec;case"left":case"right":return t?Px:Ox;default:return[]}}function Dx(e,t,n,r){const o=fr(e);let s=Mx(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ti)))),s}function Lo(e){return e.replace(/left|right|bottom|top/g,t=>Nx[t])}function Lx(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ic(e){return typeof e!="number"?Lx(e):{top:e,right:e,bottom:e,left:e}}function $o(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 Nc(e,t,n){let{reference:r,floating:o}=e;const s=hn(t),i=Ci(t),a=Si(i),l=In(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(fr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const $x=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Nc(c,r,l),p=r,h={},x=0;for(let m=0;m<a.length;m++){const{name:v,fn:g}=a[m],{x:b,y:S,data:k,reset:C}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,h={...h,[v]:{...h[v],...k}},C&&x<=50&&(x++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Nc(c,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Or(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=En(t,e),x=Ic(h),v=a[p?f==="floating"?"reference":"floating":f],g=$o(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=$o(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(g.top-C.top+x.top)/k.y,bottom:(C.bottom-g.bottom+x.bottom)/k.y,left:(g.left-C.left+x.left)/k.x,right:(C.right-g.right+x.right)/k.x}}const Fx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=En(e,t)||{};if(c==null)return{};const f=Ic(d),p={x:n,y:r},h=Ci(o),x=Si(h),m=await i.getDimensions(c),v=h==="y",g=v?"top":"left",b=v?"bottom":"right",S=v?"clientHeight":"clientWidth",k=s.reference[x]+s.reference[h]-p[h]-s.floating[x],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[x]);const N=k/2-C/2,j=E/2-m[x]/2-1,$=Rn(f[g],j),P=Rn(f[b],j),D=$,F=E-m[x]-P,A=E/2-m[x]/2+N,z=bi(D,A,F),_=!l.arrow&&fr(o)!=null&&A!==z&&s.reference[x]/2-(A<D?$:P)-m[x]/2<0,K=_?A<D?A-D:A-F:0;return{[h]:p[h]+K,data:{[h]:z,centerOffset:A-z-K,..._&&{alignmentOffset:K}},reset:_}}}),zx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:m=!0,...v}=En(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=In(o),b=hn(a),S=In(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[Lo(a)]:Rx(a)),T=x!=="none";!p&&T&&C.push(...Dx(a,m,x,k));const E=[a,...C],N=await Or(t,v),j=[];let $=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(N[g]),f){const A=_x(o,i,k);j.push(N[A[0]],N[A[1]])}if($=[...$,{placement:o,overflows:j}],!j.every(A=>A<=0)){var P,D;const A=(((P=s.flip)==null?void 0:P.index)||0)+1,z=E[A];if(z&&(!(f==="alignment"?b!==hn(z):!1)||$.every(B=>hn(B.placement)===b?B.overflows[0]>0:!0)))return{data:{index:A,overflows:$},reset:{placement:z}};let _=(D=$.filter(K=>K.overflows[0]<=0).sort((K,B)=>K.overflows[1]-B.overflows[1])[0])==null?void 0:D.placement;if(!_)switch(h){case"bestFit":{var F;const K=(F=$.filter(B=>{if(T){const R=hn(B.placement);return R===b||R==="y"}return!0}).map(B=>[B.placement,B.overflows.filter(R=>R>0).reduce((R,Y)=>R+Y,0)]).sort((B,R)=>B[1]-R[1])[0])==null?void 0:F[0];K&&(_=K);break}case"initialPlacement":_=a;break}if(o!==_)return{reset:{placement:_}}}return{}}}};function Ac(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function jc(e){return Ix.some(t=>e[t]>=0)}const Bx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=En(e,t);switch(r){case"referenceHidden":{const s=await Or(t,{...o,elementContext:"reference"}),i=Ac(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:jc(i)}}}case"escaped":{const s=await Or(t,{...o,altBoundary:!0}),i=Ac(s,n.floating);return{data:{escapedOffsets:i,escaped:jc(i)}}}default:return{}}}}},_c=new Set(["left","top"]);async function Hx(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=fr(n),l=hn(n)==="y",c=_c.has(i)?-1:1,d=s&&l?-1:1,f=En(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:x}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof x=="number"&&(h=a==="end"?x*-1:x),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Ux=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 Hx(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}}}}},Wx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:g,y:b}=v;return{x:g,y:b}}},...l}=En(e,t),c={x:n,y:r},d=await Or(t,l),f=hn(In(o)),p=wi(f);let h=c[p],x=c[f];if(s){const v=p==="y"?"top":"left",g=p==="y"?"bottom":"right",b=h+d[v],S=h-d[g];h=bi(b,h,S)}if(i){const v=f==="y"?"top":"left",g=f==="y"?"bottom":"right",b=x+d[v],S=x-d[g];x=bi(b,x,S)}const m=a.fn({...t,[p]:h,[f]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},Vx=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=En(e,t),d={x:n,y:r},f=hn(o),p=wi(f);let h=d[p],x=d[f];const m=En(a,t),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+v.mainAxis,C=s.reference[p]+s.reference[S]-v.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var g,b;const S=p==="y"?"width":"height",k=_c.has(In(o)),C=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:v.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?v.crossAxis:0);x<C?x=C:x>T&&(x=T)}return{[p]:h,[f]:x}}}},Kx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=En(e,t),d=await Or(t,c),f=In(o),p=fr(o),h=hn(o)==="y",{width:x,height:m}=s.floating;let v,g;f==="top"||f==="bottom"?(v=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,v=p==="end"?"top":"bottom");const b=m-d.top-d.bottom,S=x-d.left-d.right,k=Rn(m-d[v],b),C=Rn(x-d[g],S),T=!t.middlewareData.shift;let E=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!p){const $=Wt(d.left,0),P=Wt(d.right,0),D=Wt(d.top,0),F=Wt(d.bottom,0);h?N=x-2*($!==0||P!==0?$+P:Wt(d.left,d.right)):E=m-2*(D!==0||F!==0?D+F:Wt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const j=await i.getDimensions(a.floating);return x!==j.width||m!==j.height?{reset:{rects:!0}}:{}}}};function Fo(){return typeof window<"u"}function pr(e){return Rc(e)?(e.nodeName||"").toLowerCase():"#document"}function Vt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(Rc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Rc(e){return Fo()?e instanceof Node||e instanceof Vt(e).Node:!1}function sn(e){return Fo()?e instanceof Element||e instanceof Vt(e).Element:!1}function gn(e){return Fo()?e instanceof HTMLElement||e instanceof Vt(e).HTMLElement:!1}function Pc(e){return!Fo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vt(e).ShadowRoot}const qx=new Set(["inline","contents"]);function Mr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=an(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!qx.has(o)}const Gx=new Set(["table","td","th"]);function Yx(e){return Gx.has(pr(e))}const Xx=[":popover-open",":modal"];function zo(e){return Xx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Jx=["transform","translate","scale","rotate","perspective"],Zx=["transform","translate","scale","rotate","perspective","filter"],Qx=["paint","layout","strict","content"];function ki(e){const t=Ei(),n=sn(e)?an(e):e;return Jx.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)||Zx.some(r=>(n.willChange||"").includes(r))||Qx.some(r=>(n.contain||"").includes(r))}function ey(e){let t=Pn(e);for(;gn(t)&&!hr(t);){if(ki(t))return t;if(zo(t))return null;t=Pn(t)}return null}function Ei(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ty=new Set(["html","body","#document"]);function hr(e){return ty.has(pr(e))}function an(e){return Vt(e).getComputedStyle(e)}function Bo(e){return sn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Pn(e){if(pr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Pc(e)&&e.host||mn(e);return Pc(t)?t.host:t}function Oc(e){const t=Pn(e);return hr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&Mr(t)?t:Oc(t)}function Dr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Oc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Vt(o);if(s){const a=Ii(i);return t.concat(i,i.visualViewport||[],Mr(o)?o:[],a&&n?Dr(a):[])}return t.concat(o,Dr(o,[],n))}function Ii(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Mc(e){const t=an(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=gn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Mo(n)!==s||Mo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ni(e){return sn(e)?e:e.contextElement}function mr(e){const t=Ni(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Mc(t);let i=(s?Mo(n.width):n.width)/r,a=(s?Mo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ny=pn(0);function Dc(e){const t=Vt(e);return!Ei()||!t.visualViewport?ny:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ry(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Vt(e)?!1:t}function qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ni(e);let i=pn(1);t&&(r?sn(r)&&(i=mr(r)):i=mr(e));const a=ry(s,n,r)?Dc(s):pn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Vt(s),h=r&&sn(r)?Vt(r):r;let x=p,m=Ii(x);for(;m&&r&&h!==x;){const v=mr(m),g=m.getBoundingClientRect(),b=an(m),S=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*v.x,k=g.top+(m.clientTop+parseFloat(b.paddingTop))*v.y;l*=v.x,c*=v.y,d*=v.x,f*=v.y,l+=S,c+=k,x=Vt(m),m=Ii(x)}}return $o({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Bo(e).scrollLeft;return t?t.left+n:qn(mn(e)).left+n}function Lc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ho(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function oy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pn(1);const d=pn(0),f=gn(r);if((f||!f&&!s)&&((pr(r)!=="body"||Mr(i))&&(l=Bo(r)),gn(r))){const h=qn(r);c=mr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Lc(i,l):pn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function sy(e){return Array.from(e.getClientRects())}function iy(e){const t=mn(e),n=Bo(e),r=e.ownerDocument.body,o=Wt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Wt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ho(e);const a=-n.scrollTop;return an(r).direction==="rtl"&&(i+=Wt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const $c=25;function ay(e,t){const n=Vt(e),r=mn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ei();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Ho(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,x=Math.abs(r.clientWidth-f.clientWidth-h);x<=$c&&(s-=x)}else c<=$c&&(s+=c);return{width:s,height:i,x:a,y:l}}const ly=new Set(["absolute","fixed"]);function cy(e,t){const n=qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=gn(e)?mr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Fc(e,t,n){let r;if(t==="viewport")r=ay(e,n);else if(t==="document")r=iy(mn(e));else if(sn(t))r=cy(t,n);else{const o=Dc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return $o(r)}function zc(e,t){const n=Pn(e);return n===t||!sn(n)||hr(n)?!1:an(n).position==="fixed"||zc(n,t)}function uy(e,t){const n=t.get(e);if(n)return n;let r=Dr(e,[],!1).filter(a=>sn(a)&&pr(a)!=="body"),o=null;const s=an(e).position==="fixed";let i=s?Pn(e):e;for(;sn(i)&&!hr(i);){const a=an(i),l=ki(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&ly.has(o.position)||Mr(i)&&!l&&zc(e,i))?r=r.filter(d=>d!==i):o=a,i=Pn(i)}return t.set(e,r),r}function dy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:uy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Fc(t,d,o);return c.top=Wt(f.top,c.top),c.right=Rn(f.right,c.right),c.bottom=Rn(f.bottom,c.bottom),c.left=Wt(f.left,c.left),c},Fc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function fy(e){const{width:t,height:n}=Mc(e);return{width:t,height:n}}function py(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((pr(t)!=="body"||Mr(o))&&(a=Bo(t)),r){const h=qn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Lc(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function Ai(e){return an(e).position==="static"}function Bc(e,t){if(!gn(e)||an(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function Hc(e,t){const n=Vt(e);if(zo(e))return n;if(!gn(e)){let o=Pn(e);for(;o&&!hr(o);){if(sn(o)&&!Ai(o))return o;o=Pn(o)}return n}let r=Bc(e,t);for(;r&&Yx(r)&&Ai(r);)r=Bc(r,t);return r&&hr(r)&&Ai(r)&&!ki(r)?n:r||ey(e)||n}const hy=async function(e){const t=this.getOffsetParent||Hc,n=this.getDimensions,r=await n(e.floating);return{reference:py(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function my(e){return an(e).direction==="rtl"}const gy={convertOffsetParentRelativeRectToViewportRelativeRect:oy,getDocumentElement:mn,getClippingRect:dy,getOffsetParent:Hc,getElementRects:hy,getClientRects:sy,getDimensions:fy,getScale:mr,isElement:sn,isRTL:my};function Uc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function xy(e,t){let n=null,r;const o=mn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const x=Do(f),m=Do(o.clientWidth-(d+p)),v=Do(o.clientHeight-(f+h)),g=Do(d),S={rootMargin:-x+"px "+-m+"px "+-v+"px "+-g+"px",threshold:Wt(0,Rn(1,l))||1};let k=!0;function C(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&&!Uc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function yy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ni(e),d=o||s?[...c?Dr(c):[],...Dr(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?xy(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[b]=g;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let x,m=l?qn(e):null;l&&v();function v(){const g=qn(e);m&&!Uc(m,g)&&n(),m=g,x=requestAnimationFrame(v)}return n(),()=>{var g;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(x)}}const vy=Ux,by=Wx,wy=zx,Sy=Kx,Cy=Bx,Wc=Fx,Ty=Vx,ky=(e,t,n)=>{const r=new Map,o={platform:gy,...n},s={...o.platform,_c:r};return $x(e,t,{...o,platform:s})};var Ey=typeof document<"u",Iy=function(){},Uo=Ey?w.useLayoutEffect:Iy;function Wo(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(!Wo(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)&&!Wo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Vc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Kc(e,t){const n=Vc(e);return Math.round(t*n)/n}function ji(e){const t=y.useRef(e);return Uo(()=>{t.current=e}),t}function Ny(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=y.useState(r);Wo(p,r)||h(r);const[x,m]=y.useState(null),[v,g]=y.useState(null),b=y.useCallback(B=>{B!==T.current&&(T.current=B,m(B))},[]),S=y.useCallback(B=>{B!==E.current&&(E.current=B,g(B))},[]),k=s||x,C=i||v,T=y.useRef(null),E=y.useRef(null),N=y.useRef(d),j=l!=null,$=ji(l),P=ji(o),D=ji(c),F=y.useCallback(()=>{if(!T.current||!E.current)return;const B={placement:t,strategy:n,middleware:p};P.current&&(B.platform=P.current),ky(T.current,E.current,B).then(R=>{const Y={...R,isPositioned:D.current!==!1};A.current&&!Wo(N.current,Y)&&(N.current=Y,po.flushSync(()=>{f(Y)}))})},[p,t,n,P,D]);Uo(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[c]);const A=y.useRef(!1);Uo(()=>(A.current=!0,()=>{A.current=!1}),[]),Uo(()=>{if(k&&(T.current=k),C&&(E.current=C),k&&C){if($.current)return $.current(k,C,F);F()}},[k,C,F,$,j]);const z=y.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),_=y.useMemo(()=>({reference:k,floating:C}),[k,C]),K=y.useMemo(()=>{const B={position:n,left:0,top:0};if(!_.floating)return B;const R=Kc(_.floating,d.x),Y=Kc(_.floating,d.y);return a?{...B,transform:"translate("+R+"px, "+Y+"px)",...Vc(_.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:R,top:Y}},[n,a,_.floating,d.x,d.y]);return y.useMemo(()=>({...d,update:F,refs:z,elements:_,floatingStyles:K}),[d,F,z,_,K])}const Ay=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?Wc({element:r.current,padding:o}).fn(n):{}:r?Wc({element:r,padding:o}).fn(n):{}}}},jy=(e,t)=>({...vy(e),options:[e,t]}),_y=(e,t)=>({...by(e),options:[e,t]}),Ry=(e,t)=>({...Ty(e),options:[e,t]}),Py=(e,t)=>({...wy(e),options:[e,t]}),Oy=(e,t)=>({...Sy(e),options:[e,t]}),My=(e,t)=>({...Cy(e),options:[e,t]}),Dy=(e,t)=>({...Ay(e),options:[e,t]});var Ly="Arrow",qc=y.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});qc.displayName=Ly;var $y=qc;function Gc(e){const[t,n]=y.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,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var _i="Popper",[Yc,Vo]=Tn(_i),[Fy,Xc]=Yc(_i),Jc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=y.useState(null);return u.jsx(Fy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Jc.displayName=_i;var Zc="PopperAnchor",Qc=y.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Xc(Zc,n),i=y.useRef(null),a=Ve(t,i),l=y.useRef(null);return y.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(_e.div,{...o,ref:a})});Qc.displayName=Zc;var Ri="PopperContent",[zy,By]=Yc(Ri),eu=y.forwardRef((e,t)=>{var J,L,G,Z,fe,re;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:x,...m}=e,v=Xc(Ri,n),[g,b]=y.useState(null),S=Ve(t,Ae=>b(Ae)),[k,C]=y.useState(null),T=Gc(k),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,j=r+(s!=="center"?"-"+s:""),$=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],D=P.length>0,F={padding:$,boundary:P.filter(Uy),altBoundary:D},{refs:A,floatingStyles:z,placement:_,isPositioned:K,middlewareData:B}=Ny({strategy:"fixed",placement:j,whileElementsMounted:(...Ae)=>yy(...Ae,{animationFrame:h==="always"}),elements:{reference:v.anchor},middleware:[jy({mainAxis:o+N,alignmentAxis:i}),l&&_y({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Ry():void 0,...F}),l&&Py({...F}),Oy({...F,apply:({elements:Ae,rects:qe,availableWidth:Fe,availableHeight:Je})=>{const{width:ie,height:be}=qe.reference,je=Ae.floating.style;je.setProperty("--radix-popper-available-width",`${Fe}px`),je.setProperty("--radix-popper-available-height",`${Je}px`),je.setProperty("--radix-popper-anchor-width",`${ie}px`),je.setProperty("--radix-popper-anchor-height",`${be}px`)}}),k&&Dy({element:k,padding:a}),Wy({arrowWidth:E,arrowHeight:N}),p&&My({strategy:"referenceHidden",...F})]}),[R,Y]=ru(_),X=jt(x);At(()=>{K&&(X==null||X())},[K,X]);const se=(J=B.arrow)==null?void 0:J.x,ve=(L=B.arrow)==null?void 0:L.y,Oe=((G=B.arrow)==null?void 0:G.centerOffset)!==0,[q,H]=y.useState();return At(()=>{g&&H(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:A.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:K?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:q,"--radix-popper-transform-origin":[(Z=B.transformOrigin)==null?void 0:Z.x,(fe=B.transformOrigin)==null?void 0:fe.y].join(" "),...((re=B.hide)==null?void 0:re.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(zy,{scope:n,placedSide:R,onArrowChange:C,arrowX:se,arrowY:ve,shouldHideArrow:Oe,children:u.jsx(_e.div,{"data-side":R,"data-align":Y,...m,ref:S,style:{...m.style,animation:K?void 0:"none"}})})})});eu.displayName=Ri;var tu="PopperArrow",Hy={top:"bottom",right:"left",bottom:"top",left:"right"},nu=y.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=By(tu,r),i=Hy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx($y,{...o,ref:n,style:{...o.style,display:"block"}})})});nu.displayName=tu;function Uy(e){return e!==null}var Wy=e=>({name:"transformOrigin",options:e,fn(t){var v,g,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,[c,d]=ru(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let x="",m="";return c==="bottom"?(x=i?f:`${p}px`,m=`${-l}px`):c==="top"?(x=i?f:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(x=`${-l}px`,m=i?f:`${h}px`):c==="left"&&(x=`${r.floating.width+l}px`,m=i?f:`${h}px`),{data:{x,y:m}}}});function ru(e){const[t,n="center"]=e.split("-");return[t,n]}var ou=Jc,su=Qc,iu=eu,au=nu,Vy="Portal",Ko=y.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=y.useState(!1);At(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ks.createPortal(u.jsx(_e.div,{...r,ref:t}),i):null});Ko.displayName=Vy;function Ky(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Jt=e=>{const{present:t,children:n}=e,r=qy(t),o=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),s=Ve(r.ref,Gy(o));return typeof n=="function"||r.isPresent?y.cloneElement(o,{ref:s}):null};Jt.displayName="Presence";function qy(e){const[t,n]=y.useState(),r=y.useRef(null),o=y.useRef(e),s=y.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Ky(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{const c=qo(r.current);s.current=a==="mounted"?c:"none"},[a]),At(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=qo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),At(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=qo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},p=h=>{h.target===t&&(s.current=qo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:y.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function qo(e){return(e==null?void 0:e.animationName)||"none"}function Gy(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Pi="rovingFocusGroup.onEntryFocus",Yy={bubbles:!1,cancelable:!0},Lr="RovingFocusGroup",[Oi,lu,Xy]=hi(Lr),[Jy,cu]=Tn(Lr,[Xy]),[Zy,Qy]=Jy(Lr),uu=y.forwardRef((e,t)=>u.jsx(Oi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Oi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ev,{...e,ref:t})})}));uu.displayName=Lr;var ev=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=y.useRef(null),h=Ve(t,p),x=Ro(s),[m,v]=dr({prop:i,defaultProp:a??null,onChange:l,caller:Lr}),[g,b]=y.useState(!1),S=jt(c),k=lu(n),C=y.useRef(!1),[T,E]=y.useState(0);return y.useEffect(()=>{const N=p.current;if(N)return N.addEventListener(Pi,S),()=>N.removeEventListener(Pi,S)},[S]),u.jsx(Zy,{scope:n,orientation:r,dir:x,loop:o,currentTabStopId:m,onItemFocus:y.useCallback(N=>v(N),[v]),onItemShiftTab:y.useCallback(()=>b(!0),[]),onFocusableItemAdd:y.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:y.useCallback(()=>E(N=>N-1),[]),children:u.jsx(_e.div,{tabIndex:g||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:me(e.onMouseDown,()=>{C.current=!0}),onFocus:me(e.onFocus,N=>{const j=!C.current;if(N.target===N.currentTarget&&j&&!g){const $=new CustomEvent(Pi,Yy);if(N.currentTarget.dispatchEvent($),!$.defaultPrevented){const P=k().filter(_=>_.focusable),D=P.find(_=>_.active),F=P.find(_=>_.id===m),z=[D,F,...P].filter(Boolean).map(_=>_.ref.current);pu(z,d)}}C.current=!1}),onBlur:me(e.onBlur,()=>b(!1))})})}),du="RovingFocusGroupItem",fu=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=kn(),c=s||l,d=Qy(du,n),f=d.currentTabStopId===c,p=lu(n),{onFocusableItemAdd:h,onFocusableItemRemove:x,currentTabStopId:m}=d;return y.useEffect(()=>{if(r)return h(),()=>x()},[r,h,x]),u.jsx(Oi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:me(e.onMouseDown,v=>{r?d.onItemFocus(c):v.preventDefault()}),onFocus:me(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:me(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const g=rv(v,d.orientation,d.dir);if(g!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(v.currentTarget);S=d.loop?ov(S,k+1):S.slice(k+1)}setTimeout(()=>pu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});fu.displayName=du;var tv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function nv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function rv(e,t,n){const r=nv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return tv[r]}function pu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function ov(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var sv=uu,iv=fu,av=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},gr=new WeakMap,Go=new WeakMap,Yo={},Mi=0,hu=function(e){return e&&(e.host||hu(e.parentNode))},lv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=hu(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})},cv=function(e,t,n,r){var o=lv(t,Array.isArray(e)?e:[e]);Yo[n]||(Yo[n]=new WeakMap);var s=Yo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),x=h!==null&&h!=="false",m=(gr.get(p)||0)+1,v=(s.get(p)||0)+1;gr.set(p,m),s.set(p,v),i.push(p),m===1&&x&&Go.set(p,!0),v===1&&p.setAttribute(n,"true"),x||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),Mi++,function(){i.forEach(function(f){var p=gr.get(f)-1,h=s.get(f)-1;gr.set(f,p),s.set(f,h),p||(Go.has(f)||f.removeAttribute(r),Go.delete(f)),h||f.removeAttribute(n)}),Mi--,Mi||(gr=new WeakMap,gr=new WeakMap,Go=new WeakMap,Yo={})}},Di=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=av(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),cv(r,o,n,"aria-hidden")):function(){return null}},xn=function(){return xn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},xn.apply(this,arguments)};function mu(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 uv(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 Xo="right-scroll-bar-position",Jo="width-before-scroll-bar",dv="with-scroll-bars-hidden",fv="--removed-body-scroll-bar-size";function Li(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function pv(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 hv=typeof window<"u"?y.useLayoutEffect:y.useEffect,gu=new WeakMap;function mv(e,t){var n=pv(null,function(r){return e.forEach(function(o){return Li(o,r)})});return hv(function(){var r=gu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Li(a,null)}),s.forEach(function(a){o.has(a)||Li(a,i)})}gu.set(n,e)},[e]),n}function gv(e){return e}function xv(e,t){t===void 0&&(t=gv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function yv(e){e===void 0&&(e={});var t=xv(null);return t.options=xn({async:!0,ssr:!1},e),t}var xu=function(e){var t=e.sideCar,n=mu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return y.createElement(r,xn({},n))};xu.isSideCarExport=!0;function vv(e,t){return e.useMedium(t),xu}var yu=yv(),$i=function(){},Zo=y.forwardRef(function(e,t){var n=y.useRef(null),r=y.useState({onScrollCapture:$i,onWheelCapture:$i,onTouchMoveCapture:$i}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,x=e.noIsolation,m=e.inert,v=e.allowPinchZoom,g=e.as,b=g===void 0?"div":g,S=e.gapMode,k=mu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=mv([n,t]),E=xn(xn({},k),o);return y.createElement(y.Fragment,null,d&&y.createElement(C,{sideCar:yu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:x,inert:m,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:S}),i?y.cloneElement(y.Children.only(a),xn(xn({},E),{ref:T})):y.createElement(b,xn({},E,{className:l,ref:T}),a))});Zo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Zo.classNames={fullWidth:Jo,zeroRight:Xo};var bv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function wv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=bv();return t&&e.setAttribute("nonce",t),e}function Sv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Cv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Tv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=wv())&&(Sv(t,n),Cv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},kv=function(){var e=Tv();return function(t,n){y.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},vu=function(){var e=kv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Ev={left:0,top:0,right:0,gap:0},Fi=function(e){return parseInt(e||"",10)||0},Iv=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[Fi(n),Fi(r),Fi(o)]},Nv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Ev;var t=Iv(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])}},Av=vu(),xr="data-scroll-locked",jv=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(dv,` {
37
+ `))>=0;){const Q=xt.slice(0,O);xt=xt.slice(O+2);const re=Xg(Q);if(!re)continue;let Me;try{Me=JSON.parse(re)}catch{console.debug("[use-chat] malformed SSE:",re.slice(0,200));continue}const ge=Yg(Me)?Me.data:Me;Ye=Date.now();const Xe=ge.seq;if(Xe!==void 0){if(Xe<=ft){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Xe,lastProcessedSeq:ft,type:ge.type});continue}ft>0&&Xe>ft+1&&((L=j==null?void 0:j.onGap)==null||L.call(j,{from:ft,to:Xe})),ft=Xe,C.current=Xe,v(Xe)}if(console.debug("[use-chat] received event",{seq:ge.seq,type:ge.type,preview:(()=>{var xe;try{return ge.type==="message_delta"?{deltaTypes:(xe=ge.delta)==null?void 0:xe.map(st=>st.type),textLen:(ge.delta||[]).filter(st=>st.type==="text").map(st=>String(st.text||"").length)}:ge.content||ge.delta?{hasContent:!0}:{}}catch(st){return{err:String(st)}}})()}),ge.type==="checkpoint")E.current=ge.checkpointId??null,N.current=ge.checkpointNs??null,x(ge.checkpointId??null);else if(ge.type==="state_history"){_.current=ge;try{const st=ur(ge).latest;st&&(E.current=st.checkpointId??null,N.current=st.checkpointNs??null,x(st.checkpointId??null))}catch(xe){console.warn("[use-chat] Failed to hydrate state_history payload",xe)}}try{z==null||z(ge)}catch(xe){console.error("[use-chat] Error in onEvent callback:",xe,"for event:",ge.type)}if(ge.type==="token"&&e.autoAppendAssistant!==!1)ct.push(ge.content),Nt();else if(ge.type==="message_delta"){const xe=ge.delta.filter(st=>st.type==="text").map(st=>st.text).join("");xe&&e.autoAppendAssistant!==!1&&(ct.push(xe),Nt())}else if(ge.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(G=j==null?void 0:j.onHeartbeat)==null||G.call(j,ge)}catch(xe){console.warn("[use-chat] heartbeat callback failed",xe)}}else if(pt!==null&&cancelAnimationFrame(pt),yt(),ge.type==="checkpoint")x(ge.checkpointId);else if(ge.type==="error"){const xe=ge;if(d(xe.message),B="error",R=xe.message,xe.error_type==="auth_error"||xe.code==="TOKEN_EXPIRED"||((Z=xe.message)==null?void 0:Z.includes("token"))||((fe=xe.message)==null?void 0:fe.includes("401"))||((oe=xe.message)==null?void 0:oe.includes("unauthorized"))||((Ae=xe.message)==null?void 0:Ae.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",xe.message);try{(qe=j==null?void 0:j.onAuthError)==null||qe.call(j,xe.message)}catch(An){console.warn("[use-chat] onAuthError handler failed",An)}K.abort()}}}}yt(),B===null&&!K.signal.aborted&&(B="complete")}catch(tt){if(tt.name==="AbortError")B=B??"aborted";else{const ot=tt.message||String(tt);B="error",R=ot,d(ot),(Fe=j==null?void 0:j.onError)==null||Fe.call(j,ot)}}finally{try{await et.cancel()}catch{}finally{(Ze=et.releaseLock)==null||Ze.call(et)}pt!==null&&typeof window<"u"&&window.cancelAnimationFrame(pt),clearInterval(jt)}}catch(Le){if(Le.name==="AbortError")B=B??"aborted";else{const Ue=Le.message||String(Le);B="error",R=Ue,d(Ue),(ie=j==null?void 0:j.onError)==null||ie.call(j,Ue),Y||((we=j==null?void 0:j.onConnectionError)==null||we.call(j,Ue),Y=!0)}}finally{const Le=C.current,Ue=E.current,Ge=N.current,ze=_.current,He=B??(K.signal.aborted?"aborted":R?"error":"complete");try{(_e=j==null?void 0:j.onClosed)==null||_e.call(j,{reason:He,lastSeq:Le,lastCheckpointId:Ue,lastCheckpointNs:Ge,lastStateHistory:ze,error:R})}catch(et){console.warn("[use-chat] onClosed callback failed",et)}l(!1),b(!1),S.current=null,C.current=0,v(0),T.current=null}})(),{close:()=>K.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var A;k.current=!1,(A=S.current)==null||A.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:m,connected:g,stream:F,stop:D,clear:P,setToken:$}}function Yg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Xg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
38
+ `)}function Jg(e){return e.type!=="token"}const Zg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Qg(e,t){var n;switch(t.type){case"reset":return{messages:di(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=di(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=di(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return ec(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>ec(o,s),e):e}case"interrupt_response":return{...e,messages:tc(e.messages),pendingInterrupt:null};default:return e}}function Ql(e=[]){const[t,n]=w.useReducer(Qg,{...Zg,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function ec(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=rx(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},p={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:p}}const d={id:a,role:"assistant",name:l||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:a,messages:[...e.messages,d]}}if(t.type==="message_delta"){const a=e.assemblingId??nc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(k=>k.id===a&&k.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},p=f[a]??{lastSeq:null,lastText:sc(d.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof p.lastSeq=="number"&&h<=p.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:p.lastSeq}),e;const{newParts:x,newMeta:m,changed:v}=ex(d.content,t.delta,p,h);if(!v)return e;const g={...d,content:x},b=No(l,c,g),S={...f,[a]:m};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??nc(e.messages);if(!a)return{...e,assemblingId:null};const l=e.messages,c=l.findIndex(d=>d.id===a&&d.role==="assistant");if(c>=0){const d=l[c];if(!((n=d.content)==null?void 0:n.some(p=>{var h;return(p==null?void 0:p.type)==="text"&&((h=p.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=d.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 p=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:p}}}return e}if(t.type==="tool_start"){const a=rc(t),l=a[0]??(typeof t.id=="string"?t.id:null)??(typeof t.call_id=="string"?t.call_id:null),c=t.name??t.tool??"tool";!l&&a.length===0&&a.push(`${c}-${Date.now()}`);const d=a.length?a:l?[l]:[],f=oc(e,d,c),p=f>=0?e.messages[f]:null,h=l??d[0]??`${c}-${Date.now()}`,x=(p==null?void 0:p.id)??`tool-${h}`,m=d[0]??h,v={type:"tool_call",id:m,name:c,args:t.args};if(p){const S=pi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?No(e.messages,C,k):e.messages,E=Ao(k,d),N=hi(e.toolIndex,x,E);return{...e,messages:T,toolIndex:N}}const g={id:x,role:"tool",name:c,createdAt:new Date().toISOString(),content:[v],additionalKwargs:pi(void 0,d.length?d:[m],c,t.args)},b=Ao(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:hi(e.toolIndex,x,b)}}if(t.type==="tool_end"){const a=rc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=oc(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,x=Ao(d,a);let m=t.output;if(typeof t.output=="string")try{const E=t.output.trim();(E.startsWith("{")||E.startsWith("["))&&(m=JSON.parse(E))}catch{m=t.output}const v=t.artifact??(d==null?void 0:d.artifact),g={type:"text",text:typeof m=="string"?m:JSON.stringify(m)},b=(d==null?void 0:d.createdAt)??new Date().toISOString(),S=pi(d??void 0,x.length?x:a,f),k={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[g],createdAt:b,artifact:v??void 0,additionalKwargs:S},C=c>=0?No(e.messages,c,k):[...e.messages,k],T=Ao(k,a.length?a:x);return{...e,messages:C,toolIndex:hi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=nx(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=ur(t),l=a.interrupt,c=a.latest,d=l===null?tc(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function di(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function No(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function tc(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 nc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function rc(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 fi(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 pi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=fi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Ao(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=fi(e);for(const o of r)n.add(o);return Array.from(n)}function hi(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 oc(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(fi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function sc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function ex(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??sc(e);let l="",c=e.slice();if(s){const f=tx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const p=c[c.length-1];if((p==null?void 0:p.type)==="text"){const h=p.text??"",x={...p,text:h+l};c=[...c.slice(0,c.length-1),x]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const d=!!(l||i.length);return{newParts:c,newMeta:o,changed:d}}function ic(e){return e.replace(/\s+/g," ").trim()}function tx(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=ic(e),o=ic(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 nx(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return No(e,r,s)}return e}function rx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const ac=200;function ox({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),x=w.useRef(null),m=w.useCallback(P=>{try{const D=globalThis.structuredClone;if(typeof D=="function")return D(P)}catch{}try{return JSON.parse(JSON.stringify(P))}catch{return P}},[]),v=w.useCallback((P,D)=>{if(!P)return;const F=p.current.get(P)??[],A=m(D),z=F.length>=ac?[...F.slice(F.length-ac+1),A]:[...F,A];p.current.set(P,z)},[m]),g=w.useCallback(P=>{P&&p.current.set(P,[])},[]),b=w.useCallback(P=>{const D=P??f.current;if(!D)return;const F=p.current.get(D);F!=null&&F.length&&F.forEach(A=>{try{n(A)}catch(z){console.error("[useChatStreamingService] Failed to replay buffered event",z)}})},[n]),S=w.useCallback(P=>{var A,z,j,K,B;const D=P.seq??null;if(D!==null){const R=d.current;if(R!==null){if(D<=R)return;D>R+1&&(s==null||s({from:R,to:D}))}d.current=D}if(P.type==="thread_info"){f.current=P.threadId,h.current&&(h.current.threadIdGuess=P.threadId),x.current=P,g(P.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",P);try{t(P)}catch(R){console.error("[useChatStreamingService] Error in onThreadInfo handler:",R)}return}if(P.type==="heartbeat"){try{c==null||c(P)}catch(R){console.error("[useChatStreamingService] Error in onHeartbeat handler:",R)}return}if(P.type==="error"){const R=P;if(R.error_type==="auth_error"||R.code==="TOKEN_EXPIRED"||((A=R.message)==null?void 0:A.includes("token"))||((z=R.message)==null?void 0:z.includes("401"))||((j=R.message)==null?void 0:j.includes("unauthorized"))||((K=R.message)==null?void 0:K.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",R.message);try{l==null||l(R.message)}catch(X){console.warn("[useChatStreamingService] onAuthError handler failed",X)}}}const F=P.threadId??(P.type==="state_history"?P.threadId:void 0)??f.current??((B=h.current)==null?void 0:B.threadIdGuess)??null;if(P.type==="state_history"){f.current=F??f.current;try{r==null||r(P)}catch(R){console.error("[useChatStreamingService] onStateHistory handler failed",R)}}if(Jg(P)){P.type==="checkpoint"||P.type==="state_history"?g(F??null):v(F??null,P);try{n(P)}catch(R){console.error("[useChatStreamingService] Error in onMessageEvent handler:",R)}return}try{o==null||o(P)}catch(R){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",R)}},[v,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:E,setToken:N}=Zl({baseUrl:e,token:void 0}),_=w.useCallback((P,D)=>{d.current=null,x.current=null,f.current=P.threadId??null,h.current={request:P,callbacks:D,manualStop:!1,threadIdGuess:P.threadId??null},k(P,S,{onOpen:D==null?void 0:D.onOpen,onError:F=>{var A;(A=D==null?void 0:D.onError)==null||A.call(D,F)},onGap:(D==null?void 0:D.onGap)??s,onConnectionError:F=>{var A;a==null||a(F),(A=D==null?void 0:D.onConnectionError)==null||A.call(D,F)},onAuthError:F=>{var A;l==null||l(F),(A=D==null?void 0:D.onAuthError)==null||A.call(D,F)},onHeartbeat:F=>{var A;try{c==null||c(F)}catch(z){console.warn("[useChatStreamingService] onHeartbeat handler failed",z)}try{(A=D==null?void 0:D.onHeartbeat)==null||A.call(D,F)}catch(z){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",z)}},onClosed:F=>{var K,B,R,Y;const A=((K=h.current)==null?void 0:K.manualStop)??!1,z=f.current??((B=h.current)==null?void 0:B.threadIdGuess)??((R=F.lastStateHistory)==null?void 0:R.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&A)&&g(z);const j={...F,threadId:z,threadInfo:x.current,manualStop:A};try{i==null||i(j)}catch(X){console.warn("[useChatStreamingService] onStreamClosed handler failed",X)}try{(Y=D==null?void 0:D.onClosed)==null||Y.call(D,j)}catch(X){console.warn("[useChatStreamingService] downstream onClosed handler failed",X)}h.current&&(h.current=null)}})},[g,S,l,a,c,s,i,k]),$=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:_,stop:$,isStreaming:T,error:E,setAuthToken:N,replayBufferedEvents:b}),[_,$,T,E,N,b])}const lc=w.createContext(null),cc=w.createContext(null),uc=w.createContext(null);w.createContext(!1);function sx({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a}){const{api:l,baseUrl:c}=ci(),d=w.useMemo(()=>Cn(c),[c]),[f,p]=w.useState([]),[h,x]=w.useState(t),[m,v]=w.useState(!1),[g,b]=w.useState(null),[S,k]=w.useState(!1),[C,T]=w.useState(null),{state:E,seed:N,prepend:_,pushUser:$,onEvent:P}=Ql(),[D,F]=w.useState(!1),[A,z]=w.useState(!1),[j,K]=w.useState(null),[B,R]=w.useState([]),[Y,X]=w.useState([]),[se,be]=w.useState(!1),Oe=w.useMemo(()=>B.flatMap(V=>V.messages??[]),[B]),q=w.useMemo(()=>Jl(Oe),[Oe]),H=w.useRef(h),J=w.useRef(null),L=w.useRef(null),G=w.useRef(null),Z=w.useRef(null),fe=w.useRef(!1),oe=w.useRef(null),Ae=w.useRef(new Map),qe=w.useRef(new Map);w.useEffect(()=>{H.current=h},[h]);const Fe=w.useCallback(async()=>{v(!0),b(null);try{const V=await l.listThreads();p(V??[])}catch(V){const ce=String(V);b(ce),s==null||s(ce)}finally{v(!1)}},[l,s]),Ze=w.useCallback(V=>{if(!(V!=null&&V.threadId))return;const ce={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};p(Ce=>Ce.some(Q=>Q.threadId===ce.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",ce.threadId),Ce):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",ce.threadId),[ce,...Ce]))},[]),ie=w.useCallback(V=>{const ce=V.threadId??H.current;if(!ce||H.current&&H.current!==ce)return;const{checkpoints:Ce,timeline:O}=ur(V);if(!Ce.length)return;const Q=Ce.find(re=>re.messages&&re.messages.length>0)??Ce.find(re=>!!re.checkpointId)??Ce[0];N((Q==null?void 0:Q.messages)??[],{checkpointId:(Q==null?void 0:Q.checkpointId)??null,checkpointNs:(Q==null?void 0:Q.checkpointNs)??null}),X(O),R(Ce),F(!!(Q!=null&&Q.nextCursor)),K((Q==null?void 0:Q.nextCursor)??null),oe.current=`${ce}:latest`,L.current=null,G.current=null},[N]),we=w.useCallback(V=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",V.threadId),Ze(V),H.current!==V.threadId&&((V.created??!H.current)&&(L.current=V.threadId),G.current=V.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(V.threadId))},[Ze]),{startStream:_e,stop:Le,isStreaming:Ue,error:Ge,setAuthToken:ze}=ox({baseUrl:d,onThreadInfo:we,onMessageEvent:P,onStateHistory:ie,onUnhandledEvent:V=>{console.warn("[ChatSessionProvider] Unhandled event:",V.type)},onAuthError:i}),He=w.useCallback(async V=>{try{const ce=await l.createThread(V);return x(ce.threadId),await Fe(),ce.threadId}catch(ce){return s==null||s(String(ce)),null}},[l,Fe,s]),et=w.useCallback(async V=>{const ce=f;p(O=>O.filter(Q=>Q.threadId!==V));const Ce=new AbortController;qe.current.set(V,Ce);try{await l.deleteThread(V),H.current===V&&(x(null),N([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",V)}catch(O){console.error("[ChatSessionProvider] Delete failed, restoring thread:",V,O),p(ce),s==null||s(`Failed to delete thread: ${String(O)}`)}finally{qe.current.delete(V)}},[f,l,N,s]),Et=w.useCallback(async(V,ce)=>{try{await l.updateThread(V,ce),await Fe()}catch(Ce){s==null||s(String(Ce))}},[l,Fe,s]),xt=w.useCallback(async(V,ce)=>{if(!V)return;const Ce=`${V}:${ce??"latest"}`,O=Ae.current.get(Ce);if(O)return O;const Q=(async()=>{const re=V;k(!0),T(null);try{const Me=await l.getStateHistory({threadId:re,checkpointId:ce||void 0});if(H.current!==re){console.log(`[ChatSessionProvider] Thread changed during load (was ${re}, now ${H.current}), discarding stale data`);return}const{checkpoints:ge,timeline:Xe}=ur(Me),xe=ge.find(st=>st.messages&&st.messages.length>0)??(ce?ge.find(st=>st.checkpointId===ce):null)??ge[0];N((xe==null?void 0:xe.messages)??[],{checkpointId:(xe==null?void 0:xe.checkpointId)??null,checkpointNs:(xe==null?void 0:xe.checkpointNs)??null}),X(Xe),R(ge),F(!!(xe!=null&&xe.nextCursor)),K((xe==null?void 0:xe.nextCursor)??null)}catch(Me){if(H.current===re){const ge=String(Me);T(ge),s==null||s(ge)}}finally{k(!1)}})();Ae.current.set(Ce,Q);try{await Q}finally{Ae.current.delete(Ce)}return H.current===V&&(oe.current=Ce),Q},[l,N,s]),ct=w.useCallback(async(V,ce)=>{Z.current=V;try{await xt(V,ce)}finally{Z.current===V&&(Z.current=null)}},[xt]);w.useEffect(()=>{if(!o||!h||S||Ue)return;if(L.current===h){L.current=null,J.current=h;return}if(G.current===h){J.current=h;return}if(Z.current===h){Z.current=null,J.current=h;return}if(J.current===h)return;J.current=h;const V=!fe.current&&!!n&&h===t;let ce;V&&n?(ce=n,fe.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",ce,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const Ce=`${h}:${ce??"latest"}`;oe.current!==Ce&&ct(h,ce)},[o,h,n,r,t,S,Ue,ct]);const ft=w.useCallback(async(V,ce)=>{const Ce=H.current;if(!Ce)return;const O=Ce;be(!0);try{const Q=await l.getStateHistory({threadId:O,checkpointId:V,checkpointNs:ce??void 0});if(H.current!==O){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${O}, now ${H.current}), discarding stale data`);return}const{checkpoints:re,timeline:Me}=ur(Q),ge=re.find(Xe=>Xe.checkpointId===V&&(ce?Xe.checkpointNs===ce:!0));if(!ge){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:V,checkpointNs:ce});return}X(Me),R(re),N(ge.messages??[],{checkpointId:ge.checkpointId??null,checkpointNs:ge.checkpointNs??null})}catch(Q){H.current===O&&(s==null||s(String(Q)))}finally{be(!1)}},[l,N,s]),pt=w.useCallback((V,ce)=>{N(E.messages,{checkpointId:V??null,checkpointNs:ce??null})},[N,E.messages]),yt=w.useCallback(async()=>{H.current&&await ct(H.current)},[ct]),Nt=w.useCallback(async()=>{if(!H.current||!j)return;const V=H.current;z(!0);try{const ce=await l.getStateHistory({threadId:V,checkpointId:j});if(H.current!==V){console.log(`[ChatSessionProvider] Thread changed during history load (was ${V}, now ${H.current}), discarding stale data`);return}const{checkpoints:Ce}=ur(ce);if(Ce.length>0){const O=Ce[Ce.length-1];_((O==null?void 0:O.messages)??[]),F(!!(O!=null&&O.nextCursor)),K((O==null?void 0:O.nextCursor)??null)}}catch(ce){H.current===V&&(s==null||s(String(ce)))}finally{z(!1)}},[l,j,_,s]),Ye=w.useCallback(async()=>{N([],{}),x(null),Le(),R([]),X([]),F(!1),K(null),k(!1),be(!1),z(!1),T(null);try{await l.getAgent("default")}catch(V){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",V)}},[N,Le,l]),jt=w.useCallback(async(V,ce,Ce)=>{const O=H.current;if(!O)throw new Error("No active thread to handle interrupt");const Q=ce?Ce??!0:!1;try{const re={threadId:O,checkpointId:E.lastCheckpointId??void 0,checkpointNs:E.lastCheckpointNs??void 0,command:{kind:"resume",value:Q}};_e(re)}catch(re){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${V}:`,re),re}},[E.lastCheckpointId,E.lastCheckpointNs,_e]);w.useEffect(()=>{Fe()},[Fe]),w.useEffect(()=>{a==null||a(h)},[h,a]);const Sn=w.useCallback(async(V,ce)=>{let Ce=H.current;const O=(V==null?void 0:V.text)??"";if(!Ce&&!O)return;if(!Ce&&O){const Xe=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),xe=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);Ce=`${Xe}${xe}`,L.current=Ce,x(Ce)}const{contentParts:Q}=await Sg(l,(V==null?void 0:V.attachments)??[]),re=[...Q];O!=null&&O.trim()&&re.push({type:"text",text:O});const Me={id:`msg-${Date.now()}`,role:"user",content:re,createdAt:new Date().toISOString()};$(Me);const ge={threadId:Ce,payload:{messages:[Me]},checkpointId:(ce==null?void 0:ce.checkpointId)??E.lastCheckpointId??void 0,checkpointNs:(ce==null?void 0:ce.checkpointNs)??E.lastCheckpointNs??void 0};_e(ge)},[l,He,$,E,_e]),tt=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:He,deleteThread:et,renameThread:Et,refreshThreads:Fe}}),[f,h,m,g,He,et,Et,Fe]),ot=w.useMemo(()=>({threadId:h,messages:E.messages,interrupt:null,checkpoint:{id:E.lastCheckpointId??null,namespace:E.lastCheckpointNs??null},checkpoints:B,timelineCheckpoints:Y,metadata:null,isLoading:S,isHistoryLoading:A,isLoadingCheckpoint:se,error:C,hasMore:D,loadOlder:Nt,clearState:Ye,navigateToCheckpoint:ft,setCurrentCheckpointId:pt,returnToLatest:yt,loadThread:ct,clearThread:Ye,respondToInterrupt:jt,messagePreviews:q}),[h,E,B,Y,S,A,se,C,D,Nt,Ye,ft,pt,yt,ct,jt,q]),bt=w.useMemo(()=>({isStreaming:Ue,error:Ge,connectionState:Ue?"connected":"idle",submit:Sn,send:Sn,stop:Le,setAuthToken:ze}),[Ue,Ge,Sn,Le,ze]);return u.jsx(lc.Provider,{value:tt,children:u.jsx(cc.Provider,{value:ot,children:u.jsx(uc.Provider,{value:bt,children:e})})})}function _o(){const e=w.useContext(lc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(cc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function dc(){const e=w.useContext(uc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ro({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onAuthError:a,onThreadChange:l}){return u.jsx(bg,{apiConfig:t,children:u.jsx(sx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function te(...e){return qh.twMerge(Kh.clsx(e))}const ix=po.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),nt=y.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return u.jsx(i,{className:te(ix({variant:t,size:n,className:e})),ref:s,...o})});nt.displayName="Button";const fc=y.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:te("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));fc.displayName="Textarea";function pc({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:d,className:f="",textareaClassName:p="",allowEmptySend:h=!1}){const x=i!==void 0,[m,v]=w.useState(e),g=(x?i:m)??"",[b,S]=w.useTransition(),k=w.useRef(null),C=w.useRef(0),T=w.useRef(null);w.useEffect(()=>{x||(v(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,x]);const E=w.useCallback(()=>{const z=k.current;z&&(z.style.height="auto",z.style.height=`${z.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,g]);const N=w.useCallback((z,{fromUser:j})=>{x||v(z),j&&(a==null||a(z))},[x,a]),_=w.useCallback(async z=>{z&&z.preventDefault();const j=(g??"").trim();if(!j&&!h)return;const K=++C.current;T.current={id:K,shouldClear:!0},S(()=>{var B,R,Y;try{const X=l(j);X&&typeof X.then=="function"?X.then(()=>{var se,be;((se=T.current)==null?void 0:se.id)===K&&T.current.shouldClear&&(x||(v(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((be=T.current)==null?void 0:be.id)===K&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===K&&(T.current=null)}):(((B=T.current)==null?void 0:B.id)===K&&T.current.shouldClear&&(x||(v(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((R=T.current)==null?void 0:R.id)===K&&(T.current=null))}catch{((Y=T.current)==null?void 0:Y.id)===K&&(T.current=null)}})},[g,l,h,x,a]),$=w.useCallback(z=>{const j=z.target.value;N(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[N]),P=w.useCallback(z=>{z.key==="Enter"&&!z.shiftKey?(z.preventDefault(),_()):z.key==="Escape"&&t&&(z.preventDefault(),c==null||c())},[_,t,c]),A=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:z=>void _(z),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(fc,{ref:k,value:g,onChange:$,onKeyDown:P,placeholder:t?"Edit your message...":n,className:A,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(nt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(le.Square,{size:16})}):u.jsx(nt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||b,children:u.jsx(le.Send,{size:16})})})]})})}const ax=w.memo(pc);function me(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 hc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function mi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=hc(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():hc(e[o],null)}}}}function Ve(...e){return y.useCallback(mi(...e),e)}function lx(e,t){const n=y.createContext(t),r=s=>{const{children:i,...a}=s,l=y.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=y.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Tn(e,t=[]){let n=[];function r(s,i){const a=y.createContext(i),l=n.length;n=[...n,i];const c=f=>{var g;const{scope:p,children:h,...x}=f,m=((g=p==null?void 0:p[e])==null?void 0:g[l])||a,v=y.useMemo(()=>x,Object.values(x));return u.jsx(m.Provider,{value:v,children:h})};c.displayName=s+"Provider";function d(f,p){var m;const h=((m=p==null?void 0:p[e])==null?void 0:m[l])||a,x=y.useContext(h);if(x)return x;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=n.map(i=>y.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return y.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,cx(o,...t)]}function cx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var At=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},ux=y[" useInsertionEffect ".trim().toString()]||At;function fr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=dx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=y.useRef(e!==void 0);y.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=y.useCallback(d=>{var f;if(a){const p=fx(d)?d(e):d;p!==e&&((f=i.current)==null||f.call(i,p))}else s(d)},[a,e,s,i]);return[l,c]}function dx({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),o=y.useRef(n),s=y.useRef(t);return ux(()=>{s.current=t},[t]),y.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function fx(e){return typeof e=="function"}var px=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],je=px.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=y.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function mc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function gi(e){const t=e+"CollectionProvider",[n,r]=Tn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:v,children:g}=m,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:v,itemMap:S,collectionRef:b,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Wn.createSlot(a),c=w.forwardRef((m,v)=>{const{scope:g,children:b}=m,S=s(a,g),k=Ve(v,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Wn.createSlot(d),h=w.forwardRef((m,v)=>{const{scope:g,children:b,...S}=m,k=w.useRef(null),C=Ve(v,k),T=s(d,g);return w.useEffect(()=>(T.itemMap.set(k,{ref:k,...S}),()=>void T.itemMap.delete(k))),u.jsx(p,{[f]:"",ref:C,children:b})});h.displayName=d;function x(m){const v=s(e+"CollectionConsumer",m);return w.useCallback(()=>{const b=v.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(v.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[v.collectionRef,v.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},x,r]}var hx=y.createContext(void 0);function Po(e){const t=y.useContext(hx);return e||t||"ltr"}function _t(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function mx(e,t=globalThis==null?void 0:globalThis.document){const n=_t(e);y.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var gx="DismissableLayer",xi="dismissableLayer.update",xx="dismissableLayer.pointerDownOutside",yx="dismissableLayer.focusOutside",gc,xc=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Oo=y.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=y.useContext(xc),[d,f]=y.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=y.useState({}),x=Ve(t,E=>f(E)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=m.indexOf(v),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=g,C=wx(E=>{const N=E.target,_=[...c.branches].some($=>$.contains(N));!k||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),T=Sx(E=>{const N=E.target;[...c.branches].some($=>$.contains(N))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return mx(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),y.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(gc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),yc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=gc)}},[d,p,n,c]),y.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),yc())},[d,c]),y.useEffect(()=>{const E=()=>h({});return document.addEventListener(xi,E),()=>document.removeEventListener(xi,E)},[]),u.jsx(je.div,{...l,ref:x,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:me(e.onFocusCapture,T.onFocusCapture),onBlurCapture:me(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:me(e.onPointerDownCapture,C.onPointerDownCapture)})});Oo.displayName=gx;var vx="DismissableLayerBranch",bx=y.forwardRef((e,t)=>{const n=y.useContext(xc),r=y.useRef(null),o=Ve(t,r);return y.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(je.div,{...e,ref:o})});bx.displayName=vx;function wx(e,t=globalThis==null?void 0:globalThis.document){const n=_t(e),r=y.useRef(!1),o=y.useRef(()=>{});return y.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){vc(xx,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Sx(e,t=globalThis==null?void 0:globalThis.document){const n=_t(e),r=y.useRef(!1);return y.useEffect(()=>{const o=s=>{s.target&&!r.current&&vc(yx,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 yc(){const e=new CustomEvent(xi);document.dispatchEvent(e)}function vc(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?mc(o,s):o.dispatchEvent(s)}var yi=0;function vi(){y.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??bc()),document.body.insertAdjacentElement("beforeend",e[1]??bc()),yi++,()=>{yi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),yi--}},[])}function bc(){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 bi="focusScope.autoFocusOnMount",wi="focusScope.autoFocusOnUnmount",wc={bubbles:!1,cancelable:!0},Cx="FocusScope",Mo=y.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=y.useState(null),c=_t(o),d=_t(s),f=y.useRef(null),p=Ve(t,m=>l(m)),h=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(r){let m=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:Rn(f.current,{select:!0})},v=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||Rn(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Rn(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const b=new MutationObserver(g);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),b.disconnect()}}},[r,a,h.paused]),y.useEffect(()=>{if(a){Tc.add(h);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(bi,wc);a.addEventListener(bi,c),a.dispatchEvent(g),g.defaultPrevented||(Tx(Ax(Sc(a)),{select:!0}),document.activeElement===m&&Rn(a))}return()=>{a.removeEventListener(bi,c),setTimeout(()=>{const g=new CustomEvent(wi,wc);a.addEventListener(wi,d),a.dispatchEvent(g),g.defaultPrevented||Rn(m??document.body,{select:!0}),a.removeEventListener(wi,d),Tc.remove(h)},0)}}},[a,c,d,h]);const x=y.useCallback(m=>{if(!n&&!r||h.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,g=document.activeElement;if(v&&g){const b=m.currentTarget,[S,k]=kx(b);S&&k?!m.shiftKey&&g===k?(m.preventDefault(),n&&Rn(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&Rn(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(je.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Mo.displayName=Cx;function Tx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Rn(r,{select:t}),document.activeElement!==n)return}function kx(e){const t=Sc(e),n=Cc(t,e),r=Cc(t.reverse(),e);return[n,r]}function Sc(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 Cc(e,t){for(const n of e)if(!Ex(n,{upTo:t}))return n}function Ex(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 Ix(e){return e instanceof HTMLInputElement&&"select"in e}function Rn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ix(e)&&t&&e.select()}}var Tc=Nx();function Nx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=kc(e,t),e.unshift(t)},remove(t){var n;e=kc(e,t),(n=e[0])==null||n.resume()}}}function kc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Ax(e){return e.filter(t=>t.tagName!=="A")}var _x=y[" useId ".trim().toString()]||(()=>{}),jx=0;function kn(e){const[t,n]=y.useState(_x());return At(()=>{n(r=>r??String(jx++))},[e]),t?`radix-${t}`:""}const Rx=["top","right","bottom","left"],Pn=Math.min,Wt=Math.max,Do=Math.round,Lo=Math.floor,pn=e=>({x:e,y:e}),Px={left:"right",right:"left",bottom:"top",top:"bottom"},Ox={start:"end",end:"start"};function Si(e,t,n){return Wt(e,Pn(t,n))}function En(e,t){return typeof e=="function"?e(t):e}function In(e){return e.split("-")[0]}function pr(e){return e.split("-")[1]}function Ci(e){return e==="x"?"y":"x"}function Ti(e){return e==="y"?"height":"width"}const Mx=new Set(["top","bottom"]);function hn(e){return Mx.has(In(e))?"y":"x"}function ki(e){return Ci(hn(e))}function Dx(e,t,n){n===void 0&&(n=!1);const r=pr(e),o=ki(e),s=Ti(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=$o(i)),[i,$o(i)]}function Lx(e){const t=$o(e);return[Ei(e),t,Ei(t)]}function Ei(e){return e.replace(/start|end/g,t=>Ox[t])}const Ec=["left","right"],Ic=["right","left"],$x=["top","bottom"],Fx=["bottom","top"];function zx(e,t,n){switch(e){case"top":case"bottom":return n?t?Ic:Ec:t?Ec:Ic;case"left":case"right":return t?$x:Fx;default:return[]}}function Bx(e,t,n,r){const o=pr(e);let s=zx(In(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ei)))),s}function $o(e){return e.replace(/left|right|bottom|top/g,t=>Px[t])}function Hx(e){return{top:0,right:0,bottom:0,left:0,...e}}function Nc(e){return typeof e!="number"?Hx(e):{top:e,right:e,bottom:e,left:e}}function Fo(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Ac(e,t,n){let{reference:r,floating:o}=e;const s=hn(t),i=ki(t),a=Ti(i),l=In(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(pr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Ux=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=Ac(c,r,l),p=r,h={},x=0;for(let m=0;m<a.length;m++){const{name:v,fn:g}=a[m],{x:b,y:S,data:k,reset:C}=await g({x:d,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:h,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,h={...h,[v]:{...h[v],...k}},C&&x<=50&&(x++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=Ac(c,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Mr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=En(t,e),x=Nc(h),v=a[p?f==="floating"?"reference":"floating":f],g=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(g.top-C.top+x.top)/k.y,bottom:(C.bottom-g.bottom+x.bottom)/k.y,left:(g.left-C.left+x.left)/k.x,right:(C.right-g.right+x.right)/k.x}}const Wx=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:d=0}=En(e,t)||{};if(c==null)return{};const f=Nc(d),p={x:n,y:r},h=ki(o),x=Ti(h),m=await i.getDimensions(c),v=h==="y",g=v?"top":"left",b=v?"bottom":"right",S=v?"clientHeight":"clientWidth",k=s.reference[x]+s.reference[h]-p[h]-s.floating[x],C=p[h]-s.reference[h],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[x]);const N=k/2-C/2,_=E/2-m[x]/2-1,$=Pn(f[g],_),P=Pn(f[b],_),D=$,F=E-m[x]-P,A=E/2-m[x]/2+N,z=Si(D,A,F),j=!l.arrow&&pr(o)!=null&&A!==z&&s.reference[x]/2-(A<D?$:P)-m[x]/2<0,K=j?A<D?A-D:A-F:0;return{[h]:p[h]+K,data:{[h]:z,centerOffset:A-z-K,...j&&{alignmentOffset:K}},reset:j}}}),Vx=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:m=!0,...v}=En(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=In(o),b=hn(a),S=In(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[$o(a)]:Lx(a)),T=x!=="none";!p&&T&&C.push(...Bx(a,m,x,k));const E=[a,...C],N=await Mr(t,v),_=[];let $=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(N[g]),f){const A=Dx(o,i,k);_.push(N[A[0]],N[A[1]])}if($=[...$,{placement:o,overflows:_}],!_.every(A=>A<=0)){var P,D;const A=(((P=s.flip)==null?void 0:P.index)||0)+1,z=E[A];if(z&&(!(f==="alignment"?b!==hn(z):!1)||$.every(B=>hn(B.placement)===b?B.overflows[0]>0:!0)))return{data:{index:A,overflows:$},reset:{placement:z}};let j=(D=$.filter(K=>K.overflows[0]<=0).sort((K,B)=>K.overflows[1]-B.overflows[1])[0])==null?void 0:D.placement;if(!j)switch(h){case"bestFit":{var F;const K=(F=$.filter(B=>{if(T){const R=hn(B.placement);return R===b||R==="y"}return!0}).map(B=>[B.placement,B.overflows.filter(R=>R>0).reduce((R,Y)=>R+Y,0)]).sort((B,R)=>B[1]-R[1])[0])==null?void 0:F[0];K&&(j=K);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function _c(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function jc(e){return Rx.some(t=>e[t]>=0)}const Kx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=En(e,t);switch(r){case"referenceHidden":{const s=await Mr(t,{...o,elementContext:"reference"}),i=_c(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:jc(i)}}}case"escaped":{const s=await Mr(t,{...o,altBoundary:!0}),i=_c(s,n.floating);return{data:{escapedOffsets:i,escaped:jc(i)}}}default:return{}}}}},Rc=new Set(["left","top"]);async function qx(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=pr(n),l=hn(n)==="y",c=Rc.has(i)?-1:1,d=s&&l?-1:1,f=En(t,e);let{mainAxis:p,crossAxis:h,alignmentAxis:x}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof x=="number"&&(h=a==="end"?x*-1:x),l?{x:h*d,y:p*c}:{x:p*c,y:h*d}}const Gx=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 qx(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}}}}},Yx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:g,y:b}=v;return{x:g,y:b}}},...l}=En(e,t),c={x:n,y:r},d=await Mr(t,l),f=hn(In(o)),p=Ci(f);let h=c[p],x=c[f];if(s){const v=p==="y"?"top":"left",g=p==="y"?"bottom":"right",b=h+d[v],S=h-d[g];h=Si(b,h,S)}if(i){const v=f==="y"?"top":"left",g=f==="y"?"bottom":"right",b=x+d[v],S=x-d[g];x=Si(b,x,S)}const m=a.fn({...t,[p]:h,[f]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},Xx=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=En(e,t),d={x:n,y:r},f=hn(o),p=Ci(f);let h=d[p],x=d[f];const m=En(a,t),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const S=p==="y"?"height":"width",k=s.reference[p]-s.floating[S]+v.mainAxis,C=s.reference[p]+s.reference[S]-v.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var g,b;const S=p==="y"?"width":"height",k=Rc.has(In(o)),C=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:v.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?v.crossAxis:0);x<C?x=C:x>T&&(x=T)}return{[p]:h,[f]:x}}}},Jx=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=En(e,t),d=await Mr(t,c),f=In(o),p=pr(o),h=hn(o)==="y",{width:x,height:m}=s.floating;let v,g;f==="top"||f==="bottom"?(v=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,v=p==="end"?"top":"bottom");const b=m-d.top-d.bottom,S=x-d.left-d.right,k=Pn(m-d[v],b),C=Pn(x-d[g],S),T=!t.middlewareData.shift;let E=k,N=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!p){const $=Wt(d.left,0),P=Wt(d.right,0),D=Wt(d.top,0),F=Wt(d.bottom,0);h?N=x-2*($!==0||P!==0?$+P:Wt(d.left,d.right)):E=m-2*(D!==0||F!==0?D+F:Wt(d.top,d.bottom))}await l({...t,availableWidth:N,availableHeight:E});const _=await i.getDimensions(a.floating);return x!==_.width||m!==_.height?{reset:{rects:!0}}:{}}}};function zo(){return typeof window<"u"}function hr(e){return Pc(e)?(e.nodeName||"").toLowerCase():"#document"}function Vt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function mn(e){var t;return(t=(Pc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Pc(e){return zo()?e instanceof Node||e instanceof Vt(e).Node:!1}function sn(e){return zo()?e instanceof Element||e instanceof Vt(e).Element:!1}function gn(e){return zo()?e instanceof HTMLElement||e instanceof Vt(e).HTMLElement:!1}function Oc(e){return!zo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vt(e).ShadowRoot}const Zx=new Set(["inline","contents"]);function Dr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=an(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Zx.has(o)}const Qx=new Set(["table","td","th"]);function ey(e){return Qx.has(hr(e))}const ty=[":popover-open",":modal"];function Bo(e){return ty.some(t=>{try{return e.matches(t)}catch{return!1}})}const ny=["transform","translate","scale","rotate","perspective"],ry=["transform","translate","scale","rotate","perspective","filter"],oy=["paint","layout","strict","content"];function Ii(e){const t=Ni(),n=sn(e)?an(e):e;return ny.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)||ry.some(r=>(n.willChange||"").includes(r))||oy.some(r=>(n.contain||"").includes(r))}function sy(e){let t=On(e);for(;gn(t)&&!mr(t);){if(Ii(t))return t;if(Bo(t))return null;t=On(t)}return null}function Ni(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const iy=new Set(["html","body","#document"]);function mr(e){return iy.has(hr(e))}function an(e){return Vt(e).getComputedStyle(e)}function Ho(e){return sn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function On(e){if(hr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Oc(e)&&e.host||mn(e);return Oc(t)?t.host:t}function Mc(e){const t=On(e);return mr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&Dr(t)?t:Mc(t)}function Lr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Mc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Vt(o);if(s){const a=Ai(i);return t.concat(i,i.visualViewport||[],Dr(o)?o:[],a&&n?Lr(a):[])}return t.concat(o,Lr(o,[],n))}function Ai(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Dc(e){const t=an(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=gn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Do(n)!==s||Do(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function _i(e){return sn(e)?e:e.contextElement}function gr(e){const t=_i(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Dc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ay=pn(0);function Lc(e){const t=Vt(e);return!Ni()||!t.visualViewport?ay:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ly(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Vt(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=_i(e);let i=pn(1);t&&(r?sn(r)&&(i=gr(r)):i=gr(e));const a=ly(s,n,r)?Lc(s):pn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Vt(s),h=r&&sn(r)?Vt(r):r;let x=p,m=Ai(x);for(;m&&r&&h!==x;){const v=gr(m),g=m.getBoundingClientRect(),b=an(m),S=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*v.x,k=g.top+(m.clientTop+parseFloat(b.paddingTop))*v.y;l*=v.x,c*=v.y,d*=v.x,f*=v.y,l+=S,c+=k,x=Vt(m),m=Ai(x)}}return Fo({width:d,height:f,x:l,y:c})}function Uo(e,t){const n=Ho(e).scrollLeft;return t?t.left+n:Gn(mn(e)).left+n}function $c(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Uo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function cy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?Bo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pn(1);const d=pn(0),f=gn(r);if((f||!f&&!s)&&((hr(r)!=="body"||Dr(i))&&(l=Ho(r)),gn(r))){const h=Gn(r);c=gr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?$c(i,l):pn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:n.y*c.y-l.scrollTop*c.y+d.y+p.y}}function uy(e){return Array.from(e.getClientRects())}function dy(e){const t=mn(e),n=Ho(e),r=e.ownerDocument.body,o=Wt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Wt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Uo(e);const a=-n.scrollTop;return an(r).direction==="rtl"&&(i+=Wt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Fc=25;function fy(e,t){const n=Vt(e),r=mn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ni();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Uo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,x=Math.abs(r.clientWidth-f.clientWidth-h);x<=Fc&&(s-=x)}else c<=Fc&&(s+=c);return{width:s,height:i,x:a,y:l}}const py=new Set(["absolute","fixed"]);function hy(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=gn(e)?gr(e):pn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function zc(e,t,n){let r;if(t==="viewport")r=fy(e,n);else if(t==="document")r=dy(mn(e));else if(sn(t))r=hy(t,n);else{const o=Lc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function Bc(e,t){const n=On(e);return n===t||!sn(n)||mr(n)?!1:an(n).position==="fixed"||Bc(n,t)}function my(e,t){const n=t.get(e);if(n)return n;let r=Lr(e,[],!1).filter(a=>sn(a)&&hr(a)!=="body"),o=null;const s=an(e).position==="fixed";let i=s?On(e):e;for(;sn(i)&&!mr(i);){const a=an(i),l=Ii(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&py.has(o.position)||Dr(i)&&!l&&Bc(e,i))?r=r.filter(d=>d!==i):o=a,i=On(i)}return t.set(e,r),r}function gy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Bo(t)?[]:my(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=zc(t,d,o);return c.top=Wt(f.top,c.top),c.right=Pn(f.right,c.right),c.bottom=Pn(f.bottom,c.bottom),c.left=Wt(f.left,c.left),c},zc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function xy(e){const{width:t,height:n}=Dc(e);return{width:t,height:n}}function yy(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Uo(o)}if(r||!r&&!s)if((hr(t)!=="body"||Dr(o))&&(a=Ho(t)),r){const h=Gn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?$c(o,a):pn(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function ji(e){return an(e).position==="static"}function Hc(e,t){if(!gn(e)||an(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return mn(e)===n&&(n=n.ownerDocument.body),n}function Uc(e,t){const n=Vt(e);if(Bo(e))return n;if(!gn(e)){let o=On(e);for(;o&&!mr(o);){if(sn(o)&&!ji(o))return o;o=On(o)}return n}let r=Hc(e,t);for(;r&&ey(r)&&ji(r);)r=Hc(r,t);return r&&mr(r)&&ji(r)&&!Ii(r)?n:r||sy(e)||n}const vy=async function(e){const t=this.getOffsetParent||Uc,n=this.getDimensions,r=await n(e.floating);return{reference:yy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function by(e){return an(e).direction==="rtl"}const wy={convertOffsetParentRelativeRectToViewportRelativeRect:cy,getDocumentElement:mn,getClippingRect:gy,getOffsetParent:Uc,getElementRects:vy,getClientRects:uy,getDimensions:xy,getScale:gr,isElement:sn,isRTL:by};function Wc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Sy(e,t){let n=null,r;const o=mn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const x=Lo(f),m=Lo(o.clientWidth-(d+p)),v=Lo(o.clientHeight-(f+h)),g=Lo(d),S={rootMargin:-x+"px "+-m+"px "+-v+"px "+-g+"px",threshold:Wt(0,Pn(1,l))||1};let k=!0;function C(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&&!Wc(c,e.getBoundingClientRect())&&i(),k=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function Cy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=_i(e),d=o||s?[...c?Lr(c):[],...Lr(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?Sy(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[b]=g;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let x,m=l?Gn(e):null;l&&v();function v(){const g=Gn(e);m&&!Wc(m,g)&&n(),m=g,x=requestAnimationFrame(v)}return n(),()=>{var g;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(x)}}const Ty=Gx,ky=Yx,Ey=Vx,Iy=Jx,Ny=Kx,Vc=Wx,Ay=Xx,_y=(e,t,n)=>{const r=new Map,o={platform:wy,...n},s={...o.platform,_c:r};return Ux(e,t,{...o,platform:s})};var jy=typeof document<"u",Ry=function(){},Wo=jy?w.useLayoutEffect:Ry;function Vo(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Vo(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Vo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Kc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function qc(e,t){const n=Kc(e);return Math.round(t*n)/n}function Ri(e){const t=y.useRef(e);return Wo(()=>{t.current=e}),t}function Py(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=y.useState(r);Vo(p,r)||h(r);const[x,m]=y.useState(null),[v,g]=y.useState(null),b=y.useCallback(B=>{B!==T.current&&(T.current=B,m(B))},[]),S=y.useCallback(B=>{B!==E.current&&(E.current=B,g(B))},[]),k=s||x,C=i||v,T=y.useRef(null),E=y.useRef(null),N=y.useRef(d),_=l!=null,$=Ri(l),P=Ri(o),D=Ri(c),F=y.useCallback(()=>{if(!T.current||!E.current)return;const B={placement:t,strategy:n,middleware:p};P.current&&(B.platform=P.current),_y(T.current,E.current,B).then(R=>{const Y={...R,isPositioned:D.current!==!1};A.current&&!Vo(N.current,Y)&&(N.current=Y,ho.flushSync(()=>{f(Y)}))})},[p,t,n,P,D]);Wo(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(B=>({...B,isPositioned:!1})))},[c]);const A=y.useRef(!1);Wo(()=>(A.current=!0,()=>{A.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(E.current=C),k&&C){if($.current)return $.current(k,C,F);F()}},[k,C,F,$,_]);const z=y.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),j=y.useMemo(()=>({reference:k,floating:C}),[k,C]),K=y.useMemo(()=>{const B={position:n,left:0,top:0};if(!j.floating)return B;const R=qc(j.floating,d.x),Y=qc(j.floating,d.y);return a?{...B,transform:"translate("+R+"px, "+Y+"px)",...Kc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:R,top:Y}},[n,a,j.floating,d.x,d.y]);return y.useMemo(()=>({...d,update:F,refs:z,elements:j,floatingStyles:K}),[d,F,z,j,K])}const Oy=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?Vc({element:r.current,padding:o}).fn(n):{}:r?Vc({element:r,padding:o}).fn(n):{}}}},My=(e,t)=>({...Ty(e),options:[e,t]}),Dy=(e,t)=>({...ky(e),options:[e,t]}),Ly=(e,t)=>({...Ay(e),options:[e,t]}),$y=(e,t)=>({...Ey(e),options:[e,t]}),Fy=(e,t)=>({...Iy(e),options:[e,t]}),zy=(e,t)=>({...Ny(e),options:[e,t]}),By=(e,t)=>({...Oy(e),options:[e,t]});var Hy="Arrow",Gc=y.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(je.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});Gc.displayName=Hy;var Uy=Gc;function Yc(e){const[t,n]=y.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,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Pi="Popper",[Xc,Ko]=Tn(Pi),[Wy,Jc]=Xc(Pi),Zc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=y.useState(null);return u.jsx(Wy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Zc.displayName=Pi;var Qc="PopperAnchor",eu=y.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Jc(Qc,n),i=y.useRef(null),a=Ve(t,i),l=y.useRef(null);return y.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(je.div,{...o,ref:a})});eu.displayName=Qc;var Oi="PopperContent",[Vy,Ky]=Xc(Oi),tu=y.forwardRef((e,t)=>{var J,L,G,Z,fe,oe;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:h="optimized",onPlaced:x,...m}=e,v=Jc(Oi,n),[g,b]=y.useState(null),S=Ve(t,Ae=>b(Ae)),[k,C]=y.useState(null),T=Yc(k),E=(T==null?void 0:T.width)??0,N=(T==null?void 0:T.height)??0,_=r+(s!=="center"?"-"+s:""),$=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],D=P.length>0,F={padding:$,boundary:P.filter(Gy),altBoundary:D},{refs:A,floatingStyles:z,placement:j,isPositioned:K,middlewareData:B}=Py({strategy:"fixed",placement:_,whileElementsMounted:(...Ae)=>Cy(...Ae,{animationFrame:h==="always"}),elements:{reference:v.anchor},middleware:[My({mainAxis:o+N,alignmentAxis:i}),l&&Dy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Ly():void 0,...F}),l&&$y({...F}),Fy({...F,apply:({elements:Ae,rects:qe,availableWidth:Fe,availableHeight:Ze})=>{const{width:ie,height:we}=qe.reference,_e=Ae.floating.style;_e.setProperty("--radix-popper-available-width",`${Fe}px`),_e.setProperty("--radix-popper-available-height",`${Ze}px`),_e.setProperty("--radix-popper-anchor-width",`${ie}px`),_e.setProperty("--radix-popper-anchor-height",`${we}px`)}}),k&&By({element:k,padding:a}),Yy({arrowWidth:E,arrowHeight:N}),p&&zy({strategy:"referenceHidden",...F})]}),[R,Y]=ou(j),X=_t(x);At(()=>{K&&(X==null||X())},[K,X]);const se=(J=B.arrow)==null?void 0:J.x,be=(L=B.arrow)==null?void 0:L.y,Oe=((G=B.arrow)==null?void 0:G.centerOffset)!==0,[q,H]=y.useState();return At(()=>{g&&H(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:A.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:K?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:q,"--radix-popper-transform-origin":[(Z=B.transformOrigin)==null?void 0:Z.x,(fe=B.transformOrigin)==null?void 0:fe.y].join(" "),...((oe=B.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Vy,{scope:n,placedSide:R,onArrowChange:C,arrowX:se,arrowY:be,shouldHideArrow:Oe,children:u.jsx(je.div,{"data-side":R,"data-align":Y,...m,ref:S,style:{...m.style,animation:K?void 0:"none"}})})})});tu.displayName=Oi;var nu="PopperArrow",qy={top:"bottom",right:"left",bottom:"top",left:"right"},ru=y.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Ky(nu,r),i=qy[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Uy,{...o,ref:n,style:{...o.style,display:"block"}})})});ru.displayName=nu;function Gy(e){return e!==null}var Yy=e=>({name:"transformOrigin",options:e,fn(t){var v,g,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,[c,d]=ou(n),f={start:"0%",center:"50%",end:"100%"}[d],p=(((g=o.arrow)==null?void 0:g.x)??0)+a/2,h=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let x="",m="";return c==="bottom"?(x=i?f:`${p}px`,m=`${-l}px`):c==="top"?(x=i?f:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(x=`${-l}px`,m=i?f:`${h}px`):c==="left"&&(x=`${r.floating.width+l}px`,m=i?f:`${h}px`),{data:{x,y:m}}}});function ou(e){const[t,n="center"]=e.split("-");return[t,n]}var su=Zc,iu=eu,au=tu,lu=ru,Xy="Portal",qo=y.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=y.useState(!1);At(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?qs.createPortal(u.jsx(je.div,{...r,ref:t}),i):null});qo.displayName=Xy;function Jy(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Zt=e=>{const{present:t,children:n}=e,r=Zy(t),o=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),s=Ve(r.ref,Qy(o));return typeof n=="function"||r.isPresent?y.cloneElement(o,{ref:s}):null};Zt.displayName="Presence";function Zy(e){const[t,n]=y.useState(),r=y.useRef(null),o=y.useRef(e),s=y.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Jy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),At(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Go(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),At(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=Go(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(l("ANIMATION_END"),!o.current)){const v=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=v)})}},p=h=>{h.target===t&&(s.current=Go(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:y.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function Qy(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 Mi="rovingFocusGroup.onEntryFocus",ev={bubbles:!1,cancelable:!0},$r="RovingFocusGroup",[Di,cu,tv]=gi($r),[nv,uu]=Tn($r,[tv]),[rv,ov]=nv($r),du=y.forwardRef((e,t)=>u.jsx(Di.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Di.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(sv,{...e,ref:t})})}));du.displayName=$r;var sv=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=y.useRef(null),h=Ve(t,p),x=Po(s),[m,v]=fr({prop:i,defaultProp:a??null,onChange:l,caller:$r}),[g,b]=y.useState(!1),S=_t(c),k=cu(n),C=y.useRef(!1),[T,E]=y.useState(0);return y.useEffect(()=>{const N=p.current;if(N)return N.addEventListener(Mi,S),()=>N.removeEventListener(Mi,S)},[S]),u.jsx(rv,{scope:n,orientation:r,dir:x,loop:o,currentTabStopId:m,onItemFocus:y.useCallback(N=>v(N),[v]),onItemShiftTab:y.useCallback(()=>b(!0),[]),onFocusableItemAdd:y.useCallback(()=>E(N=>N+1),[]),onFocusableItemRemove:y.useCallback(()=>E(N=>N-1),[]),children:u.jsx(je.div,{tabIndex:g||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:me(e.onMouseDown,()=>{C.current=!0}),onFocus:me(e.onFocus,N=>{const _=!C.current;if(N.target===N.currentTarget&&_&&!g){const $=new CustomEvent(Mi,ev);if(N.currentTarget.dispatchEvent($),!$.defaultPrevented){const P=k().filter(j=>j.focusable),D=P.find(j=>j.active),F=P.find(j=>j.id===m),z=[D,F,...P].filter(Boolean).map(j=>j.ref.current);hu(z,d)}}C.current=!1}),onBlur:me(e.onBlur,()=>b(!1))})})}),fu="RovingFocusGroupItem",pu=y.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=kn(),c=s||l,d=ov(fu,n),f=d.currentTabStopId===c,p=cu(n),{onFocusableItemAdd:h,onFocusableItemRemove:x,currentTabStopId:m}=d;return y.useEffect(()=>{if(r)return h(),()=>x()},[r,h,x]),u.jsx(Di.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(je.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:me(e.onMouseDown,v=>{r?d.onItemFocus(c):v.preventDefault()}),onFocus:me(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:me(e.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){d.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const g=lv(v,d.orientation,d.dir);if(g!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(v.currentTarget);S=d.loop?cv(S,k+1):S.slice(k+1)}setTimeout(()=>hu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});pu.displayName=fu;var iv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function av(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function lv(e,t,n){const r=av(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return iv[r]}function hu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function cv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var uv=du,dv=pu,fv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},xr=new WeakMap,Yo=new WeakMap,Xo={},Li=0,mu=function(e){return e&&(e.host||mu(e.parentNode))},pv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=mu(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})},hv=function(e,t,n,r){var o=pv(t,Array.isArray(e)?e:[e]);Xo[n]||(Xo[n]=new WeakMap);var s=Xo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),x=h!==null&&h!=="false",m=(xr.get(p)||0)+1,v=(s.get(p)||0)+1;xr.set(p,m),s.set(p,v),i.push(p),m===1&&x&&Yo.set(p,!0),v===1&&p.setAttribute(n,"true"),x||p.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",p,g)}})};return d(t),a.clear(),Li++,function(){i.forEach(function(f){var p=xr.get(f)-1,h=s.get(f)-1;xr.set(f,p),s.set(f,h),p||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),h||f.removeAttribute(n)}),Li--,Li||(xr=new WeakMap,xr=new WeakMap,Yo=new WeakMap,Xo={})}},$i=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=fv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),hv(r,o,n,"aria-hidden")):function(){return null}},xn=function(){return xn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},xn.apply(this,arguments)};function gu(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 mv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Jo="right-scroll-bar-position",Zo="width-before-scroll-bar",gv="with-scroll-bars-hidden",xv="--removed-body-scroll-bar-size";function Fi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function yv(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 vv=typeof window<"u"?y.useLayoutEffect:y.useEffect,xu=new WeakMap;function bv(e,t){var n=yv(null,function(r){return e.forEach(function(o){return Fi(o,r)})});return vv(function(){var r=xu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Fi(a,null)}),s.forEach(function(a){o.has(a)||Fi(a,i)})}xu.set(n,e)},[e]),n}function wv(e){return e}function Sv(e,t){t===void 0&&(t=wv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),n}}}};return o}function Cv(e){e===void 0&&(e={});var t=Sv(null);return t.options=xn({async:!0,ssr:!1},e),t}var yu=function(e){var t=e.sideCar,n=gu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return y.createElement(r,xn({},n))};yu.isSideCarExport=!0;function Tv(e,t){return e.useMedium(t),yu}var vu=Cv(),zi=function(){},Qo=y.forwardRef(function(e,t){var n=y.useRef(null),r=y.useState({onScrollCapture:zi,onWheelCapture:zi,onTouchMoveCapture:zi}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,h=e.noRelative,x=e.noIsolation,m=e.inert,v=e.allowPinchZoom,g=e.as,b=g===void 0?"div":g,S=e.gapMode,k=gu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=bv([n,t]),E=xn(xn({},k),o);return y.createElement(y.Fragment,null,d&&y.createElement(C,{sideCar:vu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:x,inert:m,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:S}),i?y.cloneElement(y.Children.only(a),xn(xn({},E),{ref:T})):y.createElement(b,xn({},E,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var kv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ev(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=kv();return t&&e.setAttribute("nonce",t),e}function Iv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Nv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Av=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Ev())&&(Iv(t,n),Nv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_v=function(){var e=Av();return function(t,n){y.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},bu=function(){var e=_v(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},jv={left:0,top:0,right:0,gap:0},Bi=function(e){return parseInt(e||"",10)||0},Rv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Bi(n),Bi(r),Bi(o)]},Pv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return jv;var t=Rv(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])}},Ov=bu(),yr="data-scroll-locked",Mv=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(gv,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(xr,`] {
43
+ body[`).concat(yr,`] {
44
44
  overflow: hidden `).concat(r,`;
45
45
  overscroll-behavior: contain;
46
46
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -53,29 +53,29 @@ React keys must be passed directly to JSX without using spread:
53
53
  `),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
54
54
  }
55
55
 
56
- .`).concat(Xo,` {
56
+ .`).concat(Jo,` {
57
57
  right: `).concat(a,"px ").concat(r,`;
58
58
  }
59
59
 
60
- .`).concat(Jo,` {
60
+ .`).concat(Zo,` {
61
61
  margin-right: `).concat(a,"px ").concat(r,`;
62
62
  }
63
63
 
64
- .`).concat(Xo," .").concat(Xo,` {
64
+ .`).concat(Jo," .").concat(Jo,` {
65
65
  right: 0 `).concat(r,`;
66
66
  }
67
67
 
68
- .`).concat(Jo," .").concat(Jo,` {
68
+ .`).concat(Zo," .").concat(Zo,` {
69
69
  margin-right: 0 `).concat(r,`;
70
70
  }
71
71
 
72
- body[`).concat(xr,`] {
73
- `).concat(fv,": ").concat(a,`px;
72
+ body[`).concat(yr,`] {
73
+ `).concat(xv,": ").concat(a,`px;
74
74
  }
75
- `)},bu=function(){var e=parseInt(document.body.getAttribute(xr)||"0",10);return isFinite(e)?e:0},_v=function(){y.useEffect(function(){return document.body.setAttribute(xr,(bu()+1).toString()),function(){var e=bu()-1;e<=0?document.body.removeAttribute(xr):document.body.setAttribute(xr,e.toString())}},[])},Rv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;_v();var s=y.useMemo(function(){return Nv(o)},[o]);return y.createElement(Av,{styles:jv(s,!t,o,n?"":"!important")})},zi=!1;if(typeof window<"u")try{var Qo=Object.defineProperty({},"passive",{get:function(){return zi=!0,!0}});window.addEventListener("test",Qo,Qo),window.removeEventListener("test",Qo,Qo)}catch{zi=!1}var yr=zi?{passive:!1}:!1,Pv=function(e){return e.tagName==="TEXTAREA"},wu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Pv(e)&&n[t]==="visible")},Ov=function(e){return wu(e,"overflowY")},Mv=function(e){return wu(e,"overflowX")},Su=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Cu(e,r);if(o){var s=Tu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Dv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Lv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Cu=function(e,t){return e==="v"?Ov(t):Mv(t)},Tu=function(e,t){return e==="v"?Dv(t):Lv(t)},$v=function(e,t){return e==="h"&&t==="rtl"?-1:1},Fv=function(e,t,n,r,o){var s=$v(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,p=0;do{if(!a)break;var h=Tu(e,a),x=h[0],m=h[1],v=h[2],g=m-v-s*x;(x||g)&&Cu(e,a)&&(f+=g,p+=x);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},es=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ku=function(e){return[e.deltaX,e.deltaY]},Eu=function(e){return e&&"current"in e?e.current:e},zv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Bv=function(e){return`
75
+ `)},wu=function(){var e=parseInt(document.body.getAttribute(yr)||"0",10);return isFinite(e)?e:0},Dv=function(){y.useEffect(function(){return document.body.setAttribute(yr,(wu()+1).toString()),function(){var e=wu()-1;e<=0?document.body.removeAttribute(yr):document.body.setAttribute(yr,e.toString())}},[])},Lv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Dv();var s=y.useMemo(function(){return Pv(o)},[o]);return y.createElement(Ov,{styles:Mv(s,!t,o,n?"":"!important")})},Hi=!1;if(typeof window<"u")try{var es=Object.defineProperty({},"passive",{get:function(){return Hi=!0,!0}});window.addEventListener("test",es,es),window.removeEventListener("test",es,es)}catch{Hi=!1}var vr=Hi?{passive:!1}:!1,$v=function(e){return e.tagName==="TEXTAREA"},Su=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!$v(e)&&n[t]==="visible")},Fv=function(e){return Su(e,"overflowY")},zv=function(e){return Su(e,"overflowX")},Cu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Tu(e,r);if(o){var s=ku(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Bv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Hv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Tu=function(e,t){return e==="v"?Fv(t):zv(t)},ku=function(e,t){return e==="v"?Bv(t):Hv(t)},Uv=function(e,t){return e==="h"&&t==="rtl"?-1:1},Wv=function(e,t,n,r,o){var s=Uv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,p=0;do{if(!a)break;var h=ku(e,a),x=h[0],m=h[1],v=h[2],g=m-v-s*x;(x||g)&&Tu(e,a)&&(f+=g,p+=x);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Eu=function(e){return[e.deltaX,e.deltaY]},Iu=function(e){return e&&"current"in e?e.current:e},Vv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Kv=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},Hv=0,vr=[];function Uv(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),o=y.useState(Hv++)[0],s=y.useState(vu)[0],i=y.useRef(e);y.useEffect(function(){i.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=uv([e.lockRef.current],(e.shards||[]).map(Eu),!0).filter(Boolean);return m.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=y.useCallback(function(m,v){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var g=es(m),b=n.current,S="deltaX"in m?m.deltaX:b[0]-g[0],k="deltaY"in m?m.deltaY:b[1]-g[1],C,T=m.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&E==="h"&&T.type==="range")return!1;var N=Su(E,T);if(!N)return!0;if(N?C=E:(C=E==="v"?"h":"v",N=Su(E,T)),!N)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var j=r.current||C;return Fv(j,v,m,j==="h"?S:k)},[]),l=y.useCallback(function(m){var v=m;if(!(!vr.length||vr[vr.length-1]!==s)){var g="deltaY"in v?ku(v):es(v),b=t.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&zv(C.delta,g)})[0];if(b&&b.should){v.cancelable&&v.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Eu).filter(Boolean).filter(function(C){return C.contains(v.target)}),k=S.length>0?a(v,S[0]):!i.current.noIsolation;k&&v.cancelable&&v.preventDefault()}}},[]),c=y.useCallback(function(m,v,g,b){var S={name:m,delta:v,target:g,should:b,shadowParent:Wv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=y.useCallback(function(m){n.current=es(m),r.current=void 0},[]),f=y.useCallback(function(m){c(m.type,ku(m),m.target,a(m,e.lockRef.current))},[]),p=y.useCallback(function(m){c(m.type,es(m),m.target,a(m,e.lockRef.current))},[]);y.useEffect(function(){return vr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,yr),document.addEventListener("touchmove",l,yr),document.addEventListener("touchstart",d,yr),function(){vr=vr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,yr),document.removeEventListener("touchmove",l,yr),document.removeEventListener("touchstart",d,yr)}},[]);var h=e.removeScrollBar,x=e.inert;return y.createElement(y.Fragment,null,x?y.createElement(s,{styles:Bv(o)}):null,h?y.createElement(Rv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Wv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Vv=vv(yu,Uv);var ts=y.forwardRef(function(e,t){return y.createElement(Zo,xn({},e,{ref:t,sideCar:Vv}))});ts.classNames=Zo.classNames;var Bi=["Enter"," "],Kv=["ArrowDown","PageUp","Home"],Iu=["ArrowUp","PageDown","End"],qv=[...Kv,...Iu],Gv={ltr:[...Bi,"ArrowRight"],rtl:[...Bi,"ArrowLeft"]},Yv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},$r="Menu",[Fr,Xv,Jv]=hi($r),[Gn,Nu]=Tn($r,[Jv,Vo,cu]),ns=Vo(),Au=cu(),[Zv,Yn]=Gn($r),[Qv,zr]=Gn($r),ju=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ns(t),[l,c]=y.useState(null),d=y.useRef(!1),f=jt(s),p=Ro(o);return y.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},x=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),u.jsx(ou,{...a,children:u.jsx(Zv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Qv,{scope:t,onClose:y.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};ju.displayName=$r;var eb="MenuAnchor",Hi=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ns(n);return u.jsx(su,{...o,...r,ref:t})});Hi.displayName=eb;var Ui="MenuPortal",[tb,_u]=Gn(Ui,{forceMount:void 0}),Ru=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Yn(Ui,t);return u.jsx(tb,{scope:t,forceMount:n,children:u.jsx(Jt,{present:n||s.open,children:u.jsx(Ko,{asChild:!0,container:o,children:r})})})};Ru.displayName=Ui;var Zt="MenuContent",[nb,Wi]=Gn(Zt),Pu=y.forwardRef((e,t)=>{const n=_u(Zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Zt,e.__scopeMenu),i=zr(Zt,e.__scopeMenu);return u.jsx(Fr.Provider,{scope:e.__scopeMenu,children:u.jsx(Jt,{present:r||s.open,children:u.jsx(Fr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(rb,{...o,ref:t}):u.jsx(ob,{...o,ref:t})})})})}),rb=y.forwardRef((e,t)=>{const n=Yn(Zt,e.__scopeMenu),r=y.useRef(null),o=Ve(t,r);return y.useEffect(()=>{const s=r.current;if(s)return Di(s)},[]),u.jsx(Vi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:me(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ob=y.forwardRef((e,t)=>{const n=Yn(Zt,e.__scopeMenu);return u.jsx(Vi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),sb=Un.createSlot("MenuContent.ScrollLock"),Vi=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:x,...m}=e,v=Yn(Zt,n),g=zr(Zt,n),b=ns(n),S=Au(n),k=Xv(n),[C,T]=y.useState(null),E=y.useRef(null),N=Ve(t,E,v.onContentChange),j=y.useRef(0),$=y.useRef(""),P=y.useRef(0),D=y.useRef(null),F=y.useRef("right"),A=y.useRef(0),z=x?ts:y.Fragment,_=x?{as:sb,allowPinchZoom:!0}:void 0,K=R=>{var J,L;const Y=$.current+R,X=k().filter(G=>!G.disabled),se=document.activeElement,ve=(J=X.find(G=>G.ref.current===se))==null?void 0:J.textValue,Oe=X.map(G=>G.textValue),q=xb(Oe,Y,ve),H=(L=X.find(G=>G.textValue===q))==null?void 0:L.ref.current;(function G(Z){$.current=Z,window.clearTimeout(j.current),Z!==""&&(j.current=window.setTimeout(()=>G(""),1e3))})(Y),H&&setTimeout(()=>H.focus())};y.useEffect(()=>()=>window.clearTimeout(j.current),[]),xi();const B=y.useCallback(R=>{var X,se;return F.current===((X=D.current)==null?void 0:X.side)&&vb(R,(se=D.current)==null?void 0:se.area)},[]);return u.jsx(nb,{scope:n,searchRef:$,onItemEnter:y.useCallback(R=>{B(R)&&R.preventDefault()},[B]),onItemLeave:y.useCallback(R=>{var Y;B(R)||((Y=E.current)==null||Y.focus(),T(null))},[B]),onTriggerLeave:y.useCallback(R=>{B(R)&&R.preventDefault()},[B]),pointerGraceTimerRef:P,onPointerGraceIntentChange:y.useCallback(R=>{D.current=R},[]),children:u.jsx(z,{..._,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:me(s,R=>{var Y;R.preventDefault(),(Y=E.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(sv,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:me(l,R=>{g.isUsingKeyboardRef.current||R.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(iu,{role:"menu","aria-orientation":"vertical","data-state":Xu(v.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:N,style:{outline:"none",...m.style},onKeyDown:me(m.onKeyDown,R=>{const X=R.target.closest("[data-radix-menu-content]")===R.currentTarget,se=R.ctrlKey||R.altKey||R.metaKey,ve=R.key.length===1;X&&(R.key==="Tab"&&R.preventDefault(),!se&&ve&&K(R.key));const Oe=E.current;if(R.target!==Oe||!qv.includes(R.key))return;R.preventDefault();const H=k().filter(J=>!J.disabled).map(J=>J.ref.current);Iu.includes(R.key)&&H.reverse(),mb(H)}),onBlur:me(e.onBlur,R=>{R.currentTarget.contains(R.target)||(window.clearTimeout(j.current),$.current="")}),onPointerMove:me(e.onPointerMove,Hr(R=>{const Y=R.target,X=A.current!==R.clientX;if(R.currentTarget.contains(Y)&&X){const se=R.clientX>A.current?"right":"left";F.current=se,A.current=R.clientX}}))})})})})})})});Pu.displayName=Zt;var ib="MenuGroup",Ki=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"group",...r,ref:t})});Ki.displayName=ib;var ab="MenuLabel",Ou=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{...r,ref:t})});Ou.displayName=ab;var rs="MenuItem",Mu="menu.itemSelect",os=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=y.useRef(null),i=zr(rs,e.__scopeMenu),a=Wi(rs,e.__scopeMenu),l=Ve(t,s),c=y.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Mu,{bubbles:!0,cancelable:!0});f.addEventListener(Mu,h=>r==null?void 0:r(h),{once:!0}),hc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Du,{...o,ref:l,disabled:n,onClick:me(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:me(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:me(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Bi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});os.displayName=rs;var Du=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Wi(rs,n),a=Au(n),l=y.useRef(null),c=Ve(t,l),[d,f]=y.useState(!1),[p,h]=y.useState("");return y.useEffect(()=>{const x=l.current;x&&h((x.textContent??"").trim())},[s.children]),u.jsx(Fr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(iv,{asChild:!0,...a,focusable:!r,children:u.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:me(e.onPointerMove,Hr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:me(e.onPointerLeave,Hr(x=>i.onItemLeave(x))),onFocus:me(e.onFocus,()=>f(!0)),onBlur:me(e.onBlur,()=>f(!1))})})})}),lb="MenuCheckboxItem",Lu=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Hu,{scope:e.__scopeMenu,checked:n,children:u.jsx(os,{role:"menuitemcheckbox","aria-checked":ss(n)?"mixed":n,...o,ref:t,"data-state":Gi(n),onSelect:me(o.onSelect,()=>r==null?void 0:r(ss(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Lu.displayName=lb;var $u="MenuRadioGroup",[cb,ub]=Gn($u,{value:void 0,onValueChange:()=>{}}),Fu=y.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=jt(r);return u.jsx(cb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Ki,{...o,ref:t})})});Fu.displayName=$u;var zu="MenuRadioItem",Bu=y.forwardRef((e,t)=>{const{value:n,...r}=e,o=ub(zu,e.__scopeMenu),s=n===o.value;return u.jsx(Hu,{scope:e.__scopeMenu,checked:s,children:u.jsx(os,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Gi(s),onSelect:me(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Bu.displayName=zu;var qi="MenuItemIndicator",[Hu,db]=Gn(qi,{checked:!1}),Uu=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=db(qi,n);return u.jsx(Jt,{present:r||ss(s.checked)||s.checked===!0,children:u.jsx(_e.span,{...o,ref:t,"data-state":Gi(s.checked)})})});Uu.displayName=qi;var fb="MenuSeparator",Wu=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Wu.displayName=fb;var pb="MenuArrow",Vu=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ns(n);return u.jsx(au,{...o,...r,ref:t})});Vu.displayName=pb;var hb="MenuSub",[wT,Ku]=Gn(hb),Br="MenuSubTrigger",qu=y.forwardRef((e,t)=>{const n=Yn(Br,e.__scopeMenu),r=zr(Br,e.__scopeMenu),o=Ku(Br,e.__scopeMenu),s=Wi(Br,e.__scopeMenu),i=y.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=y.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return y.useEffect(()=>d,[d]),y.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Hi,{asChild:!0,...c,children:u.jsx(Du,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Xu(n.open),...e,ref:pi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:me(e.onPointerMove,Hr(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:me(e.onPointerLeave,Hr(f=>{var h,x;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const m=(x=n.content)==null?void 0:x.dataset.side,v=m==="right",g=v?-5:5,b=p[v?"left":"right"],S=p[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:b,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:b,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:me(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||Gv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});qu.displayName=Br;var Gu="MenuSubContent",Yu=y.forwardRef((e,t)=>{const n=_u(Zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Zt,e.__scopeMenu),i=zr(Zt,e.__scopeMenu),a=Ku(Gu,e.__scopeMenu),l=y.useRef(null),c=Ve(t,l);return u.jsx(Fr.Provider,{scope:e.__scopeMenu,children:u.jsx(Jt,{present:r||s.open,children:u.jsx(Fr.Slot,{scope:e.__scopeMenu,children:u.jsx(Vi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:me(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:me(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:me(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=Yv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Yu.displayName=Gu;function Xu(e){return e?"open":"closed"}function ss(e){return e==="indeterminate"}function Gi(e){return ss(e)?"indeterminate":e?"checked":"unchecked"}function mb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function gb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function xb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=gb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function yb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function vb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return yb(n,t)}function Hr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var bb=ju,wb=Hi,Sb=Ru,Cb=Pu,Tb=Ki,kb=Ou,Eb=os,Ib=Lu,Nb=Fu,Ab=Bu,jb=Uu,_b=Wu,Rb=Vu,Pb=qu,Ob=Yu,is="DropdownMenu",[Mb,ST]=Tn(is,[Nu]),$t=Nu(),[Db,Ju]=Mb(is),Zu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=$t(t),c=y.useRef(null),[d,f]=dr({prop:o,defaultProp:s??!1,onChange:i,caller:is});return u.jsx(Db,{scope:t,triggerId:kn(),triggerRef:c,contentId:kn(),open:d,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(bb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Zu.displayName=is;var Qu="DropdownMenuTrigger",ed=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ju(Qu,n),i=$t(n);return u.jsx(wb,{asChild:!0,...i,children:u.jsx(_e.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:pi(t,s.triggerRef),onPointerDown:me(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:me(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=Qu;var Lb="DropdownMenuPortal",td=e=>{const{__scopeDropdownMenu:t,...n}=e,r=$t(t);return u.jsx(Sb,{...r,...n})};td.displayName=Lb;var nd="DropdownMenuContent",rd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ju(nd,n),s=$t(n),i=y.useRef(!1);return u.jsx(Cb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:me(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:me(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});rd.displayName=nd;var $b="DropdownMenuGroup",Fb=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Tb,{...o,...r,ref:t})});Fb.displayName=$b;var zb="DropdownMenuLabel",od=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(kb,{...o,...r,ref:t})});od.displayName=zb;var Bb="DropdownMenuItem",sd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Eb,{...o,...r,ref:t})});sd.displayName=Bb;var Hb="DropdownMenuCheckboxItem",id=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Ib,{...o,...r,ref:t})});id.displayName=Hb;var Ub="DropdownMenuRadioGroup",Wb=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Nb,{...o,...r,ref:t})});Wb.displayName=Ub;var Vb="DropdownMenuRadioItem",ad=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Ab,{...o,...r,ref:t})});ad.displayName=Vb;var Kb="DropdownMenuItemIndicator",ld=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(jb,{...o,...r,ref:t})});ld.displayName=Kb;var qb="DropdownMenuSeparator",cd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(_b,{...o,...r,ref:t})});cd.displayName=qb;var Gb="DropdownMenuArrow",Yb=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Rb,{...o,...r,ref:t})});Yb.displayName=Gb;var Xb="DropdownMenuSubTrigger",ud=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Pb,{...o,...r,ref:t})});ud.displayName=Xb;var Jb="DropdownMenuSubContent",dd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Ob,{...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)"}})});dd.displayName=Jb;var Zb=Zu,Qb=ed,ew=td,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd,vd=ud,bd=dd;const tw=Zb,nw=Qb,rw=y.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(vd,{ref:o,className:te("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(le.ChevronRight,{className:"ml-auto h-4 w-4"})]}));rw.displayName=vd.displayName;const ow=y.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:te("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));ow.displayName=bd.displayName;const wd=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(ew,{children:u.jsx(fd,{ref:r,sideOffset:t,className:te("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));wd.displayName=fd.displayName;const Yi=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(hd,{ref:r,className:te("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Yi.displayName=hd.displayName;const sw=y.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(md,{ref:o,className:te("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));sw.displayName=md.displayName;const iw=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gd,{ref:r,className:te("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));iw.displayName=gd.displayName;const aw=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(pd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));aw.displayName=pd.displayName;const lw=y.forwardRef(({className:e,...t},n)=>u.jsx(yd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));lw.displayName=yd.displayName;const as=1e4;function cw(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
+ `)},qv=0,br=[];function Gv(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),o=y.useState(qv++)[0],s=y.useState(bu)[0],i=y.useRef(e);y.useEffect(function(){i.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=mv([e.lockRef.current],(e.shards||[]).map(Iu),!0).filter(Boolean);return m.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=y.useCallback(function(m,v){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var g=ts(m),b=n.current,S="deltaX"in m?m.deltaX:b[0]-g[0],k="deltaY"in m?m.deltaY:b[1]-g[1],C,T=m.target,E=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&E==="h"&&T.type==="range")return!1;var N=Cu(E,T);if(!N)return!0;if(N?C=E:(C=E==="v"?"h":"v",N=Cu(E,T)),!N)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var _=r.current||C;return Wv(_,v,m,_==="h"?S:k)},[]),l=y.useCallback(function(m){var v=m;if(!(!br.length||br[br.length-1]!==s)){var g="deltaY"in v?Eu(v):ts(v),b=t.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&Vv(C.delta,g)})[0];if(b&&b.should){v.cancelable&&v.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Iu).filter(Boolean).filter(function(C){return C.contains(v.target)}),k=S.length>0?a(v,S[0]):!i.current.noIsolation;k&&v.cancelable&&v.preventDefault()}}},[]),c=y.useCallback(function(m,v,g,b){var S={name:m,delta:v,target:g,should:b,shadowParent:Yv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=y.useCallback(function(m){n.current=ts(m),r.current=void 0},[]),f=y.useCallback(function(m){c(m.type,Eu(m),m.target,a(m,e.lockRef.current))},[]),p=y.useCallback(function(m){c(m.type,ts(m),m.target,a(m,e.lockRef.current))},[]);y.useEffect(function(){return br.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,vr),document.addEventListener("touchmove",l,vr),document.addEventListener("touchstart",d,vr),function(){br=br.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,vr),document.removeEventListener("touchmove",l,vr),document.removeEventListener("touchstart",d,vr)}},[]);var h=e.removeScrollBar,x=e.inert;return y.createElement(y.Fragment,null,x?y.createElement(s,{styles:Kv(o)}):null,h?y.createElement(Lv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Yv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Xv=Tv(vu,Gv);var ns=y.forwardRef(function(e,t){return y.createElement(Qo,xn({},e,{ref:t,sideCar:Xv}))});ns.classNames=Qo.classNames;var Ui=["Enter"," "],Jv=["ArrowDown","PageUp","Home"],Nu=["ArrowUp","PageDown","End"],Zv=[...Jv,...Nu],Qv={ltr:[...Ui,"ArrowRight"],rtl:[...Ui,"ArrowLeft"]},eb={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Fr="Menu",[zr,tb,nb]=gi(Fr),[Yn,Au]=Tn(Fr,[nb,Ko,uu]),rs=Ko(),_u=uu(),[rb,Xn]=Yn(Fr),[ob,Br]=Yn(Fr),ju=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=y.useState(null),d=y.useRef(!1),f=_t(s),p=Po(o);return y.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",x,{capture:!0,once:!0}),document.addEventListener("pointermove",x,{capture:!0,once:!0})},x=()=>d.current=!1;return document.addEventListener("keydown",h,{capture:!0}),()=>{document.removeEventListener("keydown",h,{capture:!0}),document.removeEventListener("pointerdown",x,{capture:!0}),document.removeEventListener("pointermove",x,{capture:!0})}},[]),u.jsx(su,{...a,children:u.jsx(rb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(ob,{scope:t,onClose:y.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};ju.displayName=Fr;var sb="MenuAnchor",Wi=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(iu,{...o,...r,ref:t})});Wi.displayName=sb;var Vi="MenuPortal",[ib,Ru]=Yn(Vi,{forceMount:void 0}),Pu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(Vi,t);return u.jsx(ib,{scope:t,forceMount:n,children:u.jsx(Zt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};Pu.displayName=Vi;var Qt="MenuContent",[ab,Ki]=Yn(Qt),Ou=y.forwardRef((e,t)=>{const n=Ru(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Qt,e.__scopeMenu),i=Br(Qt,e.__scopeMenu);return u.jsx(zr.Provider,{scope:e.__scopeMenu,children:u.jsx(Zt,{present:r||s.open,children:u.jsx(zr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(lb,{...o,ref:t}):u.jsx(cb,{...o,ref:t})})})})}),lb=y.forwardRef((e,t)=>{const n=Xn(Qt,e.__scopeMenu),r=y.useRef(null),o=Ve(t,r);return y.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(qi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:me(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),cb=y.forwardRef((e,t)=>{const n=Xn(Qt,e.__scopeMenu);return u.jsx(qi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ub=Wn.createSlot("MenuContent.ScrollLock"),qi=y.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:x,...m}=e,v=Xn(Qt,n),g=Br(Qt,n),b=rs(n),S=_u(n),k=tb(n),[C,T]=y.useState(null),E=y.useRef(null),N=Ve(t,E,v.onContentChange),_=y.useRef(0),$=y.useRef(""),P=y.useRef(0),D=y.useRef(null),F=y.useRef("right"),A=y.useRef(0),z=x?ns:y.Fragment,j=x?{as:ub,allowPinchZoom:!0}:void 0,K=R=>{var J,L;const Y=$.current+R,X=k().filter(G=>!G.disabled),se=document.activeElement,be=(J=X.find(G=>G.ref.current===se))==null?void 0:J.textValue,Oe=X.map(G=>G.textValue),q=Sb(Oe,Y,be),H=(L=X.find(G=>G.textValue===q))==null?void 0:L.ref.current;(function G(Z){$.current=Z,window.clearTimeout(_.current),Z!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(Y),H&&setTimeout(()=>H.focus())};y.useEffect(()=>()=>window.clearTimeout(_.current),[]),vi();const B=y.useCallback(R=>{var X,se;return F.current===((X=D.current)==null?void 0:X.side)&&Tb(R,(se=D.current)==null?void 0:se.area)},[]);return u.jsx(ab,{scope:n,searchRef:$,onItemEnter:y.useCallback(R=>{B(R)&&R.preventDefault()},[B]),onItemLeave:y.useCallback(R=>{var Y;B(R)||((Y=E.current)==null||Y.focus(),T(null))},[B]),onTriggerLeave:y.useCallback(R=>{B(R)&&R.preventDefault()},[B]),pointerGraceTimerRef:P,onPointerGraceIntentChange:y.useCallback(R=>{D.current=R},[]),children:u.jsx(z,{...j,children:u.jsx(Mo,{asChild:!0,trapped:o,onMountAutoFocus:me(s,R=>{var Y;R.preventDefault(),(Y=E.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(uv,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:me(l,R=>{g.isUsingKeyboardRef.current||R.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(au,{role:"menu","aria-orientation":"vertical","data-state":Ju(v.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:N,style:{outline:"none",...m.style},onKeyDown:me(m.onKeyDown,R=>{const X=R.target.closest("[data-radix-menu-content]")===R.currentTarget,se=R.ctrlKey||R.altKey||R.metaKey,be=R.key.length===1;X&&(R.key==="Tab"&&R.preventDefault(),!se&&be&&K(R.key));const Oe=E.current;if(R.target!==Oe||!Zv.includes(R.key))return;R.preventDefault();const H=k().filter(J=>!J.disabled).map(J=>J.ref.current);Nu.includes(R.key)&&H.reverse(),bb(H)}),onBlur:me(e.onBlur,R=>{R.currentTarget.contains(R.target)||(window.clearTimeout(_.current),$.current="")}),onPointerMove:me(e.onPointerMove,Ur(R=>{const Y=R.target,X=A.current!==R.clientX;if(R.currentTarget.contains(Y)&&X){const se=R.clientX>A.current?"right":"left";F.current=se,A.current=R.clientX}}))})})})})})})});Ou.displayName=Qt;var db="MenuGroup",Gi=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(je.div,{role:"group",...r,ref:t})});Gi.displayName=db;var fb="MenuLabel",Mu=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(je.div,{...r,ref:t})});Mu.displayName=fb;var os="MenuItem",Du="menu.itemSelect",ss=y.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=y.useRef(null),i=Br(os,e.__scopeMenu),a=Ki(os,e.__scopeMenu),l=Ve(t,s),c=y.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Du,{bubbles:!0,cancelable:!0});f.addEventListener(Du,h=>r==null?void 0:r(h),{once:!0}),mc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Lu,{...o,ref:l,disabled:n,onClick:me(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:me(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:me(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Ui.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Lu=y.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ki(os,n),a=_u(n),l=y.useRef(null),c=Ve(t,l),[d,f]=y.useState(!1),[p,h]=y.useState("");return y.useEffect(()=>{const x=l.current;x&&h((x.textContent??"").trim())},[s.children]),u.jsx(zr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(dv,{asChild:!0,...a,focusable:!r,children:u.jsx(je.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:me(e.onPointerMove,Ur(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:me(e.onPointerLeave,Ur(x=>i.onItemLeave(x))),onFocus:me(e.onFocus,()=>f(!0)),onBlur:me(e.onBlur,()=>f(!1))})})})}),pb="MenuCheckboxItem",$u=y.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Uu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Xi(n),onSelect:me(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});$u.displayName=pb;var Fu="MenuRadioGroup",[hb,mb]=Yn(Fu,{value:void 0,onValueChange:()=>{}}),zu=y.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=_t(r);return u.jsx(hb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Gi,{...o,ref:t})})});zu.displayName=Fu;var Bu="MenuRadioItem",Hu=y.forwardRef((e,t)=>{const{value:n,...r}=e,o=mb(Bu,e.__scopeMenu),s=n===o.value;return u.jsx(Uu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Xi(s),onSelect:me(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Hu.displayName=Bu;var Yi="MenuItemIndicator",[Uu,gb]=Yn(Yi,{checked:!1}),Wu=y.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=gb(Yi,n);return u.jsx(Zt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(je.span,{...o,ref:t,"data-state":Xi(s.checked)})})});Wu.displayName=Yi;var xb="MenuSeparator",Vu=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(je.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Vu.displayName=xb;var yb="MenuArrow",Ku=y.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(lu,{...o,...r,ref:t})});Ku.displayName=yb;var vb="MenuSub",[kT,qu]=Yn(vb),Hr="MenuSubTrigger",Gu=y.forwardRef((e,t)=>{const n=Xn(Hr,e.__scopeMenu),r=Br(Hr,e.__scopeMenu),o=qu(Hr,e.__scopeMenu),s=Ki(Hr,e.__scopeMenu),i=y.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=y.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return y.useEffect(()=>d,[d]),y.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Wi,{asChild:!0,...c,children:u.jsx(Lu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Ju(n.open),...e,ref:mi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:me(e.onPointerMove,Ur(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:me(e.onPointerLeave,Ur(f=>{var h,x;d();const p=(h=n.content)==null?void 0:h.getBoundingClientRect();if(p){const m=(x=n.content)==null?void 0:x.dataset.side,v=m==="right",g=v?-5:5,b=p[v?"left":"right"],S=p[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+g,y:f.clientY},{x:b,y:p.top},{x:S,y:p.top},{x:S,y:p.bottom},{x:b,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:me(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||Qv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Gu.displayName=Hr;var Yu="MenuSubContent",Xu=y.forwardRef((e,t)=>{const n=Ru(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Qt,e.__scopeMenu),i=Br(Qt,e.__scopeMenu),a=qu(Yu,e.__scopeMenu),l=y.useRef(null),c=Ve(t,l);return u.jsx(zr.Provider,{scope:e.__scopeMenu,children:u.jsx(Zt,{present:r||s.open,children:u.jsx(zr.Slot,{scope:e.__scopeMenu,children:u.jsx(qi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:me(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:me(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:me(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=eb[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Xu.displayName=Yu;function Ju(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Xi(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function bb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function wb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Sb(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=wb(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Cb(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,d=a.y,f=l.x,p=l.y;d>r!=p>r&&n<(f-c)*(r-d)/(p-d)+c&&(o=!o)}return o}function Tb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Cb(n,t)}function Ur(e){return t=>t.pointerType==="mouse"?e(t):void 0}var kb=ju,Eb=Wi,Ib=Pu,Nb=Ou,Ab=Gi,_b=Mu,jb=ss,Rb=$u,Pb=zu,Ob=Hu,Mb=Wu,Db=Vu,Lb=Ku,$b=Gu,Fb=Xu,as="DropdownMenu",[zb,ET]=Tn(as,[Au]),$t=Au(),[Bb,Zu]=zb(as),Qu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=$t(t),c=y.useRef(null),[d,f]=fr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Bb,{scope:t,triggerId:kn(),triggerRef:c,contentId:kn(),open:d,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(kb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Qu.displayName=as;var ed="DropdownMenuTrigger",td=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Zu(ed,n),i=$t(n);return u.jsx(Eb,{asChild:!0,...i,children:u.jsx(je.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:mi(t,s.triggerRef),onPointerDown:me(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:me(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});td.displayName=ed;var Hb="DropdownMenuPortal",nd=e=>{const{__scopeDropdownMenu:t,...n}=e,r=$t(t);return u.jsx(Ib,{...r,...n})};nd.displayName=Hb;var rd="DropdownMenuContent",od=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Zu(rd,n),s=$t(n),i=y.useRef(!1);return u.jsx(Nb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:me(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:me(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});od.displayName=rd;var Ub="DropdownMenuGroup",Wb=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Ab,{...o,...r,ref:t})});Wb.displayName=Ub;var Vb="DropdownMenuLabel",sd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(_b,{...o,...r,ref:t})});sd.displayName=Vb;var Kb="DropdownMenuItem",id=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(jb,{...o,...r,ref:t})});id.displayName=Kb;var qb="DropdownMenuCheckboxItem",ad=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Rb,{...o,...r,ref:t})});ad.displayName=qb;var Gb="DropdownMenuRadioGroup",Yb=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Pb,{...o,...r,ref:t})});Yb.displayName=Gb;var Xb="DropdownMenuRadioItem",ld=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Ob,{...o,...r,ref:t})});ld.displayName=Xb;var Jb="DropdownMenuItemIndicator",cd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Mb,{...o,...r,ref:t})});cd.displayName=Jb;var Zb="DropdownMenuSeparator",ud=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Db,{...o,...r,ref:t})});ud.displayName=Zb;var Qb="DropdownMenuArrow",ew=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Lb,{...o,...r,ref:t})});ew.displayName=Qb;var tw="DropdownMenuSubTrigger",dd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx($b,{...o,...r,ref:t})});dd.displayName=tw;var nw="DropdownMenuSubContent",fd=y.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$t(n);return u.jsx(Fb,{...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)"}})});fd.displayName=nw;var rw=Qu,ow=td,sw=nd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd,vd=ud,bd=dd,wd=fd;const iw=rw,aw=ow,lw=y.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(bd,{ref:o,className:te("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(le.ChevronRight,{className:"ml-auto h-4 w-4"})]}));lw.displayName=bd.displayName;const cw=y.forwardRef(({className:e,...t},n)=>u.jsx(wd,{ref:n,className:te("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));cw.displayName=wd.displayName;const Sd=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(sw,{children:u.jsx(pd,{ref:r,sideOffset:t,className:te("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Sd.displayName=pd.displayName;const Ji=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(md,{ref:r,className:te("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ji.displayName=md.displayName;const uw=y.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(gd,{ref:o,className:te("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(yd,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),t]}));uw.displayName=gd.displayName;const dw=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xd,{ref:r,className:te("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(yd,{children:u.jsx(le.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));dw.displayName=xd.displayName;const fw=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(hd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));fw.displayName=hd.displayName;const pw=y.forwardRef(({className:e,...t},n)=>u.jsx(vd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));pw.displayName=vd.displayName;const ls=1e4;function hw(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,24 +83,24 @@ 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 uw(e,t=as){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 dw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),uw(t),cw(t)}const ls=0,On=1,br=2,Sd=4;function Cd(e){return()=>e}function fw(e){e()}function Td(e,t){return n=>e(t(n))}function kd(e,t){return()=>e(t)}function pw(e,t){return n=>e(t,n)}function Xi(e){return e!==void 0}function hw(...e){return()=>{e.map(fw)}}function wr(){}function cs(e,t){return t(e),e}function mw(e,t){return t(e)}function ut(...e){return e}function rt(e,t){return e(On,t)}function Me(e,t){e(ls,t)}function Ji(e){e(br)}function Tt(e){return e(Sd)}function xe(e,t){return rt(e,pw(t,ls))}function ln(e,t){const n=e(On,r=>{n(),t(r)});return n}function Ed(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Id(e,t){return e===t}function dt(e=Id){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ie(e){return t=>n=>{e(n)&&t(n)}}function de(e){return t=>Td(t,e)}function yn(e){return t=>()=>{t(e)}}function U(e,...t){const n=gw(...t);return(r,o)=>{switch(r){case br:Ji(e);return;case On:return rt(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Xn(e){return t=>n=>{e>0?e--:t(n)}}function Nn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...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);rt(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function gw(...e){return t=>e.reduceRight(mw,t)}function xw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case On:return s?n===s?void 0:(r(),n=s,t=rt(e,s),t):(r(),wr);case br:r(),n=null;return}}}function ee(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case ls:t=o;break;case On:{o(t);break}case Sd:return t}return n(r,o)}}function Mt(e,t){return cs(ee(t),n=>xe(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case ls:e.slice().forEach(r=>{r(n)});return;case br:e.splice(0,e.length);return;case On:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Kt(e){return cs(Ke(),t=>xe(e,t))}function Xe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:yw(),singleton:n}}const yw=()=>Symbol();function vw(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 kt(...e){const t=Ke(),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);rt(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case br:{Ji(t);return}case On:return r===o&&i(n),rt(t,i)}}}function Te(e,t=Id){return U(e,dt(t))}function Zi(...e){return function(t,n){switch(t){case br:return;case On:return hw(...e.map(r=>rt(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 bw={0:"debug",3:"error",1:"log",2:"warn"},ww=()=>typeof globalThis>"u"?window:globalThis,Mn=Xe(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=ww().VIRTUOSO_LOG_LEVEL)!=null?o:Tt(e);r>=s&&console[bw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Jn(e,t,n){return Qi(e,t,n).callbackRef}function Qi(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 Sw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Cw(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let x;h&&(x=p.ownerDocument.defaultView);const m=i?a?i.scrollLeft:i.scrollTop:h?a?x.scrollX||x.document.documentElement.scrollLeft:x.scrollY||x.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:h?a?x.document.documentElement.scrollWidth:x.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:h?a?x.innerWidth:x.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(m,0),viewportHeight:g}),s==null||s(a?Nd("column-gap",getComputedStyle(d).columnGap,o):Nd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Qi(c,n,l)}function Cw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ht.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Nd(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 Ad(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),x=c.top-h.top;p=h.height-Math.max(0,x),f=x+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Qi(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Ft=Xe(()=>{const e=Ke(),t=Ke(),n=ee(0),r=Ke(),o=ee(0),s=Ke(),i=Ke(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Ke(),p=Ke(),h=ee(!1),x=ee(!1),m=ee(!1);return xe(U(e,de(({scrollTop:v})=>v)),t),xe(U(e,de(({scrollHeight:v})=>v)),i),xe(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:x,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:m,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Ur={lvl:0};function jd(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===Ur}function Wr(e,t){if(!it(e))return t===e.k?e.v:t<e.k?Wr(e.l,t):Wr(e.r,t)}function cn(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=cn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return cn(e.l,t,n)}function qt(e,t,n){return it(e)?Pd(t,n,1):t===e.k?It(e,{k:t,v:n}):t<e.k?Od(It(e,{l:qt(e.l,t,n)})):Od(It(e,{r:qt(e.r,t,n)}))}function Sr(){return Ur}function us(e,t,n){if(it(e))return[];const r=cn(e,t)[0];return Tw(ta(e,r,n))}function ea(e,t){if(it(e))return Ur;const{k:n,l:r,r:o}=e;if(t===n){if(it(r))return o;if(it(o))return r;{const[s,i]=Rd(r);return ds(It(e,{k:s,l:_d(r),v:i}))}}else return t<n?ds(It(e,{l:ea(r,t)})):ds(It(e,{r:ea(o,t)}))}function Zn(e){return it(e)?[]:[...Zn(e.l),{k:e.k,v:e.v},...Zn(e.r)]}function ta(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(ta(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ta(s,t,n))),a}function ds(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(na(t))return Md(It(e,{lvl:n-1}));if(!it(t)&&!it(t.r))return It(t.r,{l:It(t,{r:t.r.l}),lvl:n,r:It(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(na(e))return ra(It(e,{lvl:n-1}));if(!it(r)&&!it(r.l)){const o=r.l,s=na(o)?r.lvl-1:r.lvl;return It(o,{l:It(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ra(It(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function It(e,t){return Pd(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 _d(e){return it(e.r)?e.l:ds(It(e,{r:_d(e.r)}))}function na(e){return it(e)||e.lvl>e.r.lvl}function Rd(e){return it(e.r)?[e.k,e.v]:Rd(e.r)}function Pd(e,t,n,r=Ur,o=Ur){return{k:e,l:r,lvl:n,r:o,v:t}}function Od(e){return ra(Md(e))}function Md(e){const{l:t}=e;return!it(t)&&t.lvl===e.lvl?It(t,{r:It(e,{l:t.r})}):e}function ra(e){const{lvl:t,r:n}=e;return!it(n)&&!it(n.r)&&n.lvl===t&&n.r.lvl===t?It(n,{l:It(e,{r:n.l}),lvl:t+1}):e}function Tw(e){return jd(e,({k:t,v:n})=>({index:t,value:n}))}function Dd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Vr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const oa=Xe(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Ld(e,t,n){return e[fs(e,t,n)]}function fs(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 kw(e,t,n,r){const o=fs(e,t,r),s=fs(e,n,r,o);return e.slice(o,s+1)}function Dn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ps(e){return!it(e.groupOffsetTree)}function sa({index:e},t){return t===e?0:t<e?-1:1}function Ew(){return{groupIndices:[],groupOffsetTree:Sr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Sr()}}function Iw(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=qt(e,0,s);continue}const a=us(e,i-1,o+1);if(a.some(Ow(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ea(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=qt(e,o+1,p));c&&(e=qt(e,i,s))}return[e,n]}function Nw(e){return typeof e.groupIndex<"u"}function Aw({offset:e},t){return t===e?0:t<e?-1:1}function Kr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Ld(t,e,sa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function $d(e,t){if(!ps(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Fd(e,t,n){if(Nw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=$d(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function jw(e,t,n,r=0){return r>0&&(t=Math.max(t,Ld(e,r,sa).offset)),jd(kw(e,t,n,Aw),Pw)}function _w(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&&it(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((x,m)=>qt(qt(x,m,p),m+1,h),i)}else[i,a]=Iw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=ia(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>qt(p,h,Kr(h,f,o)),Sr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Rw(e){return Zn(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 zd(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 ia(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=fs(o,t-1,sa),a=o[l].offset;const c=cn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===cn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of us(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Pw(e){return{index:e.index,value:e}}function Ow(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 Mw={offsetHeight:"height",offsetWidth:"width"},bn=Xe(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=Mt(r,0),s=Ke(),i=Ke(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Dn(C,Mw[T])),p=ee(void 0),h=ee(0),x=Ew(),m=Mt(U(n,$e(l,e,h),vn(_w,x),dt()),x),v=Mt(U(l,dt(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),de(({prev:C})=>C)),[]);xe(U(l,Ie(C=>C.length>0),$e(m,h),de(([C,T,E])=>{const N=C.reduce((j,$,P)=>qt(j,$,Kr($,T.offsetTree,E)||P),Sr());return{...T,groupIndices:C,groupOffsetTree:N}})),m),xe(U(r,$e(m),Ie(([C,{lastIndex:T}])=>C<T),de(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),xe(c,d);const g=Mt(U(c,de(C=>C===void 0)),!0);xe(U(d,Ie(C=>C!==void 0&&it(Tt(m).sizeTree)),de(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Kt(U(n,$e(m),vn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:x}),de(C=>C.changed)));rt(U(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),de(C=>C.diff)),C=>{const{groupIndices:T}=Tt(m);if(C>0)Me(t,!0),Me(s,C+zd(C,T));else if(C<0){const E=Tt(v);E.length>0&&(C-=zd(-C,E)),Me(i,C)}}),rt(U(a,$e(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Ht.ERROR)});const S=Kt(s);xe(U(s,$e(m),de(([C,T])=>{const E=T.groupIndices.length>0,N=[],j=T.lastSize;if(E){const $=Wr(T.sizeTree,0);let P=0,D=0;for(;P<C;){const A=T.groupIndices[D],z=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-A-1;N.push({endIndex:A,size:$,startIndex:A}),N.push({endIndex:A+1+z-1,size:j,startIndex:A+1}),D++,P+=z+1}const F=Zn(T.sizeTree);return P!==C&&F.shift(),F.reduce((A,{k:z,v:_})=>{let K=A.ranges;return A.prevSize!==0&&(K=[...A.ranges,{endIndex:z+C-1,size:A.prevSize,startIndex:A.prevIndex}]),{prevIndex:z+C,prevSize:_,ranges:K}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Zn(T.sizeTree).reduce(($,{k:P,v:D})=>({prevIndex:P+C,prevSize:D,ranges:[...$.ranges,{endIndex:P+C-1,size:$.prevSize,startIndex:$.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const k=Kt(U(i,$e(m,h),de(([C,{offsetTree:T},E])=>{const N=-C;return Kr(N,T,E)})));return xe(U(i,$e(m,h),de(([C,T,E])=>{if(T.groupIndices.length>0){if(it(T.sizeTree))return T;let N=Sr();const j=Tt(v);let $=0,P=0,D=0;for(;$<-C;){D=j[P];const F=j[P+1]-D-1;P++,$+=F+1}if(N=Zn(T.sizeTree).reduce((F,{k:A,v:z})=>qt(F,Math.max(0,A+C),z),N),$!==-C){const F=Wr(T.sizeTree,D);N=qt(N,0,F);const A=cn(T.sizeTree,-C+1)[1];N=qt(N,1,A)}return{...T,sizeTree:N,...ia(T.offsetTree,0,N,E)}}else{const N=Zn(T.sizeTree).reduce((j,{k:$,v:P})=>qt(j,Math.max(0,$+C),P),Sr());return{...T,sizeTree:N,...ia(T.offsetTree,0,N,E)}}})),m),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},ut(Mn,oa),{singleton:!0});function Dw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Bd=Xe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Kt(U(s,de(Dw)));return xe(U(a,de(l=>l.totalCount)),n),xe(U(a,de(l=>l.groupIndices)),e),xe(U(kt(o,t,r),Ie(([l,c])=>ps(c)),de(([l,c,d])=>cn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),dt(),de(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ut(bn,Ft)),Ln=Xe(([{log:e}])=>{const t=ee(!1),n=Kt(U(t,Ie(r=>r),dt()));return rt(t,r=>{r&&Tt(e)("props updated",{},Ht.DEBUG)}),{didMount:n,propsReady:t}},ut(Mn),{singleton:!0}),Lw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Hd(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Lw)&&(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:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=Ke(),x=Ke(),m=ee(0);let v=null,g=null,b=null;function S(){v&&(v(),v=null),b&&(b(),b=null),g&&(clearTimeout(g),g=null),Me(l,!1)}return xe(U(h,$e(n,f,r,m,a,i,p),$e(e,s,o),de(([[k,C,T,E,N,j,$,P],D,F,A])=>{const z=Hd(k),{align:_,behavior:K,offset:B}=z,R=E-1,Y=Fd(z,C,R);let X=Kr(Y,C.offsetTree,D)+j;_==="end"?(X+=F+cn(C.sizeTree,Y)[1]-T+A,Y===R&&(X+=$)):_==="center"?X+=(F+cn(C.sizeTree,Y)[1]-T+A)/2:X-=N,B&&(X+=B);const se=ve=>{S(),ve?(P("retrying to scroll to",{location:k},Ht.DEBUG),Me(h,k)):(Me(x,!0),P("list did not change, scroll successful",{},Ht.DEBUG))};if(S(),K==="smooth"){let ve=!1;b=rt(t,Oe=>{ve=ve||Oe}),v=ln(d,()=>{se(ve)})}else v=ln(U(t,$w(150)),se);return g=setTimeout(()=>{S()},1200),Me(l,!0),P("scrolling from index to",{behavior:K,index:Y,top:X},Ht.DEBUG),{behavior:K,top:X}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},ut(bn,Ft,Mn),{singleton:!0});function $w(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function aa(e,t){e==0?t():requestAnimationFrame(()=>{aa(e-1,t)})}function la(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Gr=Xe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return xe(U(i,$e(l),Ie(([d,f])=>!!f),yn(!1)),a),xe(U(i,$e(l),Ie(([d,f])=>!!f),yn(!1)),c),rt(U(kt(t,i),$e(a,n,e,c),Ie(([[,d],f,{sizeTree:p},h,x])=>d&&(!it(p)||Xi(h))&&!f&&!x),$e(l)),([,d])=>{ln(o,()=>{Me(c,!0)}),aa(4,()=>{ln(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ut(bn,Ft,qr,Ln),{singleton:!0});function Ud(e,t){return Math.abs(e-t)<1.01}const Yr="up",Xr="down",Fw="none",zw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Bw=0,Jr=Xe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Ke(),c=Ke(),d=ee(4),f=ee(Bw),p=Mt(U(Zi(U(Te(o),Xn(1),yn(!0)),U(Te(o),Xn(1),yn(!1),Ed(100))),dt()),!1),h=Mt(U(Zi(U(n,yn(!0)),U(n,yn(!1),Ed(200))),dt()),!1);xe(U(kt(Te(o),Te(f)),de(([b,S])=>b<=S),dt()),a),xe(U(a,Nn(50)),c);const x=Kt(U(kt(r,Te(s),Te(t),Te(e),Te(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,E,N])=>{const j=k+C-S>-N,$={scrollHeight:S,scrollTop:k,viewportHeight:C};if(j){let D,F;return k>b.state.scrollTop?(D="SCROLLED_DOWN",F=b.state.scrollTop-k):(D="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:F,state:$}}let P;return $.scrollHeight>b.state.scrollHeight?P="SIZE_INCREASED":C<b.state.viewportHeight?P="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?P="SCROLLING_UPWARDS":P="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:P,state:$}},zw),dt((b,S)=>b&&b.atBottom===S.atBottom))),m=Mt(U(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Ud(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ie(b=>b.changed),de(b=>b.jump)),0);xe(U(x,de(b=>b.atBottom)),i),xe(U(i,Nn(50)),l);const v=ee(Xr);xe(U(r,de(({scrollTop:b})=>b),dt(),vn((b,S)=>Tt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Yr:Xr,prevScrollTop:S},{direction:Xr,prevScrollTop:0}),de(b=>b.direction)),v),xe(U(r,Nn(50),yn(Fw)),v);const g=ee(0);return xe(U(p,Ie(b=>!b),yn(0)),g),xe(U(o,Nn(100),$e(p),Ie(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),de(([b,S])=>S-b)),g),{atBottomState:x,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:v,scrollVelocity:g}},ut(Ft)),hs="top",ms="bottom",Wd="none";function Vd(e,t,n){return typeof e=="number"?n===Yr&&t===hs||n===Xr&&t===ms?e:0:n===Yr?t===hs?e.main:e.reverse:t===ms?e.main:e.reverse}function Kd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ca=Xe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=ee(0),a=ee(0),l=ee(0),c=Mt(U(kt(Te(r),Te(o),Te(n),Te(s,Vr),Te(l),Te(i),Te(t),Te(e),Te(a)),de(([d,f,p,[h,x],m,v,g,b,S])=>{const k=d-b,C=v+g,T=Math.max(p-k,0);let E=Wd;const N=Kd(S,hs),j=Kd(S,ms);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-N&&(E=Yr),x<d-T+f+j&&(E=Xr),E!==Wd?[Math.max(k-p-Vd(m,hs,E)-N,0),k-T-g+f+Vd(m,ms,E)+j]:null}),Ie(d=>d!=null),dt(Vr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ut(Ft),{singleton:!0});function Hw(e,t,n){if(ps(t)){const r=$d(e,t);return[{index:cn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const ua={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function gs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const m=e[e.length-1];d=m.offset+m.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,x=p-d;return{bottom:d,firstItemIndex:s,items:Gd(e,o,s),offsetBottom:x,offsetTop:c,top:h,topItems:Gd(t,o,s),topListHeight:t.reduce((m,v)=>v.size+m,0),totalCount:n}}function qd(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=la(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return gs(c,[],a,o,n,r)}function Gd(e,t,n){if(e.length===0)return[];if(!ps(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=us(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Qn=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:x}])=>{const m=ee([]),v=ee(0),g=Ke();xe(s.topItemsIndexes,m);const b=Mt(U(kt(h,x,Te(l,Vr),Te(o),Te(r),Te(c),d,Te(m),Te(t),Te(n),e),Ie(([T,E,,N,,,,,,,j])=>{const $=j&&j.length!==N;return T&&!E&&!$}),de(([,,[T,E],N,j,$,P,D,F,A,z])=>{const _=j,{offsetTree:K,sizeTree:B}=_,R=Tt(v);if(N===0)return{...ua,totalCount:N};if(T===0&&E===0)return R===0?{...ua,totalCount:N}:qd(R,$,j,F,A,z||[]);if(it(B))return R>0?null:gs(Hw(la($,N),_,z),[],N,A,_,F);const Y=[];if(D.length>0){const q=D[0],H=D[D.length-1];let J=0;for(const L of us(B,q,H)){const G=L.value,Z=Math.max(L.start,q),fe=Math.min(L.end,H);for(let re=Z;re<=fe;re++)Y.push({data:z==null?void 0:z[re],index:re,offset:J,size:G}),J+=G}}if(!P)return gs([],Y,N,A,_,F);const X=D.length>0?D[D.length-1]+1:0,se=jw(K,T,E,X);if(se.length===0)return null;const ve=N-1,Oe=cs([],q=>{for(const H of se){const J=H.value;let L=J.offset,G=H.start;const Z=J.size;if(J.offset<T){G+=Math.floor((T-J.offset+A)/(Z+A));const re=G-H.start;L+=re*Z+re*A}G<X&&(L+=(X-G)*Z,G=X);const fe=Math.min(H.end,ve);for(let re=G;re<=fe&&!(L>=E);re++)q.push({data:z==null?void 0:z[re],index:re,offset:L,size:Z}),L+=Z+A}});return gs(Oe,Y,N,A,_,F)}),Ie(T=>T!==null),dt()),ua);xe(U(e,Ie(Xi),de(T=>T==null?void 0:T.length)),o),xe(U(b,de(T=>T.topListHeight)),f),xe(f,a),xe(U(b,de(T=>[T.top,T.bottom])),i),xe(U(b,de(T=>T.items)),g);const S=Kt(U(b,Ie(({items:T})=>T.length>0),$e(o,e),Ie(([{items:T},E])=>T[T.length-1].originalIndex===E-1),de(([,T,E])=>[T-1,E]),dt(Vr),de(([T])=>T))),k=Kt(U(b,Nn(200),Ie(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),de(({items:T})=>T[0].index),dt())),C=Kt(U(b,Ie(({items:T})=>T.length>0),de(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),dt(Dd)));return{endReached:S,initialItemCount:v,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},ut(bn,Bd,ca,Gr,qr,Jr,Ln,oa),{singleton:!0}),Yd=Xe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=Mt(U(kt(n,e,r,t,o),de(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return xe(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ut(Ft,Qn),{singleton:!0}),Uw=Xe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Mt(U(kt(n,e,t),Ie(([o])=>o),de(([,o,s])=>Math.max(0,o-s)),Nn(0),dt()),0);return{alignToBottom:n,paddingTopAddition:r}},ut(Ft,Yd),{singleton:!0}),Xd=Xe(()=>({context:ee(null)})),Ww=({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,Jd=Xe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ke();return xe(U(d,$e(t,l,n,s,o,r,a),$e(e),de(([[f,p,h,x,m,v,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Ww,done:E,...N}=f,j=Fd(f,p,x-1),$=Kr(j,p.offsetTree,S)+m+v,P=$+cn(p.sizeTree,j)[1],D=b+v,F=b+h-g,A=T({itemBottom:P,itemTop:$,locationParams:{align:k,behavior:C,...N},viewportBottom:F,viewportTop:D});return A?E&&ln(U(i,Ie(z=>!z),Xn(Tt(i)?1:2)),E):E&&E(),A}),Ie(f=>f!==null)),c),{scrollIntoView:d}},ut(bn,Ft,qr,Qn,Mn),{singleton:!0});function Zd(e){return e?e==="smooth"?"smooth":"auto":!1}const Vw=(e,t)=>typeof e=="function"?Zd(e(t)):t&&Zd(e),Kw=Xe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const x=ee(!1),m=Ke();let v=null;function g(C){Me(i,{align:"end",behavior:C,index:"LAST"})}rt(U(kt(U(Te(t),Xn(1)),l),$e(Te(x),s,a,f),de(([[C,T],E,N,j,$])=>{let P=T&&j,D="auto";return P&&(D=Vw(E,N||$),P=P&&!!D),{followOutputBehavior:D,shouldFollow:P,totalCount:C}}),Ie(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{v&&(v(),v=null),Tt(n)?requestAnimationFrame(()=>{Tt(d)("following output to ",{totalCount:T},Ht.DEBUG),g(C)}):v=ln(e,()=>{Tt(d)("following output to ",{totalCount:T},Ht.DEBUG),g(C),v=null})});function b(C){const T=ln(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(Tt(d)("scrolling to bottom due to increased size",{},Ht.DEBUG),g("auto"))});setTimeout(T,100)}rt(U(kt(Te(x),t,c),Ie(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ie(({refreshed:C})=>C),$e(x,t)),([,C])=>{Tt(a)&&b(C!==!1)}),rt(m,()=>{b(Tt(x)!==!1)}),rt(kt(Te(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=Ke();return xe(Zi(U(Te(r),de(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),U(Te(t))),k),rt(U(kt(U(k,Xn(1)),l),$e(Te(S),a,f,p),de(([[C,T],E,N,j,$])=>T&&N&&(E==null?void 0:E({context:$,totalCount:C,scrollingInProgress:j}))),Ie(C=>!!C),Nn(0)),C=>{v&&(v(),v=null),Tt(n)?requestAnimationFrame(()=>{Tt(d)("scrolling into view",{}),Me(h,C)}):v=ln(e,()=>{Tt(d)("scrolling into view",{}),Me(h,C),v=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},ut(bn,Jr,qr,Gr,Ln,Mn,Ft,Xd,Jd)),qw=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(xe(U(a,$e(s),Ie(([,l])=>l!==0),$e(o,r,t,n,e),de(([[,l],c,d,f,p,h=[]])=>qd(l,c,d,f,p,h))),i),{}),ut(bn,Gr,Qn,Ln),{singleton:!0}),Gw=Xe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return rt(U(e,$e(r),Ie(([,o])=>o!==0),de(([,o])=>({top:o}))),o=>{ln(U(n,Xn(1),Ie(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},ut(Ln,Ft,Qn),{singleton:!0}),Qd=Xe(([{scrollVelocity:e}])=>{const t=ee(!1),n=Ke(),r=ee(!1);return xe(U(e,$e(r,t,n),Ie(([o,s])=>!!s),de(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),dt()),t),rt(U(kt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ut(Jr),{singleton:!0}),da=Xe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=ee(!1),i=ee(void 0);return xe(U(kt(n,r),de(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),xe(U(t,$e(r),de(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ut(Ft)),Yw=Xe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ke(),d=ee(void 0),f=ee(null),p=ee(null);return xe(a,f),xe(l,p),rt(U(c,$e(t,r,i,f,p,n)),([h,x,m,v,g,b,S])=>{const k=Rw(x.sizeTree);v&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),xe(U(d,Ie(Xi),de(Xw)),o),xe(U(s,$e(d),Ie(([,h])=>h!==void 0),dt(),de(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},ut(bn,Ft,Gr,Ln,da));function Xw(e){return{align:"start",index:0,offset:e.scrollTop}}const Jw=Xe(([{topItemsIndexes:e}])=>{const t=ee(0);return xe(U(t,Ie(n=>n>=0),de(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ut(Qn));function ef(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Zw=ef(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Qw=Xe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:x}])=>{const m=Kt(U(l,$e(i),vn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:E},N])=>{const j=k+T;let $=0;return b===E&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||($=j-S,$!==0&&($+=N))),[$,C,E,j]},[0,[],0,0]),Ie(([g])=>g!==0),$e(r,a,n,o,h,x),Ie(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Yr),de(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Ht.DEBUG),g))));function v(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return rt(U(m,$e(e,s)),([g,b,S])=>{S&&Zw()?Me(e,b-g):v(-g)}),rt(U(kt(Mt(s,!1),e,x),Ie(([g,b,S])=>!g&&!S&&b!==0),de(([g,b])=>b),Nn(1)),v),xe(U(f,de(g=>({top:-g}))),t),rt(U(c,$e(p,d),de(([g,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(g);{let E=0;const N=Wr(k,0);let j=0,$=0;for(;j<g;){j++,E+=N;let P=b.length===$+1?1/0:b[$+1]-b[$]-1;j+P>g&&(E-=N,P=g-j+1),j+=P,E+=T(P),$++}return E}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(x,!1)})})}),{deviation:e}},ut(Ft,Jr,Qn,bn,Mn,oa)),e0=Xe(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ut(ca,qw,Ln,Qd,Yd,Gw,Uw,da,Jd,Mn,Xd)),tf=Xe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x},m,v,g,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},j])=>(xe(k.rangeChanged,j.scrollSeekRangeChanged),xe(U(j.windowViewportRect,de($=>$.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,...j,...m,sizes:l,...v}),ut(bn,Gr,Ft,Yw,Kw,Qn,qr,Qw,Jw,Bd,e0));function t0(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 xs=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,g){v.propsReady&&Me(v.propsReady,!1);for(const b of r){const S=v[t.required[b]];Me(S,g[b])}for(const b of o)if(b in g){const S=v[t.optional[b]];Me(S,g[b])}v.propsReady&&Me(v.propsReady,!0)}function c(v){return s.reduce((g,b)=>(g[b]=S=>{const k=v[t.methods[b]];Me(k,S)},g),{})}function d(v){return i.reduce((g,b)=>(g[b]=xw(v[t.events[b]]),g),{})}const f=w.forwardRef((v,g)=>{const{children:b,...S}=v,[k]=w.useState(()=>cs(vw(e),E=>{l(E,S)})),[C]=w.useState(kd(d,k));xs(()=>{for(const E of i)E in S&&rt(C[E],S[E]);return()=>{Object.values(C).map(Ji)}},[S,C,k]),xs(()=>{l(k,S)}),w.useImperativeHandle(g,Cd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...t0([...r,...o,...i],S),children:b}):b})}),p=v=>{const g=w.useContext(a);return w.useCallback(b=>{Me(g[v],b)},[g,v])},h=v=>{const g=w.useContext(a)[v],b=w.useCallback(S=>rt(g,S),[g]);return w.useSyncExternalStore(b,()=>Tt(g),()=>Tt(g))},x=v=>{const g=w.useContext(a)[v],[b,S]=w.useState(kd(Tt,g));return xs(()=>rt(g,k=>{k!==b&&S(Cd(k))}),[g,b]),b},m=w.version.startsWith("18")?h:x;return{Component:f,useEmitter:(v,g)=>{const b=w.useContext(a)[v];xs(()=>rt(b,g),[g,b])},useEmitterValue:m,usePublisher:p}}const rf=w.createContext(void 0),of=w.createContext(void 0),sf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function fa(e){return"self"in e}function n0(e){return"body"in e}function af(e,t,n,r=wr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,x,m;const v=p.target;if(n0(v)||fa(v)){const b=fa(v)?v:v.defaultView;m=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,x=s?b.innerWidth:b.innerHeight}else m=s?v.scrollLeft:v.scrollTop,h=s?v.scrollWidth:v.scrollHeight,x=s?v.offsetWidth:v.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:x})};p.suppressFlushSync?g():Ks.flushSync(g),a.current!==null&&(m===a.current||m<=0||m===h-x)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const x=p.behavior==="smooth";let m,v,g;fa(h)?(v=Math.max(Dn(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),m=s?h.innerWidth:h.innerHeight,g=s?window.scrollX:window.scrollY):(v=h[s?"scrollWidth":"scrollHeight"],m=Dn(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const b=v-m;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Ud(m,v)||p.top===g){e({scrollHeight:v,scrollTop:g,viewportHeight:m}),x&&t(!0);return}x?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const pa="-webkit-sticky",lf="sticky",ha=ef(()=>{if(typeof document>"u")return lf;const e=document.createElement("div");return e.style.position=pa,e.style.position===pa?pa:lf});function ma(e){return e}const r0=Xe(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ma),o=ee("div"),s=ee(wr),i=(a,l=null)=>Mt(U(n,de(c=>c[a]),dt()),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")}}),o0=Xe(([e,t])=>({...e,...t}),ut(tf,r0)),s0=({height:e})=>u.jsx("div",{style:{height:e}}),i0={overflowAnchor:"none",position:ha(),zIndex:1},cf={overflowAnchor:"none"},a0={...cf,display:"inline-block",height:"100%"},uf=w.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=Qt("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=Qt("windowScrollContainerState"),i=Qt("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),c=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),p=Ne("itemSize"),h=Ne("log"),x=Qt("gap"),m=Ne("horizontalDirection"),{callbackRef:v}=Sw(n,p,f,e?wr:a,h,x,o,m,Ne("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);ga("deviation",A=>{g!==A&&b(A)});const S=Ne("EmptyPlaceholder"),k=Ne("ScrollSeekPlaceholder")||s0,C=Ne("ListComponent"),T=Ne("ItemComponent"),E=Ne("GroupComponent"),N=Ne("computeItemKey"),j=Ne("isSeeking"),$=Ne("groupIndices").length>0,P=Ne("alignToBottom"),D=Ne("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:g!==0?g:P?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:P?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Dt(S,c)}):u.jsx(C,{...Dt(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:F,children:(e?t.topItems:t.items).map(A=>{const z=A.originalIndex,_=N(z+t.firstItemIndex,A.data,c);return j?w.createElement(k,{...Dt(k,c),height:A.size,index:A.index,key:_,type:A.type||"item",...A.type==="group"?{}:{groupIndex:A.groupIndex}}):A.type==="group"?w.createElement(E,{...Dt(E,c),"data-index":z,"data-item-index":A.index,"data-known-size":A.size,key:_,style:i0},d(A.index,c)):w.createElement(T,{...Dt(T,c),...d0(T,A.data),"data-index":z,"data-item-group-index":A.groupIndex,"data-item-index":A.index,"data-known-size":A.size,key:_,style:m?a0:cf},$?l(A.index,A.groupIndex,A.data,c):l(A.index,A.data,c))})})}),l0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},c0={outline:"none",overflowX:"auto",position:"relative"},ys=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),u0={position:ha(),top:0,width:"100%",zIndex:1};function Dt(e,t){if(typeof e!="string")return{context:t}}function d0(e,t){return{item:typeof e=="string"?void 0:t}}const f0=w.memo(function(){const e=Ne("HeaderComponent"),t=Qt("headerHeight"),n=Ne("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Dt(e,o)})}):null}),p0=w.memo(function(){const e=Ne("FooterComponent"),t=Qt("footerHeight"),n=Ne("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.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"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:x}=af(a,c,l,d,void 0,f);return e("scrollTo",x),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?c0:l0,...o},tabIndex:0,...i,...Dt(l,s),children:r})})}function ff({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=w.useRef(null),x=t("scrollerRef"),{scrollByCallback:m,scrollerRef:v,scrollToCallback:g}=af(a,c,l,x,p);return sf(()=>{var b;return v.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{v.current=null}},[v,p]),e("windowScrollTo",g),e("scrollBy",m),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Dt(l,s),children:r})})}const h0=({children:e})=>{const t=w.useContext(rf),n=Qt("viewportHeight"),r=Qt("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=w.useMemo(()=>Td(n,l=>Dn(l,s?"width":"height")),[n,s]),a=Jn(i,!0,Ne("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:ys(o),children:e})},m0=({children:e})=>{const t=w.useContext(rf),n=Qt("windowViewportRect"),r=Qt("fixedItemHeight"),o=Ne("customScrollParent"),s=Ad(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:ys(i),children:e})},g0=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...u0,marginTop:`${n}px`},o=Ne("context");return u.jsx(t,{style:r,...Dt(t,o),children:e})},x0=w.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return u.jsxs(r||t?b0:v0,{...e,context:o,children:[n&&u.jsx(g0,{children:u.jsx(uf,{showTopList:!0})}),u.jsxs(r||t?m0:h0,{children:[u.jsx(f0,{}),u.jsx(uf,{}),u.jsx(p0,{})]})]})}),{Component:y0,useEmitter:ga,useEmitterValue:Ne,usePublisher:Qt}=nf(o0,{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"}},x0),v0=df({useEmitter:ga,useEmitterValue:Ne,usePublisher:Qt}),b0=ff({useEmitter:ga,useEmitterValue:Ne,usePublisher:Qt}),w0=y0;ut(tf,Xe(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(ma),a=ee(wr),l=(c,d=null)=>Mt(U(s,de(f=>f[c]),dt()),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")}})),ha();const pf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},S0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:hf,floor:vs,max:Zr,min:xa,round:mf}=Math;function gf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function C0(e){return{...S0,items:e}}function bs(e,t){return e&&e.width===t.width&&e.height===t.height}function T0(e,t){return e&&e.column===t.column&&e.row===t.row}const k0=Xe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:x,propsReady:m},{customScrollParent:v,useWindowScroll:g,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),E=ee(0),N=ee(pf),j=ee({height:0,width:0}),$=ee({height:0,width:0}),P=Ke(),D=Ke(),F=ee(0),A=ee(null),z=ee({column:0,row:0}),_=Ke(),K=Ke(),B=ee(!1),R=ee(0),Y=ee(!0),X=ee(!1),se=ee(!1);rt(U(x,$e(R),Ie(([L,G])=>!!G)),()=>{Me(Y,!1)}),rt(U(kt(x,Y,$,j,R,X),Ie(([L,G,Z,fe,,re])=>L&&!G&&Z.height!==0&&fe.height!==0&&!re)),([,,,,L])=>{Me(X,!0),aa(1,()=>{Me(P,L)}),ln(U(c),()=>{Me(t,[0,0]),Me(Y,!0)})}),xe(U(K,Ie(L=>L!=null&&L.scrollTop>0),yn(0)),E),rt(U(x,$e(K),Ie(([,L])=>L!=null)),([,L])=>{L&&(Me(j,L.viewport),Me($,L.item),Me(z,L.gap),L.scrollTop>0&&(Me(B,!0),ln(U(c,Xn(1)),G=>{Me(B,!1)}),Me(l,{top:L.scrollTop})))}),xe(U(j,de(({height:L})=>L)),f),xe(U(kt(Te(j,bs),Te($,bs),Te(z,(L,G)=>L&&L.column===G.column&&L.row===G.row),Te(c)),de(([L,G,Z,fe])=>({gap:Z,item:G,scrollTop:fe,viewport:L}))),_),xe(U(kt(Te(T),r,Te(z,T0),Te($,bs),Te(j,bs),Te(A),Te(E),Te(B),Te(Y),Te(R)),Ie(([,,,,,,,L])=>!L),de(([L,[G,Z],fe,re,Ae,qe,Fe,,Je,ie])=>{const{column:be,row:je}=fe,{height:De,width:Ue}=re,{width:Ge}=Ae;if(Fe===0&&(L===0||Ge===0))return pf;if(Ue===0){const yt=la(ie,L),Nt=yt+Math.max(Fe-1,0);return C0(gf(yt,Nt,qe))}const ze=xf(Ge,Ue,be);let He,Qe;Je?G===0&&Z===0&&Fe>0?(He=0,Qe=Fe-1):(He=ze*vs((G+je)/(De+je)),Qe=ze*hf((Z+je)/(De+je))-1,Qe=xa(L-1,Zr(Qe,ze-1)),He=xa(Qe,Zr(0,He))):(He=0,Qe=-1);const Et=gf(He,Qe,qe),{bottom:xt,top:lt}=yf(Ae,fe,re,Et),ft=hf(L/ze),pt=ft*De+(ft-1)*je-xt;return{bottom:xt,itemHeight:De,items:Et,itemWidth:Ue,offsetBottom:pt,offsetTop:lt,top:lt}})),N),xe(U(A,Ie(L=>L!==null),de(L=>L.length)),T),xe(U(kt(j,$,N,z),Ie(([L,G,{items:Z}])=>Z.length>0&&G.height!==0&&L.height!==0),de(([L,G,{items:Z},fe])=>{const{bottom:re,top:Ae}=yf(L,fe,G,Z);return[Ae,re]}),dt(Vr)),t);const ve=ee(!1);xe(U(c,$e(ve),de(([L,G])=>G||L!==0)),ve);const Oe=Kt(U(kt(N,T),Ie(([{items:L}])=>L.length>0),$e(ve),Ie(([[L,G],Z])=>{const fe=L.items[L.items.length-1].index===G-1;return(Z||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===G)&&fe}),de(([[,L]])=>L-1),dt())),q=Kt(U(Te(N),Ie(({items:L})=>L.length>0&&L[0].index===0),yn(0),dt())),H=Kt(U(Te(N),$e(B),Ie(([{items:L},G])=>L.length>0&&!G),de(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),dt(Dd),Nn(0)));xe(H,h.scrollSeekRangeChanged),xe(U(P,$e(j,$,T,z),de(([L,G,Z,fe,re])=>{const Ae=Hd(L),{align:qe,behavior:Fe,offset:Je}=Ae;let ie=Ae.index;ie==="LAST"&&(ie=fe-1),ie=Zr(0,ie,xa(fe-1,ie));let be=ya(G,re,Z,ie);return qe==="end"?be=mf(be-G.height+Z.height):qe==="center"&&(be=mf(be-G.height/2+Z.height/2)),Je&&(be+=Je),{behavior:Fe,top:be}})),l);const J=Mt(U(N,de(L=>L.offsetBottom+L.bottom)),0);return xe(U(k,de(L=>({height:L.visibleHeight,width:L.visibleWidth}))),j),{customScrollParent:v,data:A,deviation:F,footerHeight:o,gap:z,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:$,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:P,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:N,horizontalDirection:se,initialTopMostItemIndex:R,totalListHeight:J,...p,endReached:Oe,propsReady:m,rangeChanged:H,startReached:q,stateChanged:_,stateRestoreInProgress:B,...C}},ut(ca,Ft,Jr,Qd,Ln,da,Mn));function xf(e,t,n){return Zr(1,vs((e+n)/(vs(t)+n)))}function yf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ya(e,t,n,r[0].index);return{bottom:ya(e,t,n,r[r.length-1].index)+o,top:s}}function ya(e,t,n,r){const o=xf(e.width,n.width,t.column),s=vs(r/o),i=s*n.height+Zr(0,s-1)*t.row;return i>0?i+t.row:i}const E0=Xe(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ma),i=ee("div"),a=ee(wr),l=(f,p=null)=>Mt(U(t,de(h=>h[f]),dt()),p),c=ee(!1),d=ee(!1);return xe(Te(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),I0=Xe(([e,t])=>({...e,...t}),ut(k0,E0)),N0=w.memo(function(){const e=gt("gridState"),t=gt("listClassName"),n=gt("itemClassName"),r=gt("itemContent"),o=gt("computeItemKey"),s=gt("isSeeking"),i=en("scrollHeight"),a=gt("ItemComponent"),l=gt("ListComponent"),c=gt("ScrollSeekPlaceholder"),d=gt("context"),f=en("itemDimensions"),p=en("gap"),h=gt("log"),x=gt("stateRestoreInProgress"),m=en("reportReadyState"),v=Jn(w.useMemo(()=>g=>{const b=g.parentElement.parentElement.scrollHeight;i(b);const S=g.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:bf("column-gap",getComputedStyle(g).columnGap,h),row:bf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return sf(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),x?null:u.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(g=>{const b=o(g.index,g.data,d);return s?u.jsx(c,{...Dt(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},b):w.createElement(a,{...Dt(a,d),className:n,"data-index":g.index,key:b},r(g.index,g.data,d))})})}),A0=w.memo(function(){const e=gt("HeaderComponent"),t=en("headerHeight"),n=gt("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=gt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Dt(e,o)})}):null}),j0=w.memo(function(){const e=gt("FooterComponent"),t=en("footerHeight"),n=gt("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Dn(s,"height"))},[t]),!0,!1),o=gt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Dt(e,o)})}):null}),_0=({children:e})=>{const t=w.useContext(of),n=en("itemDimensions"),r=en("viewportDimensions"),o=Jn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:ys(!1),children:e})},R0=({children:e})=>{const t=w.useContext(of),n=en("windowViewportRect"),r=en("itemDimensions"),o=gt("customScrollParent"),s=Ad(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:ys(!1),children:e})},P0=w.memo(function({...e}){const t=gt("useWindowScroll"),n=gt("customScrollParent"),r=n||t?M0:O0,o=n||t?R0:_0,s=gt("context");return u.jsx(r,{...e,...Dt(r,s),children:u.jsxs(o,{children:[u.jsx(A0,{}),u.jsx(N0,{}),u.jsx(j0,{})]})})}),{useEmitter:vf,useEmitterValue:gt,usePublisher:en}=nf(I0,{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"}},P0),O0=df({useEmitter:vf,useEmitterValue:gt,usePublisher:en}),M0=ff({useEmitter:vf,useEmitterValue:gt,usePublisher:en});function bf(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 D0=fo.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 wf({className:e,variant:t,...n}){return u.jsx("div",{className:te(D0({variant:t}),e),...n})}const Qr=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Qr.displayName="Card";const eo=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));eo.displayName="CardHeader";const to=y.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));to.displayName="CardTitle";const Sf=y.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Sf.displayName="CardDescription";const no=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));no.displayName="CardContent";const Cf=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));Cf.displayName="CardFooter";const L0=1,$0=1e6;let va=0;function F0(){return va=(va+1)%Number.MAX_SAFE_INTEGER,va.toString()}const ba=new Map,Tf=e=>{if(ba.has(e))return;const t=setTimeout(()=>{ba.delete(e),ro({type:"REMOVE_TOAST",toastId:e})},$0);ba.set(e,t)},z0=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,L0)};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?Tf(n):e.toasts.forEach(r=>{Tf(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)}}},ws=[];let Ss={toasts:[]};function ro(e){Ss=z0(Ss,e),ws.forEach(t=>{t(Ss)})}function B0({...e}){const t=F0(),n=o=>ro({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>ro({type:"DISMISS_TOAST",toastId:t});return ro({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function wa(){const[e,t]=y.useState(Ss);return y.useEffect(()=>(ws.push(t),()=>{const n=ws.indexOf(t);n>-1&&ws.splice(n,1)}),[e]),{...e,toast:B0,dismiss:n=>ro({type:"DISMISS_TOAST",toastId:n})}}async function kf(e,t){return await Yt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Ef(e,t){return await(await kf(`/files/${e}/view`,t)).text()}async function H0(e,t){const n=await kf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Yt(`/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 U0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Yt("/files",{params:r})}function Sa(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 If(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(If(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(If(e))return"";try{const t=oo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function W0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function V0(e){const t=so(e);return typeof e=="string"&&W0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Cs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Sa(t);if(n!==null)return Cs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Cs(e.content):e}var Ts="Dialog",[Nf,TT]=Tn(Ts),[K0,un]=Nf(Ts),Af=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=y.useRef(null),l=y.useRef(null),[c,d]=dr({prop:r,defaultProp:o??!1,onChange:s,caller:Ts});return u.jsx(K0,{scope:t,triggerRef:a,contentRef:l,contentId:kn(),titleId:kn(),descriptionId:kn(),open:c,onOpenChange:d,onOpenToggle:y.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Af.displayName=Ts;var jf="DialogTrigger",_f=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(jf,n),s=Ve(t,o.triggerRef);return u.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ka(o.open),...r,ref:s,onClick:me(e.onClick,o.onOpenToggle)})});_f.displayName=jf;var Ca="DialogPortal",[q0,Rf]=Nf(Ca,{forceMount:void 0}),Pf=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=un(Ca,t);return u.jsx(q0,{scope:t,forceMount:n,children:y.Children.map(r,i=>u.jsx(Jt,{present:n||s.open,children:u.jsx(Ko,{asChild:!0,container:o,children:i})}))})};Pf.displayName=Ca;var ks="DialogOverlay",Of=y.forwardRef((e,t)=>{const n=Rf(ks,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(ks,e.__scopeDialog);return s.modal?u.jsx(Jt,{present:r||s.open,children:u.jsx(Y0,{...o,ref:t})}):null});Of.displayName=ks;var G0=Un.createSlot("DialogOverlay.RemoveScroll"),Y0=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(ks,n);return u.jsx(ts,{as:G0,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(_e.div,{"data-state":ka(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),er="DialogContent",Mf=y.forwardRef((e,t)=>{const n=Rf(er,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(er,e.__scopeDialog);return u.jsx(Jt,{present:r||s.open,children:s.modal?u.jsx(X0,{...o,ref:t}):u.jsx(J0,{...o,ref:t})})});Mf.displayName=er;var X0=y.forwardRef((e,t)=>{const n=un(er,e.__scopeDialog),r=y.useRef(null),o=Ve(t,n.contentRef,r);return y.useEffect(()=>{const s=r.current;if(s)return Di(s)},[]),u.jsx(Df,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:me(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:me(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:me(e.onFocusOutside,s=>s.preventDefault())})}),J0=y.forwardRef((e,t)=>{const n=un(er,e.__scopeDialog),r=y.useRef(!1),o=y.useRef(!1);return u.jsx(Df,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Df=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=un(er,n),l=y.useRef(null),c=Ve(t,l);return xi(),u.jsxs(u.Fragment,{children:[u.jsx(Oo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Po,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ka(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(Z0,{titleId:a.titleId}),u.jsx(eS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ta="DialogTitle",Lf=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Ta,n);return u.jsx(_e.h2,{id:o.titleId,...r,ref:t})});Lf.displayName=Ta;var $f="DialogDescription",Ff=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un($f,n);return u.jsx(_e.p,{id:o.descriptionId,...r,ref:t})});Ff.displayName=$f;var zf="DialogClose",Bf=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(zf,n);return u.jsx(_e.button,{type:"button",...r,ref:t,onClick:me(e.onClick,()=>o.onOpenChange(!1))})});Bf.displayName=zf;function ka(e){return e?"open":"closed"}var Hf="DialogTitleWarning",[kT,Uf]=rx(Hf,{contentName:er,titleName:Ta,docsSlug:"dialog"}),Z0=({titleId:e})=>{const t=Uf(Hf),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 mw(e,t=ls){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function gw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),mw(t),hw(t)}const cs=0,Mn=1,wr=2,Cd=4;function Td(e){return()=>e}function xw(e){e()}function kd(e,t){return n=>e(t(n))}function Ed(e,t){return()=>e(t)}function yw(e,t){return n=>e(t,n)}function Zi(e){return e!==void 0}function vw(...e){return()=>{e.map(xw)}}function Sr(){}function us(e,t){return t(e),e}function bw(e,t){return t(e)}function ut(...e){return e}function rt(e,t){return e(Mn,t)}function De(e,t){e(cs,t)}function Qi(e){e(wr)}function Tt(e){return e(Cd)}function ye(e,t){return rt(e,yw(t,cs))}function ln(e,t){const n=e(Mn,r=>{n(),t(r)});return n}function Id(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Nd(e,t){return e===t}function dt(e=Nd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ie(e){return t=>n=>{e(n)&&t(n)}}function de(e){return t=>kd(t,e)}function yn(e){return t=>()=>{t(e)}}function U(e,...t){const n=ww(...t);return(r,o)=>{switch(r){case wr:Qi(e);return;case Mn:return rt(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Jn(e){return t=>n=>{e>0?e--:t(n)}}function Nn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...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);rt(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function ww(...e){return t=>e.reduceRight(bw,t)}function Sw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Mn:return s?n===s?void 0:(r(),n=s,t=rt(e,s),t):(r(),Sr);case wr:r(),n=null;return}}}function ee(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case cs:t=o;break;case Mn:{o(t);break}case Cd:return t}return n(r,o)}}function Ot(e,t){return us(ee(t),n=>ye(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case cs:e.slice().forEach(r=>{r(n)});return;case wr:e.splice(0,e.length);return;case Mn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Kt(e){return us(Ke(),t=>ye(e,t))}function Je(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Cw(),singleton:n}}const Cw=()=>Symbol();function Tw(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 kt(...e){const t=Ke(),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);rt(s,l=>{n[i]=l,r=r|a,r===o&&De(t,n)})}),function(s,i){switch(s){case wr:{Qi(t);return}case Mn:return r===o&&i(n),rt(t,i)}}}function Te(e,t=Nd){return U(e,dt(t))}function ea(...e){return function(t,n){switch(t){case wr:return;case Mn:return vw(...e.map(r=>rt(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 kw={0:"debug",3:"error",1:"log",2:"warn"},Ew=()=>typeof globalThis>"u"?window:globalThis,Dn=Je(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Ew().VIRTUOSO_LOG_LEVEL)!=null?o:Tt(e);r>=s&&console[kw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Zn(e,t,n){return ta(e,t,n).callbackRef}function ta(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 Iw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Nw(d.children,t,a?"offsetWidth":"offsetHeight",o);let p=d.parentElement;for(;!p.dataset.virtuosoScroller;)p=p.parentElement;const h=p.lastElementChild.dataset.viewportType==="window";let x;h&&(x=p.ownerDocument.defaultView);const m=i?a?i.scrollLeft:i.scrollTop:h?a?x.scrollX||x.document.documentElement.scrollLeft:x.scrollY||x.document.documentElement.scrollTop:a?p.scrollLeft:p.scrollTop,v=i?a?i.scrollWidth:i.scrollHeight:h?a?x.document.documentElement.scrollWidth:x.document.documentElement.scrollHeight:a?p.scrollWidth:p.scrollHeight,g=i?a?i.offsetWidth:i.offsetHeight:h?a?x.innerWidth:x.innerHeight:a?p.offsetWidth:p.offsetHeight;r({scrollHeight:v,scrollTop:Math.max(m,0),viewportHeight:g}),s==null||s(a?Ad("column-gap",getComputedStyle(d).columnGap,o):Ad("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ta(c,n,l)}function Nw(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ht.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Ad(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 _d(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),x=c.top-h.top;p=h.height-Math.max(0,x),f=x+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ta(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Ft=Je(()=>{const e=Ke(),t=Ke(),n=ee(0),r=Ke(),o=ee(0),s=Ke(),i=Ke(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Ke(),p=Ke(),h=ee(!1),x=ee(!1),m=ee(!1);return ye(U(e,de(({scrollTop:v})=>v)),t),ye(U(e,de(({scrollHeight:v})=>v)),i),ye(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:x,scrollBy:p,scrollContainerState:e,scrollHeight:i,scrollingInProgress:h,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:m,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Wr={lvl:0};function jd(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 at(e){return e===Wr}function Vr(e,t){if(!at(e))return t===e.k?e.v:t<e.k?Vr(e.l,t):Vr(e.r,t)}function cn(e,t,n="k"){if(at(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=cn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return cn(e.l,t,n)}function qt(e,t,n){return at(e)?Od(t,n,1):t===e.k?It(e,{k:t,v:n}):t<e.k?Md(It(e,{l:qt(e.l,t,n)})):Md(It(e,{r:qt(e.r,t,n)}))}function Cr(){return Wr}function ds(e,t,n){if(at(e))return[];const r=cn(e,t)[0];return Aw(ra(e,r,n))}function na(e,t){if(at(e))return Wr;const{k:n,l:r,r:o}=e;if(t===n){if(at(r))return o;if(at(o))return r;{const[s,i]=Pd(r);return fs(It(e,{k:s,l:Rd(r),v:i}))}}else return t<n?fs(It(e,{l:na(r,t)})):fs(It(e,{r:na(o,t)}))}function Qn(e){return at(e)?[]:[...Qn(e.l),{k:e.k,v:e.v},...Qn(e.r)]}function ra(e,t,n){if(at(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ra(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ra(s,t,n))),a}function fs(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(oa(t))return Dd(It(e,{lvl:n-1}));if(!at(t)&&!at(t.r))return It(t.r,{l:It(t,{r:t.r.l}),lvl:n,r:It(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(oa(e))return sa(It(e,{lvl:n-1}));if(!at(r)&&!at(r.l)){const o=r.l,s=oa(o)?r.lvl-1:r.lvl;return It(o,{l:It(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:sa(It(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function It(e,t){return Od(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 Rd(e){return at(e.r)?e.l:fs(It(e,{r:Rd(e.r)}))}function oa(e){return at(e)||e.lvl>e.r.lvl}function Pd(e){return at(e.r)?[e.k,e.v]:Pd(e.r)}function Od(e,t,n,r=Wr,o=Wr){return{k:e,l:r,lvl:n,r:o,v:t}}function Md(e){return sa(Dd(e))}function Dd(e){const{l:t}=e;return!at(t)&&t.lvl===e.lvl?It(t,{r:It(e,{l:t.r})}):e}function sa(e){const{lvl:t,r:n}=e;return!at(n)&&!at(n.r)&&n.lvl===t&&n.r.lvl===t?It(n,{l:It(e,{r:n.l}),lvl:t+1}):e}function Aw(e){return jd(e,({k:t,v:n})=>({index:t,value:n}))}function Ld(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Kr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ia=Je(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function $d(e,t,n){return e[ps(e,t,n)]}function ps(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 _w(e,t,n,r){const o=ps(e,t,r),s=ps(e,n,r,o);return e.slice(o,s+1)}function Ln(e,t){return Math.round(e.getBoundingClientRect()[t])}function hs(e){return!at(e.groupOffsetTree)}function aa({index:e},t){return t===e?0:t<e?-1:1}function jw(){return{groupIndices:[],groupOffsetTree:Cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Cr()}}function Rw(e,t){let n=at(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),at(e)){e=qt(e,0,s);continue}const a=ds(e,i-1,o+1);if(a.some(Fw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=na(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=qt(e,o+1,p));c&&(e=qt(e,i,s))}return[e,n]}function Pw(e){return typeof e.groupIndex<"u"}function Ow({offset:e},t){return t===e?0:t<e?-1:1}function qr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=$d(t,e,aa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Fd(e,t){if(!hs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function zd(e,t,n){if(Pw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Fd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Mw(e,t,n,r=0){return r>0&&(t=Math.max(t,$d(e,r,aa).offset)),jd(_w(e,t,n,Ow),$w)}function Dw(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&&at(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((x,m)=>qt(qt(x,m,p),m+1,h),i)}else[i,a]=Rw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=la(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>qt(p,h,qr(h,f,o)),Cr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Lw(e){return Qn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function Bd(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 la(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ps(o,t-1,aa),a=o[l].offset;const c=cn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===cn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ds(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function $w(e){return{index:e.index,value:e}}function Fw(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 zw={offsetHeight:"height",offsetWidth:"width"},bn=Je(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=Ot(r,0),s=Ke(),i=Ke(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Ln(C,zw[T])),p=ee(void 0),h=ee(0),x=jw(),m=Ot(U(n,$e(l,e,h),vn(Dw,x),dt()),x),v=Ot(U(l,dt(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),de(({prev:C})=>C)),[]);ye(U(l,Ie(C=>C.length>0),$e(m,h),de(([C,T,E])=>{const N=C.reduce((_,$,P)=>qt(_,$,qr($,T.offsetTree,E)||P),Cr());return{...T,groupIndices:C,groupOffsetTree:N}})),m),ye(U(r,$e(m),Ie(([C,{lastIndex:T}])=>C<T),de(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),ye(c,d);const g=Ot(U(c,de(C=>C===void 0)),!0);ye(U(d,Ie(C=>C!==void 0&&at(Tt(m).sizeTree)),de(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Kt(U(n,$e(m),vn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:x}),de(C=>C.changed)));rt(U(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),de(C=>C.diff)),C=>{const{groupIndices:T}=Tt(m);if(C>0)De(t,!0),De(s,C+Bd(C,T));else if(C<0){const E=Tt(v);E.length>0&&(C-=Bd(-C,E)),De(i,C)}}),rt(U(a,$e(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Ht.ERROR)});const S=Kt(s);ye(U(s,$e(m),de(([C,T])=>{const E=T.groupIndices.length>0,N=[],_=T.lastSize;if(E){const $=Vr(T.sizeTree,0);let P=0,D=0;for(;P<C;){const A=T.groupIndices[D],z=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-A-1;N.push({endIndex:A,size:$,startIndex:A}),N.push({endIndex:A+1+z-1,size:_,startIndex:A+1}),D++,P+=z+1}const F=Qn(T.sizeTree);return P!==C&&F.shift(),F.reduce((A,{k:z,v:j})=>{let K=A.ranges;return A.prevSize!==0&&(K=[...A.ranges,{endIndex:z+C-1,size:A.prevSize,startIndex:A.prevIndex}]),{prevIndex:z+C,prevSize:j,ranges:K}},{prevIndex:C,prevSize:0,ranges:N}).ranges}return Qn(T.sizeTree).reduce(($,{k:P,v:D})=>({prevIndex:P+C,prevSize:D,ranges:[...$.ranges,{endIndex:P+C-1,size:$.prevSize,startIndex:$.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Kt(U(i,$e(m,h),de(([C,{offsetTree:T},E])=>{const N=-C;return qr(N,T,E)})));return ye(U(i,$e(m,h),de(([C,T,E])=>{if(T.groupIndices.length>0){if(at(T.sizeTree))return T;let N=Cr();const _=Tt(v);let $=0,P=0,D=0;for(;$<-C;){D=_[P];const F=_[P+1]-D-1;P++,$+=F+1}if(N=Qn(T.sizeTree).reduce((F,{k:A,v:z})=>qt(F,Math.max(0,A+C),z),N),$!==-C){const F=Vr(T.sizeTree,D);N=qt(N,0,F);const A=cn(T.sizeTree,-C+1)[1];N=qt(N,1,A)}return{...T,sizeTree:N,...la(T.offsetTree,0,N,E)}}else{const N=Qn(T.sizeTree).reduce((_,{k:$,v:P})=>qt(_,Math.max(0,$+C),P),Cr());return{...T,sizeTree:N,...la(T.offsetTree,0,N,E)}}})),m),{beforeUnshiftWith:S,data:p,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:h,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:k,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:r,trackItemSizes:g,unshiftWith:s}},ut(Dn,ia),{singleton:!0});function Bw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Hd=Je(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Kt(U(s,de(Bw)));return ye(U(a,de(l=>l.totalCount)),n),ye(U(a,de(l=>l.groupIndices)),e),ye(U(kt(o,t,r),Ie(([l,c])=>hs(c)),de(([l,c,d])=>cn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),dt(),de(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ut(bn,Ft)),$n=Je(([{log:e}])=>{const t=ee(!1),n=Kt(U(t,Ie(r=>r),dt()));return rt(t,r=>{r&&Tt(e)("props updated",{},Ht.DEBUG)}),{didMount:n,propsReady:t}},ut(Dn),{singleton:!0}),Hw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Ud(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Hw)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Gr=Je(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=Ke(),x=Ke(),m=ee(0);let v=null,g=null,b=null;function S(){v&&(v(),v=null),b&&(b(),b=null),g&&(clearTimeout(g),g=null),De(l,!1)}return ye(U(h,$e(n,f,r,m,a,i,p),$e(e,s,o),de(([[k,C,T,E,N,_,$,P],D,F,A])=>{const z=Ud(k),{align:j,behavior:K,offset:B}=z,R=E-1,Y=zd(z,C,R);let X=qr(Y,C.offsetTree,D)+_;j==="end"?(X+=F+cn(C.sizeTree,Y)[1]-T+A,Y===R&&(X+=$)):j==="center"?X+=(F+cn(C.sizeTree,Y)[1]-T+A)/2:X-=N,B&&(X+=B);const se=be=>{S(),be?(P("retrying to scroll to",{location:k},Ht.DEBUG),De(h,k)):(De(x,!0),P("list did not change, scroll successful",{},Ht.DEBUG))};if(S(),K==="smooth"){let be=!1;b=rt(t,Oe=>{be=be||Oe}),v=ln(d,()=>{se(be)})}else v=ln(U(t,Uw(150)),se);return g=setTimeout(()=>{S()},1200),De(l,!0),P("scrolling from index to",{behavior:K,index:Y,top:X},Ht.DEBUG),{behavior:K,top:X}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},ut(bn,Ft,Dn),{singleton:!0});function Uw(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ca(e,t){e==0?t():requestAnimationFrame(()=>{ca(e-1,t)})}function ua(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Yr=Je(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return ye(U(i,$e(l),Ie(([d,f])=>!!f),yn(!1)),a),ye(U(i,$e(l),Ie(([d,f])=>!!f),yn(!1)),c),rt(U(kt(t,i),$e(a,n,e,c),Ie(([[,d],f,{sizeTree:p},h,x])=>d&&(!at(p)||Zi(h))&&!f&&!x),$e(l)),([,d])=>{ln(o,()=>{De(c,!0)}),ca(4,()=>{ln(r,()=>{De(a,!0)}),De(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ut(bn,Ft,Gr,$n),{singleton:!0});function Wd(e,t){return Math.abs(e-t)<1.01}const Xr="up",Jr="down",Ww="none",Vw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Kw=0,Zr=Je(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Ke(),c=Ke(),d=ee(4),f=ee(Kw),p=Ot(U(ea(U(Te(o),Jn(1),yn(!0)),U(Te(o),Jn(1),yn(!1),Id(100))),dt()),!1),h=Ot(U(ea(U(n,yn(!0)),U(n,yn(!1),Id(200))),dt()),!1);ye(U(kt(Te(o),Te(f)),de(([b,S])=>b<=S),dt()),a),ye(U(a,Nn(50)),c);const x=Kt(U(kt(r,Te(s),Te(t),Te(e),Te(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,E,N])=>{const _=k+C-S>-N,$={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let D,F;return k>b.state.scrollTop?(D="SCROLLED_DOWN",F=b.state.scrollTop-k):(D="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:D,scrollTopDelta:F,state:$}}let P;return $.scrollHeight>b.state.scrollHeight?P="SIZE_INCREASED":C<b.state.viewportHeight?P="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?P="SCROLLING_UPWARDS":P="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:P,state:$}},Vw),dt((b,S)=>b&&b.atBottom===S.atBottom))),m=Ot(U(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Wd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ie(b=>b.changed),de(b=>b.jump)),0);ye(U(x,de(b=>b.atBottom)),i),ye(U(i,Nn(50)),l);const v=ee(Jr);ye(U(r,de(({scrollTop:b})=>b),dt(),vn((b,S)=>Tt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Xr:Jr,prevScrollTop:S},{direction:Jr,prevScrollTop:0}),de(b=>b.direction)),v),ye(U(r,Nn(50),yn(Ww)),v);const g=ee(0);return ye(U(p,Ie(b=>!b),yn(0)),g),ye(U(o,Nn(100),$e(p),Ie(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),de(([b,S])=>S-b)),g),{atBottomState:x,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:v,scrollVelocity:g}},ut(Ft)),ms="top",gs="bottom",Vd="none";function Kd(e,t,n){return typeof e=="number"?n===Xr&&t===ms||n===Jr&&t===gs?e:0:n===Xr?t===ms?e.main:e.reverse:t===gs?e.main:e.reverse}function qd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const da=Je(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=ee(0),a=ee(0),l=ee(0),c=Ot(U(kt(Te(r),Te(o),Te(n),Te(s,Kr),Te(l),Te(i),Te(t),Te(e),Te(a)),de(([d,f,p,[h,x],m,v,g,b,S])=>{const k=d-b,C=v+g,T=Math.max(p-k,0);let E=Vd;const N=qd(S,ms),_=qd(S,gs);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-N&&(E=Xr),x<d-T+f+_&&(E=Jr),E!==Vd?[Math.max(k-p-Kd(m,ms,E)-N,0),k-T-g+f+Kd(m,gs,E)+_]:null}),Ie(d=>d!=null),dt(Kr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ut(Ft),{singleton:!0});function qw(e,t,n){if(hs(t)){const r=Fd(e,t);return[{index:cn(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const fa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function xs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const m=e[e.length-1];d=m.offset+m.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,x=p-d;return{bottom:d,firstItemIndex:s,items:Yd(e,o,s),offsetBottom:x,offsetTop:c,top:h,topItems:Yd(t,o,s),topListHeight:t.reduce((m,v)=>v.size+m,0),totalCount:n}}function Gd(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=ua(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return xs(c,[],a,o,n,r)}function Yd(e,t,n){if(e.length===0)return[];if(!hs(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ds(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const er=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:x}])=>{const m=ee([]),v=ee(0),g=Ke();ye(s.topItemsIndexes,m);const b=Ot(U(kt(h,x,Te(l,Kr),Te(o),Te(r),Te(c),d,Te(m),Te(t),Te(n),e),Ie(([T,E,,N,,,,,,,_])=>{const $=_&&_.length!==N;return T&&!E&&!$}),de(([,,[T,E],N,_,$,P,D,F,A,z])=>{const j=_,{offsetTree:K,sizeTree:B}=j,R=Tt(v);if(N===0)return{...fa,totalCount:N};if(T===0&&E===0)return R===0?{...fa,totalCount:N}:Gd(R,$,_,F,A,z||[]);if(at(B))return R>0?null:xs(qw(ua($,N),j,z),[],N,A,j,F);const Y=[];if(D.length>0){const q=D[0],H=D[D.length-1];let J=0;for(const L of ds(B,q,H)){const G=L.value,Z=Math.max(L.start,q),fe=Math.min(L.end,H);for(let oe=Z;oe<=fe;oe++)Y.push({data:z==null?void 0:z[oe],index:oe,offset:J,size:G}),J+=G}}if(!P)return xs([],Y,N,A,j,F);const X=D.length>0?D[D.length-1]+1:0,se=Mw(K,T,E,X);if(se.length===0)return null;const be=N-1,Oe=us([],q=>{for(const H of se){const J=H.value;let L=J.offset,G=H.start;const Z=J.size;if(J.offset<T){G+=Math.floor((T-J.offset+A)/(Z+A));const oe=G-H.start;L+=oe*Z+oe*A}G<X&&(L+=(X-G)*Z,G=X);const fe=Math.min(H.end,be);for(let oe=G;oe<=fe&&!(L>=E);oe++)q.push({data:z==null?void 0:z[oe],index:oe,offset:L,size:Z}),L+=Z+A}});return xs(Oe,Y,N,A,j,F)}),Ie(T=>T!==null),dt()),fa);ye(U(e,Ie(Zi),de(T=>T==null?void 0:T.length)),o),ye(U(b,de(T=>T.topListHeight)),f),ye(f,a),ye(U(b,de(T=>[T.top,T.bottom])),i),ye(U(b,de(T=>T.items)),g);const S=Kt(U(b,Ie(({items:T})=>T.length>0),$e(o,e),Ie(([{items:T},E])=>T[T.length-1].originalIndex===E-1),de(([,T,E])=>[T-1,E]),dt(Kr),de(([T])=>T))),k=Kt(U(b,Nn(200),Ie(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),de(({items:T})=>T[0].index),dt())),C=Kt(U(b,Ie(({items:T})=>T.length>0),de(({items:T})=>{let E=0,N=T.length-1;for(;T[E].type==="group"&&E<N;)E++;for(;T[N].type==="group"&&N>E;)N--;return{endIndex:T[N].index,startIndex:T[E].index}}),dt(Ld)));return{endReached:S,initialItemCount:v,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},ut(bn,Hd,da,Yr,Gr,Zr,$n,ia),{singleton:!0}),Xd=Je(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=Ot(U(kt(n,e,r,t,o),de(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return ye(Te(i),s),{totalListHeight:i,totalListHeightChanged:s}},ut(Ft,er),{singleton:!0}),Gw=Je(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Ot(U(kt(n,e,t),Ie(([o])=>o),de(([,o,s])=>Math.max(0,o-s)),Nn(0),dt()),0);return{alignToBottom:n,paddingTopAddition:r}},ut(Ft,Xd),{singleton:!0}),Jd=Je(()=>({context:ee(null)})),Yw=({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,Zd=Je(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Ke();return ye(U(d,$e(t,l,n,s,o,r,a),$e(e),de(([[f,p,h,x,m,v,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Yw,done:E,...N}=f,_=zd(f,p,x-1),$=qr(_,p.offsetTree,S)+m+v,P=$+cn(p.sizeTree,_)[1],D=b+v,F=b+h-g,A=T({itemBottom:P,itemTop:$,locationParams:{align:k,behavior:C,...N},viewportBottom:F,viewportTop:D});return A?E&&ln(U(i,Ie(z=>!z),Jn(Tt(i)?1:2)),E):E&&E(),A}),Ie(f=>f!==null)),c),{scrollIntoView:d}},ut(bn,Ft,Gr,er,Dn),{singleton:!0});function Qd(e){return e?e==="smooth"?"smooth":"auto":!1}const Xw=(e,t)=>typeof e=="function"?Qd(e(t)):t&&Qd(e),Jw=Je(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const x=ee(!1),m=Ke();let v=null;function g(C){De(i,{align:"end",behavior:C,index:"LAST"})}rt(U(kt(U(Te(t),Jn(1)),l),$e(Te(x),s,a,f),de(([[C,T],E,N,_,$])=>{let P=T&&_,D="auto";return P&&(D=Xw(E,N||$),P=P&&!!D),{followOutputBehavior:D,shouldFollow:P,totalCount:C}}),Ie(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{v&&(v(),v=null),Tt(n)?requestAnimationFrame(()=>{Tt(d)("following output to ",{totalCount:T},Ht.DEBUG),g(C)}):v=ln(e,()=>{Tt(d)("following output to ",{totalCount:T},Ht.DEBUG),g(C),v=null})});function b(C){const T=ln(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!v&&(Tt(d)("scrolling to bottom due to increased size",{},Ht.DEBUG),g("auto"))});setTimeout(T,100)}rt(U(kt(Te(x),t,c),Ie(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ie(({refreshed:C})=>C),$e(x,t)),([,C])=>{Tt(a)&&b(C!==!1)}),rt(m,()=>{b(Tt(x)!==!1)}),rt(kt(Te(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=Ke();return ye(ea(U(Te(r),de(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),U(Te(t))),k),rt(U(kt(U(k,Jn(1)),l),$e(Te(S),a,f,p),de(([[C,T],E,N,_,$])=>T&&N&&(E==null?void 0:E({context:$,totalCount:C,scrollingInProgress:_}))),Ie(C=>!!C),Nn(0)),C=>{v&&(v(),v=null),Tt(n)?requestAnimationFrame(()=>{Tt(d)("scrolling into view",{}),De(h,C)}):v=ln(e,()=>{Tt(d)("scrolling into view",{}),De(h,C),v=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},ut(bn,Zr,Gr,Yr,$n,Dn,Ft,Jd,Zd)),Zw=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ye(U(a,$e(s),Ie(([,l])=>l!==0),$e(o,r,t,n,e),de(([[,l],c,d,f,p,h=[]])=>Gd(l,c,d,f,p,h))),i),{}),ut(bn,Yr,er,$n),{singleton:!0}),Qw=Je(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return rt(U(e,$e(r),Ie(([,o])=>o!==0),de(([,o])=>({top:o}))),o=>{ln(U(n,Jn(1),Ie(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{De(t,o)})})}),{initialScrollTop:r}},ut($n,Ft,er),{singleton:!0}),ef=Je(([{scrollVelocity:e}])=>{const t=ee(!1),n=Ke(),r=ee(!1);return ye(U(e,$e(r,t,n),Ie(([o,s])=>!!s),de(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),dt()),t),rt(U(kt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ut(Zr),{singleton:!0}),pa=Je(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=ee(!1),i=ee(void 0);return ye(U(kt(n,r),de(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),ye(U(t,$e(r),de(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ut(Ft)),e0=Je(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ke(),d=ee(void 0),f=ee(null),p=ee(null);return ye(a,f),ye(l,p),rt(U(c,$e(t,r,i,f,p,n)),([h,x,m,v,g,b,S])=>{const k=Lw(x.sizeTree);v&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),ye(U(d,Ie(Zi),de(t0)),o),ye(U(s,$e(d),Ie(([,h])=>h!==void 0),dt(),de(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},ut(bn,Ft,Yr,$n,pa));function t0(e){return{align:"start",index:0,offset:e.scrollTop}}const n0=Je(([{topItemsIndexes:e}])=>{const t=ee(0);return ye(U(t,Ie(n=>n>=0),de(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ut(er));function tf(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const r0=tf(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),o0=Je(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:x}])=>{const m=Kt(U(l,$e(i),vn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:E},N])=>{const _=k+T;let $=0;return b===E&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||($=_-S,$!==0&&($+=N))),[$,C,E,_]},[0,[],0,0]),Ie(([g])=>g!==0),$e(r,a,n,o,h,x),Ie(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Xr),de(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Ht.DEBUG),g))));function v(g){g>0?(De(t,{behavior:"auto",top:-g}),De(e,0)):(De(e,0),De(t,{behavior:"auto",top:-g}))}return rt(U(m,$e(e,s)),([g,b,S])=>{S&&r0()?De(e,b-g):v(-g)}),rt(U(kt(Ot(s,!1),e,x),Ie(([g,b,S])=>!g&&!S&&b!==0),de(([g,b])=>b),Nn(1)),v),ye(U(f,de(g=>({top:-g}))),t),rt(U(c,$e(p,d),de(([g,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(g);{let E=0;const N=Vr(k,0);let _=0,$=0;for(;_<g;){_++,E+=N;let P=b.length===$+1?1/0:b[$+1]-b[$]-1;_+P>g&&(E-=N,P=g-_+1),_+=P,E+=T(P),$++}return E}})),g=>{De(e,g),requestAnimationFrame(()=>{De(t,{top:g}),requestAnimationFrame(()=>{De(e,0),De(x,!1)})})}),{deviation:e}},ut(Ft,Zr,er,bn,Dn,ia)),s0=Je(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ut(da,Zw,$n,ef,Xd,Qw,Gw,pa,Zd,Dn,Jd)),nf=Je(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x},m,v,g,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:N},_])=>(ye(k.rangeChanged,_.scrollSeekRangeChanged),ye(U(_.windowViewportRect,de($=>$.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,..._,...m,sizes:l,...v}),ut(bn,Yr,Ft,e0,Jw,er,Gr,o0,n0,Hd,s0));function i0(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 ys=typeof document<"u"?w.useLayoutEffect:w.useEffect;function rf(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,g){v.propsReady&&De(v.propsReady,!1);for(const b of r){const S=v[t.required[b]];De(S,g[b])}for(const b of o)if(b in g){const S=v[t.optional[b]];De(S,g[b])}v.propsReady&&De(v.propsReady,!0)}function c(v){return s.reduce((g,b)=>(g[b]=S=>{const k=v[t.methods[b]];De(k,S)},g),{})}function d(v){return i.reduce((g,b)=>(g[b]=Sw(v[t.events[b]]),g),{})}const f=w.forwardRef((v,g)=>{const{children:b,...S}=v,[k]=w.useState(()=>us(Tw(e),E=>{l(E,S)})),[C]=w.useState(Ed(d,k));ys(()=>{for(const E of i)E in S&&rt(C[E],S[E]);return()=>{Object.values(C).map(Qi)}},[S,C,k]),ys(()=>{l(k,S)}),w.useImperativeHandle(g,Td(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...i0([...r,...o,...i],S),children:b}):b})}),p=v=>{const g=w.useContext(a);return w.useCallback(b=>{De(g[v],b)},[g,v])},h=v=>{const g=w.useContext(a)[v],b=w.useCallback(S=>rt(g,S),[g]);return w.useSyncExternalStore(b,()=>Tt(g),()=>Tt(g))},x=v=>{const g=w.useContext(a)[v],[b,S]=w.useState(Ed(Tt,g));return ys(()=>rt(g,k=>{k!==b&&S(Td(k))}),[g,b]),b},m=w.version.startsWith("18")?h:x;return{Component:f,useEmitter:(v,g)=>{const b=w.useContext(a)[v];ys(()=>rt(b,g),[g,b])},useEmitterValue:m,usePublisher:p}}const of=w.createContext(void 0),sf=w.createContext(void 0),af=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ha(e){return"self"in e}function a0(e){return"body"in e}function lf(e,t,n,r=Sr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,x,m;const v=p.target;if(a0(v)||ha(v)){const b=ha(v)?v:v.defaultView;m=s?b.scrollX:b.scrollY,h=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,x=s?b.innerWidth:b.innerHeight}else m=s?v.scrollLeft:v.scrollTop,h=s?v.scrollWidth:v.scrollHeight,x=s?v.offsetWidth:v.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:x})};p.suppressFlushSync?g():qs.flushSync(g),a.current!==null&&(m===a.current||m<=0||m===h-x)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const x=p.behavior==="smooth";let m,v,g;ha(h)?(v=Math.max(Ln(h.document.documentElement,s?"width":"height"),s?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),m=s?h.innerWidth:h.innerHeight,g=s?window.scrollX:window.scrollY):(v=h[s?"scrollWidth":"scrollHeight"],m=Ln(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const b=v-m;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Wd(m,v)||p.top===g){e({scrollHeight:v,scrollTop:g,viewportHeight:m}),x&&t(!0);return}x?(a.current=p.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(p={behavior:p.behavior,left:p.top}),h.scrollTo(p)}function f(p){s&&(p={behavior:p.behavior,left:p.top}),i.current.scrollBy(p)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ma="-webkit-sticky",cf="sticky",ga=tf(()=>{if(typeof document>"u")return cf;const e=document.createElement("div");return e.style.position=ma,e.style.position===ma?ma:cf});function xa(e){return e}const l0=Je(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(xa),o=ee("div"),s=ee(Sr),i=(a,l=null)=>Ot(U(n,de(c=>c[a]),dt()),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")}}),c0=Je(([e,t])=>({...e,...t}),ut(nf,l0)),u0=({height:e})=>u.jsx("div",{style:{height:e}}),d0={overflowAnchor:"none",position:ga(),zIndex:1},uf={overflowAnchor:"none"},f0={...uf,display:"inline-block",height:"100%"},df=w.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=en("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),c=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),p=Ne("itemSize"),h=Ne("log"),x=en("gap"),m=Ne("horizontalDirection"),{callbackRef:v}=Iw(n,p,f,e?Sr:a,h,x,o,m,Ne("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);ya("deviation",A=>{g!==A&&b(A)});const S=Ne("EmptyPlaceholder"),k=Ne("ScrollSeekPlaceholder")||u0,C=Ne("ListComponent"),T=Ne("ItemComponent"),E=Ne("GroupComponent"),N=Ne("computeItemKey"),_=Ne("isSeeking"),$=Ne("groupIndices").length>0,P=Ne("alignToBottom"),D=Ne("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:g!==0?g:P?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:P?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...D?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Mt(S,c)}):u.jsx(C,{...Mt(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:F,children:(e?t.topItems:t.items).map(A=>{const z=A.originalIndex,j=N(z+t.firstItemIndex,A.data,c);return _?w.createElement(k,{...Mt(k,c),height:A.size,index:A.index,key:j,type:A.type||"item",...A.type==="group"?{}:{groupIndex:A.groupIndex}}):A.type==="group"?w.createElement(E,{...Mt(E,c),"data-index":z,"data-item-index":A.index,"data-known-size":A.size,key:j,style:d0},d(A.index,c)):w.createElement(T,{...Mt(T,c),...g0(T,A.data),"data-index":z,"data-item-group-index":A.groupIndex,"data-item-index":A.index,"data-known-size":A.size,key:j,style:m?f0:uf},$?l(A.index,A.groupIndex,A.data,c):l(A.index,A.data,c))})})}),p0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},h0={outline:"none",overflowX:"auto",position:"relative"},vs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),m0={position:ga(),top:0,width:"100%",zIndex:1};function Mt(e,t){if(typeof e!="string")return{context:t}}function g0(e,t){return{item:typeof e=="string"?void 0:t}}const x0=w.memo(function(){const e=Ne("HeaderComponent"),t=en("headerHeight"),n=Ne("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Mt(e,o)})}):null}),y0=w.memo(function(){const e=Ne("FooterComponent"),t=en("footerHeight"),n=Ne("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Mt(e,o)})}):null});function ff({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:h,scrollToCallback:x}=lf(a,c,l,d,void 0,f);return e("scrollTo",x),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?h0:p0,...o},tabIndex:0,...i,...Mt(l,s),children:r})})}function pf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),p=t("customScrollParent"),h=w.useRef(null),x=t("scrollerRef"),{scrollByCallback:m,scrollerRef:v,scrollToCallback:g}=lf(a,c,l,x,p);return af(()=>{var b;return v.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{v.current=null}},[v,p]),e("windowScrollTo",g),e("scrollBy",m),u.jsx(l,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Mt(l,s),children:r})})}const v0=({children:e})=>{const t=w.useContext(of),n=en("viewportHeight"),r=en("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=w.useMemo(()=>kd(n,l=>Ln(l,s?"width":"height")),[n,s]),a=Zn(i,!0,Ne("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:vs(o),children:e})},b0=({children:e})=>{const t=w.useContext(of),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=Ne("customScrollParent"),s=_d(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:vs(i),children:e})},w0=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...m0,marginTop:`${n}px`},o=Ne("context");return u.jsx(t,{style:r,...Mt(t,o),children:e})},S0=w.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return u.jsxs(r||t?k0:T0,{...e,context:o,children:[n&&u.jsx(w0,{children:u.jsx(df,{showTopList:!0})}),u.jsxs(r||t?b0:v0,{children:[u.jsx(x0,{}),u.jsx(df,{}),u.jsx(y0,{})]})]})}),{Component:C0,useEmitter:ya,useEmitterValue:Ne,usePublisher:en}=rf(c0,{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"}},S0),T0=ff({useEmitter:ya,useEmitterValue:Ne,usePublisher:en}),k0=pf({useEmitter:ya,useEmitterValue:Ne,usePublisher:en}),E0=C0;ut(nf,Je(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(xa),a=ee(Sr),l=(c,d=null)=>Ot(U(s,de(f=>f[c]),dt()),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")}})),ga();const hf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},I0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:mf,floor:bs,max:Qr,min:va,round:gf}=Math;function xf(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function N0(e){return{...I0,items:e}}function ws(e,t){return e&&e.width===t.width&&e.height===t.height}function A0(e,t){return e&&e.column===t.column&&e.row===t.row}const _0=Je(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:x,propsReady:m},{customScrollParent:v,useWindowScroll:g,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),E=ee(0),N=ee(hf),_=ee({height:0,width:0}),$=ee({height:0,width:0}),P=Ke(),D=Ke(),F=ee(0),A=ee(null),z=ee({column:0,row:0}),j=Ke(),K=Ke(),B=ee(!1),R=ee(0),Y=ee(!0),X=ee(!1),se=ee(!1);rt(U(x,$e(R),Ie(([L,G])=>!!G)),()=>{De(Y,!1)}),rt(U(kt(x,Y,$,_,R,X),Ie(([L,G,Z,fe,,oe])=>L&&!G&&Z.height!==0&&fe.height!==0&&!oe)),([,,,,L])=>{De(X,!0),ca(1,()=>{De(P,L)}),ln(U(c),()=>{De(t,[0,0]),De(Y,!0)})}),ye(U(K,Ie(L=>L!=null&&L.scrollTop>0),yn(0)),E),rt(U(x,$e(K),Ie(([,L])=>L!=null)),([,L])=>{L&&(De(_,L.viewport),De($,L.item),De(z,L.gap),L.scrollTop>0&&(De(B,!0),ln(U(c,Jn(1)),G=>{De(B,!1)}),De(l,{top:L.scrollTop})))}),ye(U(_,de(({height:L})=>L)),f),ye(U(kt(Te(_,ws),Te($,ws),Te(z,(L,G)=>L&&L.column===G.column&&L.row===G.row),Te(c)),de(([L,G,Z,fe])=>({gap:Z,item:G,scrollTop:fe,viewport:L}))),j),ye(U(kt(Te(T),r,Te(z,A0),Te($,ws),Te(_,ws),Te(A),Te(E),Te(B),Te(Y),Te(R)),Ie(([,,,,,,,L])=>!L),de(([L,[G,Z],fe,oe,Ae,qe,Fe,,Ze,ie])=>{const{column:we,row:_e}=fe,{height:Le,width:Ue}=oe,{width:Ge}=Ae;if(Fe===0&&(L===0||Ge===0))return hf;if(Ue===0){const yt=ua(ie,L),Nt=yt+Math.max(Fe-1,0);return N0(xf(yt,Nt,qe))}const ze=yf(Ge,Ue,we);let He,et;Ze?G===0&&Z===0&&Fe>0?(He=0,et=Fe-1):(He=ze*bs((G+_e)/(Le+_e)),et=ze*mf((Z+_e)/(Le+_e))-1,et=va(L-1,Qr(et,ze-1)),He=va(et,Qr(0,He))):(He=0,et=-1);const Et=xf(He,et,qe),{bottom:xt,top:ct}=vf(Ae,fe,oe,Et),ft=mf(L/ze),pt=ft*Le+(ft-1)*_e-xt;return{bottom:xt,itemHeight:Le,items:Et,itemWidth:Ue,offsetBottom:pt,offsetTop:ct,top:ct}})),N),ye(U(A,Ie(L=>L!==null),de(L=>L.length)),T),ye(U(kt(_,$,N,z),Ie(([L,G,{items:Z}])=>Z.length>0&&G.height!==0&&L.height!==0),de(([L,G,{items:Z},fe])=>{const{bottom:oe,top:Ae}=vf(L,fe,G,Z);return[Ae,oe]}),dt(Kr)),t);const be=ee(!1);ye(U(c,$e(be),de(([L,G])=>G||L!==0)),be);const Oe=Kt(U(kt(N,T),Ie(([{items:L}])=>L.length>0),$e(be),Ie(([[L,G],Z])=>{const fe=L.items[L.items.length-1].index===G-1;return(Z||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===G)&&fe}),de(([[,L]])=>L-1),dt())),q=Kt(U(Te(N),Ie(({items:L})=>L.length>0&&L[0].index===0),yn(0),dt())),H=Kt(U(Te(N),$e(B),Ie(([{items:L},G])=>L.length>0&&!G),de(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),dt(Ld),Nn(0)));ye(H,h.scrollSeekRangeChanged),ye(U(P,$e(_,$,T,z),de(([L,G,Z,fe,oe])=>{const Ae=Ud(L),{align:qe,behavior:Fe,offset:Ze}=Ae;let ie=Ae.index;ie==="LAST"&&(ie=fe-1),ie=Qr(0,ie,va(fe-1,ie));let we=ba(G,oe,Z,ie);return qe==="end"?we=gf(we-G.height+Z.height):qe==="center"&&(we=gf(we-G.height/2+Z.height/2)),Ze&&(we+=Ze),{behavior:Fe,top:we}})),l);const J=Ot(U(N,de(L=>L.offsetBottom+L.bottom)),0);return ye(U(k,de(L=>({height:L.visibleHeight,width:L.visibleWidth}))),_),{customScrollParent:v,data:A,deviation:F,footerHeight:o,gap:z,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:$,overscan:n,restoreStateFrom:K,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:P,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:N,horizontalDirection:se,initialTopMostItemIndex:R,totalListHeight:J,...p,endReached:Oe,propsReady:m,rangeChanged:H,startReached:q,stateChanged:j,stateRestoreInProgress:B,...C}},ut(da,Ft,Zr,ef,$n,pa,Dn));function yf(e,t,n){return Qr(1,bs((e+n)/(bs(t)+n)))}function vf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ba(e,t,n,r[0].index);return{bottom:ba(e,t,n,r[r.length-1].index)+o,top:s}}function ba(e,t,n,r){const o=yf(e.width,n.width,t.column),s=bs(r/o),i=s*n.height+Qr(0,s-1)*t.row;return i>0?i+t.row:i}const j0=Je(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(xa),i=ee("div"),a=ee(Sr),l=(f,p=null)=>Ot(U(t,de(h=>h[f]),dt()),p),c=ee(!1),d=ee(!1);return ye(Te(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),R0=Je(([e,t])=>({...e,...t}),ut(_0,j0)),P0=w.memo(function(){const e=gt("gridState"),t=gt("listClassName"),n=gt("itemClassName"),r=gt("itemContent"),o=gt("computeItemKey"),s=gt("isSeeking"),i=tn("scrollHeight"),a=gt("ItemComponent"),l=gt("ListComponent"),c=gt("ScrollSeekPlaceholder"),d=gt("context"),f=tn("itemDimensions"),p=tn("gap"),h=gt("log"),x=gt("stateRestoreInProgress"),m=tn("reportReadyState"),v=Zn(w.useMemo(()=>g=>{const b=g.parentElement.parentElement.scrollHeight;i(b);const S=g.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:wf("column-gap",getComputedStyle(g).columnGap,h),row:wf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return af(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),x?null:u.jsx(l,{className:t,ref:v,...Mt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const b=o(g.index,g.data,d);return s?u.jsx(c,{...Mt(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},b):w.createElement(a,{...Mt(a,d),className:n,"data-index":g.index,key:b},r(g.index,g.data,d))})})}),O0=w.memo(function(){const e=gt("HeaderComponent"),t=tn("headerHeight"),n=gt("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=gt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Mt(e,o)})}):null}),M0=w.memo(function(){const e=gt("FooterComponent"),t=tn("footerHeight"),n=gt("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=gt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Mt(e,o)})}):null}),D0=({children:e})=>{const t=w.useContext(sf),n=tn("itemDimensions"),r=tn("viewportDimensions"),o=Zn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:vs(!1),children:e})},L0=({children:e})=>{const t=w.useContext(sf),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=gt("customScrollParent"),s=_d(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:vs(!1),children:e})},$0=w.memo(function({...e}){const t=gt("useWindowScroll"),n=gt("customScrollParent"),r=n||t?z0:F0,o=n||t?L0:D0,s=gt("context");return u.jsx(r,{...e,...Mt(r,s),children:u.jsxs(o,{children:[u.jsx(O0,{}),u.jsx(P0,{}),u.jsx(M0,{})]})})}),{useEmitter:bf,useEmitterValue:gt,usePublisher:tn}=rf(R0,{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"}},$0),F0=ff({useEmitter:bf,useEmitterValue:gt,usePublisher:tn}),z0=pf({useEmitter:bf,useEmitterValue:gt,usePublisher:tn});function wf(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 B0=po.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Sf({className:e,variant:t,...n}){return u.jsx("div",{className:te(B0({variant:t}),e),...n})}const eo=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));eo.displayName="Card";const to=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));to.displayName="CardHeader";const no=y.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));no.displayName="CardTitle";const Cf=y.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Cf.displayName="CardDescription";const ro=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));ro.displayName="CardContent";const Tf=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));Tf.displayName="CardFooter";const H0=1,U0=1e6;let wa=0;function W0(){return wa=(wa+1)%Number.MAX_SAFE_INTEGER,wa.toString()}const Sa=new Map,kf=e=>{if(Sa.has(e))return;const t=setTimeout(()=>{Sa.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},U0);Sa.set(e,t)},V0=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,H0)};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?kf(n):e.toasts.forEach(r=>{kf(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)}}},Ss=[];let Cs={toasts:[]};function oo(e){Cs=V0(Cs,e),Ss.forEach(t=>{t(Cs)})}function K0({...e}){const t=W0(),n=o=>oo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>oo({type:"DISMISS_TOAST",toastId:t});return oo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ca(){const[e,t]=y.useState(Cs);return y.useEffect(()=>(Ss.push(t),()=>{const n=Ss.indexOf(t);n>-1&&Ss.splice(n,1)}),[e]),{...e,toast:K0,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}async function Ef(e,t){return await Yt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function If(e,t){return await(await Ef(`/files/${e}/view`,t)).text()}async function q0(e,t){const n=await Ef(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Yt(`/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 G0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Yt("/files",{params:r})}function Ta(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function Nf(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(Nf(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(Nf(e))return"";try{const t=so(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Y0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function X0(e){const t=io(e);return typeof e=="string"&&Y0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ts(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ta(t);if(n!==null)return Ts(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ts(e.content):e}var ks="Dialog",[Af,NT]=Tn(ks),[J0,un]=Af(ks),_f=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=y.useRef(null),l=y.useRef(null),[c,d]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:ks});return u.jsx(J0,{scope:t,triggerRef:a,contentRef:l,contentId:kn(),titleId:kn(),descriptionId:kn(),open:c,onOpenChange:d,onOpenToggle:y.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};_f.displayName=ks;var jf="DialogTrigger",Rf=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(jf,n),s=Ve(t,o.triggerRef);return u.jsx(je.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ia(o.open),...r,ref:s,onClick:me(e.onClick,o.onOpenToggle)})});Rf.displayName=jf;var ka="DialogPortal",[Z0,Pf]=Af(ka,{forceMount:void 0}),Of=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=un(ka,t);return u.jsx(Z0,{scope:t,forceMount:n,children:y.Children.map(r,i=>u.jsx(Zt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:i})}))})};Of.displayName=ka;var Es="DialogOverlay",Mf=y.forwardRef((e,t)=>{const n=Pf(Es,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(Es,e.__scopeDialog);return s.modal?u.jsx(Zt,{present:r||s.open,children:u.jsx(eS,{...o,ref:t})}):null});Mf.displayName=Es;var Q0=Wn.createSlot("DialogOverlay.RemoveScroll"),eS=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Es,n);return u.jsx(ns,{as:Q0,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(je.div,{"data-state":Ia(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),tr="DialogContent",Df=y.forwardRef((e,t)=>{const n=Pf(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=un(tr,e.__scopeDialog);return u.jsx(Zt,{present:r||s.open,children:s.modal?u.jsx(tS,{...o,ref:t}):u.jsx(nS,{...o,ref:t})})});Df.displayName=tr;var tS=y.forwardRef((e,t)=>{const n=un(tr,e.__scopeDialog),r=y.useRef(null),o=Ve(t,n.contentRef,r);return y.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(Lf,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:me(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:me(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:me(e.onFocusOutside,s=>s.preventDefault())})}),nS=y.forwardRef((e,t)=>{const n=un(tr,e.__scopeDialog),r=y.useRef(!1),o=y.useRef(!1);return u.jsx(Lf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Lf=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=un(tr,n),l=y.useRef(null),c=Ve(t,l);return vi(),u.jsxs(u.Fragment,{children:[u.jsx(Mo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Oo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ia(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(rS,{titleId:a.titleId}),u.jsx(sS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ea="DialogTitle",$f=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Ea,n);return u.jsx(je.h2,{id:o.titleId,...r,ref:t})});$f.displayName=Ea;var Ff="DialogDescription",zf=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Ff,n);return u.jsx(je.p,{id:o.descriptionId,...r,ref:t})});zf.displayName=Ff;var Bf="DialogClose",Hf=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=un(Bf,n);return u.jsx(je.button,{type:"button",...r,ref:t,onClick:me(e.onClick,()=>o.onOpenChange(!1))})});Hf.displayName=Bf;function Ia(e){return e?"open":"closed"}var Uf="DialogTitleWarning",[AT,Wf]=lx(Uf,{contentName:tr,titleName:Ea,docsSlug:"dialog"}),rS=({titleId:e})=>{const t=Wf(Uf),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
87
87
 
88
88
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
89
89
 
90
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return y.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Q0="DialogDescriptionWarning",eS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Uf(Q0).contentName}}.`;return y.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},Wf=Af,tS=_f,Vf=Pf,Es=Of,Is=Mf,tr=Lf,Ns=Ff,Kf=Bf;const nS=Wf,rS=Vf,qf=y.forwardRef(({className:e,...t},n)=>u.jsx(Es,{ref:n,className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));qf.displayName=Es.displayName;const Gf=y.forwardRef(({className:e,children:t,...n},r)=>{const o=y.useMemo(()=>{let s=!1;function i(a){y.Children.forEach(a,l=>{if(s||!y.isValidElement(l))return;const c=l.type;if(c===tr||(c==null?void 0:c.displayName)===tr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(rS,{children:[u.jsx(qf,{}),u.jsxs(Is,{ref:r,className:te("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(tr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Kf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Gf.displayName=Is.displayName;const Yf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Yf.displayName="DialogHeader";const Xf=y.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Xf.displayName=tr.displayName;const oS=y.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));oS.displayName=Ns.displayName;function sS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=wa(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await Ef(n);l(g)}catch(g){console.error("Failed to load file:",g),d(g instanceof Error?g.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await H0(n),f({title:"Download started",description:`Downloading ${r}`})}catch(g){console.error("Failed to download file:",g),f({title:"Download failed",description:String(g),variant:"destructive"})}},x=async()=>{if(n)try{const g=await Ef(n),b=new Blob([g],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(g){console.error("Failed to open file externally:",g),f({title:"Failed to open file",description:String(g),variant:"destructive"})}},m=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(le.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(nt,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(le.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),v=()=>o.startsWith("image/")?u.jsx(le.Image,{className:"h-5 w-5"}):u.jsx(le.FileText,{className:"h-5 w-5"});return u.jsx(nS,{open:e,onOpenChange:t,children:u.jsxs(Gf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Yf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[v(),u.jsxs("div",{children:[u.jsx(Xf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(nt,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(nt,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(le.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:m()})]})})}function Jf(){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 nr=Jf();function iS(e){nr=e}const Zf=/[&<>"']/,aS=new RegExp(Zf.source,"g"),Qf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,lS=new RegExp(Qf.source,"g"),cS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ep=e=>cS[e];function Lt(e,t){if(t){if(Zf.test(e))return e.replace(aS,ep)}else if(Qf.test(e))return e.replace(lS,ep);return e}const uS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function tp(e){return e.replace(uS,(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 dS=/(^|[^\[])\^/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(dS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const fS=/[^\w:]/g,pS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function np(e,t,n){if(e){let r;try{r=decodeURIComponent(tp(n)).replace(fS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!pS.test(n)&&(n=xS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const As={},hS=/^[^:]+:\/*[^/]*$/,mS=/^([^:]+:)[\s\S]*$/,gS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function xS(e,t){As[" "+e]||(hS.test(e)?As[" "+e]=e+"/":As[" "+e]=_s(e,"/",!0)),e=As[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(mS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(gS,"$1")+t:e+t}const js={exec:function(){}};function rp(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function _s(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function yS(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function vS(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 op(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function sp(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 bS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
90
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return y.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},oS="DialogDescriptionWarning",sS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Wf(oS).contentName}}.`;return y.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},Vf=_f,iS=Rf,Kf=Of,Is=Mf,Ns=Df,nr=$f,As=zf,qf=Hf;const aS=Vf,lS=Kf,Gf=y.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Gf.displayName=Is.displayName;const Yf=y.forwardRef(({className:e,children:t,...n},r)=>{const o=y.useMemo(()=>{let s=!1;function i(a){y.Children.forEach(a,l=>{if(s||!y.isValidElement(l))return;const c=l.type;if(c===nr||(c==null?void 0:c.displayName)===nr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(lS,{children:[u.jsx(Gf,{}),u.jsxs(Ns,{ref:r,className:te("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(nr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(qf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Yf.displayName=Ns.displayName;const Xf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Xf.displayName="DialogHeader";const Jf=y.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Jf.displayName=nr.displayName;const cS=y.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));cS.displayName=As.displayName;function uS({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[c,d]=w.useState(null),{toast:f}=Ca(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await If(n);l(g)}catch(g){console.error("Failed to load file:",g),d(g instanceof Error?g.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&p()},[e,n,p]);const h=async()=>{if(n)try{await q0(n),f({title:"Download started",description:`Downloading ${r}`})}catch(g){console.error("Failed to download file:",g),f({title:"Download failed",description:String(g),variant:"destructive"})}},x=async()=>{if(n)try{const g=await If(n),b=new Blob([g],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(g){console.error("Failed to open file externally:",g),f({title:"Failed to open file",description:String(g),variant:"destructive"})}},m=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(le.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(nt,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(le.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),v=()=>o.startsWith("image/")?u.jsx(le.Image,{className:"h-5 w-5"}):u.jsx(le.FileText,{className:"h-5 w-5"});return u.jsx(aS,{open:e,onOpenChange:t,children:u.jsxs(Yf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Xf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[v(),u.jsxs("div",{children:[u.jsx(Jf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(nt,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(le.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(nt,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(le.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:m()})]})})}function Zf(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let rr=Zf();function dS(e){rr=e}const Qf=/[&<>"']/,fS=new RegExp(Qf.source,"g"),ep=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,pS=new RegExp(ep.source,"g"),hS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},tp=e=>hS[e];function Dt(e,t){if(t){if(Qf.test(e))return e.replace(fS,tp)}else if(ep.test(e))return e.replace(pS,tp);return e}const mS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function np(e){return e.replace(mS,(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 gS=/(^|[^\[])\^/g;function lt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(gS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const xS=/[^\w:]/g,yS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function rp(e,t,n){if(e){let r;try{r=decodeURIComponent(np(n)).replace(xS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!yS.test(n)&&(n=SS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const _s={},vS=/^[^:]+:\/*[^/]*$/,bS=/^([^:]+:)[\s\S]*$/,wS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function SS(e,t){_s[" "+e]||(vS.test(e)?_s[" "+e]=e+"/":_s[" "+e]=Rs(e,"/",!0)),e=_s[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(bS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(wS,"$1")+t:e+t}const js={exec:function(){}};function op(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Rs(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 CS(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 TS(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 sp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function ip(e,t,n,r){const o=t.href,s=t.title?Dt(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:Dt(i)}}function kS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
91
91
  `).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(`
92
- `)}class Ea{constructor(t){this.options=t||nr}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:_s(r,`
93
- `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=bS(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=_s(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,p,h,x,m=n[1].trim();const v=m.length>1,g={type:"list",raw:"",ordered:v,start:v?+m.slice(0,-1):"",loose:!1,items:[]};m=v?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=v?m:"[*+-]");const b=new RegExp(`^( {0,3}${m})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(x=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
92
+ `)}class Na{constructor(t){this.options=t||rr}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Rs(r,`
93
+ `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=kS(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=Rs(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,p,h,x,m=n[1].trim();const v=m.length>1,g={type:"list",raw:"",ordered:v,start:v?+m.slice(0,-1):"",loose:!1,items:[]};m=v?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=v?m:"[*+-]");const b=new RegExp(`^( {0,3}${m})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(x=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
94
94
  `,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
95
95
  `,1)[0],this.options.pedantic?(i=2,h=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,h=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
96
96
  `,t=t.substring(f.length+1),x=!0),!x){const k=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=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&&(p=t.split(`
97
97
  `,1)[0],f=p,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||E.test(f)||k.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())h+=`
98
98
  `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||E.test(d)||C.test(d))break;h+=`
99
99
  `+f}!l&&!f.trim()&&(l=!0),r+=p+`
100
- `,t=t.substring(p.length+1),d=f.slice(i)}}g.loose||(c?g.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(h),o&&(s=o[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),g.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:h}),g.raw+=r}g.items[g.items.length-1].raw=r.trimRight(),g.items[g.items.length-1].text=h.trimRight(),g.raw=g.raw.trimRight();const S=g.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,g.items[a].tokens=this.lexer.blockTokens(g.items[a].text,[]),!g.loose){const k=g.items[a].tokens.filter(T=>T.type==="space"),C=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));g.loose=C}if(g.loose)for(a=0;a<S;a++)g.items[a].loose=!0;return g}}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:rp(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
101
- `):[]};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]=rp(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
102
- `?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=_s(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=yS(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),sp(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 sp(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const p=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const x=p.slice(1,-1);return{type:"em",raw:p,text:x,tokens:this.lexer.inlineTokens(x)}}const h=p.slice(2,-2);return{type:"strong",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=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 Se={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:js,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Se._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Se._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Se.def=at(Se.def).replace("label",Se._label).replace("title",Se._title).getRegex(),Se.bullet=/(?:[*+-]|\d{1,9}[.)])/,Se.listItemStart=at(/^( *)(bull) */).replace("bull",Se.bullet).getRegex(),Se.list=at(Se.list).replace(/bull/g,Se.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Se.def.source+")").getRegex(),Se._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",Se._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Se.html=at(Se.html,"i").replace("comment",Se._comment).replace("tag",Se._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Se.paragraph=at(Se._paragraph).replace("hr",Se.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",Se._tag).getRegex(),Se.blockquote=at(Se.blockquote).replace("paragraph",Se.paragraph).getRegex(),Se.normal={...Se},Se.gfm={...Se.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Se.gfm.table=at(Se.gfm.table).replace("hr",Se.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",Se._tag).getRegex(),Se.gfm.paragraph=at(Se._paragraph).replace("hr",Se.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Se.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",Se._tag).getRegex(),Se.pedantic={...Se.normal,html:at(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Se._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:js,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:at(Se.normal._paragraph).replace("hr",Se.hr).replace("heading",` *#{1,6} *[^
103
- ]`).replace("lheading",Se.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const pe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:js,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:js,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};pe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",pe.punctuation=at(pe.punctuation).replace(/punctuation/g,pe._punctuation).getRegex(),pe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,pe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,pe._comment=at(Se._comment).replace("(?:-->|$)","-->").getRegex(),pe.emStrong.lDelim=at(pe.emStrong.lDelim).replace(/punct/g,pe._punctuation).getRegex(),pe.emStrong.rDelimAst=at(pe.emStrong.rDelimAst,"g").replace(/punct/g,pe._punctuation).getRegex(),pe.emStrong.rDelimUnd=at(pe.emStrong.rDelimUnd,"g").replace(/punct/g,pe._punctuation).getRegex(),pe._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,pe._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,pe._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,pe.autolink=at(pe.autolink).replace("scheme",pe._scheme).replace("email",pe._email).getRegex(),pe._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,pe.tag=at(pe.tag).replace("comment",pe._comment).replace("attribute",pe._attribute).getRegex(),pe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,pe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,pe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,pe.link=at(pe.link).replace("label",pe._label).replace("href",pe._href).replace("title",pe._title).getRegex(),pe.reflink=at(pe.reflink).replace("label",pe._label).replace("ref",Se._label).getRegex(),pe.nolink=at(pe.nolink).replace("ref",Se._label).getRegex(),pe.reflinkSearch=at(pe.reflinkSearch,"g").replace("reflink",pe.reflink).replace("nolink",pe.nolink).getRegex(),pe.normal={...pe},pe.pedantic={...pe.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:at(/^!?\[(label)\]\((.*?)\)/).replace("label",pe._label).getRegex(),reflink:at(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",pe._label).getRegex()},pe.gfm={...pe.normal,escape:at(pe.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},pe.gfm.url=at(pe.gfm.url,"i").replace("email",pe.gfm._extended_email).getRegex(),pe.breaks={...pe.gfm,br:at(pe.br).replace("{2,}","*").getRegex(),text:at(pe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function wS(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 ip(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class $n{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||nr,this.options.tokenizer=this.options.tokenizer||new Ea,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:Se.normal,inline:pe.normal};this.options.pedantic?(n.block=Se.pedantic,n.inline=pe.pedantic):this.options.gfm&&(n.block=Se.gfm,this.options.breaks?n.inline=pe.breaks:n.inline=pe.gfm),this.tokenizer.rules=n}static get rules(){return{block:Se,inline:pe}}static lex(t,n){return new $n(n).lex(t)}static lexInline(t,n){return new $n(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
100
+ `,t=t.substring(p.length+1),d=f.slice(i)}}g.loose||(c?g.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(h),o&&(s=o[0]!=="[ ] ",h=h.replace(/^\[[ xX]\] +/,""))),g.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:h}),g.raw+=r}g.items[g.items.length-1].raw=r.trimRight(),g.items[g.items.length-1].text=h.trimRight(),g.raw=g.raw.trimRight();const S=g.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,g.items[a].tokens=this.lexer.blockTokens(g.items[a].text,[]),!g.loose){const k=g.items[a].tokens.filter(T=>T.type==="space"),C=k.length>0&&k.some(T=>/\n.*\n/.test(T.raw));g.loose=C}if(g.loose)for(a=0;a<S;a++)g.items[a].loose=!0;return g}}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]):Dt(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:op(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
101
+ `):[]};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]=op(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
102
+ `?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:Dt(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]):Dt(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=Rs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=CS(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)),ip(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 ip(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+d);const p=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const x=p.slice(1,-1);return{type:"em",raw:p,text:x,tokens:this.lexer.inlineTokens(x)}}const h=p.slice(2,-2);return{type:"strong",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Dt(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=Dt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Dt(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=Dt(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=Dt(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]):Dt(r[0]):r[0]:o=Dt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const Se={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:js,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Se._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Se._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Se.def=lt(Se.def).replace("label",Se._label).replace("title",Se._title).getRegex(),Se.bullet=/(?:[*+-]|\d{1,9}[.)])/,Se.listItemStart=lt(/^( *)(bull) */).replace("bull",Se.bullet).getRegex(),Se.list=lt(Se.list).replace(/bull/g,Se.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Se.def.source+")").getRegex(),Se._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",Se._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Se.html=lt(Se.html,"i").replace("comment",Se._comment).replace("tag",Se._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Se.paragraph=lt(Se._paragraph).replace("hr",Se.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",Se._tag).getRegex(),Se.blockquote=lt(Se.blockquote).replace("paragraph",Se.paragraph).getRegex(),Se.normal={...Se},Se.gfm={...Se.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Se.gfm.table=lt(Se.gfm.table).replace("hr",Se.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",Se._tag).getRegex(),Se.gfm.paragraph=lt(Se._paragraph).replace("hr",Se.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Se.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",Se._tag).getRegex(),Se.pedantic={...Se.normal,html:lt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Se._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:js,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:lt(Se.normal._paragraph).replace("hr",Se.hr).replace("heading",` *#{1,6} *[^
103
+ ]`).replace("lheading",Se.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const pe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:js,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:js,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};pe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",pe.punctuation=lt(pe.punctuation).replace(/punctuation/g,pe._punctuation).getRegex(),pe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,pe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,pe._comment=lt(Se._comment).replace("(?:-->|$)","-->").getRegex(),pe.emStrong.lDelim=lt(pe.emStrong.lDelim).replace(/punct/g,pe._punctuation).getRegex(),pe.emStrong.rDelimAst=lt(pe.emStrong.rDelimAst,"g").replace(/punct/g,pe._punctuation).getRegex(),pe.emStrong.rDelimUnd=lt(pe.emStrong.rDelimUnd,"g").replace(/punct/g,pe._punctuation).getRegex(),pe._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,pe._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,pe._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,pe.autolink=lt(pe.autolink).replace("scheme",pe._scheme).replace("email",pe._email).getRegex(),pe._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,pe.tag=lt(pe.tag).replace("comment",pe._comment).replace("attribute",pe._attribute).getRegex(),pe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,pe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,pe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,pe.link=lt(pe.link).replace("label",pe._label).replace("href",pe._href).replace("title",pe._title).getRegex(),pe.reflink=lt(pe.reflink).replace("label",pe._label).replace("ref",Se._label).getRegex(),pe.nolink=lt(pe.nolink).replace("ref",Se._label).getRegex(),pe.reflinkSearch=lt(pe.reflinkSearch,"g").replace("reflink",pe.reflink).replace("nolink",pe.nolink).getRegex(),pe.normal={...pe},pe.pedantic={...pe.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:lt(/^!?\[(label)\]\((.*?)\)/).replace("label",pe._label).getRegex(),reflink:lt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",pe._label).getRegex()},pe.gfm={...pe.normal,escape:lt(pe.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},pe.gfm.url=lt(pe.gfm.url,"i").replace("email",pe.gfm._extended_email).getRegex(),pe.breaks={...pe.gfm,br:lt(pe.br).replace("{2,}","*").getRegex(),text:lt(pe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function ES(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 ap(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 Fn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||rr,this.options.tokenizer=this.options.tokenizer||new Na,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:Se.normal,inline:pe.normal};this.options.pedantic?(n.block=Se.pedantic,n.inline=pe.pedantic):this.options.gfm&&(n.block=Se.gfm,this.options.breaks?n.inline=pe.breaks:n.inline=pe.gfm),this.tokenizer.rules=n}static get rules(){return{block:Se,inline:pe}}static lex(t,n){return new Fn(n).lex(t)}static lexInline(t,n){return new Fn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
104
104
  `),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
105
105
  `: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+=`
106
106
  `+r.raw,o.text+=`
@@ -110,9 +110,9 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
110
110
  `+r.raw,o.text+=`
111
111
  `+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+=`
112
112
  `+r.raw,o.text+=`
113
- `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+op("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)+"["+op("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,ip)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,ip))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let p;this.options.extensions.startInline.forEach(function(h){p=h.call({lexer:this},f),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,wS)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class Ia{constructor(t){this.options=t||nr}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$/,"")+`
114
- `,o?'<pre><code class="'+this.options.langPrefix+Lt(o)+'">'+(r?t:Lt(t,!0))+`</code></pre>
115
- `:"<pre><code>"+(r?t:Lt(t,!0))+`</code></pre>
113
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+sp("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)+"["+sp("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(l||(c=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,c)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,ap)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,ap))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let p;this.options.extensions.startInline.forEach(function(h){p=h.call({lexer:this},f),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,ES)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class Aa{constructor(t){this.options=t||rr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
114
+ `,o?'<pre><code class="'+this.options.langPrefix+Dt(o)+'">'+(r?t:Dt(t,!0))+`</code></pre>
115
+ `:"<pre><code>"+(r?t:Dt(t,!0))+`</code></pre>
116
116
  `}blockquote(t){return`<blockquote>
117
117
  ${t}</blockquote>
118
118
  `}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}>
@@ -130,8 +130,8 @@ ${t}</blockquote>
130
130
  `}tablerow(t){return`<tr>
131
131
  ${t}</tr>
132
132
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
133
- `}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=np(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=np(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 ap{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 lp{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Fn{constructor(t){this.options=t||nr,this.options.renderer=this.options.renderer||new Ia,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ap,this.slugger=new lp}static parse(t,n){return new Fn(n).parse(t)}static parseInline(t,n){return new Fn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,x,m,v,g,b,S,k,C,T;const E=t.length;for(o=0;o<E;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,tp(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(x=h.ordered,m=h.start,v=h.loose,a=h.items.length,p="",s=0;s<a;s++)b=h.items[s],S=b.checked,k=b.task,g="",b.task&&(C=this.renderer.checkbox(S),v?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):g+=C),g+=this.parse(b.tokens,v),p+=this.renderer.listitem(g,k,S);r+=this.renderer.list(p,x,m);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<E&&t[o+1].type==="text";)h=t[++o],p+=`
134
- `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Rs{constructor(t){this.options=t||nr}preprocess(t){return t}postprocess(t){return t}}Uh(Rs,"passThroughHooks",new Set(["preprocess","postprocess"]));function SS(e,t,n){return r=>{if(r.message+=`
135
- 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 cp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ye.defaults,...s};const i=SS(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(vS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&ye.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ye.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(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 cp($n.lex,Fn.parse)(e,t,n)}ye.options=ye.setOptions=function(e){return ye.defaults={...ye.defaults,...e},iS(ye.defaults),ye},ye.getDefaults=Jf,ye.defaults=nr,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 Ia;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 Ea;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=ye.defaults.hooks||new Rs;for(const s in n.hooks){const i=o[s];Rs.passThroughHooks.has(s)?o[s]=a=>{if(ye.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=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=cp($n.lexInline,Fn.parseInline),ye.Parser=Fn,ye.parser=Fn.parse,ye.Renderer=Ia,ye.TextRenderer=ap,ye.Lexer=$n,ye.lexer=$n.lex,ye.Tokenizer=Ea,ye.Slugger=lp,ye.Hooks=Rs,ye.parse=ye,ye.options,ye.setOptions,ye.use,ye.walkTokens,ye.parseInline,Fn.parse,$n.lex;function io({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 u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const CS="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 TS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function up(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 kS(e){const t=o=>{try{const s=oo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
136
- `)):r=t(e),r||""}function ES(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function dp(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 IS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function NS(e,t){const n=[],r=o=>{o&&o.trim()&&n.push(o.trim())};return r(e.plotId),r(e.artifactId),t&&(r(t.plotId),r(t.artifactId)),n}function fp({base64:e,url:t,formatHint:n,artifact:r,extras:o}){const s=typeof e=="string"&&e.length>0,i=typeof t=="string"&&t.length>0;if(!s&&!i)return null;const a=s?`data:${IS(n)};base64,${e}`:t,l=NS(r,o),c=l.length?l.join(" / "):void 0,d=c?`${c} artifact`:"artifact image";return{src:a,alt:d,label:c}}function AS(e,t){if(!e)return null;const n=typeof e.content_base64=="string"&&e.content_base64.trim()||void 0,r=typeof e.url=="string"&&e.url.trim()||void 0,o=(typeof e.format=="string"?e.format.trim():void 0)||(typeof e.mimeType=="string"?e.mimeType.trim():void 0)||(typeof e.mime_type=="string"?e.mime_type.trim():void 0);return fp({base64:n,url:r,formatHint:o,artifact:t})}function jS(e,t){if(!e||typeof e!="object")return null;const n=e,r=typeof n.content_base64=="string"&&n.content_base64.trim()||void 0,o=typeof n.url=="string"&&n.url.trim()||void 0,s=(typeof n.format=="string"?n.format.trim():void 0)||(typeof n.mimeType=="string"?n.mimeType.trim():void 0)||(typeof n.mime_type=="string"?n.mime_type.trim():void 0);return fp({base64:r,url:o,formatHint:s,artifact:t,extras:{plotId:typeof n.plotId=="string"?n.plotId:void 0,artifactId:typeof n.artifactId=="string"?n.artifactId:void 0}})}function _S({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Na=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:v,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:N,defaultCheckpointId:j=null,messageParentCheckpointId:$=null}){const[P,D]=w.useState(!1),[F,A]=w.useState("preview"),[z,_]=w.useState(!1),{currentThreadId:K}=Ao(),{respondToInterrupt:B}=jo(),R=l==="phone"||l==="half-screen",Y=t.role,X=Y==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ve=!!se,Oe=!(r&&Y!=="user"),{uploadingFiles:q,handleFileClick:H,fileViewerOpen:J,currentFileInfo:L,closeFileViewer:G}=PS({allowFileOpen:Oe,currentThreadId:K}),Z=w.useMemo(()=>{switch(Y){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))]"}},[Y]),fe=w.useMemo(()=>se?"":TS(t.content),[se,t]),re=w.useMemo(()=>se?{}:up(t),[se,t]),Ae=w.useMemo(()=>se?[]:t.content.filter(M=>M.type==="image_url"),[se,t]),qe=w.useMemo(()=>se?[]:t.content.filter(M=>M.type==="file"),[se,t]),Fe=w.useMemo(()=>se?[]:t.content.filter(M=>M.type==="interrupt"),[se,t]),Je=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),ie=Ps(Je),be=b==null?void 0:b.value,je=w.useMemo(()=>se?"":kS(t.content),[se,t]),De=w.useMemo(()=>{var ct,we;if(se||!p)return[];const Q=t.artifact;if(!Q)return[];const oe=[],Le=AS(Q.data,Q);Le&&oe.push(Le);const ge=[...Array.isArray(Q.plots)?Q.plots:[],...Array.isArray((ct=Q.data)==null?void 0:ct.plots)?(we=Q.data)==null?void 0:we.plots:[]];for(const tt of ge){const rn=jS(tt,Q);rn&&oe.push(rn)}return oe},[se,t,p]),Ue=w.useCallback(async()=>{const M=X?je:fe;async function Q(oe){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(oe);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Le=new Blob([oe],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Le})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(M),D(!0),setTimeout(()=>D(!1),2e3),g==null||g(M)}catch(oe){console.error("Failed to copy:",oe)}},[X,je,fe,g]),Ge=w.useCallback(()=>{if(!x)return;const M=X?je:fe,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,M,Q)},[x,t.id,X,je,fe,t]),ze=w.useCallback(()=>{m==null||m(n)},[m,n]),He=w.useCallback(()=>{const Q=te(R?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(Y){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[R,Z,Y]),Qe=w.useCallback(()=>{const M="group relative mb-4 flex w-full";switch(Y){case"user":return te(M,"justify-end");case"assistant":case"tool":case"system":return te(M,"justify-start");default:return M}},[Y]),Et=w.useCallback(()=>{const M=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",R&&"px-3 py-2 text-sm");if(ve)return te(M,"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(Y){case"user":return te(M,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(M,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(M,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(M,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(M,"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")}},[R,ve,Y]);if(ve&&se)return u.jsx("div",{className:te(Qe(),h.container),children:u.jsxs("div",{className:te(Et(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(io,{content:se.content,className:"text-current"})]})});const xt=w.useCallback(async M=>{if(S)return;const Q=Ps((M==null?void 0:M.id)??(M==null?void 0:M.interrupt_id));if(!Q){console.warn("Interrupt part missing id",M);return}try{k==null||k(),await B(Q,!0)}catch(oe){console.error("Failed to approve interrupt:",oe)}finally{C==null||C()}},[S,C,k,B]),lt=w.useCallback(async M=>{if(S)return;const Q=Ps((M==null?void 0:M.id)??(M==null?void 0:M.interrupt_id));if(!Q){console.warn("Interrupt part missing id",M);return}try{k==null||k(),await B(Q,!1)}catch(oe){console.error("Failed to reject interrupt:",oe)}finally{C==null||C()}},[S,C,k,B]),ft=w.useCallback(({part:M,i:Q})=>{if(M.type==="text"){const oe=M.text??"",Le=oe.trim(),ge=Sa(Le);return ge&&Y!=="tool"?u.jsx(pp,{data:ge},Q):Y==="user"&&c&&Le.length>d?u.jsx(OS,{text:Le,expanded:z,onExpandedChange:_,previewLength:d,isCompact:R},Q):u.jsx(io,{content:oe,allowHtml:!1},Q)}if(M.type==="image_url"){const oe=M;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:oe.url,alt:oe.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(M.type==="file"){const oe=M,Le=oe.name||"file";return u.jsxs("a",{href:oe.url,onClick:ge=>H(ge,oe,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[q[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Le,q[Q]?" (processing)":""]})]},Q)}if(M.type==="interrupt"){const oe=M,Le=Ps((oe==null?void 0:oe.id)??(oe==null?void 0:oe.interrupt_id)),ge=!!(ie&&Le&&Le===ie),ct=ge?be??(oe==null?void 0:oe.value):oe==null?void 0:oe.value,we=Le?{...oe,id:Le,interrupt_id:Le}:oe;return u.jsx(RS,{interruptPart:we,onApprove:xt,onReject:lt,disabled:S,isActive:ge,payload:ct},Q)}return null},[H,q,xt,lt,Y,c,d,z,R,ie,be,b,S,Fe]),pt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),yt=w.useCallback(()=>{const M=fe.trim().length>0||Ae.length>0||qe.length>0||Fe.length>0;if(!X&&qe.length>0&&!r)return pt();if(!X&&!M&&!r)return null;if(X)return u.jsx(MS,{message:t,viewMode:F},t.id);if(!X&&!se){const Q=t,oe=u.jsx("div",{className:"space-y-2",children:Q.content.map((Le,ge)=>u.jsx(ft,{part:Le,i:ge},ge))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[oe,u.jsx(_S,{className:Z})]}):oe}},[fe,Ae.length,qe.length,Fe.length,r,X,F,pt,Z]),Nt=w.useMemo(()=>se?"Assistant":ES(t),[se,t]),Ye=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),_t=w.useMemo(()=>{var M;return Ye.length?j&&Ye.some(Q=>Q.id===j)?j:((M=Ye[0])==null?void 0:M.id)??null:null},[j,Ye]),et=w.useMemo(()=>!Ye.length||!E?null:Ye.some(M=>M.id===E)?E:null,[E,Ye])??_t,ot=Y==="user"&&Ye.length>0&&typeof N=="function",bt=w.useCallback(M=>{if(!N)return;const Q=(M==null?void 0:M.id)??null,oe=(M==null?void 0:M.parentId)??$??null;N(Q,oe)},[$,N]),V=w.useMemo(()=>et?Ye.findIndex(M=>M.id===et):-1,[et,Ye]),ce=w.useMemo(()=>V<0?null:Ye[V]??null,[V,Ye]),Ce=w.useCallback(M=>{const Q=[];if(M.step!==null&&Q.push(`Step ${M.step}`),M.source&&Q.push(M.source),!M.createdAt)return Q.length?Q.join(" • "):M.id.slice(0,8);let oe="";try{const Le=new Date(M.createdAt);Number.isNaN(Le.getTime())||(oe=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(Le))}catch{oe=""}return`${oe}`},[]);return X&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(Qe(),h.container),children:u.jsxs("div",{className:te(Et(),h.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",R&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[He(),a&&Nt&&u.jsx("span",{className:te("font-medium",R?"text-xs":"text-sm"),children:Nt}),X&&u.jsxs(wf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",R&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>A(M=>M==="expanded"?"preview":"expanded"),onKeyDown:M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),A(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:re.name??"Tool Output"}),re.toolCallId&&u.jsx("span",{className:"opacity-70",children:re.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[ot&&ce&&V>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",V>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(V<=0)return;const M=Ye[V-1];M&&bt(M)},"aria-label":"Previous checkpoint",disabled:V<=0,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[V+1," / ",Ye.length]}),u.jsx("span",{className:"text-muted-foreground",children:Ce(ce)})]}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",V<Ye.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(V>=Ye.length-1)return;const M=Ye[V+1];M&&bt(M)},"aria-label":"Next checkpoint",disabled:V>=Ye.length-1,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,R&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,R&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(P?"text-success":Z,R?"h-3 w-3":"h-4 w-4")})})}),Y==="user"&&x&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,R&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,R?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ze,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,R&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,R?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[yt(),p&&De.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:De.map((M,Q)=>u.jsxs("div",{className:"space-y-2",children:[M.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",M.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:M.src,alt:M.alt,title:M.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain"})})]},`artifact-${Q}`))})]}),X&&F==="expanded"&&(re.toolCallId||re.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",R&&"text-xs"),children:[re.name&&u.jsxs("div",{children:["Function: ",re.name]}),re.toolCallId&&u.jsxs("div",{children:["Call ID: ",re.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(P?"text-success":"text-current",R?"h-3 w-3":"h-4 w-4")})}),Y==="user"&&x&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",R?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ze,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",R?"h-3 w-3":"h-4 w-4")})})]})]})}),L&&u.jsx(sS,{isOpen:J,onClose:G,fileId:L.id,fileName:L.name,mimeType:L.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&dp(e.message)===dp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(x=>e[x]===t[x]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});function pp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:CS,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:so(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:so(e)})}function RS({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=so(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(Qr,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(eo,{className:"pb-3",children:[u.jsx(to,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Sf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(no,{className:"pt-0 pb-3",children:a}),u.jsx(Cf,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function PS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=wa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,x,m)=>{var v,g;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(x.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=x.name||`file_${k}`,T=x.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await U0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof E.size=="number"?E.size===x.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${x.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:x.name||T.filename||`file_${T.id}`,mimeType:x.mimeType||T.mime_type||"application/octet-stream"}),(v=k.update)==null||v.call(k,{id:k.id,title:"Success",description:`Opened ${x.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function OS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(io,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(nt,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function MS({message:e,viewMode:t}){const r=up(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sa(c)??c:c;if(d&&typeof d=="object")return u.jsx(pp,{data:d});const f=typeof d=="string"?d:(()=>{try{return so(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=V0(c);return f?u.jsx(io,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=oo(i),l=Cs(a);return s(l)}const DS=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r})=>{const o=e??[],s=o.length>0,i=w.useMemo(()=>s?[...o].reverse():[],[o,s]),a=t??(o.length?o[o.length-1].id:null);return w.useEffect(()=>{console.debug("[TimelineColumn] entries:",o.length)},[o.length]),s?u.jsxs("div",{className:"w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(le.Info,{className:"h-3 w-3 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[10px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:"Backend pre-selects user inputs + latest loop checkpoint. Click a dot to jump, or use “Latest” to return to the newest messages."})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:i.map(l=>{const c=a===l.id,d=l.messageId?(r==null?void 0:r.get(l.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(l.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${c?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${c?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${c?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:l.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[l.step!==null?`STEP ${l.step}`:"STEP —",l.next?` - ${l.next}`:""]}),d&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:d,children:d})]})]},l.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null},hp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,LS=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Aa=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:v,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:N,checkpointIndexByKey:j,activeCheckpointId:$,onSelectCheckpoint:P,timelineCheckpoints:D,messagePreviews:F,createSyntheticThinkingMessage:A=!1},z)=>{const _=w.useRef(null),K=w.useRef(null),B=w.useRef(!1),[R,Y]=w.useState(!0),X=w.useMemo(()=>b?e.some(ie=>"type"in ie&&ie.type==="default_message"?!1:Array.isArray(ie==null?void 0:ie.content)&&ie.content.some(be=>be&&be.type==="interrupt"&&(be.id??be.interrupt_id)===b.id)):!1,[b,e]),se=w.useMemo(()=>{if(!b||X)return null;const ie=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let be;const je=b.value;if(je&&typeof je=="object"&&!Array.isArray(je)){const De=je.title;typeof De=="string"&&De.trim()&&(be=De.trim())}return{id:`interrupt-${ie}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:ie,value:je,title:be}]}},[b,X]),ve=w.useMemo(()=>se?[...e,se]:e,[e,se]),Oe=w.useMemo(()=>!A||!t?ve:!ve.some(be=>be.role==="assistant")&&ve.length>0?[...ve,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:ve,[ve,t,A]),q=w.useMemo(()=>T?Oe:Oe.filter(ie=>(ie==null?void 0:ie.role)!=="tool"),[Oe,T]),H=w.useMemo(()=>{const ie=new Set,be=[];for(let je=q.length-1;je>=0;je--){const De=q[je];if(!De)continue;if("type"in De&&De.type==="default_message"){be.push(De);continue}const Ue=De,Ge=LS(Ue);ie.has(Ge)||(ie.add(Ge),be.push(Ue))}return be.reverse()},[q]),J=w.useCallback(ie=>{Y(ie),v&&v(!ie),g&&g(ie)},[v,g]),L=w.useMemo(()=>{if(a)return async()=>{if(!B.current){B.current=!0;try{await a()}finally{B.current=!1}}}},[a]),G=w.useMemo(()=>!x||m?!1:R?"auto":!1,[R,x,m]),Z=D??[],fe=Z.length>0,re=w.useMemo(()=>{if(typeof h!="string")return null;const ie=h.trim();return ie?{id:"default-message",role:"assistant",type:"default_message",content:ie,createdAt:new Date().toISOString()}:null},[h]),Ae=fe?u.jsx(DS,{timelineEntries:Z,activeCheckpointId:$??null,onSelectCheckpoint:P,messagePreviews:F}):null,qe=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Fe=()=>re?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Na,{message:re,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),Je=H.length>0;return w.useImperativeHandle(z,()=>({scrollToLatest:()=>{var ie,be;if(_.current&&H.length>0){const je=H.length-1;(be=(ie=_.current).scrollToIndex)==null||be.call(ie,{index:je,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},scrollToTop:()=>{var ie,be;_.current&&H.length>0?(be=(ie=_.current).scrollToIndex)==null||be.call(ie,{index:0,align:"start",behavior:"auto"}):K.current&&(K.current.scrollTop=0)}}),[H]),u.jsxs("div",{className:qe,style:p,children:[Ae,u.jsx("div",{className:"relative flex-1 min-h-0",children:Je?u.jsx(w0,{ref:ie=>{_.current=ie},scrollerRef:ie=>{K.current=ie instanceof HTMLDivElement?ie:null},data:H,followOutput:G,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!0,startReached:()=>{L&&L()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(ie,be)=>hp(be,ie),itemContent:(ie,be)=>{var lt;const je=hp(be,ie),De="type"in be&&be.type==="default_message";let Ue=[],Ge=null,ze={},He={},Qe=null,Et=null;if(!De){const ft=be,pt=ft.checkpointId??null;ze=ft.additionalKwargs??{},He=ft.responseMetadata??{};const yt=pt&&N?N.get(pt)??null:null;Qe=typeof ze.step=="number"?ze.step:typeof He.step=="number"?He.step:(yt==null?void 0:yt.step)??null;const Nt=typeof ze.source=="string"?ze.source:typeof He.source=="string"?He.source:(yt==null?void 0:yt.source)??null;Et=Nt?String(Nt):null;const Ye=Qe!==null&&Et?`${Qe}:${Et}`:null;Ye&&(j!=null&&j.has(Ye))?Ue=j.get(Ye)??[]:pt&&yt&&(Ue=[yt]),Ge=pt??((lt=Ue[0])==null?void 0:lt.id)??null}const xt=(()=>{if(typeof ze.parentCheckpointId=="string")return ze.parentCheckpointId;if(typeof He.parentCheckpointId=="string")return He.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":je,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Na,{message:be,messageIndex:ie,isStreamingMessage:t&&n===be.id,streamingDebounceMs:r,isEditing:i===be.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(ie),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:E,checkpointCandidates:Ue,activeCheckpointId:$??null,onSelectCheckpoint:P,defaultCheckpointId:Ge,messageParentCheckpointId:xt})})}}):Fe()})]})});Aa.displayName="MessageList";const mp={value:""};function Os({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:v}=ai(),{currentThreadId:g}=Ao(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:N,checkpoints:j,interrupt:$,metadata:P,timelineCheckpoints:D,messagePreviews:F}=jo(),{isStreaming:A,error:z,connectionState:_,submit:K,stop:B}=uc(),R=b??g??null,Y=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,ve=$,[Oe,q]=w.useState(!1);w.useEffect(()=>{ve||q(!1)},[ve]);const H=w.useCallback(()=>{q(!0)},[]),J=w.useCallback(()=>{q(!1)},[]),L=!!ve||Oe,[G,Z]=w.useState(null),[fe,re]=w.useState(""),[Ae,qe]=w.useState(null),[Fe,Je]=w.useState(null),[ie,be]=w.useState([]),[je,De]=w.useState(0),[Ue,Ge]=w.useState(0),[ze,He]=w.useState(!1),[Qe,Et]=w.useState(null),[xt,lt]=w.useState(null),[ft,pt]=w.useState(!1),[yt,Nt]=w.useState(null),Ye=w.useRef(!1),[_t,Sn]=w.useState(()=>mp.value),et=w.useRef(_t),ot=w.useRef(null),bt=w.useCallback(ne=>{mp.value=ne,Sn(ne)},[]),[V,ce]=w.useState(!1),Ce=w.useRef(null),M=w.useCallback((ne,he)=>{if(!ne||typeof ne!="object")return null;const ae=ne[he];return typeof ae=="number"?ae:null},[]),Q=w.useCallback((ne,he)=>{if(!ne||typeof ne!="object")return null;const ae=ne[he];return typeof ae=="string"&&ae.trim()?ae:null},[]),oe=w.useMemo(()=>{const ne=Re=>{if(!Array.isArray(Re)||Re.length===0)return null;const ht=Re.map(vt=>{if(typeof vt=="string")return vt.trim();if(vt&&typeof vt=="object"&&"type"in vt){const An=vt;if(typeof An.type=="string")return An.type}return null}).filter(vt=>!!(vt&&vt.length));return ht.length?ht.join(", "):null},he=Array.isArray(j)?j.map(Re=>{const ht=ne(Re.next);return ht?{...Re,metadata:{...Re.metadata??{},next:ht}}:Re}):[];return he.some(Re=>M(Re.metadata,"step")!==null)&&he.sort((Re,ht)=>{const vt=M(Re.metadata,"step"),An=M(ht.metadata,"step");if(vt!==null||An!==null)return(An??Number.NEGATIVE_INFINITY)-(vt??Number.NEGATIVE_INFINITY);const co=Date.parse(Re.createdAt??""),uo=Date.parse(ht.createdAt??"");return Number.isNaN(co)||Number.isNaN(uo)?0:uo-co}),he},[j,M]),{checkpointMetaById:Le,checkpointIndexByKey:ge}=w.useMemo(()=>{const ne=new Map,he=new Map;for(const ae of oe){const Re=ae.checkpointId??null;if(!Re)continue;const ht=M(ae.metadata,"step"),vt=Q(ae.metadata,"source"),An={id:Re,step:ht,source:vt,createdAt:ae.createdAt??null,namespace:ae.checkpointNs??null,parentId:ae.parentId??null};if(ne.set(Re,An),ht!==null&&vt){const co=`${ht}:${vt}`,uo=he.get(co)??[];uo.push(An),he.set(co,uo)}}for(const ae of he.values())ae.sort((Re,ht)=>{const vt=Re.createdAt??"";return(ht.createdAt??"").localeCompare(vt)});return{checkpointMetaById:ne,checkpointIndexByKey:he}},[oe,M,Q]),ct=D??[],we=w.useRef(null),tt=w.useRef(null),rn=w.useCallback(()=>{we.current&&(we.current.value=""),tt.current&&(tt.current.value=""),De(ne=>ne+1),Ge(ne=>ne+1)},[]),Vs=w.useCallback(ne=>{bt(ne)},[bt]),lo=w.useRef(!1);w.useEffect(()=>{lo.current&&!A&&(be([]),rn()),lo.current=A},[A,rn]);const[Wa,Va]=w.useState("desktop");w.useEffect(()=>{const ne=()=>{const he=window.innerWidth;Va(he<640?"phone":he<1024?"tablet":"desktop")};return ne(),window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[]),w.useEffect(()=>{Ye.current=!1},[R]),w.useEffect(()=>{et.current=_t},[_t]),w.useEffect(()=>{if(!G){ot.current=null;return}ot.current===null&&(ot.current=et.current),bt(fe??"")},[fe,G,bt]),w.useEffect(()=>{(async()=>{if(!v.baseUrl){Nt(null);return}try{const ae=(await v.getAgent("default")).uiDefaultMessage||"";Nt(ae||null)}catch(he){console.warn("Failed to fetch default message:",he),Nt(null)}})()},[v.baseUrl]),w.useEffect(()=>{z&&!ft&&(m==null||m(z))},[z,ft,m]);const Ka=ne=>{if(ne.length>as)return`Message too long (${ne.length}/${as} characters)`;try{return dw(ne),null}catch(he){return(he==null?void 0:he.message)||"Invalid message"}},qa=async ne=>{const he=ne.trim();if(!(!he&&ie.length===0)){if(he){const ae=Ka(he);if(ae){Je(ae);return}}try{const ae=Y??void 0,Re=X??void 0,ht=G?{edit:!0,originalMessageId:G,...Ae!=null&&Ae.checkpointId?{originalCheckpointId:Ae.checkpointId}:{},...Ae!=null&&Ae.checkpointNs?{originalCheckpointNs:Ae.checkpointNs}:{}}:void 0;await K({text:he||"",attachments:ie,messageAdditionalKwargs:ht},{checkpointId:ae,checkpointNs:Re}),h==null||h(he),bt(""),Je(null),be([]),rn(),Z(null),re(""),qe(null)}catch(ae){const Re=(ae==null?void 0:ae.message)||"Failed to send message";Je(Re),m==null||m(Re)}}},I=w.useCallback((ne,he,ae)=>{c&&(ot.current=_t,Z(ne),re(he),bt(he),Je(null),qe({checkpointId:(ae==null?void 0:ae.checkpointId)??null,checkpointNs:(ae==null?void 0:ae.checkpointNs)??null}))},[_t,c,bt]),W=w.useCallback(()=>{Z(null),re(""),qe(null),Je(null),bt(ot.current??_t),ot.current=null},[_t,bt]),ue=w.useCallback((ne,he,ae)=>{I(ne,he,ae)},[I]),ke=w.useCallback(ne=>{for(let he=ne-1;he>=0;he--)if(S[he].role==="user"){const ae=S[he].content||[],ht=ae.filter(vt=>vt.type==="text").map(vt=>vt.text).join("")||(()=>{try{return JSON.stringify(ae,null,2)}catch{return String(ae)}})();ht&&K({text:ht},{checkpointId:Y??void 0,checkpointNs:X??void 0});break}},[S,K,Y,X]),Ze=ne=>{const he=Array.from(ne.target.files||[]);be(ae=>[...ae,...he]),ne.target.value=""},st=ne=>{be(he=>{const ae=he.filter((Re,ht)=>ne!==ht);return ae.length===0&&rn(),ae})},We=async ne=>{const he=(ne.target.files||[])[0];if(he){Et(null),lt(null),He(!0);try{await K({attachments:[he]},{checkpointId:Y??void 0,checkpointNs:X??void 0});const ae=`Uploaded ${he.name} - processing through chat stream`;lt(ae)}catch(ae){const Re=ae instanceof Error?ae.message:"Failed to upload Excel file";console.error("Excel upload failed",ae),Et(Re),m==null||m(Re)}finally{He(!1),ne.target.value="",rn()}}},Be=async ne=>{if(g){ce(!0);try{if(!ne){await E(),requestAnimationFrame(()=>{var Re;(Re=Ce.current)==null||Re.scrollToLatest()});return}const he=oe.find(Re=>Re.checkpointId===ne),ae=(he==null?void 0:he.checkpointNs)??null;await T(ne,ae),requestAnimationFrame(()=>{var Re;(Re=Ce.current)==null||Re.scrollToTop()})}finally{ce(!1)}}},Rt=w.useCallback(async ne=>{await Be(ne)},[Be]),wt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,St=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,Ut=`flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return w.useCallback(ne=>{if(!ne)return"Latest";const he=[];ne.step!==null&&he.push(`Step ${ne.step}`),ne.source&&he.push(ne.source);const ae=ne.createdAt?new Date(ne.createdAt):null,Re=ae&&!Number.isNaN(ae.getTime())?ae.toLocaleString():ne.createdAt??ne.id,ht=he.length?` — ${he.join(" • ")}`:"";return`${Re}${ht}`},[]),u.jsxs("div",{className:wt,children:[!!z&&!ft&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:z}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>pt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${St}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Aa,{ref:Ce,className:"h-full",style:{height:"100%"},messages:S,isStreaming:A,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Wa,enableMessageEditing:c,editingMessageId:G,onEdit:ue,onRegenerate:ke,onCancelEdit:W,emptyMessage:yt??void 0,isNavigatingCheckpoint:V,activeInterrupt:ve,disableInterruptActions:Oe,onInterruptActionStart:H,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:Le,checkpointIndexByKey:ge,activeCheckpointId:Y,onSelectCheckpoint:Rt,timelineCheckpoints:ct,messagePreviews:F}),(_==="reconnecting"||_==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(le.Loader2,{className:"h-3 w-3 animate-spin"}),_==="reconnecting"?"Reconnecting…":"Connecting…"]})}),_==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||V)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:Ut,children:[G&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:W,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:we,type:"file",multiple:!0,onChange:ne=>Ze(ne),className:"hidden"},je),ie.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:ie.map((ne,he)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ne.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>st(he),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 ${ne.name}`,children:u.jsx(le.X,{size:12})})]},he))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:tt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:We,className:"hidden"},Ue),ze&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!ze&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),Qe&&!ze&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Fe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Fe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(tw,{children:[u.jsx(nw,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:A||L,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(wd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Yi,{onClick:()=>{var ne;return(ne=we.current)==null?void 0:ne.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Yi,{onClick:()=>{var ne;ze||(ne=tt.current)==null||ne.click()},className:`cursor-pointer ${ze?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(nx,{initialValue:fe,editingMessageId:G,value:_t,onValueChange:Vs,placeholder:G?"Edit your message...":t,isStreaming:A,disabled:L,maxLength:as,onSend:qa,onCancelEdit:W,onStop:B,allowEmptySend:ie.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${G?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Fe?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Ms=y.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Ms.displayName="Input";function ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function $S(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var _a="ScrollArea",[gp,ET]=Tn(_a),[FS,tn]=gp(_a),xp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=y.useState(null),[c,d]=y.useState(null),[f,p]=y.useState(null),[h,x]=y.useState(null),[m,v]=y.useState(null),[g,b]=y.useState(0),[S,k]=y.useState(0),[C,T]=y.useState(!1),[E,N]=y.useState(!1),j=Ve(t,P=>l(P)),$=Ro(o);return u.jsx(FS,{scope:n,type:r,dir:$,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(_e.div,{dir:$,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});xp.displayName=_a;var yp="ScrollAreaViewport",vp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=tn(yp,n),a=y.useRef(null),l=Ve(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});vp.displayName=yp;var wn="ScrollAreaScrollbar",Ra=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return y.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(zS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(BS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(bp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Pa,{...r,ref:t}):null});Ra.displayName=wn;var zS=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,e.__scopeScrollArea),[s,i]=y.useState(!1);return y.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Jt,{present:n||s,children:u.jsx(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),BS=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Fs(()=>l("SCROLL_END"),100),[a,l]=$S("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return y.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),y.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Jt,{present:n||a!=="hidden",children:u.jsx(Pa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:me(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:me(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=y.forwardRef((e,t)=>{const n=tn(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=y.useState(!1),a=e.orientation==="horizontal",l=Fs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Cr(n.viewport,l),Cr(n.content,l),u.jsx(Jt,{present:r||s,children:u.jsx(Pa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Pa=y.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=tn(wn,e.__scopeScrollArea),s=y.useRef(null),i=y.useRef(0),[a,l]=y.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=kp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return qS(p,i.current,a,h)}return n==="horizontal"?u.jsx(HS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Ep(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(US,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Ep(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),HS=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(wn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=Ve(t,l,s.onScrollbarXChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Sp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":$s(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Np(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ls(i.paddingLeft),paddingEnd:Ls(i.paddingRight)}})}})}),US=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(wn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=Ve(t,l,s.onScrollbarYChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Sp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":$s(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Np(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ls(i.paddingTop),paddingEnd:Ls(i.paddingBottom)}})}})}),[WS,wp]=gp(wn),Sp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=tn(wn,n),[x,m]=y.useState(null),v=Ve(t,j=>m(j)),g=y.useRef(null),b=y.useRef(""),S=h.viewport,k=r.content-r.viewport,C=jt(d),T=jt(l),E=Fs(f,10);function N(j){if(g.current){const $=j.clientX-g.current.left,P=j.clientY-g.current.top;c({x:$,y:P})}}return y.useEffect(()=>{const j=$=>{const P=$.target;(x==null?void 0:x.contains(P))&&C($,k)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,x,k,C]),y.useEffect(T,[r,T]),Cr(x,E),Cr(h.content,E),u.jsx(WS,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:jt(s),onThumbPointerUp:jt(i),onThumbPositionChange:T,onThumbPointerDown:jt(a),children:u.jsx(_e.div,{...p,ref:v,style:{position:"absolute",...p.style},onPointerDown:me(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(j))}),onPointerMove:me(e.onPointerMove,N),onPointerUp:me(e.onPointerUp,j=>{const $=j.target;$.hasPointerCapture(j.pointerId)&&$.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Ds="ScrollAreaThumb",Cp=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wp(Ds,e.__scopeScrollArea);return u.jsx(Jt,{present:n||o.hasThumb,children:u.jsx(VS,{ref:t,...r})})}),VS=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=tn(Ds,n),i=wp(Ds,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),c=y.useRef(void 0),d=Fs(()=>{c.current&&(c.current(),c.current=void 0)},100);return y.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=GS(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(_e.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:me(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:me(e.onPointerUp,i.onThumbPointerUp)})});Cp.displayName=Ds;var Oa="ScrollAreaCorner",Tp=y.forwardRef((e,t)=>{const n=tn(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(KS,{...e,ref:t}):null});Tp.displayName=Oa;var KS=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=tn(Oa,n),[s,i]=y.useState(0),[a,l]=y.useState(0),c=!!(s&&a);return Cr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Cr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_e.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 Ls(e){return e?parseInt(e,10):0}function kp(e,t){const n=e/t;return isNaN(n)?0:n}function $s(e){const t=kp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function qS(e,t,n,r="ltr"){const o=$s(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ip([l,c],f)(e)}function Ep(e,t,n="ltr"){const r=$s(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=ja(e,l);return Ip([0,i],[0,a])(c)}function Ip(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Np(e,t){return e>0&&e<t}var GS=(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 Fs(e,t){const n=jt(e),r=y.useRef(0);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),y.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Cr(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 Ap=xp,YS=vp,XS=Tp;const jp=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ap,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(YS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(_p,{}),u.jsx(XS,{})]}));jp.displayName=Ap.displayName;const _p=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ra,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Cp,{className:"relative flex-1 rounded-full bg-border"})}));_p.displayName=Ra.displayName;const Rp=25;function Ma({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=Ao(),{loadThread:v}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),E=w.useRef(null),N=w.useRef(0),[j,$]=w.useState(null),[P,D]=w.useState(""),[F,A]=w.useState(!1);w.useEffect(()=>{const q=Array.isArray(f)?f:[];if(q.length>0){T.current=!0,C(q);return}x||(T.current=!1,C(q))},[f,x]),w.useEffect(()=>{if(!E.current)return;const q=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!q)return;let H=null,J=null;return H=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{q.scrollTop=N.current})}),()=>{H!==null&&cancelAnimationFrame(H),J!==null&&cancelAnimationFrame(J)}},[k]);const z=async q=>{try{h(q),await v(q),a==null||a(q),l==null||l(q)}catch(H){console.error("Failed to select thread:",H)}},_=async()=>{try{A(!0);const q=await g();q&&(c==null||c(q),a==null||a(q))}catch(q){console.error("Failed to create thread:",q)}finally{A(!1)}},K=async(q,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const J=E.current.querySelector("[data-radix-scroll-area-viewport]");J&&(N.current=J.scrollTop)}try{await b(q),d==null||d(q)}catch(J){console.error("Failed to delete thread:",J)}}},B=(q,H)=>{H.stopPropagation(),$(q.threadId),D(q.title||`Thread ${q.threadId.slice(0,8)}`)},R=async q=>{if(P.trim())try{await S(q,P.trim()),$(null),D("")}catch(H){console.error("Failed to update title:",H)}},Y=()=>{$(null),D("")},X=(q,H)=>{q.key==="Enter"?R(H):q.key==="Escape"&&Y()},se=q=>{if(!q)return"";try{const H=new Date(q),L=new Date().getTime()-H.getTime(),G=Math.floor(L/(1e3*60*60*24));return G===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):G===1?"Yesterday":G<7?`${G} days ago`:H.toLocaleDateString()}catch{return""}},ve=q=>q.title||`Thread ${q.threadId.slice(0,8)}`,Oe=q=>{const H=ve(q);return H.length<=Rp?H:`${H.slice(0,Rp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(nt,{onClick:_,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(jp,{ref:E,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(le.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((q,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>z(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===q.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[u.jsx(Ms,{value:P,onChange:H=>D(H.target.value),onKeyDown:H=>X(H,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>R(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:Y,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Oe(q)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:se(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==q.threadId&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:H=>B(q,H),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:H=>K(q.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(le.Trash2,{size:12})})]})]}),i===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}function Tr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function JS(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function Pp(){const e=[Tr("__API_BASE_URL__"),Tr("__CHAT_API_BASE_URL__"),Tr("__CHAT_API_URL__")];for(const t of e){const n=JS(t);if(n)return n}}function Op(){const e=[Tr("__API_AUTH_TOKEN__"),Tr("__CHAT_API_KEY__"),Tr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Mp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Dp(){const e={},t=Pp(),n=Op();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Lp(){const e=Dp(),t=jn.getAuthToken(),n=Pp();return{apiBaseUrl:Mp(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||Op()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const $p="chat-settings";function ZS(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function QS(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function eC(){const e=Lp(),t=ZS(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Mp(jn.baseUrl,r,e.apiBaseUrl)}}function tC(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),QS(e)}var nC="Label",Fp=y.forwardRef((e,t)=>u.jsx(_e.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())}}));Fp.displayName=nC;var zp=Fp;const rC=fo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),nn=y.forwardRef(({className:e,...t},n)=>u.jsx(zp,{ref:n,className:te(rC(),e),...t}));nn.displayName=zp.displayName;function Bp(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var zs="Switch",[oC,IT]=Tn(zs),[sC,iC]=oC(zs),Hp=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=y.useState(null),x=Ve(t,S=>h(S)),m=y.useRef(!1),v=p?d||!!p.closest("form"):!0,[g,b]=dr({prop:o,defaultProp:s??!1,onChange:c,caller:zs});return u.jsxs(sC,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Kp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:me(e.onClick,S=>{b(k=>!k),v&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),v&&u.jsx(Vp,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Hp.displayName=zs;var Up="SwitchThumb",Wp=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=iC(Up,n);return u.jsx(_e.span,{"data-state":Kp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Wp.displayName=Up;var aC="SwitchBubbleInput",Vp=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=y.useRef(null),a=Ve(i,s),l=Bp(n),c=Gc(t);return y.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const x=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Vp.displayName=aC;function Kp(e){return e?"checked":"unchecked"}var qp=Hp,lC=Wp;const zn=y.forwardRef(({className:e,...t},n)=>u.jsx(qp,{className:te("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(lC,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));zn.displayName=qp.displayName;var Gp=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"}),cC="VisuallyHidden",uC=y.forwardRef((e,t)=>u.jsx(_e.span,{...e,ref:t,style:{...Gp,...e.style}}));uC.displayName=cC;var dC=[" ","Enter","ArrowUp","ArrowDown"],fC=[" ","Enter"],rr="Select",[Bs,Hs,pC]=hi(rr),[kr,NT]=Tn(rr,[pC,Vo]),Us=Vo(),[hC,Bn]=kr(rr),[mC,gC]=kr(rr),Yp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Us(t),[v,g]=y.useState(null),[b,S]=y.useState(null),[k,C]=y.useState(!1),T=Ro(c),[E,N]=dr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[j,$]=dr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=y.useRef(null),D=v?x||!!v.closest("form"):!0,[F,A]=y.useState(new Set),z=Array.from(F).map(_=>_.props.value).join(";");return u.jsx(ou,{...m,children:u.jsxs(hC,{required:h,scope:t,trigger:v,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:kn(),value:j,onValueChange:$,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Bs.Provider,{scope:t,children:u.jsx(mC,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(_=>{A(K=>new Set(K).add(_))},[]),onNativeOptionRemove:y.useCallback(_=>{A(K=>{const B=new Set(K);return B.delete(_),B})},[]),children:n})}),D?u.jsxs(vh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:_=>$(_.target.value),disabled:p,form:x,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},z):null]})})};Yp.displayName=rr;var Xp="SelectTrigger",Jp=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Us(n),i=Bn(Xp,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),c=Hs(n),d=y.useRef("touch"),[f,p,h]=wh(m=>{const v=c().filter(S=>!S.disabled),g=v.find(S=>S.value===i.value),b=Sh(v,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(su,{asChild:!0,...s,children:u.jsx(_e.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":bh(i.value)?"":void 0,...o,ref:l,onClick:me(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:me(o.onPointerDown,m=>{d.current=m.pointerType;const v=m.target;v.hasPointerCapture(m.pointerId)&&v.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:me(o.onKeyDown,m=>{const v=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(v&&m.key===" ")&&dC.includes(m.key)&&(x(),m.preventDefault())})})})});Jp.displayName=Xp;var Zp="SelectValue",Qp=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Zp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ve(t,l.onValueNodeChange);return At(()=>{c(d)},[c,d]),u.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:bh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Qp.displayName=Zp;var xC="SelectIcon",eh=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});eh.displayName=xC;var yC="SelectPortal",th=e=>u.jsx(Ko,{asChild:!0,...e});th.displayName=yC;var or="SelectContent",nh=y.forwardRef((e,t)=>{const n=Bn(or,e.__scopeSelect),[r,o]=y.useState();if(At(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?po.createPortal(u.jsx(rh,{scope:e.__scopeSelect,children:u.jsx(Bs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(oh,{...e,ref:t})});nh.displayName=or;var dn=10,[rh,Hn]=kr(or),vC="SelectContentImpl",bC=Un.createSlot("SelectContent.RemoveScroll"),oh=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:v,...g}=e,b=Bn(or,n),[S,k]=y.useState(null),[C,T]=y.useState(null),E=Ve(t,J=>k(J)),[N,j]=y.useState(null),[$,P]=y.useState(null),D=Hs(n),[F,A]=y.useState(!1),z=y.useRef(!1);y.useEffect(()=>{if(S)return Di(S)},[S]),xi();const _=y.useCallback(J=>{const[L,...G]=D().map(re=>re.ref.current),[Z]=G.slice(-1),fe=document.activeElement;for(const re of J)if(re===fe||(re==null||re.scrollIntoView({block:"nearest"}),re===L&&C&&(C.scrollTop=0),re===Z&&C&&(C.scrollTop=C.scrollHeight),re==null||re.focus(),document.activeElement!==fe))return},[D,C]),K=y.useCallback(()=>_([N,S]),[_,N,S]);y.useEffect(()=>{F&&K()},[F,K]);const{onOpenChange:B,triggerPointerDownPosRef:R}=b;y.useEffect(()=>{if(S){let J={x:0,y:0};const L=Z=>{var fe,re;J={x:Math.abs(Math.round(Z.pageX)-(((fe=R.current)==null?void 0:fe.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((re=R.current)==null?void 0:re.y)??0))}},G=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||B(!1),document.removeEventListener("pointermove",L),R.current=null};return R.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",G,{capture:!0})}}},[S,B,R]),y.useEffect(()=>{const J=()=>B(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[B]);const[Y,X]=wh(J=>{const L=D().filter(fe=>!fe.disabled),G=L.find(fe=>fe.ref.current===document.activeElement),Z=Sh(L,J,G);Z&&setTimeout(()=>Z.ref.current.focus())}),se=y.useCallback((J,L,G)=>{const Z=!z.current&&!G;(b.value!==void 0&&b.value===L||Z)&&(j(J),Z&&(z.current=!0))},[b.value]),ve=y.useCallback(()=>S==null?void 0:S.focus(),[S]),Oe=y.useCallback((J,L,G)=>{const Z=!z.current&&!G;(b.value!==void 0&&b.value===L||Z)&&P(J)},[b.value]),q=r==="popper"?Da:sh,H=q===Da?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:v}:{};return u.jsx(rh,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:N,onItemLeave:ve,itemTextRefCallback:Oe,focusSelectedItem:K,selectedItemText:$,position:r,isPositioned:F,searchRef:Y,children:u.jsx(ts,{as:bC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:me(o,J=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(q,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...g,...H,onPlaced:()=>A(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:me(g.onKeyDown,J=>{const L=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!L&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=D().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const fe=J.target,re=Z.indexOf(fe);Z=Z.slice(re+1)}setTimeout(()=>_(Z)),J.preventDefault()}})})})})})})});oh.displayName=vC;var wC="SelectItemAlignedPosition",sh=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(or,n),i=Hn(or,n),[a,l]=y.useState(null),[c,d]=y.useState(null),f=Ve(t,E=>d(E)),p=Hs(n),h=y.useRef(!1),x=y.useRef(!0),{viewport:m,selectedItem:v,selectedItemText:g,focusSelectedItem:b}=i,S=y.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&v&&g){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),$=g.getBoundingClientRect();if(s.dir!=="rtl"){const fe=$.left-N.left,re=j.left-fe,Ae=E.left-re,qe=E.width+Ae,Fe=Math.max(qe,N.width),Je=window.innerWidth-dn,ie=ja(re,[dn,Math.max(dn,Je-Fe)]);a.style.minWidth=qe+"px",a.style.left=ie+"px"}else{const fe=N.right-$.right,re=window.innerWidth-j.right-fe,Ae=window.innerWidth-E.right-re,qe=E.width+Ae,Fe=Math.max(qe,N.width),Je=window.innerWidth-dn,ie=ja(re,[dn,Math.max(dn,Je-Fe)]);a.style.minWidth=qe+"px",a.style.right=ie+"px"}const P=p(),D=window.innerHeight-dn*2,F=m.scrollHeight,A=window.getComputedStyle(c),z=parseInt(A.borderTopWidth,10),_=parseInt(A.paddingTop,10),K=parseInt(A.borderBottomWidth,10),B=parseInt(A.paddingBottom,10),R=z+_+F+B+K,Y=Math.min(v.offsetHeight*5,R),X=window.getComputedStyle(m),se=parseInt(X.paddingTop,10),ve=parseInt(X.paddingBottom,10),Oe=E.top+E.height/2-dn,q=D-Oe,H=v.offsetHeight/2,J=v.offsetTop+H,L=z+_+J,G=R-L;if(L<=Oe){const fe=P.length>0&&v===P[P.length-1].ref.current;a.style.bottom="0px";const re=c.clientHeight-m.offsetTop-m.offsetHeight,Ae=Math.max(q,H+(fe?ve:0)+re+K),qe=L+Ae;a.style.height=qe+"px"}else{const fe=P.length>0&&v===P[0].ref.current;a.style.top="0px";const Ae=Math.max(Oe,z+m.offsetTop+(fe?se:0)+H)+G;a.style.height=Ae+"px",m.scrollTop=L-Oe+m.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=Y+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,v,g,s.dir,r]);At(()=>S(),[S]);const[k,C]=y.useState();At(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=y.useCallback(E=>{E&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(CC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});sh.displayName=wC;var SC="SelectPopperPosition",Da=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Us(n);return u.jsx(iu,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Da.displayName=SC;var[CC,La]=kr(or,{}),$a="SelectViewport",ih=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Hn($a,n),i=La($a,n),a=Ve(t,s.onViewportChange),l=y.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Bs.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:me(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-dn*2,m=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),g=Math.max(m,v);if(g<x){const b=g+h,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});ih.displayName=$a;var ah="SelectGroup",[TC,kC]=kr(ah),EC=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return u.jsx(TC,{scope:n,id:o,children:u.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});EC.displayName=ah;var lh="SelectLabel",ch=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kC(lh,n);return u.jsx(_e.div,{id:o.id,...r,ref:t})});ch.displayName=lh;var Ws="SelectItem",[IC,uh]=kr(Ws),dh=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(Ws,n),l=Hn(Ws,n),c=a.value===r,[d,f]=y.useState(s??""),[p,h]=y.useState(!1),x=Ve(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=kn(),v=y.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(IC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:y.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Bs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:me(i.onFocus,()=>h(!0)),onBlur:me(i.onBlur,()=>h(!1)),onClick:me(i.onClick,()=>{v.current!=="mouse"&&g()}),onPointerUp:me(i.onPointerUp,()=>{v.current==="mouse"&&g()}),onPointerDown:me(i.onPointerDown,b=>{v.current=b.pointerType}),onPointerMove:me(i.onPointerMove,b=>{var S;v.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):v.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:me(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:me(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(fC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});dh.displayName=Ws;var ao="SelectItemText",fh=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(ao,n),a=Hn(ao,n),l=uh(ao,n),c=gC(ao,n),[d,f]=y.useState(null),p=Ve(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,x=y.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:v}=c;return At(()=>(m(x),()=>v(x)),[m,v,x]),u.jsxs(u.Fragment,{children:[u.jsx(_e.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?po.createPortal(s.children,i.valueNode):null]})});fh.displayName=ao;var ph="SelectItemIndicator",hh=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return uh(ph,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});hh.displayName=ph;var Fa="SelectScrollUpButton",mh=y.forwardRef((e,t)=>{const n=Hn(Fa,e.__scopeSelect),r=La(Fa,e.__scopeSelect),[o,s]=y.useState(!1),i=Ve(t,r.onScrollButtonChange);return At(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});mh.displayName=Fa;var za="SelectScrollDownButton",gh=y.forwardRef((e,t)=>{const n=Hn(za,e.__scopeSelect),r=La(za,e.__scopeSelect),[o,s]=y.useState(!1),i=Ve(t,r.onScrollButtonChange);return At(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(xh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});gh.displayName=za;var xh=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Hn("SelectScrollButton",n),i=y.useRef(null),a=Hs(n),l=y.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return y.useEffect(()=>()=>l(),[l]),At(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:me(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:me(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:me(o.onPointerLeave,()=>{l()})})}),NC="SelectSeparator",yh=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});yh.displayName=NC;var Ba="SelectArrow",AC=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Us(n),s=Bn(Ba,n),i=Hn(Ba,n);return s.open&&i.position==="popper"?u.jsx(au,{...o,...r,ref:t}):null});AC.displayName=Ba;var jC="SelectBubbleInput",vh=y.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=y.useRef(null),s=Ve(r,o),i=Bp(t);return y.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(_e.select,{...n,style:{...Gp,...n.style},ref:s,defaultValue:t})});vh.displayName=jC;function bh(e){return e===""||e===void 0}function wh(e){const t=jt(e),n=y.useRef(""),r=y.useRef(0),o=y.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=y.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Sh(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=_C(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function _C(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var RC=Yp,Ch=Jp,PC=Qp,OC=eh,MC=th,Th=nh,DC=ih,kh=ch,Eh=dh,LC=fh,$C=hh,Ih=mh,Nh=gh,Ah=yh;const jh=RC,_h=PC,Ha=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ch,{ref:r,className:te("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(OC,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=Ch.displayName;const Rh=y.forwardRef(({className:e,...t},n)=>u.jsx(Ih,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));Rh.displayName=Ih.displayName;const Ph=y.forwardRef(({className:e,...t},n)=>u.jsx(Nh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));Ph.displayName=Nh.displayName;const Ua=y.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(MC,{children:u.jsxs(Th,{ref:o,className:te("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Rh,{}),u.jsx(DC,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ph,{})]})}));Ua.displayName=Th.displayName;const FC=y.forwardRef(({className:e,...t},n)=>u.jsx(kh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));FC.displayName=kh.displayName;const sr=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Eh,{ref:r,className:te("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx($C,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(LC,{children:t})]}));sr.displayName=Eh.displayName;const zC=y.forwardRef(({className:e,...t},n)=>u.jsx(Ah,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));zC.displayName=Ah.displayName;var BC="Separator",Oh="horizontal",HC=["horizontal","vertical"],Mh=y.forwardRef((e,t)=>{const{decorative:n,orientation:r=Oh,...o}=e,s=UC(r)?r:Oh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Mh.displayName=BC;function UC(e){return HC.includes(e)}var Dh=Mh;const Lh=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Dh,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Lh.displayName=Dh.displayName;const WC=Wf,VC=tS,KC=Vf,$h=y.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));$h.displayName=Es.displayName;const qC=fo.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"}}),Fh=y.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(KC,{children:[u.jsx($h,{}),u.jsxs(Is,{ref:o,className:te(qC({side:e}),t),...r,children:[n,u.jsxs(Kf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Fh.displayName=Is.displayName;const zh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});zh.displayName="SheetHeader";const Bh=y.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Bh.displayName=tr.displayName;const Hh=y.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Hh.displayName=Ns.displayName;const GC={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 YC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=wa();w.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);d(v)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(GC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(WC,{open:r,onOpenChange:o,children:[u.jsx(VC,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(wf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Fh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(zh,{children:[u.jsx(Bh,{children:"Chat Settings"}),u.jsx(Hh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Qr,{children:[u.jsx(eo,{className:"pb-3",children:u.jsxs(to,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(no,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ms,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(g=>({...g,api:{...g.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(nt,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(zn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(g=>({...g,api:{...g.api,enableAuth:v}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ms,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(g=>({...g,api:{...g.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Qr,{children:[u.jsx(eo,{className:"pb-3",children:u.jsxs(to,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(no,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(jh,{value:a.ui.layout,onValueChange:v=>l(g=>({...g,ui:{...g.ui,layout:v}})),children:[u.jsx(Ha,{children:u.jsx(_h,{})}),u.jsxs(Ua,{children:[u.jsx(sr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(sr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"theme",children:"Theme"}),u.jsxs(jh,{value:a.ui.theme,onValueChange:v=>l(g=>({...g,ui:{...g.ui,theme:v}})),children:[u.jsx(Ha,{children:u.jsx(_h,{})}),u.jsxs(Ua,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Lh,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(zn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showTimestamps:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(zn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showAgentNames:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,compactMessages:v}}))})]})]})]})]}),u.jsxs(Qr,{children:[u.jsx(eo,{className:"pb-3",children:u.jsxs(to,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(no,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(zn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,autoSave:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(zn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(zn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:v}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(nt,{variant:"outline",onClick:h,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function XC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(_o,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Os,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(_o,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Ma,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Os,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(_o,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Ma,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Os,{onError:s.onError,enableFileUpload:!0})})]})})}Ee.ChatApi=Hl,Ee.ChatInput=fc,Ee.ChatInterface=Os,Ee.ChatProviders=_o,Ee.ChatSettings=YC,Ee.MarkdownContent=io,Ee.MessageComponent=Na,Ee.MessageList=Aa,Ee.ThreadManager=Ma,Ee.applySettings=tC,Ee.buildMessagePreviewMap=Xl,Ee.chatApiClient=jn,Ee.default=XC,Ee.del=Bl,Ee.get=Yt,Ee.getChatToken=$l,Ee.getCurrentSettings=eC,Ee.getDefaultApiConfig=Dp,Ee.getDefaultChatSettings=Lp,Ee.onChatTokenChanged=Fl,Ee.post=ii,Ee.put=zl,Ee.setChatToken=ko,Ee.useApi=ai,Ee.useChatStream=Jl,Ee.useMessagesReducer=Zl,Ee.useStream=uc,Ee.useThreadState=jo,Ee.useThreads=Ao,Object.defineProperties(Ee,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
133
+ `}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=rp(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=rp(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 lp{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 cp{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 zn{constructor(t){this.options=t||rr,this.options.renderer=this.options.renderer||new Aa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new lp,this.slugger=new cp}static parse(t,n){return new zn(n).parse(t)}static parseInline(t,n){return new zn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,x,m,v,g,b,S,k,C,T;const E=t.length;for(o=0;o<E;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,np(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(x=h.ordered,m=h.start,v=h.loose,a=h.items.length,p="",s=0;s<a;s++)b=h.items[s],S=b.checked,k=b.task,g="",b.task&&(C=this.renderer.checkbox(S),v?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):g+=C),g+=this.parse(b.tokens,v),p+=this.renderer.listitem(g,k,S);r+=this.renderer.list(p,x,m);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<E&&t[o+1].type==="text";)h=t[++o],p+=`
134
+ `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ps{constructor(t){this.options=t||rr}preprocess(t){return t}postprocess(t){return t}}Wh(Ps,"passThroughHooks",new Set(["preprocess","postprocess"]));function IS(e,t,n){return r=>{if(r.message+=`
135
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Dt(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 up(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ve.defaults,...s};const i=IS(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(TS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&ve.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ve.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(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 up(Fn.lex,zn.parse)(e,t,n)}ve.options=ve.setOptions=function(e){return ve.defaults={...ve.defaults,...e},dS(ve.defaults),ve},ve.getDefaults=Zf,ve.defaults=rr,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 Aa;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=ve.defaults.tokenizer||new Na;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 Ps;for(const s in n.hooks){const i=o[s];Ps.passThroughHooks.has(s)?o[s]=a=>{if(ve.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=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=up(Fn.lexInline,zn.parseInline),ve.Parser=zn,ve.parser=zn.parse,ve.Renderer=Aa,ve.TextRenderer=lp,ve.Lexer=Fn,ve.lexer=Fn.lex,ve.Tokenizer=Na,ve.Slugger=cp,ve.Hooks=Ps,ve.parse=ve,ve.options,ve.setOptions,ve.use,ve.walkTokens,ve.parseInline,zn.parse,Fn.lex;function ao({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 u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const NS="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 AS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function dp(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 Os(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function _S(e){const t=o=>{try{const s=so(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
136
+ `)):r=t(e),r||""}function jS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function fp(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 pp(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function RS(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function PS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=typeof t=="string"&&t.length>0;if(!o&&!s)return null;const i=o?`data:${pp(n)};base64,${e}`:t;Jt()&&console.debug("[MessageComponent] Created artifact preview source:",{srcLength:i.length,srcPreview:i.substring(0,100),mimeType:pp(n)});const a=RS(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function OS(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 Jt()&&console.debug("[MessageComponent] Processing plot:",{hasBase64:!!t,base64Length:t==null?void 0:t.length,hasUrl:!!n,formatHint:r,plotId:e.plotId,artifactId:e.artifactId}),PS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function MS({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const _a=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:v,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:$=null}){const[P,D]=w.useState(!1),[F,A]=w.useState("preview"),[z,j]=w.useState(!1),{currentThreadId:K}=_o(),{respondToInterrupt:B}=jo(),R=l==="phone"||l==="half-screen",Y=t.role,X=Y==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),be=!!se,Oe=!(r&&Y!=="user"),{uploadingFiles:q,handleFileClick:H,fileViewerOpen:J,currentFileInfo:L,closeFileViewer:G}=LS({allowFileOpen:Oe,currentThreadId:K}),Z=w.useMemo(()=>{switch(Y){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))]"}},[Y]),fe=w.useMemo(()=>se?"":AS(t.content),[se,t]),oe=w.useMemo(()=>se?{}:dp(t),[se,t]),Ae=w.useMemo(()=>se?[]:t.content.filter(O=>O.type==="image_url"),[se,t]),qe=w.useMemo(()=>se?[]:t.content.filter(O=>O.type==="file"),[se,t]),Fe=w.useMemo(()=>se?[]:t.content.filter(O=>O.type==="interrupt"),[se,t]),Ze=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),ie=Os(Ze),we=b==null?void 0:b.value,_e=w.useMemo(()=>se?"":_S(t.content),[se,t]),Le=w.useMemo(()=>{var ge;if(se||!p)return[];const O=t,Q=O.artifact;if(Jt()&&console.debug("[MessageComponent] Artifact check:",{messageId:O.id,messageRole:O.role,hasArtifact:!!Q,artifactKeys:Q?Object.keys(Q):[],artifactPlots:Q==null?void 0:Q.plots}),!Q)return[];const re=[],Me=[...Array.isArray(Q.plots)?Q.plots:[]];Jt()&&console.debug("[MessageComponent] Artifact processing:",{artifactPlots:((ge=Q.plots)==null?void 0:ge.length)??0,totalPlots:Me.length,plotEntries:Me.map(Xe=>{var xe;return{hasBase64:!!Xe.content_base64,base64Len:((xe=Xe.content_base64)==null?void 0:xe.length)??0,format:Xe.format}})});for(const Xe of Me){const xe=OS(Xe);xe&&re.push(xe)}return Jt()&&console.debug("[MessageComponent] Artifact previews result:",{inputPlots:Me.length,outputPreviews:re.length,previews:re.map(Xe=>{var xe;return{src:(xe=Xe.src)==null?void 0:xe.substring(0,100),alt:Xe.alt,label:Xe.label}})}),re},[se,t,p]),Ue=w.useCallback(async()=>{const O=X?_e:fe;async function Q(re){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(re);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Me=new Blob([re],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Me})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(O),D(!0),setTimeout(()=>D(!1),2e3),g==null||g(O)}catch(re){console.error("Failed to copy:",re)}},[X,_e,fe,g]),Ge=w.useCallback(()=>{if(!x)return;const O=X?_e:fe,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,O,Q)},[x,t.id,X,_e,fe,t]),ze=w.useCallback(()=>{m==null||m(n)},[m,n]),He=w.useCallback(()=>{const Q=te(R?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(Y){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[R,Z,Y]),et=w.useCallback(()=>{const O="group relative mb-4 flex w-full";switch(Y){case"user":return te(O,"justify-end");case"assistant":case"tool":case"system":return te(O,"justify-start");default:return O}},[Y]),Et=w.useCallback(()=>{const O=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",R&&"px-3 py-2 text-sm");if(be)return te(O,"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(Y){case"user":return te(O,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(O,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(O,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(O,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(O,"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")}},[R,be,Y]);if(be&&se)return u.jsx("div",{className:te(et(),h.container),children:u.jsxs("div",{className:te(Et(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(ao,{content:se.content,className:"text-current"})]})});const xt=w.useCallback(async O=>{if(S)return;const Q=Os((O==null?void 0:O.id)??(O==null?void 0:O.interrupt_id));if(!Q){console.warn("Interrupt part missing id",O);return}try{k==null||k(),await B(Q,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{C==null||C()}},[S,C,k,B]),ct=w.useCallback(async O=>{if(S)return;const Q=Os((O==null?void 0:O.id)??(O==null?void 0:O.interrupt_id));if(!Q){console.warn("Interrupt part missing id",O);return}try{k==null||k(),await B(Q,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{C==null||C()}},[S,C,k,B]),ft=w.useCallback(({part:O,i:Q})=>{if(O.type==="text"){const re=O.text??"",Me=re.trim(),ge=Ta(Me);return ge&&Y!=="tool"?u.jsx(hp,{data:ge},Q):Y==="user"&&c&&Me.length>d?u.jsx($S,{text:Me,expanded:z,onExpandedChange:j,previewLength:d,isCompact:R},Q):u.jsx(ao,{content:re,allowHtml:!1},Q)}if(O.type==="image_url"){const re=O;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:re.url,alt:re.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(O.type==="file"){const re=O,Me=re.name||"file";return u.jsxs("a",{href:re.url,onClick:ge=>H(ge,re,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[q[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Me,q[Q]?" (processing)":""]})]},Q)}if(O.type==="interrupt"){const re=O,Me=Os((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id)),ge=!!(ie&&Me&&Me===ie),Xe=ge?we??(re==null?void 0:re.value):re==null?void 0:re.value,xe=Me?{...re,id:Me,interrupt_id:Me}:re;return u.jsx(DS,{interruptPart:xe,onApprove:xt,onReject:ct,disabled:S,isActive:ge,payload:Xe},Q)}return null},[H,q,xt,ct,Y,c,d,z,R,ie,we,b,S,Fe]),pt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),yt=w.useCallback(()=>{const O=fe.trim().length>0||Ae.length>0||qe.length>0||Fe.length>0;if(!X&&qe.length>0&&!r)return pt();if(!X&&!O&&!r)return null;if(X)return u.jsx(FS,{message:t,viewMode:F},t.id);if(!X&&!se){const Q=t,re=u.jsx("div",{className:"space-y-2",children:Q.content.map((Me,ge)=>u.jsx(ft,{part:Me,i:ge},ge))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[re,u.jsx(MS,{className:Z})]}):re}},[fe,Ae.length,qe.length,Fe.length,r,X,F,pt,Z]),Nt=w.useMemo(()=>se?"Assistant":jS(t),[se,t]),Ye=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),jt=w.useMemo(()=>{var O;return Ye.length?_&&Ye.some(Q=>Q.id===_)?_:((O=Ye[0])==null?void 0:O.id)??null:null},[_,Ye]),tt=w.useMemo(()=>!Ye.length||!E?null:Ye.some(O=>O.id===E)?E:null,[E,Ye])??jt,ot=Y==="user"&&Ye.length>0&&typeof N=="function",bt=w.useCallback(O=>{if(!N)return;const Q=(O==null?void 0:O.id)??null,re=(O==null?void 0:O.parentId)??$??null;N(Q,re)},[$,N]),V=w.useMemo(()=>tt?Ye.findIndex(O=>O.id===tt):-1,[tt,Ye]),ce=w.useMemo(()=>V<0?null:Ye[V]??null,[V,Ye]),Ce=w.useCallback(O=>{const Q=[];if(O.step!==null&&Q.push(`Step ${O.step}`),O.source&&Q.push(O.source),!O.createdAt)return Q.length?Q.join(" • "):O.id.slice(0,8);let re="";try{const Me=new Date(O.createdAt);Number.isNaN(Me.getTime())||(re=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(Me))}catch{re=""}return`${re}`},[]);return X&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(et(),h.container),children:u.jsxs("div",{className:te(Et(),h.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",R&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[He(),a&&Nt&&u.jsx("span",{className:te("font-medium",R?"text-xs":"text-sm"),children:Nt}),X&&u.jsxs(Sf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",R&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>A(O=>O==="expanded"?"preview":"expanded"),onKeyDown:O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),A(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[ot&&ce&&V>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",V>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(V<=0)return;const O=Ye[V-1];O&&bt(O)},"aria-label":"Previous checkpoint",disabled:V<=0,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[V+1," / ",Ye.length]}),u.jsx("span",{className:"text-muted-foreground",children:Ce(ce)})]}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",V<Ye.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(V>=Ye.length-1)return;const O=Ye[V+1];O&&bt(O)},"aria-label":"Next checkpoint",disabled:V>=Ye.length-1,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,R&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,R&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(P?"text-success":Z,R?"h-3 w-3":"h-4 w-4")})})}),Y==="user"&&x&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,R&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,R?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ze,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,R&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,R?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[yt(),p&&Le.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Le.map((O,Q)=>u.jsxs("div",{className:"space-y-2",children:[O.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",O.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:O.src,alt:O.alt,title:O.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain"})})]},`artifact-${Q}`))})]}),X&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",R&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(P?"text-success":"text-current",R?"h-3 w-3":"h-4 w-4")})}),Y==="user"&&x&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",R?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ze,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",R?"h-3 w-3":"h-4 w-4")})})]})]})}),L&&u.jsx(uS,{isOpen:J,onClose:G,fileId:L.id,fileName:L.name,mimeType:L.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&fp(e.message)===fp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(x=>e[x]===t[x]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});function hp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:NS,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:io(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:io(e)})}function DS({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=io(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(eo,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(to,{className:"pb-3",children:[u.jsx(no,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Cf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(ro,{className:"pt-0 pb-3",children:a}),u.jsx(Tf,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function LS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ca(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,x,m)=>{var v,g;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(x.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=x.name||`file_${k}`,T=x.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await G0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof E.size=="number"?E.size===x.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${x.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:x.name||T.filename||`file_${T.id}`,mimeType:x.mimeType||T.mime_type||"application/octet-stream"}),(v=k.update)==null||v.call(k,{id:k.id,title:"Success",description:`Opened ${x.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function $S({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(ao,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(nt,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function FS({message:e,viewMode:t}){const r=dp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ta(c)??c:c;if(d&&typeof d=="object")return u.jsx(hp,{data:d});const f=typeof d=="string"?d:(()=>{try{return io(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=X0(c);return f?u.jsx(ao,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Ts(d);return s(f)}const a=so(i),l=Ts(a);return s(l)}const zS=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r})=>{const o=e??[],s=o.length>0,i=w.useMemo(()=>s?[...o].reverse():[],[o,s]),a=t??(o.length?o[o.length-1].id:null);return w.useEffect(()=>{console.debug("[TimelineColumn] entries:",o.length)},[o.length]),s?u.jsxs("div",{className:"w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(le.Info,{className:"h-3 w-3 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[10px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:"Backend pre-selects user inputs + latest loop checkpoint. Click a dot to jump, or use “Latest” to return to the newest messages."})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:i.map(l=>{const c=a===l.id,d=l.messageId?(r==null?void 0:r.get(l.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(l.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${c?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${c?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${c?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:l.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[l.step!==null?`STEP ${l.step}`:"STEP —",l.next?` - ${l.next}`:""]}),d&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:d,children:d})]})]},l.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null},mp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,BS=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},ja=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:v,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:N,checkpointIndexByKey:_,activeCheckpointId:$,onSelectCheckpoint:P,timelineCheckpoints:D,messagePreviews:F,createSyntheticThinkingMessage:A=!1},z)=>{const j=w.useRef(null),K=w.useRef(null),B=w.useRef(!1),[R,Y]=w.useState(!0),X=w.useMemo(()=>b?e.some(ie=>"type"in ie&&ie.type==="default_message"?!1:Array.isArray(ie==null?void 0:ie.content)&&ie.content.some(we=>we&&we.type==="interrupt"&&(we.id??we.interrupt_id)===b.id)):!1,[b,e]),se=w.useMemo(()=>{if(!b||X)return null;const ie=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let we;const _e=b.value;if(_e&&typeof _e=="object"&&!Array.isArray(_e)){const Le=_e.title;typeof Le=="string"&&Le.trim()&&(we=Le.trim())}return{id:`interrupt-${ie}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:ie,value:_e,title:we}]}},[b,X]),be=w.useMemo(()=>se?[...e,se]:e,[e,se]),Oe=w.useMemo(()=>!A||!t?be:!be.some(we=>we.role==="assistant")&&be.length>0?[...be,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:be,[be,t,A]),q=w.useMemo(()=>T?Oe:Oe.filter(ie=>(ie==null?void 0:ie.role)!=="tool"),[Oe,T]),H=w.useMemo(()=>{const ie=new Set,we=[];for(let _e=q.length-1;_e>=0;_e--){const Le=q[_e];if(!Le)continue;if("type"in Le&&Le.type==="default_message"){we.push(Le);continue}const Ue=Le,Ge=BS(Ue);ie.has(Ge)||(ie.add(Ge),we.push(Ue))}return we.reverse()},[q]),J=w.useCallback(ie=>{Y(ie),v&&v(!ie),g&&g(ie)},[v,g]),L=w.useMemo(()=>{if(a)return async()=>{if(!B.current){B.current=!0;try{await a()}finally{B.current=!1}}}},[a]),G=w.useMemo(()=>!x||m?!1:R?"auto":!1,[R,x,m]),Z=D??[],fe=Z.length>0,oe=w.useMemo(()=>{if(typeof h!="string")return null;const ie=h.trim();return ie?{id:"default-message",role:"assistant",type:"default_message",content:ie,createdAt:new Date().toISOString()}:null},[h]),Ae=fe?u.jsx(zS,{timelineEntries:Z,activeCheckpointId:$??null,onSelectCheckpoint:P,messagePreviews:F}):null,qe=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Fe=()=>oe?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(_a,{message:oe,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),Ze=H.length>0;return w.useImperativeHandle(z,()=>({scrollToLatest:()=>{var ie,we;if(j.current&&H.length>0){const _e=H.length-1;(we=(ie=j.current).scrollToIndex)==null||we.call(ie,{index:_e,align:"end",behavior:"auto"})}else K.current&&(K.current.scrollTop=K.current.scrollHeight)},scrollToTop:()=>{var ie,we;j.current&&H.length>0?(we=(ie=j.current).scrollToIndex)==null||we.call(ie,{index:0,align:"start",behavior:"auto"}):K.current&&(K.current.scrollTop=0)}}),[H]),u.jsxs("div",{className:qe,style:p,children:[Ae,u.jsx("div",{className:"relative flex-1 min-h-0",children:Ze?u.jsx(E0,{ref:ie=>{j.current=ie},scrollerRef:ie=>{K.current=ie instanceof HTMLDivElement?ie:null},data:H,followOutput:G,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!0,startReached:()=>{L&&L()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(ie,we)=>mp(we,ie),itemContent:(ie,we)=>{var ct;const _e=mp(we,ie),Le="type"in we&&we.type==="default_message";let Ue=[],Ge=null,ze={},He={},et=null,Et=null;if(!Le){const ft=we,pt=ft.checkpointId??null;ze=ft.additionalKwargs??{},He=ft.responseMetadata??{};const yt=pt&&N?N.get(pt)??null:null;et=typeof ze.step=="number"?ze.step:typeof He.step=="number"?He.step:(yt==null?void 0:yt.step)??null;const Nt=typeof ze.source=="string"?ze.source:typeof He.source=="string"?He.source:(yt==null?void 0:yt.source)??null;Et=Nt?String(Nt):null;const Ye=et!==null&&Et?`${et}:${Et}`:null;Ye&&(_!=null&&_.has(Ye))?Ue=_.get(Ye)??[]:pt&&yt&&(Ue=[yt]),Ge=pt??((ct=Ue[0])==null?void 0:ct.id)??null}const xt=(()=>{if(typeof ze.parentCheckpointId=="string")return ze.parentCheckpointId;if(typeof He.parentCheckpointId=="string")return He.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":_e,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(_a,{message:we,messageIndex:ie,isStreamingMessage:t&&n===we.id,streamingDebounceMs:r,isEditing:i===we.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(ie),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:E,checkpointCandidates:Ue,activeCheckpointId:$??null,onSelectCheckpoint:P,defaultCheckpointId:Ge,messageParentCheckpointId:xt})})}}):Fe()})]})});ja.displayName="MessageList";const gp={value:""};function Ms({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:v}=ci(),{currentThreadId:g}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:N,checkpoints:_,interrupt:$,metadata:P,timelineCheckpoints:D,messagePreviews:F}=jo(),{isStreaming:A,error:z,connectionState:j,submit:K,stop:B}=dc(),R=b??g??null,Y=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,be=$,[Oe,q]=w.useState(!1);w.useEffect(()=>{be||q(!1)},[be]);const H=w.useCallback(()=>{q(!0)},[]),J=w.useCallback(()=>{q(!1)},[]),L=!!be||Oe,[G,Z]=w.useState(null),[fe,oe]=w.useState(""),[Ae,qe]=w.useState(null),[Fe,Ze]=w.useState(null),[ie,we]=w.useState([]),[_e,Le]=w.useState(0),[Ue,Ge]=w.useState(0),[ze,He]=w.useState(!1),[et,Et]=w.useState(null),[xt,ct]=w.useState(null),[ft,pt]=w.useState(!1),[yt,Nt]=w.useState(null),Ye=w.useRef(!1),[jt,Sn]=w.useState(()=>gp.value),tt=w.useRef(jt),ot=w.useRef(null),bt=w.useCallback(ne=>{gp.value=ne,Sn(ne)},[]),[V,ce]=w.useState(!1),Ce=w.useRef(null),O=w.useCallback((ne,he)=>{if(!ne||typeof ne!="object")return null;const ae=ne[he];return typeof ae=="number"?ae:null},[]),Q=w.useCallback((ne,he)=>{if(!ne||typeof ne!="object")return null;const ae=ne[he];return typeof ae=="string"&&ae.trim()?ae:null},[]),re=w.useMemo(()=>{const ne=Re=>{if(!Array.isArray(Re)||Re.length===0)return null;const ht=Re.map(vt=>{if(typeof vt=="string")return vt.trim();if(vt&&typeof vt=="object"&&"type"in vt){const _n=vt;if(typeof _n.type=="string")return _n.type}return null}).filter(vt=>!!(vt&&vt.length));return ht.length?ht.join(", "):null},he=Array.isArray(_)?_.map(Re=>{const ht=ne(Re.next);return ht?{...Re,metadata:{...Re.metadata??{},next:ht}}:Re}):[];return he.some(Re=>O(Re.metadata,"step")!==null)&&he.sort((Re,ht)=>{const vt=O(Re.metadata,"step"),_n=O(ht.metadata,"step");if(vt!==null||_n!==null)return(_n??Number.NEGATIVE_INFINITY)-(vt??Number.NEGATIVE_INFINITY);const uo=Date.parse(Re.createdAt??""),fo=Date.parse(ht.createdAt??"");return Number.isNaN(uo)||Number.isNaN(fo)?0:fo-uo}),he},[_,O]),{checkpointMetaById:Me,checkpointIndexByKey:ge}=w.useMemo(()=>{const ne=new Map,he=new Map;for(const ae of re){const Re=ae.checkpointId??null;if(!Re)continue;const ht=O(ae.metadata,"step"),vt=Q(ae.metadata,"source"),_n={id:Re,step:ht,source:vt,createdAt:ae.createdAt??null,namespace:ae.checkpointNs??null,parentId:ae.parentId??null};if(ne.set(Re,_n),ht!==null&&vt){const uo=`${ht}:${vt}`,fo=he.get(uo)??[];fo.push(_n),he.set(uo,fo)}}for(const ae of he.values())ae.sort((Re,ht)=>{const vt=Re.createdAt??"";return(ht.createdAt??"").localeCompare(vt)});return{checkpointMetaById:ne,checkpointIndexByKey:he}},[re,O,Q]),Xe=D??[],xe=w.useRef(null),st=w.useRef(null),An=w.useCallback(()=>{xe.current&&(xe.current.value=""),st.current&&(st.current.value=""),Le(ne=>ne+1),Ge(ne=>ne+1)},[]),Ks=w.useCallback(ne=>{bt(ne)},[bt]),co=w.useRef(!1);w.useEffect(()=>{co.current&&!A&&(we([]),An()),co.current=A},[A,An]);const[Ka,qa]=w.useState("desktop");w.useEffect(()=>{const ne=()=>{const he=window.innerWidth;qa(he<640?"phone":he<1024?"tablet":"desktop")};return ne(),window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[]),w.useEffect(()=>{Ye.current=!1},[R]),w.useEffect(()=>{tt.current=jt},[jt]),w.useEffect(()=>{if(!G){ot.current=null;return}ot.current===null&&(ot.current=tt.current),bt(fe??"")},[fe,G,bt]),w.useEffect(()=>{(async()=>{if(!v.baseUrl){Nt(null);return}try{const ae=(await v.getAgent("default")).uiDefaultMessage||"";Nt(ae||null)}catch(he){console.warn("Failed to fetch default message:",he),Nt(null)}})()},[v.baseUrl]),w.useEffect(()=>{z&&!ft&&(m==null||m(z))},[z,ft,m]);const Ga=ne=>{if(ne.length>ls)return`Message too long (${ne.length}/${ls} characters)`;try{return gw(ne),null}catch(he){return(he==null?void 0:he.message)||"Invalid message"}},Ya=async ne=>{const he=ne.trim();if(!(!he&&ie.length===0)){if(he){const ae=Ga(he);if(ae){Ze(ae);return}}try{const ae=Y??void 0,Re=X??void 0,ht=G?{edit:!0,originalMessageId:G,...Ae!=null&&Ae.checkpointId?{originalCheckpointId:Ae.checkpointId}:{},...Ae!=null&&Ae.checkpointNs?{originalCheckpointNs:Ae.checkpointNs}:{}}:void 0;await K({text:he||"",attachments:ie,messageAdditionalKwargs:ht},{checkpointId:ae,checkpointNs:Re}),h==null||h(he),bt(""),Ze(null),we([]),An(),Z(null),oe(""),qe(null)}catch(ae){const Re=(ae==null?void 0:ae.message)||"Failed to send message";Ze(Re),m==null||m(Re)}}},I=w.useCallback((ne,he,ae)=>{c&&(ot.current=jt,Z(ne),oe(he),bt(he),Ze(null),qe({checkpointId:(ae==null?void 0:ae.checkpointId)??null,checkpointNs:(ae==null?void 0:ae.checkpointNs)??null}))},[jt,c,bt]),W=w.useCallback(()=>{Z(null),oe(""),qe(null),Ze(null),bt(ot.current??jt),ot.current=null},[jt,bt]),ue=w.useCallback((ne,he,ae)=>{I(ne,he,ae)},[I]),ke=w.useCallback(ne=>{for(let he=ne-1;he>=0;he--)if(S[he].role==="user"){const ae=S[he].content||[],ht=ae.filter(vt=>vt.type==="text").map(vt=>vt.text).join("")||(()=>{try{return JSON.stringify(ae,null,2)}catch{return String(ae)}})();ht&&K({text:ht},{checkpointId:Y??void 0,checkpointNs:X??void 0});break}},[S,K,Y,X]),Qe=ne=>{const he=Array.from(ne.target.files||[]);we(ae=>[...ae,...he]),ne.target.value=""},it=ne=>{we(he=>{const ae=he.filter((Re,ht)=>ne!==ht);return ae.length===0&&An(),ae})},We=async ne=>{const he=(ne.target.files||[])[0];if(he){Et(null),ct(null),He(!0);try{await K({attachments:[he]},{checkpointId:Y??void 0,checkpointNs:X??void 0});const ae=`Uploaded ${he.name} - processing through chat stream`;ct(ae)}catch(ae){const Re=ae instanceof Error?ae.message:"Failed to upload Excel file";console.error("Excel upload failed",ae),Et(Re),m==null||m(Re)}finally{He(!1),ne.target.value="",An()}}},Be=async ne=>{if(g){ce(!0);try{if(!ne){await E(),requestAnimationFrame(()=>{var Re;(Re=Ce.current)==null||Re.scrollToLatest()});return}const he=re.find(Re=>Re.checkpointId===ne),ae=(he==null?void 0:he.checkpointNs)??null;await T(ne,ae),requestAnimationFrame(()=>{var Re;(Re=Ce.current)==null||Re.scrollToTop()})}finally{ce(!1)}}},Rt=w.useCallback(async ne=>{await Be(ne)},[Be]),wt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,St=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,Ut=`flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return w.useCallback(ne=>{if(!ne)return"Latest";const he=[];ne.step!==null&&he.push(`Step ${ne.step}`),ne.source&&he.push(ne.source);const ae=ne.createdAt?new Date(ne.createdAt):null,Re=ae&&!Number.isNaN(ae.getTime())?ae.toLocaleString():ne.createdAt??ne.id,ht=he.length?` — ${he.join(" • ")}`:"";return`${Re}${ht}`},[]),u.jsxs("div",{className:wt,children:[!!z&&!ft&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:z}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>pt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${St}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:Ce,className:"h-full",style:{height:"100%"},messages:S,isStreaming:A,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Ka,enableMessageEditing:c,editingMessageId:G,onEdit:ue,onRegenerate:ke,onCancelEdit:W,emptyMessage:yt??void 0,isNavigatingCheckpoint:V,activeInterrupt:be,disableInterruptActions:Oe,onInterruptActionStart:H,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:Me,checkpointIndexByKey:ge,activeCheckpointId:Y,onSelectCheckpoint:Rt,timelineCheckpoints:Xe,messagePreviews:F}),(j==="reconnecting"||j==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(le.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||V)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:Ut,children:[G&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:W,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:xe,type:"file",multiple:!0,onChange:ne=>Qe(ne),className:"hidden"},_e),ie.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:ie.map((ne,he)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ne.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>it(he),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 ${ne.name}`,children:u.jsx(le.X,{size:12})})]},he))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:st,type:"file",accept:".xls,.xlsx,.xlsm",onChange:We,className:"hidden"},Ue),ze&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!ze&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),et&&!ze&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:et})]})]}),Fe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Fe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(iw,{children:[u.jsx(aw,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:A||L,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(Sd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ji,{onClick:()=>{var ne;return(ne=xe.current)==null?void 0:ne.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ji,{onClick:()=>{var ne;ze||(ne=st.current)==null||ne.click()},className:`cursor-pointer ${ze?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ax,{initialValue:fe,editingMessageId:G,value:jt,onValueChange:Ks,placeholder:G?"Edit your message...":t,isStreaming:A,disabled:L,maxLength:ls,onSend:Ya,onCancelEdit:W,onStop:B,allowEmptySend:ie.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${G?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Fe?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Ds=y.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Ds.displayName="Input";function Ra(e,[t,n]){return Math.min(n,Math.max(t,e))}function HS(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}var Pa="ScrollArea",[xp,_T]=Tn(Pa),[US,nn]=xp(Pa),yp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=y.useState(null),[c,d]=y.useState(null),[f,p]=y.useState(null),[h,x]=y.useState(null),[m,v]=y.useState(null),[g,b]=y.useState(0),[S,k]=y.useState(0),[C,T]=y.useState(!1),[E,N]=y.useState(!1),_=Ve(t,P=>l(P)),$=Po(o);return u.jsx(US,{scope:n,type:r,dir:$,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:v,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(je.div,{dir:$,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});yp.displayName=Pa;var vp="ScrollAreaViewport",bp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=nn(vp,n),a=y.useRef(null),l=Ve(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(je.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});bp.displayName=vp;var wn="ScrollAreaScrollbar",Oa=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return y.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(WS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(VS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(wp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ma,{...r,ref:t}):null});Oa.displayName=wn;var WS=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(wn,e.__scopeScrollArea),[s,i]=y.useState(!1);return y.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Zt,{present:n||s,children:u.jsx(wp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),VS=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=nn(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=zs(()=>l("SCROLL_END"),100),[a,l]=HS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return y.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),y.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Zt,{present:n||a!=="hidden",children:u.jsx(Ma,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:me(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:me(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),wp=y.forwardRef((e,t)=>{const n=nn(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=y.useState(!1),a=e.orientation==="horizontal",l=zs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Tr(n.viewport,l),Tr(n.content,l),u.jsx(Zt,{present:r||s,children:u.jsx(Ma,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ma=y.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=nn(wn,e.__scopeScrollArea),s=y.useRef(null),i=y.useRef(0),[a,l]=y.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Ep(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return JS(p,i.current,a,h)}return n==="horizontal"?u.jsx(KS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Ip(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(qS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Ip(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),KS=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(wn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=Ve(t,l,s.onScrollbarXChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Cp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Fs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Ap(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:$s(i.paddingLeft),paddingEnd:$s(i.paddingRight)}})}})}),qS=y.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=nn(wn,e.__scopeScrollArea),[i,a]=y.useState(),l=y.useRef(null),c=Ve(t,l,s.onScrollbarYChange);return y.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Cp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Fs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Ap(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:$s(i.paddingTop),paddingEnd:$s(i.paddingBottom)}})}})}),[GS,Sp]=xp(wn),Cp=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=nn(wn,n),[x,m]=y.useState(null),v=Ve(t,_=>m(_)),g=y.useRef(null),b=y.useRef(""),S=h.viewport,k=r.content-r.viewport,C=_t(d),T=_t(l),E=zs(f,10);function N(_){if(g.current){const $=_.clientX-g.current.left,P=_.clientY-g.current.top;c({x:$,y:P})}}return y.useEffect(()=>{const _=$=>{const P=$.target;(x==null?void 0:x.contains(P))&&C($,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,x,k,C]),y.useEffect(T,[r,T]),Tr(x,E),Tr(h.content,E),u.jsx(GS,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:_t(s),onThumbPointerUp:_t(i),onThumbPositionChange:T,onThumbPointerDown:_t(a),children:u.jsx(je.div,{...p,ref:v,style:{position:"absolute",...p.style},onPointerDown:me(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:me(e.onPointerMove,N),onPointerUp:me(e.onPointerUp,_=>{const $=_.target;$.hasPointerCapture(_.pointerId)&&$.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Ls="ScrollAreaThumb",Tp=y.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sp(Ls,e.__scopeScrollArea);return u.jsx(Zt,{present:n||o.hasThumb,children:u.jsx(YS,{ref:t,...r})})}),YS=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=nn(Ls,n),i=Sp(Ls,n),{onThumbPositionChange:a}=i,l=Ve(t,f=>i.onThumbChange(f)),c=y.useRef(void 0),d=zs(()=>{c.current&&(c.current(),c.current=void 0)},100);return y.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=ZS(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(je.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:me(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:me(e.onPointerUp,i.onThumbPointerUp)})});Tp.displayName=Ls;var Da="ScrollAreaCorner",kp=y.forwardRef((e,t)=>{const n=nn(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(XS,{...e,ref:t}):null});kp.displayName=Da;var XS=y.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=nn(Da,n),[s,i]=y.useState(0),[a,l]=y.useState(0),c=!!(s&&a);return Tr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Tr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(je.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 $s(e){return e?parseInt(e,10):0}function Ep(e,t){const n=e/t;return isNaN(n)?0:n}function Fs(e){const t=Ep(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function JS(e,t,n,r="ltr"){const o=Fs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Np([l,c],f)(e)}function Ip(e,t,n="ltr"){const r=Fs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Ra(e,l);return Np([0,i],[0,a])(c)}function Np(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 Ap(e,t){return e>0&&e<t}var ZS=(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 zs(e,t){const n=_t(e),r=y.useRef(0);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),y.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Tr(e,t){const n=_t(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 _p=yp,QS=bp,eC=kp;const jp=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(QS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Rp,{}),u.jsx(eC,{})]}));jp.displayName=_p.displayName;const Rp=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Oa,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Tp,{className:"relative flex-1 rounded-full bg-border"})}));Rp.displayName=Oa.displayName;const Pp=25;function La({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=_o(),{loadThread:v}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),E=w.useRef(null),N=w.useRef(0),[_,$]=w.useState(null),[P,D]=w.useState(""),[F,A]=w.useState(!1);w.useEffect(()=>{const q=Array.isArray(f)?f:[];if(q.length>0){T.current=!0,C(q);return}x||(T.current=!1,C(q))},[f,x]),w.useEffect(()=>{if(!E.current)return;const q=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!q)return;let H=null,J=null;return H=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{q.scrollTop=N.current})}),()=>{H!==null&&cancelAnimationFrame(H),J!==null&&cancelAnimationFrame(J)}},[k]);const z=async q=>{try{h(q),await v(q),a==null||a(q),l==null||l(q)}catch(H){console.error("Failed to select thread:",H)}},j=async()=>{try{A(!0);const q=await g();q&&(c==null||c(q),a==null||a(q))}catch(q){console.error("Failed to create thread:",q)}finally{A(!1)}},K=async(q,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const J=E.current.querySelector("[data-radix-scroll-area-viewport]");J&&(N.current=J.scrollTop)}try{await b(q),d==null||d(q)}catch(J){console.error("Failed to delete thread:",J)}}},B=(q,H)=>{H.stopPropagation(),$(q.threadId),D(q.title||`Thread ${q.threadId.slice(0,8)}`)},R=async q=>{if(P.trim())try{await S(q,P.trim()),$(null),D("")}catch(H){console.error("Failed to update title:",H)}},Y=()=>{$(null),D("")},X=(q,H)=>{q.key==="Enter"?R(H):q.key==="Escape"&&Y()},se=q=>{if(!q)return"";try{const H=new Date(q),L=new Date().getTime()-H.getTime(),G=Math.floor(L/(1e3*60*60*24));return G===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):G===1?"Yesterday":G<7?`${G} days ago`:H.toLocaleDateString()}catch{return""}},be=q=>q.title||`Thread ${q.threadId.slice(0,8)}`,Oe=q=>{const H=be(q);return H.length<=Pp?H:`${H.slice(0,Pp)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(nt,{onClick:j,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(jp,{ref:E,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(le.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((q,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>z(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===q.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:_===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[u.jsx(Ds,{value:P,onChange:H=>D(H.target.value),onKeyDown:H=>X(H,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>R(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:Y,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Oe(q)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:se(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==q.threadId&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:H=>B(q,H),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:H=>K(q.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(le.Trash2,{size:12})})]})]}),i===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}function kr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function tC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function Op(){const e=[kr("__API_BASE_URL__"),kr("__CHAT_API_BASE_URL__"),kr("__CHAT_API_URL__")];for(const t of e){const n=tC(t);if(n)return n}}function Mp(){const e=[kr("__API_AUTH_TOKEN__"),kr("__CHAT_API_KEY__"),kr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Dp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Lp(){const e={},t=Op(),n=Mp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $p(){const e=Lp(),t=jn.getAuthToken(),n=Op();return{apiBaseUrl:Dp(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||Mp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Fp="chat-settings";function nC(){try{const e=localStorage.getItem(Fp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function rC(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem(Fp,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function oC(){const e=$p(),t=nC(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Dp(jn.baseUrl,r,e.apiBaseUrl)}}function sC(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),rC(e)}var iC="Label",zp=y.forwardRef((e,t)=>u.jsx(je.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())}}));zp.displayName=iC;var Bp=zp;const aC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),rn=y.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:te(aC(),e),...t}));rn.displayName=Bp.displayName;function Hp(e){const t=y.useRef({value:e,previous:e});return y.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Bs="Switch",[lC,jT]=Tn(Bs),[cC,uC]=lC(Bs),Up=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=y.useState(null),x=Ve(t,S=>h(S)),m=y.useRef(!1),v=p?d||!!p.closest("form"):!0,[g,b]=fr({prop:o,defaultProp:s??!1,onChange:c,caller:Bs});return u.jsxs(cC,{scope:n,checked:g,disabled:a,children:[u.jsx(je.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":qp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:me(e.onClick,S=>{b(k=>!k),v&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),v&&u.jsx(Kp,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Up.displayName=Bs;var Wp="SwitchThumb",Vp=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=uC(Wp,n);return u.jsx(je.span,{"data-state":qp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Vp.displayName=Wp;var dC="SwitchBubbleInput",Kp=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=y.useRef(null),a=Ve(i,s),l=Hp(n),c=Yc(t);return y.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const x=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Kp.displayName=dC;function qp(e){return e?"checked":"unchecked"}var Gp=Up,fC=Vp;const Bn=y.forwardRef(({className:e,...t},n)=>u.jsx(Gp,{className:te("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(fC,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Bn.displayName=Gp.displayName;var Yp=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"}),pC="VisuallyHidden",hC=y.forwardRef((e,t)=>u.jsx(je.span,{...e,ref:t,style:{...Yp,...e.style}}));hC.displayName=pC;var mC=[" ","Enter","ArrowUp","ArrowDown"],gC=[" ","Enter"],or="Select",[Hs,Us,xC]=gi(or),[Er,RT]=Tn(or,[xC,Ko]),Ws=Ko(),[yC,Hn]=Er(or),[vC,bC]=Er(or),Xp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Ws(t),[v,g]=y.useState(null),[b,S]=y.useState(null),[k,C]=y.useState(!1),T=Po(c),[E,N]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:or}),[_,$]=fr({prop:i,defaultProp:a,onChange:l,caller:or}),P=y.useRef(null),D=v?x||!!v.closest("form"):!0,[F,A]=y.useState(new Set),z=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(su,{...m,children:u.jsxs(yC,{required:h,scope:t,trigger:v,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:kn(),value:_,onValueChange:$,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(vC,{scope:e.__scopeSelect,onNativeOptionAdd:y.useCallback(j=>{A(K=>new Set(K).add(j))},[]),onNativeOptionRemove:y.useCallback(j=>{A(K=>{const B=new Set(K);return B.delete(j),B})},[]),children:n})}),D?u.jsxs(bh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:j=>$(j.target.value),disabled:p,form:x,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},z):null]})})};Xp.displayName=or;var Jp="SelectTrigger",Zp=y.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ws(n),i=Hn(Jp,n),a=i.disabled||r,l=Ve(t,i.onTriggerChange),c=Us(n),d=y.useRef("touch"),[f,p,h]=Sh(m=>{const v=c().filter(S=>!S.disabled),g=v.find(S=>S.value===i.value),b=Ch(v,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(iu,{asChild:!0,...s,children:u.jsx(je.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":wh(i.value)?"":void 0,...o,ref:l,onClick:me(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:me(o.onPointerDown,m=>{d.current=m.pointerType;const v=m.target;v.hasPointerCapture(m.pointerId)&&v.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:me(o.onKeyDown,m=>{const v=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(v&&m.key===" ")&&mC.includes(m.key)&&(x(),m.preventDefault())})})})});Zp.displayName=Jp;var Qp="SelectValue",eh=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Hn(Qp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ve(t,l.onValueNodeChange);return At(()=>{c(d)},[c,d]),u.jsx(je.span,{...a,ref:f,style:{pointerEvents:"none"},children:wh(l.value)?u.jsx(u.Fragment,{children:i}):s})});eh.displayName=Qp;var wC="SelectIcon",th=y.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(je.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});th.displayName=wC;var SC="SelectPortal",nh=e=>u.jsx(qo,{asChild:!0,...e});nh.displayName=SC;var sr="SelectContent",rh=y.forwardRef((e,t)=>{const n=Hn(sr,e.__scopeSelect),[r,o]=y.useState();if(At(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(oh,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(sh,{...e,ref:t})});rh.displayName=sr;var dn=10,[oh,Un]=Er(sr),CC="SelectContentImpl",TC=Wn.createSlot("SelectContent.RemoveScroll"),sh=y.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:v,...g}=e,b=Hn(sr,n),[S,k]=y.useState(null),[C,T]=y.useState(null),E=Ve(t,J=>k(J)),[N,_]=y.useState(null),[$,P]=y.useState(null),D=Us(n),[F,A]=y.useState(!1),z=y.useRef(!1);y.useEffect(()=>{if(S)return $i(S)},[S]),vi();const j=y.useCallback(J=>{const[L,...G]=D().map(oe=>oe.ref.current),[Z]=G.slice(-1),fe=document.activeElement;for(const oe of J)if(oe===fe||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===L&&C&&(C.scrollTop=0),oe===Z&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==fe))return},[D,C]),K=y.useCallback(()=>j([N,S]),[j,N,S]);y.useEffect(()=>{F&&K()},[F,K]);const{onOpenChange:B,triggerPointerDownPosRef:R}=b;y.useEffect(()=>{if(S){let J={x:0,y:0};const L=Z=>{var fe,oe;J={x:Math.abs(Math.round(Z.pageX)-(((fe=R.current)==null?void 0:fe.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((oe=R.current)==null?void 0:oe.y)??0))}},G=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||B(!1),document.removeEventListener("pointermove",L),R.current=null};return R.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",G,{capture:!0})}}},[S,B,R]),y.useEffect(()=>{const J=()=>B(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[B]);const[Y,X]=Sh(J=>{const L=D().filter(fe=>!fe.disabled),G=L.find(fe=>fe.ref.current===document.activeElement),Z=Ch(L,J,G);Z&&setTimeout(()=>Z.ref.current.focus())}),se=y.useCallback((J,L,G)=>{const Z=!z.current&&!G;(b.value!==void 0&&b.value===L||Z)&&(_(J),Z&&(z.current=!0))},[b.value]),be=y.useCallback(()=>S==null?void 0:S.focus(),[S]),Oe=y.useCallback((J,L,G)=>{const Z=!z.current&&!G;(b.value!==void 0&&b.value===L||Z)&&P(J)},[b.value]),q=r==="popper"?$a:ih,H=q===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:v}:{};return u.jsx(oh,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:N,onItemLeave:be,itemTextRefCallback:Oe,focusSelectedItem:K,selectedItemText:$,position:r,isPositioned:F,searchRef:Y,children:u.jsx(ns,{as:TC,allowPinchZoom:!0,children:u.jsx(Mo,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:me(o,J=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(q,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...g,...H,onPlaced:()=>A(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:me(g.onKeyDown,J=>{const L=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!L&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=D().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const fe=J.target,oe=Z.indexOf(fe);Z=Z.slice(oe+1)}setTimeout(()=>j(Z)),J.preventDefault()}})})})})})})});sh.displayName=CC;var kC="SelectItemAlignedPosition",ih=y.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Hn(sr,n),i=Un(sr,n),[a,l]=y.useState(null),[c,d]=y.useState(null),f=Ve(t,E=>d(E)),p=Us(n),h=y.useRef(!1),x=y.useRef(!0),{viewport:m,selectedItem:v,selectedItemText:g,focusSelectedItem:b}=i,S=y.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&v&&g){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),$=g.getBoundingClientRect();if(s.dir!=="rtl"){const fe=$.left-N.left,oe=_.left-fe,Ae=E.left-oe,qe=E.width+Ae,Fe=Math.max(qe,N.width),Ze=window.innerWidth-dn,ie=Ra(oe,[dn,Math.max(dn,Ze-Fe)]);a.style.minWidth=qe+"px",a.style.left=ie+"px"}else{const fe=N.right-$.right,oe=window.innerWidth-_.right-fe,Ae=window.innerWidth-E.right-oe,qe=E.width+Ae,Fe=Math.max(qe,N.width),Ze=window.innerWidth-dn,ie=Ra(oe,[dn,Math.max(dn,Ze-Fe)]);a.style.minWidth=qe+"px",a.style.right=ie+"px"}const P=p(),D=window.innerHeight-dn*2,F=m.scrollHeight,A=window.getComputedStyle(c),z=parseInt(A.borderTopWidth,10),j=parseInt(A.paddingTop,10),K=parseInt(A.borderBottomWidth,10),B=parseInt(A.paddingBottom,10),R=z+j+F+B+K,Y=Math.min(v.offsetHeight*5,R),X=window.getComputedStyle(m),se=parseInt(X.paddingTop,10),be=parseInt(X.paddingBottom,10),Oe=E.top+E.height/2-dn,q=D-Oe,H=v.offsetHeight/2,J=v.offsetTop+H,L=z+j+J,G=R-L;if(L<=Oe){const fe=P.length>0&&v===P[P.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,Ae=Math.max(q,H+(fe?be:0)+oe+K),qe=L+Ae;a.style.height=qe+"px"}else{const fe=P.length>0&&v===P[0].ref.current;a.style.top="0px";const Ae=Math.max(Oe,z+m.offsetTop+(fe?se:0)+H)+G;a.style.height=Ae+"px",m.scrollTop=L-Oe+m.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=Y+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,v,g,s.dir,r]);At(()=>S(),[S]);const[k,C]=y.useState();At(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=y.useCallback(E=>{E&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(IC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(je.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ih.displayName=kC;var EC="SelectPopperPosition",$a=y.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Ws(n);return u.jsx(au,{...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)"}})});$a.displayName=EC;var[IC,Fa]=Er(sr,{}),za="SelectViewport",ah=y.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Un(za,n),i=Fa(za,n),a=Ve(t,s.onViewportChange),l=y.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(je.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:me(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-dn*2,m=parseFloat(f.style.minHeight),v=parseFloat(f.style.height),g=Math.max(m,v);if(g<x){const b=g+h,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});ah.displayName=za;var lh="SelectGroup",[NC,AC]=Er(lh),_C=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return u.jsx(NC,{scope:n,id:o,children:u.jsx(je.div,{role:"group","aria-labelledby":o,...r,ref:t})})});_C.displayName=lh;var ch="SelectLabel",uh=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=AC(ch,n);return u.jsx(je.div,{id:o.id,...r,ref:t})});uh.displayName=ch;var Vs="SelectItem",[jC,dh]=Er(Vs),fh=y.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Hn(Vs,n),l=Un(Vs,n),c=a.value===r,[d,f]=y.useState(s??""),[p,h]=y.useState(!1),x=Ve(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=kn(),v=y.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(jC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:y.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(je.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:me(i.onFocus,()=>h(!0)),onBlur:me(i.onBlur,()=>h(!1)),onClick:me(i.onClick,()=>{v.current!=="mouse"&&g()}),onPointerUp:me(i.onPointerUp,()=>{v.current==="mouse"&&g()}),onPointerDown:me(i.onPointerDown,b=>{v.current=b.pointerType}),onPointerMove:me(i.onPointerMove,b=>{var S;v.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):v.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:me(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:me(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(gC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});fh.displayName=Vs;var lo="SelectItemText",ph=y.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Hn(lo,n),a=Un(lo,n),l=dh(lo,n),c=bC(lo,n),[d,f]=y.useState(null),p=Ve(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,x=y.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:v}=c;return At(()=>(m(x),()=>v(x)),[m,v,x]),u.jsxs(u.Fragment,{children:[u.jsx(je.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});ph.displayName=lo;var hh="SelectItemIndicator",mh=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return dh(hh,n).isSelected?u.jsx(je.span,{"aria-hidden":!0,...r,ref:t}):null});mh.displayName=hh;var Ba="SelectScrollUpButton",gh=y.forwardRef((e,t)=>{const n=Un(Ba,e.__scopeSelect),r=Fa(Ba,e.__scopeSelect),[o,s]=y.useState(!1),i=Ve(t,r.onScrollButtonChange);return At(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(yh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});gh.displayName=Ba;var Ha="SelectScrollDownButton",xh=y.forwardRef((e,t)=>{const n=Un(Ha,e.__scopeSelect),r=Fa(Ha,e.__scopeSelect),[o,s]=y.useState(!1),i=Ve(t,r.onScrollButtonChange);return At(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(yh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});xh.displayName=Ha;var yh=y.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Un("SelectScrollButton",n),i=y.useRef(null),a=Us(n),l=y.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return y.useEffect(()=>()=>l(),[l]),At(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(je.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:me(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:me(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:me(o.onPointerLeave,()=>{l()})})}),RC="SelectSeparator",vh=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(je.div,{"aria-hidden":!0,...r,ref:t})});vh.displayName=RC;var Ua="SelectArrow",PC=y.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ws(n),s=Hn(Ua,n),i=Un(Ua,n);return s.open&&i.position==="popper"?u.jsx(lu,{...o,...r,ref:t}):null});PC.displayName=Ua;var OC="SelectBubbleInput",bh=y.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=y.useRef(null),s=Ve(r,o),i=Hp(t);return y.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(je.select,{...n,style:{...Yp,...n.style},ref:s,defaultValue:t})});bh.displayName=OC;function wh(e){return e===""||e===void 0}function Sh(e){const t=_t(e),n=y.useRef(""),r=y.useRef(0),o=y.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=y.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return y.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Ch(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=MC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function MC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var DC=Xp,Th=Zp,LC=eh,$C=th,FC=nh,kh=rh,zC=ah,Eh=uh,Ih=fh,BC=ph,HC=mh,Nh=gh,Ah=xh,_h=vh;const jh=DC,Rh=LC,Wa=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Th,{ref:r,className:te("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx($C,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=Th.displayName;const Ph=y.forwardRef(({className:e,...t},n)=>u.jsx(Nh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));Ph.displayName=Nh.displayName;const Oh=y.forwardRef(({className:e,...t},n)=>u.jsx(Ah,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));Oh.displayName=Ah.displayName;const Va=y.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(FC,{children:u.jsxs(kh,{ref:o,className:te("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Ph,{}),u.jsx(zC,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Oh,{})]})}));Va.displayName=kh.displayName;const UC=y.forwardRef(({className:e,...t},n)=>u.jsx(Eh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));UC.displayName=Eh.displayName;const ir=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ih,{ref:r,className:te("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(HC,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(BC,{children:t})]}));ir.displayName=Ih.displayName;const WC=y.forwardRef(({className:e,...t},n)=>u.jsx(_h,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));WC.displayName=_h.displayName;var VC="Separator",Mh="horizontal",KC=["horizontal","vertical"],Dh=y.forwardRef((e,t)=>{const{decorative:n,orientation:r=Mh,...o}=e,s=qC(r)?r:Mh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(je.div,{"data-orientation":s,...a,...o,ref:t})});Dh.displayName=VC;function qC(e){return KC.includes(e)}var Lh=Dh;const $h=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Lh,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$h.displayName=Lh.displayName;const GC=Vf,YC=iS,XC=Kf,Fh=y.forwardRef(({className:e,...t},n)=>u.jsx(Is,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));Fh.displayName=Is.displayName;const JC=po.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),zh=y.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(XC,{children:[u.jsx(Fh,{}),u.jsxs(Ns,{ref:o,className:te(JC({side:e}),t),...r,children:[n,u.jsxs(qf,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[u.jsx(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));zh.displayName=Ns.displayName;const Bh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Bh.displayName="SheetHeader";const Hh=y.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Hh.displayName=nr.displayName;const Uh=y.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Uh.displayName=As.displayName;const ZC={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 QC({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ca();w.useEffect(()=>{const v=JSON.stringify(a)!==JSON.stringify(e);d(v)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(ZC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(GC,{open:r,onOpenChange:o,children:[u.jsx(YC,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Sf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(zh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Bh,{children:[u.jsx(Hh,{children:"Chat Settings"}),u.jsx(Uh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(eo,{children:[u.jsx(to,{className:"pb-3",children:u.jsxs(no,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(ro,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ds,{id:"api-url",value:a.api.baseUrl,onChange:v=>l(g=>({...g,api:{...g.api,baseUrl:v.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(nt,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(rn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:v=>l(g=>({...g,api:{...g.api,enableAuth:v}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ds,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:v=>l(g=>({...g,api:{...g.api,authToken:v.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(eo,{children:[u.jsx(to,{className:"pb-3",children:u.jsxs(no,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(ro,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(jh,{value:a.ui.layout,onValueChange:v=>l(g=>({...g,ui:{...g.ui,layout:v}})),children:[u.jsx(Wa,{children:u.jsx(Rh,{})}),u.jsxs(Va,{children:[u.jsx(ir,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ir,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ir,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(rn,{htmlFor:"theme",children:"Theme"}),u.jsxs(jh,{value:a.ui.theme,onValueChange:v=>l(g=>({...g,ui:{...g.ui,theme:v}})),children:[u.jsx(Wa,{children:u.jsx(Rh,{})}),u.jsxs(Va,{children:[u.jsx(ir,{value:"light",children:"Light"}),u.jsx(ir,{value:"dark",children:"Dark"}),u.jsx(ir,{value:"system",children:"System"})]})]})]}),u.jsx($h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(rn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showTimestamps:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(rn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,showAgentNames:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(rn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:v=>l(g=>({...g,ui:{...g.ui,compactMessages:v}}))})]})]})]})]}),u.jsxs(eo,{children:[u.jsx(to,{className:"pb-3",children:u.jsxs(no,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(ro,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(rn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,autoSave:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(rn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:v}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(rn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:v=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:v}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(nt,{variant:"outline",onClick:h,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function eT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ms,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(La,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ms,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ro,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(La,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Ms,{onError:s.onError,enableFileUpload:!0})})]})})}Ee.ChatApi=Wl,Ee.ChatInput=pc,Ee.ChatInterface=Ms,Ee.ChatProviders=Ro,Ee.ChatSettings=QC,Ee.MarkdownContent=ao,Ee.MessageComponent=_a,Ee.MessageList=ja,Ee.ThreadManager=La,Ee.applySettings=sC,Ee.buildMessagePreviewMap=Jl,Ee.chatApiClient=jn,Ee.default=eT,Ee.del=Ul,Ee.get=Yt,Ee.getChatToken=zl,Ee.getCurrentSettings=oC,Ee.getDefaultApiConfig=Lp,Ee.getDefaultChatSettings=$p,Ee.onChatTokenChanged=Bl,Ee.post=li,Ee.put=Hl,Ee.setChatToken=Eo,Ee.useApi=ci,Ee.useChatStream=Zl,Ee.useMessagesReducer=Ql,Ee.useStream=dc,Ee.useThreadState=jo,Ee.useThreads=_o,Object.defineProperties(Ee,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});