teodor-new-chat-ui 4.3.330 → 4.3.332

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(Ie,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):(Ie=typeof globalThis<"u"?globalThis:Ie||self,w(Ie.NewChatUI={},Ie.React,Ie.LucideReact,Ie.reactSlot,Ie.classVarianceAuthority,Ie.clsx,Ie.tailwindMerge,Ie.ReactDOM))})(this,function(Ie,w,se,zn,co,Vh,Kh,qs){"use strict";var hT=Object.defineProperty;var mT=(Ie,w,se)=>w in Ie?hT(Ie,w,{enumerable:!0,configurable:!0,writable:!0,value:se}):Ie[w]=se;var Hh=(Ie,w,se)=>mT(Ie,typeof w!="symbol"?w+"":w,se);var Gs=typeof document<"u"?document.currentScript:null;function Ga(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const v=Ga(w),uo=Ga(qs);var Ys={exports:{}},kr={};/**
1
+ (function(Te,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):(Te=typeof globalThis<"u"?globalThis:Te||self,w(Te.NewChatUI={},Te.React,Te.LucideReact,Te.reactSlot,Te.classVarianceAuthority,Te.clsx,Te.tailwindMerge,Te.ReactDOM))})(this,function(Te,w,ae,Wn,fo,zh,Uh,qs){"use strict";var uT=Object.defineProperty;var dT=(Te,w,ae)=>w in Te?uT(Te,w,{enumerable:!0,configurable:!0,writable:!0,value:ae}):Te[w]=ae;var Fh=(Te,w,ae)=>dT(Te,typeof w!="symbol"?w+"":w,ae);var Gs=typeof document<"u"?document.currentScript:null;function Va(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=Va(w),po=Va(qs);var Ys={exports:{}},Ar={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Ya;function qh(){if(Ya)return kr;Ya=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:p,ref:h,props:f,_owner:o.current}}return kr.Fragment=n,kr.jsx=i,kr.jsxs=i,kr}var Ir={};/**
9
+ */var Ka;function Hh(){if(Ka)return Ar;Ka=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var d,f={},p=null,h=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(h=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:p,ref:h,props:f,_owner:o.current}}return Ar.Fragment=n,Ar.jsx=i,Ar.jsxs=i,Ar}var Nr={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,33 +14,33 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Xa;function Gh(){return Xa||(Xa=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),h=Symbol.for("react.offscreen"),x=Symbol.iterator,m="@@iterator";function y(E){if(E===null||typeof E!="object")return null;var q=x&&E[x]||E[m];return typeof q=="function"?q:null}var g=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(E){{for(var q=arguments.length,ae=new Array(q>1?q-1:0),Te=1;Te<q;Te++)ae[Te-1]=arguments[Te];S("error",E,ae)}}function S(E,q,ae){{var Te=g.ReactDebugCurrentFrame,qe=Te.getStackAddendum();qe!==""&&(q+="%s",ae=ae.concat([qe]));var rt=ae.map(function($e){return String($e)});rt.unshift("Warning: "+q),Function.prototype.apply.call(console[E],console,rt)}}var k=!1,C=!1,T=!1,I=!1,A=!1,_;_=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===_||E.getModuleId!==void 0))}function M(E,q,ae){var Te=E.displayName;if(Te)return Te;var qe=q.displayName||q.name||"";return qe!==""?ae+"("+qe+")":ae}function P(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 q=E;return P(q)+".Consumer";case i:var ae=E;return P(ae._context)+".Provider";case l:return M(E,E.render,"ForwardRef");case f:var Te=E.displayName||null;return Te!==null?Te:F(E.type)||"Memo";case p:{var qe=E,rt=qe._payload,$e=qe._init;try{return F($e(rt))}catch{return null}}}return null}var N=Object.assign,B=0,R,Z,z,j,Y,J,oe;function ye(){}ye.__reactDisabledLog=!0;function Re(){{if(B===0){R=console.log,Z=console.info,z=console.warn,j=console.error,Y=console.group,J=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 K(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},E,{value:R}),info:N({},E,{value:Z}),warn:N({},E,{value:z}),error:N({},E,{value:j}),group:N({},E,{value:Y}),groupCollapsed:N({},E,{value:J}),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,G;function $(E,q,ae){{if(G===void 0)try{throw Error()}catch(qe){var Te=qe.stack.trim().match(/\n( *(at )?)/);G=Te&&Te[1]||""}return`
18
- `+G+E}}var W=!1,Q;{var le=typeof WeakMap=="function"?WeakMap:Map;Q=new le}function re(E,q){if(!E||W)return"";{var ae=Q.get(E);if(ae!==void 0)return ae}var Te;W=!0;var qe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var rt;rt=U.current,U.current=null,Re();try{if(q){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(Fe){Te=Fe}Reflect.construct(E,[],$e)}else{try{$e.call()}catch(Fe){Te=Fe}E.call($e.prototype)}}else{try{throw Error()}catch(Fe){Te=Fe}E()}}catch(Fe){if(Fe&&Te&&typeof Fe.stack=="string"){for(var Le=Fe.stack.split(`
19
- `),Et=Te.stack.split(`
17
+ */var qa;function Wh(){return qa||(qa=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),Ce=1;Ce<W;Ce++)ie[Ce-1]=arguments[Ce];S("error",E,ie)}}function S(E,W,ie){{var Ce=g.ReactDebugCurrentFrame,Ye=Ce.getStackAddendum();Ye!==""&&(W+="%s",ie=ie.concat([Ye]));var rt=ie.map(function($e){return String($e)});rt.unshift("Warning: "+W),Function.prototype.apply.call(console[E],console,rt)}}var k=!1,C=!1,T=!1,I=!1,A=!1,j;j=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===j||E.getModuleId!==void 0))}function M(E,W,ie){var Ce=E.displayName;if(Ce)return Ce;var Ye=W.displayName||W.name||"";return Ye!==""?ie+"("+Ye+")":ie}function P(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 P(W)+".Consumer";case i:var ie=E;return P(ie._context)+".Provider";case l:return M(E,E.render,"ForwardRef");case f:var Ce=E.displayName||null;return Ce!==null?Ce:F(E.type)||"Memo";case p:{var Ye=E,rt=Ye._payload,$e=Ye._init;try{return F($e(rt))}catch{return null}}}return null}var N=Object.assign,B=0,R,J,z,_,Y,X,se;function ye(){}ye.__reactDisabledLog=!0;function Re(){{if(B===0){R=console.log,J=console.info,z=console.warn,_=console.error,Y=console.group,X=console.groupCollapsed,se=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 K(){{if(B--,B===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},E,{value:R}),info:N({},E,{value:J}),warn:N({},E,{value:z}),error:N({},E,{value:_}),group:N({},E,{value:Y}),groupCollapsed:N({},E,{value:X}),groupEnd:N({},E,{value:se})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var H=g.ReactCurrentDispatcher,G;function $(E,W,ie){{if(G===void 0)try{throw Error()}catch(Ye){var Ce=Ye.stack.trim().match(/\n( *(at )?)/);G=Ce&&Ce[1]||""}return`
18
+ `+G+E}}var q=!1,Z;{var le=typeof WeakMap=="function"?WeakMap:Map;Z=new le}function oe(E,W){if(!E||q)return"";{var ie=Z.get(E);if(ie!==void 0)return ie}var Ce;q=!0;var Ye=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var rt;rt=H.current,H.current=null,Re();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(ze){Ce=ze}Reflect.construct(E,[],$e)}else{try{$e.call()}catch(ze){Ce=ze}E.call($e.prototype)}}else{try{throw Error()}catch(ze){Ce=ze}E()}}catch(ze){if(ze&&Ce&&typeof ze.stack=="string"){for(var Le=ze.stack.split(`
19
+ `),Et=Ce.stack.split(`
20
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 pe=`
21
- `+Le[mt].replace(" at new "," at ");return E.displayName&&pe.includes("<anonymous>")&&(pe=pe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Q.set(E,pe),pe}while(mt>=1&&xt>=0);break}}}finally{W=!1,U.current=rt,K(),Error.prepareStackTrace=qe}var ke=E?E.displayName||E.name:"",ve=ke?$(ke):"";return typeof E=="function"&&Q.set(E,ve),ve}function Ae(E,q,ae){return re(E,!1)}function Ue(E){var q=E.prototype;return!!(q&&q.isReactComponent)}function De(E,q,ae){if(E==null)return"";if(typeof E=="function")return re(E,Ue(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 De(E.type,q,ae);case p:{var Te=E,qe=Te._payload,rt=Te._init;try{return De(rt(qe),q,ae)}catch{}}}return""}var Ke=Object.prototype.hasOwnProperty,He={},fe=g.ReactDebugCurrentFrame;function be(E){if(E){var q=E._owner,ae=De(E.type,E._source,q?q.type:null);fe.setExtraStackFrame(ae)}else fe.setExtraStackFrame(null)}function Pe(E,q,ae,Te,qe){{var rt=Function.call.bind(Ke);for(var $e in E)if(rt(E,$e)){var Le=void 0;try{if(typeof E[$e]!="function"){var Et=Error((Te||"React class")+": "+ae+" type `"+$e+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[$e]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Et.name="Invariant Violation",Et}Le=E[$e](q,$e,Te,ae,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Le=mt}Le&&!(Le instanceof Error)&&(be(qe),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Te||"React class",ae,$e,typeof Le),be(null)),Le instanceof Error&&!(Le.message in He)&&(He[Le.message]=!0,be(qe),b("Failed %s type: %s",ae,Le.message),be(null))}}}var We=Array.isArray;function it(E){return We(E)}function Ge(E){{var q=typeof Symbol=="function"&&Symbol.toStringTag,ae=q&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ae}}function Qe(E){try{return at(E),!1}catch{return!0}}function at(E){return""+E}function Rt(E){if(Qe(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(E)),at(E)}var gt=g.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0},bt,St;function Lt(E){if(Ke.call(E,"ref")){var q=Object.getOwnPropertyDescriptor(E,"ref").get;if(q&&q.isReactWarning)return!1}return E.ref!==void 0}function Mt(E){if(Ke.call(E,"key")){var q=Object.getOwnPropertyDescriptor(E,"key").get;if(q&&q.isReactWarning)return!1}return E.key!==void 0}function et(E,q){typeof E.ref=="string"&&gt.current}function It(E,q){{var ae=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)",q))};ae.isReactWarning=!0,Object.defineProperty(E,"key",{get:ae,configurable:!0})}}function vn(E,q){{var ae=function(){St||(St=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",q))};ae.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ae,configurable:!0})}}var Ye=function(E,q,ae,Te,qe,rt,$e){var Le={$$typeof:t,type:E,key:q,ref:ae,props:$e,_owner:rt};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:Te}),Object.defineProperty(Le,"_source",{configurable:!1,enumerable:!1,writable:!1,value:qe}),Object.freeze&&(Object.freeze(Le.props),Object.freeze(Le)),Le};function tt(E,q,ae,Te,qe){{var rt,$e={},Le=null,Et=null;ae!==void 0&&(Rt(ae),Le=""+ae),Mt(q)&&(Rt(q.key),Le=""+q.key),Lt(q)&&(Et=q.ref,et(q,qe));for(rt in q)Ke.call(q,rt)&&!ht.hasOwnProperty(rt)&&($e[rt]=q[rt]);if(E&&E.defaultProps){var mt=E.defaultProps;for(rt in mt)$e[rt]===void 0&&($e[rt]=mt[rt])}if(Le||Et){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Le&&It($e,xt),Et&&vn($e,xt)}return Ye(E,Le,Et,qe,Te,gt.current,$e)}}var pt=g.ReactCurrentOwner,V=g.ReactDebugCurrentFrame;function ie(E){if(E){var q=E._owner,ae=De(E.type,E._source,q?q.type:null);V.setExtraStackFrame(ae)}else V.setExtraStackFrame(null)}var D;D=!1;function X(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function ne(){{if(pt.current){var E=F(pt.current.type);if(E)return`
21
+ `+Le[mt].replace(" at new "," at ");return E.displayName&&pe.includes("<anonymous>")&&(pe=pe.replace("<anonymous>",E.displayName)),typeof E=="function"&&Z.set(E,pe),pe}while(mt>=1&&xt>=0);break}}}finally{q=!1,H.current=rt,K(),Error.prepareStackTrace=Ye}var Ie=E?E.displayName||E.name:"",Ee=Ie?$(Ie):"";return typeof E=="function"&&Z.set(E,Ee),Ee}function _e(E,W,ie){return oe(E,!1)}function Ue(E){var W=E.prototype;return!!(W&&W.isReactComponent)}function De(E,W,ie){if(E==null)return"";if(typeof E=="function")return oe(E,Ue(E));if(typeof E=="string")return $(E);switch(E){case c:return $("Suspense");case d:return $("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case l:return _e(E.render);case f:return De(E.type,W,ie);case p:{var Ce=E,Ye=Ce._payload,rt=Ce._init;try{return De(rt(Ye),W,ie)}catch{}}}return""}var Ge=Object.prototype.hasOwnProperty,He={},fe=g.ReactDebugCurrentFrame;function ve(E){if(E){var W=E._owner,ie=De(E.type,E._source,W?W.type:null);fe.setExtraStackFrame(ie)}else fe.setExtraStackFrame(null)}function Pe(E,W,ie,Ce,Ye){{var rt=Function.call.bind(Ge);for(var $e in E)if(rt(E,$e)){var Le=void 0;try{if(typeof E[$e]!="function"){var Et=Error((Ce||"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,Ce,ie,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(mt){Le=mt}Le&&!(Le instanceof Error)&&(ve(Ye),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).",Ce||"React class",ie,$e,typeof Le),ve(null)),Le instanceof Error&&!(Le.message in He)&&(He[Le.message]=!0,ve(Ye),b("Failed %s type: %s",ie,Le.message),ve(null))}}}var We=Array.isArray;function it(E){return We(E)}function Xe(E){{var W=typeof Symbol=="function"&&Symbol.toStringTag,ie=W&&E[Symbol.toStringTag]||E.constructor.name||"Object";return ie}}function nt(E){try{return at(E),!1}catch{return!0}}function at(E){return""+E}function Rt(E){if(nt(E))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Xe(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 et(E,W){typeof E.ref=="string"&&gt.current}function It(E,W){{var ie=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))};ie.isReactWarning=!0,Object.defineProperty(E,"key",{get:ie,configurable:!0})}}function vn(E,W){{var ie=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))};ie.isReactWarning=!0,Object.defineProperty(E,"ref",{get:ie,configurable:!0})}}var Je=function(E,W,ie,Ce,Ye,rt,$e){var Le={$$typeof:t,type:E,key:W,ref:ie,props:$e,_owner:rt};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:Ce}),Object.defineProperty(Le,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ye}),Object.freeze&&(Object.freeze(Le.props),Object.freeze(Le)),Le};function tt(E,W,ie,Ce,Ye){{var rt,$e={},Le=null,Et=null;ie!==void 0&&(Rt(ie),Le=""+ie),Mt(W)&&(Rt(W.key),Le=""+W.key),Lt(W)&&(Et=W.ref,et(W,Ye));for(rt in W)Ge.call(W,rt)&&!ht.hasOwnProperty(rt)&&($e[rt]=W[rt]);if(E&&E.defaultProps){var mt=E.defaultProps;for(rt in mt)$e[rt]===void 0&&($e[rt]=mt[rt])}if(Le||Et){var xt=typeof E=="function"?E.displayName||E.name||"Unknown":E;Le&&It($e,xt),Et&&vn($e,xt)}return Je(E,Le,Et,Ye,Ce,gt.current,$e)}}var pt=g.ReactCurrentOwner,U=g.ReactDebugCurrentFrame;function re(E){if(E){var W=E._owner,ie=De(E.type,E._source,W?W.type:null);U.setExtraStackFrame(ie)}else U.setExtraStackFrame(null)}var D;D=!1;function Q(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function ne(){{if(pt.current){var E=F(pt.current.type);if(E)return`
22
22
 
23
- Check the render method of \``+E+"`."}return""}}function Ce(E){return""}var Xe={};function ge(E){{var q=ne();if(!q){var ae=typeof E=="string"?E:E.displayName||E.name;ae&&(q=`
23
+ Check the render method of \``+E+"`."}return""}}function Se(E){return""}var Ve={};function ge(E){{var W=ne();if(!W){var ie=typeof E=="string"?E:E.displayName||E.name;ie&&(W=`
24
24
 
25
- Check the top-level render call using <`+ae+">.")}return q}}function ut(E,q){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ae=ge(q);if(Xe[ae])return;Xe[ae]=!0;var Te="";E&&E._owner&&E._owner!==pt.current&&(Te=" It was passed a child from "+F(E._owner.type)+"."),ie(E),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ae,Te),ie(null)}}function we(E,q){{if(typeof E!="object")return;if(it(E))for(var ae=0;ae<E.length;ae++){var Te=E[ae];X(Te)&&ut(Te,q)}else if(X(E))E._store&&(E._store.validated=!0);else if(E){var qe=y(E);if(typeof qe=="function"&&qe!==E.entries)for(var rt=qe.call(E),$e;!($e=rt.next()).done;)X($e.value)&&ut($e.value,q)}}}function nt(E){{var q=E.type;if(q==null||typeof q=="string")return;var ae;if(typeof q=="function")ae=q.propTypes;else if(typeof q=="object"&&(q.$$typeof===l||q.$$typeof===f))ae=q.propTypes;else return;if(ae){var Te=F(q);Pe(ae,E.props,"prop",Te,E)}else if(q.PropTypes!==void 0&&!D){D=!0;var qe=F(q);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",qe||"Unknown")}typeof q.getDefaultProps=="function"&&!q.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ao(E){{for(var q=Object.keys(E.props),ae=0;ae<q.length;ae++){var Te=q[ae];if(Te!=="children"&&Te!=="key"){ie(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Te),ie(null);break}}E.ref!==null&&(ie(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}}var lo={};function Vs(E,q,ae,Te,qe,rt){{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=Ce();Et?Le+=Et:Le+=ne();var mt;E===null?mt="null":it(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=tt(E,q,ae,qe,rt);if(xt==null)return xt;if($e){var pe=q.children;if(pe!==void 0)if(Te)if(it(pe)){for(var ke=0;ke<pe.length;ke++)we(pe[ke],E);Object.freeze&&Object.freeze(pe)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else we(pe,E)}if(Ke.call(q,"key")){var ve=F(E),Fe=Object.keys(q).filter(function(Bn){return Bn!=="key"}),Fn=Fe.length>0?"{key: someKey, "+Fe.join(": ..., ")+": ...}":"{key: someKey}";if(!lo[ve+Fn]){var Tr=Fe.length>0?"{"+Fe.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 lt(E,W){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var ie=ge(W);if(Ve[ie])return;Ve[ie]=!0;var Ce="";E&&E._owner&&E._owner!==pt.current&&(Ce=" It was passed a child from "+F(E._owner.type)+"."),re(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,Ce),re(null)}}function be(E,W){{if(typeof E!="object")return;if(it(E))for(var ie=0;ie<E.length;ie++){var Ce=E[ie];Q(Ce)&&lt(Ce,W)}else if(Q(E))E._store&&(E._store.validated=!0);else if(E){var Ye=y(E);if(typeof Ye=="function"&&Ye!==E.entries)for(var rt=Ye.call(E),$e;!($e=rt.next()).done;)Q($e.value)&&lt($e.value,W)}}}function Ke(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 Ce=F(W);Pe(ie,E.props,"prop",Ce,E)}else if(W.PropTypes!==void 0&&!D){D=!0;var Ye=F(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ye||"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 In(E){{for(var W=Object.keys(E.props),ie=0;ie<W.length;ie++){var Ce=W[ie];if(Ce!=="children"&&Ce!=="key"){re(E),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ce),re(null);break}}E.ref!==null&&(re(E),b("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}}var En={};function Un(E,W,ie,Ce,Ye,rt){{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=Se();Et?Le+=Et:Le+=ne();var mt;E===null?mt="null":it(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=tt(E,W,ie,Ye,rt);if(xt==null)return xt;if($e){var pe=W.children;if(pe!==void 0)if(Ce)if(it(pe)){for(var Ie=0;Ie<pe.length;Ie++)be(pe[Ie],E);Object.freeze&&Object.freeze(pe)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else be(pe,E)}if(Ge.call(W,"key")){var Ee=F(E),ze=Object.keys(W).filter(function(cT){return cT!=="key"}),ln=ze.length>0?"{key: someKey, "+ze.join(": ..., ")+": ...}":"{key: someKey}";if(!En[Ee+ln]){var lT=ze.length>0?"{"+ze.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} />`,Fn,ve,Tr,ve),lo[ve+Fn]=!0}}return E===r?ao(xt):nt(xt),xt}}function Va(E,q,ae){return Vs(E,q,ae,!0)}function Ka(E,q,ae){return Vs(E,q,ae,!1)}var qa=Ka,Ks=Va;Ir.Fragment=r,Ir.jsx=qa,Ir.jsxs=Ks}()),Ir}process.env.NODE_ENV==="production"?Ys.exports=qh():Ys.exports=Gh();var u=Ys.exports;function Ja(e,t){return function(){return e.apply(t,arguments)}}const{toString:Yh}=Object.prototype,{getPrototypeOf:Xs}=Object,{iterator:fo,toStringTag:Za}=Symbol,po=(e=>t=>{const n=Yh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),en=e=>(e=e.toLowerCase(),t=>po(t)===e),ho=e=>t=>typeof t===e,{isArray:or}=Array,sr=ho("undefined");function Er(e){return e!==null&&!sr(e)&&e.constructor!==null&&!sr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Qa=en("ArrayBuffer");function Xh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Qa(e.buffer),t}const Jh=ho("string"),$t=ho("function"),el=ho("number"),Ar=e=>e!==null&&typeof e=="object",Zh=e=>e===!0||e===!1,mo=e=>{if(po(e)!=="object")return!1;const t=Xs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Za in e)&&!(fo in e)},Qh=e=>{if(!Ar(e)||Er(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},em=en("Date"),tm=en("File"),nm=en("Blob"),rm=en("FileList"),om=e=>Ar(e)&&$t(e.pipe),sm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=po(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},im=en("URLSearchParams"),[am,lm,cm,um]=["ReadableStream","Request","Response","Headers"].map(en),dm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Nr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),or(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Er(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function tl(e,t){if(Er(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 Un=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,nl=e=>!sr(e)&&e!==Un;function Js(){const{caseless:e,skipUndefined:t}=nl(this)&&this||{},n={},r=(o,s)=>{const i=e&&tl(n,s)||s;mo(n[i])&&mo(o)?n[i]=Js(n[i],o):mo(o)?n[i]=Js({},o):or(o)?n[i]=o.slice():(!t||!sr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Nr(arguments[o],r);return n}const fm=(e,t,n,{allOwnKeys:r}={})=>(Nr(t,(o,s)=>{n&&$t(o)?e[s]=Ja(o,n):e[s]=o},{allOwnKeys:r}),e),pm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),hm=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},mm=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&Xs(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(or(e))return e;let t=e.length;if(!el(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},ym=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Xs(Uint8Array)),vm=(e,t)=>{const r=(e&&e[fo]).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=en("HTMLFormElement"),Sm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),rl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Cm=en("RegExp"),ol=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Nr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},Tm=e=>{ol(e,(t,n)=>{if($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+"'")})}})},km=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return or(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&&$t(e.append)&&e[Za]==="FormData"&&e[fo])}const Nm=e=>{const t=new Array(10),n=(r,o)=>{if(Ar(r)){if(t.indexOf(r)>=0)return;if(Er(r))return r;if(!("toJSON"in r)){t[o]=r;const s=or(r)?[]:{};return Nr(r,(i,a)=>{const l=n(i,o+1);!sr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},_m=en("AsyncFunction"),jm=e=>e&&(Ar(e)||$t(e))&&$t(e.then)&&$t(e.catch),sl=((e,t)=>e?setImmediate:t?((n,r)=>(Un.addEventListener("message",({source:o,data:s})=>{o===Un&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Un.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Un.postMessage)),Rm=typeof queueMicrotask<"u"?queueMicrotask.bind(Un):typeof process<"u"&&process.nextTick||sl,O={isArray:or,isArrayBuffer:Qa,isBuffer:Er,isFormData:sm,isArrayBufferView:Xh,isString:Jh,isNumber:el,isBoolean:Zh,isObject:Ar,isPlainObject:mo,isEmptyObject:Qh,isReadableStream:am,isRequest:lm,isResponse:cm,isHeaders:um,isUndefined:sr,isDate:em,isFile:tm,isBlob:nm,isRegExp:Cm,isFunction:$t,isStream:om,isURLSearchParams:im,isTypedArray:ym,isFileList:rm,forEach:Nr,merge:Js,extend:fm,trim:dm,stripBOM:pm,inherits:hm,toFlatObject:mm,kindOf:po,kindOfTest:en,endsWith:gm,toArray:xm,forEachEntry:vm,matchAll:bm,isHTMLForm:wm,hasOwnProperty:rl,hasOwnProp:rl,reduceDescriptors:ol,freezeMethods:Tm,toObjectSet:km,toCamelCase:Sm,noop:Im,toFiniteNumber:Em,findKey:tl,global:Un,isContextDefined:nl,isSpecCompliantForm:Am,toJSONObject:Nm,isAsyncFn:_m,isThenable:jm,setImmediate:sl,asap:Rm,isIterable:e=>e!=null&&$t(e[fo])};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 il=je.prototype,al={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{al[e]={value:e}}),Object.defineProperties(je,al),Object.defineProperty(il,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(il);O.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return 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 Zs(e){return O.isPlainObject(e)||O.isArray(e)}function ll(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function cl(e,t,n){return e?e.concat(t).map(function(o,s){return o=ll(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function Pm(e){return O.isArray(e)&&!e.some(Zs)}const Om=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function go(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=ll(m),g.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?cl([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Zs(x)?!0:(t.append(cl(y,m,s),c(x)),!1)}const f=[],p=Object.assign(Om,{defaultVisitor:d,convertValue:c,isVisitable:Zs});function h(x,m){if(!O.isUndefined(x)){if(f.indexOf(x)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(x),O.forEach(x,function(g,b){(!(O.isUndefined(g)||g===null)&&o.call(t,g,O.isString(b)?b.trim():b,m,p))===!0&&h(g,m?m.concat(b):[b])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return h(e),t}function ul(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Qs(e,t){this._pairs=[],e&&go(e,this,t)}const dl=Qs.prototype;dl.append=function(t,n){this._pairs.push([t,n])},dl.toString=function(t){const n=t?function(r){return t.call(this,r,ul)}:ul;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Dm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function fl(e,t,n){if(!t)return e;const r=n&&n.encode||Dm;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new Qs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class pl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const hl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Lm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Qs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ei=typeof window<"u"&&typeof document<"u",ti=typeof navigator=="object"&&navigator||void 0,$m=ei&&(!ti||["ReactNative","NativeScript","NS"].indexOf(ti.product)<0),Fm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Bm=ei&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ei,hasStandardBrowserEnv:$m,hasStandardBrowserWebWorkerEnv:Fm,navigator:ti,origin:Bm},Symbol.toStringTag,{value:"Module"})),...Lm};function zm(e,t){return go(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 ml(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=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 _r={transitional:hl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(ml(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return zm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return go(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Wm(t)):t}],transformResponse:[function(t){const n=this.transitional||_r.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?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=>{_r.headers[e]={}});const Vm=O.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Km=e=>{const t={};let n,r,o;return e&&e.split(`
31
- `).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Vm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},gl=Symbol("internals");function jr(e){return e&&String(e).trim().toLowerCase()}function xo(e){return e===!1||e==null?e:O.isArray(e)?e.map(xo):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 ni(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 Ft=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=jr(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]=xo(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=jr(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=jr(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ni(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=jr(i),i){const a=O.findKey(r,i);a&&(!n||ni(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||ni(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]=xo(o),delete n[s];return}const a=t?Ym(s):String(s).trim();a!==s&&delete n[s],n[a]=xo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
32
- `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[gl]=this[gl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=jr(i);r[a]||(Xm(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function ri(e,t){const n=this||_r,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function xl(e){return!!(e&&e.__CANCEL__)}function ir(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(ir,je,{__CANCEL__:!0});function yl(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 yo=(e,t,n=3)=>{let r=0;const o=Zm(50,250);return Qm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&d?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},vl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},bl=e=>(...t)=>O.asap(()=>e(...t)),eg=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 wl(e,t,n){let r=!ng(t);return e&&(r||n==!1)?rg(e,t):t}const Sl=e=>e instanceof Ft?{...e}:e;function Hn(e,t){t=t||{};const n={};function r(c,d,f,p){return O.isPlainObject(c)&&O.isPlainObject(d)?O.merge.call({caseless:p},c,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(c,d,f,p){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c,f,p)}else return r(c,d,f,p)}function s(c,d){if(!O.isUndefined(d))return r(void 0,d)}function i(c,d){if(O.isUndefined(d)){if(!O.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(Sl(c),Sl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,p=f(e[d],t[d],d);O.isUndefined(p)&&f!==a||(n[d]=p)}),n}const Cl=e=>{const t=Hn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=fl(wl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(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=Cl(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};yl(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||hl;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]=yo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=yo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new ir(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 ir(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()}},Tl=(e,t,n,r)=>{const o=ag(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:d}=await o.next();if(c){a(),l.close();return}let f=d.byteLength;if(n){let p=s+=f;n(p)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},kl=64*1024,{isFunction:vo}=O,cg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Il,TextEncoder:El}=O.global,Al=(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?vo(t):typeof fetch=="function",s=vo(n),i=vo(r);if(!o)return!1;const a=o&&vo(Il),l=o&&(typeof El=="function"?(x=>m=>x.encode(m))(new El):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&Al(()=>{let x=!1;const m=new n(At.origin,{body:new Il,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&Al(()=>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:_="same-origin",fetchOptions:L}=Cl(x),M=t||fetch;I=I?(I+"").toLowerCase():"text";let P=sg([b,S&&S.toAbortSignal()],k),F=null;const N=P&&P.unsubscribe&&(()=>{P.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"}),oe;if(O.isFormData(g)&&(oe=J.headers.get("content-type"))&&A.setContentType(oe),J.body){const[ye,Re]=vl(B,yo(bl(T)));g=Tl(J.body,kl,ye,Re)}}O.isString(_)||(_=_?"include":"omit");const R=s&&"credentials"in n.prototype,Z={...L,signal:P,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:g,duplex:"half",credentials:R?_:void 0};F=s&&new n(m,Z);let z=await(s?M(F,L):M(m,Z));const j=d&&(I==="stream"||I==="response");if(d&&(C||j&&N)){const J={};["status","statusText","headers"].forEach(K=>{J[K]=z[K]});const oe=O.toFiniteNumber(z.headers.get("content-length")),[ye,Re]=C&&vl(oe,yo(bl(C),!0))||[];z=new r(Tl(z.body,kl,ye,()=>{Re&&Re(),N&&N()}),J)}I=I||"text";let Y=await f[O.findKey(f,I)||"text"](z,x);return!j&&N&&N(),await new Promise((J,oe)=>{yl(J,oe,{data:Y,headers:Ft.from(z.headers),status:z.status,statusText:z.statusText,config:x,request:F})})}catch(R){throw N&&N(),R&&R.name==="TypeError"&&/Load failed|fetch/i.test(R.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,x,F),{cause:R.cause||R}):je.from(R,R&&R.code,x,F)}}},dg=new Map,Nl=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};Nl();const oi={http:Mm,xhr:og,fetch:{get:Nl}};O.forEach(oi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const _l=e=>`- ${e}`,fg=e=>O.isFunction(e)||e===null||e===!1,jl={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=oi[(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(_l).join(`
34
- `):" "+_l(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:oi};function si(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ir(null,e)}function Rl(e){return si(e),e.headers=Ft.from(e.headers),e.data=ri.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),jl.getAdapter(e.adapter||_r.adapter,e)(e).then(function(r){return si(e),r.data=ri.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return xl(r)||(si(e),r&&r.response&&(r.response.data=ri.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const Ml="1.12.2",bo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{bo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Pl={};bo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Ml+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new je(o(i," has been removed"+(n?" in "+n:"")),je.ERR_DEPRECATED);return n&&!Pl[i]&&(Pl[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}},bo.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 wo={assertOptions:pg,validators:bo},cn=wo.validators;let Wn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new pl,response:new pl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
35
- `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Hn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&wo.assertOptions(r,{silentJSONParsing:cn.transitional(cn.boolean),forcedJSONParsing:cn.transitional(cn.boolean),clarifyTimeoutError:cn.transitional(cn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:wo.assertOptions(o,{encode:cn.function,serialize:cn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),wo.assertOptions(n,{baseUrl:cn.spelling("baseURL"),withXsrfToken:cn.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=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=[Rl.bind(this),void 0];for(x.unshift(...a),x.push(...c),p=x.length,d=Promise.resolve(n);f<p;)d=d.then(x[f++],x[f++]);return d}p=a.length;let h=n;for(;f<p;){const x=a[f++],m=a[f++];try{h=x(h)}catch(y){m.call(this,y);break}}try{d=Rl.call(this,h)}catch(x){return Promise.reject(x)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Hn(this.defaults,t);const n=wl(t.baseURL,t.url,t.allowAbsoluteUrls);return fl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){Wn.prototype[t]=function(n,r){return this.request(Hn(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(Hn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Wn.prototype[t]=n(),Wn.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 ir(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 ii={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ii).forEach(([e,t])=>{ii[t]=e});function Ol(e){const t=new Wn(e),n=Ja(Wn.prototype.request,t);return O.extend(n,Wn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ol(Hn(e,o))},n}const yt=Ol(_r);yt.Axios=Wn,yt.CanceledError=ir,yt.CancelToken=hg,yt.isCancel=xl,yt.VERSION=Ml,yt.toFormData=go,yt.AxiosError=je,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=mg,yt.isAxiosError=gg,yt.mergeConfig=Hn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>ml(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=jl.getAdapter,yt.HttpStatusCode=ii,yt.default=yt;const{Axios:ST,AxiosError:CT,CanceledError:TT,isCancel:kT,CancelToken:IT,VERSION:ET,all:AT,Cancel:NT,isAxiosError:_T,spread:jT,toFormData:RT,AxiosHeaders:MT,HttpStatusCode:PT,formToJSON:OT,getAdapter:DT,mergeConfig:LT}=yt,Dl=typeof window<"u"?window.__API_BASE_URL__:void 0,Ll=Dl?bn(Dl):void 0;function bn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let So=null;const ai=new Set;function $l(){return So}function Co(e){So=e,ai.forEach(t=>t(e))}function Fl(e){return ai.add(e),()=>ai.delete(e)}const xg=3e4,yg=9e4,Vt=yt.create({...Ll?{baseURL:Ll}:{},timeout:xg,withCredentials:!0});Vt.interceptors.request.use(e=>(So&&(e.headers.Authorization=`Bearer ${So}`),e)),Vt.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),Co(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Kt(e,t){return Vt.defaults.baseURL?(await Vt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function li(e,t,n){return Vt.defaults.baseURL?(await Vt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Bl(e,t,n){return Vt.defaults.baseURL?(await Vt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function zl(e,t){return Vt.defaults.baseURL?(await Vt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function qt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Ul{get baseUrl(){const t=Vt.defaults.baseURL;return t?bn(String(t)):""}updateConfig(t){t.baseUrl&&(Vt.defaults.baseURL=bn(String(t.baseUrl))),t.authToken!==void 0&&Co(t.authToken)}getAuthToken(){return $l()}setAuthToken(t){Co(t)}onTokenChange(t){return Fl(t)}async listThreads(){const t=await Kt("/threads"),n=qt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await li("/threads",t?{title:t}:void 0);return qt(r)}async updateThread(t,n){const r=await Bl(`/threads/${t}`,{title:n});return qt(r)}async deleteThread(t){const n=await zl(`/threads/${t}`);return qt(n)}async threadInfo(t){const n=await Kt(`/threads/${t}/info`);return qt(n)}async listAgents(){const t=await Kt("/agents"),n=qt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Kt(`/agents/${t}`);return qt(n)}async getAgentSchema(t){const n=await Kt(`/agents/${t}/schema`);return qt(n)}async getState(t){const n=await Kt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return qt(n)}async getStateHistory(t){const n=await Kt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:yg});return qt(n)}async cancelRun(t){const n=await li("/runs/cancel",{threadId:t});return qt(n)}async listCheckpointSummaries(t){const n=await Kt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=qt(n);return(r==null?void 0:r.items)??[]}}const In=new Ul,Hl=w.createContext(null);function vg({children:e,apiConfig:t}){const n=In;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(Hl.Provider,{value:r,children:e})}function ci(){const e=w.useContext(Hl);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 ui(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Cg(e,t){return`${e??""}::${t??""}`}function ar(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!ui(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=kg(t),i=Wl(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 Wl(e,t){if(!ui(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,L)=>Og(_,L)).filter(_=>!!_),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(_=>_.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: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(!ui(o))return;const i=Wl(o,s);if(!(i!=null&&i.checkpointId))return;const a=Cg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,Ng(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Kl(s.createdAt??"")-Kl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function 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=dt(i,["label"])??dt(i,["branch_label","branchLabel"])??dt(i,["description"])??"User input",l=Ag(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=Eg(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0})}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:To(e.metadata,t.metadata)??null,config:To(e.config,t.config)??null,parentConfig:To(e.parentConfig,t.parentConfig)??null,next:_g(e.next,t.next)??null,tasks:jg(e.tasks,t.tasks)??null,values:To(e.values,t.values)??null}}function To(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=Rr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Rr(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=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 Rr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Vl(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Rr(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=Rr(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=Rr(l,t,n+1,r);if(c)return c}}return null}function Vl(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=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=Vl(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Kl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Og(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=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=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=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(Pt(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=>ql(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=ql(e);return t?[t]:[]}return[]}function ql(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=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 Gl(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=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 Gl(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=Ug(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Lg(e){return Array.isArray(e)?e.map((t,n)=>Gl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function $g(e,t){const n=e.content??e.output;if(!n)return t;const o={type:"text",text:typeof n=="string"?n:JSON.stringify(n)};return[...t,o]}function Fg(e){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 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 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}function Yl(e,t){if(!t||!e.length)return null;for(const n of e)if(n.lastUserMessageId!==t&&n.lastUserMessageId!==null&&n.lastUserMessageId!==void 0)return n;return null}const lr=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>lr?`${n.slice(0,lr-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>lr?`${i.slice(0,lr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>lr?`${n.slice(0,lr-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(()=>bn(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),_=w.useRef(null),L=w.useCallback(N=>{o(N)},[]),M=w.useCallback(()=>{p(""),x(null),d(null),I.current=null,A.current=null,_.current=null},[]),P=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,R)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),I.current=null,A.current=null,_.current=null;const Z=new AbortController;S.current=Z;let z=null,j=null,Y=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var oe,ye,Re,K,U,G,$,W,Q,le,re,Ae,Ue,De,Ke,He,fe,be;const J=Pe=>{var We;try{const it=JSON.parse(JSON.stringify(Pe));return(We=it==null?void 0:it.payload)!=null&&We.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(Ge=>({...Ge,data:Ge!=null&&Ge.data?`<base64 ${String(Ge.data).length} chars>`:Ge==null?void 0:Ge.data}))),it}catch{return Pe}};try{let Pe={};try{if(r)Pe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const tt=window.__AUTH_TOKEN__,pt=((oe=window.localStorage)==null?void 0:oe.getItem("authToken"))||null;let V=null;try{const D=(ye=window.localStorage)==null?void 0:ye.getItem("chat-settings");D&&(V=((Re=JSON.parse(D))==null?void 0:Re.apiKey)||null)}catch{}const ie=tt||pt||V||null;ie&&(Pe={Authorization:`Bearer ${ie}`})}}catch{}console.debug("[use-chat] POST",t+n,J(N));let We={};if(typeof window<"u")try{const Ye=(K=window.localStorage)==null?void 0:K.getItem("authSessionId");Ye&&(We={"X-Session-Id":Ye})}catch{}const it={...Pe,...We,...s.current},Ge={"Content-Type":"application/json",Accept:"text/event-stream",...it},Qe=await fetch(t+n,{method:"POST",headers:Ge,body:JSON.stringify(N),signal:Z.signal,credentials:i});if(T.current&&(T.current.headers=it),!Qe.ok||!Qe.body){const Ye=await Qe.text().catch(()=>"");console.debug("[use-chat] non-OK response",Qe.status,Ye==null?void 0:Ye.slice(0,500));const tt=`stream ${Qe.status}${Ye?": "+Ye:""}`;throw(U=R==null?void 0:R.onConnectionError)==null||U.call(R,tt),Y=!0,z="error",j=tt,new Error(tt)}b(!0);const at=Qe.body.getReader(),Rt=new TextDecoder;let gt="",ht=[];C.current=0,y(0);let bt=0,St=null;const Lt=()=>{if(ht.length){const Ye=ht.join("");ht=[],k.current&&p(tt=>tt+Ye)}St=null},Mt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Lt))};let et=Date.now();const It=setInterval(()=>{var Ye;if(Date.now()-et>18e5){const tt="Stream idle timeout";d(tt),z="error",j=tt,Z.abort(),(Ye=R==null?void 0:R.onError)==null||Ye.call(R,tt)}},5e3),vn=1024*1024;try{const Ye=Qe.headers.get("X-Thread-Id")||Qe.headers.get("x-thread-id"),tt=Qe.headers.get("X-Thread-Created")||Qe.headers.get("x-thread-created"),pt=Ye??null,V=String(tt??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(G=R==null?void 0:R.onOpen)==null||G.call(R,{threadId:pt,created:V});;){const{value:ie,done:D}=await at.read();if(D)break;gt+=Rt.decode(ie,{stream:!0}),gt.length>vn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let X;for(;(X=gt.indexOf(`
30
+ <%s key={someKey} {...props} />`,ln,Ee,lT,Ee),En[Ee+ln]=!0}}return E===r?In(xt):Ke(xt),xt}}function uo(E,W,ie){return Un(E,W,ie,!0)}function Hn(E,W,ie){return Un(E,W,ie,!1)}var Er=Hn,An=uo;Nr.Fragment=r,Nr.jsx=Er,Nr.jsxs=An}()),Nr}process.env.NODE_ENV==="production"?Ys.exports=Hh():Ys.exports=Wh();var u=Ys.exports;function Ga(e,t){return function(){return e.apply(t,arguments)}}const{toString:Vh}=Object.prototype,{getPrototypeOf:Xs}=Object,{iterator:ho,toStringTag:Ya}=Symbol,mo=(e=>t=>{const n=Vh.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),en=e=>(e=e.toLowerCase(),t=>mo(t)===e),go=e=>t=>typeof t===e,{isArray:ar}=Array,lr=go("undefined");function _r(e){return e!==null&&!lr(e)&&e.constructor!==null&&!lr(e.constructor)&&$t(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Xa=en("ArrayBuffer");function Kh(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Xa(e.buffer),t}const qh=go("string"),$t=go("function"),Ja=go("number"),jr=e=>e!==null&&typeof e=="object",Gh=e=>e===!0||e===!1,xo=e=>{if(mo(e)!=="object")return!1;const t=Xs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ya in e)&&!(ho in e)},Yh=e=>{if(!jr(e)||_r(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Xh=en("Date"),Jh=en("File"),Zh=en("Blob"),Qh=en("FileList"),em=e=>jr(e)&&$t(e.pipe),tm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||$t(e.append)&&((t=mo(e))==="formdata"||t==="object"&&$t(e.toString)&&e.toString()==="[object FormData]"))},nm=en("URLSearchParams"),[rm,om,sm,im]=["ReadableStream","Request","Response","Headers"].map(en),am=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Rr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),ar(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(_r(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 Za(e,t){if(_r(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Vn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Qa=e=>!lr(e)&&e!==Vn;function Js(){const{caseless:e,skipUndefined:t}=Qa(this)&&this||{},n={},r=(o,s)=>{const i=e&&Za(n,s)||s;xo(n[i])&&xo(o)?n[i]=Js(n[i],o):xo(o)?n[i]=Js({},o):ar(o)?n[i]=o.slice():(!t||!lr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Rr(arguments[o],r);return n}const lm=(e,t,n,{allOwnKeys:r}={})=>(Rr(t,(o,s)=>{n&&$t(o)?e[s]=Ga(o,n):e[s]=o},{allOwnKeys:r}),e),cm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),um=(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)},dm=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&Xs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},fm=(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},pm=e=>{if(!e)return null;if(ar(e))return e;let t=e.length;if(!Ja(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},hm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Xs(Uint8Array)),mm=(e,t)=>{const r=(e&&e[ho]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},gm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},xm=en("HTMLFormElement"),ym=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),el=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),vm=en("RegExp"),tl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Rr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},bm=e=>{tl(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+"'")})}})},wm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ar(e)?r(e):r(String(e).split(t)),n},Sm=()=>{},Cm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Tm(e){return!!(e&&$t(e.append)&&e[Ya]==="FormData"&&e[ho])}const km=e=>{const t=new Array(10),n=(r,o)=>{if(jr(r)){if(t.indexOf(r)>=0)return;if(_r(r))return r;if(!("toJSON"in r)){t[o]=r;const s=ar(r)?[]:{};return Rr(r,(i,a)=>{const l=n(i,o+1);!lr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Im=en("AsyncFunction"),Em=e=>e&&(jr(e)||$t(e))&&$t(e.then)&&$t(e.catch),nl=((e,t)=>e?setImmediate:t?((n,r)=>(Vn.addEventListener("message",({source:o,data:s})=>{o===Vn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Vn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",$t(Vn.postMessage)),Am=typeof queueMicrotask<"u"?queueMicrotask.bind(Vn):typeof process<"u"&&process.nextTick||nl,O={isArray:ar,isArrayBuffer:Xa,isBuffer:_r,isFormData:tm,isArrayBufferView:Kh,isString:qh,isNumber:Ja,isBoolean:Gh,isObject:jr,isPlainObject:xo,isEmptyObject:Yh,isReadableStream:rm,isRequest:om,isResponse:sm,isHeaders:im,isUndefined:lr,isDate:Xh,isFile:Jh,isBlob:Zh,isRegExp:vm,isFunction:$t,isStream:em,isURLSearchParams:nm,isTypedArray:hm,isFileList:Qh,forEach:Rr,merge:Js,extend:lm,trim:am,stripBOM:cm,inherits:um,toFlatObject:dm,kindOf:mo,kindOfTest:en,endsWith:fm,toArray:pm,forEachEntry:mm,matchAll:gm,isHTMLForm:xm,hasOwnProperty:el,hasOwnProp:el,reduceDescriptors:tl,freezeMethods:bm,toObjectSet:wm,toCamelCase:ym,noop:Sm,toFiniteNumber:Cm,findKey:Za,global:Vn,isContextDefined:Qa,isSpecCompliantForm:Tm,toJSONObject:km,isAsyncFn:Im,isThenable:Em,setImmediate:nl,asap:Am,isIterable:e=>e!=null&&$t(e[ho])};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 rl=je.prototype,ol={};["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=>{ol[e]={value:e}}),Object.defineProperties(je,ol),Object.defineProperty(rl,"isAxiosError",{value:!0}),je.from=(e,t,n,r,o,s)=>{const i=Object.create(rl);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 Nm=null;function Zs(e){return O.isPlainObject(e)||O.isArray(e)}function sl(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function il(e,t,n){return e?e.concat(t).map(function(o,s){return o=sl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function _m(e){return O.isArray(e)&&!e.some(Zs)}const jm=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function yo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,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)&&_m(x)||(O.isFileList(x)||O.endsWith(m,"[]"))&&(g=O.toArray(x)))return m=sl(m),g.forEach(function(S,k){!(O.isUndefined(S)||S===null)&&t.append(i===!0?il([m],k,s):i===null?m:m+"[]",c(S))}),!1}return Zs(x)?!0:(t.append(il(y,m,s),c(x)),!1)}const f=[],p=Object.assign(jm,{defaultVisitor:d,convertValue:c,isVisitable:Zs});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 al(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Qs(e,t){this._pairs=[],e&&yo(e,this,t)}const ll=Qs.prototype;ll.append=function(t,n){this._pairs.push([t,n])},ll.toString=function(t){const n=t?function(r){return t.call(this,r,al)}:al;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Rm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function cl(e,t,n){if(!t)return e;const r=n&&n.encode||Rm;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 Qs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class ul{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 dl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Mm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Qs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ei=typeof window<"u"&&typeof document<"u",ti=typeof navigator=="object"&&navigator||void 0,Pm=ei&&(!ti||["ReactNative","NativeScript","NS"].indexOf(ti.product)<0),Om=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Dm=ei&&window.location.href||"http://localhost",At={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ei,hasStandardBrowserEnv:Pm,hasStandardBrowserWebWorkerEnv:Om,navigator:ti,origin:Dm},Symbol.toStringTag,{value:"Module"})),...Mm};function Lm(e,t){return yo(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 $m(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Fm(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function fl(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]=Fm(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t($m(r),o,n,0)}),n}return null}function Bm(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 Mr={transitional:dl,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(fl(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 Lm(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return yo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Bm(t)):t}],transformResponse:[function(t){const n=this.transitional||Mr.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=>{Mr.headers[e]={}});const zm=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"]),Um=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]&&zm[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},pl=Symbol("internals");function Pr(e){return e&&String(e).trim().toLowerCase()}function vo(e){return e===!1||e==null?e:O.isArray(e)?e.map(vo):String(e)}function Hm(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const Wm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ni(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 Vm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Km(e,t){const n=O.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Ft=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=Pr(l);if(!d)throw new Error("header name must be a non-empty string");const f=O.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=vo(a))}const i=(a,l)=>O.forEach(a,(c,d)=>s(c,d,l));if(O.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(O.isString(t)&&(t=t.trim())&&!Wm(t))i(Um(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=Pr(t),t){const r=O.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Hm(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=Pr(t),t){const r=O.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ni(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Pr(i),i){const a=O.findKey(r,i);a&&(!n||ni(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||ni(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return O.forEach(this,(o,s)=>{const i=O.findKey(r,s);if(i){n[i]=vo(o),delete n[s];return}const a=t?Vm(s):String(s).trim();a!==s&&delete n[s],n[a]=vo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return O.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&O.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
32
+ `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[pl]=this[pl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Pr(i);r[a]||(Km(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ft);function ri(e,t){const n=this||Mr,r=t||n,o=Ft.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function hl(e){return!!(e&&e.__CANCEL__)}function cr(e,t,n){je.call(this,e??"canceled",je.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(cr,je,{__CANCEL__:!0});function ml(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 qm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Gm(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 Ym(e,t){let n=0,r=1e3/t,o,s;const i=(c,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const d=Date.now(),f=d-n;f>=r?i(c,d):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const bo=(e,t,n=3)=>{let r=0;const o=Gm(50,250);return Ym(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)},gl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},xl=e=>(...t)=>O.asap(()=>e(...t)),Xm=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,Jm=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 Zm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Qm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function yl(e,t,n){let r=!Zm(t);return e&&(r||n==!1)?Qm(e,t):t}const vl=e=>e instanceof Ft?{...e}:e;function Kn(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(vl(c),vl(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 bl=e=>{const t=Kn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=cl(yl(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&&Xm(t.url))){const l=o&&s&&Jm.read(s);l&&i.set(o,l)}return t},eg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=bl(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};ml(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||dl;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]=bo(c,!0),y.addEventListener("progress",p)),l&&y.upload&&([f,h]=bo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",h)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new cr(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=qm(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)})},tg=(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 cr(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}},ng=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},rg=async function*(e,t){for await(const n of og(e))yield*ng(n,t)},og=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()}},wl=(e,t,n,r)=>{const o=rg(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})},Sl=64*1024,{isFunction:wo}=O,sg=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:Cl,TextEncoder:Tl}=O.global,kl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ig=e=>{e=O.merge.call({skipUndefined:!0},sg,e);const{fetch:t,Request:n,Response:r}=e,o=t?wo(t):typeof fetch=="function",s=wo(n),i=wo(r);if(!o)return!1;const a=o&&wo(Cl),l=o&&(typeof Tl=="function"?(x=>m=>x.encode(m))(new Tl):async x=>new Uint8Array(await new n(x).arrayBuffer())),c=s&&a&&kl(()=>{let x=!1;const m=new n(At.origin,{body:new Cl,method:"POST",get duplex(){return x=!0,"half"}}).headers.has("Content-Type");return x&&!m}),d=i&&a&&kl(()=>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:j="same-origin",fetchOptions:L}=bl(x),M=t||fetch;I=I?(I+"").toLowerCase():"text";let P=tg([b,S&&S.toAbortSignal()],k),F=null;const N=P&&P.unsubscribe&&(()=>{P.unsubscribe()});let B;try{if(T&&c&&y!=="get"&&y!=="head"&&(B=await h(A,g))!==0){let X=new n(m,{method:"POST",body:g,duplex:"half"}),se;if(O.isFormData(g)&&(se=X.headers.get("content-type"))&&A.setContentType(se),X.body){const[ye,Re]=gl(B,bo(xl(T)));g=wl(X.body,Sl,ye,Re)}}O.isString(j)||(j=j?"include":"omit");const R=s&&"credentials"in n.prototype,J={...L,signal:P,method:y.toUpperCase(),headers:A.normalize().toJSON(),body:g,duplex:"half",credentials:R?j:void 0};F=s&&new n(m,J);let z=await(s?M(F,L):M(m,J));const _=d&&(I==="stream"||I==="response");if(d&&(C||_&&N)){const X={};["status","statusText","headers"].forEach(K=>{X[K]=z[K]});const se=O.toFiniteNumber(z.headers.get("content-length")),[ye,Re]=C&&gl(se,bo(xl(C),!0))||[];z=new r(wl(z.body,Sl,ye,()=>{Re&&Re(),N&&N()}),X)}I=I||"text";let Y=await f[O.findKey(f,I)||"text"](z,x);return!_&&N&&N(),await new Promise((X,se)=>{ml(X,se,{data:Y,headers:Ft.from(z.headers),status:z.status,statusText:z.statusText,config:x,request:F})})}catch(R){throw N&&N(),R&&R.name==="TypeError"&&/Load failed|fetch/i.test(R.message)?Object.assign(new je("Network Error",je.ERR_NETWORK,x,F),{cause:R.cause||R}):je.from(R,R&&R.code,x,F)}}},ag=new Map,Il=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,d=ag;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ig(t)),d=c;return c};Il();const oi={http:Nm,xhr:eg,fetch:{get:Il}};O.forEach(oi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const El=e=>`- ${e}`,lg=e=>O.isFunction(e)||e===null||e===!1,Al={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,!lg(r)&&(o=oi[(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(El).join(`
34
+ `):" "+El(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:oi};function si(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new cr(null,e)}function Nl(e){return si(e),e.headers=Ft.from(e.headers),e.data=ri.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Al.getAdapter(e.adapter||Mr.adapter,e)(e).then(function(r){return si(e),r.data=ri.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return hl(r)||(si(e),r&&r.response&&(r.response.data=ri.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const _l="1.12.2",So={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{So[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const jl={};So.transitional=function(t,n,r){function o(s,i){return"[Axios v"+_l+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new je(o(i," has been removed"+(n?" in "+n:"")),je.ERR_DEPRECATED);return n&&!jl[i]&&(jl[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},So.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function cg(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 Co={assertOptions:cg,validators:So},cn=Co.validators;let qn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new ul,response:new ul}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
35
+ `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Kn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Co.assertOptions(r,{silentJSONParsing:cn.transitional(cn.boolean),forcedJSONParsing:cn.transitional(cn.boolean),clarifyTimeoutError:cn.transitional(cn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:Co.assertOptions(o,{encode:cn.function,serialize:cn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Co.assertOptions(n,{baseUrl:cn.spelling("baseURL"),withXsrfToken:cn.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=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=[Nl.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=Nl.call(this,h)}catch(x){return Promise.reject(x)}for(f=0,p=c.length;f<p;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=Kn(this.defaults,t);const n=yl(t.baseURL,t.url,t.allowAbsoluteUrls);return cl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){qn.prototype[t]=function(n,r){return this.request(Kn(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Kn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}qn.prototype[t]=n(),qn.prototype[t+"Form"]=n(!0)});let ug=class Bh{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new cr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Bh(function(o){t=o}),cancel:t}}};function dg(e){return function(n){return e.apply(null,n)}}function fg(e){return O.isObject(e)&&e.isAxiosError===!0}const ii={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ii).forEach(([e,t])=>{ii[t]=e});function Rl(e){const t=new qn(e),n=Ga(qn.prototype.request,t);return O.extend(n,qn.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Rl(Kn(e,o))},n}const yt=Rl(Mr);yt.Axios=qn,yt.CanceledError=cr,yt.CancelToken=ug,yt.isCancel=hl,yt.VERSION=_l,yt.toFormData=yo,yt.AxiosError=je,yt.Cancel=yt.CanceledError,yt.all=function(t){return Promise.all(t)},yt.spread=dg,yt.isAxiosError=fg,yt.mergeConfig=Kn,yt.AxiosHeaders=Ft,yt.formToJSON=e=>fl(O.isHTMLForm(e)?new FormData(e):e),yt.getAdapter=Al.getAdapter,yt.HttpStatusCode=ii,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,Ml=typeof window<"u"?window.__API_BASE_URL__:void 0,Pl=Ml?bn(Ml):void 0;function bn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let To=null;const ai=new Set;function Ol(){return To}function ko(e){To=e,ai.forEach(t=>t(e))}function Dl(e){return ai.add(e),()=>ai.delete(e)}const pg=3e4,hg=9e4,Vt=yt.create({...Pl?{baseURL:Pl}:{},timeout:pg,withCredentials:!0});Vt.interceptors.request.use(e=>(To&&(e.headers.Authorization=`Bearer ${To}`),e)),Vt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem("authToken",r),ko(r)),o&&localStorage.setItem("authTokenExpiresAt",o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Kt(e,t){return Vt.defaults.baseURL?(await Vt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function li(e,t,n){return Vt.defaults.baseURL?(await Vt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ll(e,t,n){return Vt.defaults.baseURL?(await Vt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function $l(e,t){return Vt.defaults.baseURL?(await Vt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function qt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Fl{get baseUrl(){const t=Vt.defaults.baseURL;return t?bn(String(t)):""}updateConfig(t){t.baseUrl&&(Vt.defaults.baseURL=bn(String(t.baseUrl))),t.authToken!==void 0&&ko(t.authToken)}getAuthToken(){return Ol()}setAuthToken(t){ko(t)}onTokenChange(t){return Dl(t)}async listThreads(){const t=await Kt("/threads"),n=qt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await li("/threads",t?{title:t}:void 0);return qt(r)}async updateThread(t,n){const r=await Ll(`/threads/${t}`,{title:n});return qt(r)}async deleteThread(t){const n=await $l(`/threads/${t}`);return qt(n)}async threadInfo(t){const n=await Kt(`/threads/${t}/info`);return qt(n)}async listAgents(){const t=await Kt("/agents"),n=qt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Kt(`/agents/${t}`);return qt(n)}async getAgentSchema(t){const n=await Kt(`/agents/${t}/schema`);return qt(n)}async getState(t){const n=await Kt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return qt(n)}async getStateHistory(t){const n=await Kt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:hg});return qt(n)}async cancelRun(t){const n=await li("/runs/cancel",{threadId:t});return qt(n)}async listCheckpointSummaries(t){const n=await Kt(`/threads/${t}/state/checkpoints`,{params:{thread_id:t}}),r=qt(n);return(r==null?void 0:r.items)??[]}}const Nn=new Fl,Bl=w.createContext(null);function mg({children:e,apiConfig:t}){const n=Nn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return u.jsx(Bl.Provider,{value:r,children:e})}function ci(){const e=w.useContext(Bl);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function gg(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 xg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await gg(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const yg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function ui(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function vg(e,t){return`${e??""}::${t??""}`}function ur(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!ui(r))return{threadId:n,latest:null,checkpoints:[],timeline:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=wg(t),i=zl(r,0),a=Sg(o);return{threadId:n,latest:i,checkpoints:o,timeline:a,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function zl(e,t){if(!ui(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(j=>!!j&&typeof j=="object").map(j=>({...j})):a===null?null:void 0,c=r.map((j,L)=>jg(j,L)).filter(j=>!!j),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(j=>j.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:bg(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 bg(e,t,n){const r=Ng(e,n);return r||Ag(t,n)}function wg(e){const t=new Map;e.forEach((o,s)=>{if(!ui(o))return;const i=zl(o,s);if(!(i!=null&&i.checkpointId))return;const a=vg(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,kg(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Hl(s.createdAt??"")-Hl(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function Sg(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=Tg(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=Cg(o.next);t.push({id:s,label:a,messageId:p,step:l,source:c??null,createdAt:d,next:h??void 0})}return t}function Cg(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 Tg(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 kg(e,t){return{...e,metadata:Io(e.metadata,t.metadata)??null,config:Io(e.config,t.config)??null,parentConfig:Io(e.parentConfig,t.parentConfig)??null,next:Ig(e.next,t.next)??null,tasks:Eg(e.tasks,t.tasks)??null,values:Io(e.values,t.values)??null}}function Io(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?e:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Ig(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 Eg(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 Ag(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 Ng(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=_g(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Or(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Or(r.state,`${o}-state`);if(s)return s}}return null}function _g(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 Or(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Ul(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Or(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Or(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const c=Or(l,t,n+1,r);if(c)return c}}return null}function Ul(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=Ul(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 Hl(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function jg(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=yg[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=Rg(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=Og(Pt(o.artifact??r.artifact??o.artifacts??r.artifacts));y&&(m.artifact=y);const g=Fg(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=Mg((c==null?void 0:c.tool_calls)??o.tool_calls);if(S.length&&(m.content=[...m.content,...S]),i==="tool"){const k=Pg(o,m.content);k&&(m.content=k)}return m}function Rg(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Wl(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Wl(e);return t?[t]:[]}return[]}function Wl(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 Vl(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 Vl(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=$g(e.args??e.arguments??((s=Pt(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Mg(e){return Array.isArray(e)?e.map((t,n)=>Vl(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Pg(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 Og(e){return e?{plots:Dg(e.plots)}:void 0}function Dg(e){return Array.isArray(e)?e.map(t=>Lg(t)).filter(t=>!!t):[]}function Lg(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 $g(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 Fg(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}const dr=120;function Bg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>dr?`${n.slice(0,dr-3)}…`:n:""}function zg(e){var r,o;const t=[(r=e.additionalKwargs)==null?void 0:r.summary,(o=e.responseMetadata)==null?void 0:o.summary];for(const s of t)if(typeof s=="string"&&s.trim()){const i=s.trim();return i.length>dr?`${i.slice(0,dr-3)}…`:i}const n=(e.name||e.id||"").toString().trim();return n?n.length>dr?`${n.slice(0,dr-3)}…`:n:""}function Kl(e){const t=new Map;for(const n of e){if(!n.id||n.role!=="user")continue;const o=Bg(n.content)||zg(n);o&&t.set(n.id,o)}return t}function ql(e={}){const t=w.useMemo(()=>bn(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),j=w.useRef(null),L=w.useCallback(N=>{o(N)},[]),M=w.useCallback(()=>{p(""),x(null),d(null),I.current=null,A.current=null,j.current=null},[]),P=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,R)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&p(""),x(null),I.current=null,A.current=null,j.current=null;const J=new AbortController;S.current=J;let z=null,_=null,Y=!1;return T.current={threadId:N.threadId??null,headers:{}},(async()=>{var se,ye,Re,K,H,G,$,q,Z,le,oe,_e,Ue,De,Ge,He,fe,ve;const X=Pe=>{var We;try{const it=JSON.parse(JSON.stringify(Pe));return(We=it==null?void 0:it.payload)!=null&&We.files_info&&Array.isArray(it.payload.files_info)&&(it.payload.files_info=it.payload.files_info.map(Xe=>({...Xe,data:Xe!=null&&Xe.data?`<base64 ${String(Xe.data).length} chars>`:Xe==null?void 0:Xe.data}))),it}catch{return Pe}};try{let Pe={};try{if(r)Pe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const tt=window.__AUTH_TOKEN__,pt=((se=window.localStorage)==null?void 0:se.getItem("authToken"))||null;let U=null;try{const D=(ye=window.localStorage)==null?void 0:ye.getItem("chat-settings");D&&(U=((Re=JSON.parse(D))==null?void 0:Re.apiKey)||null)}catch{}const re=tt||pt||U||null;re&&(Pe={Authorization:`Bearer ${re}`})}}catch{}console.debug("[use-chat] POST",t+n,X(N));let We={};if(typeof window<"u")try{const Je=(K=window.localStorage)==null?void 0:K.getItem("authSessionId");Je&&(We={"X-Session-Id":Je})}catch{}const it={...Pe,...We,...s.current},Xe={"Content-Type":"application/json",Accept:"text/event-stream",...it},nt=await fetch(t+n,{method:"POST",headers:Xe,body:JSON.stringify(N),signal:J.signal,credentials:i});if(T.current&&(T.current.headers=it),!nt.ok||!nt.body){const Je=await nt.text().catch(()=>"");console.debug("[use-chat] non-OK response",nt.status,Je==null?void 0:Je.slice(0,500));const tt=`stream ${nt.status}${Je?": "+Je:""}`;throw(H=R==null?void 0:R.onConnectionError)==null||H.call(R,tt),Y=!0,z="error",_=tt,new Error(tt)}b(!0);const at=nt.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(tt=>tt+Je)}St=null},Mt=()=>{typeof window<"u"&&St==null&&(St=requestAnimationFrame(Lt))};let et=Date.now();const It=setInterval(()=>{var Je;if(Date.now()-et>18e5){const tt="Stream idle timeout";d(tt),z="error",_=tt,J.abort(),(Je=R==null?void 0:R.onError)==null||Je.call(R,tt)}},5e3),vn=1024*1024;try{const Je=nt.headers.get("X-Thread-Id")||nt.headers.get("x-thread-id"),tt=nt.headers.get("X-Thread-Created")||nt.headers.get("x-thread-created"),pt=Je??null,U=String(tt??"").toLowerCase()==="true";for(T.current&&!T.current.threadId&&(T.current={...T.current,threadId:pt}),(G=R==null?void 0:R.onOpen)==null||G.call(R,{threadId:pt,created:U});;){const{value:re,done:D}=await at.read();if(D)break;gt+=Rt.decode(re,{stream:!0}),gt.length>vn&&(gt="",console.warn("Stream buffer reset: exceeded 1MB"));let Q;for(;(Q=gt.indexOf(`
36
36
 
37
- `))>=0;){const ne=gt.slice(0,X);gt=gt.slice(X+2);const Ce=qg(ne);if(!Ce)continue;let Xe;try{Xe=JSON.parse(Ce)}catch{console.debug("[use-chat] malformed SSE:",Ce.slice(0,200));continue}const ge=Kg(Xe)?Xe.data:Xe;et=Date.now();const ut=ge.seq;if(ut!==void 0){if(ut<=bt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:ut,lastProcessedSeq:bt,type:ge.type});continue}bt>0&&ut>bt+1&&(($=R==null?void 0:R.onGap)==null||$.call(R,{from:bt,to:ut})),bt=ut,C.current=ut,y(ut)}if(console.debug("[use-chat] received event",{seq:ge.seq,type:ge.type,preview:(()=>{var we;try{return ge.type==="message_delta"?{deltaTypes:(we=ge.delta)==null?void 0:we.map(nt=>nt.type),textLen:(ge.delta||[]).filter(nt=>nt.type==="text").map(nt=>String(nt.text||"").length)}:ge.content||ge.delta?{hasContent:!0}:{}}catch(nt){return{err:String(nt)}}})()}),ge.type==="checkpoint")I.current=ge.checkpointId??null,A.current=ge.checkpointNs??null,x(ge.checkpointId??null);else if(ge.type==="state_history"){_.current=ge;try{const nt=ar(ge).latest;nt&&(I.current=nt.checkpointId??null,A.current=nt.checkpointNs??null,x(nt.checkpointId??null))}catch(we){console.warn("[use-chat] Failed to hydrate state_history payload",we)}}try{B==null||B(ge)}catch(we){console.error("[use-chat] Error in onEvent callback:",we,"for event:",ge.type)}if(ge.type==="token"&&e.autoAppendAssistant!==!1)ht.push(ge.content),Mt();else if(ge.type==="message_delta"){const we=ge.delta.filter(nt=>nt.type==="text").map(nt=>nt.text).join("");we&&e.autoAppendAssistant!==!1&&(ht.push(we),Mt())}else if(ge.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(W=R==null?void 0:R.onHeartbeat)==null||W.call(R,ge)}catch(we){console.warn("[use-chat] heartbeat callback failed",we)}}else if(St!==null&&cancelAnimationFrame(St),Lt(),ge.type==="checkpoint")x(ge.checkpointId);else if(ge.type==="error"){const we=ge;if(d(we.message),z="error",j=we.message,we.error_type==="auth_error"||we.code==="TOKEN_EXPIRED"||((Q=we.message)==null?void 0:Q.includes("token"))||((le=we.message)==null?void 0:le.includes("401"))||((re=we.message)==null?void 0:re.includes("unauthorized"))||((Ae=we.message)==null?void 0:Ae.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",we.message);try{(Ue=R==null?void 0:R.onAuthError)==null||Ue.call(R,we.message)}catch(ao){console.warn("[use-chat] onAuthError handler failed",ao)}Z.abort()}}}}Lt(),z===null&&!Z.signal.aborted&&(z="complete")}catch(Ye){if(Ye.name==="AbortError")z=z??"aborted";else{const tt=Ye.message||String(Ye);z="error",j=tt,d(tt),(De=R==null?void 0:R.onError)==null||De.call(R,tt)}}finally{try{await at.cancel()}catch{}finally{(Ke=at.releaseLock)==null||Ke.call(at)}St!==null&&typeof window<"u"&&window.cancelAnimationFrame(St),clearInterval(It)}}catch(Pe){if(Pe.name==="AbortError")z=z??"aborted";else{const We=Pe.message||String(Pe);z="error",j=We,d(We),(He=R==null?void 0:R.onError)==null||He.call(R,We),Y||((fe=R==null?void 0:R.onConnectionError)==null||fe.call(R,We),Y=!0)}}finally{const Pe=C.current,We=I.current,it=A.current,Ge=_.current,Qe=z??(Z.signal.aborted?"aborted":j?"error":"complete");try{(be=R==null?void 0:R.onClosed)==null||be.call(R,{reason:Qe,lastSeq:Pe,lastCheckpointId:We,lastCheckpointNs:it,lastStateHistory:Ge,error:j})}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:()=>Z.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:P,clear:M,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:di(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=di(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=di(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return 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=ko(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=pi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?ko(e.messages,C,k):e.messages,I=Io(k,d),A=hi(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:pi(void 0,d.length?d:[m],c,t.args)},b=Io(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:hi(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=Io(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=pi(d??void 0,x.length?x:a,f),k={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[g],createdAt:b,artifact:y??void 0,additionalKwargs:S},C=c>=0?ko(e.messages,c,k):[...e.messages,k],T=Io(k,a.length?a:x);return{...e,messages:C,toolIndex:hi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=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=ar(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 di(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function ko(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 fi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function pi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=fi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Io(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=fi(e);for(const o of r)n.add(o);return Array.from(n)}function hi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function 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(fi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function 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 ko(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(M=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(M)}catch{}try{return JSON.parse(JSON.stringify(M))}catch{return M}},[]),y=w.useCallback((M,P)=>{if(!M)return;const F=p.current.get(M)??[],N=m(P),B=F.length>=ic?[...F.slice(F.length-ic+1),N]:[...F,N];p.current.set(M,B)},[m]),g=w.useCallback(M=>{M&&p.current.set(M,[])},[]),b=w.useCallback(M=>{const P=M??f.current;if(!P)return;const F=p.current.get(P);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(M=>{var N,B,R,Z,z;const P=M.seq??null;if(P!==null){const j=d.current;if(j!==null){if(P<=j)return;P>j+1&&(s==null||s({from:j,to:P}))}d.current=P}if(M.type==="thread_info"){f.current=M.threadId,h.current&&(h.current.threadIdGuess=M.threadId),x.current=M,g(M.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",M);try{t(M)}catch(j){console.error("[useChatStreamingService] Error in onThreadInfo handler:",j)}return}if(M.type==="heartbeat"){try{c==null||c(M)}catch(j){console.error("[useChatStreamingService] Error in onHeartbeat handler:",j)}return}if(M.type==="error"){const j=M;if(j.error_type==="auth_error"||j.code==="TOKEN_EXPIRED"||((N=j.message)==null?void 0:N.includes("token"))||((B=j.message)==null?void 0:B.includes("401"))||((R=j.message)==null?void 0:R.includes("unauthorized"))||((Z=j.message)==null?void 0:Z.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",j.message);try{l==null||l(j.message)}catch(J){console.warn("[useChatStreamingService] onAuthError handler failed",J)}}}const F=M.threadId??(M.type==="state_history"?M.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.threadIdGuess)??null;if(M.type==="state_history"){f.current=F??f.current;try{r==null||r(M)}catch(j){console.error("[useChatStreamingService] onStateHistory handler failed",j)}}if(Gg(M)){M.type==="checkpoint"||M.type==="state_history"?g(F??null):y(F??null,M);try{n(M)}catch(j){console.error("[useChatStreamingService] Error in onMessageEvent handler:",j)}return}try{o==null||o(M)}catch(j){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",j)}},[y,g,n,s,t,r,o]),{stream:k,stop:C,isStreaming:T,error:I,setToken:A}=Jl({baseUrl:e,token:void 0}),_=w.useCallback((M,P)=>{d.current=null,x.current=null,f.current=M.threadId??null,h.current={request:M,callbacks:P,manualStop:!1,threadIdGuess:M.threadId??null},k(M,S,{onOpen:P==null?void 0:P.onOpen,onError:F=>{var N;(N=P==null?void 0:P.onError)==null||N.call(P,F)},onGap:(P==null?void 0:P.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=P==null?void 0:P.onConnectionError)==null||N.call(P,F)},onAuthError:F=>{var N;l==null||l(F),(N=P==null?void 0:P.onAuthError)==null||N.call(P,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=P==null?void 0:P.onHeartbeat)==null||N.call(P,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var Z,z,j,Y;const N=((Z=h.current)==null?void 0:Z.manualStop)??!1,B=f.current??((z=h.current)==null?void 0:z.threadIdGuess)??((j=F.lastStateHistory)==null?void 0:j.threadId)??null;(F.reason==="complete"||F.reason==="aborted"&&N)&&g(B);const R={...F,threadId:B,threadInfo:x.current,manualStop:N};try{i==null||i(R)}catch(J){console.warn("[useChatStreamingService] onStreamClosed handler failed",J)}try{(Y=P==null?void 0:P.onClosed)==null||Y.call(P,R)}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:_,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[_,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}=ci(),d=w.useMemo(()=>bn(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:_,pushUser:L,onEvent:M}=Zl(),[P,F]=w.useState(!1),[N,B]=w.useState(!1),[R,Z]=w.useState(null),[z,j]=w.useState([]),[Y,J]=w.useState([]),[oe,ye]=w.useState(!1),Re=w.useMemo(()=>z.flatMap(V=>V.messages??[]),[z]),K=w.useMemo(()=>Xl(Re),[Re]),U=w.useRef(h),G=w.useRef(null),$=w.useRef(null),W=w.useRef(null),Q=w.useRef(null),le=w.useRef(!1),re=w.useRef(null),Ae=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 V=await l.listThreads();p(V??[])}catch(V){const ie=String(V);b(ie),s==null||s(ie)}finally{y(!1)}},[l,s]),Ke=w.useCallback(V=>{if(!(V!=null&&V.threadId))return;const ie={threadId:V.threadId,title:V.title||`Thread ${V.threadId.slice(0,8)}`,createdAt:V.createdAt||new Date().toISOString(),updatedAt:V.updatedAt||new Date().toISOString(),messageCount:V.messageCount??1};p(D=>D.some(ne=>ne.threadId===ie.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",ie.threadId),D):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",ie.threadId),[ie,...D]))},[]),He=w.useCallback(V=>{const ie=V.threadId??U.current;if(!ie||U.current&&U.current!==ie)return;const{checkpoints:D,timeline:X}=ar(V);if(!D.length)return;const ne=D.find(Ce=>Ce.messages&&Ce.messages.length>0)??D.find(Ce=>!!Ce.checkpointId)??D[0];A((ne==null?void 0:ne.messages)??[],{checkpointId:(ne==null?void 0:ne.checkpointId)??null,checkpointNs:(ne==null?void 0:ne.checkpointNs)??null}),J(X),j(D),F(!!(ne!=null&&ne.nextCursor)),Z((ne==null?void 0:ne.nextCursor)??null),re.current=`${ie}:latest`,$.current=null,W.current=null},[A]),fe=w.useCallback(V=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",V.threadId),Ke(V),U.current!==V.threadId&&((V.created??!U.current)&&($.current=V.threadId),W.current=V.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(V.threadId))},[Ke]),{startStream:be,stop:Pe,isStreaming:We,error:it,setAuthToken:Ge}=tx({baseUrl:d,onThreadInfo:fe,onMessageEvent:M,onStateHistory:He,onUnhandledEvent:V=>{console.warn("[ChatSessionProvider] Unhandled event:",V.type)},onAuthError:i}),Qe=w.useCallback(async V=>{try{const ie=await l.createThread(V);return x(ie.threadId),await De(),ie.threadId}catch(ie){return s==null||s(String(ie)),null}},[l,De,s]),at=w.useCallback(async V=>{const ie=f;p(X=>X.filter(ne=>ne.threadId!==V));const D=new AbortController;Ue.current.set(V,D);try{await l.deleteThread(V),U.current===V&&(x(null),A([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",V)}catch(X){console.error("[ChatSessionProvider] Delete failed, restoring thread:",V,X),p(ie),s==null||s(`Failed to delete thread: ${String(X)}`)}finally{Ue.current.delete(V)}},[f,l,A,s]),Rt=w.useCallback(async(V,ie)=>{try{await l.updateThread(V,ie),await De()}catch(D){s==null||s(String(D))}},[l,De,s]),gt=w.useCallback(async(V,ie)=>{if(!V)return;const D=`${V}:${ie??"latest"}`,X=Ae.current.get(D);if(X)return X;const ne=(async()=>{const Ce=V;k(!0),T(null);try{const Xe=await l.getStateHistory({threadId:Ce,checkpointId:ie||void 0});if(U.current!==Ce){console.log(`[ChatSessionProvider] Thread changed during load (was ${Ce}, now ${U.current}), discarding stale data`);return}const{checkpoints:ge,timeline:ut}=ar(Xe),we=ge.find(nt=>nt.messages&&nt.messages.length>0)??(ie?ge.find(nt=>nt.checkpointId===ie):null)??ge[0];A((we==null?void 0:we.messages)??[],{checkpointId:(we==null?void 0:we.checkpointId)??null,checkpointNs:(we==null?void 0:we.checkpointNs)??null}),J(ut),j(ge),F(!!(we!=null&&we.nextCursor)),Z((we==null?void 0:we.nextCursor)??null)}catch(Xe){if(U.current===Ce){const ge=String(Xe);T(ge),s==null||s(ge)}}finally{k(!1)}})();Ae.current.set(D,ne);try{await ne}finally{Ae.current.delete(D)}return U.current===V&&(re.current=D),ne},[l,A,s]),ht=w.useCallback(async(V,ie)=>{Q.current=V;try{await gt(V,ie)}finally{Q.current===V&&(Q.current=null)}},[gt]);w.useEffect(()=>{if(!o||!h||S||We)return;if($.current===h){$.current=null,G.current=h;return}if(W.current===h){G.current=h;return}if(Q.current===h){Q.current=null,G.current=h;return}if(G.current===h)return;G.current=h;const V=!le.current&&!!n&&h===t;let ie;V&&n?(ie=n,le.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",ie,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const D=`${h}:${ie??"latest"}`;re.current!==D&&ht(h,ie)},[o,h,n,r,t,S,We,ht]);const bt=w.useCallback(async(V,ie)=>{const D=U.current;if(!D)return;const X=D;ye(!0);try{const ne=await l.getStateHistory({threadId:X,checkpointId:V,checkpointNs:ie??void 0});if(U.current!==X){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${X}, now ${U.current}), discarding stale data`);return}const{checkpoints:Ce,timeline:Xe}=ar(ne),ge=Ce.find(ut=>ut.checkpointId===V&&(ie?ut.checkpointNs===ie:!0));if(!ge){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:V,checkpointNs:ie});return}J(Xe),j(Ce),A(ge.messages??[],{checkpointId:ge.checkpointId??null,checkpointNs:ge.checkpointNs??null})}catch(ne){U.current===X&&(s==null||s(String(ne)))}finally{ye(!1)}},[l,A,s]),St=w.useCallback((V,ie)=>{A(I.messages,{checkpointId:V??null,checkpointNs:ie??null})},[A,I.messages]),Lt=w.useCallback(async()=>{U.current&&await ht(U.current)},[ht]),Mt=w.useCallback(async()=>{if(!U.current||!R)return;const V=U.current;B(!0);try{const ie=await l.getStateHistory({threadId:V,checkpointId:R});if(U.current!==V)return;const{checkpoints:D}=ar(ie);if(D.length>0){const X=D[D.length-1];_((X==null?void 0:X.messages)??[]),F(!!(X!=null&&X.nextCursor)),Z((X==null?void 0:X.nextCursor)??null)}}catch(ie){U.current===V&&(s==null||s(String(ie)))}finally{B(!1)}},[l,R,_,s]),et=w.useCallback(async()=>{A([],{}),x(null),Pe(),j([]),J([]),F(!1),Z(null),k(!1),ye(!1),B(!1),T(null);try{await l.getAgent("default")}catch(V){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",V)}},[A,Pe,l]),It=w.useCallback(async(V,ie,D)=>{const X=U.current;if(!X)throw new Error("No active thread to handle interrupt");const ne=ie?D??!0:!1;try{const Ce={threadId:X,checkpointId:I.lastCheckpointId??void 0,checkpointNs:I.lastCheckpointNs??void 0,command:{kind:"resume",value:ne}};be(Ce)}catch(Ce){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${V}:`,Ce),Ce}},[I.lastCheckpointId,I.lastCheckpointNs,be]);w.useEffect(()=>{De()},[De]),w.useEffect(()=>{a==null||a(h)},[h,a]);const vn=w.useCallback(async(V,ie)=>{let D=U.current;const X=(V==null?void 0:V.text)??"";if(!D&&!X)return;if(!D&&X){const ut=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),we=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);D=`${ut}${we}`,$.current=D,x(D)}const{contentParts:ne}=await wg(l,(V==null?void 0:V.attachments)??[]),Ce=[...ne];X!=null&&X.trim()&&Ce.push({type:"text",text:X});const Xe={id:`msg-${Date.now()}`,role:"user",content:Ce,createdAt:new Date().toISOString()};L(Xe);const ge={threadId:D,payload:{messages:[Xe]},checkpointId:(ie==null?void 0:ie.checkpointId)??I.lastCheckpointId??void 0,checkpointNs:(ie==null?void 0:ie.checkpointNs)??I.lastCheckpointNs??void 0};be(ge)},[l,Qe,L,I,be]),Ye=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:Qe,deleteThread:at,renameThread:Rt,refreshThreads:De}}),[f,h,m,g,Qe,at,Rt,De]),tt=w.useMemo(()=>({threadId:h,messages:I.messages,interrupt:null,checkpoint:{id:I.lastCheckpointId??null,namespace:I.lastCheckpointNs??null},checkpoints:z,timelineCheckpoints:Y,metadata:null,isLoading:S,isHistoryLoading:N,isLoadingCheckpoint:oe,error:C,hasMore:P,loadOlder:Mt,clearState:et,navigateToCheckpoint:bt,setCurrentCheckpointId:St,returnToLatest:Lt,loadThread:ht,clearThread:et,respondToInterrupt:It,messagePreviews:K}),[h,I,z,Y,S,N,oe,C,P,Mt,et,bt,St,Lt,ht,It,K]),pt=w.useMemo(()=>({isStreaming:We,error:it,connectionState:We?"connected":"idle",submit:vn,send:vn,stop:Pe,setAuthToken:Ge}),[We,it,vn,Pe,Ge]);return u.jsx(ac.Provider,{value:Ye,children:u.jsx(lc.Provider,{value:tt,children:u.jsx(cc.Provider,{value:pt,children:e})})})}function Eo(){const e=w.useContext(ac);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Ao(){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 No({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 te(...e){return Kh.twMerge(Vh.clsx(e))}const rx=co.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Je=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?zn.Slot:"button";return u.jsx(i,{className:te(rx({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const dc=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}));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:R})=>{x||y(B),R&&(a==null||a(B))},[x,a]),_=w.useCallback(async B=>{B&&B.preventDefault();const R=(g??"").trim();if(!R&&!h)return;const Z=++C.current;T.current={id:Z,shouldClear:!0},S(()=>{var z,j,Y;try{const J=l(R);J&&typeof J.then=="function"?J.then(()=>{var oe,ye;((oe=T.current)==null?void 0:oe.id)===Z&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ye=T.current)==null?void 0:ye.id)===Z&&(T.current=null)}).catch(()=>{var oe;((oe=T.current)==null?void 0:oe.id)===Z&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===Z&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((j=T.current)==null?void 0:j.id)===Z&&(T.current=null))}catch{((Y=T.current)==null?void 0:Y.id)===Z&&(T.current=null)}})},[g,l,h,x,a]),L=w.useCallback(B=>{const R=B.target.value;A(R,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),M=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),_()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[_,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 _(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:M,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(Je,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(se.Square,{size:16})}):u.jsx(Je,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!g.trim()&&!h||b,children:u.jsx(se.Send,{size:16})})})]})})}const ox=w.memo(fc);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 pc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function mi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=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 Be(...e){return v.useCallback(mi(...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 wn(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 cr({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"],_e=ux.reduce((e,t)=>{const n=zn.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&&uo.flushSync(()=>e.dispatchEvent(t))}function gi(e){const t=e+"CollectionProvider",[n,r]=wn(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=zn.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=zn.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 dx=v.createContext(void 0);function _o(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",xi="dismissableLayer.update",hx="dismissableLayer.pointerDownOutside",mx="dismissableLayer.focusOutside",mc,gc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),jo=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=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=yx(I=>{const A=I.target,_=[...c.branches].some(L=>L.contains(A));!k||_||(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(xi,I),()=>document.removeEventListener(xi,I)},[]),u.jsx(_e.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)})});jo.displayName=px;var gx="DismissableLayerBranch",xx=v.forwardRef((e,t)=>{const n=v.useContext(gc),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(_e.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(xi);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 yi=0;function vi(){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()),yi++,()=>{yi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),yi--}},[])}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 bi="focusScope.autoFocusOnMount",wi="focusScope.autoFocusOnUnmount",bc={bubbles:!1,cancelable:!0},bx="FocusScope",Ro=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:En(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||En(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&En(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(bi,bc);a.addEventListener(bi,c),a.dispatchEvent(g),g.defaultPrevented||(wx(Ix(wc(a)),{select:!0}),document.activeElement===m&&En(a))}return()=>{a.removeEventListener(bi,c),setTimeout(()=>{const g=new CustomEvent(wi,bc);a.addEventListener(wi,d),a.dispatchEvent(g),g.defaultPrevented||En(m??document.body,{select:!0}),a.removeEventListener(wi,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&&En(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&En(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(_e.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Ro.displayName=bx;function wx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(En(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 En(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 Sn(e){const[t,n]=v.useState(Ex());return Tt(()=>{n(r=>r??String(Ax++))},[e]),t?`radix-${t}`:""}const Nx=["top","right","bottom","left"],An=Math.min,zt=Math.max,Mo=Math.round,Po=Math.floor,un=e=>({x:e,y:e}),_x={left:"right",right:"left",bottom:"top",top:"bottom"},jx={start:"end",end:"start"};function Si(e,t,n){return zt(e,An(t,n))}function Cn(e,t){return typeof e=="function"?e(t):e}function Tn(e){return e.split("-")[0]}function ur(e){return e.split("-")[1]}function Ci(e){return e==="x"?"y":"x"}function Ti(e){return e==="y"?"height":"width"}const Rx=new Set(["top","bottom"]);function dn(e){return Rx.has(Tn(e))?"y":"x"}function ki(e){return Ci(dn(e))}function Mx(e,t,n){n===void 0&&(n=!1);const r=ur(e),o=ki(e),s=Ti(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Oo(i)),[i,Oo(i)]}function Px(e){const t=Oo(e);return[Ii(e),t,Ii(t)]}function Ii(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=ur(e);let s=Lx(Tn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ii)))),s}function Oo(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 Do(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=dn(t),i=ki(t),a=Ti(i),l=Tn(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(ur(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 Mr(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=Cn(t,e),x=Ec(h),y=a[p?f==="floating"?"reference":"floating":f],g=Do(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=Do(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}=Cn(e,t)||{};if(c==null)return{};const f=Ec(d),p={x:n,y:r},h=ki(o),x=Ti(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,_=I/2-m[x]/2-1,L=An(f[g],_),M=An(f[b],_),P=L,F=I-m[x]-M,N=I/2-m[x]/2+A,B=Si(P,N,F),R=!l.arrow&&ur(o)!=null&&N!==B&&s.reference[x]/2-(N<P?L:M)-m[x]/2<0,Z=R?N<P?N-P:N-F:0;return{[h]:p[h]+Z,data:{[h]:B,centerOffset:N-B-Z,...R&&{alignmentOffset:Z}},reset:R}}}),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}=Cn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=Tn(o),b=dn(a),S=Tn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[Oo(a)]:Px(a)),T=x!=="none";!p&&T&&C.push(...$x(a,m,x,k));const I=[a,...C],A=await Mr(t,y),_=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(A[g]),f){const N=Mx(o,i,k);_.push(A[N[0]],A[N[1]])}if(L=[...L,{placement:o,overflows:_}],!_.every(N=>N<=0)){var M,P;const N=(((M=s.flip)==null?void 0:M.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==dn(B):!1)||L.every(z=>dn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:L},reset:{placement:B}};let R=(P=L.filter(Z=>Z.overflows[0]<=0).sort((Z,z)=>Z.overflows[1]-z.overflows[1])[0])==null?void 0:P.placement;if(!R)switch(h){case"bestFit":{var F;const Z=(F=L.filter(z=>{if(T){const j=dn(z.placement);return j===b||j==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(j=>j>0).reduce((j,Y)=>j+Y,0)]).sort((z,j)=>z[1]-j[1])[0])==null?void 0:F[0];Z&&(R=Z);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}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}=Cn(e,t);switch(r){case"referenceHidden":{const s=await Mr(t,{...o,elementContext:"reference"}),i=Nc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:_c(i)}}}case"escaped":{const s=await Mr(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=Tn(n),a=ur(n),l=dn(n)==="y",c=jc.has(i)?-1:1,d=s&&l?-1:1,f=Cn(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}=Cn(e,t),c={x:n,y:r},d=await Mr(t,l),f=dn(Tn(o)),p=Ci(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=Si(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=Si(b,x,S)}const m=a.fn({...t,[p]:h,[f]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},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}=Cn(e,t),d={x:n,y:r},f=dn(o),p=Ci(f);let h=d[p],x=d[f];const m=Cn(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(Tn(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}=Cn(e,t),d=await Mr(t,c),f=Tn(o),p=ur(o),h=dn(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=An(m-d[y],b),C=An(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=zt(d.left,0),M=zt(d.right,0),P=zt(d.top,0),F=zt(d.bottom,0);h?A=x-2*(L!==0||M!==0?L+M:zt(d.left,d.right)):I=m-2*(P!==0||F!==0?P+F:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const _=await i.getDimensions(a.floating);return x!==_.width||m!==_.height?{reset:{rects:!0}}:{}}}};function Lo(){return typeof window<"u"}function dr(e){return Rc(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function fn(e){var t;return(t=(Rc(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Rc(e){return Lo()?e instanceof Node||e instanceof Ut(e).Node:!1}function tn(e){return Lo()?e instanceof Element||e instanceof Ut(e).Element:!1}function pn(e){return Lo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function Mc(e){return!Lo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const Yx=new Set(["inline","contents"]);function Pr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=nn(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(dr(e))}const Zx=[":popover-open",":modal"];function $o(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 Ei(e){const t=Ai(),n=tn(e)?nn(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=Nn(e);for(;pn(t)&&!fr(t);){if(Ei(t))return t;if($o(t))return null;t=Nn(t)}return null}function Ai(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ry=new Set(["html","body","#document"]);function fr(e){return ry.has(dr(e))}function nn(e){return Ut(e).getComputedStyle(e)}function Fo(e){return tn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Nn(e){if(dr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Mc(e)&&e.host||fn(e);return Mc(t)?t.host:t}function Pc(e){const t=Nn(e);return fr(t)?e.ownerDocument?e.ownerDocument.body:e.body:pn(t)&&Pr(t)?t:Pc(t)}function Or(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=Ut(o);if(s){const a=Ni(i);return t.concat(i,i.visualViewport||[],Pr(o)?o:[],a&&n?Or(a):[])}return t.concat(o,Or(o,[],n))}function Ni(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Oc(e){const t=nn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=pn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Mo(n)!==s||Mo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function _i(e){return tn(e)?e:e.contextElement}function pr(e){const t=_i(e);if(!pn(t))return un(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Oc(t);let i=(s?Mo(n.width):n.width)/r,a=(s?Mo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const oy=un(0);function Dc(e){const t=Ut(e);return!Ai()||!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!==Ut(e)?!1:t}function Vn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=_i(e);let i=un(1);t&&(r?tn(r)&&(i=pr(r)):i=pr(e));const a=sy(s,n,r)?Dc(s):un(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&&tn(r)?Ut(r):r;let x=p,m=Ni(x);for(;m&&r&&h!==x;){const y=pr(m),g=m.getBoundingClientRect(),b=nn(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=Ni(x)}}return Do({width:d,height:f,x:l,y:c})}function Bo(e,t){const n=Fo(e).scrollLeft;return t?t.left+n:Vn(fn(e)).left+n}function Lc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Bo(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=fn(r),a=t?$o(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=un(1);const d=un(0),f=pn(r);if((f||!f&&!s)&&((dr(r)!=="body"||Pr(i))&&(l=Fo(r)),pn(r))){const h=Vn(r);c=pr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Lc(i,l):un(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=fn(e),n=Fo(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+Bo(e);const a=-n.scrollTop;return nn(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const $c=25;function cy(e,t){const n=Ut(e),r=fn(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=Ai();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Bo(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=Vn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=pn(e)?pr(e):un(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(fn(e));else if(tn(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 Do(r)}function Bc(e,t){const n=Nn(e);return n===t||!tn(n)||fr(n)?!1:nn(n).position==="fixed"||Bc(n,t)}function fy(e,t){const n=t.get(e);if(n)return n;let r=Or(e,[],!1).filter(a=>tn(a)&&dr(a)!=="body"),o=null;const s=nn(e).position==="fixed";let i=s?Nn(e):e;for(;tn(i)&&!fr(i);){const a=nn(i),l=Ei(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&uy.has(o.position)||Pr(i)&&!l&&Bc(e,i))?r=r.filter(d=>d!==i):o=a,i=Nn(i)}return t.set(e,r),r}function py(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?$o(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=zt(f.top,c.top),c.right=An(f.right,c.right),c.bottom=An(f.bottom,c.bottom),c.left=zt(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=pn(t),o=fn(t),s=n==="fixed",i=Vn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=un(0);function c(){l.x=Bo(o)}if(r||!r&&!s)if((dr(t)!=="body"||Pr(o))&&(a=Fo(t)),r){const h=Vn(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):un(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function ji(e){return nn(e).position==="static"}function zc(e,t){if(!pn(e)||nn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return fn(e)===n&&(n=n.ownerDocument.body),n}function Uc(e,t){const n=Ut(e);if($o(e))return n;if(!pn(e)){let o=Nn(e);for(;o&&!fr(o);){if(tn(o)&&!ji(o))return o;o=Nn(o)}return n}let r=zc(e,t);for(;r&&Jx(r)&&ji(r);)r=zc(r,t);return r&&fr(r)&&ji(r)&&!Ei(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 nn(e).direction==="rtl"}const yy={convertOffsetParentRelativeRectToViewportRelativeRect:iy,getDocumentElement:fn,getClippingRect:py,getOffsetParent:Uc,getElementRects:gy,getClientRects:ay,getDimensions:hy,getScale:pr,isElement:tn,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=fn(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=Po(f),m=Po(o.clientWidth-(d+p)),y=Po(o.clientHeight-(f+h)),g=Po(d),S={rootMargin:-x+"px "+-m+"px "+-y+"px "+-g+"px",threshold:zt(0,An(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=_i(e),d=o||s?[...c?Or(c):[],...Or(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?Vn(e):null;l&&y();function y(){const g=Vn(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(){},zo=Ay?w.useLayoutEffect:Ny;function Uo(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(!Uo(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)&&!Uo(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 Ri(e){const t=v.useRef(e);return zo(()=>{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);Uo(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),_=l!=null,L=Ri(l),M=Ri(o),P=Ri(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};M.current&&(z.platform=M.current),Ey(T.current,I.current,z).then(j=>{const Y={...j,isPositioned:P.current!==!1};N.current&&!Uo(A.current,Y)&&(A.current=Y,uo.flushSync(()=>{f(Y)}))})},[p,t,n,M,P]);zo(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);zo(()=>(N.current=!0,()=>{N.current=!1}),[]),zo(()=>{if(k&&(T.current=k),C&&(I.current=C),k&&C){if(L.current)return L.current(k,C,F);F()}},[k,C,F,L,_]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),R=v.useMemo(()=>({reference:k,floating:C}),[k,C]),Z=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!R.floating)return z;const j=Kc(R.floating,d.x),Y=Kc(R.floating,d.y);return a?{...z,transform:"translate("+j+"px, "+Y+"px)",...Vc(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:j,top:Y}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:R,floatingStyles:Z}),[d,F,B,R,Z])}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(_e.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});qc.displayName=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 Mi="Popper",[Yc,Ho]=wn(Mi),[zy,Xc]=Yc(Mi),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=Mi;var Zc="PopperAnchor",Qc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Xc(Zc,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(_e.div,{...o,ref:a})});Qc.displayName=Zc;var Pi="PopperContent",[Uy,Hy]=Yc(Pi),eu=v.forwardRef((e,t)=>{var G,$,W,Q,le,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=Xc(Pi,n),[g,b]=v.useState(null),S=Be(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,_=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},M=Array.isArray(c)?c:[c],P=M.length>0,F={padding:L,boundary:M.filter(Vy),altBoundary:P},{refs:N,floatingStyles:B,placement:R,isPositioned:Z,middlewareData:z}=_y({strategy:"fixed",placement:_,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:Ue,availableWidth:De,availableHeight:Ke})=>{const{width:He,height:fe}=Ue.reference,be=Ae.floating.style;be.setProperty("--radix-popper-available-width",`${De}px`),be.setProperty("--radix-popper-available-height",`${Ke}px`),be.setProperty("--radix-popper-anchor-width",`${He}px`),be.setProperty("--radix-popper-anchor-height",`${fe}px`)}}),k&&$y({element:k,padding:a}),Ky({arrowWidth:I,arrowHeight:A}),p&&Ly({strategy:"referenceHidden",...F})]}),[j,Y]=ru(R),J=kt(x);Tt(()=>{Z&&(J==null||J())},[Z,J]);const oe=(G=z.arrow)==null?void 0:G.x,ye=($=z.arrow)==null?void 0:$.y,Re=((W=z.arrow)==null?void 0:W.centerOffset)!==0,[K,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:Z?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:K,"--radix-popper-transform-origin":[(Q=z.transformOrigin)==null?void 0:Q.x,(le=z.transformOrigin)==null?void 0:le.y].join(" "),...((re=z.hide)==null?void 0:re.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Uy,{scope:n,placedSide:j,onArrowChange:C,arrowX:oe,arrowY:ye,shouldHideArrow:Re,children:u.jsx(_e.div,{"data-side":j,"data-align":Y,...m,ref:S,style:{...m.style,animation:Z?void 0:"none"}})})})});eu.displayName=Pi;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",Wo=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?qs.createPortal(u.jsx(_e.div,{...r,ref:t}),i):null});Wo.displayName=qy;function Gy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Gt=e=>{const{present:t,children:n}=e,r=Yy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Be(r.ref,Xy(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Gt.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=Vo(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=Vo(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=Vo(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=Vo(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 Vo(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 Oi="rovingFocusGroup.onEntryFocus",Jy={bubbles:!1,cancelable:!0},Dr="RovingFocusGroup",[Di,lu,Zy]=gi(Dr),[Qy,cu]=wn(Dr,[Zy]),[ev,tv]=Qy(Dr),uu=v.forwardRef((e,t)=>u.jsx(Di.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Di.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(nv,{...e,ref:t})})}));uu.displayName=Dr;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=Be(t,p),x=_o(s),[m,y]=cr({prop:i,defaultProp:a??null,onChange:l,caller:Dr}),[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(Oi,S),()=>A.removeEventListener(Oi,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(_e.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 _=!C.current;if(A.target===A.currentTarget&&_&&!g){const L=new CustomEvent(Oi,Jy);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const M=k().filter(R=>R.focusable),P=M.find(R=>R.active),F=M.find(R=>R.id===m),B=[P,F,...M].filter(Boolean).map(R=>R.ref.current);pu(B,d)}}C.current=!1}),onBlur:de(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=Sn(),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(Di.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(_e.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown: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=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},hr=new WeakMap,Ko=new WeakMap,qo={},Li=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]);qo[n]||(qo[n]=new WeakMap);var s=qo[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=(hr.get(p)||0)+1,y=(s.get(p)||0)+1;hr.set(p,m),s.set(p,y),i.push(p),m===1&&x&&Ko.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(),Li++,function(){i.forEach(function(f){var p=hr.get(f)-1,h=s.get(f)-1;hr.set(f,p),s.set(f,h),p||(Ko.has(f)||f.removeAttribute(r),Ko.delete(f)),h||f.removeAttribute(n)}),Li--,Li||(hr=new WeakMap,hr=new WeakMap,Ko=new WeakMap,qo={})}},$i=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}},hn=function(){return hn=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},hn.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 Go="right-scroll-bar-position",Yo="width-before-scroll-bar",pv="with-scroll-bars-hidden",hv="--removed-body-scroll-bar-size";function Fi(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 Fi(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)||Fi(a,null)}),s.forEach(function(a){o.has(a)||Fi(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=hn({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,hn({},n))};xu.isSideCarExport=!0;function wv(e,t){return e.useMedium(t),xu}var yu=bv(),Bi=function(){},Xo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Bi,onWheelCapture:Bi,onTouchMoveCapture:Bi}),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=hn(hn({},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),hn(hn({},I),{ref:T})):v.createElement(b,hn({},I,{className:l,ref:T}),a))});Xo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Xo.classNames={fullWidth:Yo,zeroRight:Go};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},zi=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[zi(n),zi(r),zi(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(),mr="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,` {
37
+ `))>=0;){const ne=gt.slice(0,Q);gt=gt.slice(Q+2);const Se=Hg(ne);if(!Se)continue;let Ve;try{Ve=JSON.parse(Se)}catch{console.debug("[use-chat] malformed SSE:",Se.slice(0,200));continue}const ge=Ug(Ve)?Ve.data:Ve;et=Date.now();const lt=ge.seq;if(lt!==void 0){if(lt<=bt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:lt,lastProcessedSeq:bt,type:ge.type});continue}bt>0&&lt>bt+1&&(($=R==null?void 0:R.onGap)==null||$.call(R,{from:bt,to:lt})),bt=lt,C.current=lt,y(lt)}if(console.debug("[use-chat] received event",{seq:ge.seq,type:ge.type,preview:(()=>{var be;try{return ge.type==="message_delta"?{deltaTypes:(be=ge.delta)==null?void 0:be.map(Ke=>Ke.type),textLen:(ge.delta||[]).filter(Ke=>Ke.type==="text").map(Ke=>String(Ke.text||"").length)}:ge.content||ge.delta?{hasContent:!0}:{}}catch(Ke){return{err:String(Ke)}}})()}),ge.type==="checkpoint")I.current=ge.checkpointId??null,A.current=ge.checkpointNs??null,x(ge.checkpointId??null);else if(ge.type==="state_history"){j.current=ge;try{const Ke=ur(ge).latest;Ke&&(I.current=Ke.checkpointId??null,A.current=Ke.checkpointNs??null,x(Ke.checkpointId??null))}catch(be){console.warn("[use-chat] Failed to hydrate state_history payload",be)}}try{B==null||B(ge)}catch(be){console.error("[use-chat] Error in onEvent callback:",be,"for event:",ge.type)}if(ge.type==="token"&&e.autoAppendAssistant!==!1)ht.push(ge.content),Mt();else if(ge.type==="message_delta"){const be=ge.delta.filter(Ke=>Ke.type==="text").map(Ke=>Ke.text).join("");be&&e.autoAppendAssistant!==!1&&(ht.push(be),Mt())}else if(ge.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(q=R==null?void 0:R.onHeartbeat)==null||q.call(R,ge)}catch(be){console.warn("[use-chat] heartbeat callback failed",be)}}else if(St!==null&&cancelAnimationFrame(St),Lt(),ge.type==="checkpoint")x(ge.checkpointId);else if(ge.type==="error"){const be=ge;if(d(be.message),z="error",_=be.message,be.error_type==="auth_error"||be.code==="TOKEN_EXPIRED"||((Z=be.message)==null?void 0:Z.includes("token"))||((le=be.message)==null?void 0:le.includes("401"))||((oe=be.message)==null?void 0:oe.includes("unauthorized"))||((_e=be.message)==null?void 0:_e.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",be.message);try{(Ue=R==null?void 0:R.onAuthError)==null||Ue.call(R,be.message)}catch(In){console.warn("[use-chat] onAuthError handler failed",In)}J.abort()}}}}Lt(),z===null&&!J.signal.aborted&&(z="complete")}catch(Je){if(Je.name==="AbortError")z=z??"aborted";else{const tt=Je.message||String(Je);z="error",_=tt,d(tt),(De=R==null?void 0:R.onError)==null||De.call(R,tt)}}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(Pe){if(Pe.name==="AbortError")z=z??"aborted";else{const We=Pe.message||String(Pe);z="error",_=We,d(We),(He=R==null?void 0:R.onError)==null||He.call(R,We),Y||((fe=R==null?void 0:R.onConnectionError)==null||fe.call(R,We),Y=!0)}}finally{const Pe=C.current,We=I.current,it=A.current,Xe=j.current,nt=z??(J.signal.aborted?"aborted":_?"error":"complete");try{(ve=R==null?void 0:R.onClosed)==null||ve.call(R,{reason:nt,lastSeq:Pe,lastCheckpointId:We,lastCheckpointNs:it,lastStateHistory:Xe,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:()=>J.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:P,clear:M,setToken:L}}function Ug(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Hg(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 Wg(e){return e.type!=="token"}const Vg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Kg(e,t){var n;switch(t.type){case"reset":return{messages:di(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=di(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=di(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return s.length?{...e,messages:[...s,...e.messages]}:e}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Yl(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Yl(o,s),e):e}case"interrupt_response":return{...e,messages:Xl(e.messages),pendingInterrupt:null};default:return e}}function Gl(e=[]){const[t,n]=w.useReducer(Kg,{...Vg,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 Yl(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Xg(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??Jl(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:ec(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}=qg(d.content,t.delta,p,h);if(!y)return e;const g={...d,content:x},b=Eo(l,c,g),S={...f,[a]:m};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Jl(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=Zl(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=Ql(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=pi(p,d,c,t.args),k={...p,name:p.name??c,additionalKwargs:S},C=f,T=C>=0?Eo(e.messages,C,k):e.messages,I=Ao(k,d),A=hi(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:pi(void 0,d.length?d:[m],c,t.args)},b=Ao(g,d.length?d:[m]);return{...e,messages:[...e.messages,g],toolIndex:hi(e.toolIndex,x,b)}}if(t.type==="tool_end"){const a=Zl(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Ql(e,a,l),d=c>=0?e.messages[c]:null,f=l??(d==null?void 0:d.name)??((s=d==null?void 0:d.additionalKwargs)==null?void 0:s.toolName)??"tool",p=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,h=(d==null?void 0:d.id)??`tool-${p}`,x=Ao(d,a);let m=t.output;if(typeof t.output=="string")try{const 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=pi(d??void 0,x.length?x:a,f),k={id:h,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[g],createdAt:b,artifact:y??void 0,additionalKwargs:S},C=c>=0?Eo(e.messages,c,k):[...e.messages,k],T=Ao(k,a.length?a:x);return{...e,messages:C,toolIndex:hi(e.toolIndex,h,T)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Yg(e.messages,t.checkpointId,a);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:a,messages:l}}if(t.type==="branch"){const a=t.checkpointId??e.lastCheckpointId,l=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:a??null,lastCheckpointNs:l??null}}if(t.type==="error"){const a={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,a]}}if(t.type==="state_history"){const a=ur(t),l=a.interrupt,c=a.latest,d=l===null?Xl(e.messages):e.messages;return{...e,messages:d,pendingInterrupt:l,lastCheckpointId:(c==null?void 0:c.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(c==null?void 0:c.checkpointNs)??e.lastCheckpointNs}}return t.type==="thread_info",e}function di(e){return e.filter(t=>{var s;if(t.role!=="assistant")return!0;const n=(t.content||[]).some(i=>{var a;return i&&i.type==="text"&&((a=i.text)==null?void 0:a.trim())}),r=(t.content||[]).some(i=>i&&i.type==="image_url"),o=!!((s=t.artifact)!=null&&s.plots&&t.artifact.plots.length>0);return!!(n||r||o)})}function Eo(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Xl(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 Jl(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Zl(e){const t=new Set,n=r=>{typeof r=="string"&&r.trim()&&t.add(r.trim())};return n(e.id),n(e==null?void 0:e.call_id),n(e==null?void 0:e.callId),Array.from(t)}function fi(e){if(!e)return[];const t=new Set,n=o=>{typeof o=="string"&&o.trim()&&t.add(o.trim())},r=e.additionalKwargs;if(r){n(r.toolCallId);const o=r.toolCallIds;if(Array.isArray(o))for(const s of o)n(s)}for(const o of e.content??[])(o==null?void 0:o.type)==="tool_call"&&n(o.id);return Array.from(t)}function pi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=fi(e);for(const c of l)s(c)}for(const l of t)s(l);const i=Array.from(o),a={...(e==null?void 0:e.additionalKwargs)??{}};if(i.length){a.toolCallIds=i;const l=typeof a.toolCallId=="string"?a.toolCallId.trim():null;a.toolCallId=l&&o.has(l)?l:i[0]}return n&&(a.toolName=n),r!==void 0&&(a.toolArgs=r),a}function Ao(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=fi(e);for(const o of r)n.add(o);return Array.from(n)}function hi(e,t,n){if(!n.length)return e;let r=!1;const o={...e};for(const s of n)s&&o[s]!==t&&(o[s]=t,r=!0);return r?o:e}function Ql(e,t,n){var o,s;const r=new Set(t.filter(i=>typeof i=="string"&&i.trim()));for(const i of r){const a=e.toolIndex[i];if(a){const l=e.messages.findIndex(c=>c.id===a);if(l!==-1)return l}}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(fi(a).some(c=>r.has(c)))return i}if(typeof n=="string"&&n.trim())for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool"||a.name&&a.name!==n)continue;if(!((o=a.content)==null?void 0:o.some(c=>c.type!=="tool_call")))return i}for(let i=e.messages.length-1;i>=0;i--){const a=e.messages[i];if(a.role!=="tool")continue;if(!((s=a.content)==null?void 0:s.some(c=>c.type!=="tool_call")))return i}return-1}function ec(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function qg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??ec(e);let l="",c=e.slice();if(s){const f=Gg(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 tc(e){return e.replace(/\s+/g," ").trim()}function Gg(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=tc(e),o=tc(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 Yg(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 Eo(e,r,s)}return e}function Xg(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const nc=200;function Jg({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(M=>{try{const P=globalThis.structuredClone;if(typeof P=="function")return P(M)}catch{}try{return JSON.parse(JSON.stringify(M))}catch{return M}},[]),y=w.useCallback((M,P)=>{if(!M)return;const F=p.current.get(M)??[],N=m(P),B=F.length>=nc?[...F.slice(F.length-nc+1),N]:[...F,N];p.current.set(M,B)},[m]),g=w.useCallback(M=>{M&&p.current.set(M,[])},[]),b=w.useCallback(M=>{const P=M??f.current;if(!P)return;const F=p.current.get(P);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(M=>{var N,B,R,J,z;const P=M.seq??null;if(P!==null){const _=d.current;if(_!==null){if(P<=_)return;P>_+1&&(s==null||s({from:_,to:P}))}d.current=P}if(M.type==="thread_info"){f.current=M.threadId,h.current&&(h.current.threadIdGuess=M.threadId),x.current=M,g(M.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",M);try{t(M)}catch(_){console.error("[useChatStreamingService] Error in onThreadInfo handler:",_)}return}if(M.type==="heartbeat"){try{c==null||c(M)}catch(_){console.error("[useChatStreamingService] Error in onHeartbeat handler:",_)}return}if(M.type==="error"){const _=M;if(_.error_type==="auth_error"||_.code==="TOKEN_EXPIRED"||((N=_.message)==null?void 0:N.includes("token"))||((B=_.message)==null?void 0:B.includes("401"))||((R=_.message)==null?void 0:R.includes("unauthorized"))||((J=_.message)==null?void 0:J.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",_.message);try{l==null||l(_.message)}catch(X){console.warn("[useChatStreamingService] onAuthError handler failed",X)}}}const F=M.threadId??(M.type==="state_history"?M.threadId:void 0)??f.current??((z=h.current)==null?void 0:z.threadIdGuess)??null;if(M.type==="state_history"){f.current=F??f.current;try{r==null||r(M)}catch(_){console.error("[useChatStreamingService] onStateHistory handler failed",_)}}if(Wg(M)){M.type==="checkpoint"||M.type==="state_history"?g(F??null):y(F??null,M);try{n(M)}catch(_){console.error("[useChatStreamingService] Error in onMessageEvent handler:",_)}return}try{o==null||o(M)}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}=ql({baseUrl:e,token:void 0}),j=w.useCallback((M,P)=>{d.current=null,x.current=null,f.current=M.threadId??null,h.current={request:M,callbacks:P,manualStop:!1,threadIdGuess:M.threadId??null},k(M,S,{onOpen:P==null?void 0:P.onOpen,onError:F=>{var N;(N=P==null?void 0:P.onError)==null||N.call(P,F)},onGap:(P==null?void 0:P.onGap)??s,onConnectionError:F=>{var N;a==null||a(F),(N=P==null?void 0:P.onConnectionError)==null||N.call(P,F)},onAuthError:F=>{var N;l==null||l(F),(N=P==null?void 0:P.onAuthError)==null||N.call(P,F)},onHeartbeat:F=>{var N;try{c==null||c(F)}catch(B){console.warn("[useChatStreamingService] onHeartbeat handler failed",B)}try{(N=P==null?void 0:P.onHeartbeat)==null||N.call(P,F)}catch(B){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",B)}},onClosed:F=>{var J,z,_,Y;const N=((J=h.current)==null?void 0:J.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 R={...F,threadId:B,threadInfo:x.current,manualStop:N};try{i==null||i(R)}catch(X){console.warn("[useChatStreamingService] onStreamClosed handler failed",X)}try{(Y=P==null?void 0:P.onClosed)==null||Y.call(P,R)}catch(X){console.warn("[useChatStreamingService] downstream onClosed handler failed",X)}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:j,stop:L,isStreaming:T,error:I,setAuthToken:A,replayBufferedEvents:b}),[j,L,T,I,A,b])}const rc=w.createContext(null),oc=w.createContext(null),sc=w.createContext(null);w.createContext(!1);function Zg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a}){const{api:l,baseUrl:c}=ci(),d=w.useMemo(()=>bn(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:j,pushUser:L,onEvent:M}=Gl(),[P,F]=w.useState(!1),[N,B]=w.useState(!1),[R,J]=w.useState(null),[z,_]=w.useState([]),[Y,X]=w.useState([]),[se,ye]=w.useState(!1),Re=w.useMemo(()=>z.flatMap(U=>U.messages??[]),[z]),K=w.useMemo(()=>Kl(Re),[Re]),H=w.useRef(h),G=w.useRef(null),$=w.useRef(null),q=w.useRef(null),Z=w.useRef(null),le=w.useRef(!1),oe=w.useRef(null),_e=w.useRef(new Map),Ue=w.useRef(new Map);w.useEffect(()=>{H.current=h},[h]);const De=w.useCallback(async()=>{y(!0),b(null);try{const U=await l.listThreads();p(U??[])}catch(U){const re=String(U);b(re),s==null||s(re)}finally{y(!1)}},[l,s]),Ge=w.useCallback(U=>{if(!(U!=null&&U.threadId))return;const re={threadId:U.threadId,title:U.title||`Thread ${U.threadId.slice(0,8)}`,createdAt:U.createdAt||new Date().toISOString(),updatedAt:U.updatedAt||new Date().toISOString(),messageCount:U.messageCount??1};p(D=>D.some(ne=>ne.threadId===re.threadId)?(console.debug("[ChatSessionProvider] thread_info: thread already in list",re.threadId),D):(console.debug("[ChatSessionProvider] thread_info: adding thread to list",re.threadId),[re,...D]))},[]),He=w.useCallback(U=>{const re=U.threadId??H.current;if(!re||H.current&&H.current!==re)return;const{checkpoints:D,timeline:Q}=ur(U);if(!D.length)return;const ne=D.find(Se=>Se.messages&&Se.messages.length>0)??D.find(Se=>!!Se.checkpointId)??D[0];A((ne==null?void 0:ne.messages)??[],{checkpointId:(ne==null?void 0:ne.checkpointId)??null,checkpointNs:(ne==null?void 0:ne.checkpointNs)??null}),X(Q),_(D),F(!!(ne!=null&&ne.nextCursor)),J((ne==null?void 0:ne.nextCursor)??null),oe.current=`${re}:latest`,$.current=null,q.current=null},[A]),fe=w.useCallback(U=>{console.log("[ChatSessionProvider] 🎯 Received thread_info:",U.threadId),Ge(U),H.current!==U.threadId&&((U.created??!H.current)&&($.current=U.threadId),q.current=U.threadId,console.log("[ChatSessionProvider] thread_info: marking to skip auto-load for new thread"),x(U.threadId))},[Ge]),{startStream:ve,stop:Pe,isStreaming:We,error:it,setAuthToken:Xe}=Jg({baseUrl:d,onThreadInfo:fe,onMessageEvent:M,onStateHistory:He,onUnhandledEvent:U=>{console.warn("[ChatSessionProvider] Unhandled event:",U.type)},onAuthError:i}),nt=w.useCallback(async U=>{try{const re=await l.createThread(U);return x(re.threadId),await De(),re.threadId}catch(re){return s==null||s(String(re)),null}},[l,De,s]),at=w.useCallback(async U=>{const re=f;p(Q=>Q.filter(ne=>ne.threadId!==U));const D=new AbortController;Ue.current.set(U,D);try{await l.deleteThread(U),H.current===U&&(x(null),A([],{})),console.log("[ChatSessionProvider] Thread deleted successfully:",U)}catch(Q){console.error("[ChatSessionProvider] Delete failed, restoring thread:",U,Q),p(re),s==null||s(`Failed to delete thread: ${String(Q)}`)}finally{Ue.current.delete(U)}},[f,l,A,s]),Rt=w.useCallback(async(U,re)=>{try{await l.updateThread(U,re),await De()}catch(D){s==null||s(String(D))}},[l,De,s]),gt=w.useCallback(async(U,re)=>{if(!U)return;const D=`${U}:${re??"latest"}`,Q=_e.current.get(D);if(Q)return Q;const ne=(async()=>{const Se=U;k(!0),T(null);try{const Ve=await l.getStateHistory({threadId:Se,checkpointId:re||void 0});if(H.current!==Se){console.log(`[ChatSessionProvider] Thread changed during load (was ${Se}, now ${H.current}), discarding stale data`);return}const{checkpoints:ge,timeline:lt}=ur(Ve),be=ge.find(Ke=>Ke.messages&&Ke.messages.length>0)??(re?ge.find(Ke=>Ke.checkpointId===re):null)??ge[0];A((be==null?void 0:be.messages)??[],{checkpointId:(be==null?void 0:be.checkpointId)??null,checkpointNs:(be==null?void 0:be.checkpointNs)??null}),X(lt),_(ge),F(!!(be!=null&&be.nextCursor)),J((be==null?void 0:be.nextCursor)??null)}catch(Ve){if(H.current===Se){const ge=String(Ve);T(ge),s==null||s(ge)}}finally{k(!1)}})();_e.current.set(D,ne);try{await ne}finally{_e.current.delete(D)}return H.current===U&&(oe.current=D),ne},[l,A,s]),ht=w.useCallback(async(U,re)=>{Z.current=U;try{await gt(U,re)}finally{Z.current===U&&(Z.current=null)}},[gt]);w.useEffect(()=>{if(!o||!h||S||We)return;if($.current===h){$.current=null,G.current=h;return}if(q.current===h){G.current=h;return}if(Z.current===h){Z.current=null,G.current=h;return}if(G.current===h)return;G.current=h;const U=!le.current&&!!n&&h===t;let re;U&&n?(re=n,le.current=!0,console.log("[ChatSessionProvider] Loading thread with checkpoint:",re,r?`(ns: ${r})`:"")):console.log("[ChatSessionProvider] Loading thread with latest checkpoint");const D=`${h}:${re??"latest"}`;oe.current!==D&&ht(h,re)},[o,h,n,r,t,S,We,ht]);const bt=w.useCallback(async(U,re)=>{const D=H.current;if(!D)return;const Q=D;ye(!0);try{const ne=await l.getStateHistory({threadId:Q,checkpointId:U,checkpointNs:re??void 0});if(H.current!==Q){console.log(`[ChatSessionProvider] Thread changed during checkpoint navigation (was ${Q}, now ${H.current}), discarding stale data`);return}const{checkpoints:Se,timeline:Ve}=ur(ne),ge=Se.find(lt=>lt.checkpointId===U&&(re?lt.checkpointNs===re:!0));if(!ge){console.warn("[ChatSessionProvider] Requested checkpoint not found:",{checkpointId:U,checkpointNs:re});return}X(Ve),_(Se),A(ge.messages??[],{checkpointId:ge.checkpointId??null,checkpointNs:ge.checkpointNs??null})}catch(ne){H.current===Q&&(s==null||s(String(ne)))}finally{ye(!1)}},[l,A,s]),St=w.useCallback((U,re)=>{A(I.messages,{checkpointId:U??null,checkpointNs:re??null})},[A,I.messages]),Lt=w.useCallback(async()=>{H.current&&await ht(H.current)},[ht]),Mt=w.useCallback(async()=>{if(!H.current||!R)return;const U=H.current;B(!0);try{const re=await l.getStateHistory({threadId:U,checkpointId:R});if(H.current!==U)return;const{checkpoints:D}=ur(re);if(D.length>0){const Q=D[D.length-1];j((Q==null?void 0:Q.messages)??[]),F(!!(Q!=null&&Q.nextCursor)),J((Q==null?void 0:Q.nextCursor)??null)}}catch(re){H.current===U&&(s==null||s(String(re)))}finally{B(!1)}},[l,R,j,s]),et=w.useCallback(async()=>{A([],{}),x(null),Pe(),_([]),X([]),F(!1),J(null),k(!1),ye(!1),B(!1),T(null);try{await l.getAgent("default")}catch(U){console.warn("[ChatSessionProvider] Failed to refetch agent after clearing thread:",U)}},[A,Pe,l]),It=w.useCallback(async(U,re,D)=>{const Q=H.current;if(!Q)throw new Error("No active thread to handle interrupt");const ne=re?D??!0:!1;try{const Se={threadId:Q,checkpointId:I.lastCheckpointId??void 0,checkpointNs:I.lastCheckpointNs??void 0,command:{kind:"resume",value:ne}};ve(Se)}catch(Se){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${U}:`,Se),Se}},[I.lastCheckpointId,I.lastCheckpointNs,ve]);w.useEffect(()=>{De()},[De]),w.useEffect(()=>{a==null||a(h)},[h,a]);const vn=w.useCallback(async(U,re)=>{let D=H.current;const Q=(U==null?void 0:U.text)??"",ne=(U==null?void 0:U.attachments)??[],Se=(Q==null?void 0:Q.trim())??"",Ve={...(U==null?void 0:U.payload)??{}},ge=Array.isArray(Ve.messages)?Ve.messages:void 0;ge&&delete Ve.messages;const lt=!!(ge&&ge.length);if(!D&&!Se&&ne.length===0&&!lt)return;if(!D){const W=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ie=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);D=`${W}${ie}`,$.current=D,x(D)}const{contentParts:be,filesInfo:Ke}=await xg(l,ne),In=[...be];Se&&In.push({type:"text",text:Q});const En=re==null?void 0:re.originalMessageId,Un=!!(re!=null&&re.edit&&En),uo=!lt&&In.length>0;let Hn=null;uo&&(Hn={id:Un?En:`msg-${Date.now()}`,role:"user",content:In,createdAt:new Date().toISOString()},Un||L(Hn));const Er=lt?ge:Hn?[Hn]:[],An={...Ve,...Ke.length?{files_info:Ke}:{}};Er.length?An.messages=Er:"messages"in An||(An.messages=[]);const E={threadId:D,payload:An,checkpointId:(re==null?void 0:re.checkpointId)??I.lastCheckpointId??void 0,checkpointNs:(re==null?void 0:re.checkpointNs)??I.lastCheckpointNs??void 0,edit:!!(re!=null&&re.edit),originalMessageId:Un?En:void 0};ve(E)},[l,L,I,ve]),Je=w.useMemo(()=>({threads:f,currentThreadId:h,setCurrentThreadId:x,isLoading:m,error:g,actions:{createThread:nt,deleteThread:at,renameThread:Rt,refreshThreads:De}}),[f,h,m,g,nt,at,Rt,De]),tt=w.useMemo(()=>({threadId:h,messages:I.messages,interrupt:null,checkpoint:{id:I.lastCheckpointId??null,namespace:I.lastCheckpointNs??null},checkpoints:z,timelineCheckpoints:Y,metadata:null,isLoading:S,isHistoryLoading:N,isLoadingCheckpoint:se,error:C,hasMore:P,loadOlder:Mt,clearState:et,navigateToCheckpoint:bt,setCurrentCheckpointId:St,returnToLatest:Lt,loadThread:ht,clearThread:et,respondToInterrupt:It,messagePreviews:K}),[h,I,z,Y,S,N,se,C,P,Mt,et,bt,St,Lt,ht,It,K]),pt=w.useMemo(()=>({isStreaming:We,error:it,connectionState:We?"connected":"idle",submit:vn,send:vn,stop:Pe,setAuthToken:Xe}),[We,it,vn,Pe,Xe]);return u.jsx(rc.Provider,{value:Je,children:u.jsx(oc.Provider,{value:tt,children:u.jsx(sc.Provider,{value:pt,children:e})})})}function No(){const e=w.useContext(rc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function _o(){const e=w.useContext(oc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function ic(){const e=w.useContext(sc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function jo({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(mg,{apiConfig:t,children:u.jsx(Zg,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:i,onAuthError:a,onThreadChange:l,children:e})})}function te(...e){return Uh.twMerge(zh.clsx(e))}const Qg=fo.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ze=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?Wn.Slot:"button";return u.jsx(i,{className:te(Qg({variant:t,size:n,className:e})),ref:s,...o})});Ze.displayName="Button";const ac=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}));ac.displayName="Textarea";function lc({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:R})=>{x||y(B),R&&(a==null||a(B))},[x,a]),j=w.useCallback(async B=>{B&&B.preventDefault();const R=(g??"").trim();if(!R&&!h)return;const J=++C.current;T.current={id:J,shouldClear:!0},S(()=>{var z,_,Y;try{const X=l(R);X&&typeof X.then=="function"?X.then(()=>{var se,ye;((se=T.current)==null?void 0:se.id)===J&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((ye=T.current)==null?void 0:ye.id)===J&&(T.current=null)}).catch(()=>{var se;((se=T.current)==null?void 0:se.id)===J&&(T.current=null)}):(((z=T.current)==null?void 0:z.id)===J&&T.current.shouldClear&&(x||(y(""),k.current&&(k.current.style.height="auto"),a==null||a(""))),((_=T.current)==null?void 0:_.id)===J&&(T.current=null))}catch{((Y=T.current)==null?void 0:Y.id)===J&&(T.current=null)}})},[g,l,h,x,a]),L=w.useCallback(B=>{const R=B.target.value;A(R,{fromUser:!0}),T.current&&(T.current.shouldClear=!1),k.current&&(k.current.style.height="auto",k.current.style.height=`${k.current.scrollHeight}px`)},[A]),M=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),j()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[j,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 j(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(ac,{ref:k,value:g,onChange:L,onKeyDown:M,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(Ze,{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(Ze,{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 ex=w.memo(lc);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 cc(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function mi(...e){return t=>{let n=!1;const r=e.map(o=>{const s=cc(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():cc(e[o],null)}}}}function Fe(...e){return v.useCallback(mi(...e),e)}function tx(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 wn(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,nx(o,...t)]}function nx(...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:()=>{},rx=v[" useInsertionEffect ".trim().toString()]||Tt;function fr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ox({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=sx(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 ox({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return rx(()=>{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 sx(e){return typeof e=="function"}var ix=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=ix.reduce((e,t)=>{const n=Wn.createSlot(`Primitive.${t}`),r=v.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function uc(e,t){e&&po.flushSync(()=>e.dispatchEvent(t))}function gi(e){const t=e+"CollectionProvider",[n,r]=wn(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=Wn.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=Wn.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 ax=v.createContext(void 0);function Ro(e){const t=v.useContext(ax);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 lx(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 cx="DismissableLayer",xi="dismissableLayer.update",ux="dismissableLayer.pointerDownOutside",dx="dismissableLayer.focusOutside",dc,fc=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Mo=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(fc),[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=hx(I=>{const A=I.target,j=[...c.branches].some(L=>L.contains(A));!k||j||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),T=mx(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 lx(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&&(dc=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),pc(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=dc)}},[d,p,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),pc())},[d,c]),v.useEffect(()=>{const I=()=>h({});return document.addEventListener(xi,I),()=>document.removeEventListener(xi,I)},[]),u.jsx(Ne.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)})});Mo.displayName=cx;var fx="DismissableLayerBranch",px=v.forwardRef((e,t)=>{const n=v.useContext(fc),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})});px.displayName=fx;function hx(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(){hc(ux,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 mx(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&&hc(dx,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 pc(){const e=new CustomEvent(xi);document.dispatchEvent(e)}function hc(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?uc(o,s):o.dispatchEvent(s)}var yi=0;function vi(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??mc()),document.body.insertAdjacentElement("beforeend",e[1]??mc()),yi++,()=>{yi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),yi--}},[])}function mc(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var bi="focusScope.autoFocusOnMount",wi="focusScope.autoFocusOnUnmount",gc={bubbles:!1,cancelable:!0},gx="FocusScope",Po=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:_n(f.current,{select:!0})},y=function(S){if(h.paused||!a)return;const k=S.relatedTarget;k!==null&&(a.contains(k)||_n(f.current,{select:!0}))},g=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&_n(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",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){vc.add(h);const m=document.activeElement;if(!a.contains(m)){const g=new CustomEvent(bi,gc);a.addEventListener(bi,c),a.dispatchEvent(g),g.defaultPrevented||(xx(Sx(xc(a)),{select:!0}),document.activeElement===m&&_n(a))}return()=>{a.removeEventListener(bi,c),setTimeout(()=>{const g=new CustomEvent(wi,gc);a.addEventListener(wi,d),a.dispatchEvent(g),g.defaultPrevented||_n(m??document.body,{select:!0}),a.removeEventListener(wi,d),vc.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]=yx(b);S&&k?!m.shiftKey&&g===k?(m.preventDefault(),n&&_n(S,{select:!0})):m.shiftKey&&g===S&&(m.preventDefault(),n&&_n(k,{select:!0})):g===b&&m.preventDefault()}},[n,r,h.paused]);return u.jsx(Ne.div,{tabIndex:-1,...i,ref:p,onKeyDown:x})});Po.displayName=gx;function xx(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(_n(r,{select:t}),document.activeElement!==n)return}function yx(e){const t=xc(e),n=yc(t,e),r=yc(t.reverse(),e);return[n,r]}function xc(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 yc(e,t){for(const n of e)if(!vx(n,{upTo:t}))return n}function vx(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 bx(e){return e instanceof HTMLInputElement&&"select"in e}function _n(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&bx(e)&&t&&e.select()}}var vc=wx();function wx(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=bc(e,t),e.unshift(t)},remove(t){var n;e=bc(e,t),(n=e[0])==null||n.resume()}}}function bc(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Sx(e){return e.filter(t=>t.tagName!=="A")}var Cx=v[" useId ".trim().toString()]||(()=>{}),Tx=0;function Sn(e){const[t,n]=v.useState(Cx());return Tt(()=>{n(r=>r??String(Tx++))},[e]),t?`radix-${t}`:""}const kx=["top","right","bottom","left"],jn=Math.min,zt=Math.max,Oo=Math.round,Do=Math.floor,un=e=>({x:e,y:e}),Ix={left:"right",right:"left",bottom:"top",top:"bottom"},Ex={start:"end",end:"start"};function Si(e,t,n){return zt(e,jn(t,n))}function Cn(e,t){return typeof e=="function"?e(t):e}function Tn(e){return e.split("-")[0]}function pr(e){return e.split("-")[1]}function Ci(e){return e==="x"?"y":"x"}function Ti(e){return e==="y"?"height":"width"}const Ax=new Set(["top","bottom"]);function dn(e){return Ax.has(Tn(e))?"y":"x"}function ki(e){return Ci(dn(e))}function Nx(e,t,n){n===void 0&&(n=!1);const r=pr(e),o=ki(e),s=Ti(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Lo(i)),[i,Lo(i)]}function _x(e){const t=Lo(e);return[Ii(e),t,Ii(t)]}function Ii(e){return e.replace(/start|end/g,t=>Ex[t])}const wc=["left","right"],Sc=["right","left"],jx=["top","bottom"],Rx=["bottom","top"];function Mx(e,t,n){switch(e){case"top":case"bottom":return n?t?Sc:wc:t?wc:Sc;case"left":case"right":return t?jx:Rx;default:return[]}}function Px(e,t,n,r){const o=pr(e);let s=Mx(Tn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ii)))),s}function Lo(e){return e.replace(/left|right|bottom|top/g,t=>Ix[t])}function Ox(e){return{top:0,right:0,bottom:0,left:0,...e}}function Cc(e){return typeof e!="number"?Ox(e):{top:e,right:e,bottom:e,left:e}}function $o(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Tc(e,t,n){let{reference:r,floating:o}=e;const s=dn(t),i=ki(t),a=Ti(i),l=Tn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let h;switch(l){case"top":h={x:d,y:r.y-o.height};break;case"bottom":h={x:d,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:f};break;case"left":h={x:r.x-o.width,y:f};break;default:h={x:r.x,y:r.y}}switch(pr(t)){case"start":h[i]-=p*(n&&c?-1:1);break;case"end":h[i]+=p*(n&&c?-1:1);break}return h}const Dx=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}=Tc(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}=Tc(c,p,l)),m=-1)}return{x:d,y:f,placement:p,strategy:o,middlewareData:h}};async function Dr(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}=Cn(t,e),x=Cc(h),y=a[p?f==="floating"?"reference":"floating":f],g=$o(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=$o(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(g.top-C.top+x.top)/k.y,bottom:(C.bottom-g.bottom+x.bottom)/k.y,left:(g.left-C.left+x.left)/k.x,right:(C.right-g.right+x.right)/k.x}}const Lx=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}=Cn(e,t)||{};if(c==null)return{};const f=Cc(d),p={x:n,y:r},h=ki(o),x=Ti(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,j=I/2-m[x]/2-1,L=jn(f[g],j),M=jn(f[b],j),P=L,F=I-m[x]-M,N=I/2-m[x]/2+A,B=Si(P,N,F),R=!l.arrow&&pr(o)!=null&&N!==B&&s.reference[x]/2-(N<P?L:M)-m[x]/2<0,J=R?N<P?N-P:N-F:0;return{[h]:p[h]+J,data:{[h]:B,centerOffset:N-B-J,...R&&{alignmentOffset:J}},reset:R}}}),$x=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}=Cn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const g=Tn(o),b=dn(a),S=Tn(a)===a,k=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(S||!m?[Lo(a)]:_x(a)),T=x!=="none";!p&&T&&C.push(...Px(a,m,x,k));const I=[a,...C],A=await Dr(t,y),j=[];let L=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[g]),f){const N=Nx(o,i,k);j.push(A[N[0]],A[N[1]])}if(L=[...L,{placement:o,overflows:j}],!j.every(N=>N<=0)){var M,P;const N=(((M=s.flip)==null?void 0:M.index)||0)+1,B=I[N];if(B&&(!(f==="alignment"?b!==dn(B):!1)||L.every(z=>dn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:N,overflows:L},reset:{placement:B}};let R=(P=L.filter(J=>J.overflows[0]<=0).sort((J,z)=>J.overflows[1]-z.overflows[1])[0])==null?void 0:P.placement;if(!R)switch(h){case"bestFit":{var F;const J=(F=L.filter(z=>{if(T){const _=dn(z.placement);return _===b||_==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(_=>_>0).reduce((_,Y)=>_+Y,0)]).sort((z,_)=>z[1]-_[1])[0])==null?void 0:F[0];J&&(R=J);break}case"initialPlacement":R=a;break}if(o!==R)return{reset:{placement:R}}}return{}}}};function kc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ic(e){return kx.some(t=>e[t]>=0)}const Fx=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Cn(e,t);switch(r){case"referenceHidden":{const s=await Dr(t,{...o,elementContext:"reference"}),i=kc(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ic(i)}}}case"escaped":{const s=await Dr(t,{...o,altBoundary:!0}),i=kc(s,n.floating);return{data:{escapedOffsets:i,escaped:Ic(i)}}}default:return{}}}}},Ec=new Set(["left","top"]);async function Bx(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Tn(n),a=pr(n),l=dn(n)==="y",c=Ec.has(i)?-1:1,d=s&&l?-1:1,f=Cn(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 zx=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 Bx(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}}}}},Ux=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}=Cn(e,t),c={x:n,y:r},d=await Dr(t,l),f=dn(Tn(o)),p=Ci(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=Si(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=Si(b,x,S)}const m=a.fn({...t,[p]:h,[f]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[f]:i}}}}}},Hx=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}=Cn(e,t),d={x:n,y:r},f=dn(o),p=Ci(f);let h=d[p],x=d[f];const m=Cn(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=Ec.has(Tn(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}}}},Wx=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}=Cn(e,t),d=await Dr(t,c),f=Tn(o),p=pr(o),h=dn(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=jn(m-d[y],b),C=jn(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=zt(d.left,0),M=zt(d.right,0),P=zt(d.top,0),F=zt(d.bottom,0);h?A=x-2*(L!==0||M!==0?L+M:zt(d.left,d.right)):I=m-2*(P!==0||F!==0?P+F:zt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:I});const j=await i.getDimensions(a.floating);return x!==j.width||m!==j.height?{reset:{rects:!0}}:{}}}};function Fo(){return typeof window<"u"}function hr(e){return Ac(e)?(e.nodeName||"").toLowerCase():"#document"}function Ut(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function fn(e){var t;return(t=(Ac(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Ac(e){return Fo()?e instanceof Node||e instanceof Ut(e).Node:!1}function tn(e){return Fo()?e instanceof Element||e instanceof Ut(e).Element:!1}function pn(e){return Fo()?e instanceof HTMLElement||e instanceof Ut(e).HTMLElement:!1}function Nc(e){return!Fo()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ut(e).ShadowRoot}const Vx=new Set(["inline","contents"]);function Lr(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=nn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Vx.has(o)}const Kx=new Set(["table","td","th"]);function qx(e){return Kx.has(hr(e))}const Gx=[":popover-open",":modal"];function Bo(e){return Gx.some(t=>{try{return e.matches(t)}catch{return!1}})}const Yx=["transform","translate","scale","rotate","perspective"],Xx=["transform","translate","scale","rotate","perspective","filter"],Jx=["paint","layout","strict","content"];function Ei(e){const t=Ai(),n=tn(e)?nn(e):e;return Yx.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)||Xx.some(r=>(n.willChange||"").includes(r))||Jx.some(r=>(n.contain||"").includes(r))}function Zx(e){let t=Rn(e);for(;pn(t)&&!mr(t);){if(Ei(t))return t;if(Bo(t))return null;t=Rn(t)}return null}function Ai(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qx=new Set(["html","body","#document"]);function mr(e){return Qx.has(hr(e))}function nn(e){return Ut(e).getComputedStyle(e)}function zo(e){return tn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Rn(e){if(hr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Nc(e)&&e.host||fn(e);return Nc(t)?t.host:t}function _c(e){const t=Rn(e);return mr(t)?e.ownerDocument?e.ownerDocument.body:e.body:pn(t)&&Lr(t)?t:_c(t)}function $r(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=_c(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ut(o);if(s){const a=Ni(i);return t.concat(i,i.visualViewport||[],Lr(o)?o:[],a&&n?$r(a):[])}return t.concat(o,$r(o,[],n))}function Ni(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function jc(e){const t=nn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=pn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Oo(n)!==s||Oo(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function _i(e){return tn(e)?e:e.contextElement}function gr(e){const t=_i(e);if(!pn(t))return un(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=jc(t);let i=(s?Oo(n.width):n.width)/r,a=(s?Oo(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ey=un(0);function Rc(e){const t=Ut(e);return!Ai()||!t.visualViewport?ey:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ty(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ut(e)?!1:t}function Gn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=_i(e);let i=un(1);t&&(r?tn(r)&&(i=gr(r)):i=gr(e));const a=ty(s,n,r)?Rc(s):un(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&&tn(r)?Ut(r):r;let x=p,m=Ni(x);for(;m&&r&&h!==x;){const y=gr(m),g=m.getBoundingClientRect(),b=nn(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=Ni(x)}}return $o({width:d,height:f,x:l,y:c})}function Uo(e,t){const n=zo(e).scrollLeft;return t?t.left+n:Gn(fn(e)).left+n}function Mc(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Uo(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function ny(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=fn(r),a=t?Bo(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=un(1);const d=un(0),f=pn(r);if((f||!f&&!s)&&((hr(r)!=="body"||Lr(i))&&(l=zo(r)),pn(r))){const h=Gn(r);c=gr(r),d.x=h.x+r.clientLeft,d.y=h.y+r.clientTop}const p=i&&!f&&!s?Mc(i,l):un(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 ry(e){return Array.from(e.getClientRects())}function oy(e){const t=fn(e),n=zo(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+Uo(e);const a=-n.scrollTop;return nn(r).direction==="rtl"&&(i+=zt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Pc=25;function sy(e,t){const n=Ut(e),r=fn(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=Ai();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Uo(r);if(c<=0){const d=r.ownerDocument,f=d.body,p=getComputedStyle(f),h=d.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,x=Math.abs(r.clientWidth-f.clientWidth-h);x<=Pc&&(s-=x)}else c<=Pc&&(s+=c);return{width:s,height:i,x:a,y:l}}const iy=new Set(["absolute","fixed"]);function ay(e,t){const n=Gn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=pn(e)?gr(e):un(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 Oc(e,t,n){let r;if(t==="viewport")r=sy(e,n);else if(t==="document")r=oy(fn(e));else if(tn(t))r=ay(t,n);else{const o=Rc(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return $o(r)}function Dc(e,t){const n=Rn(e);return n===t||!tn(n)||mr(n)?!1:nn(n).position==="fixed"||Dc(n,t)}function ly(e,t){const n=t.get(e);if(n)return n;let r=$r(e,[],!1).filter(a=>tn(a)&&hr(a)!=="body"),o=null;const s=nn(e).position==="fixed";let i=s?Rn(e):e;for(;tn(i)&&!mr(i);){const a=nn(i),l=Ei(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&iy.has(o.position)||Lr(i)&&!l&&Dc(e,i))?r=r.filter(d=>d!==i):o=a,i=Rn(i)}return t.set(e,r),r}function cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Bo(t)?[]:ly(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Oc(t,d,o);return c.top=zt(f.top,c.top),c.right=jn(f.right,c.right),c.bottom=jn(f.bottom,c.bottom),c.left=zt(f.left,c.left),c},Oc(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function uy(e){const{width:t,height:n}=jc(e);return{width:t,height:n}}function dy(e,t,n){const r=pn(t),o=fn(t),s=n==="fixed",i=Gn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=un(0);function c(){l.x=Uo(o)}if(r||!r&&!s)if((hr(t)!=="body"||Lr(o))&&(a=zo(t)),r){const h=Gn(t,!0,s,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Mc(o,a):un(0),f=i.left+a.scrollLeft-l.x-d.x,p=i.top+a.scrollTop-l.y-d.y;return{x:f,y:p,width:i.width,height:i.height}}function ji(e){return nn(e).position==="static"}function Lc(e,t){if(!pn(e)||nn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return fn(e)===n&&(n=n.ownerDocument.body),n}function $c(e,t){const n=Ut(e);if(Bo(e))return n;if(!pn(e)){let o=Rn(e);for(;o&&!mr(o);){if(tn(o)&&!ji(o))return o;o=Rn(o)}return n}let r=Lc(e,t);for(;r&&qx(r)&&ji(r);)r=Lc(r,t);return r&&mr(r)&&ji(r)&&!Ei(r)?n:r||Zx(e)||n}const fy=async function(e){const t=this.getOffsetParent||$c,n=this.getDimensions,r=await n(e.floating);return{reference:dy(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function py(e){return nn(e).direction==="rtl"}const hy={convertOffsetParentRelativeRectToViewportRelativeRect:ny,getDocumentElement:fn,getClippingRect:cy,getOffsetParent:$c,getElementRects:fy,getClientRects:ry,getDimensions:uy,getScale:gr,isElement:tn,isRTL:py};function Fc(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function my(e,t){let n=null,r;const o=fn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:d,top:f,width:p,height:h}=c;if(a||t(),!p||!h)return;const x=Do(f),m=Do(o.clientWidth-(d+p)),y=Do(o.clientHeight-(f+h)),g=Do(d),S={rootMargin:-x+"px "+-m+"px "+-y+"px "+-g+"px",threshold:zt(0,jn(1,l))||1};let k=!0;function C(T){const I=T[0].intersectionRatio;if(I!==l){if(!k)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!Fc(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 gy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=_i(e),d=o||s?[...c?$r(c):[],...$r(t)]:[];d.forEach(g=>{o&&g.addEventListener("scroll",n,{passive:!0}),s&&g.addEventListener("resize",n)});const f=c&&a?my(c,n):null;let p=-1,h=null;i&&(h=new ResizeObserver(g=>{let[b]=g;b&&b.target===c&&h&&(h.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var S;(S=h)==null||S.observe(t)})),n()}),c&&!l&&h.observe(c),h.observe(t));let x,m=l?Gn(e):null;l&&y();function y(){const g=Gn(e);m&&!Fc(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 xy=zx,yy=Ux,vy=$x,by=Wx,wy=Fx,Bc=Lx,Sy=Hx,Cy=(e,t,n)=>{const r=new Map,o={platform:hy,...n},s={...o.platform,_c:r};return Dx(e,t,{...o,platform:s})};var Ty=typeof document<"u",ky=function(){},Ho=Ty?w.useLayoutEffect:ky;function Wo(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Wo(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Wo(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function zc(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Uc(e,t){const n=zc(e);return Math.round(t*n)/n}function Ri(e){const t=v.useRef(e);return Ho(()=>{t.current=e}),t}function Iy(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);Wo(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),j=l!=null,L=Ri(l),M=Ri(o),P=Ri(c),F=v.useCallback(()=>{if(!T.current||!I.current)return;const z={placement:t,strategy:n,middleware:p};M.current&&(z.platform=M.current),Cy(T.current,I.current,z).then(_=>{const Y={..._,isPositioned:P.current!==!1};N.current&&!Wo(A.current,Y)&&(A.current=Y,po.flushSync(()=>{f(Y)}))})},[p,t,n,M,P]);Ho(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[c]);const N=v.useRef(!1);Ho(()=>(N.current=!0,()=>{N.current=!1}),[]),Ho(()=>{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,j]);const B=v.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),R=v.useMemo(()=>({reference:k,floating:C}),[k,C]),J=v.useMemo(()=>{const z={position:n,left:0,top:0};if(!R.floating)return z;const _=Uc(R.floating,d.x),Y=Uc(R.floating,d.y);return a?{...z,transform:"translate("+_+"px, "+Y+"px)",...zc(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:_,top:Y}},[n,a,R.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:F,refs:B,elements:R,floatingStyles:J}),[d,F,B,R,J])}const Ey=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?Bc({element:r.current,padding:o}).fn(n):{}:r?Bc({element:r,padding:o}).fn(n):{}}}},Ay=(e,t)=>({...xy(e),options:[e,t]}),Ny=(e,t)=>({...yy(e),options:[e,t]}),_y=(e,t)=>({...Sy(e),options:[e,t]}),jy=(e,t)=>({...vy(e),options:[e,t]}),Ry=(e,t)=>({...by(e),options:[e,t]}),My=(e,t)=>({...wy(e),options:[e,t]}),Py=(e,t)=>({...Ey(e),options:[e,t]});var Oy="Arrow",Hc=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"})})});Hc.displayName=Oy;var Dy=Hc;function Wc(e){const[t,n]=v.useState(void 0);return Tt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Mi="Popper",[Vc,Vo]=wn(Mi),[Ly,Kc]=Vc(Mi),qc=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(Ly,{scope:t,anchor:r,onAnchorChange:o,children:n})};qc.displayName=Mi;var Gc="PopperAnchor",Yc=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Kc(Gc,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})});Yc.displayName=Gc;var Pi="PopperContent",[$y,Fy]=Vc(Pi),Xc=v.forwardRef((e,t)=>{var G,$,q,Z,le,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=Kc(Pi,n),[g,b]=v.useState(null),S=Fe(t,_e=>b(_e)),[k,C]=v.useState(null),T=Wc(k),I=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,j=r+(s!=="center"?"-"+s:""),L=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},M=Array.isArray(c)?c:[c],P=M.length>0,F={padding:L,boundary:M.filter(zy),altBoundary:P},{refs:N,floatingStyles:B,placement:R,isPositioned:J,middlewareData:z}=Iy({strategy:"fixed",placement:j,whileElementsMounted:(..._e)=>gy(..._e,{animationFrame:h==="always"}),elements:{reference:y.anchor},middleware:[Ay({mainAxis:o+A,alignmentAxis:i}),l&&Ny({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?_y():void 0,...F}),l&&jy({...F}),Ry({...F,apply:({elements:_e,rects:Ue,availableWidth:De,availableHeight:Ge})=>{const{width:He,height:fe}=Ue.reference,ve=_e.floating.style;ve.setProperty("--radix-popper-available-width",`${De}px`),ve.setProperty("--radix-popper-available-height",`${Ge}px`),ve.setProperty("--radix-popper-anchor-width",`${He}px`),ve.setProperty("--radix-popper-anchor-height",`${fe}px`)}}),k&&Py({element:k,padding:a}),Uy({arrowWidth:I,arrowHeight:A}),p&&My({strategy:"referenceHidden",...F})]}),[_,Y]=Qc(R),X=kt(x);Tt(()=>{J&&(X==null||X())},[J,X]);const se=(G=z.arrow)==null?void 0:G.x,ye=($=z.arrow)==null?void 0:$.y,Re=((q=z.arrow)==null?void 0:q.centerOffset)!==0,[K,H]=v.useState();return Tt(()=>{g&&H(window.getComputedStyle(g).zIndex)},[g]),u.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:J?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:K,"--radix-popper-transform-origin":[(Z=z.transformOrigin)==null?void 0:Z.x,(le=z.transformOrigin)==null?void 0:le.y].join(" "),...((oe=z.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx($y,{scope:n,placedSide:_,onArrowChange:C,arrowX:se,arrowY:ye,shouldHideArrow:Re,children:u.jsx(Ne.div,{"data-side":_,"data-align":Y,...m,ref:S,style:{...m.style,animation:J?void 0:"none"}})})})});Xc.displayName=Pi;var Jc="PopperArrow",By={top:"bottom",right:"left",bottom:"top",left:"right"},Zc=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Fy(Jc,r),i=By[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(Dy,{...o,ref:n,style:{...o.style,display:"block"}})})});Zc.displayName=Jc;function zy(e){return e!==null}var Uy=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]=Qc(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 Qc(e){const[t,n="center"]=e.split("-");return[t,n]}var eu=qc,tu=Yc,nu=Xc,ru=Zc,Hy="Portal",Ko=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?qs.createPortal(u.jsx(Ne.div,{...r,ref:t}),i):null});Ko.displayName=Hy;function Wy(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Gt=e=>{const{present:t,children:n}=e,r=Vy(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Fe(r.ref,Ky(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};Gt.displayName="Presence";function Vy(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Wy(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=qo(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=qo(c);e?l("MOUNT"):h==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==h?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Tt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=h=>{const m=qo(r.current).includes(CSS.escape(h.animationName));if(h.target===t&&m&&(l("ANIMATION_END"),!o.current)){const 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=qo(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:v.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function qo(e){return(e==null?void 0:e.animationName)||"none"}function Ky(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 Oi="rovingFocusGroup.onEntryFocus",qy={bubbles:!1,cancelable:!0},Fr="RovingFocusGroup",[Di,ou,Gy]=gi(Fr),[Yy,su]=wn(Fr,[Gy]),[Xy,Jy]=Yy(Fr),iu=v.forwardRef((e,t)=>u.jsx(Di.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Di.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Zy,{...e,ref:t})})}));iu.displayName=Fr;var Zy=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=Ro(s),[m,y]=fr({prop:i,defaultProp:a??null,onChange:l,caller:Fr}),[g,b]=v.useState(!1),S=kt(c),k=ou(n),C=v.useRef(!1),[T,I]=v.useState(0);return v.useEffect(()=>{const A=p.current;if(A)return A.addEventListener(Oi,S),()=>A.removeEventListener(Oi,S)},[S]),u.jsx(Xy,{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:de(e.onMouseDown,()=>{C.current=!0}),onFocus:de(e.onFocus,A=>{const j=!C.current;if(A.target===A.currentTarget&&j&&!g){const L=new CustomEvent(Oi,qy);if(A.currentTarget.dispatchEvent(L),!L.defaultPrevented){const M=k().filter(R=>R.focusable),P=M.find(R=>R.active),F=M.find(R=>R.id===m),B=[P,F,...M].filter(Boolean).map(R=>R.ref.current);cu(B,d)}}C.current=!1}),onBlur:de(e.onBlur,()=>b(!1))})})}),au="RovingFocusGroupItem",lu=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Sn(),c=s||l,d=Jy(au,n),f=d.currentTabStopId===c,p=ou(n),{onFocusableItemAdd:h,onFocusableItemRemove:x,currentTabStopId:m}=d;return v.useEffect(()=>{if(r)return h(),()=>x()},[r,h,x]),u.jsx(Di.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: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=tv(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?nv(S,k+1):S.slice(k+1)}setTimeout(()=>cu(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:m!=null}):i})})});lu.displayName=au;var Qy={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ev(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function tv(e,t,n){const r=ev(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Qy[r]}function cu(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function nv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var rv=iu,ov=lu,sv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},xr=new WeakMap,Go=new WeakMap,Yo={},Li=0,uu=function(e){return e&&(e.host||uu(e.parentNode))},iv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=uu(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})},av=function(e,t,n,r){var o=iv(t,Array.isArray(e)?e:[e]);Yo[n]||(Yo[n]=new WeakMap);var s=Yo[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var h=p.getAttribute(r),x=h!==null&&h!=="false",m=(xr.get(p)||0)+1,y=(s.get(p)||0)+1;xr.set(p,m),s.set(p,y),i.push(p),m===1&&x&&Go.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(),Li++,function(){i.forEach(function(f){var p=xr.get(f)-1,h=s.get(f)-1;xr.set(f,p),s.set(f,h),p||(Go.has(f)||f.removeAttribute(r),Go.delete(f)),h||f.removeAttribute(n)}),Li--,Li||(xr=new WeakMap,xr=new WeakMap,Go=new WeakMap,Yo={})}},$i=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=sv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),av(r,o,n,"aria-hidden")):function(){return null}},hn=function(){return hn=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},hn.apply(this,arguments)};function du(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 lv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Xo="right-scroll-bar-position",Jo="width-before-scroll-bar",cv="with-scroll-bars-hidden",uv="--removed-body-scroll-bar-size";function Fi(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function dv(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 fv=typeof window<"u"?v.useLayoutEffect:v.useEffect,fu=new WeakMap;function pv(e,t){var n=dv(null,function(r){return e.forEach(function(o){return Fi(o,r)})});return fv(function(){var r=fu.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Fi(a,null)}),s.forEach(function(a){o.has(a)||Fi(a,i)})}fu.set(n,e)},[e]),n}function hv(e){return e}function mv(e,t){t===void 0&&(t=hv);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 gv(e){e===void 0&&(e={});var t=mv(null);return t.options=hn({async:!0,ssr:!1},e),t}var pu=function(e){var t=e.sideCar,n=du(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,hn({},n))};pu.isSideCarExport=!0;function xv(e,t){return e.useMedium(t),pu}var hu=gv(),Bi=function(){},Zo=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Bi,onWheelCapture:Bi,onTouchMoveCapture:Bi}),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=du(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,T=pv([n,t]),I=hn(hn({},k),o);return v.createElement(v.Fragment,null,d&&v.createElement(C,{sideCar:hu,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),hn(hn({},I),{ref:T})):v.createElement(b,hn({},I,{className:l,ref:T}),a))});Zo.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Zo.classNames={fullWidth:Jo,zeroRight:Xo};var yv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function vv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=yv();return t&&e.setAttribute("nonce",t),e}function bv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function wv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Sv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=vv())&&(bv(t,n),wv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Cv=function(){var e=Sv();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},mu=function(){var e=Cv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Tv={left:0,top:0,right:0,gap:0},zi=function(e){return parseInt(e||"",10)||0},kv=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[zi(n),zi(r),zi(o)]},Iv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Tv;var t=kv(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])}},Ev=mu(),yr="data-scroll-locked",Av=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(cv,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(mr,`] {
43
+ body[`).concat(yr,`] {
44
44
  overflow: hidden `).concat(r,`;
45
45
  overscroll-behavior: contain;
46
46
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -53,29 +53,29 @@ React keys must be passed directly to JSX without using spread:
53
53
  `),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
54
54
  }
55
55
 
56
- .`).concat(Go,` {
56
+ .`).concat(Xo,` {
57
57
  right: `).concat(a,"px ").concat(r,`;
58
58
  }
59
59
 
60
- .`).concat(Yo,` {
60
+ .`).concat(Jo,` {
61
61
  margin-right: `).concat(a,"px ").concat(r,`;
62
62
  }
63
63
 
64
- .`).concat(Go," .").concat(Go,` {
64
+ .`).concat(Xo," .").concat(Xo,` {
65
65
  right: 0 `).concat(r,`;
66
66
  }
67
67
 
68
- .`).concat(Yo," .").concat(Yo,` {
68
+ .`).concat(Jo," .").concat(Jo,` {
69
69
  margin-right: 0 `).concat(r,`;
70
70
  }
71
71
 
72
- body[`).concat(mr,`] {
73
- `).concat(hv,": ").concat(a,`px;
72
+ body[`).concat(yr,`] {
73
+ `).concat(uv,": ").concat(a,`px;
74
74
  }
75
- `)},bu=function(){var e=parseInt(document.body.getAttribute(mr)||"0",10);return isFinite(e)?e:0},Mv=function(){v.useEffect(function(){return document.body.setAttribute(mr,(bu()+1).toString()),function(){var e=bu()-1;e<=0?document.body.removeAttribute(mr):document.body.setAttribute(mr,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")})},Ui=!1;if(typeof window<"u")try{var Jo=Object.defineProperty({},"passive",{get:function(){return Ui=!0,!0}});window.addEventListener("test",Jo,Jo),window.removeEventListener("test",Jo,Jo)}catch{Ui=!1}var gr=Ui?{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},Zo=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`
75
+ `)},gu=function(){var e=parseInt(document.body.getAttribute(yr)||"0",10);return isFinite(e)?e:0},Nv=function(){v.useEffect(function(){return document.body.setAttribute(yr,(gu()+1).toString()),function(){var e=gu()-1;e<=0?document.body.removeAttribute(yr):document.body.setAttribute(yr,e.toString())}},[])},_v=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Nv();var s=v.useMemo(function(){return Iv(o)},[o]);return v.createElement(Ev,{styles:Av(s,!t,o,n?"":"!important")})},Ui=!1;if(typeof window<"u")try{var Qo=Object.defineProperty({},"passive",{get:function(){return Ui=!0,!0}});window.addEventListener("test",Qo,Qo),window.removeEventListener("test",Qo,Qo)}catch{Ui=!1}var vr=Ui?{passive:!1}:!1,jv=function(e){return e.tagName==="TEXTAREA"},xu=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!jv(e)&&n[t]==="visible")},Rv=function(e){return xu(e,"overflowY")},Mv=function(e){return xu(e,"overflowX")},yu=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=vu(e,r);if(o){var s=bu(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Pv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Ov=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},vu=function(e,t){return e==="v"?Rv(t):Mv(t)},bu=function(e,t){return e==="v"?Pv(t):Ov(t)},Dv=function(e,t){return e==="h"&&t==="rtl"?-1:1},Lv=function(e,t,n,r,o){var s=Dv(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=bu(e,a),x=h[0],m=h[1],y=h[2],g=m-y-s*x;(x||g)&&vu(e,a)&&(f+=g,p+=x);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},es=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},wu=function(e){return[e.deltaX,e.deltaY]},Su=function(e){return e&&"current"in e?e.current:e},$v=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Fv=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},Wv=0,xr=[];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=Zo(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 _=r.current||C;return zv(_,y,m,_==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!xr.length||xr[xr.length-1]!==s)){var g="deltaY"in y?ku(y):Zo(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=Zo(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,Zo(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return xr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,gr),document.addEventListener("touchmove",l,gr),document.addEventListener("touchstart",d,gr),function(){xr=xr.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,gr),document.removeEventListener("touchmove",l,gr),document.removeEventListener("touchstart",d,gr)}},[]);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 Qo=v.forwardRef(function(e,t){return v.createElement(Xo,hn({},e,{ref:t,sideCar:qv}))});Qo.classNames=Xo.classNames;var Hi=["Enter"," "],Gv=["ArrowDown","PageUp","Home"],Eu=["ArrowUp","PageDown","End"],Yv=[...Gv,...Eu],Xv={ltr:[...Hi,"ArrowRight"],rtl:[...Hi,"ArrowLeft"]},Jv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Lr="Menu",[$r,Zv,Qv]=gi(Lr),[Kn,Au]=wn(Lr,[Qv,Ho,cu]),es=Ho(),Nu=cu(),[eb,qn]=Kn(Lr),[tb,Fr]=Kn(Lr),_u=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=es(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),p=_o(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=Lr;var nb="MenuAnchor",Wi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=es(n);return u.jsx(su,{...o,...r,ref:t})});Wi.displayName=nb;var Vi="MenuPortal",[rb,ju]=Kn(Vi,{forceMount:void 0}),Ru=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=qn(Vi,t);return u.jsx(rb,{scope:t,forceMount:n,children:u.jsx(Gt,{present:n||s.open,children:u.jsx(Wo,{asChild:!0,container:o,children:r})})})};Ru.displayName=Vi;var Yt="MenuContent",[ob,Ki]=Kn(Yt),Mu=v.forwardRef((e,t)=>{const n=ju(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=qn(Yt,e.__scopeMenu),i=Fr(Yt,e.__scopeMenu);return u.jsx($r.Provider,{scope:e.__scopeMenu,children:u.jsx(Gt,{present:r||s.open,children:u.jsx($r.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=qn(Yt,e.__scopeMenu),r=v.useRef(null),o=Be(t,r);return v.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(qi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ib=v.forwardRef((e,t)=>{const n=qn(Yt,e.__scopeMenu);return u.jsx(qi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),ab=zn.createSlot("MenuContent.ScrollLock"),qi=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=qn(Yt,n),g=Fr(Yt,n),b=es(n),S=Nu(n),k=Zv(n),[C,T]=v.useState(null),I=v.useRef(null),A=Be(t,I,y.onContentChange),_=v.useRef(0),L=v.useRef(""),M=v.useRef(0),P=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=x?Qo:v.Fragment,R=x?{as:ab,allowPinchZoom:!0}:void 0,Z=j=>{var G,$;const Y=L.current+j,J=k().filter(W=>!W.disabled),oe=document.activeElement,ye=(G=J.find(W=>W.ref.current===oe))==null?void 0:G.textValue,Re=J.map(W=>W.textValue),K=vb(Re,Y,ye),U=($=J.find(W=>W.textValue===K))==null?void 0:$.ref.current;(function W(Q){L.current=Q,window.clearTimeout(_.current),Q!==""&&(_.current=window.setTimeout(()=>W(""),1e3))})(Y),U&&setTimeout(()=>U.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),vi();const z=v.useCallback(j=>{var J,oe;return F.current===((J=P.current)==null?void 0:J.side)&&wb(j,(oe=P.current)==null?void 0:oe.area)},[]);return u.jsx(ob,{scope:n,searchRef:L,onItemEnter:v.useCallback(j=>{z(j)&&j.preventDefault()},[z]),onItemLeave:v.useCallback(j=>{var Y;z(j)||((Y=I.current)==null||Y.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(j=>{z(j)&&j.preventDefault()},[z]),pointerGraceTimerRef:M,onPointerGraceIntentChange:v.useCallback(j=>{P.current=j},[]),children:u.jsx(B,{...R,children:u.jsx(Ro,{asChild:!0,trapped:o,onMountAutoFocus:de(s,j=>{var Y;j.preventDefault(),(Y=I.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(jo,{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:de(l,j=>{g.isUsingKeyboardRef.current||j.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:de(m.onKeyDown,j=>{const J=j.target.closest("[data-radix-menu-content]")===j.currentTarget,oe=j.ctrlKey||j.altKey||j.metaKey,ye=j.key.length===1;J&&(j.key==="Tab"&&j.preventDefault(),!oe&&ye&&Z(j.key));const Re=I.current;if(j.target!==Re||!Yv.includes(j.key))return;j.preventDefault();const U=k().filter(G=>!G.disabled).map(G=>G.ref.current);Eu.includes(j.key)&&U.reverse(),xb(U)}),onBlur:de(e.onBlur,j=>{j.currentTarget.contains(j.target)||(window.clearTimeout(_.current),L.current="")}),onPointerMove:de(e.onPointerMove,zr(j=>{const Y=j.target,J=N.current!==j.clientX;if(j.currentTarget.contains(Y)&&J){const oe=j.clientX>N.current?"right":"left";F.current=oe,N.current=j.clientX}}))})})})})})})});Mu.displayName=Yt;var lb="MenuGroup",Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{role:"group",...r,ref:t})});Gi.displayName=lb;var cb="MenuLabel",Pu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.div,{...r,ref:t})});Pu.displayName=cb;var ts="MenuItem",Ou="menu.itemSelect",ns=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Fr(ts,e.__scopeMenu),a=Ki(ts,e.__scopeMenu),l=Be(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: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===" "||Hi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ns.displayName=ts;var Du=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ki(ts,n),a=Nu(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($r.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(lv,{asChild:!0,...a,focusable:!r,children:u.jsx(_e.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:de(e.onPointerMove,zr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,zr(x=>i.onItemLeave(x))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(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(ns,{role:"menuitemcheckbox","aria-checked":rs(n)?"mixed":n,...o,ref:t,"data-state":Xi(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(rs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Lu.displayName=ub;var $u="MenuRadioGroup",[db,fb]=Kn($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(Gi,{...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(ns,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Xi(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});zu.displayName=Bu;var Yi="MenuItemIndicator",[Uu,pb]=Kn(Yi,{checked:!1}),Hu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=pb(Yi,n);return u.jsx(Gt,{present:r||rs(s.checked)||s.checked===!0,children:u.jsx(_e.span,{...o,ref:t,"data-state":Xi(s.checked)})})});Hu.displayName=Yi;var hb="MenuSeparator",Wu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(_e.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=es(n);return u.jsx(au,{...o,...r,ref:t})});Vu.displayName=mb;var gb="MenuSub",[$T,Ku]=Kn(gb),Br="MenuSubTrigger",qu=v.forwardRef((e,t)=>{const n=qn(Br,e.__scopeMenu),r=Fr(Br,e.__scopeMenu),o=Ku(Br,e.__scopeMenu),s=Ki(Br,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(Wi,{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:mi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:de(e.onPointerMove,zr(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,zr(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===" "||Xv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});qu.displayName=Br;var Gu="MenuSubContent",Yu=v.forwardRef((e,t)=>{const n=ju(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=qn(Yt,e.__scopeMenu),i=Fr(Yt,e.__scopeMenu),a=Ku(Gu,e.__scopeMenu),l=v.useRef(null),c=Be(t,l);return u.jsx($r.Provider,{scope:e.__scopeMenu,children:u.jsx(Gt,{present:r||s.open,children:u.jsx($r.Slot,{scope:e.__scopeMenu,children:u.jsx(qi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside: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=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 rs(e){return e==="indeterminate"}function Xi(e){return rs(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 zr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Sb=_u,Cb=Wi,Tb=Ru,kb=Mu,Ib=Gi,Eb=Pu,Ab=ns,Nb=Lu,_b=Fu,jb=zu,Rb=Hu,Mb=Wu,Pb=Vu,Ob=qu,Db=Yu,os="DropdownMenu",[Lb,FT]=wn(os,[Au]),Ot=Au(),[$b,Ju]=Lb(os),Zu=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]=cr({prop:o,defaultProp:s??!1,onChange:i,caller:os});return u.jsx($b,{scope:t,triggerId:Sn(),triggerRef:c,contentId:Sn(),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=os;var Qu="DropdownMenuTrigger",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ju(Qu,n),i=Ot(n);return u.jsx(Cb,{asChild:!0,...i,children:u.jsx(_e.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:mi(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())})})})});ed.displayName=Qu;var Fb="DropdownMenuPortal",td=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(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=Ot(n),i=v.useRef(!1);return u.jsx(kb,{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)"}})});rd.displayName=nd;var Bb="DropdownMenuGroup",zb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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=Ot(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: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(se.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: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}));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:te("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));wd.displayName=fd.displayName;const Ji=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(hd,{ref:r,className:te("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ji.displayName=hd.displayName;const aw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(md,{ref:o,className:te("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(se.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:te("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(se.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:te("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:te("-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 ss(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=>ss(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=ss(r.metadata,"step"),i=ss(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=ss(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 is=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,`
78
+ `)},Bv=0,br=[];function zv(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(Bv++)[0],s=v.useState(mu)[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=lv([e.lockRef.current],(e.shards||[]).map(Su),!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=es(m),b=n.current,S="deltaX"in m?m.deltaX:b[0]-g[0],k="deltaY"in m?m.deltaY:b[1]-g[1],C,T=m.target,I=Math.abs(S)>Math.abs(k)?"h":"v";if("touches"in m&&I==="h"&&T.type==="range")return!1;var A=yu(I,T);if(!A)return!0;if(A?C=I:(C=I==="v"?"h":"v",A=yu(I,T)),!A)return!1;if(!r.current&&"changedTouches"in m&&(S||k)&&(r.current=C),!C)return!0;var j=r.current||C;return Lv(j,y,m,j==="h"?S:k)},[]),l=v.useCallback(function(m){var y=m;if(!(!br.length||br[br.length-1]!==s)){var g="deltaY"in y?wu(y):es(y),b=t.current.filter(function(C){return C.name===y.type&&(C.target===y.target||y.target===C.shadowParent)&&$v(C.delta,g)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Su).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:Uv(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=es(m),r.current=void 0},[]),f=v.useCallback(function(m){c(m.type,wu(m),m.target,a(m,e.lockRef.current))},[]),p=v.useCallback(function(m){c(m.type,es(m),m.target,a(m,e.lockRef.current))},[]);v.useEffect(function(){return br.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,vr),document.addEventListener("touchmove",l,vr),document.addEventListener("touchstart",d,vr),function(){br=br.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,vr),document.removeEventListener("touchmove",l,vr),document.removeEventListener("touchstart",d,vr)}},[]);var h=e.removeScrollBar,x=e.inert;return v.createElement(v.Fragment,null,x?v.createElement(s,{styles:Fv(o)}):null,h?v.createElement(_v,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Uv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Hv=xv(hu,zv);var ts=v.forwardRef(function(e,t){return v.createElement(Zo,hn({},e,{ref:t,sideCar:Hv}))});ts.classNames=Zo.classNames;var Hi=["Enter"," "],Wv=["ArrowDown","PageUp","Home"],Cu=["ArrowUp","PageDown","End"],Vv=[...Wv,...Cu],Kv={ltr:[...Hi,"ArrowRight"],rtl:[...Hi,"ArrowLeft"]},qv={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Br="Menu",[zr,Gv,Yv]=gi(Br),[Yn,Tu]=wn(Br,[Yv,Vo,su]),ns=Vo(),ku=su(),[Xv,Xn]=Yn(Br),[Jv,Ur]=Yn(Br),Iu=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ns(t),[l,c]=v.useState(null),d=v.useRef(!1),f=kt(s),p=Ro(o);return v.useEffect(()=>{const h=()=>{d.current=!0,document.addEventListener("pointerdown",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(eu,{...a,children:u.jsx(Xv,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(Jv,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};Iu.displayName=Br;var Zv="MenuAnchor",Wi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ns(n);return u.jsx(tu,{...o,...r,ref:t})});Wi.displayName=Zv;var Vi="MenuPortal",[Qv,Eu]=Yn(Vi,{forceMount:void 0}),Au=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Xn(Vi,t);return u.jsx(Qv,{scope:t,forceMount:n,children:u.jsx(Gt,{present:n||s.open,children:u.jsx(Ko,{asChild:!0,container:o,children:r})})})};Au.displayName=Vi;var Yt="MenuContent",[eb,Ki]=Yn(Yt),Nu=v.forwardRef((e,t)=>{const n=Eu(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Yt,e.__scopeMenu),i=Ur(Yt,e.__scopeMenu);return u.jsx(zr.Provider,{scope:e.__scopeMenu,children:u.jsx(Gt,{present:r||s.open,children:u.jsx(zr.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(tb,{...o,ref:t}):u.jsx(nb,{...o,ref:t})})})})}),tb=v.forwardRef((e,t)=>{const n=Xn(Yt,e.__scopeMenu),r=v.useRef(null),o=Fe(t,r);return v.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(qi,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:de(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),nb=v.forwardRef((e,t)=>{const n=Xn(Yt,e.__scopeMenu);return u.jsx(qi,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),rb=Wn.createSlot("MenuContent.ScrollLock"),qi=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=Xn(Yt,n),g=Ur(Yt,n),b=ns(n),S=ku(n),k=Gv(n),[C,T]=v.useState(null),I=v.useRef(null),A=Fe(t,I,y.onContentChange),j=v.useRef(0),L=v.useRef(""),M=v.useRef(0),P=v.useRef(null),F=v.useRef("right"),N=v.useRef(0),B=x?ts:v.Fragment,R=x?{as:rb,allowPinchZoom:!0}:void 0,J=_=>{var G,$;const Y=L.current+_,X=k().filter(q=>!q.disabled),se=document.activeElement,ye=(G=X.find(q=>q.ref.current===se))==null?void 0:G.textValue,Re=X.map(q=>q.textValue),K=mb(Re,Y,ye),H=($=X.find(q=>q.textValue===K))==null?void 0:$.ref.current;(function q(Z){L.current=Z,window.clearTimeout(j.current),Z!==""&&(j.current=window.setTimeout(()=>q(""),1e3))})(Y),H&&setTimeout(()=>H.focus())};v.useEffect(()=>()=>window.clearTimeout(j.current),[]),vi();const z=v.useCallback(_=>{var X,se;return F.current===((X=P.current)==null?void 0:X.side)&&xb(_,(se=P.current)==null?void 0:se.area)},[]);return u.jsx(eb,{scope:n,searchRef:L,onItemEnter:v.useCallback(_=>{z(_)&&_.preventDefault()},[z]),onItemLeave:v.useCallback(_=>{var Y;z(_)||((Y=I.current)==null||Y.focus(),T(null))},[z]),onTriggerLeave:v.useCallback(_=>{z(_)&&_.preventDefault()},[z]),pointerGraceTimerRef:M,onPointerGraceIntentChange:v.useCallback(_=>{P.current=_},[]),children:u.jsx(B,{...R,children:u.jsx(Po,{asChild:!0,trapped:o,onMountAutoFocus:de(s,_=>{var Y;_.preventDefault(),(Y=I.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Mo,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:h,children:u.jsx(rv,{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(nu,{role:"menu","aria-orientation":"vertical","data-state":Ku(y.open),"data-radix-menu-content":"",dir:g.dir,...b,...m,ref:A,style:{outline:"none",...m.style},onKeyDown:de(m.onKeyDown,_=>{const X=_.target.closest("[data-radix-menu-content]")===_.currentTarget,se=_.ctrlKey||_.altKey||_.metaKey,ye=_.key.length===1;X&&(_.key==="Tab"&&_.preventDefault(),!se&&ye&&J(_.key));const Re=I.current;if(_.target!==Re||!Vv.includes(_.key))return;_.preventDefault();const H=k().filter(G=>!G.disabled).map(G=>G.ref.current);Cu.includes(_.key)&&H.reverse(),pb(H)}),onBlur:de(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(j.current),L.current="")}),onPointerMove:de(e.onPointerMove,Wr(_=>{const Y=_.target,X=N.current!==_.clientX;if(_.currentTarget.contains(Y)&&X){const se=_.clientX>N.current?"right":"left";F.current=se,N.current=_.clientX}}))})})})})})})});Nu.displayName=Yt;var ob="MenuGroup",Gi=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"group",...r,ref:t})});Gi.displayName=ob;var sb="MenuLabel",_u=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{...r,ref:t})});_u.displayName=sb;var rs="MenuItem",ju="menu.itemSelect",os=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Ur(rs,e.__scopeMenu),a=Ki(rs,e.__scopeMenu),l=Fe(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const p=new CustomEvent(ju,{bubbles:!0,cancelable:!0});f.addEventListener(ju,h=>r==null?void 0:r(h),{once:!0}),uc(f,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(Ru,{...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===" "||Hi.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});os.displayName=rs;var Ru=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ki(rs,n),a=ku(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(zr.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:u.jsx(ov,{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:de(e.onPointerMove,Wr(x=>{r?i.onItemLeave(x):(i.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:de(e.onPointerLeave,Wr(x=>i.onItemLeave(x))),onFocus:de(e.onFocus,()=>f(!0)),onBlur:de(e.onBlur,()=>f(!1))})})})}),ib="MenuCheckboxItem",Mu=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx($u,{scope:e.__scopeMenu,checked:n,children:u.jsx(os,{role:"menuitemcheckbox","aria-checked":ss(n)?"mixed":n,...o,ref:t,"data-state":Xi(n),onSelect:de(o.onSelect,()=>r==null?void 0:r(ss(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Mu.displayName=ib;var Pu="MenuRadioGroup",[ab,lb]=Yn(Pu,{value:void 0,onValueChange:()=>{}}),Ou=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return u.jsx(ab,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Gi,{...o,ref:t})})});Ou.displayName=Pu;var Du="MenuRadioItem",Lu=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=lb(Du,e.__scopeMenu),s=n===o.value;return u.jsx($u,{scope:e.__scopeMenu,checked:s,children:u.jsx(os,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Xi(s),onSelect:de(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Lu.displayName=Du;var Yi="MenuItemIndicator",[$u,cb]=Yn(Yi,{checked:!1}),Fu=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=cb(Yi,n);return u.jsx(Gt,{present:r||ss(s.checked)||s.checked===!0,children:u.jsx(Ne.span,{...o,ref:t,"data-state":Xi(s.checked)})})});Fu.displayName=Yi;var ub="MenuSeparator",Bu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Bu.displayName=ub;var db="MenuArrow",zu=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ns(n);return u.jsx(ru,{...o,...r,ref:t})});zu.displayName=db;var fb="MenuSub",[PT,Uu]=Yn(fb),Hr="MenuSubTrigger",Hu=v.forwardRef((e,t)=>{const n=Xn(Hr,e.__scopeMenu),r=Ur(Hr,e.__scopeMenu),o=Uu(Hr,e.__scopeMenu),s=Ki(Hr,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(Wi,{asChild:!0,...c,children:u.jsx(Ru,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Ku(n.open),...e,ref:mi(t,o.onTriggerChange),onClick:f=>{var p;(p=e.onClick)==null||p.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:de(e.onPointerMove,Wr(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,Wr(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===" "||Kv[r.dir].includes(f.key)&&(n.onOpenChange(!0),(h=n.content)==null||h.focus(),f.preventDefault())})})})});Hu.displayName=Hr;var Wu="MenuSubContent",Vu=v.forwardRef((e,t)=>{const n=Eu(Yt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Xn(Yt,e.__scopeMenu),i=Ur(Yt,e.__scopeMenu),a=Uu(Wu,e.__scopeMenu),l=v.useRef(null),c=Fe(t,l);return u.jsx(zr.Provider,{scope:e.__scopeMenu,children:u.jsx(Gt,{present:r||s.open,children:u.jsx(zr.Slot,{scope:e.__scopeMenu,children:u.jsx(qi,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside: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=qv[i.dir].includes(d.key);f&&p&&(s.onOpenChange(!1),(h=a.trigger)==null||h.focus(),d.preventDefault())})})})})})});Vu.displayName=Wu;function Ku(e){return e?"open":"closed"}function ss(e){return e==="indeterminate"}function Xi(e){return ss(e)?"indeterminate":e?"checked":"unchecked"}function pb(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function hb(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function mb(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=hb(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 gb(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 xb(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return gb(n,t)}function Wr(e){return t=>t.pointerType==="mouse"?e(t):void 0}var yb=Iu,vb=Wi,bb=Au,wb=Nu,Sb=Gi,Cb=_u,Tb=os,kb=Mu,Ib=Ou,Eb=Lu,Ab=Fu,Nb=Bu,_b=zu,jb=Hu,Rb=Vu,is="DropdownMenu",[Mb,OT]=wn(is,[Tu]),Ot=Tu(),[Pb,qu]=Mb(is),Gu=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]=fr({prop:o,defaultProp:s??!1,onChange:i,caller:is});return u.jsx(Pb,{scope:t,triggerId:Sn(),triggerRef:c,contentId:Sn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(p=>!p),[f]),modal:a,children:u.jsx(yb,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Gu.displayName=is;var Yu="DropdownMenuTrigger",Xu=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=qu(Yu,n),i=Ot(n);return u.jsx(vb,{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:mi(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())})})})});Xu.displayName=Yu;var Ob="DropdownMenuPortal",Ju=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return u.jsx(bb,{...r,...n})};Ju.displayName=Ob;var Zu="DropdownMenuContent",Qu=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=qu(Zu,n),s=Ot(n),i=v.useRef(!1);return u.jsx(wb,{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)"}})});Qu.displayName=Zu;var Db="DropdownMenuGroup",Lb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Sb,{...o,...r,ref:t})});Lb.displayName=Db;var $b="DropdownMenuLabel",ed=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Cb,{...o,...r,ref:t})});ed.displayName=$b;var Fb="DropdownMenuItem",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="DropdownMenuCheckboxItem",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="DropdownMenuRadioGroup",Ub=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Ib,{...o,...r,ref:t})});Ub.displayName=zb;var Hb="DropdownMenuRadioItem",rd=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Eb,{...o,...r,ref:t})});rd.displayName=Hb;var Wb="DropdownMenuItemIndicator",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="DropdownMenuSeparator",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="DropdownMenuArrow",qb=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(_b,{...o,...r,ref:t})});qb.displayName=Kb;var Gb="DropdownMenuSubTrigger",id=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(jb,{...o,...r,ref:t})});id.displayName=Gb;var Yb="DropdownMenuSubContent",ad=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return u.jsx(Rb,{...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)"}})});ad.displayName=Yb;var Xb=Gu,Jb=Xu,Zb=Ju,ld=Qu,cd=ed,ud=td,dd=nd,fd=rd,pd=od,hd=sd,md=id,gd=ad;const Qb=Xb,ew=Jb,tw=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(md,{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"})]}));tw.displayName=md.displayName;const nw=v.forwardRef(({className:e,...t},n)=>u.jsx(gd,{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}));nw.displayName=gd.displayName;const xd=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Zb,{children:u.jsx(ld,{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})}));xd.displayName=ld.displayName;const Ji=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:te("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ji.displayName=ud.displayName;const rw=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(dd,{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(pd,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),t]}));rw.displayName=dd.displayName;const ow=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(fd,{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(pd,{children:u.jsx(ae.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));ow.displayName=fd.displayName;const sw=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(cd,{ref:r,className:te("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));sw.displayName=cd.displayName;const iw=v.forwardRef(({className:e,...t},n)=>u.jsx(hd,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));iw.displayName=hd.displayName;function aw(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 lw(e){console.log("[attemptDetection] buildAttemptMetadataMap called with",e.length,"checkpoints");const t=new Map,n=aw(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 cw(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 as(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="number"?n:null}function uw(e,t){if(!e||typeof e!="object")return null;const n=e[t];return typeof n=="string"&&n.trim()?n:null}function dw(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 fw(e){const t=Array.isArray(e)?e.map(r=>{const o=dw(r.next);return o?{...r,metadata:{...r.metadata??{},next:o}}:r}):[];return t.some(r=>as(r.metadata,"step")!==null)&&t.sort((r,o)=>{const s=as(r.metadata,"step"),i=as(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 pw(e){const t=w.useMemo(()=>fw(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=as(f.metadata,"step"),x=uw(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=lw(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=cw(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 ls=1e4;function hw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
79
79
  `).replace(/<p>(.*?)<\/p>/gi,`$1
80
80
 
81
81
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
@@ -83,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 vw(e,t=is){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 as=0,_n=1,yr=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 Zi(e){return e!==void 0}function Cw(...e){return()=>{e.map(ww)}}function vr(){}function ls(e,t){return t(e),e}function Tw(e,t){return t(e)}function lt(...e){return e}function Ze(e,t){return e(_n,t)}function Me(e,t){e(as,t)}function Qi(e){e(yr)}function vt(e){return e(Sd)}function he(e,t){return Ze(e,Sw(t,as))}function rn(e,t){const n=e(_n,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 Ee(e){return t=>n=>{e(n)&&t(n)}}function ce(e){return t=>Td(t,e)}function mn(e){return t=>()=>{t(e)}}function H(e,...t){const n=kw(...t);return(r,o)=>{switch(r){case yr:Qi(e);return;case _n:return Ze(e,n(o))}}}function gn(e,t){return n=>r=>{n(t=e(t,r))}}function Gn(e){return t=>n=>{e>0?e--:t(n)}}function kn(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);Ze(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function 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 _n:return s?n===s?void 0:(r(),n=s,t=Ze(e,s),t):(r(),vr);case yr:r(),n=null;return}}}function ee(e){let t=e;const n=ze();return(r,o)=>{switch(r){case as:t=o;break;case _n:{o(t);break}case Sd:return t}return n(r,o)}}function Nt(e,t){return ls(ee(t),n=>he(e,n))}function ze(){const e=[];return(t,n)=>{switch(t){case as:e.slice().forEach(r=>{r(n)});return;case yr:e.splice(0,e.length);return;case _n:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return ls(ze(),t=>he(e,t))}function Ve(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 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);Ze(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case yr:{Qi(t);return}case _n:return r===o&&i(n),Ze(t,i)}}}function Se(e,t=Ed){return H(e,ct(t))}function ea(...e){return function(t,n){switch(t){case yr:return;case _n:return Cw(...e.map(r=>Ze(r,n)))}}}var Bt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Bt||{});const Nw={0:"debug",3:"error",1:"log",2:"warn"},_w=()=>typeof globalThis>"u"?window:globalThis,jn=Ve(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=_w().VIRTUOSO_LOG_LEVEL)!=null?o:vt(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 Yn(e,t,n){return ta(e,t,n).callbackRef}function ta(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function 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 ta(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},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 Ad(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 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}=ta(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=Ve(()=>{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,ce(({scrollTop:y})=>y)),t),he(H(e,ce(({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}),Ur={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 ot(e){return e===Ur}function Hr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?Hr(e.l,t):Hr(e.r,t)}function on(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=on(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return on(e.l,t,n)}function Wt(e,t,n){return ot(e)?Md(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?Pd(Ct(e,{l:Wt(e.l,t,n)})):Pd(Ct(e,{r:Wt(e.r,t,n)}))}function br(){return Ur}function cs(e,t,n){if(ot(e))return[];const r=on(e,t)[0];return Mw(ra(e,r,n))}function na(e,t){if(ot(e))return Ur;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Rd(r);return us(Ct(e,{k:s,l:jd(r),v:i}))}}else return t<n?us(Ct(e,{l:na(r,t)})):us(Ct(e,{r:na(o,t)}))}function Xn(e){return ot(e)?[]:[...Xn(e.l),{k:e.k,v:e.v},...Xn(e.r)]}function ra(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ra(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ra(s,t,n))),a}function us(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(oa(t))return Od(Ct(e,{lvl:n-1}));if(!ot(t)&&!ot(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(oa(e))return sa(Ct(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=oa(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:sa(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 ot(e.r)?e.l:us(Ct(e,{r:jd(e.r)}))}function oa(e){return ot(e)||e.lvl>e.r.lvl}function Rd(e){return ot(e.r)?[e.k,e.v]:Rd(e.r)}function Md(e,t,n,r=Ur,o=Ur){return{k:e,l:r,lvl:n,r:o,v:t}}function Pd(e){return sa(Od(e))}function Od(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function sa(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(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 Wr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ia=Ve(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Ld(e,t,n){return e[ds(e,t,n)]}function ds(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=ds(e,t,r),s=ds(e,n,r,o);return e.slice(o,s+1)}function Rn(e,t){return Math.round(e.getBoundingClientRect()[t])}function fs(e){return!ot(e.groupOffsetTree)}function aa({index:e},t){return t===e?0:t<e?-1:1}function Ow(){return{groupIndices:[],groupOffsetTree:br(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:br()}}function Dw(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Wt(e,0,s);continue}const a=cs(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=na(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 Lw(e){return typeof e.groupIndex<"u"}function $w({offset:e},t){return t===e?0:t<e?-1:1}function Vr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Ld(t,e,aa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function $d(e,t){if(!fs(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,aa).offset)),_d(Pw(e,t,n,$w),Uw)}function Bw(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&&ot(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]=Dw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=la(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Wt(p,h,Vr(h,f,o)),br()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function zw(e){return Xn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function Bd(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function la(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ds(o,t-1,aa),a=o[l].offset;const c=on(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===on(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of cs(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"},xn=Ve(([{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)=>Rn(C,Ww[T])),p=ee(void 0),h=ee(0),x=Ow(),m=Nt(H(n,Oe(l,e,h),gn(Bw,x),ct()),x),y=Nt(H(l,ct(),gn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ce(({prev:C})=>C)),[]);he(H(l,Ee(C=>C.length>0),Oe(m,h),ce(([C,T,I])=>{const A=C.reduce((_,L,M)=>Wt(_,L,Vr(L,T.offsetTree,I)||M),br());return{...T,groupIndices:C,groupOffsetTree:A}})),m),he(H(r,Oe(m),Ee(([C,{lastIndex:T}])=>C<T),ce(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const g=Nt(H(c,ce(C=>C===void 0)),!0);he(H(d,Ee(C=>C!==void 0&&ot(vt(m).sizeTree)),ce(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(H(n,Oe(m),gn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:x}),ce(C=>C.changed)));Ze(H(a,gn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ce(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Me(t,!0),Me(s,C+Bd(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=Bd(-C,I)),Me(i,C)}}),Ze(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),ce(([C,T])=>{const I=T.groupIndices.length>0,A=[],_=T.lastSize;if(I){const L=Hr(T.sizeTree,0);let M=0,P=0;for(;M<C;){const N=T.groupIndices[P],B=T.groupIndices.length===P+1?1/0:T.groupIndices[P+1]-N-1;A.push({endIndex:N,size:L,startIndex:N}),A.push({endIndex:N+1+B-1,size:_,startIndex:N+1}),P++,M+=B+1}const F=Xn(T.sizeTree);return M!==C&&F.shift(),F.reduce((N,{k:B,v:R})=>{let Z=N.ranges;return N.prevSize!==0&&(Z=[...N.ranges,{endIndex:B+C-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+C,prevSize:R,ranges:Z}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Xn(T.sizeTree).reduce((L,{k:M,v:P})=>({prevIndex:M+C,prevSize:P,ranges:[...L.ranges,{endIndex:M+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const k=Ht(H(i,Oe(m,h),ce(([C,{offsetTree:T},I])=>{const A=-C;return Vr(A,T,I)})));return he(H(i,Oe(m,h),ce(([C,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=br();const _=vt(y);let L=0,M=0,P=0;for(;L<-C;){P=_[M];const F=_[M+1]-P-1;M++,L+=F+1}if(A=Xn(T.sizeTree).reduce((F,{k:N,v:B})=>Wt(F,Math.max(0,N+C),B),A),L!==-C){const F=Hr(T.sizeTree,P);A=Wt(A,0,F);const N=on(T.sizeTree,-C+1)[1];A=Wt(A,1,N)}return{...T,sizeTree:A,...la(T.offsetTree,0,A,I)}}else{const A=Xn(T.sizeTree).reduce((_,{k:L,v:M})=>Wt(_,Math.max(0,L+C),M),br());return{...T,sizeTree:A,...la(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(jn,ia),{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=Ve(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=ze(),i=ze(),a=Ht(H(s,ce(Vw)));return he(H(a,ce(l=>l.totalCount)),n),he(H(a,ce(l=>l.groupIndices)),e),he(H(wt(o,t,r),Ee(([l,c])=>fs(c)),ce(([l,c,d])=>on(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ct(),ce(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},lt(xn,Dt)),Mn=Ve(([{log:e}])=>{const t=ee(!1),n=Ht(H(t,Ee(r=>r),ct()));return Ze(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},lt(jn),{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 Kr=Ve(([{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),Me(l,!1)}return he(H(h,Oe(n,f,r,m,a,i,p),Oe(e,s,o),ce(([[k,C,T,I,A,_,L,M],P,F,N])=>{const B=Ud(k),{align:R,behavior:Z,offset:z}=B,j=I-1,Y=Fd(B,C,j);let J=Vr(Y,C.offsetTree,P)+_;R==="end"?(J+=F+on(C.sizeTree,Y)[1]-T+N,Y===j&&(J+=L)):R==="center"?J+=(F+on(C.sizeTree,Y)[1]-T+N)/2:J-=A,z&&(J+=z);const oe=ye=>{S(),ye?(M("retrying to scroll to",{location:k},Bt.DEBUG),Me(h,k)):(Me(x,!0),M("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),Z==="smooth"){let ye=!1;b=Ze(t,Re=>{ye=ye||Re}),y=rn(d,()=>{oe(ye)})}else y=rn(H(t,qw(150)),oe);return g=setTimeout(()=>{S()},1200),Me(l,!0),M("scrolling from index to",{behavior:Z,index:Y,top:J},Bt.DEBUG),{behavior:Z,top:J}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},lt(xn,Dt,jn),{singleton:!0});function qw(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ca(e,t){e==0?t():requestAnimationFrame(()=>{ca(e-1,t)})}function ua(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const qr=Ve(([{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),Ee(([d,f])=>!!f),mn(!1)),a),he(H(i,Oe(l),Ee(([d,f])=>!!f),mn(!1)),c),Ze(H(wt(t,i),Oe(a,n,e,c),Ee(([[,d],f,{sizeTree:p},h,x])=>d&&(!ot(p)||Zi(h))&&!f&&!x),Oe(l)),([,d])=>{rn(o,()=>{Me(c,!0)}),ca(4,()=>{rn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},lt(xn,Dt,Kr,Mn),{singleton:!0});function Hd(e,t){return Math.abs(e-t)<1.01}const Gr="up",Yr="down",Gw="none",Yw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Xw=0,Xr=Ve(([{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(Xw),p=Nt(H(ea(H(Se(o),Gn(1),mn(!0)),H(Se(o),Gn(1),mn(!1),Id(100))),ct()),!1),h=Nt(H(ea(H(n,mn(!0)),H(n,mn(!1),Id(200))),ct()),!1);he(H(wt(Se(o),Se(f)),ce(([b,S])=>b<=S),ct()),a),he(H(a,kn(50)),c);const x=Ht(H(wt(r,Se(s),Se(t),Se(e),Se(d)),gn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const _=k+C-S>-A,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(_){let P,F;return k>b.state.scrollTop?(P="SCROLLED_DOWN",F=b.state.scrollTop-k):(P="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:P,scrollTopDelta:F,state:L}}let M;return L.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:L}},Yw),ct((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(H(r,gn((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}),Ee(b=>b.changed),ce(b=>b.jump)),0);he(H(x,ce(b=>b.atBottom)),i),he(H(i,kn(50)),l);const y=ee(Yr);he(H(r,ce(({scrollTop:b})=>b),ct(),gn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Gr:Yr,prevScrollTop:S},{direction:Yr,prevScrollTop:0}),ce(b=>b.direction)),y),he(H(r,kn(50),mn(Gw)),y);const g=ee(0);return he(H(p,Ee(b=>!b),mn(0)),g),he(H(o,kn(100),Oe(p),Ee(([b,S])=>!!S),gn(([b,S],[k])=>[S,k],[0,0]),ce(([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(Dt)),ps="top",hs="bottom",Wd="none";function Vd(e,t,n){return typeof e=="number"?n===Gr&&t===ps||n===Yr&&t===hs?e:0:n===Gr?t===ps?e.main:e.reverse:t===hs?e.main:e.reverse}function Kd(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const da=Ve(([{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,Wr),Se(l),Se(i),Se(t),Se(e),Se(a)),ce(([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,ps),_=Kd(S,hs);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-A&&(I=Gr),x<d-T+f+_&&(I=Yr),I!==Wd?[Math.max(k-p-Vd(m,ps,I)-A,0),k-T-g+f+Vd(m,hs,I)+_]:null}),Ee(d=>d!=null),ct(Wr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},lt(Dt),{singleton:!0});function Jw(e,t,n){if(fs(t)){const r=$d(e,t);return[{index:on(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const fa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ms(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=ua(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ms(c,[],a,o,n,r)}function Gd(e,t,n){if(e.length===0)return[];if(!fs(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=cs(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 Jn=Ve(([{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,Wr),Se(o),Se(r),Se(c),d,Se(m),Se(t),Se(n),e),Ee(([T,I,,A,,,,,,,_])=>{const L=_&&_.length!==A;return T&&!I&&!L}),ce(([,,[T,I],A,_,L,M,P,F,N,B])=>{const R=_,{offsetTree:Z,sizeTree:z}=R,j=vt(y);if(A===0)return{...fa,totalCount:A};if(T===0&&I===0)return j===0?{...fa,totalCount:A}:qd(j,L,_,F,N,B||[]);if(ot(z))return j>0?null:ms(Jw(ua(L,A),R,B),[],A,N,R,F);const Y=[];if(P.length>0){const K=P[0],U=P[P.length-1];let G=0;for(const $ of cs(z,K,U)){const W=$.value,Q=Math.max($.start,K),le=Math.min($.end,U);for(let re=Q;re<=le;re++)Y.push({data:B==null?void 0:B[re],index:re,offset:G,size:W}),G+=W}}if(!M)return ms([],Y,A,N,R,F);const J=P.length>0?P[P.length-1]+1:0,oe=Fw(Z,T,I,J);if(oe.length===0)return null;const ye=A-1,Re=ls([],K=>{for(const U of oe){const G=U.value;let $=G.offset,W=U.start;const Q=G.size;if(G.offset<T){W+=Math.floor((T-G.offset+N)/(Q+N));const re=W-U.start;$+=re*Q+re*N}W<J&&($+=(J-W)*Q,W=J);const le=Math.min(U.end,ye);for(let re=W;re<=le&&!($>=I);re++)K.push({data:B==null?void 0:B[re],index:re,offset:$,size:Q}),$+=Q+N}});return ms(Re,Y,A,N,R,F)}),Ee(T=>T!==null),ct()),fa);he(H(e,Ee(Zi),ce(T=>T==null?void 0:T.length)),o),he(H(b,ce(T=>T.topListHeight)),f),he(f,a),he(H(b,ce(T=>[T.top,T.bottom])),i),he(H(b,ce(T=>T.items)),g);const S=Ht(H(b,Ee(({items:T})=>T.length>0),Oe(o,e),Ee(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ce(([,T,I])=>[T-1,I]),ct(Wr),ce(([T])=>T))),k=Ht(H(b,kn(200),Ee(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ce(({items:T})=>T[0].index),ct())),C=Ht(H(b,Ee(({items:T})=>T.length>0),ce(({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(xn,zd,da,qr,Kr,Xr,Mn,ia),{singleton:!0}),Yd=Ve(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=ze(),i=Nt(H(wt(n,e,r,t,o),ce(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(Se(i),s),{totalListHeight:i,totalListHeightChanged:s}},lt(Dt,Jn),{singleton:!0}),Zw=Ve(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(H(wt(n,e,t),Ee(([o])=>o),ce(([,o,s])=>Math.max(0,o-s)),kn(0),ct()),0);return{alignToBottom:n,paddingTopAddition:r}},lt(Dt,Yd),{singleton:!0}),Xd=Ve(()=>({context:ee(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=Ve(([{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),ce(([[f,p,h,x,m,y,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Qw,done:I,...A}=f,_=Fd(f,p,x-1),L=Vr(_,p.offsetTree,S)+m+y,M=L+on(p.sizeTree,_)[1],P=b+y,F=b+h-g,N=T({itemBottom:M,itemTop:L,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:P});return N?I&&rn(H(i,Ee(B=>!B),Gn(vt(i)?1:2)),I):I&&I(),N}),Ee(f=>f!==null)),c),{scrollIntoView:d}},lt(xn,Dt,Kr,Jn,jn),{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=Ve(([{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){Me(i,{align:"end",behavior:C,index:"LAST"})}Ze(H(wt(H(Se(t),Gn(1)),l),Oe(Se(x),s,a,f),ce(([[C,T],I,A,_,L])=>{let M=T&&_,P="auto";return M&&(P=e0(I,A||L),M=M&&!!P),{followOutputBehavior:P,shouldFollow:M,totalCount:C}}),Ee(({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=rn(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C),y=null})});function b(C){const T=rn(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)}Ze(H(wt(Se(x),t,c),Ee(([C,,T])=>C&&T),gn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ee(({refreshed:C})=>C),Oe(x,t)),([,C])=>{vt(a)&&b(C!==!1)}),Ze(m,()=>{b(vt(x)!==!1)}),Ze(wt(Se(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=ze();return he(ea(H(Se(r),ce(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),H(Se(t))),k),Ze(H(wt(H(k,Gn(1)),l),Oe(Se(S),a,f,p),ce(([[C,T],I,A,_,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:_}))),Ee(C=>!!C),kn(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=rn(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},lt(xn,Xr,Kr,qr,Mn,jn,Dt,Xd,Jd)),n0=Ve(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(H(a,Oe(s),Ee(([,l])=>l!==0),Oe(o,r,t,n,e),ce(([[,l],c,d,f,p,h=[]])=>qd(l,c,d,f,p,h))),i),{}),lt(xn,qr,Jn,Mn),{singleton:!0}),r0=Ve(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Ze(H(e,Oe(r),Ee(([,o])=>o!==0),ce(([,o])=>({top:o}))),o=>{rn(H(n,Gn(1),Ee(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},lt(Mn,Dt,Jn),{singleton:!0}),Qd=Ve(([{scrollVelocity:e}])=>{const t=ee(!1),n=ze(),r=ee(!1);return he(H(e,Oe(r,t,n),Ee(([o,s])=>!!s),ce(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ct()),t),Ze(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}},lt(Xr),{singleton:!0}),pa=Ve(([{scrollContainerState:e,scrollTo:t}])=>{const n=ze(),r=ze(),o=ze(),s=ee(!1),i=ee(void 0);return he(H(wt(n,r),ce(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(H(t,Oe(r),ce(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},lt(Dt)),o0=Ve(([{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),Ze(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,Ee(Zi),ce(s0)),o),he(H(s,Oe(d),Ee(([,h])=>h!==void 0),ct(),ce(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},lt(xn,Dt,qr,Mn,pa));function s0(e){return{align:"start",index:0,offset:e.scrollTop}}const i0=Ve(([{topItemsIndexes:e}])=>{const t=ee(0);return he(H(t,Ee(n=>n>=0),ce(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},lt(Jn));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=Ve(([{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),gn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const _=k+T;let L=0;return b===I&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||(L=_-S,L!==0&&(L+=A))),[L,C,I,_]},[0,[],0,0]),Ee(([g])=>g!==0),Oe(r,a,n,o,h,x),Ee(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Gr),ce(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Bt.DEBUG),g))));function y(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return Ze(H(m,Oe(e,s)),([g,b,S])=>{S&&a0()?Me(e,b-g):y(-g)}),Ze(H(wt(Nt(s,!1),e,x),Ee(([g,b,S])=>!g&&!S&&b!==0),ce(([g,b])=>b),kn(1)),y),he(H(f,ce(g=>({top:-g}))),t),Ze(H(c,Oe(p,d),ce(([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=Hr(k,0);let _=0,L=0;for(;_<g;){_++,I+=A;let M=b.length===L+1?1/0:b[L+1]-b[L]-1;_+M>g&&(I-=A,M=g-_+1),_+=M,I+=T(M),L++}return I}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(x,!1)})})}),{deviation:e}},lt(Dt,Xr,Jn,xn,jn,ia)),c0=Ve(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),lt(da,n0,Mn,Qd,Yd,r0,Zw,pa,Jd,jn,Xd)),tf=Ve(([{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},_])=>(he(k.rangeChanged,_.scrollSeekRangeChanged),he(H(_.windowViewportRect,ce(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,sizes:l,...y}),lt(xn,qr,Dt,o0,t0,Jn,Kr,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 gs=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&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,g[b])}for(const b of o)if(b in g){const S=y[t.optional[b]];Me(S,g[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((g,b)=>(g[b]=S=>{const k=y[t.methods[b]];Me(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(()=>ls(Aw(e),I=>{l(I,S)})),[C]=w.useState(kd(d,k));gs(()=>{for(const I of i)I in S&&Ze(C[I],S[I]);return()=>{Object.values(C).map(Qi)}},[S,C,k]),gs(()=>{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=>{Me(g[y],b)},[g,y])},h=y=>{const g=w.useContext(a)[y],b=w.useCallback(S=>Ze(g,S),[g]);return w.useSyncExternalStore(b,()=>vt(g),()=>vt(g))},x=y=>{const g=w.useContext(a)[y],[b,S]=w.useState(kd(vt,g));return gs(()=>Ze(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];gs(()=>Ze(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 ha(e){return"self"in e}function d0(e){return"body"in e}function af(e,t,n,r=vr,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)||ha(y)){const b=ha(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():qs.flushSync(g),a.current!==null&&(m===a.current||m<=0||m===h-x)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const x=p.behavior==="smooth";let m,y,g;ha(h)?(y=Math.max(Rn(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=Rn(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 ma="-webkit-sticky",lf="sticky",ga=ef(()=>{if(typeof document>"u")return lf;const e=document.createElement("div");return e.style.position=ma,e.style.position===ma?ma:lf});function xa(e){return e}const f0=Ve(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(xa),o=ee("div"),s=ee(vr),i=(a,l=null)=>Nt(H(n,ce(c=>c[a]),ct()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),p0=Ve(([e,t])=>({...e,...t}),lt(tf,f0)),h0=({height:e})=>u.jsx("div",{style:{height:e}}),m0={overflowAnchor:"none",position:ga(),zIndex:1},cf={overflowAnchor:"none"},g0={...cf,display:"inline-block",height:"100%"},uf=w.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=Xt("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=Xt("windowScrollContainerState"),i=Xt("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),c=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),p=Ne("itemSize"),h=Ne("log"),x=Xt("gap"),m=Ne("horizontalDirection"),{callbackRef:y}=jw(n,p,f,e?vr:a,h,x,o,m,Ne("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);ya("deviation",N=>{g!==N&&b(N)});const S=Ne("EmptyPlaceholder"),k=Ne("ScrollSeekPlaceholder")||h0,C=Ne("ListComponent"),T=Ne("ItemComponent"),I=Ne("GroupComponent"),A=Ne("computeItemKey"),_=Ne("isSeeking"),L=Ne("groupIndices").length>0,M=Ne("alignToBottom"),P=Ne("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:g!==0?g:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...P?{}:{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,R=A(B+t.firstItemIndex,N.data,c);return _?w.createElement(k,{..._t(k,c),height:N.size,index:N.index,key:R,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:R,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:R,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"},xs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),v0={position:ga(),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=Ne("HeaderComponent"),t=Xt("headerHeight"),n=Ne("HeaderFooterTag"),r=Yn(w.useMemo(()=>s=>{t(Rn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),S0=w.memo(function(){const e=Ne("FooterComponent"),t=Xt("footerHeight"),n=Ne("HeaderFooterTag"),r=Yn(w.useMemo(()=>s=>{t(Rn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("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=Xt("viewportHeight"),r=Xt("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=w.useMemo(()=>Td(n,l=>Rn(l,s?"width":"height")),[n,s]),a=Yn(i,!0,Ne("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:xs(o),children:e})},T0=({children:e})=>{const t=w.useContext(rf),n=Xt("windowViewportRect"),r=Xt("fixedItemHeight"),o=Ne("customScrollParent"),s=Nd(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:xs(i),children:e})},k0=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...v0,marginTop:`${n}px`},o=Ne("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},I0=w.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("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:ya,useEmitterValue:Ne,usePublisher:Xt}=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:ya,useEmitterValue:Ne,usePublisher:Xt}),N0=ff({useEmitter:ya,useEmitterValue:Ne,usePublisher:Xt}),_0=E0;lt(tf,Ve(()=>{const e=ee(c=>u.jsxs("td",{children:["Item $",c]})),t=ee(null),n=ee(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ee(null),o=ee(null),s=ee({}),i=ee(xa),a=ee(vr),l=(c,d=null)=>Nt(H(s,ce(f=>f[c]),ct()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),ga();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:ys,max:Jr,min:va,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 vs(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=Ve(([{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(pf),_=ee({height:0,width:0}),L=ee({height:0,width:0}),M=ze(),P=ze(),F=ee(0),N=ee(null),B=ee({column:0,row:0}),R=ze(),Z=ze(),z=ee(!1),j=ee(0),Y=ee(!0),J=ee(!1),oe=ee(!1);Ze(H(x,Oe(j),Ee(([$,W])=>!!W)),()=>{Me(Y,!1)}),Ze(H(wt(x,Y,L,_,j,J),Ee(([$,W,Q,le,,re])=>$&&!W&&Q.height!==0&&le.height!==0&&!re)),([,,,,$])=>{Me(J,!0),ca(1,()=>{Me(M,$)}),rn(H(c),()=>{Me(t,[0,0]),Me(Y,!0)})}),he(H(Z,Ee($=>$!=null&&$.scrollTop>0),mn(0)),I),Ze(H(x,Oe(Z),Ee(([,$])=>$!=null)),([,$])=>{$&&(Me(_,$.viewport),Me(L,$.item),Me(B,$.gap),$.scrollTop>0&&(Me(z,!0),rn(H(c,Gn(1)),W=>{Me(z,!1)}),Me(l,{top:$.scrollTop})))}),he(H(_,ce(({height:$})=>$)),f),he(H(wt(Se(_,vs),Se(L,vs),Se(B,($,W)=>$&&$.column===W.column&&$.row===W.row),Se(c)),ce(([$,W,Q,le])=>({gap:Q,item:W,scrollTop:le,viewport:$}))),R),he(H(wt(Se(T),r,Se(B,M0),Se(L,vs),Se(_,vs),Se(N),Se(I),Se(z),Se(Y),Se(j)),Ee(([,,,,,,,$])=>!$),ce(([$,[W,Q],le,re,Ae,Ue,De,,Ke,He])=>{const{column:fe,row:be}=le,{height:Pe,width:We}=re,{width:it}=Ae;if(De===0&&($===0||it===0))return pf;if(We===0){const Lt=ua(He,$),Mt=Lt+Math.max(De-1,0);return R0(gf(Lt,Mt,Ue))}const Ge=xf(it,We,fe);let Qe,at;Ke?W===0&&Q===0&&De>0?(Qe=0,at=De-1):(Qe=Ge*ys((W+be)/(Pe+be)),at=Ge*hf((Q+be)/(Pe+be))-1,at=va($-1,Jr(at,Ge-1)),Qe=va(at,Jr(0,Qe))):(Qe=0,at=-1);const Rt=gf(Qe,at,Ue),{bottom:gt,top:ht}=yf(Ae,le,re,Rt),bt=hf($/Ge),St=bt*Pe+(bt-1)*be-gt;return{bottom:gt,itemHeight:Pe,items:Rt,itemWidth:We,offsetBottom:St,offsetTop:ht,top:ht}})),A),he(H(N,Ee($=>$!==null),ce($=>$.length)),T),he(H(wt(_,L,A,B),Ee(([$,W,{items:Q}])=>Q.length>0&&W.height!==0&&$.height!==0),ce(([$,W,{items:Q},le])=>{const{bottom:re,top:Ae}=yf($,le,W,Q);return[Ae,re]}),ct(Wr)),t);const ye=ee(!1);he(H(c,Oe(ye),ce(([$,W])=>W||$!==0)),ye);const Re=Ht(H(wt(A,T),Ee(([{items:$}])=>$.length>0),Oe(ye),Ee(([[$,W],Q])=>{const le=$.items[$.items.length-1].index===W-1;return(Q||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===W)&&le}),ce(([[,$]])=>$-1),ct())),K=Ht(H(Se(A),Ee(({items:$})=>$.length>0&&$[0].index===0),mn(0),ct())),U=Ht(H(Se(A),Oe(z),Ee(([{items:$},W])=>$.length>0&&!W),ce(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ct(Dd),kn(0)));he(U,h.scrollSeekRangeChanged),he(H(M,Oe(_,L,T,B),ce(([$,W,Q,le,re])=>{const Ae=Ud($),{align:Ue,behavior:De,offset:Ke}=Ae;let He=Ae.index;He==="LAST"&&(He=le-1),He=Jr(0,He,va(le-1,He));let fe=ba(W,re,Q,He);return Ue==="end"?fe=mf(fe-W.height+Q.height):Ue==="center"&&(fe=mf(fe-W.height/2+Q.height/2)),Ke&&(fe+=Ke),{behavior:De,top:fe}})),l);const G=Nt(H(A,ce($=>$.offsetBottom+$.bottom)),0);return he(H(k,ce($=>({height:$.visibleHeight,width:$.visibleWidth}))),_),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:Z,scrollBy:i,scrollContainerState:a,scrollHeight:P,scrollTo:l,scrollToIndex:M,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:A,horizontalDirection:oe,initialTopMostItemIndex:j,totalListHeight:G,...p,endReached:Re,propsReady:m,rangeChanged:U,startReached:K,stateChanged:R,stateRestoreInProgress:z,...C}},lt(da,Dt,Xr,Qd,Mn,pa,jn));function xf(e,t,n){return Jr(1,ys((e+n)/(ys(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=ba(e,t,n,r[0].index);return{bottom:ba(e,t,n,r[r.length-1].index)+o,top:s}}function ba(e,t,n,r){const o=xf(e.width,n.width,t.column),s=ys(r/o),i=s*n.height+Jr(0,s-1)*t.row;return i>0?i+t.row:i}const O0=Ve(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(xa),i=ee("div"),a=ee(vr),l=(f,p=null)=>Nt(H(t,ce(h=>h[f]),ct()),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")}}),D0=Ve(([e,t])=>({...e,...t}),lt(P0,O0)),L0=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Jt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Jt("itemDimensions"),p=Jt("gap"),h=ft("log"),x=ft("stateRestoreInProgress"),m=Jt("reportReadyState"),y=Yn(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=ft("HeaderComponent"),t=Jt("headerHeight"),n=ft("headerFooterTag"),r=Yn(w.useMemo(()=>s=>{t(Rn(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),F0=w.memo(function(){const e=ft("FooterComponent"),t=Jt("footerHeight"),n=ft("headerFooterTag"),r=Yn(w.useMemo(()=>s=>{t(Rn(s,"height"))},[t]),!0,!1),o=ft("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=Jt("itemDimensions"),r=Jt("viewportDimensions"),o=Yn(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:xs(!1),children:e})},z0=({children:e})=>{const t=w.useContext(of),n=Jt("windowViewportRect"),r=Jt("itemDimensions"),o=ft("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:xs(!1),children:e})},U0=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?W0:H0,o=n||t?z0:B0,s=ft("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:ft,usePublisher:Jt}=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:ft,usePublisher:Jt}),W0=ff({useEmitter:vf,useEmitterValue:ft,usePublisher:Jt});function bf(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 V0=co.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function wf({className:e,variant:t,...n}){return u.jsx("div",{className:te(V0({variant:t}),e),...n})}function wa(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 Zr(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Zr).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=Zr(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 Qr(e){if(typeof e=="string")return e;if(Sf(e))return"";try{const t=Zr(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=Qr(e);return typeof e=="string"&&K0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function bs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=wa(t);if(n!==null)return bs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?bs(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 ws(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=Zr(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 Kt(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 Kt(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function nS(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Kt("/files",{params:r})}var Ss="Dialog",[Ef,zT]=wn(Ss),[rS,sn]=Ef(Ss),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]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:Ss});return u.jsx(rS,{scope:t,triggerRef:a,contentRef:l,contentId:Sn(),titleId:Sn(),descriptionId:Sn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Af.displayName=Ss;var Nf="DialogTrigger",_f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Nf,n),s=Be(t,o.triggerRef);return u.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ta(o.open),...r,ref:s,onClick:de(e.onClick,o.onOpenToggle)})});_f.displayName=Nf;var Sa="DialogPortal",[oS,jf]=Ef(Sa,{forceMount:void 0}),Rf=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=sn(Sa,t);return u.jsx(oS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Gt,{present:n||s.open,children:u.jsx(Wo,{asChild:!0,container:o,children:i})}))})};Rf.displayName=Sa;var Cs="DialogOverlay",Mf=v.forwardRef((e,t)=>{const n=jf(Cs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=sn(Cs,e.__scopeDialog);return s.modal?u.jsx(Gt,{present:r||s.open,children:u.jsx(iS,{...o,ref:t})}):null});Mf.displayName=Cs;var sS=zn.createSlot("DialogOverlay.RemoveScroll"),iS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Cs,n);return u.jsx(Qo,{as:sS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(_e.div,{"data-state":Ta(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Zn="DialogContent",Pf=v.forwardRef((e,t)=>{const n=jf(Zn,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=sn(Zn,e.__scopeDialog);return u.jsx(Gt,{present:r||s.open,children:s.modal?u.jsx(aS,{...o,ref:t}):u.jsx(lS,{...o,ref:t})})});Pf.displayName=Zn;var aS=v.forwardRef((e,t)=>{const n=sn(Zn,e.__scopeDialog),r=v.useRef(null),o=Be(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(Of,{...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())})}),lS=v.forwardRef((e,t)=>{const n=sn(Zn,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=sn(Zn,n),l=v.useRef(null),c=Be(t,l);return vi(),u.jsxs(u.Fragment,{children:[u.jsx(Ro,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(jo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ta(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})]})]})}),Ca="DialogTitle",Df=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Ca,n);return u.jsx(_e.h2,{id:o.titleId,...r,ref:t})});Df.displayName=Ca;var Lf="DialogDescription",$f=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Lf,n);return u.jsx(_e.p,{id:o.descriptionId,...r,ref:t})});$f.displayName=Lf;var Ff="DialogClose",Bf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Ff,n);return u.jsx(_e.button,{type:"button",...r,ref:t,onClick:de(e.onClick,()=>o.onOpenChange(!1))})});Bf.displayName=Ff;function Ta(e){return e?"open":"closed"}var zf="DialogTitleWarning",[UT,Uf]=sx(zf,{contentName:Zn,titleName:Ca,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.
86
+ `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function mw(e,t=ls){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function gw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),mw(t),hw(t)}const cs=0,Mn=1,wr=2,yd=4;function vd(e){return()=>e}function xw(e){e()}function bd(e,t){return n=>e(t(n))}function wd(e,t){return()=>e(t)}function yw(e,t){return n=>e(t,n)}function Zi(e){return e!==void 0}function vw(...e){return()=>{e.map(xw)}}function Sr(){}function us(e,t){return t(e),e}function bw(e,t){return t(e)}function ct(...e){return e}function Qe(e,t){return e(Mn,t)}function Me(e,t){e(cs,t)}function Qi(e){e(wr)}function vt(e){return e(yd)}function he(e,t){return Qe(e,yw(t,cs))}function rn(e,t){const n=e(Mn,r=>{n(),t(r)});return n}function Sd(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Cd(e,t){return e===t}function ut(e=Cd){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function ke(e){return t=>n=>{e(n)&&t(n)}}function ce(e){return t=>bd(t,e)}function mn(e){return t=>()=>{t(e)}}function V(e,...t){const n=ww(...t);return(r,o)=>{switch(r){case wr:Qi(e);return;case Mn:return Qe(e,n(o))}}}function gn(e,t){return n=>r=>{n(t=e(t,r))}}function Jn(e){return t=>n=>{e>0?e--:t(n)}}function kn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Oe(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Qe(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function ww(...e){return t=>e.reduceRight(bw,t)}function Sw(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Mn:return s?n===s?void 0:(r(),n=s,t=Qe(e,s),t):(r(),Sr);case wr:r(),n=null;return}}}function ee(e){let t=e;const n=Be();return(r,o)=>{switch(r){case cs:t=o;break;case Mn:{o(t);break}case yd:return t}return n(r,o)}}function Nt(e,t){return us(ee(t),n=>he(e,n))}function Be(){const e=[];return(t,n)=>{switch(t){case cs:e.slice().forEach(r=>{r(n)});return;case wr:e.splice(0,e.length);return;case Mn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return us(Be(),t=>he(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Cw(),singleton:n}}const Cw=()=>Symbol();function Tw(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function wt(...e){const t=Be(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Qe(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case wr:{Qi(t);return}case Mn:return r===o&&i(n),Qe(t,i)}}}function we(e,t=Cd){return V(e,ut(t))}function ea(...e){return function(t,n){switch(t){case wr:return;case Mn:return vw(...e.map(r=>Qe(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 kw={0:"debug",3:"error",1:"log",2:"warn"},Iw=()=>typeof globalThis>"u"?window:globalThis,Pn=qe(()=>{const e=ee(3);return{log:ee((t,n,r=1)=>{var o;const s=(o=Iw().VIRTUOSO_LOG_LEVEL)!=null?o:vt(e);r>=s&&console[kw[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Zn(e,t,n){return ta(e,t,n).callbackRef}function ta(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Ew(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Aw(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?Td("column-gap",getComputedStyle(d).columnGap,o):Td("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ta(c,n,l)}function Aw(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 Td(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 kd(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),d=c.width;let f,p;if(t){const h=t.getBoundingClientRect(),x=c.top-h.top;p=h.height-Math.max(0,x),f=x+t.scrollTop}else{const h=i.current.ownerDocument.defaultView;p=h.innerHeight-Math.max(0,c.top),f=c.top+h.scrollY}r.current={offsetTop:f,visibleHeight:p,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ta(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const Dt=qe(()=>{const e=Be(),t=Be(),n=ee(0),r=Be(),o=ee(0),s=Be(),i=Be(),a=ee(0),l=ee(0),c=ee(0),d=ee(0),f=Be(),p=Be(),h=ee(!1),x=ee(!1),m=ee(!1);return he(V(e,ce(({scrollTop:y})=>y)),t),he(V(e,ce(({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}),Vr={lvl:0};function Id(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Vr}function Kr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?Kr(e.l,t):Kr(e.r,t)}function on(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=on(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return on(e.l,t,n)}function Wt(e,t,n){return ot(e)?Nd(t,n,1):t===e.k?Ct(e,{k:t,v:n}):t<e.k?_d(Ct(e,{l:Wt(e.l,t,n)})):_d(Ct(e,{r:Wt(e.r,t,n)}))}function Cr(){return Vr}function ds(e,t,n){if(ot(e))return[];const r=on(e,t)[0];return Nw(ra(e,r,n))}function na(e,t){if(ot(e))return Vr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Ad(r);return fs(Ct(e,{k:s,l:Ed(r),v:i}))}}else return t<n?fs(Ct(e,{l:na(r,t)})):fs(Ct(e,{r:na(o,t)}))}function Qn(e){return ot(e)?[]:[...Qn(e.l),{k:e.k,v:e.v},...Qn(e.r)]}function ra(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(ra(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(ra(s,t,n))),a}function fs(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(oa(t))return jd(Ct(e,{lvl:n-1}));if(!ot(t)&&!ot(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(oa(e))return sa(Ct(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=oa(o)?r.lvl-1:r.lvl;return Ct(o,{l:Ct(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:sa(Ct(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ct(e,t){return Nd(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 Ed(e){return ot(e.r)?e.l:fs(Ct(e,{r:Ed(e.r)}))}function oa(e){return ot(e)||e.lvl>e.r.lvl}function Ad(e){return ot(e.r)?[e.k,e.v]:Ad(e.r)}function Nd(e,t,n,r=Vr,o=Vr){return{k:e,l:r,lvl:n,r:o,v:t}}function _d(e){return sa(jd(e))}function jd(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?Ct(t,{r:Ct(e,{l:t.r})}):e}function sa(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?Ct(n,{l:Ct(e,{r:n.l}),lvl:t+1}):e}function Nw(e){return Id(e,({k:t,v:n})=>({index:t,value:n}))}function Rd(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function qr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ia=qe(()=>({recalcInProgress:ee(!1)}),[],{singleton:!0});function Md(e,t,n){return e[ps(e,t,n)]}function ps(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function _w(e,t,n,r){const o=ps(e,t,r),s=ps(e,n,r,o);return e.slice(o,s+1)}function On(e,t){return Math.round(e.getBoundingClientRect()[t])}function hs(e){return!ot(e.groupOffsetTree)}function aa({index:e},t){return t===e?0:t<e?-1:1}function jw(){return{groupIndices:[],groupOffsetTree:Cr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Cr()}}function Rw(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Wt(e,0,s);continue}const a=ds(e,i-1,o+1);if(a.some(Fw(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:p}of a)l?(o>=f||s===p)&&(e=na(e,f)):(c=p!==s,l=!0),d>o&&o>=f&&p!==s&&(e=Wt(e,o+1,p));c&&(e=Wt(e,i,s))}return[e,n]}function Mw(e){return typeof e.groupIndex<"u"}function Pw({offset:e},t){return t===e?0:t<e?-1:1}function Gr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=Md(t,e,aa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Pd(e,t){if(!hs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Od(e,t,n){if(Mw(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Pd(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Ow(e,t,n,r=0){return r>0&&(t=Math.max(t,Md(e,r,aa).offset)),Id(_w(e,t,n,Pw),$w)}function Dw(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&&ot(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]=Rw(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=la(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((p,h)=>Wt(p,h,Gr(h,f,o)),Cr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Lw(e){return Qn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function Dd(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function la(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ps(o,t-1,aa),a=o[l].offset;const c=on(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===on(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ds(n,t,1/0)){const f=c-s,p=f*i+a+f*r;o.push({index:c,offset:p,size:d}),s=c,a=p,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function $w(e){return{index:e.index,value:e}}function Fw(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const Bw={offsetHeight:"height",offsetWidth:"width"},xn=qe(([{log:e},{recalcInProgress:t}])=>{const n=Be(),r=Be(),o=Nt(r,0),s=Be(),i=Be(),a=ee(0),l=ee([]),c=ee(void 0),d=ee(void 0),f=ee((C,T)=>On(C,Bw[T])),p=ee(void 0),h=ee(0),x=jw(),m=Nt(V(n,Oe(l,e,h),gn(Dw,x),ut()),x),y=Nt(V(l,ut(),gn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),ce(({prev:C})=>C)),[]);he(V(l,ke(C=>C.length>0),Oe(m,h),ce(([C,T,I])=>{const A=C.reduce((j,L,M)=>Wt(j,L,Gr(L,T.offsetTree,I)||M),Cr());return{...T,groupIndices:C,groupOffsetTree:A}})),m),he(V(r,Oe(m),ke(([C,{lastIndex:T}])=>C<T),ce(([C,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:C}])),n),he(c,d);const g=Nt(V(c,ce(C=>C===void 0)),!0);he(V(d,ke(C=>C!==void 0&&ot(vt(m).sizeTree)),ce(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(V(n,Oe(m),gn(({sizes:C},[T,I])=>({changed:I!==C,sizes:I}),{changed:!1,sizes:x}),ce(C=>C.changed)));Qe(V(a,gn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),ce(C=>C.diff)),C=>{const{groupIndices:T}=vt(m);if(C>0)Me(t,!0),Me(s,C+Dd(C,T));else if(C<0){const I=vt(y);I.length>0&&(C-=Dd(-C,I)),Me(i,C)}}),Qe(V(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(V(s,Oe(m),ce(([C,T])=>{const I=T.groupIndices.length>0,A=[],j=T.lastSize;if(I){const L=Kr(T.sizeTree,0);let M=0,P=0;for(;M<C;){const N=T.groupIndices[P],B=T.groupIndices.length===P+1?1/0:T.groupIndices[P+1]-N-1;A.push({endIndex:N,size:L,startIndex:N}),A.push({endIndex:N+1+B-1,size:j,startIndex:N+1}),P++,M+=B+1}const F=Qn(T.sizeTree);return M!==C&&F.shift(),F.reduce((N,{k:B,v:R})=>{let J=N.ranges;return N.prevSize!==0&&(J=[...N.ranges,{endIndex:B+C-1,size:N.prevSize,startIndex:N.prevIndex}]),{prevIndex:B+C,prevSize:R,ranges:J}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return Qn(T.sizeTree).reduce((L,{k:M,v:P})=>({prevIndex:M+C,prevSize:P,ranges:[...L.ranges,{endIndex:M+C-1,size:L.prevSize,startIndex:L.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const k=Ht(V(i,Oe(m,h),ce(([C,{offsetTree:T},I])=>{const A=-C;return Gr(A,T,I)})));return he(V(i,Oe(m,h),ce(([C,T,I])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=Cr();const j=vt(y);let L=0,M=0,P=0;for(;L<-C;){P=j[M];const F=j[M+1]-P-1;M++,L+=F+1}if(A=Qn(T.sizeTree).reduce((F,{k:N,v:B})=>Wt(F,Math.max(0,N+C),B),A),L!==-C){const F=Kr(T.sizeTree,P);A=Wt(A,0,F);const N=on(T.sizeTree,-C+1)[1];A=Wt(A,1,N)}return{...T,sizeTree:A,...la(T.offsetTree,0,A,I)}}else{const A=Qn(T.sizeTree).reduce((j,{k:L,v:M})=>Wt(j,Math.max(0,L+C),M),Cr());return{...T,sizeTree:A,...la(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(Pn,ia),{singleton:!0});function zw(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Ld=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Be(),i=Be(),a=Ht(V(s,ce(zw)));return he(V(a,ce(l=>l.totalCount)),n),he(V(a,ce(l=>l.groupIndices)),e),he(V(wt(o,t,r),ke(([l,c])=>hs(c)),ce(([l,c,d])=>on(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),ut(),ce(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},ct(xn,Dt)),Dn=qe(([{log:e}])=>{const t=ee(!1),n=Ht(V(t,ke(r=>r),ut()));return Qe(t,r=>{r&&vt(e)("props updated",{},Bt.DEBUG)}),{didMount:n,propsReady:t}},ct(Pn),{singleton:!0}),Uw=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function $d(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Uw)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Yr=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=Be(),x=Be(),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),Me(l,!1)}return he(V(h,Oe(n,f,r,m,a,i,p),Oe(e,s,o),ce(([[k,C,T,I,A,j,L,M],P,F,N])=>{const B=$d(k),{align:R,behavior:J,offset:z}=B,_=I-1,Y=Od(B,C,_);let X=Gr(Y,C.offsetTree,P)+j;R==="end"?(X+=F+on(C.sizeTree,Y)[1]-T+N,Y===_&&(X+=L)):R==="center"?X+=(F+on(C.sizeTree,Y)[1]-T+N)/2:X-=A,z&&(X+=z);const se=ye=>{S(),ye?(M("retrying to scroll to",{location:k},Bt.DEBUG),Me(h,k)):(Me(x,!0),M("list did not change, scroll successful",{},Bt.DEBUG))};if(S(),J==="smooth"){let ye=!1;b=Qe(t,Re=>{ye=ye||Re}),y=rn(d,()=>{se(ye)})}else y=rn(V(t,Hw(150)),se);return g=setTimeout(()=>{S()},1200),Me(l,!0),M("scrolling from index to",{behavior:J,index:Y,top:X},Bt.DEBUG),{behavior:J,top:X}})),c),{scrollTargetReached:x,scrollToIndex:h,topListHeight:m}},ct(xn,Dt,Pn),{singleton:!0});function Hw(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ca(e,t){e==0?t():requestAnimationFrame(()=>{ca(e-1,t)})}function ua(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Xr=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(V(i,Oe(l),ke(([d,f])=>!!f),mn(!1)),a),he(V(i,Oe(l),ke(([d,f])=>!!f),mn(!1)),c),Qe(V(wt(t,i),Oe(a,n,e,c),ke(([[,d],f,{sizeTree:p},h,x])=>d&&(!ot(p)||Zi(h))&&!f&&!x),Oe(l)),([,d])=>{rn(o,()=>{Me(c,!0)}),ca(4,()=>{rn(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},ct(xn,Dt,Yr,Dn),{singleton:!0});function Fd(e,t){return Math.abs(e-t)<1.01}const Jr="up",Zr="down",Ww="none",Vw={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Kw=0,Qr=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ee(!1),a=ee(!0),l=Be(),c=Be(),d=ee(4),f=ee(Kw),p=Nt(V(ea(V(we(o),Jn(1),mn(!0)),V(we(o),Jn(1),mn(!1),Sd(100))),ut()),!1),h=Nt(V(ea(V(n,mn(!0)),V(n,mn(!1),Sd(200))),ut()),!1);he(V(wt(we(o),we(f)),ce(([b,S])=>b<=S),ut()),a),he(V(a,kn(50)),c);const x=Ht(V(wt(r,we(s),we(t),we(e),we(d)),gn((b,[{scrollHeight:S,scrollTop:k},C,T,I,A])=>{const j=k+C-S>-A,L={scrollHeight:S,scrollTop:k,viewportHeight:C};if(j){let P,F;return k>b.state.scrollTop?(P="SCROLLED_DOWN",F=b.state.scrollTop-k):(P="SIZE_DECREASED",F=b.state.scrollTop-k||b.scrollTopDelta),{atBottom:!0,atBottomBecause:P,scrollTopDelta:F,state:L}}let M;return L.scrollHeight>b.state.scrollHeight?M="SIZE_INCREASED":C<b.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":k<b.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:L}},Vw),ut((b,S)=>b&&b.atBottom===S.atBottom))),m=Nt(V(r,gn((b,{scrollHeight:S,scrollTop:k,viewportHeight:C})=>{if(Fd(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:k};{const T=S-(k+C)<1;return b.scrollTop!==k&&T?{changed:!0,jump:b.scrollTop-k,scrollHeight:S,scrollTop:k}:{changed:!0,jump:0,scrollHeight:S,scrollTop:k}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(b=>b.changed),ce(b=>b.jump)),0);he(V(x,ce(b=>b.atBottom)),i),he(V(i,kn(50)),l);const y=ee(Zr);he(V(r,ce(({scrollTop:b})=>b),ut(),gn((b,S)=>vt(h)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?Jr:Zr,prevScrollTop:S},{direction:Zr,prevScrollTop:0}),ce(b=>b.direction)),y),he(V(r,kn(50),mn(Ww)),y);const g=ee(0);return he(V(p,ke(b=>!b),mn(0)),g),he(V(o,kn(100),Oe(p),ke(([b,S])=>!!S),gn(([b,S],[k])=>[S,k],[0,0]),ce(([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)),ms="top",gs="bottom",Bd="none";function zd(e,t,n){return typeof e=="number"?n===Jr&&t===ms||n===Zr&&t===gs?e:0:n===Jr?t===ms?e.main:e.reverse:t===gs?e.main:e.reverse}function Ud(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const da=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Be(),i=ee(0),a=ee(0),l=ee(0),c=Nt(V(wt(we(r),we(o),we(n),we(s,qr),we(l),we(i),we(t),we(e),we(a)),ce(([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=Bd;const A=Ud(S,ms),j=Ud(S,gs);return h-=b,h+=p+g,x+=p+g,x-=b,h>d+C-A&&(I=Jr),x<d-T+f+j&&(I=Zr),I!==Bd?[Math.max(k-p-zd(m,ms,I)-A,0),k-T-g+f+zd(m,gs,I)+j]:null}),ke(d=>d!=null),ut(qr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},ct(Dt),{singleton:!0});function qw(e,t,n){if(hs(t)){const r=Pd(e,t);return[{index:on(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const fa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function xs(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,d=0;if(e.length>0){c=e[0].offset;const m=e[e.length-1];d=m.offset+m.size}const f=n-i,p=a+f*l+(f-1)*r,h=c,x=p-d;return{bottom:d,firstItemIndex:s,items:Wd(e,o,s),offsetBottom:x,offsetTop:c,top:h,topItems:Wd(t,o,s),topListHeight:t.reduce((m,y)=>y.size+m,0),totalCount:n}}function Hd(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=ua(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return xs(c,[],a,o,n,r)}function Wd(e,t,n){if(e.length===0)return[];if(!hs(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ds(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const er=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=Be();he(s.topItemsIndexes,m);const b=Nt(V(wt(h,x,we(l,qr),we(o),we(r),we(c),d,we(m),we(t),we(n),e),ke(([T,I,,A,,,,,,,j])=>{const L=j&&j.length!==A;return T&&!I&&!L}),ce(([,,[T,I],A,j,L,M,P,F,N,B])=>{const R=j,{offsetTree:J,sizeTree:z}=R,_=vt(y);if(A===0)return{...fa,totalCount:A};if(T===0&&I===0)return _===0?{...fa,totalCount:A}:Hd(_,L,j,F,N,B||[]);if(ot(z))return _>0?null:xs(qw(ua(L,A),R,B),[],A,N,R,F);const Y=[];if(P.length>0){const K=P[0],H=P[P.length-1];let G=0;for(const $ of ds(z,K,H)){const q=$.value,Z=Math.max($.start,K),le=Math.min($.end,H);for(let oe=Z;oe<=le;oe++)Y.push({data:B==null?void 0:B[oe],index:oe,offset:G,size:q}),G+=q}}if(!M)return xs([],Y,A,N,R,F);const X=P.length>0?P[P.length-1]+1:0,se=Ow(J,T,I,X);if(se.length===0)return null;const ye=A-1,Re=us([],K=>{for(const H of se){const G=H.value;let $=G.offset,q=H.start;const Z=G.size;if(G.offset<T){q+=Math.floor((T-G.offset+N)/(Z+N));const oe=q-H.start;$+=oe*Z+oe*N}q<X&&($+=(X-q)*Z,q=X);const le=Math.min(H.end,ye);for(let oe=q;oe<=le&&!($>=I);oe++)K.push({data:B==null?void 0:B[oe],index:oe,offset:$,size:Z}),$+=Z+N}});return xs(Re,Y,A,N,R,F)}),ke(T=>T!==null),ut()),fa);he(V(e,ke(Zi),ce(T=>T==null?void 0:T.length)),o),he(V(b,ce(T=>T.topListHeight)),f),he(f,a),he(V(b,ce(T=>[T.top,T.bottom])),i),he(V(b,ce(T=>T.items)),g);const S=Ht(V(b,ke(({items:T})=>T.length>0),Oe(o,e),ke(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ce(([,T,I])=>[T-1,I]),ut(qr),ce(([T])=>T))),k=Ht(V(b,kn(200),ke(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ce(({items:T})=>T[0].index),ut())),C=Ht(V(b,ke(({items:T})=>T.length>0),ce(({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(Rd)));return{endReached:S,initialItemCount:y,itemsRendered:g,listState:b,rangeChanged:C,startReached:k,topItemsIndexes:m,...p}},ct(xn,Ld,da,Xr,Yr,Qr,Dn,ia),{singleton:!0}),Vd=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Be(),i=Nt(V(wt(n,e,r,t,o),ce(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return he(we(i),s),{totalListHeight:i,totalListHeightChanged:s}},ct(Dt,er),{singleton:!0}),Gw=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ee(!1),r=Nt(V(wt(n,e,t),ke(([o])=>o),ce(([,o,s])=>Math.max(0,o-s)),kn(0),ut()),0);return{alignToBottom:n,paddingTopAddition:r}},ct(Dt,Vd),{singleton:!0}),Kd=qe(()=>({context:ee(null)})),Yw=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,qd=qe(([{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(V(d,Oe(t,l,n,s,o,r,a),Oe(e),ce(([[f,p,h,x,m,y,g,b],S])=>{const{align:k,behavior:C,calculateViewLocation:T=Yw,done:I,...A}=f,j=Od(f,p,x-1),L=Gr(j,p.offsetTree,S)+m+y,M=L+on(p.sizeTree,j)[1],P=b+y,F=b+h-g,N=T({itemBottom:M,itemTop:L,locationParams:{align:k,behavior:C,...A},viewportBottom:F,viewportTop:P});return N?I&&rn(V(i,ke(B=>!B),Jn(vt(i)?1:2)),I):I&&I(),N}),ke(f=>f!==null)),c),{scrollIntoView:d}},ct(xn,Dt,Yr,er,Pn),{singleton:!0});function Gd(e){return e?e==="smooth"?"smooth":"auto":!1}const Xw=(e,t)=>typeof e=="function"?Gd(e(t)):t&&Gd(e),Jw=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=Be();let y=null;function g(C){Me(i,{align:"end",behavior:C,index:"LAST"})}Qe(V(wt(V(we(t),Jn(1)),l),Oe(we(x),s,a,f),ce(([[C,T],I,A,j,L])=>{let M=T&&j,P="auto";return M&&(P=Xw(I,A||L),M=M&&!!P),{followOutputBehavior:P,shouldFollow:M,totalCount:C}}),ke(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C)}):y=rn(e,()=>{vt(d)("following output to ",{totalCount:T},Bt.DEBUG),g(C),y=null})});function b(C){const T=rn(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)}Qe(V(wt(we(x),t,c),ke(([C,,T])=>C&&T),gn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),ke(({refreshed:C})=>C),Oe(x,t)),([,C])=>{vt(a)&&b(C!==!1)}),Qe(m,()=>{b(vt(x)!==!1)}),Qe(wt(we(x),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&g("auto")});const S=ee(null),k=Be();return he(ea(V(we(r),ce(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),V(we(t))),k),Qe(V(wt(V(k,Jn(1)),l),Oe(we(S),a,f,p),ce(([[C,T],I,A,j,L])=>T&&A&&(I==null?void 0:I({context:L,totalCount:C,scrollingInProgress:j}))),ke(C=>!!C),kn(0)),C=>{y&&(y(),y=null),vt(n)?requestAnimationFrame(()=>{vt(d)("scrolling into view",{}),Me(h,C)}):y=rn(e,()=>{vt(d)("scrolling into view",{}),Me(h,C),y=null})}),{autoscrollToBottom:m,followOutput:x,scrollIntoViewOnChange:S}},ct(xn,Qr,Yr,Xr,Dn,Pn,Dt,Kd,qd)),Zw=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(V(a,Oe(s),ke(([,l])=>l!==0),Oe(o,r,t,n,e),ce(([[,l],c,d,f,p,h=[]])=>Hd(l,c,d,f,p,h))),i),{}),ct(xn,Xr,er,Dn),{singleton:!0}),Qw=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ee(0);return Qe(V(e,Oe(r),ke(([,o])=>o!==0),ce(([,o])=>({top:o}))),o=>{rn(V(n,Jn(1),ke(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},ct(Dn,Dt,er),{singleton:!0}),Yd=qe(([{scrollVelocity:e}])=>{const t=ee(!1),n=Be(),r=ee(!1);return he(V(e,Oe(r,t,n),ke(([o,s])=>!!s),ce(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),ut()),t),Qe(V(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(Qr),{singleton:!0}),pa=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Be(),r=Be(),o=Be(),s=ee(!1),i=ee(void 0);return he(V(wt(n,r),ce(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),he(V(t,Oe(r),ce(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},ct(Dt)),e0=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Be(),d=ee(void 0),f=ee(null),p=ee(null);return he(a,f),he(l,p),Qe(V(c,Oe(t,r,i,f,p,n)),([h,x,m,y,g,b,S])=>{const k=Lw(x.sizeTree);y&&g!==null&&b!==null&&(m=g.scrollTop-b.offsetTop),m-=S,h({ranges:k,scrollTop:m})}),he(V(d,ke(Zi),ce(t0)),o),he(V(s,Oe(d),ke(([,h])=>h!==void 0),ut(),ce(([,h])=>h.ranges)),e),{getState:c,restoreStateFrom:d}},ct(xn,Dt,Xr,Dn,pa));function t0(e){return{align:"start",index:0,offset:e.scrollTop}}const n0=qe(([{topItemsIndexes:e}])=>{const t=ee(0);return he(V(t,ke(n=>n>=0),ce(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},ct(er));function Xd(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const r0=Xd(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),o0=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(V(l,Oe(i),gn(([,g,b,S],[{bottom:k,items:C,offsetBottom:T,totalCount:I},A])=>{const j=k+T;let L=0;return b===I&&g.length>0&&C.length>0&&(C[0].originalIndex===0&&g[0].originalIndex===0||(L=j-S,L!==0&&(L+=A))),[L,C,I,j]},[0,[],0,0]),ke(([g])=>g!==0),Oe(r,a,n,o,h,x),ke(([,g,b,S,,,k])=>!k&&!S&&g!==0&&b===Jr),ce(([[g],,,,,b])=>(b("Upward scrolling compensation",{amount:g},Bt.DEBUG),g))));function y(g){g>0?(Me(t,{behavior:"auto",top:-g}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-g}))}return Qe(V(m,Oe(e,s)),([g,b,S])=>{S&&r0()?Me(e,b-g):y(-g)}),Qe(V(wt(Nt(s,!1),e,x),ke(([g,b,S])=>!g&&!S&&b!==0),ce(([g,b])=>b),kn(1)),y),he(V(f,ce(g=>({top:-g}))),t),Qe(V(c,Oe(p,d),ce(([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=Kr(k,0);let j=0,L=0;for(;j<g;){j++,I+=A;let M=b.length===L+1?1/0:b[L+1]-b[L]-1;j+M>g&&(I-=A,M=g-j+1),j+=M,I+=T(M),L++}return I}})),g=>{Me(e,g),requestAnimationFrame(()=>{Me(t,{top:g}),requestAnimationFrame(()=>{Me(e,0),Me(x,!1)})})}),{deviation:e}},ct(Dt,Qr,er,xn,Pn,ia)),s0=qe(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),ct(da,Zw,Dn,Yd,Vd,Qw,Gw,pa,qd,Pn,Kd)),Jd=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},j])=>(he(k.rangeChanged,j.scrollSeekRangeChanged),he(V(j.windowViewportRect,ce(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,...j,...m,sizes:l,...y}),ct(xn,Xr,Dt,e0,Jw,er,Yr,o0,n0,Ld,s0));function i0(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const ys=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Zd(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&&Me(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];Me(S,g[b])}for(const b of o)if(b in g){const S=y[t.optional[b]];Me(S,g[b])}y.propsReady&&Me(y.propsReady,!0)}function c(y){return s.reduce((g,b)=>(g[b]=S=>{const k=y[t.methods[b]];Me(k,S)},g),{})}function d(y){return i.reduce((g,b)=>(g[b]=Sw(y[t.events[b]]),g),{})}const f=w.forwardRef((y,g)=>{const{children:b,...S}=y,[k]=w.useState(()=>us(Tw(e),I=>{l(I,S)})),[C]=w.useState(wd(d,k));ys(()=>{for(const I of i)I in S&&Qe(C[I],S[I]);return()=>{Object.values(C).map(Qi)}},[S,C,k]),ys(()=>{l(k,S)}),w.useImperativeHandle(g,vd(c(k)));const T=n;return u.jsx(a.Provider,{value:k,children:n?u.jsx(T,{...i0([...r,...o,...i],S),children:b}):b})}),p=y=>{const g=w.useContext(a);return w.useCallback(b=>{Me(g[y],b)},[g,y])},h=y=>{const g=w.useContext(a)[y],b=w.useCallback(S=>Qe(g,S),[g]);return w.useSyncExternalStore(b,()=>vt(g),()=>vt(g))},x=y=>{const g=w.useContext(a)[y],[b,S]=w.useState(wd(vt,g));return ys(()=>Qe(g,k=>{k!==b&&S(vd(k))}),[g,b]),b},m=w.version.startsWith("18")?h:x;return{Component:f,useEmitter:(y,g)=>{const b=w.useContext(a)[y];ys(()=>Qe(b,g),[g,b])},useEmitterValue:m,usePublisher:p}}const Qd=w.createContext(void 0),ef=w.createContext(void 0),tf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ha(e){return"self"in e}function a0(e){return"body"in e}function nf(e,t,n,r=Sr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(p=>{let h,x,m;const y=p.target;if(a0(y)||ha(y)){const b=ha(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():qs.flushSync(g),a.current!==null&&(m===a.current||m<=0||m===h-x)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const p=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",c,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(p){const h=i.current;if(!h||(s?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const x=p.behavior==="smooth";let m,y,g;ha(h)?(y=Math.max(On(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=On(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)),Fd(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 ma="-webkit-sticky",rf="sticky",ga=Xd(()=>{if(typeof document>"u")return rf;const e=document.createElement("div");return e.style.position=ma,e.style.position===ma?ma:rf});function xa(e){return e}const l0=qe(()=>{const e=ee(a=>`Item ${a}`),t=ee(a=>`Group ${a}`),n=ee({}),r=ee(xa),o=ee("div"),s=ee(Sr),i=(a,l=null)=>Nt(V(n,ce(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")}}),c0=qe(([e,t])=>({...e,...t}),ct(Jd,l0)),u0=({height:e})=>u.jsx("div",{style:{height:e}}),d0={overflowAnchor:"none",position:ga(),zIndex:1},of={overflowAnchor:"none"},f0={...of,display:"inline-block",height:"100%"},sf=w.memo(function({showTopList:e=!1}){const t=Ae("listState"),n=Xt("sizeRanges"),r=Ae("useWindowScroll"),o=Ae("customScrollParent"),s=Xt("windowScrollContainerState"),i=Xt("scrollContainerState"),a=o||r?s:i,l=Ae("itemContent"),c=Ae("context"),d=Ae("groupContent"),f=Ae("trackItemSizes"),p=Ae("itemSize"),h=Ae("log"),x=Xt("gap"),m=Ae("horizontalDirection"),{callbackRef:y}=Ew(n,p,f,e?Sr:a,h,x,o,m,Ae("skipAnimationFrameInResizeObserver")),[g,b]=w.useState(0);ya("deviation",N=>{g!==N&&b(N)});const S=Ae("EmptyPlaceholder"),k=Ae("ScrollSeekPlaceholder")||u0,C=Ae("ListComponent"),T=Ae("ItemComponent"),I=Ae("GroupComponent"),A=Ae("computeItemKey"),j=Ae("isSeeking"),L=Ae("groupIndices").length>0,M=Ae("alignToBottom"),P=Ae("initialItemFinalLocationReached"),F=e?{}:{boxSizing:"border-box",...m?{display:"inline-block",height:"100%",marginLeft:g!==0?g:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:g!==0?g:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...P?{}:{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,R=A(B+t.firstItemIndex,N.data,c);return j?w.createElement(k,{..._t(k,c),height:N.size,index:N.index,key:R,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:R,style:d0},d(N.index,c)):w.createElement(T,{..._t(T,c),...g0(T,N.data),"data-index":B,"data-item-group-index":N.groupIndex,"data-item-index":N.index,"data-known-size":N.size,key:R,style:m?f0:of},L?l(N.index,N.groupIndex,N.data,c):l(N.index,N.data,c))})})}),p0={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},h0={outline:"none",overflowX:"auto",position:"relative"},vs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),m0={position:ga(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function g0(e,t){return{item:typeof e=="string"?void 0:t}}const x0=w.memo(function(){const e=Ae("HeaderComponent"),t=Xt("headerHeight"),n=Ae("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),y0=w.memo(function(){const e=Ae("FooterComponent"),t=Xt("footerHeight"),n=Ae("HeaderFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,Ae("skipAnimationFrameInResizeObserver")),o=Ae("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null});function af({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}=nf(a,c,l,d,void 0,f);return e("scrollTo",x),e("scrollBy",p),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...f?h0:p0,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function lf({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),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}=nf(a,c,l,x,p);return tf(()=>{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 v0=({children:e})=>{const t=w.useContext(Qd),n=Xt("viewportHeight"),r=Xt("fixedItemHeight"),o=Ae("alignToBottom"),s=Ae("horizontalDirection"),i=w.useMemo(()=>bd(n,l=>On(l,s?"width":"height")),[n,s]),a=Zn(i,!0,Ae("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:vs(o),children:e})},b0=({children:e})=>{const t=w.useContext(Qd),n=Xt("windowViewportRect"),r=Xt("fixedItemHeight"),o=Ae("customScrollParent"),s=kd(n,o,Ae("skipAnimationFrameInResizeObserver")),i=Ae("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:vs(i),children:e})},w0=({children:e})=>{const t=Ae("TopItemListComponent")||"div",n=Ae("headerHeight"),r={...m0,marginTop:`${n}px`},o=Ae("context");return u.jsx(t,{style:r,..._t(t,o),children:e})},S0=w.memo(function(e){const t=Ae("useWindowScroll"),n=Ae("topItemsIndexes").length>0,r=Ae("customScrollParent"),o=Ae("context");return u.jsxs(r||t?k0:T0,{...e,context:o,children:[n&&u.jsx(w0,{children:u.jsx(sf,{showTopList:!0})}),u.jsxs(r||t?b0:v0,{children:[u.jsx(x0,{}),u.jsx(sf,{}),u.jsx(y0,{})]})]})}),{Component:C0,useEmitter:ya,useEmitterValue:Ae,usePublisher:Xt}=Zd(c0,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},S0),T0=af({useEmitter:ya,useEmitterValue:Ae,usePublisher:Xt}),k0=lf({useEmitter:ya,useEmitterValue:Ae,usePublisher:Xt}),I0=C0;ct(Jd,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(xa),a=ee(Sr),l=(c,d=null)=>Nt(V(s,ce(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")}})),ga();const cf={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},E0={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:uf,floor:bs,max:eo,min:va,round:df}=Math;function ff(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function A0(e){return{...E0,items:e}}function ws(e,t){return e&&e.width===t.width&&e.height===t.height}function N0(e,t){return e&&e.column===t.column&&e.row===t.row}const _0=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(cf),j=ee({height:0,width:0}),L=ee({height:0,width:0}),M=Be(),P=Be(),F=ee(0),N=ee(null),B=ee({column:0,row:0}),R=Be(),J=Be(),z=ee(!1),_=ee(0),Y=ee(!0),X=ee(!1),se=ee(!1);Qe(V(x,Oe(_),ke(([$,q])=>!!q)),()=>{Me(Y,!1)}),Qe(V(wt(x,Y,L,j,_,X),ke(([$,q,Z,le,,oe])=>$&&!q&&Z.height!==0&&le.height!==0&&!oe)),([,,,,$])=>{Me(X,!0),ca(1,()=>{Me(M,$)}),rn(V(c),()=>{Me(t,[0,0]),Me(Y,!0)})}),he(V(J,ke($=>$!=null&&$.scrollTop>0),mn(0)),I),Qe(V(x,Oe(J),ke(([,$])=>$!=null)),([,$])=>{$&&(Me(j,$.viewport),Me(L,$.item),Me(B,$.gap),$.scrollTop>0&&(Me(z,!0),rn(V(c,Jn(1)),q=>{Me(z,!1)}),Me(l,{top:$.scrollTop})))}),he(V(j,ce(({height:$})=>$)),f),he(V(wt(we(j,ws),we(L,ws),we(B,($,q)=>$&&$.column===q.column&&$.row===q.row),we(c)),ce(([$,q,Z,le])=>({gap:Z,item:q,scrollTop:le,viewport:$}))),R),he(V(wt(we(T),r,we(B,N0),we(L,ws),we(j,ws),we(N),we(I),we(z),we(Y),we(_)),ke(([,,,,,,,$])=>!$),ce(([$,[q,Z],le,oe,_e,Ue,De,,Ge,He])=>{const{column:fe,row:ve}=le,{height:Pe,width:We}=oe,{width:it}=_e;if(De===0&&($===0||it===0))return cf;if(We===0){const Lt=ua(He,$),Mt=Lt+Math.max(De-1,0);return A0(ff(Lt,Mt,Ue))}const Xe=pf(it,We,fe);let nt,at;Ge?q===0&&Z===0&&De>0?(nt=0,at=De-1):(nt=Xe*bs((q+ve)/(Pe+ve)),at=Xe*uf((Z+ve)/(Pe+ve))-1,at=va($-1,eo(at,Xe-1)),nt=va(at,eo(0,nt))):(nt=0,at=-1);const Rt=ff(nt,at,Ue),{bottom:gt,top:ht}=hf(_e,le,oe,Rt),bt=uf($/Xe),St=bt*Pe+(bt-1)*ve-gt;return{bottom:gt,itemHeight:Pe,items:Rt,itemWidth:We,offsetBottom:St,offsetTop:ht,top:ht}})),A),he(V(N,ke($=>$!==null),ce($=>$.length)),T),he(V(wt(j,L,A,B),ke(([$,q,{items:Z}])=>Z.length>0&&q.height!==0&&$.height!==0),ce(([$,q,{items:Z},le])=>{const{bottom:oe,top:_e}=hf($,le,q,Z);return[_e,oe]}),ut(qr)),t);const ye=ee(!1);he(V(c,Oe(ye),ce(([$,q])=>q||$!==0)),ye);const Re=Ht(V(wt(A,T),ke(([{items:$}])=>$.length>0),Oe(ye),ke(([[$,q],Z])=>{const le=$.items[$.items.length-1].index===q-1;return(Z||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===q)&&le}),ce(([[,$]])=>$-1),ut())),K=Ht(V(we(A),ke(({items:$})=>$.length>0&&$[0].index===0),mn(0),ut())),H=Ht(V(we(A),Oe(z),ke(([{items:$},q])=>$.length>0&&!q),ce(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),ut(Rd),kn(0)));he(H,h.scrollSeekRangeChanged),he(V(M,Oe(j,L,T,B),ce(([$,q,Z,le,oe])=>{const _e=$d($),{align:Ue,behavior:De,offset:Ge}=_e;let He=_e.index;He==="LAST"&&(He=le-1),He=eo(0,He,va(le-1,He));let fe=ba(q,oe,Z,He);return Ue==="end"?fe=df(fe-q.height+Z.height):Ue==="center"&&(fe=df(fe-q.height/2+Z.height/2)),Ge&&(fe+=Ge),{behavior:De,top:fe}})),l);const G=Nt(V(A,ce($=>$.offsetBottom+$.bottom)),0);return he(V(k,ce($=>({height:$.visibleHeight,width:$.visibleWidth}))),j),{customScrollParent:y,data:N,deviation:F,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:L,overscan:n,restoreStateFrom:J,scrollBy:i,scrollContainerState:a,scrollHeight:P,scrollTo:l,scrollToIndex:M,scrollTop:c,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:g,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:k,...h,gridState:A,horizontalDirection:se,initialTopMostItemIndex:_,totalListHeight:G,...p,endReached:Re,propsReady:m,rangeChanged:H,startReached:K,stateChanged:R,stateRestoreInProgress:z,...C}},ct(da,Dt,Qr,Yd,Dn,pa,Pn));function pf(e,t,n){return eo(1,bs((e+n)/(bs(t)+n)))}function hf(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ba(e,t,n,r[0].index);return{bottom:ba(e,t,n,r[r.length-1].index)+o,top:s}}function ba(e,t,n,r){const o=pf(e.width,n.width,t.column),s=bs(r/o),i=s*n.height+eo(0,s-1)*t.row;return i>0?i+t.row:i}const j0=qe(()=>{const e=ee(f=>`Item ${f}`),t=ee({}),n=ee(null),r=ee("virtuoso-grid-item"),o=ee("virtuoso-grid-list"),s=ee(xa),i=ee("div"),a=ee(Sr),l=(f,p=null)=>Nt(V(t,ce(h=>h[f]),ut()),p),c=ee(!1),d=ee(!1);return he(we(d),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),R0=qe(([e,t])=>({...e,...t}),ct(_0,j0)),M0=w.memo(function(){const e=ft("gridState"),t=ft("listClassName"),n=ft("itemClassName"),r=ft("itemContent"),o=ft("computeItemKey"),s=ft("isSeeking"),i=Jt("scrollHeight"),a=ft("ItemComponent"),l=ft("ListComponent"),c=ft("ScrollSeekPlaceholder"),d=ft("context"),f=Jt("itemDimensions"),p=Jt("gap"),h=ft("log"),x=ft("stateRestoreInProgress"),m=Jt("reportReadyState"),y=Zn(w.useMemo(()=>g=>{const b=g.parentElement.parentElement.scrollHeight;i(b);const S=g.firstChild;if(S){const{height:k,width:C}=S.getBoundingClientRect();f({height:k,width:C})}p({column:gf("column-gap",getComputedStyle(g).columnGap,h),row:gf("row-gap",getComputedStyle(g).rowGap,h)})},[i,f,p,h]),!0,!1);return tf(()=>{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))})})}),P0=w.memo(function(){const e=ft("HeaderComponent"),t=Jt("headerHeight"),n=ft("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),O0=w.memo(function(){const e=ft("FooterComponent"),t=Jt("footerHeight"),n=ft("headerFooterTag"),r=Zn(w.useMemo(()=>s=>{t(On(s,"height"))},[t]),!0,!1),o=ft("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{..._t(e,o)})}):null}),D0=({children:e})=>{const t=w.useContext(ef),n=Jt("itemDimensions"),r=Jt("viewportDimensions"),o=Zn(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:vs(!1),children:e})},L0=({children:e})=>{const t=w.useContext(ef),n=Jt("windowViewportRect"),r=Jt("itemDimensions"),o=ft("customScrollParent"),s=kd(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:vs(!1),children:e})},$0=w.memo(function({...e}){const t=ft("useWindowScroll"),n=ft("customScrollParent"),r=n||t?B0:F0,o=n||t?L0:D0,s=ft("context");return u.jsx(r,{...e,..._t(r,s),children:u.jsxs(o,{children:[u.jsx(P0,{}),u.jsx(M0,{}),u.jsx(O0,{})]})})}),{useEmitter:mf,useEmitterValue:ft,usePublisher:Jt}=Zd(R0,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},$0),F0=af({useEmitter:mf,useEmitterValue:ft,usePublisher:Jt}),B0=lf({useEmitter:mf,useEmitterValue:ft,usePublisher:Jt});function gf(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 z0=fo.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function xf({className:e,variant:t,...n}){return u.jsx("div",{className:te(z0({variant:t}),e),...n})}function wa(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 yf(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function to(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(to).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(yf(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=to(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 no(e){if(typeof e=="string")return e;if(yf(e))return"";try{const t=to(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function U0(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function H0(e){const t=no(e);return typeof e=="string"&&U0(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Ss(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=wa(t);if(n!==null)return Ss(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Ss(e.content):e}function W0(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function vf(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 Cs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function V0(e){const t=r=>{try{const o=to(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 K0(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function bf(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 q0(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function G0(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function Y0({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=q0(n),i=o?`data:${s};base64,${e}`:t,a=G0(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function X0(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 Y0({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}async function wf(e,t){return await Kt(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function Sf(e,t){return await(await wf(`/files/${e}/view`,t)).text()}async function J0(e,t){const n=await wf(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await Kt(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function Z0(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await Kt("/files",{params:r})}var Ts="Dialog",[Cf,LT]=wn(Ts),[Q0,sn]=Cf(Ts),Tf=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=v.useRef(null),l=v.useRef(null),[c,d]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:Ts});return u.jsx(Q0,{scope:t,triggerRef:a,contentRef:l,contentId:Sn(),titleId:Sn(),descriptionId:Sn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Tf.displayName=Ts;var kf="DialogTrigger",If=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(kf,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":Ta(o.open),...r,ref:s,onClick:de(e.onClick,o.onOpenToggle)})});If.displayName=kf;var Sa="DialogPortal",[eS,Ef]=Cf(Sa,{forceMount:void 0}),Af=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=sn(Sa,t);return u.jsx(eS,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(Gt,{present:n||s.open,children:u.jsx(Ko,{asChild:!0,container:o,children:i})}))})};Af.displayName=Sa;var ks="DialogOverlay",Nf=v.forwardRef((e,t)=>{const n=Ef(ks,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=sn(ks,e.__scopeDialog);return s.modal?u.jsx(Gt,{present:r||s.open,children:u.jsx(nS,{...o,ref:t})}):null});Nf.displayName=ks;var tS=Wn.createSlot("DialogOverlay.RemoveScroll"),nS=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(ks,n);return u.jsx(ts,{as:tS,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ne.div,{"data-state":Ta(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),tr="DialogContent",_f=v.forwardRef((e,t)=>{const n=Ef(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=sn(tr,e.__scopeDialog);return u.jsx(Gt,{present:r||s.open,children:s.modal?u.jsx(rS,{...o,ref:t}):u.jsx(oS,{...o,ref:t})})});_f.displayName=tr;var rS=v.forwardRef((e,t)=>{const n=sn(tr,e.__scopeDialog),r=v.useRef(null),o=Fe(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return $i(s)},[]),u.jsx(jf,{...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())})}),oS=v.forwardRef((e,t)=>{const n=sn(tr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(jf,{...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()}})}),jf=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=sn(tr,n),l=v.useRef(null),c=Fe(t,l);return vi(),u.jsxs(u.Fragment,{children:[u.jsx(Po,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Mo,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ta(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(sS,{titleId:a.titleId}),u.jsx(aS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ca="DialogTitle",Rf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Ca,n);return u.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Rf.displayName=Ca;var Mf="DialogDescription",Pf=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Mf,n);return u.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Pf.displayName=Mf;var Of="DialogClose",Df=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=sn(Of,n);return u.jsx(Ne.button,{type:"button",...r,ref:t,onClick:de(e.onClick,()=>o.onOpenChange(!1))})});Df.displayName=Of;function Ta(e){return e?"open":"closed"}var Lf="DialogTitleWarning",[$T,$f]=tx(Lf,{contentName:tr,titleName:Ca,docsSlug:"dialog"}),sS=({titleId:e})=>{const t=$f(Lf),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},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,Ts=Mf,ks=Pf,Qn=Df,Is=$f,Vf=Bf;const pS=Hf,hS=Wf,Kf=v.forwardRef(({className:e,...t},n)=>u.jsx(Ts,{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}));Kf.displayName=Ts.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===Qn||(c==null?void 0:c.displayName)===Qn.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(ks,{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(Qn,{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(se.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});qf.displayName=ks.displayName;const Gf=({className:e,...t})=>u.jsx("div",{className:te("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(Qn,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Yf.displayName=Qn.displayName;const mS=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));mS.displayName=Is.displayName;const gS=1,xS=1e6;let ka=0;function yS(){return ka=(ka+1)%Number.MAX_SAFE_INTEGER,ka.toString()}const Ia=new Map,Xf=e=>{if(Ia.has(e))return;const t=setTimeout(()=>{Ia.delete(e),eo({type:"REMOVE_TOAST",toastId:e})},xS);Ia.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)}}},Es=[];let As={toasts:[]};function eo(e){As=vS(As,e),Es.forEach(t=>{t(As)})}function bS({...e}){const t=yS(),n=o=>eo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>eo({type:"DISMISS_TOAST",toastId:t});return eo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ea(){const[e,t]=v.useState(As);return v.useEffect(()=>(Es.push(t),()=>{const n=Es.indexOf(t);n>-1&&Es.splice(n,1)}),[e]),{...e,toast:bS,dismiss:n=>eo({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}=Ea(),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(se.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(Je,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(se.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(se.Image,{className:"h-5 w-5"}):u.jsx(se.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(Je,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(se.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Je,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(se.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 er=Jf();function SS(e){er=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 st(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 Ns={},_S=/^[^:]+:\/*[^/]*$/,jS=/^([^:]+:)[\s\S]*$/,RS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function MS(e,t){Ns[" "+e]||(_S.test(e)?Ns[" "+e]=e+"/":Ns[" "+e]=js(e,"/",!0)),e=Ns[" "+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 _s={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 js(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(`
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},iS="DialogDescriptionWarning",aS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${$f(iS).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},Ff=Tf,lS=If,Bf=Af,Is=Nf,Es=_f,nr=Rf,As=Pf,zf=Df;const cS=Ff,uS=Bf,Uf=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Uf.displayName=Is.displayName;const Hf=v.forwardRef(({className:e,children:t,...n},r)=>{const o=v.useMemo(()=>{let s=!1;function i(a){v.Children.forEach(a,l=>{if(s||!v.isValidElement(l))return;const c=l.type;if(c===nr||(c==null?void 0:c.displayName)===nr.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return u.jsxs(uS,{children:[u.jsx(Uf,{}),u.jsxs(Es,{ref:r,className:te("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(nr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(zf,{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"})]})]})]})});Hf.displayName=Es.displayName;const Wf=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Wf.displayName="DialogHeader";const Vf=v.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold leading-none tracking-tight",e),...t}));Vf.displayName=nr.displayName;const dS=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));dS.displayName=As.displayName;const fS=1,pS=1e6;let ka=0;function hS(){return ka=(ka+1)%Number.MAX_SAFE_INTEGER,ka.toString()}const Ia=new Map,Kf=e=>{if(Ia.has(e))return;const t=setTimeout(()=>{Ia.delete(e),ro({type:"REMOVE_TOAST",toastId:e})},pS);Ia.set(e,t)},mS=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,fS)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?Kf(n):e.toasts.forEach(r=>{Kf(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},Ns=[];let _s={toasts:[]};function ro(e){_s=mS(_s,e),Ns.forEach(t=>{t(_s)})}function gS({...e}){const t=hS(),n=o=>ro({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>ro({type:"DISMISS_TOAST",toastId:t});return ro({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Ea(){const[e,t]=v.useState(_s);return v.useEffect(()=>(Ns.push(t),()=>{const n=Ns.indexOf(t);n>-1&&Ns.splice(n,1)}),[e]),{...e,toast:gS,dismiss:n=>ro({type:"DISMISS_TOAST",toastId:n})}}function xS({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}=Ea(),p=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const g=await Sf(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 J0(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 Sf(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(Ze,{onClick:p,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(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(cS,{open:e,onOpenChange:t,children:u.jsxs(Hf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(Wf,{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(Vf,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Ze,{variant:"outline",size:"sm",onClick:x,className:"flex items-center gap-2",children:[u.jsx(ae.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(Ze,{variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[u.jsx(ae.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:m()})]})})}function qf(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let rr=qf();function yS(e){rr=e}const Gf=/[&<>"']/,vS=new RegExp(Gf.source,"g"),Yf=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,bS=new RegExp(Yf.source,"g"),wS={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Xf=e=>wS[e];function jt(e,t){if(t){if(Gf.test(e))return e.replace(vS,Xf)}else if(Yf.test(e))return e.replace(bS,Xf);return e}const SS=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Jf(e){return e.replace(SS,(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 CS=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(CS,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const TS=/[^\w:]/g,kS=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Zf(e,t,n){if(e){let r;try{r=decodeURIComponent(Jf(n)).replace(TS,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!kS.test(n)&&(n=NS(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const js={},IS=/^[^:]+:\/*[^/]*$/,ES=/^([^:]+:)[\s\S]*$/,AS=/^([^:]+:\/*[^/]*)[\s\S]*$/;function NS(e,t){js[" "+e]||(IS.test(e)?js[" "+e]=e+"/":js[" "+e]=Ms(e,"/",!0)),e=js[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(ES,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(AS,"$1")+t:e+t}const Rs={exec:function(){}};function Qf(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 Ms(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 _S(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 jS(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 ep(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function tp(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 RS(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 Aa{constructor(t){this.options=t||er}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:js(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=js(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 Aa{constructor(t){this.options=t||rr}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Ms(r,`
94
+ `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=RS(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=Ms(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: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=js(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 xe={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:_s,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};xe._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,xe._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,xe.def=st(xe.def).replace("label",xe._label).replace("title",xe._title).getRegex(),xe.bullet=/(?:[*+-]|\d{1,9}[.)])/,xe.listItemStart=st(/^( *)(bull) */).replace("bull",xe.bullet).getRegex(),xe.list=st(xe.list).replace(/bull/g,xe.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+xe.def.source+")").getRegex(),xe._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",xe._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,xe.html=st(xe.html,"i").replace("comment",xe._comment).replace("tag",xe._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),xe.paragraph=st(xe._paragraph).replace("hr",xe.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",xe._tag).getRegex(),xe.blockquote=st(xe.blockquote).replace("paragraph",xe.paragraph).getRegex(),xe.normal={...xe},xe.gfm={...xe.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},xe.gfm.table=st(xe.gfm.table).replace("hr",xe.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",xe._tag).getRegex(),xe.gfm.paragraph=st(xe._paragraph).replace("hr",xe.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",xe.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",xe._tag).getRegex(),xe.pedantic={...xe.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",xe._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:_s,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(xe.normal._paragraph).replace("hr",xe.hr).replace("heading",` *#{1,6} *[^
104
- ]`).replace("lheading",xe.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ue={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:_s,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:_s,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ue._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ue.punctuation=st(ue.punctuation).replace(/punctuation/g,ue._punctuation).getRegex(),ue.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ue.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ue._comment=st(xe._comment).replace("(?:-->|$)","-->").getRegex(),ue.emStrong.lDelim=st(ue.emStrong.lDelim).replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimAst=st(ue.emStrong.rDelimAst,"g").replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimUnd=st(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=st(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=st(ue.tag).replace("comment",ue._comment).replace("attribute",ue._attribute).getRegex(),ue._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ue._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ue._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ue.link=st(ue.link).replace("label",ue._label).replace("href",ue._href).replace("title",ue._title).getRegex(),ue.reflink=st(ue.reflink).replace("label",ue._label).replace("ref",xe._label).getRegex(),ue.nolink=st(ue.nolink).replace("ref",xe._label).getRegex(),ue.reflinkSearch=st(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:st(/^!?\[(label)\]\((.*?)\)/).replace("label",ue._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ue._label).getRegex()},ue.gfm={...ue.normal,escape:st(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=st(ue.gfm.url,"i").replace("email",ue.gfm._extended_email).getRegex(),ue.breaks={...ue.gfm,br:st(ue.br).replace("{2,}","*").getRegex(),text:st(ue.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 Pn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||er,this.options.tokenizer=this.options.tokenizer||new Aa,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:xe.normal,inline:ue.normal};this.options.pedantic?(n.block=xe.pedantic,n.inline=ue.pedantic):this.options.gfm&&(n.block=xe.gfm,this.options.breaks?n.inline=ue.breaks:n.inline=ue.gfm),this.tokenizer.rules=n}static get rules(){return{block:xe,inline:ue}}static lex(t,n){return new Pn(n).lex(t)}static lexInline(t,n){return new Pn(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:Qf(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]=Qf(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=Ms(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=_S(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)),tp(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 tp(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 xe={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:Rs,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};xe._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,xe._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,xe.def=st(xe.def).replace("label",xe._label).replace("title",xe._title).getRegex(),xe.bullet=/(?:[*+-]|\d{1,9}[.)])/,xe.listItemStart=st(/^( *)(bull) */).replace("bull",xe.bullet).getRegex(),xe.list=st(xe.list).replace(/bull/g,xe.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+xe.def.source+")").getRegex(),xe._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",xe._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,xe.html=st(xe.html,"i").replace("comment",xe._comment).replace("tag",xe._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),xe.paragraph=st(xe._paragraph).replace("hr",xe.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",xe._tag).getRegex(),xe.blockquote=st(xe.blockquote).replace("paragraph",xe.paragraph).getRegex(),xe.normal={...xe},xe.gfm={...xe.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},xe.gfm.table=st(xe.gfm.table).replace("hr",xe.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",xe._tag).getRegex(),xe.gfm.paragraph=st(xe._paragraph).replace("hr",xe.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",xe.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",xe._tag).getRegex(),xe.pedantic={...xe.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",xe._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Rs,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(xe.normal._paragraph).replace("hr",xe.hr).replace("heading",` *#{1,6} *[^
104
+ ]`).replace("lheading",xe.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ue={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Rs,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Rs,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ue._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ue.punctuation=st(ue.punctuation).replace(/punctuation/g,ue._punctuation).getRegex(),ue.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ue.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ue._comment=st(xe._comment).replace("(?:-->|$)","-->").getRegex(),ue.emStrong.lDelim=st(ue.emStrong.lDelim).replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimAst=st(ue.emStrong.rDelimAst,"g").replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimUnd=st(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=st(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=st(ue.tag).replace("comment",ue._comment).replace("attribute",ue._attribute).getRegex(),ue._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ue._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ue._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ue.link=st(ue.link).replace("label",ue._label).replace("href",ue._href).replace("title",ue._title).getRegex(),ue.reflink=st(ue.reflink).replace("label",ue._label).replace("ref",xe._label).getRegex(),ue.nolink=st(ue.nolink).replace("ref",xe._label).getRegex(),ue.reflinkSearch=st(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:st(/^!?\[(label)\]\((.*?)\)/).replace("label",ue._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ue._label).getRegex()},ue.gfm={...ue.normal,escape:st(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=st(ue.gfm.url,"i").replace("email",ue.gfm._extended_email).getRegex(),ue.breaks={...ue.gfm,br:st(ue.br).replace("{2,}","*").getRegex(),text:st(ue.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function MS(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 np(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class Ln{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||rr,this.options.tokenizer=this.options.tokenizer||new Aa,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:xe.normal,inline:ue.normal};this.options.pedantic?(n.block=xe.pedantic,n.inline=ue.pedantic):this.options.gfm&&(n.block=xe.gfm,this.options.breaks?n.inline=ue.breaks:n.inline=ue.gfm),this.tokenizer.rules=n}static get rules(){return{block:xe,inline:ue}}static lex(t,n){return new Ln(n).lex(t)}static lexInline(t,n){return new Ln(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
105
105
  `),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,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)+"["+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 Na{constructor(t){this.options=t||er}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)+"["+ep("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)+"["+ep("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,np)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,np))){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,MS)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(c=r.raw.slice(-1)),l=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class Na{constructor(t){this.options=t||rr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
115
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=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 On{constructor(t){this.options=t||er,this.options.renderer=this.options.renderer||new Na,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ap,this.slugger=new lp}static parse(t,n){return new On(n).parse(t)}static parseInline(t,n){return new On(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 Rs{constructor(t){this.options=t||er}preprocess(t){return t}postprocess(t){return t}}Hh(Rs,"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(Pn.lex,On.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=er,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 Na;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Aa;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 Rs;for(const s in n.hooks){const i=o[s];Rs.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(Pn.lexInline,On.parseInline),me.Parser=On,me.parser=On.parse,me.Renderer=Na,me.TextRenderer=ap,me.Lexer=Pn,me.lexer=Pn.lex,me.Tokenizer=Aa,me.Slugger=lp,me.Hooks=Rs,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,On.parse,Pn.lex;function to({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 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:Gs&&Gs.tagName.toUpperCase()==="SCRIPT"&&Gs.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:Qr(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Qr(e)})}const no=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}));no.displayName="Card";const ro=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));ro.displayName="CardHeader";const oo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));oo.displayName="CardTitle";const dp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));dp.displayName="CardDescription";const so=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));so.displayName="CardContent";const fp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("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=Qr(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(no,{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(ro,{className:"pb-3",children:[u.jsx(oo,{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(so,{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(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function qS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[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:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(to,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Je,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(se.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(se.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"?wa(c)??c:c;if(d&&typeof d=="object")return u.jsx(up,{data:d});const f=typeof d=="string"?d:(()=>{try{return Qr(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(to,{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(se.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=bs(d);return s(f)}const a=Zr(i),l=bs(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:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ms=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:_=null,messageParentCheckpointId:L=null}){const[M,P]=w.useState(!1),[F,N]=w.useState("preview"),[B,R]=w.useState(!1),{currentThreadId:Z}=Eo(),{respondToInterrupt:z}=Ao(),j=l==="phone"||l==="half-screen",Y=t.role,J=Y==="tool",oe=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!oe,Re=!(r&&Y!=="user"),{uploadingFiles:K,handleFileClick:U,fileViewerOpen:G,currentFileInfo:$,closeFileViewer:W}=qS({allowFileOpen:Re,currentThreadId:Z}),Q=w.useMemo(()=>{switch(Y){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[Y]),le=w.useMemo(()=>{if(oe)return"";const D=t.content;return Array.isArray(D)?G0(D):""},[oe,t]),re=w.useMemo(()=>{if(oe)return{};const D=t.content;return Array.isArray(D)?Cf(t):{}},[oe,t]),Ae=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="image_url"):[]},[oe,t]),Ue=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="file"):[]},[oe,t]),De=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="interrupt"):[]},[oe,t]),Ke=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),He=ws(Ke),fe=b==null?void 0:b.value,be=w.useMemo(()=>{if(oe)return"";const D=t.content;return Array.isArray(D)?Y0(D):""},[oe,t]),Pe=w.useMemo(()=>{if(oe||!p)return[];const X=t.artifact;if(!X)return[];const ne=[],Ce=[...Array.isArray(X.plots)?X.plots:[]];for(const Xe of Ce){const ge=eS(Xe);ge&&ne.push(ge)}return ne},[oe,t,p]),We=w.useCallback(async()=>{const D=J?be:le;async function X(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 Ce=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Ce})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(D),P(!0),setTimeout(()=>P(!1),2e3),g==null||g(D)}catch(ne){console.error("Failed to copy:",ne)}},[J,be,le,g]),it=w.useCallback(()=>{if(!x)return;const D=J?be:le,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,D,X)},[x,t.id,J,be,le,t]),Ge=w.useCallback(()=>{m==null||m(n)},[m,n]),Qe=w.useCallback(()=>{const X=te(j?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(Y){case"user":return u.jsx(se.User,{className:X});case"assistant":return u.jsx(se.Bot,{className:X});case"tool":return u.jsx(se.Wrench,{className:X});default:return u.jsx(se.Bot,{className:X})}},[j,Q,Y]),at=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(Y){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[Y]),Rt=w.useCallback(()=>{const D=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",j&&"px-3 py-2 text-sm");if(ye)return te(D,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(Y){case"user":return te(D,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(D,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[j,ye,Y]),gt=w.useCallback(async D=>{if(S)return;const X=ws((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!X){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(X,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async D=>{if(S)return;const X=ws((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!X){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(X,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:D,i:X})=>{if(D.type==="text"){const ne=D.text??"",Ce=ne.trim(),Xe=wa(Ce);return Xe&&Y!=="tool"?u.jsx(up,{data:Xe},X):Y==="user"&&c&&Ce.length>d?u.jsx(GS,{text:Ce,expanded:B,onExpandedChange:R,previewLength:d,isCompact:j},X):u.jsx(to,{content:ne,allowHtml:!1},X)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(D.type==="file"){const ne=D,Ce=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:Xe=>U(Xe.nativeEvent,ne,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:[K[X]?u.jsx(se.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Ce,K[X]?" (processing)":""]})]},X)}if(D.type==="interrupt"){const ne=D,Ce=ws((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),Xe=!!(He&&Ce&&Ce===He),ge=Xe?fe??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,ut=Ce?{...ne,id:Ce,interrupt_id:Ce}:ne;return u.jsx(KS,{interruptPart:ut,onApprove:gt,onReject:ht,disabled:S,isActive:Xe,payload:ge},X)}return null},[U,K,gt,ht,Y,c,d,B,j,He,fe,b,S,De]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(se.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 D=le.trim().length>0||Ae.length>0||Ue.length>0||De.length>0;if(!J&&Ue.length>0&&!r)return St();if(!J&&!D&&!r)return null;if(J)return!f&&Pe.length>0?null:f?u.jsx(YS,{message:t,viewMode:F},t.id):null;if(!J&&!oe){const X=t,ne=u.jsx("div",{className:"space-y-2",children:X.content.map((Ce,Xe)=>u.jsx(bt,{part:Ce,i:Xe},Xe))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(XS,{className:Q})]}):ne}},[le,Ae.length,Ue.length,De.length,r,J,F,f,Pe.length,St,Q]),Mt=w.useMemo(()=>oe?"Assistant":X0(t),[oe,t]),et=w.useMemo(()=>oe?[]:Array.isArray(T)?T:[],[T,oe]),It=w.useMemo(()=>{var D;return et.length?_&&et.some(X=>X.id===_)?_:((D=et[0])==null?void 0:D.id)??null:null},[_,et]),Ye=w.useMemo(()=>!et.length||!I?null:et.some(D=>D.id===I)?I:null,[I,et])??It,tt=Y==="user"&&et.length>0&&typeof A=="function",pt=w.useCallback((D,X=!1)=>{if(!A)return;const ne=(D==null?void 0:D.id)??null,Ce=(D==null?void 0:D.parentId)??L??null;A(ne,Ce,X)},[L,A]),V=w.useMemo(()=>Ye?et.findIndex(D=>D.id===Ye):-1,[Ye,et]),ie=w.useMemo(()=>V<0?null:et[V]??null,[V,et]);return J&&!f&&Pe.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(se.Bot,{className:te("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(to,{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||J)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",j&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Qe(),a&&Mt&&u.jsx("span",{className:te("font-medium",j?"text-xs":"text-sm"),children:Mt}),J&&u.jsxs(wf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",j&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(D=>D==="expanded"?"preview":"expanded"),onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),N(X=>X==="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(se.ChevronUp,{className:"h-3 w-3"}):u.jsx(se.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[tt&&ie&&V>=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",V<et.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(V>=et.length-1)return;const D=et[V+1];D&&pt(D)},"aria-label":"Older checkpoint (back in time)",disabled:V>=et.length-1,children:u.jsx(se.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[et.length-V," / ",et.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",V>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(V<=0))if(V===1)pt(null,!0);else{const D=et[V-1];D&&pt(D,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:V<=0,children:u.jsx(se.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Q,j&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>We(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,j&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(se.Copy,{className:te(M?"text-success":Q,j?"h-3 w-3":"h-4 w-4")})})}),Y==="user"&&x&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:it,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,j&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(se.Edit,{className:te(Q,j?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,j&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(se.RotateCcw,{className:te(Q,j?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),p&&Pe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Pe.map((D,X)=>u.jsx(WS,{preview:D,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(re.toolCallId||re.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",j&&"text-xs"),children:[re.name&&u.jsxs("div",{children:["Function: ",re.name]}),re.toolCallId&&u.jsxs("div",{children:["Call ID: ",re.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>We(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",j&&"h-5 w-5"),children:u.jsx(se.Copy,{className:te(M?"text-success":"text-current",j?"h-3 w-3":"h-4 w-4")})}),Y==="user"&&x&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:it,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",j&&"h-5 w-5"),children:u.jsx(se.Edit,{className:te("text-current",j?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",j&&"h-5 w-5"),children:u.jsx(se.RotateCcw,{className:te("text-current",j?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(wS,{isOpen:G,onClose:W,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});Ms.displayName="MessageComponent";const JS=({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(se.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 ZS(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),_="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:M,attemptMeta:P}=ZS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!_?t.additionalKwargs??{}:{},N=t&&!_?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(Ms,{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:M,messageParentCheckpointId:B,attemptMeta:P})})});hp.displayName="MessageRow";const _a=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:_,attemptMetaById:L,userMessageIdToAttempts:M,activeCheckpointId:P,onSelectCheckpoint:F,timelineCheckpoints:N,messagePreviews:B,createSyntheticThinkingMessage:R=!1},Z)=>{const z=w.useRef(null),j=w.useRef(null),Y=w.useRef(!1),[J,oe]=w.useState(!0),ye=w.useMemo(()=>b?e.some(fe=>"type"in fe&&fe.type==="default_message"?!1:Array.isArray(fe==null?void 0:fe.content)&&fe.content.some(be=>be&&be.type==="interrupt"&&(be.id??be.interrupt_id)===b.id)):!1,[b,e]),Re=w.useMemo(()=>{if(!b||ye)return null;const fe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let be;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const We=Pe.title;typeof We=="string"&&We.trim()&&(be=We.trim())}return{id:`interrupt-${fe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:fe,value:Pe,title:be}]}},[b,ye]),K=w.useMemo(()=>Re?[...e,Re]:e,[e,Re]),U=w.useMemo(()=>!R||!t?K:!K.some(be=>be.role==="assistant")&&K.length>0?[...K,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:K,[K,t,R]),G=w.useMemo(()=>T?U:U.filter(fe=>(fe==null?void 0:fe.role)!=="tool"),[U,T]),$=w.useCallback(fe=>{oe(fe),y&&y(!fe),g&&g(fe)},[y,g]),W=w.useMemo(()=>{if(a)return async()=>{if(!Y.current){Y.current=!0;try{await a()}finally{Y.current=!1}}}},[a]),Q=w.useMemo(()=>!x||m?!1:J?"auto":!1,[J,x,m]),le=N??[],re=le.length>0,Ae=w.useMemo(()=>{if(typeof h!="string")return null;const fe=h.trim();return fe?{id:"default-message",role:"assistant",type:"default_message",content:fe,createdAt:new Date().toISOString()}:null},[h]),Ue=re?u.jsx(JS,{timelineEntries:le,activeCheckpointId:P??null,onSelectCheckpoint:F,messagePreviews:B}):null,De=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Ke=()=>Ae?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ms,{message:Ae,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!"}),He=G.length>0;return w.useImperativeHandle(Z,()=>({scrollToLatest:()=>{var fe,be;if(z.current&&G.length>0){const Pe=G.length-1;(be=(fe=z.current).scrollToIndex)==null||be.call(fe,{index:Pe,align:"end",behavior:"auto"})}else j.current&&(j.current.scrollTop=j.current.scrollHeight)},scrollToTop:()=>{var fe,be;z.current&&G.length>0?(be=(fe=z.current).scrollToIndex)==null||be.call(fe,{index:0,align:"start",behavior:"auto"}):j.current&&(j.current.scrollTop=0)}}),[G]),u.jsxs("div",{className:De,style:p,children:[Ue,u.jsx("div",{className:"relative flex-1 min-h-0",children:He?u.jsx(_0,{ref:fe=>{z.current=fe},scrollerRef:fe=>{j.current=fe instanceof HTMLDivElement?fe:null},data:G,followOutput:Q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!0,startReached:()=>{W&&W()},atBottomStateChange:$,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(fe,be)=>pp(be,fe),itemContent:(fe,be)=>u.jsx(hp,{message:be,index:fe,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:_,attemptMetaById:L,userMessageIdToAttempts:M,activeCheckpointId:P,onSelectCheckpoint:F})}):Ke()})]})});_a.displayName="MessageList";const mp={value:""};function Ps({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}=ci(),{currentThreadId:g}=Eo(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:_,interrupt:L,metadata:M,timelineCheckpoints:P,messagePreviews:F}=Ao(),{isStreaming:N,error:B,connectionState:R,submit:Z,stop:z}=uc(),j=b??g??null,Y=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,oe=(M==null?void 0:M.assemblingMessageId)??null,ye=L,[Re,K]=w.useState(!1);w.useEffect(()=>{ye||K(!1)},[ye]);const U=w.useCallback(()=>{K(!0)},[]),G=w.useCallback(()=>{K(!1)},[]),$=!!ye||Re,[W,Q]=w.useState(null),[le,re]=w.useState(""),[Ae,Ue]=w.useState(null),[De,Ke]=w.useState(null),[He,fe]=w.useState([]),[be,Pe]=w.useState(0),[We,it]=w.useState(0),[Ge,Qe]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),et=w.useRef(!1),[It,vn]=w.useState(()=>mp.value),Ye=w.useRef(It),tt=w.useRef(null),pt=w.useCallback(pe=>{mp.value=pe,vn(pe)},[]),[V,ie]=w.useState(!1),D=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:ne,attemptMetaById:Ce,userMessageIdToAttempts:Xe}=xw(_),ge=P??[],ut=w.useRef(null),we=w.useRef(null),nt=w.useCallback(()=>{ut.current&&(ut.current.value=""),we.current&&(we.current.value=""),Pe(pe=>pe+1),it(pe=>pe+1)},[]),ao=w.useCallback(pe=>{pt(pe)},[pt]),lo=w.useRef(!1);w.useEffect(()=>{lo.current&&!N&&(fe([]),nt()),lo.current=N},[N,nt]);const[Vs,Va]=w.useState("desktop");w.useEffect(()=>{const pe=()=>{const ke=window.innerWidth;Va(ke<640?"phone":ke<1024?"tablet":"desktop")};return pe(),window.addEventListener("resize",pe),()=>window.removeEventListener("resize",pe)},[]),w.useEffect(()=>{et.current=!1},[j]),w.useEffect(()=>{Ye.current=It},[It]),w.useEffect(()=>{if(!W){tt.current=null;return}tt.current===null&&(tt.current=Ye.current),pt(le??"")},[le,W,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const ve=(await y.getAgent("default")).uiDefaultMessage||"";Mt(ve||null)}catch(ke){console.warn("Failed to fetch default message:",ke),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const Ka=pe=>{if(pe.length>is)return`Message too long (${pe.length}/${is} characters)`;try{return bw(pe),null}catch(ke){return(ke==null?void 0:ke.message)||"Invalid message"}},qa=async pe=>{const ke=pe.trim();if(!(!ke&&He.length===0)){if(ke){const ve=Ka(ke);if(ve){Ke(ve);return}}try{const ve=W?Yl(_??[],W):null,Fe=(W&&(ve==null?void 0:ve.checkpointId))??Y??void 0,Fn=(W&&(ve==null?void 0:ve.checkpointNs))??J??void 0,Tr=W?{edit:!0,originalMessageId:W,...Ae!=null&&Ae.checkpointId?{originalCheckpointId:Ae.checkpointId}:{},...Ae!=null&&Ae.checkpointNs?{originalCheckpointNs:Ae.checkpointNs}:{}}:void 0;await Z({text:ke||"",attachments:He,messageAdditionalKwargs:Tr},{checkpointId:Fe,checkpointNs:Fn}),h==null||h(ke),pt(""),Ke(null),fe([]),nt(),Q(null),re(""),Ue(null)}catch(ve){const Fe=(ve==null?void 0:ve.message)||"Failed to send message";Ke(Fe),m==null||m(Fe)}}},Ks=w.useCallback((pe,ke,ve)=>{c&&(tt.current=It,Q(pe),re(ke),pt(ke),Ke(null),Ue({checkpointId:(ve==null?void 0:ve.checkpointId)??null,checkpointNs:(ve==null?void 0:ve.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Q(null),re(""),Ue(null),Ke(null),pt(tt.current??It),tt.current=null},[It,pt]),q=w.useCallback((pe,ke,ve)=>{Ks(pe,ke,ve)},[Ks]),ae=w.useCallback(pe=>{let ke=null,ve=null;for(let ln=pe-1;ln>=0;ln--)if(S[ln].role==="user"){ke=S[ln],ve=S[ln].id;break}if(!ke||!ve)return;const Fe=Array.isArray(ke.content)?ke.content:[],Tr=Fe.filter(ln=>(ln==null?void 0:ln.type)==="text").map(ln=>ln.text).join("")||(()=>{try{return JSON.stringify(Fe,null,2)}catch{return String(Fe)}})();if(!Tr)return;const Bn=Yl(_,ve),fT=(Bn==null?void 0:Bn.checkpointId)??Y??void 0,pT=(Bn==null?void 0:Bn.checkpointNs)??J??void 0;Z({text:Tr},{checkpointId:fT,checkpointNs:pT})},[S,Z,_,Y,J]),Te=pe=>{const ke=Array.from(pe.target.files||[]);fe(ve=>[...ve,...ke]),pe.target.value=""},qe=pe=>{fe(ke=>{const ve=ke.filter((Fe,Fn)=>pe!==Fn);return ve.length===0&&nt(),ve})},rt=async pe=>{const ke=(pe.target.files||[])[0];if(ke){Rt(null),ht(null),Qe(!0);try{await Z({attachments:[ke]},{checkpointId:Y??void 0,checkpointNs:J??void 0});const ve=`Uploaded ${ke.name} - processing through chat stream`;ht(ve)}catch(ve){const Fe=ve instanceof Error?ve.message:"Failed to upload Excel file";console.error("Excel upload failed",ve),Rt(Fe),m==null||m(Fe)}finally{Qe(!1),pe.target.value="",nt()}}},$e=async pe=>{if(g){ie(!0);try{if(!pe){await I(),requestAnimationFrame(()=>{var Fe;(Fe=D.current)==null||Fe.scrollToLatest()});return}const ke=_.find(Fe=>Fe.checkpointId===pe),ve=(ke==null?void 0:ke.checkpointNs)??null;await T(pe,ve),requestAnimationFrame(()=>{var Fe;(Fe=D.current)==null||Fe.scrollToTop()})}finally{ie(!1)}}},Le=w.useCallback(async(pe,ke,ve)=>{await $e(ve?null:pe)},[$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(Je,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(se.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(_a,{ref:D,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:oe,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Vs,enableMessageEditing:c,editingMessageId:W,onEdit:q,onRegenerate:ae,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:V,activeInterrupt:ye,disableInterruptActions:Re,onInterruptActionStart:U,onInterruptActionEnd:G,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:ne,attemptMetaById:Ce,userMessageIdToAttempts:Xe,activeCheckpointId:Y,onSelectCheckpoint:Le,timelineCheckpoints:ge,messagePreviews:F}),(R==="reconnecting"||R==="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(se.Loader2,{className:"h-3 w-3 animate-spin"}),R==="reconnecting"?"Reconnecting…":"Connecting…"]})}),R==="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(se.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||V)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(se.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:[W&&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(se.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(se.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:ut,type:"file",multiple:!0,onChange:pe=>Te(pe),className:"hidden"},be),He.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:He.map((pe,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(se.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:pe.name}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>qe(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 ${pe.name}`,children:u.jsx(se.X,{size:12})})]},ke))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:we,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},We),Ge&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(se.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!Ge&&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(rw,{children:[u.jsx(ow,{asChild:!0,children:u.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(se.Plus,{size:16})})}),u.jsxs(wd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ji,{onClick:()=>{var pe;return(pe=ut.current)==null?void 0:pe.click()},className:"cursor-pointer",children:[u.jsx(se.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ji,{onClick:()=>{var pe;Ge||(pe=we.current)==null||pe.click()},className:`cursor-pointer ${Ge?"opacity-60 pointer-events-none":""}`,children:[u.jsx(se.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ox,{initialValue:le,editingMessageId:W,value:It,onValueChange:ao,placeholder:W?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:is,onSend:qa,onCancelEdit:E,onStop:z,allowEmptySend:He.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${W?"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 Os=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}));Os.displayName="Input";function ja(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 Ra="ScrollArea",[gp,HT]=wn(Ra),[eC,Zt]=gp(Ra),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),_=Be(t,M=>l(M)),L=_o(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(_e.div,{dir:L,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});xp.displayName=Ra;var yp="ScrollAreaViewport",vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Zt(yp,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(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});vp.displayName=yp;var yn="ScrollAreaScrollbar",Ma=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,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(Pa,{...r,ref:t}):null});Ma.displayName=yn;var tC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,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(Gt,{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=Zt(yn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Fs(()=>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(Gt,{present:n||a!=="hidden",children:u.jsx(Pa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=v.forwardRef((e,t)=>{const n=Zt(yn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Fs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return wr(n.viewport,l),wr(n.content,l),u.jsx(Gt,{present:r||s,children:u.jsx(Pa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Pa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Zt(yn,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=Zt(yn,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(Sp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":$s(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),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:Ls(i.paddingLeft),paddingEnd:Ls(i.paddingRight)}})}})}),oC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(yn,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(Sp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":$s(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),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:Ls(i.paddingTop),paddingEnd:Ls(i.paddingBottom)}})}})}),[sC,wp]=gp(yn),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=Zt(yn,n),[x,m]=v.useState(null),y=Be(t,_=>m(_)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Fs(f,10);function A(_){if(g.current){const L=_.clientX-g.current.left,M=_.clientY-g.current.top;c({x:L,y:M})}}return v.useEffect(()=>{const _=L=>{const M=L.target;(x==null?void 0:x.contains(M))&&C(L,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),wr(x,I),wr(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(_e.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:de(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(_))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,_=>{const L=_.target;L.hasPointerCapture(_.pointerId)&&L.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Ds="ScrollAreaThumb",Cp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wp(Ds,e.__scopeScrollArea);return u.jsx(Gt,{present:n||o.hasThumb,children:u.jsx(iC,{ref:t,...r})})}),iC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Zt(Ds,n),i=wp(Ds,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Fs(()=>{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(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture: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)})});Cp.displayName=Ds;var Oa="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=Zt(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(aC,{...e,ref:t}):null});Tp.displayName=Oa;var aC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Zt(Oa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return wr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),wr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_e.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ls(e){return e?parseInt(e,10):0}function kp(e,t){const n=e/t;return isNaN(n)?0:n}function $s(e){const t=kp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function lC(e,t,n,r="ltr"){const o=$s(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ep([l,c],f)(e)}function Ip(e,t,n="ltr"){const r=$s(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=ja(e,l);return 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 Fs(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 wr(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:te("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(Ma,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Cp,{className:"relative flex-1 rounded-full bg-border"})}));jp.displayName=Ma.displayName;const Rp=25;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=Eo(),{loadThread:y}=Ao(),{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),[_,L]=w.useState(null),[M,P]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const K=Array.isArray(f)?f:[];if(K.length>0){T.current=!0,C(K);return}x||(T.current=!1,C(K))},[f,x]),w.useEffect(()=>{if(!I.current)return;const K=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!K)return;let U=null,G=null;return U=requestAnimationFrame(()=>{G=requestAnimationFrame(()=>{K.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),G!==null&&cancelAnimationFrame(G)}},[k]);const B=async K=>{try{h(K),await y(K),a==null||a(K),l==null||l(K)}catch(U){console.error("Failed to select thread:",U)}},R=async()=>{try{N(!0);const K=await g();K&&(c==null||c(K),a==null||a(K))}catch(K){console.error("Failed to create thread:",K)}finally{N(!1)}},Z=async(K,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const G=I.current.querySelector("[data-radix-scroll-area-viewport]");G&&(A.current=G.scrollTop)}try{await b(K),d==null||d(K)}catch(G){console.error("Failed to delete thread:",G)}}},z=(K,U)=>{U.stopPropagation(),L(K.threadId),P(K.title||`Thread ${K.threadId.slice(0,8)}`)},j=async K=>{if(M.trim())try{await S(K,M.trim()),L(null),P("")}catch(U){console.error("Failed to update title:",U)}},Y=()=>{L(null),P("")},J=(K,U)=>{K.key==="Enter"?j(U):K.key==="Escape"&&Y()},oe=K=>{if(!K)return"";try{const U=new Date(K),$=new Date().getTime()-U.getTime(),W=Math.floor($/(1e3*60*60*24));return W===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):W===1?"Yesterday":W<7?`${W} days ago`:U.toLocaleDateString()}catch{return""}},ye=K=>K.title||`Thread ${K.threadId.slice(0,8)}`,Re=K=>{const U=ye(K);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(Je,{onClick:R,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(se.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(se.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(se.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((K,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(K.updatedAt||K.createdAt||"").getTime()).map(K=>u.jsxs("div",{onClick:()=>B(K.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===K.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:_===K.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Os,{value:M,onChange:U=>P(U.target.value),onKeyDown:U=>J(U,K.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>j(K.threadId),className:"h-6 w-6 p-0",children:u.jsx(se.Check,{size:12})}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:Y,className:"h-6 w-6 p-0",children:u.jsx(se.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:Re(K)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(se.Calendar,{size:10}),u.jsx("span",{children:oe(K.updatedAt||K.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==K.threadId&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>z(K,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(se.Edit3,{size:12})}),n&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>Z(K.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(se.Trash2,{size:12})})]})]}),i===K.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},K.threadId))})})]})}function Sr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function fC(e){if(typeof e!="string")return;const t=e.trim();if(t)return bn(t)}function Mp(){const e=[Sr("__API_BASE_URL__"),Sr("__CHAT_API_BASE_URL__"),Sr("__CHAT_API_URL__")];for(const t of e){const n=fC(t);if(n)return n}}function Pp(){const e=[Sr("__API_AUTH_TOKEN__"),Sr("__CHAT_API_KEY__"),Sr("__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 bn(t);return bn()}function Dp(){const e={},t=Mp(),n=Pp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Lp(){const e=Dp(),t=In.getAuthToken(),n=Mp();return{apiBaseUrl:Op(e.baseUrl,In.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:bn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&In.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function mC(){const e=Lp(),t=pC(),n=In.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Op(In.baseUrl,r,e.apiBaseUrl)}}function gC(e){In.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),hC(e)}var xC="Label",Fp=v.forwardRef((e,t)=>u.jsx(_e.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Fp.displayName=xC;var Bp=Fp;const yC=co.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Qt=v.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:te(yC(),e),...t}));Qt.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(_e.span,{...e,ref:t,style:{...Up,...e.style}}));bC.displayName=vC;var wC=[" ","Enter","ArrowUp","ArrowDown"],SC=[" ","Enter"],tr="Select",[Bs,zs,CC]=gi(tr),[Cr,WT]=wn(tr,[CC,Ho]),Us=Ho(),[TC,Dn]=Cr(tr),[kC,IC]=Cr(tr),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=Us(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=_o(c),[I,A]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:tr}),[_,L]=cr({prop:i,defaultProp:a,onChange:l,caller:tr}),M=v.useRef(null),P=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(R=>R.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:Sn(),value:_,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:M,disabled:p,children:[u.jsx(Bs.Provider,{scope:t,children:u.jsx(kC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{N(Z=>new Set(Z).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{N(Z=>{const z=new Set(Z);return z.delete(R),z})},[]),children:n})}),P?u.jsxs(ph,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:R=>L(R.target.value),disabled:p,form:x,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Hp.displayName=tr;var Wp="SelectTrigger",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Us(n),i=Dn(Wp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=zs(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(_e.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":hh(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===" ")&&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=Dn(Kp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(_e.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(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Gp.displayName=EC;var AC="SelectPortal",Yp=e=>u.jsx(Wo,{asChild:!0,...e});Yp.displayName=AC;var nr="SelectContent",Xp=v.forwardRef((e,t)=>{const n=Dn(nr,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?uo.createPortal(u.jsx(Jp,{scope:e.__scopeSelect,children:u.jsx(Bs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Zp,{...e,ref:t})});Xp.displayName=nr;var an=10,[Jp,Ln]=Cr(nr),NC="SelectContentImpl",_C=zn.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=Dn(nr,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,G=>k(G)),[A,_]=v.useState(null),[L,M]=v.useState(null),P=zs(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return $i(S)},[S]),vi();const R=v.useCallback(G=>{const[$,...W]=P().map(re=>re.ref.current),[Q]=W.slice(-1),le=document.activeElement;for(const re of G)if(re===le||(re==null||re.scrollIntoView({block:"nearest"}),re===$&&C&&(C.scrollTop=0),re===Q&&C&&(C.scrollTop=C.scrollHeight),re==null||re.focus(),document.activeElement!==le))return},[P,C]),Z=v.useCallback(()=>R([A,S]),[R,A,S]);v.useEffect(()=>{F&&Z()},[F,Z]);const{onOpenChange:z,triggerPointerDownPosRef:j}=b;v.useEffect(()=>{if(S){let G={x:0,y:0};const $=Q=>{var le,re;G={x:Math.abs(Math.round(Q.pageX)-(((le=j.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((re=j.current)==null?void 0:re.y)??0))}},W=Q=>{G.x<=10&&G.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",$),j.current=null};return j.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",W,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",W,{capture:!0})}}},[S,z,j]),v.useEffect(()=>{const G=()=>z(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[z]);const[Y,J]=mh(G=>{const $=P().filter(le=>!le.disabled),W=$.find(le=>le.ref.current===document.activeElement),Q=gh($,G,W);Q&&setTimeout(()=>Q.ref.current.focus())}),oe=v.useCallback((G,$,W)=>{const Q=!B.current&&!W;(b.value!==void 0&&b.value===$||Q)&&(_(G),Q&&(B.current=!0))},[b.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Re=v.useCallback((G,$,W)=>{const Q=!B.current&&!W;(b.value!==void 0&&b.value===$||Q)&&M(G)},[b.value]),K=r==="popper"?La:Qp,U=K===La?{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:oe,selectedItem:A,onItemLeave:ye,itemTextRefCallback:Re,focusSelectedItem:Z,selectedItemText:L,position:r,isPositioned:F,searchRef:Y,children:u.jsx(Qo,{as:_C,allowPinchZoom:!0,children:u.jsx(Ro,{asChild:!0,trapped:b.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:de(o,G=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),G.preventDefault()}),children:u.jsx(jo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(K,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:G=>G.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,G=>{const $=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!$&&G.key.length===1&&J(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let Q=P().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(G.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const le=G.target,re=Q.indexOf(le);Q=Q.slice(re+1)}setTimeout(()=>R(Q)),G.preventDefault()}})})})})})})});Zp.displayName=NC;var jC="SelectItemAlignedPosition",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Dn(nr,n),i=Ln(nr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),p=zs(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(),_=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const le=L.left-A.left,re=_.left-le,Ae=I.left-re,Ue=I.width+Ae,De=Math.max(Ue,A.width),Ke=window.innerWidth-an,He=ja(re,[an,Math.max(an,Ke-De)]);a.style.minWidth=Ue+"px",a.style.left=He+"px"}else{const le=A.right-L.right,re=window.innerWidth-_.right-le,Ae=window.innerWidth-I.right-re,Ue=I.width+Ae,De=Math.max(Ue,A.width),Ke=window.innerWidth-an,He=ja(re,[an,Math.max(an,Ke-De)]);a.style.minWidth=Ue+"px",a.style.right=He+"px"}const M=p(),P=window.innerHeight-an*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),R=parseInt(N.paddingTop,10),Z=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),j=B+R+F+z+Z,Y=Math.min(y.offsetHeight*5,j),J=window.getComputedStyle(m),oe=parseInt(J.paddingTop,10),ye=parseInt(J.paddingBottom,10),Re=I.top+I.height/2-an,K=P-Re,U=y.offsetHeight/2,G=y.offsetTop+U,$=B+R+G,W=j-$;if($<=Re){const le=M.length>0&&y===M[M.length-1].ref.current;a.style.bottom="0px";const re=c.clientHeight-m.offsetTop-m.offsetHeight,Ae=Math.max(K,U+(le?ye:0)+re+Z),Ue=$+Ae;a.style.height=Ue+"px"}else{const le=M.length>0&&y===M[0].ref.current;a.style.top="0px";const Ae=Math.max(Re,B+m.offsetTop+(le?oe:0)+U)+W;a.style.height=Ae+"px",m.scrollTop=$-Re+m.offsetTop}a.style.margin=`${an}px 0`,a.style.minHeight=Y+"px",a.style.maxHeight=P+"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(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Qp.displayName=jC;var RC="SelectPopperPosition",La=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=an,...s}=e,i=Us(n);return u.jsx(iu,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});La.displayName=RC;var[MC,$a]=Cr(nr,{}),Fa="SelectViewport",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Ln(Fa,n),i=$a(Fa,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(Bs.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll: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-an*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=Fa;var th="SelectGroup",[PC,OC]=Cr(th),DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sn();return u.jsx(PC,{scope:n,id:o,children:u.jsx(_e.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(_e.div,{id:o.id,...r,ref:t})});rh.displayName=nh;var Hs="SelectItem",[LC,oh]=Cr(Hs),sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Dn(Hs,n),l=Ln(Hs,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=Sn(),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(Bs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus: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===" "||(SC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});sh.displayName=Hs;var io="SelectItemText",ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Dn(io,n),a=Ln(io,n),l=oh(io,n),c=IC(io,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(_e.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?uo.createPortal(s.children,i.valueNode):null]})});ih.displayName=io;var ah="SelectItemIndicator",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return oh(ah,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});lh.displayName=ah;var Ba="SelectScrollUpButton",ch=v.forwardRef((e,t)=>{const n=Ln(Ba,e.__scopeSelect),r=$a(Ba,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(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ch.displayName=Ba;var za="SelectScrollDownButton",uh=v.forwardRef((e,t)=>{const n=Ln(za,e.__scopeSelect),r=$a(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.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=za;var dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Ln("SelectScrollButton",n),i=v.useRef(null),a=zs(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(_e.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()})})}),$C="SelectSeparator",fh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});fh.displayName=$C;var Ua="SelectArrow",FC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Us(n),s=Dn(Ua,n),i=Ln(Ua,n);return s.open&&i.position==="popper"?u.jsx(au,{...o,...r,ref:t}):null});FC.displayName=Ua;var BC="SelectBubbleInput",ph=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(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(_e.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,Ha=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{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(WC,{asChild:!0,children:u.jsx(se.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=xh.displayName;const Ih=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(se.ChevronUp,{className:"h-4 w-4"})}));Ih.displayName=wh.displayName;const Eh=v.forwardRef(({className:e,...t},n)=>u.jsx(Sh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(se.ChevronDown,{className:"h-4 w-4"})}));Eh.displayName=Sh.displayName;const Wa=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(VC,{children:u.jsxs(yh,{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(Ih,{}),u.jsx(KC,{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(Eh,{})]})}));Wa.displayName=yh.displayName;const YC=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));YC.displayName=vh.displayName;const rr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bh,{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(GC,{children:u.jsx(se.Check,{className:"h-4 w-4"})})}),u.jsx(qC,{children:t})]}));rr.displayName=bh.displayName;const XC=v.forwardRef(({className:e,...t},n)=>u.jsx(Ch,{ref:n,className:te("-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(_e.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:te("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(Ts,{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}));Rh.displayName=Ts.displayName;const rT=co.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(ks,{ref:o,className:te(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(se.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mh.displayName=ks.displayName;const Ph=({className:e,...t})=>u.jsx("div",{className:te("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(Qn,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Oh.displayName=Qn.displayName;const Dh=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Dh.displayName=Is.displayName;var Ws="Switch",[oT,VT]=wn(Ws),[sT,iT]=oT(Ws),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=Be(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=cr({prop:o,defaultProp:s??!1,onChange:c,caller:Ws});return u.jsxs(sT,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.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:de(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=Ws;var $h="SwitchThumb",Fh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=iT($h,n);return u.jsx(_e.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=Be(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 $n=v.forwardRef(({className:e,...t},n)=>u.jsx(Uh,{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(lT,{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")})}));$n.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}=Ea();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(Je,{variant:"outline",size:"sm",className:n,children:[u.jsx(se.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(no,{children:[u.jsx(ro,{className:"pb-3",children:u.jsxs(oo,{className:"text-lg flex items-center gap-2",children:[u.jsx(se.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(so,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Os,{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(Je,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx($n,{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(Qt,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Os,{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(Je,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(se.EyeOff,{className:"h-4 w-4"}):u.jsx(se.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(no,{children:[u.jsx(ro,{className:"pb-3",children:u.jsxs(oo,{className:"text-lg flex items-center gap-2",children:[u.jsx(se.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(so,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{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(Ha,{children:u.jsx(kh,{})}),u.jsxs(Wa,{children:[u.jsx(rr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(rr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(rr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"theme",children:"Theme"}),u.jsxs(Th,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Ha,{children:u.jsx(kh,{})}),u.jsxs(Wa,{children:[u.jsx(rr,{value:"light",children:"Light"}),u.jsx(rr,{value:"dark",children:"Dark"}),u.jsx(rr,{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(Qt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx($n,{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(Qt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx($n,{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(Qt,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx($n,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(no,{children:[u.jsx(ro,{className:"pb-3",children:u.jsxs(oo,{className:"text-lg flex items-center gap-2",children:[u.jsx(se.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(so,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx($n,{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(Qt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx($n,{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(Qt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx($n,{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(Je,{variant:"outline",onClick:h,children:[u.jsx(se.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Je,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Je,{onClick:p,disabled:!c,children:[u.jsx(se.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(No,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ps,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(No,{...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(Da,{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(Ps,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(No,{...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(Da,{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(Ps,{onError:s.onError,enableFileUpload:!0})})]})})}Ie.ChatApi=Ul,Ie.ChatInput=fc,Ie.ChatInterface=Ps,Ie.ChatProviders=No,Ie.ChatSettings=uT,Ie.MarkdownContent=to,Ie.MessageComponent=Ms,Ie.MessageList=_a,Ie.ThreadManager=Da,Ie.applySettings=gC,Ie.buildMessagePreviewMap=Xl,Ie.chatApiClient=In,Ie.default=dT,Ie.del=zl,Ie.get=Kt,Ie.getChatToken=$l,Ie.getCurrentSettings=mC,Ie.getDefaultApiConfig=Dp,Ie.getDefaultChatSettings=Lp,Ie.onChatTokenChanged=Fl,Ie.post=li,Ie.put=Bl,Ie.setChatToken=Co,Ie.useApi=ci,Ie.useChatStream=Jl,Ie.useMessagesReducer=Zl,Ie.useStream=uc,Ie.useThreadState=Ao,Ie.useThreads=Eo,Object.defineProperties(Ie,{__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=Zf(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=Zf(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 rp{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 op{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class $n{constructor(t){this.options=t||rr,this.options.renderer=this.options.renderer||new Na,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new rp,this.slugger=new op}static parse(t,n){return new $n(n).parse(t)}static parseInline(t,n){return new $n(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,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,Jf(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 Ps{constructor(t){this.options=t||rr}preprocess(t){return t}postprocess(t){return t}}Fh(Ps,"passThroughHooks",new Set(["preprocess","postprocess"]));function PS(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 sp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=PS(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(jS(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 sp(Ln.lex,$n.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},yS(me.defaults),me},me.getDefaults=qf,me.defaults=rr,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 Na;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Aa;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 Ps;for(const s in n.hooks){const i=o[s];Ps.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=sp(Ln.lexInline,$n.parseInline),me.Parser=$n,me.parser=$n.parse,me.Renderer=Na,me.TextRenderer=rp,me.Lexer=Ln,me.lexer=Ln.lex,me.Tokenizer=Aa,me.Slugger=op,me.Hooks=Ps,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,$n.parse,Ln.lex;function oo({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 OS={MODE:"library"};function DS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Gs&&Gs.tagName.toUpperCase()==="SCRIPT"&&Gs.src||new URL("index.umd.js",document.baseURI).href}<"u"?OS: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 LS(){return!DS()}function $S(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function FS(){return LS()||$S()}function BS({preview:e,idx:t}){return w.useEffect(()=>{FS()&&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 zS="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 ip({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:zS,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:no(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:no(e)})}const so=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}));so.displayName="Card";const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));io.displayName="CardHeader";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));ao.displayName="CardTitle";const ap=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));ap.displayName="CardDescription";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));lo.displayName="CardContent";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));lp.displayName="CardFooter";function US({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=no(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(so,{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(io,{className:"pb-3",children:[u.jsx(ao,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(ap,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(lo,{className:"pt-0 pb-3",children:a}),u.jsx(lp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function HS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[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 Z0(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 WS({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(oo,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ze,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(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 VS({message:e,viewMode:t}){const r=vf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?wa(c)??c:c;if(d&&typeof d=="object")return u.jsx(ip,{data:d});const f=typeof d=="string"?d:(()=>{try{return no(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}=H0(c);return f?u.jsx(oo,{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=Ss(d);return s(f)}const a=to(i),l=Ss(a);return s(l)}function KS({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 Os=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:j=null,messageParentCheckpointId:L=null}){const[M,P]=w.useState(!1),[F,N]=w.useState("preview"),[B,R]=w.useState(!1),{currentThreadId:J}=No(),{respondToInterrupt:z}=_o(),_=l==="phone"||l==="half-screen",Y=t.role,X=Y==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!se,Re=!(r&&Y!=="user"),{uploadingFiles:K,handleFileClick:H,fileViewerOpen:G,currentFileInfo:$,closeFileViewer:q}=HS({allowFileOpen:Re,currentThreadId:J}),Z=w.useMemo(()=>{switch(Y){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[Y]),le=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?W0(D):""},[se,t]),oe=w.useMemo(()=>{if(se)return{};const D=t.content;return Array.isArray(D)?vf(t):{}},[se,t]),_e=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="image_url"):[]},[se,t]),Ue=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="file"):[]},[se,t]),De=w.useMemo(()=>{if(se)return[];const D=t.content;return Array.isArray(D)?D.filter(Q=>Q.type==="interrupt"):[]},[se,t]),Ge=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),He=Cs(Ge),fe=b==null?void 0:b.value,ve=w.useMemo(()=>{if(se)return"";const D=t.content;return Array.isArray(D)?V0(D):""},[se,t]),Pe=w.useMemo(()=>{if(se||!p)return[];const Q=t.artifact;if(!Q)return[];const ne=[],Se=[...Array.isArray(Q.plots)?Q.plots:[]];for(const Ve of Se){const ge=X0(Ve);ge&&ne.push(ge)}return ne},[se,t,p]),We=w.useCallback(async()=>{const D=X?ve:le;async function Q(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Se=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Se})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(D),P(!0),setTimeout(()=>P(!1),2e3),g==null||g(D)}catch(ne){console.error("Failed to copy:",ne)}},[X,ve,le,g]),it=w.useCallback(()=>{if(!x)return;const D=X?ve:le,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,D,Q)},[x,t.id,X,ve,le,t]),Xe=w.useCallback(()=>{m==null||m(n)},[m,n]),nt=w.useCallback(()=>{const Q=te(_?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(Y){case"user":return u.jsx(ae.User,{className:Q});case"assistant":return u.jsx(ae.Bot,{className:Q});case"tool":return u.jsx(ae.Wrench,{className:Q});default:return u.jsx(ae.Bot,{className:Q})}},[_,Z,Y]),at=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(Y){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[Y]),Rt=w.useCallback(()=>{const D=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(D,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(Y){case"user":return te(D,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(D,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[_,ye,Y]),gt=w.useCallback(async D=>{if(S)return;const Q=Cs((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async D=>{if(S)return;const Q=Cs((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!Q){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(Q,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:D,i:Q})=>{if(D.type==="text"){const ne=D.text??"",Se=ne.trim(),Ve=wa(Se);return Ve&&Y!=="tool"?u.jsx(ip,{data:Ve},Q):Y==="user"&&c&&Se.length>d?u.jsx(WS,{text:Se,expanded:B,onExpandedChange:R,previewLength:d,isCompact:_},Q):u.jsx(oo,{content:ne,allowHtml:!1},Q)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(D.type==="file"){const ne=D,Se=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:Ve=>H(Ve.nativeEvent,ne,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[K[Q]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Se,K[Q]?" (processing)":""]})]},Q)}if(D.type==="interrupt"){const ne=D,Se=Cs((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),Ve=!!(He&&Se&&Se===He),ge=Ve?fe??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,lt=Se?{...ne,id:Se,interrupt_id:Se}:ne;return u.jsx(US,{interruptPart:lt,onApprove:gt,onReject:ht,disabled:S,isActive:Ve,payload:ge},Q)}return null},[H,K,gt,ht,Y,c,d,B,_,He,fe,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 D=le.trim().length>0||_e.length>0||Ue.length>0||De.length>0;if(!X&&Ue.length>0&&!r)return St();if(!X&&!D&&!r)return null;if(X)return!f&&Pe.length>0?null:f?u.jsx(VS,{message:t,viewMode:F},t.id):null;if(!X&&!se){const Q=t,ne=u.jsx("div",{className:"space-y-2",children:Q.content.map((Se,Ve)=>u.jsx(bt,{part:Se,i:Ve},Ve))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(KS,{className:Z})]}):ne}},[le,_e.length,Ue.length,De.length,r,X,F,f,Pe.length,St,Z]),Mt=w.useMemo(()=>se?"Assistant":K0(t),[se,t]),et=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),It=w.useMemo(()=>{var D;return et.length?j&&et.some(Q=>Q.id===j)?j:((D=et[0])==null?void 0:D.id)??null:null},[j,et]),Je=w.useMemo(()=>!et.length||!I?null:et.some(D=>D.id===I)?I:null,[I,et])??It,tt=Y==="user"&&et.length>0&&typeof A=="function",pt=w.useCallback((D,Q=!1)=>{if(!A)return;const ne=(D==null?void 0:D.id)??null,Se=(D==null?void 0:D.parentId)??L??null;A(ne,Se,Q)},[L,A]),U=w.useMemo(()=>Je?et.findIndex(D=>D.id===Je):-1,[Je,et]),re=w.useMemo(()=>U<0?null:et[U]??null,[U,et]);return X&&!f&&Pe.length===0?null:ye&&se?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(oo,{content:se.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||X)&&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:[nt(),a&&Mt&&u.jsx("span",{className:te("font-medium",_?"text-xs":"text-sm"),children:Mt}),X&&u.jsxs(xf,{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(D=>D==="expanded"?"preview":"expanded"),onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),N(Q=>Q==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(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:[tt&&re&&U>=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",U<et.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(U>=et.length-1)return;const D=et[U+1];D&&pt(D)},"aria-label":"Older checkpoint (back in time)",disabled:U>=et.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:[et.length-U," / ",et.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",U>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(U<=0))if(U===1)pt(null,!0);else{const D=et[U-1];D&&pt(D,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:U<=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(Ze,{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":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:te(M?"text-success":Z,_?"h-3 w-3":"h-4 w-4")})})}),Y==="user"&&x&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:it,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")})}),Y==="assistant"&&m&&u.jsx(Ze,{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":"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&&Pe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Pe.map((D,Q)=>u.jsx(BS,{preview:D,idx:Q},`artifact-${Q}`))})]}),X&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",_&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Ze,{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.Copy,{className:te(M?"text-success":"text-current",_?"h-3 w-3":"h-4 w-4")})}),Y==="user"&&x&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:it,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")})}),Y==="assistant"&&m&&u.jsx(Ze,{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.RotateCcw,{className:te("text-current",_?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(xS,{isOpen:G,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&&bf(e.message)===bf(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});Os.displayName="MessageComponent";const qS=({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 GS(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 cp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,up=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=cp(t,n),j="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:M,attemptMeta:P}=GS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!j?t.additionalKwargs??{}:{},N=t&&!j?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(Os,{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:M,messageParentCheckpointId:B,attemptMeta:P})})});up.displayName="MessageRow";const _a=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:j,attemptMetaById:L,userMessageIdToAttempts:M,activeCheckpointId:P,onSelectCheckpoint:F,timelineCheckpoints:N,messagePreviews:B,createSyntheticThinkingMessage:R=!1},J)=>{const z=w.useRef(null),_=w.useRef(null),Y=w.useRef(!1),[X,se]=w.useState(!0),ye=w.useMemo(()=>b?e.some(fe=>"type"in fe&&fe.type==="default_message"?!1:Array.isArray(fe==null?void 0:fe.content)&&fe.content.some(ve=>ve&&ve.type==="interrupt"&&(ve.id??ve.interrupt_id)===b.id)):!1,[b,e]),Re=w.useMemo(()=>{if(!b||ye)return null;const fe=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let ve;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const We=Pe.title;typeof We=="string"&&We.trim()&&(ve=We.trim())}return{id:`interrupt-${fe}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:fe,value:Pe,title:ve}]}},[b,ye]),K=w.useMemo(()=>Re?[...e,Re]:e,[e,Re]),H=w.useMemo(()=>!R||!t?K:!K.some(ve=>ve.role==="assistant")&&K.length>0?[...K,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:K,[K,t,R]),G=w.useMemo(()=>T?H:H.filter(fe=>(fe==null?void 0:fe.role)!=="tool"),[H,T]),$=w.useCallback(fe=>{se(fe),y&&y(!fe),g&&g(fe)},[y,g]),q=w.useMemo(()=>{if(a)return async()=>{if(!Y.current){Y.current=!0;try{await a()}finally{Y.current=!1}}}},[a]),Z=w.useMemo(()=>!x||m?!1:X?"auto":!1,[X,x,m]),le=N??[],oe=le.length>0,_e=w.useMemo(()=>{if(typeof h!="string")return null;const fe=h.trim();return fe?{id:"default-message",role:"assistant",type:"default_message",content:fe,createdAt:new Date().toISOString()}:null},[h]),Ue=oe?u.jsx(qS,{timelineEntries:le,activeCheckpointId:P??null,onSelectCheckpoint:F,messagePreviews:B}):null,De=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Ge=()=>_e?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Os,{message:_e,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!"}),He=G.length>0;return w.useImperativeHandle(J,()=>({scrollToLatest:()=>{var fe,ve;if(z.current&&G.length>0){const Pe=G.length-1;(ve=(fe=z.current).scrollToIndex)==null||ve.call(fe,{index:Pe,align:"end",behavior:"auto"})}else _.current&&(_.current.scrollTop=_.current.scrollHeight)},scrollToTop:()=>{var fe,ve;z.current&&G.length>0?(ve=(fe=z.current).scrollToIndex)==null||ve.call(fe,{index:0,align:"start",behavior:"auto"}):_.current&&(_.current.scrollTop=0)}}),[G]),u.jsxs("div",{className:De,style:p,children:[Ue,u.jsx("div",{className:"relative flex-1 min-h-0",children:He?u.jsx(I0,{ref:fe=>{z.current=fe},scrollerRef:fe=>{_.current=fe instanceof HTMLDivElement?fe:null},data:G,followOutput:Z,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!0,startReached:()=>{q&&q()},atBottomStateChange:$,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(fe,ve)=>cp(ve,fe),itemContent:(fe,ve)=>u.jsx(up,{message:ve,index:fe,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:j,attemptMetaById:L,userMessageIdToAttempts:M,activeCheckpointId:P,onSelectCheckpoint:F})}):Ge()})]})});_a.displayName="MessageList";const dp={value:""};function Ds({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}=ci(),{currentThreadId:g}=No(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:j,interrupt:L,metadata:M,timelineCheckpoints:P,messagePreviews:F}=_o(),{isStreaming:N,error:B,connectionState:R,submit:J,stop:z}=ic(),_=b??g??null,Y=(A==null?void 0:A.id)??null,X=(A==null?void 0:A.namespace)??null,se=(M==null?void 0:M.assemblingMessageId)??null,ye=L,[Re,K]=w.useState(!1);w.useEffect(()=>{ye||K(!1)},[ye]);const H=w.useCallback(()=>{K(!0)},[]),G=w.useCallback(()=>{K(!1)},[]),$=!!ye||Re,[q,Z]=w.useState(null),[le,oe]=w.useState(""),[_e,Ue]=w.useState(null),[De,Ge]=w.useState(null),[He,fe]=w.useState([]),[ve,Pe]=w.useState(0),[We,it]=w.useState(0),[Xe,nt]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),et=w.useRef(!1),[It,vn]=w.useState(()=>dp.value),Je=w.useRef(It),tt=w.useRef(null),pt=w.useCallback(pe=>{dp.value=pe,vn(pe)},[]),[U,re]=w.useState(!1),D=w.useRef(null),{checkpointMetaById:Q,checkpointIndexByKey:ne,attemptMetaById:Se,userMessageIdToAttempts:Ve}=pw(j),ge=P??[],lt=w.useRef(null),be=w.useRef(null),Ke=w.useCallback(()=>{lt.current&&(lt.current.value=""),be.current&&(be.current.value=""),Pe(pe=>pe+1),it(pe=>pe+1)},[]),In=w.useCallback(pe=>{pt(pe)},[pt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(fe([]),Ke()),En.current=N},[N,Ke]);const[Un,uo]=w.useState("desktop");w.useEffect(()=>{const pe=()=>{const Ie=window.innerWidth;uo(Ie<640?"phone":Ie<1024?"tablet":"desktop")};return pe(),window.addEventListener("resize",pe),()=>window.removeEventListener("resize",pe)},[]),w.useEffect(()=>{et.current=!1},[_]),w.useEffect(()=>{Je.current=It},[It]),w.useEffect(()=>{if(!q){tt.current=null;return}tt.current===null&&(tt.current=Je.current),pt(le??"")},[le,q,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";Mt(Ee||null)}catch(Ie){console.warn("Failed to fetch default message:",Ie),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const Hn=pe=>{if(pe.length>ls)return`Message too long (${pe.length}/${ls} characters)`;try{return gw(pe),null}catch(Ie){return(Ie==null?void 0:Ie.message)||"Invalid message"}},Er=async pe=>{const Ie=pe.trim();if(!(!Ie&&He.length===0)){if(Ie){const Ee=Hn(Ie);if(Ee){Ge(Ee);return}}try{const Ee=q?(_e==null?void 0:_e.checkpointId)??Y??void 0:Y??void 0,ze=q?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await J({text:Ie||"",attachments:He},{checkpointId:Ee,checkpointNs:ze,edit:!!q,originalMessageId:q??void 0}),h==null||h(Ie),pt(""),Ge(null),fe([]),Ke(),Z(null),oe(""),Ue(null)}catch(Ee){const ze=(Ee==null?void 0:Ee.message)||"Failed to send message";Ge(ze),m==null||m(ze)}}},An=w.useCallback((pe,Ie,Ee)=>{c&&(tt.current=It,Z(pe),oe(Ie),pt(Ie),Ge(null),Ue({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Z(null),oe(""),Ue(null),Ge(null),pt(tt.current??It),tt.current=null},[It,pt]),W=w.useCallback((pe,Ie,Ee)=>{An(pe,Ie,Ee)},[An]),ie=w.useCallback(pe=>{let Ie=null,Ee=null;for(let ln=pe-1;ln>=0;ln--)if(S[ln].role==="user"){Ie=ln,Ee=S[ln];break}if(Ie===null||!Ee)return;const ze=S.slice(0,Ie+1);ze.length&&J({payload:{messages:ze}},{checkpointId:Y??void 0,checkpointNs:X??void 0,edit:!0})},[S,J,Y,X]),Ce=pe=>{const Ie=Array.from(pe.target.files||[]);fe(Ee=>[...Ee,...Ie]),pe.target.value=""},Ye=pe=>{fe(Ie=>{const Ee=Ie.filter((ze,ln)=>pe!==ln);return Ee.length===0&&Ke(),Ee})},rt=async pe=>{const Ie=(pe.target.files||[])[0];if(Ie){Rt(null),ht(null),nt(!0);try{await J({attachments:[Ie]},{checkpointId:Y??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${Ie.name} - processing through chat stream`;ht(Ee)}catch(Ee){const ze=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),Rt(ze),m==null||m(ze)}finally{nt(!1),pe.target.value="",Ke()}}},$e=async pe=>{if(g){re(!0);try{if(!pe){await I(),requestAnimationFrame(()=>{var ze;(ze=D.current)==null||ze.scrollToLatest()});return}const Ie=j.find(ze=>ze.checkpointId===pe),Ee=(Ie==null?void 0:Ie.checkpointNs)??null;await T(pe,Ee),requestAnimationFrame(()=>{var ze;(ze=D.current)==null||ze.scrollToTop()})}finally{re(!1)}}},Le=w.useCallback(async(pe,Ie,Ee)=>{await $e(Ee?null:pe)},[$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(Ze,{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(_a,{ref:D,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Un,enableMessageEditing:c,editingMessageId:q,onEdit:W,onRegenerate:ie,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:U,activeInterrupt:ye,disableInterruptActions:Re,onInterruptActionStart:H,onInterruptActionEnd:G,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:Q,checkpointIndexByKey:ne,attemptMetaById:Se,userMessageIdToAttempts:Ve,activeCheckpointId:Y,onSelectCheckpoint:Le,timelineCheckpoints:ge,messagePreviews:F}),(R==="reconnecting"||R==="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"}),R==="reconnecting"?"Reconnecting…":"Connecting…"]})}),R==="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||U)&&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:[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(Ze,{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:lt,type:"file",multiple:!0,onChange:pe=>Ce(pe),className:"hidden"},ve),He.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:He.map((pe,Ie)=>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:pe.name}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ye(Ie),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${pe.name}`,children:u.jsx(ae.X,{size:12})})]},Ie))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:be,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},We),Xe&&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&&!Xe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!Xe&&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(Qb,{children:[u.jsx(ew,{asChild:!0,children:u.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(xd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ji,{onClick:()=>{var pe;return(pe=lt.current)==null?void 0:pe.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ji,{onClick:()=>{var pe;Xe||(pe=be.current)==null||pe.click()},className:`cursor-pointer ${Xe?"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(ex,{initialValue:le,editingMessageId:q,value:It,onValueChange:In,placeholder:q?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:ls,onSend:Er,onCancelEdit:E,onStop:z,allowEmptySend:He.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":""} ${De?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Ls=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}));Ls.displayName="Input";function ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function YS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ra="ScrollArea",[fp,FT]=wn(Ra),[XS,Zt]=fp(Ra),pp=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),j=Fe(t,M=>l(M)),L=Ro(o);return u.jsx(XS,{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:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});pp.displayName=Ra;var hp="ScrollAreaViewport",mp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Zt(hp,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})})]})});mp.displayName=hp;var yn="ScrollAreaScrollbar",Ma=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,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(JS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(gp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Pa,{...r,ref:t}):null});Ma.displayName=yn;var JS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,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(Gt,{present:n||s,children:u.jsx(gp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ZS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=zs(()=>l("SCROLL_END"),100),[a,l]=YS("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(Gt,{present:n||a!=="hidden",children:u.jsx(Pa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),gp=v.forwardRef((e,t)=>{const n=Zt(yn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=zs(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Tr(n.viewport,l),Tr(n.content,l),u.jsx(Gt,{present:r||s,children:u.jsx(Pa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Pa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Zt(yn,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=wp(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 oC(p,i.current,a,h)}return n==="horizontal"?u.jsx(QS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Sp(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(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Sp(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}),QS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(yn,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(yp,{"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":Bs(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),Tp(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:Fs(i.paddingLeft),paddingEnd:Fs(i.paddingRight)}})}})}),eC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(yn,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(yp,{"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":Bs(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),Tp(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:Fs(i.paddingTop),paddingEnd:Fs(i.paddingBottom)}})}})}),[tC,xp]=fp(yn),yp=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=Zt(yn,n),[x,m]=v.useState(null),y=Fe(t,j=>m(j)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=zs(f,10);function A(j){if(g.current){const L=j.clientX-g.current.left,M=j.clientY-g.current.top;c({x:L,y:M})}}return v.useEffect(()=>{const j=L=>{const M=L.target;(x==null?void 0:x.contains(M))&&C(L,k)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),Tr(x,I),Tr(h.content,I),u.jsx(tC,{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:de(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,j=>{const L=j.target;L.hasPointerCapture(j.pointerId)&&L.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),$s="ScrollAreaThumb",vp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=xp($s,e.__scopeScrollArea);return u.jsx(Gt,{present:n||o.hasThumb,children:u.jsx(nC,{ref:t,...r})})}),nC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Zt($s,n),i=xp($s,n),{onThumbPositionChange:a}=i,l=Fe(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=zs(()=>{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=sC(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: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)})});vp.displayName=$s;var Oa="ScrollAreaCorner",bp=v.forwardRef((e,t)=>{const n=Zt(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(rC,{...e,ref:t}):null});bp.displayName=Oa;var rC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Zt(Oa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Tr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Tr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Fs(e){return e?parseInt(e,10):0}function wp(e,t){const n=e/t;return isNaN(n)?0:n}function Bs(e){const t=wp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function oC(e,t,n,r="ltr"){const o=Bs(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 Cp([l,c],f)(e)}function Sp(e,t,n="ltr"){const r=Bs(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=ja(e,l);return Cp([0,i],[0,a])(c)}function Cp(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 Tp(e,t){return e>0&&e<t}var sC=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function zs(e,t){const n=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 Tr(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 kp=pp,iC=mp,aC=bp;const Ip=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kp,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(iC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ep,{}),u.jsx(aC,{})]}));Ip.displayName=kp.displayName;const Ep=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ma,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(vp,{className:"relative flex-1 rounded-full bg-border"})}));Ep.displayName=Ma.displayName;const Ap=25;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=No(),{loadThread:y}=_o(),{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),[j,L]=w.useState(null),[M,P]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const K=Array.isArray(f)?f:[];if(K.length>0){T.current=!0,C(K);return}x||(T.current=!1,C(K))},[f,x]),w.useEffect(()=>{if(!I.current)return;const K=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!K)return;let H=null,G=null;return H=requestAnimationFrame(()=>{G=requestAnimationFrame(()=>{K.scrollTop=A.current})}),()=>{H!==null&&cancelAnimationFrame(H),G!==null&&cancelAnimationFrame(G)}},[k]);const B=async K=>{try{h(K),await y(K),a==null||a(K),l==null||l(K)}catch(H){console.error("Failed to select thread:",H)}},R=async()=>{try{N(!0);const K=await g();K&&(c==null||c(K),a==null||a(K))}catch(K){console.error("Failed to create thread:",K)}finally{N(!1)}},J=async(K,H)=>{if(H.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const G=I.current.querySelector("[data-radix-scroll-area-viewport]");G&&(A.current=G.scrollTop)}try{await b(K),d==null||d(K)}catch(G){console.error("Failed to delete thread:",G)}}},z=(K,H)=>{H.stopPropagation(),L(K.threadId),P(K.title||`Thread ${K.threadId.slice(0,8)}`)},_=async K=>{if(M.trim())try{await S(K,M.trim()),L(null),P("")}catch(H){console.error("Failed to update title:",H)}},Y=()=>{L(null),P("")},X=(K,H)=>{K.key==="Enter"?_(H):K.key==="Escape"&&Y()},se=K=>{if(!K)return"";try{const H=new Date(K),$=new Date().getTime()-H.getTime(),q=Math.floor($/(1e3*60*60*24));return q===0?H.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):q===1?"Yesterday":q<7?`${q} days ago`:H.toLocaleDateString()}catch{return""}},ye=K=>K.title||`Thread ${K.threadId.slice(0,8)}`,Re=K=>{const H=ye(K);return H.length<=Ap?H:`${H.slice(0,Ap)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Ze,{onClick:R,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(Ip,{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((K,H)=>new Date(H.updatedAt||H.createdAt||"").getTime()-new Date(K.updatedAt||K.createdAt||"").getTime()).map(K=>u.jsxs("div",{onClick:()=>B(K.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===K.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===K.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:H=>H.stopPropagation(),children:[u.jsx(Ls,{value:M,onChange:H=>P(H.target.value),onKeyDown:H=>X(H,K.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>_(K.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Y,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:Re(K)}),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(K.updatedAt||K.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==K.threadId&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:H=>z(K,H),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:H=>J(K.threadId,H),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.Trash2,{size:12})})]})]}),i===K.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},K.threadId))})})]})}function kr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function lC(e){if(typeof e!="string")return;const t=e.trim();if(t)return bn(t)}function Np(){const e=[kr("__API_BASE_URL__"),kr("__CHAT_API_BASE_URL__"),kr("__CHAT_API_URL__")];for(const t of e){const n=lC(t);if(n)return n}}function _p(){const e=[kr("__API_AUTH_TOKEN__"),kr("__CHAT_API_KEY__"),kr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function jp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return bn(t);return bn()}function Rp(){const e={},t=Np(),n=_p();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Mp(){const e=Rp(),t=Nn.getAuthToken(),n=Np();return{apiBaseUrl:jp(e.baseUrl,Nn.baseUrl,n),apiKey:t||e.apiKey||_p()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Pp="chat-settings";function cC(){try{const e=localStorage.getItem(Pp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function uC(e){try{const t={...e,apiBaseUrl:bn(e.apiBaseUrl)};localStorage.setItem(Pp,JSON.stringify(t)),t.apiKey&&Nn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function dC(){const e=Mp(),t=cC(),n=Nn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:jp(Nn.baseUrl,r,e.apiBaseUrl)}}function fC(e){Nn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),uC(e)}var pC="Label",Op=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())}}));Op.displayName=pC;var Dp=Op;const hC=fo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Qt=v.forwardRef(({className:e,...t},n)=>u.jsx(Dp,{ref:n,className:te(hC(),e),...t}));Qt.displayName=Dp.displayName;function Lp(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 $p=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"}),mC="VisuallyHidden",gC=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...$p,...e.style}}));gC.displayName=mC;var xC=[" ","Enter","ArrowUp","ArrowDown"],yC=[" ","Enter"],or="Select",[Us,Hs,vC]=gi(or),[Ir,BT]=wn(or,[vC,Vo]),Ws=Vo(),[bC,Fn]=Ir(or),[wC,SC]=Ir(or),Fp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Ws(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Ro(c),[I,A]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:or}),[j,L]=fr({prop:i,defaultProp:a,onChange:l,caller:or}),M=v.useRef(null),P=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(R=>R.props.value).join(";");return u.jsx(eu,{...m,children:u.jsxs(bC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Sn(),value:j,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:M,disabled:p,children:[u.jsx(Us.Provider,{scope:t,children:u.jsx(wC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{N(J=>new Set(J).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{N(J=>{const z=new Set(J);return z.delete(R),z})},[]),children:n})}),P?u.jsxs(ch,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:R=>L(R.target.value),disabled:p,form:x,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Fp.displayName=or;var Bp="SelectTrigger",zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ws(n),i=Fn(Bp,n),a=i.disabled||r,l=Fe(t,i.onTriggerChange),c=Hs(n),d=v.useRef("touch"),[f,p,h]=dh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=fh(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(tu,{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":uh(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===" ")&&xC.includes(m.key)&&(x(),m.preventDefault())})})})});zp.displayName=Bp;var Up="SelectValue",Hp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Fn(Up,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:uh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Hp.displayName=Up;var CC="SelectIcon",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Wp.displayName=CC;var TC="SelectPortal",Vp=e=>u.jsx(Ko,{asChild:!0,...e});Vp.displayName=TC;var sr="SelectContent",Kp=v.forwardRef((e,t)=>{const n=Fn(sr,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?po.createPortal(u.jsx(qp,{scope:e.__scopeSelect,children:u.jsx(Us.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Gp,{...e,ref:t})});Kp.displayName=sr;var an=10,[qp,Bn]=Ir(sr),kC="SelectContentImpl",IC=Wn.createSlot("SelectContent.RemoveScroll"),Gp=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=Fn(sr,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Fe(t,G=>k(G)),[A,j]=v.useState(null),[L,M]=v.useState(null),P=Hs(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return $i(S)},[S]),vi();const R=v.useCallback(G=>{const[$,...q]=P().map(oe=>oe.ref.current),[Z]=q.slice(-1),le=document.activeElement;for(const oe of G)if(oe===le||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Z&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==le))return},[P,C]),J=v.useCallback(()=>R([A,S]),[R,A,S]);v.useEffect(()=>{F&&J()},[F,J]);const{onOpenChange:z,triggerPointerDownPosRef:_}=b;v.useEffect(()=>{if(S){let G={x:0,y:0};const $=Z=>{var le,oe;G={x:Math.abs(Math.round(Z.pageX)-(((le=_.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((oe=_.current)==null?void 0:oe.y)??0))}},q=Z=>{G.x<=10&&G.y<=10?Z.preventDefault():S.contains(Z.target)||z(!1),document.removeEventListener("pointermove",$),_.current=null};return _.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",q,{capture:!0})}}},[S,z,_]),v.useEffect(()=>{const G=()=>z(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[z]);const[Y,X]=dh(G=>{const $=P().filter(le=>!le.disabled),q=$.find(le=>le.ref.current===document.activeElement),Z=fh($,G,q);Z&&setTimeout(()=>Z.ref.current.focus())}),se=v.useCallback((G,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&(j(G),Z&&(B.current=!0))},[b.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Re=v.useCallback((G,$,q)=>{const Z=!B.current&&!q;(b.value!==void 0&&b.value===$||Z)&&M(G)},[b.value]),K=r==="popper"?La:Yp,H=K===La?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(qp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:ye,itemTextRefCallback:Re,focusSelectedItem:J,selectedItemText:L,position:r,isPositioned:F,searchRef:Y,children:u.jsx(ts,{as:IC,allowPinchZoom:!0,children:u.jsx(Po,{asChild:!0,trapped:b.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:de(o,G=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),G.preventDefault()}),children:u.jsx(Mo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(K,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:G=>G.preventDefault(),...g,...H,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,G=>{const $=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!$&&G.key.length===1&&X(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let Z=P().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(G.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const le=G.target,oe=Z.indexOf(le);Z=Z.slice(oe+1)}setTimeout(()=>R(Z)),G.preventDefault()}})})})})})})});Gp.displayName=kC;var EC="SelectItemAlignedPosition",Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Fn(sr,n),i=Bn(sr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Fe(t,I=>d(I)),p=Hs(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(),j=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const le=L.left-A.left,oe=j.left-le,_e=I.left-oe,Ue=I.width+_e,De=Math.max(Ue,A.width),Ge=window.innerWidth-an,He=ja(oe,[an,Math.max(an,Ge-De)]);a.style.minWidth=Ue+"px",a.style.left=He+"px"}else{const le=A.right-L.right,oe=window.innerWidth-j.right-le,_e=window.innerWidth-I.right-oe,Ue=I.width+_e,De=Math.max(Ue,A.width),Ge=window.innerWidth-an,He=ja(oe,[an,Math.max(an,Ge-De)]);a.style.minWidth=Ue+"px",a.style.right=He+"px"}const M=p(),P=window.innerHeight-an*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),R=parseInt(N.paddingTop,10),J=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),_=B+R+F+z+J,Y=Math.min(y.offsetHeight*5,_),X=window.getComputedStyle(m),se=parseInt(X.paddingTop,10),ye=parseInt(X.paddingBottom,10),Re=I.top+I.height/2-an,K=P-Re,H=y.offsetHeight/2,G=y.offsetTop+H,$=B+R+G,q=_-$;if($<=Re){const le=M.length>0&&y===M[M.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,_e=Math.max(K,H+(le?ye:0)+oe+J),Ue=$+_e;a.style.height=Ue+"px"}else{const le=M.length>0&&y===M[0].ref.current;a.style.top="0px";const _e=Math.max(Re,B+m.offsetTop+(le?se:0)+H)+q;a.style.height=_e+"px",m.scrollTop=$-Re+m.offsetTop}a.style.margin=`${an}px 0`,a.style.minHeight=Y+"px",a.style.maxHeight=P+"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(NC,{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}})})})});Yp.displayName=EC;var AC="SelectPopperPosition",La=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=an,...s}=e,i=Ws(n);return u.jsx(nu,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});La.displayName=AC;var[NC,$a]=Ir(sr,{}),Fa="SelectViewport",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Bn(Fa,n),i=$a(Fa,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(Us.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: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-an*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})})})]})});Xp.displayName=Fa;var Jp="SelectGroup",[_C,jC]=Ir(Jp),RC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sn();return u.jsx(_C,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});RC.displayName=Jp;var Zp="SelectLabel",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=jC(Zp,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});Qp.displayName=Zp;var Vs="SelectItem",[MC,eh]=Ir(Vs),th=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Fn(Vs,n),l=Bn(Vs,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=Sn(),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(MC,{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(Us.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: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===" "||(yC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});th.displayName=Vs;var co="SelectItemText",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Fn(co,n),a=Bn(co,n),l=eh(co,n),c=SC(co,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?po.createPortal(s.children,i.valueNode):null]})});nh.displayName=co;var rh="SelectItemIndicator",oh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return eh(rh,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});oh.displayName=rh;var Ba="SelectScrollUpButton",sh=v.forwardRef((e,t)=>{const n=Bn(Ba,e.__scopeSelect),r=$a(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=Fe(t,r.onScrollButtonChange);return Tt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.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(ah,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});sh.displayName=Ba;var za="SelectScrollDownButton",ih=v.forwardRef((e,t)=>{const n=Bn(za,e.__scopeSelect),r=$a(za,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(ah,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ih.displayName=za;var ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Bn("SelectScrollButton",n),i=v.useRef(null),a=Hs(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: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()})})}),PC="SelectSeparator",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});lh.displayName=PC;var Ua="SelectArrow",OC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ws(n),s=Fn(Ua,n),i=Bn(Ua,n);return s.open&&i.position==="popper"?u.jsx(ru,{...o,...r,ref:t}):null});OC.displayName=Ua;var DC="SelectBubbleInput",ch=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Fe(r,o),i=Lp(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:{...$p,...n.style},ref:s,defaultValue:t})});ch.displayName=DC;function uh(e){return e===""||e===void 0}function dh(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 fh(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=LC(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 LC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var $C=Fp,ph=zp,FC=Hp,BC=Wp,zC=Vp,hh=Kp,UC=Xp,mh=Qp,gh=th,HC=nh,WC=oh,xh=sh,yh=ih,vh=lh;const bh=$C,wh=FC,Ha=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ph,{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(BC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=ph.displayName;const Sh=v.forwardRef(({className:e,...t},n)=>u.jsx(xh,{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"})}));Sh.displayName=xh.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.ChevronDown,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Wa=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(zC,{children:u.jsxs(hh,{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(Sh,{}),u.jsx(UC,{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(Ch,{})]})}));Wa.displayName=hh.displayName;const VC=v.forwardRef(({className:e,...t},n)=>u.jsx(mh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));VC.displayName=mh.displayName;const ir=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gh,{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(WC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(HC,{children:t})]}));ir.displayName=gh.displayName;const KC=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));KC.displayName=vh.displayName;var qC="Separator",Th="horizontal",GC=["horizontal","vertical"],kh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Th,...o}=e,s=YC(r)?r:Th,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})});kh.displayName=qC;function YC(e){return GC.includes(e)}var Ih=kh;const Eh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Ih,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Eh.displayName=Ih.displayName;const XC=Ff,JC=lS,ZC=Bf,Ah=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));Ah.displayName=Is.displayName;const QC=fo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Nh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(ZC,{children:[u.jsx(Ah,{}),u.jsxs(Es,{ref:o,className:te(QC({side:e}),t),...r,children:[n,u.jsxs(zf,{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"})]})]})]}));Nh.displayName=Es.displayName;const _h=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});_h.displayName="SheetHeader";const jh=v.forwardRef(({className:e,...t},n)=>u.jsx(nr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));jh.displayName=nr.displayName;const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Rh.displayName=As.displayName;var Ks="Switch",[eT,zT]=wn(Ks),[tT,nT]=eT(Ks),Mh=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]=fr({prop:o,defaultProp:s??!1,onChange:c,caller:Ks});return u.jsxs(tT,{scope:n,checked:g,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Lh(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(Dh,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Mh.displayName=Ks;var Ph="SwitchThumb",Oh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=nT(Ph,n);return u.jsx(Ne.span,{"data-state":Lh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Oh.displayName=Ph;var rT="SwitchBubbleInput",Dh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Fe(i,s),l=Lp(n),c=Wc(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}})});Dh.displayName=rT;function Lh(e){return e?"checked":"unchecked"}var $h=Mh,oT=Oh;const zn=v.forwardRef(({className:e,...t},n)=>u.jsx($h,{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(oT,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));zn.displayName=$h.displayName;const sT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function iT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Ea();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(sT),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(XC,{open:r,onOpenChange:o,children:[u.jsx(JC,{asChild:!0,children:u.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(xf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Nh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(_h,{children:[u.jsx(jh,{children:"Chat Settings"}),u.jsx(Rh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(so,{children:[u.jsx(io,{className:"pb-3",children:u.jsxs(ao,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(lo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ls,{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(Ze,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(zn,{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(Qt,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ls,{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(Ze,{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(so,{children:[u.jsx(io,{className:"pb-3",children:u.jsxs(ao,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(lo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(bh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Ha,{children:u.jsx(wh,{})}),u.jsxs(Wa,{children:[u.jsx(ir,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ir,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ir,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"theme",children:"Theme"}),u.jsxs(bh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Ha,{children:u.jsx(wh,{})}),u.jsxs(Wa,{children:[u.jsx(ir,{value:"light",children:"Light"}),u.jsx(ir,{value:"dark",children:"Dark"}),u.jsx(ir,{value:"system",children:"System"})]})]})]}),u.jsx(Eh,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(zn,{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(Qt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(zn,{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(Qt,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(so,{children:[u.jsx(io,{className:"pb-3",children:u.jsxs(ao,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(lo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(zn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(zn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(zn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ze,{variant:"outline",onClick:h,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ze,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Ze,{onClick:p,disabled:!c,children:[u.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function aT({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(jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ds,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(jo,{...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(Da,{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(Ds,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(jo,{...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(Da,{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(Ds,{onError:s.onError,enableFileUpload:!0})})]})})}Te.ChatApi=Fl,Te.ChatInput=lc,Te.ChatInterface=Ds,Te.ChatProviders=jo,Te.ChatSettings=iT,Te.MarkdownContent=oo,Te.MessageComponent=Os,Te.MessageList=_a,Te.ThreadManager=Da,Te.applySettings=fC,Te.buildMessagePreviewMap=Kl,Te.chatApiClient=Nn,Te.default=aT,Te.del=$l,Te.get=Kt,Te.getChatToken=Ol,Te.getCurrentSettings=dC,Te.getDefaultApiConfig=Rp,Te.getDefaultChatSettings=Mp,Te.onChatTokenChanged=Dl,Te.post=li,Te.put=Ll,Te.setChatToken=ko,Te.useApi=ci,Te.useChatStream=ql,Te.useMessagesReducer=Gl,Te.useStream=ic,Te.useThreadState=_o,Te.useThreads=No,Object.defineProperties(Te,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});