teodor-new-chat-ui 4.3.335 → 4.3.337

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(Ce,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],w):(Ce=typeof globalThis<"u"?globalThis:Ce||self,w(Ce.NewChatUI={},Ce.React,Ce.LucideReact,Ce.reactSlot,Ce.classVarianceAuthority,Ce.clsx,Ce.tailwindMerge,Ce.ReactDOM))})(this,function(Ce,w,ae,Hn,po,Uh,Hh,Gs){"use strict";var uT=Object.defineProperty;var dT=(Ce,w,ae)=>w in Ce?uT(Ce,w,{enumerable:!0,configurable:!0,writable:!0,value:ae}):Ce[w]=ae;var Bh=(Ce,w,ae)=>dT(Ce,typeof w!="symbol"?w+"":w,ae);var Ys=typeof document<"u"?document.currentScript:null;function Ka(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const v=Ka(w),ho=Ka(Gs);var Xs={exports:{}},Nr={};/**
1
+ (function(Ce,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],w):(Ce=typeof globalThis<"u"?globalThis:Ce||self,w(Ce.NewChatUI={},Ce.React,Ce.LucideReact,Ce.reactSlot,Ce.classVarianceAuthority,Ce.clsx,Ce.tailwindMerge,Ce.ReactDOM))})(this,function(Ce,w,ae,Kn,mo,Vh,Kh,Js){"use strict";var fT=Object.defineProperty;var pT=(Ce,w,ae)=>w in Ce?fT(Ce,w,{enumerable:!0,configurable:!0,writable:!0,value:ae}):Ce[w]=ae;var Hh=(Ce,w,ae)=>pT(Ce,typeof w!="symbol"?w+"":w,ae);var Zs=typeof document<"u"?document.currentScript:null;function Ya(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const v=Ya(w),go=Ya(Js);var Qs={exports:{}},Rr={};/**
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 qa;function Wh(){if(qa)return Nr;qa=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:p,ref:h,props:f,_owner:o.current}}return Nr.Fragment=n,Nr.jsx=i,Nr.jsxs=i,Nr}var _r={};/**
9
+ */var Xa;function qh(){if(Xa)return Rr;Xa=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 Rr.Fragment=n,Rr.jsx=i,Rr.jsxs=i,Rr}var Mr={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,33 +14,33 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Ga;function Vh(){return Ga||(Ga=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 y(E){if(E===null||typeof E!="object")return null;var W=x&&E[x]||E[m];return typeof W=="function"?W:null}var g=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var W=arguments.length,se=new Array(W>1?W-1:0),ve=1;ve<W;ve++)se[ve-1]=arguments[ve];S("error",E,se)}}function S(E,W,se){{var ve=g.ReactDebugCurrentFrame,Xe=ve.getStackAddendum();Xe!==""&&(W+="%s",se=se.concat([Xe]));var ot=se.map(function($e){return String($e)});ot.unshift("Warning: "+W),Function.prototype.apply.call(console[E],console,ot)}}var k=!1,C=!1,T=!1,I=!1,A=!1,R;R=Symbol.for("react.module.reference");function $(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===c||E===d||I||E===h||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===p||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===R||E.getModuleId!==void 0))}function P(E,W,se){var ve=E.displayName;if(ve)return ve;var Xe=W.displayName||W.name||"";return Xe!==""?se+"("+Xe+")":se}function O(E){return E.displayName||"Context"}function F(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var W=E;return O(W)+".Consumer";case i:var se=E;return O(se._context)+".Provider";case l:return P(E,E.render,"ForwardRef");case f:var ve=E.displayName||null;return ve!==null?ve:F(E.type)||"Memo";case p:{var Xe=E,ot=Xe._payload,$e=Xe._init;try{return F($e(ot))}catch{return null}}}return null}var N=Object.assign,B=0,M,Q,z,_,V,Y,oe;function ye(){}ye.__reactDisabledLog=!0;function Me(){{if(B===0){M=console.log,Q=console.info,z=console.warn,_=console.error,V=console.group,Y=console.groupCollapsed,oe=console.groupEnd;var E={configurable:!0,enumerable:!0,value:ye,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}B++}}function G(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},E,{value:M}),info:N({},E,{value:Q}),warn:N({},E,{value:z}),error:N({},E,{value:_}),group:N({},E,{value:V}),groupCollapsed:N({},E,{value:Y}),groupEnd:N({},E,{value:oe})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=g.ReactCurrentDispatcher,X;function L(E,W,se){{if(X===void 0)try{throw Error()}catch(Xe){var ve=Xe.stack.trim().match(/\n( *(at )?)/);X=ve&&ve[1]||""}return`
18
- `+X+E}}var K=!1,Z;{var ce=typeof WeakMap=="function"?WeakMap:Map;Z=new ce}function re(E,W){if(!E||K)return"";{var se=Z.get(E);if(se!==void 0)return se}var ve;K=!0;var Xe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ot;ot=U.current,U.current=null,Me();try{if(W){var $e=function(){throw Error()};if(Object.defineProperty($e.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct($e,[])}catch(Ke){ve=Ke}Reflect.construct(E,[],$e)}else{try{$e.call()}catch(Ke){ve=Ke}E.call($e.prototype)}}else{try{throw Error()}catch(Ke){ve=Ke}E()}}catch(Ke){if(Ke&&ve&&typeof Ke.stack=="string"){for(var Le=Ke.stack.split(`
17
+ */var Ja;function Gh(){return Ja||(Ja=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 y(E){if(E===null||typeof E!="object")return null;var W=x&&E[x]||E[m];return typeof W=="function"?W:null}var g=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var W=arguments.length,ie=new Array(W>1?W-1:0),ve=1;ve<W;ve++)ie[ve-1]=arguments[ve];S("error",E,ie)}}function S(E,W,ie){{var ve=g.ReactDebugCurrentFrame,Ve=ve.getStackAddendum();Ve!==""&&(W+="%s",ie=ie.concat([Ve]));var nt=ie.map(function($e){return String($e)});nt.unshift("Warning: "+W),Function.prototype.apply.call(console[E],console,nt)}}var k=!1,C=!1,T=!1,I=!1,A=!1,M;M=Symbol.for("react.module.reference");function L(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===c||E===d||I||E===h||k||C||T||typeof E=="object"&&E!==null&&(E.$$typeof===p||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===l||E.$$typeof===M||E.getModuleId!==void 0))}function P(E,W,ie){var ve=E.displayName;if(ve)return ve;var Ve=W.displayName||W.name||"";return Ve!==""?ie+"("+Ve+")":ie}function D(E){return E.displayName||"Context"}function F(E){if(E==null)return null;if(typeof E.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var W=E;return D(W)+".Consumer";case i:var ie=E;return D(ie._context)+".Provider";case l:return P(E,E.render,"ForwardRef");case f:var ve=E.displayName||null;return ve!==null?ve:F(E.type)||"Memo";case p:{var Ve=E,nt=Ve._payload,$e=Ve._init;try{return F($e(nt))}catch{return null}}}return null}var N=Object.assign,B=0,j,V,z,R,K,J,se;function ge(){}ge.__reactDisabledLog=!0;function Ie(){{if(B===0){j=console.log,V=console.info,z=console.warn,R=console.error,K=console.group,J=console.groupCollapsed,se=console.groupEnd;var E={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}B++}}function Y(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},E,{value:j}),info:N({},E,{value:V}),warn:N({},E,{value:z}),error:N({},E,{value:R}),group:N({},E,{value:K}),groupCollapsed:N({},E,{value:J}),groupEnd:N({},E,{value:se})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var U=g.ReactCurrentDispatcher,Z;function $(E,W,ie){{if(Z===void 0)try{throw Error()}catch(Ve){var ve=Ve.stack.trim().match(/\n( *(at )?)/);Z=ve&&ve[1]||""}return`
18
+ `+Z+E}}var q=!1,Q;{var ce=typeof WeakMap=="function"?WeakMap:Map;Q=new ce}function oe(E,W){if(!E||q)return"";{var ie=Q.get(E);if(ie!==void 0)return ie}var ve;q=!0;var Ve=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var nt;nt=U.current,U.current=null,Ie();try{if(W){var $e=function(){throw Error()};if(Object.defineProperty($e.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct($e,[])}catch(ue){ve=ue}Reflect.construct(E,[],$e)}else{try{$e.call()}catch(ue){ve=ue}E.call($e.prototype)}}else{try{throw Error()}catch(ue){ve=ue}E()}}catch(ue){if(ue&&ve&&typeof ue.stack=="string"){for(var Le=ue.stack.split(`
19
19
  `),Et=ve.stack.split(`
20
- `),mt=Le.length-1,xt=Et.length-1;mt>=1&&xt>=0&&Le[mt]!==Et[xt];)xt--;for(;mt>=1&&xt>=0;mt--,xt--)if(Le[mt]!==Et[xt]){if(mt!==1||xt!==1)do if(mt--,xt--,xt<0||Le[mt]!==Et[xt]){var fe=`
21
- `+Le[mt].replace(" at new "," at ");return E.displayName&&fe.includes("<anonymous>")&&(fe=fe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Z.set(E,fe),fe}while(mt>=1&&xt>=0);break}}}finally{K=!1,U.current=ot,G(),Error.prepareStackTrace=Xe}var we=E?E.displayName||E.name:"",ke=we?L(we):"";return typeof E=="function"&&Z.set(E,ke),ke}function je(E,W,se){return re(E,!1)}function Ue(E){var W=E.prototype;return!!(W&&W.isReactComponent)}function De(E,W,se){if(E==null)return"";if(typeof E=="function")return re(E,Ue(E));if(typeof E=="string")return L(E);switch(E){case c:return L("Suspense");case d:return L("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return je(E.render);case f:return De(E.type,W,se);case p:{var ve=E,Xe=ve._payload,ot=ve._init;try{return De(ot(Xe),W,se)}catch{}}}return""}var Ge=Object.prototype.hasOwnProperty,Ve={},tt=g.ReactDebugCurrentFrame;function Ye(E){if(E){var W=E._owner,se=De(E.type,E._source,W?W.type:null);tt.setExtraStackFrame(se)}else tt.setExtraStackFrame(null)}function ie(E,W,se,ve,Xe){{var ot=Function.call.bind(Ge);for(var $e in E)if(ot(E,$e)){var Le=void 0;try{if(typeof E[$e]!="function"){var Et=Error((ve||"React class")+": "+se+" type `"+$e+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[$e]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Et.name="Invariant Violation",Et}Le=E[$e](W,$e,ve,se,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Le=mt}Le&&!(Le instanceof Error)&&(Ye(Xe),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).",ve||"React class",se,$e,typeof Le),Ye(null)),Le instanceof Error&&!(Le.message in Ve)&&(Ve[Le.message]=!0,Ye(Xe),b("Failed %s type: %s",se,Le.message),Ye(null))}}}var xe=Array.isArray;function He(E){return xe(E)}function We(E){{var W=typeof Symbol=="function"&&Symbol.toStringTag,se=W&&E[Symbol.toStringTag]||E.constructor.name||"Object";return se}}function rt(E){try{return at(E),!1}catch{return!0}}function at(E){return""+E}function Rt(E){if(rt(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",We(E)),at(E)}var gt=g.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0},bt,St;function Lt(E){if(Ge.call(E,"ref")){var W=Object.getOwnPropertyDescriptor(E,"ref").get;if(W&&W.isReactWarning)return!1}return E.ref!==void 0}function Mt(E){if(Ge.call(E,"key")){var W=Object.getOwnPropertyDescriptor(E,"key").get;if(W&&W.isReactWarning)return!1}return E.key!==void 0}function nt(E,W){typeof E.ref=="string"&&gt.current}function It(E,W){{var se=function(){bt||(bt=!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))};se.isReactWarning=!0,Object.defineProperty(E,"key",{get:se,configurable:!0})}}function bn(E,W){{var se=function(){St||(St=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",W))};se.isReactWarning=!0,Object.defineProperty(E,"ref",{get:se,configurable:!0})}}var Je=function(E,W,se,ve,Xe,ot,$e){var Le={$$typeof:t,type:E,key:W,ref:se,props:$e,_owner:ot};return Le._store={},Object.defineProperty(Le._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Le,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ve}),Object.defineProperty(Le,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Xe}),Object.freeze&&(Object.freeze(Le.props),Object.freeze(Le)),Le};function Ze(E,W,se,ve,Xe){{var ot,$e={},Le=null,Et=null;se!==void 0&&(Rt(se),Le=""+se),Mt(W)&&(Rt(W.key),Le=""+W.key),Lt(W)&&(Et=W.ref,nt(W,Xe));for(ot in W)Ge.call(W,ot)&&!ht.hasOwnProperty(ot)&&($e[ot]=W[ot]);if(E&&E.defaultProps){var mt=E.defaultProps;for(ot in mt)$e[ot]===void 0&&($e[ot]=mt[ot])}if(Le||Et){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Le&&It($e,xt),Et&&bn($e,xt)}return Je(E,Le,Et,Xe,ve,gt.current,$e)}}var pt=g.ReactCurrentOwner,lt=g.ReactDebugCurrentFrame;function q(E){if(E){var W=E._owner,se=De(E.type,E._source,W?W.type:null);lt.setExtraStackFrame(se)}else lt.setExtraStackFrame(null)}var j;j=!1;function J(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function ne(){{if(pt.current){var E=F(pt.current.type);if(E)return`
20
+ `),pt=Le.length-1,mt=Et.length-1;pt>=1&&mt>=0&&Le[pt]!==Et[mt];)mt--;for(;pt>=1&&mt>=0;pt--,mt--)if(Le[pt]!==Et[mt]){if(pt!==1||mt!==1)do if(pt--,mt--,mt<0||Le[pt]!==Et[mt]){var Ut=`
21
+ `+Le[pt].replace(" at new "," at ");return E.displayName&&Ut.includes("<anonymous>")&&(Ut=Ut.replace("<anonymous>",E.displayName)),typeof E=="function"&&Q.set(E,Ut),Ut}while(pt>=1&&mt>=0);break}}}finally{q=!1,U.current=nt,Y(),Error.prepareStackTrace=Ve}var Vn=E?E.displayName||E.name:"",_n=Vn?$(Vn):"";return typeof E=="function"&&Q.set(E,_n),_n}function Ae(E,W,ie){return oe(E,!1)}function ze(E){var W=E.prototype;return!!(W&&W.isReactComponent)}function re(E,W,ie){if(E==null)return"";if(typeof E=="function")return oe(E,ze(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return Ae(E.render);case f:return re(E.type,W,ie);case p:{var ve=E,Ve=ve._payload,nt=ve._init;try{return re(nt(Ve),W,ie)}catch{}}}return""}var xe=Object.prototype.hasOwnProperty,Me={},Je=g.ReactDebugCurrentFrame;function Ze(E){if(E){var W=E._owner,ie=re(E.type,E._source,W?W.type:null);Je.setExtraStackFrame(ie)}else Je.setExtraStackFrame(null)}function We(E,W,ie,ve,Ve){{var nt=Function.call.bind(xe);for(var $e in E)if(nt(E,$e)){var Le=void 0;try{if(typeof E[$e]!="function"){var Et=Error((ve||"React class")+": "+ie+" type `"+$e+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[$e]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Et.name="Invariant Violation",Et}Le=E[$e](W,$e,ve,ie,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(pt){Le=pt}Le&&!(Le instanceof Error)&&(Ze(Ve),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).",ve||"React class",ie,$e,typeof Le),Ze(null)),Le instanceof Error&&!(Le.message in Me)&&(Me[Le.message]=!0,Ze(Ve),b("Failed %s type: %s",ie,Le.message),Ze(null))}}}var et=Array.isArray;function st(E){return et(E)}function Ke(E){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ie=W&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ie}}function tt(E){try{return it(E),!1}catch{return!0}}function it(E){return""+E}function Rt(E){if(tt(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(E)),it(E)}var gt=g.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0},vt,wt;function $t(E){if(xe.call(E,"ref")){var W=Object.getOwnPropertyDescriptor(E,"ref").get;if(W&&W.isReactWarning)return!1}return E.ref!==void 0}function Mt(E){if(xe.call(E,"key")){var W=Object.getOwnPropertyDescriptor(E,"key").get;if(W&&W.isReactWarning)return!1}return E.key!==void 0}function Qe(E,W){typeof E.ref=="string"&&gt.current}function It(E,W){{var ie=function(){vt||(vt=!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))};ie.isReactWarning=!0,Object.defineProperty(E,"key",{get:ie,configurable:!0})}}function Sn(E,W){{var ie=function(){wt||(wt=!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))};ie.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ie,configurable:!0})}}var qe=function(E,W,ie,ve,Ve,nt,$e){var Le={$$typeof:t,type:E,key:W,ref:ie,props:$e,_owner:nt};return Le._store={},Object.defineProperty(Le._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Le,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ve}),Object.defineProperty(Le,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ve}),Object.freeze&&(Object.freeze(Le.props),Object.freeze(Le)),Le};function Ge(E,W,ie,ve,Ve){{var nt,$e={},Le=null,Et=null;ie!==void 0&&(Rt(ie),Le=""+ie),Mt(W)&&(Rt(W.key),Le=""+W.key),$t(W)&&(Et=W.ref,Qe(W,Ve));for(nt in W)xe.call(W,nt)&&!ht.hasOwnProperty(nt)&&($e[nt]=W[nt]);if(E&&E.defaultProps){var pt=E.defaultProps;for(nt in pt)$e[nt]===void 0&&($e[nt]=pt[nt])}if(Le||Et){var mt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Le&&It($e,mt),Et&&Sn($e,mt)}return qe(E,Le,Et,Ve,ve,gt.current,$e)}}var ft=g.ReactCurrentOwner,at=g.ReactDebugCurrentFrame;function G(E){if(E){var W=E._owner,ie=re(E.type,E._source,W?W.type:null);at.setExtraStackFrame(ie)}else at.setExtraStackFrame(null)}var _;_=!1;function X(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function ee(){{if(ft.current){var E=F(ft.current.type);if(E)return`
22
22
 
23
- Check the render method of \``+E+"`."}return""}}function pe(E){return""}var Ae={};function be(E){{var W=ne();if(!W){var se=typeof E=="string"?E:E.displayName||E.name;se&&(W=`
23
+ Check the render method of \``+E+"`."}return""}}function pe(E){return""}var be={};function we(E){{var W=ee();if(!W){var ie=typeof E=="string"?E:E.displayName||E.name;ie&&(W=`
24
24
 
25
- Check the top-level render call using <`+se+">.")}return W}}function Fe(E,W){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var se=be(W);if(Ae[se])return;Ae[se]=!0;var ve="";E&&E._owner&&E._owner!==pt.current&&(ve=" It was passed a child from "+F(E._owner.type)+"."),q(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',se,ve),q(null)}}function Pe(E,W){{if(typeof E!="object")return;if(He(E))for(var se=0;se<E.length;se++){var ve=E[se];J(ve)&&Fe(ve,W)}else if(J(E))E._store&&(E._store.validated=!0);else if(E){var Xe=y(E);if(typeof Xe=="function"&&Xe!==E.entries)for(var ot=Xe.call(E),$e;!($e=ot.next()).done;)J($e.value)&&Fe($e.value,W)}}}function Ne(E){{var W=E.type;if(W==null||typeof W=="string")return;var se;if(typeof W=="function")se=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))se=W.propTypes;else return;if(se){var ve=F(W);ie(se,E.props,"prop",ve,E)}else if(W.PropTypes!==void 0&&!j){j=!0;var Xe=F(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Xe||"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 Vt(E){{for(var W=Object.keys(E.props),se=0;se<W.length;se++){var ve=W[se];if(ve!=="children"&&ve!=="key"){q(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ve),q(null);break}}E.ref!==null&&(q(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),q(null))}}var En={};function ir(E,W,se,ve,Xe,ot){{var $e=$(E);if(!$e){var Le="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(Le+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Et=pe();Et?Le+=Et:Le+=ne();var mt;E===null?mt="null":He(E)?mt="array":E!==void 0&&E.$$typeof===t?(mt="<"+(F(E.type)||"Unknown")+" />",Le=" Did you accidentally export a JSX literal instead of a component?"):mt=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",mt,Le)}var xt=Ze(E,W,se,Xe,ot);if(xt==null)return xt;if($e){var fe=W.children;if(fe!==void 0)if(ve)if(He(fe)){for(var we=0;we<fe.length;we++)Pe(fe[we],E);Object.freeze&&Object.freeze(fe)}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 Pe(fe,E)}if(Ge.call(W,"key")){var ke=F(E),Ke=Object.keys(W).filter(function(cT){return cT!=="key"}),Un=Ke.length>0?"{key: someKey, "+Ke.join(": ..., ")+": ...}":"{key: someKey}";if(!En[ke+Un]){var tn=Ke.length>0?"{"+Ke.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+ie+">.")}return W}}function Ue(E,W){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ie=we(W);if(be[ie])return;be[ie]=!0;var ve="";E&&E._owner&&E._owner!==ft.current&&(ve=" It was passed a child from "+F(E._owner.type)+"."),G(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ie,ve),G(null)}}function _e(E,W){{if(typeof E!="object")return;if(st(E))for(var ie=0;ie<E.length;ie++){var ve=E[ie];X(ve)&&Ue(ve,W)}else if(X(E))E._store&&(E._store.validated=!0);else if(E){var Ve=y(E);if(typeof Ve=="function"&&Ve!==E.entries)for(var nt=Ve.call(E),$e;!($e=nt.next()).done;)X($e.value)&&Ue($e.value,W)}}}function De(E){{var W=E.type;if(W==null||typeof W=="string")return;var ie;if(typeof W=="function")ie=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))ie=W.propTypes;else return;if(ie){var ve=F(W);We(ie,E.props,"prop",ve,E)}else if(W.PropTypes!==void 0&&!_){_=!0;var Ve=F(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ve||"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 Pt(E){{for(var W=Object.keys(E.props),ie=0;ie<W.length;ie++){var ve=W[ie];if(ve!=="children"&&ve!=="key"){G(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ve),G(null);break}}E.ref!==null&&(G(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),G(null))}}var un={};function dn(E,W,ie,ve,Ve,nt){{var $e=L(E);if(!$e){var Le="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(Le+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Et=pe();Et?Le+=Et:Le+=ee();var pt;E===null?pt="null":st(E)?pt="array":E!==void 0&&E.$$typeof===t?(pt="<"+(F(E.type)||"Unknown")+" />",Le=" Did you accidentally export a JSX literal instead of a component?"):pt=typeof E,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",pt,Le)}var mt=Ge(E,W,ie,Ve,nt);if(mt==null)return mt;if($e){var Ut=W.children;if(Ut!==void 0)if(ve)if(st(Ut)){for(var Vn=0;Vn<Ut.length;Vn++)_e(Ut[Vn],E);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 _e(Ut,E)}if(xe.call(W,"key")){var _n=F(E),ue=Object.keys(W).filter(function(St){return St!=="key"}),ke=ue.length>0?"{key: someKey, "+ue.join(": ..., ")+": ...}":"{key: someKey}";if(!un[_n+ke]){var Pe=ue.length>0?"{"+ue.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
26
26
  let props = %s;
27
27
  <%s {...props} />
28
28
  React keys must be passed directly to JSX without using spread:
29
29
  let props = %s;
30
- <%s key={someKey} {...props} />`,Un,ke,tn,ke),En[ke+Un]=!0}}return E===r?Vt(xt):Ne(xt),xt}}function Ar(E,W,se){return ir(E,W,se,!0)}function fo(E,W,se){return ir(E,W,se,!1)}var zn=fo,ar=Ar;_r.Fragment=r,_r.jsx=zn,_r.jsxs=ar}()),_r}process.env.NODE_ENV==="production"?Xs.exports=Wh():Xs.exports=Vh();var u=Xs.exports;function Ya(e,t){return function(){return e.apply(t,arguments)}}const{toString:Kh}=Object.prototype,{getPrototypeOf:Js}=Object,{iterator:mo,toStringTag:Xa}=Symbol,go=(e=>t=>{const n=Kh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),nn=e=>(e=e.toLowerCase(),t=>go(t)===e),xo=e=>t=>typeof t===e,{isArray:lr}=Array,cr=xo("undefined");function jr(e){return e!==null&&!cr(e)&&e.constructor!==null&&!cr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Ja=nn("ArrayBuffer");function qh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Ja(e.buffer),t}const Gh=xo("string"),$t=xo("function"),Za=xo("number"),Rr=e=>e!==null&&typeof e=="object",Yh=e=>e===!0||e===!1,yo=e=>{if(go(e)!=="object")return!1;const t=Js(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Xa in e)&&!(mo in e)},Xh=e=>{if(!Rr(e)||jr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Jh=nn("Date"),Zh=nn("File"),Qh=nn("Blob"),em=nn("FileList"),tm=e=>Rr(e)&&$t(e.pipe),nm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=go(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},rm=nn("URLSearchParams"),[om,sm,im,am]=["ReadableStream","Request","Response","Headers"].map(nn),lm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Mr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),lr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(jr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function Qa(e,t){if(jr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Wn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,el=e=>!cr(e)&&e!==Wn;function Zs(){const{caseless:e,skipUndefined:t}=el(this)&&this||{},n={},r=(o,s)=>{const i=e&&Qa(n,s)||s;yo(n[i])&&yo(o)?n[i]=Zs(n[i],o):yo(o)?n[i]=Zs({},o):lr(o)?n[i]=o.slice():(!t||!cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Mr(arguments[o],r);return n}const cm=(e,t,n,{allOwnKeys:r}={})=>(Mr(t,(o,s)=>{n&&$t(o)?e[s]=Ya(o,n):e[s]=o},{allOwnKeys:r}),e),um=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),dm=(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)},fm=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&Js(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},pm=(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},hm=e=>{if(!e)return null;if(lr(e))return e;let t=e.length;if(!Za(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},mm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Js(Uint8Array)),gm=(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])}},xm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},ym=nn("HTMLFormElement"),vm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),tl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),bm=nn("RegExp"),nl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Mr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wm=e=>{nl(e,(t,n)=>{if($t(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if($t(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Sm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return lr(e)?r(e):r(String(e).split(t)),n},Cm=()=>{},Tm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function km(e){return!!(e&&$t(e.append)&&e[Xa]==="FormData"&&e[mo])}const Im=e=>{const t=new Array(10),n=(r,o)=>{if(Rr(r)){if(t.indexOf(r)>=0)return;if(jr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=lr(r)?[]:{};return Mr(r,(i,a)=>{const l=n(i,o+1);!cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Em=nn("AsyncFunction"),Am=e=>e&&(Rr(e)||$t(e))&&$t(e.then)&&$t(e.catch),rl=((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",$t(Wn.postMessage)),Nm=typeof queueMicrotask<"u"?queueMicrotask.bind(Wn):typeof process<"u"&&process.nextTick||rl,D={isArray:lr,isArrayBuffer:Ja,isBuffer:jr,isFormData:nm,isArrayBufferView:qh,isString:Gh,isNumber:Za,isBoolean:Yh,isObject:Rr,isPlainObject:yo,isEmptyObject:Xh,isReadableStream:om,isRequest:sm,isResponse:im,isHeaders:am,isUndefined:cr,isDate:Jh,isFile:Zh,isBlob:Qh,isRegExp:bm,isFunction:$t,isStream:tm,isURLSearchParams:rm,isTypedArray:mm,isFileList:em,forEach:Mr,merge:Zs,extend:cm,trim:lm,stripBOM:um,inherits:dm,toFlatObject:fm,kindOf:go,kindOfTest:nn,endsWith:pm,toArray:hm,forEachEntry:gm,matchAll:xm,isHTMLForm:ym,hasOwnProperty:tl,hasOwnProp:tl,reduceDescriptors:nl,freezeMethods:wm,toObjectSet:Sm,toCamelCase:vm,noop:Cm,toFiniteNumber:Tm,findKey:Qa,global:Wn,isContextDefined:el,isSpecCompliantForm:km,toJSONObject:Im,isAsyncFn:Em,isThenable:Am,setImmediate:rl,asap:Nm,isIterable:e=>e!=null&&$t(e[mo])};function _e(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}D.inherits(_e,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:D.toJSONObject(this.config),code:this.code,status:this.status}}});const ol=_e.prototype,sl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{sl[e]={value:e}}),Object.defineProperties(_e,sl),Object.defineProperty(ol,"isAxiosError",{value:!0}),_e.from=(e,t,n,r,o,s)=>{const i=Object.create(ol);D.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 _e.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const _m=null;function Qs(e){return D.isPlainObject(e)||D.isArray(e)}function il(e){return D.endsWith(e,"[]")?e.slice(0,-2):e}function al(e,t,n){return e?e.concat(t).map(function(o,s){return o=il(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function jm(e){return D.isArray(e)&&!e.some(Qs)}const Rm=D.toFlatObject(D,{},null,function(t){return/^is[A-Z]/.test(t)});function vo(e,t,n){if(!D.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=D.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,y){return!D.isUndefined(y[m])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&D.isSpecCompliantForm(t);if(!D.isFunction(o))throw new TypeError("visitor must be a function");function c(x){if(x===null)return"";if(D.isDate(x))return x.toISOString();if(D.isBoolean(x))return x.toString();if(!l&&D.isBlob(x))throw new _e("Blob is not supported. Use a Buffer instead.");return D.isArrayBuffer(x)||D.isTypedArray(x)?l&&typeof Blob=="function"?new Blob([x]):Buffer.from(x):x}function d(x,m,y){let g=x;if(x&&!y&&typeof x=="object"){if(D.endsWith(m,"{}"))m=r?m:m.slice(0,-2),x=JSON.stringify(x);else if(D.isArray(x)&&jm(x)||(D.isFileList(x)||D.endsWith(m,"[]"))&&(g=D.toArray(x)))return m=il(m),g.forEach(function(S,k){!(D.isUndefined(S)||S===null)&&t.append(i===!0?al([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Qs(x)?!0:(t.append(al(y,m,s),c(x)),!1)}const f=[],p=Object.assign(Rm,{defaultVisitor:d,convertValue:c,isVisitable:Qs});function h(x,m){if(!D.isUndefined(x)){if(f.indexOf(x)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(x),D.forEach(x,function(g,b){(!(D.isUndefined(g)||g===null)&&o.call(t,g,D.isString(b)?b.trim():b,m,p))===!0&&h(g,m?m.concat(b):[b])}),f.pop()}}if(!D.isObject(e))throw new TypeError("data must be an object");return h(e),t}function ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ei(e,t){this._pairs=[],e&&vo(e,this,t)}const cl=ei.prototype;cl.append=function(t,n){this._pairs.push([t,n])},cl.toString=function(t){const n=t?function(r){return t.call(this,r,ll)}:ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Mm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ul(e,t,n){if(!t)return e;const r=n&&n.encode||Mm;D.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=D.isURLSearchParams(t)?t.toString():new ei(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class dl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){D.forEach(this.handlers,function(r){r!==null&&t(r)})}}const fl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Pm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ei,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ti=typeof window<"u"&&typeof document<"u",ni=typeof navigator=="object"&&navigator||void 0,Om=ti&&(!ni||["ReactNative","NativeScript","NS"].indexOf(ni.product)<0),Dm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Lm=ti&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ti,hasStandardBrowserEnv:Om,hasStandardBrowserWebWorkerEnv:Dm,navigator:ni,origin:Lm},Symbol.toStringTag,{value:"Module"})),...Pm};function $m(e,t){return vo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&D.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Fm(e){return D.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Bm(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 pl(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&&D.isArray(o)?o.length:i,l?(D.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!D.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&D.isArray(o[i])&&(o[i]=Bm(o[i])),!a)}if(D.isFormData(e)&&D.isFunction(e.entries)){const n={};return D.forEachEntry(e,(r,o)=>{t(Fm(r),o,n,0)}),n}return null}function zm(e,t,n){if(D.isString(e))try{return(t||JSON.parse)(e),D.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Pr={transitional:fl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=D.isObject(t);if(s&&D.isHTMLForm(t)&&(t=new FormData(t)),D.isFormData(t))return o?JSON.stringify(pl(t)):t;if(D.isArrayBuffer(t)||D.isBuffer(t)||D.isStream(t)||D.isFile(t)||D.isBlob(t)||D.isReadableStream(t))return t;if(D.isArrayBufferView(t))return t.buffer;if(D.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 $m(t,this.formSerializer).toString();if((a=D.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),zm(t)):t}],transformResponse:[function(t){const n=this.transitional||Pr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(D.isResponse(t)||D.isReadableStream(t))return t;if(t&&D.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?_e.from(a,_e.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};D.forEach(["delete","get","head","post","put","patch"],e=>{Pr.headers[e]={}});const Um=D.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"]),Hm=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]&&Um[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},hl=Symbol("internals");function Or(e){return e&&String(e).trim().toLowerCase()}function bo(e){return e===!1||e==null?e:D.isArray(e)?e.map(bo):String(e)}function Wm(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 Vm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ri(e,t,n,r,o){if(D.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!D.isString(t)){if(D.isString(r))return t.indexOf(r)!==-1;if(D.isRegExp(r))return r.test(t)}}function Km(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function qm(e,t){const n=D.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Ft=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Or(l);if(!d)throw new Error("header name must be a non-empty string");const f=D.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)=>D.forEach(a,(c,d)=>s(c,d,l));if(D.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(D.isString(t)&&(t=t.trim())&&!Vm(t))i(Hm(t),n);else if(D.isObject(t)&&D.isIterable(t)){let a={},l,c;for(const d of t){if(!D.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?D.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Or(t),t){const r=D.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Wm(o);if(D.isFunction(n))return n.call(this,o,r);if(D.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Or(t),t){const r=D.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ri(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Or(i),i){const a=D.findKey(r,i);a&&(!n||ri(r,r[a],a,n))&&(delete r[a],o=!0)}}return D.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||ri(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return D.forEach(this,(o,s)=>{const i=D.findKey(r,s);if(i){n[i]=bo(o),delete n[s];return}const a=t?Km(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 D.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&D.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[hl]=this[hl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Or(i);r[a]||(qm(o,i),r[a]=!0)}return D.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),D.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),D.freezeMethods(Ft);function oi(e,t){const n=this||Pr,r=t||n,o=Ft.from(r.headers);let s=r.data;return D.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ml(e){return!!(e&&e.__CANCEL__)}function ur(e,t,n){_e.call(this,e??"canceled",_e.ERR_CANCELED,t,n),this.name="CanceledError"}D.inherits(ur,_e,{__CANCEL__:!0});function gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new _e("Request failed with status code "+n.status,[_e.ERR_BAD_REQUEST,_e.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Gm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Ym(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 Xm(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=Ym(50,250);return Xm(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)},xl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},yl=e=>(...t)=>D.asap(()=>e(...t)),Jm=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,Zm=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];D.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),D.isString(r)&&i.push("path="+r),D.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 Qm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function eg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function vl(e,t,n){let r=!Qm(t);return e&&(r||n==!1)?eg(e,t):t}const bl=e=>e instanceof Ft?{...e}:e;function Vn(e,t){t=t||{};const n={};function r(c,d,f,p){return D.isPlainObject(c)&&D.isPlainObject(d)?D.merge.call({caseless:p},c,d):D.isPlainObject(d)?D.merge({},d):D.isArray(d)?d.slice():d}function o(c,d,f,p){if(D.isUndefined(d)){if(!D.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!D.isUndefined(d))return r(void 0,d)}function i(c,d){if(D.isUndefined(d)){if(!D.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(bl(c),bl(d),f,!0)};return D.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);D.isUndefined(p)&&f!==a||(n[d]=p)}),n}const wl=e=>{const t=Vn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=ul(vl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),D.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(D.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(At.hasStandardBrowserEnv&&(r&&D.isFunction(r)&&(r=r(t)),r||r!==!1&&Jm(t.url))){const l=o&&s&&Zm.read(s);l&&i.set(o,l)}return t},tg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=wl(e);let s=o.data;const i=Ft.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 y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function g(){if(!y)return;const S=Ft.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};gl(function(I){n(I),m()},function(I){r(I),m()},C),y=null}"onloadend"in y?y.onloadend=g:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(g)},y.onabort=function(){y&&(r(new _e("Request aborted",_e.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new _e(C,_e.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||fl;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new _e(k,C.clarifyTimeoutError?_e.ETIMEDOUT:_e.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&D.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),D.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,x]=wo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=wo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ur(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Gm(o.url);if(b&&At.protocols.indexOf(b)===-1){r(new _e("Unsupported protocol "+b+":",_e.ERR_BAD_REQUEST,e));return}y.send(s||null)})},ng=(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 _e?d:new ur(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new _e(`timeout ${t} of ms exceeded`,_e.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(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=()=>D.asap(a),l}},rg=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},og=async function*(e,t){for await(const n of sg(e))yield*rg(n,t)},sg=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Sl=(e,t,n,r)=>{const o=og(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})},Cl=64*1024,{isFunction:So}=D,ig=(({Request:e,Response:t})=>({Request:e,Response:t}))(D.global),{ReadableStream:Tl,TextEncoder:kl}=D.global,Il=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ag=e=>{e=D.merge.call({skipUndefined:!0},ig,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(Tl),l=o&&(typeof kl=="function"?(x=>m=>x.encode(m))(new kl):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&Il(()=>{let x=!1;const m=new n(At.origin,{body:new Tl,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&Il(()=>D.isReadableStream(new r("").body)),f={stream:d&&(x=>x.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(x=>{!f[x]&&(f[x]=(m,y)=>{let g=m&&m[x];if(g)return g.call(m);throw new _e(`Response type '${x}' is not supported`,_e.ERR_NOT_SUPPORT,y)})});const p=async x=>{if(x==null)return 0;if(D.isBlob(x))return x.size;if(D.isSpecCompliantForm(x))return(await new n(At.origin,{method:"POST",body:x}).arrayBuffer()).byteLength;if(D.isArrayBufferView(x)||D.isArrayBuffer(x))return x.byteLength;if(D.isURLSearchParams(x)&&(x=x+""),D.isString(x))return(await l(x)).byteLength},h=async(x,m)=>{const y=D.toFiniteNumber(x.getContentLength());return y??p(m)};return async x=>{let{url:m,method:y,data:g,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:A,withCredentials:R="same-origin",fetchOptions:$}=wl(x),P=t||fetch;I=I?(I+"").toLowerCase():"text";let O=ng([b,S&&S.toAbortSignal()],k),F=null;const N=O&&O.unsubscribe&&(()=>{O.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await h(A,g))!==0){let Y=new n(m,{method:"POST",body:g,duplex:"half"}),oe;if(D.isFormData(g)&&(oe=Y.headers.get("content-type"))&&A.setContentType(oe),Y.body){const[ye,Me]=xl(B,wo(yl(T)));g=Sl(Y.body,Cl,ye,Me)}}D.isString(R)||(R=R?"include":"omit");const M=s&&"credentials"in n.prototype,Q={...$,signal:O,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:g,duplex:"half",credentials:M?R:void 0};F=s&&new n(m,Q);let z=await(s?P(F,$):P(m,Q));const _=d&&(I==="stream"||I==="response");if(d&&(C||_&&N)){const Y={};["status","statusText","headers"].forEach(G=>{Y[G]=z[G]});const oe=D.toFiniteNumber(z.headers.get("content-length")),[ye,Me]=C&&xl(oe,wo(yl(C),!0))||[];z=new r(Sl(z.body,Cl,ye,()=>{Me&&Me(),N&&N()}),Y)}I=I||"text";let V=await f[D.findKey(f,I)||"text"](z,x);return!_&&N&&N(),await new Promise((Y,oe)=>{gl(Y,oe,{data:V,headers:Ft.from(z.headers),status:z.status,statusText:z.statusText,config:x,request:F})})}catch(M){throw N&&N(),M&&M.name==="TypeError"&&/Load failed|fetch/i.test(M.message)?Object.assign(new _e("Network Error",_e.ERR_NETWORK,x,F),{cause:M.cause||M}):_e.from(M,M&&M.code,x,F)}}},lg=new Map,El=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=lg;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ag(t)),d=c;return c};El();const si={http:_m,xhr:tg,fetch:{get:El}};D.forEach(si,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Al=e=>`- ${e}`,cg=e=>D.isFunction(e)||e===null||e===!1,Nl={getAdapter:(e,t)=>{e=D.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,!cg(r)&&(o=si[(a=String(r)).toLowerCase()],o===void 0))throw new _e(`Unknown adapter '${a}'`);if(o&&(D.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(Al).join(`
34
- `):" "+Al(i[0]):"as no adapter specified";throw new _e("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:si};function ii(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ur(null,e)}function _l(e){return ii(e),e.headers=Ft.from(e.headers),e.data=oi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Nl.getAdapter(e.adapter||Pr.adapter,e)(e).then(function(r){return ii(e),r.data=oi.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return ml(r)||(ii(e),r&&r.response&&(r.response.data=oi.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const jl="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 Rl={};Co.transitional=function(t,n,r){function o(s,i){return"[Axios v"+jl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new _e(o(i," has been removed"+(n?" in "+n:"")),_e.ERR_DEPRECATED);return n&&!Rl[i]&&(Rl[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},Co.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function ug(e,t,n){if(typeof e!="object")throw new _e("options must be an object",_e.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new _e("option "+s+" must be "+l,_e.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new _e("Unknown option "+s,_e.ERR_BAD_OPTION)}}const To={assertOptions:ug,validators:Co},un=To.validators;let Kn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new dl,response:new dl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
35
- `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Vn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&To.assertOptions(r,{silentJSONParsing:un.transitional(un.boolean),forcedJSONParsing:un.transitional(un.boolean),clarifyTimeoutError:un.transitional(un.boolean)},!1),o!=null&&(D.isFunction(o)?n.paramsSerializer={serialize:o}:To.assertOptions(o,{encode:un.function,serialize:un.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),To.assertOptions(n,{baseUrl:un.spelling("baseURL"),withXsrfToken:un.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&D.merge(s.common,s[n.method]);s&&D.forEach(["delete","get","head","post","put","patch","common"],x=>{delete s[x]}),n.headers=Ft.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=[_l.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(y){m.call(this,y);break}}try{d=_l.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=vl(t.baseURL,t.url,t.allowAbsoluteUrls);return ul(n,t.params,t.paramsSerializer)}};D.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}))}}),D.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 dg=class zh{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new ur(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new zh(function(o){t=o}),cancel:t}}};function fg(e){return function(n){return e.apply(null,n)}}function pg(e){return D.isObject(e)&&e.isAxiosError===!0}const ai={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ai).forEach(([e,t])=>{ai[t]=e});function Ml(e){const t=new Kn(e),n=Ya(Kn.prototype.request,t);return D.extend(n,Kn.prototype,t,{allOwnKeys:!0}),D.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ml(Vn(e,o))},n}const yt=Ml(Pr);yt.Axios=Kn,yt.CanceledError=ur,yt.CancelToken=dg,yt.isCancel=ml,yt.VERSION=jl,yt.toFormData=vo,yt.AxiosError=_e,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=fg,yt.isAxiosError=pg,yt.mergeConfig=Vn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>pl(D.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Nl.getAdapter,yt.HttpStatusCode=ai,yt.default=yt;const{Axios:yT,AxiosError:vT,CanceledError:bT,isCancel:wT,CancelToken:ST,VERSION:CT,all:TT,Cancel:kT,isAxiosError:IT,spread:ET,toFormData:AT,AxiosHeaders:NT,HttpStatusCode:_T,formToJSON:jT,getAdapter:RT,mergeConfig:MT}=yt,Pl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ol=Pl?wn(Pl):void 0;function wn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ko=null;const li=new Set;function Dl(){return ko}function Io(e){ko=e,li.forEach(t=>t(e))}function Ll(e){return li.add(e),()=>li.delete(e)}const hg=3e4,mg=9e4,Kt=yt.create({...Ol?{baseURL:Ol}:{},timeout:hg,withCredentials:!0});Kt.interceptors.request.use(e=>(ko&&(e.headers.Authorization=`Bearer ${ko}`),e)),Kt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Io(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function qt(e,t){return Kt.defaults.baseURL?(await Kt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function ci(e,t,n){return Kt.defaults.baseURL?(await Kt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t,n){return Kt.defaults.baseURL?(await Kt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fl(e,t){return Kt.defaults.baseURL?(await Kt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Gt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Bl{get baseUrl(){const t=Kt.defaults.baseURL;return t?wn(String(t)):""}updateConfig(t){t.baseUrl&&(Kt.defaults.baseURL=wn(String(t.baseUrl))),t.authToken!==void 0&&Io(t.authToken)}getAuthToken(){return Dl()}setAuthToken(t){Io(t)}onTokenChange(t){return Ll(t)}async listThreads(){const t=await qt("/threads"),n=Gt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await ci("/threads",t?{title:t}:void 0);return Gt(r)}async updateThread(t,n){const r=await $l(`/threads/${t}`,{title:n});return Gt(r)}async deleteThread(t){const n=await Fl(`/threads/${t}`);return Gt(n)}async threadInfo(t){const n=await qt(`/threads/${t}/info`);return Gt(n)}async listAgents(){const t=await qt("/agents"),n=Gt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await qt(`/agents/${t}`);return Gt(n)}async getAgentSchema(t){const n=await qt(`/agents/${t}/schema`);return Gt(n)}async getState(t){const n=await qt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Gt(n)}async getStateHistory(t){const n=await qt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:mg});return Gt(n)}async cancelRun(t){const n=await ci("/runs/cancel",{threadId:t});return Gt(n)}async listCheckpointSummaries(t){const n=await qt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Gt(n);return(r==null?void 0:r.items)??[]}}const An=new Bl,zl=w.createContext(null);function gg({children:e,apiConfig:t}){const n=An;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(zl.Provider,{value:r,children:e})}function ui(){const e=w.useContext(zl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function xg(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 yg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await xg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const vg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function di(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function bg(e,t){return`${e??""}::${t??""}`}function dr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!di(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=Sg(t),i=Ul(r,0),a=Cg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Ul(e,t){if(!di(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(R=>!!R&&typeof R=="object").map(R=>({...R})):a===null?null:void 0,c=r.map((R,$)=>Rg(R,$)).filter(R=>!!R),d=Pt(e.config),f=Pt(d==null?void 0:d.configurable),p=dt(f,["checkpoint_id","checkpointId"]),h=dt(f,["checkpoint_ns","checkpointNs"]),x=Pt(e==null?void 0:e.parentConfig),m=Pt(x==null?void 0:x.configurable),y=dt(m,["checkpoint_id","checkpointId"])??null,g=dt(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(R=>R.role==="user")??null,C=Pt(e==null?void 0:e.metadata),T=dt(C,["branch_label","branchLabel"]),I=dt(m,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:g,interrupt:wg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:x??null,next:A??null,tasks:l??null,values:i??null}}function wg(e,t,n){const r=_g(e,n);return r||Ng(t,n)}function Sg(e){const t=new Map;e.forEach((o,s)=>{if(!di(o))return;const i=Ul(o,s);if(!(i!=null&&i.checkpointId))return;const a=bg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ig(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Wl(s.createdAt??"")-Wl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Cg(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=kg(i,["step"]),c=dt(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Tg(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0,parentConfig:o.parentConfig??null})}return t}function Tg(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 kg(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 Ig(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:Eg(e.next,t.next)??null,tasks:Ag(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 Eg(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 Ag(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 Ng(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 _g(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=jg(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Dr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Dr(r.state,`${o}-state`);if(s)return s}}return null}function jg(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,y=p.length?p[p.length-1]:void 0;return{id:h,name:x,interrupts:m,state:y!==void 0?y:f}}const n=Pt(e);if(!n)return null;const r=dt(n,["id","thread_id","taskId"])??t,o=dt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Dr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Hl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Dr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Dr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Dr(l,t,n+1,r);if(c)return c}}return null}function Hl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=dt(n,["type","event","kind"]),o=dt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Hl(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 Wl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Rg(e,t){if(!e||typeof e!="object")return null;const n=e,r=Pt(e)??{},o=Pt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=vg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,c=Pt(o.additional_kwargs)??Pt(o.additionalKwargs),d=Pt(o.response_metadata)??Pt(o.responseMetadata),f=dt(c,["createdAt","created_at"])??dt(o,["created_at","createdAt"]),p=dt(c,["checkpointId","checkpoint_id"]),h=dt(c,["checkpointNs","checkpoint_ns"]),x=Mg(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 y=Dg(Pt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);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=Pg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=Og(o,m.content);k&&(m.content=k)}return m}function Mg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Vl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Vl(e);return t?[t]:[]}return[]}function Vl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=dt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=dt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Kl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=dt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Kl(e,t){var s;const n=dt(e,["id","call_id"])??t,r=dt(e,["name"])??dt(Pt(e.function),["name"]);if(!n||!r)return null;const o=Fg(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Pg(e){return Array.isArray(e)?e.map((t,n)=>Kl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Og(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 Dg(e){return e?{plots:Lg(e.plots)}:void 0}function Lg(e){return Array.isArray(e)?e.map(t=>$g(t)).filter(t=>!!t):[]}function $g(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function Fg(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function Pt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function dt(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 fr=120;function zg(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>fr?`${n.slice(0,fr-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>fr?`${i.slice(0,fr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>fr?`${n.slice(0,fr-3)}…`:n:""}function ql(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=zg(n.content)||Ug(n);o&&t.set(n.id,o)}return t}function Gl(e={}){const t=w.useMemo(()=>wn(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,y]=w.useState(0),[g,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),A=w.useRef(null),R=w.useRef(null),$=w.useCallback(N=>{o(N)},[]),P=w.useCallback(()=>{p(""),x(null),d(null),I.current=null,A.current=null,R.current=null},[]),O=w.useCallback(()=>{var N;console.debug("[use-chat] stop() invoked - aborting stream"),(N=S.current)==null||N.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),F=w.useCallback((N,B,M)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),I.current=null,A.current=null,R.current=null;const Q=new AbortController;S.current=Q;let z=null,_=null,V=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var oe,ye,Me,G,U,X,L,K,Z,ce,re,je,Ue,De,Ge,Ve,tt,Ye;const Y=ie=>{var xe;try{const He=JSON.parse(JSON.stringify(ie));return(xe=He==null?void 0:He.payload)!=null&&xe.files_info&&Array.isArray(He.payload.files_info)&&(He.payload.files_info=He.payload.files_info.map(We=>({...We,data:We!=null&&We.data?`<base64 ${String(We.data).length} chars>`:We==null?void 0:We.data}))),He}catch{return ie}};try{let ie={};try{if(r)ie={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ze=window.__AUTH_TOKEN__,pt=((oe=window.localStorage)==null?void 0:oe.getItem("authToken"))||null;let lt=null;try{const j=(ye=window.localStorage)==null?void 0:ye.getItem("chat-settings");j&&(lt=((Me=JSON.parse(j))==null?void 0:Me.apiKey)||null)}catch{}const q=Ze||pt||lt||null;q&&(ie={Authorization:`Bearer ${q}`})}}catch{}console.debug("[use-chat] POST",t+n,Y(N));let xe={};if(typeof window<"u")try{const Je=(G=window.localStorage)==null?void 0:G.getItem("authSessionId");Je&&(xe={"X-Session-Id":Je})}catch{}const He={...ie,...xe,...s.current},We={"Content-Type":"application/json",Accept:"text/event-stream",...He},rt=await fetch(t+n,{method:"POST",headers:We,body:JSON.stringify(N),signal:Q.signal,credentials:i});if(T.current&&(T.current.headers=He),!rt.ok||!rt.body){const Je=await rt.text().catch(()=>"");console.debug("[use-chat] non-OK response",rt.status,Je==null?void 0:Je.slice(0,500));const Ze=`stream ${rt.status}${Je?": "+Je:""}`;throw(U=M==null?void 0:M.onConnectionError)==null||U.call(M,Ze),V=!0,z="error",_=Ze,new Error(Ze)}b(!0);const at=rt.body.getReader(),Rt=new TextDecoder;let gt="",ht=[];C.current=0,y(0);let bt=0,St=null;const Lt=()=>{if(ht.length){const Je=ht.join("");ht=[],k.current&&p(Ze=>Ze+Je)}St=null},Mt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Lt))};let nt=Date.now();const It=setInterval(()=>{var Je;if(Date.now()-nt>18e5){const Ze="Stream idle timeout";d(Ze),z="error",_=Ze,Q.abort(),(Je=M==null?void 0:M.onError)==null||Je.call(M,Ze)}},5e3),bn=1024*1024;try{const Je=rt.headers.get("X-Thread-Id")||rt.headers.get("x-thread-id"),Ze=rt.headers.get("X-Thread-Created")||rt.headers.get("x-thread-created"),pt=Je??null,lt=String(Ze??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(X=M==null?void 0:M.onOpen)==null||X.call(M,{threadId:pt,created:lt});;){const{value:q,done:j}=await at.read();if(j)break;gt+=Rt.decode(q,{stream:!0}),gt.length>bn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let J;for(;(J=gt.indexOf(`
30
+ <%s key={someKey} {...props} />`,ke,_n,Pe,_n),un[_n+ke]=!0}}return E===r?Pt(mt):De(mt),mt}}function Nr(E,W,ie){return dn(E,W,ie,!0)}function _r(E,W,ie){return dn(E,W,ie,!1)}var Wn=_r,jr=Nr;Mr.Fragment=r,Mr.jsx=Wn,Mr.jsxs=jr}()),Mr}process.env.NODE_ENV==="production"?Qs.exports=qh():Qs.exports=Gh();var u=Qs.exports;function Za(e,t){return function(){return e.apply(t,arguments)}}const{toString:Yh}=Object.prototype,{getPrototypeOf:ei}=Object,{iterator:xo,toStringTag:Qa}=Symbol,yo=(e=>t=>{const n=Yh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),nn=e=>(e=e.toLowerCase(),t=>yo(t)===e),vo=e=>t=>typeof t===e,{isArray:cr}=Array,ur=vo("undefined");function Pr(e){return e!==null&&!ur(e)&&e.constructor!==null&&!ur(e.constructor)&&Ft(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const el=nn("ArrayBuffer");function Xh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&el(e.buffer),t}const Jh=vo("string"),Ft=vo("function"),tl=vo("number"),Or=e=>e!==null&&typeof e=="object",Zh=e=>e===!0||e===!1,bo=e=>{if(yo(e)!=="object")return!1;const t=ei(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Qa in e)&&!(xo in e)},Qh=e=>{if(!Or(e)||Pr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},em=nn("Date"),tm=nn("File"),nm=nn("Blob"),rm=nn("FileList"),om=e=>Or(e)&&Ft(e.pipe),sm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Ft(e.append)&&((t=yo(e))==="formdata"||t==="object"&&Ft(e.toString)&&e.toString()==="[object FormData]"))},im=nn("URLSearchParams"),[am,lm,cm,um]=["ReadableStream","Request","Response","Headers"].map(nn),dm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Dr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),cr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Pr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function nl(e,t){if(Pr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const qn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,rl=e=>!ur(e)&&e!==qn;function ti(){const{caseless:e,skipUndefined:t}=rl(this)&&this||{},n={},r=(o,s)=>{const i=e&&nl(n,s)||s;bo(n[i])&&bo(o)?n[i]=ti(n[i],o):bo(o)?n[i]=ti({},o):cr(o)?n[i]=o.slice():(!t||!ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Dr(arguments[o],r);return n}const fm=(e,t,n,{allOwnKeys:r}={})=>(Dr(t,(o,s)=>{n&&Ft(o)?e[s]=Za(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&&ei(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(cr(e))return e;let t=e.length;if(!tl(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"&&ei(Uint8Array)),vm=(e,t)=>{const r=(e&&e[xo]).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=nn("HTMLFormElement"),Sm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),ol=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Cm=nn("RegExp"),sl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Dr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Tm=e=>{sl(e,(t,n)=>{if(Ft(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Ft(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 cr(e)?r(e):r(String(e).split(t)),n},Im=()=>{},Em=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Am(e){return!!(e&&Ft(e.append)&&e[Qa]==="FormData"&&e[xo])}const Nm=e=>{const t=new Array(10),n=(r,o)=>{if(Or(r)){if(t.indexOf(r)>=0)return;if(Pr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=cr(r)?[]:{};return Dr(r,(i,a)=>{const l=n(i,o+1);!ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},_m=nn("AsyncFunction"),jm=e=>e&&(Or(e)||Ft(e))&&Ft(e.then)&&Ft(e.catch),il=((e,t)=>e?setImmediate:t?((n,r)=>(qn.addEventListener("message",({source:o,data:s})=>{o===qn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),qn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Ft(qn.postMessage)),Rm=typeof queueMicrotask<"u"?queueMicrotask.bind(qn):typeof process<"u"&&process.nextTick||il,O={isArray:cr,isArrayBuffer:el,isBuffer:Pr,isFormData:sm,isArrayBufferView:Xh,isString:Jh,isNumber:tl,isBoolean:Zh,isObject:Or,isPlainObject:bo,isEmptyObject:Qh,isReadableStream:am,isRequest:lm,isResponse:cm,isHeaders:um,isUndefined:ur,isDate:em,isFile:tm,isBlob:nm,isRegExp:Cm,isFunction:Ft,isStream:om,isURLSearchParams:im,isTypedArray:ym,isFileList:rm,forEach:Dr,merge:ti,extend:fm,trim:dm,stripBOM:pm,inherits:hm,toFlatObject:mm,kindOf:yo,kindOfTest:nn,endsWith:gm,toArray:xm,forEachEntry:vm,matchAll:bm,isHTMLForm:wm,hasOwnProperty:ol,hasOwnProp:ol,reduceDescriptors:sl,freezeMethods:Tm,toObjectSet:km,toCamelCase:Sm,noop:Im,toFiniteNumber:Em,findKey:nl,global:qn,isContextDefined:rl,isSpecCompliantForm:Am,toJSONObject:Nm,isAsyncFn:_m,isThenable:jm,setImmediate:il,asap:Rm,isIterable:e=>e!=null&&Ft(e[xo])};function je(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}O.inherits(je,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:O.toJSONObject(this.config),code:this.code,status:this.status}}});const al=je.prototype,ll={};["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=>{ll[e]={value:e}}),Object.defineProperties(je,ll),Object.defineProperty(al,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(al);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return je.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const Mm=null;function ni(e){return O.isPlainObject(e)||O.isArray(e)}function cl(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function ul(e,t,n){return e?e.concat(t).map(function(o,s){return o=cl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Pm(e){return O.isArray(e)&&!e.some(ni)}const Om=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function wo(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,y){return!O.isUndefined(y[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 je("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,y){let g=x;if(x&&!y&&typeof x=="object"){if(O.endsWith(m,"{}"))m=r?m:m.slice(0,-2),x=JSON.stringify(x);else if(O.isArray(x)&&Pm(x)||(O.isFileList(x)||O.endsWith(m,"[]"))&&(g=O.toArray(x)))return m=cl(m),g.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?ul([m],k,s):i===null?m:m+"[]",c(S))}),!1}return ni(x)?!0:(t.append(ul(y,m,s),c(x)),!1)}const f=[],p=Object.assign(Om,{defaultVisitor:d,convertValue:c,isVisitable:ni});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 dl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ri(e,t){this._pairs=[],e&&wo(e,this,t)}const fl=ri.prototype;fl.append=function(t,n){this._pairs.push([t,n])},fl.toString=function(t){const n=t?function(r){return t.call(this,r,dl)}:dl;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 pl(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 ri(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class hl{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 ml={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Lm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:ri,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},oi=typeof window<"u"&&typeof document<"u",si=typeof navigator=="object"&&navigator||void 0,$m=oi&&(!si||["ReactNative","NativeScript","NS"].indexOf(si.product)<0),Fm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Bm=oi&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:oi,hasStandardBrowserEnv:$m,hasStandardBrowserWebWorkerEnv:Fm,navigator:si,origin:Bm},Symbol.toStringTag,{value:"Module"})),...Lm};function zm(e,t){return wo(e,new At.classes.URLSearchParams,{visitor:function(n,r,o,s){return At.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Um(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Hm(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 gl(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]=Hm(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Um(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 Lr={transitional:ml,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(gl(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 zm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return wo(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||Lr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?je.from(a,je.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:At.classes.FormData,Blob:At.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Lr.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},xl=Symbol("internals");function $r(e){return e&&String(e).trim().toLowerCase()}function So(e){return e===!1||e==null?e:O.isArray(e)?e.map(So):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 ii(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=$r(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]=So(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=$r(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=$r(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ii(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=$r(i),i){const a=O.findKey(r,i);a&&(!n||ii(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||ii(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]=So(o),delete n[s];return}const a=t?Ym(s):String(s).trim();a!==s&&delete n[s],n[a]=So(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[xl]=this[xl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=$r(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 ai(e,t){const n=this||Lr,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 yl(e){return!!(e&&e.__CANCEL__)}function dr(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(dr,je,{__CANCEL__:!0});function vl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new je("Request failed with status code "+n.status,[je.ERR_BAD_REQUEST,je.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function 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 Co=(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)},bl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},wl=e=>(...t)=>O.asap(()=>e(...t)),eg=At.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,At.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(At.origin),At.navigator&&/(msie|trident)/i.test(At.navigator.userAgent)):()=>!0,tg=At.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function ng(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function rg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Sl(e,t,n){let r=!ng(t);return e&&(r||n==!1)?rg(e,t):t}const Cl=e=>e instanceof Bt?{...e}:e;function Gn(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(Cl(c),Cl(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 Tl=e=>{const t=Gn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Bt.from(i),t.url=pl(Sl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(At.hasStandardBrowserEnv||At.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(At.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&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=Tl(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 y=new XMLHttpRequest;y.open(o.method.toUpperCase(),o.url,!0),y.timeout=o.timeout;function g(){if(!y)return;const S=Bt.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};vl(function(I){n(I),m()},function(I){r(I),m()},C),y=null}"onloadend"in y?y.onloadend=g:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(g)},y.onabort=function(){y&&(r(new je("Request aborted",je.ECONNABORTED,e,y)),y=null)},y.onerror=function(k){const C=k&&k.message?k.message:"Network Error",T=new je(C,je.ERR_NETWORK,e,y);T.event=k||null,r(T),y=null},y.ontimeout=function(){let k=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||ml;o.timeoutErrorMessage&&(k=o.timeoutErrorMessage),r(new je(k,C.clarifyTimeoutError?je.ETIMEDOUT:je.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&O.forEach(i.toJSON(),function(k,C){y.setRequestHeader(C,k)}),O.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([p,x]=Co(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=Co(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new dr(null,e,y):S),y.abort(),y=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Jm(o.url);if(b&&At.protocols.indexOf(b)===-1){r(new je("Unsupported protocol "+b+":",je.ERR_BAD_REQUEST,e));return}y.send(s||null)})},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 je?d:new dr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new je(`timeout ${t} of ms exceeded`,je.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>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()}},kl=(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})},Il=64*1024,{isFunction:To}=O,cg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:El,TextEncoder:Al}=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?To(t):typeof fetch=="function",s=To(n),i=To(r);if(!o)return!1;const a=o&&To(El),l=o&&(typeof Al=="function"?(x=>m=>x.encode(m))(new Al):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&Nl(()=>{let x=!1;const m=new n(At.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,y)=>{let g=m&&m[x];if(g)return g.call(m);throw new je(`Response type '${x}' is not supported`,je.ERR_NOT_SUPPORT,y)})});const p=async x=>{if(x==null)return 0;if(O.isBlob(x))return x.size;if(O.isSpecCompliantForm(x))return(await new n(At.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 y=O.toFiniteNumber(x.getContentLength());return y??p(m)};return async x=>{let{url:m,method:y,data:g,signal:b,cancelToken:S,timeout:k,onDownloadProgress:C,onUploadProgress:T,responseType:I,headers:A,withCredentials:M="same-origin",fetchOptions:L}=Tl(x),P=t||fetch;I=I?(I+"").toLowerCase():"text";let D=sg([b,S&&S.toAbortSignal()],k),F=null;const N=D&&D.unsubscribe&&(()=>{D.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await h(A,g))!==0){let J=new n(m,{method:"POST",body:g,duplex:"half"}),se;if(O.isFormData(g)&&(se=J.headers.get("content-type"))&&A.setContentType(se),J.body){const[ge,Ie]=bl(B,Co(wl(T)));g=kl(J.body,Il,ge,Ie)}}O.isString(M)||(M=M?"include":"omit");const j=s&&"credentials"in n.prototype,V={...L,signal:D,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:g,duplex:"half",credentials:j?M:void 0};F=s&&new n(m,V);let z=await(s?P(F,L):P(m,V));const R=d&&(I==="stream"||I==="response");if(d&&(C||R&&N)){const J={};["status","statusText","headers"].forEach(Y=>{J[Y]=z[Y]});const se=O.toFiniteNumber(z.headers.get("content-length")),[ge,Ie]=C&&bl(se,Co(wl(C),!0))||[];z=new r(kl(z.body,Il,ge,()=>{Ie&&Ie(),N&&N()}),J)}I=I||"text";let K=await f[O.findKey(f,I)||"text"](z,x);return!R&&N&&N(),await new Promise((J,se)=>{vl(J,se,{data:K,headers:Bt.from(z.headers),status:z.status,statusText:z.statusText,config:x,request:F})})}catch(j){throw N&&N(),j&&j.name==="TypeError"&&/Load failed|fetch/i.test(j.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,x,F),{cause:j.cause||j}):je.from(j,j&&j.code,x,F)}}},dg=new Map,_l=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};_l();const li={http:Mm,xhr:og,fetch:{get:_l}};O.forEach(li,(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,Rl={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=li[(a=String(r)).toLowerCase()],o===void 0))throw new je(`Unknown adapter '${a}'`);if(o&&(O.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
+ `+i.map(jl).join(`
34
+ `):" "+jl(i[0]):"as no adapter specified";throw new je("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:li};function ci(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dr(null,e)}function Ml(e){return ci(e),e.headers=Bt.from(e.headers),e.data=ai.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Rl.getAdapter(e.adapter||Lr.adapter,e)(e).then(function(r){return ci(e),r.data=ai.call(e,e.transformResponse,r),r.headers=Bt.from(r.headers),r},function(r){return yl(r)||(ci(e),r&&r.response&&(r.response.data=ai.call(e,e.transformResponse,r.response),r.response.headers=Bt.from(r.response.headers))),Promise.reject(r)})}const Pl="1.12.2",ko={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ko[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Ol={};ko.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 je(o(i," has been removed"+(n?" in "+n:"")),je.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}},ko.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 je("options must be an object",je.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new je("option "+s+" must be "+l,je.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new je("Unknown option "+s,je.ERR_BAD_OPTION)}}const Io={assertOptions:pg,validators:ko},fn=Io.validators;let Yn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new hl,response:new hl}}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=Gn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Io.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}:Io.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),Io.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=[Ml.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(y){m.call(this,y);break}}try{d=Ml.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=Gn(this.defaults,t);const n=Sl(t.baseURL,t.url,t.allowAbsoluteUrls);return pl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Yn.prototype[t]=function(n,r){return this.request(Gn(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(Gn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Yn.prototype[t]=n(),Yn.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 dr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new 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 ui={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(ui).forEach(([e,t])=>{ui[t]=e});function Dl(e){const t=new Yn(e),n=Za(Yn.prototype.request,t);return O.extend(n,Yn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Dl(Gn(e,o))},n}const xt=Dl(Lr);xt.Axios=Yn,xt.CanceledError=dr,xt.CancelToken=hg,xt.isCancel=yl,xt.VERSION=Pl,xt.toFormData=wo,xt.AxiosError=je,xt.Cancel=xt.CanceledError,xt.all=function(t){return Promise.all(t)},xt.spread=mg,xt.isAxiosError=gg,xt.mergeConfig=Gn,xt.AxiosHeaders=Bt,xt.formToJSON=e=>gl(O.isHTMLForm(e)?new FormData(e):e),xt.getAdapter=Rl.getAdapter,xt.HttpStatusCode=ui,xt.default=xt;const{Axios:bT,AxiosError:wT,CanceledError:ST,isCancel:CT,CancelToken:TT,VERSION:kT,all:IT,Cancel:ET,isAxiosError:AT,spread:NT,toFormData:_T,AxiosHeaders:jT,HttpStatusCode:RT,formToJSON:MT,getAdapter:PT,mergeConfig:OT}=xt,Ll=typeof window<"u"?window.__API_BASE_URL__:void 0,$l=Ll?Tn(Ll):void 0;function Tn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Eo=null;const di=new Set;function Fl(){return Eo}function Ao(e){Eo=e,di.forEach(t=>t(e))}function Bl(e){return di.add(e),()=>di.delete(e)}const xg=3e4,yg=9e4,qt=xt.create({...$l?{baseURL:$l}:{},timeout:xg,withCredentials:!0});qt.interceptors.request.use(e=>(Eo&&(e.headers.Authorization=`Bearer ${Eo}`),e)),qt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),Ao(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Gt(e,t){return qt.defaults.baseURL?(await qt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function fi(e,t,n){return qt.defaults.baseURL?(await qt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function zl(e,t,n){return qt.defaults.baseURL?(await qt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ul(e,t){return qt.defaults.baseURL?(await qt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Yt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Hl{get baseUrl(){const t=qt.defaults.baseURL;return t?Tn(String(t)):""}updateConfig(t){t.baseUrl&&(qt.defaults.baseURL=Tn(String(t.baseUrl))),t.authToken!==void 0&&Ao(t.authToken)}getAuthToken(){return Fl()}setAuthToken(t){Ao(t)}onTokenChange(t){return Bl(t)}async listThreads(){const t=await Gt("/threads"),n=Yt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await fi("/threads",t?{title:t}:void 0);return Yt(r)}async updateThread(t,n){const r=await zl(`/threads/${t}`,{title:n});return Yt(r)}async deleteThread(t){const n=await Ul(`/threads/${t}`);return Yt(n)}async threadInfo(t){const n=await Gt(`/threads/${t}/info`);return Yt(n)}async listAgents(){const t=await Gt("/agents"),n=Yt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Gt(`/agents/${t}`);return Yt(n)}async getAgentSchema(t){const n=await Gt(`/agents/${t}/schema`);return Yt(n)}async getState(t){const n=await Gt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Yt(n)}async getStateHistory(t){const n=await Gt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:yg});return Yt(n)}async cancelRun(t){const n=await fi("/runs/cancel",{threadId:t});return Yt(n)}async listCheckpointSummaries(t){const n=await Gt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=Yt(n);return(r==null?void 0:r.items)??[]}}const jn=new Hl,Wl=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(Wl.Provider,{value:r,children:e})}function pi(){const e=w.useContext(Wl);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 hi(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 fr(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!hi(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=kg(t),i=Vl(r,0),a=Ig(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Vl(e,t){if(!hi(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(M=>!!M&&typeof M=="object").map(M=>({...M})):a===null?null:void 0,c=r.map((M,L)=>Og(M,L)).filter(M=>!!M),d=Ot(e.config),f=Ot(d==null?void 0:d.configurable),p=ut(f,["checkpoint_id","checkpointId"]),h=ut(f,["checkpoint_ns","checkpointNs"]),x=Ot(e==null?void 0:e.parentConfig),m=Ot(x==null?void 0:x.configurable),y=ut(m,["checkpoint_id","checkpointId"])??null,g=ut(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(M=>M.role==="user")??null,C=Ot(e==null?void 0:e.metadata),T=ut(C,["branch_label","branchLabel"]),I=ut(m,["checkpoint_id","checkpointId"]),A=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:p??null,checkpointNs:h??null,nextCursor:y,nextCursorNs:g,interrupt:Tg(a,c,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastUserMessageId:(k==null?void 0:k.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:C??null,config:d??null,parentConfig:x??null,next:A??null,tasks:l??null,values:i??null}}function Tg(e,t,n){const r=Mg(e,n);return r||Rg(t,n)}function kg(e){const t=new Map;e.forEach((o,s)=>{if(!hi(o))return;const i=Vl(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,Ng(l,i))});const n=Array.from(t.values());n.sort((o,s)=>ql(s.createdAt??"")-ql(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Ig(e){var n,r;const t=[];for(const o of e){const s=o.checkpointId??null;if(!s)continue;const i=o.metadata??{},a=ut(i,["label"])??ut(i,["branch_label","branchLabel"])??ut(i,["description"])??"User input",l=Ag(i,["step"]),c=ut(i,["source"]),d=o.createdAt??null,f=((r=(n=o.messages)==null?void 0:n[o.messages.length-1])==null?void 0:r.id)??null,p=o.lastUserMessageId??f,h=Eg(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0,parentConfig:o.parentConfig??null})}return t}function Eg(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 Ag(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function Ng(e,t){return{...e,metadata:No(e.metadata,t.metadata)??null,config:No(e.config,t.config)??null,parentConfig:No(e.parentConfig,t.parentConfig)??null,next:_g(e.next,t.next)??null,tasks:jg(e.tasks,t.tasks)??null,values:No(e.values,t.values)??null}}function No(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 _g(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 jg(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 Mg(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=Pg(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Fr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Fr(r.state,`${o}-state`);if(s)return s}}return null}function Pg(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,y=p.length?p[p.length-1]:void 0;return{id:h,name:x,interrupts:m,state:y!==void 0?y:f}}const n=Ot(e);if(!n)return null;const r=ut(n,["id","thread_id","taskId"])??t,o=ut(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Fr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Kl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Fr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Fr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Fr(l,t,n+1,r);if(c)return c}}return null}function Kl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ut(n,["type","event","kind"]),o=ut(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Kl(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 ql(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Og(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=ut(c,["createdAt","created_at"])??ut(o,["created_at","createdAt"]),p=ut(c,["checkpointId","checkpoint_id"]),h=ut(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 y=Fg(Ot(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);const g=Hg(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=>Gl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Gl(e);return t?[t]:[]}return[]}function Gl(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ut(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ut(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Yl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=ut(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Yl(e,t){var s;const n=ut(e,["id","call_id"])??t,r=ut(e,["name"])??ut(Ot(e.function),["name"]);if(!n||!r)return null;const o=Ug(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)=>Yl(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){return e?{plots:Bg(e.plots)}:void 0}function Bg(e){return Array.isArray(e)?e.map(t=>zg(t)).filter(t=>!!t):[]}function zg(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.content_base64=="string"&&t.content_base64.trim()||void 0,r=typeof t.url=="string"&&t.url.trim()||void 0,o=(typeof t.format=="string"?t.format.trim():void 0)||(typeof t.mimeType=="string"?t.mimeType.trim():void 0)||(typeof t.mime_type=="string"?t.mime_type.trim():void 0),s=typeof t.plotId=="string"&&t.plotId.trim()||void 0,i=typeof t.artifactId=="string"&&t.artifactId.trim()||void 0,a={};return n&&(a.content_base64=n),r&&(a.url=r),o&&(a.format=o),s&&(a.plotId=s),i&&(a.artifactId=i),a}function Ug(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 ut(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function Hg(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 pr=120;function Wg(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>pr?`${n.slice(0,pr-3)}…`:n:""}function Vg(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>pr?`${i.slice(0,pr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>pr?`${n.slice(0,pr-3)}…`:n:""}function Xl(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=Wg(n.content)||Vg(n);o&&t.set(n.id,o)}return t}function Jl(e={}){const t=w.useMemo(()=>Tn(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,y]=w.useState(0),[g,b]=w.useState(!1),S=w.useRef(null),k=w.useRef(!0),C=w.useRef(0),T=w.useRef(null),I=w.useRef(null),A=w.useRef(null),M=w.useRef(null),L=w.useCallback(N=>{o(N)},[]),P=w.useCallback(()=>{p(""),x(null),d(null),I.current=null,A.current=null,M.current=null},[]),D=w.useCallback(()=>{var N;console.debug("[use-chat] stop() invoked - aborting stream"),(N=S.current)==null||N.abort(),S.current=null,T.current=null,l(!1),b(!1),C.current=0,y(0)},[]),F=w.useCallback((N,B,j)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),I.current=null,A.current=null,M.current=null;const V=new AbortController;S.current=V;let z=null,R=null,K=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var se,ge,Ie,Y,U,Z,$,q,Q,ce,oe,Ae,ze,re,xe,Me,Je,Ze;const J=We=>{var et;try{const st=JSON.parse(JSON.stringify(We));return(et=st==null?void 0:st.payload)!=null&&et.files_info&&Array.isArray(st.payload.files_info)&&(st.payload.files_info=st.payload.files_info.map(Ke=>({...Ke,data:Ke!=null&&Ke.data?`<base64 ${String(Ke.data).length} chars>`:Ke==null?void 0:Ke.data}))),st}catch{return We}};try{let We={};try{if(r)We={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ge=window.__AUTH_TOKEN__,ft=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let at=null;try{const _=(ge=window.localStorage)==null?void 0:ge.getItem("chat-settings");_&&(at=((Ie=JSON.parse(_))==null?void 0:Ie.apiKey)||null)}catch{}const G=Ge||ft||at||null;G&&(We={Authorization:`Bearer ${G}`})}}catch{}console.debug("[use-chat] POST",t+n,J(N));let et={};if(typeof window<"u")try{const qe=(Y=window.localStorage)==null?void 0:Y.getItem("authSessionId");qe&&(et={"X-Session-Id":qe})}catch{}const st={...We,...et,...s.current},Ke={"Content-Type":"application/json",Accept:"text/event-stream",...st},tt=await fetch(t+n,{method:"POST",headers:Ke,body:JSON.stringify(N),signal:V.signal,credentials:i});if(T.current&&(T.current.headers=st),!tt.ok||!tt.body){const qe=await tt.text().catch(()=>"");console.debug("[use-chat] non-OK response",tt.status,qe==null?void 0:qe.slice(0,500));const Ge=`stream ${tt.status}${qe?": "+qe:""}`;throw(U=j==null?void 0:j.onConnectionError)==null||U.call(j,Ge),K=!0,z="error",R=Ge,new Error(Ge)}b(!0);const it=tt.body.getReader(),Rt=new TextDecoder;let gt="",ht=[];C.current=0,y(0);let vt=0,wt=null;const $t=()=>{if(ht.length){const qe=ht.join("");ht=[],k.current&&p(Ge=>Ge+qe)}wt=null},Mt=()=>{typeof window<"u"&&wt==null&&(wt=requestAnimationFrame($t))};let Qe=Date.now();const It=setInterval(()=>{var qe;if(Date.now()-Qe>18e5){const Ge="Stream idle timeout";d(Ge),z="error",R=Ge,V.abort(),(qe=j==null?void 0:j.onError)==null||qe.call(j,Ge)}},5e3),Sn=1024*1024;try{const qe=tt.headers.get("X-Thread-Id")||tt.headers.get("x-thread-id"),Ge=tt.headers.get("X-Thread-Created")||tt.headers.get("x-thread-created"),ft=qe??null,at=String(Ge??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:ft}),(Z=j==null?void 0:j.onOpen)==null||Z.call(j,{threadId:ft,created:at});;){const{value:G,done:_}=await it.read();if(_)break;gt+=Rt.decode(G,{stream:!0}),gt.length>Sn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let X;for(;(X=gt.indexOf(`
36
36
 
37
- `))>=0;){const ne=gt.slice(0,J);gt=gt.slice(J+2);const pe=Wg(ne);if(!pe)continue;let Ae;try{Ae=JSON.parse(pe)}catch{console.debug("[use-chat] malformed SSE:",pe.slice(0,200));continue}const be=Hg(Ae)?Ae.data:Ae;nt=Date.now();const Fe=be.seq;if(Fe!==void 0){if(Fe<=bt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Fe,lastProcessedSeq:bt,type:be.type});continue}bt>0&&Fe>bt+1&&((L=M==null?void 0:M.onGap)==null||L.call(M,{from:bt,to:Fe})),bt=Fe,C.current=Fe,y(Fe)}if(console.debug("[use-chat] received event",{seq:be.seq,type:be.type,preview:(()=>{var Pe;try{return be.type==="message_delta"?{deltaTypes:(Pe=be.delta)==null?void 0:Pe.map(Ne=>Ne.type),textLen:(be.delta||[]).filter(Ne=>Ne.type==="text").map(Ne=>String(Ne.text||"").length)}:be.content||be.delta?{hasContent:!0}:{}}catch(Ne){return{err:String(Ne)}}})()}),be.type==="checkpoint")I.current=be.checkpointId??null,A.current=be.checkpointNs??null,x(be.checkpointId??null);else if(be.type==="state_history"){R.current=be;try{const Ne=dr(be).latest;Ne&&(I.current=Ne.checkpointId??null,A.current=Ne.checkpointNs??null,x(Ne.checkpointId??null))}catch(Pe){console.warn("[use-chat] Failed to hydrate state_history payload",Pe)}}try{B==null||B(be)}catch(Pe){console.error("[use-chat] Error in onEvent callback:",Pe,"for event:",be.type)}if(be.type==="token"&&e.autoAppendAssistant!==!1)ht.push(be.content),Mt();else if(be.type==="message_delta"){const Pe=be.delta.filter(Ne=>Ne.type==="text").map(Ne=>Ne.text).join("");Pe&&e.autoAppendAssistant!==!1&&(ht.push(Pe),Mt())}else if(be.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(K=M==null?void 0:M.onHeartbeat)==null||K.call(M,be)}catch(Pe){console.warn("[use-chat] heartbeat callback failed",Pe)}}else if(St!==null&&cancelAnimationFrame(St),Lt(),be.type==="checkpoint")x(be.checkpointId);else if(be.type==="error"){const Pe=be;if(d(Pe.message),z="error",_=Pe.message,Pe.error_type==="auth_error"||Pe.code==="TOKEN_EXPIRED"||((Z=Pe.message)==null?void 0:Z.includes("token"))||((ce=Pe.message)==null?void 0:ce.includes("401"))||((re=Pe.message)==null?void 0:re.includes("unauthorized"))||((je=Pe.message)==null?void 0:je.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Pe.message);try{(Ue=M==null?void 0:M.onAuthError)==null||Ue.call(M,Pe.message)}catch(Vt){console.warn("[use-chat] onAuthError handler failed",Vt)}Q.abort()}}}}Lt(),z===null&&!Q.signal.aborted&&(z="complete")}catch(Je){if(Je.name==="AbortError")z=z??"aborted";else{const Ze=Je.message||String(Je);z="error",_=Ze,d(Ze),(De=M==null?void 0:M.onError)==null||De.call(M,Ze)}}finally{try{await at.cancel()}catch{}finally{(Ge=at.releaseLock)==null||Ge.call(at)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(It)}}catch(ie){if(ie.name==="AbortError")z=z??"aborted";else{const xe=ie.message||String(ie);z="error",_=xe,d(xe),(Ve=M==null?void 0:M.onError)==null||Ve.call(M,xe),V||((tt=M==null?void 0:M.onConnectionError)==null||tt.call(M,xe),V=!0)}}finally{const ie=C.current,xe=I.current,He=A.current,We=R.current,rt=z??(Q.signal.aborted?"aborted":_?"error":"complete");try{(Ye=M==null?void 0:M.onClosed)==null||Ye.call(M,{reason:rt,lastSeq:ie,lastCheckpointId:xe,lastCheckpointNs:He,lastStateHistory:We,error:_})}catch(at){console.warn("[use-chat] onClosed callback failed",at)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>Q.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var N;k.current=!1,(N=S.current)==null||N.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:m,connected:g,stream:F,stop:O,clear:P,setToken:$}}function Hg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Wg(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 Vg(e){return e.type!=="token"}const Kg={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:fi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=fi(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=fi(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 Xl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Xl(o,s),e):e}case"interrupt_response":return{...e,messages:Jl(e.messages),pendingInterrupt:null};default:return e}}function Yl(e=[]){const[t,n]=w.useReducer(qg,{...Kg,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 Xl(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Jg(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??Zl(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:tc(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:y}=Gg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:x},b=Ao(l,c,g),S={...f,[a]:m};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Zl(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=Ql(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=ec(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,y={type:"tool_call",id:m,name:c,args:t.args};if(p){const S=hi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?Ao(e.messages,C,k):e.messages,I=No(k,d),A=mi(e.toolIndex,x,I);return{...e,messages:T,toolIndex:A}}const g={id:x,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:hi(void 0,d.length?d:[m],c,t.args)},b=No(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:mi(e.toolIndex,x,b)}}if(t.type==="tool_end"){const a=Ql(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=ec(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 I=t.output.trim();(I.startsWith("{")||I.startsWith("["))&&(m=JSON.parse(I))}catch{m=t.output}const y=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=hi(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:y??void 0,additionalKwargs:S},C=c>=0?Ao(e.messages,c,k):[...e.messages,k],T=No(k,a.length?a:x);return{...e,messages:C,toolIndex:mi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Xg(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=dr(t),l=a.interrupt,c=a.latest,d=l===null?Jl(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 fi(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Ao(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Jl(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 Zl(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ql(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 pi(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 hi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=pi(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=pi(e);for(const o of r)n.add(o);return Array.from(n)}function mi(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 ec(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(pi(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 tc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Gg(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??tc(e);let l="",c=e.slice();if(s){const f=Yg(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 nc(e){return e.replace(/\s+/g," ").trim()}function Yg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=nc(e),o=nc(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function Xg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return Ao(e,r,s)}return e}function Jg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const rc=200;function Zg({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 O=globalThis.structuredClone;if(typeof O=="function")return O(P)}catch{}try{return JSON.parse(JSON.stringify(P))}catch{return P}},[]),y=w.useCallback((P,O)=>{if(!P)return;const F=p.current.get(P)??[],N=m(O),B=F.length>=rc?[...F.slice(F.length-rc+1),N]:[...F,N];p.current.set(P,B)},[m]),g=w.useCallback(P=>{P&&p.current.set(P,[])},[]),b=w.useCallback(P=>{const O=P??f.current;if(!O)return;const F=p.current.get(O);F!=null&&F.length&&F.forEach(N=>{try{n(N)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),S=w.useCallback(P=>{var N,B,M,Q,z;const O=P.seq??null;if(O!==null){const _=d.current;if(_!==null){if(O<=_)return;O>_+1&&(s==null||s({from:_,to:O}))}d.current=O}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(_){console.error("[useChatStreamingService] Error in onThreadInfo handler:",_)}return}if(P.type==="heartbeat"){try{c==null||c(P)}catch(_){console.error("[useChatStreamingService] Error in onHeartbeat handler:",_)}return}if(P.type==="error"){const _=P;if(_.error_type==="auth_error"||_.code==="TOKEN_EXPIRED"||((N=_.message)==null?void 0:N.includes("token"))||((B=_.message)==null?void 0:B.includes("401"))||((M=_.message)==null?void 0:M.includes("unauthorized"))||((Q=_.message)==null?void 0:Q.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",_.message);try{l==null||l(_.message)}catch(Y){console.warn("[useChatStreamingService] onAuthError handler failed",Y)}}}const F=P.threadId??(P.type==="state_history"?P.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.threadIdGuess)??null;if(P.type==="state_history"){f.current=F??f.current;try{r==null||r(P)}catch(_){console.error("[useChatStreamingService] onStateHistory handler failed",_)}}if(Vg(P)){P.type==="checkpoint"||P.type==="state_history"?g(F??null):y(F??null,P);try{n(P)}catch(_){console.error("[useChatStreamingService] Error in onMessageEvent handler:",_)}return}try{o==null||o(P)}catch(_){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",_)}},[y,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:A}=Gl({baseUrl:e,token:void 0}),R=w.useCallback((P,O)=>{d.current=null,x.current=null,f.current=P.threadId??null,h.current={request:P,callbacks:O,manualStop:!1,threadIdGuess:P.threadId??null},k(P,S,{onOpen:O==null?void 0:O.onOpen,onError:F=>{var N;(N=O==null?void 0:O.onError)==null||N.call(O,F)},onGap:(O==null?void 0:O.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=O==null?void 0:O.onConnectionError)==null||N.call(O,F)},onAuthError:F=>{var N;l==null||l(F),(N=O==null?void 0:O.onAuthError)==null||N.call(O,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=O==null?void 0:O.onHeartbeat)==null||N.call(O,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var Q,z,_,V;const N=((Q=h.current)==null?void 0:Q.manualStop)??!1,B=f.current??((z=h.current)==null?void 0:z.threadIdGuess)??((_=F.lastStateHistory)==null?void 0:_.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&N)&&g(B);const M={...F,threadId:B,threadInfo:x.current,manualStop:N};try{i==null||i(M)}catch(Y){console.warn("[useChatStreamingService] onStreamClosed handler failed",Y)}try{(V=O==null?void 0:O.onClosed)==null||V.call(O,M)}catch(Y){console.warn("[useChatStreamingService] downstream onClosed handler failed",Y)}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:R,stop:$,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[R,$,T,I,A,b])}const oc=w.createContext(null),sc=w.createContext(null),ic=w.createContext(null);w.createContext(!1);function Qg({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}=ui(),d=w.useMemo(()=>wn(c),[c]),[f,p]=w.useState([]),[h,x]=w.useState(t),[m,y]=w.useState(!1),[g,b]=w.useState(null),[S,k]=w.useState(!1),[C,T]=w.useState(null),{state:I,seed:A,prepend:R,pushUser:$,onEvent:P}=Yl(),[O,F]=w.useState(!1),[N,B]=w.useState(!1),[M,Q]=w.useState(null),[z,_]=w.useState([]),[V,Y]=w.useState([]),[oe,ye]=w.useState(!1),Me=w.useMemo(()=>z.flatMap(q=>q.messages??[]),[z]),G=w.useMemo(()=>ql(Me),[Me]),U=w.useRef(h),X=w.useRef(null),L=w.useRef(null),K=w.useRef(null),Z=w.useRef(null),ce=w.useRef(!1),re=w.useRef(null),je=w.useRef(new Map),Ue=w.useRef(new Map);w.useEffect(()=>{U.current=h},[h]);const De=w.useCallback(async()=>{y(!0),b(null);try{const q=await l.listThreads();p(q??[])}catch(q){const j=String(q);b(j),s==null||s(j)}finally{y(!1)}},[l,s]),Ge=w.useCallback(q=>{if(!(q!=null&&q.threadId))return;const j={threadId:q.threadId,title:q.title||`Thread ${q.threadId.slice(0,8)}`,createdAt:q.createdAt||new Date().toISOString(),updatedAt:q.updatedAt||new Date().toISOString(),messageCount:q.messageCount??1};p(J=>J.some(pe=>pe.threadId===j.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",j.threadId),J):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",j.threadId),[j,...J]))},[]),Ve=w.useCallback(q=>{const j=q.threadId??U.current;if(!j||U.current&&U.current!==j)return;const{checkpoints:J,timeline:ne}=dr(q);if(!J.length)return;const pe=J.find(Ae=>Ae.messages&&Ae.messages.length>0)??J.find(Ae=>!!Ae.checkpointId)??J[0];A((pe==null?void 0:pe.messages)??[],{checkpointId:(pe==null?void 0:pe.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??null}),Y(ne),_(J),F(!!(pe!=null&&pe.nextCursor)),Q((pe==null?void 0:pe.nextCursor)??null),re.current=`${j}:latest`,L.current=null,K.current=null},[A]),tt=w.useCallback(q=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",q.threadId),Ge(q),U.current!==q.threadId&&((q.created??!U.current)&&(L.current=q.threadId),K.current=q.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(q.threadId))},[Ge]),{startStream:Ye,stop:ie,isStreaming:xe,error:He,setAuthToken:We}=Zg({baseUrl:d,onThreadInfo:tt,onMessageEvent:P,onStateHistory:Ve,onUnhandledEvent:q=>{console.warn("[ChatSessionProvider] Unhandled event:",q.type)},onAuthError:i}),rt=w.useCallback(async q=>{try{const j=await l.createThread(q);return x(j.threadId),await De(),j.threadId}catch(j){return s==null||s(String(j)),null}},[l,De,s]),at=w.useCallback(async q=>{const j=f;p(ne=>ne.filter(pe=>pe.threadId!==q));const J=new AbortController;Ue.current.set(q,J);try{await l.deleteThread(q),U.current===q&&(x(null),A([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",q)}catch(ne){console.error("[ChatSessionProvider] Delete failed, restoring thread:",q,ne),p(j),s==null||s(`Failed to delete thread: ${String(ne)}`)}finally{Ue.current.delete(q)}},[f,l,A,s]),Rt=w.useCallback(async(q,j)=>{try{await l.updateThread(q,j),await De()}catch(J){s==null||s(String(J))}},[l,De,s]),gt=w.useCallback(async(q,j)=>{if(!q)return;const J=`${q}:${j??"latest"}`,ne=je.current.get(J);if(ne)return ne;const pe=(async()=>{const Ae=q;k(!0),T(null);try{const be=await l.getStateHistory({threadId:Ae,checkpointId:j||void 0});if(U.current!==Ae){console.log(`[ChatSessionProvider] Thread changed during load (was ${Ae}, now ${U.current}), discarding stale data`);return}const{checkpoints:Fe,timeline:Pe}=dr(be),Ne=Fe.find(Vt=>Vt.messages&&Vt.messages.length>0)??(j?Fe.find(Vt=>Vt.checkpointId===j):null)??Fe[0];A((Ne==null?void 0:Ne.messages)??[],{checkpointId:(Ne==null?void 0:Ne.checkpointId)??null,checkpointNs:(Ne==null?void 0:Ne.checkpointNs)??null}),Y(Pe),_(Fe),F(!!(Ne!=null&&Ne.nextCursor)),Q((Ne==null?void 0:Ne.nextCursor)??null)}catch(be){if(U.current===Ae){const Fe=String(be);T(Fe),s==null||s(Fe)}}finally{k(!1)}})();je.current.set(J,pe);try{await pe}finally{je.current.delete(J)}return U.current===q&&(re.current=J),pe},[l,A,s]),ht=w.useCallback(async(q,j)=>{Z.current=q;try{await gt(q,j)}finally{Z.current===q&&(Z.current=null)}},[gt]);w.useEffect(()=>{if(!o||!h||S||xe)return;if(L.current===h){L.current=null,X.current=h;return}if(K.current===h){X.current=h;return}if(Z.current===h){Z.current=null,X.current=h;return}if(X.current===h)return;X.current=h;const q=!ce.current&&!!n&&h===t;let j;q&&n?(j=n,ce.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",j,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const J=`${h}:${j??"latest"}`;re.current!==J&&ht(h,j)},[o,h,n,r,t,S,xe,ht]);const bt=w.useCallback(async(q,j)=>{const J=U.current;if(!J)return;const ne=J;ye(!0);try{const pe=await l.getStateHistory({threadId:ne,checkpointId:q,checkpointNs:j??void 0});if(U.current!==ne){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${ne}, now ${U.current}), discarding stale data`);return}const{checkpoints:Ae,timeline:be}=dr(pe),Fe=Ae.find(Pe=>Pe.checkpointId===q&&(j?Pe.checkpointNs===j:!0));if(!Fe){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:q,checkpointNs:j});return}Y(be),_(Ae),A(Fe.messages??[],{checkpointId:Fe.checkpointId??null,checkpointNs:Fe.checkpointNs??null})}catch(pe){U.current===ne&&(s==null||s(String(pe)))}finally{ye(!1)}},[l,A,s]),St=w.useCallback((q,j)=>{A(I.messages,{checkpointId:q??null,checkpointNs:j??null})},[A,I.messages]),Lt=w.useCallback(async()=>{U.current&&await ht(U.current)},[ht]),Mt=w.useCallback(async()=>{if(!U.current||!M)return;const q=U.current;B(!0);try{const j=await l.getStateHistory({threadId:q,checkpointId:M});if(U.current!==q)return;const{checkpoints:J}=dr(j);if(J.length>0){const ne=J[J.length-1];R((ne==null?void 0:ne.messages)??[]),F(!!(ne!=null&&ne.nextCursor)),Q((ne==null?void 0:ne.nextCursor)??null)}}catch(j){U.current===q&&(s==null||s(String(j)))}finally{B(!1)}},[l,M,R,s]),nt=w.useCallback(async()=>{A([],{}),x(null),ie(),_([]),Y([]),F(!1),Q(null),k(!1),ye(!1),B(!1),T(null);try{await l.getAgent("default")}catch(q){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",q)}},[A,ie,l]),It=w.useCallback(async(q,j,J)=>{const ne=U.current;if(!ne)throw new Error("No active thread to handle interrupt");const pe=j?J??!0:!1;try{const Ae={threadId:ne,checkpointId:I.lastCheckpointId??void 0,checkpointNs:I.lastCheckpointNs??void 0,command:{kind:"resume",value:pe}};Ye(Ae)}catch(Ae){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${q}:`,Ae),Ae}},[I.lastCheckpointId,I.lastCheckpointNs,Ye]);w.useEffect(()=>{De()},[De]),w.useEffect(()=>{a==null||a(h)},[h,a]);const bn=w.useCallback(async(q,j)=>{let J=U.current;const ne=(q==null?void 0:q.text)??"",pe=(q==null?void 0:q.attachments)??[],Ae=(ne==null?void 0:ne.trim())??"",be={...(q==null?void 0:q.payload)??{}},Fe=Array.isArray(be.messages)?be.messages:void 0;Fe&&delete be.messages;const Pe=!!(Fe&&Fe.length);if(!J&&!Ae&&pe.length===0&&!Pe)return;if(!J){const se=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ve=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);J=`${se}${ve}`,L.current=J,x(J)}const{contentParts:Ne,filesInfo:Vt}=await yg(l,pe),En=[...Ne];Ae&&En.push({type:"text",text:ne});const ir=j==null?void 0:j.originalMessageId,Ar=!!(j!=null&&j.edit&&ir),fo=!Pe&&En.length>0;let zn=null;fo&&(zn={id:Ar?ir:`msg-${Date.now()}`,role:"user",content:En,createdAt:new Date().toISOString()},Ar||$(zn));const ar=Pe?Fe:zn?[zn]:[],E={...be,...Vt.length?{files_info:Vt}:{}};ar.length?E.messages=ar:"messages"in E||(E.messages=[]);const W={threadId:J,payload:E,checkpointId:(j==null?void 0:j.checkpointId)??I.lastCheckpointId??void 0,checkpointNs:(j==null?void 0:j.checkpointNs)??I.lastCheckpointNs??void 0,edit:!!(j!=null&&j.edit),timelineCheckpoints:V};Ye(W)},[l,$,I,Ye,V]),Je=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:rt,deleteThread:at,renameThread:Rt,refreshThreads:De}}),[f,h,m,g,rt,at,Rt,De]),Ze=w.useMemo(()=>{const q=I.assemblingId??null;return q?{assemblingMessageId:q}:null},[I.assemblingId]),pt=w.useMemo(()=>({threadId:h,messages:I.messages,interrupt:null,checkpoint:{id:I.lastCheckpointId??null,namespace:I.lastCheckpointNs??null},checkpoints:z,timelineCheckpoints:V,metadata:Ze,isLoading:S,isHistoryLoading:N,isLoadingCheckpoint:oe,error:C,hasMore:O,loadOlder:Mt,clearState:nt,navigateToCheckpoint:bt,setCurrentCheckpointId:St,returnToLatest:Lt,loadThread:ht,clearThread:nt,respondToInterrupt:It,messagePreviews:G}),[h,I,z,V,S,N,oe,C,O,Mt,nt,bt,St,Lt,ht,It,G,Ze]),lt=w.useMemo(()=>({isStreaming:xe,error:He,connectionState:xe?"connected":"idle",submit:bn,send:bn,stop:ie,setAuthToken:We}),[xe,He,bn,ie,We]);return u.jsx(oc.Provider,{value:Je,children:u.jsx(sc.Provider,{value:pt,children:u.jsx(ic.Provider,{value:lt,children:e})})})}function _o(){const e=w.useContext(oc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function jo(){const e=w.useContext(sc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function ac(){const e=w.useContext(ic);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(gg,{apiConfig:t,children:u.jsx(Qg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function te(...e){return Hh.twMerge(Uh.clsx(e))}const ex=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"}}),Qe=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Hn.Slot:"button";return u.jsx(i,{className:te(ex({variant:t,size:n,className:e})),ref:s,...o})});Qe.displayName="Button";const lc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:te("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));lc.displayName="Textarea";function cc({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,y]=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||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,x]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,g]);const A=w.useCallback((B,{fromUser:M})=>{x||y(B),M&&(a==null||a(B))},[x,a]),R=w.useCallback(async B=>{B&&B.preventDefault();const M=(g??"").trim();if(!M&&!h)return;const Q=++C.current;T.current={id:Q,shouldClear:!0},S(()=>{var z,_,V;try{const Y=l(M);Y&&typeof Y.then=="function"?Y.then(()=>{var oe,ye;((oe=T.current)==null?void 0:oe.id)===Q&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ye=T.current)==null?void 0:ye.id)===Q&&(T.current=null)}).catch(()=>{var oe;((oe=T.current)==null?void 0:oe.id)===Q&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===Q&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((_=T.current)==null?void 0:_.id)===Q&&(T.current=null))}catch{((V=T.current)==null?void 0:V.id)===Q&&(T.current=null)}})},[g,l,h,x,a]),$=w.useCallback(B=>{const M=B.target.value;A(M,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),P=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),R()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[R,t,c]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:B=>void R(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(lc,{ref:k,value:g,onChange:$,onKeyDown:P,placeholder:t?"Edit your message...":n,className:N,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Qe,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ae.Square,{size:16})}):u.jsx(Qe,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||b,children:u.jsx(ae.Send,{size:16})})})]})})}const tx=w.memo(cc);function de(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 uc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function gi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=uc(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():uc(e[o],null)}}}}function Be(...e){return v.useCallback(gi(...e),e)}function nx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Sn(e,t=[]){let n=[];function r(s,i){const a=v.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,y=v.useMemo(()=>x,Object.values(x));return u.jsx(m.Provider,{value:y,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=v.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=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,rx(o,...t)]}function rx(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ox=v[" useInsertionEffect ".trim().toString()]||Tt;function pr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=sx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=ix(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 sx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return ox(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ix(e){return typeof e=="function"}var ax=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=ax.reduce((e,t)=>{const n=Hn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function dc(e,t){e&&ho.flushSync(()=>e.dispatchEvent(t))}function xi(e){const t=e+"CollectionProvider",[n,r]=Sn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:y,children:g}=m,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Hn.createSlot(a),c=w.forwardRef((m,y)=>{const{scope:g,children:b}=m,S=s(a,g),k=Be(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Hn.createSlot(d),h=w.forwardRef((m,y)=>{const{scope:g,children:b,...S}=m,k=w.useRef(null),C=Be(y,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 y=s(e+"CollectionConsumer",m);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},x,r]}var lx=v.createContext(void 0);function Mo(e){const t=v.useContext(lx);return e||t||"ltr"}function kt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function cx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var ux="DismissableLayer",yi="dismissableLayer.update",dx="dismissableLayer.pointerDownOutside",fx="dismissableLayer.focusOutside",fc,pc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Po=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(pc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),x=Be(t,I=>f(I)),m=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=m.indexOf(y),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=g,C=mx(I=>{const A=I.target,R=[...c.branches].some($=>$.contains(A));!k||R||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=gx(I=>{const A=I.target;[...c.branches].some($=>$.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return cx(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(fc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),hc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=fc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),hc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(yi,I),()=>document.removeEventListener(yi,I)},[]),u.jsx(Ee.div,{...l,ref:x,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:de(e.onFocusCapture,T.onFocusCapture),onBlurCapture:de(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:de(e.onPointerDownCapture,C.onPointerDownCapture)})});Po.displayName=ux;var px="DismissableLayerBranch",hx=v.forwardRef((e,t)=>{const n=v.useContext(pc),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ee.div,{...e,ref:o})});hx.displayName=px;function mx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){mc(dx,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 gx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&mc(fx,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function hc(){const e=new CustomEvent(yi);document.dispatchEvent(e)}function mc(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?dc(o,s):o.dispatchEvent(s)}var vi=0;function bi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??gc()),document.body.insertAdjacentElement("beforeend",e[1]??gc()),vi++,()=>{vi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),vi--}},[])}function gc(){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 wi="focusScope.autoFocusOnMount",Si="focusScope.autoFocusOnUnmount",xc={bubbles:!1,cancelable:!0},xx="FocusScope",Oo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=kt(o),d=kt(s),f=v.useRef(null),p=Be(t,m=>l(m)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let m=function(S){if(h.paused||!a)return;const k=S.target;a.contains(k)?f.current=k:Nn(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||Nn(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Nn(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",y);const b=new MutationObserver(g);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){bc.add(h);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(wi,xc);a.addEventListener(wi,c),a.dispatchEvent(g),g.defaultPrevented||(yx(Cx(yc(a)),{select:!0}),document.activeElement===m&&Nn(a))}return()=>{a.removeEventListener(wi,c),setTimeout(()=>{const g=new CustomEvent(Si,xc);a.addEventListener(Si,d),a.dispatchEvent(g),g.defaultPrevented||Nn(m??document.body,{select:!0}),a.removeEventListener(Si,d),bc.remove(h)},0)}}},[a,c,d,h]);const x=v.useCallback(m=>{if(!n&&!r||h.paused)return;const y=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,g=document.activeElement;if(y&&g){const b=m.currentTarget,[S,k]=vx(b);S&&k?!m.shiftKey&&g===k?(m.preventDefault(),n&&Nn(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&Nn(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(Ee.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Oo.displayName=xx;function yx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Nn(r,{select:t}),document.activeElement!==n)return}function vx(e){const t=yc(e),n=vc(t,e),r=vc(t.reverse(),e);return[n,r]}function yc(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 vc(e,t){for(const n of e)if(!bx(n,{upTo:t}))return n}function bx(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 wx(e){return e instanceof HTMLInputElement&&"select"in e}function Nn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&wx(e)&&t&&e.select()}}var bc=Sx();function Sx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=wc(e,t),e.unshift(t)},remove(t){var n;e=wc(e,t),(n=e[0])==null||n.resume()}}}function wc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Cx(e){return e.filter(t=>t.tagName!=="A")}var Tx=v[" useId ".trim().toString()]||(()=>{}),kx=0;function Cn(e){const[t,n]=v.useState(Tx());return Tt(()=>{n(r=>r??String(kx++))},[e]),t?`radix-${t}`:""}const Ix=["top","right","bottom","left"],_n=Math.min,zt=Math.max,Do=Math.round,Lo=Math.floor,dn=e=>({x:e,y:e}),Ex={left:"right",right:"left",bottom:"top",top:"bottom"},Ax={start:"end",end:"start"};function Ci(e,t,n){return zt(e,_n(t,n))}function Tn(e,t){return typeof e=="function"?e(t):e}function kn(e){return e.split("-")[0]}function hr(e){return e.split("-")[1]}function Ti(e){return e==="x"?"y":"x"}function ki(e){return e==="y"?"height":"width"}const Nx=new Set(["top","bottom"]);function fn(e){return Nx.has(kn(e))?"y":"x"}function Ii(e){return Ti(fn(e))}function _x(e,t,n){n===void 0&&(n=!1);const r=hr(e),o=Ii(e),s=ki(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 jx(e){const t=$o(e);return[Ei(e),t,Ei(t)]}function Ei(e){return e.replace(/start|end/g,t=>Ax[t])}const Sc=["left","right"],Cc=["right","left"],Rx=["top","bottom"],Mx=["bottom","top"];function Px(e,t,n){switch(e){case"top":case"bottom":return n?t?Cc:Sc:t?Sc:Cc;case"left":case"right":return t?Rx:Mx;default:return[]}}function Ox(e,t,n,r){const o=hr(e);let s=Px(kn(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=>Ex[t])}function Dx(e){return{top:0,right:0,bottom:0,left:0,...e}}function Tc(e){return typeof e!="number"?Dx(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 kc(e,t,n){let{reference:r,floating:o}=e;const s=fn(t),i=Ii(t),a=ki(i),l=kn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(hr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Lx=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}=kc(c,r,l),p=r,h={},x=0;for(let m=0;m<a.length;m++){const{name:y,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,[y]:{...h[y],...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}=kc(c,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Lr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=Tn(t,e),x=Tc(h),y=a[p?f==="floating"?"reference":"floating":f],g=Fo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Fo(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(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 $x=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}=Tn(e,t)||{};if(c==null)return{};const f=Tc(d),p={x:n,y:r},h=Ii(o),x=ki(h),m=await i.getDimensions(c),y=h==="y",g=y?"top":"left",b=y?"bottom":"right",S=y?"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 I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[x]);const A=k/2-C/2,R=I/2-m[x]/2-1,$=_n(f[g],R),P=_n(f[b],R),O=$,F=I-m[x]-P,N=I/2-m[x]/2+A,B=Ci(O,N,F),M=!l.arrow&&hr(o)!=null&&N!==B&&s.reference[x]/2-(N<O?$:P)-m[x]/2<0,Q=M?N<O?N-O:N-F:0;return{[h]:p[h]+Q,data:{[h]:B,centerOffset:N-B-Q,...M&&{alignmentOffset:Q}},reset:M}}}),Fx=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,...y}=Tn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=kn(o),b=fn(a),S=kn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[$o(a)]:jx(a)),T=x!=="none";!p&&T&&C.push(...Ox(a,m,x,k));const I=[a,...C],A=await Lr(t,y),R=[];let $=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&R.push(A[g]),f){const N=_x(o,i,k);R.push(A[N[0]],A[N[1]])}if($=[...$,{placement:o,overflows:R}],!R.every(N=>N<=0)){var P,O;const N=(((P=s.flip)==null?void 0:P.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==fn(B):!1)||$.every(z=>fn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:$},reset:{placement:B}};let M=(O=$.filter(Q=>Q.overflows[0]<=0).sort((Q,z)=>Q.overflows[1]-z.overflows[1])[0])==null?void 0:O.placement;if(!M)switch(h){case"bestFit":{var F;const Q=(F=$.filter(z=>{if(T){const _=fn(z.placement);return _===b||_==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(_=>_>0).reduce((_,V)=>_+V,0)]).sort((z,_)=>z[1]-_[1])[0])==null?void 0:F[0];Q&&(M=Q);break}case"initialPlacement":M=a;break}if(o!==M)return{reset:{placement:M}}}return{}}}};function Ic(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ec(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}=Tn(e,t);switch(r){case"referenceHidden":{const s=await Lr(t,{...o,elementContext:"reference"}),i=Ic(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ec(i)}}}case"escaped":{const s=await Lr(t,{...o,altBoundary:!0}),i=Ic(s,n.floating);return{data:{escapedOffsets:i,escaped:Ec(i)}}}default:return{}}}}},Ac=new Set(["left","top"]);async function zx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=kn(n),a=hr(n),l=fn(n)==="y",c=Ac.has(i)?-1:1,d=s&&l?-1:1,f=Tn(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 zx(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}}}}},Hx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:b}=y;return{x:g,y:b}}},...l}=Tn(e,t),c={x:n,y:r},d=await Lr(t,l),f=fn(kn(o)),p=Ti(f);let h=c[p],x=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",b=h+d[y],S=h-d[g];h=Ci(b,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",b=x+d[y],S=x-d[g];x=Ci(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}}}}}},Wx=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}=Tn(e,t),d={x:n,y:r},f=fn(o),p=Ti(f);let h=d[p],x=d[f];const m=Tn(a,t),y=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]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var g,b;const S=p==="y"?"width":"height",k=Ac.has(kn(o)),C=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);x<C?x=C:x>T&&(x=T)}return{[p]:h,[f]:x}}}},Vx=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}=Tn(e,t),d=await Lr(t,c),f=kn(o),p=hr(o),h=fn(o)==="y",{width:x,height:m}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const b=m-d.top-d.bottom,S=x-d.left-d.right,k=_n(m-d[y],b),C=_n(x-d[g],S),T=!t.middlewareData.shift;let I=k,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!p){const $=zt(d.left,0),P=zt(d.right,0),O=zt(d.top,0),F=zt(d.bottom,0);h?A=x-2*($!==0||P!==0?$+P:zt(d.left,d.right)):I=m-2*(O!==0||F!==0?O+F:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const R=await i.getDimensions(a.floating);return x!==R.width||m!==R.height?{reset:{rects:!0}}:{}}}};function Bo(){return typeof window<"u"}function mr(e){return Nc(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pn(e){var t;return(t=(Nc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Nc(e){return Bo()?e instanceof Node||e instanceof Ut(e).Node:!1}function rn(e){return Bo()?e instanceof Element||e instanceof Ut(e).Element:!1}function hn(e){return Bo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function _c(e){return!Bo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const Kx=new Set(["inline","contents"]);function $r(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=on(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Kx.has(o)}const qx=new Set(["table","td","th"]);function Gx(e){return qx.has(mr(e))}const Yx=[":popover-open",":modal"];function zo(e){return Yx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Xx=["transform","translate","scale","rotate","perspective"],Jx=["transform","translate","scale","rotate","perspective","filter"],Zx=["paint","layout","strict","content"];function Ai(e){const t=Ni(),n=rn(e)?on(e):e;return Xx.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)||Jx.some(r=>(n.willChange||"").includes(r))||Zx.some(r=>(n.contain||"").includes(r))}function Qx(e){let t=jn(e);for(;hn(t)&&!gr(t);){if(Ai(t))return t;if(zo(t))return null;t=jn(t)}return null}function Ni(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ey=new Set(["html","body","#document"]);function gr(e){return ey.has(mr(e))}function on(e){return Ut(e).getComputedStyle(e)}function Uo(e){return rn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jn(e){if(mr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||_c(e)&&e.host||pn(e);return _c(t)?t.host:t}function jc(e){const t=jn(e);return gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:hn(t)&&$r(t)?t:jc(t)}function Fr(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=jc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ut(o);if(s){const a=_i(i);return t.concat(i,i.visualViewport||[],$r(o)?o:[],a&&n?Fr(a):[])}return t.concat(o,Fr(o,[],n))}function _i(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rc(e){const t=on(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=hn(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 ji(e){return rn(e)?e:e.contextElement}function xr(e){const t=ji(e);if(!hn(t))return dn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rc(t);let i=(s?Do(n.width):n.width)/r,a=(s?Do(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ty=dn(0);function Mc(e){const t=Ut(e);return!Ni()||!t.visualViewport?ty:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ny(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ut(e)?!1:t}function qn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ji(e);let i=dn(1);t&&(r?rn(r)&&(i=xr(r)):i=xr(e));const a=ny(s,n,r)?Mc(s):dn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const p=Ut(s),h=r&&rn(r)?Ut(r):r;let x=p,m=_i(x);for(;m&&r&&h!==x;){const y=xr(m),g=m.getBoundingClientRect(),b=on(m),S=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*y.x,k=g.top+(m.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,x=Ut(m),m=_i(x)}}return Fo({width:d,height:f,x:l,y:c})}function Ho(e,t){const n=Uo(e).scrollLeft;return t?t.left+n:qn(pn(e)).left+n}function Pc(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 ry(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=pn(r),a=t?zo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=dn(1);const d=dn(0),f=hn(r);if((f||!f&&!s)&&((mr(r)!=="body"||$r(i))&&(l=Uo(r)),hn(r))){const h=qn(r);c=xr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Pc(i,l):dn(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 oy(e){return Array.from(e.getClientRects())}function sy(e){const t=pn(e),n=Uo(e),r=e.ownerDocument.body,o=zt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=zt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ho(e);const a=-n.scrollTop;return on(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Oc=25;function iy(e,t){const n=Ut(e),r=pn(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=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<=Oc&&(s-=x)}else c<=Oc&&(s+=c);return{width:s,height:i,x:a,y:l}}const ay=new Set(["absolute","fixed"]);function ly(e,t){const n=qn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=hn(e)?xr(e):dn(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 Dc(e,t,n){let r;if(t==="viewport")r=iy(e,n);else if(t==="document")r=sy(pn(e));else if(rn(t))r=ly(t,n);else{const o=Mc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Fo(r)}function Lc(e,t){const n=jn(e);return n===t||!rn(n)||gr(n)?!1:on(n).position==="fixed"||Lc(n,t)}function cy(e,t){const n=t.get(e);if(n)return n;let r=Fr(e,[],!1).filter(a=>rn(a)&&mr(a)!=="body"),o=null;const s=on(e).position==="fixed";let i=s?jn(e):e;for(;rn(i)&&!gr(i);){const a=on(i),l=Ai(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&ay.has(o.position)||$r(i)&&!l&&Lc(e,i))?r=r.filter(d=>d!==i):o=a,i=jn(i)}return t.set(e,r),r}function uy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?zo(t)?[]:cy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Dc(t,d,o);return c.top=zt(f.top,c.top),c.right=_n(f.right,c.right),c.bottom=_n(f.bottom,c.bottom),c.left=zt(f.left,c.left),c},Dc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function dy(e){const{width:t,height:n}=Rc(e);return{width:t,height:n}}function fy(e,t,n){const r=hn(t),o=pn(t),s=n==="fixed",i=qn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=dn(0);function c(){l.x=Ho(o)}if(r||!r&&!s)if((mr(t)!=="body"||$r(o))&&(a=Uo(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?Pc(o,a):dn(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 Ri(e){return on(e).position==="static"}function $c(e,t){if(!hn(e)||on(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pn(e)===n&&(n=n.ownerDocument.body),n}function Fc(e,t){const n=Ut(e);if(zo(e))return n;if(!hn(e)){let o=jn(e);for(;o&&!gr(o);){if(rn(o)&&!Ri(o))return o;o=jn(o)}return n}let r=$c(e,t);for(;r&&Gx(r)&&Ri(r);)r=$c(r,t);return r&&gr(r)&&Ri(r)&&!Ai(r)?n:r||Qx(e)||n}const py=async function(e){const t=this.getOffsetParent||Fc,n=this.getDimensions,r=await n(e.floating);return{reference:fy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function hy(e){return on(e).direction==="rtl"}const my={convertOffsetParentRelativeRectToViewportRelativeRect:ry,getDocumentElement:pn,getClippingRect:uy,getOffsetParent:Fc,getElementRects:py,getClientRects:oy,getDimensions:dy,getScale:xr,isElement:rn,isRTL:hy};function Bc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function gy(e,t){let n=null,r;const o=pn(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)),y=Lo(o.clientHeight-(f+h)),g=Lo(d),S={rootMargin:-x+"px "+-m+"px "+-y+"px "+-g+"px",threshold:zt(0,_n(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Bc(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 xy(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=ji(e),d=o||s?[...c?Fr(c):[],...Fr(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?gy(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&&y();function y(){const g=qn(e);m&&!Bc(m,g)&&n(),m=g,x=requestAnimationFrame(y)}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 yy=Ux,vy=Hx,by=Fx,wy=Vx,Sy=Bx,zc=$x,Cy=Wx,Ty=(e,t,n)=>{const r=new Map,o={platform:my,...n},s={...o.platform,_c:r};return Lx(e,t,{...o,platform:s})};var ky=typeof document<"u",Iy=function(){},Wo=ky?w.useLayoutEffect:Iy;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 Uc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Hc(e,t){const n=Uc(e);return Math.round(t*n)/n}function Mi(e){const t=v.useRef(e);return Wo(()=>{t.current=e}),t}function Ey(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);Vo(p,r)||h(r);const[x,m]=v.useState(null),[y,g]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,m(z))},[]),S=v.useCallback(z=>{z!==I.current&&(I.current=z,g(z))},[]),k=s||x,C=i||y,T=v.useRef(null),I=v.useRef(null),A=v.useRef(d),R=l!=null,$=Mi(l),P=Mi(o),O=Mi(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};P.current&&(z.platform=P.current),Ty(T.current,I.current,z).then(_=>{const V={..._,isPositioned:O.current!==!1};N.current&&!Vo(A.current,V)&&(A.current=V,ho.flushSync(()=>{f(V)}))})},[p,t,n,P,O]);Wo(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);Wo(()=>(N.current=!0,()=>{N.current=!1}),[]),Wo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if($.current)return $.current(k,C,F);F()}},[k,C,F,$,R]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),M=v.useMemo(()=>({reference:k,floating:C}),[k,C]),Q=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!M.floating)return z;const _=Hc(M.floating,d.x),V=Hc(M.floating,d.y);return a?{...z,transform:"translate("+_+"px, "+V+"px)",...Uc(M.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:_,top:V}},[n,a,M.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:M,floatingStyles:Q}),[d,F,B,M,Q])}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?zc({element:r.current,padding:o}).fn(n):{}:r?zc({element:r,padding:o}).fn(n):{}}}},Ny=(e,t)=>({...yy(e),options:[e,t]}),_y=(e,t)=>({...vy(e),options:[e,t]}),jy=(e,t)=>({...Cy(e),options:[e,t]}),Ry=(e,t)=>({...by(e),options:[e,t]}),My=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...Sy(e),options:[e,t]}),Oy=(e,t)=>({...Ay(e),options:[e,t]});var Dy="Arrow",Wc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ee.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"})})});Wc.displayName=Dy;var Ly=Wc;function Vc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Pi="Popper",[Kc,Ko]=Sn(Pi),[$y,qc]=Kc(Pi),Gc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx($y,{scope:t,anchor:r,onAnchorChange:o,children:n})};Gc.displayName=Pi;var Yc="PopperAnchor",Xc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=qc(Yc,n),i=v.useRef(null),a=Be(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Ee.div,{...o,ref:a})});Xc.displayName=Yc;var Oi="PopperContent",[Fy,By]=Kc(Oi),Jc=v.forwardRef((e,t)=>{var X,L,K,Z,ce,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,y=qc(Oi,n),[g,b]=v.useState(null),S=Be(t,je=>b(je)),[k,C]=v.useState(null),T=Vc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,R=r+(s!=="center"?"-"+s:""),$=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},P=Array.isArray(c)?c:[c],O=P.length>0,F={padding:$,boundary:P.filter(Uy),altBoundary:O},{refs:N,floatingStyles:B,placement:M,isPositioned:Q,middlewareData:z}=Ey({strategy:"fixed",placement:R,whileElementsMounted:(...je)=>xy(...je,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ny({mainAxis:o+A,alignmentAxis:i}),l&&_y({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?jy():void 0,...F}),l&&Ry({...F}),My({...F,apply:({elements:je,rects:Ue,availableWidth:De,availableHeight:Ge})=>{const{width:Ve,height:tt}=Ue.reference,Ye=je.floating.style;Ye.setProperty("--radix-popper-available-width",`${De}px`),Ye.setProperty("--radix-popper-available-height",`${Ge}px`),Ye.setProperty("--radix-popper-anchor-width",`${Ve}px`),Ye.setProperty("--radix-popper-anchor-height",`${tt}px`)}}),k&&Oy({element:k,padding:a}),Hy({arrowWidth:I,arrowHeight:A}),p&&Py({strategy:"referenceHidden",...F})]}),[_,V]=eu(M),Y=kt(x);Tt(()=>{Q&&(Y==null||Y())},[Q,Y]);const oe=(X=z.arrow)==null?void 0:X.x,ye=(L=z.arrow)==null?void 0:L.y,Me=((K=z.arrow)==null?void 0:K.centerOffset)!==0,[G,U]=v.useState();return Tt(()=>{g&&U(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:Q?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:G,"--radix-popper-transform-origin":[(Z=z.transformOrigin)==null?void 0:Z.x,(ce=z.transformOrigin)==null?void 0:ce.y].join(" "),...((re=z.hide)==null?void 0:re.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fy,{scope:n,placedSide:_,onArrowChange:C,arrowX:oe,arrowY:ye,shouldHideArrow:Me,children:u.jsx(Ee.div,{"data-side":_,"data-align":V,...m,ref:S,style:{...m.style,animation:Q?void 0:"none"}})})})});Jc.displayName=Oi;var Zc="PopperArrow",zy={top:"bottom",right:"left",bottom:"top",left:"right"},Qc=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=By(Zc,r),i=zy[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(Ly,{...o,ref:n,style:{...o.style,display:"block"}})})});Qc.displayName=Zc;function Uy(e){return e!==null}var Hy=e=>({name:"transformOrigin",options:e,fn(t){var y,g,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=eu(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 eu(e){const[t,n="center"]=e.split("-");return[t,n]}var tu=Gc,nu=Xc,ru=Jc,ou=Qc,Wy="Portal",qo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Gs.createPortal(u.jsx(Ee.div,{...r,ref:t}),i):null});qo.displayName=Wy;function Vy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Yt=e=>{const{present:t,children:n}=e,r=Ky(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Be(r.ref,qy(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Yt.displayName="Presence";function Ky(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Vy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Go(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Go(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=Go(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Go(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Go(e){return(e==null?void 0:e.animationName)||"none"}function 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 Di="rovingFocusGroup.onEntryFocus",Gy={bubbles:!1,cancelable:!0},Br="RovingFocusGroup",[Li,su,Yy]=xi(Br),[Xy,iu]=Sn(Br,[Yy]),[Jy,Zy]=Xy(Br),au=v.forwardRef((e,t)=>u.jsx(Li.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Li.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Qy,{...e,ref:t})})}));au.displayName=Br;var Qy=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Be(t,p),x=Mo(s),[m,y]=pr({prop:i,defaultProp:a??null,onChange:l,caller:Br}),[g,b]=v.useState(!1),S=kt(c),k=su(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Di,S),()=>A.removeEventListener(Di,S)},[S]),u.jsx(Jy,{scope:n,orientation:r,dir:x,loop:o,currentTabStopId:m,onItemFocus:v.useCallback(A=>y(A),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:v.useCallback(()=>I(A=>A-1),[]),children:u.jsx(Ee.div,{tabIndex:g||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:de(e.onMouseDown,()=>{C.current=!0}),onFocus:de(e.onFocus,A=>{const R=!C.current;if(A.target===A.currentTarget&&R&&!g){const $=new CustomEvent(Di,Gy);if(A.currentTarget.dispatchEvent($),!$.defaultPrevented){const P=k().filter(M=>M.focusable),O=P.find(M=>M.active),F=P.find(M=>M.id===m),B=[O,F,...P].filter(Boolean).map(M=>M.ref.current);uu(B,d)}}C.current=!1}),onBlur:de(e.onBlur,()=>b(!1))})})}),lu="RovingFocusGroupItem",cu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Cn(),c=s||l,d=Zy(lu,n),f=d.currentTabStopId===c,p=su(n),{onFocusableItemAdd:h,onFocusableItemRemove:x,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return h(),()=>x()},[r,h,x]),u.jsx(Li.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ee.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:de(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:de(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:de(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=nv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?rv(S,k+1):S.slice(k+1)}setTimeout(()=>uu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});cu.displayName=lu;var ev={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function tv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function nv(e,t,n){const r=tv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ev[r]}function uu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function rv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ov=au,sv=cu,iv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},yr=new WeakMap,Yo=new WeakMap,Xo={},$i=0,du=function(e){return e&&(e.host||du(e.parentNode))},av=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=du(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})},lv=function(e,t,n,r){var o=av(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=(yr.get(p)||0)+1,y=(s.get(p)||0)+1;yr.set(p,m),s.set(p,y),i.push(p),m===1&&x&&Yo.set(p,!0),y===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(),$i++,function(){i.forEach(function(f){var p=yr.get(f)-1,h=s.get(f)-1;yr.set(f,p),s.set(f,h),p||(Yo.has(f)||f.removeAttribute(r),Yo.delete(f)),h||f.removeAttribute(n)}),$i--,$i||(yr=new WeakMap,yr=new WeakMap,Yo=new WeakMap,Xo={})}},Fi=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=iv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),lv(r,o,n,"aria-hidden")):function(){return null}},mn=function(){return mn=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},mn.apply(this,arguments)};function fu(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 cv(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",uv="with-scroll-bars-hidden",dv="--removed-body-scroll-bar-size";function Bi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function fv(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 pv=typeof window<"u"?v.useLayoutEffect:v.useEffect,pu=new WeakMap;function hv(e,t){var n=fv(null,function(r){return e.forEach(function(o){return Bi(o,r)})});return pv(function(){var r=pu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Bi(a,null)}),s.forEach(function(a){o.has(a)||Bi(a,i)})}pu.set(n,e)},[e]),n}function mv(e){return e}function gv(e,t){t===void 0&&(t=mv);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 xv(e){e===void 0&&(e={});var t=gv(null);return t.options=mn({async:!0,ssr:!1},e),t}var hu=function(e){var t=e.sideCar,n=fu(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,mn({},n))};hu.isSideCarExport=!0;function yv(e,t){return e.useMedium(t),hu}var mu=xv(),zi=function(){},Qo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.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,y=e.allowPinchZoom,g=e.as,b=g===void 0?"div":g,S=e.gapMode,k=fu(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=hv([n,t]),I=mn(mn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:mu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:x,inert:m,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),mn(mn({},I),{ref:T})):v.createElement(b,mn({},I,{className:l,ref:T}),a))});Qo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qo.classNames={fullWidth:Zo,zeroRight:Jo};var vv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=vv();return t&&e.setAttribute("nonce",t),e}function wv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Sv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Cv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=bv())&&(wv(t,n),Sv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Tv=function(){var e=Cv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},gu=function(){var e=Tv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},kv={left:0,top:0,right:0,gap:0},Ui=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[Ui(n),Ui(r),Ui(o)]},Ev=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kv;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=gu(),vr="data-scroll-locked",Nv=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(uv,` {
37
+ `))>=0;){const ee=gt.slice(0,X);gt=gt.slice(X+2);const pe=qg(ee);if(!pe)continue;let be;try{be=JSON.parse(pe)}catch{console.debug("[use-chat] malformed SSE:",pe.slice(0,200));continue}const we=Kg(be)?be.data:be;Qe=Date.now();const Ue=we.seq;if(Ue!==void 0){if(Ue<=vt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ue,lastProcessedSeq:vt,type:we.type});continue}vt>0&&Ue>vt+1&&(($=j==null?void 0:j.onGap)==null||$.call(j,{from:vt,to:Ue})),vt=Ue,C.current=Ue,y(Ue)}if(console.debug("[use-chat] received event",{seq:we.seq,type:we.type,preview:(()=>{var _e;try{return we.type==="message_delta"?{deltaTypes:(_e=we.delta)==null?void 0:_e.map(De=>De.type),textLen:(we.delta||[]).filter(De=>De.type==="text").map(De=>String(De.text||"").length)}:we.content||we.delta?{hasContent:!0}:{}}catch(De){return{err:String(De)}}})()}),we.type==="checkpoint")I.current=we.checkpointId??null,A.current=we.checkpointNs??null,x(we.checkpointId??null);else if(we.type==="state_history"){M.current=we;try{const De=fr(we).latest;De&&(I.current=De.checkpointId??null,A.current=De.checkpointNs??null,x(De.checkpointId??null))}catch(_e){console.warn("[use-chat] Failed to hydrate state_history payload",_e)}}try{B==null||B(we)}catch(_e){console.error("[use-chat] Error in onEvent callback:",_e,"for event:",we.type)}if(we.type==="token"&&e.autoAppendAssistant!==!1)ht.push(we.content),Mt();else if(we.type==="message_delta"){const _e=we.delta.filter(De=>De.type==="text").map(De=>De.text).join("");_e&&e.autoAppendAssistant!==!1&&(ht.push(_e),Mt())}else if(we.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(q=j==null?void 0:j.onHeartbeat)==null||q.call(j,we)}catch(_e){console.warn("[use-chat] heartbeat callback failed",_e)}}else if(wt!==null&&cancelAnimationFrame(wt),$t(),we.type==="checkpoint")x(we.checkpointId);else if(we.type==="error"){const _e=we;if(d(_e.message),z="error",R=_e.message,_e.error_type==="auth_error"||_e.code==="TOKEN_EXPIRED"||((Q=_e.message)==null?void 0:Q.includes("token"))||((ce=_e.message)==null?void 0:ce.includes("401"))||((oe=_e.message)==null?void 0:oe.includes("unauthorized"))||((Ae=_e.message)==null?void 0:Ae.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",_e.message);try{(ze=j==null?void 0:j.onAuthError)==null||ze.call(j,_e.message)}catch(Pt){console.warn("[use-chat] onAuthError handler failed",Pt)}V.abort()}}}}$t(),z===null&&!V.signal.aborted&&(z="complete")}catch(qe){if(qe.name==="AbortError")z=z??"aborted";else{const Ge=qe.message||String(qe);z="error",R=Ge,d(Ge),(re=j==null?void 0:j.onError)==null||re.call(j,Ge)}}finally{try{await it.cancel()}catch{}finally{(xe=it.releaseLock)==null||xe.call(it)}wt!==null&&typeof window<"u"&&window.cancelAnimationFrame(wt),clearInterval(It)}}catch(We){if(We.name==="AbortError")z=z??"aborted";else{const et=We.message||String(We);z="error",R=et,d(et),(Me=j==null?void 0:j.onError)==null||Me.call(j,et),K||((Je=j==null?void 0:j.onConnectionError)==null||Je.call(j,et),K=!0)}}finally{const We=C.current,et=I.current,st=A.current,Ke=M.current,tt=z??(V.signal.aborted?"aborted":R?"error":"complete");try{(Ze=j==null?void 0:j.onClosed)==null||Ze.call(j,{reason:tt,lastSeq:We,lastCheckpointId:et,lastCheckpointNs:st,lastStateHistory:Ke,error:R})}catch(it){console.warn("[use-chat] onClosed callback failed",it)}l(!1),b(!1),S.current=null,C.current=0,y(0),T.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var N;k.current=!1,(N=S.current)==null||N.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:h,lastSeq:m,connected:g,stream:F,stop:D,clear:P,setToken:L}}function Kg(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function qg(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
38
+ `)}function Gg(e){return e.type!=="token"}const Yg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Xg(e,t){var n;switch(t.type){case"reset":return{messages:mi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=mi(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=mi(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return 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(Xg,{...Yg,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=ex(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:y}=Jg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:x},b=_o(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,y={type:"tool_call",id:m,name:c,args:t.args};if(p){const S=xi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?_o(e.messages,C,k):e.messages,I=jo(k,d),A=yi(e.toolIndex,x,I);return{...e,messages:T,toolIndex:A}}const g={id:x,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:xi(void 0,d.length?d:[m],c,t.args)},b=jo(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:yi(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=jo(d,a);let m=t.output;if(typeof t.output=="string")try{const I=t.output.trim();(I.startsWith("{")||I.startsWith("["))&&(m=JSON.parse(I))}catch{m=t.output}const y=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=xi(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:y??void 0,additionalKwargs:S},C=c>=0?_o(e.messages,c,k):[...e.messages,k],T=jo(k,a.length?a:x);return{...e,messages:C,toolIndex:yi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Qg(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=fr(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 mi(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 _o(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 gi(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 xi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=gi(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 jo(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=gi(e);for(const o of r)n.add(o);return Array.from(n)}function yi(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(gi(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 Jg(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=Zg(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 Zg(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 Qg(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 _o(e,r,s)}return e}function ex(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const ic=200;function tx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onStateHistory:r,onUnhandledEvent:o,onSequenceGap:s,onStreamClosed:i,onConnectionError:a,onAuthError:l,onHeartbeat:c}){const d=w.useRef(null),f=w.useRef(null),p=w.useRef(new Map),h=w.useRef(null),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}},[]),y=w.useCallback((P,D)=>{if(!P)return;const F=p.current.get(P)??[],N=m(D),B=F.length>=ic?[...F.slice(F.length-ic+1),N]:[...F,N];p.current.set(P,B)},[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(N=>{try{n(N)}catch(B){console.error("[useChatStreamingService] Failed to replay buffered event",B)}})},[n]),S=w.useCallback(P=>{var N,B,j,V,z;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"||((N=R.message)==null?void 0:N.includes("token"))||((B=R.message)==null?void 0:B.includes("401"))||((j=R.message)==null?void 0:j.includes("unauthorized"))||((V=R.message)==null?void 0:V.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",R.message);try{l==null||l(R.message)}catch(J){console.warn("[useChatStreamingService] onAuthError handler failed",J)}}}const F=P.threadId??(P.type==="state_history"?P.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.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(Gg(P)){P.type==="checkpoint"||P.type==="state_history"?g(F??null):y(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)}},[y,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:A}=Jl({baseUrl:e,token:void 0}),M=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 N;(N=D==null?void 0:D.onError)==null||N.call(D,F)},onGap:(D==null?void 0:D.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=D==null?void 0:D.onConnectionError)==null||N.call(D,F)},onAuthError:F=>{var N;l==null||l(F),(N=D==null?void 0:D.onAuthError)==null||N.call(D,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=D==null?void 0:D.onHeartbeat)==null||N.call(D,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var V,z,R,K;const N=((V=h.current)==null?void 0:V.manualStop)??!1,B=f.current??((z=h.current)==null?void 0:z.threadIdGuess)??((R=F.lastStateHistory)==null?void 0:R.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&N)&&g(B);const j={...F,threadId:B,threadInfo:x.current,manualStop:N};try{i==null||i(j)}catch(J){console.warn("[useChatStreamingService] onStreamClosed handler failed",J)}try{(K=D==null?void 0:D.onClosed)==null||K.call(D,j)}catch(J){console.warn("[useChatStreamingService] downstream onClosed handler failed",J)}h.current&&(h.current=null)}})},[g,S,l,a,c,s,i,k]),L=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),C()},[C]);return w.useMemo(()=>({startStream:M,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[M,L,T,I,A,b])}const ac=w.createContext(null),lc=w.createContext(null),cc=w.createContext(null);w.createContext(!1);function nx({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}=pi(),d=w.useMemo(()=>Tn(c),[c]),[f,p]=w.useState([]),[h,x]=w.useState(t),[m,y]=w.useState(!1),[g,b]=w.useState(null),[S,k]=w.useState(!1),[C,T]=w.useState(null),{state:I,seed:A,prepend:M,pushUser:L,onEvent:P}=Zl(),[D,F]=w.useState(!1),[N,B]=w.useState(!1),[j,V]=w.useState(null),[z,R]=w.useState([]),[K,J]=w.useState([]),[se,ge]=w.useState(!1),Ie=w.useMemo(()=>z.flatMap(G=>G.messages??[]),[z]),Y=w.useMemo(()=>Xl(Ie),[Ie]),U=w.useRef(h),Z=w.useRef(null),$=w.useRef(null),q=w.useRef(null),Q=w.useRef(null),ce=w.useRef(!1),oe=w.useRef(null),Ae=w.useRef(new Map),ze=w.useRef(new Map);w.useEffect(()=>{U.current=h},[h]);const re=w.useCallback(async()=>{y(!0),b(null);try{const G=await l.listThreads();p(G??[])}catch(G){const _=String(G);b(_),s==null||s(_)}finally{y(!1)}},[l,s]),xe=w.useCallback(G=>{if(!(G!=null&&G.threadId))return;const _={threadId:G.threadId,title:G.title||`Thread ${G.threadId.slice(0,8)}`,createdAt:G.createdAt||new Date().toISOString(),updatedAt:G.updatedAt||new Date().toISOString(),messageCount:G.messageCount??1};p(X=>{let ee=!1;const pe=X.map(be=>be.threadId===_.threadId?(ee=!0,console.debug("[ChatSessionProvider] thread_info: updating existing thread",_.threadId),{...be,title:_.title??be.title,updatedAt:_.updatedAt??be.updatedAt,messageCount:_.messageCount??be.messageCount}):be);return ee?pe:(console.debug("[ChatSessionProvider] thread_info: adding thread to list",_.threadId),[_,...X])})},[]),Me=w.useCallback(G=>{const _=G.threadId??U.current;if(!_||U.current&&U.current!==_)return;const{checkpoints:X,timeline:ee}=fr(G);if(!X.length)return;const pe=X.find(be=>be.messages&&be.messages.length>0)??X.find(be=>!!be.checkpointId)??X[0];A((pe==null?void 0:pe.messages)??[],{checkpointId:(pe==null?void 0:pe.checkpointId)??null,checkpointNs:(pe==null?void 0:pe.checkpointNs)??null}),J(ee),R(X),F(!!(pe!=null&&pe.nextCursor)),V((pe==null?void 0:pe.nextCursor)??null),oe.current=`${_}:latest`,$.current=null,q.current=null},[A]),Je=w.useCallback(G=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",G.threadId),xe(G),U.current!==G.threadId&&((G.created??!U.current)&&($.current=G.threadId),q.current=G.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(G.threadId))},[xe]),{startStream:Ze,stop:We,isStreaming:et,error:st,setAuthToken:Ke}=tx({baseUrl:d,onThreadInfo:Je,onMessageEvent:P,onStateHistory:Me,onUnhandledEvent:G=>{console.warn("[ChatSessionProvider] Unhandled event:",G.type)},onAuthError:i}),tt=w.useCallback(async G=>{try{const _=await l.createThread(G);return x(_.threadId),await re(),_.threadId}catch(_){return s==null||s(String(_)),null}},[l,re,s]),it=w.useCallback(async G=>{const _=f;p(ee=>ee.filter(pe=>pe.threadId!==G));const X=new AbortController;ze.current.set(G,X);try{await l.deleteThread(G),U.current===G&&(x(null),A([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",G)}catch(ee){console.error("[ChatSessionProvider] Delete failed, restoring thread:",G,ee),p(_),s==null||s(`Failed to delete thread: ${String(ee)}`)}finally{ze.current.delete(G)}},[f,l,A,s]),Rt=w.useCallback(async(G,_)=>{try{await l.updateThread(G,_),await re()}catch(X){s==null||s(String(X))}},[l,re,s]),gt=w.useCallback(async(G,_)=>{if(!G)return;const X=`${G}:${_??"latest"}`,ee=Ae.current.get(X);if(ee)return ee;const pe=(async()=>{const be=G;k(!0),T(null);try{const we=await l.getStateHistory({threadId:be,checkpointId:_||void 0});if(U.current!==be){console.log(`[ChatSessionProvider] Thread changed during load (was ${be}, now ${U.current}), discarding stale data`);return}const{checkpoints:Ue,timeline:_e}=fr(we),De=Ue.find(Pt=>Pt.messages&&Pt.messages.length>0)??(_?Ue.find(Pt=>Pt.checkpointId===_):null)??Ue[0];A((De==null?void 0:De.messages)??[],{checkpointId:(De==null?void 0:De.checkpointId)??null,checkpointNs:(De==null?void 0:De.checkpointNs)??null}),J(_e),R(Ue),F(!!(De!=null&&De.nextCursor)),V((De==null?void 0:De.nextCursor)??null)}catch(we){if(U.current===be){const Ue=String(we);T(Ue),s==null||s(Ue)}}finally{k(!1)}})();Ae.current.set(X,pe);try{await pe}finally{Ae.current.delete(X)}return U.current===G&&(oe.current=X),pe},[l,A,s]),ht=w.useCallback(async(G,_)=>{Q.current=G;try{await gt(G,_)}finally{Q.current===G&&(Q.current=null)}},[gt]);w.useEffect(()=>{if(!o||!h||S||et)return;if($.current===h){$.current=null,Z.current=h;return}if(q.current===h){Z.current=h;return}if(Q.current===h){Q.current=null,Z.current=h;return}if(Z.current===h)return;Z.current=h;const G=!ce.current&&!!n&&h===t;let _;G&&n?(_=n,ce.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",_,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const X=`${h}:${_??"latest"}`;oe.current!==X&&ht(h,_)},[o,h,n,r,t,S,et,ht]);const vt=w.useCallback(async(G,_)=>{const X=U.current;if(!X)return;const ee=X;ge(!0);try{const pe=await l.getStateHistory({threadId:ee,checkpointId:G,checkpointNs:_??void 0});if(U.current!==ee){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${ee}, now ${U.current}), discarding stale data`);return}const{checkpoints:be,timeline:we}=fr(pe),Ue=be.find(_e=>_e.checkpointId===G&&(_?_e.checkpointNs===_:!0));if(!Ue){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:G,checkpointNs:_});return}J(we),R(be),A(Ue.messages??[],{checkpointId:Ue.checkpointId??null,checkpointNs:Ue.checkpointNs??null})}catch(pe){U.current===ee&&(s==null||s(String(pe)))}finally{ge(!1)}},[l,A,s]),wt=w.useCallback((G,_)=>{A(I.messages,{checkpointId:G??null,checkpointNs:_??null})},[A,I.messages]),$t=w.useCallback(async()=>{U.current&&await ht(U.current)},[ht]),Mt=w.useCallback(async()=>{if(!U.current||!j)return;const G=U.current;B(!0);try{const _=await l.getStateHistory({threadId:G,checkpointId:j});if(U.current!==G)return;const{checkpoints:X}=fr(_);if(X.length>0){const ee=X[X.length-1];M((ee==null?void 0:ee.messages)??[]),F(!!(ee!=null&&ee.nextCursor)),V((ee==null?void 0:ee.nextCursor)??null)}}catch(_){U.current===G&&(s==null||s(String(_)))}finally{B(!1)}},[l,j,M,s]),Qe=w.useCallback(async()=>{A([],{}),x(null),We(),R([]),J([]),F(!1),V(null),k(!1),ge(!1),B(!1),T(null);try{await l.getAgent("default")}catch(G){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",G)}},[A,We,l]),It=w.useCallback(async(G,_,X)=>{const ee=U.current;if(!ee)throw new Error("No active thread to handle interrupt");const pe=_?X??!0:!1;try{const be={threadId:ee,checkpointId:I.lastCheckpointId??void 0,checkpointNs:I.lastCheckpointNs??void 0,command:{kind:"resume",value:pe}};Ze(be)}catch(be){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${G}:`,be),be}},[I.lastCheckpointId,I.lastCheckpointNs,Ze]);w.useEffect(()=>{re()},[re]),w.useEffect(()=>{a==null||a(h)},[h,a]);const Sn=w.useCallback(async(G,_)=>{let X=U.current;const ee=(G==null?void 0:G.text)??"",pe=(G==null?void 0:G.attachments)??[],be=(ee==null?void 0:ee.trim())??"",we={...(G==null?void 0:G.payload)??{}},Ue=Array.isArray(we.messages)?we.messages:void 0;Ue&&delete we.messages;const _e=!!(Ue&&Ue.length);if(!X&&!be&&pe.length===0&&!_e)return;if(!X){const ie=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ve=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);X=`${ie}${ve}`,$.current=X,x(X)}const{contentParts:De,filesInfo:Pt}=await wg(l,pe),un=[...De];be&&un.push({type:"text",text:ee});const dn=_==null?void 0:_.originalMessageId,Nr=!!(_!=null&&_.edit&&dn),_r=!_e&&un.length>0;let Wn=null;_r&&(Wn={id:Nr?dn:`msg-${Date.now()}`,role:"user",content:un,createdAt:new Date().toISOString()},Nr||L(Wn));const jr=_e?Ue:Wn?[Wn]:[],E={...we,...Pt.length?{files_info:Pt}:{}};jr.length?E.messages=jr:"messages"in E||(E.messages=[]);const W={threadId:X,payload:E,checkpointId:(_==null?void 0:_.checkpointId)??I.lastCheckpointId??void 0,checkpointNs:(_==null?void 0:_.checkpointNs)??I.lastCheckpointNs??void 0,edit:!!(_!=null&&_.edit),timelineCheckpoints:K};Ze(W)},[l,L,I,Ze,K]),qe=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:tt,deleteThread:it,renameThread:Rt,refreshThreads:re}}),[f,h,m,g,tt,it,Rt,re]),Ge=w.useMemo(()=>{const G=I.assemblingId??null;return G?{assemblingMessageId:G}:null},[I.assemblingId]),ft=w.useMemo(()=>({threadId:h,messages:I.messages,interrupt:null,checkpoint:{id:I.lastCheckpointId??null,namespace:I.lastCheckpointNs??null},checkpoints:z,timelineCheckpoints:K,metadata:Ge,isLoading:S,isHistoryLoading:N,isLoadingCheckpoint:se,error:C,hasMore:D,loadOlder:Mt,clearState:Qe,navigateToCheckpoint:vt,setCurrentCheckpointId:wt,returnToLatest:$t,loadThread:ht,clearThread:Qe,respondToInterrupt:It,messagePreviews:Y}),[h,I,z,K,S,N,se,C,D,Mt,Qe,vt,wt,$t,ht,It,Y,Ge]),at=w.useMemo(()=>({isStreaming:et,error:st,connectionState:et?"connected":"idle",submit:Sn,send:Sn,stop:We,setAuthToken:Ke}),[et,st,Sn,We,Ke]);return u.jsx(ac.Provider,{value:qe,children:u.jsx(lc.Provider,{value:ft,children:u.jsx(cc.Provider,{value:at,children:e})})})}function Ro(){const e=w.useContext(ac);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Mo(){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 Po({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(nx,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function ne(...e){return Kh.twMerge(Vh.clsx(e))}const rx=mo.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"}}),Ye=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Kn.Slot:"button";return u.jsx(i,{className:ne(rx({variant:t,size:n,className:e})),ref:s,...o})});Ye.displayName="Button";const dc=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:ne("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));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,y]=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||(y(e??""),T.current=null,k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`))},[e,t,x]);const I=w.useCallback(()=>{const B=k.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{I()},[I,g]);const A=w.useCallback((B,{fromUser:j})=>{x||y(B),j&&(a==null||a(B))},[x,a]),M=w.useCallback(async B=>{B&&B.preventDefault();const j=(g??"").trim();if(!j&&!h)return;const V=++C.current;T.current={id:V,shouldClear:!0},S(()=>{var z,R,K;try{const J=l(j);J&&typeof J.then=="function"?J.then(()=>{var se,ge;((se=T.current)==null?void 0:se.id)===V&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ge=T.current)==null?void 0:ge.id)===V&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===V&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===V&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((R=T.current)==null?void 0:R.id)===V&&(T.current=null))}catch{((K=T.current)==null?void 0:K.id)===V&&(T.current=null)}})},[g,l,h,x,a]),L=w.useCallback(B=>{const j=B.target.value;A(j,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),P=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),M()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[M,t,c]),N=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${p}`;return u.jsx("form",{onSubmit:B=>void M(B),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(dc,{ref:k,value:g,onChange:L,onKeyDown:P,placeholder:t?"Edit your message...":n,className:N,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(Ye,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(ae.Square,{size:16})}):u.jsx(Ye,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||b,children:u.jsx(ae.Send,{size:16})})})]})})}const ox=w.memo(fc);function fe(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function pc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function vi(...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 Fe(...e){return v.useCallback(vi(...e),e)}function sx(e,t){const n=v.createContext(t),r=s=>{const{children:i,...a}=s,l=v.useMemo(()=>a,Object.values(a));return u.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=v.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function kn(e,t=[]){let n=[];function r(s,i){const a=v.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,y=v.useMemo(()=>x,Object.values(x));return u.jsx(m.Provider,{value:y,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=v.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=>v.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return v.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,ix(o,...t)]}function ix(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Tt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ax=v[" useInsertionEffect ".trim().toString()]||Tt;function hr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=lx({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=v.useRef(e!==void 0);v.useEffect(()=>{const f=d.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=a},[a,r])}const c=v.useCallback(d=>{var f;if(a){const p=cx(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 lx({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return ax(()=>{s.current=t},[t]),v.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function cx(e){return typeof e=="function"}var ux=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=ux.reduce((e,t)=>{const n=Kn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function hc(e,t){e&&go.flushSync(()=>e.dispatchEvent(t))}function bi(e){const t=e+"CollectionProvider",[n,r]=kn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=m=>{const{scope:y,children:g}=m,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:g})};i.displayName=t;const a=e+"CollectionSlot",l=Kn.createSlot(a),c=w.forwardRef((m,y)=>{const{scope:g,children:b}=m,S=s(a,g),k=Fe(y,S.collectionRef);return u.jsx(l,{ref:k,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",p=Kn.createSlot(d),h=w.forwardRef((m,y)=>{const{scope:g,children:b,...S}=m,k=w.useRef(null),C=Fe(y,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 y=s(e+"CollectionConsumer",m);return w.useCallback(()=>{const b=y.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(y.itemMap.values()).sort((T,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:h},x,r]}var dx=v.createContext(void 0);function Oo(e){const t=v.useContext(dx);return e||t||"ltr"}function kt(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e}),v.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function fx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var px="DismissableLayer",wi="dismissableLayer.update",hx="dismissableLayer.pointerDownOutside",mx="dismissableLayer.focusOutside",mc,gc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Do=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(gc),[d,f]=v.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,h]=v.useState({}),x=Fe(t,I=>f(I)),m=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),g=m.indexOf(y),b=d?m.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,k=b>=g,C=yx(I=>{const A=I.target,M=[...c.branches].some(L=>L.contains(A));!k||M||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=vx(I=>{const A=I.target;[...c.branches].some(L=>L.contains(A))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return fx(I=>{b===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(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]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),xc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(wi,I),()=>document.removeEventListener(wi,I)},[]),u.jsx(Ne.div,{...l,ref:x,style:{pointerEvents:S?k?"auto":"none":void 0,...e.style},onFocusCapture:fe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:fe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:fe(e.onPointerDownCapture,C.onPointerDownCapture)})});Do.displayName=px;var gx="DismissableLayerBranch",xx=v.forwardRef((e,t)=>{const n=v.useContext(gc),r=v.useRef(null),o=Fe(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Ne.div,{...e,ref:o})});xx.displayName=gx;function yx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){yc(hx,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 vx(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&yc(mx,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(wi);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 Si=0;function Ci(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??vc()),document.body.insertAdjacentElement("beforeend",e[1]??vc()),Si++,()=>{Si===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Si--}},[])}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 Ti="focusScope.autoFocusOnMount",ki="focusScope.autoFocusOnUnmount",bc={bubbles:!1,cancelable:!0},bx="FocusScope",Lo=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=kt(o),d=kt(s),f=v.useRef(null),p=Fe(t,m=>l(m)),h=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.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})},y=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",y);const b=new MutationObserver(g);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,h.paused]),v.useEffect(()=>{if(a){Cc.add(h);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(Ti,bc);a.addEventListener(Ti,c),a.dispatchEvent(g),g.defaultPrevented||(wx(Ix(wc(a)),{select:!0}),document.activeElement===m&&Rn(a))}return()=>{a.removeEventListener(Ti,c),setTimeout(()=>{const g=new CustomEvent(ki,bc);a.addEventListener(ki,d),a.dispatchEvent(g),g.defaultPrevented||Rn(m??document.body,{select:!0}),a.removeEventListener(ki,d),Cc.remove(h)},0)}}},[a,c,d,h]);const x=v.useCallback(m=>{if(!n&&!r||h.paused)return;const y=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,g=document.activeElement;if(y&&g){const b=m.currentTarget,[S,k]=Sx(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(Ne.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Lo.displayName=bx;function wx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Rn(r,{select:t}),document.activeElement!==n)return}function Sx(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(!Cx(n,{upTo:t}))return n}function Cx(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 Tx(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&&Tx(e)&&t&&e.select()}}var Cc=kx();function kx(){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 Ix(e){return e.filter(t=>t.tagName!=="A")}var Ex=v[" useId ".trim().toString()]||(()=>{}),Ax=0;function In(e){const[t,n]=v.useState(Ex());return Tt(()=>{n(r=>r??String(Ax++))},[e]),t?`radix-${t}`:""}const Nx=["top","right","bottom","left"],Mn=Math.min,Ht=Math.max,$o=Math.round,Fo=Math.floor,pn=e=>({x:e,y:e}),_x={left:"right",right:"left",bottom:"top",top:"bottom"},jx={start:"end",end:"start"};function Ii(e,t,n){return Ht(e,Mn(t,n))}function En(e,t){return typeof e=="function"?e(t):e}function An(e){return e.split("-")[0]}function mr(e){return e.split("-")[1]}function Ei(e){return e==="x"?"y":"x"}function Ai(e){return e==="y"?"height":"width"}const Rx=new Set(["top","bottom"]);function hn(e){return Rx.has(An(e))?"y":"x"}function Ni(e){return Ei(hn(e))}function Mx(e,t,n){n===void 0&&(n=!1);const r=mr(e),o=Ni(e),s=Ai(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Bo(i)),[i,Bo(i)]}function Px(e){const t=Bo(e);return[_i(e),t,_i(t)]}function _i(e){return e.replace(/start|end/g,t=>jx[t])}const kc=["left","right"],Ic=["right","left"],Ox=["top","bottom"],Dx=["bottom","top"];function Lx(e,t,n){switch(e){case"top":case"bottom":return n?t?Ic:kc:t?kc:Ic;case"left":case"right":return t?Ox:Dx;default:return[]}}function $x(e,t,n,r){const o=mr(e);let s=Lx(An(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(_i)))),s}function Bo(e){return e.replace(/left|right|bottom|top/g,t=>_x[t])}function Fx(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ec(e){return typeof e!="number"?Fx(e):{top:e,right:e,bottom:e,left:e}}function zo(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=Ni(t),a=Ai(i),l=An(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(mr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Bx=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:y,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,[y]:{...h[y],...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 Br(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=Ec(h),y=a[p?f==="floating"?"reference":"floating":f],g=zo(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(y)))==null||n?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),k=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=zo(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 zx=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=Ec(d),p={x:n,y:r},h=Ni(o),x=Ai(h),m=await i.getDimensions(c),y=h==="y",g=y?"top":"left",b=y?"bottom":"right",S=y?"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 I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[x]);const A=k/2-C/2,M=I/2-m[x]/2-1,L=Mn(f[g],M),P=Mn(f[b],M),D=L,F=I-m[x]-P,N=I/2-m[x]/2+A,B=Ii(D,N,F),j=!l.arrow&&mr(o)!=null&&N!==B&&s.reference[x]/2-(N<D?L:P)-m[x]/2<0,V=j?N<D?N-D:N-F:0;return{[h]:p[h]+V,data:{[h]:B,centerOffset:N-B-V,...j&&{alignmentOffset:V}},reset:j}}}),Ux=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,...y}=En(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=An(o),b=hn(a),S=An(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[Bo(a)]:Px(a)),T=x!=="none";!p&&T&&C.push(...$x(a,m,x,k));const I=[a,...C],A=await Br(t,y),M=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&M.push(A[g]),f){const N=Mx(o,i,k);M.push(A[N[0]],A[N[1]])}if(L=[...L,{placement:o,overflows:M}],!M.every(N=>N<=0)){var P,D;const N=(((P=s.flip)==null?void 0:P.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==hn(B):!1)||L.every(z=>hn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:L},reset:{placement:B}};let j=(D=L.filter(V=>V.overflows[0]<=0).sort((V,z)=>V.overflows[1]-z.overflows[1])[0])==null?void 0:D.placement;if(!j)switch(h){case"bestFit":{var F;const V=(F=L.filter(z=>{if(T){const R=hn(z.placement);return R===b||R==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(R=>R>0).reduce((R,K)=>R+K,0)]).sort((z,R)=>z[1]-R[1])[0])==null?void 0:F[0];V&&(j=V);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function Nc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function _c(e){return Nx.some(t=>e[t]>=0)}const Hx=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 Br(t,{...o,elementContext:"reference"}),i=Nc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:_c(i)}}}case"escaped":{const s=await Br(t,{...o,altBoundary:!0}),i=Nc(s,n.floating);return{data:{escapedOffsets:i,escaped:_c(i)}}}default:return{}}}}},jc=new Set(["left","top"]);async function Wx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=An(n),a=mr(n),l=hn(n)==="y",c=jc.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 Vx=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 Wx(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}}}}},Kx=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:g,y:b}=y;return{x:g,y:b}}},...l}=En(e,t),c={x:n,y:r},d=await Br(t,l),f=hn(An(o)),p=Ei(f);let h=c[p],x=c[f];if(s){const y=p==="y"?"top":"left",g=p==="y"?"bottom":"right",b=h+d[y],S=h-d[g];h=Ii(b,h,S)}if(i){const y=f==="y"?"top":"left",g=f==="y"?"bottom":"right",b=x+d[y],S=x-d[g];x=Ii(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}}}}}},qx=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=Ei(f);let h=d[p],x=d[f];const m=En(a,t),y=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]+y.mainAxis,C=s.reference[p]+s.reference[S]-y.mainAxis;h<k?h=k:h>C&&(h=C)}if(c){var g,b;const S=p==="y"?"width":"height",k=jc.has(An(o)),C=s.reference[f]-s.floating[S]+(k&&((g=i.offset)==null?void 0:g[f])||0)+(k?0:y.crossAxis),T=s.reference[f]+s.reference[S]+(k?0:((b=i.offset)==null?void 0:b[f])||0)-(k?y.crossAxis:0);x<C?x=C:x>T&&(x=T)}return{[p]:h,[f]:x}}}},Gx=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 Br(t,c),f=An(o),p=mr(o),h=hn(o)==="y",{width:x,height:m}=s.floating;let y,g;f==="top"||f==="bottom"?(y=f,g=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(g=f,y=p==="end"?"top":"bottom");const b=m-d.top-d.bottom,S=x-d.left-d.right,k=Mn(m-d[y],b),C=Mn(x-d[g],S),T=!t.middlewareData.shift;let I=k,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!p){const L=Ht(d.left,0),P=Ht(d.right,0),D=Ht(d.top,0),F=Ht(d.bottom,0);h?A=x-2*(L!==0||P!==0?L+P:Ht(d.left,d.right)):I=m-2*(D!==0||F!==0?D+F:Ht(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const M=await i.getDimensions(a.floating);return x!==M.width||m!==M.height?{reset:{rects:!0}}:{}}}};function Uo(){return typeof window<"u"}function gr(e){return Rc(e)?(e.nodeName||"").toLowerCase():"#document"}function Wt(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 Uo()?e instanceof Node||e instanceof Wt(e).Node:!1}function rn(e){return Uo()?e instanceof Element||e instanceof Wt(e).Element:!1}function gn(e){return Uo()?e instanceof HTMLElement||e instanceof Wt(e).HTMLElement:!1}function Mc(e){return!Uo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Wt(e).ShadowRoot}const Yx=new Set(["inline","contents"]);function zr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=on(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Yx.has(o)}const Xx=new Set(["table","td","th"]);function Jx(e){return Xx.has(gr(e))}const Zx=[":popover-open",":modal"];function Ho(e){return Zx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Qx=["transform","translate","scale","rotate","perspective"],ey=["transform","translate","scale","rotate","perspective","filter"],ty=["paint","layout","strict","content"];function ji(e){const t=Ri(),n=rn(e)?on(e):e;return Qx.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)||ey.some(r=>(n.willChange||"").includes(r))||ty.some(r=>(n.contain||"").includes(r))}function ny(e){let t=Pn(e);for(;gn(t)&&!xr(t);){if(ji(t))return t;if(Ho(t))return null;t=Pn(t)}return null}function Ri(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ry=new Set(["html","body","#document"]);function xr(e){return ry.has(gr(e))}function on(e){return Wt(e).getComputedStyle(e)}function Wo(e){return rn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Pn(e){if(gr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Mc(e)&&e.host||mn(e);return Mc(t)?t.host:t}function Pc(e){const t=Pn(e);return xr(t)?e.ownerDocument?e.ownerDocument.body:e.body:gn(t)&&zr(t)?t:Pc(t)}function Ur(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Pc(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Wt(o);if(s){const a=Mi(i);return t.concat(i,i.visualViewport||[],zr(o)?o:[],a&&n?Ur(a):[])}return t.concat(o,Ur(o,[],n))}function Mi(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Oc(e){const t=on(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=$o(n)!==s||$o(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Pi(e){return rn(e)?e:e.contextElement}function yr(e){const t=Pi(e);if(!gn(t))return pn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Oc(t);let i=(s?$o(n.width):n.width)/r,a=(s?$o(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const oy=pn(0);function Dc(e){const t=Wt(e);return!Ri()||!t.visualViewport?oy:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function sy(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Wt(e)?!1:t}function Xn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Pi(e);let i=pn(1);t&&(r?rn(r)&&(i=yr(r)):i=yr(e));const a=sy(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=Wt(s),h=r&&rn(r)?Wt(r):r;let x=p,m=Mi(x);for(;m&&r&&h!==x;){const y=yr(m),g=m.getBoundingClientRect(),b=on(m),S=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*y.x,k=g.top+(m.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=k,x=Wt(m),m=Mi(x)}}return zo({width:d,height:f,x:l,y:c})}function Vo(e,t){const n=Wo(e).scrollLeft;return t?t.left+n:Xn(mn(e)).left+n}function Lc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Vo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function iy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=mn(r),a=t?Ho(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)&&((gr(r)!=="body"||zr(i))&&(l=Wo(r)),gn(r))){const h=Xn(r);c=yr(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 ay(e){return Array.from(e.getClientRects())}function ly(e){const t=mn(e),n=Wo(e),r=e.ownerDocument.body,o=Ht(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ht(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Vo(e);const a=-n.scrollTop;return on(r).direction==="rtl"&&(i+=Ht(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const $c=25;function cy(e,t){const n=Wt(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=Ri();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Vo(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 uy=new Set(["absolute","fixed"]);function dy(e,t){const n=Xn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=gn(e)?yr(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=cy(e,n);else if(t==="document")r=ly(mn(e));else if(rn(t))r=dy(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 zo(r)}function Bc(e,t){const n=Pn(e);return n===t||!rn(n)||xr(n)?!1:on(n).position==="fixed"||Bc(n,t)}function fy(e,t){const n=t.get(e);if(n)return n;let r=Ur(e,[],!1).filter(a=>rn(a)&&gr(a)!=="body"),o=null;const s=on(e).position==="fixed";let i=s?Pn(e):e;for(;rn(i)&&!xr(i);){const a=on(i),l=ji(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&uy.has(o.position)||zr(i)&&!l&&Bc(e,i))?r=r.filter(d=>d!==i):o=a,i=Pn(i)}return t.set(e,r),r}function py(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Ho(t)?[]:fy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Fc(t,d,o);return c.top=Ht(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Ht(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 hy(e){const{width:t,height:n}=Oc(e);return{width:t,height:n}}function my(e,t,n){const r=gn(t),o=mn(t),s=n==="fixed",i=Xn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=pn(0);function c(){l.x=Vo(o)}if(r||!r&&!s)if((gr(t)!=="body"||zr(o))&&(a=Wo(t)),r){const h=Xn(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 Oi(e){return on(e).position==="static"}function zc(e,t){if(!gn(e)||on(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=Wt(e);if(Ho(e))return n;if(!gn(e)){let o=Pn(e);for(;o&&!xr(o);){if(rn(o)&&!Oi(o))return o;o=Pn(o)}return n}let r=zc(e,t);for(;r&&Jx(r)&&Oi(r);)r=zc(r,t);return r&&xr(r)&&Oi(r)&&!ji(r)?n:r||ny(e)||n}const gy=async function(e){const t=this.getOffsetParent||Uc,n=this.getDimensions,r=await n(e.floating);return{reference:my(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function xy(e){return on(e).direction==="rtl"}const yy={convertOffsetParentRelativeRectToViewportRelativeRect:iy,getDocumentElement:mn,getClippingRect:py,getOffsetParent:Uc,getElementRects:gy,getClientRects:ay,getDimensions:hy,getScale:yr,isElement:rn,isRTL:xy};function Hc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function vy(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=Fo(f),m=Fo(o.clientWidth-(d+p)),y=Fo(o.clientHeight-(f+h)),g=Fo(d),S={rootMargin:-x+"px "+-m+"px "+-y+"px "+-g+"px",threshold:Ht(0,Mn(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Hc(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 by(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=Pi(e),d=o||s?[...c?Ur(c):[],...Ur(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?vy(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?Xn(e):null;l&&y();function y(){const g=Xn(e);m&&!Hc(m,g)&&n(),m=g,x=requestAnimationFrame(y)}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 wy=Vx,Sy=Kx,Cy=Ux,Ty=Gx,ky=Hx,Wc=zx,Iy=qx,Ey=(e,t,n)=>{const r=new Map,o={platform:yy,...n},s={...o.platform,_c:r};return Bx(e,t,{...o,platform:s})};var Ay=typeof document<"u",Ny=function(){},Ko=Ay?w.useLayoutEffect:Ny;function qo(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(!qo(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)&&!qo(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 Di(e){const t=v.useRef(e);return Ko(()=>{t.current=e}),t}function _y(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,f]=v.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,h]=v.useState(r);qo(p,r)||h(r);const[x,m]=v.useState(null),[y,g]=v.useState(null),b=v.useCallback(z=>{z!==T.current&&(T.current=z,m(z))},[]),S=v.useCallback(z=>{z!==I.current&&(I.current=z,g(z))},[]),k=s||x,C=i||y,T=v.useRef(null),I=v.useRef(null),A=v.useRef(d),M=l!=null,L=Di(l),P=Di(o),D=Di(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};P.current&&(z.platform=P.current),Ey(T.current,I.current,z).then(R=>{const K={...R,isPositioned:D.current!==!1};N.current&&!qo(A.current,K)&&(A.current=K,go.flushSync(()=>{f(K)}))})},[p,t,n,P,D]);Ko(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);Ko(()=>(N.current=!0,()=>{N.current=!1}),[]),Ko(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,F);F()}},[k,C,F,L,M]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),j=v.useMemo(()=>({reference:k,floating:C}),[k,C]),V=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!j.floating)return z;const R=Kc(j.floating,d.x),K=Kc(j.floating,d.y);return a?{...z,transform:"translate("+R+"px, "+K+"px)",...Vc(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:R,top:K}},[n,a,j.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:j,floatingStyles:V}),[d,F,B,j,V])}const jy=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):{}}}},Ry=(e,t)=>({...wy(e),options:[e,t]}),My=(e,t)=>({...Sy(e),options:[e,t]}),Py=(e,t)=>({...Iy(e),options:[e,t]}),Oy=(e,t)=>({...Cy(e),options:[e,t]}),Dy=(e,t)=>({...Ty(e),options:[e,t]}),Ly=(e,t)=>({...ky(e),options:[e,t]}),$y=(e,t)=>({...jy(e),options:[e,t]});var Fy="Arrow",qc=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Ne.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});qc.displayName=Fy;var By=qc;function Gc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Li="Popper",[Yc,Go]=kn(Li),[zy,Xc]=Yc(Li),Jc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(zy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Jc.displayName=Li;var Zc="PopperAnchor",Qc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Xc(Zc,n),i=v.useRef(null),a=Fe(t,i),l=v.useRef(null);return v.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:u.jsx(Ne.div,{...o,ref:a})});Qc.displayName=Zc;var $i="PopperContent",[Uy,Hy]=Yc($i),eu=v.forwardRef((e,t)=>{var Z,$,q,Q,ce,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,y=Xc($i,n),[g,b]=v.useState(null),S=Fe(t,Ae=>b(Ae)),[k,C]=v.useState(null),T=Gc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,M=r+(s!=="center"?"-"+s:""),L=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:L,boundary:P.filter(Vy),altBoundary:D},{refs:N,floatingStyles:B,placement:j,isPositioned:V,middlewareData:z}=_y({strategy:"fixed",placement:M,whileElementsMounted:(...Ae)=>by(...Ae,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ry({mainAxis:o+A,alignmentAxis:i}),l&&My({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Py():void 0,...F}),l&&Oy({...F}),Dy({...F,apply:({elements:Ae,rects:ze,availableWidth:re,availableHeight:xe})=>{const{width:Me,height:Je}=ze.reference,Ze=Ae.floating.style;Ze.setProperty("--radix-popper-available-width",`${re}px`),Ze.setProperty("--radix-popper-available-height",`${xe}px`),Ze.setProperty("--radix-popper-anchor-width",`${Me}px`),Ze.setProperty("--radix-popper-anchor-height",`${Je}px`)}}),k&&$y({element:k,padding:a}),Ky({arrowWidth:I,arrowHeight:A}),p&&Ly({strategy:"referenceHidden",...F})]}),[R,K]=ru(j),J=kt(x);Tt(()=>{V&&(J==null||J())},[V,J]);const se=(Z=z.arrow)==null?void 0:Z.x,ge=($=z.arrow)==null?void 0:$.y,Ie=((q=z.arrow)==null?void 0:q.centerOffset)!==0,[Y,U]=v.useState();return Tt(()=>{g&&U(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:V?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Y,"--radix-popper-transform-origin":[(Q=z.transformOrigin)==null?void 0:Q.x,(ce=z.transformOrigin)==null?void 0:ce.y].join(" "),...((oe=z.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Uy,{scope:n,placedSide:R,onArrowChange:C,arrowX:se,arrowY:ge,shouldHideArrow:Ie,children:u.jsx(Ne.div,{"data-side":R,"data-align":K,...m,ref:S,style:{...m.style,animation:V?void 0:"none"}})})})});eu.displayName=$i;var tu="PopperArrow",Wy={top:"bottom",right:"left",bottom:"top",left:"right"},nu=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Hy(tu,r),i=Wy[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(By,{...o,ref:n,style:{...o.style,display:"block"}})})});nu.displayName=tu;function Vy(e){return e!==null}var Ky=e=>({name:"transformOrigin",options:e,fn(t){var y,g,b;const{placement:n,rects:r,middlewareData:o}=t,i=((y=o.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=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,qy="Portal",Yo=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Tt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Js.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});Yo.displayName=qy;function Gy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Xt=e=>{const{present:t,children:n}=e,r=Yy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Fe(r.ref,Xy(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Xt.displayName="Presence";function Yy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Gy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Xo(r.current);s.current=a==="mounted"?c:"none"},[a]),Tt(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,h=Xo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=Xo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(l("ANIMATION_END"),!o.current)){const y=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=y)})}},p=h=>{h.target===t&&(s.current=Xo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function Xo(e){return(e==null?void 0:e.animationName)||"none"}function Xy(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 Fi="rovingFocusGroup.onEntryFocus",Jy={bubbles:!1,cancelable:!0},Hr="RovingFocusGroup",[Bi,lu,Zy]=bi(Hr),[Qy,cu]=kn(Hr,[Zy]),[ev,tv]=Qy(Hr),uu=v.forwardRef((e,t)=>u.jsx(Bi.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Bi.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(nv,{...e,ref:t})})}));uu.displayName=Hr;var nv=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=e,p=v.useRef(null),h=Fe(t,p),x=Oo(s),[m,y]=hr({prop:i,defaultProp:a??null,onChange:l,caller:Hr}),[g,b]=v.useState(!1),S=kt(c),k=lu(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Fi,S),()=>A.removeEventListener(Fi,S)},[S]),u.jsx(ev,{scope:n,orientation:r,dir:x,loop:o,currentTabStopId:m,onItemFocus:v.useCallback(A=>y(A),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>I(A=>A+1),[]),onFocusableItemRemove:v.useCallback(()=>I(A=>A-1),[]),children:u.jsx(Ne.div,{tabIndex:g||T===0?-1:0,"data-orientation":r,...f,ref:h,style:{outline:"none",...e.style},onMouseDown:fe(e.onMouseDown,()=>{C.current=!0}),onFocus:fe(e.onFocus,A=>{const M=!C.current;if(A.target===A.currentTarget&&M&&!g){const L=new CustomEvent(Fi,Jy);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const P=k().filter(j=>j.focusable),D=P.find(j=>j.active),F=P.find(j=>j.id===m),B=[D,F,...P].filter(Boolean).map(j=>j.ref.current);pu(B,d)}}C.current=!1}),onBlur:fe(e.onBlur,()=>b(!1))})})}),du="RovingFocusGroupItem",fu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=In(),c=s||l,d=tv(du,n),f=d.currentTabStopId===c,p=lu(n),{onFocusableItemAdd:h,onFocusableItemRemove:x,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return h(),()=>x()},[r,h,x]),u.jsx(Bi.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:fe(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:fe(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:fe(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=sv(y,d.orientation,d.dir);if(g!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const k=S.indexOf(y.currentTarget);S=d.loop?iv(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 rv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ov(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function sv(e,t,n){const r=ov(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return rv[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 iv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var av=uu,lv=fu,cv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},vr=new WeakMap,Jo=new WeakMap,Zo={},zi=0,hu=function(e){return e&&(e.host||hu(e.parentNode))},uv=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})},dv=function(e,t,n,r){var o=uv(t,Array.isArray(e)?e:[e]);Zo[n]||(Zo[n]=new WeakMap);var s=Zo[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=(vr.get(p)||0)+1,y=(s.get(p)||0)+1;vr.set(p,m),s.set(p,y),i.push(p),m===1&&x&&Jo.set(p,!0),y===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(),zi++,function(){i.forEach(function(f){var p=vr.get(f)-1,h=s.get(f)-1;vr.set(f,p),s.set(f,h),p||(Jo.has(f)||f.removeAttribute(r),Jo.delete(f)),h||f.removeAttribute(n)}),zi--,zi||(vr=new WeakMap,vr=new WeakMap,Jo=new WeakMap,Zo={})}},Ui=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=cv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),dv(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 fv(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 Qo="right-scroll-bar-position",es="width-before-scroll-bar",pv="with-scroll-bars-hidden",hv="--removed-body-scroll-bar-size";function Hi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function mv(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 gv=typeof window<"u"?v.useLayoutEffect:v.useEffect,gu=new WeakMap;function xv(e,t){var n=mv(null,function(r){return e.forEach(function(o){return Hi(o,r)})});return gv(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)||Hi(a,null)}),s.forEach(function(a){o.has(a)||Hi(a,i)})}gu.set(n,e)},[e]),n}function yv(e){return e}function vv(e,t){t===void 0&&(t=yv);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 bv(e){e===void 0&&(e={});var t=vv(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 v.createElement(r,xn({},n))};xu.isSideCarExport=!0;function wv(e,t){return e.useMedium(t),xu}var yu=bv(),Wi=function(){},ts=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Wi,onWheelCapture:Wi,onTouchMoveCapture:Wi}),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,y=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=xv([n,t]),I=xn(xn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:yu,removeScrollBar:c,shards:f,noRelative:h,noIsolation:x,inert:m,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),xn(xn({},I),{ref:T})):v.createElement(b,xn({},I,{className:l,ref:T}),a))});ts.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ts.classNames={fullWidth:es,zeroRight:Qo};var Sv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Cv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Sv();return t&&e.setAttribute("nonce",t),e}function Tv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function kv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Iv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Cv())&&(Tv(t,n),kv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ev=function(){var e=Iv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},vu=function(){var e=Ev(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Av={left:0,top:0,right:0,gap:0},Vi=function(e){return parseInt(e||"",10)||0},Nv=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[Vi(n),Vi(r),Vi(o)]},_v=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Av;var t=Nv(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])}},jv=vu(),br="data-scroll-locked",Rv=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(pv,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(vr,`] {
43
+ body[`).concat(br,`] {
44
44
  overflow: hidden `).concat(r,`;
45
45
  overscroll-behavior: contain;
46
46
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -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(Jo,` {
56
+ .`).concat(Qo,` {
57
57
  right: `).concat(a,"px ").concat(r,`;
58
58
  }
59
59
 
60
- .`).concat(Zo,` {
60
+ .`).concat(es,` {
61
61
  margin-right: `).concat(a,"px ").concat(r,`;
62
62
  }
63
63
 
64
- .`).concat(Jo," .").concat(Jo,` {
64
+ .`).concat(Qo," .").concat(Qo,` {
65
65
  right: 0 `).concat(r,`;
66
66
  }
67
67
 
68
- .`).concat(Zo," .").concat(Zo,` {
68
+ .`).concat(es," .").concat(es,` {
69
69
  margin-right: 0 `).concat(r,`;
70
70
  }
71
71
 
72
- body[`).concat(vr,`] {
73
- `).concat(dv,": ").concat(a,`px;
72
+ body[`).concat(br,`] {
73
+ `).concat(hv,": ").concat(a,`px;
74
74
  }
75
- `)},xu=function(){var e=parseInt(document.body.getAttribute(vr)||"0",10);return isFinite(e)?e:0},_v=function(){v.useEffect(function(){return document.body.setAttribute(vr,(xu()+1).toString()),function(){var e=xu()-1;e<=0?document.body.removeAttribute(vr):document.body.setAttribute(vr,e.toString())}},[])},jv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;_v();var s=v.useMemo(function(){return Ev(o)},[o]);return v.createElement(Av,{styles:Nv(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 br=Hi?{passive:!1}:!1,Rv=function(e){return e.tagName==="TEXTAREA"},yu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Rv(e)&&n[t]==="visible")},Mv=function(e){return yu(e,"overflowY")},Pv=function(e){return yu(e,"overflowX")},vu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=bu(e,r);if(o){var s=wu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ov=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Dv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},bu=function(e,t){return e==="v"?Mv(t):Pv(t)},wu=function(e,t){return e==="v"?Ov(t):Dv(t)},Lv=function(e,t){return e==="h"&&t==="rtl"?-1:1},$v=function(e,t,n,r,o){var s=Lv(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=wu(e,a),x=h[0],m=h[1],y=h[2],g=m-y-s*x;(x||g)&&bu(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]},Su=function(e){return[e.deltaX,e.deltaY]},Cu=function(e){return e&&"current"in e?e.current:e},Fv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Bv=function(e){return`
75
+ `)},bu=function(){var e=parseInt(document.body.getAttribute(br)||"0",10);return isFinite(e)?e:0},Mv=function(){v.useEffect(function(){return document.body.setAttribute(br,(bu()+1).toString()),function(){var e=bu()-1;e<=0?document.body.removeAttribute(br):document.body.setAttribute(br,e.toString())}},[])},Pv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Mv();var s=v.useMemo(function(){return _v(o)},[o]);return v.createElement(jv,{styles:Rv(s,!t,o,n?"":"!important")})},Ki=!1;if(typeof window<"u")try{var ns=Object.defineProperty({},"passive",{get:function(){return Ki=!0,!0}});window.addEventListener("test",ns,ns),window.removeEventListener("test",ns,ns)}catch{Ki=!1}var wr=Ki?{passive:!1}:!1,Ov=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&&!Ov(e)&&n[t]==="visible")},Dv=function(e){return wu(e,"overflowY")},Lv=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},$v=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Fv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Cu=function(e,t){return e==="v"?Dv(t):Lv(t)},Tu=function(e,t){return e==="v"?$v(t):Fv(t)},Bv=function(e,t){return e==="h"&&t==="rtl"?-1:1},zv=function(e,t,n,r,o){var s=Bv(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],y=h[2],g=m-y-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},rs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ku=function(e){return[e.deltaX,e.deltaY]},Iu=function(e){return e&&"current"in e?e.current:e},Uv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Hv=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},zv=0,wr=[];function Uv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(zv++)[0],s=v.useState(gu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=cv([e.lockRef.current],(e.shards||[]).map(Cu),!0).filter(Boolean);return m.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(m,y){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,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&I==="h"&&T.type==="range")return!1;var A=vu(I,T);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=vu(I,T)),!A)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var R=r.current||C;return $v(R,y,m,R==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!wr.length||wr[wr.length-1]!==s)){var g="deltaY"in y?Su(y):ts(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&Fv(C.delta,g)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Cu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(m,y,g,b){var S={name:m,delta:y,target:g,should:b,shadowParent:Hv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(m){n.current=ts(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,Su(m),m.target,a(m,e.lockRef.current))},[]),p=v.useCallback(function(m){c(m.type,ts(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,br),document.addEventListener("touchmove",l,br),document.addEventListener("touchstart",d,br),function(){wr=wr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,br),document.removeEventListener("touchmove",l,br),document.removeEventListener("touchstart",d,br)}},[]);var h=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:Bv(o)}):null,h?v.createElement(jv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Hv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Wv=yv(mu,Uv);var ns=v.forwardRef(function(e,t){return v.createElement(Qo,mn({},e,{ref:t,sideCar:Wv}))});ns.classNames=Qo.classNames;var Wi=["Enter"," "],Vv=["ArrowDown","PageUp","Home"],Tu=["ArrowUp","PageDown","End"],Kv=[...Vv,...Tu],qv={ltr:[...Wi,"ArrowRight"],rtl:[...Wi,"ArrowLeft"]},Gv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},zr="Menu",[Ur,Yv,Xv]=xi(zr),[Gn,ku]=Sn(zr,[Xv,Ko,iu]),rs=Ko(),Iu=iu(),[Jv,Yn]=Gn(zr),[Zv,Hr]=Gn(zr),Eu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=rs(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),p=Mo(o);return v.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(tu,{...a,children:u.jsx(Jv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Zv,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Eu.displayName=zr;var Qv="MenuAnchor",Vi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(nu,{...o,...r,ref:t})});Vi.displayName=Qv;var Ki="MenuPortal",[eb,Au]=Gn(Ki,{forceMount:void 0}),Nu=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Yn(Ki,t);return u.jsx(eb,{scope:t,forceMount:n,children:u.jsx(Yt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:r})})})};Nu.displayName=Ki;var Xt="MenuContent",[tb,qi]=Gn(Xt),_u=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(nb,{...o,ref:t}):u.jsx(rb,{...o,ref:t})})})})}),nb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx(Gi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),rb=v.forwardRef((e,t)=>{const n=Yn(Xt,e.__scopeMenu);return u.jsx(Gi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ob=Hn.createSlot("MenuContent.ScrollLock"),Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:x,...m}=e,y=Yn(Xt,n),g=Hr(Xt,n),b=rs(n),S=Iu(n),k=Yv(n),[C,T]=v.useState(null),I=v.useRef(null),A=Be(t,I,y.onContentChange),R=v.useRef(0),$=v.useRef(""),P=v.useRef(0),O=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=x?ns:v.Fragment,M=x?{as:ob,allowPinchZoom:!0}:void 0,Q=_=>{var X,L;const V=$.current+_,Y=k().filter(K=>!K.disabled),oe=document.activeElement,ye=(X=Y.find(K=>K.ref.current===oe))==null?void 0:X.textValue,Me=Y.map(K=>K.textValue),G=gb(Me,V,ye),U=(L=Y.find(K=>K.textValue===G))==null?void 0:L.ref.current;(function K(Z){$.current=Z,window.clearTimeout(R.current),Z!==""&&(R.current=window.setTimeout(()=>K(""),1e3))})(V),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(R.current),[]),bi();const z=v.useCallback(_=>{var Y,oe;return F.current===((Y=O.current)==null?void 0:Y.side)&&yb(_,(oe=O.current)==null?void 0:oe.area)},[]);return u.jsx(tb,{scope:n,searchRef:$,onItemEnter:v.useCallback(_=>{z(_)&&_.preventDefault()},[z]),onItemLeave:v.useCallback(_=>{var V;z(_)||((V=I.current)==null||V.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(_=>{z(_)&&_.preventDefault()},[z]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(_=>{O.current=_},[]),children:u.jsx(B,{...M,children:u.jsx(Oo,{asChild:!0,trapped:o,onMountAutoFocus:de(s,_=>{var V;_.preventDefault(),(V=I.current)==null||V.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(ov,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:de(l,_=>{g.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ru,{role:"menu","aria-orientation":"vertical","data-state":qu(y.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:A,style:{outline:"none",...m.style},onKeyDown:de(m.onKeyDown,_=>{const Y=_.target.closest("[data-radix-menu-content]")===_.currentTarget,oe=_.ctrlKey||_.altKey||_.metaKey,ye=_.key.length===1;Y&&(_.key==="Tab"&&_.preventDefault(),!oe&&ye&&Q(_.key));const Me=I.current;if(_.target!==Me||!Kv.includes(_.key))return;_.preventDefault();const U=k().filter(X=>!X.disabled).map(X=>X.ref.current);Tu.includes(_.key)&&U.reverse(),hb(U)}),onBlur:de(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(R.current),$.current="")}),onPointerMove:de(e.onPointerMove,Vr(_=>{const V=_.target,Y=N.current!==_.clientX;if(_.currentTarget.contains(V)&&Y){const oe=_.clientX>N.current?"right":"left";F.current=oe,N.current=_.clientX}}))})})})})})})});_u.displayName=Xt;var sb="MenuGroup",Yi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ee.div,{role:"group",...r,ref:t})});Yi.displayName=sb;var ib="MenuLabel",ju=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ee.div,{...r,ref:t})});ju.displayName=ib;var os="MenuItem",Ru="menu.itemSelect",ss=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Hr(os,e.__scopeMenu),a=qi(os,e.__scopeMenu),l=Be(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Ru,{bubbles:!0,cancelable:!0});f.addEventListener(Ru,h=>r==null?void 0:r(h),{once:!0}),dc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Mu,{...o,ref:l,disabled:n,onClick:de(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:de(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:de(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||Wi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ss.displayName=os;var Mu=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=qi(os,n),a=Iu(n),l=v.useRef(null),c=Be(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const x=l.current;x&&h((x.textContent??"").trim())},[s.children]),u.jsx(Ur.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(sv,{asChild:!0,...a,focusable:!r,children:u.jsx(Ee.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:de(e.onPointerMove,Vr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,Vr(x=>i.onItemLeave(x))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(e.onBlur,()=>f(!1))})})})}),ab="MenuCheckboxItem",Pu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Fu,{scope:e.__scopeMenu,checked:n,children:u.jsx(ss,{role:"menuitemcheckbox","aria-checked":is(n)?"mixed":n,...o,ref:t,"data-state":Ji(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(is(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Pu.displayName=ab;var Ou="MenuRadioGroup",[lb,cb]=Gn(Ou,{value:void 0,onValueChange:()=>{}}),Du=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(lb,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Yi,{...o,ref:t})})});Du.displayName=Ou;var Lu="MenuRadioItem",$u=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=cb(Lu,e.__scopeMenu),s=n===o.value;return u.jsx(Fu,{scope:e.__scopeMenu,checked:s,children:u.jsx(ss,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ji(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});$u.displayName=Lu;var Xi="MenuItemIndicator",[Fu,ub]=Gn(Xi,{checked:!1}),Bu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=ub(Xi,n);return u.jsx(Yt,{present:r||is(s.checked)||s.checked===!0,children:u.jsx(Ee.span,{...o,ref:t,"data-state":Ji(s.checked)})})});Bu.displayName=Xi;var db="MenuSeparator",zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ee.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});zu.displayName=db;var fb="MenuArrow",Uu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=rs(n);return u.jsx(ou,{...o,...r,ref:t})});Uu.displayName=fb;var pb="MenuSub",[PT,Hu]=Gn(pb),Wr="MenuSubTrigger",Wu=v.forwardRef((e,t)=>{const n=Yn(Wr,e.__scopeMenu),r=Hr(Wr,e.__scopeMenu),o=Hu(Wr,e.__scopeMenu),s=qi(Wr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Vi,{asChild:!0,...c,children:u.jsx(Mu,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":qu(n.open),...e,ref:gi(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:de(e.onPointerMove,Vr(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:de(e.onPointerLeave,Vr(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,y=m==="right",g=y?-5:5,b=p[y?"left":"right"],S=p[y?"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:de(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())})})})});Wu.displayName=Wr;var Vu="MenuSubContent",Ku=v.forwardRef((e,t)=>{const n=Au(Xt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Yn(Xt,e.__scopeMenu),i=Hr(Xt,e.__scopeMenu),a=Hu(Vu,e.__scopeMenu),l=v.useRef(null),c=Be(t,l);return u.jsx(Ur.Provider,{scope:e.__scopeMenu,children:u.jsx(Yt,{present:r||s.open,children:u.jsx(Ur.Slot,{scope:e.__scopeMenu,children:u.jsx(Gi,{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:de(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:de(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:de(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=Gv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Ku.displayName=Vu;function qu(e){return e?"open":"closed"}function is(e){return e==="indeterminate"}function Ji(e){return is(e)?"indeterminate":e?"checked":"unchecked"}function hb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function mb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function gb(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=mb(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 xb(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 yb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return xb(n,t)}function Vr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var vb=Eu,bb=Vi,wb=Nu,Sb=_u,Cb=Yi,Tb=ju,kb=ss,Ib=Pu,Eb=Du,Ab=$u,Nb=Bu,_b=zu,jb=Uu,Rb=Wu,Mb=Ku,as="DropdownMenu",[Pb,OT]=Sn(as,[ku]),Ot=ku(),[Ob,Gu]=Pb(as),Yu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),c=v.useRef(null),[d,f]=pr({prop:o,defaultProp:s??!1,onChange:i,caller:as});return u.jsx(Ob,{scope:t,triggerId:Cn(),triggerRef:c,contentId:Cn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(vb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Yu.displayName=as;var Xu="DropdownMenuTrigger",Ju=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Gu(Xu,n),i=Ot(n);return u.jsx(bb,{asChild:!0,...i,children:u.jsx(Ee.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:gi(t,s.triggerRef),onPointerDown:de(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:de(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ju.displayName=Xu;var Db="DropdownMenuPortal",Zu=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return u.jsx(wb,{...r,...n})};Zu.displayName=Db;var Qu="DropdownMenuContent",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Gu(Qu,n),s=Ot(n),i=v.useRef(!1);return u.jsx(Sb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:de(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:de(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)"}})});ed.displayName=Qu;var Lb="DropdownMenuGroup",$b=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Cb,{...o,...r,ref:t})});$b.displayName=Lb;var Fb="DropdownMenuLabel",td=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Tb,{...o,...r,ref:t})});td.displayName=Fb;var Bb="DropdownMenuItem",nd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(kb,{...o,...r,ref:t})});nd.displayName=Bb;var zb="DropdownMenuCheckboxItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ib,{...o,...r,ref:t})});rd.displayName=zb;var Ub="DropdownMenuRadioGroup",Hb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Eb,{...o,...r,ref:t})});Hb.displayName=Ub;var Wb="DropdownMenuRadioItem",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ab,{...o,...r,ref:t})});od.displayName=Wb;var Vb="DropdownMenuItemIndicator",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Nb,{...o,...r,ref:t})});sd.displayName=Vb;var Kb="DropdownMenuSeparator",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(_b,{...o,...r,ref:t})});id.displayName=Kb;var qb="DropdownMenuArrow",Gb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(jb,{...o,...r,ref:t})});Gb.displayName=qb;var Yb="DropdownMenuSubTrigger",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Rb,{...o,...r,ref:t})});ad.displayName=Yb;var Xb="DropdownMenuSubContent",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Mb,{...o,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ld.displayName=Xb;var Jb=Yu,Zb=Ju,Qb=Zu,cd=ed,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld;const ew=Jb,tw=Zb,nw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(gd,{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(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));nw.displayName=gd.displayName;const rw=v.forwardRef(({className:e,...t},n)=>u.jsx(xd,{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}));rw.displayName=xd.displayName;const yd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Qb,{children:u.jsx(cd,{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})}));yd.displayName=cd.displayName;const Zi=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{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}));Zi.displayName=dd.displayName;const ow=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(fd,{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(hd,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));ow.displayName=fd.displayName;const sw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pd,{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(hd,{children:u.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));sw.displayName=pd.displayName;const iw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));iw.displayName=ud.displayName;const aw=v.forwardRef(({className:e,...t},n)=>u.jsx(md,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));aw.displayName=md.displayName;function lw(e){const t=new Map;console.log("[attemptDetection] groupCheckpointsByLastUserMessageId processing",e.length,"checkpoints");for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s),s.length===1?console.log(`[attemptDetection] New user message group: "${o.id}" checkpoint ${n.checkpointId}`):console.log(`[attemptDetection] Adding to existing group: "${o.id}" now has ${s.length} checkpoints`)}else console.log(`[attemptDetection] Checkpoint ${n.checkpointId} has no user messages`)}return console.log("[attemptDetection] Final grouping:",{totalGroups:t.size,groupSizes:Array.from(t.entries()).map(([n,r])=>({userMessageId:n,count:r.length}))}),t}function cw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=lw(e);console.log("[attemptDetection] Grouped into",n.size,"unique user message IDs");for(const[r,o]of n.entries())o.length>1&&console.log(`[attemptDetection] User message "${r}" found in ${o.length} checkpoints (EDITS DETECTED)`,{checkpointIds:o.map(s=>s.checkpointId),createdAts:o.map(s=>s.createdAt)});for(const[r,o]of n.entries())if(o.length===1){const s=o[0];s.checkpointId&&t.set(s.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:r})}else{const s=[...o].sort((i,a)=>Date.parse(a.createdAt??"0")-Date.parse(i.createdAt??"0"));console.log(`[attemptDetection] Sorted ${s.length} versions for user message "${r}":`,{versionOrder:s.map((i,a)=>`v${a}: ${i.checkpointId} (${i.createdAt})`)}),s.forEach((i,a)=>{i.checkpointId&&t.set(i.checkpointId,{attemptIndex:a,attemptCount:s.length,isLatestAttempt:a===s.length-1,baseUserMessageId:r})})}return console.log("[attemptDetection] Final versionMetadata:",{totalCheckpoints:t.size,editedMessages:Array.from(t.entries()).filter(([r,o])=>o.attemptCount>1).map(([r,o])=>({checkpointId:r,attemptIndex:o.attemptIndex,attemptCount:o.attemptCount,isLatestAttempt:o.isLatestAttempt}))}),t}function uw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function ls(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function dw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function fw(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 pw(e){const t=Array.isArray(e)?e.map(r=>{const o=fw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>ls(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ls(r.metadata,"step"),i=ls(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function hw(e){const t=w.useMemo(()=>pw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const p=f.checkpointId??null;if(!p)continue;const h=ls(f.metadata,"step"),x=dw(f.metadata,"source"),m={id:p,step:h,source:x,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,m),h!==null&&x){const y=`${h}:${x}`,g=a.get(y)??[];g.push(m),a.set(y,g)}}console.log("[useCheckpointMetadata] Building attempt metadata for",t.length,"checkpoints");const c=cw(t);for(const[f,p]of i.entries()){const h=c.get(f);h?l.set(f,{...p,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount,isLatestAttempt:h.isLatestAttempt,baseUserMessageId:h.baseUserMessageId??null}):l.set(f,{...p,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}console.log("[useCheckpointMetadata] Final attemptMetaById:",{totalCheckpoints:l.size,withMultipleAttempts:Array.from(l.values()).filter(f=>f.attemptCount>1).length,samples:Array.from(l.entries()).slice(0,3).map(([f,p])=>({checkpointId:f,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount}))});const d=uw(l);return console.log("[useCheckpointMetadata] userMessageIdToAttempts map built with",d.size,"user message IDs with multiple attempts"),{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const cs=1e4;function mw(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
+ `)},Wv=0,Sr=[];function Vv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(Wv++)[0],s=v.useState(vu)[0],i=v.useRef(e);v.useEffect(function(){i.current=e},[e]),v.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=fv([e.lockRef.current],(e.shards||[]).map(Iu),!0).filter(Boolean);return m.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(m,y){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var g=rs(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,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&I==="h"&&T.type==="range")return!1;var A=Su(I,T);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=Su(I,T)),!A)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var M=r.current||C;return zv(M,y,m,M==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!Sr.length||Sr[Sr.length-1]!==s)){var g="deltaY"in y?ku(y):rs(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&Uv(C.delta,g)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Iu).filter(Boolean).filter(function(C){return C.contains(y.target)}),k=S.length>0?a(y,S[0]):!i.current.noIsolation;k&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(m,y,g,b){var S={name:m,delta:y,target:g,should:b,shadowParent:Kv(g)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(k){return k!==S})},1)},[]),d=v.useCallback(function(m){n.current=rs(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,ku(m),m.target,a(m,e.lockRef.current))},[]),p=v.useCallback(function(m){c(m.type,rs(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return Sr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,wr),document.addEventListener("touchmove",l,wr),document.addEventListener("touchstart",d,wr),function(){Sr=Sr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,wr),document.removeEventListener("touchmove",l,wr),document.removeEventListener("touchstart",d,wr)}},[]);var h=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:Hv(o)}):null,h?v.createElement(Pv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Kv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const qv=wv(yu,Vv);var os=v.forwardRef(function(e,t){return v.createElement(ts,xn({},e,{ref:t,sideCar:qv}))});os.classNames=ts.classNames;var qi=["Enter"," "],Gv=["ArrowDown","PageUp","Home"],Eu=["ArrowUp","PageDown","End"],Yv=[...Gv,...Eu],Xv={ltr:[...qi,"ArrowRight"],rtl:[...qi,"ArrowLeft"]},Jv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Wr="Menu",[Vr,Zv,Qv]=bi(Wr),[Jn,Au]=kn(Wr,[Qv,Go,cu]),ss=Go(),Nu=cu(),[eb,Zn]=Jn(Wr),[tb,Kr]=Jn(Wr),_u=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ss(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),p=Oo(o);return v.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(eb,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(tb,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};_u.displayName=Wr;var nb="MenuAnchor",Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ss(n);return u.jsx(su,{...o,...r,ref:t})});Gi.displayName=nb;var Yi="MenuPortal",[rb,ju]=Jn(Yi,{forceMount:void 0}),Ru=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Zn(Yi,t);return u.jsx(rb,{scope:t,forceMount:n,children:u.jsx(Xt,{present:n||s.open,children:u.jsx(Yo,{asChild:!0,container:o,children:r})})})};Ru.displayName=Yi;var Jt="MenuContent",[ob,Xi]=Jn(Jt),Mu=v.forwardRef((e,t)=>{const n=ju(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Zn(Jt,e.__scopeMenu),i=Kr(Jt,e.__scopeMenu);return u.jsx(Vr.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Vr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(sb,{...o,ref:t}):u.jsx(ib,{...o,ref:t})})})})}),sb=v.forwardRef((e,t)=>{const n=Zn(Jt,e.__scopeMenu),r=v.useRef(null),o=Fe(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Ui(s)},[]),u.jsx(Ji,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ib=v.forwardRef((e,t)=>{const n=Zn(Jt,e.__scopeMenu);return u.jsx(Ji,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ab=Kn.createSlot("MenuContent.ScrollLock"),Ji=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,disableOutsideScroll:x,...m}=e,y=Zn(Jt,n),g=Kr(Jt,n),b=ss(n),S=Nu(n),k=Zv(n),[C,T]=v.useState(null),I=v.useRef(null),A=Fe(t,I,y.onContentChange),M=v.useRef(0),L=v.useRef(""),P=v.useRef(0),D=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=x?os:v.Fragment,j=x?{as:ab,allowPinchZoom:!0}:void 0,V=R=>{var Z,$;const K=L.current+R,J=k().filter(q=>!q.disabled),se=document.activeElement,ge=(Z=J.find(q=>q.ref.current===se))==null?void 0:Z.textValue,Ie=J.map(q=>q.textValue),Y=vb(Ie,K,ge),U=($=J.find(q=>q.textValue===Y))==null?void 0:$.ref.current;(function q(Q){L.current=Q,window.clearTimeout(M.current),Q!==""&&(M.current=window.setTimeout(()=>q(""),1e3))})(K),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(M.current),[]),Ci();const z=v.useCallback(R=>{var J,se;return F.current===((J=D.current)==null?void 0:J.side)&&wb(R,(se=D.current)==null?void 0:se.area)},[]);return u.jsx(ob,{scope:n,searchRef:L,onItemEnter:v.useCallback(R=>{z(R)&&R.preventDefault()},[z]),onItemLeave:v.useCallback(R=>{var K;z(R)||((K=I.current)==null||K.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(R=>{z(R)&&R.preventDefault()},[z]),pointerGraceTimerRef:P,onPointerGraceIntentChange:v.useCallback(R=>{D.current=R},[]),children:u.jsx(B,{...j,children:u.jsx(Lo,{asChild:!0,trapped:o,onMountAutoFocus:fe(s,R=>{var K;R.preventDefault(),(K=I.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Do,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(av,{asChild:!0,...S,dir:g.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:fe(l,R=>{g.isUsingKeyboardRef.current||R.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(iu,{role:"menu","aria-orientation":"vertical","data-state":Xu(y.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:A,style:{outline:"none",...m.style},onKeyDown:fe(m.onKeyDown,R=>{const J=R.target.closest("[data-radix-menu-content]")===R.currentTarget,se=R.ctrlKey||R.altKey||R.metaKey,ge=R.key.length===1;J&&(R.key==="Tab"&&R.preventDefault(),!se&&ge&&V(R.key));const Ie=I.current;if(R.target!==Ie||!Yv.includes(R.key))return;R.preventDefault();const U=k().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);Eu.includes(R.key)&&U.reverse(),xb(U)}),onBlur:fe(e.onBlur,R=>{R.currentTarget.contains(R.target)||(window.clearTimeout(M.current),L.current="")}),onPointerMove:fe(e.onPointerMove,Gr(R=>{const K=R.target,J=N.current!==R.clientX;if(R.currentTarget.contains(K)&&J){const se=R.clientX>N.current?"right":"left";F.current=se,N.current=R.clientX}}))})})})})})})});Mu.displayName=Jt;var lb="MenuGroup",Zi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});Zi.displayName=lb;var cb="MenuLabel",Pu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});Pu.displayName=cb;var is="MenuItem",Ou="menu.itemSelect",as=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Kr(is,e.__scopeMenu),a=Xi(is,e.__scopeMenu),l=Fe(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(Ou,{bubbles:!0,cancelable:!0});f.addEventListener(Ou,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:fe(e.onClick,d),onPointerDown:f=>{var p;(p=e.onPointerDown)==null||p.call(e,f),c.current=!0},onPointerUp:fe(e.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:fe(e.onKeyDown,f=>{const p=a.searchRef.current!=="";n||p&&f.key===" "||qi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});as.displayName=is;var Du=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Xi(is,n),a=Nu(n),l=v.useRef(null),c=Fe(t,l),[d,f]=v.useState(!1),[p,h]=v.useState("");return v.useEffect(()=>{const x=l.current;x&&h((x.textContent??"").trim())},[s.children]),u.jsx(Vr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(lv,{asChild:!0,...a,focusable:!r,children:u.jsx(Ne.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:fe(e.onPointerMove,Gr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:fe(e.onPointerLeave,Gr(x=>i.onItemLeave(x))),onFocus:fe(e.onFocus,()=>f(!0)),onBlur:fe(e.onBlur,()=>f(!1))})})})}),ub="MenuCheckboxItem",Lu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(Uu,{scope:e.__scopeMenu,checked:n,children:u.jsx(as,{role:"menuitemcheckbox","aria-checked":ls(n)?"mixed":n,...o,ref:t,"data-state":ea(n),onSelect:fe(o.onSelect,()=>r==null?void 0:r(ls(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Lu.displayName=ub;var $u="MenuRadioGroup",[db,fb]=Jn($u,{value:void 0,onValueChange:()=>{}}),Fu=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(db,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Zi,{...o,ref:t})})});Fu.displayName=$u;var Bu="MenuRadioItem",zu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=fb(Bu,e.__scopeMenu),s=n===o.value;return u.jsx(Uu,{scope:e.__scopeMenu,checked:s,children:u.jsx(as,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":ea(s),onSelect:fe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});zu.displayName=Bu;var Qi="MenuItemIndicator",[Uu,pb]=Jn(Qi,{checked:!1}),Hu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=pb(Qi,n);return u.jsx(Xt,{present:r||ls(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":ea(s.checked)})})});Hu.displayName=Qi;var hb="MenuSeparator",Wu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Wu.displayName=hb;var mb="MenuArrow",Vu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ss(n);return u.jsx(au,{...o,...r,ref:t})});Vu.displayName=mb;var gb="MenuSub",[DT,Ku]=Jn(gb),qr="MenuSubTrigger",qu=v.forwardRef((e,t)=>{const n=Zn(qr,e.__scopeMenu),r=Kr(qr,e.__scopeMenu),o=Ku(qr,e.__scopeMenu),s=Xi(qr,e.__scopeMenu),i=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=v.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return v.useEffect(()=>d,[d]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),u.jsx(Gi,{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:vi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:fe(e.onPointerMove,Gr(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:fe(e.onPointerLeave,Gr(f=>{var 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,y=m==="right",g=y?-5:5,b=p[y?"left":"right"],S=p[y?"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:fe(e.onKeyDown,f=>{var h;const p=s.searchRef.current!=="";e.disabled||p&&f.key===" "||Xv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});qu.displayName=qr;var Gu="MenuSubContent",Yu=v.forwardRef((e,t)=>{const n=ju(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Zn(Jt,e.__scopeMenu),i=Kr(Jt,e.__scopeMenu),a=Ku(Gu,e.__scopeMenu),l=v.useRef(null),c=Fe(t,l);return u.jsx(Vr.Provider,{scope:e.__scopeMenu,children:u.jsx(Xt,{present:r||s.open,children:u.jsx(Vr.Slot,{scope:e.__scopeMenu,children:u.jsx(Ji,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:fe(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:fe(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:fe(e.onKeyDown,d=>{var h;const f=d.currentTarget.contains(d.target),p=Jv[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 ls(e){return e==="indeterminate"}function ea(e){return ls(e)?"indeterminate":e?"checked":"unchecked"}function xb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function yb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function vb(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=yb(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 bb(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 wb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return bb(n,t)}function Gr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Sb=_u,Cb=Gi,Tb=Ru,kb=Mu,Ib=Zi,Eb=Pu,Ab=as,Nb=Lu,_b=Fu,jb=zu,Rb=Hu,Mb=Wu,Pb=Vu,Ob=qu,Db=Yu,cs="DropdownMenu",[Lb,LT]=kn(cs,[Au]),Dt=Au(),[$b,Ju]=Lb(cs),Zu=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Dt(t),c=v.useRef(null),[d,f]=hr({prop:o,defaultProp:s??!1,onChange:i,caller:cs});return u.jsx($b,{scope:t,triggerId:In(),triggerRef:c,contentId:In(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(Sb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Zu.displayName=cs;var Qu="DropdownMenuTrigger",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ju(Qu,n),i=Dt(n);return u.jsx(Cb,{asChild:!0,...i,children:u.jsx(Ne.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:vi(t,s.triggerRef),onPointerDown:fe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:fe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});ed.displayName=Qu;var Fb="DropdownMenuPortal",td=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Dt(t);return u.jsx(Tb,{...r,...n})};td.displayName=Fb;var nd="DropdownMenuContent",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ju(nd,n),s=Dt(n),i=v.useRef(!1);return u.jsx(kb,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:fe(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:fe(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});rd.displayName=nd;var Bb="DropdownMenuGroup",zb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Ib,{...o,...r,ref:t})});zb.displayName=Bb;var Ub="DropdownMenuLabel",od=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Eb,{...o,...r,ref:t})});od.displayName=Ub;var Hb="DropdownMenuItem",sd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Ab,{...o,...r,ref:t})});sd.displayName=Hb;var Wb="DropdownMenuCheckboxItem",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Nb,{...o,...r,ref:t})});id.displayName=Wb;var Vb="DropdownMenuRadioGroup",Kb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(_b,{...o,...r,ref:t})});Kb.displayName=Vb;var qb="DropdownMenuRadioItem",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(jb,{...o,...r,ref:t})});ad.displayName=qb;var Gb="DropdownMenuItemIndicator",ld=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Rb,{...o,...r,ref:t})});ld.displayName=Gb;var Yb="DropdownMenuSeparator",cd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Mb,{...o,...r,ref:t})});cd.displayName=Yb;var Xb="DropdownMenuArrow",Jb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Pb,{...o,...r,ref:t})});Jb.displayName=Xb;var Zb="DropdownMenuSubTrigger",ud=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Ob,{...o,...r,ref:t})});ud.displayName=Zb;var Qb="DropdownMenuSubContent",dd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return u.jsx(Db,{...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=Qb;var ew=Zu,tw=ed,nw=td,fd=rd,pd=od,hd=sd,md=id,gd=ad,xd=ld,yd=cd,vd=ud,bd=dd;const rw=ew,ow=tw,sw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(vd,{ref:o,className:ne("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(ae.ChevronRight,{className:"ml-auto h-4 w-4"})]}));sw.displayName=vd.displayName;const iw=v.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:ne("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));iw.displayName=bd.displayName;const wd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(nw,{children:u.jsx(fd,{ref:r,sideOffset:t,className:ne("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));wd.displayName=fd.displayName;const ta=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(hd,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));ta.displayName=hd.displayName;const aw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(md,{ref:o,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[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(ae.Check,{className:"h-4 w-4"})})}),t]}));aw.displayName=md.displayName;const lw=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gd,{ref:r,className:ne("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[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(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));lw.displayName=gd.displayName;const cw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(pd,{ref:r,className:ne("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));cw.displayName=pd.displayName;const uw=v.forwardRef(({className:e,...t},n)=>u.jsx(yd,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));uw.displayName=yd.displayName;function dw(e){const t=new Map;console.log("[attemptDetection] groupCheckpointsByLastUserMessageId processing",e.length,"checkpoints");for(const n of e){const o=[...n.messages??[]].reverse().find(s=>s.role==="user");if(o!=null&&o.id){const s=t.get(o.id)??[];s.push(n),t.set(o.id,s),s.length===1?console.log(`[attemptDetection] New user message group: "${o.id}" checkpoint ${n.checkpointId}`):console.log(`[attemptDetection] Adding to existing group: "${o.id}" now has ${s.length} checkpoints`)}else console.log(`[attemptDetection] Checkpoint ${n.checkpointId} has no user messages`)}return console.log("[attemptDetection] Final grouping:",{totalGroups:t.size,groupSizes:Array.from(t.entries()).map(([n,r])=>({userMessageId:n,count:r.length}))}),t}function fw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=dw(e);console.log("[attemptDetection] Grouped into",n.size,"unique user message IDs");for(const[r,o]of n.entries())o.length>1&&console.log(`[attemptDetection] User message "${r}" found in ${o.length} checkpoints (EDITS DETECTED)`,{checkpointIds:o.map(s=>s.checkpointId),createdAts:o.map(s=>s.createdAt)});for(const[r,o]of n.entries())if(o.length===1){const s=o[0];s.checkpointId&&t.set(s.checkpointId,{attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:r})}else{const s=[...o].sort((i,a)=>Date.parse(a.createdAt??"0")-Date.parse(i.createdAt??"0"));console.log(`[attemptDetection] Sorted ${s.length} versions for user message "${r}":`,{versionOrder:s.map((i,a)=>`v${a}: ${i.checkpointId} (${i.createdAt})`)}),s.forEach((i,a)=>{i.checkpointId&&t.set(i.checkpointId,{attemptIndex:a,attemptCount:s.length,isLatestAttempt:a===s.length-1,baseUserMessageId:r})})}return console.log("[attemptDetection] Final versionMetadata:",{totalCheckpoints:t.size,editedMessages:Array.from(t.entries()).filter(([r,o])=>o.attemptCount>1).map(([r,o])=>({checkpointId:r,attemptIndex:o.attemptIndex,attemptCount:o.attemptCount,isLatestAttempt:o.isLatestAttempt}))}),t}function pw(e){const t=new Map;for(const[n,r]of e.entries())if(r.baseUserMessageId&&r.attemptCount>1){const o=t.get(r.baseUserMessageId)??[];o.push({checkpointId:n,attemptIndex:r.attemptIndex,attemptCount:r.attemptCount,isLatestAttempt:r.isLatestAttempt}),t.set(r.baseUserMessageId,o)}return t}function us(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function hw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function mw(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 gw(e){const t=Array.isArray(e)?e.map(r=>{const o=mw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>us(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=us(r.metadata,"step"),i=us(o.metadata,"step");if(s!==null||i!==null)return(i??Number.NEGATIVE_INFINITY)-(s??Number.NEGATIVE_INFINITY);const a=Date.parse(r.createdAt??""),l=Date.parse(o.createdAt??"");return Number.isNaN(a)||Number.isNaN(l)?0:l-a}),t}function xw(e){const t=w.useMemo(()=>gw(e),[e]),{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}=w.useMemo(()=>{const i=new Map,a=new Map,l=new Map;for(const f of t){const p=f.checkpointId??null;if(!p)continue;const h=us(f.metadata,"step"),x=hw(f.metadata,"source"),m={id:p,step:h,source:x,createdAt:f.createdAt??null,namespace:f.checkpointNs??null,parentId:f.parentId??null};if(i.set(p,m),h!==null&&x){const y=`${h}:${x}`,g=a.get(y)??[];g.push(m),a.set(y,g)}}console.log("[useCheckpointMetadata] Building attempt metadata for",t.length,"checkpoints");const c=fw(t);for(const[f,p]of i.entries()){const h=c.get(f);h?l.set(f,{...p,attemptIndex:h.attemptIndex,attemptCount:h.attemptCount,isLatestAttempt:h.isLatestAttempt,baseUserMessageId:h.baseUserMessageId??null}):l.set(f,{...p,attemptIndex:0,attemptCount:1,isLatestAttempt:!0,baseUserMessageId:null})}console.log("[useCheckpointMetadata] Final attemptMetaById:",{totalCheckpoints:l.size,withMultipleAttempts:Array.from(l.values()).filter(f=>f.attemptCount>1).length,samples:Array.from(l.entries()).slice(0,3).map(([f,p])=>({checkpointId:f,attemptIndex:p.attemptIndex,attemptCount:p.attemptCount}))});const d=pw(l);return console.log("[useCheckpointMetadata] userMessageIdToAttempts map built with",d.size,"user message IDs with multiple attempts"),{checkpointMetaById:i,checkpointIndexByKey:a,attemptMetaById:l,userMessageIdToAttempts:d}},[t]);return{checkpointMetaById:n,checkpointIndexByKey:r,attemptMetaById:o,userMessageIdToAttempts:s}}const ds=1e4;function yw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
79
79
  `).replace(/<p>(.*?)<\/p>/gi,`$1
80
80
 
81
81
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
@@ -83,25 +83,25 @@ React keys must be passed directly to JSX without using spread:
83
83
  `).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
84
84
  `).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
85
85
  `).replace(/<li>(.*?)<\/li>/gi,`- $1
86
- `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function gw(e,t=cs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function xw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),gw(t),mw(t)}const us=0,Rn=1,Sr=2,vd=4;function bd(e){return()=>e}function yw(e){e()}function wd(e,t){return n=>e(t(n))}function Sd(e,t){return()=>e(t)}function vw(e,t){return n=>e(t,n)}function Qi(e){return e!==void 0}function bw(...e){return()=>{e.map(yw)}}function Cr(){}function ds(e,t){return t(e),e}function ww(e,t){return t(e)}function ct(...e){return e}function et(e,t){return e(Rn,t)}function Re(e,t){e(us,t)}function ea(e){e(Sr)}function vt(e){return e(vd)}function he(e,t){return et(e,vw(t,us))}function sn(e,t){const n=e(Rn,r=>{n(),t(r)});return n}function Cd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Td(e,t){return e===t}function ut(e=Td){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>wd(t,e)}function gn(e){return t=>()=>{t(e)}}function H(e,...t){const n=Sw(...t);return(r,o)=>{switch(r){case Sr:ea(e);return;case Rn:return et(e,n(o))}}}function xn(e,t){return n=>r=>{n(t=e(t,r))}}function Xn(e){return t=>n=>{e>0?e--:t(n)}}function In(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Oe(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);et(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 Sw(...e){return t=>e.reduceRight(ww,t)}function Cw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Rn:return s?n===s?void 0:(r(),n=s,t=et(e,s),t):(r(),Cr);case Sr:r(),n=null;return}}}function ee(e){let t=e;const n=ze();return(r,o)=>{switch(r){case us:t=o;break;case Rn:{o(t);break}case vd:return t}return n(r,o)}}function Nt(e,t){return ds(ee(t),n=>he(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case us:e.slice().forEach(r=>{r(n)});return;case Sr:e.splice(0,e.length);return;case Rn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return ds(ze(),t=>he(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Tw(),singleton:n}}const Tw=()=>Symbol();function kw(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=ze(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);et(s,l=>{n[i]=l,r=r|a,r===o&&Re(t,n)})}),function(s,i){switch(s){case Sr:{ea(t);return}case Rn:return r===o&&i(n),et(t,i)}}}function Se(e,t=Td){return H(e,ut(t))}function ta(...e){return function(t,n){switch(t){case Sr:return;case Rn:return bw(...e.map(r=>et(r,n)))}}}var Bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Bt||{});const Iw={0:"debug",3:"error",1:"log",2:"warn"},Ew=()=>typeof globalThis>"u"?window:globalThis,Mn=qe(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Ew().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[Iw[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 na(e,t,n).callbackRef}function na(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 Aw(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,y=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:y,scrollTop:Math.max(m,0),viewportHeight:g}),s==null||s(a?kd("column-gap",getComputedStyle(d).columnGap,o):kd("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return na(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},Bt.ERROR),d===c)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function kd(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Id(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}=na(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=qe(()=>{const e=ze(),t=ze(),n=ee(0),r=ze(),o=ee(0),s=ze(),i=ze(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=ze(),p=ze(),h=ee(!1),x=ee(!1),m=ee(!1);return he(H(e,le(({scrollTop:y})=>y)),t),he(H(e,le(({scrollHeight:y})=>y)),i),he(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}),Kr={lvl:0};function Ed(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function st(e){return e===Kr}function qr(e,t){if(!st(e))return t===e.k?e.v:t<e.k?qr(e.l,t):qr(e.r,t)}function an(e,t,n="k"){if(st(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=an(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return an(e.l,t,n)}function Wt(e,t,n){return st(e)?_d(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?jd(Ct(e,{l:Wt(e.l,t,n)})):jd(Ct(e,{r:Wt(e.r,t,n)}))}function Tr(){return Kr}function fs(e,t,n){if(st(e))return[];const r=an(e,t)[0];return _w(oa(e,r,n))}function ra(e,t){if(st(e))return Kr;const{k:n,l:r,r:o}=e;if(t===n){if(st(r))return o;if(st(o))return r;{const[s,i]=Nd(r);return ps(Ct(e,{k:s,l:Ad(r),v:i}))}}else return t<n?ps(Ct(e,{l:ra(r,t)})):ps(Ct(e,{r:ra(o,t)}))}function Zn(e){return st(e)?[]:[...Zn(e.l),{k:e.k,v:e.v},...Zn(e.r)]}function oa(e,t,n){if(st(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(oa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(oa(s,t,n))),a}function ps(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(sa(t))return Rd(Ct(e,{lvl:n-1}));if(!st(t)&&!st(t.r))return Ct(t.r,{l:Ct(t,{r:t.r.l}),lvl:n,r:Ct(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(sa(e))return ia(Ct(e,{lvl:n-1}));if(!st(r)&&!st(r.l)){const o=r.l,s=sa(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ia(Ct(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ct(e,t){return _d(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Ad(e){return st(e.r)?e.l:ps(Ct(e,{r:Ad(e.r)}))}function sa(e){return st(e)||e.lvl>e.r.lvl}function Nd(e){return st(e.r)?[e.k,e.v]:Nd(e.r)}function _d(e,t,n,r=Kr,o=Kr){return{k:e,l:r,lvl:n,r:o,v:t}}function jd(e){return ia(Rd(e))}function Rd(e){const{l:t}=e;return!st(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function ia(e){const{lvl:t,r:n}=e;return!st(n)&&!st(n.r)&&n.lvl===t&&n.r.lvl===t?Ct(n,{l:Ct(e,{r:n.l}),lvl:t+1}):e}function _w(e){return Ed(e,({k:t,v:n})=>({index:t,value:n}))}function Md(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Gr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const aa=qe(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Pd(e,t,n){return e[hs(e,t,n)]}function hs(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function jw(e,t,n,r){const o=hs(e,t,r),s=hs(e,n,r,o);return e.slice(o,s+1)}function Pn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ms(e){return!st(e.groupOffsetTree)}function la({index:e},t){return t===e?0:t<e?-1:1}function Rw(){return{groupIndices:[],groupOffsetTree:Tr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Tr()}}function Mw(e,t){let n=st(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),st(e)){e=Wt(e,0,s);continue}const a=fs(e,i-1,o+1);if(a.some(Bw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ra(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Wt(e,o+1,p));c&&(e=Wt(e,i,s))}return[e,n]}function Pw(e){return typeof e.groupIndex<"u"}function Ow({offset:e},t){return t===e?0:t<e?-1:1}function Yr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Pd(t,e,la),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Od(e,t){if(!ms(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Dd(e,t,n){if(Pw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Od(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Dw(e,t,n,r=0){return r>0&&(t=Math.max(t,Pd(e,r,la).offset)),Ed(jw(e,t,n,Ow),Fw)}function Lw(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Bt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&st(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((x,m)=>Wt(Wt(x,m,p),m+1,h),i)}else[i,a]=Mw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=ca(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Wt(p,h,Yr(h,f,o)),Tr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function $w(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 Ld(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 ca(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=hs(o,t-1,la),a=o[l].offset;const c=an(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===an(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of fs(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Fw(e){return{index:e.index,value:e}}function Bw(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"},yn=qe(([{log:e},{recalcInProgress:t}])=>{const n=ze(),r=ze(),o=Nt(r,0),s=ze(),i=ze(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>Pn(C,zw[T])),p=ee(void 0),h=ee(0),x=Rw(),m=Nt(H(n,Oe(l,e,h),xn(Lw,x),ut()),x),y=Nt(H(l,ut(),xn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);he(H(l,Te(C=>C.length>0),Oe(m,h),le(([C,T,I])=>{const A=C.reduce((R,$,P)=>Wt(R,$,Yr($,T.offsetTree,I)||P),Tr());return{...T,groupIndices:C,groupOffsetTree:A}})),m),he(H(r,Oe(m),Te(([C,{lastIndex:T}])=>C<T),le(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const g=Nt(H(c,le(C=>C===void 0)),!0);he(H(d,Te(C=>C!==void 0&&st(vt(m).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(H(n,Oe(m),xn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:x}),le(C=>C.changed)));et(H(a,xn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Re(t,!0),Re(s,C+Ld(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=Ld(-C,I)),Re(i,C)}}),et(H(a,Oe(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Bt.ERROR)});const S=Ht(s);he(H(s,Oe(m),le(([C,T])=>{const I=T.groupIndices.length>0,A=[],R=T.lastSize;if(I){const $=qr(T.sizeTree,0);let P=0,O=0;for(;P<C;){const N=T.groupIndices[O],B=T.groupIndices.length===O+1?1/0:T.groupIndices[O+1]-N-1;A.push({endIndex:N,size:$,startIndex:N}),A.push({endIndex:N+1+B-1,size:R,startIndex:N+1}),O++,P+=B+1}const F=Zn(T.sizeTree);return P!==C&&F.shift(),F.reduce((N,{k:B,v:M})=>{let Q=N.ranges;return N.prevSize!==0&&(Q=[...N.ranges,{endIndex:B+C-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+C,prevSize:M,ranges:Q}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Zn(T.sizeTree).reduce(($,{k:P,v:O})=>({prevIndex:P+C,prevSize:O,ranges:[...$.ranges,{endIndex:P+C-1,size:$.prevSize,startIndex:$.prevIndex}]}),{prevIndex:0,prevSize:R,ranges:[]}).ranges})),n);const k=Ht(H(i,Oe(m,h),le(([C,{offsetTree:T},I])=>{const A=-C;return Yr(A,T,I)})));return he(H(i,Oe(m,h),le(([C,T,I])=>{if(T.groupIndices.length>0){if(st(T.sizeTree))return T;let A=Tr();const R=vt(y);let $=0,P=0,O=0;for(;$<-C;){O=R[P];const F=R[P+1]-O-1;P++,$+=F+1}if(A=Zn(T.sizeTree).reduce((F,{k:N,v:B})=>Wt(F,Math.max(0,N+C),B),A),$!==-C){const F=qr(T.sizeTree,O);A=Wt(A,0,F);const N=an(T.sizeTree,-C+1)[1];A=Wt(A,1,N)}return{...T,sizeTree:A,...ca(T.offsetTree,0,A,I)}}else{const A=Zn(T.sizeTree).reduce((R,{k:$,v:P})=>Wt(R,Math.max(0,$+C),P),Tr());return{...T,sizeTree:A,...ca(T.offsetTree,0,A,I)}}})),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}},ct(Mn,aa),{singleton:!0});function Uw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const $d=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=Ht(H(s,le(Uw)));return he(H(a,le(l=>l.totalCount)),n),he(H(a,le(l=>l.groupIndices)),e),he(H(wt(o,t,r),Te(([l,c])=>ms(c)),le(([l,c,d])=>an(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(yn,Dt)),On=qe(([{log:e}])=>{const t=ee(!1),n=Ht(H(t,Te(r=>r),ut()));return et(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},ct(Mn),{singleton:!0}),Hw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Fd(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 Xr=qe(([{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=ze(),x=ze(),m=ee(0);let y=null,g=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),g&&(clearTimeout(g),g=null),Re(l,!1)}return he(H(h,Oe(n,f,r,m,a,i,p),Oe(e,s,o),le(([[k,C,T,I,A,R,$,P],O,F,N])=>{const B=Fd(k),{align:M,behavior:Q,offset:z}=B,_=I-1,V=Dd(B,C,_);let Y=Yr(V,C.offsetTree,O)+R;M==="end"?(Y+=F+an(C.sizeTree,V)[1]-T+N,V===_&&(Y+=$)):M==="center"?Y+=(F+an(C.sizeTree,V)[1]-T+N)/2:Y-=A,z&&(Y+=z);const oe=ye=>{S(),ye?(P("retrying to scroll to",{location:k},Bt.DEBUG),Re(h,k)):(Re(x,!0),P("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),Q==="smooth"){let ye=!1;b=et(t,Me=>{ye=ye||Me}),y=sn(d,()=>{oe(ye)})}else y=sn(H(t,Ww(150)),oe);return g=setTimeout(()=>{S()},1200),Re(l,!0),P("scrolling from index to",{behavior:Q,index:V,top:Y},Bt.DEBUG),{behavior:Q,top:Y}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},ct(yn,Dt,Mn),{singleton:!0});function Ww(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ua(e,t){e==0?t():requestAnimationFrame(()=>{ua(e-1,t)})}function da(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Jr=qe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ee(!0),l=ee(0),c=ee(!0);return he(H(i,Oe(l),Te(([d,f])=>!!f),gn(!1)),a),he(H(i,Oe(l),Te(([d,f])=>!!f),gn(!1)),c),et(H(wt(t,i),Oe(a,n,e,c),Te(([[,d],f,{sizeTree:p},h,x])=>d&&(!st(p)||Qi(h))&&!f&&!x),Oe(l)),([,d])=>{sn(o,()=>{Re(c,!0)}),ua(4,()=>{sn(r,()=>{Re(a,!0)}),Re(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(yn,Dt,Xr,On),{singleton:!0});function Bd(e,t){return Math.abs(e-t)<1.01}const Zr="up",Qr="down",Vw="none",Kw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},qw=0,eo=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=ze(),c=ze(),d=ee(4),f=ee(qw),p=Nt(H(ta(H(Se(o),Xn(1),gn(!0)),H(Se(o),Xn(1),gn(!1),Cd(100))),ut()),!1),h=Nt(H(ta(H(n,gn(!0)),H(n,gn(!1),Cd(200))),ut()),!1);he(H(wt(Se(o),Se(f)),le(([b,S])=>b<=S),ut()),a),he(H(a,In(50)),c);const x=Ht(H(wt(r,Se(s),Se(t),Se(e),Se(d)),xn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const R=k+C-S>-A,$={scrollHeight:S,scrollTop:k,viewportHeight:C};if(R){let O,F;return k>b.state.scrollTop?(O="SCROLLED_DOWN",F=b.state.scrollTop-k):(O="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:O,scrollTopDelta:F,state:$}}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:$}},Kw),ut((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(H(r,xn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Bd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(b=>b.changed),le(b=>b.jump)),0);he(H(x,le(b=>b.atBottom)),i),he(H(i,In(50)),l);const y=ee(Qr);he(H(r,le(({scrollTop:b})=>b),ut(),xn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Zr:Qr,prevScrollTop:S},{direction:Qr,prevScrollTop:0}),le(b=>b.direction)),y),he(H(r,In(50),gn(Vw)),y);const g=ee(0);return he(H(p,Te(b=>!b),gn(0)),g),he(H(o,In(100),Oe(p),Te(([b,S])=>!!S),xn(([b,S],[k])=>[S,k],[0,0]),le(([b,S])=>S-b)),g),{atBottomState:x,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:y,scrollVelocity:g}},ct(Dt)),gs="top",xs="bottom",zd="none";function Ud(e,t,n){return typeof e=="number"?n===Zr&&t===gs||n===Qr&&t===xs?e:0:n===Zr?t===gs?e.main:e.reverse:t===xs?e.main:e.reverse}function Hd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const fa=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=ze(),i=ee(0),a=ee(0),l=ee(0),c=Nt(H(wt(Se(r),Se(o),Se(n),Se(s,Gr),Se(l),Se(i),Se(t),Se(e),Se(a)),le(([d,f,p,[h,x],m,y,g,b,S])=>{const k=d-b,C=y+g,T=Math.max(p-k,0);let I=zd;const A=Hd(S,gs),R=Hd(S,xs);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-A&&(I=Zr),x<d-T+f+R&&(I=Qr),I!==zd?[Math.max(k-p-Ud(m,gs,I)-A,0),k-T-g+f+Ud(m,xs,I)+R]:null}),Te(d=>d!=null),ut(Gr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Dt),{singleton:!0});function Gw(e,t,n){if(ms(t)){const r=Od(e,t);return[{index:an(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 pa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ys(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const 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:Vd(e,o,s),offsetBottom:x,offsetTop:c,top:h,topItems:Vd(t,o,s),topListHeight:t.reduce((m,y)=>y.size+m,0),totalCount:n}}function Wd(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=da(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ys(c,[],a,o,n,r)}function Vd(e,t,n){if(e.length===0)return[];if(!ms(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=fs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Qn=qe(([{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([]),y=ee(0),g=ze();he(s.topItemsIndexes,m);const b=Nt(H(wt(h,x,Se(l,Gr),Se(o),Se(r),Se(c),d,Se(m),Se(t),Se(n),e),Te(([T,I,,A,,,,,,,R])=>{const $=R&&R.length!==A;return T&&!I&&!$}),le(([,,[T,I],A,R,$,P,O,F,N,B])=>{const M=R,{offsetTree:Q,sizeTree:z}=M,_=vt(y);if(A===0)return{...pa,totalCount:A};if(T===0&&I===0)return _===0?{...pa,totalCount:A}:Wd(_,$,R,F,N,B||[]);if(st(z))return _>0?null:ys(Gw(da($,A),M,B),[],A,N,M,F);const V=[];if(O.length>0){const G=O[0],U=O[O.length-1];let X=0;for(const L of fs(z,G,U)){const K=L.value,Z=Math.max(L.start,G),ce=Math.min(L.end,U);for(let re=Z;re<=ce;re++)V.push({data:B==null?void 0:B[re],index:re,offset:X,size:K}),X+=K}}if(!P)return ys([],V,A,N,M,F);const Y=O.length>0?O[O.length-1]+1:0,oe=Dw(Q,T,I,Y);if(oe.length===0)return null;const ye=A-1,Me=ds([],G=>{for(const U of oe){const X=U.value;let L=X.offset,K=U.start;const Z=X.size;if(X.offset<T){K+=Math.floor((T-X.offset+N)/(Z+N));const re=K-U.start;L+=re*Z+re*N}K<Y&&(L+=(Y-K)*Z,K=Y);const ce=Math.min(U.end,ye);for(let re=K;re<=ce&&!(L>=I);re++)G.push({data:B==null?void 0:B[re],index:re,offset:L,size:Z}),L+=Z+N}});return ys(Me,V,A,N,M,F)}),Te(T=>T!==null),ut()),pa);he(H(e,Te(Qi),le(T=>T==null?void 0:T.length)),o),he(H(b,le(T=>T.topListHeight)),f),he(f,a),he(H(b,le(T=>[T.top,T.bottom])),i),he(H(b,le(T=>T.items)),g);const S=Ht(H(b,Te(({items:T})=>T.length>0),Oe(o,e),Te(([{items:T},I])=>T[T.length-1].originalIndex===I-1),le(([,T,I])=>[T-1,I]),ut(Gr),le(([T])=>T))),k=Ht(H(b,In(200),Te(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),le(({items:T})=>T[0].index),ut())),C=Ht(H(b,Te(({items:T})=>T.length>0),le(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),ut(Md)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},ct(yn,$d,fa,Jr,Xr,eo,On,aa),{singleton:!0}),Kd=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=Nt(H(wt(n,e,r,t,o),le(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Se(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Dt,Qn),{singleton:!0}),Yw=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(H(wt(n,e,t),Te(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),In(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Dt,Kd),{singleton:!0}),qd=qe(()=>({context:ee(null)})),Xw=({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,Gd=qe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=ze();return he(H(d,Oe(t,l,n,s,o,r,a),Oe(e),le(([[f,p,h,x,m,y,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Xw,done:I,...A}=f,R=Dd(f,p,x-1),$=Yr(R,p.offsetTree,S)+m+y,P=$+an(p.sizeTree,R)[1],O=b+y,F=b+h-g,N=T({itemBottom:P,itemTop:$,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:O});return N?I&&sn(H(i,Te(B=>!B),Xn(vt(i)?1:2)),I):I&&I(),N}),Te(f=>f!==null)),c),{scrollIntoView:d}},ct(yn,Dt,Xr,Qn,Mn),{singleton:!0});function Yd(e){return e?e==="smooth"?"smooth":"auto":!1}const Jw=(e,t)=>typeof e=="function"?Yd(e(t)):t&&Yd(e),Zw=qe(([{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=ze();let y=null;function g(C){Re(i,{align:"end",behavior:C,index:"LAST"})}et(H(wt(H(Se(t),Xn(1)),l),Oe(Se(x),s,a,f),le(([[C,T],I,A,R,$])=>{let P=T&&R,O="auto";return P&&(O=Jw(I,A||$),P=P&&!!O),{followOutputBehavior:O,shouldFollow:P,totalCount:C}}),Te(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C)}):y=sn(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C),y=null})});function b(C){const T=sn(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(vt(d)("scrolling to bottom due to increased size",{},Bt.DEBUG),g("auto"))});setTimeout(T,100)}et(H(wt(Se(x),t,c),Te(([C,,T])=>C&&T),xn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Te(({refreshed:C})=>C),Oe(x,t)),([,C])=>{vt(a)&&b(C!==!1)}),et(m,()=>{b(vt(x)!==!1)}),et(wt(Se(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=ze();return he(ta(H(Se(r),le(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),H(Se(t))),k),et(H(wt(H(k,Xn(1)),l),Oe(Se(S),a,f,p),le(([[C,T],I,A,R,$])=>T&&A&&(I==null?void 0:I({context:$,totalCount:C,scrollingInProgress:R}))),Te(C=>!!C),In(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Re(h,C)}):y=sn(e,()=>{vt(d)("scrolling into view",{}),Re(h,C),y=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},ct(yn,eo,Xr,Jr,On,Mn,Dt,qd,Gd)),Qw=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(H(a,Oe(s),Te(([,l])=>l!==0),Oe(o,r,t,n,e),le(([[,l],c,d,f,p,h=[]])=>Wd(l,c,d,f,p,h))),i),{}),ct(yn,Jr,Qn,On),{singleton:!0}),e0=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return et(H(e,Oe(r),Te(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{sn(H(n,Xn(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Re(t,o)})})}),{initialScrollTop:r}},ct(On,Dt,Qn),{singleton:!0}),Xd=qe(([{scrollVelocity:e}])=>{const t=ee(!1),n=ze(),r=ee(!1);return he(H(e,Oe(r,t,n),Te(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ut()),t),et(H(wt(t,e,n),Oe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},ct(eo),{singleton:!0}),ha=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=ee(!1),i=ee(void 0);return he(H(wt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(H(t,Oe(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Dt)),t0=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=ze(),d=ee(void 0),f=ee(null),p=ee(null);return he(a,f),he(l,p),et(H(c,Oe(t,r,i,f,p,n)),([h,x,m,y,g,b,S])=>{const k=$w(x.sizeTree);y&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),he(H(d,Te(Qi),le(n0)),o),he(H(s,Oe(d),Te(([,h])=>h!==void 0),ut(),le(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},ct(yn,Dt,Jr,On,ha));function n0(e){return{align:"start",index:0,offset:e.scrollTop}}const r0=qe(([{topItemsIndexes:e}])=>{const t=ee(0);return he(H(t,Te(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(Qn));function Jd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const o0=Jd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),s0=qe(([{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=Ht(H(l,Oe(i),xn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const R=k+T;let $=0;return b===I&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||($=R-S,$!==0&&($+=A))),[$,C,I,R]},[0,[],0,0]),Te(([g])=>g!==0),Oe(r,a,n,o,h,x),Te(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Zr),le(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Bt.DEBUG),g))));function y(g){g>0?(Re(t,{behavior:"auto",top:-g}),Re(e,0)):(Re(e,0),Re(t,{behavior:"auto",top:-g}))}return et(H(m,Oe(e,s)),([g,b,S])=>{S&&o0()?Re(e,b-g):y(-g)}),et(H(wt(Nt(s,!1),e,x),Te(([g,b,S])=>!g&&!S&&b!==0),le(([g,b])=>b),In(1)),y),he(H(f,le(g=>({top:-g}))),t),et(H(c,Oe(p,d),le(([g,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(g);{let I=0;const A=qr(k,0);let R=0,$=0;for(;R<g;){R++,I+=A;let P=b.length===$+1?1/0:b[$+1]-b[$]-1;R+P>g&&(I-=A,P=g-R+1),R+=P,I+=T(P),$++}return I}})),g=>{Re(e,g),requestAnimationFrame(()=>{Re(t,{top:g}),requestAnimationFrame(()=>{Re(e,0),Re(x,!1)})})}),{deviation:e}},ct(Dt,eo,Qn,yn,Mn,aa)),i0=qe(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ct(fa,Qw,On,Xd,Kd,e0,Yw,ha,Gd,Mn,qd)),Zd=qe(([{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,y,g,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},R])=>(he(k.rangeChanged,R.scrollSeekRangeChanged),he(H(R.windowViewportRect,le($=>$.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,...R,...m,sizes:l,...y}),ct(yn,Jr,Dt,t0,Zw,Qn,Xr,s0,r0,$d,i0));function a0(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const vs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Qd(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=w.createContext({});function l(y,g){y.propsReady&&Re(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Re(S,g[b])}for(const b of o)if(b in g){const S=y[t.optional[b]];Re(S,g[b])}y.propsReady&&Re(y.propsReady,!0)}function c(y){return s.reduce((g,b)=>(g[b]=S=>{const k=y[t.methods[b]];Re(k,S)},g),{})}function d(y){return i.reduce((g,b)=>(g[b]=Cw(y[t.events[b]]),g),{})}const f=w.forwardRef((y,g)=>{const{children:b,...S}=y,[k]=w.useState(()=>ds(kw(e),I=>{l(I,S)})),[C]=w.useState(Sd(d,k));vs(()=>{for(const I of i)I in S&&et(C[I],S[I]);return()=>{Object.values(C).map(ea)}},[S,C,k]),vs(()=>{l(k,S)}),w.useImperativeHandle(g,bd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...a0([...r,...o,...i],S),children:b}):b})}),p=y=>{const g=w.useContext(a);return w.useCallback(b=>{Re(g[y],b)},[g,y])},h=y=>{const g=w.useContext(a)[y],b=w.useCallback(S=>et(g,S),[g]);return w.useSyncExternalStore(b,()=>vt(g),()=>vt(g))},x=y=>{const g=w.useContext(a)[y],[b,S]=w.useState(Sd(vt,g));return vs(()=>et(g,k=>{k!==b&&S(bd(k))}),[g,b]),b},m=w.version.startsWith("18")?h:x;return{Component:f,useEmitter:(y,g)=>{const b=w.useContext(a)[y];vs(()=>et(b,g),[g,b])},useEmitterValue:m,usePublisher:p}}const ef=w.createContext(void 0),tf=w.createContext(void 0),nf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ma(e){return"self"in e}function l0(e){return"body"in e}function rf(e,t,n,r=Cr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,x,m;const y=p.target;if(l0(y)||ma(y)){const b=ma(y)?y:y.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?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,x=s?y.offsetWidth:y.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:x})};p.suppressFlushSync?g():Gs.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,y,g;ma(h)?(y=Math.max(Pn(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):(y=h[s?"scrollWidth":"scrollHeight"],m=Pn(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const b=y-m;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Bd(m,y)||p.top===g){e({scrollHeight:y,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 ga="-webkit-sticky",of="sticky",xa=Jd(()=>{if(typeof document>"u")return of;const e=document.createElement("div");return e.style.position=ga,e.style.position===ga?ga:of});function ya(e){return e}const c0=qe(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(ya),o=ee("div"),s=ee(Cr),i=(a,l=null)=>Nt(H(n,le(c=>c[a]),ut()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),u0=qe(([e,t])=>({...e,...t}),ct(Zd,c0)),d0=({height:e})=>u.jsx("div",{style:{height:e}}),f0={overflowAnchor:"none",position:xa(),zIndex:1},sf={overflowAnchor:"none"},p0={...sf,display:"inline-block",height:"100%"},af=w.memo(function({showTopList:e=!1}){const t=Ie("listState"),n=Jt("sizeRanges"),r=Ie("useWindowScroll"),o=Ie("customScrollParent"),s=Jt("windowScrollContainerState"),i=Jt("scrollContainerState"),a=o||r?s:i,l=Ie("itemContent"),c=Ie("context"),d=Ie("groupContent"),f=Ie("trackItemSizes"),p=Ie("itemSize"),h=Ie("log"),x=Jt("gap"),m=Ie("horizontalDirection"),{callbackRef:y}=Aw(n,p,f,e?Cr:a,h,x,o,m,Ie("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);va("deviation",N=>{g!==N&&b(N)});const S=Ie("EmptyPlaceholder"),k=Ie("ScrollSeekPlaceholder")||d0,C=Ie("ListComponent"),T=Ie("ItemComponent"),I=Ie("GroupComponent"),A=Ie("computeItemKey"),R=Ie("isSeeking"),$=Ie("groupIndices").length>0,P=Ie("alignToBottom"),O=Ie("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},...O?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(N=>{const B=N.originalIndex,M=A(B+t.firstItemIndex,N.data,c);return R?w.createElement(k,{..._t(k,c),height:N.size,index:N.index,key:M,type:N.type||"item",...N.type==="group"?{}:{groupIndex:N.groupIndex}}):N.type==="group"?w.createElement(I,{..._t(I,c),"data-index":B,"data-item-index":N.index,"data-known-size":N.size,key:M,style:f0},d(N.index,c)):w.createElement(T,{..._t(T,c),...x0(T,N.data),"data-index":B,"data-item-group-index":N.groupIndex,"data-item-index":N.index,"data-known-size":N.size,key:M,style:m?p0:sf},$?l(N.index,N.groupIndex,N.data,c):l(N.index,N.data,c))})})}),h0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},m0={outline:"none",overflowX:"auto",position:"relative"},bs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),g0={position:xa(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function x0(e,t){return{item:typeof e=="string"?void 0:t}}const y0=w.memo(function(){const e=Ie("HeaderComponent"),t=Jt("headerHeight"),n=Ie("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ie("skipAnimationFrameInResizeObserver")),o=Ie("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),v0=w.memo(function(){const e=Ie("FooterComponent"),t=Jt("footerHeight"),n=Ie("HeaderFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,Ie("skipAnimationFrameInResizeObserver")),o=Ie("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function lf({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}=rf(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?m0:h0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function cf({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:y,scrollToCallback:g}=rf(a,c,l,x,p);return nf(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,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,..._t(l,s),children:r})})}const b0=({children:e})=>{const t=w.useContext(ef),n=Jt("viewportHeight"),r=Jt("fixedItemHeight"),o=Ie("alignToBottom"),s=Ie("horizontalDirection"),i=w.useMemo(()=>wd(n,l=>Pn(l,s?"width":"height")),[n,s]),a=Jn(i,!0,Ie("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:bs(o),children:e})},w0=({children:e})=>{const t=w.useContext(ef),n=Jt("windowViewportRect"),r=Jt("fixedItemHeight"),o=Ie("customScrollParent"),s=Id(n,o,Ie("skipAnimationFrameInResizeObserver")),i=Ie("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:bs(i),children:e})},S0=({children:e})=>{const t=Ie("TopItemListComponent")||"div",n=Ie("headerHeight"),r={...g0,marginTop:`${n}px`},o=Ie("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},C0=w.memo(function(e){const t=Ie("useWindowScroll"),n=Ie("topItemsIndexes").length>0,r=Ie("customScrollParent"),o=Ie("context");return u.jsxs(r||t?I0:k0,{...e,context:o,children:[n&&u.jsx(S0,{children:u.jsx(af,{showTopList:!0})}),u.jsxs(r||t?w0:b0,{children:[u.jsx(y0,{}),u.jsx(af,{}),u.jsx(v0,{})]})]})}),{Component:T0,useEmitter:va,useEmitterValue:Ie,usePublisher:Jt}=Qd(u0,{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"}},C0),k0=lf({useEmitter:va,useEmitterValue:Ie,usePublisher:Jt}),I0=cf({useEmitter:va,useEmitterValue:Ie,usePublisher:Jt}),E0=T0;ct(Zd,qe(()=>{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(ya),a=ee(Cr),l=(c,d=null)=>Nt(H(s,le(f=>f[c]),ut()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),xa();const uf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},A0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:df,floor:ws,max:to,min:ba,round:ff}=Math;function pf(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{...A0,items:e}}function Ss(e,t){return e&&e.width===t.width&&e.height===t.height}function _0(e,t){return e&&e.column===t.column&&e.row===t.row}const j0=qe(([{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:y,useWindowScroll:g,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=ee(0),I=ee(0),A=ee(uf),R=ee({height:0,width:0}),$=ee({height:0,width:0}),P=ze(),O=ze(),F=ee(0),N=ee(null),B=ee({column:0,row:0}),M=ze(),Q=ze(),z=ee(!1),_=ee(0),V=ee(!0),Y=ee(!1),oe=ee(!1);et(H(x,Oe(_),Te(([L,K])=>!!K)),()=>{Re(V,!1)}),et(H(wt(x,V,$,R,_,Y),Te(([L,K,Z,ce,,re])=>L&&!K&&Z.height!==0&&ce.height!==0&&!re)),([,,,,L])=>{Re(Y,!0),ua(1,()=>{Re(P,L)}),sn(H(c),()=>{Re(t,[0,0]),Re(V,!0)})}),he(H(Q,Te(L=>L!=null&&L.scrollTop>0),gn(0)),I),et(H(x,Oe(Q),Te(([,L])=>L!=null)),([,L])=>{L&&(Re(R,L.viewport),Re($,L.item),Re(B,L.gap),L.scrollTop>0&&(Re(z,!0),sn(H(c,Xn(1)),K=>{Re(z,!1)}),Re(l,{top:L.scrollTop})))}),he(H(R,le(({height:L})=>L)),f),he(H(wt(Se(R,Ss),Se($,Ss),Se(B,(L,K)=>L&&L.column===K.column&&L.row===K.row),Se(c)),le(([L,K,Z,ce])=>({gap:Z,item:K,scrollTop:ce,viewport:L}))),M),he(H(wt(Se(T),r,Se(B,_0),Se($,Ss),Se(R,Ss),Se(N),Se(I),Se(z),Se(V),Se(_)),Te(([,,,,,,,L])=>!L),le(([L,[K,Z],ce,re,je,Ue,De,,Ge,Ve])=>{const{column:tt,row:Ye}=ce,{height:ie,width:xe}=re,{width:He}=je;if(De===0&&(L===0||He===0))return uf;if(xe===0){const Lt=da(Ve,L),Mt=Lt+Math.max(De-1,0);return N0(pf(Lt,Mt,Ue))}const We=hf(He,xe,tt);let rt,at;Ge?K===0&&Z===0&&De>0?(rt=0,at=De-1):(rt=We*ws((K+Ye)/(ie+Ye)),at=We*df((Z+Ye)/(ie+Ye))-1,at=ba(L-1,to(at,We-1)),rt=ba(at,to(0,rt))):(rt=0,at=-1);const Rt=pf(rt,at,Ue),{bottom:gt,top:ht}=mf(je,ce,re,Rt),bt=df(L/We),St=bt*ie+(bt-1)*Ye-gt;return{bottom:gt,itemHeight:ie,items:Rt,itemWidth:xe,offsetBottom:St,offsetTop:ht,top:ht}})),A),he(H(N,Te(L=>L!==null),le(L=>L.length)),T),he(H(wt(R,$,A,B),Te(([L,K,{items:Z}])=>Z.length>0&&K.height!==0&&L.height!==0),le(([L,K,{items:Z},ce])=>{const{bottom:re,top:je}=mf(L,ce,K,Z);return[je,re]}),ut(Gr)),t);const ye=ee(!1);he(H(c,Oe(ye),le(([L,K])=>K||L!==0)),ye);const Me=Ht(H(wt(A,T),Te(([{items:L}])=>L.length>0),Oe(ye),Te(([[L,K],Z])=>{const ce=L.items[L.items.length-1].index===K-1;return(Z||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===K)&&ce}),le(([[,L]])=>L-1),ut())),G=Ht(H(Se(A),Te(({items:L})=>L.length>0&&L[0].index===0),gn(0),ut())),U=Ht(H(Se(A),Oe(z),Te(([{items:L},K])=>L.length>0&&!K),le(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),ut(Md),In(0)));he(U,h.scrollSeekRangeChanged),he(H(P,Oe(R,$,T,B),le(([L,K,Z,ce,re])=>{const je=Fd(L),{align:Ue,behavior:De,offset:Ge}=je;let Ve=je.index;Ve==="LAST"&&(Ve=ce-1),Ve=to(0,Ve,ba(ce-1,Ve));let tt=wa(K,re,Z,Ve);return Ue==="end"?tt=ff(tt-K.height+Z.height):Ue==="center"&&(tt=ff(tt-K.height/2+Z.height/2)),Ge&&(tt+=Ge),{behavior:De,top:tt}})),l);const X=Nt(H(A,le(L=>L.offsetBottom+L.bottom)),0);return he(H(k,le(L=>({height:L.visibleHeight,width:L.visibleWidth}))),R),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:$,overscan:n,restoreStateFrom:Q,scrollBy:i,scrollContainerState:a,scrollHeight:O,scrollTo:l,scrollToIndex:P,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:R,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:A,horizontalDirection:oe,initialTopMostItemIndex:_,totalListHeight:X,...p,endReached:Me,propsReady:m,rangeChanged:U,startReached:G,stateChanged:M,stateRestoreInProgress:z,...C}},ct(fa,Dt,eo,Xd,On,ha,Mn));function hf(e,t,n){return to(1,ws((e+n)/(ws(t)+n)))}function mf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=wa(e,t,n,r[0].index);return{bottom:wa(e,t,n,r[r.length-1].index)+o,top:s}}function wa(e,t,n,r){const o=hf(e.width,n.width,t.column),s=ws(r/o),i=s*n.height+to(0,s-1)*t.row;return i>0?i+t.row:i}const R0=qe(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(ya),i=ee("div"),a=ee(Cr),l=(f,p=null)=>Nt(H(t,le(h=>h[f]),ut()),p),c=ee(!1),d=ee(!1);return he(Se(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")}}),M0=qe(([e,t])=>({...e,...t}),ct(j0,R0)),P0=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Zt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Zt("itemDimensions"),p=Zt("gap"),h=ft("log"),x=ft("stateRestoreInProgress"),m=Zt("reportReadyState"),y=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:xf("column-gap",getComputedStyle(g).columnGap,h),row:xf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return nf(()=>{e.itemHeight>0&&e.itemWidth>0&&m(!0)},[e]),x?null:u.jsx(l,{className:t,ref:y,..._t(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(g=>{const b=o(g.index,g.data,d);return s?u.jsx(c,{..._t(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":g.index,key:b},r(g.index,g.data,d))})})}),O0=w.memo(function(){const e=ft("HeaderComponent"),t=Zt("headerHeight"),n=ft("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),D0=w.memo(function(){const e=ft("FooterComponent"),t=Zt("footerHeight"),n=ft("headerFooterTag"),r=Jn(w.useMemo(()=>s=>{t(Pn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),L0=({children:e})=>{const t=w.useContext(tf),n=Zt("itemDimensions"),r=Zt("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:bs(!1),children:e})},$0=({children:e})=>{const t=w.useContext(tf),n=Zt("windowViewportRect"),r=Zt("itemDimensions"),o=ft("customScrollParent"),s=Id(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:bs(!1),children:e})},F0=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?z0:B0,o=n||t?$0:L0,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(O0,{}),u.jsx(P0,{}),u.jsx(D0,{})]})})}),{useEmitter:gf,useEmitterValue:ft,usePublisher:Zt}=Qd(M0,{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"}},F0),B0=lf({useEmitter:gf,useEmitterValue:ft,usePublisher:Zt}),z0=cf({useEmitter:gf,useEmitterValue:ft,usePublisher:Zt});function xf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Bt.WARN),t==="normal"?0:parseInt(t??"0",10)}const U0=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 yf({className:e,variant:t,...n}){return u.jsx("div",{className:te(U0({variant:t}),e),...n})}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 vf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function no(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(no).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(vf(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=no(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function ro(e){if(typeof e=="string")return e;if(vf(e))return"";try{const t=no(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function H0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function W0(e){const t=ro(e);return typeof e=="string"&&H0(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}function V0(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function bf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Ts(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function K0(e){const t=r=>{try{const o=no(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
87
- `)):t(e)}function q0(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function wf(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 G0(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function Y0(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function X0({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=G0(n),i=o?`data:${s};base64,${e}`:t,a=Y0(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function J0(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 X0({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function Sf(e,t){return await qt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Cf(e,t){return await(await Sf(`/files/${e}/view`,t)).text()}async function Z0(e,t){const n=await Sf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await qt(`/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 Q0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await qt("/files",{params:r})}var ks="Dialog",[Tf,LT]=Sn(ks),[eS,ln]=Tf(ks),kf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:ks});return u.jsx(eS,{scope:t,triggerRef:a,contentRef:l,contentId:Cn(),titleId:Cn(),descriptionId:Cn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};kf.displayName=ks;var If="DialogTrigger",Ef=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(If,n),s=Be(t,o.triggerRef);return u.jsx(Ee.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":ka(o.open),...r,ref:s,onClick:de(e.onClick,o.onOpenToggle)})});Ef.displayName=If;var Ca="DialogPortal",[tS,Af]=Tf(Ca,{forceMount:void 0}),Nf=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=ln(Ca,t);return u.jsx(tS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Yt,{present:n||s.open,children:u.jsx(qo,{asChild:!0,container:o,children:i})}))})};Nf.displayName=Ca;var Is="DialogOverlay",_f=v.forwardRef((e,t)=>{const n=Af(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ln(Is,e.__scopeDialog);return s.modal?u.jsx(Yt,{present:r||s.open,children:u.jsx(rS,{...o,ref:t})}):null});_f.displayName=Is;var nS=Hn.createSlot("DialogOverlay.RemoveScroll"),rS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Is,n);return u.jsx(ns,{as:nS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ee.div,{"data-state":ka(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),er="DialogContent",jf=v.forwardRef((e,t)=>{const n=Af(er,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ln(er,e.__scopeDialog);return u.jsx(Yt,{present:r||s.open,children:s.modal?u.jsx(oS,{...o,ref:t}):u.jsx(sS,{...o,ref:t})})});jf.displayName=er;var oS=v.forwardRef((e,t)=>{const n=ln(er,e.__scopeDialog),r=v.useRef(null),o=Be(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Fi(s)},[]),u.jsx(Rf,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:de(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:de(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault())})}),sS=v.forwardRef((e,t)=>{const n=ln(er,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Rf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Rf=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=ln(er,n),l=v.useRef(null),c=Be(t,l);return bi(),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(iS,{titleId:a.titleId}),u.jsx(lS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ta="DialogTitle",Mf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Ta,n);return u.jsx(Ee.h2,{id:o.titleId,...r,ref:t})});Mf.displayName=Ta;var Pf="DialogDescription",Of=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Pf,n);return u.jsx(Ee.p,{id:o.descriptionId,...r,ref:t})});Of.displayName=Pf;var Df="DialogClose",Lf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Df,n);return u.jsx(Ee.button,{type:"button",...r,ref:t,onClick:de(e.onClick,()=>o.onOpenChange(!1))})});Lf.displayName=Df;function ka(e){return e?"open":"closed"}var $f="DialogTitleWarning",[$T,Ff]=nx($f,{contentName:er,titleName:Ta,docsSlug:"dialog"}),iS=({titleId:e})=>{const t=Ff($f),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 vw(e,t=ds){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 bw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),vw(t),yw(t)}const fs=0,On=1,Cr=2,Sd=4;function Cd(e){return()=>e}function ww(e){e()}function Td(e,t){return n=>e(t(n))}function kd(e,t){return()=>e(t)}function Sw(e,t){return n=>e(t,n)}function na(e){return e!==void 0}function Cw(...e){return()=>{e.map(ww)}}function Tr(){}function ps(e,t){return t(e),e}function Tw(e,t){return t(e)}function lt(...e){return e}function Xe(e,t){return e(On,t)}function Re(e,t){e(fs,t)}function ra(e){e(Cr)}function yt(e){return e(Sd)}function he(e,t){return Xe(e,Sw(t,fs))}function sn(e,t){const n=e(On,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 Ed(e,t){return e===t}function ct(e=Ed){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>Td(t,e)}function yn(e){return t=>()=>{t(e)}}function H(e,...t){const n=kw(...t);return(r,o)=>{switch(r){case Cr:ra(e);return;case On:return Xe(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function Qn(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 Oe(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Xe(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 kw(...e){return t=>e.reduceRight(Tw,t)}function Iw(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=Xe(e,s),t):(r(),Tr);case Cr:r(),n=null;return}}}function te(e){let t=e;const n=Be();return(r,o)=>{switch(r){case fs:t=o;break;case On:{o(t);break}case Sd:return t}return n(r,o)}}function Nt(e,t){return ps(te(t),n=>he(e,n))}function Be(){const e=[];return(t,n)=>{switch(t){case fs:e.slice().forEach(r=>{r(n)});return;case Cr:e.splice(0,e.length);return;case On:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Vt(e){return ps(Be(),t=>he(e,t))}function He(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Ew(),singleton:n}}const Ew=()=>Symbol();function Aw(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function bt(...e){const t=Be(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Xe(s,l=>{n[i]=l,r=r|a,r===o&&Re(t,n)})}),function(s,i){switch(s){case Cr:{ra(t);return}case On:return r===o&&i(n),Xe(t,i)}}}function Se(e,t=Ed){return H(e,ct(t))}function oa(...e){return function(t,n){switch(t){case Cr:return;case On:return Cw(...e.map(r=>Xe(r,n)))}}}var zt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(zt||{});const Nw={0:"debug",3:"error",1:"log",2:"warn"},_w=()=>typeof globalThis>"u"?window:globalThis,Dn=He(()=>{const e=te(3);return{log:te((t,n,r=1)=>{var o;const s=(o=_w().VIRTUOSO_LOG_LEVEL)!=null?o:yt(e);r>=s&&console[Nw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function er(e,t,n){return sa(e,t,n).callbackRef}function sa(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 jw(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Rw(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,y=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:y,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 sa(c,n,l)}function Rw(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},zt.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,zt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Nd(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}=sa(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Lt=He(()=>{const e=Be(),t=Be(),n=te(0),r=Be(),o=te(0),s=Be(),i=Be(),a=te(0),l=te(0),c=te(0),d=te(0),f=Be(),p=Be(),h=te(!1),x=te(!1),m=te(!1);return he(H(e,le(({scrollTop:y})=>y)),t),he(H(e,le(({scrollHeight:y})=>y)),i),he(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}),Yr={lvl:0};function _d(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function rt(e){return e===Yr}function Xr(e,t){if(!rt(e))return t===e.k?e.v:t<e.k?Xr(e.l,t):Xr(e.r,t)}function an(e,t,n="k"){if(rt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=an(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return an(e.l,t,n)}function Kt(e,t,n){return rt(e)?Md(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?Pd(Ct(e,{l:Kt(e.l,t,n)})):Pd(Ct(e,{r:Kt(e.r,t,n)}))}function kr(){return Yr}function hs(e,t,n){if(rt(e))return[];const r=an(e,t)[0];return Mw(aa(e,r,n))}function ia(e,t){if(rt(e))return Yr;const{k:n,l:r,r:o}=e;if(t===n){if(rt(r))return o;if(rt(o))return r;{const[s,i]=Rd(r);return ms(Ct(e,{k:s,l:jd(r),v:i}))}}else return t<n?ms(Ct(e,{l:ia(r,t)})):ms(Ct(e,{r:ia(o,t)}))}function tr(e){return rt(e)?[]:[...tr(e.l),{k:e.k,v:e.v},...tr(e.r)]}function aa(e,t,n){if(rt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(aa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(aa(s,t,n))),a}function ms(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(la(t))return Od(Ct(e,{lvl:n-1}));if(!rt(t)&&!rt(t.r))return Ct(t.r,{l:Ct(t,{r:t.r.l}),lvl:n,r:Ct(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(la(e))return ca(Ct(e,{lvl:n-1}));if(!rt(r)&&!rt(r.l)){const o=r.l,s=la(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ca(Ct(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ct(e,t){return Md(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 jd(e){return rt(e.r)?e.l:ms(Ct(e,{r:jd(e.r)}))}function la(e){return rt(e)||e.lvl>e.r.lvl}function Rd(e){return rt(e.r)?[e.k,e.v]:Rd(e.r)}function Md(e,t,n,r=Yr,o=Yr){return{k:e,l:r,lvl:n,r:o,v:t}}function Pd(e){return ca(Od(e))}function Od(e){const{l:t}=e;return!rt(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function ca(e){const{lvl:t,r:n}=e;return!rt(n)&&!rt(n.r)&&n.lvl===t&&n.r.lvl===t?Ct(n,{l:Ct(e,{r:n.l}),lvl:t+1}):e}function Mw(e){return _d(e,({k:t,v:n})=>({index:t,value:n}))}function Dd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Jr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ua=He(()=>({recalcInProgress:te(!1)}),[],{singleton:!0});function Ld(e,t,n){return e[gs(e,t,n)]}function gs(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 Pw(e,t,n,r){const o=gs(e,t,r),s=gs(e,n,r,o);return e.slice(o,s+1)}function Ln(e,t){return Math.round(e.getBoundingClientRect()[t])}function xs(e){return!rt(e.groupOffsetTree)}function da({index:e},t){return t===e?0:t<e?-1:1}function Ow(){return{groupIndices:[],groupOffsetTree:kr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:kr()}}function Dw(e,t){let n=rt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),rt(e)){e=Kt(e,0,s);continue}const a=hs(e,i-1,o+1);if(a.some(Hw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=ia(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Kt(e,o+1,p));c&&(e=Kt(e,i,s))}return[e,n]}function Lw(e){return typeof e.groupIndex<"u"}function $w({offset:e},t){return t===e?0:t<e?-1:1}function Zr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Ld(t,e,da),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function $d(e,t){if(!xs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Fd(e,t,n){if(Lw(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 Fw(e,t,n,r=0){return r>0&&(t=Math.max(t,Ld(e,r,da).offset)),_d(Pw(e,t,n,$w),Uw)}function Bw(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,zt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&rt(s)&&t.length===2){const p=t[0].size,h=t[1].size;i=n.reduce((x,m)=>Kt(Kt(x,m,p),m+1,h),i)}else[i,a]=Dw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=fa(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Kt(p,h,Zr(h,f,o)),kr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function zw(e){return tr(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 fa(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=gs(o,t-1,da),a=o[l].offset;const c=an(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===an(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of hs(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 Uw(e){return{index:e.index,value:e}}function Hw(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 Ww={offsetHeight:"height",offsetWidth:"width"},bn=He(([{log:e},{recalcInProgress:t}])=>{const n=Be(),r=Be(),o=Nt(r,0),s=Be(),i=Be(),a=te(0),l=te([]),c=te(void 0),d=te(void 0),f=te((C,T)=>Ln(C,Ww[T])),p=te(void 0),h=te(0),x=Ow(),m=Nt(H(n,Oe(l,e,h),vn(Bw,x),ct()),x),y=Nt(H(l,ct(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);he(H(l,Te(C=>C.length>0),Oe(m,h),le(([C,T,I])=>{const A=C.reduce((M,L,P)=>Kt(M,L,Zr(L,T.offsetTree,I)||P),kr());return{...T,groupIndices:C,groupOffsetTree:A}})),m),he(H(r,Oe(m),Te(([C,{lastIndex:T}])=>C<T),le(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const g=Nt(H(c,le(C=>C===void 0)),!0);he(H(d,Te(C=>C!==void 0&&rt(yt(m).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Vt(H(n,Oe(m),vn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:x}),le(C=>C.changed)));Xe(H(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:T}=yt(m);if(C>0)Re(t,!0),Re(s,C+Bd(C,T));else if(C<0){const I=yt(y);I.length>0&&(C-=Bd(-C,I)),Re(i,C)}}),Xe(H(a,Oe(e)),([C,T])=>{C<0&&T("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},zt.ERROR)});const S=Vt(s);he(H(s,Oe(m),le(([C,T])=>{const I=T.groupIndices.length>0,A=[],M=T.lastSize;if(I){const L=Xr(T.sizeTree,0);let P=0,D=0;for(;P<C;){const N=T.groupIndices[D],B=T.groupIndices.length===D+1?1/0:T.groupIndices[D+1]-N-1;A.push({endIndex:N,size:L,startIndex:N}),A.push({endIndex:N+1+B-1,size:M,startIndex:N+1}),D++,P+=B+1}const F=tr(T.sizeTree);return P!==C&&F.shift(),F.reduce((N,{k:B,v:j})=>{let V=N.ranges;return N.prevSize!==0&&(V=[...N.ranges,{endIndex:B+C-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+C,prevSize:j,ranges:V}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return tr(T.sizeTree).reduce((L,{k:P,v:D})=>({prevIndex:P+C,prevSize:D,ranges:[...L.ranges,{endIndex:P+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:M,ranges:[]}).ranges})),n);const k=Vt(H(i,Oe(m,h),le(([C,{offsetTree:T},I])=>{const A=-C;return Zr(A,T,I)})));return he(H(i,Oe(m,h),le(([C,T,I])=>{if(T.groupIndices.length>0){if(rt(T.sizeTree))return T;let A=kr();const M=yt(y);let L=0,P=0,D=0;for(;L<-C;){D=M[P];const F=M[P+1]-D-1;P++,L+=F+1}if(A=tr(T.sizeTree).reduce((F,{k:N,v:B})=>Kt(F,Math.max(0,N+C),B),A),L!==-C){const F=Xr(T.sizeTree,D);A=Kt(A,0,F);const N=an(T.sizeTree,-C+1)[1];A=Kt(A,1,N)}return{...T,sizeTree:A,...fa(T.offsetTree,0,A,I)}}else{const A=tr(T.sizeTree).reduce((M,{k:L,v:P})=>Kt(M,Math.max(0,L+C),P),kr());return{...T,sizeTree:A,...fa(T.offsetTree,0,A,I)}}})),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}},lt(Dn,ua),{singleton:!0});function Vw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const zd=He(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Be(),i=Be(),a=Vt(H(s,le(Vw)));return he(H(a,le(l=>l.totalCount)),n),he(H(a,le(l=>l.groupIndices)),e),he(H(bt(o,t,r),Te(([l,c])=>xs(c)),le(([l,c,d])=>an(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(bn,Lt)),$n=He(([{log:e}])=>{const t=te(!1),n=Vt(H(t,Te(r=>r),ct()));return Xe(t,r=>{r&&yt(e)("props updated",{},zt.DEBUG)}),{didMount:n,propsReady:t}},lt(Dn),{singleton:!0}),Kw=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||!Kw)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Qr=He(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:d,viewportHeight:f},{log:p}])=>{const h=Be(),x=Be(),m=te(0);let y=null,g=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),g&&(clearTimeout(g),g=null),Re(l,!1)}return he(H(h,Oe(n,f,r,m,a,i,p),Oe(e,s,o),le(([[k,C,T,I,A,M,L,P],D,F,N])=>{const B=Ud(k),{align:j,behavior:V,offset:z}=B,R=I-1,K=Fd(B,C,R);let J=Zr(K,C.offsetTree,D)+M;j==="end"?(J+=F+an(C.sizeTree,K)[1]-T+N,K===R&&(J+=L)):j==="center"?J+=(F+an(C.sizeTree,K)[1]-T+N)/2:J-=A,z&&(J+=z);const se=ge=>{S(),ge?(P("retrying to scroll to",{location:k},zt.DEBUG),Re(h,k)):(Re(x,!0),P("list did not change, scroll successful",{},zt.DEBUG))};if(S(),V==="smooth"){let ge=!1;b=Xe(t,Ie=>{ge=ge||Ie}),y=sn(d,()=>{se(ge)})}else y=sn(H(t,qw(150)),se);return g=setTimeout(()=>{S()},1200),Re(l,!0),P("scrolling from index to",{behavior:V,index:K,top:J},zt.DEBUG),{behavior:V,top:J}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},lt(bn,Lt,Dn),{singleton:!0});function qw(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function pa(e,t){e==0?t():requestAnimationFrame(()=>{pa(e-1,t)})}function ha(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const eo=He(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=te(!0),l=te(0),c=te(!0);return he(H(i,Oe(l),Te(([d,f])=>!!f),yn(!1)),a),he(H(i,Oe(l),Te(([d,f])=>!!f),yn(!1)),c),Xe(H(bt(t,i),Oe(a,n,e,c),Te(([[,d],f,{sizeTree:p},h,x])=>d&&(!rt(p)||na(h))&&!f&&!x),Oe(l)),([,d])=>{sn(o,()=>{Re(c,!0)}),pa(4,()=>{sn(r,()=>{Re(a,!0)}),Re(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(bn,Lt,Qr,$n),{singleton:!0});function Hd(e,t){return Math.abs(e-t)<1.01}const to="up",no="down",Gw="none",Yw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Xw=0,ro=He(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=te(!1),a=te(!0),l=Be(),c=Be(),d=te(4),f=te(Xw),p=Nt(H(oa(H(Se(o),Qn(1),yn(!0)),H(Se(o),Qn(1),yn(!1),Id(100))),ct()),!1),h=Nt(H(oa(H(n,yn(!0)),H(n,yn(!1),Id(200))),ct()),!1);he(H(bt(Se(o),Se(f)),le(([b,S])=>b<=S),ct()),a),he(H(a,Nn(50)),c);const x=Vt(H(bt(r,Se(s),Se(t),Se(e),Se(d)),vn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const M=k+C-S>-A,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(M){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:L}}let P;return L.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:L}},Yw),ct((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(H(r,vn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Hd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(b=>b.changed),le(b=>b.jump)),0);he(H(x,le(b=>b.atBottom)),i),he(H(i,Nn(50)),l);const y=te(no);he(H(r,le(({scrollTop:b})=>b),ct(),vn((b,S)=>yt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?to:no,prevScrollTop:S},{direction:no,prevScrollTop:0}),le(b=>b.direction)),y),he(H(r,Nn(50),yn(Gw)),y);const g=te(0);return he(H(p,Te(b=>!b),yn(0)),g),he(H(o,Nn(100),Oe(p),Te(([b,S])=>!!S),vn(([b,S],[k])=>[S,k],[0,0]),le(([b,S])=>S-b)),g),{atBottomState:x,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:p,lastJumpDueToItemResize:m,scrollDirection:y,scrollVelocity:g}},lt(Lt)),ys="top",vs="bottom",Wd="none";function Vd(e,t,n){return typeof e=="number"?n===to&&t===ys||n===no&&t===vs?e:0:n===to?t===ys?e.main:e.reverse:t===vs?e.main:e.reverse}function Kd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ma=He(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Be(),i=te(0),a=te(0),l=te(0),c=Nt(H(bt(Se(r),Se(o),Se(n),Se(s,Jr),Se(l),Se(i),Se(t),Se(e),Se(a)),le(([d,f,p,[h,x],m,y,g,b,S])=>{const k=d-b,C=y+g,T=Math.max(p-k,0);let I=Wd;const A=Kd(S,ys),M=Kd(S,vs);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-A&&(I=to),x<d-T+f+M&&(I=no),I!==Wd?[Math.max(k-p-Vd(m,ys,I)-A,0),k-T-g+f+Vd(m,vs,I)+M]:null}),Te(d=>d!=null),ct(Jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Lt),{singleton:!0});function Jw(e,t,n){if(xs(t)){const r=$d(e,t);return[{index:an(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 ga={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function bs(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,y)=>y.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=ha(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return bs(c,[],a,o,n,r)}function Gd(e,t,n){if(e.length===0)return[];if(!xs(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=hs(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 nr=He(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},p,{didMount:h},{recalcInProgress:x}])=>{const m=te([]),y=te(0),g=Be();he(s.topItemsIndexes,m);const b=Nt(H(bt(h,x,Se(l,Jr),Se(o),Se(r),Se(c),d,Se(m),Se(t),Se(n),e),Te(([T,I,,A,,,,,,,M])=>{const L=M&&M.length!==A;return T&&!I&&!L}),le(([,,[T,I],A,M,L,P,D,F,N,B])=>{const j=M,{offsetTree:V,sizeTree:z}=j,R=yt(y);if(A===0)return{...ga,totalCount:A};if(T===0&&I===0)return R===0?{...ga,totalCount:A}:qd(R,L,M,F,N,B||[]);if(rt(z))return R>0?null:bs(Jw(ha(L,A),j,B),[],A,N,j,F);const K=[];if(D.length>0){const Y=D[0],U=D[D.length-1];let Z=0;for(const $ of hs(z,Y,U)){const q=$.value,Q=Math.max($.start,Y),ce=Math.min($.end,U);for(let oe=Q;oe<=ce;oe++)K.push({data:B==null?void 0:B[oe],index:oe,offset:Z,size:q}),Z+=q}}if(!P)return bs([],K,A,N,j,F);const J=D.length>0?D[D.length-1]+1:0,se=Fw(V,T,I,J);if(se.length===0)return null;const ge=A-1,Ie=ps([],Y=>{for(const U of se){const Z=U.value;let $=Z.offset,q=U.start;const Q=Z.size;if(Z.offset<T){q+=Math.floor((T-Z.offset+N)/(Q+N));const oe=q-U.start;$+=oe*Q+oe*N}q<J&&($+=(J-q)*Q,q=J);const ce=Math.min(U.end,ge);for(let oe=q;oe<=ce&&!($>=I);oe++)Y.push({data:B==null?void 0:B[oe],index:oe,offset:$,size:Q}),$+=Q+N}});return bs(Ie,K,A,N,j,F)}),Te(T=>T!==null),ct()),ga);he(H(e,Te(na),le(T=>T==null?void 0:T.length)),o),he(H(b,le(T=>T.topListHeight)),f),he(f,a),he(H(b,le(T=>[T.top,T.bottom])),i),he(H(b,le(T=>T.items)),g);const S=Vt(H(b,Te(({items:T})=>T.length>0),Oe(o,e),Te(([{items:T},I])=>T[T.length-1].originalIndex===I-1),le(([,T,I])=>[T-1,I]),ct(Jr),le(([T])=>T))),k=Vt(H(b,Nn(200),Te(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),le(({items:T})=>T[0].index),ct())),C=Vt(H(b,Te(({items:T})=>T.length>0),le(({items:T})=>{let I=0,A=T.length-1;for(;T[I].type==="group"&&I<A;)I++;for(;T[A].type==="group"&&A>I;)A--;return{endIndex:T[A].index,startIndex:T[I].index}}),ct(Dd)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},lt(bn,zd,ma,eo,Qr,ro,$n,ua),{singleton:!0}),Yd=He(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Be(),i=Nt(H(bt(n,e,r,t,o),le(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Se(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Lt,nr),{singleton:!0}),Zw=He(([{viewportHeight:e},{totalListHeight:t}])=>{const n=te(!1),r=Nt(H(bt(n,e,t),Te(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),Nn(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Lt,Yd),{singleton:!0}),Xd=He(()=>({context:te(null)})),Qw=({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=He(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Be();return he(H(d,Oe(t,l,n,s,o,r,a),Oe(e),le(([[f,p,h,x,m,y,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Qw,done:I,...A}=f,M=Fd(f,p,x-1),L=Zr(M,p.offsetTree,S)+m+y,P=L+an(p.sizeTree,M)[1],D=b+y,F=b+h-g,N=T({itemBottom:P,itemTop:L,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:D});return N?I&&sn(H(i,Te(B=>!B),Qn(yt(i)?1:2)),I):I&&I(),N}),Te(f=>f!==null)),c),{scrollIntoView:d}},lt(bn,Lt,Qr,nr,Dn),{singleton:!0});function Zd(e){return e?e==="smooth"?"smooth":"auto":!1}const e0=(e,t)=>typeof e=="function"?Zd(e(t)):t&&Zd(e),t0=He(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:d},{scrollingInProgress:f},{context:p},{scrollIntoView:h}])=>{const x=te(!1),m=Be();let y=null;function g(C){Re(i,{align:"end",behavior:C,index:"LAST"})}Xe(H(bt(H(Se(t),Qn(1)),l),Oe(Se(x),s,a,f),le(([[C,T],I,A,M,L])=>{let P=T&&M,D="auto";return P&&(D=e0(I,A||L),P=P&&!!D),{followOutputBehavior:D,shouldFollow:P,totalCount:C}}),Te(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),yt(n)?requestAnimationFrame(()=>{yt(d)("following output to ",{totalCount:T},zt.DEBUG),g(C)}):y=sn(e,()=>{yt(d)("following output to ",{totalCount:T},zt.DEBUG),g(C),y=null})});function b(C){const T=sn(o,I=>{C&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(yt(d)("scrolling to bottom due to increased size",{},zt.DEBUG),g("auto"))});setTimeout(T,100)}Xe(H(bt(Se(x),t,c),Te(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Te(({refreshed:C})=>C),Oe(x,t)),([,C])=>{yt(a)&&b(C!==!1)}),Xe(m,()=>{b(yt(x)!==!1)}),Xe(bt(Se(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=te(null),k=Be();return he(oa(H(Se(r),le(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),H(Se(t))),k),Xe(H(bt(H(k,Qn(1)),l),Oe(Se(S),a,f,p),le(([[C,T],I,A,M,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:M}))),Te(C=>!!C),Nn(0)),C=>{y&&(y(),y=null),yt(n)?requestAnimationFrame(()=>{yt(d)("scrolling into view",{}),Re(h,C)}):y=sn(e,()=>{yt(d)("scrolling into view",{}),Re(h,C),y=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},lt(bn,ro,Qr,eo,$n,Dn,Lt,Xd,Jd)),n0=He(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(H(a,Oe(s),Te(([,l])=>l!==0),Oe(o,r,t,n,e),le(([[,l],c,d,f,p,h=[]])=>qd(l,c,d,f,p,h))),i),{}),lt(bn,eo,nr,$n),{singleton:!0}),r0=He(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=te(0);return Xe(H(e,Oe(r),Te(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{sn(H(n,Qn(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Re(t,o)})})}),{initialScrollTop:r}},lt($n,Lt,nr),{singleton:!0}),Qd=He(([{scrollVelocity:e}])=>{const t=te(!1),n=Be(),r=te(!1);return he(H(e,Oe(r,t,n),Te(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Xe(H(bt(t,e,n),Oe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},lt(ro),{singleton:!0}),xa=He(([{scrollContainerState:e,scrollTo:t}])=>{const n=Be(),r=Be(),o=Be(),s=te(!1),i=te(void 0);return he(H(bt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(H(t,Oe(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Lt)),o0=He(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Be(),d=te(void 0),f=te(null),p=te(null);return he(a,f),he(l,p),Xe(H(c,Oe(t,r,i,f,p,n)),([h,x,m,y,g,b,S])=>{const k=zw(x.sizeTree);y&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),he(H(d,Te(na),le(s0)),o),he(H(s,Oe(d),Te(([,h])=>h!==void 0),ct(),le(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(bn,Lt,eo,$n,xa));function s0(e){return{align:"start",index:0,offset:e.scrollTop}}const i0=He(([{topItemsIndexes:e}])=>{const t=te(0);return he(H(t,Te(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(nr));function ef(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const a0=ef(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),l0=He(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:d,shiftWithOffset:f,sizes:p},{log:h},{recalcInProgress:x}])=>{const m=Vt(H(l,Oe(i),vn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const M=k+T;let L=0;return b===I&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||(L=M-S,L!==0&&(L+=A))),[L,C,I,M]},[0,[],0,0]),Te(([g])=>g!==0),Oe(r,a,n,o,h,x),Te(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===to),le(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},zt.DEBUG),g))));function y(g){g>0?(Re(t,{behavior:"auto",top:-g}),Re(e,0)):(Re(e,0),Re(t,{behavior:"auto",top:-g}))}return Xe(H(m,Oe(e,s)),([g,b,S])=>{S&&a0()?Re(e,b-g):y(-g)}),Xe(H(bt(Nt(s,!1),e,x),Te(([g,b,S])=>!g&&!S&&b!==0),le(([g,b])=>b),Nn(1)),y),he(H(f,le(g=>({top:-g}))),t),Xe(H(c,Oe(p,d),le(([g,{groupIndices:b,lastSize:S,sizeTree:k},C])=>{function T(I){return I*(S+C)}if(b.length===0)return T(g);{let I=0;const A=Xr(k,0);let M=0,L=0;for(;M<g;){M++,I+=A;let P=b.length===L+1?1/0:b[L+1]-b[L]-1;M+P>g&&(I-=A,P=g-M+1),M+=P,I+=T(P),L++}return I}})),g=>{Re(e,g),requestAnimationFrame(()=>{Re(t,{top:g}),requestAnimationFrame(()=>{Re(e,0),Re(x,!1)})})}),{deviation:e}},lt(Lt,ro,nr,bn,Dn,ua)),c0=He(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(ma,n0,$n,Qd,Yd,r0,Zw,xa,Jd,Dn,Xd)),tf=He(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x},m,y,g,{listState:b,topItemsIndexes:S,...k},{scrollToIndex:C},T,{topItemCount:I},{groupCounts:A},M])=>(he(k.rangeChanged,M.scrollSeekRangeChanged),he(H(M.windowViewportRect,le(L=>L.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:p,initialTopMostItemIndex:h,scrolledToInitialItem:x,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...g,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:c,trackItemSizes:f,...k,...M,...m,sizes:l,...y}),lt(bn,eo,Lt,o0,t0,nr,Qr,l0,i0,zd,c0));function u0(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 ws=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(y,g){y.propsReady&&Re(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Re(S,g[b])}for(const b of o)if(b in g){const S=y[t.optional[b]];Re(S,g[b])}y.propsReady&&Re(y.propsReady,!0)}function c(y){return s.reduce((g,b)=>(g[b]=S=>{const k=y[t.methods[b]];Re(k,S)},g),{})}function d(y){return i.reduce((g,b)=>(g[b]=Iw(y[t.events[b]]),g),{})}const f=w.forwardRef((y,g)=>{const{children:b,...S}=y,[k]=w.useState(()=>ps(Aw(e),I=>{l(I,S)})),[C]=w.useState(kd(d,k));ws(()=>{for(const I of i)I in S&&Xe(C[I],S[I]);return()=>{Object.values(C).map(ra)}},[S,C,k]),ws(()=>{l(k,S)}),w.useImperativeHandle(g,Cd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...u0([...r,...o,...i],S),children:b}):b})}),p=y=>{const g=w.useContext(a);return w.useCallback(b=>{Re(g[y],b)},[g,y])},h=y=>{const g=w.useContext(a)[y],b=w.useCallback(S=>Xe(g,S),[g]);return w.useSyncExternalStore(b,()=>yt(g),()=>yt(g))},x=y=>{const g=w.useContext(a)[y],[b,S]=w.useState(kd(yt,g));return ws(()=>Xe(g,k=>{k!==b&&S(Cd(k))}),[g,b]),b},m=w.version.startsWith("18")?h:x;return{Component:f,useEmitter:(y,g)=>{const b=w.useContext(a)[y];ws(()=>Xe(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 ya(e){return"self"in e}function d0(e){return"body"in e}function af(e,t,n,r=Tr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,x,m;const y=p.target;if(d0(y)||ya(y)){const b=ya(y)?y:y.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?y.scrollLeft:y.scrollTop,h=s?y.scrollWidth:y.scrollHeight,x=s?y.offsetWidth:y.offsetHeight;const g=()=>{e({scrollHeight:h,scrollTop:Math.max(m,0),viewportHeight:x})};p.suppressFlushSync?g():Js.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,y,g;ya(h)?(y=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):(y=h[s?"scrollWidth":"scrollHeight"],m=Ln(h,s?"width":"height"),g=h[s?"scrollLeft":"scrollTop"]);const b=y-m;if(p.top=Math.ceil(Math.max(Math.min(b,p.top),0)),Hd(m,y)||p.top===g){e({scrollHeight:y,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 va="-webkit-sticky",lf="sticky",ba=ef(()=>{if(typeof document>"u")return lf;const e=document.createElement("div");return e.style.position=va,e.style.position===va?va:lf});function wa(e){return e}const f0=He(()=>{const e=te(a=>`Item ${a}`),t=te(a=>`Group ${a}`),n=te({}),r=te(wa),o=te("div"),s=te(Tr),i=(a,l=null)=>Nt(H(n,le(c=>c[a]),ct()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),p0=He(([e,t])=>({...e,...t}),lt(tf,f0)),h0=({height:e})=>u.jsx("div",{style:{height:e}}),m0={overflowAnchor:"none",position:ba(),zIndex:1},cf={overflowAnchor:"none"},g0={...cf,display:"inline-block",height:"100%"},uf=w.memo(function({showTopList:e=!1}){const t=Ee("listState"),n=Zt("sizeRanges"),r=Ee("useWindowScroll"),o=Ee("customScrollParent"),s=Zt("windowScrollContainerState"),i=Zt("scrollContainerState"),a=o||r?s:i,l=Ee("itemContent"),c=Ee("context"),d=Ee("groupContent"),f=Ee("trackItemSizes"),p=Ee("itemSize"),h=Ee("log"),x=Zt("gap"),m=Ee("horizontalDirection"),{callbackRef:y}=jw(n,p,f,e?Tr:a,h,x,o,m,Ee("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);Sa("deviation",N=>{g!==N&&b(N)});const S=Ee("EmptyPlaceholder"),k=Ee("ScrollSeekPlaceholder")||h0,C=Ee("ListComponent"),T=Ee("ItemComponent"),I=Ee("GroupComponent"),A=Ee("computeItemKey"),M=Ee("isSeeking"),L=Ee("groupIndices").length>0,P=Ee("alignToBottom"),D=Ee("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,{..._t(S,c)}):u.jsx(C,{..._t(C,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:F,children:(e?t.topItems:t.items).map(N=>{const B=N.originalIndex,j=A(B+t.firstItemIndex,N.data,c);return M?w.createElement(k,{..._t(k,c),height:N.size,index:N.index,key:j,type:N.type||"item",...N.type==="group"?{}:{groupIndex:N.groupIndex}}):N.type==="group"?w.createElement(I,{..._t(I,c),"data-index":B,"data-item-index":N.index,"data-known-size":N.size,key:j,style:m0},d(N.index,c)):w.createElement(T,{..._t(T,c),...b0(T,N.data),"data-index":B,"data-item-group-index":N.groupIndex,"data-item-index":N.index,"data-known-size":N.size,key:j,style:m?g0:cf},L?l(N.index,N.groupIndex,N.data,c):l(N.index,N.data,c))})})}),x0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},y0={outline:"none",overflowX:"auto",position:"relative"},Ss=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),v0={position:ba(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function b0(e,t){return{item:typeof e=="string"?void 0:t}}const w0=w.memo(function(){const e=Ee("HeaderComponent"),t=Zt("headerHeight"),n=Ee("HeaderFooterTag"),r=er(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Ee("skipAnimationFrameInResizeObserver")),o=Ee("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),S0=w.memo(function(){const e=Ee("FooterComponent"),t=Zt("footerHeight"),n=Ee("HeaderFooterTag"),r=er(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,Ee("skipAnimationFrameInResizeObserver")),o=Ee("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(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?y0:x0,...o},tabIndex:0,...i,..._t(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:y,scrollToCallback:g}=af(a,c,l,x,p);return sf(()=>{var b;return y.current=p||((b=h.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,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,..._t(l,s),children:r})})}const C0=({children:e})=>{const t=w.useContext(rf),n=Zt("viewportHeight"),r=Zt("fixedItemHeight"),o=Ee("alignToBottom"),s=Ee("horizontalDirection"),i=w.useMemo(()=>Td(n,l=>Ln(l,s?"width":"height")),[n,s]),a=er(i,!0,Ee("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Ss(o),children:e})},T0=({children:e})=>{const t=w.useContext(rf),n=Zt("windowViewportRect"),r=Zt("fixedItemHeight"),o=Ee("customScrollParent"),s=Nd(n,o,Ee("skipAnimationFrameInResizeObserver")),i=Ee("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:Ss(i),children:e})},k0=({children:e})=>{const t=Ee("TopItemListComponent")||"div",n=Ee("headerHeight"),r={...v0,marginTop:`${n}px`},o=Ee("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},I0=w.memo(function(e){const t=Ee("useWindowScroll"),n=Ee("topItemsIndexes").length>0,r=Ee("customScrollParent"),o=Ee("context");return u.jsxs(r||t?N0:A0,{...e,context:o,children:[n&&u.jsx(k0,{children:u.jsx(uf,{showTopList:!0})}),u.jsxs(r||t?T0:C0,{children:[u.jsx(w0,{}),u.jsx(uf,{}),u.jsx(S0,{})]})]})}),{Component:E0,useEmitter:Sa,useEmitterValue:Ee,usePublisher:Zt}=nf(p0,{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"}},I0),A0=df({useEmitter:Sa,useEmitterValue:Ee,usePublisher:Zt}),N0=ff({useEmitter:Sa,useEmitterValue:Ee,usePublisher:Zt}),_0=E0;lt(tf,He(()=>{const e=te(c=>u.jsxs("td",{children:["Item $",c]})),t=te(null),n=te(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=te(null),o=te(null),s=te({}),i=te(wa),a=te(Tr),l=(c,d=null)=>Nt(H(s,le(f=>f[c]),ct()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),ba();const pf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},j0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:hf,floor:Cs,max:oo,min:Ca,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 R0(e){return{...j0,items:e}}function Ts(e,t){return e&&e.width===t.width&&e.height===t.height}function M0(e,t){return e&&e.column===t.column&&e.row===t.row}const P0=He(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},p,h,{didMount:x,propsReady:m},{customScrollParent:y,useWindowScroll:g,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k},C])=>{const T=te(0),I=te(0),A=te(pf),M=te({height:0,width:0}),L=te({height:0,width:0}),P=Be(),D=Be(),F=te(0),N=te(null),B=te({column:0,row:0}),j=Be(),V=Be(),z=te(!1),R=te(0),K=te(!0),J=te(!1),se=te(!1);Xe(H(x,Oe(R),Te(([$,q])=>!!q)),()=>{Re(K,!1)}),Xe(H(bt(x,K,L,M,R,J),Te(([$,q,Q,ce,,oe])=>$&&!q&&Q.height!==0&&ce.height!==0&&!oe)),([,,,,$])=>{Re(J,!0),pa(1,()=>{Re(P,$)}),sn(H(c),()=>{Re(t,[0,0]),Re(K,!0)})}),he(H(V,Te($=>$!=null&&$.scrollTop>0),yn(0)),I),Xe(H(x,Oe(V),Te(([,$])=>$!=null)),([,$])=>{$&&(Re(M,$.viewport),Re(L,$.item),Re(B,$.gap),$.scrollTop>0&&(Re(z,!0),sn(H(c,Qn(1)),q=>{Re(z,!1)}),Re(l,{top:$.scrollTop})))}),he(H(M,le(({height:$})=>$)),f),he(H(bt(Se(M,Ts),Se(L,Ts),Se(B,($,q)=>$&&$.column===q.column&&$.row===q.row),Se(c)),le(([$,q,Q,ce])=>({gap:Q,item:q,scrollTop:ce,viewport:$}))),j),he(H(bt(Se(T),r,Se(B,M0),Se(L,Ts),Se(M,Ts),Se(N),Se(I),Se(z),Se(K),Se(R)),Te(([,,,,,,,$])=>!$),le(([$,[q,Q],ce,oe,Ae,ze,re,,xe,Me])=>{const{column:Je,row:Ze}=ce,{height:We,width:et}=oe,{width:st}=Ae;if(re===0&&($===0||st===0))return pf;if(et===0){const $t=ha(Me,$),Mt=$t+Math.max(re-1,0);return R0(gf($t,Mt,ze))}const Ke=xf(st,et,Je);let tt,it;xe?q===0&&Q===0&&re>0?(tt=0,it=re-1):(tt=Ke*Cs((q+Ze)/(We+Ze)),it=Ke*hf((Q+Ze)/(We+Ze))-1,it=Ca($-1,oo(it,Ke-1)),tt=Ca(it,oo(0,tt))):(tt=0,it=-1);const Rt=gf(tt,it,ze),{bottom:gt,top:ht}=yf(Ae,ce,oe,Rt),vt=hf($/Ke),wt=vt*We+(vt-1)*Ze-gt;return{bottom:gt,itemHeight:We,items:Rt,itemWidth:et,offsetBottom:wt,offsetTop:ht,top:ht}})),A),he(H(N,Te($=>$!==null),le($=>$.length)),T),he(H(bt(M,L,A,B),Te(([$,q,{items:Q}])=>Q.length>0&&q.height!==0&&$.height!==0),le(([$,q,{items:Q},ce])=>{const{bottom:oe,top:Ae}=yf($,ce,q,Q);return[Ae,oe]}),ct(Jr)),t);const ge=te(!1);he(H(c,Oe(ge),le(([$,q])=>q||$!==0)),ge);const Ie=Vt(H(bt(A,T),Te(([{items:$}])=>$.length>0),Oe(ge),Te(([[$,q],Q])=>{const ce=$.items[$.items.length-1].index===q-1;return(Q||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===q)&&ce}),le(([[,$]])=>$-1),ct())),Y=Vt(H(Se(A),Te(({items:$})=>$.length>0&&$[0].index===0),yn(0),ct())),U=Vt(H(Se(A),Oe(z),Te(([{items:$},q])=>$.length>0&&!q),le(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Dd),Nn(0)));he(U,h.scrollSeekRangeChanged),he(H(P,Oe(M,L,T,B),le(([$,q,Q,ce,oe])=>{const Ae=Ud($),{align:ze,behavior:re,offset:xe}=Ae;let Me=Ae.index;Me==="LAST"&&(Me=ce-1),Me=oo(0,Me,Ca(ce-1,Me));let Je=Ta(q,oe,Q,Me);return ze==="end"?Je=mf(Je-q.height+Q.height):ze==="center"&&(Je=mf(Je-q.height/2+Q.height/2)),xe&&(Je+=xe),{behavior:re,top:Je}})),l);const Z=Nt(H(A,le($=>$.offsetBottom+$.bottom)),0);return he(H(k,le($=>({height:$.visibleHeight,width:$.visibleWidth}))),M),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:D,scrollTo:l,scrollToIndex:P,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:M,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:A,horizontalDirection:se,initialTopMostItemIndex:R,totalListHeight:Z,...p,endReached:Ie,propsReady:m,rangeChanged:U,startReached:Y,stateChanged:j,stateRestoreInProgress:z,...C}},lt(ma,Lt,ro,Qd,$n,xa,Dn));function xf(e,t,n){return oo(1,Cs((e+n)/(Cs(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=Ta(e,t,n,r[0].index);return{bottom:Ta(e,t,n,r[r.length-1].index)+o,top:s}}function Ta(e,t,n,r){const o=xf(e.width,n.width,t.column),s=Cs(r/o),i=s*n.height+oo(0,s-1)*t.row;return i>0?i+t.row:i}const O0=He(()=>{const e=te(f=>`Item ${f}`),t=te({}),n=te(null),r=te("virtuoso-grid-item"),o=te("virtuoso-grid-list"),s=te(wa),i=te("div"),a=te(Tr),l=(f,p=null)=>Nt(H(t,le(h=>h[f]),ct()),p),c=te(!1),d=te(!1);return he(Se(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")}}),D0=He(([e,t])=>({...e,...t}),lt(P0,O0)),L0=w.memo(function(){const e=dt("gridState"),t=dt("listClassName"),n=dt("itemClassName"),r=dt("itemContent"),o=dt("computeItemKey"),s=dt("isSeeking"),i=Qt("scrollHeight"),a=dt("ItemComponent"),l=dt("ListComponent"),c=dt("ScrollSeekPlaceholder"),d=dt("context"),f=Qt("itemDimensions"),p=Qt("gap"),h=dt("log"),x=dt("stateRestoreInProgress"),m=Qt("reportReadyState"),y=er(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:y,..._t(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,{..._t(c,d),height:e.itemHeight,index:g.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":g.index,key:b},r(g.index,g.data,d))})})}),$0=w.memo(function(){const e=dt("HeaderComponent"),t=Qt("headerHeight"),n=dt("headerFooterTag"),r=er(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),F0=w.memo(function(){const e=dt("FooterComponent"),t=Qt("footerHeight"),n=dt("headerFooterTag"),r=er(w.useMemo(()=>s=>{t(Ln(s,"height"))},[t]),!0,!1),o=dt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),B0=({children:e})=>{const t=w.useContext(of),n=Qt("itemDimensions"),r=Qt("viewportDimensions"),o=er(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:Ss(!1),children:e})},z0=({children:e})=>{const t=w.useContext(of),n=Qt("windowViewportRect"),r=Qt("itemDimensions"),o=dt("customScrollParent"),s=Nd(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:Ss(!1),children:e})},U0=w.memo(function({...e}){const t=dt("useWindowScroll"),n=dt("customScrollParent"),r=n||t?W0:H0,o=n||t?z0:B0,s=dt("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx($0,{}),u.jsx(L0,{}),u.jsx(F0,{})]})})}),{useEmitter:vf,useEmitterValue:dt,usePublisher:Qt}=nf(D0,{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"}},U0),H0=df({useEmitter:vf,useEmitterValue:dt,usePublisher:Qt}),W0=ff({useEmitter:vf,useEmitterValue:dt,usePublisher:Qt});function bf(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,zt.WARN),t==="normal"?0:parseInt(t??"0",10)}const V0=mo.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:ne(V0({variant:t}),e),...n})}function ka(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 Sf(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(Sf(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(Sf(e))return"";try{const t=so(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function K0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function q0(e){const t=io(e);return typeof e=="string"&&K0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function ks(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=ka(t);if(n!==null)return ks(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?ks(e.content):e}function G0(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Cf(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 Is(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Y0(e){const t=r=>{try{const o=so(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
87
+ `)):t(e)}function X0(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Tf(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 J0(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function Z0(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function Q0({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=J0(n),i=o?`data:${s};base64,${e}`:t,a=Z0(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function eS(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 Q0({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function kf(e,t){return await Gt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function If(e,t){return await(await kf(`/files/${e}/view`,t)).text()}async function tS(e,t){const n=await kf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Gt(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function nS(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Gt("/files",{params:r})}var Es="Dialog",[Ef,FT]=kn(Es),[rS,ln]=Ef(Es),Af=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=hr({prop:r,defaultProp:o??!1,onChange:s,caller:Es});return u.jsx(rS,{scope:t,triggerRef:a,contentRef:l,contentId:In(),titleId:In(),descriptionId:In(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Af.displayName=Es;var Nf="DialogTrigger",_f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Nf,n),s=Fe(t,o.triggerRef);return u.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Aa(o.open),...r,ref:s,onClick:fe(e.onClick,o.onOpenToggle)})});_f.displayName=Nf;var Ia="DialogPortal",[oS,jf]=Ef(Ia,{forceMount:void 0}),Rf=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=ln(Ia,t);return u.jsx(oS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Xt,{present:n||s.open,children:u.jsx(Yo,{asChild:!0,container:o,children:i})}))})};Rf.displayName=Ia;var As="DialogOverlay",Mf=v.forwardRef((e,t)=>{const n=jf(As,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ln(As,e.__scopeDialog);return s.modal?u.jsx(Xt,{present:r||s.open,children:u.jsx(iS,{...o,ref:t})}):null});Mf.displayName=As;var sS=Kn.createSlot("DialogOverlay.RemoveScroll"),iS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(As,n);return u.jsx(os,{as:sS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":Aa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),rr="DialogContent",Pf=v.forwardRef((e,t)=>{const n=jf(rr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ln(rr,e.__scopeDialog);return u.jsx(Xt,{present:r||s.open,children:s.modal?u.jsx(aS,{...o,ref:t}):u.jsx(lS,{...o,ref:t})})});Pf.displayName=rr;var aS=v.forwardRef((e,t)=>{const n=ln(rr,e.__scopeDialog),r=v.useRef(null),o=Fe(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Ui(s)},[]),u.jsx(Of,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:fe(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:fe(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault())})}),lS=v.forwardRef((e,t)=>{const n=ln(rr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Of,{...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()}})}),Of=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=ln(rr,n),l=v.useRef(null),c=Fe(t,l);return Ci(),u.jsxs(u.Fragment,{children:[u.jsx(Lo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Do,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Aa(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(cS,{titleId:a.titleId}),u.jsx(dS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ea="DialogTitle",Df=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Ea,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Df.displayName=Ea;var Lf="DialogDescription",$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Lf,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});$f.displayName=Lf;var Ff="DialogClose",Bf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ln(Ff,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:fe(e.onClick,()=>o.onOpenChange(!1))})});Bf.displayName=Ff;function Aa(e){return e?"open":"closed"}var zf="DialogTitleWarning",[BT,Uf]=sx(zf,{contentName:rr,titleName:Ea,docsSlug:"dialog"}),cS=({titleId:e})=>{const t=Uf(zf),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
88
88
 
89
89
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
90
90
 
91
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},aS="DialogDescriptionWarning",lS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Ff(aS).contentName}}.`;return v.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Bf=kf,cS=Ef,zf=Nf,Es=_f,As=jf,tr=Mf,Ns=Of,Uf=Lf;const uS=Bf,dS=zf,Hf=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{ref:n,className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Hf.displayName=Es.displayName;const Wf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===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(dS,{children:[u.jsx(Hf,{}),u.jsxs(As,{ref:r,className:te("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(tr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Uf,{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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Wf.displayName=As.displayName;const Vf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Vf.displayName="DialogHeader";const Kf=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Kf.displayName=tr.displayName;const fS=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));fS.displayName=Ns.displayName;const pS=1,hS=1e6;let Ia=0;function mS(){return Ia=(Ia+1)%Number.MAX_SAFE_INTEGER,Ia.toString()}const Ea=new Map,qf=e=>{if(Ea.has(e))return;const t=setTimeout(()=>{Ea.delete(e),oo({type:"REMOVE_TOAST",toastId:e})},hS);Ea.set(e,t)},gS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,pS)};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?qf(n):e.toasts.forEach(r=>{qf(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},_s=[];let js={toasts:[]};function oo(e){js=gS(js,e),_s.forEach(t=>{t(js)})}function xS({...e}){const t=mS(),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 Aa(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:xS,dismiss:n=>oo({type:"DISMISS_TOAST",toastId:n})}}function yS({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}=Aa(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await Cf(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 Z0(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 Cf(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(ae.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(Qe,{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(ae.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(ae.Image,{className:"h-5 w-5"}):u.jsx(ae.FileText,{className:"h-5 w-5"});return u.jsx(uS,{open:e,onOpenChange:t,children:u.jsxs(Wf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Vf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(Kf,{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(Qe,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Qe,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:m()})]})})}function Gf(){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=Gf();function vS(e){nr=e}const Yf=/[&<>"']/,bS=new RegExp(Yf.source,"g"),Xf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,wS=new RegExp(Xf.source,"g"),SS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Jf=e=>SS[e];function jt(e,t){if(t){if(Yf.test(e))return e.replace(bS,Jf)}else if(Xf.test(e))return e.replace(wS,Jf);return e}const CS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zf(e){return e.replace(CS,(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 TS=/(^|[^\[])\^/g;function it(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(TS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const kS=/[^\w:]/g,IS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qf(e,t,n){if(e){let r;try{r=decodeURIComponent(Zf(n)).replace(kS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!IS.test(n)&&(n=_S(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Rs={},ES=/^[^:]+:\/*[^/]*$/,AS=/^([^:]+:)[\s\S]*$/,NS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function _S(e,t){Rs[" "+e]||(ES.test(e)?Rs[" "+e]=e+"/":Rs[" "+e]=Ps(e,"/",!0)),e=Rs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(AS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(NS,"$1")+t:e+t}const Ms={exec:function(){}};function ep(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function Ps(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function jS(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 RS(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 tp(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function np(e,t,n,r){const o=t.href,s=t.title?jt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:jt(i)}}function MS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
91
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return v.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},uS="DialogDescriptionWarning",dS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Uf(uS).contentName}}.`;return v.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Hf=Af,fS=_f,Wf=Rf,Ns=Mf,_s=Pf,or=Df,js=$f,Vf=Bf;const pS=Hf,hS=Wf,Kf=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Kf.displayName=Ns.displayName;const qf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===or||(c==null?void 0:c.displayName)===or.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(hS,{children:[u.jsx(Kf,{}),u.jsxs(_s,{ref:r,className:ne("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(or,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Vf,{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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});qf.displayName=_s.displayName;const Gf=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Gf.displayName="DialogHeader";const Yf=v.forwardRef(({className:e,...t},n)=>u.jsx(or,{ref:n,className:ne("text-lg font-semibold leading-none tracking-tight",e),...t}));Yf.displayName=or.displayName;const mS=v.forwardRef(({className:e,...t},n)=>u.jsx(js,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));mS.displayName=js.displayName;const gS=1,xS=1e6;let Na=0;function yS(){return Na=(Na+1)%Number.MAX_SAFE_INTEGER,Na.toString()}const _a=new Map,Xf=e=>{if(_a.has(e))return;const t=setTimeout(()=>{_a.delete(e),ao({type:"REMOVE_TOAST",toastId:e})},xS);_a.set(e,t)},vS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,gS)};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?Xf(n):e.toasts.forEach(r=>{Xf(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)}}},Rs=[];let Ms={toasts:[]};function ao(e){Ms=vS(Ms,e),Rs.forEach(t=>{t(Ms)})}function bS({...e}){const t=yS(),n=o=>ao({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>ao({type:"DISMISS_TOAST",toastId:t});return ao({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function ja(){const[e,t]=v.useState(Ms);return v.useEffect(()=>(Rs.push(t),()=>{const n=Rs.indexOf(t);n>-1&&Rs.splice(n,1)}),[e]),{...e,toast:bS,dismiss:n=>ao({type:"DISMISS_TOAST",toastId:n})}}function wS({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}=ja(),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 tS(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(ae.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(Ye,{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(ae.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),y=()=>o.startsWith("image/")?u.jsx(ae.Image,{className:"h-5 w-5"}):u.jsx(ae.FileText,{className:"h-5 w-5"});return u.jsx(pS,{open:e,onOpenChange:t,children:u.jsxs(qf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Gf,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[y(),u.jsxs("div",{children:[u.jsx(Yf,{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(Ye,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ye,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(ae.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 sr=Jf();function SS(e){sr=e}const Zf=/[&<>"']/,CS=new RegExp(Zf.source,"g"),Qf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,TS=new RegExp(Qf.source,"g"),kS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ep=e=>kS[e];function jt(e,t){if(t){if(Zf.test(e))return e.replace(CS,ep)}else if(Qf.test(e))return e.replace(TS,ep);return e}const IS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function tp(e){return e.replace(IS,(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 ES=/(^|[^\[])\^/g;function ot(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(ES,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const AS=/[^\w:]/g,NS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function np(e,t,n){if(e){let r;try{r=decodeURIComponent(tp(n)).replace(AS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!NS.test(n)&&(n=MS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Ps={},_S=/^[^:]+:\/*[^/]*$/,jS=/^([^:]+:)[\s\S]*$/,RS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function MS(e,t){Ps[" "+e]||(_S.test(e)?Ps[" "+e]=e+"/":Ps[" "+e]=Ds(e,"/",!0)),e=Ps[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(jS,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(RS,"$1")+t:e+t}const Os={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 Ds(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 PS(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 OS(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?jt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:jt(i)}}function DS(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
92
92
  `).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
93
- `)}class Na{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:Ps(r,`
94
- `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=MS(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=Ps(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,d,f,p,h,x,m=n[1].trim();const y=m.length>1,g={type:"list",raw:"",ordered:y,start:y?+m.slice(0,-1):"",loose:!1,items:[]};m=y?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=y?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(`
93
+ `)}class Ra{constructor(t){this.options=t||sr}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:Ds(r,`
94
+ `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=DS(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=Ds(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 y=m.length>1,g={type:"list",raw:"",ordered:y,start:y?+m.slice(0,-1):"",loose:!1,items:[]};m=y?`\\d{1,9}\\${m.slice(-1)}`:`\\${m}`,this.options.pedantic&&(m=y?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(`
95
95
  `,1)[0].replace(/^\t+/,k=>" ".repeat(3*k.length)),f=t.split(`
96
96
  `,1)[0],this.options.pedantic?(i=2,h=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,h=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
97
97
  `,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)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(p=t.split(`
98
98
  `,1)[0],f=p,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||I.test(f)||k.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())h+=`
99
99
  `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||C.test(d))break;h+=`
100
100
  `+f}!l&&!f.trim()&&(l=!0),r+=p+`
101
- `,t=t.substring(p.length+1),d=f.slice(i)}}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]):jt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:ep(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
102
- `):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=ep(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
103
- `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:jt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ps(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=jS(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)),np(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 np(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=jt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=jt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=jt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=jt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=jt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):jt(r[0]):r[0]:o=jt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ge={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:Ms,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ge._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ge._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ge.def=it(ge.def).replace("label",ge._label).replace("title",ge._title).getRegex(),ge.bullet=/(?:[*+-]|\d{1,9}[.)])/,ge.listItemStart=it(/^( *)(bull) */).replace("bull",ge.bullet).getRegex(),ge.list=it(ge.list).replace(/bull/g,ge.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ge.def.source+")").getRegex(),ge._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",ge._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ge.html=it(ge.html,"i").replace("comment",ge._comment).replace("tag",ge._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ge.paragraph=it(ge._paragraph).replace("hr",ge.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",ge._tag).getRegex(),ge.blockquote=it(ge.blockquote).replace("paragraph",ge.paragraph).getRegex(),ge.normal={...ge},ge.gfm={...ge.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ge.gfm.table=it(ge.gfm.table).replace("hr",ge.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",ge._tag).getRegex(),ge.gfm.paragraph=it(ge._paragraph).replace("hr",ge.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ge.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",ge._tag).getRegex(),ge.pedantic={...ge.normal,html:it(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ge._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:Ms,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:it(ge.normal._paragraph).replace("hr",ge.hr).replace("heading",` *#{1,6} *[^
104
- ]`).replace("lheading",ge.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ue={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Ms,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:Ms,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ue._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ue.punctuation=it(ue.punctuation).replace(/punctuation/g,ue._punctuation).getRegex(),ue.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ue.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ue._comment=it(ge._comment).replace("(?:-->|$)","-->").getRegex(),ue.emStrong.lDelim=it(ue.emStrong.lDelim).replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimAst=it(ue.emStrong.rDelimAst,"g").replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimUnd=it(ue.emStrong.rDelimUnd,"g").replace(/punct/g,ue._punctuation).getRegex(),ue._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ue._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ue._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])?)+(?![-_])/,ue.autolink=it(ue.autolink).replace("scheme",ue._scheme).replace("email",ue._email).getRegex(),ue._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ue.tag=it(ue.tag).replace("comment",ue._comment).replace("attribute",ue._attribute).getRegex(),ue._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ue._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ue._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ue.link=it(ue.link).replace("label",ue._label).replace("href",ue._href).replace("title",ue._title).getRegex(),ue.reflink=it(ue.reflink).replace("label",ue._label).replace("ref",ge._label).getRegex(),ue.nolink=it(ue.nolink).replace("ref",ge._label).getRegex(),ue.reflinkSearch=it(ue.reflinkSearch,"g").replace("reflink",ue.reflink).replace("nolink",ue.nolink).getRegex(),ue.normal={...ue},ue.pedantic={...ue.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:it(/^!?\[(label)\]\((.*?)\)/).replace("label",ue._label).getRegex(),reflink:it(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ue._label).getRegex()},ue.gfm={...ue.normal,escape:it(ue.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},ue.gfm.url=it(ue.gfm.url,"i").replace("email",ue.gfm._extended_email).getRegex(),ue.breaks={...ue.gfm,br:it(ue.br).replace("{2,}","*").getRegex(),text:it(ue.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function PS(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 rp(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 Dn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||nr,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:ge.normal,inline:ue.normal};this.options.pedantic?(n.block=ge.pedantic,n.inline=ue.pedantic):this.options.gfm&&(n.block=ge.gfm,this.options.breaks?n.inline=ue.breaks:n.inline=ue.gfm),this.tokenizer.rules=n}static get rules(){return{block:ge,inline:ue}}static lex(t,n){return new Dn(n).lex(t)}static lexInline(t,n){return new Dn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
101
+ `,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]):jt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header: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(`
102
+ `):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=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)===`
103
+ `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:jt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):jt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=Ds(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=PS(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=jt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=jt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=jt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=jt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=jt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):jt(r[0]):r[0]:o=jt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ye={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:Os,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ye._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ye._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ye.def=ot(ye.def).replace("label",ye._label).replace("title",ye._title).getRegex(),ye.bullet=/(?:[*+-]|\d{1,9}[.)])/,ye.listItemStart=ot(/^( *)(bull) */).replace("bull",ye.bullet).getRegex(),ye.list=ot(ye.list).replace(/bull/g,ye.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ye.def.source+")").getRegex(),ye._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ye._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ye.html=ot(ye.html,"i").replace("comment",ye._comment).replace("tag",ye._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ye.paragraph=ot(ye._paragraph).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ye._tag).getRegex(),ye.blockquote=ot(ye.blockquote).replace("paragraph",ye.paragraph).getRegex(),ye.normal={...ye},ye.gfm={...ye.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ye.gfm.table=ot(ye.gfm.table).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ye._tag).getRegex(),ye.gfm.paragraph=ot(ye._paragraph).replace("hr",ye.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ye.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ye._tag).getRegex(),ye.pedantic={...ye.normal,html:ot(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ye._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Os,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ot(ye.normal._paragraph).replace("hr",ye.hr).replace("heading",` *#{1,6} *[^
104
+ ]`).replace("lheading",ye.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const de={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Os,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:Os,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};de._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",de.punctuation=ot(de.punctuation).replace(/punctuation/g,de._punctuation).getRegex(),de.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,de.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,de._comment=ot(ye._comment).replace("(?:-->|$)","-->").getRegex(),de.emStrong.lDelim=ot(de.emStrong.lDelim).replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimAst=ot(de.emStrong.rDelimAst,"g").replace(/punct/g,de._punctuation).getRegex(),de.emStrong.rDelimUnd=ot(de.emStrong.rDelimUnd,"g").replace(/punct/g,de._punctuation).getRegex(),de._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,de._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,de._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,de.autolink=ot(de.autolink).replace("scheme",de._scheme).replace("email",de._email).getRegex(),de._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,de.tag=ot(de.tag).replace("comment",de._comment).replace("attribute",de._attribute).getRegex(),de._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,de._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,de._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,de.link=ot(de.link).replace("label",de._label).replace("href",de._href).replace("title",de._title).getRegex(),de.reflink=ot(de.reflink).replace("label",de._label).replace("ref",ye._label).getRegex(),de.nolink=ot(de.nolink).replace("ref",ye._label).getRegex(),de.reflinkSearch=ot(de.reflinkSearch,"g").replace("reflink",de.reflink).replace("nolink",de.nolink).getRegex(),de.normal={...de},de.pedantic={...de.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:ot(/^!?\[(label)\]\((.*?)\)/).replace("label",de._label).getRegex(),reflink:ot(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",de._label).getRegex()},de.gfm={...de.normal,escape:ot(de.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},de.gfm.url=ot(de.gfm.url,"i").replace("email",de.gfm._extended_email).getRegex(),de.breaks={...de.gfm,br:ot(de.br).replace("{2,}","*").getRegex(),text:ot(de.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function LS(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 Fn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||sr,this.options.tokenizer=this.options.tokenizer||new Ra,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ye.normal,inline:de.normal};this.options.pedantic?(n.block=ye.pedantic,n.inline=de.pedantic):this.options.gfm&&(n.block=ye.gfm,this.options.breaks?n.inline=de.breaks:n.inline=de.gfm),this.tokenizer.rules=n}static get rules(){return{block:ye,inline:de}}static lex(t,n){return new Fn(n).lex(t)}static lexInline(t,n){return new Fn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
105
105
  `),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
106
106
  `:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
107
107
  `+r.raw,o.text+=`
@@ -111,7 +111,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
111
111
  `+r.raw,o.text+=`
112
112
  `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
113
113
  `+r.raw,o.text+=`
114
- `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,l,c;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+tp("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)+"["+tp("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,rp)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,rp))){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,PS)){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 _a{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
+ `+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,LS)){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 Ma{constructor(t){this.options=t||sr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
115
115
  `,o?'<pre><code class="'+this.options.langPrefix+jt(o)+'">'+(r?t:jt(t,!0))+`</code></pre>
116
116
  `:"<pre><code>"+(r?t:jt(t,!0))+`</code></pre>
117
117
  `}blockquote(t){return`<blockquote>
@@ -131,7 +131,7 @@ ${t}</blockquote>
131
131
  `}tablerow(t){return`<tr>
132
132
  ${t}</tr>
133
133
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
134
- `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Qf(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=Qf(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 op{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 sp{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 Ln{constructor(t){this.options=t||nr,this.options.renderer=this.options.renderer||new _a,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new op,this.slugger=new sp}static parse(t,n){return new Ln(n).parse(t)}static parseInline(t,n){return new Ln(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,x,m,y,g,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,Zf(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,y=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),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):g+=C),g+=this.parse(b.tokens,y),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<I&&t[o+1].type==="text";)h=t[++o],p+=`
135
- `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const A='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Os{constructor(t){this.options=t||nr}preprocess(t){return t}postprocess(t){return t}}Bh(Os,"passThroughHooks",new Set(["preprocess","postprocess"]));function OS(e,t,n){return r=>{if(r.message+=`
136
- Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ip(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=OS(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(RS(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&&me.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;me.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(me.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&&me.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function me(e,t,n){return ip(Dn.lex,Ln.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},vS(me.defaults),me},me.getDefaults=Gf,me.defaults=nr,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.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=me.defaults.renderer||new _a;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=me.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=me.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(me.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=me.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}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=ip(Dn.lexInline,Ln.parseInline),me.Parser=Ln,me.parser=Ln.parse,me.Renderer=_a,me.TextRenderer=op,me.Lexer=Dn,me.lexer=Dn.lex,me.Tokenizer=Na,me.Slugger=sp,me.Hooks=Os,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,Ln.parse,Dn.lex;function so({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof me.parse=="function"?me.parse(i):me(i)}return typeof me.parse=="function"?me.parse(e):me(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 DS={MODE:"library"};function LS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?DS: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 $S(){return!LS()}function FS(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function BS(){return $S()||FS()}function zS({preview:e,idx:t}){return w.useEffect(()=>{BS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const US="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 ap({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:US,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function HS({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Qe,{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(Qe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function WS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Aa(),[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 y,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 Q0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof I.size=="number"?I.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"}),(y=k.update)==null||y.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 VS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Qe,{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(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function KS({message:e,viewMode:t}){const r=bf(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(ap,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=W0(c);return f?u.jsx(so,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function qS({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 Ds=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:R=null,messageParentCheckpointId:$=null}){const[P,O]=w.useState(!1),[F,N]=w.useState("preview"),[B,M]=w.useState(!1),{currentThreadId:Q}=_o(),{respondToInterrupt:z}=jo(),_=l==="phone"||l==="half-screen",V=t.role,Y=V==="tool",oe=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!oe,Me=!(r&&V!=="user"),{uploadingFiles:G,handleFileClick:U,fileViewerOpen:X,currentFileInfo:L,closeFileViewer:K}=WS({allowFileOpen:Me,currentThreadId:Q}),Z=w.useMemo(()=>{switch(V){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))]"}},[V]),ce=w.useMemo(()=>{if(oe)return"";const j=t.content;return Array.isArray(j)?V0(j):""},[oe,t]),re=w.useMemo(()=>{if(oe)return{};const j=t.content;return Array.isArray(j)?bf(t):{}},[oe,t]),je=w.useMemo(()=>{if(oe)return[];const j=t.content;return Array.isArray(j)?j.filter(J=>J.type==="image_url"):[]},[oe,t]),Ue=w.useMemo(()=>{if(oe)return[];const j=t.content;return Array.isArray(j)?j.filter(J=>J.type==="file"):[]},[oe,t]),De=w.useMemo(()=>{if(oe)return[];const j=t.content;return Array.isArray(j)?j.filter(J=>J.type==="interrupt"):[]},[oe,t]),Ge=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ve=Ts(Ge),tt=b==null?void 0:b.value,Ye=w.useMemo(()=>{if(oe)return"";const j=t.content;return Array.isArray(j)?K0(j):""},[oe,t]),ie=w.useMemo(()=>{if(oe||!p)return[];const J=t.artifact;if(!J)return[];const ne=[],pe=[...Array.isArray(J.plots)?J.plots:[]];for(const Ae of pe){const be=J0(Ae);be&&ne.push(be)}return ne},[oe,t,p]),xe=w.useCallback(async()=>{const j=Y?Ye:ce;async function J(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const pe=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":pe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await J(j),O(!0),setTimeout(()=>O(!1),2e3),g==null||g(j)}catch(ne){console.error("Failed to copy:",ne)}},[Y,Ye,ce,g]),He=w.useCallback(()=>{if(!x)return;const j=Y?Ye:ce,J="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,j,J)},[x,t.id,Y,Ye,ce,t]),We=w.useCallback(()=>{m==null||m(n)},[m,n]),rt=w.useCallback(()=>{const J=te(_?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(V){case"user":return u.jsx(ae.User,{className:J});case"assistant":return u.jsx(ae.Bot,{className:J});case"tool":return u.jsx(ae.Wrench,{className:J});default:return u.jsx(ae.Bot,{className:J})}},[_,Z,V]),at=w.useCallback(()=>{const j="group relative mb-4 flex w-full";switch(V){case"user":return te(j,"justify-end");case"assistant":case"tool":case"system":return te(j,"justify-start");default:return j}},[V]),Rt=w.useCallback(()=>{const j=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",_&&"px-3 py-2 text-sm");if(ye)return te(j,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(V){case"user":return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(j,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(j,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[_,ye,V]),gt=w.useCallback(async j=>{if(S)return;const J=Ts((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!J){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await z(J,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async j=>{if(S)return;const J=Ts((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!J){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await z(J,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:j,i:J})=>{if(j.type==="text"){const ne=j.text??"",pe=ne.trim(),Ae=Sa(pe);return Ae&&V!=="tool"?u.jsx(ap,{data:Ae},J):V==="user"&&c&&pe.length>d?u.jsx(VS,{text:pe,expanded:B,onExpandedChange:M,previewLength:d,isCompact:_},J):u.jsx(so,{content:ne,allowHtml:!1},J)}if(j.type==="image_url"){const ne=j;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},J)}if(j.type==="file"){const ne=j,pe=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:Ae=>U(Ae.nativeEvent,ne,J),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:[G[J]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,G[J]?" (processing)":""]})]},J)}if(j.type==="interrupt"){const ne=j,pe=Ts((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),Ae=!!(Ve&&pe&&pe===Ve),be=Ae?tt??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,Fe=pe?{...ne,id:pe,interrupt_id:pe}:ne;return u.jsx(HS,{interruptPart:Fe,onApprove:gt,onReject:ht,disabled:S,isActive:Ae,payload:be},J)}return null},[U,G,gt,ht,V,c,d,B,_,Ve,tt,b,S,De]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const j=ce.trim().length>0||je.length>0||Ue.length>0||De.length>0;if(!Y&&Ue.length>0&&!r)return St();if(!Y&&!j&&!r)return null;if(Y)return!f&&ie.length>0?null:f?u.jsx(KS,{message:t,viewMode:F},t.id):null;if(!Y&&!oe){const J=t,ne=u.jsx("div",{className:"space-y-2",children:J.content.map((pe,Ae)=>u.jsx(bt,{part:pe,i:Ae},Ae))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(qS,{className:Z})]}):ne}},[ce,je.length,Ue.length,De.length,r,Y,F,f,ie.length,St,Z]),Mt=w.useMemo(()=>oe?"Assistant":q0(t),[oe,t]),nt=w.useMemo(()=>oe?[]:Array.isArray(T)?T:[],[T,oe]),It=w.useMemo(()=>{var j;return nt.length?R&&nt.some(J=>J.id===R)?R:((j=nt[0])==null?void 0:j.id)??null:null},[R,nt]),Je=w.useMemo(()=>!nt.length||!I?null:nt.some(j=>j.id===I)?I:null,[I,nt])??It,Ze=V==="user"&&nt.length>0&&typeof A=="function",pt=w.useCallback((j,J=!1)=>{if(!A)return;const ne=(j==null?void 0:j.id)??null,pe=(j==null?void 0:j.parentId)??$??null;A(ne,pe,J)},[$,A]),lt=w.useMemo(()=>Je?nt.findIndex(j=>j.id===Je):-1,[Je,nt]),q=w.useMemo(()=>lt<0?null:nt[lt]??null,[lt,nt]);return Y&&!f&&ie.length===0?null:ye&&oe?u.jsx("div",{className:te(at(),h.container),children:u.jsxs("div",{className:te(Rt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:oe.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(at(),h.container),children:u.jsxs("div",{className:te(Rt(),h.content),children:[(i||a||Y)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",_&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[rt(),a&&Mt&&u.jsx("span",{className:te("font-medium",_?"text-xs":"text-sm"),children:Mt}),Y&&u.jsxs(yf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",_&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(j=>j==="expanded"?"preview":"expanded"),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),N(J=>J==="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(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ze&&q&&lt>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt<nt.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(lt>=nt.length-1)return;const j=nt[lt+1];j&&pt(j)},"aria-label":"Older checkpoint (back in time)",disabled:lt>=nt.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[nt.length-lt," / ",nt.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(lt<=0))if(lt===1)pt(null,!0);else{const j=nt[lt-1];j&&pt(j,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:lt<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,_&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&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(Qe,{variant:"ghost",size:"sm",onClick:()=>xe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,_&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:te(P?"text-success":Z,_?"h-3 w-3":"h-4 w-4")})})}),V==="user"&&x&&u.jsx(Qe,{variant:"ghost",size:"sm",onClick:He,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,_&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:te(Z,_?"h-3 w-3":"h-4 w-4")})}),V==="assistant"&&m&&u.jsx(Qe,{variant:"ghost",size:"sm",onClick:We,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,_&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:te(Z,_?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),p&&ie.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:ie.map((j,J)=>u.jsx(zS,{preview:j,idx:J},`artifact-${J}`))})]}),Y&&F==="expanded"&&(re.toolCallId||re.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",_&&"text-xs"),children:[re.name&&u.jsxs("div",{children:["Function: ",re.name]}),re.toolCallId&&u.jsxs("div",{children:["Call ID: ",re.toolCallId]})]}),!(i||a||Y)&&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(Qe,{variant:"ghost",size:"sm",onClick:()=>xe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:te(P?"text-success":"text-current",_?"h-3 w-3":"h-4 w-4")})}),V==="user"&&x&&u.jsx(Qe,{variant:"ghost",size:"sm",onClick:He,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:te("text-current",_?"h-3 w-3":"h-4 w-4")})}),V==="assistant"&&m&&u.jsx(Qe,{variant:"ghost",size:"sm",onClick:We,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:te("text-current",_?"h-3 w-3":"h-4 w-4")})})]})]})}),L&&u.jsx(yS,{isOpen:X,onClose:K,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&&wf(e.message)===wf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].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});Ds.displayName="MessageComponent";const GS=({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(ae.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};function YS(e,t){return w.useMemo(()=>{var d,f,p,h,x;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.responseMetadata??{};const g=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(g==null?void 0:g.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(g==null?void 0:g.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&g&&(r=[g]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(x=t.checkpointMetaById)==null?void 0:x.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const up=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=up(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:$,defaultCheckpointId:P,attemptMeta:O}=YS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!R?t.additionalKwargs??{}:{},N=t&&!R?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointCandidates:$,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:P,messageParentCheckpointId:B,attemptMeta:O})})});dp.displayName="MessageRow";const 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:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:$,userMessageIdToAttempts:P,activeCheckpointId:O,onSelectCheckpoint:F,timelineCheckpoints:N,messagePreviews:B,createSyntheticThinkingMessage:M=!1},Q)=>{const z=w.useRef(null),_=w.useRef(null),V=w.useRef(!1),Y=w.useRef(!1),[oe,ye]=w.useState(!0),Me=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(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),G=w.useMemo(()=>{if(!b||Me)return null;const ie=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const He=b.value;if(He&&typeof He=="object"&&!Array.isArray(He)){const We=He.title;typeof We=="string"&&We.trim()&&(xe=We.trim())}return{id:`interrupt-${ie}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:ie,value:He,title:xe}]}},[b,Me]),U=w.useMemo(()=>G?[...e,G]:e,[e,G]),X=w.useMemo(()=>!M||!t?U:!U.some(xe=>xe.role==="assistant")&&U.length>0?[...U,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:U,[U,t,M]),L=w.useMemo(()=>T?X:X.filter(ie=>(ie==null?void 0:ie.role)!=="tool"),[X,T]),K=w.useCallback(ie=>{ye(ie),y&&y(!ie),g&&g(ie)},[y,g]),Z=w.useMemo(()=>{if(a)return async()=>{if(!V.current){V.current=!0;try{await a()}finally{V.current=!1}}}},[a]),ce=w.useMemo(()=>!x||m?!1:oe?"auto":!1,[oe,x,m]),re=N??[],je=re.length>0,Ue=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]),De=je?u.jsx(GS,{timelineEntries:re,activeCheckpointId:O??null,onSelectCheckpoint:F,messagePreviews:B}):null,Ge=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Ve=()=>Ue?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Ue,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),tt=L.length,Ye=tt>0;return w.useEffect(()=>{var ie,xe;if(tt===0){Y.current=!1;return}Y.current||(Y.current=!0,z.current?(xe=(ie=z.current).scrollToIndex)==null||xe.call(ie,{index:0,align:"start",behavior:"auto"}):_.current&&(_.current.scrollTop=0))},[tt]),w.useImperativeHandle(Q,()=>({scrollToLatest:()=>{var ie,xe;if(z.current&&L.length>0){const He=L.length-1;(xe=(ie=z.current).scrollToIndex)==null||xe.call(ie,{index:He,align:"end",behavior:"auto"})}else _.current&&(_.current.scrollTop=_.current.scrollHeight)},scrollToTop:()=>{var ie,xe;z.current&&L.length>0?(xe=(ie=z.current).scrollToIndex)==null||xe.call(ie,{index:0,align:"start",behavior:"auto"}):_.current&&(_.current.scrollTop=0)}}),[L]),u.jsxs("div",{className:Ge,style:p,children:[De,u.jsx("div",{className:"relative flex-1 min-h-0",children:Ye?u.jsx(E0,{ref:ie=>{z.current=ie},scrollerRef:ie=>{_.current=ie instanceof HTMLDivElement?ie:null},data:L,followOutput:ce,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{Z&&Z()},atBottomStateChange:K,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(ie,xe)=>up(xe,ie),itemContent:(ie,xe)=>u.jsx(dp,{message:xe,index:ie,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:$,userMessageIdToAttempts:P,activeCheckpointId:O,onSelectCheckpoint:F})}):Ve()})]})});ja.displayName="MessageList";const fp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:y}=ui(),{currentThreadId:g}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:R,interrupt:$,metadata:P,timelineCheckpoints:O,messagePreviews:F}=jo(),{isStreaming:N,error:B,connectionState:M,submit:Q,stop:z}=ac(),_=b??g??null,V=(A==null?void 0:A.id)??null,Y=(A==null?void 0:A.namespace)??null,oe=(P==null?void 0:P.assemblingMessageId)??null,ye=$,[Me,G]=w.useState(!1);w.useEffect(()=>{ye||G(!1)},[ye]);const U=w.useCallback(()=>{G(!0)},[]),X=w.useCallback(()=>{G(!1)},[]),L=!!ye||Me,[K,Z]=w.useState(null),[ce,re]=w.useState(""),[je,Ue]=w.useState(null),[De,Ge]=w.useState(null),[Ve,tt]=w.useState([]),[Ye,ie]=w.useState(0),[xe,He]=w.useState(0),[We,rt]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),nt=w.useRef(!1),[It,bn]=w.useState(()=>fp.value),Je=w.useRef(It),Ze=w.useRef(null),pt=w.useCallback(fe=>{fp.value=fe,bn(fe)},[]),[lt,q]=w.useState(!1),j=w.useRef(null),{checkpointMetaById:J,checkpointIndexByKey:ne,attemptMetaById:pe,userMessageIdToAttempts:Ae}=hw(R),be=O??[],Fe=w.useRef(null),Pe=w.useRef(null),Ne=w.useCallback(()=>{Fe.current&&(Fe.current.value=""),Pe.current&&(Pe.current.value=""),ie(fe=>fe+1),He(fe=>fe+1)},[]),Vt=w.useCallback(fe=>{pt(fe)},[pt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(tt([]),Ne()),En.current=N},[N,Ne]);const[ir,Ar]=w.useState("desktop");w.useEffect(()=>{const fe=()=>{const we=window.innerWidth;Ar(we<640?"phone":we<1024?"tablet":"desktop")};return fe(),window.addEventListener("resize",fe),()=>window.removeEventListener("resize",fe)},[]),w.useEffect(()=>{nt.current=!1},[_]),w.useEffect(()=>{Je.current=It},[It]),w.useEffect(()=>{if(!K){Ze.current=null;return}Ze.current===null&&(Ze.current=Je.current),pt(ce??"")},[ce,K,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const ke=(await y.getAgent("default")).uiDefaultMessage||"";Mt(ke||null)}catch(we){console.warn("Failed to fetch default message:",we),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const fo=fe=>{if(fe.length>cs)return`Message too long (${fe.length}/${cs} characters)`;try{return xw(fe),null}catch(we){return(we==null?void 0:we.message)||"Invalid message"}},zn=async fe=>{const we=fe.trim();if(!(!we&&Ve.length===0)){if(we){const ke=fo(we);if(ke){Ge(ke);return}}try{const ke=K?(je==null?void 0:je.checkpointId)??V??void 0:V??void 0,Ke=K?(je==null?void 0:je.checkpointNs)??Y??void 0:Y??void 0;await Q({text:we||"",attachments:Ve},{checkpointId:ke,checkpointNs:Ke,edit:!!K,originalMessageId:K??void 0}),h==null||h(we),pt(""),Ge(null),tt([]),Ne(),Z(null),re(""),Ue(null)}catch(ke){const Ke=(ke==null?void 0:ke.message)||"Failed to send message";Ge(Ke),m==null||m(Ke)}}},ar=w.useCallback((fe,we,ke)=>{c&&(Ze.current=It,Z(fe),re(we),pt(we),Ge(null),Ue({checkpointId:(ke==null?void 0:ke.checkpointId)??null,checkpointNs:(ke==null?void 0:ke.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Z(null),re(""),Ue(null),Ge(null),pt(Ze.current??It),Ze.current=null},[It,pt]),W=w.useCallback((fe,we,ke)=>{ar(fe,we,ke)},[ar]),se=w.useCallback(fe=>{let we=null;for(let tn=fe-1;tn>=0;tn--)if(S[tn].role==="user"){we=S[tn];break}if(!we)return;const ke=Array.isArray(we.content)?we.content:[],Un=ke.filter(tn=>(tn==null?void 0:tn.type)==="text").map(tn=>tn.text).join("")||(()=>{try{return JSON.stringify(ke,null,2)}catch{return String(ke)}})();Un&&Q({text:Un},{checkpointId:V??void 0,checkpointNs:Y??void 0,edit:!0,originalMessageId:we.id})},[S,Q,V,Y]),ve=fe=>{const we=Array.from(fe.target.files||[]);tt(ke=>[...ke,...we]),fe.target.value=""},Xe=fe=>{tt(we=>{const ke=we.filter((Ke,Un)=>fe!==Un);return ke.length===0&&Ne(),ke})},ot=async fe=>{const we=(fe.target.files||[])[0];if(we){Rt(null),ht(null),rt(!0);try{await Q({attachments:[we]},{checkpointId:V??void 0,checkpointNs:Y??void 0});const ke=`Uploaded ${we.name} - processing through chat stream`;ht(ke)}catch(ke){const Ke=ke instanceof Error?ke.message:"Failed to upload Excel file";console.error("Excel upload failed",ke),Rt(Ke),m==null||m(Ke)}finally{rt(!1),fe.target.value="",Ne()}}},$e=async fe=>{if(g){q(!0);try{if(!fe){await I(),requestAnimationFrame(()=>{var Ke;(Ke=j.current)==null||Ke.scrollToLatest()});return}const we=R.find(Ke=>Ke.checkpointId===fe),ke=(we==null?void 0:we.checkpointNs)??null;await T(fe,ke),requestAnimationFrame(()=>{var Ke;(Ke=j.current)==null||Ke.scrollToTop()})}finally{q(!1)}}},Le=w.useCallback(async(fe,we,ke)=>{await $e(ke?null:fe)},[$e]),Et=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,xt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:Et,children:[!!B&&!bt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Qe,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:j,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:oe,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ir,enableMessageEditing:c,editingMessageId:K,onEdit:W,onRegenerate:se,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:lt,activeInterrupt:ye,disableInterruptActions:Me,onInterruptActionStart:U,onInterruptActionEnd:X,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:J,checkpointIndexByKey:ne,attemptMetaById:pe,userMessageIdToAttempts:Ae,activeCheckpointId:V,onSelectCheckpoint:Le,timelineCheckpoints:be,messagePreviews:F}),(M==="reconnecting"||M==="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(ae.Loader2,{className:"h-3 w-3 animate-spin"}),M==="reconnecting"?"Reconnecting…":"Connecting…"]})}),M==="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(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||lt)&&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(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[K&&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(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Qe,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.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:Fe,type:"file",multiple:!0,onChange:fe=>ve(fe),className:"hidden"},Ye),Ve.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Ve.map((fe,we)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:fe.name}),u.jsx(Qe,{variant:"ghost",size:"sm",onClick:()=>Xe(we),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${fe.name}`,children:u.jsx(ae.X,{size:12})})]},we))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Pe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:ot,className:"hidden"},xe),We&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!We&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!We&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),De&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:De}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(ew,{children:[u.jsx(tw,{asChild:!0,children:u.jsx(Qe,{type:"button",size:"icon",variant:"outline",disabled:N||L,title:"More input actions",className:p.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Zi,{onClick:()=>{var fe;return(fe=Fe.current)==null?void 0:fe.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Zi,{onClick:()=>{var fe;We||(fe=Pe.current)==null||fe.click()},className:`cursor-pointer ${We?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(tx,{initialValue:ce,editingMessageId:K,value:It,onValueChange:Vt,placeholder:K?"Edit your message...":t,isStreaming:N,disabled:L,maxLength:cs,onSend:zn,onCancelEdit:E,onStop:z,allowEmptySend:Ve.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${K?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${De?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));$s.displayName="Input";function Ra(e,[t,n]){return Math.min(n,Math.max(t,e))}function XS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[pp,FT]=Sn(Ma),[JS,Qt]=pp(Ma),hp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),R=Be(t,P=>l(P)),$=Mo(o);return u.jsx(JS,{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:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ee.div,{dir:$,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hp.displayName=Ma;var mp="ScrollAreaViewport",gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(mp,n),a=v.useRef(null),l=Be(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(Ee.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})})]})});gp.displayName=mp;var vn="ScrollAreaScrollbar",Pa=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(QS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(xp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Oa,{...r,ref:t}):null});Pa.displayName=vn;var ZS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Yt,{present:n||s,children:u.jsx(xp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),QS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=XS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Yt,{present:n||a!=="hidden",children:u.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),xp=v.forwardRef((e,t)=>{const n=Qt(vn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Yt,{present:r||s,children:u.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(vn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Sp(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 sC(p,i.current,a,h)}return n==="horizontal"?u.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Cp(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(tC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Cp(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}),eC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),tC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[nC,yp]=pp(vn),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=Qt(vn,n),[x,m]=v.useState(null),y=Be(t,R=>m(R)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function A(R){if(g.current){const $=R.clientX-g.current.left,P=R.clientY-g.current.top;c({x:$,y:P})}}return v.useEffect(()=>{const R=$=>{const P=$.target;(x==null?void 0:x.contains(P))&&C($,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),kr(x,I),kr(h.content,I),u.jsx(nC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(Ee.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:de(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,R=>{const $=R.target;$.hasPointerCapture(R.pointerId)&&$.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Fs="ScrollAreaThumb",bp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yp(Fs,e.__scopeScrollArea);return u.jsx(Yt,{present:n||o.hasThumb,children:u.jsx(rC,{ref:t,...r})})}),rC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt(Fs,n),i=yp(Fs,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=iC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ee.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:de(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});bp.displayName=Fs;var Da="ScrollAreaCorner",wp=v.forwardRef((e,t)=>{const n=Qt(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(oC,{...e,ref:t}):null});wp.displayName=Da;var oC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(Da,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ee.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Bs(e){return e?parseInt(e,10):0}function Sp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function sC(e,t,n,r="ltr"){const o=zs(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Tp([l,c],f)(e)}function Cp(e,t,n="ltr"){const r=zs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=Ra(e,l);return Tp([0,i],[0,a])(c)}function Tp(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 kp(e,t){return e>0&&e<t}var iC=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Us(e,t){const n=kt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function kr(e,t){const n=kt(t);Tt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Ip=hp,aC=gp,lC=wp;const Ep=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ip,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(aC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ap,{}),u.jsx(lC,{})]}));Ep.displayName=Ip.displayName;const Ap=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pa,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(bp,{className:"relative flex-1 rounded-full bg-border"})}));Ap.displayName=Pa.displayName;const Np=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:y}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[R,$]=w.useState(null),[P,O]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const G=Array.isArray(f)?f:[];if(G.length>0){T.current=!0,C(G);return}x||(T.current=!1,C(G))},[f,x]),w.useEffect(()=>{if(!I.current)return;const G=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!G)return;let U=null,X=null;return U=requestAnimationFrame(()=>{X=requestAnimationFrame(()=>{G.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),X!==null&&cancelAnimationFrame(X)}},[k]);const B=async G=>{try{h(G),await y(G),a==null||a(G),l==null||l(G)}catch(U){console.error("Failed to select thread:",U)}},M=async()=>{try{N(!0);const G=await g();G&&(c==null||c(G),a==null||a(G))}catch(G){console.error("Failed to create thread:",G)}finally{N(!1)}},Q=async(G,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const X=I.current.querySelector("[data-radix-scroll-area-viewport]");X&&(A.current=X.scrollTop)}try{await b(G),d==null||d(G)}catch(X){console.error("Failed to delete thread:",X)}}},z=(G,U)=>{U.stopPropagation(),$(G.threadId),O(G.title||`Thread ${G.threadId.slice(0,8)}`)},_=async G=>{if(P.trim())try{await S(G,P.trim()),$(null),O("")}catch(U){console.error("Failed to update title:",U)}},V=()=>{$(null),O("")},Y=(G,U)=>{G.key==="Enter"?_(U):G.key==="Escape"&&V()},oe=G=>{if(!G)return"";try{const U=new Date(G),L=new Date().getTime()-U.getTime(),K=Math.floor(L/(1e3*60*60*24));return K===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):K===1?"Yesterday":K<7?`${K} days ago`:U.toLocaleDateString()}catch{return""}},ye=G=>G.title||`Thread ${G.threadId.slice(0,8)}`,Me=G=>{const U=ye(G);return U.length<=Np?U:`${U.slice(0,Np)}...`};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(Qe,{onClick:M,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})}),u.jsx(Ep,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.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(ae.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((G,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(G.updatedAt||G.createdAt||"").getTime()).map(G=>u.jsxs("div",{onClick:()=>B(G.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===G.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:R===G.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:P,onChange:U=>O(U.target.value),onKeyDown:U=>Y(U,G.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Qe,{variant:"ghost",size:"sm",onClick:()=>_(G.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Qe,{variant:"ghost",size:"sm",onClick:V,className:"h-6 w-6 p-0",children:u.jsx(ae.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:Me(G)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:oe(G.updatedAt||G.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&R!==G.threadId&&u.jsx(Qe,{variant:"ghost",size:"sm",onClick:U=>z(G,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Qe,{variant:"ghost",size:"sm",onClick:U=>Q(G.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.Trash2,{size:12})})]})]}),i===G.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},G.threadId))})})]})}function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return wn(t)}function _p(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function jp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return wn(t);return wn()}function Mp(){const e={},t=_p(),n=jp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Pp(){const e=Mp(),t=An.getAuthToken(),n=_p();return{apiBaseUrl:Rp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||jp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Op="chat-settings";function uC(){try{const e=localStorage.getItem(Op);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:wn(e.apiBaseUrl)};localStorage.setItem(Op,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=Pp(),t=uC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Rp(An.baseUrl,r,e.apiBaseUrl)}}function pC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var hC="Label",Dp=v.forwardRef((e,t)=>u.jsx(Ee.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())}}));Dp.displayName=hC;var Lp=Dp;const mC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=v.forwardRef(({className:e,...t},n)=>u.jsx(Lp,{ref:n,className:te(mC(),e),...t}));en.displayName=Lp.displayName;function $p(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Fp=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"}),gC="VisuallyHidden",xC=v.forwardRef((e,t)=>u.jsx(Ee.span,{...e,ref:t,style:{...Fp,...e.style}}));xC.displayName=gC;var yC=[" ","Enter","ArrowUp","ArrowDown"],vC=[" ","Enter"],rr="Select",[Hs,Ws,bC]=xi(rr),[Er,BT]=Sn(rr,[bC,Ko]),Vs=Ko(),[wC,$n]=Er(rr),[SC,CC]=Er(rr),Bp=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=Vs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Mo(c),[I,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[R,$]=pr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),O=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(M=>M.props.value).join(";");return u.jsx(tu,{...m,children:u.jsxs(wC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Cn(),value:R,onValueChange:$,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(SC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(M=>{N(Q=>new Set(Q).add(M))},[]),onNativeOptionRemove:v.useCallback(M=>{N(Q=>{const z=new Set(Q);return z.delete(M),z})},[]),children:n})}),O?u.jsxs(uh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:M=>$(M.target.value),disabled:p,form:x,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Bp.displayName=rr;var zp="SelectTrigger",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=$n(zp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,p,h]=fh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=ph(y,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(nu,{asChild:!0,...s,children:u.jsx(Ee.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":dh(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:de(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:de(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&yC.includes(m.key)&&(x(),m.preventDefault())})})})});Up.displayName=zp;var Hp="SelectValue",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=$n(Hp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(Ee.span,{...a,ref:f,style:{pointerEvents:"none"},children:dh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Wp.displayName=Hp;var TC="SelectIcon",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ee.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Vp.displayName=TC;var kC="SelectPortal",Kp=e=>u.jsx(qo,{asChild:!0,...e});Kp.displayName=kC;var or="SelectContent",qp=v.forwardRef((e,t)=>{const n=$n(or,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Gp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Yp,{...e,ref:t})});qp.displayName=or;var cn=10,[Gp,Fn]=Er(or),IC="SelectContentImpl",EC=Hn.createSlot("SelectContent.RemoveScroll"),Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=$n(or,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,X=>k(X)),[A,R]=v.useState(null),[$,P]=v.useState(null),O=Ws(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Fi(S)},[S]),bi();const M=v.useCallback(X=>{const[L,...K]=O().map(re=>re.ref.current),[Z]=K.slice(-1),ce=document.activeElement;for(const re of X)if(re===ce||(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!==ce))return},[O,C]),Q=v.useCallback(()=>M([A,S]),[M,A,S]);v.useEffect(()=>{F&&Q()},[F,Q]);const{onOpenChange:z,triggerPointerDownPosRef:_}=b;v.useEffect(()=>{if(S){let X={x:0,y:0};const L=Z=>{var ce,re;X={x:Math.abs(Math.round(Z.pageX)-(((ce=_.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((re=_.current)==null?void 0:re.y)??0))}},K=Z=>{X.x<=10&&X.y<=10?Z.preventDefault():S.contains(Z.target)||z(!1),document.removeEventListener("pointermove",L),_.current=null};return _.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",K,{capture:!0})}}},[S,z,_]),v.useEffect(()=>{const X=()=>z(!1);return window.addEventListener("blur",X),window.addEventListener("resize",X),()=>{window.removeEventListener("blur",X),window.removeEventListener("resize",X)}},[z]);const[V,Y]=fh(X=>{const L=O().filter(ce=>!ce.disabled),K=L.find(ce=>ce.ref.current===document.activeElement),Z=ph(L,X,K);Z&&setTimeout(()=>Z.ref.current.focus())}),oe=v.useCallback((X,L,K)=>{const Z=!B.current&&!K;(b.value!==void 0&&b.value===L||Z)&&(R(X),Z&&(B.current=!0))},[b.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Me=v.useCallback((X,L,K)=>{const Z=!B.current&&!K;(b.value!==void 0&&b.value===L||Z)&&P(X)},[b.value]),G=r==="popper"?$a:Xp,U=G===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Gp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:oe,selectedItem:A,onItemLeave:ye,itemTextRefCallback:Me,focusSelectedItem:Q,selectedItemText:$,position:r,isPositioned:F,searchRef:V,children:u.jsx(ns,{as:EC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:X=>{X.preventDefault()},onUnmountAutoFocus:de(o,X=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),X.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:X=>X.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(G,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:X=>X.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,X=>{const L=X.ctrlKey||X.altKey||X.metaKey;if(X.key==="Tab"&&X.preventDefault(),!L&&X.key.length===1&&Y(X.key),["ArrowUp","ArrowDown","Home","End"].includes(X.key)){let Z=O().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(X.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(X.key)){const ce=X.target,re=Z.indexOf(ce);Z=Z.slice(re+1)}setTimeout(()=>M(Z)),X.preventDefault()}})})})})})})});Yp.displayName=IC;var AC="SelectItemAlignedPosition",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=$n(or,n),i=Fn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),p=Ws(n),h=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),$=g.getBoundingClientRect();if(s.dir!=="rtl"){const ce=$.left-A.left,re=R.left-ce,je=I.left-re,Ue=I.width+je,De=Math.max(Ue,A.width),Ge=window.innerWidth-cn,Ve=Ra(re,[cn,Math.max(cn,Ge-De)]);a.style.minWidth=Ue+"px",a.style.left=Ve+"px"}else{const ce=A.right-$.right,re=window.innerWidth-R.right-ce,je=window.innerWidth-I.right-re,Ue=I.width+je,De=Math.max(Ue,A.width),Ge=window.innerWidth-cn,Ve=Ra(re,[cn,Math.max(cn,Ge-De)]);a.style.minWidth=Ue+"px",a.style.right=Ve+"px"}const P=p(),O=window.innerHeight-cn*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),M=parseInt(N.paddingTop,10),Q=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),_=B+M+F+z+Q,V=Math.min(y.offsetHeight*5,_),Y=window.getComputedStyle(m),oe=parseInt(Y.paddingTop,10),ye=parseInt(Y.paddingBottom,10),Me=I.top+I.height/2-cn,G=O-Me,U=y.offsetHeight/2,X=y.offsetTop+U,L=B+M+X,K=_-L;if(L<=Me){const ce=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const re=c.clientHeight-m.offsetTop-m.offsetHeight,je=Math.max(G,U+(ce?ye:0)+re+Q),Ue=L+je;a.style.height=Ue+"px"}else{const ce=P.length>0&&y===P[0].ref.current;a.style.top="0px";const je=Math.max(Me,B+m.offsetTop+(ce?oe:0)+U)+K;a.style.height=je+"px",m.scrollTop=L-Me+m.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=V+"px",a.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(_C,{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(Ee.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Xp.displayName=AC;var NC="SelectPopperPosition",$a=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Vs(n);return u.jsx(ru,{...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=NC;var[_C,Fa]=Er(or,{}),Ba="SelectViewport",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Fn(Ba,n),i=Fa(Ba,n),a=Be(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Hs.Slot,{scope:n,children:u.jsx(Ee.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:de(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-cn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);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})})})]})});Jp.displayName=Ba;var Zp="SelectGroup",[jC,RC]=Er(Zp),MC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cn();return u.jsx(jC,{scope:n,id:o,children:u.jsx(Ee.div,{role:"group","aria-labelledby":o,...r,ref:t})})});MC.displayName=Zp;var Qp="SelectLabel",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=RC(Qp,n);return u.jsx(Ee.div,{id:o.id,...r,ref:t})});eh.displayName=Qp;var Ks="SelectItem",[PC,th]=Er(Ks),nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=$n(Ks,n),l=Fn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),x=Be(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=Cn(),y=v.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(PC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ee.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:de(i.onFocus,()=>h(!0)),onBlur:de(i.onBlur,()=>h(!1)),onClick:de(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:de(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:de(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:de(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(vC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});nh.displayName=Ks;var uo="SelectItemText",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=$n(uo,n),a=Fn(uo,n),l=th(uo,n),c=CC(uo,n),[d,f]=v.useState(null),p=Be(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=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Tt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(Ee.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});rh.displayName=uo;var oh="SelectItemIndicator",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return th(oh,n).isSelected?u.jsx(Ee.span,{"aria-hidden":!0,...r,ref:t}):null});sh.displayName=oh;var za="SelectScrollUpButton",ih=v.forwardRef((e,t)=>{const n=Fn(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ih.displayName=za;var Ua="SelectScrollDownButton",ah=v.forwardRef((e,t)=>{const n=Fn(Ua,e.__scopeSelect),r=Fa(Ua,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ah.displayName=Ua;var lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Fn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ee.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:de(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:de(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:de(o.onPointerLeave,()=>{l()})})}),OC="SelectSeparator",ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ee.div,{"aria-hidden":!0,...r,ref:t})});ch.displayName=OC;var Ha="SelectArrow",DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=$n(Ha,n),i=Fn(Ha,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});DC.displayName=Ha;var LC="SelectBubbleInput",uh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=$p(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ee.select,{...n,style:{...Fp,...n.style},ref:s,defaultValue:t})});uh.displayName=LC;function dh(e){return e===""||e===void 0}function fh(e){const t=kt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function ph(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 FC=Bp,hh=Up,BC=Wp,zC=Vp,UC=Kp,mh=qp,HC=Jp,gh=eh,xh=nh,WC=rh,VC=sh,yh=ih,vh=ah,bh=ch;const wh=FC,Sh=BC,Wa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hh,{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(zC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=hh.displayName;const Ch=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const Va=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(UC,{children:u.jsxs(mh,{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(Ch,{}),u.jsx(HC,{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(Th,{})]})}));Va.displayName=mh.displayName;const KC=v.forwardRef(({className:e,...t},n)=>u.jsx(gh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));KC.displayName=gh.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{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(VC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(WC,{children:t})]}));sr.displayName=xh.displayName;const qC=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));qC.displayName=bh.displayName;var GC="Separator",kh="horizontal",YC=["horizontal","vertical"],Ih=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=kh,...o}=e,s=XC(r)?r:kh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ee.div,{"data-orientation":s,...a,...o,ref:t})});Ih.displayName=GC;function XC(e){return YC.includes(e)}var Eh=Ih;const Ah=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Eh,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ah.displayName=Eh.displayName;const JC=Bf,ZC=cS,QC=zf,Nh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));Nh.displayName=Es.displayName;const eT=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"}}),_h=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(QC,{children:[u.jsx(Nh,{}),u.jsxs(As,{ref:o,className:te(eT({side:e}),t),...r,children:[n,u.jsxs(Uf,{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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_h.displayName=As.displayName;const jh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});jh.displayName="SheetHeader";const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Rh.displayName=tr.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Mh.displayName=Ns.displayName;var qs="Switch",[tT,zT]=Sn(qs),[nT,rT]=tT(qs),Ph=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),x=Be(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(nT,{scope:n,checked:g,disabled:a,children:[u.jsx(Ee.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":$h(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:de(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Lh,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Ph.displayName=qs;var Oh="SwitchThumb",Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rT(Oh,n);return u.jsx(Ee.span,{"data-state":$h(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Dh.displayName=Oh;var oT="SwitchBubbleInput",Lh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=$p(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const 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}})});Lh.displayName=oT;function $h(e){return e?"checked":"unchecked"}var Fh=Ph,sT=Dh;const Bn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fh,{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(sT,{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=Fh.displayName;const iT={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 aT({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}=Aa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(iT),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(JC,{open:r,onOpenChange:o,children:[u.jsx(ZC,{asChild:!0,children:u.jsxs(Qe,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(yf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(_h,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(jh,{children:[u.jsx(Rh,{children:"Chat Settings"}),u.jsx(Mh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Qe,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Qe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(wh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{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(en,{htmlFor:"theme",children:"Theme"}),u.jsxs(wh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Ah,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{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:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{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:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{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:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Qe,{variant:"outline",onClick:h,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Qe,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Qe,{onClick:p,disabled:!c,children:[u.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function lT({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(Ls,{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(Ls,{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(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Bl,Ce.ChatInput=cc,Ce.ChatInterface=Ls,Ce.ChatProviders=Ro,Ce.ChatSettings=aT,Ce.MarkdownContent=so,Ce.MessageComponent=Ds,Ce.MessageList=ja,Ce.ThreadManager=La,Ce.applySettings=pC,Ce.buildMessagePreviewMap=ql,Ce.chatApiClient=An,Ce.default=lT,Ce.del=Fl,Ce.get=qt,Ce.getChatToken=Dl,Ce.getCurrentSettings=fC,Ce.getDefaultApiConfig=Mp,Ce.getDefaultChatSettings=Pp,Ce.onChatTokenChanged=Ll,Ce.post=ci,Ce.put=$l,Ce.setChatToken=Io,Ce.useApi=ui,Ce.useChatStream=Gl,Ce.useMessagesReducer=Yl,Ce.useStream=ac,Ce.useThreadState=jo,Ce.useThreads=_o,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
134
+ `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=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 Bn{constructor(t){this.options=t||sr,this.options.renderer=this.options.renderer||new Ma,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ap,this.slugger=new lp}static parse(t,n){return new Bn(n).parse(t)}static parseInline(t,n){return new Bn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,x,m,y,g,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,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,y=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),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):g+=C),g+=this.parse(b.tokens,y),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<I&&t[o+1].type==="text";)h=t[++o],p+=`
135
+ `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const A='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ls{constructor(t){this.options=t||sr}preprocess(t){return t}postprocess(t){return t}}Hh(Ls,"passThroughHooks",new Set(["preprocess","postprocess"]));function $S(e,t,n){return r=>{if(r.message+=`
136
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function cp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=$S(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(OS(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&&me.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;me.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(me.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&&me.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function me(e,t,n){return cp(Fn.lex,Bn.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},SS(me.defaults),me},me.getDefaults=Jf,me.defaults=sr,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.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=me.defaults.renderer||new Ma;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=me.defaults.tokenizer||new Ra;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=me.defaults.hooks||new Ls;for(const s in n.hooks){const i=o[s];Ls.passThroughHooks.has(s)?o[s]=a=>{if(me.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=me.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}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=cp(Fn.lexInline,Bn.parseInline),me.Parser=Bn,me.parser=Bn.parse,me.Renderer=Ma,me.TextRenderer=ap,me.Lexer=Fn,me.lexer=Fn.lex,me.Tokenizer=Ra,me.Slugger=lp,me.Hooks=Ls,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,Bn.parse,Fn.lex;function lo({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 me.parse=="function"?me.parse(i):me(i)}return typeof me.parse=="function"?me.parse(e):me(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:ne("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const FS={MODE:"library"};function BS(){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:Zs&&Zs.tagName.toUpperCase()==="SCRIPT"&&Zs.src||new URL("index.umd.js",document.baseURI).href}<"u"?FS: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 zS(){return!BS()}function US(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function HS(){return zS()||US()}function WS({preview:e,idx:t}){return w.useEffect(()=>{HS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const VS="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function up({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:VS,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)})}const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));co.displayName="Card";const uo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex flex-col space-y-1.5 p-6",e),...t}));uo.displayName="CardHeader";const fo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:ne("text-2xl font-semibold leading-none tracking-tight",e),...t}));fo.displayName="CardTitle";const dp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));dp.displayName="CardDescription";const po=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("p-6 pt-0",e),...t}));po.displayName="CardContent";const fp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex items-center p-6 pt-0",e),...t}));fp.displayName="CardFooter";function KS({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(co,{className:ne("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(uo,{className:"pb-3",children:[u.jsx(fo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(dp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(po,{className:"pt-0 pb-3",children:a}),u.jsx(fp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ye,{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(Ye,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function qS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ja(),[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 y,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 nS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof I.size=="number"?I.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"}),(y=k.update)==null||y.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 GS({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:ne("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(lo,{content:e,allowHtml:!1}):u.jsxs("pre",{className:ne("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ye,{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(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function YS({message:e,viewMode:t}){const r=Cf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?ka(c)??c:c;if(d&&typeof d=="object")return u.jsx(up,{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}=q0(c);return f?u.jsx(lo,{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(ae.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=ks(d);return s(f)}const a=so(i),l=ks(a);return s(l)}function XS({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:ne("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const $s=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:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:M=null,messageParentCheckpointId:L=null}){const[P,D]=w.useState(!1),[F,N]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:V}=Ro(),{respondToInterrupt:z}=Mo(),R=l==="phone"||l==="half-screen",K=t.role,J=K==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ge=!!se,Ie=!(r&&K!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:Z,currentFileInfo:$,closeFileViewer:q}=qS({allowFileOpen:Ie,currentThreadId:V}),Q=w.useMemo(()=>{switch(K){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))]"}},[K]),ce=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?G0(_):""},[se,t]),oe=w.useMemo(()=>{if(se)return{};const _=t.content;return Array.isArray(_)?Cf(t):{}},[se,t]),Ae=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="image_url"):[]},[se,t]),ze=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="file"):[]},[se,t]),re=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="interrupt"):[]},[se,t]),xe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Me=Is(xe),Je=b==null?void 0:b.value,Ze=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?Y0(_):""},[se,t]),We=w.useMemo(()=>{if(se||!p)return[];const X=t.artifact;if(!X)return[];const ee=[],pe=[...Array.isArray(X.plots)?X.plots:[]];for(const be of pe){const we=eS(be);we&&ee.push(we)}return ee},[se,t,p]),et=w.useCallback(async()=>{const _=J?Ze:ce;async function X(ee){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ee);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const pe=new Blob([ee],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":pe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(_),D(!0),setTimeout(()=>D(!1),2e3),g==null||g(_)}catch(ee){console.error("Failed to copy:",ee)}},[J,Ze,ce,g]),st=w.useCallback(()=>{if(!x)return;const _=J?Ze:ce,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,_,X)},[x,t.id,J,Ze,ce,t]),Ke=w.useCallback(()=>{m==null||m(n)},[m,n]),tt=w.useCallback(()=>{const X=ne(R?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(K){case"user":return u.jsx(ae.User,{className:X});case"assistant":return u.jsx(ae.Bot,{className:X});case"tool":return u.jsx(ae.Wrench,{className:X});default:return u.jsx(ae.Bot,{className:X})}},[R,Q,K]),it=w.useCallback(()=>{const _="group relative mb-4 flex w-full";switch(K){case"user":return ne(_,"justify-end");case"assistant":case"tool":case"system":return ne(_,"justify-start");default:return _}},[K]),Rt=w.useCallback(()=>{const _=ne("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",R&&"px-3 py-2 text-sm");if(ge)return ne(_,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(K){case"user":return ne(_,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return ne(_,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return ne(_,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ne(_,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ne(_,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[R,ge,K]),gt=w.useCallback(async _=>{if(S)return;const X=Is((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!0)}catch(ee){console.error("Failed to approve interrupt:",ee)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async _=>{if(S)return;const X=Is((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!1)}catch(ee){console.error("Failed to reject interrupt:",ee)}finally{C==null||C()}},[S,C,k,z]),vt=w.useCallback(({part:_,i:X})=>{if(_.type==="text"){const ee=_.text??"",pe=ee.trim(),be=ka(pe);return be&&K!=="tool"?u.jsx(up,{data:be},X):K==="user"&&c&&pe.length>d?u.jsx(GS,{text:pe,expanded:B,onExpandedChange:j,previewLength:d,isCompact:R},X):u.jsx(lo,{content:ee,allowHtml:!1},X)}if(_.type==="image_url"){const ee=_;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ee.url,alt:ee.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(_.type==="file"){const ee=_,pe=ee.name||"file";return u.jsxs("a",{href:ee.url,onClick:be=>U(be.nativeEvent,ee,X),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[X]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,Y[X]?" (processing)":""]})]},X)}if(_.type==="interrupt"){const ee=_,pe=Is((ee==null?void 0:ee.id)??(ee==null?void 0:ee.interrupt_id)),be=!!(Me&&pe&&pe===Me),we=be?Je??(ee==null?void 0:ee.value):ee==null?void 0:ee.value,Ue=pe?{...ee,id:pe,interrupt_id:pe}:ee;return u.jsx(KS,{interruptPart:Ue,onApprove:gt,onReject:ht,disabled:S,isActive:be,payload:we},X)}return null},[U,Y,gt,ht,K,c,d,B,R,Me,Je,b,S,re]),wt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),$t=w.useCallback(()=>{const _=ce.trim().length>0||Ae.length>0||ze.length>0||re.length>0;if(!J&&ze.length>0&&!r)return wt();if(!J&&!_&&!r)return null;if(J)return!f&&We.length>0?null:f?u.jsx(YS,{message:t,viewMode:F},t.id):null;if(!J&&!se){const X=t,ee=u.jsx("div",{className:"space-y-2",children:X.content.map((pe,be)=>u.jsx(vt,{part:pe,i:be},be))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ee,u.jsx(XS,{className:Q})]}):ee}},[ce,Ae.length,ze.length,re.length,r,J,F,f,We.length,wt,Q]),Mt=w.useMemo(()=>se?"Assistant":X0(t),[se,t]),Qe=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),It=w.useMemo(()=>{var _;return Qe.length?M&&Qe.some(X=>X.id===M)?M:((_=Qe[0])==null?void 0:_.id)??null:null},[M,Qe]),qe=w.useMemo(()=>!Qe.length||!I?null:Qe.some(_=>_.id===I)?I:null,[I,Qe])??It,Ge=K==="user"&&Qe.length>0&&typeof A=="function",ft=w.useCallback((_,X=!1)=>{if(!A)return;const ee=(_==null?void 0:_.id)??null,pe=(_==null?void 0:_.parentId)??L??null;A(ee,pe,X)},[L,A]),at=w.useMemo(()=>qe?Qe.findIndex(_=>_.id===qe):-1,[qe,Qe]),G=w.useMemo(()=>at<0?null:Qe[at]??null,[at,Qe]);return J&&!f&&We.length===0?null:ge&&se?u.jsx("div",{className:ne(it(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:ne("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(lo,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ne(it(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[(i||a||J)&&u.jsxs("div",{className:ne("flex items-center justify-between mb-2 pb-2 border-b border-current/10",R&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[tt(),a&&Mt&&u.jsx("span",{className:ne("font-medium",R?"text-xs":"text-sm"),children:Mt}),J&&u.jsxs(wf,{variant:"outline",className:ne("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",R&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(_=>_==="expanded"?"preview":"expanded"),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),N(X=>X==="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(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ge&&G&&at>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",at<Qe.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(at>=Qe.length-1)return;const _=Qe[at+1];_&&ft(_)},"aria-label":"Older checkpoint (back in time)",disabled:at>=Qe.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Qe.length-at," / ",Qe.length]})}),u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",at>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(at<=0))if(at===1)ft(null,!0);else{const _=Qe[at-1];_&&ft(_,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:at<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:ne("text-xs opacity-60",Q,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:ne("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>et(),className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,R&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:ne(P?"text-success":Q,R?"h-3 w-3":"h-4 w-4")})})}),K==="user"&&x&&u.jsx(Ye,{variant:"ghost",size:"sm",onClick:st,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,R&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:ne(Q,R?"h-3 w-3":"h-4 w-4")})}),K==="assistant"&&m&&u.jsx(Ye,{variant:"ghost",size:"sm",onClick:Ke,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,R&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:ne(Q,R?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[$t(),p&&We.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:We.map((_,X)=>u.jsx(WS,{preview:_,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:ne("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||J)&&s&&!o&&u.jsxs("div",{className:ne("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>et(),className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:ne(P?"text-success":"text-current",R?"h-3 w-3":"h-4 w-4")})}),K==="user"&&x&&u.jsx(Ye,{variant:"ghost",size:"sm",onClick:st,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:ne("text-current",R?"h-3 w-3":"h-4 w-4")})}),K==="assistant"&&m&&u.jsx(Ye,{variant:"ghost",size:"sm",onClick:Ke,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:ne("text-current",R?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(wS,{isOpen:Z,onClose:q,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Tf(e.message)===Tf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].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});$s.displayName="MessageComponent";function JS(e,t){return w.useMemo(()=>{var d,f,p,h,x;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.responseMetadata??{};const g=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(g==null?void 0:g.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(g==null?void 0:g.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&g&&(r=[g]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(x=t.checkpointMetaById)==null?void 0:x.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const pp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,hp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=pp(t,n),M="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:P,attemptMeta:D}=JS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!M?t.additionalKwargs??{}:{},N=t&&!M?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx($s,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:P,messageParentCheckpointId:B,attemptMeta:D})})});hp.displayName="MessageRow";const Pa=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:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:M,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F,createSyntheticThinkingMessage:N=!1},B)=>{const j=w.useRef(null),V=w.useRef(null),z=w.useRef(!1),R=w.useRef(!1),[K,J]=w.useState(!0),se=w.useMemo(()=>b?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),ge=w.useMemo(()=>{if(!b||se)return null;const re=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Me=b.value;if(Me&&typeof Me=="object"&&!Array.isArray(Me)){const Je=Me.title;typeof Je=="string"&&Je.trim()&&(xe=Je.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Me,title:xe}]}},[b,se]),Ie=w.useMemo(()=>ge?[...e,ge]:e,[e,ge]),Y=w.useMemo(()=>!N||!t?Ie:!Ie.some(xe=>xe.role==="assistant")&&Ie.length>0?[...Ie,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ie,[Ie,t,N]),U=w.useMemo(()=>T?Y:Y.filter(re=>(re==null?void 0:re.role)!=="tool"),[Y,T]),Z=w.useCallback(re=>{J(re),y&&y(!re),g&&g(re)},[y,g]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),q=w.useMemo(()=>!x||m?!1:K?"auto":!1,[K,x,m]),Q=w.useMemo(()=>{if(typeof h!="string")return null;const re=h.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[h]),ce=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx($s,{message:Q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),Ae=U.length,ze=Ae>0;return w.useEffect(()=>{var re,xe;if(Ae===0){R.current=!1;return}R.current||(R.current=!0,j.current?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0))},[Ae]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var re,xe;if(j.current&&U.length>0){const Me=U.length-1;(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:Me,align:"end",behavior:"auto"})}else V.current&&(V.current.scrollTop=V.current.scrollHeight)},scrollToTop:()=>{var re,xe;j.current&&U.length>0?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ce,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ze?u.jsx(_0,{ref:re=>{j.current=re},scrollerRef:re=>{V.current=re instanceof HTMLDivElement?re:null},data:U,followOutput:q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:Z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>pp(xe,re),itemContent:(re,xe)=>u.jsx(hp,{message:xe,index:re,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:M,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F})}):oe()})})});Pa.displayName="MessageList";const ZS=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o})=>{const s=e??[],i=s.length>0,a=w.useMemo(()=>i?[...s].reverse():[],[s,i]),l=t??(s.length?s[s.length-1].id:null);if(!i)return null;const d=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex",o].filter(Boolean).join(" ");return u.jsxs("div",{className:d,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:a.map(f=>{const p=l===f.id,h=f.messageId?(r==null?void 0:r.get(f.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(f.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${p?"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 ${p?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${p?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:f.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[f.step!==null?`STEP ${f.step}`:"STEP —",f.next?` - ${f.next}`:""]}),h&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:h,children:h})]})]},f.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"})]})},mp={value:""};function Fs({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:y}=pi(),{currentThreadId:g}=Ro(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:M,interrupt:L,metadata:P,timelineCheckpoints:D,messagePreviews:F}=Mo(),{isStreaming:N,error:B,connectionState:j,submit:V,stop:z}=uc(),R=b??g??null,K=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,ge=L,[Ie,Y]=w.useState(!1);w.useEffect(()=>{ge||Y(!1)},[ge]);const U=w.useCallback(()=>{Y(!0)},[]),Z=w.useCallback(()=>{Y(!1)},[]),$=!!ge||Ie,[q,Q]=w.useState(null),[ce,oe]=w.useState(""),[Ae,ze]=w.useState(null),[re,xe]=w.useState(null),[Me,Je]=w.useState([]),[Ze,We]=w.useState(0),[et,st]=w.useState(0),[Ke,tt]=w.useState(!1),[it,Rt]=w.useState(null),[gt,ht]=w.useState(null),[vt,wt]=w.useState(!1),[$t,Mt]=w.useState(null),Qe=w.useRef(!1),[It,Sn]=w.useState(()=>mp.value),qe=w.useRef(It),Ge=w.useRef(null),ft=w.useCallback(ue=>{mp.value=ue,Sn(ue)},[]),[at,G]=w.useState(!1),_=w.useRef(null),[X,ee]=w.useState(!1),{checkpointMetaById:pe,checkpointIndexByKey:be,attemptMetaById:we,userMessageIdToAttempts:Ue}=xw(M),_e=D??[],De="Backend pre-selects user inputs + latest loop checkpoint. Click a dot to jump, or use “Latest” to return to the newest messages.";w.useEffect(()=>{_e.length||ee(!1)},[_e.length,ee]),w.useEffect(()=>{ee(!1)},[R,ee]);const Pt=w.useRef(null),un=w.useRef(null),dn=w.useCallback(()=>{Pt.current&&(Pt.current.value=""),un.current&&(un.current.value=""),We(ue=>ue+1),st(ue=>ue+1)},[]),Nr=w.useCallback(ue=>{ft(ue)},[ft]),_r=w.useRef(!1);w.useEffect(()=>{_r.current&&!N&&(Je([]),dn()),_r.current=N},[N,dn]);const[Wn,jr]=w.useState("desktop");w.useEffect(()=>{const ue=()=>{const ke=window.innerWidth;jr(ke<640?"phone":ke<1024?"tablet":"desktop")};return ue(),window.addEventListener("resize",ue),()=>window.removeEventListener("resize",ue)},[]),w.useEffect(()=>{Qe.current=!1},[R]),w.useEffect(()=>{qe.current=It},[It]),w.useEffect(()=>{if(!q){Ge.current=null;return}Ge.current===null&&(Ge.current=qe.current),ft(ce??"")},[ce,q,ft]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const Pe=(await y.getAgent("default")).uiDefaultMessage||"";Mt(Pe||null)}catch(ke){console.warn("Failed to fetch default message:",ke),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!vt&&(m==null||m(B))},[B,vt,m]);const E=ue=>{if(ue.length>ds)return`Message too long (${ue.length}/${ds} characters)`;try{return bw(ue),null}catch(ke){return(ke==null?void 0:ke.message)||"Invalid message"}},W=async ue=>{const ke=ue.trim();if(!(!ke&&Me.length===0)){if(ke){const Pe=E(ke);if(Pe){xe(Pe);return}}try{const Pe=q?(Ae==null?void 0:Ae.checkpointId)??K??void 0:K??void 0,St=q?(Ae==null?void 0:Ae.checkpointNs)??J??void 0:J??void 0;await V({text:ke||"",attachments:Me},{checkpointId:Pe,checkpointNs:St,edit:!!q,originalMessageId:q??void 0}),h==null||h(ke),ft(""),xe(null),Je([]),dn(),Q(null),oe(""),ze(null)}catch(Pe){const St=(Pe==null?void 0:Pe.message)||"Failed to send message";xe(St),m==null||m(St)}}},ie=w.useCallback((ue,ke,Pe)=>{c&&(Ge.current=It,Q(ue),oe(ke),ft(ke),xe(null),ze({checkpointId:(Pe==null?void 0:Pe.checkpointId)??null,checkpointNs:(Pe==null?void 0:Pe.checkpointNs)??null}))},[It,c,ft]),ve=w.useCallback(()=>{Q(null),oe(""),ze(null),xe(null),ft(Ge.current??It),Ge.current=null},[It,ft]),Ve=w.useCallback((ue,ke,Pe)=>{ie(ue,ke,Pe)},[ie]),nt=w.useCallback(ue=>{let ke=null;for(let Cn=ue-1;Cn>=0;Cn--)if(S[Cn].role==="user"){ke=S[Cn];break}if(!ke)return;const Pe=Array.isArray(ke.content)?ke.content:[],Xs=Pe.filter(Cn=>(Cn==null?void 0:Cn.type)==="text").map(Cn=>Cn.text).join("")||(()=>{try{return JSON.stringify(Pe,null,2)}catch{return String(Pe)}})();Xs&&V({text:Xs},{checkpointId:K??void 0,checkpointNs:J??void 0,edit:!0,originalMessageId:ke.id})},[S,V,K,J]),$e=ue=>{const ke=Array.from(ue.target.files||[]);Je(Pe=>[...Pe,...ke]),ue.target.value=""},Le=ue=>{Je(ke=>{const Pe=ke.filter((St,Xs)=>ue!==Xs);return Pe.length===0&&dn(),Pe})},Et=async ue=>{const ke=(ue.target.files||[])[0];if(ke){Rt(null),ht(null),tt(!0);try{await V({attachments:[ke]},{checkpointId:K??void 0,checkpointNs:J??void 0});const Pe=`Uploaded ${ke.name} - processing through chat stream`;ht(Pe)}catch(Pe){const St=Pe instanceof Error?Pe.message:"Failed to upload Excel file";console.error("Excel upload failed",Pe),Rt(St),m==null||m(St)}finally{tt(!1),ue.target.value="",dn()}}},pt=async ue=>{if(g){G(!0);try{if(!ue){await I(),requestAnimationFrame(()=>{var St;(St=_.current)==null||St.scrollToLatest()});return}const ke=M.find(St=>St.checkpointId===ue),Pe=(ke==null?void 0:ke.checkpointNs)??null;await T(ue,Pe),requestAnimationFrame(()=>{var St;(St=_.current)==null||St.scrollToTop()})}finally{G(!1)}}},mt=w.useCallback(async(ue,ke,Pe)=>{await pt(Pe?null:ue),ee(!1)},[pt,ee]),Ut=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,Vn=`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||""}`,_n=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:Ut,children:[!!B&&!vt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>wt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${Vn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Pa,{ref:_,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Wn,enableMessageEditing:c,editingMessageId:q,onEdit:Ve,onRegenerate:nt,onCancelEdit:ve,emptyMessage:$t??void 0,isNavigatingCheckpoint:at,activeInterrupt:ge,disableInterruptActions:Ie,onInterruptActionStart:U,onInterruptActionEnd:Z,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:pe,checkpointIndexByKey:be,attemptMetaById:we,userMessageIdToAttempts:Ue,activeCheckpointId:K,onSelectCheckpoint:mt,timelineCheckpoints:_e,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(ae.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(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||at)&&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(ae.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:_n,children:[X&&_e.length>0&&u.jsx("div",{className:"absolute right-4 bottom-full mb-3 z-30",children:u.jsx("div",{className:"w-72 overflow-hidden rounded-2xl border border-border/70 bg-background shadow-2xl",children:u.jsx(ZS,{timelineEntries:_e,activeCheckpointId:K,onSelectCheckpoint:mt,messagePreviews:F,className:"w-72 max-h-[360px] border-0 pr-3"})})}),q&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ye,{variant:"ghost",size:"sm",onClick:ve,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.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:Pt,type:"file",multiple:!0,onChange:ue=>$e(ue),className:"hidden"},Ze),Me.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Me.map((ue,ke)=>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(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ue.name}),u.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>Le(ke),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 ${ue.name}`,children:u.jsx(ae.X,{size:12})})]},ke))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:un,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Et,className:"hidden"},et),Ke&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),it&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:it})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(rw,{children:[u.jsx(ow,{asChild:!0,children:u.jsx(Ye,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(wd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(ta,{onClick:()=>{var ue;return(ue=Pt.current)==null?void 0:ue.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(ta,{onClick:()=>{var ue;Ke||(ue=un.current)==null||ue.click()},className:`cursor-pointer ${Ke?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",disabled:_e.length===0,onClick:()=>ee(ue=>!ue),className:`rounded-md border px-3 py-1 text-xs font-semibold uppercase tracking-wide transition ${X?"border-blue-500 bg-blue-50 text-blue-700 hover:bg-blue-100":"border-border/70 text-muted-foreground hover:border-foreground/60 hover:text-foreground"} ${_e.length===0?"opacity-50 cursor-not-allowed":""}`,children:"Timeline"}),u.jsxs("div",{className:"relative inline-flex items-center group",children:[u.jsx(ae.Info,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("div",{className:"pointer-events-none absolute left-1/2 -top-9 z-40 w-64 -translate-x-1/2 rounded-md border border-border/60 bg-background px-3 py-2 text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:De})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ox,{initialValue:ce,editingMessageId:q,value:It,onValueChange:Nr,placeholder:q?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:ds,onSend:W,onCancelEdit:ve,onStop:z,allowEmptySend:Me.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${q?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${re?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Bs=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:ne("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Bs.displayName="Input";function Oa(e,[t,n]){return Math.min(n,Math.max(t,e))}function QS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Da="ScrollArea",[gp,zT]=kn(Da),[eC,en]=gp(Da),xp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),M=Fe(t,P=>l(P)),L=Oo(o);return u.jsx(eC,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:L,...i,ref:M,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});xp.displayName=Da;var yp="ScrollAreaViewport",vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(yp,n),a=v.useRef(null),l=Fe(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(Ne.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});vp.displayName=yp;var wn="ScrollAreaScrollbar",La=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(tC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(nC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(bp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx($a,{...r,ref:t}):null});La.displayName=wn;var tC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Xt,{present:n||s,children:u.jsx(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),nC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ws(()=>l("SCROLL_END"),100),[a,l]=QS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Xt,{present:n||a!=="hidden",children:u.jsx($a,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=v.forwardRef((e,t)=>{const n=en(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ws(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Ir(n.viewport,l),Ir(n.content,l),u.jsx(Xt,{present:r||s,children:u.jsx($a,{"data-state":s?"visible":"hidden",...o,ref:t})})}),$a=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(wn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=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 lC(p,i.current,a,h)}return n==="horizontal"?u.jsx(rC,{...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(oC,{...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}),rC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Fe(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(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":Hs(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:Us(i.paddingLeft),paddingEnd:Us(i.paddingRight)}})}})}),oC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Fe(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(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":Hs(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:Us(i.paddingTop),paddingEnd:Us(i.paddingBottom)}})}})}),[sC,wp]=gp(wn),Sp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=en(wn,n),[x,m]=v.useState(null),y=Fe(t,M=>m(M)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Ws(f,10);function A(M){if(g.current){const L=M.clientX-g.current.left,P=M.clientY-g.current.top;c({x:L,y:P})}}return v.useEffect(()=>{const M=L=>{const P=L.target;(x==null?void 0:x.contains(P))&&C(L,k)};return document.addEventListener("wheel",M,{passive:!1}),()=>document.removeEventListener("wheel",M,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),Ir(x,I),Ir(h.content,I),u.jsx(sC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(Ne.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:fe(e.onPointerDown,M=>{M.button===0&&(M.target.setPointerCapture(M.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(M))}),onPointerMove:fe(e.onPointerMove,A),onPointerUp:fe(e.onPointerUp,M=>{const L=M.target;L.hasPointerCapture(M.pointerId)&&L.releasePointerCapture(M.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),zs="ScrollAreaThumb",Cp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wp(zs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(iC,{ref:t,...r})})}),iC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(zs,n),i=wp(zs,n),{onThumbPositionChange:a}=i,l=Fe(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ws(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=cC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ne.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:fe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});Cp.displayName=zs;var Fa="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=en(Fa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(aC,{...e,ref:t}):null});Tp.displayName=Fa;var aC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Fa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Ir(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Ir(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Us(e){return e?parseInt(e,10):0}function kp(e,t){const n=e/t;return isNaN(n)?0:n}function Hs(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 lC(e,t,n,r="ltr"){const o=Hs(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 Ep([l,c],f)(e)}function Ip(e,t,n="ltr"){const r=Hs(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=Oa(e,l);return Ep([0,i],[0,a])(c)}function Ep(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 cC=(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 Ws(e,t){const n=kt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Ir(e,t){const n=kt(t);Tt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Np=xp,uC=vp,dC=Tp;const _p=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Np,{ref:r,className:ne("relative overflow-hidden",e),...n,children:[u.jsx(uC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(jp,{}),u.jsx(dC,{})]}));_p.displayName=Np.displayName;const jp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(La,{ref:r,orientation:t,className:ne("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Cp,{className:"relative flex-1 rounded-full bg-border"})}));jp.displayName=La.displayName;const Rp=25;function Ba({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}=Ro(),{loadThread:y}=Mo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[M,L]=w.useState(null),[P,D]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}x||(T.current=!1,C(Y))},[f,x]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,Z=null;return U=requestAnimationFrame(()=>{Z=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),Z!==null&&cancelAnimationFrame(Z)}},[k]);const B=async Y=>{try{h(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{N(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{N(!1)}},V=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const Z=I.current.querySelector("[data-radix-scroll-area-viewport]");Z&&(A.current=Z.scrollTop)}try{await b(Y),d==null||d(Y)}catch(Z){console.error("Failed to delete thread:",Z)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),D(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},R=async Y=>{if(P.trim())try{await S(Y,P.trim()),L(null),D("")}catch(U){console.error("Failed to update title:",U)}},K=()=>{L(null),D("")},J=(Y,U)=>{Y.key==="Enter"?R(U):Y.key==="Escape"&&K()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),q=Math.floor($/(1e3*60*60*24));return q===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:U.toLocaleDateString()}catch{return""}},ge=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ie=Y=>{const U=ge(Y);return U.length<=Rp?U:`${U.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(Ye,{onClick:j,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})}),u.jsx(_p,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.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(ae.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((Y,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===Y.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:M===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Bs,{value:P,onChange:U=>D(U.target.value),onKeyDown:U=>J(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>R(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Ye,{variant:"ghost",size:"sm",onClick:K,className:"h-6 w-6 p-0",children:u.jsx(ae.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ie(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:se(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&M!==Y.threadId&&u.jsx(Ye,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Ye,{variant:"ghost",size:"sm",onClick:U=>V(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}function Er(e){if(!(typeof globalThis>"u"))return globalThis[e]}function fC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Tn(t)}function Mp(){const e=[Er("__API_BASE_URL__"),Er("__CHAT_API_BASE_URL__"),Er("__CHAT_API_URL__")];for(const t of e){const n=fC(t);if(n)return n}}function Pp(){const e=[Er("__API_AUTH_TOKEN__"),Er("__CHAT_API_KEY__"),Er("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Op(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Tn(t);return Tn()}function Dp(){const e={},t=Mp(),n=Pp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Lp(){const e=Dp(),t=jn.getAuthToken(),n=Mp();return{apiBaseUrl:Op(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||Pp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const $p="chat-settings";function pC(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function hC(e){try{const t={...e,apiBaseUrl:Tn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function mC(){const e=Lp(),t=pC(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Op(jn.baseUrl,r,e.apiBaseUrl)}}function gC(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),hC(e)}var xC="Label",Fp=v.forwardRef((e,t)=>u.jsx(Ne.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Fp.displayName=xC;var Bp=Fp;const yC=mo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),tn=v.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:ne(yC(),e),...t}));tn.displayName=Bp.displayName;function zp(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Up=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"}),vC="VisuallyHidden",bC=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Up,...e.style}}));bC.displayName=vC;var wC=[" ","Enter","ArrowUp","ArrowDown"],SC=[" ","Enter"],ir="Select",[Vs,Ks,CC]=bi(ir),[Ar,UT]=kn(ir,[CC,Go]),qs=Go(),[TC,zn]=Ar(ir),[kC,IC]=Ar(ir),Hp=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=qs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Oo(c),[I,A]=hr({prop:r,defaultProp:o??!1,onChange:s,caller:ir}),[M,L]=hr({prop:i,defaultProp:a,onChange:l,caller:ir}),P=v.useRef(null),D=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(ou,{...m,children:u.jsxs(TC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:In(),value:M,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Vs.Provider,{scope:t,children:u.jsx(kC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{N(V=>new Set(V).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{N(V=>{const z=new Set(V);return z.delete(j),z})},[]),children:n})}),D?u.jsxs(ph,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:M,onChange:j=>L(j.target.value),disabled:p,form:x,children:[M===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Hp.displayName=ir;var Wp="SelectTrigger",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=qs(n),i=zn(Wp,n),a=i.disabled||r,l=Fe(t,i.onTriggerChange),c=Ks(n),d=v.useRef("touch"),[f,p,h]=mh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=gh(y,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(Ne.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":hh(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:fe(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:fe(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&wC.includes(m.key)&&(x(),m.preventDefault())})})})});Vp.displayName=Wp;var Kp="SelectValue",qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=zn(Kp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Fe(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:hh(l.value)?u.jsx(u.Fragment,{children:i}):s})});qp.displayName=Kp;var EC="SelectIcon",Gp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Gp.displayName=EC;var AC="SelectPortal",Yp=e=>u.jsx(Yo,{asChild:!0,...e});Yp.displayName=AC;var ar="SelectContent",Xp=v.forwardRef((e,t)=>{const n=zn(ar,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?go.createPortal(u.jsx(Jp,{scope:e.__scopeSelect,children:u.jsx(Vs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Zp,{...e,ref:t})});Xp.displayName=ar;var cn=10,[Jp,Un]=Ar(ar),NC="SelectContentImpl",_C=Kn.createSlot("SelectContent.RemoveScroll"),Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=zn(ar,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Fe(t,Z=>k(Z)),[A,M]=v.useState(null),[L,P]=v.useState(null),D=Ks(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Ui(S)},[S]),Ci();const j=v.useCallback(Z=>{const[$,...q]=D().map(oe=>oe.ref.current),[Q]=q.slice(-1),ce=document.activeElement;for(const oe of Z)if(oe===ce||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Q&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==ce))return},[D,C]),V=v.useCallback(()=>j([A,S]),[j,A,S]);v.useEffect(()=>{F&&V()},[F,V]);const{onOpenChange:z,triggerPointerDownPosRef:R}=b;v.useEffect(()=>{if(S){let Z={x:0,y:0};const $=Q=>{var ce,oe;Z={x:Math.abs(Math.round(Q.pageX)-(((ce=R.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((oe=R.current)==null?void 0:oe.y)??0))}},q=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",$),R.current=null};return R.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",q,{capture:!0})}}},[S,z,R]),v.useEffect(()=>{const Z=()=>z(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[z]);const[K,J]=mh(Z=>{const $=D().filter(ce=>!ce.disabled),q=$.find(ce=>ce.ref.current===document.activeElement),Q=gh($,Z,q);Q&&setTimeout(()=>Q.ref.current.focus())}),se=v.useCallback((Z,$,q)=>{const Q=!B.current&&!q;(b.value!==void 0&&b.value===$||Q)&&(M(Z),Q&&(B.current=!0))},[b.value]),ge=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ie=v.useCallback((Z,$,q)=>{const Q=!B.current&&!q;(b.value!==void 0&&b.value===$||Q)&&P(Z)},[b.value]),Y=r==="popper"?za:Qp,U=Y===za?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Jp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:ge,itemTextRefCallback:Ie,focusSelectedItem:V,selectedItemText:L,position:r,isPositioned:F,searchRef:K,children:u.jsx(os,{as:_C,allowPinchZoom:!0,children:u.jsx(Lo,{asChild:!0,trapped:b.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:fe(o,Z=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),Z.preventDefault()}),children:u.jsx(Do,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Z=>Z.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,Z=>{const $=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!$&&Z.key.length===1&&J(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=D().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ce=Z.target,oe=Q.indexOf(ce);Q=Q.slice(oe+1)}setTimeout(()=>j(Q)),Z.preventDefault()}})})})})})})});Zp.displayName=NC;var jC="SelectItemAlignedPosition",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=zn(ar,n),i=Un(ar,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Fe(t,I=>d(I)),p=Ks(n),h=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),M=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const ce=L.left-A.left,oe=M.left-ce,Ae=I.left-oe,ze=I.width+Ae,re=Math.max(ze,A.width),xe=window.innerWidth-cn,Me=Oa(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=ze+"px",a.style.left=Me+"px"}else{const ce=A.right-L.right,oe=window.innerWidth-M.right-ce,Ae=window.innerWidth-I.right-oe,ze=I.width+Ae,re=Math.max(ze,A.width),xe=window.innerWidth-cn,Me=Oa(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=ze+"px",a.style.right=Me+"px"}const P=p(),D=window.innerHeight-cn*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),j=parseInt(N.paddingTop,10),V=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),R=B+j+F+z+V,K=Math.min(y.offsetHeight*5,R),J=window.getComputedStyle(m),se=parseInt(J.paddingTop,10),ge=parseInt(J.paddingBottom,10),Ie=I.top+I.height/2-cn,Y=D-Ie,U=y.offsetHeight/2,Z=y.offsetTop+U,$=B+j+Z,q=R-$;if($<=Ie){const ce=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,Ae=Math.max(Y,U+(ce?ge:0)+oe+V),ze=$+Ae;a.style.height=ze+"px"}else{const ce=P.length>0&&y===P[0].ref.current;a.style.top="0px";const Ae=Math.max(Ie,B+m.offsetTop+(ce?se:0)+U)+q;a.style.height=Ae+"px",m.scrollTop=$-Ie+m.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=K+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(MC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Qp.displayName=jC;var RC="SelectPopperPosition",za=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=qs(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)"}})});za.displayName=RC;var[MC,Ua]=Ar(ar,{}),Ha="SelectViewport",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Un(Ha,n),i=Ua(Ha,n),a=Fe(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx(Vs.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-cn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);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})})})]})});eh.displayName=Ha;var th="SelectGroup",[PC,OC]=Ar(th),DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=In();return u.jsx(PC,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});DC.displayName=th;var nh="SelectLabel",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=OC(nh,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});rh.displayName=nh;var Gs="SelectItem",[LC,oh]=Ar(Gs),sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=zn(Gs,n),l=Un(Gs,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),x=Fe(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=In(),y=v.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(LC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Vs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.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:fe(i.onFocus,()=>h(!0)),onBlur:fe(i.onBlur,()=>h(!1)),onClick:fe(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:fe(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:fe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(SC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});sh.displayName=Gs;var ho="SelectItemText",ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=zn(ho,n),a=Un(ho,n),l=oh(ho,n),c=IC(ho,n),[d,f]=v.useState(null),p=Fe(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=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Tt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?go.createPortal(s.children,i.valueNode):null]})});ih.displayName=ho;var ah="SelectItemIndicator",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return oh(ah,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});lh.displayName=ah;var Wa="SelectScrollUpButton",ch=v.forwardRef((e,t)=>{const n=Un(Wa,e.__scopeSelect),r=Ua(Wa,e.__scopeSelect),[o,s]=v.useState(!1),i=Fe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ch.displayName=Wa;var Va="SelectScrollDownButton",uh=v.forwardRef((e,t)=>{const n=Un(Va,e.__scopeSelect),r=Ua(Va,e.__scopeSelect),[o,s]=v.useState(!1),i=Fe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});uh.displayName=Va;var dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Un("SelectScrollButton",n),i=v.useRef(null),a=Ks(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:fe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:fe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),$C="SelectSeparator",fh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});fh.displayName=$C;var Ka="SelectArrow",FC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=qs(n),s=zn(Ka,n),i=Un(Ka,n);return s.open&&i.position==="popper"?u.jsx(au,{...o,...r,ref:t}):null});FC.displayName=Ka;var BC="SelectBubbleInput",ph=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Fe(r,o),i=zp(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(Ne.select,{...n,style:{...Up,...n.style},ref:s,defaultValue:t})});ph.displayName=BC;function hh(e){return e===""||e===void 0}function mh(e){const t=kt(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function gh(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=zC(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 zC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var UC=Hp,xh=Vp,HC=qp,WC=Gp,VC=Yp,yh=Xp,KC=eh,vh=rh,bh=sh,qC=ih,GC=lh,wh=ch,Sh=uh,Ch=fh;const Th=UC,kh=HC,qa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:ne("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(WC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));qa.displayName=xh.displayName;const Ih=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));Ih.displayName=wh.displayName;const Eh=v.forwardRef(({className:e,...t},n)=>u.jsx(Sh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));Eh.displayName=Sh.displayName;const Ga=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(VC,{children:u.jsxs(yh,{ref:o,className:ne("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Ih,{}),u.jsx(KC,{className:ne("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Eh,{})]})}));Ga.displayName=yh.displayName;const YC=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));YC.displayName=vh.displayName;const lr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bh,{ref:r,className:ne("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(GC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(qC,{children:t})]}));lr.displayName=bh.displayName;const XC=v.forwardRef(({className:e,...t},n)=>u.jsx(Ch,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));XC.displayName=Ch.displayName;var JC="Separator",Ah="horizontal",ZC=["horizontal","vertical"],Nh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ah,...o}=e,s=QC(r)?r:Ah,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});Nh.displayName=JC;function QC(e){return ZC.includes(e)}var _h=Nh;const jh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(_h,{ref:o,decorative:n,orientation:t,className:ne("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));jh.displayName=_h.displayName;const eT=Hf,tT=fS,nT=Wf,Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{className:ne("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));Rh.displayName=Ns.displayName;const rT=mo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Mh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(nT,{children:[u.jsx(Rh,{}),u.jsxs(_s,{ref:o,className:ne(rT({side:e}),t),...r,children:[n,u.jsxs(Vf,{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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mh.displayName=_s.displayName;const Ph=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-2 text-center sm:text-left",e),...t});Ph.displayName="SheetHeader";const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(or,{ref:n,className:ne("text-lg font-semibold text-foreground",e),...t}));Oh.displayName=or.displayName;const Dh=v.forwardRef(({className:e,...t},n)=>u.jsx(js,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));Dh.displayName=js.displayName;var Ys="Switch",[oT,HT]=kn(Ys),[sT,iT]=oT(Ys),Lh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),x=Fe(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=hr({prop:o,defaultProp:s??!1,onChange:c,caller:Ys});return u.jsxs(sT,{scope:n,checked:g,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":zh(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:fe(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Bh,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Lh.displayName=Ys;var $h="SwitchThumb",Fh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=iT($h,n);return u.jsx(Ne.span,{"data-state":zh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Fh.displayName=$h;var aT="SwitchBubbleInput",Bh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Fe(i,s),l=zp(n),c=Gc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const 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}})});Bh.displayName=aT;function zh(e){return e?"checked":"unchecked"}var Uh=Lh,lT=Fh;const Hn=v.forwardRef(({className:e,...t},n)=>u.jsx(Uh,{className:ne("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(lT,{className:ne("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Hn.displayName=Uh.displayName;const cT={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 uT({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}=ja();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(cT),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(eT,{open:r,onOpenChange:o,children:[u.jsx(tT,{asChild:!0,children:u.jsxs(Ye,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.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(Mh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Ph,{children:[u.jsx(Oh,{children:"Chat Settings"}),u.jsx(Dh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(co,{children:[u.jsx(uo,{className:"pb-3",children:u.jsxs(fo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(po,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Bs,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ye,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Hn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Bs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ye,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(co,{children:[u.jsx(uo,{className:"pb-3",children:u.jsxs(fo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(po,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Th,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(qa,{children:u.jsx(kh,{})}),u.jsxs(Ga,{children:[u.jsx(lr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(lr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(lr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Th,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(qa,{children:u.jsx(kh,{})}),u.jsxs(Ga,{children:[u.jsx(lr,{value:"light",children:"Light"}),u.jsx(lr,{value:"dark",children:"Dark"}),u.jsx(lr,{value:"system",children:"System"})]})]})]}),u.jsx(jh,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Hn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Hn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Hn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(co,{children:[u.jsx(uo,{className:"pb-3",children:u.jsxs(fo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(po,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Hn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Hn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Hn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ye,{variant:"outline",onClick:h,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ye,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Ye,{onClick:p,disabled:!c,children:[u.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function dT({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(Po,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Fs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Po,{...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(Ba,{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(Fs,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Po,{...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(Ba,{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(Fs,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Hl,Ce.ChatInput=fc,Ce.ChatInterface=Fs,Ce.ChatProviders=Po,Ce.ChatSettings=uT,Ce.MarkdownContent=lo,Ce.MessageComponent=$s,Ce.MessageList=Pa,Ce.ThreadManager=Ba,Ce.applySettings=gC,Ce.buildMessagePreviewMap=Xl,Ce.chatApiClient=jn,Ce.default=dT,Ce.del=Ul,Ce.get=Gt,Ce.getChatToken=Fl,Ce.getCurrentSettings=mC,Ce.getDefaultApiConfig=Dp,Ce.getDefaultChatSettings=Lp,Ce.onChatTokenChanged=Bl,Ce.post=fi,Ce.put=zl,Ce.setChatToken=Ao,Ce.useApi=pi,Ce.useChatStream=Jl,Ce.useMessagesReducer=Zl,Ce.useStream=uc,Ce.useThreadState=Mo,Ce.useThreads=Ro,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});