teodor-new-chat-ui 4.3.113 → 4.3.115

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(Pe,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):(Pe=typeof globalThis<"u"?globalThis:Pe||self,w(Pe.NewChatUI={},Pe.React,Pe.LucideReact,Pe.reactSlot,Pe.classVarianceAuthority,Pe.clsx,Pe.tailwindMerge,Pe.ReactDOM))})(this,function(Pe,w,pe,hr,Uo,Bm,Hm,Ti){"use strict";var oT=Object.defineProperty;var sT=(Pe,w,pe)=>w in Pe?oT(Pe,w,{enumerable:!0,configurable:!0,writable:!0,value:pe}):Pe[w]=pe;var Fm=(Pe,w,pe)=>sT(Pe,typeof w!="symbol"?w+"":w,pe);function Dl(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=Dl(w),Wo=Dl(Ti);var Ei={exports:{}},to={};/**
1
+ (function(je,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):(je=typeof globalThis<"u"?globalThis:je||self,w(je.NewChatUI={},je.React,je.LucideReact,je.reactSlot,je.classVarianceAuthority,je.clsx,je.tailwindMerge,je.ReactDOM))})(this,function(je,w,he,xr,Go,Bm,Hm,ji){"use strict";var oT=Object.defineProperty;var sT=(je,w,he)=>w in je?oT(je,w,{enumerable:!0,configurable:!0,writable:!0,value:he}):je[w]=he;var $m=(je,w,he)=>sT(je,typeof w!="symbol"?w+"":w,he);function Hl(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=Hl(w),Yo=Hl(ji);var Ri={exports:{}},so={};/**
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 Ll;function Um(){if(Ll)return to;Ll=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={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return to.Fragment=n,to.jsx=i,to.jsxs=i,to}var no={};/**
9
+ */var Ul;function Um(){if(Ul)return so;Ul=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={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return so.Fragment=n,so.jsx=i,so.jsxs=i,so}var io={};/**
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 $l;function Wm(){return $l||($l=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"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),g=Symbol.iterator,x="@@iterator";function y(I){if(I===null||typeof I!="object")return null;var q=g&&I[g]||I[x];return typeof q=="function"?q:null}var m=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(I){{for(var q=arguments.length,ue=new Array(q>1?q-1:0),ke=1;ke<q;ke++)ue[ke-1]=arguments[ke];S("error",I,ue)}}function S(I,q,ue){{var ke=m.ReactDebugCurrentFrame,Xe=ke.getStackAddendum();Xe!==""&&(q+="%s",ue=ue.concat([Xe]));var at=ue.map(function(Ke){return String(Ke)});at.unshift("Warning: "+q),Function.prototype.apply.call(console[I],console,at)}}var T=!1,k=!1,C=!1,E=!1,R=!1,_;_=Symbol.for("react.module.reference");function j(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||R||I===o||I===c||I===d||E||I===p||T||k||C||typeof I=="object"&&I!==null&&(I.$$typeof===h||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===_||I.getModuleId!==void 0))}function L(I,q,ue){var ke=I.displayName;if(ke)return ke;var Xe=q.displayName||q.name||"";return Xe!==""?ue+"("+Xe+")":ue}function z(I){return I.displayName||"Context"}function V(I){if(I==null)return null;if(typeof I.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var q=I;return z(q)+".Consumer";case i:var ue=I;return z(ue._context)+".Provider";case l:return L(I,I.render,"ForwardRef");case f:var ke=I.displayName||null;return ke!==null?ke:V(I.type)||"Memo";case h:{var Xe=I,at=Xe._payload,Ke=Xe._init;try{return V(Ke(at))}catch{return null}}}return null}var O=Object.assign,H=0,P,W,F,$,ne,oe,we;function Ne(){}Ne.__reactDisabledLog=!0;function Z(){{if(H===0){P=console.log,W=console.info,F=console.warn,$=console.error,ne=console.group,oe=console.groupCollapsed,we=console.groupEnd;var I={configurable:!0,enumerable:!0,value:Ne,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}H++}}function ie(){{if(H--,H===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},I,{value:P}),info:O({},I,{value:W}),warn:O({},I,{value:F}),error:O({},I,{value:$}),group:O({},I,{value:ne}),groupCollapsed:O({},I,{value:oe}),groupEnd:O({},I,{value:we})})}H<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Te=m.ReactCurrentDispatcher,ee;function D(I,q,ue){{if(ee===void 0)try{throw Error()}catch(Xe){var ke=Xe.stack.trim().match(/\n( *(at )?)/);ee=ke&&ke[1]||""}return`
18
- `+ee+I}}var G=!1,ae;{var fe=typeof WeakMap=="function"?WeakMap:Map;ae=new fe}function B(I,q){if(!I||G)return"";{var ue=ae.get(I);if(ue!==void 0)return ue}var ke;G=!0;var Xe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var at;at=Te.current,Te.current=null,Z();try{if(q){var Ke=function(){throw Error()};if(Object.defineProperty(Ke.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Ke,[])}catch(de){ke=de}Reflect.construct(I,[],Ke)}else{try{Ke.call()}catch(de){ke=de}I.call(Ke.prototype)}}else{try{throw Error()}catch(de){ke=de}I()}}catch(de){if(de&&ke&&typeof de.stack=="string"){for(var $e=de.stack.split(`
19
- `),jt=ke.stack.split(`
20
- `),vt=$e.length-1,pt=jt.length-1;vt>=1&&pt>=0&&$e[vt]!==jt[pt];)pt--;for(;vt>=1&&pt>=0;vt--,pt--)if($e[vt]!==jt[pt]){if(vt!==1||pt!==1)do if(vt--,pt--,pt<0||$e[vt]!==jt[pt]){var qt=`
21
- `+$e[vt].replace(" at new "," at ");return I.displayName&&qt.includes("<anonymous>")&&(qt=qt.replace("<anonymous>",I.displayName)),typeof I=="function"&&ae.set(I,qt),qt}while(vt>=1&&pt>=0);break}}}finally{G=!1,Te.current=at,ie(),Error.prepareStackTrace=Xe}var Gt=I?I.displayName||I.name:"",J=Gt?D(Gt):"";return typeof I=="function"&&ae.set(I,J),J}function le(I,q,ue){return B(I,!1)}function Q(I){var q=I.prototype;return!!(q&&q.isReactComponent)}function Ae(I,q,ue){if(I==null)return"";if(typeof I=="function")return B(I,Q(I));if(typeof I=="string")return D(I);switch(I){case c:return D("Suspense");case d:return D("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return le(I.render);case f:return Ae(I.type,q,ue);case h:{var ke=I,Xe=ke._payload,at=ke._init;try{return Ae(at(Xe),q,ue)}catch{}}}return""}var ve=Object.prototype.hasOwnProperty,Re={},Ve=m.ReactDebugCurrentFrame;function Qe(I){if(I){var q=I._owner,ue=Ae(I.type,I._source,q?q.type:null);Ve.setExtraStackFrame(ue)}else Ve.setExtraStackFrame(null)}function et(I,q,ue,ke,Xe){{var at=Function.call.bind(ve);for(var Ke in I)if(at(I,Ke)){var $e=void 0;try{if(typeof I[Ke]!="function"){var jt=Error((ke||"React class")+": "+ue+" type `"+Ke+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[Ke]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw jt.name="Invariant Violation",jt}$e=I[Ke](q,Ke,ke,ue,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(vt){$e=vt}$e&&!($e instanceof Error)&&(Qe(Xe),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",ke||"React class",ue,Ke,typeof $e),Qe(null)),$e instanceof Error&&!($e.message in Re)&&(Re[$e.message]=!0,Qe(Xe),b("Failed %s type: %s",ue,$e.message),Qe(null))}}}var Se=Array.isArray;function nt(I){return Se(I)}function ut(I){{var q=typeof Symbol=="function"&&Symbol.toStringTag,ue=q&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ue}}function rt(I){try{return Ye(I),!1}catch{return!0}}function Ye(I){return""+I}function It(I){if(rt(I))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ut(I)),Ye(I)}var dt=m.ReactCurrentOwner,kt={key:!0,ref:!0,__self:!0,__source:!0},Nt,tt;function He(I){if(ve.call(I,"ref")){var q=Object.getOwnPropertyDescriptor(I,"ref").get;if(q&&q.isReactWarning)return!1}return I.ref!==void 0}function Tt(I){if(ve.call(I,"key")){var q=Object.getOwnPropertyDescriptor(I,"key").get;if(q&&q.isReactWarning)return!1}return I.key!==void 0}function Vt(I,q){typeof I.ref=="string"&&dt.current}function zt(I,q){{var ue=function(){Nt||(Nt=!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))};ue.isReactWarning=!0,Object.defineProperty(I,"key",{get:ue,configurable:!0})}}function Kt(I,q){{var ue=function(){tt||(tt=!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))};ue.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ue,configurable:!0})}}var st=function(I,q,ue,ke,Xe,at,Ke){var $e={$$typeof:t,type:I,key:q,ref:ue,props:Ke,_owner:at};return $e._store={},Object.defineProperty($e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty($e,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ke}),Object.defineProperty($e,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Xe}),Object.freeze&&(Object.freeze($e.props),Object.freeze($e)),$e};function Le(I,q,ue,ke,Xe){{var at,Ke={},$e=null,jt=null;ue!==void 0&&(It(ue),$e=""+ue),Tt(q)&&(It(q.key),$e=""+q.key),He(q)&&(jt=q.ref,Vt(q,Xe));for(at in q)ve.call(q,at)&&!kt.hasOwnProperty(at)&&(Ke[at]=q[at]);if(I&&I.defaultProps){var vt=I.defaultProps;for(at in vt)Ke[at]===void 0&&(Ke[at]=vt[at])}if($e||jt){var pt=typeof I=="function"?I.displayName||I.name||"Unknown":I;$e&&zt(Ke,pt),jt&&Kt(Ke,pt)}return st(I,$e,jt,Xe,ke,dt.current,Ke)}}var _t=m.ReactCurrentOwner,yt=m.ReactDebugCurrentFrame;function X(I){if(I){var q=I._owner,ue=Ae(I.type,I._source,q?q.type:null);yt.setExtraStackFrame(ue)}else yt.setExtraStackFrame(null)}var Ce;Ce=!1;function ge(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function xt(){{if(_t.current){var I=V(_t.current.type);if(I)return`
17
+ */var Wl;function Wm(){return Wl||(Wl=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"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),g=Symbol.iterator,x="@@iterator";function y(I){if(I===null||typeof I!="object")return null;var G=g&&I[g]||I[x];return typeof G=="function"?G:null}var m=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(I){{for(var G=arguments.length,ie=new Array(G>1?G-1:0),Ce=1;Ce<G;Ce++)ie[Ce-1]=arguments[Ce];S("error",I,ie)}}function S(I,G,ie){{var Ce=m.ReactDebugCurrentFrame,Ye=Ce.getStackAddendum();Ye!==""&&(G+="%s",ie=ie.concat([Ye]));var ct=ie.map(function(Ke){return String(Ke)});ct.unshift("Warning: "+G),Function.prototype.apply.call(console[I],console,ct)}}var T=!1,k=!1,C=!1,E=!1,R=!1,_;_=Symbol.for("react.module.reference");function j(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||R||I===o||I===c||I===d||E||I===p||T||k||C||typeof I=="object"&&I!==null&&(I.$$typeof===h||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===_||I.getModuleId!==void 0))}function D(I,G,ie){var Ce=I.displayName;if(Ce)return Ce;var Ye=G.displayName||G.name||"";return Ye!==""?ie+"("+Ye+")":ie}function z(I){return I.displayName||"Context"}function W(I){if(I==null)return null;if(typeof I.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case d:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var G=I;return z(G)+".Consumer";case i:var ie=I;return z(ie._context)+".Provider";case l:return D(I,I.render,"ForwardRef");case f:var Ce=I.displayName||null;return Ce!==null?Ce:W(I.type)||"Memo";case h:{var Ye=I,ct=Ye._payload,Ke=Ye._init;try{return W(Ke(ct))}catch{return null}}}return null}var O=Object.assign,B=0,P,V,$,F,ee,te,ve;function Ie(){}Ie.__reactDisabledLog=!0;function Z(){{if(B===0){P=console.log,V=console.info,$=console.warn,F=console.error,ee=console.group,te=console.groupCollapsed,ve=console.groupEnd;var I={configurable:!0,enumerable:!0,value:Ie,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}B++}}function de(){{if(B--,B===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},I,{value:P}),info:O({},I,{value:V}),warn:O({},I,{value:$}),error:O({},I,{value:F}),group:O({},I,{value:ee}),groupCollapsed:O({},I,{value:te}),groupEnd:O({},I,{value:ve})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var we=m.ReactCurrentDispatcher,ne;function L(I,G,ie){{if(ne===void 0)try{throw Error()}catch(Ye){var Ce=Ye.stack.trim().match(/\n( *(at )?)/);ne=Ce&&Ce[1]||""}return`
18
+ `+ne+I}}var J=!1,se;{var ue=typeof WeakMap=="function"?WeakMap:Map;se=new ue}function le(I,G){if(!I||J)return"";{var ie=se.get(I);if(ie!==void 0)return ie}var Ce;J=!0;var Ye=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ct;ct=we.current,we.current=null,Z();try{if(G){var Ke=function(){throw Error()};if(Object.defineProperty(Ke.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Ke,[])}catch(Ut){Ce=Ut}Reflect.construct(I,[],Ke)}else{try{Ke.call()}catch(Ut){Ce=Ut}I.call(Ke.prototype)}}else{try{throw Error()}catch(Ut){Ce=Ut}I()}}catch(Ut){if(Ut&&Ce&&typeof Ut.stack=="string"){for(var Ue=Ut.stack.split(`
19
+ `),Pt=Ce.stack.split(`
20
+ `),gt=Ue.length-1,xt=Pt.length-1;gt>=1&&xt>=0&&Ue[gt]!==Pt[xt];)xt--;for(;gt>=1&&xt>=0;gt--,xt--)if(Ue[gt]!==Pt[xt]){if(gt!==1||xt!==1)do if(gt--,xt--,xt<0||Ue[gt]!==Pt[xt]){var Gt=`
21
+ `+Ue[gt].replace(" at new "," at ");return I.displayName&&Gt.includes("<anonymous>")&&(Gt=Gt.replace("<anonymous>",I.displayName)),typeof I=="function"&&se.set(I,Gt),Gt}while(gt>=1&&xt>=0);break}}}finally{J=!1,we.current=ct,de(),Error.prepareStackTrace=Ye}var Yt=I?I.displayName||I.name:"",un=Yt?L(Yt):"";return typeof I=="function"&&se.set(I,un),un}function Me(I,G,ie){return le(I,!1)}function U(I){var G=I.prototype;return!!(G&&G.isReactComponent)}function ye(I,G,ie){if(I==null)return"";if(typeof I=="function")return le(I,U(I));if(typeof I=="string")return L(I);switch(I){case c:return L("Suspense");case d:return L("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return Me(I.render);case f:return ye(I.type,G,ie);case h:{var Ce=I,Ye=Ce._payload,ct=Ce._init;try{return ye(ct(Ye),G,ie)}catch{}}}return""}var _e=Object.prototype.hasOwnProperty,Pe={},et=m.ReactDebugCurrentFrame;function nt(I){if(I){var G=I._owner,ie=ye(I.type,I._source,G?G.type:null);et.setExtraStackFrame(ie)}else et.setExtraStackFrame(null)}function Ze(I,G,ie,Ce,Ye){{var ct=Function.call.bind(_e);for(var Ke in I)if(ct(I,Ke)){var Ue=void 0;try{if(typeof I[Ke]!="function"){var Pt=Error((Ce||"React class")+": "+ie+" type `"+Ke+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[Ke]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Pt.name="Invariant Violation",Pt}Ue=I[Ke](G,Ke,Ce,ie,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(gt){Ue=gt}Ue&&!(Ue instanceof Error)&&(nt(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,Ke,typeof Ue),nt(null)),Ue instanceof Error&&!(Ue.message in Pe)&&(Pe[Ue.message]=!0,nt(Ye),b("Failed %s type: %s",ie,Ue.message),nt(null))}}}var be=Array.isArray;function Qe(I){return be(I)}function it(I){{var G=typeof Symbol=="function"&&Symbol.toStringTag,ie=G&&I[Symbol.toStringTag]||I.constructor.name||"Object";return ie}}function rt(I){try{return Be(I),!1}catch{return!0}}function Be(I){return""+I}function wt(I){if(rt(I))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",it(I)),Be(I)}var mt=m.ReactCurrentOwner,jt={key:!0,ref:!0,__self:!0,__source:!0},Dt,bt;function He(I){if(_e.call(I,"ref")){var G=Object.getOwnPropertyDescriptor(I,"ref").get;if(G&&G.isReactWarning)return!1}return I.ref!==void 0}function St(I){if(_e.call(I,"key")){var G=Object.getOwnPropertyDescriptor(I,"key").get;if(G&&G.isReactWarning)return!1}return I.key!==void 0}function Ct(I,G){typeof I.ref=="string"&&mt.current}function Lt(I,G){{var ie=function(){Dt||(Dt=!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)",G))};ie.isReactWarning=!0,Object.defineProperty(I,"key",{get:ie,configurable:!0})}}function Ft(I,G){{var ie=function(){bt||(bt=!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)",G))};ie.isReactWarning=!0,Object.defineProperty(I,"ref",{get:ie,configurable:!0})}}var at=function(I,G,ie,Ce,Ye,ct,Ke){var Ue={$$typeof:t,type:I,key:G,ref:ie,props:Ke,_owner:ct};return Ue._store={},Object.defineProperty(Ue._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Ue,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Ce}),Object.defineProperty(Ue,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ye}),Object.freeze&&(Object.freeze(Ue.props),Object.freeze(Ue)),Ue};function De(I,G,ie,Ce,Ye){{var ct,Ke={},Ue=null,Pt=null;ie!==void 0&&(wt(ie),Ue=""+ie),St(G)&&(wt(G.key),Ue=""+G.key),He(G)&&(Pt=G.ref,Ct(G,Ye));for(ct in G)_e.call(G,ct)&&!jt.hasOwnProperty(ct)&&(Ke[ct]=G[ct]);if(I&&I.defaultProps){var gt=I.defaultProps;for(ct in gt)Ke[ct]===void 0&&(Ke[ct]=gt[ct])}if(Ue||Pt){var xt=typeof I=="function"?I.displayName||I.name||"Unknown":I;Ue&&Lt(Ke,xt),Pt&&Ft(Ke,xt)}return at(I,Ue,Pt,Ye,Ce,mt.current,Ke)}}var Rt=m.ReactCurrentOwner,kt=m.ReactDebugCurrentFrame;function q(I){if(I){var G=I._owner,ie=ye(I.type,I._source,G?G.type:null);kt.setExtraStackFrame(ie)}else kt.setExtraStackFrame(null)}var ke;ke=!1;function xe(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function ot(){{if(Rt.current){var I=W(Rt.current.type);if(I)return`
22
22
 
23
- Check the render method of \``+I+"`."}return""}}function ft(I){return""}var ht={};function Be(I){{var q=xt();if(!q){var ue=typeof I=="string"?I:I.displayName||I.name;ue&&(q=`
23
+ Check the render method of \``+I+"`."}return""}}function ft(I){return""}var tt={};function Fe(I){{var G=ot();if(!G){var ie=typeof I=="string"?I:I.displayName||I.name;ie&&(G=`
24
24
 
25
- Check the top-level render call using <`+ue+">.")}return q}}function Ft(I,q){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ue=Be(q);if(ht[ue])return;ht[ue]=!0;var ke="";I&&I._owner&&I._owner!==_t.current&&(ke=" It was passed a child from "+V(I._owner.type)+"."),X(I),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ue,ke),X(null)}}function Oe(I,q){{if(typeof I!="object")return;if(nt(I))for(var ue=0;ue<I.length;ue++){var ke=I[ue];ge(ke)&&Ft(ke,q)}else if(ge(I))I._store&&(I._store.validated=!0);else if(I){var Xe=y(I);if(typeof Xe=="function"&&Xe!==I.entries)for(var at=Xe.call(I),Ke;!(Ke=at.next()).done;)ge(Ke.value)&&Ft(Ke.value,q)}}}function it(I){{var q=I.type;if(q==null||typeof q=="string")return;var ue;if(typeof q=="function")ue=q.propTypes;else if(typeof q=="object"&&(q.$$typeof===l||q.$$typeof===f))ue=q.propTypes;else return;if(ue){var ke=V(q);et(ue,I.props,"prop",ke,I)}else if(q.PropTypes!==void 0&&!Ce){Ce=!0;var Xe=V(q);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Xe||"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 ar(I){{for(var q=Object.keys(I.props),ue=0;ue<q.length;ue++){var ke=q[ue];if(ke!=="children"&&ke!=="key"){X(I),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ke),X(null);break}}I.ref!==null&&(X(I),b("Invalid attribute `ref` supplied to `React.Fragment`."),X(null))}}var jr={};function lr(I,q,ue,ke,Xe,at){{var Ke=j(I);if(!Ke){var $e="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&($e+=" 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 jt=ft();jt?$e+=jt:$e+=xt();var vt;I===null?vt="null":nt(I)?vt="array":I!==void 0&&I.$$typeof===t?(vt="<"+(V(I.type)||"Unknown")+" />",$e=" Did you accidentally export a JSX literal instead of a component?"):vt=typeof I,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",vt,$e)}var pt=Le(I,q,ue,Xe,at);if(pt==null)return pt;if(Ke){var qt=q.children;if(qt!==void 0)if(ke)if(nt(qt)){for(var Gt=0;Gt<qt.length;Gt++)Oe(qt[Gt],I);Object.freeze&&Object.freeze(qt)}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 Oe(qt,I)}if(ve.call(q,"key")){var J=V(I),de=Object.keys(q).filter(function(Ot){return Ot!=="key"}),he=de.length>0?"{key: someKey, "+de.join(": ..., ")+": ...}":"{key: someKey}";if(!jr[J+he]){var wt=de.length>0?"{"+de.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+ie+">.")}return G}}function en(I,G){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var ie=Fe(G);if(tt[ie])return;tt[ie]=!0;var Ce="";I&&I._owner&&I._owner!==Rt.current&&(Ce=" It was passed a child from "+W(I._owner.type)+"."),q(I),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',ie,Ce),q(null)}}function $e(I,G){{if(typeof I!="object")return;if(Qe(I))for(var ie=0;ie<I.length;ie++){var Ce=I[ie];xe(Ce)&&en(Ce,G)}else if(xe(I))I._store&&(I._store.validated=!0);else if(I){var Ye=y(I);if(typeof Ye=="function"&&Ye!==I.entries)for(var ct=Ye.call(I),Ke;!(Ke=ct.next()).done;)xe(Ke.value)&&en(Ke.value,G)}}}function ht(I){{var G=I.type;if(G==null||typeof G=="string")return;var ie;if(typeof G=="function")ie=G.propTypes;else if(typeof G=="object"&&(G.$$typeof===l||G.$$typeof===f))ie=G.propTypes;else return;if(ie){var Ce=W(G);Ze(ie,I.props,"prop",Ce,I)}else if(G.PropTypes!==void 0&&!ke){ke=!0;var Ye=W(G);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Ye||"Unknown")}typeof G.getDefaultProps=="function"&&!G.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function On(I){{for(var G=Object.keys(I.props),ie=0;ie<G.length;ie++){var Ce=G[ie];if(Ce!=="children"&&Ce!=="key"){q(I),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Ce),q(null);break}}I.ref!==null&&(q(I),b("Invalid attribute `ref` supplied to `React.Fragment`."),q(null))}}var Vn={};function hr(I,G,ie,Ce,Ye,ct){{var Ke=j(I);if(!Ke){var Ue="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(Ue+=" 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 Pt=ft();Pt?Ue+=Pt:Ue+=ot();var gt;I===null?gt="null":Qe(I)?gt="array":I!==void 0&&I.$$typeof===t?(gt="<"+(W(I.type)||"Unknown")+" />",Ue=" Did you accidentally export a JSX literal instead of a component?"):gt=typeof I,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",gt,Ue)}var xt=De(I,G,ie,Ye,ct);if(xt==null)return xt;if(Ke){var Gt=G.children;if(Gt!==void 0)if(Ce)if(Qe(Gt)){for(var Yt=0;Yt<Gt.length;Yt++)$e(Gt[Yt],I);Object.freeze&&Object.freeze(Gt)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else $e(Gt,I)}if(_e.call(G,"key")){var un=W(I),Ut=Object.keys(G).filter(function(ce){return ce!=="key"}),Y=Ut.length>0?"{key: someKey, "+Ut.join(": ..., ")+": ...}":"{key: someKey}";if(!Vn[un+Y]){var fe=Ut.length>0?"{"+Ut.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} />`,he,J,wt,J),jr[J+he]=!0}}return I===r?ar(pt):it(pt),pt}}function Rr(I,q,ue){return lr(I,q,ue,!0)}function Pr(I,q,ue){return lr(I,q,ue,!1)}var Kn=Pr,Qr=Rr;no.Fragment=r,no.jsx=Kn,no.jsxs=Qr}()),no}process.env.NODE_ENV==="production"?Ei.exports=Um():Ei.exports=Wm();var u=Ei.exports;function Fl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Vm}=Object.prototype,{getPrototypeOf:Ii}=Object,{iterator:Vo,toStringTag:zl}=Symbol,Ko=(e=>t=>{const n=Vm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),wn=e=>(e=e.toLowerCase(),t=>Ko(t)===e),qo=e=>t=>typeof t===e,{isArray:Mr}=Array,Dr=qo("undefined");function ro(e){return e!==null&&!Dr(e)&&e.constructor!==null&&!Dr(e.constructor)&&nn(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Bl=wn("ArrayBuffer");function Km(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Bl(e.buffer),t}const qm=qo("string"),nn=qo("function"),Hl=qo("number"),oo=e=>e!==null&&typeof e=="object",Gm=e=>e===!0||e===!1,Go=e=>{if(Ko(e)!=="object")return!1;const t=Ii(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(zl in e)&&!(Vo in e)},Xm=e=>{if(!oo(e)||ro(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Ym=wn("Date"),Jm=wn("File"),Zm=wn("Blob"),Qm=wn("FileList"),eg=e=>oo(e)&&nn(e.pipe),tg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||nn(e.append)&&((t=Ko(e))==="formdata"||t==="object"&&nn(e.toString)&&e.toString()==="[object FormData]"))},ng=wn("URLSearchParams"),[rg,og,sg,ig]=["ReadableStream","Request","Response","Headers"].map(wn),ag=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function so(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Mr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(ro(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 Ul(e,t){if(ro(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 pr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Wl=e=>!Dr(e)&&e!==pr;function Ni(){const{caseless:e,skipUndefined:t}=Wl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Ul(n,s)||s;Go(n[i])&&Go(o)?n[i]=Ni(n[i],o):Go(o)?n[i]=Ni({},o):Mr(o)?n[i]=o.slice():(!t||!Dr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&so(arguments[o],r);return n}const lg=(e,t,n,{allOwnKeys:r}={})=>(so(t,(o,s)=>{n&&nn(o)?e[s]=Fl(o,n):e[s]=o},{allOwnKeys:r}),e),cg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),ug=(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)},dg=(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&&Ii(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},fg=(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},hg=e=>{if(!e)return null;if(Mr(e))return e;let t=e.length;if(!Hl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},pg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Ii(Uint8Array)),mg=(e,t)=>{const r=(e&&e[Vo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},gg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},xg=wn("HTMLFormElement"),yg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Vl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),vg=wn("RegExp"),Kl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};so(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wg=e=>{Kl(e,(t,n)=>{if(nn(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(nn(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+"'")})}})},bg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Mr(e)?r(e):r(String(e).split(t)),n},Sg=()=>{},Cg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function kg(e){return!!(e&&nn(e.append)&&e[zl]==="FormData"&&e[Vo])}const Tg=e=>{const t=new Array(10),n=(r,o)=>{if(oo(r)){if(t.indexOf(r)>=0)return;if(ro(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Mr(r)?[]:{};return so(r,(i,a)=>{const l=n(i,o+1);!Dr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Eg=wn("AsyncFunction"),Ig=e=>e&&(oo(e)||nn(e))&&nn(e.then)&&nn(e.catch),ql=((e,t)=>e?setImmediate:t?((n,r)=>(pr.addEventListener("message",({source:o,data:s})=>{o===pr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),pr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",nn(pr.postMessage)),Ng=typeof queueMicrotask<"u"?queueMicrotask.bind(pr):typeof process<"u"&&process.nextTick||ql,M={isArray:Mr,isArrayBuffer:Bl,isBuffer:ro,isFormData:tg,isArrayBufferView:Km,isString:qm,isNumber:Hl,isBoolean:Gm,isObject:oo,isPlainObject:Go,isEmptyObject:Xm,isReadableStream:rg,isRequest:og,isResponse:sg,isHeaders:ig,isUndefined:Dr,isDate:Ym,isFile:Jm,isBlob:Zm,isRegExp:vg,isFunction:nn,isStream:eg,isURLSearchParams:ng,isTypedArray:pg,isFileList:Qm,forEach:so,merge:Ni,extend:lg,trim:ag,stripBOM:cg,inherits:ug,toFlatObject:dg,kindOf:Ko,kindOfTest:wn,endsWith:fg,toArray:hg,forEachEntry:mg,matchAll:gg,isHTMLForm:xg,hasOwnProperty:Vl,hasOwnProp:Vl,reduceDescriptors:Kl,freezeMethods:wg,toObjectSet:bg,toCamelCase:yg,noop:Sg,toFiniteNumber:Cg,findKey:Ul,global:pr,isContextDefined:Wl,isSpecCompliantForm:kg,toJSONObject:Tg,isAsyncFn:Eg,isThenable:Ig,setImmediate:ql,asap:Ng,isIterable:e=>e!=null&&nn(e[Vo])};function Fe(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}M.inherits(Fe,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:M.toJSONObject(this.config),code:this.code,status:this.status}}});const Gl=Fe.prototype,Xl={};["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=>{Xl[e]={value:e}}),Object.defineProperties(Fe,Xl),Object.defineProperty(Gl,"isAxiosError",{value:!0}),Fe.from=(e,t,n,r,o,s)=>{const i=Object.create(Gl);M.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Fe.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 Ag=null;function Ai(e){return M.isPlainObject(e)||M.isArray(e)}function Yl(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function Jl(e,t,n){return e?e.concat(t).map(function(o,s){return o=Yl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function _g(e){return M.isArray(e)&&!e.some(Ai)}const jg=M.toFlatObject(M,{},null,function(t){return/^is[A-Z]/.test(t)});function Xo(e,t,n){if(!M.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=M.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,y){return!M.isUndefined(y[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&M.isSpecCompliantForm(t);if(!M.isFunction(o))throw new TypeError("visitor must be a function");function c(g){if(g===null)return"";if(M.isDate(g))return g.toISOString();if(M.isBoolean(g))return g.toString();if(!l&&M.isBlob(g))throw new Fe("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(g)||M.isTypedArray(g)?l&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function d(g,x,y){let m=g;if(g&&!y&&typeof g=="object"){if(M.endsWith(x,"{}"))x=r?x:x.slice(0,-2),g=JSON.stringify(g);else if(M.isArray(g)&&_g(g)||(M.isFileList(g)||M.endsWith(x,"[]"))&&(m=M.toArray(g)))return x=Yl(x),m.forEach(function(S,T){!(M.isUndefined(S)||S===null)&&t.append(i===!0?Jl([x],T,s):i===null?x:x+"[]",c(S))}),!1}return Ai(g)?!0:(t.append(Jl(y,x,s),c(g)),!1)}const f=[],h=Object.assign(jg,{defaultVisitor:d,convertValue:c,isVisitable:Ai});function p(g,x){if(!M.isUndefined(g)){if(f.indexOf(g)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(g),M.forEach(g,function(m,b){(!(M.isUndefined(m)||m===null)&&o.call(t,m,M.isString(b)?b.trim():b,x,h))===!0&&p(m,x?x.concat(b):[b])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Zl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function _i(e,t){this._pairs=[],e&&Xo(e,this,t)}const Ql=_i.prototype;Ql.append=function(t,n){this._pairs.push([t,n])},Ql.toString=function(t){const n=t?function(r){return t.call(this,r,Zl)}:Zl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Rg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ec(e,t,n){if(!t)return e;const r=n&&n.encode||Rg;M.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=M.isURLSearchParams(t)?t.toString():new _i(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class tc{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){M.forEach(this.handlers,function(r){r!==null&&t(r)})}}const nc={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Pg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:_i,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},ji=typeof window<"u"&&typeof document<"u",Ri=typeof navigator=="object"&&navigator||void 0,Og=ji&&(!Ri||["ReactNative","NativeScript","NS"].indexOf(Ri.product)<0),Mg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Dg=ji&&window.location.href||"http://localhost",Xt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ji,hasStandardBrowserEnv:Og,hasStandardBrowserWebWorkerEnv:Mg,navigator:Ri,origin:Dg},Symbol.toStringTag,{value:"Module"})),...Pg};function Lg(e,t){return Xo(e,new Xt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Xt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function $g(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Fg(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 rc(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&M.isArray(o)?o.length:i,l?(M.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!M.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&M.isArray(o[i])&&(o[i]=Fg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t($g(r),o,n,0)}),n}return null}function zg(e,t,n){if(M.isString(e))try{return(t||JSON.parse)(e),M.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const io={transitional:nc,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=M.isObject(t);if(s&&M.isHTMLForm(t)&&(t=new FormData(t)),M.isFormData(t))return o?JSON.stringify(rc(t)):t;if(M.isArrayBuffer(t)||M.isBuffer(t)||M.isStream(t)||M.isFile(t)||M.isBlob(t)||M.isReadableStream(t))return t;if(M.isArrayBufferView(t))return t.buffer;if(M.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Lg(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Xo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),zg(t)):t}],transformResponse:[function(t){const n=this.transitional||io.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(M.isResponse(t)||M.isReadableStream(t))return t;if(t&&M.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Fe.from(a,Fe.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:Xt.classes.FormData,Blob:Xt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};M.forEach(["delete","get","head","post","put","patch"],e=>{io.headers[e]={}});const Bg=M.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Hg=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]&&Bg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},oc=Symbol("internals");function ao(e){return e&&String(e).trim().toLowerCase()}function Yo(e){return e===!1||e==null?e:M.isArray(e)?e.map(Yo):String(e)}function Ug(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 Wg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Pi(e,t,n,r,o){if(M.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!M.isString(t)){if(M.isString(r))return t.indexOf(r)!==-1;if(M.isRegExp(r))return r.test(t)}}function Vg(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Kg(e,t){const n=M.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let rn=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=ao(l);if(!d)throw new Error("header name must be a non-empty string");const f=M.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=Yo(a))}const i=(a,l)=>M.forEach(a,(c,d)=>s(c,d,l));if(M.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(M.isString(t)&&(t=t.trim())&&!Wg(t))i(Hg(t),n);else if(M.isObject(t)&&M.isIterable(t)){let a={},l,c;for(const d of t){if(!M.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?M.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=ao(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Ug(o);if(M.isFunction(n))return n.call(this,o,r);if(M.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=ao(t),t){const r=M.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Pi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=ao(i),i){const a=M.findKey(r,i);a&&(!n||Pi(r,r[a],a,n))&&(delete r[a],o=!0)}}return M.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||Pi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return M.forEach(this,(o,s)=>{const i=M.findKey(r,s);if(i){n[i]=Yo(o),delete n[s];return}const a=t?Vg(s):String(s).trim();a!==s&&delete n[s],n[a]=Yo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return M.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&M.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
32
- `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[oc]=this[oc]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=ao(i);r[a]||(Kg(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};rn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(rn.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(rn);function Oi(e,t){const n=this||io,r=t||n,o=rn.from(r.headers);let s=r.data;return M.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function sc(e){return!!(e&&e.__CANCEL__)}function Lr(e,t,n){Fe.call(this,e??"canceled",Fe.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(Lr,Fe,{__CANCEL__:!0});function ic(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Fe("Request failed with status code "+n.status,[Fe.ERR_BAD_REQUEST,Fe.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function qg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Gg(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,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function Xg(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 Jo=(e,t,n=3)=>{let r=0;const o=Gg(50,250);return Xg(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)},ac=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},lc=e=>(...t)=>M.asap(()=>e(...t)),Yg=Xt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Xt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Xt.origin),Xt.navigator&&/(msie|trident)/i.test(Xt.navigator.userAgent)):()=>!0,Jg=Xt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];M.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),M.isString(r)&&i.push("path="+r),M.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Zg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Qg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function cc(e,t,n){let r=!Zg(t);return e&&(r||n==!1)?Qg(e,t):t}const uc=e=>e instanceof rn?{...e}:e;function mr(e,t){t=t||{};const n={};function r(c,d,f,h){return M.isPlainObject(c)&&M.isPlainObject(d)?M.merge.call({caseless:h},c,d):M.isPlainObject(d)?M.merge({},d):M.isArray(d)?d.slice():d}function o(c,d,f,h){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!M.isUndefined(d))return r(void 0,d)}function i(c,d){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(uc(c),uc(d),f,!0)};return M.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);M.isUndefined(h)&&f!==a||(n[d]=h)}),n}const dc=e=>{const t=mr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=rn.from(i),t.url=ec(cc(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),M.isFormData(n)){if(Xt.hasStandardBrowserEnv||Xt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(M.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Xt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&Yg(t.url))){const l=o&&s&&Jg.read(s);l&&i.set(o,l)}return t},ex=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=dc(e);let s=o.data;const i=rn.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,g;function x(){p&&p(),g&&g(),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 m(){if(!y)return;const S=rn.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};ic(function(E){n(E),x()},function(E){r(E),x()},k),y=null}"onloadend"in y?y.onloadend=m:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(m)},y.onabort=function(){y&&(r(new Fe("Request aborted",Fe.ECONNABORTED,e,y)),y=null)},y.onerror=function(T){const k=T&&T.message?T.message:"Network Error",C=new Fe(k,Fe.ERR_NETWORK,e,y);C.event=T||null,r(C),y=null},y.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||nc;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new Fe(T,k.clarifyTimeoutError?Fe.ETIMEDOUT:Fe.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&M.forEach(i.toJSON(),function(T,k){y.setRequestHeader(k,T)}),M.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([h,g]=Jo(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=Jo(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new Lr(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=qg(o.url);if(b&&Xt.protocols.indexOf(b)===-1){r(new Fe("Unsupported protocol "+b+":",Fe.ERR_BAD_REQUEST,e));return}y.send(s||null)})},tx=(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 Fe?d:new Lr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Fe(`timeout ${t} of ms exceeded`,Fe.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>M.asap(a),l}},nx=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},rx=async function*(e,t){for await(const n of ox(e))yield*nx(n,t)},ox=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()}},fc=(e,t,n,r)=>{const o=rx(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 h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},hc=64*1024,{isFunction:Zo}=M,sx=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:pc,TextEncoder:mc}=M.global,gc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ix=e=>{e=M.merge.call({skipUndefined:!0},sx,e);const{fetch:t,Request:n,Response:r}=e,o=t?Zo(t):typeof fetch=="function",s=Zo(n),i=Zo(r);if(!o)return!1;const a=o&&Zo(pc),l=o&&(typeof mc=="function"?(g=>x=>g.encode(x))(new mc):async g=>new Uint8Array(await new n(g).arrayBuffer())),c=s&&a&&gc(()=>{let g=!1;const x=new n(Xt.origin,{body:new pc,method:"POST",get duplex(){return g=!0,"half"}}).headers.has("Content-Type");return g&&!x}),d=i&&a&&gc(()=>M.isReadableStream(new r("").body)),f={stream:d&&(g=>g.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!f[g]&&(f[g]=(x,y)=>{let m=x&&x[g];if(m)return m.call(x);throw new Fe(`Response type '${g}' is not supported`,Fe.ERR_NOT_SUPPORT,y)})});const h=async g=>{if(g==null)return 0;if(M.isBlob(g))return g.size;if(M.isSpecCompliantForm(g))return(await new n(Xt.origin,{method:"POST",body:g}).arrayBuffer()).byteLength;if(M.isArrayBufferView(g)||M.isArrayBuffer(g))return g.byteLength;if(M.isURLSearchParams(g)&&(g=g+""),M.isString(g))return(await l(g)).byteLength},p=async(g,x)=>{const y=M.toFiniteNumber(g.getContentLength());return y??h(x)};return async g=>{let{url:x,method:y,data:m,signal:b,cancelToken:S,timeout:T,onDownloadProgress:k,onUploadProgress:C,responseType:E,headers:R,withCredentials:_="same-origin",fetchOptions:j}=dc(g),L=t||fetch;E=E?(E+"").toLowerCase():"text";let z=tx([b,S&&S.toAbortSignal()],T),V=null;const O=z&&z.unsubscribe&&(()=>{z.unsubscribe()});let H;try{if(C&&c&&y!=="get"&&y!=="head"&&(H=await p(R,m))!==0){let oe=new n(x,{method:"POST",body:m,duplex:"half"}),we;if(M.isFormData(m)&&(we=oe.headers.get("content-type"))&&R.setContentType(we),oe.body){const[Ne,Z]=ac(H,Jo(lc(C)));m=fc(oe.body,hc,Ne,Z)}}M.isString(_)||(_=_?"include":"omit");const P=s&&"credentials"in n.prototype,W={...j,signal:z,method:y.toUpperCase(),headers:R.normalize().toJSON(),body:m,duplex:"half",credentials:P?_:void 0};V=s&&new n(x,W);let F=await(s?L(V,j):L(x,W));const $=d&&(E==="stream"||E==="response");if(d&&(k||$&&O)){const oe={};["status","statusText","headers"].forEach(ie=>{oe[ie]=F[ie]});const we=M.toFiniteNumber(F.headers.get("content-length")),[Ne,Z]=k&&ac(we,Jo(lc(k),!0))||[];F=new r(fc(F.body,hc,Ne,()=>{Z&&Z(),O&&O()}),oe)}E=E||"text";let ne=await f[M.findKey(f,E)||"text"](F,g);return!$&&O&&O(),await new Promise((oe,we)=>{ic(oe,we,{data:ne,headers:rn.from(F.headers),status:F.status,statusText:F.statusText,config:g,request:V})})}catch(P){throw O&&O(),P&&P.name==="TypeError"&&/Load failed|fetch/i.test(P.message)?Object.assign(new Fe("Network Error",Fe.ERR_NETWORK,g,V),{cause:P.cause||P}):Fe.from(P,P&&P.code,g,V)}}},ax=new Map,xc=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=ax;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ix(t)),d=c;return c};xc();const Mi={http:Ag,xhr:ex,fetch:{get:xc}};M.forEach(Mi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const yc=e=>`- ${e}`,lx=e=>M.isFunction(e)||e===null||e===!1,vc={getAdapter:(e,t)=>{e=M.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!lx(r)&&(o=Mi[(a=String(r)).toLowerCase()],o===void 0))throw new Fe(`Unknown adapter '${a}'`);if(o&&(M.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
- `+i.map(yc).join(`
34
- `):" "+yc(i[0]):"as no adapter specified";throw new Fe("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Mi};function Di(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Lr(null,e)}function wc(e){return Di(e),e.headers=rn.from(e.headers),e.data=Oi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),vc.getAdapter(e.adapter||io.adapter,e)(e).then(function(r){return Di(e),r.data=Oi.call(e,e.transformResponse,r),r.headers=rn.from(r.headers),r},function(r){return sc(r)||(Di(e),r&&r.response&&(r.response.data=Oi.call(e,e.transformResponse,r.response),r.response.headers=rn.from(r.response.headers))),Promise.reject(r)})}const bc="1.12.2",Qo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Qo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Sc={};Qo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+bc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Fe(o(i," has been removed"+(n?" in "+n:"")),Fe.ERR_DEPRECATED);return n&&!Sc[i]&&(Sc[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}},Qo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function cx(e,t,n){if(typeof e!="object")throw new Fe("options must be an object",Fe.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 Fe("option "+s+" must be "+l,Fe.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Fe("Unknown option "+s,Fe.ERR_BAD_OPTION)}}const es={assertOptions:cx,validators:Qo},An=es.validators;let gr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new tc,response:new tc}}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=mr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&es.assertOptions(r,{silentJSONParsing:An.transitional(An.boolean),forcedJSONParsing:An.transitional(An.boolean),clarifyTimeoutError:An.transitional(An.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:es.assertOptions(o,{encode:An.function,serialize:An.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),es.assertOptions(n,{baseUrl:An.spelling("baseURL"),withXsrfToken:An.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&M.merge(s.common,s[n.method]);s&&M.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=rn.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const g=[wc.bind(this),void 0];for(g.unshift(...a),g.push(...c),h=g.length,d=Promise.resolve(n);f<h;)d=d.then(g[f++],g[f++]);return d}h=a.length;let p=n;for(;f<h;){const g=a[f++],x=a[f++];try{p=g(p)}catch(y){x.call(this,y);break}}try{d=wc.call(this,p)}catch(g){return Promise.reject(g)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=mr(this.defaults,t);const n=cc(t.baseURL,t.url,t.allowAbsoluteUrls);return ec(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){gr.prototype[t]=function(n,r){return this.request(mr(r||{},{method:t,url:n,data:(r||{}).data}))}}),M.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(mr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}gr.prototype[t]=n(),gr.prototype[t+"Form"]=n(!0)});let ux=class zm{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new Lr(s,i,a),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new zm(function(o){t=o}),cancel:t}}};function dx(e){return function(n){return e.apply(null,n)}}function fx(e){return M.isObject(e)&&e.isAxiosError===!0}const Li={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(Li).forEach(([e,t])=>{Li[t]=e});function Cc(e){const t=new gr(e),n=Fl(gr.prototype.request,t);return M.extend(n,gr.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Cc(mr(e,o))},n}const Rt=Cc(io);Rt.Axios=gr,Rt.CanceledError=Lr,Rt.CancelToken=ux,Rt.isCancel=sc,Rt.VERSION=bc,Rt.toFormData=Xo,Rt.AxiosError=Fe,Rt.Cancel=Rt.CanceledError,Rt.all=function(t){return Promise.all(t)},Rt.spread=dx,Rt.isAxiosError=fx,Rt.mergeConfig=mr,Rt.AxiosHeaders=rn,Rt.formToJSON=e=>rc(M.isHTMLForm(e)?new FormData(e):e),Rt.getAdapter=vc.getAdapter,Rt.HttpStatusCode=Li,Rt.default=Rt;const{Axios:fT,AxiosError:hT,CanceledError:pT,isCancel:mT,CancelToken:gT,VERSION:xT,all:yT,Cancel:vT,isAxiosError:wT,spread:bT,toFormData:ST,AxiosHeaders:CT,HttpStatusCode:kT,formToJSON:TT,getAdapter:ET,mergeConfig:IT}=Rt,kc=typeof window<"u"?window.__API_BASE_URL__:void 0,Tc=kc?zn(kc):void 0;function zn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let ts=null;const $i=new Set;function Ec(){return ts}function Fi(e){ts=e,$i.forEach(t=>t(e))}function Ic(e){return $i.add(e),()=>$i.delete(e)}const fn=Rt.create({...Tc?{baseURL:Tc}:{},timeout:3e4,withCredentials:!0});fn.interceptors.request.use(e=>(ts&&(e.headers.Authorization=`Bearer ${ts}`),e)),fn.interceptors.response.use(e=>e,e=>Promise.reject(e));async function bn(e,t){return fn.defaults.baseURL?(await fn.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function zi(e,t,n){return fn.defaults.baseURL?(await fn.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Nc(e,t,n){return fn.defaults.baseURL?(await fn.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ac(e,t){return fn.defaults.baseURL?(await fn.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function Sn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class _c{get baseUrl(){const t=fn.defaults.baseURL;return t?zn(String(t)):""}updateConfig(t){t.baseUrl&&(fn.defaults.baseURL=zn(String(t.baseUrl))),t.authToken!==void 0&&Fi(t.authToken)}getAuthToken(){return Ec()}setAuthToken(t){Fi(t)}onTokenChange(t){return Ic(t)}async listThreads(){const t=await bn("/threads"),n=Sn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await zi("/threads",t?{title:t}:void 0);return Sn(r)}async updateThread(t,n){const r=await Nc(`/threads/${t}`,{title:n});return Sn(r)}async deleteThread(t){const n=await Ac(`/threads/${t}`);return Sn(n)}async threadInfo(t){const n=await bn(`/threads/${t}/info`);return Sn(n)}async listAgents(){const t=await bn("/agents"),n=Sn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await bn(`/agents/${t}`);return Sn(n)}async getAgentSchema(t){const n=await bn(`/agents/${t}/schema`);return Sn(n)}async getState(t){const n=await bn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Sn(n)}async getStateHistory(t){const n=await bn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Sn(n)}async cancelRun(t){const n=await zi("/runs/cancel",{threadId:t});return Sn(n)}}const Gn=new _c,jc=w.createContext(null);function hx({children:e,apiConfig:t}){const n=Gn;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(jc.Provider,{value:r,children:e})}function Bi(){const e=w.useContext(jc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function px(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 mx(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await px(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const gx={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Hi(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function lo(e,t){return`${e??""}::${t??""}`}function ns(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Hi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=yx(t),i=Rc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Rc(e,t){if(!Hi(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(_=>!!_&&typeof _=="object").map(_=>({..._})):a===null?null:void 0,c=r.map((_,j)=>Tx(_,j)).filter(_=>!!_),d=on(e.config),f=on(d==null?void 0:d.configurable),h=Mt(f,["checkpoint_id","checkpointId"]),p=Mt(f,["checkpoint_ns","checkpointNs"]),g=on(e==null?void 0:e.parentConfig),x=on(g==null?void 0:g.configurable),y=Mt(x,["checkpoint_id","checkpointId"])??null,m=Mt(x,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=on(e==null?void 0:e.metadata),C=Mt(k,["branch_label","branchLabel"]),E=Mt(x,["checkpoint_id","checkpointId"]),R=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:y,nextCursorNs:m,interrupt:xx(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:g??null,next:R??null,tasks:l??null,values:i??null}}function xx(e,t,n){const r=Cx(e,n);return r||Sx(t,n)}function yx(e){const t=new Map;e.forEach((o,s)=>{if(!Hi(o))return;const i=Rc(o,s);if(!(i!=null&&i.checkpointId))return;const a=lo(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,vx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Oc(s.createdAt??"")-Oc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function vx(e,t){return{...e,metadata:rs(e.metadata,t.metadata)??null,config:rs(e.config,t.config)??null,parentConfig:rs(e.parentConfig,t.parentConfig)??null,next:wx(e.next,t.next)??null,tasks:bx(e.tasks,t.tasks)??null,values:rs(e.values,t.values)??null}}function rs(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 wx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function bx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Sx(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 Cx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=kx(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=co(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=co(r.state,`${o}-state`);if(s)return s}}return null}function kx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,g=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:g,interrupts:x,state:y!==void 0?y:f}}const n=on(e);if(!n)return null;const r=Mt(n,["id","task_id","taskId"])??t,o=Mt(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function co(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=Pc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=co(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=co(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=co(l,t,n+1,r);if(c)return c}}return null}function Pc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=Mt(n,["type","event","kind"]),o=Mt(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=Pc(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function Oc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Tx(e,t){if(!e||typeof e!="object")return null;const n=e,r=on(e)??{},o=on(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=gx[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=on(o.additional_kwargs)??on(o.additionalKwargs),d=on(o.response_metadata)??on(o.responseMetadata),f=Mt(c,["createdAt","created_at"])??Mt(o,["created_at","createdAt"]),h=Mt(c,["checkpointId","checkpoint_id"]),p=Mt(c,["checkpointNs","checkpoint_ns"]),g=Ex(o.content),x={id:l,role:i,content:g};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const y=_x(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),m=d?{...d}:void 0;y&&Object.keys(y).length&&(x.additionalKwargs=y),m&&Object.keys(m).length&&(x.responseMetadata=m);const b=Ix((c==null?void 0:c.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=Nx(o,x.content);S&&(x.content=S)}return x}function Ex(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Mc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Mc(e);return t?[t]:[]}return[]}function Mc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=Mt(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=Mt(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return Dc(t)??null;if(n==="tool_end"){const o="output"in t?t.output:t.content;return o?{type:"text",text:typeof o=="string"?o:JSON.stringify(o)}:null}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=Mt(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function Dc(e,t){var s;const n=Mt(e,["id","call_id"])??t,r=Mt(e,["name"])??Mt(on(e.function),["name"]);if(!n||!r)return null;const o=Ax(e.args??e.arguments??((s=on(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Ix(e){return Array.isArray(e)?e.map((t,n)=>Dc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Nx(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 Ax(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 on(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Mt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function _x(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 jx(e){return e.type!=="thread_info"&&e.type!=="token"}const Rx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Px(e,t){var n;switch(t.type){case"reset":return{messages:Ui(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Ui(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=Ui(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 $c(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>$c(o,s),e):e}case"interrupt_response":return{...e,messages:Fc(e.messages),pendingInterrupt:null};default:return e}}function Lc(e=[]){const[t,n]=w.useReducer(Px,{...Rx,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 $c(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Lx(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}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??zc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(T=>T.id===a&&T.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:Uc(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:g,newMeta:x,changed:y}=Ox(d.content,t.delta,h,p);if(!y)return e;const m={...d,content:g},b=os(l,c,m),S={...f,[a]:x};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??zc(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(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=Bc(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=Hc(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,g=(h==null?void 0:h.id)??`tool-${p}`,x=d[0]??p,y={type:"tool_call",id:x,name:c,args:t.args};if(h){const S=Vi(h,d,c,t.args),T={...h,name:h.name??c,additionalKwargs:S},k=f,C=k>=0?os(e.messages,k,T):e.messages,E=ss(T,d),R=Ki(e.toolIndex,g,E);return{...e,messages:C,toolIndex:R}}const m={id:g,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:Vi(void 0,d.length?d:[x],c,t.args)},b=ss(m,d.length?d:[x]);return{...e,messages:[...e.messages,m],toolIndex:Ki(e.toolIndex,g,b)}}if(t.type==="tool_end"){const a=Bc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Hc(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",h=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(d==null?void 0:d.id)??`tool-${h}`,g=ss(d,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const y={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},m=(d==null?void 0:d.createdAt)??new Date().toISOString(),b=Vi(d??void 0,g.length?g:a,f),S={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:m,additionalKwargs:b},T=c>=0?os(e.messages,c,S):[...e.messages,S],k=ss(S,a.length?a:g);return{...e,messages:T,toolIndex:Ki(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Dx(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=ns(t),l=a.interrupt,c=a.latest,d=l===null?Fc(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 e}function Ui(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function os(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Fc(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 zc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Bc(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 Wi(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 Vi(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Wi(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 ss(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Wi(e);for(const o of r)n.add(o);return Array.from(n)}function Ki(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 Hc(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(Wi(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 Uc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Ox(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??Uc(e);let l="",c=e.slice();if(s){const f=Mx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",g={...h,text:p+l};c=[...c.slice(0,c.length-1),g]}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 Wc(e){return e.replace(/\s+/g," ").trim()}function Mx(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=Wc(e),o=Wc(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 Dx(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 os(e,r,s)}return e}function Lx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Vc(e={}){const t=w.useMemo(()=>zn(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,h]=w.useState(""),[p,g]=w.useState(null),[x,y]=w.useState(0),[m,b]=w.useState(!1),S=w.useRef(null),T=w.useRef(!0),k=w.useRef(0),C=w.useRef(null),E=w.useRef(null),R=w.useRef(null),_=w.useRef(null),j=w.useCallback(O=>{o(O)},[]),L=w.useCallback(()=>{h(""),g(null),d(null),E.current=null,R.current=null,_.current=null},[]),z=w.useCallback(()=>{var O;console.debug("[use-chat] stop() invoked - aborting stream"),(O=S.current)==null||O.abort(),S.current=null,C.current=null,l(!1),b(!1),k.current=0,y(0)},[]),V=w.useCallback((O,H,P)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),g(null),E.current=null,R.current=null,_.current=null;const W=new AbortController;S.current=W;let F=null,$=null,ne=!1;return C.current={threadId:O.threadId??null,headers:{}},(async()=>{var we,Ne,Z,ie,Te,ee,D,G,ae,fe,B,le,Q,Ae,ve,Re,Ve,Qe;const oe=et=>{var Se;try{const nt=JSON.parse(JSON.stringify(et));return(Se=nt==null?void 0:nt.payload)!=null&&Se.files_info&&Array.isArray(nt.payload.files_info)&&(nt.payload.files_info=nt.payload.files_info.map(ut=>({...ut,data:ut!=null&&ut.data?`<base64 ${String(ut.data).length} chars>`:ut==null?void 0:ut.data}))),nt}catch{return et}};try{let et={};try{if(r)et={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Le=window.__AUTH_TOKEN__,_t=((we=window.localStorage)==null?void 0:we.getItem("authToken"))||null;let yt=null;try{const Ce=(Ne=window.localStorage)==null?void 0:Ne.getItem("chat-settings");Ce&&(yt=((Z=JSON.parse(Ce))==null?void 0:Z.apiKey)||null)}catch{}const X=Le||_t||yt||null;X&&(et={Authorization:`Bearer ${X}`})}}catch{}console.debug("[use-chat] POST",t+n,oe(O));let Se={};if(typeof window<"u")try{const st=(ie=window.localStorage)==null?void 0:ie.getItem("authSessionId");st&&(Se={"X-Session-Id":st})}catch{}const nt={...et,...Se,...s.current},ut={"Content-Type":"application/json",Accept:"text/event-stream",...nt},rt=await fetch(t+n,{method:"POST",headers:ut,body:JSON.stringify(O),signal:W.signal,credentials:i});if(C.current&&(C.current.headers=nt),!rt.ok||!rt.body){const st=await rt.text().catch(()=>"");console.debug("[use-chat] non-OK response",rt.status,st==null?void 0:st.slice(0,500));const Le=`stream ${rt.status}${st?": "+st:""}`;throw(Te=P==null?void 0:P.onConnectionError)==null||Te.call(P,Le),ne=!0,F="error",$=Le,new Error(Le)}b(!0);const Ye=rt.body.getReader(),It=new TextDecoder;let dt="",kt=[];k.current=0,y(0);let Nt=0,tt=null;const He=()=>{if(kt.length){const st=kt.join("");kt=[],T.current&&h(Le=>Le+st)}tt=null},Tt=()=>{typeof window<"u"&&tt==null&&(tt=requestAnimationFrame(He))};let Vt=Date.now();const zt=setInterval(()=>{var st;if(Date.now()-Vt>6e4){const Le="Stream idle timeout";d(Le),F="error",$=Le,W.abort(),(st=P==null?void 0:P.onError)==null||st.call(P,Le)}},5e3),Kt=1024*1024;try{const st=rt.headers.get("X-Thread-Id")||rt.headers.get("x-thread-id"),Le=rt.headers.get("X-Thread-Created")||rt.headers.get("x-thread-created"),_t=st??null,yt=String(Le??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:_t}),(ee=P==null?void 0:P.onOpen)==null||ee.call(P,{threadId:_t,created:yt});;){const{value:X,done:Ce}=await Ye.read();if(Ce)break;dt+=It.decode(X,{stream:!0}),dt.length>Kt&&(dt="",console.warn("Stream buffer reset: exceeded 1MB"));let ge;for(;(ge=dt.indexOf(`
30
+ <%s key={someKey} {...props} />`,Y,un,fe,un),Vn[un+Y]=!0}}return I===r?On(xt):ht(xt),xt}}function pr(I,G,ie){return hr(I,G,ie,!0)}function Mr(I,G,ie){return hr(I,G,ie,!1)}var Qn=Mr,no=pr;io.Fragment=r,io.jsx=Qn,io.jsxs=no}()),io}process.env.NODE_ENV==="production"?Ri.exports=Um():Ri.exports=Wm();var u=Ri.exports;function Vl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Vm}=Object.prototype,{getPrototypeOf:Pi}=Object,{iterator:Xo,toStringTag:Kl}=Symbol,Jo=(e=>t=>{const n=Vm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Tn=e=>(e=e.toLowerCase(),t=>Jo(t)===e),Zo=e=>t=>typeof t===e,{isArray:Fr}=Array,$r=Zo("undefined");function ao(e){return e!==null&&!$r(e)&&e.constructor!==null&&!$r(e.constructor)&&sn(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const ql=Tn("ArrayBuffer");function Km(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&ql(e.buffer),t}const qm=Zo("string"),sn=Zo("function"),Gl=Zo("number"),lo=e=>e!==null&&typeof e=="object",Gm=e=>e===!0||e===!1,Qo=e=>{if(Jo(e)!=="object")return!1;const t=Pi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Kl in e)&&!(Xo in e)},Ym=e=>{if(!lo(e)||ao(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Xm=Tn("Date"),Jm=Tn("File"),Zm=Tn("Blob"),Qm=Tn("FileList"),eg=e=>lo(e)&&sn(e.pipe),tg=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||sn(e.append)&&((t=Jo(e))==="formdata"||t==="object"&&sn(e.toString)&&e.toString()==="[object FormData]"))},ng=Tn("URLSearchParams"),[rg,og,sg,ig]=["ReadableStream","Request","Response","Headers"].map(Tn),ag=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function co(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Fr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(ao(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 Yl(e,t){if(ao(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 yr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Xl=e=>!$r(e)&&e!==yr;function Oi(){const{caseless:e,skipUndefined:t}=Xl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Yl(n,s)||s;Qo(n[i])&&Qo(o)?n[i]=Oi(n[i],o):Qo(o)?n[i]=Oi({},o):Fr(o)?n[i]=o.slice():(!t||!$r(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&co(arguments[o],r);return n}const lg=(e,t,n,{allOwnKeys:r}={})=>(co(t,(o,s)=>{n&&sn(o)?e[s]=Vl(o,n):e[s]=o},{allOwnKeys:r}),e),cg=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),ug=(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)},dg=(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&&Pi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},fg=(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},hg=e=>{if(!e)return null;if(Fr(e))return e;let t=e.length;if(!Gl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},pg=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Pi(Uint8Array)),mg=(e,t)=>{const r=(e&&e[Xo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},gg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},xg=Tn("HTMLFormElement"),yg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Jl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),vg=Tn("RegExp"),Zl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};co(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},wg=e=>{Zl(e,(t,n)=>{if(sn(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(sn(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+"'")})}})},bg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Fr(e)?r(e):r(String(e).split(t)),n},Sg=()=>{},Cg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function kg(e){return!!(e&&sn(e.append)&&e[Kl]==="FormData"&&e[Xo])}const Tg=e=>{const t=new Array(10),n=(r,o)=>{if(lo(r)){if(t.indexOf(r)>=0)return;if(ao(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Fr(r)?[]:{};return co(r,(i,a)=>{const l=n(i,o+1);!$r(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},Eg=Tn("AsyncFunction"),Ig=e=>e&&(lo(e)||sn(e))&&sn(e.then)&&sn(e.catch),Ql=((e,t)=>e?setImmediate:t?((n,r)=>(yr.addEventListener("message",({source:o,data:s})=>{o===yr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),yr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",sn(yr.postMessage)),Ng=typeof queueMicrotask<"u"?queueMicrotask.bind(yr):typeof process<"u"&&process.nextTick||Ql,M={isArray:Fr,isArrayBuffer:ql,isBuffer:ao,isFormData:tg,isArrayBufferView:Km,isString:qm,isNumber:Gl,isBoolean:Gm,isObject:lo,isPlainObject:Qo,isEmptyObject:Ym,isReadableStream:rg,isRequest:og,isResponse:sg,isHeaders:ig,isUndefined:$r,isDate:Xm,isFile:Jm,isBlob:Zm,isRegExp:vg,isFunction:sn,isStream:eg,isURLSearchParams:ng,isTypedArray:pg,isFileList:Qm,forEach:co,merge:Oi,extend:lg,trim:ag,stripBOM:cg,inherits:ug,toFlatObject:dg,kindOf:Jo,kindOfTest:Tn,endsWith:fg,toArray:hg,forEachEntry:mg,matchAll:gg,isHTMLForm:xg,hasOwnProperty:Jl,hasOwnProp:Jl,reduceDescriptors:Zl,freezeMethods:wg,toObjectSet:bg,toCamelCase:yg,noop:Sg,toFiniteNumber:Cg,findKey:Yl,global:yr,isContextDefined:Xl,isSpecCompliantForm:kg,toJSONObject:Tg,isAsyncFn:Eg,isThenable:Ig,setImmediate:Ql,asap:Ng,isIterable:e=>e!=null&&sn(e[Xo])};function Le(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}M.inherits(Le,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:M.toJSONObject(this.config),code:this.code,status:this.status}}});const ec=Le.prototype,tc={};["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=>{tc[e]={value:e}}),Object.defineProperties(Le,tc),Object.defineProperty(ec,"isAxiosError",{value:!0}),Le.from=(e,t,n,r,o,s)=>{const i=Object.create(ec);M.toFlatObject(e,i,function(d){return d!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Le.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 Ag=null;function Mi(e){return M.isPlainObject(e)||M.isArray(e)}function nc(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function rc(e,t,n){return e?e.concat(t).map(function(o,s){return o=nc(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function _g(e){return M.isArray(e)&&!e.some(Mi)}const jg=M.toFlatObject(M,{},null,function(t){return/^is[A-Z]/.test(t)});function es(e,t,n){if(!M.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=M.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,y){return!M.isUndefined(y[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&M.isSpecCompliantForm(t);if(!M.isFunction(o))throw new TypeError("visitor must be a function");function c(g){if(g===null)return"";if(M.isDate(g))return g.toISOString();if(M.isBoolean(g))return g.toString();if(!l&&M.isBlob(g))throw new Le("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(g)||M.isTypedArray(g)?l&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function d(g,x,y){let m=g;if(g&&!y&&typeof g=="object"){if(M.endsWith(x,"{}"))x=r?x:x.slice(0,-2),g=JSON.stringify(g);else if(M.isArray(g)&&_g(g)||(M.isFileList(g)||M.endsWith(x,"[]"))&&(m=M.toArray(g)))return x=nc(x),m.forEach(function(S,T){!(M.isUndefined(S)||S===null)&&t.append(i===!0?rc([x],T,s):i===null?x:x+"[]",c(S))}),!1}return Mi(g)?!0:(t.append(rc(y,x,s),c(g)),!1)}const f=[],h=Object.assign(jg,{defaultVisitor:d,convertValue:c,isVisitable:Mi});function p(g,x){if(!M.isUndefined(g)){if(f.indexOf(g)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(g),M.forEach(g,function(m,b){(!(M.isUndefined(m)||m===null)&&o.call(t,m,M.isString(b)?b.trim():b,x,h))===!0&&p(m,x?x.concat(b):[b])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return p(e),t}function oc(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Di(e,t){this._pairs=[],e&&es(e,this,t)}const sc=Di.prototype;sc.append=function(t,n){this._pairs.push([t,n])},sc.toString=function(t){const n=t?function(r){return t.call(this,r,oc)}:oc;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function Rg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ic(e,t,n){if(!t)return e;const r=n&&n.encode||Rg;M.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=M.isURLSearchParams(t)?t.toString():new Di(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class ac{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){M.forEach(this.handlers,function(r){r!==null&&t(r)})}}const lc={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Pg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Di,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Li=typeof window<"u"&&typeof document<"u",Fi=typeof navigator=="object"&&navigator||void 0,Og=Li&&(!Fi||["ReactNative","NativeScript","NS"].indexOf(Fi.product)<0),Mg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Dg=Li&&window.location.href||"http://localhost",Xt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Li,hasStandardBrowserEnv:Og,hasStandardBrowserWebWorkerEnv:Mg,navigator:Fi,origin:Dg},Symbol.toStringTag,{value:"Module"})),...Pg};function Lg(e,t){return es(e,new Xt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Xt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Fg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function $g(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 cc(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&M.isArray(o)?o.length:i,l?(M.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!M.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&M.isArray(o[i])&&(o[i]=$g(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Fg(r),o,n,0)}),n}return null}function zg(e,t,n){if(M.isString(e))try{return(t||JSON.parse)(e),M.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const uo={transitional:lc,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=M.isObject(t);if(s&&M.isHTMLForm(t)&&(t=new FormData(t)),M.isFormData(t))return o?JSON.stringify(cc(t)):t;if(M.isArrayBuffer(t)||M.isBuffer(t)||M.isStream(t)||M.isFile(t)||M.isBlob(t)||M.isReadableStream(t))return t;if(M.isArrayBufferView(t))return t.buffer;if(M.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Lg(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return es(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),zg(t)):t}],transformResponse:[function(t){const n=this.transitional||uo.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(M.isResponse(t)||M.isReadableStream(t))return t;if(t&&M.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Le.from(a,Le.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:Xt.classes.FormData,Blob:Xt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};M.forEach(["delete","get","head","post","put","patch"],e=>{uo.headers[e]={}});const Bg=M.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Hg=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]&&Bg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},uc=Symbol("internals");function fo(e){return e&&String(e).trim().toLowerCase()}function ts(e){return e===!1||e==null?e:M.isArray(e)?e.map(ts):String(e)}function Ug(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 Wg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function $i(e,t,n,r,o){if(M.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!M.isString(t)){if(M.isString(r))return t.indexOf(r)!==-1;if(M.isRegExp(r))return r.test(t)}}function Vg(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Kg(e,t){const n=M.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let an=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const d=fo(l);if(!d)throw new Error("header name must be a non-empty string");const f=M.findKey(o,d);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=ts(a))}const i=(a,l)=>M.forEach(a,(c,d)=>s(c,d,l));if(M.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(M.isString(t)&&(t=t.trim())&&!Wg(t))i(Hg(t),n);else if(M.isObject(t)&&M.isIterable(t)){let a={},l,c;for(const d of t){if(!M.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[c=d[0]]=(l=a[c])?M.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=fo(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Ug(o);if(M.isFunction(n))return n.call(this,o,r);if(M.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=fo(t),t){const r=M.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||$i(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=fo(i),i){const a=M.findKey(r,i);a&&(!n||$i(r,r[a],a,n))&&(delete r[a],o=!0)}}return M.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||$i(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return M.forEach(this,(o,s)=>{const i=M.findKey(r,s);if(i){n[i]=ts(o),delete n[s];return}const a=t?Vg(s):String(s).trim();a!==s&&delete n[s],n[a]=ts(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return M.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&M.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
32
+ `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[uc]=this[uc]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=fo(i);r[a]||(Kg(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};an.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(an.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(an);function zi(e,t){const n=this||uo,r=t||n,o=an.from(r.headers);let s=r.data;return M.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function dc(e){return!!(e&&e.__CANCEL__)}function zr(e,t,n){Le.call(this,e??"canceled",Le.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(zr,Le,{__CANCEL__:!0});function fc(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Le("Request failed with status code "+n.status,[Le.ERR_BAD_REQUEST,Le.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function qg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Gg(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,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=d&&c-d;return p?Math.round(h*1e3/p):void 0}}function Yg(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 ns=(e,t,n=3)=>{let r=0;const o=Gg(50,250);return Yg(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)},hc=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},pc=e=>(...t)=>M.asap(()=>e(...t)),Xg=Xt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Xt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Xt.origin),Xt.navigator&&/(msie|trident)/i.test(Xt.navigator.userAgent)):()=>!0,Jg=Xt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];M.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),M.isString(r)&&i.push("path="+r),M.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Zg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Qg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function mc(e,t,n){let r=!Zg(t);return e&&(r||n==!1)?Qg(e,t):t}const gc=e=>e instanceof an?{...e}:e;function vr(e,t){t=t||{};const n={};function r(c,d,f,h){return M.isPlainObject(c)&&M.isPlainObject(d)?M.merge.call({caseless:h},c,d):M.isPlainObject(d)?M.merge({},d):M.isArray(d)?d.slice():d}function o(c,d,f,h){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c,f,h)}else return r(c,d,f,h)}function s(c,d){if(!M.isUndefined(d))return r(void 0,d)}function i(c,d){if(M.isUndefined(d)){if(!M.isUndefined(c))return r(void 0,c)}else return r(void 0,d)}function a(c,d,f){if(f in t)return r(c,d);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,d,f)=>o(gc(c),gc(d),f,!0)};return M.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);M.isUndefined(h)&&f!==a||(n[d]=h)}),n}const xc=e=>{const t=vr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=an.from(i),t.url=ic(mc(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),M.isFormData(n)){if(Xt.hasStandardBrowserEnv||Xt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(M.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{c.includes(d.toLowerCase())&&i.set(d,f)})}}if(Xt.hasStandardBrowserEnv&&(r&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&Xg(t.url))){const l=o&&s&&Jg.read(s);l&&i.set(o,l)}return t},ex=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=xc(e);let s=o.data;const i=an.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,d,f,h,p,g;function x(){p&&p(),g&&g(),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 m(){if(!y)return;const S=an.from("getAllResponseHeaders"in y&&y.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?y.responseText:y.response,status:y.status,statusText:y.statusText,headers:S,config:e,request:y};fc(function(E){n(E),x()},function(E){r(E),x()},k),y=null}"onloadend"in y?y.onloadend=m:y.onreadystatechange=function(){!y||y.readyState!==4||y.status===0&&!(y.responseURL&&y.responseURL.indexOf("file:")===0)||setTimeout(m)},y.onabort=function(){y&&(r(new Le("Request aborted",Le.ECONNABORTED,e,y)),y=null)},y.onerror=function(T){const k=T&&T.message?T.message:"Network Error",C=new Le(k,Le.ERR_NETWORK,e,y);C.event=T||null,r(C),y=null},y.ontimeout=function(){let T=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||lc;o.timeoutErrorMessage&&(T=o.timeoutErrorMessage),r(new Le(T,k.clarifyTimeoutError?Le.ETIMEDOUT:Le.ECONNABORTED,e,y)),y=null},s===void 0&&i.setContentType(null),"setRequestHeader"in y&&M.forEach(i.toJSON(),function(T,k){y.setRequestHeader(k,T)}),M.isUndefined(o.withCredentials)||(y.withCredentials=!!o.withCredentials),a&&a!=="json"&&(y.responseType=o.responseType),c&&([h,g]=ns(c,!0),y.addEventListener("progress",h)),l&&y.upload&&([f,p]=ns(l),y.upload.addEventListener("progress",f),y.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{y&&(r(!S||S.type?new zr(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=qg(o.url);if(b&&Xt.protocols.indexOf(b)===-1){r(new Le("Unsupported protocol "+b+":",Le.ERR_BAD_REQUEST,e));return}y.send(s||null)})},tx=(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 Le?d:new zr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Le(`timeout ${t} of ms exceeded`,Le.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>M.asap(a),l}},nx=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},rx=async function*(e,t){for await(const n of ox(e))yield*nx(n,t)},ox=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()}},yc=(e,t,n,r)=>{const o=rx(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 h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},vc=64*1024,{isFunction:rs}=M,sx=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:wc,TextEncoder:bc}=M.global,Sc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},ix=e=>{e=M.merge.call({skipUndefined:!0},sx,e);const{fetch:t,Request:n,Response:r}=e,o=t?rs(t):typeof fetch=="function",s=rs(n),i=rs(r);if(!o)return!1;const a=o&&rs(wc),l=o&&(typeof bc=="function"?(g=>x=>g.encode(x))(new bc):async g=>new Uint8Array(await new n(g).arrayBuffer())),c=s&&a&&Sc(()=>{let g=!1;const x=new n(Xt.origin,{body:new wc,method:"POST",get duplex(){return g=!0,"half"}}).headers.has("Content-Type");return g&&!x}),d=i&&a&&Sc(()=>M.isReadableStream(new r("").body)),f={stream:d&&(g=>g.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!f[g]&&(f[g]=(x,y)=>{let m=x&&x[g];if(m)return m.call(x);throw new Le(`Response type '${g}' is not supported`,Le.ERR_NOT_SUPPORT,y)})});const h=async g=>{if(g==null)return 0;if(M.isBlob(g))return g.size;if(M.isSpecCompliantForm(g))return(await new n(Xt.origin,{method:"POST",body:g}).arrayBuffer()).byteLength;if(M.isArrayBufferView(g)||M.isArrayBuffer(g))return g.byteLength;if(M.isURLSearchParams(g)&&(g=g+""),M.isString(g))return(await l(g)).byteLength},p=async(g,x)=>{const y=M.toFiniteNumber(g.getContentLength());return y??h(x)};return async g=>{let{url:x,method:y,data:m,signal:b,cancelToken:S,timeout:T,onDownloadProgress:k,onUploadProgress:C,responseType:E,headers:R,withCredentials:_="same-origin",fetchOptions:j}=xc(g),D=t||fetch;E=E?(E+"").toLowerCase():"text";let z=tx([b,S&&S.toAbortSignal()],T),W=null;const O=z&&z.unsubscribe&&(()=>{z.unsubscribe()});let B;try{if(C&&c&&y!=="get"&&y!=="head"&&(B=await p(R,m))!==0){let te=new n(x,{method:"POST",body:m,duplex:"half"}),ve;if(M.isFormData(m)&&(ve=te.headers.get("content-type"))&&R.setContentType(ve),te.body){const[Ie,Z]=hc(B,ns(pc(C)));m=yc(te.body,vc,Ie,Z)}}M.isString(_)||(_=_?"include":"omit");const P=s&&"credentials"in n.prototype,V={...j,signal:z,method:y.toUpperCase(),headers:R.normalize().toJSON(),body:m,duplex:"half",credentials:P?_:void 0};W=s&&new n(x,V);let $=await(s?D(W,j):D(x,V));const F=d&&(E==="stream"||E==="response");if(d&&(k||F&&O)){const te={};["status","statusText","headers"].forEach(de=>{te[de]=$[de]});const ve=M.toFiniteNumber($.headers.get("content-length")),[Ie,Z]=k&&hc(ve,ns(pc(k),!0))||[];$=new r(yc($.body,vc,Ie,()=>{Z&&Z(),O&&O()}),te)}E=E||"text";let ee=await f[M.findKey(f,E)||"text"]($,g);return!F&&O&&O(),await new Promise((te,ve)=>{fc(te,ve,{data:ee,headers:an.from($.headers),status:$.status,statusText:$.statusText,config:g,request:W})})}catch(P){throw O&&O(),P&&P.name==="TypeError"&&/Load failed|fetch/i.test(P.message)?Object.assign(new Le("Network Error",Le.ERR_NETWORK,g,W),{cause:P.cause||P}):Le.from(P,P&&P.code,g,W)}}},ax=new Map,Cc=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=ax;for(;a--;)l=s[a],c=d.get(l),c===void 0&&d.set(l,c=a?new Map:ix(t)),d=c;return c};Cc();const Bi={http:Ag,xhr:ex,fetch:{get:Cc}};M.forEach(Bi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const kc=e=>`- ${e}`,lx=e=>M.isFunction(e)||e===null||e===!1,Tc={getAdapter:(e,t)=>{e=M.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!lx(r)&&(o=Bi[(a=String(r)).toLowerCase()],o===void 0))throw new Le(`Unknown adapter '${a}'`);if(o&&(M.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
33
+ `+i.map(kc).join(`
34
+ `):" "+kc(i[0]):"as no adapter specified";throw new Le("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Bi};function Hi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new zr(null,e)}function Ec(e){return Hi(e),e.headers=an.from(e.headers),e.data=zi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Tc.getAdapter(e.adapter||uo.adapter,e)(e).then(function(r){return Hi(e),r.data=zi.call(e,e.transformResponse,r),r.headers=an.from(r.headers),r},function(r){return dc(r)||(Hi(e),r&&r.response&&(r.response.data=zi.call(e,e.transformResponse,r.response),r.response.headers=an.from(r.response.headers))),Promise.reject(r)})}const Ic="1.12.2",os={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{os[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Nc={};os.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Ic+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Le(o(i," has been removed"+(n?" in "+n:"")),Le.ERR_DEPRECATED);return n&&!Nc[i]&&(Nc[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},os.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function cx(e,t,n){if(typeof e!="object")throw new Le("options must be an object",Le.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 Le("option "+s+" must be "+l,Le.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Le("Unknown option "+s,Le.ERR_BAD_OPTION)}}const ss={assertOptions:cx,validators:os},Mn=ss.validators;let wr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new ac,response:new ac}}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=vr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&ss.assertOptions(r,{silentJSONParsing:Mn.transitional(Mn.boolean),forcedJSONParsing:Mn.transitional(Mn.boolean),clarifyTimeoutError:Mn.transitional(Mn.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:ss.assertOptions(o,{encode:Mn.function,serialize:Mn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),ss.assertOptions(n,{baseUrl:Mn.spelling("baseURL"),withXsrfToken:Mn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&M.merge(s.common,s[n.method]);s&&M.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=an.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const c=[];this.interceptors.response.forEach(function(x){c.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const g=[Ec.bind(this),void 0];for(g.unshift(...a),g.push(...c),h=g.length,d=Promise.resolve(n);f<h;)d=d.then(g[f++],g[f++]);return d}h=a.length;let p=n;for(;f<h;){const g=a[f++],x=a[f++];try{p=g(p)}catch(y){x.call(this,y);break}}try{d=Ec.call(this,p)}catch(g){return Promise.reject(g)}for(f=0,h=c.length;f<h;)d=d.then(c[f++],c[f++]);return d}getUri(t){t=vr(this.defaults,t);const n=mc(t.baseURL,t.url,t.allowAbsoluteUrls);return ic(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){wr.prototype[t]=function(n,r){return this.request(vr(r||{},{method:t,url:n,data:(r||{}).data}))}}),M.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(vr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}wr.prototype[t]=n(),wr.prototype[t+"Form"]=n(!0)});let ux=class zm{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 zr(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 zm(function(o){t=o}),cancel:t}}};function dx(e){return function(n){return e.apply(null,n)}}function fx(e){return M.isObject(e)&&e.isAxiosError===!0}const Ui={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ui).forEach(([e,t])=>{Ui[t]=e});function Ac(e){const t=new wr(e),n=Vl(wr.prototype.request,t);return M.extend(n,wr.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Ac(vr(e,o))},n}const Ot=Ac(uo);Ot.Axios=wr,Ot.CanceledError=zr,Ot.CancelToken=ux,Ot.isCancel=dc,Ot.VERSION=Ic,Ot.toFormData=es,Ot.AxiosError=Le,Ot.Cancel=Ot.CanceledError,Ot.all=function(t){return Promise.all(t)},Ot.spread=dx,Ot.isAxiosError=fx,Ot.mergeConfig=vr,Ot.AxiosHeaders=an,Ot.formToJSON=e=>cc(M.isHTMLForm(e)?new FormData(e):e),Ot.getAdapter=Tc.getAdapter,Ot.HttpStatusCode=Ui,Ot.default=Ot;const{Axios:fT,AxiosError:hT,CanceledError:pT,isCancel:mT,CancelToken:gT,VERSION:xT,all:yT,Cancel:vT,isAxiosError:wT,spread:bT,toFormData:ST,AxiosHeaders:CT,HttpStatusCode:kT,formToJSON:TT,getAdapter:ET,mergeConfig:IT}=Ot,_c=typeof window<"u"?window.__API_BASE_URL__:void 0,jc=_c?qn(_c):void 0;function qn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let is=null;const Wi=new Set;function Rc(){return is}function Vi(e){is=e,Wi.forEach(t=>t(e))}function Pc(e){return Wi.add(e),()=>Wi.delete(e)}const gn=Ot.create({...jc?{baseURL:jc}:{},timeout:3e4,withCredentials:!0});gn.interceptors.request.use(e=>(is&&(e.headers.Authorization=`Bearer ${is}`),e)),gn.interceptors.response.use(e=>e,e=>Promise.reject(e));async function En(e,t){return gn.defaults.baseURL?(await gn.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ki(e,t,n){return gn.defaults.baseURL?(await gn.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Oc(e,t,n){return gn.defaults.baseURL?(await gn.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Mc(e,t){return gn.defaults.baseURL?(await gn.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function In(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Dc{get baseUrl(){const t=gn.defaults.baseURL;return t?qn(String(t)):""}updateConfig(t){t.baseUrl&&(gn.defaults.baseURL=qn(String(t.baseUrl))),t.authToken!==void 0&&Vi(t.authToken)}getAuthToken(){return Rc()}setAuthToken(t){Vi(t)}onTokenChange(t){return Pc(t)}async listThreads(){const t=await En("/threads"),n=In(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ki("/threads",t?{title:t}:void 0);return In(r)}async updateThread(t,n){const r=await Oc(`/threads/${t}`,{title:n});return In(r)}async deleteThread(t){const n=await Mc(`/threads/${t}`);return In(n)}async threadInfo(t){const n=await En(`/threads/${t}/info`);return In(n)}async listAgents(){const t=await En("/agents"),n=In(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await En(`/agents/${t}`);return In(n)}async getAgentSchema(t){const n=await En(`/agents/${t}/schema`);return In(n)}async getState(t){const n=await En(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return In(n)}async getStateHistory(t){const n=await En(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return In(n)}async cancelRun(t){const n=await Ki("/runs/cancel",{threadId:t});return In(n)}}const er=new Dc,Lc=w.createContext(null);function hx({children:e,apiConfig:t}){const n=er;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(Lc.Provider,{value:r,children:e})}function qi(){const e=w.useContext(Lc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function px(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 mx(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const c=await px(l);a.push({filename:l.name,data:c,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const gx={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Gi(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 ho(e,t){return`${e??""}::${t??""}`}function as(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(!Gi(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=yx(t),i=Fc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function Fc(e,t){if(!Gi(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((_,j)=>Tx(_,j)).filter(_=>!!_),d=ln(e.config),f=ln(d==null?void 0:d.configurable),h=$t(f,["checkpoint_id","checkpointId"]),p=$t(f,["checkpoint_ns","checkpointNs"]),g=ln(e==null?void 0:e.parentConfig),x=ln(g==null?void 0:g.configurable),y=$t(x,["checkpoint_id","checkpointId"])??null,m=$t(x,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),T=c[c.length-1]??null,k=ln(e==null?void 0:e.metadata),C=$t(k,["branch_label","branchLabel"]),E=$t(x,["checkpoint_id","checkpointId"]),R=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:c,checkpointId:h??null,checkpointNs:p??null,nextCursor:y,nextCursorNs:m,interrupt:xx(a,c,t),createdAt:S,parentId:E??null,branchLabel:C??null,lastMessageId:(T==null?void 0:T.id)??null,hasMessages:c.length>0,messagesLen:c.length,metadata:k??null,config:d??null,parentConfig:g??null,next:R??null,tasks:l??null,values:i??null}}function xx(e,t,n){const r=Cx(e,n);return r||Sx(t,n)}function yx(e){const t=new Map;e.forEach((o,s)=>{if(!Gi(o))return;const i=Fc(o,s);if(!(i!=null&&i.checkpointId))return;const a=ho(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,vx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>zc(s.createdAt??"")-zc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function vx(e,t){return{...e,metadata:ls(e.metadata,t.metadata)??null,config:ls(e.config,t.config)??null,parentConfig:ls(e.parentConfig,t.parentConfig)??null,next:wx(e.next,t.next)??null,tasks:bx(e.tasks,t.tasks)??null,values:ls(e.values,t.values)??null}}function ls(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 wx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function bx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Sx(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 Cx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=kx(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=po(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=po(r.state,`${o}-state`);if(s)return s}}return null}function kx(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,c,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,g=typeof l=="string"&&l.trim()?l:Array.isArray(c)&&typeof c[0]=="string"?String(c[0]):"task",x=Array.isArray(d)?d:void 0,y=h.length?h[h.length-1]:void 0;return{id:p,name:g,interrupts:x,state:y!==void 0?y:f}}const n=ln(e);if(!n)return null;const r=$t(n,["id","task_id","taskId"])??t,o=$t(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 po(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=$c(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=po(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=po(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=po(l,t,n+1,r);if(c)return c}}return null}function $c(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=$t(n,["type","event","kind"]),o=$t(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=$c(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 zc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function Tx(e,t){if(!e||typeof e!="object")return null;const n=e,r=ln(e)??{},o=ln(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=gx[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=ln(o.additional_kwargs)??ln(o.additionalKwargs),d=ln(o.response_metadata)??ln(o.responseMetadata),f=$t(c,["createdAt","created_at"])??$t(o,["created_at","createdAt"]),h=$t(c,["checkpointId","checkpoint_id"]),p=$t(c,["checkpointNs","checkpoint_ns"]),g=Ex(o.content),x={id:l,role:i,content:g};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const y=_x(c,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),m=d?{...d}:void 0;y&&Object.keys(y).length&&(x.additionalKwargs=y),m&&Object.keys(m).length&&(x.responseMetadata=m);const b=Ix((c==null?void 0:c.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=Nx(o,x.content);S&&(x.content=S)}return x}function Ex(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>Bc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=Bc(e);return t?[t]:[]}return[]}function Bc(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=$t(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=$t(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 Hc(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=$t(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 Hc(e,t){var s;const n=$t(e,["id","call_id"])??t,r=$t(e,["name"])??$t(ln(e.function),["name"]);if(!n||!r)return null;const o=Ax(e.args??e.arguments??((s=ln(e.function))==null?void 0:s.arguments));return{type:"tool_call",id:n,name:r,args:o}}function Ix(e){return Array.isArray(e)?e.map((t,n)=>Hc(t,`tool_call_${n}`)).filter(t=>!!t):[]}function Nx(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 Ax(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 ln(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function $t(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function _x(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 jx(e){return e.type!=="thread_info"&&e.type!=="token"}const Rx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function Px(e,t){var n;switch(t.type){case"reset":return{messages:Yi(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};case"seed":{const r=Yi(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=Yi(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 Wc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Wc(o,s),e):e}case"interrupt_response":return{...e,messages:Vc(e.messages),pendingInterrupt:null};default:return e}}function Uc(e=[]){const[t,n]=w.useReducer(Px,{...Rx,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 Wc(e,t){var n,r,o,s,i;if(t.type==="message_start"&&t.role==="assistant"){const a=t.id,l=Lx(t.model);if(e.messages.some(f=>f.id===a)){const f=e.messagesStreamMeta??{},h={...f,[a]:f[a]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:a,messagesStreamMeta:h}}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??Kc(e.messages);if(!a)return e;const l=e.messages,c=l.findIndex(T=>T.id===a&&T.role==="assistant");if(c===-1)return e;const d=l[c],f=e.messagesStreamMeta??{},h=f[a]??{lastSeq:null,lastText:Yc(d.content)},p=t.seq??null;if(p!==null&&typeof p=="number"&&typeof h.lastSeq=="number"&&p<=h.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:p,lastSeq:h.lastSeq}),e;const{newParts:g,newMeta:x,changed:y}=Ox(d.content,t.delta,h,p);if(!y)return e;const m={...d,content:g},b=cs(l,c,m),S={...f,[a]:x};return{...e,messages:b,messagesStreamMeta:S}}if(t.type==="message_end"){const a=e.assemblingId??Kc(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(h=>{var p;return(h==null?void 0:h.type)==="text"&&((p=h.text)==null?void 0:p.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:d.id,contentTypes:(r=d.content)==null?void 0:r.map(p=>p==null?void 0:p.type),contentPreview:(o=d.content)==null?void 0:o.map(p=>(p==null?void 0:p.type)==="text"?String(p.text).slice(0,100):p==null?void 0:p.type)});const h=[...l.slice(0,c),...l.slice(c+1)];return{...e,assemblingId:null,messages:h}}}return e}if(t.type==="tool_start"){const a=qc(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=Gc(e,d,c),h=f>=0?e.messages[f]:null,p=l??d[0]??`${c}-${Date.now()}`,g=(h==null?void 0:h.id)??`tool-${p}`,x=d[0]??p,y={type:"tool_call",id:x,name:c,args:t.args};if(h){const S=Ji(h,d,c,t.args),T={...h,name:h.name??c,additionalKwargs:S},k=f,C=k>=0?cs(e.messages,k,T):e.messages,E=us(T,d),R=Zi(e.toolIndex,g,E);return{...e,messages:C,toolIndex:R}}const m={id:g,role:"tool",name:c,createdAt:new Date().toISOString(),content:[y],additionalKwargs:Ji(void 0,d.length?d:[x],c,t.args)},b=us(m,d.length?d:[x]);return{...e,messages:[...e.messages,m],toolIndex:Zi(e.toolIndex,g,b)}}if(t.type==="tool_end"){const a=qc(t);if(!a.length&&!(typeof t.id=="string"&&t.id))return e;const l=t.name??null,c=Gc(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",h=a[0]??((i=d==null?void 0:d.id)==null?void 0:i.replace(/^tool-/,""))??`${f}-${Date.now()}`,p=(d==null?void 0:d.id)??`tool-${h}`,g=us(d,a);let x=t.output;if(typeof t.output=="string")try{const C=t.output.trim();(C.startsWith("{")||C.startsWith("["))&&(x=JSON.parse(C))}catch{x=t.output}const y={type:"text",text:typeof x=="string"?x:JSON.stringify(x)},m=(d==null?void 0:d.createdAt)??new Date().toISOString(),b=Ji(d??void 0,g.length?g:a,f),S={id:p,role:"tool",name:f??(d==null?void 0:d.name)??"tool",content:[y],createdAt:m,additionalKwargs:b},T=c>=0?cs(e.messages,c,S):[...e.messages,S],k=us(S,a.length?a:g);return{...e,messages:T,toolIndex:Zi(e.toolIndex,p,k)}}if(t.type==="checkpoint"){const a=t.checkpointNs??e.lastCheckpointNs??null,l=Dx(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=as(t),l=a.interrupt,c=a.latest,d=l===null?Vc(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 e}function Yi(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function cs(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Vc(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 Kc(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function qc(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 Xi(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 Ji(e,t,n,r){const o=new Set,s=l=>{typeof l=="string"&&l.trim()&&o.add(l.trim())};if(e){const l=Xi(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 us(e,t){const n=new Set;for(const o of t)typeof o=="string"&&o.trim()&&n.add(o.trim());const r=Xi(e);for(const o of r)n.add(o);return Array.from(n)}function Zi(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 Gc(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(Xi(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 Yc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Ox(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??Yc(e);let l="",c=e.slice();if(s){const f=Mx(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",g={...h,text:p+l};c=[...c.slice(0,c.length-1),g]}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 Xc(e){return e.replace(/\s+/g," ").trim()}function Mx(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=Xc(e),o=Xc(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 Dx(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 cs(e,r,s)}return e}function Lx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Jc(e={}){const t=w.useMemo(()=>qn(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,h]=w.useState(""),[p,g]=w.useState(null),[x,y]=w.useState(0),[m,b]=w.useState(!1),S=w.useRef(null),T=w.useRef(!0),k=w.useRef(0),C=w.useRef(null),E=w.useRef(null),R=w.useRef(null),_=w.useRef(null),j=w.useCallback(O=>{o(O)},[]),D=w.useCallback(()=>{h(""),g(null),d(null),E.current=null,R.current=null,_.current=null},[]),z=w.useCallback(()=>{var O;console.debug("[use-chat] stop() invoked - aborting stream"),(O=S.current)==null||O.abort(),S.current=null,C.current=null,l(!1),b(!1),k.current=0,y(0)},[]),W=w.useCallback((O,B,P)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h(""),g(null),E.current=null,R.current=null,_.current=null;const V=new AbortController;S.current=V;let $=null,F=null,ee=!1;return C.current={threadId:O.threadId??null,headers:{}},(async()=>{var ve,Ie,Z,de,we,ne,L,J,se,ue,le,Me,U,ye,_e,Pe,et,nt;const te=Ze=>{var be;try{const Qe=JSON.parse(JSON.stringify(Ze));return(be=Qe==null?void 0:Qe.payload)!=null&&be.files_info&&Array.isArray(Qe.payload.files_info)&&(Qe.payload.files_info=Qe.payload.files_info.map(it=>({...it,data:it!=null&&it.data?`<base64 ${String(it.data).length} chars>`:it==null?void 0:it.data}))),Qe}catch{return Ze}};try{let Ze={};try{if(r)Ze={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const De=window.__AUTH_TOKEN__,Rt=((ve=window.localStorage)==null?void 0:ve.getItem("authToken"))||null;let kt=null;try{const ke=(Ie=window.localStorage)==null?void 0:Ie.getItem("chat-settings");ke&&(kt=((Z=JSON.parse(ke))==null?void 0:Z.apiKey)||null)}catch{}const q=De||Rt||kt||null;q&&(Ze={Authorization:`Bearer ${q}`})}}catch{}console.debug("[use-chat] POST",t+n,te(O));let be={};if(typeof window<"u")try{const at=(de=window.localStorage)==null?void 0:de.getItem("authSessionId");at&&(be={"X-Session-Id":at})}catch{}const Qe={...Ze,...be,...s.current},it={"Content-Type":"application/json",Accept:"text/event-stream",...Qe},rt=await fetch(t+n,{method:"POST",headers:it,body:JSON.stringify(O),signal:V.signal,credentials:i});if(C.current&&(C.current.headers=Qe),!rt.ok||!rt.body){const at=await rt.text().catch(()=>"");console.debug("[use-chat] non-OK response",rt.status,at==null?void 0:at.slice(0,500));const De=`stream ${rt.status}${at?": "+at:""}`;throw(we=P==null?void 0:P.onConnectionError)==null||we.call(P,De),ee=!0,$="error",F=De,new Error(De)}b(!0);const Be=rt.body.getReader(),wt=new TextDecoder;let mt="",jt=[];k.current=0,y(0);let Dt=0,bt=null;const He=()=>{if(jt.length){const at=jt.join("");jt=[],T.current&&h(De=>De+at)}bt=null},St=()=>{typeof window<"u"&&bt==null&&(bt=requestAnimationFrame(He))};let Ct=Date.now();const Lt=setInterval(()=>{var at;if(Date.now()-Ct>6e4){const De="Stream idle timeout";d(De),$="error",F=De,V.abort(),(at=P==null?void 0:P.onError)==null||at.call(P,De)}},5e3),Ft=1024*1024;try{const at=rt.headers.get("X-Thread-Id")||rt.headers.get("x-thread-id"),De=rt.headers.get("X-Thread-Created")||rt.headers.get("x-thread-created"),Rt=at??null,kt=String(De??"").toLowerCase()==="true";for(C.current&&!C.current.threadId&&(C.current={...C.current,threadId:Rt}),(ne=P==null?void 0:P.onOpen)==null||ne.call(P,{threadId:Rt,created:kt});;){const{value:q,done:ke}=await Be.read();if(ke)break;mt+=wt.decode(q,{stream:!0}),mt.length>Ft&&(mt="",console.warn("Stream buffer reset: exceeded 1MB"));let xe;for(;(xe=mt.indexOf(`
36
36
 
37
- `))>=0;){const xt=dt.slice(0,ge);dt=dt.slice(ge+2);const ft=Fx(xt);if(!ft)continue;let ht;try{ht=JSON.parse(ft)}catch{console.debug("[use-chat] malformed SSE:",ft.slice(0,200));continue}const Be=$x(ht)?ht.data:ht;Vt=Date.now();const Ft=Be.seq;if(Ft!==void 0){if(Ft<=Nt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:Ft,lastProcessedSeq:Nt,type:Be.type});continue}Nt>0&&Ft>Nt+1&&((D=P==null?void 0:P.onGap)==null||D.call(P,{from:Nt,to:Ft})),Nt=Ft,k.current=Ft,y(Ft)}if(console.debug("[use-chat] received event",{seq:Be.seq,type:Be.type,preview:(()=>{var Oe;try{return Be.type==="message_delta"?{deltaTypes:(Oe=Be.delta)==null?void 0:Oe.map(it=>it.type),textLen:(Be.delta||[]).filter(it=>it.type==="text").map(it=>String(it.text||"").length)}:Be.content||Be.delta?{hasContent:!0}:{}}catch(it){return{err:String(it)}}})()}),Be.type==="checkpoint")E.current=Be.checkpointId??null,R.current=Be.checkpointNs??null,g(Be.checkpointId??null);else if(Be.type==="state_history"){_.current=Be;try{const it=ns(Be).latest;it&&(E.current=it.checkpointId??null,R.current=it.checkpointNs??null,g(it.checkpointId??null))}catch(Oe){console.warn("[use-chat] Failed to hydrate state_history payload",Oe)}}try{H==null||H(Be)}catch(Oe){console.error("[use-chat] Error in onEvent callback:",Oe,"for event:",Be.type)}if(Be.type==="token"&&e.autoAppendAssistant!==!1)kt.push(Be.content),Tt();else if(Be.type==="message_delta"){const Oe=Be.delta.filter(it=>it.type==="text").map(it=>it.text).join("");Oe&&e.autoAppendAssistant!==!1&&(kt.push(Oe),Tt())}else if(Be.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(G=P==null?void 0:P.onHeartbeat)==null||G.call(P,Be)}catch(Oe){console.warn("[use-chat] heartbeat callback failed",Oe)}}else if(tt!==null&&cancelAnimationFrame(tt),He(),Be.type==="checkpoint")g(Be.checkpointId);else if(Be.type==="error"){const Oe=Be;if(d(Oe.message),F="error",$=Oe.message,Oe.error_type==="auth_error"||Oe.code==="TOKEN_EXPIRED"||((ae=Oe.message)==null?void 0:ae.includes("token"))||((fe=Oe.message)==null?void 0:fe.includes("401"))||((B=Oe.message)==null?void 0:B.includes("unauthorized"))||((le=Oe.message)==null?void 0:le.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",Oe.message);try{(Q=P==null?void 0:P.onAuthError)==null||Q.call(P,Oe.message)}catch(ar){console.warn("[use-chat] onAuthError handler failed",ar)}W.abort()}}}}He(),F===null&&!W.signal.aborted&&(F="complete")}catch(st){if(st.name==="AbortError")F=F??"aborted";else{const Le=st.message||String(st);F="error",$=Le,d(Le),(Ae=P==null?void 0:P.onError)==null||Ae.call(P,Le)}}finally{try{await Ye.cancel()}catch{}finally{(ve=Ye.releaseLock)==null||ve.call(Ye)}tt!==null&&typeof window<"u"&&window.cancelAnimationFrame(tt),clearInterval(zt)}}catch(et){if(et.name==="AbortError")F=F??"aborted";else{const Se=et.message||String(et);F="error",$=Se,d(Se),(Re=P==null?void 0:P.onError)==null||Re.call(P,Se),ne||((Ve=P==null?void 0:P.onConnectionError)==null||Ve.call(P,Se),ne=!0)}}finally{const et=k.current,Se=E.current,nt=R.current,ut=_.current,rt=F??(W.signal.aborted?"aborted":$?"error":"complete");try{(Qe=P==null?void 0:P.onClosed)==null||Qe.call(P,{reason:rt,lastSeq:et,lastCheckpointId:Se,lastCheckpointNs:nt,lastStateHistory:ut,error:$})}catch(Ye){console.warn("[use-chat] onClosed callback failed",Ye)}l(!1),b(!1),S.current=null,k.current=0,y(0),C.current=null}})(),{close:()=>W.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var O;T.current=!1,(O=S.current)==null||O.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:x,connected:m,stream:V,stop:z,clear:L,setToken:j}}function $x(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Fx(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
38
- `)}const Kc=200;function zx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=w.useRef(null),d=w.useRef(null),f=w.useRef(new Map),h=w.useRef(null),p=w.useCallback(_=>{try{const j=globalThis.structuredClone;if(typeof j=="function")return j(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),g=w.useCallback((_,j)=>{if(!_)return;const L=f.current.get(_)??[],z=p(j),V=L.length>=Kc?[...L.slice(L.length-Kc+1),z]:[...L,z];f.current.set(_,V)},[p]),x=w.useCallback(_=>{_&&f.current.set(_,[])},[]),y=w.useCallback(_=>{const j=_??d.current;if(!j)return;const L=f.current.get(j);L!=null&&L.length&&L.forEach(z=>{try{n(z)}catch(V){console.error("[useChatStreamingService] Failed to replay buffered event",V)}})},[n]),m=w.useCallback(_=>{var z,V,O,H,P;const j=_.seq??null;if(j!==null){const W=c.current;if(W!==null){if(j<=W)return;j>W+1&&(o==null||o({from:W,to:j}))}c.current=j}if(_.type==="thread_info"){d.current=_.threadId,h.current&&(h.current.threadIdGuess=_.threadId),x(_.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",_);try{t(_)}catch(W){console.error("[useChatStreamingService] Error in onThreadInfo handler:",W)}return}if(_.type==="heartbeat"){try{r==null||r(_)}catch(W){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",W)}return}if(_.type==="error"){const W=_;if(W.error_type==="auth_error"||W.code==="TOKEN_EXPIRED"||((z=W.message)==null?void 0:z.includes("token"))||((V=W.message)==null?void 0:V.includes("401"))||((O=W.message)==null?void 0:O.includes("unauthorized"))||((H=W.message)==null?void 0:H.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",W.message);try{a==null||a(W.message)}catch($){console.warn("[useChatStreamingService] onAuthError handler failed",$)}}}const L=_.threadId??(_.type==="state_history"?_.threadId:void 0)??d.current??((P=h.current)==null?void 0:P.threadIdGuess)??null;if(_.type==="state_history"&&(d.current=L??d.current),jx(_)){_.type==="checkpoint"||_.type==="state_history"?x(L??null):g(L??null,_);try{n(_)}catch(W){console.error("[useChatStreamingService] Error in onMessageEvent handler:",W)}return}try{r==null||r(_)}catch(W){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",W)}},[g,x,n,o,t,r]),{stream:b,stop:S,isStreaming:T,error:k,setToken:C}=Vc({baseUrl:e,token:null}),E=w.useCallback((_,j)=>{c.current=null,d.current=_.threadId??null,h.current={request:_,callbacks:j,manualStop:!1,threadIdGuess:_.threadId??null},b(_,m,{onOpen:j==null?void 0:j.onOpen,onError:L=>{var z;(z=j==null?void 0:j.onError)==null||z.call(j,L)},onGap:(j==null?void 0:j.onGap)??o,onConnectionError:L=>{var z;i==null||i(L),(z=j==null?void 0:j.onConnectionError)==null||z.call(j,L)},onAuthError:L=>{var z;a==null||a(L),(z=j==null?void 0:j.onAuthError)==null||z.call(j,L)},onHeartbeat:L=>{var z;try{l==null||l(L)}catch(V){console.warn("[useChatStreamingService] onHeartbeat handler failed",V)}try{(z=j==null?void 0:j.onHeartbeat)==null||z.call(j,L)}catch(V){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",V)}},onClosed:L=>{var H,P,W,F;const z=((H=h.current)==null?void 0:H.manualStop)??!1,V=d.current??((P=h.current)==null?void 0:P.threadIdGuess)??((W=L.lastStateHistory)==null?void 0:W.threadId)??null;(L.reason==="complete"||L.reason==="aborted"&&z)&&x(V);const O={...L,threadId:V,manualStop:z};try{s==null||s(O)}catch($){console.warn("[useChatStreamingService] onStreamClosed handler failed",$)}try{(F=j==null?void 0:j.onClosed)==null||F.call(j,O)}catch($){console.warn("[useChatStreamingService] downstream onClosed handler failed",$)}h.current&&(h.current=null)}})},[x,m,a,i,l,o,s,b]),R=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),S()},[S]);return w.useMemo(()=>({startStream:E,stop:R,isStreaming:T,error:k,setAuthToken:C,replayBufferedEvents:y}),[E,R,T,k,C,y])}function qi(e){return e==null?e:{...e}}function Bx(e){return e==null?e:{...e}}function Hx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function Ux(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function hn(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=qi(e==null?void 0:e.metadata),s=qi(e==null?void 0:e.config),i=qi(e==null?void 0:e.parentConfig),a=Hx(e==null?void 0:e.next),l=Ux(e==null?void 0:e.tasks),c=Bx(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),c!==void 0&&(d.values=c),d}function Wx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function qc(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}const is=300;function Gc(e,t=is){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function xr(){return typeof window<"u"&&typeof window.localStorage<"u"}function Gi(e){if(!xr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Xi(e,t){if(!xr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Yi(e){if(xr())try{window.localStorage.removeItem(e)}catch{}}const Vx="cachedThreads",Kx="v1",Ji=200;function qx(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Zi(e,t){return`cachedThreads:v1:${e}:${qx(t||"anon")}`}function Gx(){const e=Gi(Vx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Xx(e){const t=Gi(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function Qi(e,t){Xi(e,JSON.stringify(t))}function ea(e){const t=Xx(e);if(t.length>0)return t;const n=Gx();if(n.length>0)try{Qi(e,n.slice(0,Ji))}catch{}return n}function as(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function ta(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function na(e,t){return`${e}${t}`}function Yx(e,t){const n=Gi(na(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:hn(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function Jx(e,t,n=100){if(!xr())return;const r=hn(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=na(e,t.threadId),i=JSON.stringify(o);if(!Xi(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const c=window.localStorage.key(l);if(!c||c===s||!c.startsWith(e))continue;const d=window.localStorage.getItem(c);if(!d){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:c,updatedAt:h})}catch{a.push({key:c,updatedAt:0})}}a.sort((l,c)=>l.updatedAt-c.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),Xi(s,i))break}catch{}}function Zx(e,t){Yi(na(e,t))}function Qx(e){if(xr())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}const Xc=w.createContext(null),Yc=w.createContext(null),Jc=w.createContext(null),ey=w.createContext(!1),Zc=50,ty=750,ny=5,ry=1e3,oy=15e3;function Qc(e,t,n){return`${e}__${t??""}__${n??""}`}function ls(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 sy(e,t){return ls(e,t)}function iy(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 ay(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 eu(e,t){const n=ls(e.metadata,t.metadata),r=ls(e.config,t.config),o=ls(e.parentConfig,t.parentConfig),s=iy(e.next,t.next),i=ay(e.tasks,t.tasks),a=sy(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function ly({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onAuthError:a,onThreadChange:l}){const{api:c,baseUrl:d}=Bi(),f=w.useMemo(()=>zn(d),[d]),h=w.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=w.useMemo(()=>`threadPayload:${Kx}:${h}:`,[h]),g=w.useCallback(N=>Yx(p,N),[p]),x=w.useCallback((N,A=100)=>{Jx(p,N,A)},[p]),y=w.useCallback(N=>{Zx(p,N)},[p]),m=w.useCallback(()=>{Qx(p)},[p]),[b,S]=w.useState(()=>{var N;return Zi(h,(N=c.getAuthToken)==null?void 0:N.call(c))}),[T,k]=w.useState(()=>{var A;const N=ea(Zi(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return as(N)}),C=w.useMemo(()=>ta(T),[T]),[E,R]=w.useState(t),[_,j]=w.useState(!1),[L,z]=w.useState(!1),[V,O]=w.useState(null),[H,P]=w.useState(null),[W,F]=w.useState(null),[$,ne]=w.useState([]),oe=w.useCallback(()=>{const N=ea(b);w.startTransition(()=>{k(as(N))})},[b]),[we,Ne]=w.useState(!1),[Z,ie]=w.useState(!1),[Te,ee]=w.useState(null),[D,G]=w.useState(void 0),[ae,fe]=w.useState(void 0),[B,le]=w.useState(void 0),{state:Q,dispatch:Ae,seed:ve,prepend:Re,pushUser:Ve,onEvent:Qe,reset:et}=Lc(),Se=w.useRef(E);w.useEffect(()=>{Se.current=E},[E]);const nt=w.useRef(!1),ut=w.useRef([]),rt=w.useRef(null),Ye=w.useRef(null),It=w.useRef(new Map),dt=w.useRef(E),kt=w.useRef(!1),Nt=w.useRef(null),tt=w.useRef(new Map),He=w.useRef(new Map),Tt=w.useRef(new Map),Vt=w.useRef(new Map),zt=w.useCallback(N=>{if(!N){ne([]);return}const A=tt.current.get(N);if(!A||!A.length){ne([]);return}ne(A.map(U=>hn(U,{cloneMessages:!0})))},[]);w.useEffect(()=>{zt(E)},[E,zt]);const Kt=w.useCallback(()=>{var K;const N=Vt.current;if(N.size<=Zc)return;const A=Array.from(N.entries()).sort((ce,re)=>ce[1].timestamp-re[1].timestamp),U=N.size-Zc;for(let ce=0;ce<U;ce++){const re=(K=A[ce])==null?void 0:K[0];re&&N.delete(re)}},[]),st=w.useCallback((N,A,U)=>{if(!N)return;const K=U==="replace"?[]:tt.current.get(N)??[],ce=U==="replace"?A:[...A,...K];if(!ce.length){U==="replace"&&tt.current.set(N,[]);return}const re=new Map;for(const Ge of ce){if(!(Ge!=null&&Ge.checkpointId))continue;const Ue=`${Ge.checkpointId}::${Ge.checkpointNs??""}`,bt=hn(Ge,{cloneMessages:!0}),At=re.get(Ue);if(!At){re.set(Ue,bt);continue}const Qt=eu(At,bt);re.set(Ue,{...At,...Qt})}const qe=Array.from(re.values()).sort((Ge,Ue)=>{const bt=Number.isFinite(Date.parse(Ge.createdAt??""))?Date.parse(Ge.createdAt??""):0;return(Number.isFinite(Date.parse(Ue.createdAt??""))?Date.parse(Ue.createdAt??""):0)-bt});tt.current.set(N,qe),N===Se.current&&zt(N)},[zt]),Le=w.useCallback((N,A,U)=>{if(!N)return;const K=He.current.get(N),ce=U==="replace"||!K?new Map:new Map(K);if(A&&typeof A=="object")for(const[re,qe]of Object.entries(A)){if(!(qe!=null&&qe.checkpointId))continue;const Ge=re||lo(qe.checkpointId,qe.checkpointNs??null);ce.set(Ge,hn(qe,{cloneMessages:!0}))}He.current.set(N,ce)},[]),_t=w.useCallback((N,A)=>{const{threadId:U,checkpointId:K=null,checkpointNs:ce=null}=N,re=Qc(U,K,ce);if(A!=null&&A.force)Tt.current.delete(re),Vt.current.delete(re);else{if(A!=null&&A.preferCache){const bt=Vt.current.get(re);if(bt)return Promise.resolve(bt.payload)}const Ue=Tt.current.get(re);if(Ue)return Ue}const Ge=c.getStateHistory({threadId:U,checkpointId:K??void 0,checkpointNs:ce??void 0}).then(Ue=>(Vt.current.set(re,{payload:Ue,timestamp:Date.now()}),Kt(),Ue)).finally(()=>{Tt.current.get(re)===Ge&&Tt.current.delete(re)});return Tt.current.set(re,Ge),Ge},[c,Kt]),yt=w.useCallback((N,A)=>new Promise((U,K)=>{const ce=async()=>{nt.current=!0;try{await N(),U()}catch(re){K(re)}finally{nt.current=!1;const re=ut.current.shift();re&&re().catch(()=>{})}};nt.current?ut.current.push(ce):ce().catch(re=>{K(re)})}),[]),X=w.useRef(C.length),Ce=w.useRef(!1);w.useEffect(()=>{X.current=C.length},[C.length]),w.useEffect(()=>{const N=Q.pendingInterrupt??Wx(Q.messages);qc(W,N)||F(N??null)},[W,Q.messages,Q.pendingInterrupt]);const ge=w.useCallback(async()=>{const N=X.current>0;N||j(!0);try{const A=await c.listThreads();w.startTransition(()=>{k(U=>{const K=qe=>qe.map(Ge=>`${Ge.threadId}:${Ge.updatedAt??""}:${Ge.messageCount??""}`).join("|"),ce=ta(U);return K(ce)===K(A)||A.length===0&&ce.length>0&&!Ce.current?U:as(A)})}),O(null),Ce.current||(Ce.current=!0)}catch(A){i==null||i(String(A)),console.error("[ChatSessionProvider] Failed to refresh threads:",A),O(String(A))}finally{N||j(!1)}},[c,i]),xt=w.useRef(!1),ft=w.useRef(null),ht=w.useRef(null),Be=w.useRef(""),[Ft,Oe]=w.useState("idle"),it=w.useRef({attempts:0,timer:null,reason:null}),ar=w.useRef(null),jr=w.useRef(0),lr=w.useRef(()=>{}),Rr=w.useRef(()=>{}),Pr=w.useRef(()=>{}),Kn=w.useCallback((N,A)=>{if(!xr())return;ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null);const U=N.map(ce=>`${ce.threadId}:${ce.updatedAt??""}:${ce.messageCount??""}`).join("|");if(N.length===0){try{Yi(b)}catch{}Be.current="";return}if(U===Be.current)return;const K=()=>{try{const ce=N.slice(0,Ji);Qi(b,ce),Be.current=U}catch{}finally{ht.current=null}};if(A!=null&&A.immediate){K();return}ht.current=window.setTimeout(()=>{Gc(K)},is)},[b]),Qr=w.useCallback(()=>{Kn(C,{immediate:!0})},[Kn,C]),I=w.useCallback((N,A,U,K)=>{var Ol;const ce=U??Se.current;if(!ce)return;const re=hn(N),qe=ce===Se.current,Ge=(K==null?void 0:K.persist)!==!1;if(A==="replace"){if(Ge){const Ht={threadId:ce,snapshot:hn(N,{cloneMessages:!0})};It.current.set(ce,Ht),dt.current=ce}if(!qe)return;ve(re.messages,{checkpointId:re.checkpointId??null,checkpointNs:re.checkpointNs??null,pendingInterrupt:re.interrupt??null}),F(re.interrupt??null),ee(re.nextCursor??null),Ne(!!re.nextCursor),G(re.checkpointId??void 0),fe(re.checkpointNs??void 0),le(re.nextCursorNs??void 0);return}const Ue=It.current.get(ce),bt=(Ue==null?void 0:Ue.snapshot)??null,At=Array.isArray(bt==null?void 0:bt.messages)?bt.messages:[],Qt=hn(bt),Fn=Array.isArray(N==null?void 0:N.messages)?N.messages:[],Bt=new Set,Lt=[...Fn,...At].filter(Ht=>{const Ml=Ht==null?void 0:Ht.id;return Ml?Bt.has(Ml)?!1:(Bt.add(Ml),!0):!0}),Bo=eu(Qt,re),Ho={checkpointId:Qt.checkpointId??re.checkpointId??null,checkpointNs:Qt.checkpointNs??re.checkpointNs??null,createdAt:re.createdAt??Qt.createdAt??null,parentId:re.parentId??Qt.parentId??null,branchLabel:re.branchLabel??Qt.branchLabel??null,lastMessageId:((Ol=Lt[Lt.length-1])==null?void 0:Ol.id)??null,messagesLen:Lt.length,hasMessages:Lt.length>0,messages:Lt,nextCursor:re.nextCursor??Qt.nextCursor??null,nextCursorNs:re.nextCursorNs??Qt.nextCursorNs??null,interrupt:Qt.interrupt??re.interrupt??null,...Bo};if(It.current.set(ce,{threadId:ce,snapshot:hn(Ho,{cloneMessages:!0})}),!qe)return;Fn.length&&Re(Fn);const eo=N&&Object.prototype.hasOwnProperty.call(N,"checkpointId")?N.checkpointId:void 0,dr=N&&Object.prototype.hasOwnProperty.call(N,"checkpointNs")?N.checkpointNs:void 0,Or=N&&Object.prototype.hasOwnProperty.call(N,"nextCursor")?N.nextCursor:void 0,fr=N&&Object.prototype.hasOwnProperty.call(N,"nextCursorNs")?N.nextCursorNs:void 0;ee(Ht=>Or!==void 0?Or??Ht??null:Ht??null),Ne(Ht=>Or!==void 0?!!Or:Ht),G(Ht=>eo!==void 0?eo??Ht??void 0:Ht??void 0),fe(Ht=>dr!==void 0?dr??Ht??void 0:Ht??void 0),le(Ht=>fr!==void 0?fr??void 0:Ht)},[Re,ve,F]),q=w.useCallback(N=>{if(N.threadId!=null&&N.threadId!==Se.current)return;const A=hn(N.snapshot,{cloneMessages:!0});ve(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),F(A.interrupt??null),ee(A.nextCursor??null),Ne(!!A.nextCursor),G(A.checkpointId??void 0),fe(A.checkpointNs??void 0),le(A.nextCursorNs??void 0),dt.current=N.threadId,zt(N.threadId??Se.current??null)},[ve,F,zt]),ue=w.useCallback(N=>{if(!N)return;It.current.delete(N),y(N),tt.current.delete(N),He.current.delete(N),N===Se.current&&ne([]);const A=`${N}__`;for(const U of Tt.current.keys())U.startsWith(A)&&Tt.current.delete(U);for(const U of Vt.current.keys())U.startsWith(A)&&Vt.current.delete(U);dt.current===N&&(dt.current=null)},[y]),ke=w.useCallback(()=>{const N=Se.current;N&&ue(N),et([]),Ne(!1),ie(!1),ee(null),G(void 0),fe(void 0),le(void 0)},[ue,et]),Xe=w.useCallback(({from:N,to:A})=>{const U=Se.current;U&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${A}) for thread ${U}`)},[]),at=w.useCallback(N=>{const A=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:A,title:N.title,created:N.created,currentThreads:C.length});const U={threadId:A,title:N.title||`Thread ${A.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};Se.current!==A&&(!Se.current&&Q.messages.length<=1&&(Ye.current=A),R(A)),w.startTransition(()=>{k(K=>{const ce=K.byId[A];return ce?ce.title===U.title&&ce.updatedAt===U.updatedAt&&ce.messageCount===U.messageCount?K:{byId:{...K.byId,[A]:U},order:K.order}:{byId:{...K.byId,[A]:U},order:[A,...K.order]}})})},[Q.messages.length]),{startStream:Ke,stop:$e,isStreaming:jt,error:vt,setAuthToken:pt,replayBufferedEvents:qt}=zx({baseUrl:f,onThreadInfo:at,onMessageEvent:Qe,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:Xe,onStreamClosed:N=>{lr.current(N)},onConnectionError:N=>{Rr.current(N)},onAuthError:a,onHeartbeat:N=>{Pr.current(N)}}),Gt=w.useCallback(()=>{const N=it.current;N.timer!==null&&(window.clearTimeout(N.timer),N.timer=null),N.reason=null},[]),J=w.useCallback((N,A)=>{Oe("connecting"),Ke(N,{onOpen:U=>{var K;Gt(),it.current.attempts=0,Oe("connected"),(K=A==null?void 0:A.onOpen)==null||K.call(A,U)},onError:U=>{var K;(K=A==null?void 0:A.onError)==null||K.call(A,U)},onGap:(A==null?void 0:A.onGap)??Xe,onConnectionError:U=>{var K;Rr.current(U),(K=A==null?void 0:A.onConnectionError)==null||K.call(A,U)},onHeartbeat:U=>{var K;Pr.current(U),(K=A==null?void 0:A.onHeartbeat)==null||K.call(A,U)},onClosed:U=>{var K;lr.current(U),(K=A==null?void 0:A.onClosed)==null||K.call(A,U)}})},[Gt,Xe,Oe,Ke]),de=w.useCallback(()=>{const N=Se.current;if(!N)return null;const A=ar.current,U=Q.lastCheckpointId??(A==null?void 0:A.lastCheckpointId)??null,K=Q.lastCheckpointNs??(A==null?void 0:A.lastCheckpointNs)??null,ce={};return U&&(ce.checkpointId=U),K&&(ce.checkpointNs=K),{threadId:N,checkpointId:U,checkpointNs:K,command:{kind:"resume",value:ce}}},[Q.lastCheckpointId,Q.lastCheckpointNs]),he=w.useCallback(N=>{const A=it.current;if(A.timer!==null)return;if(A.attempts>=ny){Oe("error");return}A.attempts+=1,A.reason=N;const U=Math.min(ry*Math.pow(2,A.attempts-1),oy);Oe("reconnecting"),A.timer=window.setTimeout(()=>{A.timer=null,A.reason=null;const K=de();if(!K){Oe("error");return}qt(K.threadId??void 0),J(K)},U)},[de,qt,Oe,J]),wt=w.useCallback(N=>{if(ar.current=N,N.manualStop||N.reason==="complete"){Gt(),it.current.attempts=0,Oe("idle");return}if(N.error&&(N.error.includes("token")||N.error.includes("401")||N.error.includes("unauthorized")||N.error.includes("Unauthorized")||N.error.includes("TOKEN_EXPIRED")||N.error.includes("auth_error"))){console.error("[ChatSessionProvider] Auth error detected:",N.error);try{a==null||a(N.error)}catch(U){console.error("[ChatSessionProvider] Error in onAuthError handler:",U)}return}(N.reason==="error"||N.reason==="aborted")&&he(`closed:${N.reason}`)},[Gt,he,Oe,a]),Ot=w.useCallback(N=>{console.warn("[ChatSessionProvider] Stream connection error:",N),he("connection-error")},[he]),an=w.useCallback(N=>{jr.current=Date.now(),Oe(A=>A==="reconnecting"?"connected":A)},[Oe]);lr.current=wt,Rr.current=Ot,Pr.current=an,w.useEffect(()=>()=>{Gt()},[Gt]);const qn=w.useCallback(()=>{Gt(),it.current.attempts=0,Oe("idle"),$e()},[Gt,Oe,$e]);w.useEffect(()=>{xt.current=jt},[jt]),w.useEffect(()=>{if(!xr())return;ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null);const N=C.map(U=>`${U.threadId}:${U.updatedAt??""}:${U.messageCount??""}`).join("|");if(C.length===0){try{Yi(b)}catch{}Be.current="";return}if(N===Be.current)return;const A=()=>{try{const U=C.slice(0,Ji);Qi(b,U),Be.current=N}catch{}finally{ht.current=null}};return ht.current=window.setTimeout(()=>{Gc(A),ht.current=null},is),()=>{ht.current!==null&&(window.clearTimeout(ht.current),ht.current=null)}},[C,Kn]),w.useEffect(()=>{var K;const N=c.getAuthToken();pt(N);const A=ce=>{const re=Zi(h,ce);Nt.current!==re&&(Nt.current=re,kt.current=!1),S(re);const qe=ea(re);w.startTransition(()=>{k(as(qe))}),ce&&!kt.current&&(kt.current=!0)};A(N);const U=(K=c.onTokenChange)==null?void 0:K.call(c,ce=>{ce!==N&&(pt(ce),m(),Tt.current.clear(),Vt.current.clear(),A(ce))});return()=>{U==null||U()}},[c,h,pt,m]);const cr=w.useCallback(async N=>{var K;const A=`Thread ${(K=crypto.randomUUID)==null?void 0:K.call(crypto)}`,U={threadId:A,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(ce=>({byId:{...ce.byId,[A]:U},order:[A,...ce.order]})),R(A);try{const ce=await c.createThread(N),re=typeof ce=="string"?ce:ce.threadId;return k(qe=>{const Ge=qe.byId[A];if(!Ge)return qe;const Ue={...qe.byId};delete Ue[A],Ue[re]={...Ge,threadId:re};const bt=qe.order.map(At=>At===A?re:At);return{byId:Ue,order:bt}}),R(re),setTimeout(()=>ge(),10),O(null),re}catch(ce){throw k(re=>{if(!re.byId[A])return re;const qe={...re.byId};delete qe[A];const Ge=re.order.filter(Ue=>Ue!==A);return{byId:qe,order:Ge}}),R(null),O(String(ce)),ce}},[c,ge]),Fo=w.useCallback(async N=>{try{await c.deleteThread(N);let A=null;k(U=>{if(!U.byId[N])return U;const K={...U.byId};delete K[N];const ce=U.order.filter(qe=>qe!==N),re={byId:K,order:ce};return A=ta(re),re}),A&&Kn(A,{immediate:!0}),ue(N),Se.current===N&&(Ye.current=N,R(null),Se.current=null,dt.current=null,ke()),await ge(),O(null)}catch(A){throw O(String(A)),A}},[c,ke,ue,ge,Kn]),Rm=w.useCallback(async(N,A)=>{try{await c.updateThread(N,A),k(U=>{const K=U.byId[N];return K?{byId:{...U.byId,[N]:{...K,title:A}},order:U.order}:U}),O(null)}catch(U){throw await ge(),O(String(U)),U}},[c,ge]),ur=w.useCallback(async(N,A,U,K=!1)=>{await yt(async()=>{if(Ye.current===N&&!K){Ye.current=null;return}if(rt.current===N&&!K)return;R(Bt=>Bt===N?Bt:N),Se.current=N;const qe=Qc(N,A??null,U??null),Ge=Vt.current.get(qe),Ue=!K&&!A&&!U&&Ge&&Date.now()-Ge.timestamp<ty,bt=!K&&!A&&!U;let At=!1;if(bt){const Bt=It.current.get(N);if(Bt)q(Bt),At=!0;else{const Lt=g(N);Lt&&(It.current.set(N,Lt),q(Lt),At=!0)}}const Qt=K||!At||!!A||!!U,Fn=async Bt=>{Bt&&z(!0),rt.current=N;try{const Lt=await _t({threadId:N,checkpointId:A,checkpointNs:U},{force:K}),{latest:Bo,checkpoints:Ho,snapshots:eo}=ns(Lt);I(Bo,"replace",N),st(N,Ho,"replace"),Le(N,eo,"replace"),P(null)}catch(Lt){throw(!At||K||Bt)&&(i==null||i(String(Lt))),P(String(Lt)),Lt}finally{rt.current=null,Bt&&z(!1)}};Qt?await Fn(!0):bt&&At&&!Ue&&Fn(!1).catch(Bt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Bt)})},`loadThread-${N}`)},[q,I,yt,_t,i,st,Le]),Pm=w.useCallback(async()=>{await yt(async()=>{const N=Se.current;N&&ue(N),Ye.current=null,R(null),Se.current=null,dt.current=null,ke(),G(void 0),fe(void 0),le(void 0),ne([]);try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[ke,ue,yt]),Om=w.useCallback(async(N,A)=>{var re;const U=Se.current;if(!U)throw new Error("No active thread");const K=lo(N,A??null),ce=(re=He.current.get(U))==null?void 0:re.get(K);if(ce){await yt(async()=>{I(ce,"replace",U,{persist:!1})},`navigateToCheckpoint-${U}-${K}`);return}await ur(U,N,A??void 0,!0)},[I,yt,ur]),Mm=w.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");await ur(Se.current,void 0,void 0,!0)},[ur]),Dm=w.useCallback(async()=>{if(!Se.current)throw new Error("No active thread");if(Z||!we)return;const N=Te;if(N){ie(!0);try{const A=Se.current,U=await _t({threadId:A,checkpointId:N??D??null,checkpointNs:B??ae??null}),{latest:K,checkpoints:ce,snapshots:re}=ns(U),qe=A?He.current.get(A):null;let Ge=ce.length>0;if(Ge&&qe&&qe.size>0&&(Ge=ce.some(Ue=>{if(!(Ue!=null&&Ue.checkpointId))return!1;const bt=lo(Ue.checkpointId,Ue.checkpointNs??null);return!qe.has(bt)})),!Ge){ee(null),le(void 0),Ne(!1),P(null);return}I(K,"prepend",A??void 0),A&&(st(A,ce,"prepend"),Le(A,re,"prepend")),P(null)}catch(A){throw P(String(A)),A}finally{ie(!1)}}},[I,_t,we,D,ae,B,Te,Z,st,Le]),Lm=w.useCallback(N=>{if(N!=null&&N.threadId){if(N.checkpointId){const A=lo(N.checkpointId,N.checkpointNs??null),U=hn({...N,interrupt:N.interrupt??null},{cloneMessages:!0});Le(N.threadId,{[A]:U},"prepend")}I(N,"replace",N.threadId)}},[I,Le]),zo=w.useCallback(async(N,A)=>{var Or;const U=Se.current,K=(N==null?void 0:N.text)??"",ce=(N==null?void 0:N.attachments)??[],re=ce.length?ce:(A==null?void 0:A.attachments)??[],qe=N==null?void 0:N.messageAdditionalKwargs,Ge={...(A==null?void 0:A.payloadExtras)??{},...(N==null?void 0:N.payload)??{}};if(!U&&!Object.keys(Ge).length&&re.length===0&&!K.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!U&&!Ge.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Ue,filesInfo:bt}=await mx(c,re),At=[...Ue];K&&K.trim()&&At.push({type:"text",text:K.trim()});const Qt=!!U,Fn=Qt?(A==null?void 0:A.checkpointId)??Q.lastCheckpointId??void 0:void 0,Bt=Qt?(A==null?void 0:A.checkpointNs)??Q.lastCheckpointNs??void 0:void 0,Lt={id:((Or=crypto.randomUUID)==null?void 0:Or.call(crypto))||`user-${Date.now()}`,role:"user",content:At,createdAt:new Date().toISOString(),...Fn!=null?{checkpointId:Fn}:{},...Bt!=null?{checkpointNs:Bt}:{}};qe&&Object.keys(qe).length&&(Lt.additionalKwargs={...Lt.additionalKwargs??{},...qe}),At.length>0&&Ve(Lt);const Bo={...Lt,content:At},Ho=re.length>0,eo={messages:At.length>0?[Bo]:[],files_info:bt,...o&&Ho&&s?{active_agent:s}:{},...Ge},dr={threadId:U??null,payload:eo,checkpointId:Fn??null,checkpointNs:Bt??null,nodeFilter:(A==null?void 0:A.nodeFilter)??null,config:A==null?void 0:A.config,command:(A==null?void 0:A.command)??null};dr.threadId||delete dr.threadId,dr.command||delete dr.command,J(dr,{onError:fr=>{console.warn("[ChatSessionProvider] Stream error:",fr)},onOpen:({threadId:fr})=>{!Se.current&&fr&&(Q.messages.length<=1&&(Ye.current=fr),R(fr))},onGap:Xe})},[c,o,s,Xe,Q.lastCheckpointId,Q.lastCheckpointNs,Q.messages.length,Ve,J]),$m=w.useCallback(async(N,A,U)=>{if(!Se.current)throw new Error("No active thread to handle interrupt");const ce=A?U??!0:!1;try{try{Ae({type:"interrupt_response",payload:{interruptId:N}})}catch(re){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",re)}await zo({payload:{}},{checkpointId:Q.lastCheckpointId??void 0,checkpointNs:Q.lastCheckpointNs??void 0,command:{kind:"resume",value:ce}}),F(null)}catch(re){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,re),re}},[Ae,Q.lastCheckpointId,Q.lastCheckpointNs,zo]);w.useEffect(()=>{if(l==null||l(E),E)try{localStorage.setItem("lastThreadId",E)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[E,l]),w.useEffect(()=>((async()=>{try{if(ge().catch(A=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",A),i==null||i(String(A))}),!r&&!t)try{const A=localStorage.getItem("lastThreadId");A&&(R(A),n&&await ur(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await ur(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),w.useEffect(()=>{const N=Se.current;if(!N||dt.current!==N)return;Q.messages.length&&Q.messages[Q.messages.length-1];const A=hn({checkpointId:Q.lastCheckpointId??null,checkpointNs:Q.lastCheckpointNs??null,messages:Q.messages.slice(),nextCursor:Te??null,nextCursorNs:B??null,interrupt:Q.pendingInterrupt??W??null}),U=It.current.get(N),K=U==null?void 0:U.snapshot,ce=!K||K.messages.length!==A.messages.length||K.messages.some((Ue,bt)=>{var At;return(Ue==null?void 0:Ue.id)!==((At=A.messages[bt])==null?void 0:At.id)}),re=((K==null?void 0:K.checkpointId)??null)!==A.checkpointId||((K==null?void 0:K.checkpointNs)??null)!==A.checkpointNs,qe=((K==null?void 0:K.nextCursor)??null)!==A.nextCursor||((K==null?void 0:K.nextCursorNs)??null)!==A.nextCursorNs,Ge=!qc((K==null?void 0:K.interrupt)??null,A.interrupt??null);if(ce||re||qe||Ge){const Ue={threadId:N,snapshot:A};It.current.set(N,Ue),ft.current&&window.clearTimeout(ft.current),ft.current=window.setTimeout(()=>{try{x(Ue,100)}catch(bt){console.warn("[ChatSessionProvider] Failed to persist thread payload:",bt)}},is)}},[Te,B,Q.lastCheckpointId,Q.lastCheckpointNs,Q.messages,Q.pendingInterrupt,W,x]);const tT=w.useMemo(()=>({threads:C,currentThreadId:E,setCurrentThreadId:R,isLoading:_,error:V,actions:{createThread:cr,deleteThread:Fo,renameThread:Rm,refreshThreads:()=>ge()},persistThreadsCache:Qr,hydrateFromCache:oe}),[C,E,_,V,cr,Fo,Rm,ge,Qr,oe,R]),nT=w.useMemo(()=>{const N=Q.lastBranch??null,A=Q.assemblingId??null,U=N||A?{branchLabel:(N==null?void 0:N.branchLabel)??null,lastBranch:N,assemblingMessageId:A}:null;return{threadId:E,messages:Q.messages,interrupt:W,checkpoint:{id:Q.lastCheckpointId??null,namespace:Q.lastCheckpointNs??null},checkpoints:$,metadata:U,isLoading:L,isHistoryLoading:Z,error:H,hasMore:we,loadOlder:Dm,seedFromSnapshot:Lm,clearState:ke,navigateToCheckpoint:Om,returnToLatest:Mm,loadThread:ur,clearThread:Pm,respondToInterrupt:$m}},[Pm,ke,E,W,we,Z,L,Dm,ur,Q.assemblingId,Q.lastBranch,Q.lastCheckpointId,Q.lastCheckpointNs,Q.messages,Om,$m,Mm,Lm,H,$]),rT=w.useMemo(()=>({isStreaming:jt,error:vt,connectionState:Ft,submit:zo,send:zo,stop:qn,setAuthToken:pt}),[Ft,jt,vt,qn,zo,pt]);return u.jsx(ey.Provider,{value:!0,children:u.jsx(Jc.Provider,{value:rT,children:u.jsx(Xc.Provider,{value:tT,children:u.jsx(Yc.Provider,{value:nT,children:e})})})})}function cs(){const e=w.useContext(Xc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function us(){const e=w.useContext(Yc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function tu(){const e=w.useContext(Jc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function ds({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(hx,{apiConfig:t,children:u.jsx(ly,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function se(...e){return Hm.twMerge(Bm.clsx(e))}const cy=Uo.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"}}),lt=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?hr.Slot:"button";return u.jsx(i,{className:se(cy({variant:t,size:n,className:e})),ref:s,...o})});lt.displayName="Button";const nu=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:se("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));nu.displayName="Textarea";function uy({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:h="",allowEmptySend:p=!1}){const g=i!==void 0,[x,y]=w.useState(e),m=(g?i:x)??"",[b,S]=w.useTransition(),T=w.useRef(null),k=w.useRef(0),C=w.useRef(null);w.useEffect(()=>{g||(y(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,g]);const E=w.useCallback(()=>{const H=T.current;H&&(H.style.height="auto",H.style.height=`${H.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,m]);const R=w.useCallback((H,{fromUser:P})=>{g||y(H),P&&(a==null||a(H))},[g,a]),_=w.useCallback(async H=>{H&&H.preventDefault();const P=(m??"").trim();if(!P&&!p)return;const W=++k.current;C.current={id:W,shouldClear:!0},S(()=>{var F,$,ne;try{const oe=l(P);oe&&typeof oe.then=="function"?oe.then(()=>{var we,Ne;((we=C.current)==null?void 0:we.id)===W&&C.current.shouldClear&&(g||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((Ne=C.current)==null?void 0:Ne.id)===W&&(C.current=null)}).catch(()=>{var we;((we=C.current)==null?void 0:we.id)===W&&(C.current=null)}):(((F=C.current)==null?void 0:F.id)===W&&C.current.shouldClear&&(g||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),(($=C.current)==null?void 0:$.id)===W&&(C.current=null))}catch{((ne=C.current)==null?void 0:ne.id)===W&&(C.current=null)}})},[m,l,p,g,a]),j=w.useCallback(H=>{const P=H.target.value;R(P,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[R]),L=w.useCallback(H=>{H.key==="Enter"&&!H.shiftKey?(H.preventDefault(),_()):H.key==="Escape"&&t&&(H.preventDefault(),c==null||c())},[_,t,c]),O=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return u.jsx("form",{onSubmit:H=>void _(H),className:`w-full ${f}`,children:u.jsxs("div",{className:"flex items-end gap-2",children:[u.jsx("div",{className:"flex-1",children:u.jsx(nu,{ref:T,value:m,onChange:j,onKeyDown:L,placeholder:t?"Edit your message...":n,className:O,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(lt,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(pe.Square,{size:16})}):u.jsx(lt,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!m.trim()&&!p||b,children:u.jsx(pe.Send,{size:16})})})]})})}const dy=w.memo(uy),fs=0,Xn=1,$r=2,ru=4;function ou(e){return()=>e}function fy(e){e()}function su(e,t){return n=>e(t(n))}function iu(e,t){return()=>e(t)}function hy(e,t){return n=>e(t,n)}function ra(e){return e!==void 0}function py(...e){return()=>{e.map(fy)}}function Fr(){}function hs(e,t){return t(e),e}function my(e,t){return t(e)}function St(...e){return e}function ct(e,t){return e(Xn,t)}function ze(e,t){e(fs,t)}function oa(e){e($r)}function Pt(e){return e(ru)}function be(e,t){return ct(e,hy(t,fs))}function Cn(e,t){const n=e(Xn,r=>{n(),t(r)});return n}function au(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function lu(e,t){return e===t}function Ct(e=lu){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function je(e){return t=>n=>{e(n)&&t(n)}}function me(e){return t=>su(t,e)}function _n(e){return t=>()=>{t(e)}}function Y(e,...t){const n=gy(...t);return(r,o)=>{switch(r){case $r:oa(e);return;case Xn:return ct(e,n(o))}}}function jn(e,t){return n=>r=>{n(t=e(t,r))}}function yr(e){return t=>n=>{e>0?e--:t(n)}}function Bn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function We(...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);ct(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 gy(...e){return t=>e.reduceRight(my,t)}function xy(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Xn:return s?n===s?void 0:(r(),n=s,t=ct(e,s),t):(r(),Fr);case $r:r(),n=null;return}}}function te(e){let t=e;const n=Je();return(r,o)=>{switch(r){case fs:t=o;break;case Xn:{o(t);break}case ru:return t}return n(r,o)}}function Yt(e,t){return hs(te(t),n=>be(e,n))}function Je(){const e=[];return(t,n)=>{switch(t){case fs:e.slice().forEach(r=>{r(n)});return;case $r:e.splice(0,e.length);return;case Xn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function ln(e){return hs(Je(),t=>be(e,t))}function ot(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:yy(),singleton:n}}const yy=()=>Symbol();function vy(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 Dt(...e){const t=Je(),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);ct(s,l=>{n[i]=l,r=r|a,r===o&&ze(t,n)})}),function(s,i){switch(s){case $r:{oa(t);return}case Xn:return r===o&&i(n),ct(t,i)}}}function _e(e,t=lu){return Y(e,Ct(t))}function sa(...e){return function(t,n){switch(t){case $r:return;case Xn:return py(...e.map(r=>ct(r,n)))}}}var sn=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(sn||{});const wy={0:"debug",3:"error",1:"log",2:"warn"},by=()=>typeof globalThis>"u"?window:globalThis,Yn=ot(()=>{const e=te(3);return{log:te((t,n,r=1)=>{var o;const s=(o=by().VIRTUOSO_LOG_LEVEL)!=null?o:Pt(e);r>=s&&console[wy[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function vr(e,t,n){return ia(e,t,n).callbackRef}function ia(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 Sy(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Cy(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let g;p&&(g=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,m=i?a?i.offsetWidth:i.offsetHeight:p?a?g.innerWidth:g.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(x,0),viewportHeight:m}),s==null||s(a?cu("column-gap",getComputedStyle(d).columnGap,o):cu("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return ia(c,n,l)}function Cy(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},sn.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 cu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,sn.WARN),t==="normal"?0:parseInt(t??"0",10)}function uu(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,h;if(t){const p=t.getBoundingClientRect(),g=c.top-p.top;h=p.height-Math.max(0,g),f=g+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=ia(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 en=ot(()=>{const e=Je(),t=Je(),n=te(0),r=Je(),o=te(0),s=Je(),i=Je(),a=te(0),l=te(0),c=te(0),d=te(0),f=Je(),h=Je(),p=te(!1),g=te(!1),x=te(!1);return be(Y(e,me(({scrollTop:y})=>y)),t),be(Y(e,me(({scrollHeight:y})=>y)),i),be(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:g,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),uo={lvl:0};function du(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 mt(e){return e===uo}function fo(e,t){if(!mt(e))return t===e.k?e.v:t<e.k?fo(e.l,t):fo(e.r,t)}function kn(e,t,n="k"){if(mt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=kn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return kn(e.l,t,n)}function cn(e,t,n){return mt(e)?pu(t,n,1):t===e.k?$t(e,{k:t,v:n}):t<e.k?mu($t(e,{l:cn(e.l,t,n)})):mu($t(e,{r:cn(e.r,t,n)}))}function zr(){return uo}function ps(e,t,n){if(mt(e))return[];const r=kn(e,t)[0];return ky(la(e,r,n))}function aa(e,t){if(mt(e))return uo;const{k:n,l:r,r:o}=e;if(t===n){if(mt(r))return o;if(mt(o))return r;{const[s,i]=hu(r);return ms($t(e,{k:s,l:fu(r),v:i}))}}else return t<n?ms($t(e,{l:aa(r,t)})):ms($t(e,{r:aa(o,t)}))}function wr(e){return mt(e)?[]:[...wr(e.l),{k:e.k,v:e.v},...wr(e.r)]}function la(e,t,n){if(mt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(la(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(la(s,t,n))),a}function ms(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(ca(t))return gu($t(e,{lvl:n-1}));if(!mt(t)&&!mt(t.r))return $t(t.r,{l:$t(t,{r:t.r.l}),lvl:n,r:$t(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ca(e))return ua($t(e,{lvl:n-1}));if(!mt(r)&&!mt(r.l)){const o=r.l,s=ca(o)?r.lvl-1:r.lvl;return $t(o,{l:$t(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ua($t(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function $t(e,t){return pu(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 fu(e){return mt(e.r)?e.l:ms($t(e,{r:fu(e.r)}))}function ca(e){return mt(e)||e.lvl>e.r.lvl}function hu(e){return mt(e.r)?[e.k,e.v]:hu(e.r)}function pu(e,t,n,r=uo,o=uo){return{k:e,l:r,lvl:n,r:o,v:t}}function mu(e){return ua(gu(e))}function gu(e){const{l:t}=e;return!mt(t)&&t.lvl===e.lvl?$t(t,{r:$t(e,{l:t.r})}):e}function ua(e){const{lvl:t,r:n}=e;return!mt(n)&&!mt(n.r)&&n.lvl===t&&n.r.lvl===t?$t(n,{l:$t(e,{r:n.l}),lvl:t+1}):e}function ky(e){return du(e,({k:t,v:n})=>({index:t,value:n}))}function xu(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function ho(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const da=ot(()=>({recalcInProgress:te(!1)}),[],{singleton:!0});function yu(e,t,n){return e[gs(e,t,n)]}function gs(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function Ty(e,t,n,r){const o=gs(e,t,r),s=gs(e,n,r,o);return e.slice(o,s+1)}function Jn(e,t){return Math.round(e.getBoundingClientRect()[t])}function xs(e){return!mt(e.groupOffsetTree)}function fa({index:e},t){return t===e?0:t<e?-1:1}function Ey(){return{groupIndices:[],groupOffsetTree:zr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:zr()}}function Iy(e,t){let n=mt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),mt(e)){e=cn(e,0,s);continue}const a=ps(e,i-1,o+1);if(a.some(Oy(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=aa(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=cn(e,o+1,h));c&&(e=cn(e,i,s))}return[e,n]}function Ny(e){return typeof e.groupIndex<"u"}function Ay({offset:e},t){return t===e?0:t<e?-1:1}function po(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=yu(t,e,fa),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function vu(e,t){if(!xs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function wu(e,t,n){if(Ny(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=vu(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function _y(e,t,n,r=0){return r>0&&(t=Math.max(t,yu(e,r,fa).offset)),du(Ty(e,t,n,Ay),Py)}function jy(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,sn.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&mt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((g,x)=>cn(cn(g,x,h),x+1,p),i)}else[i,a]=Iy(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=ha(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>cn(h,p,po(p,f,o)),zr()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Ry(e){return wr(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 bu(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 ha(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=gs(o,t-1,fa),a=o[l].offset;const c=kn(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===kn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of ps(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Py(e){return{index:e.index,value:e}}function Oy(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 My={offsetHeight:"height",offsetWidth:"width"},Rn=ot(([{log:e},{recalcInProgress:t}])=>{const n=Je(),r=Je(),o=Yt(r,0),s=Je(),i=Je(),a=te(0),l=te([]),c=te(void 0),d=te(void 0),f=te((k,C)=>Jn(k,My[C])),h=te(void 0),p=te(0),g=Ey(),x=Yt(Y(n,We(l,e,p),jn(jy,g),Ct()),g),y=Yt(Y(l,Ct(),jn((k,C)=>({current:C,prev:k.current}),{current:[],prev:[]}),me(({prev:k})=>k)),[]);be(Y(l,je(k=>k.length>0),We(x,p),me(([k,C,E])=>{const R=k.reduce((_,j,L)=>cn(_,j,po(j,C.offsetTree,E)||L),zr());return{...C,groupIndices:k,groupOffsetTree:R}})),x),be(Y(r,We(x),je(([k,{lastIndex:C}])=>k<C),me(([k,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:k}])),n),be(c,d);const m=Yt(Y(c,me(k=>k===void 0)),!0);be(Y(d,je(k=>k!==void 0&&mt(Pt(x).sizeTree)),me(k=>[{endIndex:0,size:k,startIndex:0}])),n);const b=ln(Y(n,We(x),jn(({sizes:k},[C,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:g}),me(k=>k.changed)));ct(Y(a,jn((k,C)=>({diff:k.prev-C,prev:C}),{diff:0,prev:0}),me(k=>k.diff)),k=>{const{groupIndices:C}=Pt(x);if(k>0)ze(t,!0),ze(s,k+bu(k,C));else if(k<0){const E=Pt(y);E.length>0&&(k-=bu(-k,E)),ze(i,k)}}),ct(Y(a,We(e)),([k,C])=>{k<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},sn.ERROR)});const S=ln(s);be(Y(s,We(x),me(([k,C])=>{const E=C.groupIndices.length>0,R=[],_=C.lastSize;if(E){const j=fo(C.sizeTree,0);let L=0,z=0;for(;L<k;){const O=C.groupIndices[z],H=C.groupIndices.length===z+1?1/0:C.groupIndices[z+1]-O-1;R.push({endIndex:O,size:j,startIndex:O}),R.push({endIndex:O+1+H-1,size:_,startIndex:O+1}),z++,L+=H+1}const V=wr(C.sizeTree);return L!==k&&V.shift(),V.reduce((O,{k:H,v:P})=>{let W=O.ranges;return O.prevSize!==0&&(W=[...O.ranges,{endIndex:H+k-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:H+k,prevSize:P,ranges:W}},{prevIndex:k,prevSize:0,ranges:R}).ranges}return wr(C.sizeTree).reduce((j,{k:L,v:z})=>({prevIndex:L+k,prevSize:z,ranges:[...j.ranges,{endIndex:L+k-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const T=ln(Y(i,We(x,p),me(([k,{offsetTree:C},E])=>{const R=-k;return po(R,C,E)})));return be(Y(i,We(x,p),me(([k,C,E])=>{if(C.groupIndices.length>0){if(mt(C.sizeTree))return C;let R=zr();const _=Pt(y);let j=0,L=0,z=0;for(;j<-k;){z=_[L];const V=_[L+1]-z-1;L++,j+=V+1}if(R=wr(C.sizeTree).reduce((V,{k:O,v:H})=>cn(V,Math.max(0,O+k),H),R),j!==-k){const V=fo(C.sizeTree,z);R=cn(R,0,V);const O=kn(C.sizeTree,-k+1)[1];R=cn(R,1,O)}return{...C,sizeTree:R,...ha(C.offsetTree,0,R,E)}}else{const R=wr(C.sizeTree).reduce((_,{k:j,v:L})=>cn(_,Math.max(0,j+k),L),zr());return{...C,sizeTree:R,...ha(C.offsetTree,0,R,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:m,unshiftWith:s}},St(Yn,da),{singleton:!0});function Dy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Su=ot(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Je(),i=Je(),a=ln(Y(s,me(Dy)));return be(Y(a,me(l=>l.totalCount)),n),be(Y(a,me(l=>l.groupIndices)),e),be(Y(Dt(o,t,r),je(([l,c])=>xs(c)),me(([l,c,d])=>kn(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),Ct(),me(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},St(Rn,en)),Zn=ot(([{log:e}])=>{const t=te(!1),n=ln(Y(t,je(r=>r),Ct()));return ct(t,r=>{r&&Pt(e)("props updated",{},sn.DEBUG)}),{didMount:n,propsReady:t}},St(Yn),{singleton:!0}),Ly=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Cu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Ly)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const mo=ot(([{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:h}])=>{const p=Je(),g=Je(),x=te(0);let y=null,m=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),m&&(clearTimeout(m),m=null),ze(l,!1)}return be(Y(p,We(n,f,r,x,a,i,h),We(e,s,o),me(([[T,k,C,E,R,_,j,L],z,V,O])=>{const H=Cu(T),{align:P,behavior:W,offset:F}=H,$=E-1,ne=wu(H,k,$);let oe=po(ne,k.offsetTree,z)+_;P==="end"?(oe+=V+kn(k.sizeTree,ne)[1]-C+O,ne===$&&(oe+=j)):P==="center"?oe+=(V+kn(k.sizeTree,ne)[1]-C+O)/2:oe-=R,F&&(oe+=F);const we=Ne=>{S(),Ne?(L("retrying to scroll to",{location:T},sn.DEBUG),ze(p,T)):(ze(g,!0),L("list did not change, scroll successful",{},sn.DEBUG))};if(S(),W==="smooth"){let Ne=!1;b=ct(t,Z=>{Ne=Ne||Z}),y=Cn(d,()=>{we(Ne)})}else y=Cn(Y(t,$y(150)),we);return m=setTimeout(()=>{S()},1200),ze(l,!0),L("scrolling from index to",{behavior:W,index:ne,top:oe},sn.DEBUG),{behavior:W,top:oe}})),c),{scrollTargetReached:g,scrollToIndex:p,topListHeight:x}},St(Rn,en,Yn),{singleton:!0});function $y(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function pa(e,t){e==0?t():requestAnimationFrame(()=>{pa(e-1,t)})}function ma(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const go=ot(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=te(!0),l=te(0),c=te(!0);return be(Y(i,We(l),je(([d,f])=>!!f),_n(!1)),a),be(Y(i,We(l),je(([d,f])=>!!f),_n(!1)),c),ct(Y(Dt(t,i),We(a,n,e,c),je(([[,d],f,{sizeTree:h},p,g])=>d&&(!mt(h)||ra(p))&&!f&&!g),We(l)),([,d])=>{Cn(o,()=>{ze(c,!0)}),pa(4,()=>{Cn(r,()=>{ze(a,!0)}),ze(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},St(Rn,en,mo,Zn),{singleton:!0});function ku(e,t){return Math.abs(e-t)<1.01}const xo="up",yo="down",Fy="none",zy={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},By=0,vo=ot(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=te(!1),a=te(!0),l=Je(),c=Je(),d=te(4),f=te(By),h=Yt(Y(sa(Y(_e(o),yr(1),_n(!0)),Y(_e(o),yr(1),_n(!1),au(100))),Ct()),!1),p=Yt(Y(sa(Y(n,_n(!0)),Y(n,_n(!1),au(200))),Ct()),!1);be(Y(Dt(_e(o),_e(f)),me(([b,S])=>b<=S),Ct()),a),be(Y(a,Bn(50)),c);const g=ln(Y(Dt(r,_e(s),_e(t),_e(e),_e(d)),jn((b,[{scrollHeight:S,scrollTop:T},k,C,E,R])=>{const _=T+k-S>-R,j={scrollHeight:S,scrollTop:T,viewportHeight:k};if(_){let z,V;return T>b.state.scrollTop?(z="SCROLLED_DOWN",V=b.state.scrollTop-T):(z="SIZE_DECREASED",V=b.state.scrollTop-T||b.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:V,state:j}}let L;return j.scrollHeight>b.state.scrollHeight?L="SIZE_INCREASED":k<b.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":T<b.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:j}},zy),Ct((b,S)=>b&&b.atBottom===S.atBottom))),x=Yt(Y(r,jn((b,{scrollHeight:S,scrollTop:T,viewportHeight:k})=>{if(ku(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:T};{const C=S-(T+k)<1;return b.scrollTop!==T&&C?{changed:!0,jump:b.scrollTop-T,scrollHeight:S,scrollTop:T}:{changed:!0,jump:0,scrollHeight:S,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),je(b=>b.changed),me(b=>b.jump)),0);be(Y(g,me(b=>b.atBottom)),i),be(Y(i,Bn(50)),l);const y=te(yo);be(Y(r,me(({scrollTop:b})=>b),Ct(),jn((b,S)=>Pt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?xo:yo,prevScrollTop:S},{direction:yo,prevScrollTop:0}),me(b=>b.direction)),y),be(Y(r,Bn(50),_n(Fy)),y);const m=te(0);return be(Y(h,je(b=>!b),_n(0)),m),be(Y(o,Bn(100),We(h),je(([b,S])=>!!S),jn(([b,S],[T])=>[S,T],[0,0]),me(([b,S])=>S-b)),m),{atBottomState:g,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:y,scrollVelocity:m}},St(en)),ys="top",vs="bottom",Tu="none";function Eu(e,t,n){return typeof e=="number"?n===xo&&t===ys||n===yo&&t===vs?e:0:n===xo?t===ys?e.main:e.reverse:t===vs?e.main:e.reverse}function Iu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ga=ot(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Je(),i=te(0),a=te(0),l=te(0),c=Yt(Y(Dt(_e(r),_e(o),_e(n),_e(s,ho),_e(l),_e(i),_e(t),_e(e),_e(a)),me(([d,f,h,[p,g],x,y,m,b,S])=>{const T=d-b,k=y+m,C=Math.max(h-T,0);let E=Tu;const R=Iu(S,ys),_=Iu(S,vs);return p-=b,p+=h+m,g+=h+m,g-=b,p>d+k-R&&(E=xo),g<d-C+f+_&&(E=yo),E!==Tu?[Math.max(T-h-Eu(x,ys,E)-R,0),T-C-m+f+Eu(x,vs,E)+_]:null}),je(d=>d!=null),Ct(ho)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},St(en),{singleton:!0});function Hy(e,t,n){if(xs(t)){const r=vu(e,t);return[{index:kn(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 xa={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ws(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 x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,g=h-d;return{bottom:d,firstItemIndex:s,items:Au(e,o,s),offsetBottom:g,offsetTop:c,top:p,topItems:Au(t,o,s),topListHeight:t.reduce((x,y)=>y.size+x,0),totalCount:n}}function Nu(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=ma(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ws(c,[],a,o,n,r)}function Au(e,t,n){if(e.length===0)return[];if(!xs(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=ps(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 br=ot(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:g}])=>{const x=te([]),y=te(0),m=Je();be(s.topItemsIndexes,x);const b=Yt(Y(Dt(p,g,_e(l,ho),_e(o),_e(r),_e(c),d,_e(x),_e(t),_e(n),e),je(([C,E,,R,,,,,,,_])=>{const j=_&&_.length!==R;return C&&!E&&!j}),me(([,,[C,E],R,_,j,L,z,V,O,H])=>{const P=_,{offsetTree:W,sizeTree:F}=P,$=Pt(y);if(R===0)return{...xa,totalCount:R};if(C===0&&E===0)return $===0?{...xa,totalCount:R}:Nu($,j,_,V,O,H||[]);if(mt(F))return $>0?null:ws(Hy(ma(j,R),P,H),[],R,O,P,V);const ne=[];if(z.length>0){const ie=z[0],Te=z[z.length-1];let ee=0;for(const D of ps(F,ie,Te)){const G=D.value,ae=Math.max(D.start,ie),fe=Math.min(D.end,Te);for(let B=ae;B<=fe;B++)ne.push({data:H==null?void 0:H[B],index:B,offset:ee,size:G}),ee+=G}}if(!L)return ws([],ne,R,O,P,V);const oe=z.length>0?z[z.length-1]+1:0,we=_y(W,C,E,oe);if(we.length===0)return null;const Ne=R-1,Z=hs([],ie=>{for(const Te of we){const ee=Te.value;let D=ee.offset,G=Te.start;const ae=ee.size;if(ee.offset<C){G+=Math.floor((C-ee.offset+O)/(ae+O));const B=G-Te.start;D+=B*ae+B*O}G<oe&&(D+=(oe-G)*ae,G=oe);const fe=Math.min(Te.end,Ne);for(let B=G;B<=fe&&!(D>=E);B++)ie.push({data:H==null?void 0:H[B],index:B,offset:D,size:ae}),D+=ae+O}});return ws(Z,ne,R,O,P,V)}),je(C=>C!==null),Ct()),xa);be(Y(e,je(ra),me(C=>C==null?void 0:C.length)),o),be(Y(b,me(C=>C.topListHeight)),f),be(f,a),be(Y(b,me(C=>[C.top,C.bottom])),i),be(Y(b,me(C=>C.items)),m);const S=ln(Y(b,je(({items:C})=>C.length>0),We(o,e),je(([{items:C},E])=>C[C.length-1].originalIndex===E-1),me(([,C,E])=>[C-1,E]),Ct(ho),me(([C])=>C))),T=ln(Y(b,Bn(200),je(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),me(({items:C})=>C[0].index),Ct())),k=ln(Y(b,je(({items:C})=>C.length>0),me(({items:C})=>{let E=0,R=C.length-1;for(;C[E].type==="group"&&E<R;)E++;for(;C[R].type==="group"&&R>E;)R--;return{endIndex:C[R].index,startIndex:C[E].index}}),Ct(xu)));return{endReached:S,initialItemCount:y,itemsRendered:m,listState:b,rangeChanged:k,startReached:T,topItemsIndexes:x,...h}},St(Rn,Su,ga,go,mo,vo,Zn,da),{singleton:!0}),_u=ot(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Je(),i=Yt(Y(Dt(n,e,r,t,o),me(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return be(_e(i),s),{totalListHeight:i,totalListHeightChanged:s}},St(en,br),{singleton:!0}),Uy=ot(([{viewportHeight:e},{totalListHeight:t}])=>{const n=te(!1),r=Yt(Y(Dt(n,e,t),je(([o])=>o),me(([,o,s])=>Math.max(0,o-s)),Bn(0),Ct()),0);return{alignToBottom:n,paddingTopAddition:r}},St(en,_u),{singleton:!0}),ju=ot(()=>({context:te(null)})),Wy=({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,Ru=ot(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Je();return be(Y(d,We(t,l,n,s,o,r,a),We(e),me(([[f,h,p,g,x,y,m,b],S])=>{const{align:T,behavior:k,calculateViewLocation:C=Wy,done:E,...R}=f,_=wu(f,h,g-1),j=po(_,h.offsetTree,S)+x+y,L=j+kn(h.sizeTree,_)[1],z=b+y,V=b+p-m,O=C({itemBottom:L,itemTop:j,locationParams:{align:T,behavior:k,...R},viewportBottom:V,viewportTop:z});return O?E&&Cn(Y(i,je(H=>!H),yr(Pt(i)?1:2)),E):E&&E(),O}),je(f=>f!==null)),c),{scrollIntoView:d}},St(Rn,en,mo,br,Yn),{singleton:!0});function Pu(e){return e?e==="smooth"?"smooth":"auto":!1}const Vy=(e,t)=>typeof e=="function"?Pu(e(t)):t&&Pu(e),Ky=ot(([{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:h},{scrollIntoView:p}])=>{const g=te(!1),x=Je();let y=null;function m(k){ze(i,{align:"end",behavior:k,index:"LAST"})}ct(Y(Dt(Y(_e(t),yr(1)),l),We(_e(g),s,a,f),me(([[k,C],E,R,_,j])=>{let L=C&&_,z="auto";return L&&(z=Vy(E,R||j),L=L&&!!z),{followOutputBehavior:z,shouldFollow:L,totalCount:k}}),je(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:C})=>{y&&(y(),y=null),Pt(n)?requestAnimationFrame(()=>{Pt(d)("following output to ",{totalCount:C},sn.DEBUG),m(k)}):y=Cn(e,()=>{Pt(d)("following output to ",{totalCount:C},sn.DEBUG),m(k),y=null})});function b(k){const C=Cn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(Pt(d)("scrolling to bottom due to increased size",{},sn.DEBUG),m("auto"))});setTimeout(C,100)}ct(Y(Dt(_e(g),t,c),je(([k,,C])=>k&&C),jn(({value:k},[,C])=>({refreshed:k===C,value:C}),{refreshed:!1,value:0}),je(({refreshed:k})=>k),We(g,t)),([,k])=>{Pt(a)&&b(k!==!1)}),ct(x,()=>{b(Pt(g)!==!1)}),ct(Dt(_e(g),o),([k,C])=>{k&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&m("auto")});const S=te(null),T=Je();return be(sa(Y(_e(r),me(k=>{var C;return(C=k==null?void 0:k.length)!=null?C:0})),Y(_e(t))),T),ct(Y(Dt(Y(T,yr(1)),l),We(_e(S),a,f,h),me(([[k,C],E,R,_,j])=>C&&R&&(E==null?void 0:E({context:j,totalCount:k,scrollingInProgress:_}))),je(k=>!!k),Bn(0)),k=>{y&&(y(),y=null),Pt(n)?requestAnimationFrame(()=>{Pt(d)("scrolling into view",{}),ze(p,k)}):y=Cn(e,()=>{Pt(d)("scrolling into view",{}),ze(p,k),y=null})}),{autoscrollToBottom:x,followOutput:g,scrollIntoViewOnChange:S}},St(Rn,vo,mo,go,Zn,Yn,en,ju,Ru)),qy=ot(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(be(Y(a,We(s),je(([,l])=>l!==0),We(o,r,t,n,e),me(([[,l],c,d,f,h,p=[]])=>Nu(l,c,d,f,h,p))),i),{}),St(Rn,go,br,Zn),{singleton:!0}),Gy=ot(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=te(0);return ct(Y(e,We(r),je(([,o])=>o!==0),me(([,o])=>({top:o}))),o=>{Cn(Y(n,yr(1),je(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ze(t,o)})})}),{initialScrollTop:r}},St(Zn,en,br),{singleton:!0}),Ou=ot(([{scrollVelocity:e}])=>{const t=te(!1),n=Je(),r=te(!1);return be(Y(e,We(r,t,n),je(([o,s])=>!!s),me(([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),ct(Y(Dt(t,e,n),We(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},St(vo),{singleton:!0}),ya=ot(([{scrollContainerState:e,scrollTo:t}])=>{const n=Je(),r=Je(),o=Je(),s=te(!1),i=te(void 0);return be(Y(Dt(n,r),me(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),be(Y(t,We(r),me(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},St(en)),Xy=ot(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Je(),d=te(void 0),f=te(null),h=te(null);return be(a,f),be(l,h),ct(Y(c,We(t,r,i,f,h,n)),([p,g,x,y,m,b,S])=>{const T=Ry(g.sizeTree);y&&m!==null&&b!==null&&(x=m.scrollTop-b.offsetTop),x-=S,p({ranges:T,scrollTop:x})}),be(Y(d,je(ra),me(Yy)),o),be(Y(s,We(d),je(([,p])=>p!==void 0),Ct(),me(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},St(Rn,en,go,Zn,ya));function Yy(e){return{align:"start",index:0,offset:e.scrollTop}}const Jy=ot(([{topItemsIndexes:e}])=>{const t=te(0);return be(Y(t,je(n=>n>=0),me(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},St(br));function Mu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Zy=Mu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Qy=ot(([{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:h},{log:p},{recalcInProgress:g}])=>{const x=ln(Y(l,We(i),jn(([,m,b,S],[{bottom:T,items:k,offsetBottom:C,totalCount:E},R])=>{const _=T+C;let j=0;return b===E&&m.length>0&&k.length>0&&(k[0].originalIndex===0&&m[0].originalIndex===0||(j=_-S,j!==0&&(j+=R))),[j,k,E,_]},[0,[],0,0]),je(([m])=>m!==0),We(r,a,n,o,p,g),je(([,m,b,S,,,T])=>!T&&!S&&m!==0&&b===xo),me(([[m],,,,,b])=>(b("Upward scrolling compensation",{amount:m},sn.DEBUG),m))));function y(m){m>0?(ze(t,{behavior:"auto",top:-m}),ze(e,0)):(ze(e,0),ze(t,{behavior:"auto",top:-m}))}return ct(Y(x,We(e,s)),([m,b,S])=>{S&&Zy()?ze(e,b-m):y(-m)}),ct(Y(Dt(Yt(s,!1),e,g),je(([m,b,S])=>!m&&!S&&b!==0),me(([m,b])=>b),Bn(1)),y),be(Y(f,me(m=>({top:-m}))),t),ct(Y(c,We(h,d),me(([m,{groupIndices:b,lastSize:S,sizeTree:T},k])=>{function C(E){return E*(S+k)}if(b.length===0)return C(m);{let E=0;const R=fo(T,0);let _=0,j=0;for(;_<m;){_++,E+=R;let L=b.length===j+1?1/0:b[j+1]-b[j]-1;_+L>m&&(E-=R,L=m-_+1),_+=L,E+=C(L),j++}return E}})),m=>{ze(e,m),requestAnimationFrame(()=>{ze(t,{top:m}),requestAnimationFrame(()=>{ze(e,0),ze(g,!1)})})}),{deviation:e}},St(en,vo,br,Rn,Yn,da)),ev=ot(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),St(ga,qy,Zn,Ou,_u,Gy,Uy,ya,Ru,Yn,ju)),Du=ot(([{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:h,initialTopMostItemIndex:p,scrolledToInitialItem:g},x,y,m,{listState:b,topItemsIndexes:S,...T},{scrollToIndex:k},C,{topItemCount:E},{groupCounts:R},_])=>(be(T.rangeChanged,_.scrollSeekRangeChanged),be(Y(_.windowViewportRect,me(j=>j.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:R,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:g,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...m,groupIndices:s,itemSize:i,listState:b,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,..._,...x,sizes:l,...y}),St(Rn,go,en,Xy,Ky,br,mo,Qy,Jy,Su,ev));function tv(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 bs=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Lu(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,m){y.propsReady&&ze(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];ze(S,m[b])}for(const b of o)if(b in m){const S=y[t.optional[b]];ze(S,m[b])}y.propsReady&&ze(y.propsReady,!0)}function c(y){return s.reduce((m,b)=>(m[b]=S=>{const T=y[t.methods[b]];ze(T,S)},m),{})}function d(y){return i.reduce((m,b)=>(m[b]=xy(y[t.events[b]]),m),{})}const f=w.forwardRef((y,m)=>{const{children:b,...S}=y,[T]=w.useState(()=>hs(vy(e),E=>{l(E,S)})),[k]=w.useState(iu(d,T));bs(()=>{for(const E of i)E in S&&ct(k[E],S[E]);return()=>{Object.values(k).map(oa)}},[S,k,T]),bs(()=>{l(T,S)}),w.useImperativeHandle(m,ou(c(T)));const C=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(C,{...tv([...r,...o,...i],S),children:b}):b})}),h=y=>{const m=w.useContext(a);return w.useCallback(b=>{ze(m[y],b)},[m,y])},p=y=>{const m=w.useContext(a)[y],b=w.useCallback(S=>ct(m,S),[m]);return w.useSyncExternalStore(b,()=>Pt(m),()=>Pt(m))},g=y=>{const m=w.useContext(a)[y],[b,S]=w.useState(iu(Pt,m));return bs(()=>ct(m,T=>{T!==b&&S(ou(T))}),[m,b]),b},x=w.version.startsWith("18")?p:g;return{Component:f,useEmitter:(y,m)=>{const b=w.useContext(a)[y];bs(()=>ct(b,m),[m,b])},useEmitterValue:x,usePublisher:h}}const $u=w.createContext(void 0),Fu=w.createContext(void 0),zu=typeof document<"u"?w.useLayoutEffect:w.useEffect;function va(e){return"self"in e}function nv(e){return"body"in e}function Bu(e,t,n,r=Fr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(h=>{let p,g,x;const y=h.target;if(nv(y)||va(y)){const b=va(y)?y:y.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,g=s?b.innerWidth:b.innerHeight}else x=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,g=s?y.offsetWidth:y.offsetHeight;const m=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:g})};h.suppressFlushSync?m():Ti.flushSync(m),a.current!==null&&(x===a.current||x<=0||x===p-g)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const g=h.behavior==="smooth";let x,y,m;va(p)?(y=Math.max(Jn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,m=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],x=Jn(p,s?"width":"height"),m=p[s?"scrollLeft":"scrollTop"]);const b=y-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),ku(x,y)||h.top===m){e({scrollHeight:y,scrollTop:m,viewportHeight:x}),g&&t(!0);return}g?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const wa="-webkit-sticky",Hu="sticky",ba=Mu(()=>{if(typeof document>"u")return Hu;const e=document.createElement("div");return e.style.position=wa,e.style.position===wa?wa:Hu});function Sa(e){return e}const rv=ot(()=>{const e=te(a=>`Item ${a}`),t=te(a=>`Group ${a}`),n=te({}),r=te(Sa),o=te("div"),s=te(Fr),i=(a,l=null)=>Yt(Y(n,me(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")}}),ov=ot(([e,t])=>({...e,...t}),St(Du,rv)),sv=({height:e})=>u.jsx("div",{style:{height:e}}),iv={overflowAnchor:"none",position:ba(),zIndex:1},Uu={overflowAnchor:"none"},av={...Uu,display:"inline-block",height:"100%"},Wu=w.memo(function({showTopList:e=!1}){const t=Me("listState"),n=pn("sizeRanges"),r=Me("useWindowScroll"),o=Me("customScrollParent"),s=pn("windowScrollContainerState"),i=pn("scrollContainerState"),a=o||r?s:i,l=Me("itemContent"),c=Me("context"),d=Me("groupContent"),f=Me("trackItemSizes"),h=Me("itemSize"),p=Me("log"),g=pn("gap"),x=Me("horizontalDirection"),{callbackRef:y}=Sy(n,h,f,e?Fr:a,p,g,o,x,Me("skipAnimationFrameInResizeObserver")),[m,b]=w.useState(0);Ca("deviation",O=>{m!==O&&b(O)});const S=Me("EmptyPlaceholder"),T=Me("ScrollSeekPlaceholder")||sv,k=Me("ListComponent"),C=Me("ItemComponent"),E=Me("GroupComponent"),R=Me("computeItemKey"),_=Me("isSeeking"),j=Me("groupIndices").length>0,L=Me("alignToBottom"),z=Me("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:m!==0?m:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:m!==0?m:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Jt(S,c)}):u.jsx(k,{...Jt(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:V,children:(e?t.topItems:t.items).map(O=>{const H=O.originalIndex,P=R(H+t.firstItemIndex,O.data,c);return _?w.createElement(T,{...Jt(T,c),height:O.size,index:O.index,key:P,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?w.createElement(E,{...Jt(E,c),"data-index":H,"data-item-index":O.index,"data-known-size":O.size,key:P,style:iv},d(O.index,c)):w.createElement(C,{...Jt(C,c),...dv(C,O.data),"data-index":H,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:P,style:x?av:Uu},j?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),lv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},cv={outline:"none",overflowX:"auto",position:"relative"},Ss=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),uv={position:ba(),top:0,width:"100%",zIndex:1};function Jt(e,t){if(typeof e!="string")return{context:t}}function dv(e,t){return{item:typeof e=="string"?void 0:t}}const fv=w.memo(function(){const e=Me("HeaderComponent"),t=pn("headerHeight"),n=Me("HeaderFooterTag"),r=vr(w.useMemo(()=>s=>{t(Jn(s,"height"))},[t]),!0,Me("skipAnimationFrameInResizeObserver")),o=Me("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),hv=w.memo(function(){const e=Me("FooterComponent"),t=pn("footerHeight"),n=Me("HeaderFooterTag"),r=vr(w.useMemo(()=>s=>{t(Jn(s,"height"))},[t]),!0,Me("skipAnimationFrameInResizeObserver")),o=Me("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null});function Vu({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:h,scrollerRef:p,scrollToCallback:g}=Bu(a,c,l,d,void 0,f);return e("scrollTo",g),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?cv:lv,...o},tabIndex:0,...i,...Jt(l,s),children:r})})}function Ku({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"),h=t("customScrollParent"),p=w.useRef(null),g=t("scrollerRef"),{scrollByCallback:x,scrollerRef:y,scrollToCallback:m}=Bu(a,c,l,g,h);return zu(()=>{var b;return y.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",m),e("scrollBy",x),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Jt(l,s),children:r})})}const pv=({children:e})=>{const t=w.useContext($u),n=pn("viewportHeight"),r=pn("fixedItemHeight"),o=Me("alignToBottom"),s=Me("horizontalDirection"),i=w.useMemo(()=>su(n,l=>Jn(l,s?"width":"height")),[n,s]),a=vr(i,!0,Me("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Ss(o),children:e})},mv=({children:e})=>{const t=w.useContext($u),n=pn("windowViewportRect"),r=pn("fixedItemHeight"),o=Me("customScrollParent"),s=uu(n,o,Me("skipAnimationFrameInResizeObserver")),i=Me("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),u.jsx("div",{"data-viewport-type":"window",ref:s,style:Ss(i),children:e})},gv=({children:e})=>{const t=Me("TopItemListComponent")||"div",n=Me("headerHeight"),r={...uv,marginTop:`${n}px`},o=Me("context");return u.jsx(t,{style:r,...Jt(t,o),children:e})},xv=w.memo(function(e){const t=Me("useWindowScroll"),n=Me("topItemsIndexes").length>0,r=Me("customScrollParent"),o=Me("context");return u.jsxs(r||t?wv:vv,{...e,context:o,children:[n&&u.jsx(gv,{children:u.jsx(Wu,{showTopList:!0})}),u.jsxs(r||t?mv:pv,{children:[u.jsx(fv,{}),u.jsx(Wu,{}),u.jsx(hv,{})]})]})}),{Component:yv,useEmitter:Ca,useEmitterValue:Me,usePublisher:pn}=Lu(ov,{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"}},xv),vv=Vu({useEmitter:Ca,useEmitterValue:Me,usePublisher:pn}),wv=Ku({useEmitter:Ca,useEmitterValue:Me,usePublisher:pn}),bv=yv;St(Du,ot(()=>{const e=te(c=>u.jsxs("td",{children:["Item $",c]})),t=te(null),n=te(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=te(null),o=te(null),s=te({}),i=te(Sa),a=te(Fr),l=(c,d=null)=>Yt(Y(s,me(f=>f[c]),Ct()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),ba();const qu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Sv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Gu,floor:Cs,max:wo,min:ka,round:Xu}=Math;function Yu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Cv(e){return{...Sv,items:e}}function ks(e,t){return e&&e.width===t.width&&e.height===t.height}function kv(e,t){return e&&e.column===t.column&&e.row===t.row}const Tv=ot(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:g,propsReady:x},{customScrollParent:y,useWindowScroll:m,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:T},k])=>{const C=te(0),E=te(0),R=te(qu),_=te({height:0,width:0}),j=te({height:0,width:0}),L=Je(),z=Je(),V=te(0),O=te(null),H=te({column:0,row:0}),P=Je(),W=Je(),F=te(!1),$=te(0),ne=te(!0),oe=te(!1),we=te(!1);ct(Y(g,We($),je(([D,G])=>!!G)),()=>{ze(ne,!1)}),ct(Y(Dt(g,ne,j,_,$,oe),je(([D,G,ae,fe,,B])=>D&&!G&&ae.height!==0&&fe.height!==0&&!B)),([,,,,D])=>{ze(oe,!0),pa(1,()=>{ze(L,D)}),Cn(Y(c),()=>{ze(t,[0,0]),ze(ne,!0)})}),be(Y(W,je(D=>D!=null&&D.scrollTop>0),_n(0)),E),ct(Y(g,We(W),je(([,D])=>D!=null)),([,D])=>{D&&(ze(_,D.viewport),ze(j,D.item),ze(H,D.gap),D.scrollTop>0&&(ze(F,!0),Cn(Y(c,yr(1)),G=>{ze(F,!1)}),ze(l,{top:D.scrollTop})))}),be(Y(_,me(({height:D})=>D)),f),be(Y(Dt(_e(_,ks),_e(j,ks),_e(H,(D,G)=>D&&D.column===G.column&&D.row===G.row),_e(c)),me(([D,G,ae,fe])=>({gap:ae,item:G,scrollTop:fe,viewport:D}))),P),be(Y(Dt(_e(C),r,_e(H,kv),_e(j,ks),_e(_,ks),_e(O),_e(E),_e(F),_e(ne),_e($)),je(([,,,,,,,D])=>!D),me(([D,[G,ae],fe,B,le,Q,Ae,,ve,Re])=>{const{column:Ve,row:Qe}=fe,{height:et,width:Se}=B,{width:nt}=le;if(Ae===0&&(D===0||nt===0))return qu;if(Se===0){const He=ma(Re,D),Tt=He+Math.max(Ae-1,0);return Cv(Yu(He,Tt,Q))}const ut=Ju(nt,Se,Ve);let rt,Ye;ve?G===0&&ae===0&&Ae>0?(rt=0,Ye=Ae-1):(rt=ut*Cs((G+Qe)/(et+Qe)),Ye=ut*Gu((ae+Qe)/(et+Qe))-1,Ye=ka(D-1,wo(Ye,ut-1)),rt=ka(Ye,wo(0,rt))):(rt=0,Ye=-1);const It=Yu(rt,Ye,Q),{bottom:dt,top:kt}=Zu(le,fe,B,It),Nt=Gu(D/ut),tt=Nt*et+(Nt-1)*Qe-dt;return{bottom:dt,itemHeight:et,items:It,itemWidth:Se,offsetBottom:tt,offsetTop:kt,top:kt}})),R),be(Y(O,je(D=>D!==null),me(D=>D.length)),C),be(Y(Dt(_,j,R,H),je(([D,G,{items:ae}])=>ae.length>0&&G.height!==0&&D.height!==0),me(([D,G,{items:ae},fe])=>{const{bottom:B,top:le}=Zu(D,fe,G,ae);return[le,B]}),Ct(ho)),t);const Ne=te(!1);be(Y(c,We(Ne),me(([D,G])=>G||D!==0)),Ne);const Z=ln(Y(Dt(R,C),je(([{items:D}])=>D.length>0),We(Ne),je(([[D,G],ae])=>{const fe=D.items[D.items.length-1].index===G-1;return(ae||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===G)&&fe}),me(([[,D]])=>D-1),Ct())),ie=ln(Y(_e(R),je(({items:D})=>D.length>0&&D[0].index===0),_n(0),Ct())),Te=ln(Y(_e(R),We(F),je(([{items:D},G])=>D.length>0&&!G),me(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),Ct(xu),Bn(0)));be(Te,p.scrollSeekRangeChanged),be(Y(L,We(_,j,C,H),me(([D,G,ae,fe,B])=>{const le=Cu(D),{align:Q,behavior:Ae,offset:ve}=le;let Re=le.index;Re==="LAST"&&(Re=fe-1),Re=wo(0,Re,ka(fe-1,Re));let Ve=Ta(G,B,ae,Re);return Q==="end"?Ve=Xu(Ve-G.height+ae.height):Q==="center"&&(Ve=Xu(Ve-G.height/2+ae.height/2)),ve&&(Ve+=ve),{behavior:Ae,top:Ve}})),l);const ee=Yt(Y(R,me(D=>D.offsetBottom+D.bottom)),0);return be(Y(T,me(D=>({height:D.visibleHeight,width:D.visibleWidth}))),_),{customScrollParent:y,data:O,deviation:V,footerHeight:o,gap:H,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:j,overscan:n,restoreStateFrom:W,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:l,scrollToIndex:L,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:m,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:T,...p,gridState:R,horizontalDirection:we,initialTopMostItemIndex:$,totalListHeight:ee,...h,endReached:Z,propsReady:x,rangeChanged:Te,startReached:ie,stateChanged:P,stateRestoreInProgress:F,...k}},St(ga,en,vo,Ou,Zn,ya,Yn));function Ju(e,t,n){return wo(1,Cs((e+n)/(Cs(t)+n)))}function Zu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Ta(e,t,n,r[0].index);return{bottom:Ta(e,t,n,r[r.length-1].index)+o,top:s}}function Ta(e,t,n,r){const o=Ju(e.width,n.width,t.column),s=Cs(r/o),i=s*n.height+wo(0,s-1)*t.row;return i>0?i+t.row:i}const Ev=ot(()=>{const e=te(f=>`Item ${f}`),t=te({}),n=te(null),r=te("virtuoso-grid-item"),o=te("virtuoso-grid-list"),s=te(Sa),i=te("div"),a=te(Fr),l=(f,h=null)=>Yt(Y(t,me(p=>p[f]),Ct()),h),c=te(!1),d=te(!1);return be(_e(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")}}),Iv=ot(([e,t])=>({...e,...t}),St(Tv,Ev)),Nv=w.memo(function(){const e=Et("gridState"),t=Et("listClassName"),n=Et("itemClassName"),r=Et("itemContent"),o=Et("computeItemKey"),s=Et("isSeeking"),i=mn("scrollHeight"),a=Et("ItemComponent"),l=Et("ListComponent"),c=Et("ScrollSeekPlaceholder"),d=Et("context"),f=mn("itemDimensions"),h=mn("gap"),p=Et("log"),g=Et("stateRestoreInProgress"),x=mn("reportReadyState"),y=vr(w.useMemo(()=>m=>{const b=m.parentElement.parentElement.scrollHeight;i(b);const S=m.firstChild;if(S){const{height:T,width:k}=S.getBoundingClientRect();f({height:T,width:k})}h({column:ed("column-gap",getComputedStyle(m).columnGap,p),row:ed("row-gap",getComputedStyle(m).rowGap,p)})},[i,f,h,p]),!0,!1);return zu(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),g?null:u.jsx(l,{className:t,ref:y,...Jt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(m=>{const b=o(m.index,m.data,d);return s?u.jsx(c,{...Jt(c,d),height:e.itemHeight,index:m.index,width:e.itemWidth},b):w.createElement(a,{...Jt(a,d),className:n,"data-index":m.index,key:b},r(m.index,m.data,d))})})}),Av=w.memo(function(){const e=Et("HeaderComponent"),t=mn("headerHeight"),n=Et("headerFooterTag"),r=vr(w.useMemo(()=>s=>{t(Jn(s,"height"))},[t]),!0,!1),o=Et("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),_v=w.memo(function(){const e=Et("FooterComponent"),t=mn("footerHeight"),n=Et("headerFooterTag"),r=vr(w.useMemo(()=>s=>{t(Jn(s,"height"))},[t]),!0,!1),o=Et("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Jt(e,o)})}):null}),jv=({children:e})=>{const t=w.useContext(Fu),n=mn("itemDimensions"),r=mn("viewportDimensions"),o=vr(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),u.jsx("div",{ref:o,style:Ss(!1),children:e})},Rv=({children:e})=>{const t=w.useContext(Fu),n=mn("windowViewportRect"),r=mn("itemDimensions"),o=Et("customScrollParent"),s=uu(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),u.jsx("div",{ref:s,style:Ss(!1),children:e})},Pv=w.memo(function({...e}){const t=Et("useWindowScroll"),n=Et("customScrollParent"),r=n||t?Mv:Ov,o=n||t?Rv:jv,s=Et("context");return u.jsx(r,{...e,...Jt(r,s),children:u.jsxs(o,{children:[u.jsx(Av,{}),u.jsx(Nv,{}),u.jsx(_v,{})]})})}),{useEmitter:Qu,useEmitterValue:Et,usePublisher:mn}=Lu(Iv,{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"}},Pv),Ov=Vu({useEmitter:Qu,useEmitterValue:Et,usePublisher:mn}),Mv=Ku({useEmitter:Qu,useEmitterValue:Et,usePublisher:mn});function ed(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,sn.WARN),t==="normal"?0:parseInt(t??"0",10)}const Dv=Uo.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 td({className:e,variant:t,...n}){return u.jsx("div",{className:se(Dv({variant:t}),e),...n})}const bo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));bo.displayName="Card";const So=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("flex flex-col space-y-1.5 p-6",e),...t}));So.displayName="CardHeader";const Co=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:se("text-2xl font-semibold leading-none tracking-tight",e),...t}));Co.displayName="CardTitle";const nd=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:se("text-sm text-muted-foreground",e),...t}));nd.displayName="CardDescription";const ko=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("p-6 pt-0",e),...t}));ko.displayName="CardContent";const rd=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:se("flex items-center p-6 pt-0",e),...t}));rd.displayName="CardFooter";const Lv=1,$v=1e6;let Ea=0;function Fv(){return Ea=(Ea+1)%Number.MAX_SAFE_INTEGER,Ea.toString()}const Ia=new Map,od=e=>{if(Ia.has(e))return;const t=setTimeout(()=>{Ia.delete(e),To({type:"REMOVE_TOAST",toastId:e})},$v);Ia.set(e,t)},zv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Lv)};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?od(n):e.toasts.forEach(r=>{od(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)}}},Ts=[];let Es={toasts:[]};function To(e){Es=zv(Es,e),Ts.forEach(t=>{t(Es)})}function Bv({...e}){const t=Fv(),n=o=>To({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>To({type:"DISMISS_TOAST",toastId:t});return To({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Na(){const[e,t]=v.useState(Es);return v.useEffect(()=>(Ts.push(t),()=>{const n=Ts.indexOf(t);n>-1&&Ts.splice(n,1)}),[e]),{...e,toast:Bv,dismiss:n=>To({type:"DISMISS_TOAST",toastId:n})}}async function sd(e,t){return await bn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function id(e,t){return await(await sd(`/files/${e}/view`,t)).text()}async function Hv(e,t){const n=await sd(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await bn(`/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 Uv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await bn("/files",{params:r})}function Aa(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 ad(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Eo(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Eo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(ad(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=Eo(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function Io(e){if(typeof e=="string")return e;if(ad(e))return"";try{const t=Eo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Wv(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function Vv(e){const t=Io(e);return typeof e=="string"&&Wv(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Is(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Aa(t);if(n!==null)return Is(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Is(e.content):e}function ye(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 ld(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function _a(...e){return t=>{let n=!1;const r=e.map(o=>{const s=ld(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():ld(e[o],null)}}}}function Ze(...e){return v.useCallback(_a(...e),e)}function Kv(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 Hn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var m;const{scope:h,children:p,...g}=f,x=((m=h==null?void 0:h[e])==null?void 0:m[l])||a,y=v.useMemo(()=>g,Object.values(g));return u.jsx(x.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=v.useContext(p);if(g)return g;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,qv(o,...t)]}function qv(...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 Ut=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Gv=v[" useId ".trim().toString()]||(()=>{}),Xv=0;function Un(e){const[t,n]=v.useState(Gv());return Ut(()=>{n(r=>r??String(Xv++))},[e]),e||(t?`radix-${t}`:"")}var Yv=v[" useInsertionEffect ".trim().toString()]||Ut;function Br({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Jv({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 h=Zv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function Jv({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Yv(()=>{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 Zv(e){return typeof e=="function"}var Qv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],De=Qv.reduce((e,t)=>{const n=hr.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 cd(e,t){e&&Wo.flushSync(()=>e.dispatchEvent(t))}function Wt(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 ew(e,t=globalThis==null?void 0:globalThis.document){const n=Wt(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 tw="DismissableLayer",ja="dismissableLayer.update",nw="dismissableLayer.pointerDownOutside",rw="dismissableLayer.focusOutside",ud,dd=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ns=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(dd),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),g=Ze(t,E=>f(E)),x=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),m=x.indexOf(y),b=d?x.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,T=b>=m,k=iw(E=>{const R=E.target,_=[...c.branches].some(j=>j.contains(R));!T||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),C=aw(E=>{const R=E.target;[...c.branches].some(j=>j.contains(R))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return ew(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(ud=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),fd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=ud)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),fd())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(ja,E),()=>document.removeEventListener(ja,E)},[]),u.jsx(De.div,{...l,ref:g,style:{pointerEvents:S?T?"auto":"none":void 0,...e.style},onFocusCapture:ye(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ye(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ye(e.onPointerDownCapture,k.onPointerDownCapture)})});Ns.displayName=tw;var ow="DismissableLayerBranch",sw=v.forwardRef((e,t)=>{const n=v.useContext(dd),r=v.useRef(null),o=Ze(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(De.div,{...e,ref:o})});sw.displayName=ow;function iw(e,t=globalThis==null?void 0:globalThis.document){const n=Wt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){hd(nw,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 aw(e,t=globalThis==null?void 0:globalThis.document){const n=Wt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&hd(rw,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 fd(){const e=new CustomEvent(ja);document.dispatchEvent(e)}function hd(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?cd(o,s):o.dispatchEvent(s)}var Ra="focusScope.autoFocusOnMount",Pa="focusScope.autoFocusOnUnmount",pd={bubbles:!1,cancelable:!0},lw="FocusScope",As=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=Wt(o),d=Wt(s),f=v.useRef(null),h=Ze(t,x=>l(x)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const T=S.target;a.contains(T)?f.current=T:Qn(f.current,{select:!0})},y=function(S){if(p.paused||!a)return;const T=S.relatedTarget;T!==null&&(a.contains(T)||Qn(f.current,{select:!0}))},m=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&Qn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const b=new MutationObserver(m);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){xd.add(p);const x=document.activeElement;if(!a.contains(x)){const m=new CustomEvent(Ra,pd);a.addEventListener(Ra,c),a.dispatchEvent(m),m.defaultPrevented||(cw(pw(md(a)),{select:!0}),document.activeElement===x&&Qn(a))}return()=>{a.removeEventListener(Ra,c),setTimeout(()=>{const m=new CustomEvent(Pa,pd);a.addEventListener(Pa,d),a.dispatchEvent(m),m.defaultPrevented||Qn(x??document.body,{select:!0}),a.removeEventListener(Pa,d),xd.remove(p)},0)}}},[a,c,d,p]);const g=v.useCallback(x=>{if(!n&&!r||p.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,m=document.activeElement;if(y&&m){const b=x.currentTarget,[S,T]=uw(b);S&&T?!x.shiftKey&&m===T?(x.preventDefault(),n&&Qn(S,{select:!0})):x.shiftKey&&m===S&&(x.preventDefault(),n&&Qn(T,{select:!0})):m===b&&x.preventDefault()}},[n,r,p.paused]);return u.jsx(De.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});As.displayName=lw;function cw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Qn(r,{select:t}),document.activeElement!==n)return}function uw(e){const t=md(e),n=gd(t,e),r=gd(t.reverse(),e);return[n,r]}function md(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 gd(e,t){for(const n of e)if(!dw(n,{upTo:t}))return n}function dw(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 fw(e){return e instanceof HTMLInputElement&&"select"in e}function Qn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&fw(e)&&t&&e.select()}}var xd=hw();function hw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=yd(e,t),e.unshift(t)},remove(t){var n;e=yd(e,t),(n=e[0])==null||n.resume()}}}function yd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function pw(e){return e.filter(t=>t.tagName!=="A")}var mw="Portal",_s=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Ut(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ti.createPortal(u.jsx(De.div,{...r,ref:t}),i):null});_s.displayName=mw;function gw(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var gn=e=>{const{present:t,children:n}=e,r=xw(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Ze(r.ref,yw(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};gn.displayName="Presence";function xw(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=gw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=js(r.current);s.current=a==="mounted"?c:"none"},[a]),Ut(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=js(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Ut(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const x=js(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(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)})}},h=p=>{p.target===t&&(s.current=js(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),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 js(e){return(e==null?void 0:e.animationName)||"none"}function yw(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 Oa=0;function Ma(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??vd()),document.body.insertAdjacentElement("beforeend",e[1]??vd()),Oa++,()=>{Oa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Oa--}},[])}function vd(){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 Pn=function(){return Pn=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},Pn.apply(this,arguments)};function wd(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 vw(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 Rs="right-scroll-bar-position",Ps="width-before-scroll-bar",ww="with-scroll-bars-hidden",bw="--removed-body-scroll-bar-size";function Da(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Sw(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 Cw=typeof window<"u"?v.useLayoutEffect:v.useEffect,bd=new WeakMap;function kw(e,t){var n=Sw(null,function(r){return e.forEach(function(o){return Da(o,r)})});return Cw(function(){var r=bd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Da(a,null)}),s.forEach(function(a){o.has(a)||Da(a,i)})}bd.set(n,e)},[e]),n}function Tw(e){return e}function Ew(e,t){t===void 0&&(t=Tw);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 Iw(e){e===void 0&&(e={});var t=Ew(null);return t.options=Pn({async:!0,ssr:!1},e),t}var Sd=function(e){var t=e.sideCar,n=wd(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,Pn({},n))};Sd.isSideCarExport=!0;function Nw(e,t){return e.useMedium(t),Sd}var Cd=Iw(),La=function(){},Os=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:La,onWheelCapture:La,onTouchMoveCapture:La}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,g=e.noIsolation,x=e.inert,y=e.allowPinchZoom,m=e.as,b=m===void 0?"div":m,S=e.gapMode,T=wd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,C=kw([n,t]),E=Pn(Pn({},T),o);return v.createElement(v.Fragment,null,d&&v.createElement(k,{sideCar:Cd,removeScrollBar:c,shards:f,noRelative:p,noIsolation:g,inert:x,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),Pn(Pn({},E),{ref:C})):v.createElement(b,Pn({},E,{className:l,ref:C}),a))});Os.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Os.classNames={fullWidth:Ps,zeroRight:Rs};var Aw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function _w(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Aw();return t&&e.setAttribute("nonce",t),e}function jw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Rw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Pw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=_w())&&(jw(t,n),Rw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ow=function(){var e=Pw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},kd=function(){var e=Ow(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Mw={left:0,top:0,right:0,gap:0},$a=function(e){return parseInt(e||"",10)||0},Dw=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[$a(n),$a(r),$a(o)]},Lw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Mw;var t=Dw(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])}},$w=kd(),Hr="data-scroll-locked",Fw=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
37
+ `))>=0;){const ot=mt.slice(0,xe);mt=mt.slice(xe+2);const ft=$x(ot);if(!ft)continue;let tt;try{tt=JSON.parse(ft)}catch{console.debug("[use-chat] malformed SSE:",ft.slice(0,200));continue}const Fe=Fx(tt)?tt.data:tt;Ct=Date.now();const en=Fe.seq;if(en!==void 0){if(en<=Dt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:en,lastProcessedSeq:Dt,type:Fe.type});continue}Dt>0&&en>Dt+1&&((L=P==null?void 0:P.onGap)==null||L.call(P,{from:Dt,to:en})),Dt=en,k.current=en,y(en)}if(console.debug("[use-chat] received event",{seq:Fe.seq,type:Fe.type,preview:(()=>{var $e;try{return Fe.type==="message_delta"?{deltaTypes:($e=Fe.delta)==null?void 0:$e.map(ht=>ht.type),textLen:(Fe.delta||[]).filter(ht=>ht.type==="text").map(ht=>String(ht.text||"").length)}:Fe.content||Fe.delta?{hasContent:!0}:{}}catch(ht){return{err:String(ht)}}})()}),Fe.type==="checkpoint")E.current=Fe.checkpointId??null,R.current=Fe.checkpointNs??null,g(Fe.checkpointId??null);else if(Fe.type==="state_history"){_.current=Fe;try{const ht=as(Fe).latest;ht&&(E.current=ht.checkpointId??null,R.current=ht.checkpointNs??null,g(ht.checkpointId??null))}catch($e){console.warn("[use-chat] Failed to hydrate state_history payload",$e)}}try{B==null||B(Fe)}catch($e){console.error("[use-chat] Error in onEvent callback:",$e,"for event:",Fe.type)}if(Fe.type==="token"&&e.autoAppendAssistant!==!1)jt.push(Fe.content),St();else if(Fe.type==="message_delta"){const $e=Fe.delta.filter(ht=>ht.type==="text").map(ht=>ht.text).join("");$e&&e.autoAppendAssistant!==!1&&(jt.push($e),St())}else if(Fe.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(J=P==null?void 0:P.onHeartbeat)==null||J.call(P,Fe)}catch($e){console.warn("[use-chat] heartbeat callback failed",$e)}}else if(bt!==null&&cancelAnimationFrame(bt),He(),Fe.type==="checkpoint")g(Fe.checkpointId);else if(Fe.type==="error"){const $e=Fe;if(d($e.message),$="error",F=$e.message,$e.error_type==="auth_error"||$e.code==="TOKEN_EXPIRED"||((se=$e.message)==null?void 0:se.includes("token"))||((ue=$e.message)==null?void 0:ue.includes("401"))||((le=$e.message)==null?void 0:le.includes("unauthorized"))||((Me=$e.message)==null?void 0:Me.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",$e.message);try{(U=P==null?void 0:P.onAuthError)==null||U.call(P,$e.message)}catch(On){console.warn("[use-chat] onAuthError handler failed",On)}V.abort()}}}}He(),$===null&&!V.signal.aborted&&($="complete")}catch(at){if(at.name==="AbortError")$=$??"aborted";else{const De=at.message||String(at);$="error",F=De,d(De),(ye=P==null?void 0:P.onError)==null||ye.call(P,De)}}finally{try{await Be.cancel()}catch{}finally{(_e=Be.releaseLock)==null||_e.call(Be)}bt!==null&&typeof window<"u"&&window.cancelAnimationFrame(bt),clearInterval(Lt)}}catch(Ze){if(Ze.name==="AbortError")$=$??"aborted";else{const be=Ze.message||String(Ze);$="error",F=be,d(be),(Pe=P==null?void 0:P.onError)==null||Pe.call(P,be),ee||((et=P==null?void 0:P.onConnectionError)==null||et.call(P,be),ee=!0)}}finally{const Ze=k.current,be=E.current,Qe=R.current,it=_.current,rt=$??(V.signal.aborted?"aborted":F?"error":"complete");try{(nt=P==null?void 0:P.onClosed)==null||nt.call(P,{reason:rt,lastSeq:Ze,lastCheckpointId:be,lastCheckpointNs:Qe,lastStateHistory:it,error:F})}catch(Be){console.warn("[use-chat] onClosed callback failed",Be)}l(!1),b(!1),S.current=null,k.current=0,y(0),C.current=null}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var O;T.current=!1,(O=S.current)==null||O.abort()},[]),{isStreaming:a,error:c,assistantText:f,lastCheckpointId:p,lastSeq:x,connected:m,stream:W,stop:z,clear:D,setToken:j}}function Fx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function $x(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
38
+ `)}const Zc=200;function zx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o,onStreamClosed:s,onConnectionError:i,onAuthError:a,onHeartbeat:l}){const c=w.useRef(null),d=w.useRef(null),f=w.useRef(new Map),h=w.useRef(null),p=w.useCallback(_=>{try{const j=globalThis.structuredClone;if(typeof j=="function")return j(_)}catch{}try{return JSON.parse(JSON.stringify(_))}catch{return _}},[]),g=w.useCallback((_,j)=>{if(!_)return;const D=f.current.get(_)??[],z=p(j),W=D.length>=Zc?[...D.slice(D.length-Zc+1),z]:[...D,z];f.current.set(_,W)},[p]),x=w.useCallback(_=>{_&&f.current.set(_,[])},[]),y=w.useCallback(_=>{const j=_??d.current;if(!j)return;const D=f.current.get(j);D!=null&&D.length&&D.forEach(z=>{try{n(z)}catch(W){console.error("[useChatStreamingService] Failed to replay buffered event",W)}})},[n]),m=w.useCallback(_=>{var z,W,O,B,P;const j=_.seq??null;if(j!==null){const V=c.current;if(V!==null){if(j<=V)return;j>V+1&&(o==null||o({from:V,to:j}))}c.current=j}if(_.type==="thread_info"){d.current=_.threadId,h.current&&(h.current.threadIdGuess=_.threadId),x(_.threadId),console.log("[useChatStreamingService] 🎯 Received thread_info event:",_);try{t(_)}catch(V){console.error("[useChatStreamingService] Error in onThreadInfo handler:",V)}return}if(_.type==="heartbeat"){try{r==null||r(_)}catch(V){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",V)}return}if(_.type==="error"){const V=_;if(V.error_type==="auth_error"||V.code==="TOKEN_EXPIRED"||((z=V.message)==null?void 0:z.includes("token"))||((W=V.message)==null?void 0:W.includes("401"))||((O=V.message)==null?void 0:O.includes("unauthorized"))||((B=V.message)==null?void 0:B.includes("Unauthorized"))){console.error("[useChatStreamingService] Auth error event detected:",V.message);try{a==null||a(V.message)}catch(F){console.warn("[useChatStreamingService] onAuthError handler failed",F)}}}const D=_.threadId??(_.type==="state_history"?_.threadId:void 0)??d.current??((P=h.current)==null?void 0:P.threadIdGuess)??null;if(_.type==="state_history"&&(d.current=D??d.current),jx(_)){_.type==="checkpoint"||_.type==="state_history"?x(D??null):g(D??null,_);try{n(_)}catch(V){console.error("[useChatStreamingService] Error in onMessageEvent handler:",V)}return}try{r==null||r(_)}catch(V){console.error("[useChatStreamingService] Error in onUnhandledEvent handler:",V)}},[g,x,n,o,t,r]),{stream:b,stop:S,isStreaming:T,error:k,setToken:C}=Jc({baseUrl:e,token:null}),E=w.useCallback((_,j)=>{c.current=null,d.current=_.threadId??null,h.current={request:_,callbacks:j,manualStop:!1,threadIdGuess:_.threadId??null},b(_,m,{onOpen:j==null?void 0:j.onOpen,onError:D=>{var z;(z=j==null?void 0:j.onError)==null||z.call(j,D)},onGap:(j==null?void 0:j.onGap)??o,onConnectionError:D=>{var z;i==null||i(D),(z=j==null?void 0:j.onConnectionError)==null||z.call(j,D)},onAuthError:D=>{var z;a==null||a(D),(z=j==null?void 0:j.onAuthError)==null||z.call(j,D)},onHeartbeat:D=>{var z;try{l==null||l(D)}catch(W){console.warn("[useChatStreamingService] onHeartbeat handler failed",W)}try{(z=j==null?void 0:j.onHeartbeat)==null||z.call(j,D)}catch(W){console.warn("[useChatStreamingService] downstream onHeartbeat handler failed",W)}},onClosed:D=>{var B,P,V,$;const z=((B=h.current)==null?void 0:B.manualStop)??!1,W=d.current??((P=h.current)==null?void 0:P.threadIdGuess)??((V=D.lastStateHistory)==null?void 0:V.threadId)??null;(D.reason==="complete"||D.reason==="aborted"&&z)&&x(W);const O={...D,threadId:W,manualStop:z};try{s==null||s(O)}catch(F){console.warn("[useChatStreamingService] onStreamClosed handler failed",F)}try{($=j==null?void 0:j.onClosed)==null||$.call(j,O)}catch(F){console.warn("[useChatStreamingService] downstream onClosed handler failed",F)}h.current&&(h.current=null)}})},[x,m,a,i,l,o,s,b]),R=w.useCallback(()=>{h.current&&(h.current.manualStop=!0),S()},[S]);return w.useMemo(()=>({startStream:E,stop:R,isStreaming:T,error:k,setAuthToken:C,replayBufferedEvents:y}),[E,R,T,k,C,y])}function Qi(e){return e==null?e:{...e}}function Bx(e){return e==null?e:{...e}}function Hx(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function Ux(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function xn(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=Qi(e==null?void 0:e.metadata),s=Qi(e==null?void 0:e.config),i=Qi(e==null?void 0:e.parentConfig),a=Hx(e==null?void 0:e.next),l=Ux(e==null?void 0:e.tasks),c=Bx(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),c!==void 0&&(d.values=c),d}function Wx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function Qc(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}const ds=300;function eu(e,t=ds){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function br(){return typeof window<"u"&&typeof window.localStorage<"u"}function ea(e){if(!br())return null;try{return window.localStorage.getItem(e)}catch{return null}}function ta(e,t){if(!br())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function na(e){if(br())try{window.localStorage.removeItem(e)}catch{}}const Vx="cachedThreads",Kx="v1",ra=200;function qx(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function oa(e,t){return`cachedThreads:v1:${e}:${qx(t||"anon")}`}function Gx(){const e=ea(Vx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Yx(e){const t=ea(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function sa(e,t){ta(e,JSON.stringify(t))}function ia(e){const t=Yx(e);if(t.length>0)return t;const n=Gx();if(n.length>0)try{sa(e,n.slice(0,ra))}catch{}return n}function fs(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function aa(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function la(e,t){return`${e}${t}`}function Xx(e,t){const n=ea(la(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:xn(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function Jx(e,t,n=100){if(!br())return;const r=xn(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=la(e,t.threadId),i=JSON.stringify(o);if(!ta(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const c=window.localStorage.key(l);if(!c||c===s||!c.startsWith(e))continue;const d=window.localStorage.getItem(c);if(!d){a.push({key:c,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:c,updatedAt:h})}catch{a.push({key:c,updatedAt:0})}}a.sort((l,c)=>l.updatedAt-c.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),ta(s,i))break}catch{}}function Zx(e,t){na(la(e,t))}function Qx(e){if(br())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}const tu=w.createContext(null),nu=w.createContext(null),ru=w.createContext(null),ey=w.createContext(!1),ou=50,ty=750,ny=5,ry=1e3,oy=15e3;function su(e,t,n){return`${e}__${t??""}__${n??""}`}function hs(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 sy(e,t){return hs(e,t)}function iy(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 ay(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 iu(e,t){const n=hs(e.metadata,t.metadata),r=hs(e.config,t.config),o=hs(e.parentConfig,t.parentConfig),s=iy(e.next,t.next),i=ay(e.tasks,t.tasks),a=sy(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function ly({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onAuthError:a,onThreadChange:l}){const{api:c,baseUrl:d}=qi(),f=w.useMemo(()=>qn(d),[d]),h=w.useMemo(()=>{try{return new URL(d).host}catch{return"unknown"}},[d]),p=w.useMemo(()=>`threadPayload:${Kx}:${h}:`,[h]),g=w.useCallback(N=>Xx(p,N),[p]),x=w.useCallback((N,A=100)=>{Jx(p,N,A)},[p]),y=w.useCallback(N=>{Zx(p,N)},[p]),m=w.useCallback(()=>{Qx(p)},[p]),[b,S]=w.useState(()=>{var N;return oa(h,(N=c.getAuthToken)==null?void 0:N.call(c))}),[T,k]=w.useState(()=>{var A;const N=ia(oa(h,(A=c.getAuthToken)==null?void 0:A.call(c)));return fs(N)}),C=w.useMemo(()=>aa(T),[T]),[E,R]=w.useState(t),[_,j]=w.useState(!1),[D,z]=w.useState(!1),[W,O]=w.useState(null),[B,P]=w.useState(null),[V,$]=w.useState(null),[F,ee]=w.useState([]),te=w.useCallback(()=>{const N=ia(b);w.startTransition(()=>{k(fs(N))})},[b]),[ve,Ie]=w.useState(!1),[Z,de]=w.useState(!1),[we,ne]=w.useState(null),[L,J]=w.useState(void 0),[se,ue]=w.useState(void 0),[le,Me]=w.useState(void 0),{state:U,dispatch:ye,seed:_e,prepend:Pe,pushUser:et,onEvent:nt,reset:Ze}=Uc(),be=w.useRef(E);w.useEffect(()=>{be.current=E},[E]);const Qe=w.useRef(!1),it=w.useRef([]),rt=w.useRef(null),Be=w.useRef(null),wt=w.useRef(new Map),mt=w.useRef(E),jt=w.useRef(!1),Dt=w.useRef(null),bt=w.useRef(new Map),He=w.useRef(new Map),St=w.useRef(new Map),Ct=w.useRef(new Map),Lt=w.useCallback(N=>{if(!N){ee([]);return}const A=bt.current.get(N);if(!A||!A.length){ee([]);return}ee(A.map(H=>xn(H,{cloneMessages:!0})))},[]);w.useEffect(()=>{Lt(E)},[E,Lt]);const Ft=w.useCallback(()=>{var K;const N=Ct.current;if(N.size<=ou)return;const A=Array.from(N.entries()).sort((ae,re)=>ae[1].timestamp-re[1].timestamp),H=N.size-ou;for(let ae=0;ae<H;ae++){const re=(K=A[ae])==null?void 0:K[0];re&&N.delete(re)}},[]),at=w.useCallback((N,A,H)=>{if(!N)return;const K=H==="replace"?[]:bt.current.get(N)??[],ae=H==="replace"?A:[...A,...K];if(!ae.length){H==="replace"&&bt.current.set(N,[]);return}const re=new Map;for(const Ge of ae){if(!(Ge!=null&&Ge.checkpointId))continue;const We=`${Ge.checkpointId}::${Ge.checkpointNs??""}`,Tt=xn(Ge,{cloneMessages:!0}),_t=re.get(We);if(!_t){re.set(We,Tt);continue}const tn=iu(_t,Tt);re.set(We,{..._t,...tn})}const qe=Array.from(re.values()).sort((Ge,We)=>{const Tt=Number.isFinite(Date.parse(Ge.createdAt??""))?Date.parse(Ge.createdAt??""):0;return(Number.isFinite(Date.parse(We.createdAt??""))?Date.parse(We.createdAt??""):0)-Tt});bt.current.set(N,qe),N===be.current&&Lt(N)},[Lt]),De=w.useCallback((N,A,H)=>{if(!N)return;const K=He.current.get(N),ae=H==="replace"||!K?new Map:new Map(K);if(A&&typeof A=="object")for(const[re,qe]of Object.entries(A)){if(!(qe!=null&&qe.checkpointId))continue;const Ge=re||ho(qe.checkpointId,qe.checkpointNs??null);ae.set(Ge,xn(qe,{cloneMessages:!0}))}He.current.set(N,ae)},[]),Rt=w.useCallback((N,A)=>{const{threadId:H,checkpointId:K=null,checkpointNs:ae=null}=N,re=su(H,K,ae);if(A!=null&&A.force)St.current.delete(re),Ct.current.delete(re);else{if(A!=null&&A.preferCache){const Tt=Ct.current.get(re);if(Tt)return Promise.resolve(Tt.payload)}const We=St.current.get(re);if(We)return We}const Ge=c.getStateHistory({threadId:H,checkpointId:K??void 0,checkpointNs:ae??void 0}).then(We=>(Ct.current.set(re,{payload:We,timestamp:Date.now()}),Ft(),We)).finally(()=>{St.current.get(re)===Ge&&St.current.delete(re)});return St.current.set(re,Ge),Ge},[c,Ft]),kt=w.useCallback((N,A)=>new Promise((H,K)=>{const ae=async()=>{Qe.current=!0;try{await N(),H()}catch(re){K(re)}finally{Qe.current=!1;const re=it.current.shift();re&&re().catch(()=>{})}};Qe.current?it.current.push(ae):ae().catch(re=>{K(re)})}),[]),q=w.useRef(C.length),ke=w.useRef(!1);w.useEffect(()=>{q.current=C.length},[C.length]),w.useEffect(()=>{const N=U.pendingInterrupt??Wx(U.messages);Qc(V,N)||$(N??null)},[V,U.messages,U.pendingInterrupt]);const xe=w.useCallback(async()=>{const N=q.current>0;N||j(!0);try{const A=await c.listThreads();w.startTransition(()=>{k(H=>{const K=qe=>qe.map(Ge=>`${Ge.threadId}:${Ge.updatedAt??""}:${Ge.messageCount??""}`).join("|"),ae=aa(H);return K(ae)===K(A)||A.length===0&&ae.length>0&&!ke.current?H:fs(A)})}),O(null),ke.current||(ke.current=!0)}catch(A){i==null||i(String(A)),console.error("[ChatSessionProvider] Failed to refresh threads:",A),O(String(A))}finally{N||j(!1)}},[c,i]),ot=w.useRef(!1),ft=w.useRef(null),tt=w.useRef(null),Fe=w.useRef(""),[en,$e]=w.useState("idle"),ht=w.useRef({attempts:0,timer:null,reason:null}),On=w.useRef(null),Vn=w.useRef(0),hr=w.useRef(()=>{}),pr=w.useRef(()=>{}),Mr=w.useRef(()=>{}),Qn=w.useCallback((N,A)=>{if(!br())return;tt.current!==null&&(window.clearTimeout(tt.current),tt.current=null);const H=N.map(ae=>`${ae.threadId}:${ae.updatedAt??""}:${ae.messageCount??""}`).join("|");if(N.length===0){try{na(b)}catch{}Fe.current="";return}if(H===Fe.current)return;const K=()=>{try{const ae=N.slice(0,ra);sa(b,ae),Fe.current=H}catch{}finally{tt.current=null}};if(A!=null&&A.immediate){K();return}tt.current=window.setTimeout(()=>{eu(K)},ds)},[b]),no=w.useCallback(()=>{Qn(C,{immediate:!0})},[Qn,C]),I=w.useCallback((N,A,H,K)=>{var zl;const ae=H??be.current;if(!ae)return;const re=xn(N),qe=ae===be.current,Ge=(K==null?void 0:K.persist)!==!1;if(A==="replace"){if(Ge){const Vt={threadId:ae,snapshot:xn(N,{cloneMessages:!0})};wt.current.set(ae,Vt),mt.current=ae}if(!qe)return;_e(re.messages,{checkpointId:re.checkpointId??null,checkpointNs:re.checkpointNs??null,pendingInterrupt:re.interrupt??null}),$(re.interrupt??null),ne(re.nextCursor??null),Ie(!!re.nextCursor),J(re.checkpointId??void 0),ue(re.checkpointNs??void 0),Me(re.nextCursorNs??void 0);return}const We=wt.current.get(ae),Tt=(We==null?void 0:We.snapshot)??null,_t=Array.isArray(Tt==null?void 0:Tt.messages)?Tt.messages:[],tn=xn(Tt),Kn=Array.isArray(N==null?void 0:N.messages)?N.messages:[],Wt=new Set,Bt=[...Kn,..._t].filter(Vt=>{const Bl=Vt==null?void 0:Vt.id;return Bl?Wt.has(Bl)?!1:(Wt.add(Bl),!0):!0}),Ko=iu(tn,re),qo={checkpointId:tn.checkpointId??re.checkpointId??null,checkpointNs:tn.checkpointNs??re.checkpointNs??null,createdAt:re.createdAt??tn.createdAt??null,parentId:re.parentId??tn.parentId??null,branchLabel:re.branchLabel??tn.branchLabel??null,lastMessageId:((zl=Bt[Bt.length-1])==null?void 0:zl.id)??null,messagesLen:Bt.length,hasMessages:Bt.length>0,messages:Bt,nextCursor:re.nextCursor??tn.nextCursor??null,nextCursorNs:re.nextCursorNs??tn.nextCursorNs??null,interrupt:tn.interrupt??re.interrupt??null,...Ko};if(wt.current.set(ae,{threadId:ae,snapshot:xn(qo,{cloneMessages:!0})}),!qe)return;Kn.length&&Pe(Kn);const oo=N&&Object.prototype.hasOwnProperty.call(N,"checkpointId")?N.checkpointId:void 0,mr=N&&Object.prototype.hasOwnProperty.call(N,"checkpointNs")?N.checkpointNs:void 0,Lr=N&&Object.prototype.hasOwnProperty.call(N,"nextCursor")?N.nextCursor:void 0,gr=N&&Object.prototype.hasOwnProperty.call(N,"nextCursorNs")?N.nextCursorNs:void 0;ne(Vt=>Lr!==void 0?Lr??Vt??null:Vt??null),Ie(Vt=>Lr!==void 0?!!Lr:Vt),J(Vt=>oo!==void 0?oo??Vt??void 0:Vt??void 0),ue(Vt=>mr!==void 0?mr??Vt??void 0:Vt??void 0),Me(Vt=>gr!==void 0?gr??void 0:Vt)},[Pe,_e,$]),G=w.useCallback(N=>{if(N.threadId!=null&&N.threadId!==be.current)return;const A=xn(N.snapshot,{cloneMessages:!0});_e(A.messages,{checkpointId:A.checkpointId??null,checkpointNs:A.checkpointNs??null,pendingInterrupt:A.interrupt??null}),$(A.interrupt??null),ne(A.nextCursor??null),Ie(!!A.nextCursor),J(A.checkpointId??void 0),ue(A.checkpointNs??void 0),Me(A.nextCursorNs??void 0),mt.current=N.threadId,Lt(N.threadId??be.current??null)},[_e,$,Lt]),ie=w.useCallback(N=>{if(!N)return;wt.current.delete(N),y(N),bt.current.delete(N),He.current.delete(N),N===be.current&&ee([]);const A=`${N}__`;for(const H of St.current.keys())H.startsWith(A)&&St.current.delete(H);for(const H of Ct.current.keys())H.startsWith(A)&&Ct.current.delete(H);mt.current===N&&(mt.current=null)},[y]),Ce=w.useCallback(()=>{const N=be.current;N&&ie(N),Ze([]),Ie(!1),de(!1),ne(null),J(void 0),ue(void 0),Me(void 0)},[ie,Ze]),Ye=w.useCallback(({from:N,to:A})=>{const H=be.current;H&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${A}) for thread ${H}`)},[]),ct=w.useCallback(N=>{const A=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:A,title:N.title,created:N.created,currentThreads:C.length});const H={threadId:A,title:N.title||`Thread ${A.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};be.current!==A&&(!be.current&&U.messages.length<=1&&(Be.current=A),R(A)),w.startTransition(()=>{k(K=>{const ae=K.byId[A];return ae?ae.title===H.title&&ae.updatedAt===H.updatedAt&&ae.messageCount===H.messageCount?K:{byId:{...K.byId,[A]:H},order:K.order}:{byId:{...K.byId,[A]:H},order:[A,...K.order]}})})},[U.messages.length]),{startStream:Ke,stop:Ue,isStreaming:Pt,error:gt,setAuthToken:xt,replayBufferedEvents:Gt}=zx({baseUrl:f,onThreadInfo:ct,onMessageEvent:nt,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:Ye,onStreamClosed:N=>{hr.current(N)},onConnectionError:N=>{pr.current(N)},onAuthError:a,onHeartbeat:N=>{Mr.current(N)}}),Yt=w.useCallback(()=>{const N=ht.current;N.timer!==null&&(window.clearTimeout(N.timer),N.timer=null),N.reason=null},[]),un=w.useCallback((N,A)=>{$e("connecting"),Ke(N,{onOpen:H=>{var K;Yt(),ht.current.attempts=0,$e("connected"),(K=A==null?void 0:A.onOpen)==null||K.call(A,H)},onError:H=>{var K;(K=A==null?void 0:A.onError)==null||K.call(A,H)},onGap:(A==null?void 0:A.onGap)??Ye,onConnectionError:H=>{var K;pr.current(H),(K=A==null?void 0:A.onConnectionError)==null||K.call(A,H)},onHeartbeat:H=>{var K;Mr.current(H),(K=A==null?void 0:A.onHeartbeat)==null||K.call(A,H)},onClosed:H=>{var K;hr.current(H),(K=A==null?void 0:A.onClosed)==null||K.call(A,H)}})},[Yt,Ye,$e,Ke]),Ut=w.useCallback(()=>{const N=be.current;if(!N)return null;const A=On.current,H=U.lastCheckpointId??(A==null?void 0:A.lastCheckpointId)??null,K=U.lastCheckpointNs??(A==null?void 0:A.lastCheckpointNs)??null,ae={};return H&&(ae.checkpointId=H),K&&(ae.checkpointNs=K),{threadId:N,checkpointId:H,checkpointNs:K,command:{kind:"resume",value:ae}}},[U.lastCheckpointId,U.lastCheckpointNs]),Y=w.useCallback(N=>{const A=ht.current;if(A.timer!==null)return;if(A.attempts>=ny){$e("error");return}A.attempts+=1,A.reason=N;const H=Math.min(ry*Math.pow(2,A.attempts-1),oy);$e("reconnecting"),A.timer=window.setTimeout(()=>{A.timer=null,A.reason=null;const K=Ut();if(!K){$e("error");return}Gt(K.threadId??void 0),un(K)},H)},[Ut,Gt,$e,un]),fe=w.useCallback(N=>{if(On.current=N,N.manualStop||N.reason==="complete"){Yt(),ht.current.attempts=0,$e("idle");return}if(N.error&&(N.error.includes("token")||N.error.includes("401")||N.error.includes("unauthorized")||N.error.includes("Unauthorized")||N.error.includes("TOKEN_EXPIRED")||N.error.includes("auth_error"))){console.error("[ChatSessionProvider] Auth error detected:",N.error);try{a==null||a(N.error)}catch(H){console.error("[ChatSessionProvider] Error in onAuthError handler:",H)}return}(N.reason==="error"||N.reason==="aborted")&&Y(`closed:${N.reason}`)},[Yt,Y,$e,a]),ce=w.useCallback(N=>{console.warn("[ChatSessionProvider] Stream connection error:",N),Y("connection-error")},[Y]),pt=w.useCallback(N=>{Vn.current=Date.now(),$e(A=>A==="reconnecting"?"connected":A)},[$e]);hr.current=fe,pr.current=ce,Mr.current=pt,w.useEffect(()=>()=>{Yt()},[Yt]);const At=w.useCallback(()=>{Yt(),ht.current.attempts=0,$e("idle"),Ue()},[Yt,$e,Ue]);w.useEffect(()=>{ot.current=Pt},[Pt]),w.useEffect(()=>{if(!br())return;tt.current!==null&&(window.clearTimeout(tt.current),tt.current=null);const N=C.map(H=>`${H.threadId}:${H.updatedAt??""}:${H.messageCount??""}`).join("|");if(C.length===0){try{na(b)}catch{}Fe.current="";return}if(N===Fe.current)return;const A=()=>{try{const H=C.slice(0,ra);sa(b,H),Fe.current=N}catch{}finally{tt.current=null}};return tt.current=window.setTimeout(()=>{eu(A),tt.current=null},ds),()=>{tt.current!==null&&(window.clearTimeout(tt.current),tt.current=null)}},[C,Qn]),w.useEffect(()=>{var K;const N=c.getAuthToken();xt(N);const A=ae=>{const re=oa(h,ae);Dt.current!==re&&(Dt.current=re,jt.current=!1),S(re);const qe=ia(re);w.startTransition(()=>{k(fs(qe))}),ae&&!jt.current&&(jt.current=!0)};A(N);const H=(K=c.onTokenChange)==null?void 0:K.call(c,ae=>{ae!==N&&(xt(ae),m(),St.current.clear(),Ct.current.clear(),A(ae))});return()=>{H==null||H()}},[c,h,xt,m]);const lt=w.useCallback(async N=>{var K;const A=`Thread ${(K=crypto.randomUUID)==null?void 0:K.call(crypto)}`,H={threadId:A,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};k(ae=>({byId:{...ae.byId,[A]:H},order:[A,...ae.order]})),R(A);try{const ae=await c.createThread(N),re=typeof ae=="string"?ae:ae.threadId;return k(qe=>{const Ge=qe.byId[A];if(!Ge)return qe;const We={...qe.byId};delete We[A],We[re]={...Ge,threadId:re};const Tt=qe.order.map(_t=>_t===A?re:_t);return{byId:We,order:Tt}}),R(re),setTimeout(()=>xe(),10),O(null),re}catch(ae){throw k(re=>{if(!re.byId[A])return re;const qe={...re.byId};delete qe[A];const Ge=re.order.filter(We=>We!==A);return{byId:qe,order:Ge}}),R(null),O(String(ae)),ae}},[c,xe]),kn=w.useCallback(async N=>{try{await c.deleteThread(N);let A=null;k(H=>{if(!H.byId[N])return H;const K={...H.byId};delete K[N];const ae=H.order.filter(qe=>qe!==N),re={byId:K,order:ae};return A=aa(re),re}),A&&Qn(A,{immediate:!0}),ie(N),be.current===N&&(Be.current=N,R(null),be.current=null,mt.current=null,Ce()),await xe(),O(null)}catch(A){throw O(String(A)),A}},[c,Ce,ie,xe,Qn]),dn=w.useCallback(async(N,A)=>{try{await c.updateThread(N,A),k(H=>{const K=H.byId[N];return K?{byId:{...H.byId,[N]:{...K,title:A}},order:H.order}:H}),O(null)}catch(H){throw await xe(),O(String(H)),H}},[c,xe]),on=w.useCallback(async(N,A,H,K=!1)=>{await kt(async()=>{if(Be.current===N&&!K){Be.current=null;return}if(rt.current===N&&!K)return;R(Wt=>Wt===N?Wt:N),be.current=N;const qe=su(N,A??null,H??null),Ge=Ct.current.get(qe),We=!K&&!A&&!H&&Ge&&Date.now()-Ge.timestamp<ty,Tt=!K&&!A&&!H;let _t=!1;if(Tt){const Wt=wt.current.get(N);if(Wt)G(Wt),_t=!0;else{const Bt=g(N);Bt&&(wt.current.set(N,Bt),G(Bt),_t=!0)}}const tn=K||!_t||!!A||!!H,Kn=async Wt=>{Wt&&z(!0),rt.current=N;try{const Bt=await Rt({threadId:N,checkpointId:A,checkpointNs:H},{force:K}),{latest:Ko,checkpoints:qo,snapshots:oo}=as(Bt);I(Ko,"replace",N),at(N,qo,"replace"),De(N,oo,"replace"),P(null)}catch(Bt){throw(!_t||K||Wt)&&(i==null||i(String(Bt))),P(String(Bt)),Bt}finally{rt.current=null,Wt&&z(!1)}};tn?await Kn(!0):Tt&&_t&&!We&&Kn(!1).catch(Wt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Wt)})},`loadThread-${N}`)},[G,I,kt,Rt,i,at,De]),Uo=w.useCallback(async()=>{await kt(async()=>{const N=be.current;N&&ie(N),Be.current=null,R(null),be.current=null,mt.current=null,Ce(),J(void 0),ue(void 0),Me(void 0),ee([]);try{localStorage.removeItem("lastThreadId")}catch(A){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",A)}},"clearCurrentThread")},[Ce,ie,kt]),ro=w.useCallback(async(N,A)=>{var re;const H=be.current;if(!H)throw new Error("No active thread");const K=ho(N,A??null),ae=(re=He.current.get(H))==null?void 0:re.get(K);if(ae){await kt(async()=>{I(ae,"replace",H,{persist:!1})},`navigateToCheckpoint-${H}-${K}`);return}await on(H,N,A??void 0,!0)},[I,kt,on]),Wo=w.useCallback(async()=>{if(!be.current)throw new Error("No active thread");await on(be.current,void 0,void 0,!0)},[on]),Dr=w.useCallback(async()=>{if(!be.current)throw new Error("No active thread");if(Z||!ve)return;const N=we;if(N){de(!0);try{const A=be.current,H=await Rt({threadId:A,checkpointId:N??L??null,checkpointNs:le??se??null}),{latest:K,checkpoints:ae,snapshots:re}=as(H),qe=A?He.current.get(A):null;let Ge=ae.length>0;if(Ge&&qe&&qe.size>0&&(Ge=ae.some(We=>{if(!(We!=null&&We.checkpointId))return!1;const Tt=ho(We.checkpointId,We.checkpointNs??null);return!qe.has(Tt)})),!Ge){ne(null),Me(void 0),Ie(!1),P(null);return}I(K,"prepend",A??void 0),A&&(at(A,ae,"prepend"),De(A,re,"prepend")),P(null)}catch(A){throw P(String(A)),A}finally{de(!1)}}},[I,Rt,ve,L,se,le,we,Z,at,De]),_i=w.useCallback(N=>{if(N!=null&&N.threadId){if(N.checkpointId){const A=ho(N.checkpointId,N.checkpointNs??null),H=xn({...N,interrupt:N.interrupt??null},{cloneMessages:!0});De(N.threadId,{[A]:H},"prepend")}I(N,"replace",N.threadId)}},[I,De]),Vo=w.useCallback(async(N,A)=>{var Lr;const H=be.current,K=(N==null?void 0:N.text)??"",ae=(N==null?void 0:N.attachments)??[],re=ae.length?ae:(A==null?void 0:A.attachments)??[],qe=N==null?void 0:N.messageAdditionalKwargs,Ge={...(A==null?void 0:A.payloadExtras)??{},...(N==null?void 0:N.payload)??{}};if(!H&&!Object.keys(Ge).length&&re.length===0&&!K.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!H&&!Ge.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:We,filesInfo:Tt}=await mx(c,re),_t=[...We];K&&K.trim()&&_t.push({type:"text",text:K.trim()});const tn=!!H,Kn=tn?(A==null?void 0:A.checkpointId)??U.lastCheckpointId??void 0:void 0,Wt=tn?(A==null?void 0:A.checkpointNs)??U.lastCheckpointNs??void 0:void 0,Bt={id:((Lr=crypto.randomUUID)==null?void 0:Lr.call(crypto))||`user-${Date.now()}`,role:"user",content:_t,createdAt:new Date().toISOString(),...Kn!=null?{checkpointId:Kn}:{},...Wt!=null?{checkpointNs:Wt}:{}};qe&&Object.keys(qe).length&&(Bt.additionalKwargs={...Bt.additionalKwargs??{},...qe}),_t.length>0&&et(Bt);const Ko={...Bt,content:_t},qo=re.length>0,oo={messages:_t.length>0?[Ko]:[],files_info:Tt,...o&&qo&&s?{active_agent:s}:{},...Ge},mr={threadId:H??null,payload:oo,checkpointId:Kn??null,checkpointNs:Wt??null,nodeFilter:(A==null?void 0:A.nodeFilter)??null,config:A==null?void 0:A.config,command:(A==null?void 0:A.command)??null};mr.threadId||delete mr.threadId,mr.command||delete mr.command,un(mr,{onError:gr=>{console.warn("[ChatSessionProvider] Stream error:",gr)},onOpen:({threadId:gr})=>{!be.current&&gr&&(U.messages.length<=1&&(Be.current=gr),R(gr))},onGap:Ye})},[c,o,s,Ye,U.lastCheckpointId,U.lastCheckpointNs,U.messages.length,et,un]),Fm=w.useCallback(async(N,A,H)=>{if(!be.current)throw new Error("No active thread to handle interrupt");const ae=A?H??!0:!1;try{try{ye({type:"interrupt_response",payload:{interruptId:N}})}catch(re){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",re)}await Vo({payload:{}},{checkpointId:U.lastCheckpointId??void 0,checkpointNs:U.lastCheckpointNs??void 0,command:{kind:"resume",value:ae}}),$(null)}catch(re){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,re),re}},[ye,U.lastCheckpointId,U.lastCheckpointNs,Vo]);w.useEffect(()=>{if(l==null||l(E),E)try{localStorage.setItem("lastThreadId",E)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[E,l]),w.useEffect(()=>((async()=>{try{if(xe().catch(A=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",A),i==null||i(String(A))}),!r&&!t)try{const A=localStorage.getItem("lastThreadId");A&&(R(A),n&&await on(A))}catch(A){console.warn("[ChatSessionProvider] Failed to restore last thread:",A)}else t&&n&&await on(t)}catch(A){console.error("[ChatSessionProvider] Initialization failed:",A),i==null||i(String(A))}})(),()=>{}),[]),w.useEffect(()=>{const N=be.current;if(!N||mt.current!==N)return;U.messages.length&&U.messages[U.messages.length-1];const A=xn({checkpointId:U.lastCheckpointId??null,checkpointNs:U.lastCheckpointNs??null,messages:U.messages.slice(),nextCursor:we??null,nextCursorNs:le??null,interrupt:U.pendingInterrupt??V??null}),H=wt.current.get(N),K=H==null?void 0:H.snapshot,ae=!K||K.messages.length!==A.messages.length||K.messages.some((We,Tt)=>{var _t;return(We==null?void 0:We.id)!==((_t=A.messages[Tt])==null?void 0:_t.id)}),re=((K==null?void 0:K.checkpointId)??null)!==A.checkpointId||((K==null?void 0:K.checkpointNs)??null)!==A.checkpointNs,qe=((K==null?void 0:K.nextCursor)??null)!==A.nextCursor||((K==null?void 0:K.nextCursorNs)??null)!==A.nextCursorNs,Ge=!Qc((K==null?void 0:K.interrupt)??null,A.interrupt??null);if(ae||re||qe||Ge){const We={threadId:N,snapshot:A};wt.current.set(N,We),ft.current&&window.clearTimeout(ft.current),ft.current=window.setTimeout(()=>{try{x(We,100)}catch(Tt){console.warn("[ChatSessionProvider] Failed to persist thread payload:",Tt)}},ds)}},[we,le,U.lastCheckpointId,U.lastCheckpointNs,U.messages,U.pendingInterrupt,V,x]);const tT=w.useMemo(()=>({threads:C,currentThreadId:E,setCurrentThreadId:R,isLoading:_,error:W,actions:{createThread:lt,deleteThread:kn,renameThread:dn,refreshThreads:()=>xe()},persistThreadsCache:no,hydrateFromCache:te}),[C,E,_,W,lt,kn,dn,xe,no,te,R]),nT=w.useMemo(()=>{const N=U.lastBranch??null,A=U.assemblingId??null,H=N||A?{branchLabel:(N==null?void 0:N.branchLabel)??null,lastBranch:N,assemblingMessageId:A}:null;return{threadId:E,messages:U.messages,interrupt:V,checkpoint:{id:U.lastCheckpointId??null,namespace:U.lastCheckpointNs??null},checkpoints:F,metadata:H,isLoading:D,isHistoryLoading:Z,error:B,hasMore:ve,loadOlder:Dr,seedFromSnapshot:_i,clearState:Ce,navigateToCheckpoint:ro,returnToLatest:Wo,loadThread:on,clearThread:Uo,respondToInterrupt:Fm}},[Uo,Ce,E,V,ve,Z,D,Dr,on,U.assemblingId,U.lastBranch,U.lastCheckpointId,U.lastCheckpointNs,U.messages,ro,Fm,Wo,_i,B,F]),rT=w.useMemo(()=>({isStreaming:Pt,error:gt,connectionState:en,submit:Vo,send:Vo,stop:At,setAuthToken:xt}),[en,Pt,gt,At,Vo,xt]);return u.jsx(ey.Provider,{value:!0,children:u.jsx(ru.Provider,{value:rT,children:u.jsx(tu.Provider,{value:tT,children:u.jsx(nu.Provider,{value:nT,children:e})})})})}function ps(){const e=w.useContext(tu);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function ms(){const e=w.useContext(nu);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function au(){const e=w.useContext(ru);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function gs({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onAuthError:l,onThreadChange:c}){return u.jsx(hx,{apiConfig:t,children:u.jsx(ly,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onAuthError:l,onThreadChange:c,children:e})})}function oe(...e){return Hm.twMerge(Bm.clsx(e))}const cy=Go.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"}}),ut=v.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?xr.Slot:"button";return u.jsx(i,{className:oe(cy({variant:t,size:n,className:e})),ref:s,...o})});ut.displayName="Button";const lu=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:oe("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}));lu.displayName="Textarea";function uy({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:h="",allowEmptySend:p=!1}){const g=i!==void 0,[x,y]=w.useState(e),m=(g?i:x)??"",[b,S]=w.useTransition(),T=w.useRef(null),k=w.useRef(0),C=w.useRef(null);w.useEffect(()=>{g||(y(e??""),C.current=null,T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`))},[e,t,g]);const E=w.useCallback(()=>{const B=T.current;B&&(B.style.height="auto",B.style.height=`${B.scrollHeight}px`)},[]);w.useEffect(()=>{E()},[E,m]);const R=w.useCallback((B,{fromUser:P})=>{g||y(B),P&&(a==null||a(B))},[g,a]),_=w.useCallback(async B=>{B&&B.preventDefault();const P=(m??"").trim();if(!P&&!p)return;const V=++k.current;C.current={id:V,shouldClear:!0},S(()=>{var $,F,ee;try{const te=l(P);te&&typeof te.then=="function"?te.then(()=>{var ve,Ie;((ve=C.current)==null?void 0:ve.id)===V&&C.current.shouldClear&&(g||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((Ie=C.current)==null?void 0:Ie.id)===V&&(C.current=null)}).catch(()=>{var ve;((ve=C.current)==null?void 0:ve.id)===V&&(C.current=null)}):((($=C.current)==null?void 0:$.id)===V&&C.current.shouldClear&&(g||(y(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((F=C.current)==null?void 0:F.id)===V&&(C.current=null))}catch{((ee=C.current)==null?void 0:ee.id)===V&&(C.current=null)}})},[m,l,p,g,a]),j=w.useCallback(B=>{const P=B.target.value;R(P,{fromUser:!0}),C.current&&(C.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`)},[R]),D=w.useCallback(B=>{B.key==="Enter"&&!B.shiftKey?(B.preventDefault(),_()):B.key==="Escape"&&t&&(B.preventDefault(),c==null||c())},[_,t,c]),O=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return 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(lu,{ref:T,value:m,onChange:j,onKeyDown:D,placeholder:t?"Edit your message...":n,className:O,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),u.jsx("div",{children:r?u.jsx(ut,{type:"button",onClick:()=>{d==null||d()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!d,children:u.jsx(he.Square,{size:16})}):u.jsx(ut,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!m.trim()&&!p||b,children:u.jsx(he.Send,{size:16})})})]})})}const dy=w.memo(uy),xs=0,tr=1,Br=2,cu=4;function uu(e){return()=>e}function fy(e){e()}function du(e,t){return n=>e(t(n))}function fu(e,t){return()=>e(t)}function hy(e,t){return n=>e(t,n)}function ca(e){return e!==void 0}function py(...e){return()=>{e.map(fy)}}function Hr(){}function ys(e,t){return t(e),e}function my(e,t){return t(e)}function Et(...e){return e}function dt(e,t){return e(tr,t)}function ze(e,t){e(xs,t)}function ua(e){e(Br)}function Mt(e){return e(cu)}function Se(e,t){return dt(e,hy(t,xs))}function Nn(e,t){const n=e(tr,r=>{n(),t(r)});return n}function hu(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function pu(e,t){return e===t}function It(e=pu){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ae(e){return t=>n=>{e(n)&&t(n)}}function pe(e){return t=>du(t,e)}function Dn(e){return t=>()=>{t(e)}}function X(e,...t){const n=gy(...t);return(r,o)=>{switch(r){case Br:ua(e);return;case tr:return dt(e,n(o))}}}function Ln(e,t){return n=>r=>{n(t=e(t,r))}}function Sr(e){return t=>n=>{e>0?e--:t(n)}}function Gn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ve(...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);dt(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 gy(...e){return t=>e.reduceRight(my,t)}function xy(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case tr:return s?n===s?void 0:(r(),n=s,t=dt(e,s),t):(r(),Hr);case Br:r(),n=null;return}}}function Q(e){let t=e;const n=Xe();return(r,o)=>{switch(r){case xs:t=o;break;case tr:{o(t);break}case cu:return t}return n(r,o)}}function Jt(e,t){return ys(Q(t),n=>Se(e,n))}function Xe(){const e=[];return(t,n)=>{switch(t){case xs:e.slice().forEach(r=>{r(n)});return;case Br:e.splice(0,e.length);return;case tr:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function fn(e){return ys(Xe(),t=>Se(e,t))}function st(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:yy(),singleton:n}}const yy=()=>Symbol();function vy(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 zt(...e){const t=Xe(),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);dt(s,l=>{n[i]=l,r=r|a,r===o&&ze(t,n)})}),function(s,i){switch(s){case Br:{ua(t);return}case tr:return r===o&&i(n),dt(t,i)}}}function Ne(e,t=pu){return X(e,It(t))}function da(...e){return function(t,n){switch(t){case Br:return;case tr:return py(...e.map(r=>dt(r,n)))}}}var cn=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(cn||{});const wy={0:"debug",3:"error",1:"log",2:"warn"},by=()=>typeof globalThis>"u"?window:globalThis,nr=st(()=>{const e=Q(3);return{log:Q((t,n,r=1)=>{var o;const s=(o=by().VIRTUOSO_LOG_LEVEL)!=null?o:Mt(e);r>=s&&console[wy[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Cr(e,t,n){return fa(e,t,n).callbackRef}function fa(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Sy(e,t,n,r,o,s,i,a,l){const c=w.useCallback(d=>{const f=Cy(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let g;p&&(g=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,y=i?a?i.scrollWidth:i.scrollHeight:p?a?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,m=i?a?i.offsetWidth:i.offsetHeight:p?a?g.innerWidth:g.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(x,0),viewportHeight:m}),s==null||s(a?mu("column-gap",getComputedStyle(d).columnGap,o):mu("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return fa(c,n,l)}function Cy(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},cn.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 mu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,cn.WARN),t==="normal"?0:parseInt(t??"0",10)}function gu(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,h;if(t){const p=t.getBoundingClientRect(),g=c.top-p.top;h=p.height-Math.max(0,g),f=g+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=fa(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const 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 nn=st(()=>{const e=Xe(),t=Xe(),n=Q(0),r=Xe(),o=Q(0),s=Xe(),i=Xe(),a=Q(0),l=Q(0),c=Q(0),d=Q(0),f=Xe(),h=Xe(),p=Q(!1),g=Q(!1),x=Q(!1);return Se(X(e,pe(({scrollTop:y})=>y)),t),Se(X(e,pe(({scrollHeight:y})=>y)),i),Se(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:g,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),mo={lvl:0};function xu(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 yt(e){return e===mo}function go(e,t){if(!yt(e))return t===e.k?e.v:t<e.k?go(e.l,t):go(e.r,t)}function An(e,t,n="k"){if(yt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=An(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return An(e.l,t,n)}function hn(e,t,n){return yt(e)?wu(t,n,1):t===e.k?Ht(e,{k:t,v:n}):t<e.k?bu(Ht(e,{l:hn(e.l,t,n)})):bu(Ht(e,{r:hn(e.r,t,n)}))}function Ur(){return mo}function vs(e,t,n){if(yt(e))return[];const r=An(e,t)[0];return ky(pa(e,r,n))}function ha(e,t){if(yt(e))return mo;const{k:n,l:r,r:o}=e;if(t===n){if(yt(r))return o;if(yt(o))return r;{const[s,i]=vu(r);return ws(Ht(e,{k:s,l:yu(r),v:i}))}}else return t<n?ws(Ht(e,{l:ha(r,t)})):ws(Ht(e,{r:ha(o,t)}))}function kr(e){return yt(e)?[]:[...kr(e.l),{k:e.k,v:e.v},...kr(e.r)]}function pa(e,t,n){if(yt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(pa(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(pa(s,t,n))),a}function ws(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(ma(t))return Su(Ht(e,{lvl:n-1}));if(!yt(t)&&!yt(t.r))return Ht(t.r,{l:Ht(t,{r:t.r.l}),lvl:n,r:Ht(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(ma(e))return ga(Ht(e,{lvl:n-1}));if(!yt(r)&&!yt(r.l)){const o=r.l,s=ma(o)?r.lvl-1:r.lvl;return Ht(o,{l:Ht(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:ga(Ht(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function Ht(e,t){return wu(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 yu(e){return yt(e.r)?e.l:ws(Ht(e,{r:yu(e.r)}))}function ma(e){return yt(e)||e.lvl>e.r.lvl}function vu(e){return yt(e.r)?[e.k,e.v]:vu(e.r)}function wu(e,t,n,r=mo,o=mo){return{k:e,l:r,lvl:n,r:o,v:t}}function bu(e){return ga(Su(e))}function Su(e){const{l:t}=e;return!yt(t)&&t.lvl===e.lvl?Ht(t,{r:Ht(e,{l:t.r})}):e}function ga(e){const{lvl:t,r:n}=e;return!yt(n)&&!yt(n.r)&&n.lvl===t&&n.r.lvl===t?Ht(n,{l:Ht(e,{r:n.l}),lvl:t+1}):e}function ky(e){return xu(e,({k:t,v:n})=>({index:t,value:n}))}function Cu(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function xo(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const xa=st(()=>({recalcInProgress:Q(!1)}),[],{singleton:!0});function ku(e,t,n){return e[bs(e,t,n)]}function bs(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 Ty(e,t,n,r){const o=bs(e,t,r),s=bs(e,n,r,o);return e.slice(o,s+1)}function rr(e,t){return Math.round(e.getBoundingClientRect()[t])}function Ss(e){return!yt(e.groupOffsetTree)}function ya({index:e},t){return t===e?0:t<e?-1:1}function Ey(){return{groupIndices:[],groupOffsetTree:Ur(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Ur()}}function Iy(e,t){let n=yt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),yt(e)){e=hn(e,0,s);continue}const a=vs(e,i-1,o+1);if(a.some(Oy(r)))continue;let l=!1,c=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=ha(e,f)):(c=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=hn(e,o+1,h));c&&(e=hn(e,i,s))}return[e,n]}function Ny(e){return typeof e.groupIndex<"u"}function Ay({offset:e},t){return t===e?0:t<e?-1:1}function yo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ku(t,e,ya),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function Tu(e,t){if(!Ss(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Eu(e,t,n){if(Ny(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=Tu(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function _y(e,t,n,r=0){return r>0&&(t=Math.max(t,ku(e,r,ya).offset)),xu(Ty(e,t,n,Ay),Py)}function jy(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,cn.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&yt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((g,x)=>hn(hn(g,x,h),x+1,p),i)}else[i,a]=Iy(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f}=va(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>hn(h,p,yo(p,f,o)),Ur()),lastIndex:l,lastOffset:c,lastSize:d,offsetTree:f,sizeTree:i}}function Ry(e){return kr(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 Iu(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function va(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=bs(o,t-1,ya),a=o[l].offset;const c=An(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===An(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:d}of vs(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:d}),s=c,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Py(e){return{index:e.index,value:e}}function Oy(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 My={offsetHeight:"height",offsetWidth:"width"},Fn=st(([{log:e},{recalcInProgress:t}])=>{const n=Xe(),r=Xe(),o=Jt(r,0),s=Xe(),i=Xe(),a=Q(0),l=Q([]),c=Q(void 0),d=Q(void 0),f=Q((k,C)=>rr(k,My[C])),h=Q(void 0),p=Q(0),g=Ey(),x=Jt(X(n,Ve(l,e,p),Ln(jy,g),It()),g),y=Jt(X(l,It(),Ln((k,C)=>({current:C,prev:k.current}),{current:[],prev:[]}),pe(({prev:k})=>k)),[]);Se(X(l,Ae(k=>k.length>0),Ve(x,p),pe(([k,C,E])=>{const R=k.reduce((_,j,D)=>hn(_,j,yo(j,C.offsetTree,E)||D),Ur());return{...C,groupIndices:k,groupOffsetTree:R}})),x),Se(X(r,Ve(x),Ae(([k,{lastIndex:C}])=>k<C),pe(([k,{lastIndex:C,lastSize:E}])=>[{endIndex:C,size:E,startIndex:k}])),n),Se(c,d);const m=Jt(X(c,pe(k=>k===void 0)),!0);Se(X(d,Ae(k=>k!==void 0&&yt(Mt(x).sizeTree)),pe(k=>[{endIndex:0,size:k,startIndex:0}])),n);const b=fn(X(n,Ve(x),Ln(({sizes:k},[C,E])=>({changed:E!==k,sizes:E}),{changed:!1,sizes:g}),pe(k=>k.changed)));dt(X(a,Ln((k,C)=>({diff:k.prev-C,prev:C}),{diff:0,prev:0}),pe(k=>k.diff)),k=>{const{groupIndices:C}=Mt(x);if(k>0)ze(t,!0),ze(s,k+Iu(k,C));else if(k<0){const E=Mt(y);E.length>0&&(k-=Iu(-k,E)),ze(i,k)}}),dt(X(a,Ve(e)),([k,C])=>{k<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},cn.ERROR)});const S=fn(s);Se(X(s,Ve(x),pe(([k,C])=>{const E=C.groupIndices.length>0,R=[],_=C.lastSize;if(E){const j=go(C.sizeTree,0);let D=0,z=0;for(;D<k;){const O=C.groupIndices[z],B=C.groupIndices.length===z+1?1/0:C.groupIndices[z+1]-O-1;R.push({endIndex:O,size:j,startIndex:O}),R.push({endIndex:O+1+B-1,size:_,startIndex:O+1}),z++,D+=B+1}const W=kr(C.sizeTree);return D!==k&&W.shift(),W.reduce((O,{k:B,v:P})=>{let V=O.ranges;return O.prevSize!==0&&(V=[...O.ranges,{endIndex:B+k-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:B+k,prevSize:P,ranges:V}},{prevIndex:k,prevSize:0,ranges:R}).ranges}return kr(C.sizeTree).reduce((j,{k:D,v:z})=>({prevIndex:D+k,prevSize:z,ranges:[...j.ranges,{endIndex:D+k-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:_,ranges:[]}).ranges})),n);const T=fn(X(i,Ve(x,p),pe(([k,{offsetTree:C},E])=>{const R=-k;return yo(R,C,E)})));return Se(X(i,Ve(x,p),pe(([k,C,E])=>{if(C.groupIndices.length>0){if(yt(C.sizeTree))return C;let R=Ur();const _=Mt(y);let j=0,D=0,z=0;for(;j<-k;){z=_[D];const W=_[D+1]-z-1;D++,j+=W+1}if(R=kr(C.sizeTree).reduce((W,{k:O,v:B})=>hn(W,Math.max(0,O+k),B),R),j!==-k){const W=go(C.sizeTree,z);R=hn(R,0,W);const O=An(C.sizeTree,-k+1)[1];R=hn(R,1,O)}return{...C,sizeTree:R,...va(C.offsetTree,0,R,E)}}else{const R=kr(C.sizeTree).reduce((_,{k:j,v:D})=>hn(_,Math.max(0,j+k),D),Ur());return{...C,sizeTree:R,...va(C.offsetTree,0,R,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:T,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:m,unshiftWith:s}},Et(nr,xa),{singleton:!0});function Dy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Nu=st(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Xe(),i=Xe(),a=fn(X(s,pe(Dy)));return Se(X(a,pe(l=>l.totalCount)),n),Se(X(a,pe(l=>l.groupIndices)),e),Se(X(zt(o,t,r),Ae(([l,c])=>Ss(c)),pe(([l,c,d])=>An(c.groupOffsetTree,Math.max(l-d,0),"v")[0]),It(),pe(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},Et(Fn,nn)),or=st(([{log:e}])=>{const t=Q(!1),n=fn(X(t,Ae(r=>r),It()));return dt(t,r=>{r&&Mt(e)("props updated",{},cn.DEBUG)}),{didMount:n,propsReady:t}},Et(nr),{singleton:!0}),Ly=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Au(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Ly)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const vo=st(([{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:h}])=>{const p=Xe(),g=Xe(),x=Q(0);let y=null,m=null,b=null;function S(){y&&(y(),y=null),b&&(b(),b=null),m&&(clearTimeout(m),m=null),ze(l,!1)}return Se(X(p,Ve(n,f,r,x,a,i,h),Ve(e,s,o),pe(([[T,k,C,E,R,_,j,D],z,W,O])=>{const B=Au(T),{align:P,behavior:V,offset:$}=B,F=E-1,ee=Eu(B,k,F);let te=yo(ee,k.offsetTree,z)+_;P==="end"?(te+=W+An(k.sizeTree,ee)[1]-C+O,ee===F&&(te+=j)):P==="center"?te+=(W+An(k.sizeTree,ee)[1]-C+O)/2:te-=R,$&&(te+=$);const ve=Ie=>{S(),Ie?(D("retrying to scroll to",{location:T},cn.DEBUG),ze(p,T)):(ze(g,!0),D("list did not change, scroll successful",{},cn.DEBUG))};if(S(),V==="smooth"){let Ie=!1;b=dt(t,Z=>{Ie=Ie||Z}),y=Nn(d,()=>{ve(Ie)})}else y=Nn(X(t,Fy(150)),ve);return m=setTimeout(()=>{S()},1200),ze(l,!0),D("scrolling from index to",{behavior:V,index:ee,top:te},cn.DEBUG),{behavior:V,top:te}})),c),{scrollTargetReached:g,scrollToIndex:p,topListHeight:x}},Et(Fn,nn,nr),{singleton:!0});function Fy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function wa(e,t){e==0?t():requestAnimationFrame(()=>{wa(e-1,t)})}function ba(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const wo=st(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Q(!0),l=Q(0),c=Q(!0);return Se(X(i,Ve(l),Ae(([d,f])=>!!f),Dn(!1)),a),Se(X(i,Ve(l),Ae(([d,f])=>!!f),Dn(!1)),c),dt(X(zt(t,i),Ve(a,n,e,c),Ae(([[,d],f,{sizeTree:h},p,g])=>d&&(!yt(h)||ca(p))&&!f&&!g),Ve(l)),([,d])=>{Nn(o,()=>{ze(c,!0)}),wa(4,()=>{Nn(r,()=>{ze(a,!0)}),ze(s,d)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Et(Fn,nn,vo,or),{singleton:!0});function _u(e,t){return Math.abs(e-t)<1.01}const bo="up",So="down",$y="none",zy={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},By=0,Co=st(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Q(!1),a=Q(!0),l=Xe(),c=Xe(),d=Q(4),f=Q(By),h=Jt(X(da(X(Ne(o),Sr(1),Dn(!0)),X(Ne(o),Sr(1),Dn(!1),hu(100))),It()),!1),p=Jt(X(da(X(n,Dn(!0)),X(n,Dn(!1),hu(200))),It()),!1);Se(X(zt(Ne(o),Ne(f)),pe(([b,S])=>b<=S),It()),a),Se(X(a,Gn(50)),c);const g=fn(X(zt(r,Ne(s),Ne(t),Ne(e),Ne(d)),Ln((b,[{scrollHeight:S,scrollTop:T},k,C,E,R])=>{const _=T+k-S>-R,j={scrollHeight:S,scrollTop:T,viewportHeight:k};if(_){let z,W;return T>b.state.scrollTop?(z="SCROLLED_DOWN",W=b.state.scrollTop-T):(z="SIZE_DECREASED",W=b.state.scrollTop-T||b.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:W,state:j}}let D;return j.scrollHeight>b.state.scrollHeight?D="SIZE_INCREASED":k<b.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":T<b.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:j}},zy),It((b,S)=>b&&b.atBottom===S.atBottom))),x=Jt(X(r,Ln((b,{scrollHeight:S,scrollTop:T,viewportHeight:k})=>{if(_u(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:T};{const C=S-(T+k)<1;return b.scrollTop!==T&&C?{changed:!0,jump:b.scrollTop-T,scrollHeight:S,scrollTop:T}:{changed:!0,jump:0,scrollHeight:S,scrollTop:T}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ae(b=>b.changed),pe(b=>b.jump)),0);Se(X(g,pe(b=>b.atBottom)),i),Se(X(i,Gn(50)),l);const y=Q(So);Se(X(r,pe(({scrollTop:b})=>b),It(),Ln((b,S)=>Mt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?bo:So,prevScrollTop:S},{direction:So,prevScrollTop:0}),pe(b=>b.direction)),y),Se(X(r,Gn(50),Dn($y)),y);const m=Q(0);return Se(X(h,Ae(b=>!b),Dn(0)),m),Se(X(o,Gn(100),Ve(h),Ae(([b,S])=>!!S),Ln(([b,S],[T])=>[S,T],[0,0]),pe(([b,S])=>S-b)),m),{atBottomState:g,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:y,scrollVelocity:m}},Et(nn)),Cs="top",ks="bottom",ju="none";function Ru(e,t,n){return typeof e=="number"?n===bo&&t===Cs||n===So&&t===ks?e:0:n===bo?t===Cs?e.main:e.reverse:t===ks?e.main:e.reverse}function Pu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Sa=st(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Xe(),i=Q(0),a=Q(0),l=Q(0),c=Jt(X(zt(Ne(r),Ne(o),Ne(n),Ne(s,xo),Ne(l),Ne(i),Ne(t),Ne(e),Ne(a)),pe(([d,f,h,[p,g],x,y,m,b,S])=>{const T=d-b,k=y+m,C=Math.max(h-T,0);let E=ju;const R=Pu(S,Cs),_=Pu(S,ks);return p-=b,p+=h+m,g+=h+m,g-=b,p>d+k-R&&(E=bo),g<d-C+f+_&&(E=So),E!==ju?[Math.max(T-h-Ru(x,Cs,E)-R,0),T-C-m+f+Ru(x,ks,E)+_]:null}),Ae(d=>d!=null),It(xo)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},Et(nn),{singleton:!0});function Hy(e,t,n){if(Ss(t)){const r=Tu(e,t);return[{index:An(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ca={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Ts(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 x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,g=h-d;return{bottom:d,firstItemIndex:s,items:Mu(e,o,s),offsetBottom:g,offsetTop:c,top:p,topItems:Mu(t,o,s),topListHeight:t.reduce((x,y)=>y.size+x,0),totalCount:n}}function Ou(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=ba(t,a),c=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Ts(c,[],a,o,n,r)}function Mu(e,t,n){if(e.length===0)return[];if(!Ss(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=vs(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;c.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:c.index-(l+1)+n},s.push({...d,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Tr=st(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:g}])=>{const x=Q([]),y=Q(0),m=Xe();Se(s.topItemsIndexes,x);const b=Jt(X(zt(p,g,Ne(l,xo),Ne(o),Ne(r),Ne(c),d,Ne(x),Ne(t),Ne(n),e),Ae(([C,E,,R,,,,,,,_])=>{const j=_&&_.length!==R;return C&&!E&&!j}),pe(([,,[C,E],R,_,j,D,z,W,O,B])=>{const P=_,{offsetTree:V,sizeTree:$}=P,F=Mt(y);if(R===0)return{...Ca,totalCount:R};if(C===0&&E===0)return F===0?{...Ca,totalCount:R}:Ou(F,j,_,W,O,B||[]);if(yt($))return F>0?null:Ts(Hy(ba(j,R),P,B),[],R,O,P,W);const ee=[];if(z.length>0){const de=z[0],we=z[z.length-1];let ne=0;for(const L of vs($,de,we)){const J=L.value,se=Math.max(L.start,de),ue=Math.min(L.end,we);for(let le=se;le<=ue;le++)ee.push({data:B==null?void 0:B[le],index:le,offset:ne,size:J}),ne+=J}}if(!D)return Ts([],ee,R,O,P,W);const te=z.length>0?z[z.length-1]+1:0,ve=_y(V,C,E,te);if(ve.length===0)return null;const Ie=R-1,Z=ys([],de=>{for(const we of ve){const ne=we.value;let L=ne.offset,J=we.start;const se=ne.size;if(ne.offset<C){J+=Math.floor((C-ne.offset+O)/(se+O));const le=J-we.start;L+=le*se+le*O}J<te&&(L+=(te-J)*se,J=te);const ue=Math.min(we.end,Ie);for(let le=J;le<=ue&&!(L>=E);le++)de.push({data:B==null?void 0:B[le],index:le,offset:L,size:se}),L+=se+O}});return Ts(Z,ee,R,O,P,W)}),Ae(C=>C!==null),It()),Ca);Se(X(e,Ae(ca),pe(C=>C==null?void 0:C.length)),o),Se(X(b,pe(C=>C.topListHeight)),f),Se(f,a),Se(X(b,pe(C=>[C.top,C.bottom])),i),Se(X(b,pe(C=>C.items)),m);const S=fn(X(b,Ae(({items:C})=>C.length>0),Ve(o,e),Ae(([{items:C},E])=>C[C.length-1].originalIndex===E-1),pe(([,C,E])=>[C-1,E]),It(xo),pe(([C])=>C))),T=fn(X(b,Gn(200),Ae(({items:C,topItems:E})=>C.length>0&&C[0].originalIndex===E.length),pe(({items:C})=>C[0].index),It())),k=fn(X(b,Ae(({items:C})=>C.length>0),pe(({items:C})=>{let E=0,R=C.length-1;for(;C[E].type==="group"&&E<R;)E++;for(;C[R].type==="group"&&R>E;)R--;return{endIndex:C[R].index,startIndex:C[E].index}}),It(Cu)));return{endReached:S,initialItemCount:y,itemsRendered:m,listState:b,rangeChanged:k,startReached:T,topItemsIndexes:x,...h}},Et(Fn,Nu,Sa,wo,vo,Co,or,xa),{singleton:!0}),Du=st(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Xe(),i=Jt(X(zt(n,e,r,t,o),pe(([a,l,c,d,f])=>a+l+c+d+f.offsetBottom+f.bottom)),0);return Se(Ne(i),s),{totalListHeight:i,totalListHeightChanged:s}},Et(nn,Tr),{singleton:!0}),Uy=st(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Q(!1),r=Jt(X(zt(n,e,t),Ae(([o])=>o),pe(([,o,s])=>Math.max(0,o-s)),Gn(0),It()),0);return{alignToBottom:n,paddingTopAddition:r}},Et(nn,Du),{singleton:!0}),Lu=st(()=>({context:Q(null)})),Wy=({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,Fu=st(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const d=Xe();return Se(X(d,Ve(t,l,n,s,o,r,a),Ve(e),pe(([[f,h,p,g,x,y,m,b],S])=>{const{align:T,behavior:k,calculateViewLocation:C=Wy,done:E,...R}=f,_=Eu(f,h,g-1),j=yo(_,h.offsetTree,S)+x+y,D=j+An(h.sizeTree,_)[1],z=b+y,W=b+p-m,O=C({itemBottom:D,itemTop:j,locationParams:{align:T,behavior:k,...R},viewportBottom:W,viewportTop:z});return O?E&&Nn(X(i,Ae(B=>!B),Sr(Mt(i)?1:2)),E):E&&E(),O}),Ae(f=>f!==null)),c),{scrollIntoView:d}},Et(Fn,nn,vo,Tr,nr),{singleton:!0});function $u(e){return e?e==="smooth"?"smooth":"auto":!1}const Vy=(e,t)=>typeof e=="function"?$u(e(t)):t&&$u(e),Ky=st(([{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:h},{scrollIntoView:p}])=>{const g=Q(!1),x=Xe();let y=null;function m(k){ze(i,{align:"end",behavior:k,index:"LAST"})}dt(X(zt(X(Ne(t),Sr(1)),l),Ve(Ne(g),s,a,f),pe(([[k,C],E,R,_,j])=>{let D=C&&_,z="auto";return D&&(z=Vy(E,R||j),D=D&&!!z),{followOutputBehavior:z,shouldFollow:D,totalCount:k}}),Ae(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:C})=>{y&&(y(),y=null),Mt(n)?requestAnimationFrame(()=>{Mt(d)("following output to ",{totalCount:C},cn.DEBUG),m(k)}):y=Nn(e,()=>{Mt(d)("following output to ",{totalCount:C},cn.DEBUG),m(k),y=null})});function b(k){const C=Nn(o,E=>{k&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!y&&(Mt(d)("scrolling to bottom due to increased size",{},cn.DEBUG),m("auto"))});setTimeout(C,100)}dt(X(zt(Ne(g),t,c),Ae(([k,,C])=>k&&C),Ln(({value:k},[,C])=>({refreshed:k===C,value:C}),{refreshed:!1,value:0}),Ae(({refreshed:k})=>k),Ve(g,t)),([,k])=>{Mt(a)&&b(k!==!1)}),dt(x,()=>{b(Mt(g)!==!1)}),dt(zt(Ne(g),o),([k,C])=>{k&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&m("auto")});const S=Q(null),T=Xe();return Se(da(X(Ne(r),pe(k=>{var C;return(C=k==null?void 0:k.length)!=null?C:0})),X(Ne(t))),T),dt(X(zt(X(T,Sr(1)),l),Ve(Ne(S),a,f,h),pe(([[k,C],E,R,_,j])=>C&&R&&(E==null?void 0:E({context:j,totalCount:k,scrollingInProgress:_}))),Ae(k=>!!k),Gn(0)),k=>{y&&(y(),y=null),Mt(n)?requestAnimationFrame(()=>{Mt(d)("scrolling into view",{}),ze(p,k)}):y=Nn(e,()=>{Mt(d)("scrolling into view",{}),ze(p,k),y=null})}),{autoscrollToBottom:x,followOutput:g,scrollIntoViewOnChange:S}},Et(Fn,Co,vo,wo,or,nr,nn,Lu,Fu)),qy=st(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(Se(X(a,Ve(s),Ae(([,l])=>l!==0),Ve(o,r,t,n,e),pe(([[,l],c,d,f,h,p=[]])=>Ou(l,c,d,f,h,p))),i),{}),Et(Fn,wo,Tr,or),{singleton:!0}),Gy=st(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Q(0);return dt(X(e,Ve(r),Ae(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{Nn(X(n,Sr(1),Ae(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ze(t,o)})})}),{initialScrollTop:r}},Et(or,nn,Tr),{singleton:!0}),zu=st(([{scrollVelocity:e}])=>{const t=Q(!1),n=Xe(),r=Q(!1);return Se(X(e,Ve(r,t,n),Ae(([o,s])=>!!s),pe(([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}),It()),t),dt(X(zt(t,e,n),Ve(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Et(Co),{singleton:!0}),ka=st(([{scrollContainerState:e,scrollTo:t}])=>{const n=Xe(),r=Xe(),o=Xe(),s=Q(!1),i=Q(void 0);return Se(X(zt(n,r),pe(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:c}))),e),Se(X(t,Ve(r),pe(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Et(nn)),Yy=st(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Xe(),d=Q(void 0),f=Q(null),h=Q(null);return Se(a,f),Se(l,h),dt(X(c,Ve(t,r,i,f,h,n)),([p,g,x,y,m,b,S])=>{const T=Ry(g.sizeTree);y&&m!==null&&b!==null&&(x=m.scrollTop-b.offsetTop),x-=S,p({ranges:T,scrollTop:x})}),Se(X(d,Ae(ca),pe(Xy)),o),Se(X(s,Ve(d),Ae(([,p])=>p!==void 0),It(),pe(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:d}},Et(Fn,nn,wo,or,ka));function Xy(e){return{align:"start",index:0,offset:e.scrollTop}}const Jy=st(([{topItemsIndexes:e}])=>{const t=Q(0);return Se(X(t,Ae(n=>n>=0),pe(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Et(Tr));function Bu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Zy=Bu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Qy=st(([{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:h},{log:p},{recalcInProgress:g}])=>{const x=fn(X(l,Ve(i),Ln(([,m,b,S],[{bottom:T,items:k,offsetBottom:C,totalCount:E},R])=>{const _=T+C;let j=0;return b===E&&m.length>0&&k.length>0&&(k[0].originalIndex===0&&m[0].originalIndex===0||(j=_-S,j!==0&&(j+=R))),[j,k,E,_]},[0,[],0,0]),Ae(([m])=>m!==0),Ve(r,a,n,o,p,g),Ae(([,m,b,S,,,T])=>!T&&!S&&m!==0&&b===bo),pe(([[m],,,,,b])=>(b("Upward scrolling compensation",{amount:m},cn.DEBUG),m))));function y(m){m>0?(ze(t,{behavior:"auto",top:-m}),ze(e,0)):(ze(e,0),ze(t,{behavior:"auto",top:-m}))}return dt(X(x,Ve(e,s)),([m,b,S])=>{S&&Zy()?ze(e,b-m):y(-m)}),dt(X(zt(Jt(s,!1),e,g),Ae(([m,b,S])=>!m&&!S&&b!==0),pe(([m,b])=>b),Gn(1)),y),Se(X(f,pe(m=>({top:-m}))),t),dt(X(c,Ve(h,d),pe(([m,{groupIndices:b,lastSize:S,sizeTree:T},k])=>{function C(E){return E*(S+k)}if(b.length===0)return C(m);{let E=0;const R=go(T,0);let _=0,j=0;for(;_<m;){_++,E+=R;let D=b.length===j+1?1/0:b[j+1]-b[j]-1;_+D>m&&(E-=R,D=m-_+1),_+=D,E+=C(D),j++}return E}})),m=>{ze(e,m),requestAnimationFrame(()=>{ze(t,{top:m}),requestAnimationFrame(()=>{ze(e,0),ze(g,!1)})})}),{deviation:e}},Et(nn,Co,Tr,Fn,nr,xa)),ev=st(([e,t,n,r,o,s,i,a,l,c,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...d}),Et(Sa,qy,or,zu,Du,Gy,Uy,ka,Fu,nr,Lu)),Hu=st(([{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:h,initialTopMostItemIndex:p,scrolledToInitialItem:g},x,y,m,{listState:b,topItemsIndexes:S,...T},{scrollToIndex:k},C,{topItemCount:E},{groupCounts:R},_])=>(Se(T.rangeChanged,_.scrollSeekRangeChanged),Se(X(_.windowViewportRect,pe(j=>j.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:R,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:g,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...m,groupIndices:s,itemSize:i,listState:b,scrollToIndex:k,statefulTotalCount:c,trackItemSizes:f,...T,..._,...x,sizes:l,...y}),Et(Fn,wo,nn,Yy,Ky,Tr,vo,Qy,Jy,Nu,ev));function tv(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 Es=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Uu(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,m){y.propsReady&&ze(y.propsReady,!1);for(const b of r){const S=y[t.required[b]];ze(S,m[b])}for(const b of o)if(b in m){const S=y[t.optional[b]];ze(S,m[b])}y.propsReady&&ze(y.propsReady,!0)}function c(y){return s.reduce((m,b)=>(m[b]=S=>{const T=y[t.methods[b]];ze(T,S)},m),{})}function d(y){return i.reduce((m,b)=>(m[b]=xy(y[t.events[b]]),m),{})}const f=w.forwardRef((y,m)=>{const{children:b,...S}=y,[T]=w.useState(()=>ys(vy(e),E=>{l(E,S)})),[k]=w.useState(fu(d,T));Es(()=>{for(const E of i)E in S&&dt(k[E],S[E]);return()=>{Object.values(k).map(ua)}},[S,k,T]),Es(()=>{l(T,S)}),w.useImperativeHandle(m,uu(c(T)));const C=n;return u.jsx(a.Provider,{value:T,children:n?u.jsx(C,{...tv([...r,...o,...i],S),children:b}):b})}),h=y=>{const m=w.useContext(a);return w.useCallback(b=>{ze(m[y],b)},[m,y])},p=y=>{const m=w.useContext(a)[y],b=w.useCallback(S=>dt(m,S),[m]);return w.useSyncExternalStore(b,()=>Mt(m),()=>Mt(m))},g=y=>{const m=w.useContext(a)[y],[b,S]=w.useState(fu(Mt,m));return Es(()=>dt(m,T=>{T!==b&&S(uu(T))}),[m,b]),b},x=w.version.startsWith("18")?p:g;return{Component:f,useEmitter:(y,m)=>{const b=w.useContext(a)[y];Es(()=>dt(b,m),[m,b])},useEmitterValue:x,usePublisher:h}}const Wu=w.createContext(void 0),Vu=w.createContext(void 0),Ku=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Ta(e){return"self"in e}function nv(e){return"body"in e}function qu(e,t,n,r=Hr,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(h=>{let p,g,x;const y=h.target;if(nv(y)||Ta(y)){const b=Ta(y)?y:y.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,g=s?b.innerWidth:b.innerHeight}else x=s?y.scrollLeft:y.scrollTop,p=s?y.scrollWidth:y.scrollHeight,g=s?y.offsetWidth:y.offsetHeight;const m=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:g})};h.suppressFlushSync?m():ji.flushSync(m),a.current!==null&&(x===a.current||x<=0||x===p-g)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const g=h.behavior==="smooth";let x,y,m;Ta(p)?(y=Math.max(rr(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,m=s?window.scrollX:window.scrollY):(y=p[s?"scrollWidth":"scrollHeight"],x=rr(p,s?"width":"height"),m=p[s?"scrollLeft":"scrollTop"]);const b=y-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),_u(x,y)||h.top===m){e({scrollHeight:y,scrollTop:m,viewportHeight:x}),g&&t(!0);return}g?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Ea="-webkit-sticky",Gu="sticky",Ia=Bu(()=>{if(typeof document>"u")return Gu;const e=document.createElement("div");return e.style.position=Ea,e.style.position===Ea?Ea:Gu});function Na(e){return e}const rv=st(()=>{const e=Q(a=>`Item ${a}`),t=Q(a=>`Group ${a}`),n=Q({}),r=Q(Na),o=Q("div"),s=Q(Hr),i=(a,l=null)=>Jt(X(n,pe(c=>c[a]),It()),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")}}),ov=st(([e,t])=>({...e,...t}),Et(Hu,rv)),sv=({height:e})=>u.jsx("div",{style:{height:e}}),iv={overflowAnchor:"none",position:Ia(),zIndex:1},Yu={overflowAnchor:"none"},av={...Yu,display:"inline-block",height:"100%"},Xu=w.memo(function({showTopList:e=!1}){const t=Re("listState"),n=yn("sizeRanges"),r=Re("useWindowScroll"),o=Re("customScrollParent"),s=yn("windowScrollContainerState"),i=yn("scrollContainerState"),a=o||r?s:i,l=Re("itemContent"),c=Re("context"),d=Re("groupContent"),f=Re("trackItemSizes"),h=Re("itemSize"),p=Re("log"),g=yn("gap"),x=Re("horizontalDirection"),{callbackRef:y}=Sy(n,h,f,e?Hr:a,p,g,o,x,Re("skipAnimationFrameInResizeObserver")),[m,b]=w.useState(0);Aa("deviation",O=>{m!==O&&b(O)});const S=Re("EmptyPlaceholder"),T=Re("ScrollSeekPlaceholder")||sv,k=Re("ListComponent"),C=Re("ItemComponent"),E=Re("GroupComponent"),R=Re("computeItemKey"),_=Re("isSeeking"),j=Re("groupIndices").length>0,D=Re("alignToBottom"),z=Re("initialItemFinalLocationReached"),W=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:m!==0?m:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:m!==0?m:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?u.jsx(S,{...Zt(S,c)}):u.jsx(k,{...Zt(k,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:W,children:(e?t.topItems:t.items).map(O=>{const B=O.originalIndex,P=R(B+t.firstItemIndex,O.data,c);return _?w.createElement(T,{...Zt(T,c),height:O.size,index:O.index,key:P,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?w.createElement(E,{...Zt(E,c),"data-index":B,"data-item-index":O.index,"data-known-size":O.size,key:P,style:iv},d(O.index,c)):w.createElement(C,{...Zt(C,c),...dv(C,O.data),"data-index":B,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:P,style:x?av:Yu},j?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),lv={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},cv={outline:"none",overflowX:"auto",position:"relative"},Is=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),uv={position:Ia(),top:0,width:"100%",zIndex:1};function Zt(e,t){if(typeof e!="string")return{context:t}}function dv(e,t){return{item:typeof e=="string"?void 0:t}}const fv=w.memo(function(){const e=Re("HeaderComponent"),t=yn("headerHeight"),n=Re("HeaderFooterTag"),r=Cr(w.useMemo(()=>s=>{t(rr(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Zt(e,o)})}):null}),hv=w.memo(function(){const e=Re("FooterComponent"),t=yn("footerHeight"),n=Re("HeaderFooterTag"),r=Cr(w.useMemo(()=>s=>{t(rr(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Zt(e,o)})}):null});function Ju({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:h,scrollerRef:p,scrollToCallback:g}=qu(a,c,l,d,void 0,f);return e("scrollTo",g),e("scrollBy",h),u.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?cv:lv,...o},tabIndex:0,...i,...Zt(l,s),children:r})})}function Zu({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"),h=t("customScrollParent"),p=w.useRef(null),g=t("scrollerRef"),{scrollByCallback:x,scrollerRef:y,scrollToCallback:m}=qu(a,c,l,g,h);return Ku(()=>{var b;return y.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{y.current=null}},[y,h]),e("windowScrollTo",m),e("scrollBy",x),u.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...Zt(l,s),children:r})})}const pv=({children:e})=>{const t=w.useContext(Wu),n=yn("viewportHeight"),r=yn("fixedItemHeight"),o=Re("alignToBottom"),s=Re("horizontalDirection"),i=w.useMemo(()=>du(n,l=>rr(l,s?"width":"height")),[n,s]),a=Cr(i,!0,Re("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),u.jsx("div",{"data-viewport-type":"element",ref:a,style:Is(o),children:e})},mv=({children:e})=>{const t=w.useContext(Wu),n=yn("windowViewportRect"),r=yn("fixedItemHeight"),o=Re("customScrollParent"),s=gu(n,o,Re("skipAnimationFrameInResizeObserver")),i=Re("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:Is(i),children:e})},gv=({children:e})=>{const t=Re("TopItemListComponent")||"div",n=Re("headerHeight"),r={...uv,marginTop:`${n}px`},o=Re("context");return u.jsx(t,{style:r,...Zt(t,o),children:e})},xv=w.memo(function(e){const t=Re("useWindowScroll"),n=Re("topItemsIndexes").length>0,r=Re("customScrollParent"),o=Re("context");return u.jsxs(r||t?wv:vv,{...e,context:o,children:[n&&u.jsx(gv,{children:u.jsx(Xu,{showTopList:!0})}),u.jsxs(r||t?mv:pv,{children:[u.jsx(fv,{}),u.jsx(Xu,{}),u.jsx(hv,{})]})]})}),{Component:yv,useEmitter:Aa,useEmitterValue:Re,usePublisher:yn}=Uu(ov,{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"}},xv),vv=Ju({useEmitter:Aa,useEmitterValue:Re,usePublisher:yn}),wv=Zu({useEmitter:Aa,useEmitterValue:Re,usePublisher:yn}),bv=yv;Et(Hu,st(()=>{const e=Q(c=>u.jsxs("td",{children:["Item $",c]})),t=Q(null),n=Q(c=>u.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=Q(null),o=Q(null),s=Q({}),i=Q(Na),a=Q(Hr),l=(c,d=null)=>Jt(X(s,pe(f=>f[c]),It()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Ia();const Qu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Sv={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:ed,floor:Ns,max:ko,min:_a,round:td}=Math;function nd(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Cv(e){return{...Sv,items:e}}function As(e,t){return e&&e.width===t.width&&e.height===t.height}function kv(e,t){return e&&e.column===t.column&&e.row===t.row}const Tv=st(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:g,propsReady:x},{customScrollParent:y,useWindowScroll:m,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:T},k])=>{const C=Q(0),E=Q(0),R=Q(Qu),_=Q({height:0,width:0}),j=Q({height:0,width:0}),D=Xe(),z=Xe(),W=Q(0),O=Q(null),B=Q({column:0,row:0}),P=Xe(),V=Xe(),$=Q(!1),F=Q(0),ee=Q(!0),te=Q(!1),ve=Q(!1);dt(X(g,Ve(F),Ae(([L,J])=>!!J)),()=>{ze(ee,!1)}),dt(X(zt(g,ee,j,_,F,te),Ae(([L,J,se,ue,,le])=>L&&!J&&se.height!==0&&ue.height!==0&&!le)),([,,,,L])=>{ze(te,!0),wa(1,()=>{ze(D,L)}),Nn(X(c),()=>{ze(t,[0,0]),ze(ee,!0)})}),Se(X(V,Ae(L=>L!=null&&L.scrollTop>0),Dn(0)),E),dt(X(g,Ve(V),Ae(([,L])=>L!=null)),([,L])=>{L&&(ze(_,L.viewport),ze(j,L.item),ze(B,L.gap),L.scrollTop>0&&(ze($,!0),Nn(X(c,Sr(1)),J=>{ze($,!1)}),ze(l,{top:L.scrollTop})))}),Se(X(_,pe(({height:L})=>L)),f),Se(X(zt(Ne(_,As),Ne(j,As),Ne(B,(L,J)=>L&&L.column===J.column&&L.row===J.row),Ne(c)),pe(([L,J,se,ue])=>({gap:se,item:J,scrollTop:ue,viewport:L}))),P),Se(X(zt(Ne(C),r,Ne(B,kv),Ne(j,As),Ne(_,As),Ne(O),Ne(E),Ne($),Ne(ee),Ne(F)),Ae(([,,,,,,,L])=>!L),pe(([L,[J,se],ue,le,Me,U,ye,,_e,Pe])=>{const{column:et,row:nt}=ue,{height:Ze,width:be}=le,{width:Qe}=Me;if(ye===0&&(L===0||Qe===0))return Qu;if(be===0){const He=ba(Pe,L),St=He+Math.max(ye-1,0);return Cv(nd(He,St,U))}const it=rd(Qe,be,et);let rt,Be;_e?J===0&&se===0&&ye>0?(rt=0,Be=ye-1):(rt=it*Ns((J+nt)/(Ze+nt)),Be=it*ed((se+nt)/(Ze+nt))-1,Be=_a(L-1,ko(Be,it-1)),rt=_a(Be,ko(0,rt))):(rt=0,Be=-1);const wt=nd(rt,Be,U),{bottom:mt,top:jt}=od(Me,ue,le,wt),Dt=ed(L/it),bt=Dt*Ze+(Dt-1)*nt-mt;return{bottom:mt,itemHeight:Ze,items:wt,itemWidth:be,offsetBottom:bt,offsetTop:jt,top:jt}})),R),Se(X(O,Ae(L=>L!==null),pe(L=>L.length)),C),Se(X(zt(_,j,R,B),Ae(([L,J,{items:se}])=>se.length>0&&J.height!==0&&L.height!==0),pe(([L,J,{items:se},ue])=>{const{bottom:le,top:Me}=od(L,ue,J,se);return[Me,le]}),It(xo)),t);const Ie=Q(!1);Se(X(c,Ve(Ie),pe(([L,J])=>J||L!==0)),Ie);const Z=fn(X(zt(R,C),Ae(([{items:L}])=>L.length>0),Ve(Ie),Ae(([[L,J],se])=>{const ue=L.items[L.items.length-1].index===J-1;return(se||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===J)&&ue}),pe(([[,L]])=>L-1),It())),de=fn(X(Ne(R),Ae(({items:L})=>L.length>0&&L[0].index===0),Dn(0),It())),we=fn(X(Ne(R),Ve($),Ae(([{items:L},J])=>L.length>0&&!J),pe(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),It(Cu),Gn(0)));Se(we,p.scrollSeekRangeChanged),Se(X(D,Ve(_,j,C,B),pe(([L,J,se,ue,le])=>{const Me=Au(L),{align:U,behavior:ye,offset:_e}=Me;let Pe=Me.index;Pe==="LAST"&&(Pe=ue-1),Pe=ko(0,Pe,_a(ue-1,Pe));let et=ja(J,le,se,Pe);return U==="end"?et=td(et-J.height+se.height):U==="center"&&(et=td(et-J.height/2+se.height/2)),_e&&(et+=_e),{behavior:ye,top:et}})),l);const ne=Jt(X(R,pe(L=>L.offsetBottom+L.bottom)),0);return Se(X(T,pe(L=>({height:L.visibleHeight,width:L.visibleWidth}))),_),{customScrollParent:y,data:O,deviation:W,footerHeight:o,gap:B,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:j,overscan:n,restoreStateFrom:V,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:l,scrollToIndex:D,scrollTop:c,smoothScrollTargetReached:d,totalCount:C,useWindowScroll:m,viewportDimensions:_,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:T,...p,gridState:R,horizontalDirection:ve,initialTopMostItemIndex:F,totalListHeight:ne,...h,endReached:Z,propsReady:x,rangeChanged:we,startReached:de,stateChanged:P,stateRestoreInProgress:$,...k}},Et(Sa,nn,Co,zu,or,ka,nr));function rd(e,t,n){return ko(1,Ns((e+n)/(Ns(t)+n)))}function od(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ja(e,t,n,r[0].index);return{bottom:ja(e,t,n,r[r.length-1].index)+o,top:s}}function ja(e,t,n,r){const o=rd(e.width,n.width,t.column),s=Ns(r/o),i=s*n.height+ko(0,s-1)*t.row;return i>0?i+t.row:i}const Ev=st(()=>{const e=Q(f=>`Item ${f}`),t=Q({}),n=Q(null),r=Q("virtuoso-grid-item"),o=Q("virtuoso-grid-list"),s=Q(Na),i=Q("div"),a=Q(Hr),l=(f,h=null)=>Jt(X(t,pe(p=>p[f]),It()),h),c=Q(!1),d=Q(!1);return Se(Ne(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")}}),Iv=st(([e,t])=>({...e,...t}),Et(Tv,Ev)),Nv=w.memo(function(){const e=Nt("gridState"),t=Nt("listClassName"),n=Nt("itemClassName"),r=Nt("itemContent"),o=Nt("computeItemKey"),s=Nt("isSeeking"),i=vn("scrollHeight"),a=Nt("ItemComponent"),l=Nt("ListComponent"),c=Nt("ScrollSeekPlaceholder"),d=Nt("context"),f=vn("itemDimensions"),h=vn("gap"),p=Nt("log"),g=Nt("stateRestoreInProgress"),x=vn("reportReadyState"),y=Cr(w.useMemo(()=>m=>{const b=m.parentElement.parentElement.scrollHeight;i(b);const S=m.firstChild;if(S){const{height:T,width:k}=S.getBoundingClientRect();f({height:T,width:k})}h({column:id("column-gap",getComputedStyle(m).columnGap,p),row:id("row-gap",getComputedStyle(m).rowGap,p)})},[i,f,h,p]),!0,!1);return Ku(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),g?null:u.jsx(l,{className:t,ref:y,...Zt(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(m=>{const b=o(m.index,m.data,d);return s?u.jsx(c,{...Zt(c,d),height:e.itemHeight,index:m.index,width:e.itemWidth},b):w.createElement(a,{...Zt(a,d),className:n,"data-index":m.index,key:b},r(m.index,m.data,d))})})}),Av=w.memo(function(){const e=Nt("HeaderComponent"),t=vn("headerHeight"),n=Nt("headerFooterTag"),r=Cr(w.useMemo(()=>s=>{t(rr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Zt(e,o)})}):null}),_v=w.memo(function(){const e=Nt("FooterComponent"),t=vn("footerHeight"),n=Nt("headerFooterTag"),r=Cr(w.useMemo(()=>s=>{t(rr(s,"height"))},[t]),!0,!1),o=Nt("context");return e?u.jsx(n,{ref:r,children:u.jsx(e,{...Zt(e,o)})}):null}),jv=({children:e})=>{const t=w.useContext(Vu),n=vn("itemDimensions"),r=vn("viewportDimensions"),o=Cr(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:Is(!1),children:e})},Rv=({children:e})=>{const t=w.useContext(Vu),n=vn("windowViewportRect"),r=vn("itemDimensions"),o=Nt("customScrollParent"),s=gu(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:Is(!1),children:e})},Pv=w.memo(function({...e}){const t=Nt("useWindowScroll"),n=Nt("customScrollParent"),r=n||t?Mv:Ov,o=n||t?Rv:jv,s=Nt("context");return u.jsx(r,{...e,...Zt(r,s),children:u.jsxs(o,{children:[u.jsx(Av,{}),u.jsx(Nv,{}),u.jsx(_v,{})]})})}),{useEmitter:sd,useEmitterValue:Nt,usePublisher:vn}=Uu(Iv,{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"}},Pv),Ov=Ju({useEmitter:sd,useEmitterValue:Nt,usePublisher:vn}),Mv=Zu({useEmitter:sd,useEmitterValue:Nt,usePublisher:vn});function id(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,cn.WARN),t==="normal"?0:parseInt(t??"0",10)}const Dv=Go.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 ad({className:e,variant:t,...n}){return u.jsx("div",{className:oe(Dv({variant:t}),e),...n})}const To=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));To.displayName="Card";const Eo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",e),...t}));Eo.displayName="CardHeader";const Io=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:oe("text-2xl font-semibold leading-none tracking-tight",e),...t}));Io.displayName="CardTitle";const ld=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));ld.displayName="CardDescription";const No=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("p-6 pt-0",e),...t}));No.displayName="CardContent";const cd=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",e),...t}));cd.displayName="CardFooter";const Lv=1,Fv=1e6;let Ra=0;function $v(){return Ra=(Ra+1)%Number.MAX_SAFE_INTEGER,Ra.toString()}const Pa=new Map,ud=e=>{if(Pa.has(e))return;const t=setTimeout(()=>{Pa.delete(e),Ao({type:"REMOVE_TOAST",toastId:e})},Fv);Pa.set(e,t)},zv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Lv)};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?ud(n):e.toasts.forEach(r=>{ud(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},_s=[];let js={toasts:[]};function Ao(e){js=zv(js,e),_s.forEach(t=>{t(js)})}function Bv({...e}){const t=$v(),n=o=>Ao({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>Ao({type:"DISMISS_TOAST",toastId:t});return Ao({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function Oa(){const[e,t]=v.useState(js);return v.useEffect(()=>(_s.push(t),()=>{const n=_s.indexOf(t);n>-1&&_s.splice(n,1)}),[e]),{...e,toast:Bv,dismiss:n=>Ao({type:"DISMISS_TOAST",toastId:n})}}async function dd(e,t){return await En(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function fd(e,t){return await(await dd(`/files/${e}/view`,t)).text()}async function Hv(e,t){const n=await dd(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await En(`/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 Uv(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await En("/files",{params:r})}function Ma(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function hd(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function _o(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(_o).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(hd(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=_o(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 jo(e){if(typeof e=="string")return e;if(hd(e))return"";try{const t=_o(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Wv(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function Vv(e){const t=jo(e);return typeof e=="string"&&Wv(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function Rs(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=Ma(t);if(n!==null)return Rs(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Rs(e.content):e}function ge(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 pd(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Da(...e){return t=>{let n=!1;const r=e.map(o=>{const s=pd(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():pd(e[o],null)}}}}function Je(...e){return v.useCallback(Da(...e),e)}function Kv(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 Yn(e,t=[]){let n=[];function r(s,i){const a=v.createContext(i),l=n.length;n=[...n,i];const c=f=>{var m;const{scope:h,children:p,...g}=f,x=((m=h==null?void 0:h[e])==null?void 0:m[l])||a,y=v.useMemo(()=>g,Object.values(g));return u.jsx(x.Provider,{value:y,children:p})};c.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,g=v.useContext(p);if(g)return g;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,qv(o,...t)]}function qv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return v.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Kt=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},Gv=v[" useId ".trim().toString()]||(()=>{}),Yv=0;function Xn(e){const[t,n]=v.useState(Gv());return Kt(()=>{n(r=>r??String(Yv++))},[e]),e||(t?`radix-${t}`:"")}var Xv=v[" useInsertionEffect ".trim().toString()]||Kt;function Wr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Jv({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 h=Zv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,c]}function Jv({defaultProp:e,onChange:t}){const[n,r]=v.useState(e),o=v.useRef(n),s=v.useRef(t);return Xv(()=>{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 Zv(e){return typeof e=="function"}var Qv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Oe=Qv.reduce((e,t)=>{const n=xr.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 md(e,t){e&&Yo.flushSync(()=>e.dispatchEvent(t))}function qt(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 ew(e,t=globalThis==null?void 0:globalThis.document){const n=qt(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 tw="DismissableLayer",La="dismissableLayer.update",nw="dismissableLayer.pointerDownOutside",rw="dismissableLayer.focusOutside",gd,xd=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ps=v.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=v.useContext(xd),[d,f]=v.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=v.useState({}),g=Je(t,E=>f(E)),x=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),m=x.indexOf(y),b=d?x.indexOf(d):-1,S=c.layersWithOutsidePointerEventsDisabled.size>0,T=b>=m,k=iw(E=>{const R=E.target,_=[...c.branches].some(j=>j.contains(R));!T||_||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),C=aw(E=>{const R=E.target;[...c.branches].some(j=>j.contains(R))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return ew(E=>{b===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),v.useEffect(()=>{if(d)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(gd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),yd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=gd)}},[d,h,n,c]),v.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),yd())},[d,c]),v.useEffect(()=>{const E=()=>p({});return document.addEventListener(La,E),()=>document.removeEventListener(La,E)},[]),u.jsx(Oe.div,{...l,ref:g,style:{pointerEvents:S?T?"auto":"none":void 0,...e.style},onFocusCapture:ge(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ge(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ge(e.onPointerDownCapture,k.onPointerDownCapture)})});Ps.displayName=tw;var ow="DismissableLayerBranch",sw=v.forwardRef((e,t)=>{const n=v.useContext(xd),r=v.useRef(null),o=Je(t,r);return v.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),u.jsx(Oe.div,{...e,ref:o})});sw.displayName=ow;function iw(e,t=globalThis==null?void 0:globalThis.document){const n=qt(e),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){vd(nw,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 aw(e,t=globalThis==null?void 0:globalThis.document){const n=qt(e),r=v.useRef(!1);return v.useEffect(()=>{const o=s=>{s.target&&!r.current&&vd(rw,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 yd(){const e=new CustomEvent(La);document.dispatchEvent(e)}function vd(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?md(o,s):o.dispatchEvent(s)}var Fa="focusScope.autoFocusOnMount",$a="focusScope.autoFocusOnUnmount",wd={bubbles:!1,cancelable:!0},lw="FocusScope",Os=v.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=v.useState(null),c=qt(o),d=qt(s),f=v.useRef(null),h=Je(t,x=>l(x)),p=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const T=S.target;a.contains(T)?f.current=T:sr(f.current,{select:!0})},y=function(S){if(p.paused||!a)return;const T=S.relatedTarget;T!==null&&(a.contains(T)||sr(f.current,{select:!0}))},m=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&sr(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",y);const b=new MutationObserver(m);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",y),b.disconnect()}}},[r,a,p.paused]),v.useEffect(()=>{if(a){Cd.add(p);const x=document.activeElement;if(!a.contains(x)){const m=new CustomEvent(Fa,wd);a.addEventListener(Fa,c),a.dispatchEvent(m),m.defaultPrevented||(cw(pw(bd(a)),{select:!0}),document.activeElement===x&&sr(a))}return()=>{a.removeEventListener(Fa,c),setTimeout(()=>{const m=new CustomEvent($a,wd);a.addEventListener($a,d),a.dispatchEvent(m),m.defaultPrevented||sr(x??document.body,{select:!0}),a.removeEventListener($a,d),Cd.remove(p)},0)}}},[a,c,d,p]);const g=v.useCallback(x=>{if(!n&&!r||p.paused)return;const y=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,m=document.activeElement;if(y&&m){const b=x.currentTarget,[S,T]=uw(b);S&&T?!x.shiftKey&&m===T?(x.preventDefault(),n&&sr(S,{select:!0})):x.shiftKey&&m===S&&(x.preventDefault(),n&&sr(T,{select:!0})):m===b&&x.preventDefault()}},[n,r,p.paused]);return u.jsx(Oe.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});Os.displayName=lw;function cw(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(sr(r,{select:t}),document.activeElement!==n)return}function uw(e){const t=bd(e),n=Sd(t,e),r=Sd(t.reverse(),e);return[n,r]}function bd(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 Sd(e,t){for(const n of e)if(!dw(n,{upTo:t}))return n}function dw(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 fw(e){return e instanceof HTMLInputElement&&"select"in e}function sr(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&fw(e)&&t&&e.select()}}var Cd=hw();function hw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=kd(e,t),e.unshift(t)},remove(t){var n;e=kd(e,t),(n=e[0])==null||n.resume()}}}function kd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function pw(e){return e.filter(t=>t.tagName!=="A")}var mw="Portal",Ms=v.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=v.useState(!1);Kt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?ji.createPortal(u.jsx(Oe.div,{...r,ref:t}),i):null});Ms.displayName=mw;function gw(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var wn=e=>{const{present:t,children:n}=e,r=xw(t),o=typeof n=="function"?n({present:r.isPresent}):v.Children.only(n),s=Je(r.ref,yw(o));return typeof n=="function"||r.isPresent?v.cloneElement(o,{ref:s}):null};wn.displayName="Presence";function xw(e){const[t,n]=v.useState(),r=v.useRef(null),o=v.useRef(e),s=v.useRef("none"),i=e?"mounted":"unmounted",[a,l]=gw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const c=Ds(r.current);s.current=a==="mounted"?c:"none"},[a]),Kt(()=>{const c=r.current,d=o.current;if(d!==e){const h=s.current,p=Ds(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Kt(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,f=p=>{const x=Ds(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(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)})}},h=p=>{p.target===t&&(s.current=Ds(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",h),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 Ds(e){return(e==null?void 0:e.animationName)||"none"}function yw(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 za=0;function Ba(){v.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Td()),document.body.insertAdjacentElement("beforeend",e[1]??Td()),za++,()=>{za===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),za--}},[])}function Td(){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 $n=function(){return $n=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},$n.apply(this,arguments)};function Ed(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 vw(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 Ls="right-scroll-bar-position",Fs="width-before-scroll-bar",ww="with-scroll-bars-hidden",bw="--removed-body-scroll-bar-size";function Ha(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Sw(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 Cw=typeof window<"u"?v.useLayoutEffect:v.useEffect,Id=new WeakMap;function kw(e,t){var n=Sw(null,function(r){return e.forEach(function(o){return Ha(o,r)})});return Cw(function(){var r=Id.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Ha(a,null)}),s.forEach(function(a){o.has(a)||Ha(a,i)})}Id.set(n,e)},[e]),n}function Tw(e){return e}function Ew(e,t){t===void 0&&(t=Tw);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 Iw(e){e===void 0&&(e={});var t=Ew(null);return t.options=$n({async:!0,ssr:!1},e),t}var Nd=function(e){var t=e.sideCar,n=Ed(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,$n({},n))};Nd.isSideCarExport=!0;function Nw(e,t){return e.useMedium(t),Nd}var Ad=Iw(),Ua=function(){},$s=v.forwardRef(function(e,t){var n=v.useRef(null),r=v.useState({onScrollCapture:Ua,onWheelCapture:Ua,onTouchMoveCapture:Ua}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,g=e.noIsolation,x=e.inert,y=e.allowPinchZoom,m=e.as,b=m===void 0?"div":m,S=e.gapMode,T=Ed(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,C=kw([n,t]),E=$n($n({},T),o);return v.createElement(v.Fragment,null,d&&v.createElement(k,{sideCar:Ad,removeScrollBar:c,shards:f,noRelative:p,noIsolation:g,inert:x,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),i?v.cloneElement(v.Children.only(a),$n($n({},E),{ref:C})):v.createElement(b,$n({},E,{className:l,ref:C}),a))});$s.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},$s.classNames={fullWidth:Fs,zeroRight:Ls};var Aw=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function _w(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Aw();return t&&e.setAttribute("nonce",t),e}function jw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Rw(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Pw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=_w())&&(jw(t,n),Rw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Ow=function(){var e=Pw();return function(t,n){v.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},_d=function(){var e=Ow(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Mw={left:0,top:0,right:0,gap:0},Wa=function(e){return parseInt(e||"",10)||0},Dw=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[Wa(n),Wa(r),Wa(o)]},Lw=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Mw;var t=Dw(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])}},Fw=_d(),Vr="data-scroll-locked",$w=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
39
  .`.concat(ww,` {
40
40
  overflow: hidden `).concat(r,`;
41
41
  padding-right: `).concat(a,"px ").concat(r,`;
42
42
  }
43
- body[`).concat(Hr,`] {
43
+ body[`).concat(Vr,`] {
44
44
  overflow: hidden `).concat(r,`;
45
45
  overscroll-behavior: contain;
46
46
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -53,46 +53,46 @@ 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(Rs,` {
56
+ .`).concat(Ls,` {
57
57
  right: `).concat(a,"px ").concat(r,`;
58
58
  }
59
59
 
60
- .`).concat(Ps,` {
60
+ .`).concat(Fs,` {
61
61
  margin-right: `).concat(a,"px ").concat(r,`;
62
62
  }
63
63
 
64
- .`).concat(Rs," .").concat(Rs,` {
64
+ .`).concat(Ls," .").concat(Ls,` {
65
65
  right: 0 `).concat(r,`;
66
66
  }
67
67
 
68
- .`).concat(Ps," .").concat(Ps,` {
68
+ .`).concat(Fs," .").concat(Fs,` {
69
69
  margin-right: 0 `).concat(r,`;
70
70
  }
71
71
 
72
- body[`).concat(Hr,`] {
72
+ body[`).concat(Vr,`] {
73
73
  `).concat(bw,": ").concat(a,`px;
74
74
  }
75
- `)},Td=function(){var e=parseInt(document.body.getAttribute(Hr)||"0",10);return isFinite(e)?e:0},zw=function(){v.useEffect(function(){return document.body.setAttribute(Hr,(Td()+1).toString()),function(){var e=Td()-1;e<=0?document.body.removeAttribute(Hr):document.body.setAttribute(Hr,e.toString())}},[])},Bw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;zw();var s=v.useMemo(function(){return Lw(o)},[o]);return v.createElement($w,{styles:Fw(s,!t,o,n?"":"!important")})},Fa=!1;if(typeof window<"u")try{var Ms=Object.defineProperty({},"passive",{get:function(){return Fa=!0,!0}});window.addEventListener("test",Ms,Ms),window.removeEventListener("test",Ms,Ms)}catch{Fa=!1}var Ur=Fa?{passive:!1}:!1,Hw=function(e){return e.tagName==="TEXTAREA"},Ed=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Hw(e)&&n[t]==="visible")},Uw=function(e){return Ed(e,"overflowY")},Ww=function(e){return Ed(e,"overflowX")},Id=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Nd(e,r);if(o){var s=Ad(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Vw=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Kw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Nd=function(e,t){return e==="v"?Uw(t):Ww(t)},Ad=function(e,t){return e==="v"?Vw(t):Kw(t)},qw=function(e,t){return e==="h"&&t==="rtl"?-1:1},Gw=function(e,t,n,r,o){var s=qw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Ad(e,a),g=p[0],x=p[1],y=p[2],m=x-y-s*g;(g||m)&&Nd(e,a)&&(f+=m,h+=g);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},Ds=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},_d=function(e){return[e.deltaX,e.deltaY]},jd=function(e){return e&&"current"in e?e.current:e},Xw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Yw=function(e){return`
75
+ `)},jd=function(){var e=parseInt(document.body.getAttribute(Vr)||"0",10);return isFinite(e)?e:0},zw=function(){v.useEffect(function(){return document.body.setAttribute(Vr,(jd()+1).toString()),function(){var e=jd()-1;e<=0?document.body.removeAttribute(Vr):document.body.setAttribute(Vr,e.toString())}},[])},Bw=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;zw();var s=v.useMemo(function(){return Lw(o)},[o]);return v.createElement(Fw,{styles:$w(s,!t,o,n?"":"!important")})},Va=!1;if(typeof window<"u")try{var zs=Object.defineProperty({},"passive",{get:function(){return Va=!0,!0}});window.addEventListener("test",zs,zs),window.removeEventListener("test",zs,zs)}catch{Va=!1}var Kr=Va?{passive:!1}:!1,Hw=function(e){return e.tagName==="TEXTAREA"},Rd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Hw(e)&&n[t]==="visible")},Uw=function(e){return Rd(e,"overflowY")},Ww=function(e){return Rd(e,"overflowX")},Pd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Od(e,r);if(o){var s=Md(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Vw=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Kw=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Od=function(e,t){return e==="v"?Uw(t):Ww(t)},Md=function(e,t){return e==="v"?Vw(t):Kw(t)},qw=function(e,t){return e==="h"&&t==="rtl"?-1:1},Gw=function(e,t,n,r,o){var s=qw(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=Md(e,a),g=p[0],x=p[1],y=p[2],m=x-y-s*g;(g||m)&&Od(e,a)&&(f+=m,h+=g);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(c=!0),c},Bs=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Dd=function(e){return[e.deltaX,e.deltaY]},Ld=function(e){return e&&"current"in e?e.current:e},Yw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Xw=function(e){return`
76
76
  .block-interactivity-`.concat(e,` {pointer-events: none;}
77
77
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
78
- `)},Jw=0,Wr=[];function Zw(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(Jw++)[0],s=v.useState(kd)[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 x=vw([e.lockRef.current],(e.shards||[]).map(jd),!0).filter(Boolean);return x.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(x,y){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var m=Ds(x),b=n.current,S="deltaX"in x?x.deltaX:b[0]-m[0],T="deltaY"in x?x.deltaY:b[1]-m[1],k,C=x.target,E=Math.abs(S)>Math.abs(T)?"h":"v";if("touches"in x&&E==="h"&&C.type==="range")return!1;var R=Id(E,C);if(!R)return!0;if(R?k=E:(k=E==="v"?"h":"v",R=Id(E,C)),!R)return!1;if(!r.current&&"changedTouches"in x&&(S||T)&&(r.current=k),!k)return!0;var _=r.current||k;return Gw(_,y,x,_==="h"?S:T)},[]),l=v.useCallback(function(x){var y=x;if(!(!Wr.length||Wr[Wr.length-1]!==s)){var m="deltaY"in y?_d(y):Ds(y),b=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&Xw(k.delta,m)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(jd).filter(Boolean).filter(function(k){return k.contains(y.target)}),T=S.length>0?a(y,S[0]):!i.current.noIsolation;T&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(x,y,m,b){var S={name:x,delta:y,target:m,should:b,shadowParent:Qw(m)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(T){return T!==S})},1)},[]),d=v.useCallback(function(x){n.current=Ds(x),r.current=void 0},[]),f=v.useCallback(function(x){c(x.type,_d(x),x.target,a(x,e.lockRef.current))},[]),h=v.useCallback(function(x){c(x.type,Ds(x),x.target,a(x,e.lockRef.current))},[]);v.useEffect(function(){return Wr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Ur),document.addEventListener("touchmove",l,Ur),document.addEventListener("touchstart",d,Ur),function(){Wr=Wr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,Ur),document.removeEventListener("touchmove",l,Ur),document.removeEventListener("touchstart",d,Ur)}},[]);var p=e.removeScrollBar,g=e.inert;return v.createElement(v.Fragment,null,g?v.createElement(s,{styles:Yw(o)}):null,p?v.createElement(Bw,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Qw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const eb=Nw(Cd,Zw);var Ls=v.forwardRef(function(e,t){return v.createElement(Os,Pn({},e,{ref:t,sideCar:eb}))});Ls.classNames=Os.classNames;var tb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Vr=new WeakMap,$s=new WeakMap,Fs={},za=0,Rd=function(e){return e&&(e.host||Rd(e.parentNode))},nb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Rd(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})},rb=function(e,t,n,r){var o=nb(t,Array.isArray(e)?e:[e]);Fs[n]||(Fs[n]=new WeakMap);var s=Fs[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(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),g=p!==null&&p!=="false",x=(Vr.get(h)||0)+1,y=(s.get(h)||0)+1;Vr.set(h,x),s.set(h,y),i.push(h),x===1&&g&&$s.set(h,!0),y===1&&h.setAttribute(n,"true"),g||h.setAttribute(r,"true")}catch(m){console.error("aria-hidden: cannot operate on ",h,m)}})};return d(t),a.clear(),za++,function(){i.forEach(function(f){var h=Vr.get(f)-1,p=s.get(f)-1;Vr.set(f,h),s.set(f,p),h||($s.has(f)||f.removeAttribute(r),$s.delete(f)),p||f.removeAttribute(n)}),za--,za||(Vr=new WeakMap,Vr=new WeakMap,$s=new WeakMap,Fs={})}},Ba=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=tb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),rb(r,o,n,"aria-hidden")):function(){return null}},zs="Dialog",[Pd,AT]=Hn(zs),[ob,Tn]=Pd(zs),Od=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]=Br({prop:r,defaultProp:o??!1,onChange:s,caller:zs});return u.jsx(ob,{scope:t,triggerRef:a,contentRef:l,contentId:Un(),titleId:Un(),descriptionId:Un(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Od.displayName=zs;var Md="DialogTrigger",Dd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Tn(Md,n),s=Ze(t,o.triggerRef);return u.jsx(De.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Wa(o.open),...r,ref:s,onClick:ye(e.onClick,o.onOpenToggle)})});Dd.displayName=Md;var Ha="DialogPortal",[sb,Ld]=Pd(Ha,{forceMount:void 0}),$d=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Tn(Ha,t);return u.jsx(sb,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(gn,{present:n||s.open,children:u.jsx(_s,{asChild:!0,container:o,children:i})}))})};$d.displayName=Ha;var Bs="DialogOverlay",Fd=v.forwardRef((e,t)=>{const n=Ld(Bs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Tn(Bs,e.__scopeDialog);return s.modal?u.jsx(gn,{present:r||s.open,children:u.jsx(ab,{...o,ref:t})}):null});Fd.displayName=Bs;var ib=hr.createSlot("DialogOverlay.RemoveScroll"),ab=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Tn(Bs,n);return u.jsx(Ls,{as:ib,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(De.div,{"data-state":Wa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Sr="DialogContent",zd=v.forwardRef((e,t)=>{const n=Ld(Sr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Tn(Sr,e.__scopeDialog);return u.jsx(gn,{present:r||s.open,children:s.modal?u.jsx(lb,{...o,ref:t}):u.jsx(cb,{...o,ref:t})})});zd.displayName=Sr;var lb=v.forwardRef((e,t)=>{const n=Tn(Sr,e.__scopeDialog),r=v.useRef(null),o=Ze(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return Ba(s)},[]),u.jsx(Bd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ye(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ye(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ye(e.onFocusOutside,s=>s.preventDefault())})}),cb=v.forwardRef((e,t)=>{const n=Tn(Sr,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(Bd,{...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()}})}),Bd=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Tn(Sr,n),l=v.useRef(null),c=Ze(t,l);return Ma(),u.jsxs(u.Fragment,{children:[u.jsx(As,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Ns,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Wa(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(ub,{titleId:a.titleId}),u.jsx(fb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ua="DialogTitle",Hd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Tn(Ua,n);return u.jsx(De.h2,{id:o.titleId,...r,ref:t})});Hd.displayName=Ua;var Ud="DialogDescription",Wd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Tn(Ud,n);return u.jsx(De.p,{id:o.descriptionId,...r,ref:t})});Wd.displayName=Ud;var Vd="DialogClose",Kd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Tn(Vd,n);return u.jsx(De.button,{type:"button",...r,ref:t,onClick:ye(e.onClick,()=>o.onOpenChange(!1))})});Kd.displayName=Vd;function Wa(e){return e?"open":"closed"}var qd="DialogTitleWarning",[_T,Gd]=Kv(qd,{contentName:Sr,titleName:Ua,docsSlug:"dialog"}),ub=({titleId:e})=>{const t=Gd(qd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
78
+ `)},Jw=0,qr=[];function Zw(e){var t=v.useRef([]),n=v.useRef([0,0]),r=v.useRef(),o=v.useState(Jw++)[0],s=v.useState(_d)[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 x=vw([e.lockRef.current],(e.shards||[]).map(Ld),!0).filter(Boolean);return x.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=v.useCallback(function(x,y){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var m=Bs(x),b=n.current,S="deltaX"in x?x.deltaX:b[0]-m[0],T="deltaY"in x?x.deltaY:b[1]-m[1],k,C=x.target,E=Math.abs(S)>Math.abs(T)?"h":"v";if("touches"in x&&E==="h"&&C.type==="range")return!1;var R=Pd(E,C);if(!R)return!0;if(R?k=E:(k=E==="v"?"h":"v",R=Pd(E,C)),!R)return!1;if(!r.current&&"changedTouches"in x&&(S||T)&&(r.current=k),!k)return!0;var _=r.current||k;return Gw(_,y,x,_==="h"?S:T)},[]),l=v.useCallback(function(x){var y=x;if(!(!qr.length||qr[qr.length-1]!==s)){var m="deltaY"in y?Dd(y):Bs(y),b=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&Yw(k.delta,m)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Ld).filter(Boolean).filter(function(k){return k.contains(y.target)}),T=S.length>0?a(y,S[0]):!i.current.noIsolation;T&&y.cancelable&&y.preventDefault()}}},[]),c=v.useCallback(function(x,y,m,b){var S={name:x,delta:y,target:m,should:b,shadowParent:Qw(m)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(T){return T!==S})},1)},[]),d=v.useCallback(function(x){n.current=Bs(x),r.current=void 0},[]),f=v.useCallback(function(x){c(x.type,Dd(x),x.target,a(x,e.lockRef.current))},[]),h=v.useCallback(function(x){c(x.type,Bs(x),x.target,a(x,e.lockRef.current))},[]);v.useEffect(function(){return qr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Kr),document.addEventListener("touchmove",l,Kr),document.addEventListener("touchstart",d,Kr),function(){qr=qr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,Kr),document.removeEventListener("touchmove",l,Kr),document.removeEventListener("touchstart",d,Kr)}},[]);var p=e.removeScrollBar,g=e.inert;return v.createElement(v.Fragment,null,g?v.createElement(s,{styles:Xw(o)}):null,p?v.createElement(Bw,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Qw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const eb=Nw(Ad,Zw);var Hs=v.forwardRef(function(e,t){return v.createElement($s,$n({},e,{ref:t,sideCar:eb}))});Hs.classNames=$s.classNames;var tb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Gr=new WeakMap,Us=new WeakMap,Ws={},Ka=0,Fd=function(e){return e&&(e.host||Fd(e.parentNode))},nb=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Fd(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})},rb=function(e,t,n,r){var o=nb(t,Array.isArray(e)?e:[e]);Ws[n]||(Ws[n]=new WeakMap);var s=Ws[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(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),g=p!==null&&p!=="false",x=(Gr.get(h)||0)+1,y=(s.get(h)||0)+1;Gr.set(h,x),s.set(h,y),i.push(h),x===1&&g&&Us.set(h,!0),y===1&&h.setAttribute(n,"true"),g||h.setAttribute(r,"true")}catch(m){console.error("aria-hidden: cannot operate on ",h,m)}})};return d(t),a.clear(),Ka++,function(){i.forEach(function(f){var h=Gr.get(f)-1,p=s.get(f)-1;Gr.set(f,h),s.set(f,p),h||(Us.has(f)||f.removeAttribute(r),Us.delete(f)),p||f.removeAttribute(n)}),Ka--,Ka||(Gr=new WeakMap,Gr=new WeakMap,Us=new WeakMap,Ws={})}},qa=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=tb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),rb(r,o,n,"aria-hidden")):function(){return null}},Vs="Dialog",[$d,AT]=Yn(Vs),[ob,_n]=$d(Vs),zd=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]=Wr({prop:r,defaultProp:o??!1,onChange:s,caller:Vs});return u.jsx(ob,{scope:t,triggerRef:a,contentRef:l,contentId:Xn(),titleId:Xn(),descriptionId:Xn(),open:c,onOpenChange:d,onOpenToggle:v.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};zd.displayName=Vs;var Bd="DialogTrigger",Hd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=_n(Bd,n),s=Je(t,o.triggerRef);return u.jsx(Oe.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Xa(o.open),...r,ref:s,onClick:ge(e.onClick,o.onOpenToggle)})});Hd.displayName=Bd;var Ga="DialogPortal",[sb,Ud]=$d(Ga,{forceMount:void 0}),Wd=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=_n(Ga,t);return u.jsx(sb,{scope:t,forceMount:n,children:v.Children.map(r,i=>u.jsx(wn,{present:n||s.open,children:u.jsx(Ms,{asChild:!0,container:o,children:i})}))})};Wd.displayName=Ga;var Ks="DialogOverlay",Vd=v.forwardRef((e,t)=>{const n=Ud(Ks,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=_n(Ks,e.__scopeDialog);return s.modal?u.jsx(wn,{present:r||s.open,children:u.jsx(ab,{...o,ref:t})}):null});Vd.displayName=Ks;var ib=xr.createSlot("DialogOverlay.RemoveScroll"),ab=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=_n(Ks,n);return u.jsx(Hs,{as:ib,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Oe.div,{"data-state":Xa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Er="DialogContent",Kd=v.forwardRef((e,t)=>{const n=Ud(Er,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=_n(Er,e.__scopeDialog);return u.jsx(wn,{present:r||s.open,children:s.modal?u.jsx(lb,{...o,ref:t}):u.jsx(cb,{...o,ref:t})})});Kd.displayName=Er;var lb=v.forwardRef((e,t)=>{const n=_n(Er,e.__scopeDialog),r=v.useRef(null),o=Je(t,n.contentRef,r);return v.useEffect(()=>{const s=r.current;if(s)return qa(s)},[]),u.jsx(qd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ge(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ge(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault())})}),cb=v.forwardRef((e,t)=>{const n=_n(Er,e.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return u.jsx(qd,{...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()}})}),qd=v.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=_n(Er,n),l=v.useRef(null),c=Je(t,l);return Ba(),u.jsxs(u.Fragment,{children:[u.jsx(Os,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Ps,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Xa(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(ub,{titleId:a.titleId}),u.jsx(fb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Ya="DialogTitle",Gd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=_n(Ya,n);return u.jsx(Oe.h2,{id:o.titleId,...r,ref:t})});Gd.displayName=Ya;var Yd="DialogDescription",Xd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=_n(Yd,n);return u.jsx(Oe.p,{id:o.descriptionId,...r,ref:t})});Xd.displayName=Yd;var Jd="DialogClose",Zd=v.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=_n(Jd,n);return u.jsx(Oe.button,{type:"button",...r,ref:t,onClick:ge(e.onClick,()=>o.onOpenChange(!1))})});Zd.displayName=Jd;function Xa(e){return e?"open":"closed"}var Qd="DialogTitleWarning",[_T,ef]=Kv(Qd,{contentName:Er,titleName:Ya,docsSlug:"dialog"}),ub=({titleId:e})=>{const t=ef(Qd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
79
79
 
80
80
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
81
81
 
82
- 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},db="DialogDescriptionWarning",fb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Gd(db).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},Xd=Od,hb=Dd,Yd=$d,Hs=Fd,Us=zd,Cr=Hd,Ws=Wd,Jd=Kd;const pb=Xd,mb=Yd,Zd=v.forwardRef(({className:e,...t},n)=>u.jsx(Hs,{ref:n,className:se("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Zd.displayName=Hs.displayName;const Qd=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===Cr||(c==null?void 0:c.displayName)===Cr.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(mb,{children:[u.jsx(Zd,{}),u.jsxs(Us,{ref:r,className:se("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&u.jsx(Cr,{className:"sr-only",children:"Dialog"}),t,u.jsxs(Jd,{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(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Qd.displayName=Us.displayName;const ef=({className:e,...t})=>u.jsx("div",{className:se("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});ef.displayName="DialogHeader";const tf=v.forwardRef(({className:e,...t},n)=>u.jsx(Cr,{ref:n,className:se("text-lg font-semibold leading-none tracking-tight",e),...t}));tf.displayName=Cr.displayName;const gb=v.forwardRef(({className:e,...t},n)=>u.jsx(Ws,{ref:n,className:se("text-sm text-muted-foreground",e),...t}));gb.displayName=Ws.displayName;function xb({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}=Na(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const m=await id(n);l(m)}catch(m){console.error("Failed to load file:",m),d(m instanceof Error?m.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await Hv(n),f({title:"Download started",description:`Downloading ${r}`})}catch(m){console.error("Failed to download file:",m),f({title:"Download failed",description:String(m),variant:"destructive"})}},g=async()=>{if(n)try{const m=await id(n),b=new Blob([m],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(m){console.error("Failed to open file externally:",m),f({title:"Failed to open file",description:String(m),variant:"destructive"})}},x=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(pe.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(lt,{onClick:h,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(pe.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(pe.Image,{className:"h-5 w-5"}):u.jsx(pe.FileText,{className:"h-5 w-5"});return u.jsx(pb,{open:e,onOpenChange:t,children:u.jsxs(Qd,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(ef,{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(tf,{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(lt,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(pe.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(lt,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(pe.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function nf(){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 kr=nf();function yb(e){kr=e}const rf=/[&<>"']/,vb=new RegExp(rf.source,"g"),of=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,wb=new RegExp(of.source,"g"),bb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},sf=e=>bb[e];function Zt(e,t){if(t){if(rf.test(e))return e.replace(vb,sf)}else if(of.test(e))return e.replace(wb,sf);return e}const Sb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function af(e){return e.replace(Sb,(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 Cb=/(^|[^\[])\^/g;function gt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Cb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const kb=/[^\w:]/g,Tb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function lf(e,t,n){if(e){let r;try{r=decodeURIComponent(af(n)).replace(kb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Tb.test(n)&&(n=Ab(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Vs={},Eb=/^[^:]+:\/*[^/]*$/,Ib=/^([^:]+:)[\s\S]*$/,Nb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Ab(e,t){Vs[" "+e]||(Eb.test(e)?Vs[" "+e]=e+"/":Vs[" "+e]=qs(e,"/",!0)),e=Vs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Ib,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Nb,"$1")+t:e+t}const Ks={exec:function(){}};function cf(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 qs(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 _b(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 jb(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 uf(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function df(e,t,n,r){const o=t.href,s=t.title?Zt(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:Zt(i)}}function Rb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
82
+ 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},db="DialogDescriptionWarning",fb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${ef(db).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},tf=zd,hb=Hd,nf=Wd,qs=Vd,Gs=Kd,Ir=Gd,Ys=Xd,rf=Zd;const pb=tf,mb=nf,of=v.forwardRef(({className:e,...t},n)=>u.jsx(qs,{ref:n,className:oe("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}));of.displayName=qs.displayName;const sf=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===Ir||(c==null?void 0:c.displayName)===Ir.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(mb,{children:[u.jsx(of,{}),u.jsxs(Gs,{ref:r,className:oe("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(Ir,{className:"sr-only",children:"Dialog"}),t,u.jsxs(rf,{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(he.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});sf.displayName=Gs.displayName;const af=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});af.displayName="DialogHeader";const lf=v.forwardRef(({className:e,...t},n)=>u.jsx(Ir,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",e),...t}));lf.displayName=Ir.displayName;const gb=v.forwardRef(({className:e,...t},n)=>u.jsx(Ys,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));gb.displayName=Ys.displayName;function xb({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}=Oa(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const m=await fd(n);l(m)}catch(m){console.error("Failed to load file:",m),d(m instanceof Error?m.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await Hv(n),f({title:"Download started",description:`Downloading ${r}`})}catch(m){console.error("Failed to download file:",m),f({title:"Download failed",description:String(m),variant:"destructive"})}},g=async()=>{if(n)try{const m=await fd(n),b=new Blob([m],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(m){console.error("Failed to open file externally:",m),f({title:"Failed to open file",description:String(m),variant:"destructive"})}},x=()=>s?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(he.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(ut,{onClick:h,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(he.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(he.Image,{className:"h-5 w-5"}):u.jsx(he.FileText,{className:"h-5 w-5"});return u.jsx(pb,{open:e,onOpenChange:t,children:u.jsxs(sf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(af,{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(lf,{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(ut,{variant:"outline",size:"sm",onClick:g,className:"flex items-center gap-2",children:[u.jsx(he.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(ut,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[u.jsx(he.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function cf(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Nr=cf();function yb(e){Nr=e}const uf=/[&<>"']/,vb=new RegExp(uf.source,"g"),df=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,wb=new RegExp(df.source,"g"),bb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ff=e=>bb[e];function Qt(e,t){if(t){if(uf.test(e))return e.replace(vb,ff)}else if(df.test(e))return e.replace(wb,ff);return e}const Sb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function hf(e){return e.replace(Sb,(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 Cb=/(^|[^\[])\^/g;function vt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Cb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const kb=/[^\w:]/g,Tb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function pf(e,t,n){if(e){let r;try{r=decodeURIComponent(hf(n)).replace(kb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Tb.test(n)&&(n=Ab(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const Xs={},Eb=/^[^:]+:\/*[^/]*$/,Ib=/^([^:]+:)[\s\S]*$/,Nb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Ab(e,t){Xs[" "+e]||(Eb.test(e)?Xs[" "+e]=e+"/":Xs[" "+e]=Zs(e,"/",!0)),e=Xs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Ib,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Nb,"$1")+t:e+t}const Js={exec:function(){}};function mf(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 Zs(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 _b(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 jb(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 gf(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function xf(e,t,n,r){const o=t.href,s=t.title?Qt(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:Qt(i)}}function Rb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
83
83
  `).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(`
84
- `)}class Va{constructor(t){this.options=t||kr}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:qs(r,`
85
- `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Rb(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=qs(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,h,p,g,x=n[1].trim();const y=x.length>1,m={type:"list",raw:"",ordered:y,start:y?+x.slice(0,-1):"",loose:!1,items:[]};x=y?`\\d{1,9}\\${x.slice(-1)}`:`\\${x}`,this.options.pedantic&&(x=y?x:"[*+-]");const b=new RegExp(`^( {0,3}${x})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(g=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
84
+ `)}class Ja{constructor(t){this.options=t||Nr}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:Zs(r,`
85
+ `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Rb(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=Zs(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,h,p,g,x=n[1].trim();const y=x.length>1,m={type:"list",raw:"",ordered:y,start:y?+x.slice(0,-1):"",loose:!1,items:[]};x=y?`\\d{1,9}\\${x.slice(-1)}`:`\\${x}`,this.options.pedantic&&(x=y?x:"[*+-]");const b=new RegExp(`^( {0,3}${x})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(g=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
86
86
  `,1)[0].replace(/^\t+/,T=>" ".repeat(3*T.length)),f=t.split(`
87
87
  `,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
88
88
  `,t=t.substring(f.length+1),g=!0),!g){const T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),k=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
89
89
  `,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(C.test(f)||E.test(f)||T.test(f)||k.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
90
90
  `+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||C.test(d)||E.test(d)||k.test(d))break;p+=`
91
91
  `+f}!l&&!f.trim()&&(l=!0),r+=h+`
92
- `,t=t.substring(h.length+1),d=f.slice(i)}}m.loose||(c?m.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),m.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),m.raw+=r}m.items[m.items.length-1].raw=r.trimRight(),m.items[m.items.length-1].text=p.trimRight(),m.raw=m.raw.trimRight();const S=m.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,m.items[a].tokens=this.lexer.blockTokens(m.items[a].text,[]),!m.loose){const T=m.items[a].tokens.filter(C=>C.type==="space"),k=T.length>0&&T.some(C=>/\n.*\n/.test(C.raw));m.loose=k}if(m.loose)for(a=0;a<S;a++)m.items[a].loose=!0;return m}}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]):Zt(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:cf(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
93
- `):[]};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]=cf(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)===`
94
- `?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:Zt(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]):Zt(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=qs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=_b(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)),df(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 df(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 h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const g=h.slice(1,-1);return{type:"em",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Zt(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=Zt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Zt(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=Zt(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=Zt(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]):Zt(r[0]):r[0]:o=Zt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const Ee={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:Ks,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Ee._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Ee._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Ee.def=gt(Ee.def).replace("label",Ee._label).replace("title",Ee._title).getRegex(),Ee.bullet=/(?:[*+-]|\d{1,9}[.)])/,Ee.listItemStart=gt(/^( *)(bull) */).replace("bull",Ee.bullet).getRegex(),Ee.list=gt(Ee.list).replace(/bull/g,Ee.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Ee.def.source+")").getRegex(),Ee._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",Ee._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Ee.html=gt(Ee.html,"i").replace("comment",Ee._comment).replace("tag",Ee._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ee.paragraph=gt(Ee._paragraph).replace("hr",Ee.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",Ee._tag).getRegex(),Ee.blockquote=gt(Ee.blockquote).replace("paragraph",Ee.paragraph).getRegex(),Ee.normal={...Ee},Ee.gfm={...Ee.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Ee.gfm.table=gt(Ee.gfm.table).replace("hr",Ee.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",Ee._tag).getRegex(),Ee.gfm.paragraph=gt(Ee._paragraph).replace("hr",Ee.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Ee.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",Ee._tag).getRegex(),Ee.pedantic={...Ee.normal,html:gt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Ee._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:Ks,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:gt(Ee.normal._paragraph).replace("hr",Ee.hr).replace("heading",` *#{1,6} *[^
95
- ]`).replace("lheading",Ee.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const xe={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Ks,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:Ks,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};xe._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",xe.punctuation=gt(xe.punctuation).replace(/punctuation/g,xe._punctuation).getRegex(),xe.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,xe.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,xe._comment=gt(Ee._comment).replace("(?:-->|$)","-->").getRegex(),xe.emStrong.lDelim=gt(xe.emStrong.lDelim).replace(/punct/g,xe._punctuation).getRegex(),xe.emStrong.rDelimAst=gt(xe.emStrong.rDelimAst,"g").replace(/punct/g,xe._punctuation).getRegex(),xe.emStrong.rDelimUnd=gt(xe.emStrong.rDelimUnd,"g").replace(/punct/g,xe._punctuation).getRegex(),xe._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,xe._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,xe._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])?)+(?![-_])/,xe.autolink=gt(xe.autolink).replace("scheme",xe._scheme).replace("email",xe._email).getRegex(),xe._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,xe.tag=gt(xe.tag).replace("comment",xe._comment).replace("attribute",xe._attribute).getRegex(),xe._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,xe._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,xe._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,xe.link=gt(xe.link).replace("label",xe._label).replace("href",xe._href).replace("title",xe._title).getRegex(),xe.reflink=gt(xe.reflink).replace("label",xe._label).replace("ref",Ee._label).getRegex(),xe.nolink=gt(xe.nolink).replace("ref",Ee._label).getRegex(),xe.reflinkSearch=gt(xe.reflinkSearch,"g").replace("reflink",xe.reflink).replace("nolink",xe.nolink).getRegex(),xe.normal={...xe},xe.pedantic={...xe.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:gt(/^!?\[(label)\]\((.*?)\)/).replace("label",xe._label).getRegex(),reflink:gt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",xe._label).getRegex()},xe.gfm={...xe.normal,escape:gt(xe.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},xe.gfm.url=gt(xe.gfm.url,"i").replace("email",xe.gfm._extended_email).getRegex(),xe.breaks={...xe.gfm,br:gt(xe.br).replace("{2,}","*").getRegex(),text:gt(xe.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function Pb(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 ff(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 er{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||kr,this.options.tokenizer=this.options.tokenizer||new Va,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:Ee.normal,inline:xe.normal};this.options.pedantic?(n.block=Ee.pedantic,n.inline=xe.pedantic):this.options.gfm&&(n.block=Ee.gfm,this.options.breaks?n.inline=xe.breaks:n.inline=xe.gfm),this.tokenizer.rules=n}static get rules(){return{block:Ee,inline:xe}}static lex(t,n){return new er(n).lex(t)}static lexInline(t,n){return new er(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
92
+ `,t=t.substring(h.length+1),d=f.slice(i)}}m.loose||(c?m.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),m.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),m.raw+=r}m.items[m.items.length-1].raw=r.trimRight(),m.items[m.items.length-1].text=p.trimRight(),m.raw=m.raw.trimRight();const S=m.items.length;for(a=0;a<S;a++)if(this.lexer.state.top=!1,m.items[a].tokens=this.lexer.blockTokens(m.items[a].text,[]),!m.loose){const T=m.items[a].tokens.filter(C=>C.type==="space"),k=T.length>0&&T.some(C=>/\n.*\n/.test(C.raw));m.loose=k}if(m.loose)for(a=0;a<S;a++)m.items[a].loose=!0;return m}}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]):Qt(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:mf(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
93
+ `):[]};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]=mf(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)===`
94
+ `?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:Qt(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]):Qt(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=Zs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=_b(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)),xf(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 xf(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 h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const g=h.slice(1,-1);return{type:"em",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=Qt(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=Qt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Qt(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=Qt(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=Qt(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]):Qt(r[0]):r[0]:o=Qt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const Te={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:Js,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Te._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Te._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Te.def=vt(Te.def).replace("label",Te._label).replace("title",Te._title).getRegex(),Te.bullet=/(?:[*+-]|\d{1,9}[.)])/,Te.listItemStart=vt(/^( *)(bull) */).replace("bull",Te.bullet).getRegex(),Te.list=vt(Te.list).replace(/bull/g,Te.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Te.def.source+")").getRegex(),Te._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",Te._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Te.html=vt(Te.html,"i").replace("comment",Te._comment).replace("tag",Te._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Te.paragraph=vt(Te._paragraph).replace("hr",Te.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",Te._tag).getRegex(),Te.blockquote=vt(Te.blockquote).replace("paragraph",Te.paragraph).getRegex(),Te.normal={...Te},Te.gfm={...Te.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Te.gfm.table=vt(Te.gfm.table).replace("hr",Te.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",Te._tag).getRegex(),Te.gfm.paragraph=vt(Te._paragraph).replace("hr",Te.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Te.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",Te._tag).getRegex(),Te.pedantic={...Te.normal,html:vt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Te._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Js,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:vt(Te.normal._paragraph).replace("hr",Te.hr).replace("heading",` *#{1,6} *[^
95
+ ]`).replace("lheading",Te.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const me={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Js,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Js,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};me._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",me.punctuation=vt(me.punctuation).replace(/punctuation/g,me._punctuation).getRegex(),me.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,me.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,me._comment=vt(Te._comment).replace("(?:-->|$)","-->").getRegex(),me.emStrong.lDelim=vt(me.emStrong.lDelim).replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimAst=vt(me.emStrong.rDelimAst,"g").replace(/punct/g,me._punctuation).getRegex(),me.emStrong.rDelimUnd=vt(me.emStrong.rDelimUnd,"g").replace(/punct/g,me._punctuation).getRegex(),me._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,me._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,me._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])?)+(?![-_])/,me.autolink=vt(me.autolink).replace("scheme",me._scheme).replace("email",me._email).getRegex(),me._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,me.tag=vt(me.tag).replace("comment",me._comment).replace("attribute",me._attribute).getRegex(),me._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,me._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,me._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,me.link=vt(me.link).replace("label",me._label).replace("href",me._href).replace("title",me._title).getRegex(),me.reflink=vt(me.reflink).replace("label",me._label).replace("ref",Te._label).getRegex(),me.nolink=vt(me.nolink).replace("ref",Te._label).getRegex(),me.reflinkSearch=vt(me.reflinkSearch,"g").replace("reflink",me.reflink).replace("nolink",me.nolink).getRegex(),me.normal={...me},me.pedantic={...me.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:vt(/^!?\[(label)\]\((.*?)\)/).replace("label",me._label).getRegex(),reflink:vt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",me._label).getRegex()},me.gfm={...me.normal,escape:vt(me.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},me.gfm.url=vt(me.gfm.url,"i").replace("email",me.gfm._extended_email).getRegex(),me.breaks={...me.gfm,br:vt(me.br).replace("{2,}","*").getRegex(),text:vt(me.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function Pb(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 yf(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 ir{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Nr,this.options.tokenizer=this.options.tokenizer||new Ja,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:Te.normal,inline:me.normal};this.options.pedantic?(n.block=Te.pedantic,n.inline=me.pedantic):this.options.gfm&&(n.block=Te.gfm,this.options.breaks?n.inline=me.breaks:n.inline=me.gfm),this.tokenizer.rules=n}static get rules(){return{block:Te,inline:me}}static lex(t,n){return new ir(n).lex(t)}static lexInline(t,n){return new ir(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
96
96
  `),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+=`
97
97
  `: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+=`
98
98
  `+r.raw,o.text+=`
@@ -102,9 +102,9 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
102
102
  `+r.raw,o.text+=`
103
103
  `+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+=`
104
104
  `+r.raw,o.text+=`
105
- `+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)+"["+uf("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)+"["+uf("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,ff)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,ff))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,Pb)){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 Ka{constructor(t){this.options=t||kr}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$/,"")+`
106
- `,o?'<pre><code class="'+this.options.langPrefix+Zt(o)+'">'+(r?t:Zt(t,!0))+`</code></pre>
107
- `:"<pre><code>"+(r?t:Zt(t,!0))+`</code></pre>
105
+ `+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)+"["+gf("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)+"["+gf("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,yf)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,yf))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,Pb)){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 Za{constructor(t){this.options=t||Nr}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
106
+ `,o?'<pre><code class="'+this.options.langPrefix+Qt(o)+'">'+(r?t:Qt(t,!0))+`</code></pre>
107
+ `:"<pre><code>"+(r?t:Qt(t,!0))+`</code></pre>
108
108
  `}blockquote(t){return`<blockquote>
109
109
  ${t}</blockquote>
110
110
  `}html(t){return t}heading(t,n,r,o){if(this.options.headerIds){const s=this.options.headerPrefix+o.slug(r);return`<h${n} id="${s}">${t}</h${n}>
@@ -122,11 +122,11 @@ ${t}</blockquote>
122
122
  `}tablerow(t){return`<tr>
123
123
  ${t}</tr>
124
124
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
125
- `}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=lf(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=lf(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 hf{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 pf{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 tr{constructor(t){this.options=t||kr,this.options.renderer=this.options.renderer||new Ka,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new hf,this.slugger=new pf}static parse(t,n){return new tr(n).parse(t)}static parseInline(t,n){return new tr(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,g,x,y,m,b,S,T,k,C;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,af(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(g=p.ordered,x=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,T=b.task,m="",b.task&&(k=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=k+" "+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=k+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:k}):m+=k),m+=this.parse(b.tokens,y),h+=this.renderer.listitem(m,T,S);r+=this.renderer.list(h,g,x);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
126
- `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const R='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(R);return}else throw new Error(R)}}}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 Gs{constructor(t){this.options=t||kr}preprocess(t){return t}postprocess(t){return t}}Fm(Gs,"passThroughHooks",new Set(["preprocess","postprocess"]));function Ob(e,t,n){return r=>{if(r.message+=`
127
- Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Zt(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 mf(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Ie.defaults,...s};const i=Ob(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(jb(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 h;if(!f)try{r.walkTokens&&Ie.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;Ie.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,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(Ie.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&&Ie.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Ie(e,t,n){return mf(er.lex,tr.parse)(e,t,n)}Ie.options=Ie.setOptions=function(e){return Ie.defaults={...Ie.defaults,...e},yb(Ie.defaults),Ie},Ie.getDefaults=nf,Ie.defaults=kr,Ie.use=function(...e){const t=Ie.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Ie.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=Ie.defaults.renderer||new Ka;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=Ie.defaults.tokenizer||new Va;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=Ie.defaults.hooks||new Gs;for(const s in n.hooks){const i=o[s];Gs.passThroughHooks.has(s)?o[s]=a=>{if(Ie.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=Ie.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}}Ie.setOptions(r)})},Ie.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Ie,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Ie.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Ie.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Ie.walkTokens(r.items,t));break}default:Ie.defaults.extensions&&Ie.defaults.extensions.childTokens&&Ie.defaults.extensions.childTokens[r.type]?Ie.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Ie.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Ie.walkTokens(r.tokens,t)))}return n},Ie.parseInline=mf(er.lexInline,tr.parseInline),Ie.Parser=tr,Ie.parser=tr.parse,Ie.Renderer=Ka,Ie.TextRenderer=hf,Ie.Lexer=er,Ie.lexer=er.lex,Ie.Tokenizer=Va,Ie.Slugger=pf,Ie.Hooks=Gs,Ie.parse=Ie,Ie.options,Ie.setOptions,Ie.use,Ie.walkTokens,Ie.parseInline,tr.parse,er.lex;function No({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 Ie.parse(i)}return Ie.parse(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:se("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const Mb="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 Db(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function gf(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function Xs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Lb(e){const t=o=>{try{const s=Eo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
128
- `)):r=t(e),r||""}function $b(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function xf(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 Fb({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:se("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const qa=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,customStyles:h={},onEdit:p,onRegenerate:g,onCancelEdit:x,onCopy:y,activeInterrupt:m,disableInterruptActions:b=!1,onInterruptActionStart:S,onInterruptActionEnd:T,checkpointCandidates:k=[],activeCheckpointId:C=null,onSelectCheckpoint:E,defaultCheckpointId:R=null,messageParentCheckpointId:_=null}){const[j,L]=w.useState(!1),[z,V]=w.useState("preview"),[O,H]=w.useState(!1),{currentThreadId:P}=cs(),{respondToInterrupt:W}=us(),F=l==="phone"||l==="half-screen",$=t.role,ne=$==="tool",oe=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),we=!!oe,Ne=!(r&&$!=="user"),{uploadingFiles:Z,handleFileClick:ie,fileViewerOpen:Te,currentFileInfo:ee,closeFileViewer:D}=Bb({allowFileOpen:Ne,currentThreadId:P}),G=w.useMemo(()=>{switch($){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))]"}},[$]),ae=w.useMemo(()=>oe?"":Db(t.content),[oe,t]),fe=w.useMemo(()=>oe?{}:gf(t),[oe,t]),B=w.useMemo(()=>oe?[]:t.content.filter(X=>X.type==="image_url"),[oe,t]),le=w.useMemo(()=>oe?[]:t.content.filter(X=>X.type==="file"),[oe,t]),Q=w.useMemo(()=>oe?[]:t.content.filter(X=>X.type==="interrupt"),[oe,t]),Ae=(m==null?void 0:m.id)??(m==null?void 0:m.interrupt_id),ve=Xs(Ae),Re=m==null?void 0:m.value,Ve=w.useMemo(()=>oe?"":Lb(t.content),[oe,t]),Qe=w.useCallback(async()=>{const X=ne?Ve:ae;async function Ce(ge){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ge);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const xt=new Blob([ge],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":xt})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Ce(X),L(!0),setTimeout(()=>L(!1),2e3),y==null||y(X)}catch(ge){console.error("Failed to copy:",ge)}},[ne,Ve,ae,y]),et=w.useCallback(()=>{if(!p)return;const X=ne?Ve:ae,Ce="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};p(t.id,X,Ce)},[p,t.id,ne,Ve,ae,t]),Se=w.useCallback(()=>{g==null||g(n)},[g,n]),nt=w.useCallback(()=>{const Ce=se(F?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",G);switch($){case"user":return u.jsx(pe.User,{className:Ce});case"assistant":return u.jsx(pe.Bot,{className:Ce});case"tool":return u.jsx(pe.Wrench,{className:Ce});default:return u.jsx(pe.Bot,{className:Ce})}},[F,G,$]),ut=w.useCallback(()=>{const X="group relative mb-4 flex w-full";switch($){case"user":return se(X,"justify-end");case"assistant":case"tool":case"system":return se(X,"justify-start");default:return X}},[$]),rt=w.useCallback(()=>{const X=se("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",F&&"px-3 py-2 text-sm");if(we)return se(X,"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($){case"user":return se(X,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return se(X,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return se(X,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return se(X,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return se(X,"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")}},[F,we,$]);if(we&&oe)return u.jsx("div",{className:se(ut(),h.container),children:u.jsxs("div",{className:se(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(pe.Bot,{className:se("h-4 w-4",G)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(No,{content:oe.content,className:"text-current"})]})});const Ye=w.useCallback(async X=>{if(b)return;const Ce=Xs((X==null?void 0:X.id)??(X==null?void 0:X.interrupt_id));if(!Ce){console.warn("Interrupt part missing id",X);return}try{S==null||S(),await W(Ce,!0)}catch(ge){console.error("Failed to approve interrupt:",ge)}finally{T==null||T()}},[b,T,S,W]),It=w.useCallback(async X=>{if(b)return;const Ce=Xs((X==null?void 0:X.id)??(X==null?void 0:X.interrupt_id));if(!Ce){console.warn("Interrupt part missing id",X);return}try{S==null||S(),await W(Ce,!1)}catch(ge){console.error("Failed to reject interrupt:",ge)}finally{T==null||T()}},[b,T,S,W]),dt=w.useCallback(({part:X,i:Ce})=>{if(X.type==="text"){const ge=X.text??"",xt=ge.trim(),ft=Aa(xt);return ft&&$!=="tool"?u.jsx(yf,{data:ft},Ce):$==="user"&&c&&xt.length>d?u.jsx(Hb,{text:xt,expanded:O,onExpandedChange:H,previewLength:d,isCompact:F},Ce):u.jsx(No,{content:ge,allowHtml:!1},Ce)}if(X.type==="image_url"){const ge=X;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ge.url,alt:ge.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Ce)}if(X.type==="file"){const ge=X,xt=ge.name||"file";return u.jsxs("a",{href:ge.url,onClick:ft=>ie(ft,ge,Ce),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
129
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Z[Ce]?u.jsx(pe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[xt,Z[Ce]?" (processing)":""]})]},Ce)}if(X.type==="interrupt"){const ge=X,xt=Xs((ge==null?void 0:ge.id)??(ge==null?void 0:ge.interrupt_id)),ft=!!(ve&&xt&&xt===ve),ht=ft?Re??(ge==null?void 0:ge.value):ge==null?void 0:ge.value,Be=xt?{...ge,id:xt,interrupt_id:xt}:ge;return u.jsx(zb,{interruptPart:Be,onApprove:Ye,onReject:It,disabled:b,isActive:ft,payload:ht},Ce)}return null},[ie,Z,Ye,It,$,c,d,O,F,ve,Re,m,b,Q]),kt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(pe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Nt=w.useCallback(()=>{const X=ae.trim().length>0||B.length>0||le.length>0||Q.length>0;if(!ne&&le.length>0&&!r)return kt();if(!ne&&!X&&!r)return null;if(ne)return u.jsx(Ub,{message:t,viewMode:z},t.id);if(!ne&&!oe){const Ce=t,ge=u.jsx("div",{className:"space-y-2",children:Ce.content.map((xt,ft)=>u.jsx(dt,{part:xt,i:ft},ft))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ge,u.jsx(Fb,{className:G})]}):ge}},[ae,B.length,le.length,Q.length,r,ne,z,kt,G]),tt=w.useMemo(()=>oe?"Assistant":$b(t),[oe,t]),He=w.useMemo(()=>oe?[]:Array.isArray(k)?k:[],[k,oe]),Tt=w.useMemo(()=>{var X;return He.length?R&&He.some(Ce=>Ce.id===R)?R:((X=He[0])==null?void 0:X.id)??null:null},[R,He]),zt=w.useMemo(()=>!He.length||!C?null:He.some(X=>X.id===C)?C:null,[C,He])??Tt,Kt=$==="user"&&He.length>0&&typeof E=="function",st=w.useCallback(X=>{if(!E)return;const Ce=(X==null?void 0:X.id)??null,ge=(X==null?void 0:X.parentId)??_??null;E(Ce,ge)},[_,E]),Le=w.useMemo(()=>zt?He.findIndex(X=>X.id===zt):-1,[zt,He]),_t=w.useMemo(()=>Le<0?null:He[Le]??null,[Le,He]),yt=w.useCallback(X=>{const Ce=[];if(X.step!==null&&Ce.push(`Step ${X.step}`),X.source&&Ce.push(X.source),!X.createdAt)return Ce.length?Ce.join(" • "):X.id.slice(0,8);let ge="";try{const ft=new Date(X.createdAt);Number.isNaN(ft.getTime())||(ge=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ft))}catch{ge=""}const xt=Ce.length?` • ${Ce.join(" • ")}`:"";return`${ge||X.id.slice(0,8)}${xt}`},[]);return ne&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:se(ut(),h.container),children:u.jsxs("div",{className:se(rt(),h.content),children:[(i||a||ne)&&u.jsxs("div",{className:se("flex items-center justify-between mb-2 pb-2 border-b border-current/10",F&&"mb-1 pb-1",G,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[nt(),a&&tt&&u.jsx("span",{className:se("font-medium",F?"text-xs":"text-sm"),children:tt}),ne&&u.jsxs(td,{variant:"outline",className:se("text-xs flex items-center gap-1 cursor-pointer select-none",G,"border border-current/40",F&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":z==="expanded",onClick:()=>V(X=>X==="expanded"?"preview":"expanded"),onKeyDown:X=>{(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),V(Ce=>Ce==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:fe.name??"Tool Output"}),fe.toolCallId&&u.jsx("span",{className:"opacity-70",children:fe.toolCallId.slice(0,8)}),z==="expanded"?u.jsx(pe.ChevronUp,{className:"h-3 w-3"}):u.jsx(pe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Kt&&_t&&Le>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:se("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Le>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Le<=0)return;const X=He[Le-1];X&&st(X)},"aria-label":"Previous checkpoint",disabled:Le<=0,children:u.jsx(pe.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[Le+1," / ",He.length]}),u.jsx("span",{className:"text-muted-foreground",children:yt(_t)})]}),u.jsx("button",{type:"button",className:se("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Le<He.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Le>=He.length-1)return;const X=He[Le+1];X&&st(X)},"aria-label":"Next checkpoint",disabled:Le>=He.length-1,children:u.jsx(pe.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:se("text-xs opacity-60",G,F&&"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:se("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:se("h-6 w-6 p-0 hover:bg-foreground/10",G,F&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(pe.Copy,{className:se(j?"text-success":G,F?"h-3 w-3":"h-4 w-4")})})}),$==="user"&&p&&u.jsx(lt,{variant:"ghost",size:"sm",onClick:et,className:se("h-6 w-6 p-0 hover:bg-foreground/10",G,F&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(pe.Edit,{className:se(G,F?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&g&&u.jsx(lt,{variant:"ghost",size:"sm",onClick:Se,className:se("h-6 w-6 p-0 hover:bg-foreground/10",G,F&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(pe.RotateCcw,{className:se(G,F?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:Nt()}),ne&&z==="expanded"&&(fe.toolCallId||fe.name)&&u.jsxs("div",{className:se("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",F&&"text-xs"),children:[fe.name&&u.jsxs("div",{children:["Function: ",fe.name]}),fe.toolCallId&&u.jsxs("div",{children:["Call ID: ",fe.toolCallId]})]}),!(i||a||ne)&&s&&!o&&u.jsxs("div",{className:se("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",F&&"h-5 w-5"),children:u.jsx(pe.Copy,{className:se(j?"text-success":"text-current",F?"h-3 w-3":"h-4 w-4")})}),$==="user"&&p&&u.jsx(lt,{variant:"ghost",size:"sm",onClick:et,className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",F&&"h-5 w-5"),children:u.jsx(pe.Edit,{className:se("text-current",F?"h-3 w-3":"h-4 w-4")})}),$==="assistant"&&g&&u.jsx(lt,{variant:"ghost",size:"sm",onClick:Se,className:se("h-6 w-6 p-0 hover:bg-background/50 text-current",F&&"h-5 w-5"),children:u.jsx(pe.RotateCcw,{className:se("text-current",F?"h-3 w-3":"h-4 w-4")})})]})]})}),ee&&u.jsx(xb,{isOpen:Te,onClose:D,fileId:ee.id,fileName:ee.name,mimeType:ee.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&xf(e.message)===xf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(g=>e[g]===t[g]),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)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function yf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:Mb,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Io(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Io(e)})}function zb({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=Io(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(bo,{className:se("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(So,{className:"pb-3",children:[u.jsx(Co,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(nd,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(ko,{className:"pt-0 pb-3",children:a}),u.jsx(rd,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(lt,{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(lt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function Bb(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Na(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,g,x)=>{var y,m;if(!t){p.preventDefault();return}if(o[x]){p.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=g.name||`file_${T}`,C=g.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(b.startsWith("data:")){p.preventDefault(),s(k=>({...k,[x]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Uv(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const C=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:g.name||C.filename||`file_${C.id}`,mimeType:g.mimeType||C.mime_type||"application/octet-stream"}),(y=T.update)==null||y.call(T,{id:T.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(m=T.update)==null||m.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[x]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function Hb({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:se("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(No,{content:e,allowHtml:!1}):u.jsxs("pre",{className:se("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(lt,{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(pe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(pe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function Ub({message:e,viewMode:t}){const r=gf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Aa(c)??c:c;if(d&&typeof d=="object")return u.jsx(yf,{data:d});const f=typeof d=="string"?d:(()=>{try{return Io(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=Vv(c);return f?u.jsx(No,{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(pe.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=Is(d);return s(f)}const a=Eo(i),l=Is(a);return s(l)}const vf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Wb=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Ga=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:h,emptyMessage:p,followNewMessages:g=!0,isNavigatingCheckpoint:x=!1,onScrollAway:y,onAtBottom:m,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:R,activeCheckpointId:_,onSelectCheckpoint:j},L)=>{const z=w.useRef(null),V=w.useRef(null),O=w.useRef(!1),[H,P]=w.useState(!0),W=w.useMemo(()=>b?e.some(B=>"type"in B&&B.type==="default_message"?!1:Array.isArray(B==null?void 0:B.content)&&B.content.some(le=>le&&le.type==="interrupt"&&(le.id??le.interrupt_id)===b.id)):!1,[b,e]),F=w.useMemo(()=>{if(!b||W)return null;const B=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let le;const Q=b.value;if(Q&&typeof Q=="object"&&!Array.isArray(Q)){const Ae=Q.title;typeof Ae=="string"&&Ae.trim()&&(le=Ae.trim())}return{id:`interrupt-${B}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:B,value:Q,title:le}]}},[b,W]),$=w.useMemo(()=>F?[...e,F]:e,[e,F]),ne=w.useMemo(()=>C?$:$.filter(B=>(B==null?void 0:B.role)!=="tool"),[$,C]),oe=w.useMemo(()=>{const B=new Set,le=[];for(let Q=ne.length-1;Q>=0;Q--){const Ae=ne[Q];if(!Ae)continue;if("type"in Ae&&Ae.type==="default_message"){le.push(Ae);continue}const ve=Ae,Re=Wb(ve);B.has(Re)||(B.add(Re),le.push(ve))}return le.reverse()},[ne]),we=w.useCallback(B=>{P(B),y&&y(!B),m&&m(B)},[y,m]),Ne=w.useMemo(()=>{if(a)return async()=>{if(!O.current){O.current=!0;try{await a()}finally{O.current=!1}}}},[a]),Z=w.useMemo(()=>!g||x?!1:H?"auto":!1,[H,g,x]),ie=w.useMemo(()=>{if(!E||E.size===0)return[];const B=Array.from(E.values()).filter(le=>!!(le!=null&&le.id));return B.length?B.sort((le,Q)=>{const Ae=typeof le.step=="number"?le.step:Number.MAX_SAFE_INTEGER,ve=typeof Q.step=="number"?Q.step:Number.MAX_SAFE_INTEGER;if(Ae!==ve)return Ae-ve;const Re=le.createdAt?Date.parse(le.createdAt):Number.MAX_VALUE,Ve=Q.createdAt?Date.parse(Q.createdAt):Number.MAX_VALUE;return Re-Ve}):[]},[E]),Te=w.useMemo(()=>_||(ie.length?ie[ie.length-1].id:null),[_,ie]),ee=w.useCallback(B=>{if(!B)return null;const le=Date.parse(B);if(Number.isNaN(le))return null;try{return new Date(le).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return null}},[]),D=w.useMemo(()=>{if(!ie.length)return null;const B=ie[0],le=ie[ie.length-1],Q=[B==null?void 0:B.createdAt,le==null?void 0:le.createdAt].map(ve=>ve?ee(ve):null).filter(Boolean).join(" → "),Ae=ve=>{j&&j(ve)};return u.jsx("div",{className:"absolute inset-y-0 left-0 hidden w-[15rem] border-r border-border/50 bg-gradient-to-b from-background/95 to-background/70 md:flex",children:u.jsxs("div",{className:"flex h-full w-full flex-col px-4 py-4",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Timeline"}),u.jsxs("div",{className:"mt-1 text-[11px] text-muted-foreground",children:[ie.length," step",ie.length===1?"":"s"]}),Q&&u.jsx("div",{className:"mt-3 text-[10px] uppercase tracking-wider text-muted-foreground/80",children:Q})]}),u.jsx("div",{className:"mt-4 space-y-2 overflow-y-auto pr-1",children:ie.map(ve=>{const Re=[];ve.source&&Re.push(ve.source);const Ve=ee(ve.createdAt);Ve&&Re.push(Ve),ve.namespace&&Re.push(ve.namespace);const Qe=Te===ve.id,et=typeof ve.step=="number"?`Step ${ve.step}`:ve.source??"Checkpoint";return u.jsxs("button",{type:"button",onClick:()=>Ae(ve.id),disabled:!j,className:`w-full rounded-md border px-3 py-2 text-left text-xs transition ${Qe?"border-primary bg-primary/10 text-primary":"border-border/60 bg-muted/40 text-foreground hover:border-foreground/60"} ${j?"":"cursor-default opacity-70"}`,children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsx("span",{className:"font-semibold",children:et}),ve.parentId&&u.jsx("span",{className:"text-[10px] text-muted-foreground/80",children:"↩︎"})]}),Re.length>0&&u.jsx("div",{className:"mt-1 text-[11px] leading-tight text-muted-foreground",children:Re.join(" • ")})]},ve.id)})}),j&&u.jsx("button",{type:"button",onClick:()=>Ae(null),className:"mt-3 rounded-md border border-border/70 px-3 py-2 text-left text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Return to latest"})]})})},[Te,ee,j,ie]),G=ie.length>0,ae=w.useMemo(()=>{if(typeof p!="string")return null;const B=p.trim();return B?{id:"default-message",role:"assistant",type:"default_message",content:B,createdAt:new Date().toISOString()}:null},[p]);if(oe.length===0)return ae?u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"p-6 overflow-y-auto h-full flex items-start justify-center",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(qa,{message:ae,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})})}):u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:p||"No messages yet. Start a conversation!"})});const fe=["flex h-full flex-col",G?"md:pl-0":"",f].filter(Boolean).join(" ");return u.jsx("div",{className:fe,style:h,children:u.jsxs("div",{className:"relative flex-1 min-h-0",children:[D,u.jsx(bv,{ref:B=>{z.current=B},scrollerRef:B=>{V.current=B instanceof HTMLDivElement?B:null},data:oe,followOutput:Z,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{Ne&&Ne()},atBottomStateChange:we,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(B,le)=>vf(le,B),itemContent:(B,le)=>{var dt;const Q=vf(le,B),Ae="type"in le&&le.type==="default_message";let ve=[],Re=null,Ve={},Qe={},et=null,Se=null,nt=null;if(!Ae){const kt=le,Nt=kt.checkpointId??null;Ve=kt.additionalKwargs??{},Qe=kt.responseMetadata??{};const tt=Nt&&E?E.get(Nt)??null:null;et=typeof Ve.step=="number"?Ve.step:typeof Qe.step=="number"?Qe.step:(tt==null?void 0:tt.step)??null;const He=typeof Ve.source=="string"?Ve.source:typeof Qe.source=="string"?Qe.source:(tt==null?void 0:tt.source)??null;Se=He?String(He):null,nt=(tt==null?void 0:tt.namespace)??null;const Tt=et!==null&&Se?`${et}:${Se}`:null;Tt&&(R!=null&&R.has(Tt))?ve=R.get(Tt)??[]:Nt&&tt&&(ve=[tt]),Re=Nt??((dt=ve[0])==null?void 0:dt.id)??null}const ut=(()=>{if(typeof Ve.parentCheckpointId=="string")return Ve.parentCheckpointId;if(typeof Qe.parentCheckpointId=="string")return Qe.parentCheckpointId})(),rt=Se||(typeof et=="number"?`Step ${et}`:null)||nt||null,Ye=Re,It=G&&Ye&&Te===Ye;return u.jsxs("div",{className:`relative mb-4 last:mb-0 ${G?"md:pl-[15rem]":""}`,"data-message-id":Q,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:[G&&u.jsx("div",{className:"pointer-events-none absolute left-0 top-1 hidden h-full w-[15rem] items-start md:flex",children:u.jsxs("div",{className:"flex items-start gap-3 pt-3",children:[u.jsx("span",{className:"mt-2 h-px w-10 bg-border/50"}),u.jsxs("div",{className:"pointer-events-auto flex flex-col gap-1",children:[u.jsx("button",{type:"button",disabled:!Ye||!j,onClick:()=>Ye&&(j==null?void 0:j(Ye)),className:`flex h-6 w-6 items-center justify-center rounded-full border transition ${It?"border-primary bg-primary/10 text-primary":"border-border/70 bg-background text-muted-foreground hover:border-foreground/60"} ${j?"":"cursor-default opacity-80"}`,children:u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"})}),rt&&u.jsx("div",{className:"text-[11px] leading-tight text-muted-foreground",children:rt})]})]})}),u.jsx(qa,{message:le,messageIndex:B,isStreamingMessage:t&&n===le.id,streamingDebounceMs:r,isEditing:i===le.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(B),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C,checkpointCandidates:ve,activeCheckpointId:_??null,onSelectCheckpoint:j,defaultCheckpointId:Re,messageParentCheckpointId:ut})]})}})]})})});Ga.displayName="MessageList";const Ys=1e4;function Vb(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,`
125
+ `}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=pf(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=pf(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 vf{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 wf{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 ar{constructor(t){this.options=t||Nr,this.options.renderer=this.options.renderer||new Za,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new vf,this.slugger=new wf}static parse(t,n){return new ar(n).parse(t)}static parseInline(t,n){return new ar(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,g,x,y,m,b,S,T,k,C;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,hf(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(g=p.ordered,x=p.start,y=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,T=b.task,m="",b.task&&(k=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=k+" "+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=k+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:k}):m+=k),m+=this.parse(b.tokens,y),h+=this.renderer.listitem(m,T,S);r+=this.renderer.list(h,g,x);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
126
+ `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const R='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(R);return}else throw new Error(R)}}}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 Qs{constructor(t){this.options=t||Nr}preprocess(t){return t}postprocess(t){return t}}$m(Qs,"passThroughHooks",new Set(["preprocess","postprocess"]));function Ob(e,t,n){return r=>{if(r.message+=`
127
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Qt(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 bf(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Ee.defaults,...s};const i=Ob(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(jb(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 h;if(!f)try{r.walkTokens&&Ee.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;Ee.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,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(Ee.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&&Ee.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Ee(e,t,n){return bf(ir.lex,ar.parse)(e,t,n)}Ee.options=Ee.setOptions=function(e){return Ee.defaults={...Ee.defaults,...e},yb(Ee.defaults),Ee},Ee.getDefaults=cf,Ee.defaults=Nr,Ee.use=function(...e){const t=Ee.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Ee.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=Ee.defaults.renderer||new Za;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=Ee.defaults.tokenizer||new Ja;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=Ee.defaults.hooks||new Qs;for(const s in n.hooks){const i=o[s];Qs.passThroughHooks.has(s)?o[s]=a=>{if(Ee.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=Ee.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}}Ee.setOptions(r)})},Ee.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Ee,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Ee.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Ee.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Ee.walkTokens(r.items,t));break}default:Ee.defaults.extensions&&Ee.defaults.extensions.childTokens&&Ee.defaults.extensions.childTokens[r.type]?Ee.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Ee.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Ee.walkTokens(r.tokens,t)))}return n},Ee.parseInline=bf(ir.lexInline,ar.parseInline),Ee.Parser=ar,Ee.parser=ar.parse,Ee.Renderer=Za,Ee.TextRenderer=vf,Ee.Lexer=ir,Ee.lexer=ir.lex,Ee.Tokenizer=Ja,Ee.Slugger=wf,Ee.Hooks=Qs,Ee.parse=Ee,Ee.options,Ee.setOptions,Ee.use,Ee.walkTokens,Ee.parseInline,ar.parse,ir.lex;function Ro({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 Ee.parse(i)}return Ee.parse(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:oe("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 Mb="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 Db(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Sf(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 ei(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Lb(e){const t=o=>{try{const s=_o(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
128
+ `)):r=t(e),r||""}function Fb(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Cf(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 $b({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:oe("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Qa=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,customStyles:h={},onEdit:p,onRegenerate:g,onCancelEdit:x,onCopy:y,activeInterrupt:m,disableInterruptActions:b=!1,onInterruptActionStart:S,onInterruptActionEnd:T,checkpointCandidates:k=[],activeCheckpointId:C=null,onSelectCheckpoint:E,defaultCheckpointId:R=null,messageParentCheckpointId:_=null}){const[j,D]=w.useState(!1),[z,W]=w.useState("preview"),[O,B]=w.useState(!1),{currentThreadId:P}=ps(),{respondToInterrupt:V}=ms(),$=l==="phone"||l==="half-screen",F=t.role,ee=F==="tool",te=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ve=!!te,Ie=!(r&&F!=="user"),{uploadingFiles:Z,handleFileClick:de,fileViewerOpen:we,currentFileInfo:ne,closeFileViewer:L}=Bb({allowFileOpen:Ie,currentThreadId:P}),J=w.useMemo(()=>{switch(F){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))]"}},[F]),se=w.useMemo(()=>te?"":Db(t.content),[te,t]),ue=w.useMemo(()=>te?{}:Sf(t),[te,t]),le=w.useMemo(()=>te?[]:t.content.filter(q=>q.type==="image_url"),[te,t]),Me=w.useMemo(()=>te?[]:t.content.filter(q=>q.type==="file"),[te,t]),U=w.useMemo(()=>te?[]:t.content.filter(q=>q.type==="interrupt"),[te,t]),ye=(m==null?void 0:m.id)??(m==null?void 0:m.interrupt_id),_e=ei(ye),Pe=m==null?void 0:m.value,et=w.useMemo(()=>te?"":Lb(t.content),[te,t]),nt=w.useCallback(async()=>{const q=ee?et:se;async function ke(xe){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(xe);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ot=new Blob([xe],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ot})]);return}throw new Error("Clipboard API not supported in this context.")}try{await ke(q),D(!0),setTimeout(()=>D(!1),2e3),y==null||y(q)}catch(xe){console.error("Failed to copy:",xe)}},[ee,et,se,y]),Ze=w.useCallback(()=>{if(!p)return;const q=ee?et:se,ke="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};p(t.id,q,ke)},[p,t.id,ee,et,se,t]),be=w.useCallback(()=>{g==null||g(n)},[g,n]),Qe=w.useCallback(()=>{const ke=oe($?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",J);switch(F){case"user":return u.jsx(he.User,{className:ke});case"assistant":return u.jsx(he.Bot,{className:ke});case"tool":return u.jsx(he.Wrench,{className:ke});default:return u.jsx(he.Bot,{className:ke})}},[$,J,F]),it=w.useCallback(()=>{const q="group relative mb-4 flex w-full";switch(F){case"user":return oe(q,"justify-end");case"assistant":case"tool":case"system":return oe(q,"justify-start");default:return q}},[F]),rt=w.useCallback(()=>{const q=oe("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",$&&"px-3 py-2 text-sm");if(ve)return oe(q,"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(F){case"user":return oe(q,"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 oe(q,"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 oe(q,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return oe(q,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return oe(q,"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")}},[$,ve,F]);if(ve&&te)return u.jsx("div",{className:oe(it(),h.container),children:u.jsxs("div",{className:oe(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(he.Bot,{className:oe("h-4 w-4",J)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Ro,{content:te.content,className:"text-current"})]})});const Be=w.useCallback(async q=>{if(b)return;const ke=ei((q==null?void 0:q.id)??(q==null?void 0:q.interrupt_id));if(!ke){console.warn("Interrupt part missing id",q);return}try{S==null||S(),await V(ke,!0)}catch(xe){console.error("Failed to approve interrupt:",xe)}finally{T==null||T()}},[b,T,S,V]),wt=w.useCallback(async q=>{if(b)return;const ke=ei((q==null?void 0:q.id)??(q==null?void 0:q.interrupt_id));if(!ke){console.warn("Interrupt part missing id",q);return}try{S==null||S(),await V(ke,!1)}catch(xe){console.error("Failed to reject interrupt:",xe)}finally{T==null||T()}},[b,T,S,V]),mt=w.useCallback(({part:q,i:ke})=>{if(q.type==="text"){const xe=q.text??"",ot=xe.trim(),ft=Ma(ot);return ft&&F!=="tool"?u.jsx(kf,{data:ft},ke):F==="user"&&c&&ot.length>d?u.jsx(Hb,{text:ot,expanded:O,onExpandedChange:B,previewLength:d,isCompact:$},ke):u.jsx(Ro,{content:xe,allowHtml:!1},ke)}if(q.type==="image_url"){const xe=q;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:xe.url,alt:xe.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},ke)}if(q.type==="file"){const xe=q,ot=xe.name||"file";return u.jsxs("a",{href:xe.url,onClick:ft=>de(ft,xe,ke),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
129
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Z[ke]?u.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ot,Z[ke]?" (processing)":""]})]},ke)}if(q.type==="interrupt"){const xe=q,ot=ei((xe==null?void 0:xe.id)??(xe==null?void 0:xe.interrupt_id)),ft=!!(_e&&ot&&ot===_e),tt=ft?Pe??(xe==null?void 0:xe.value):xe==null?void 0:xe.value,Fe=ot?{...xe,id:ot,interrupt_id:ot}:xe;return u.jsx(zb,{interruptPart:Fe,onApprove:Be,onReject:wt,disabled:b,isActive:ft,payload:tt},ke)}return null},[de,Z,Be,wt,F,c,d,O,$,_e,Pe,m,b,U]),jt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Dt=w.useCallback(()=>{const q=se.trim().length>0||le.length>0||Me.length>0||U.length>0;if(!ee&&Me.length>0&&!r)return jt();if(!ee&&!q&&!r)return null;if(ee)return u.jsx(Ub,{message:t,viewMode:z},t.id);if(!ee&&!te){const ke=t,xe=u.jsx("div",{className:"space-y-2",children:ke.content.map((ot,ft)=>u.jsx(mt,{part:ot,i:ft},ft))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[xe,u.jsx($b,{className:J})]}):xe}},[se,le.length,Me.length,U.length,r,ee,z,jt,J]),bt=w.useMemo(()=>te?"Assistant":Fb(t),[te,t]),He=w.useMemo(()=>te?[]:Array.isArray(k)?k:[],[k,te]),St=w.useMemo(()=>{var q;return He.length?R&&He.some(ke=>ke.id===R)?R:((q=He[0])==null?void 0:q.id)??null:null},[R,He]),Lt=w.useMemo(()=>!He.length||!C?null:He.some(q=>q.id===C)?C:null,[C,He])??St,Ft=F==="user"&&He.length>0&&typeof E=="function",at=w.useCallback(q=>{if(!E)return;const ke=(q==null?void 0:q.id)??null,xe=(q==null?void 0:q.parentId)??_??null;E(ke,xe)},[_,E]),De=w.useMemo(()=>Lt?He.findIndex(q=>q.id===Lt):-1,[Lt,He]),Rt=w.useMemo(()=>De<0?null:He[De]??null,[De,He]),kt=w.useCallback(q=>{const ke=[];if(q.step!==null&&ke.push(`Step ${q.step}`),q.source&&ke.push(q.source),!q.createdAt)return ke.length?ke.join(" • "):q.id.slice(0,8);let xe="";try{const ft=new Date(q.createdAt);Number.isNaN(ft.getTime())||(xe=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ft))}catch{xe=""}const ot=ke.length?` • ${ke.join(" • ")}`:"";return`${xe||q.id.slice(0,8)}${ot}`},[]);return ee&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:oe(it(),h.container),children:u.jsxs("div",{className:oe(rt(),h.content),children:[(i||a||ee)&&u.jsxs("div",{className:oe("flex items-center justify-between mb-2 pb-2 border-b border-current/10",$&&"mb-1 pb-1",J,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Qe(),a&&bt&&u.jsx("span",{className:oe("font-medium",$?"text-xs":"text-sm"),children:bt}),ee&&u.jsxs(ad,{variant:"outline",className:oe("text-xs flex items-center gap-1 cursor-pointer select-none",J,"border border-current/40",$&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":z==="expanded",onClick:()=>W(q=>q==="expanded"?"preview":"expanded"),onKeyDown:q=>{(q.key==="Enter"||q.key===" ")&&(q.preventDefault(),W(ke=>ke==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ue.name??"Tool Output"}),ue.toolCallId&&u.jsx("span",{className:"opacity-70",children:ue.toolCallId.slice(0,8)}),z==="expanded"?u.jsx(he.ChevronUp,{className:"h-3 w-3"}):u.jsx(he.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ft&&Rt&&De>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",De>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(De<=0)return;const q=He[De-1];q&&at(q)},"aria-label":"Previous checkpoint",disabled:De<=0,children:u.jsx(he.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[De+1," / ",He.length]}),u.jsx("span",{className:"text-muted-foreground",children:kt(Rt)})]}),u.jsx("button",{type:"button",className:oe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",De<He.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(De>=He.length-1)return;const q=He[De+1];q&&at(q)},"aria-label":"Next checkpoint",disabled:De>=He.length-1,children:u.jsx(he.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:oe("text-xs opacity-60",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:oe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>nt(),className:oe("h-6 w-6 p-0 hover:bg-foreground/10",J,$&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(he.Copy,{className:oe(j?"text-success":J,$?"h-3 w-3":"h-4 w-4")})})}),F==="user"&&p&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:Ze,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",J,$&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(he.Edit,{className:oe(J,$?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&g&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:be,className:oe("h-6 w-6 p-0 hover:bg-foreground/10",J,$&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(he.RotateCcw,{className:oe(J,$?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:Dt()}),ee&&z==="expanded"&&(ue.toolCallId||ue.name)&&u.jsxs("div",{className:oe("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",$&&"text-xs"),children:[ue.name&&u.jsxs("div",{children:["Function: ",ue.name]}),ue.toolCallId&&u.jsxs("div",{children:["Call ID: ",ue.toolCallId]})]}),!(i||a||ee)&&s&&!o&&u.jsxs("div",{className:oe("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>nt(),className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",$&&"h-5 w-5"),children:u.jsx(he.Copy,{className:oe(j?"text-success":"text-current",$?"h-3 w-3":"h-4 w-4")})}),F==="user"&&p&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:Ze,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",$&&"h-5 w-5"),children:u.jsx(he.Edit,{className:oe("text-current",$?"h-3 w-3":"h-4 w-4")})}),F==="assistant"&&g&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:be,className:oe("h-6 w-6 p-0 hover:bg-background/50 text-current",$&&"h-5 w-5"),children:u.jsx(he.RotateCcw,{className:oe("text-current",$?"h-3 w-3":"h-4 w-4")})})]})]})}),ne&&u.jsx(xb,{isOpen:we,onClose:L,fileId:ne.id,fileName:ne.name,mimeType:ne.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Cf(e.message)===Cf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(g=>e[g]===t[g]),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)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function kf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:Mb,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:jo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:jo(e)})}function zb({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=jo(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(To,{className:oe("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(Eo,{className:"pb-3",children:[u.jsx(Io,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(ld,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(No,{className:"pt-0 pb-3",children:a}),u.jsx(cd,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(ut,{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(ut,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function Bb(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Oa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,g,x)=>{var y,m;if(!t){p.preventDefault();return}if(o[x]){p.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=g.name||`file_${T}`,C=g.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(b.startsWith("data:")){p.preventDefault(),s(k=>({...k,[x]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Uv(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const C=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:g.name||C.filename||`file_${C.id}`,mimeType:g.mimeType||C.mime_type||"application/octet-stream"}),(y=T.update)==null||y.call(T,{id:T.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(m=T.update)==null||m.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[x]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function Hb({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:oe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(Ro,{content:e,allowHtml:!1}):u.jsxs("pre",{className:oe("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(ut,{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(he.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(he.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function Ub({message:e,viewMode:t}){const r=Sf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ma(c)??c:c;if(d&&typeof d=="object")return u.jsx(kf,{data:d});const f=typeof d=="string"?d:(()=>{try{return jo(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}=Vv(c);return f?u.jsx(Ro,{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(he.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=Rs(d);return s(f)}const a=_o(i),l=Rs(a);return s(l)}const Tf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Wb=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},el=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:h,emptyMessage:p,followNewMessages:g=!0,isNavigatingCheckpoint:x=!1,onScrollAway:y,onAtBottom:m,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:R,activeCheckpointId:_,onSelectCheckpoint:j,timelineCheckpoints:D},z)=>{const W=w.useRef(null),O=w.useRef(null),B=w.useRef(!1),[P,V]=w.useState(!0),$=w.useMemo(()=>b?e.some(U=>"type"in U&&U.type==="default_message"?!1:Array.isArray(U==null?void 0:U.content)&&U.content.some(ye=>ye&&ye.type==="interrupt"&&(ye.id??ye.interrupt_id)===b.id)):!1,[b,e]),F=w.useMemo(()=>{if(!b||$)return null;const U=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let ye;const _e=b.value;if(_e&&typeof _e=="object"&&!Array.isArray(_e)){const Pe=_e.title;typeof Pe=="string"&&Pe.trim()&&(ye=Pe.trim())}return{id:`interrupt-${U}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:U,value:_e,title:ye}]}},[b,$]),ee=w.useMemo(()=>F?[...e,F]:e,[e,F]),te=w.useMemo(()=>C?ee:ee.filter(U=>(U==null?void 0:U.role)!=="tool"),[ee,C]),ve=w.useMemo(()=>{const U=new Set,ye=[];for(let _e=te.length-1;_e>=0;_e--){const Pe=te[_e];if(!Pe)continue;if("type"in Pe&&Pe.type==="default_message"){ye.push(Pe);continue}const et=Pe,nt=Wb(et);U.has(nt)||(U.add(nt),ye.push(et))}return ye.reverse()},[te]),Ie=w.useCallback(U=>{V(U),y&&y(!U),m&&m(U)},[y,m]),Z=w.useMemo(()=>{if(a)return async()=>{if(!B.current){B.current=!0;try{await a()}finally{B.current=!1}}}},[a]),de=w.useMemo(()=>!g||x?!1:P?"auto":!1,[P,g,x]),we=w.useMemo(()=>D??[],[D]),ne=w.useMemo(()=>{const U=new Map;return we.forEach(ye=>{ye.messageId&&U.set(ye.messageId,ye)}),U},[we]),L=w.useMemo(()=>{const U=new Map;return we.forEach(ye=>{U.set(ye.id,ye)}),U},[we]),J=_??(we.length?we[we.length-1].id:null),se=we.length>0,ue=se?u.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-5 hidden md:block",children:u.jsx("span",{className:"block h-full w-px bg-border/50"})}):null,le=w.useMemo(()=>{if(typeof p!="string")return null;const U=p.trim();return U?{id:"default-message",role:"assistant",type:"default_message",content:U,createdAt:new Date().toISOString()}:null},[p]);if(ve.length===0)return le?u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"p-6 overflow-y-auto h-full flex items-start justify-center",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Qa,{message:le,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})})}):u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:p||"No messages yet. Start a conversation!"})});const Me=["flex h-full flex-col",se?"md:pl-[15rem]":"",f].filter(Boolean).join(" ");return u.jsx("div",{className:Me,style:h,children:u.jsxs("div",{className:"relative flex-1 min-h-0",children:[ue,u.jsx(bv,{ref:U=>{W.current=U},scrollerRef:U=>{O.current=U instanceof HTMLDivElement?U:null},data:ve,followOutput:de,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{Z&&Z()},atBottomStateChange:Ie,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(U,ye)=>Tf(ye,U),itemContent:(U,ye)=>{var bt;const _e=Tf(ye,U),Pe="type"in ye&&ye.type==="default_message";let et=[],nt=null,Ze={},be={},Qe=null,it=null;if(!Pe){const He=ye,St=He.checkpointId??null;Ze=He.additionalKwargs??{},be=He.responseMetadata??{};const Ct=St&&E?E.get(St)??null:null;Qe=typeof Ze.step=="number"?Ze.step:typeof be.step=="number"?be.step:(Ct==null?void 0:Ct.step)??null;const Lt=typeof Ze.source=="string"?Ze.source:typeof be.source=="string"?be.source:(Ct==null?void 0:Ct.source)??null;it=Lt?String(Lt):null;const Ft=Qe!==null&&it?`${Qe}:${it}`:null;Ft&&(R!=null&&R.has(Ft))?et=R.get(Ft)??[]:St&&Ct&&(et=[Ct]),nt=St??((bt=et[0])==null?void 0:bt.id)??null}const rt=(()=>{if(typeof Ze.parentCheckpointId=="string")return Ze.parentCheckpointId;if(typeof be.parentCheckpointId=="string")return be.parentCheckpointId})(),Be=!Pe&&ne.get(ye.id)||(nt?L.get(nt)??null:null),wt=(Be==null?void 0:Be.id)??null,mt=(Be==null?void 0:Be.label)??null,jt=se&&Be&&J===Be.id,Dt=se&&!!Be;return u.jsxs("div",{className:"relative mb-4 last:mb-0","data-message-id":_e,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:[Dt&&u.jsx("div",{className:"pointer-events-none absolute left-0 top-1 hidden h-full w-[15rem] items-start md:flex",children:u.jsxs("div",{className:"flex items-start gap-3 pt-3",children:[u.jsx("span",{className:"mt-2 h-px w-10 bg-border/50"}),u.jsxs("div",{className:"pointer-events-auto flex flex-col gap-1",children:[u.jsx("button",{type:"button",disabled:!wt||!j,onClick:()=>wt&&(j==null?void 0:j(wt)),className:`flex h-6 w-6 items-center justify-center rounded-full border transition ${jt?"border-primary bg-primary/10 text-primary":"border-border/70 bg-background text-muted-foreground hover:border-foreground/60"} ${j?"":"cursor-default opacity-80"}`,children:u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"})}),mt&&u.jsx("div",{className:"text-[11px] leading-tight text-muted-foreground",children:mt})]})]})}),u.jsx(Qa,{message:ye,messageIndex:U,isStreamingMessage:t&&n===ye.id,streamingDebounceMs:r,isEditing:i===ye.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(U),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C,checkpointCandidates:et,activeCheckpointId:_??null,onSelectCheckpoint:j,defaultCheckpointId:nt,messageParentCheckpointId:rt})]})}})]})})});el.displayName="MessageList";const ti=1e4;function Vb(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,`
130
130
  `).replace(/<p>(.*?)<\/p>/gi,`$1
131
131
 
132
132
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
@@ -134,4 +134,4 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
134
134
  `).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
135
135
  `).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
136
136
  `).replace(/<li>(.*?)<\/li>/gi,`- $1
137
- `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function Kb(e,t=Ys){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 qb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Kb(t),Vb(t)}function Xa(e){const t=e+"CollectionProvider",[n,r]=Hn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:y,children:m}=x,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:m})};i.displayName=t;const a=e+"CollectionSlot",l=hr.createSlot(a),c=w.forwardRef((x,y)=>{const{scope:m,children:b}=x,S=s(a,m),T=Ze(y,S.collectionRef);return u.jsx(l,{ref:T,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=hr.createSlot(d),p=w.forwardRef((x,y)=>{const{scope:m,children:b,...S}=x,T=w.useRef(null),k=Ze(y,T),C=s(d,m);return w.useEffect(()=>(C.itemMap.set(T,{ref:T,...S}),()=>void C.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:b})});p.displayName=d;function g(x){const y=s(e+"CollectionConsumer",x);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((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},g,r]}var Gb=v.createContext(void 0);function Js(e){const t=v.useContext(Gb);return e||t||"ltr"}const Xb=["top","right","bottom","left"],nr=Math.min,un=Math.max,Zs=Math.round,Qs=Math.floor,On=e=>({x:e,y:e}),Yb={left:"right",right:"left",bottom:"top",top:"bottom"},Jb={start:"end",end:"start"};function Ya(e,t,n){return un(e,nr(t,n))}function Wn(e,t){return typeof e=="function"?e(t):e}function Vn(e){return e.split("-")[0]}function Kr(e){return e.split("-")[1]}function Ja(e){return e==="x"?"y":"x"}function Za(e){return e==="y"?"height":"width"}const Zb=new Set(["top","bottom"]);function Mn(e){return Zb.has(Vn(e))?"y":"x"}function Qa(e){return Ja(Mn(e))}function Qb(e,t,n){n===void 0&&(n=!1);const r=Kr(e),o=Qa(e),s=Za(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=ei(i)),[i,ei(i)]}function e0(e){const t=ei(e);return[el(e),t,el(t)]}function el(e){return e.replace(/start|end/g,t=>Jb[t])}const wf=["left","right"],bf=["right","left"],t0=["top","bottom"],n0=["bottom","top"];function r0(e,t,n){switch(e){case"top":case"bottom":return n?t?bf:wf:t?wf:bf;case"left":case"right":return t?t0:n0;default:return[]}}function o0(e,t,n,r){const o=Kr(e);let s=r0(Vn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(el)))),s}function ei(e){return e.replace(/left|right|bottom|top/g,t=>Yb[t])}function s0(e){return{top:0,right:0,bottom:0,left:0,...e}}function Sf(e){return typeof e!="number"?s0(e):{top:e,right:e,bottom:e,left:e}}function ti(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 Cf(e,t,n){let{reference:r,floating:o}=e;const s=Mn(t),i=Qa(t),a=Za(i),l=Vn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Kr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const i0=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}=Cf(c,r,l),h=r,p={},g=0;for(let x=0;x<a.length;x++){const{name:y,fn:m}=a[x],{x:b,y:S,data:T,reset:k}=await m({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[y]:{...p[y],...T}},k&&g<=50&&(g++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(c=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=Cf(c,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Ao(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:h=!1,padding:p=0}=Wn(t,e),g=Sf(p),y=a[h?f==="floating"?"reference":"floating":f],m=ti(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)),T=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},k=ti(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(m.top-k.top+g.top)/T.y,bottom:(k.bottom-m.bottom+g.bottom)/T.y,left:(m.left-k.left+g.left)/T.x,right:(k.right-m.right+g.right)/T.x}}const a0=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}=Wn(e,t)||{};if(c==null)return{};const f=Sf(d),h={x:n,y:r},p=Qa(o),g=Za(p),x=await i.getDimensions(c),y=p==="y",m=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",T=s.reference[g]+s.reference[p]-h[p]-s.floating[g],k=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[g]);const R=T/2-k/2,_=E/2-x[g]/2-1,j=nr(f[m],_),L=nr(f[b],_),z=j,V=E-x[g]-L,O=E/2-x[g]/2+R,H=Ya(z,O,V),P=!l.arrow&&Kr(o)!=null&&O!==H&&s.reference[g]/2-(O<z?j:L)-x[g]/2<0,W=P?O<z?O-z:O-V:0;return{[p]:h[p]+W,data:{[p]:H,centerOffset:O-H-W,...P&&{alignmentOffset:W}},reset:P}}}),l0=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:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:x=!0,...y}=Wn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const m=Vn(o),b=Mn(a),S=Vn(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(S||!x?[ei(a)]:e0(a)),C=g!=="none";!h&&C&&k.push(...o0(a,x,g,T));const E=[a,...k],R=await Ao(t,y),_=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(R[m]),f){const O=Qb(o,i,T);_.push(R[O[0]],R[O[1]])}if(j=[...j,{placement:o,overflows:_}],!_.every(O=>O<=0)){var L,z;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,H=E[O];if(H&&(!(f==="alignment"?b!==Mn(H):!1)||j.every(F=>Mn(F.placement)===b?F.overflows[0]>0:!0)))return{data:{index:O,overflows:j},reset:{placement:H}};let P=(z=j.filter(W=>W.overflows[0]<=0).sort((W,F)=>W.overflows[1]-F.overflows[1])[0])==null?void 0:z.placement;if(!P)switch(p){case"bestFit":{var V;const W=(V=j.filter(F=>{if(C){const $=Mn(F.placement);return $===b||$==="y"}return!0}).map(F=>[F.placement,F.overflows.filter($=>$>0).reduce(($,ne)=>$+ne,0)]).sort((F,$)=>F[1]-$[1])[0])==null?void 0:V[0];W&&(P=W);break}case"initialPlacement":P=a;break}if(o!==P)return{reset:{placement:P}}}return{}}}};function kf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Tf(e){return Xb.some(t=>e[t]>=0)}const c0=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Wn(e,t);switch(r){case"referenceHidden":{const s=await Ao(t,{...o,elementContext:"reference"}),i=kf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Tf(i)}}}case"escaped":{const s=await Ao(t,{...o,altBoundary:!0}),i=kf(s,n.floating);return{data:{escapedOffsets:i,escaped:Tf(i)}}}default:return{}}}}},Ef=new Set(["left","top"]);async function u0(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Vn(n),a=Kr(n),l=Mn(n)==="y",c=Ef.has(i)?-1:1,d=s&&l?-1:1,f=Wn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const d0=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 u0(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}}}}},f0=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:m,y:b}=y;return{x:m,y:b}}},...l}=Wn(e,t),c={x:n,y:r},d=await Ao(t,l),f=Mn(Vn(o)),h=Ja(f);let p=c[h],g=c[f];if(s){const y=h==="y"?"top":"left",m=h==="y"?"bottom":"right",b=p+d[y],S=p-d[m];p=Ya(b,p,S)}if(i){const y=f==="y"?"top":"left",m=f==="y"?"bottom":"right",b=g+d[y],S=g-d[m];g=Ya(b,g,S)}const x=a.fn({...t,[h]:p,[f]:g});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},h0=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}=Wn(e,t),d={x:n,y:r},f=Mn(o),h=Ja(f);let p=d[h],g=d[f];const x=Wn(a,t),y=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",T=s.reference[h]-s.floating[S]+y.mainAxis,k=s.reference[h]+s.reference[S]-y.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var m,b;const S=h==="y"?"width":"height",T=Ef.has(Vn(o)),k=s.reference[f]-s.floating[S]+(T&&((m=i.offset)==null?void 0:m[f])||0)+(T?0:y.crossAxis),C=s.reference[f]+s.reference[S]+(T?0:((b=i.offset)==null?void 0:b[f])||0)-(T?y.crossAxis:0);g<k?g=k:g>C&&(g=C)}return{[h]:p,[f]:g}}}},p0=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}=Wn(e,t),d=await Ao(t,c),f=Vn(o),h=Kr(o),p=Mn(o)==="y",{width:g,height:x}=s.floating;let y,m;f==="top"||f==="bottom"?(y=f,m=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(m=f,y=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=g-d.left-d.right,T=nr(x-d[y],b),k=nr(g-d[m],S),C=!t.middlewareData.shift;let E=T,R=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(R=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),C&&!h){const j=un(d.left,0),L=un(d.right,0),z=un(d.top,0),V=un(d.bottom,0);p?R=g-2*(j!==0||L!==0?j+L:un(d.left,d.right)):E=x-2*(z!==0||V!==0?z+V:un(d.top,d.bottom))}await l({...t,availableWidth:R,availableHeight:E});const _=await i.getDimensions(a.floating);return g!==_.width||x!==_.height?{reset:{rects:!0}}:{}}}};function ni(){return typeof window<"u"}function qr(e){return If(e)?(e.nodeName||"").toLowerCase():"#document"}function dn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Dn(e){var t;return(t=(If(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function If(e){return ni()?e instanceof Node||e instanceof dn(e).Node:!1}function En(e){return ni()?e instanceof Element||e instanceof dn(e).Element:!1}function Ln(e){return ni()?e instanceof HTMLElement||e instanceof dn(e).HTMLElement:!1}function Nf(e){return!ni()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof dn(e).ShadowRoot}const m0=new Set(["inline","contents"]);function _o(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=In(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!m0.has(o)}const g0=new Set(["table","td","th"]);function x0(e){return g0.has(qr(e))}const y0=[":popover-open",":modal"];function ri(e){return y0.some(t=>{try{return e.matches(t)}catch{return!1}})}const v0=["transform","translate","scale","rotate","perspective"],w0=["transform","translate","scale","rotate","perspective","filter"],b0=["paint","layout","strict","content"];function tl(e){const t=nl(),n=En(e)?In(e):e;return v0.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)||w0.some(r=>(n.willChange||"").includes(r))||b0.some(r=>(n.contain||"").includes(r))}function S0(e){let t=rr(e);for(;Ln(t)&&!Gr(t);){if(tl(t))return t;if(ri(t))return null;t=rr(t)}return null}function nl(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const C0=new Set(["html","body","#document"]);function Gr(e){return C0.has(qr(e))}function In(e){return dn(e).getComputedStyle(e)}function oi(e){return En(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function rr(e){if(qr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Nf(e)&&e.host||Dn(e);return Nf(t)?t.host:t}function Af(e){const t=rr(e);return Gr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Ln(t)&&_o(t)?t:Af(t)}function jo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Af(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=dn(o);if(s){const a=rl(i);return t.concat(i,i.visualViewport||[],_o(o)?o:[],a&&n?jo(a):[])}return t.concat(o,jo(o,[],n))}function rl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function _f(e){const t=In(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Ln(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Zs(n)!==s||Zs(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ol(e){return En(e)?e:e.contextElement}function Xr(e){const t=ol(e);if(!Ln(t))return On(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=_f(t);let i=(s?Zs(n.width):n.width)/r,a=(s?Zs(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const k0=On(0);function jf(e){const t=dn(e);return!nl()||!t.visualViewport?k0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function T0(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==dn(e)?!1:t}function Tr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ol(e);let i=On(1);t&&(r?En(r)&&(i=Xr(r)):i=Xr(e));const a=T0(s,n,r)?jf(s):On(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 h=dn(s),p=r&&En(r)?dn(r):r;let g=h,x=rl(g);for(;x&&r&&p!==g;){const y=Xr(x),m=x.getBoundingClientRect(),b=In(x),S=m.left+(x.clientLeft+parseFloat(b.paddingLeft))*y.x,T=m.top+(x.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=T,g=dn(x),x=rl(g)}}return ti({width:d,height:f,x:l,y:c})}function si(e,t){const n=oi(e).scrollLeft;return t?t.left+n:Tr(Dn(e)).left+n}function Rf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-si(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function E0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Dn(r),a=t?ri(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=On(1);const d=On(0),f=Ln(r);if((f||!f&&!s)&&((qr(r)!=="body"||_o(i))&&(l=oi(r)),Ln(r))){const p=Tr(r);c=Xr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Rf(i,l):On(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function I0(e){return Array.from(e.getClientRects())}function N0(e){const t=Dn(e),n=oi(e),r=e.ownerDocument.body,o=un(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=un(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+si(e);const a=-n.scrollTop;return In(r).direction==="rtl"&&(i+=un(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Pf=25;function A0(e,t){const n=dn(e),r=Dn(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=nl();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=si(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,g=Math.abs(r.clientWidth-f.clientWidth-p);g<=Pf&&(s-=g)}else c<=Pf&&(s+=c);return{width:s,height:i,x:a,y:l}}const _0=new Set(["absolute","fixed"]);function j0(e,t){const n=Tr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Ln(e)?Xr(e):On(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 Of(e,t,n){let r;if(t==="viewport")r=A0(e,n);else if(t==="document")r=N0(Dn(e));else if(En(t))r=j0(t,n);else{const o=jf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ti(r)}function Mf(e,t){const n=rr(e);return n===t||!En(n)||Gr(n)?!1:In(n).position==="fixed"||Mf(n,t)}function R0(e,t){const n=t.get(e);if(n)return n;let r=jo(e,[],!1).filter(a=>En(a)&&qr(a)!=="body"),o=null;const s=In(e).position==="fixed";let i=s?rr(e):e;for(;En(i)&&!Gr(i);){const a=In(i),l=tl(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&_0.has(o.position)||_o(i)&&!l&&Mf(e,i))?r=r.filter(d=>d!==i):o=a,i=rr(i)}return t.set(e,r),r}function P0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?ri(t)?[]:R0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=Of(t,d,o);return c.top=un(f.top,c.top),c.right=nr(f.right,c.right),c.bottom=nr(f.bottom,c.bottom),c.left=un(f.left,c.left),c},Of(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function O0(e){const{width:t,height:n}=_f(e);return{width:t,height:n}}function M0(e,t,n){const r=Ln(t),o=Dn(t),s=n==="fixed",i=Tr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=On(0);function c(){l.x=si(o)}if(r||!r&&!s)if((qr(t)!=="body"||_o(o))&&(a=oi(t)),r){const p=Tr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Rf(o,a):On(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function sl(e){return In(e).position==="static"}function Df(e,t){if(!Ln(e)||In(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Dn(e)===n&&(n=n.ownerDocument.body),n}function Lf(e,t){const n=dn(e);if(ri(e))return n;if(!Ln(e)){let o=rr(e);for(;o&&!Gr(o);){if(En(o)&&!sl(o))return o;o=rr(o)}return n}let r=Df(e,t);for(;r&&x0(r)&&sl(r);)r=Df(r,t);return r&&Gr(r)&&sl(r)&&!tl(r)?n:r||S0(e)||n}const D0=async function(e){const t=this.getOffsetParent||Lf,n=this.getDimensions,r=await n(e.floating);return{reference:M0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function L0(e){return In(e).direction==="rtl"}const $0={convertOffsetParentRelativeRectToViewportRelativeRect:E0,getDocumentElement:Dn,getClippingRect:P0,getOffsetParent:Lf,getElementRects:D0,getClientRects:I0,getDimensions:O0,getScale:Xr,isElement:En,isRTL:L0};function $f(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function F0(e,t){let n=null,r;const o=Dn(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:h,height:p}=c;if(a||t(),!h||!p)return;const g=Qs(f),x=Qs(o.clientWidth-(d+h)),y=Qs(o.clientHeight-(f+p)),m=Qs(d),S={rootMargin:-g+"px "+-x+"px "+-y+"px "+-m+"px",threshold:un(0,nr(1,l))||1};let T=!0;function k(C){const E=C[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!$f(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,S)}n.observe(e)}return i(!0),s}function z0(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=ol(e),d=o||s?[...c?jo(c):[],...jo(t)]:[];d.forEach(m=>{o&&m.addEventListener("scroll",n,{passive:!0}),s&&m.addEventListener("resize",n)});const f=c&&a?F0(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(m=>{let[b]=m;b&&b.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let g,x=l?Tr(e):null;l&&y();function y(){const m=Tr(e);x&&!$f(x,m)&&n(),x=m,g=requestAnimationFrame(y)}return n(),()=>{var m;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(m=p)==null||m.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const B0=d0,H0=f0,U0=l0,W0=p0,V0=c0,Ff=a0,K0=h0,q0=(e,t,n)=>{const r=new Map,o={platform:$0,...n},s={...o.platform,_c:r};return i0(e,t,{...o,platform:s})};var G0=typeof document<"u",X0=function(){},ii=G0?w.useLayoutEffect:X0;function ai(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(!ai(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)&&!ai(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function zf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Bf(e,t){const n=zf(e);return Math.round(t*n)/n}function il(e){const t=v.useRef(e);return ii(()=>{t.current=e}),t}function Y0(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}),[h,p]=v.useState(r);ai(h,r)||p(r);const[g,x]=v.useState(null),[y,m]=v.useState(null),b=v.useCallback(F=>{F!==C.current&&(C.current=F,x(F))},[]),S=v.useCallback(F=>{F!==E.current&&(E.current=F,m(F))},[]),T=s||g,k=i||y,C=v.useRef(null),E=v.useRef(null),R=v.useRef(d),_=l!=null,j=il(l),L=il(o),z=il(c),V=v.useCallback(()=>{if(!C.current||!E.current)return;const F={placement:t,strategy:n,middleware:h};L.current&&(F.platform=L.current),q0(C.current,E.current,F).then($=>{const ne={...$,isPositioned:z.current!==!1};O.current&&!ai(R.current,ne)&&(R.current=ne,Wo.flushSync(()=>{f(ne)}))})},[h,t,n,L,z]);ii(()=>{c===!1&&R.current.isPositioned&&(R.current.isPositioned=!1,f(F=>({...F,isPositioned:!1})))},[c]);const O=v.useRef(!1);ii(()=>(O.current=!0,()=>{O.current=!1}),[]),ii(()=>{if(T&&(C.current=T),k&&(E.current=k),T&&k){if(j.current)return j.current(T,k,V);V()}},[T,k,V,j,_]);const H=v.useMemo(()=>({reference:C,floating:E,setReference:b,setFloating:S}),[b,S]),P=v.useMemo(()=>({reference:T,floating:k}),[T,k]),W=v.useMemo(()=>{const F={position:n,left:0,top:0};if(!P.floating)return F;const $=Bf(P.floating,d.x),ne=Bf(P.floating,d.y);return a?{...F,transform:"translate("+$+"px, "+ne+"px)",...zf(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:ne}},[n,a,P.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:V,refs:H,elements:P,floatingStyles:W}),[d,V,H,P,W])}const J0=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?Ff({element:r.current,padding:o}).fn(n):{}:r?Ff({element:r,padding:o}).fn(n):{}}}},Z0=(e,t)=>({...B0(e),options:[e,t]}),Q0=(e,t)=>({...H0(e),options:[e,t]}),eS=(e,t)=>({...K0(e),options:[e,t]}),tS=(e,t)=>({...U0(e),options:[e,t]}),nS=(e,t)=>({...W0(e),options:[e,t]}),rS=(e,t)=>({...V0(e),options:[e,t]}),oS=(e,t)=>({...J0(e),options:[e,t]});var sS="Arrow",Hf=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(De.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"})})});Hf.displayName=sS;var iS=Hf;function Uf(e){const[t,n]=v.useState(void 0);return Ut(()=>{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 al="Popper",[Wf,li]=Hn(al),[aS,Vf]=Wf(al),Kf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(aS,{scope:t,anchor:r,onAnchorChange:o,children:n})};Kf.displayName=al;var qf="PopperAnchor",Gf=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Vf(qf,n),i=v.useRef(null),a=Ze(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(De.div,{...o,ref:a})});Gf.displayName=qf;var ll="PopperContent",[lS,cS]=Wf(ll),Xf=v.forwardRef((e,t)=>{var ee,D,G,ae,fe,B;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:h=!1,updatePositionStrategy:p="optimized",onPlaced:g,...x}=e,y=Vf(ll,n),[m,b]=v.useState(null),S=Ze(t,le=>b(le)),[T,k]=v.useState(null),C=Uf(T),E=(C==null?void 0:C.width)??0,R=(C==null?void 0:C.height)??0,_=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},L=Array.isArray(c)?c:[c],z=L.length>0,V={padding:j,boundary:L.filter(dS),altBoundary:z},{refs:O,floatingStyles:H,placement:P,isPositioned:W,middlewareData:F}=Y0({strategy:"fixed",placement:_,whileElementsMounted:(...le)=>z0(...le,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[Z0({mainAxis:o+R,alignmentAxis:i}),l&&Q0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?eS():void 0,...V}),l&&tS({...V}),nS({...V,apply:({elements:le,rects:Q,availableWidth:Ae,availableHeight:ve})=>{const{width:Re,height:Ve}=Q.reference,Qe=le.floating.style;Qe.setProperty("--radix-popper-available-width",`${Ae}px`),Qe.setProperty("--radix-popper-available-height",`${ve}px`),Qe.setProperty("--radix-popper-anchor-width",`${Re}px`),Qe.setProperty("--radix-popper-anchor-height",`${Ve}px`)}}),T&&oS({element:T,padding:a}),fS({arrowWidth:E,arrowHeight:R}),h&&rS({strategy:"referenceHidden",...V})]}),[$,ne]=Zf(P),oe=Wt(g);Ut(()=>{W&&(oe==null||oe())},[W,oe]);const we=(ee=F.arrow)==null?void 0:ee.x,Ne=(D=F.arrow)==null?void 0:D.y,Z=((G=F.arrow)==null?void 0:G.centerOffset)!==0,[ie,Te]=v.useState();return Ut(()=>{m&&Te(window.getComputedStyle(m).zIndex)},[m]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...H,transform:W?H.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ie,"--radix-popper-transform-origin":[(ae=F.transformOrigin)==null?void 0:ae.x,(fe=F.transformOrigin)==null?void 0:fe.y].join(" "),...((B=F.hide)==null?void 0:B.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(lS,{scope:n,placedSide:$,onArrowChange:k,arrowX:we,arrowY:Ne,shouldHideArrow:Z,children:u.jsx(De.div,{"data-side":$,"data-align":ne,...x,ref:S,style:{...x.style,animation:W?void 0:"none"}})})})});Xf.displayName=ll;var Yf="PopperArrow",uS={top:"bottom",right:"left",bottom:"top",left:"right"},Jf=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=cS(Yf,r),i=uS[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(iS,{...o,ref:n,style:{...o.style,display:"block"}})})});Jf.displayName=Yf;function dS(e){return e!==null}var fS=e=>({name:"transformOrigin",options:e,fn(t){var y,m,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]=Zf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((m=o.arrow)==null?void 0:m.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let g="",x="";return c==="bottom"?(g=i?f:`${h}px`,x=`${-l}px`):c==="top"?(g=i?f:`${h}px`,x=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,x=i?f:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:g,y:x}}}});function Zf(e){const[t,n="center"]=e.split("-");return[t,n]}var Qf=Kf,eh=Gf,th=Xf,nh=Jf,cl="rovingFocusGroup.onEntryFocus",hS={bubbles:!1,cancelable:!0},Ro="RovingFocusGroup",[ul,rh,pS]=Xa(Ro),[mS,oh]=Hn(Ro,[pS]),[gS,xS]=mS(Ro),sh=v.forwardRef((e,t)=>u.jsx(ul.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(ul.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(yS,{...e,ref:t})})}));sh.displayName=Ro;var yS=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,h=v.useRef(null),p=Ze(t,h),g=Js(s),[x,y]=Br({prop:i,defaultProp:a??null,onChange:l,caller:Ro}),[m,b]=v.useState(!1),S=Wt(c),T=rh(n),k=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const R=h.current;if(R)return R.addEventListener(cl,S),()=>R.removeEventListener(cl,S)},[S]),u.jsx(gS,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:x,onItemFocus:v.useCallback(R=>y(R),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(R=>R+1),[]),onFocusableItemRemove:v.useCallback(()=>E(R=>R-1),[]),children:u.jsx(De.div,{tabIndex:m||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ye(e.onMouseDown,()=>{k.current=!0}),onFocus:ye(e.onFocus,R=>{const _=!k.current;if(R.target===R.currentTarget&&_&&!m){const j=new CustomEvent(cl,hS);if(R.currentTarget.dispatchEvent(j),!j.defaultPrevented){const L=T().filter(P=>P.focusable),z=L.find(P=>P.active),V=L.find(P=>P.id===x),H=[z,V,...L].filter(Boolean).map(P=>P.ref.current);lh(H,d)}}k.current=!1}),onBlur:ye(e.onBlur,()=>b(!1))})})}),ih="RovingFocusGroupItem",ah=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Un(),c=s||l,d=xS(ih,n),f=d.currentTabStopId===c,h=rh(n),{onFocusableItemAdd:p,onFocusableItemRemove:g,currentTabStopId:x}=d;return v.useEffect(()=>{if(r)return p(),()=>g()},[r,p,g]),u.jsx(ul.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(De.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ye(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ye(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ye(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const m=bS(y,d.orientation,d.dir);if(m!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=h().filter(T=>T.focusable).map(T=>T.ref.current);if(m==="last")S.reverse();else if(m==="prev"||m==="next"){m==="prev"&&S.reverse();const T=S.indexOf(y.currentTarget);S=d.loop?SS(S,T+1):S.slice(T+1)}setTimeout(()=>lh(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});ah.displayName=ih;var vS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function bS(e,t,n){const r=wS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return vS[r]}function lh(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function SS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var CS=sh,kS=ah,dl=["Enter"," "],TS=["ArrowDown","PageUp","Home"],ch=["ArrowUp","PageDown","End"],ES=[...TS,...ch],IS={ltr:[...dl,"ArrowRight"],rtl:[...dl,"ArrowLeft"]},NS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Po="Menu",[Oo,AS,_S]=Xa(Po),[Er,uh]=Hn(Po,[_S,li,oh]),ci=li(),dh=oh(),[jS,Ir]=Er(Po),[RS,Mo]=Er(Po),fh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ci(t),[l,c]=v.useState(null),d=v.useRef(!1),f=Wt(s),h=Js(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(Qf,{...a,children:u.jsx(jS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(RS,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};fh.displayName=Po;var PS="MenuAnchor",fl=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ci(n);return u.jsx(eh,{...o,...r,ref:t})});fl.displayName=PS;var hl="MenuPortal",[OS,hh]=Er(hl,{forceMount:void 0}),ph=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Ir(hl,t);return u.jsx(OS,{scope:t,forceMount:n,children:u.jsx(gn,{present:n||s.open,children:u.jsx(_s,{asChild:!0,container:o,children:r})})})};ph.displayName=hl;var xn="MenuContent",[MS,pl]=Er(xn),mh=v.forwardRef((e,t)=>{const n=hh(xn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Ir(xn,e.__scopeMenu),i=Mo(xn,e.__scopeMenu);return u.jsx(Oo.Provider,{scope:e.__scopeMenu,children:u.jsx(gn,{present:r||s.open,children:u.jsx(Oo.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(DS,{...o,ref:t}):u.jsx(LS,{...o,ref:t})})})})}),DS=v.forwardRef((e,t)=>{const n=Ir(xn,e.__scopeMenu),r=v.useRef(null),o=Ze(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Ba(s)},[]),u.jsx(ml,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ye(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),LS=v.forwardRef((e,t)=>{const n=Ir(xn,e.__scopeMenu);return u.jsx(ml,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),$S=hr.createSlot("MenuContent.ScrollLock"),ml=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:h,onDismiss:p,disableOutsideScroll:g,...x}=e,y=Ir(xn,n),m=Mo(xn,n),b=ci(n),S=dh(n),T=AS(n),[k,C]=v.useState(null),E=v.useRef(null),R=Ze(t,E,y.onContentChange),_=v.useRef(0),j=v.useRef(""),L=v.useRef(0),z=v.useRef(null),V=v.useRef("right"),O=v.useRef(0),H=g?Ls:v.Fragment,P=g?{as:$S,allowPinchZoom:!0}:void 0,W=$=>{var ee,D;const ne=j.current+$,oe=T().filter(G=>!G.disabled),we=document.activeElement,Ne=(ee=oe.find(G=>G.ref.current===we))==null?void 0:ee.textValue,Z=oe.map(G=>G.textValue),ie=YS(Z,ne,Ne),Te=(D=oe.find(G=>G.textValue===ie))==null?void 0:D.ref.current;(function G(ae){j.current=ae,window.clearTimeout(_.current),ae!==""&&(_.current=window.setTimeout(()=>G(""),1e3))})(ne),Te&&setTimeout(()=>Te.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),Ma();const F=v.useCallback($=>{var oe,we;return V.current===((oe=z.current)==null?void 0:oe.side)&&ZS($,(we=z.current)==null?void 0:we.area)},[]);return u.jsx(MS,{scope:n,searchRef:j,onItemEnter:v.useCallback($=>{F($)&&$.preventDefault()},[F]),onItemLeave:v.useCallback($=>{var ne;F($)||((ne=E.current)==null||ne.focus(),C(null))},[F]),onTriggerLeave:v.useCallback($=>{F($)&&$.preventDefault()},[F]),pointerGraceTimerRef:L,onPointerGraceIntentChange:v.useCallback($=>{z.current=$},[]),children:u.jsx(H,{...P,children:u.jsx(As,{asChild:!0,trapped:o,onMountAutoFocus:ye(s,$=>{var ne;$.preventDefault(),(ne=E.current)==null||ne.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Ns,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(CS,{asChild:!0,...S,dir:m.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:ye(l,$=>{m.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(th,{role:"menu","aria-orientation":"vertical","data-state":Rh(y.open),"data-radix-menu-content":"",dir:m.dir,...b,...x,ref:R,style:{outline:"none",...x.style},onKeyDown:ye(x.onKeyDown,$=>{const oe=$.target.closest("[data-radix-menu-content]")===$.currentTarget,we=$.ctrlKey||$.altKey||$.metaKey,Ne=$.key.length===1;oe&&($.key==="Tab"&&$.preventDefault(),!we&&Ne&&W($.key));const Z=E.current;if($.target!==Z||!ES.includes($.key))return;$.preventDefault();const Te=T().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);ch.includes($.key)&&Te.reverse(),GS(Te)}),onBlur:ye(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(_.current),j.current="")}),onPointerMove:ye(e.onPointerMove,Lo($=>{const ne=$.target,oe=O.current!==$.clientX;if($.currentTarget.contains(ne)&&oe){const we=$.clientX>O.current?"right":"left";V.current=we,O.current=$.clientX}}))})})})})})})});mh.displayName=xn;var FS="MenuGroup",gl=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"group",...r,ref:t})});gl.displayName=FS;var zS="MenuLabel",gh=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{...r,ref:t})});gh.displayName=zS;var ui="MenuItem",xh="menu.itemSelect",di=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=Mo(ui,e.__scopeMenu),a=pl(ui,e.__scopeMenu),l=Ze(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(xh,{bubbles:!0,cancelable:!0});f.addEventListener(xh,p=>r==null?void 0:r(p),{once:!0}),cd(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(yh,{...o,ref:l,disabled:n,onClick:ye(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ye(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ye(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||dl.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});di.displayName=ui;var yh=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=pl(ui,n),a=dh(n),l=v.useRef(null),c=Ze(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const g=l.current;g&&p((g.textContent??"").trim())},[s.children]),u.jsx(Oo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(kS,{asChild:!0,...a,focusable:!r,children:u.jsx(De.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ye(e.onPointerMove,Lo(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ye(e.onPointerLeave,Lo(g=>i.onItemLeave(g))),onFocus:ye(e.onFocus,()=>f(!0)),onBlur:ye(e.onBlur,()=>f(!1))})})})}),BS="MenuCheckboxItem",vh=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(kh,{scope:e.__scopeMenu,checked:n,children:u.jsx(di,{role:"menuitemcheckbox","aria-checked":fi(n)?"mixed":n,...o,ref:t,"data-state":yl(n),onSelect:ye(o.onSelect,()=>r==null?void 0:r(fi(n)?!0:!n),{checkForDefaultPrevented:!1})})})});vh.displayName=BS;var wh="MenuRadioGroup",[HS,US]=Er(wh,{value:void 0,onValueChange:()=>{}}),bh=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Wt(r);return u.jsx(HS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(gl,{...o,ref:t})})});bh.displayName=wh;var Sh="MenuRadioItem",Ch=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=US(Sh,e.__scopeMenu),s=n===o.value;return u.jsx(kh,{scope:e.__scopeMenu,checked:s,children:u.jsx(di,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":yl(s),onSelect:ye(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Ch.displayName=Sh;var xl="MenuItemIndicator",[kh,WS]=Er(xl,{checked:!1}),Th=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=WS(xl,n);return u.jsx(gn,{present:r||fi(s.checked)||s.checked===!0,children:u.jsx(De.span,{...o,ref:t,"data-state":yl(s.checked)})})});Th.displayName=xl;var VS="MenuSeparator",Eh=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(De.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Eh.displayName=VS;var KS="MenuArrow",Ih=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ci(n);return u.jsx(nh,{...o,...r,ref:t})});Ih.displayName=KS;var qS="MenuSub",[jT,Nh]=Er(qS),Do="MenuSubTrigger",Ah=v.forwardRef((e,t)=>{const n=Ir(Do,e.__scopeMenu),r=Mo(Do,e.__scopeMenu),o=Nh(Do,e.__scopeMenu),s=pl(Do,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(fl,{asChild:!0,...c,children:u.jsx(yh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Rh(n.open),...e,ref:_a(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ye(e.onPointerMove,Lo(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:ye(e.onPointerLeave,Lo(f=>{var p,g;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(g=n.content)==null?void 0:g.dataset.side,y=x==="right",m=y?-5:5,b=h[y?"left":"right"],S=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+m,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ye(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||IS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Ah.displayName=Do;var _h="MenuSubContent",jh=v.forwardRef((e,t)=>{const n=hh(xn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Ir(xn,e.__scopeMenu),i=Mo(xn,e.__scopeMenu),a=Nh(_h,e.__scopeMenu),l=v.useRef(null),c=Ze(t,l);return u.jsx(Oo.Provider,{scope:e.__scopeMenu,children:u.jsx(gn,{present:r||s.open,children:u.jsx(Oo.Slot,{scope:e.__scopeMenu,children:u.jsx(ml,{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:ye(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ye(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ye(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=NS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});jh.displayName=_h;function Rh(e){return e?"open":"closed"}function fi(e){return e==="indeterminate"}function yl(e){return fi(e)?"indeterminate":e?"checked":"unchecked"}function GS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function XS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function YS(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=XS(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 JS(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,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function ZS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return JS(n,t)}function Lo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var QS=fh,eC=fl,tC=ph,nC=mh,rC=gl,oC=gh,sC=di,iC=vh,aC=bh,lC=Ch,cC=Th,uC=Eh,dC=Ih,fC=Ah,hC=jh,hi="DropdownMenu",[pC,RT]=Hn(hi,[uh]),tn=uh(),[mC,Ph]=pC(hi),Oh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=tn(t),c=v.useRef(null),[d,f]=Br({prop:o,defaultProp:s??!1,onChange:i,caller:hi});return u.jsx(mC,{scope:t,triggerId:Un(),triggerRef:c,contentId:Un(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(QS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Oh.displayName=hi;var Mh="DropdownMenuTrigger",Dh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ph(Mh,n),i=tn(n);return u.jsx(eC,{asChild:!0,...i,children:u.jsx(De.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:_a(t,s.triggerRef),onPointerDown:ye(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ye(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Dh.displayName=Mh;var gC="DropdownMenuPortal",Lh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=tn(t);return u.jsx(tC,{...r,...n})};Lh.displayName=gC;var $h="DropdownMenuContent",Fh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ph($h,n),s=tn(n),i=v.useRef(!1);return u.jsx(nC,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ye(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ye(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)"}})});Fh.displayName=$h;var xC="DropdownMenuGroup",yC=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(rC,{...o,...r,ref:t})});yC.displayName=xC;var vC="DropdownMenuLabel",zh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(oC,{...o,...r,ref:t})});zh.displayName=vC;var wC="DropdownMenuItem",Bh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(sC,{...o,...r,ref:t})});Bh.displayName=wC;var bC="DropdownMenuCheckboxItem",Hh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(iC,{...o,...r,ref:t})});Hh.displayName=bC;var SC="DropdownMenuRadioGroup",CC=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(aC,{...o,...r,ref:t})});CC.displayName=SC;var kC="DropdownMenuRadioItem",Uh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(lC,{...o,...r,ref:t})});Uh.displayName=kC;var TC="DropdownMenuItemIndicator",Wh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(cC,{...o,...r,ref:t})});Wh.displayName=TC;var EC="DropdownMenuSeparator",Vh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(uC,{...o,...r,ref:t})});Vh.displayName=EC;var IC="DropdownMenuArrow",NC=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(dC,{...o,...r,ref:t})});NC.displayName=IC;var AC="DropdownMenuSubTrigger",Kh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(fC,{...o,...r,ref:t})});Kh.displayName=AC;var _C="DropdownMenuSubContent",qh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=tn(n);return u.jsx(hC,{...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)"}})});qh.displayName=_C;var jC=Oh,RC=Dh,PC=Lh,Gh=Fh,Xh=zh,Yh=Bh,Jh=Hh,Zh=Uh,Qh=Wh,ep=Vh,tp=Kh,np=qh;const OC=jC,MC=RC,DC=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(tp,{ref:o,className:se("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,u.jsx(pe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));DC.displayName=tp.displayName;const LC=v.forwardRef(({className:e,...t},n)=>u.jsx(np,{ref:n,className:se("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));LC.displayName=np.displayName;const rp=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(PC,{children:u.jsx(Gh,{ref:r,sideOffset:t,className:se("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));rp.displayName=Gh.displayName;const vl=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Yh,{ref:r,className:se("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));vl.displayName=Yh.displayName;const $C=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(Jh,{ref:o,className:se("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Qh,{children:u.jsx(pe.Check,{className:"h-4 w-4"})})}),t]}));$C.displayName=Jh.displayName;const FC=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Zh,{ref:r,className:se("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Qh,{children:u.jsx(pe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));FC.displayName=Zh.displayName;const zC=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Xh,{ref:r,className:se("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));zC.displayName=Xh.displayName;const BC=v.forwardRef(({className:e,...t},n)=>u.jsx(ep,{ref:n,className:se("-mx-1 my-1 h-px bg-muted",e),...t}));BC.displayName=ep.displayName;const op={value:""};function pi({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,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:g}){const{api:x}=Bi(),{currentThreadId:y}=cs(),{threadId:m,messages:b,hasMore:S,isHistoryLoading:T,isLoading:k,loadOlder:C,navigateToCheckpoint:E,returnToLatest:R,checkpoint:_,checkpoints:j,interrupt:L,metadata:z}=us(),{isStreaming:V,error:O,connectionState:H,submit:P,stop:W}=tu(),F=m??y??null,$=(_==null?void 0:_.id)??null,ne=(_==null?void 0:_.namespace)??null,oe=(z==null?void 0:z.assemblingMessageId)??null,we=L,[Ne,Z]=w.useState(!1);w.useEffect(()=>{we||Z(!1)},[we]);const ie=w.useCallback(()=>{Z(!0)},[]),Te=w.useCallback(()=>{Z(!1)},[]),ee=!!we||Ne,[D,G]=w.useState(null),[ae,fe]=w.useState(""),[B,le]=w.useState(null),[Q,Ae]=w.useState(null),[ve,Re]=w.useState([]),[Ve,Qe]=w.useState(0),[et,Se]=w.useState(0),[nt,ut]=w.useState(!1),[rt,Ye]=w.useState(null),[It,dt]=w.useState(null),[kt,Nt]=w.useState(!1),[tt,He]=w.useState(null),[Tt,Vt]=w.useState(!1),zt=w.useRef(!1),[Kt,st]=w.useState(()=>op.value),Le=w.useRef(Kt),_t=w.useRef(null),yt=w.useCallback(J=>{op.value=J,st(J)},[]),[X,Ce]=w.useState(!1),ge=w.useCallback((J,de)=>{if(!J||typeof J!="object")return null;const he=J[de];return typeof he=="number"?he:null},[]),xt=w.useCallback((J,de)=>{if(!J||typeof J!="object")return null;const he=J[de];return typeof he=="string"&&he.trim()?he:null},[]),ft=w.useMemo(()=>{const J=Array.isArray(j)?[...j]:[];return J.some(he=>ge(he.metadata,"step")!==null)&&J.sort((he,wt)=>{const Ot=ge(he.metadata,"step"),an=ge(wt.metadata,"step");if(Ot!==null||an!==null)return(an??Number.NEGATIVE_INFINITY)-(Ot??Number.NEGATIVE_INFINITY);const qn=Date.parse(he.createdAt??""),cr=Date.parse(wt.createdAt??"");return Number.isNaN(qn)||Number.isNaN(cr)?0:cr-qn}),J},[j,ge]),{checkpointMetaById:ht,checkpointIndexByKey:Be}=w.useMemo(()=>{const J=new Map,de=new Map;for(const he of ft){const wt=he.checkpointId??null;if(!wt)continue;const Ot=ge(he.metadata,"step"),an=xt(he.metadata,"source"),qn={id:wt,step:Ot,source:an,createdAt:he.createdAt??null,namespace:he.checkpointNs??null,parentId:he.parentId??null};if(J.set(wt,qn),Ot!==null&&an){const cr=`${Ot}:${an}`,Fo=de.get(cr)??[];Fo.push(qn),de.set(cr,Fo)}}for(const he of de.values())he.sort((wt,Ot)=>{const an=wt.createdAt??"";return(Ot.createdAt??"").localeCompare(an)});return{checkpointMetaById:J,checkpointIndexByKey:de}},[ft,ge,xt]),Ft=w.useRef(null),Oe=w.useRef(null),it=w.useCallback(()=>{Ft.current&&(Ft.current.value=""),Oe.current&&(Oe.current.value=""),Qe(J=>J+1),Se(J=>J+1)},[]),ar=w.useCallback(J=>{yt(J)},[yt]),jr=w.useRef(!1);w.useEffect(()=>{jr.current&&!V&&(Re([]),it()),jr.current=V},[V,it]);const[lr,Rr]=w.useState("desktop");w.useEffect(()=>{const J=()=>{const de=window.innerWidth;Rr(de<640?"phone":de<1024?"tablet":"desktop")};return J(),window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[]),w.useEffect(()=>{Vt(!1),zt.current=!1},[F]),w.useEffect(()=>{Le.current=Kt},[Kt]),w.useEffect(()=>{if(!D){_t.current=null;return}_t.current===null&&(_t.current=Le.current),yt(ae??"")},[ae,D,yt]);const Pr=w.useCallback(async()=>{if(!(!S||T||!Tt))try{await C()}catch(J){console.warn("loadOlder failed",J)}},[S,Tt,T,C]);w.useEffect(()=>{(async()=>{if(!x.baseUrl){He(null);return}try{const he=(await x.getAgent("default")).uiDefaultMessage||"";He(he||null)}catch(de){console.warn("Failed to fetch default message:",de),He(null)}})()},[x.baseUrl]),w.useEffect(()=>{O&&!kt&&(g==null||g(O))},[O,kt,g]);const Kn=J=>{if(J.length>Ys)return`Message too long (${J.length}/${Ys} characters)`;try{return qb(J),null}catch(de){return(de==null?void 0:de.message)||"Invalid message"}},Qr=async J=>{const de=J.trim();if(!(!de&&ve.length===0)){if(de){const he=Kn(de);if(he){Ae(he);return}}try{const he=$??void 0,wt=ne??void 0,Ot=D?{edit:!0,originalMessageId:D,...B!=null&&B.checkpointId?{originalCheckpointId:B.checkpointId}:{},...B!=null&&B.checkpointNs?{originalCheckpointNs:B.checkpointNs}:{}}:void 0;await P({text:de||"",attachments:ve,messageAdditionalKwargs:Ot},{checkpointId:he,checkpointNs:wt}),h==null||h(de),yt(""),Ae(null),Re([]),it(),G(null),fe(""),le(null)}catch(he){const wt=(he==null?void 0:he.message)||"Failed to send message";Ae(wt),g==null||g(wt)}}},I=w.useCallback((J,de,he)=>{c&&(_t.current=Kt,G(J),fe(de),yt(de),Ae(null),le({checkpointId:(he==null?void 0:he.checkpointId)??null,checkpointNs:(he==null?void 0:he.checkpointNs)??null}))},[Kt,c,yt]),q=w.useCallback(()=>{G(null),fe(""),le(null),Ae(null),yt(_t.current??Kt),_t.current=null},[Kt,yt]),ue=w.useCallback((J,de,he)=>{I(J,de,he)},[I]),ke=w.useCallback(J=>{for(let de=J-1;de>=0;de--)if(b[de].role==="user"){const he=b[de].content||[],Ot=he.filter(an=>an.type==="text").map(an=>an.text).join("")||(()=>{try{return JSON.stringify(he,null,2)}catch{return String(he)}})();Ot&&P({text:Ot},{checkpointId:$??void 0,checkpointNs:ne??void 0});break}},[b,P,$,ne]),Xe=J=>{const de=Array.from(J.target.files||[]);Re(he=>[...he,...de]),J.target.value=""},at=J=>{Re(de=>{const he=de.filter((wt,Ot)=>J!==Ot);return he.length===0&&it(),he})},Ke=async J=>{const de=(J.target.files||[])[0];if(de){Ye(null),dt(null),ut(!0);try{await P({attachments:[de]},{checkpointId:$??void 0,checkpointNs:ne??void 0});const he=`Uploaded ${de.name} - processing through chat stream`;dt(he)}catch(he){const wt=he instanceof Error?he.message:"Failed to upload Excel file";console.error("Excel upload failed",he),Ye(wt),g==null||g(wt)}finally{ut(!1),J.target.value="",it()}}},$e=async J=>{if(y){Ce(!0);try{if(!J){await R();return}const de=ft.find(wt=>wt.checkpointId===J),he=(de==null?void 0:de.checkpointNs)??null;await E(J,he)}finally{Ce(!1)}}},jt=w.useCallback(async J=>{await $e(J)},[$e]),vt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,pt=`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 ${f.messagesArea||""}`,qt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,Gt=w.useCallback(J=>{if(!J)return"Latest";const de=[];J.step!==null&&de.push(`Step ${J.step}`),J.source&&de.push(J.source);const he=J.createdAt?new Date(J.createdAt):null,wt=he&&!Number.isNaN(he.getTime())?he.toLocaleString():J.createdAt??J.id,Ot=de.length?` — ${de.join(" • ")}`:"";return`${wt}${Ot}`},[]);return u.jsxs("div",{className:vt,children:[!!O&&!kt&&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:O}),u.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>Nt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(pe.X,{size:16})})]}),y&&ft.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:$??"",onChange:J=>{const de=J.target.value||null;$e(de)},children:[u.jsx("option",{value:"",children:"Latest"}),ft.map(J=>{const de=ht.get(J.checkpointId??"")??null;return u.jsx("option",{value:J.checkpointId??void 0,children:Gt(de)},J.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${pt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Ga,{className:"h-full",style:{height:"100%"},messages:b,isStreaming:V,streamingAssistantId:oe,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:lr,enableMessageEditing:c,editingMessageId:D,onStartReached:()=>{Tt&&Pr()},onScrollAway:J=>{if(!zt.current){zt.current=!0;return}J&&Vt(!0)},onEdit:ue,onRegenerate:ke,onCancelEdit:q,emptyMessage:tt??void 0,isNavigatingCheckpoint:X,activeInterrupt:we,disableInterruptActions:Ne,onInterruptActionStart:ie,onInterruptActionEnd:Te,showToolMessages:d,checkpointMetaById:ht,checkpointIndexByKey:Be,activeCheckpointId:$,onSelectCheckpoint:jt}),(H==="reconnecting"||H==="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(pe.Loader2,{className:"h-3 w-3 animate-spin"}),H==="reconnecting"?"Reconnecting…":"Connecting…"]})}),H==="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"}),k&&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(pe.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),u.jsxs("div",{className:qt,children:[D&&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(pe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(lt,{variant:"ghost",size:"sm",onClick:q,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(pe.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:Ft,type:"file",multiple:!0,onChange:J=>Xe(J),className:"hidden"},Ve),ve.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:ve.map((J,de)=>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(pe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:J.name}),u.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>at(de),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 ${J.name}`,children:u.jsx(pe.X,{size:12})})]},de))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Oe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ke,className:"hidden"},et),nt&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(pe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),It&&!nt&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:It}),rt&&!nt&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:rt})]})]}),Q&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Q}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(OC,{children:[u.jsx(MC,{asChild:!0,children:u.jsx(lt,{type:"button",size:"icon",variant:"outline",disabled:V||ee,title:"More input actions",className:f.moreButton||"",children:u.jsx(pe.Plus,{size:16})})}),u.jsxs(rp,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(vl,{onClick:()=>{var J;return(J=Ft.current)==null?void 0:J.click()},className:"cursor-pointer",children:[u.jsx(pe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(vl,{onClick:()=>{var J;nt||(J=Oe.current)==null||J.click()},className:`cursor-pointer ${nt?"opacity-60 pointer-events-none":""}`,children:[u.jsx(pe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(dy,{initialValue:ae,editingMessageId:D,value:Kt,onValueChange:ar,placeholder:D?"Edit your message...":t,isStreaming:V,disabled:ee,maxLength:Ys,onSend:Qr,onCancelEdit:q,onStop:W,allowEmptySend:ve.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Q?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const mi=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:se("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));mi.displayName="Input";function wl(e,[t,n]){return Math.min(n,Math.max(t,e))}function HC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var bl="ScrollArea",[sp,PT]=Hn(bl),[UC,yn]=sp(bl),ip=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,h]=v.useState(null),[p,g]=v.useState(null),[x,y]=v.useState(null),[m,b]=v.useState(0),[S,T]=v.useState(0),[k,C]=v.useState(!1),[E,R]=v.useState(!1),_=Ze(t,L=>l(L)),j=Js(o);return u.jsx(UC,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:g,scrollbarXEnabled:k,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:R,onCornerWidthChange:b,onCornerHeightChange:T,children:u.jsx(De.div,{dir:j,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":m+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});ip.displayName=bl;var ap="ScrollAreaViewport",lp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=yn(ap,n),a=v.useRef(null),l=Ze(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(De.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})})]})});lp.displayName=ap;var $n="ScrollAreaScrollbar",Sl=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yn($n,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(WC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(VC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(cp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Cl,{...r,ref:t}):null});Sl.displayName=$n;var WC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yn($n,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(gn,{present:n||s,children:u.jsx(cp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),VC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yn($n,e.__scopeScrollArea),s=e.orientation==="horizontal",i=vi(()=>l("SCROLL_END"),100),[a,l]=HC("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(gn,{present:n||a!=="hidden",children:u.jsx(Cl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ye(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ye(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),cp=v.forwardRef((e,t)=>{const n=yn($n,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=vi(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Yr(n.viewport,l),Yr(n.content,l),u.jsx(gn,{present:r||s,children:u.jsx(Cl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Cl=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=yn($n,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=pp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return JC(h,i.current,a,p)}return n==="horizontal"?u.jsx(KC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=mp(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(qC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=mp(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),KC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=yn($n,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Ze(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(dp,{"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":yi(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),xp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:xi(i.paddingLeft),paddingEnd:xi(i.paddingRight)}})}})}),qC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=yn($n,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Ze(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(dp,{"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":yi(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),xp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:xi(i.paddingTop),paddingEnd:xi(i.paddingBottom)}})}})}),[GC,up]=sp($n),dp=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,...h}=e,p=yn($n,n),[g,x]=v.useState(null),y=Ze(t,_=>x(_)),m=v.useRef(null),b=v.useRef(""),S=p.viewport,T=r.content-r.viewport,k=Wt(d),C=Wt(l),E=vi(f,10);function R(_){if(m.current){const j=_.clientX-m.current.left,L=_.clientY-m.current.top;c({x:j,y:L})}}return v.useEffect(()=>{const _=j=>{const L=j.target;(g==null?void 0:g.contains(L))&&k(j,T)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,g,T,k]),v.useEffect(C,[r,C]),Yr(g,E),Yr(p.content,E),u.jsx(GC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:Wt(s),onThumbPointerUp:Wt(i),onThumbPositionChange:C,onThumbPointerDown:Wt(a),children:u.jsx(De.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:ye(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),m.current=g.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),R(_))}),onPointerMove:ye(e.onPointerMove,R),onPointerUp:ye(e.onPointerUp,_=>{const j=_.target;j.hasPointerCapture(_.pointerId)&&j.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),m.current=null})})})}),gi="ScrollAreaThumb",fp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=up(gi,e.__scopeScrollArea);return u.jsx(gn,{present:n||o.hasThumb,children:u.jsx(XC,{ref:t,...r})})}),XC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=yn(gi,n),i=up(gi,n),{onThumbPositionChange:a}=i,l=Ze(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=vi(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=ZC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(De.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:ye(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),g=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:g,y:x})}),onPointerUp:ye(e.onPointerUp,i.onThumbPointerUp)})});fp.displayName=gi;var kl="ScrollAreaCorner",hp=v.forwardRef((e,t)=>{const n=yn(kl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(YC,{...e,ref:t}):null});hp.displayName=kl;var YC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=yn(kl,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Yr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Yr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(De.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 xi(e){return e?parseInt(e,10):0}function pp(e,t){const n=e/t;return isNaN(n)?0:n}function yi(e){const t=pp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function JC(e,t,n,r="ltr"){const o=yi(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 gp([l,c],f)(e)}function mp(e,t,n="ltr"){const r=yi(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=wl(e,l);return gp([0,i],[0,a])(c)}function gp(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 xp(e,t){return e>0&&e<t}var ZC=(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 vi(e,t){const n=Wt(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 Yr(e,t){const n=Wt(t);Ut(()=>{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 yp=ip,QC=lp,ek=hp;const vp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(yp,{ref:r,className:se("relative overflow-hidden",e),...n,children:[u.jsx(QC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(wp,{}),u.jsx(ek,{})]}));vp.displayName=yp.displayName;const wp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Sl,{ref:r,orientation:t,className:se("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(fp,{className:"relative flex-1 rounded-full bg-border"})}));wp.displayName=Sl.displayName;const bp=25;function Tl({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:h,isLoading:p,actions:g}=cs(),{loadThread:x}=us(),{createThread:y,deleteThread:m,renameThread:b}=g,[S,T]=w.useState(Array.isArray(f)?f:[]),k=w.useRef(S.length>0),C=w.useRef(null),E=w.useRef(0),[R,_]=w.useState(null),[j,L]=w.useState(""),[z,V]=w.useState(!1);w.useEffect(()=>{const Z=Array.isArray(f)?f:[];if(Z.length>0){k.current=!0,T(Z);return}p||(k.current=!1,T(Z))},[f,p]),w.useEffect(()=>{if(!C.current)return;const Z=C.current.querySelector("[data-radix-scroll-area-viewport]");if(!Z)return;let ie=null,Te=null;return ie=requestAnimationFrame(()=>{Te=requestAnimationFrame(()=>{Z.scrollTop=E.current})}),()=>{ie!==null&&cancelAnimationFrame(ie),Te!==null&&cancelAnimationFrame(Te)}},[S]);const O=async Z=>{try{await x(Z),a==null||a(Z),l==null||l(Z)}catch(ie){console.error("Failed to select thread:",ie)}},H=async()=>{try{V(!0);const Z=await y();c==null||c(Z),a==null||a(Z)}catch(Z){console.error("Failed to create thread:",Z)}finally{V(!1)}},P=async(Z,ie)=>{if(ie.stopPropagation(),!!confirm("Delete this thread?")){if(C.current){const Te=C.current.querySelector("[data-radix-scroll-area-viewport]");Te&&(E.current=Te.scrollTop)}try{await m(Z),d==null||d(Z)}catch(Te){console.error("Failed to delete thread:",Te)}}},W=(Z,ie)=>{ie.stopPropagation(),_(Z.threadId),L(Z.title||`Thread ${Z.threadId.slice(0,8)}`)},F=async Z=>{if(j.trim())try{await b(Z,j.trim()),_(null),L("")}catch(ie){console.error("Failed to update title:",ie)}},$=()=>{_(null),L("")},ne=(Z,ie)=>{Z.key==="Enter"?F(ie):Z.key==="Escape"&&$()},oe=Z=>{if(!Z)return"";try{const ie=new Date(Z),ee=new Date().getTime()-ie.getTime(),D=Math.floor(ee/(1e3*60*60*24));return D===0?ie.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):D===1?"Yesterday":D<7?`${D} days ago`:ie.toLocaleDateString()}catch{return""}},we=Z=>Z.title||`Thread ${Z.threadId.slice(0,8)}`,Ne=Z=>{const ie=we(Z);return ie.length<=bp?ie:`${ie.slice(0,bp)}...`};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(lt,{onClick:H,disabled:z||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:z?"Creating...":"New Chat",children:u.jsx(pe.MessageSquarePlus,{size:20})})}),u.jsx(vp,{ref:C,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:p?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(pe.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(pe.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"})]}):S.slice().sort((Z,ie)=>new Date(ie.updatedAt||ie.createdAt||"").getTime()-new Date(Z.updatedAt||Z.createdAt||"").getTime()).map(Z=>u.jsxs("div",{onClick:()=>O(Z.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Z.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:R===Z.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ie=>ie.stopPropagation(),children:[u.jsx(mi,{value:j,onChange:ie=>L(ie.target.value),onKeyDown:ie=>ne(ie,Z.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>F(Z.threadId),className:"h-6 w-6 p-0",children:u.jsx(pe.Check,{size:12})}),u.jsx(lt,{variant:"ghost",size:"sm",onClick:$,className:"h-6 w-6 p-0",children:u.jsx(pe.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:Ne(Z)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(pe.Calendar,{size:10}),u.jsx("span",{children:oe(Z.updatedAt||Z.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&R!==Z.threadId&&u.jsx(lt,{variant:"ghost",size:"sm",onClick:ie=>W(Z,ie),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(pe.Edit3,{size:12})}),n&&u.jsx(lt,{variant:"ghost",size:"sm",onClick:ie=>P(Z.threadId,ie),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(pe.Trash2,{size:12})})]})]}),i===Z.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Z.threadId))})})]})}function Jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function tk(e){if(typeof e!="string")return;const t=e.trim();if(t)return zn(t)}function Sp(){const e=[Jr("__API_BASE_URL__"),Jr("__CHAT_API_BASE_URL__"),Jr("__CHAT_API_URL__")];for(const t of e){const n=tk(t);if(n)return n}}function Cp(){const e=[Jr("__API_AUTH_TOKEN__"),Jr("__CHAT_API_KEY__"),Jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function kp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return zn(t);return zn()}function Tp(){const e={},t=Sp(),n=Cp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Ep(){const e=Tp(),t=Gn.getAuthToken(),n=Sp();return{apiBaseUrl:kp(e.baseUrl,Gn.baseUrl,n),apiKey:t||e.apiKey||Cp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Ip="chat-settings";function nk(){try{const e=localStorage.getItem(Ip);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function rk(e){try{const t={...e,apiBaseUrl:zn(e.apiBaseUrl)};localStorage.setItem(Ip,JSON.stringify(t)),t.apiKey&&Gn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ok(){const e=Ep(),t=nk(),n=Gn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:kp(Gn.baseUrl,r,e.apiBaseUrl)}}function sk(e){Gn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),rk(e)}var ik="Label",Np=v.forwardRef((e,t)=>u.jsx(De.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())}}));Np.displayName=ik;var Ap=Np;const ak=Uo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),vn=v.forwardRef(({className:e,...t},n)=>u.jsx(Ap,{ref:n,className:se(ak(),e),...t}));vn.displayName=Ap.displayName;function _p(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var wi="Switch",[lk,OT]=Hn(wi),[ck,uk]=lk(wi),jp=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,[h,p]=v.useState(null),g=Ze(t,S=>p(S)),x=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[m,b]=Br({prop:o,defaultProp:s??!1,onChange:c,caller:wi});return u.jsxs(ck,{scope:n,checked:m,disabled:a,children:[u.jsx(De.button,{type:"button",role:"switch","aria-checked":m,"aria-required":i,"data-state":Mp(m),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:ye(e.onClick,S=>{b(T=>!T),y&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),y&&u.jsx(Op,{control:h,bubbles:!x.current,name:r,value:l,checked:m,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});jp.displayName=wi;var Rp="SwitchThumb",Pp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=uk(Rp,n);return u.jsx(De.span,{"data-state":Mp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Pp.displayName=Rp;var dk="SwitchBubbleInput",Op=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Ze(i,s),l=_p(n),c=Uf(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const g=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(g)}},[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}})});Op.displayName=dk;function Mp(e){return e?"checked":"unchecked"}var Dp=jp,fk=Pp;const or=v.forwardRef(({className:e,...t},n)=>u.jsx(Dp,{className:se("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(fk,{className:se("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));or.displayName=Dp.displayName;var Lp=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"}),hk="VisuallyHidden",pk=v.forwardRef((e,t)=>u.jsx(De.span,{...e,ref:t,style:{...Lp,...e.style}}));pk.displayName=hk;var mk=[" ","Enter","ArrowUp","ArrowDown"],gk=[" ","Enter"],Nr="Select",[bi,Si,xk]=Xa(Nr),[Zr,MT]=Hn(Nr,[xk,li]),Ci=li(),[yk,sr]=Zr(Nr),[vk,wk]=Zr(Nr),$p=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:h,required:p,form:g}=e,x=Ci(t),[y,m]=v.useState(null),[b,S]=v.useState(null),[T,k]=v.useState(!1),C=Js(c),[E,R]=Br({prop:r,defaultProp:o??!1,onChange:s,caller:Nr}),[_,j]=Br({prop:i,defaultProp:a,onChange:l,caller:Nr}),L=v.useRef(null),z=y?g||!!y.closest("form"):!0,[V,O]=v.useState(new Set),H=Array.from(V).map(P=>P.props.value).join(";");return u.jsx(Qf,{...x,children:u.jsxs(yk,{required:p,scope:t,trigger:y,onTriggerChange:m,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:Un(),value:_,onValueChange:j,open:E,onOpenChange:R,dir:C,triggerPointerDownPosRef:L,disabled:h,children:[u.jsx(bi.Provider,{scope:t,children:u.jsx(vk,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(P=>{O(W=>new Set(W).add(P))},[]),onNativeOptionRemove:v.useCallback(P=>{O(W=>{const F=new Set(W);return F.delete(P),F})},[]),children:n})}),z?u.jsxs(lm,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:P=>j(P.target.value),disabled:h,form:g,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},H):null]})})};$p.displayName=Nr;var Fp="SelectTrigger",zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ci(n),i=sr(Fp,n),a=i.disabled||r,l=Ze(t,i.onTriggerChange),c=Si(n),d=v.useRef("touch"),[f,h,p]=um(x=>{const y=c().filter(S=>!S.disabled),m=y.find(S=>S.value===i.value),b=dm(y,x,m);b!==void 0&&i.onValueChange(b.value)}),g=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return u.jsx(eh,{asChild:!0,...s,children:u.jsx(De.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":cm(i.value)?"":void 0,...o,ref:l,onClick:ye(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&g(x)}),onPointerDown:ye(o.onPointerDown,x=>{d.current=x.pointerType;const y=x.target;y.hasPointerCapture(x.pointerId)&&y.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(g(x),x.preventDefault())}),onKeyDown:ye(o.onKeyDown,x=>{const y=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(y&&x.key===" ")&&mk.includes(x.key)&&(g(),x.preventDefault())})})})});zp.displayName=Fp;var Bp="SelectValue",Hp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=sr(Bp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Ze(t,l.onValueNodeChange);return Ut(()=>{c(d)},[c,d]),u.jsx(De.span,{...a,ref:f,style:{pointerEvents:"none"},children:cm(l.value)?u.jsx(u.Fragment,{children:i}):s})});Hp.displayName=Bp;var bk="SelectIcon",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(De.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Up.displayName=bk;var Sk="SelectPortal",Wp=e=>u.jsx(_s,{asChild:!0,...e});Wp.displayName=Sk;var Ar="SelectContent",Vp=v.forwardRef((e,t)=>{const n=sr(Ar,e.__scopeSelect),[r,o]=v.useState();if(Ut(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Wo.createPortal(u.jsx(Kp,{scope:e.__scopeSelect,children:u.jsx(bi.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(qp,{...e,ref:t})});Vp.displayName=Ar;var Nn=10,[Kp,ir]=Zr(Ar),Ck="SelectContentImpl",kk=hr.createSlot("SelectContent.RemoveScroll"),qp=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:h,collisionPadding:p,sticky:g,hideWhenDetached:x,avoidCollisions:y,...m}=e,b=sr(Ar,n),[S,T]=v.useState(null),[k,C]=v.useState(null),E=Ze(t,ee=>T(ee)),[R,_]=v.useState(null),[j,L]=v.useState(null),z=Si(n),[V,O]=v.useState(!1),H=v.useRef(!1);v.useEffect(()=>{if(S)return Ba(S)},[S]),Ma();const P=v.useCallback(ee=>{const[D,...G]=z().map(B=>B.ref.current),[ae]=G.slice(-1),fe=document.activeElement;for(const B of ee)if(B===fe||(B==null||B.scrollIntoView({block:"nearest"}),B===D&&k&&(k.scrollTop=0),B===ae&&k&&(k.scrollTop=k.scrollHeight),B==null||B.focus(),document.activeElement!==fe))return},[z,k]),W=v.useCallback(()=>P([R,S]),[P,R,S]);v.useEffect(()=>{V&&W()},[V,W]);const{onOpenChange:F,triggerPointerDownPosRef:$}=b;v.useEffect(()=>{if(S){let ee={x:0,y:0};const D=ae=>{var fe,B;ee={x:Math.abs(Math.round(ae.pageX)-(((fe=$.current)==null?void 0:fe.x)??0)),y:Math.abs(Math.round(ae.pageY)-(((B=$.current)==null?void 0:B.y)??0))}},G=ae=>{ee.x<=10&&ee.y<=10?ae.preventDefault():S.contains(ae.target)||F(!1),document.removeEventListener("pointermove",D),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",G,{capture:!0})}}},[S,F,$]),v.useEffect(()=>{const ee=()=>F(!1);return window.addEventListener("blur",ee),window.addEventListener("resize",ee),()=>{window.removeEventListener("blur",ee),window.removeEventListener("resize",ee)}},[F]);const[ne,oe]=um(ee=>{const D=z().filter(fe=>!fe.disabled),G=D.find(fe=>fe.ref.current===document.activeElement),ae=dm(D,ee,G);ae&&setTimeout(()=>ae.ref.current.focus())}),we=v.useCallback((ee,D,G)=>{const ae=!H.current&&!G;(b.value!==void 0&&b.value===D||ae)&&(_(ee),ae&&(H.current=!0))},[b.value]),Ne=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Z=v.useCallback((ee,D,G)=>{const ae=!H.current&&!G;(b.value!==void 0&&b.value===D||ae)&&L(ee)},[b.value]),ie=r==="popper"?El:Gp,Te=ie===El?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:g,hideWhenDetached:x,avoidCollisions:y}:{};return u.jsx(Kp,{scope:n,content:S,viewport:k,onViewportChange:C,itemRefCallback:we,selectedItem:R,onItemLeave:Ne,itemTextRefCallback:Z,focusSelectedItem:W,selectedItemText:j,position:r,isPositioned:V,searchRef:ne,children:u.jsx(Ls,{as:kk,allowPinchZoom:!0,children:u.jsx(As,{asChild:!0,trapped:b.open,onMountAutoFocus:ee=>{ee.preventDefault()},onUnmountAutoFocus:ye(o,ee=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),ee.preventDefault()}),children:u.jsx(Ns,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:ee=>ee.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(ie,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:ee=>ee.preventDefault(),...m,...Te,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...m.style},onKeyDown:ye(m.onKeyDown,ee=>{const D=ee.ctrlKey||ee.altKey||ee.metaKey;if(ee.key==="Tab"&&ee.preventDefault(),!D&&ee.key.length===1&&oe(ee.key),["ArrowUp","ArrowDown","Home","End"].includes(ee.key)){let ae=z().filter(fe=>!fe.disabled).map(fe=>fe.ref.current);if(["ArrowUp","End"].includes(ee.key)&&(ae=ae.slice().reverse()),["ArrowUp","ArrowDown"].includes(ee.key)){const fe=ee.target,B=ae.indexOf(fe);ae=ae.slice(B+1)}setTimeout(()=>P(ae)),ee.preventDefault()}})})})})})})});qp.displayName=Ck;var Tk="SelectItemAlignedPosition",Gp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=sr(Ar,n),i=ir(Ar,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Ze(t,E=>d(E)),h=Si(n),p=v.useRef(!1),g=v.useRef(!0),{viewport:x,selectedItem:y,selectedItemText:m,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&y&&m){const E=s.trigger.getBoundingClientRect(),R=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),j=m.getBoundingClientRect();if(s.dir!=="rtl"){const fe=j.left-R.left,B=_.left-fe,le=E.left-B,Q=E.width+le,Ae=Math.max(Q,R.width),ve=window.innerWidth-Nn,Re=wl(B,[Nn,Math.max(Nn,ve-Ae)]);a.style.minWidth=Q+"px",a.style.left=Re+"px"}else{const fe=R.right-j.right,B=window.innerWidth-_.right-fe,le=window.innerWidth-E.right-B,Q=E.width+le,Ae=Math.max(Q,R.width),ve=window.innerWidth-Nn,Re=wl(B,[Nn,Math.max(Nn,ve-Ae)]);a.style.minWidth=Q+"px",a.style.right=Re+"px"}const L=h(),z=window.innerHeight-Nn*2,V=x.scrollHeight,O=window.getComputedStyle(c),H=parseInt(O.borderTopWidth,10),P=parseInt(O.paddingTop,10),W=parseInt(O.borderBottomWidth,10),F=parseInt(O.paddingBottom,10),$=H+P+V+F+W,ne=Math.min(y.offsetHeight*5,$),oe=window.getComputedStyle(x),we=parseInt(oe.paddingTop,10),Ne=parseInt(oe.paddingBottom,10),Z=E.top+E.height/2-Nn,ie=z-Z,Te=y.offsetHeight/2,ee=y.offsetTop+Te,D=H+P+ee,G=$-D;if(D<=Z){const fe=L.length>0&&y===L[L.length-1].ref.current;a.style.bottom="0px";const B=c.clientHeight-x.offsetTop-x.offsetHeight,le=Math.max(ie,Te+(fe?Ne:0)+B+W),Q=D+le;a.style.height=Q+"px"}else{const fe=L.length>0&&y===L[0].ref.current;a.style.top="0px";const le=Math.max(Z,H+x.offsetTop+(fe?we:0)+Te)+G;a.style.height=le+"px",x.scrollTop=D-Z+x.offsetTop}a.style.margin=`${Nn}px 0`,a.style.minHeight=ne+"px",a.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,x,y,m,s.dir,r]);Ut(()=>S(),[S]);const[T,k]=v.useState();Ut(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const C=v.useCallback(E=>{E&&g.current===!0&&(S(),b==null||b(),g.current=!1)},[S,b]);return u.jsx(Ik,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:u.jsx(De.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Gp.displayName=Tk;var Ek="SelectPopperPosition",El=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Nn,...s}=e,i=Ci(n);return u.jsx(th,{...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)"}})});El.displayName=Ek;var[Ik,Il]=Zr(Ar,{}),Nl="SelectViewport",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=ir(Nl,n),i=Il(Nl,n),a=Ze(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(bi.Slot,{scope:n,children:u.jsx(De.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ye(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const g=window.innerHeight-Nn*2,x=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),m=Math.max(x,y);if(m<g){const b=m+p,S=Math.min(g,b),T=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Xp.displayName=Nl;var Yp="SelectGroup",[Nk,Ak]=Zr(Yp),_k=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Un();return u.jsx(Nk,{scope:n,id:o,children:u.jsx(De.div,{role:"group","aria-labelledby":o,...r,ref:t})})});_k.displayName=Yp;var Jp="SelectLabel",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ak(Jp,n);return u.jsx(De.div,{id:o.id,...r,ref:t})});Zp.displayName=Jp;var ki="SelectItem",[jk,Qp]=Zr(ki),em=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=sr(ki,n),l=ir(ki,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),g=Ze(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=Un(),y=v.useRef("touch"),m=()=>{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(jk,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(bi.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(De.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:g,onFocus:ye(i.onFocus,()=>p(!0)),onBlur:ye(i.onBlur,()=>p(!1)),onClick:ye(i.onClick,()=>{y.current!=="mouse"&&m()}),onPointerUp:ye(i.onPointerUp,()=>{y.current==="mouse"&&m()}),onPointerDown:ye(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:ye(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:ye(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ye(i.onKeyDown,b=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&b.key===" "||(gk.includes(b.key)&&m(),b.key===" "&&b.preventDefault())})})})})});em.displayName=ki;var $o="SelectItemText",tm=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=sr($o,n),a=ir($o,n),l=Qp($o,n),c=wk($o,n),[d,f]=v.useState(null),h=Ze(t,m=>f(m),l.onItemTextChange,m=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,m,l.value,l.disabled)}),p=d==null?void 0:d.textContent,g=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:y}=c;return Ut(()=>(x(g),()=>y(g)),[x,y,g]),u.jsxs(u.Fragment,{children:[u.jsx(De.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Wo.createPortal(s.children,i.valueNode):null]})});tm.displayName=$o;var nm="SelectItemIndicator",rm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Qp(nm,n).isSelected?u.jsx(De.span,{"aria-hidden":!0,...r,ref:t}):null});rm.displayName=nm;var Al="SelectScrollUpButton",om=v.forwardRef((e,t)=>{const n=ir(Al,e.__scopeSelect),r=Il(Al,e.__scopeSelect),[o,s]=v.useState(!1),i=Ze(t,r.onScrollButtonChange);return Ut(()=>{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(im,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});om.displayName=Al;var _l="SelectScrollDownButton",sm=v.forwardRef((e,t)=>{const n=ir(_l,e.__scopeSelect),r=Il(_l,e.__scopeSelect),[o,s]=v.useState(!1),i=Ze(t,r.onScrollButtonChange);return Ut(()=>{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(im,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});sm.displayName=_l;var im=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=ir("SelectScrollButton",n),i=v.useRef(null),a=Si(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Ut(()=>{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(De.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ye(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ye(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ye(o.onPointerLeave,()=>{l()})})}),Rk="SelectSeparator",am=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(De.div,{"aria-hidden":!0,...r,ref:t})});am.displayName=Rk;var jl="SelectArrow",Pk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ci(n),s=sr(jl,n),i=ir(jl,n);return s.open&&i.position==="popper"?u.jsx(nh,{...o,...r,ref:t}):null});Pk.displayName=jl;var Ok="SelectBubbleInput",lm=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Ze(r,o),i=_p(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(De.select,{...n,style:{...Lp,...n.style},ref:s,defaultValue:t})});lm.displayName=Ok;function cm(e){return e===""||e===void 0}function um(e){const t=Wt(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 dm(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=Mk(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 Mk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Dk=$p,fm=zp,Lk=Hp,$k=Up,Fk=Wp,hm=Vp,zk=Xp,pm=Zp,mm=em,Bk=tm,Hk=rm,gm=om,xm=sm,ym=am;const vm=Dk,wm=Lk,Rl=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(fm,{ref:r,className:se("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx($k,{asChild:!0,children:u.jsx(pe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Rl.displayName=fm.displayName;const bm=v.forwardRef(({className:e,...t},n)=>u.jsx(gm,{ref:n,className:se("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(pe.ChevronUp,{className:"h-4 w-4"})}));bm.displayName=gm.displayName;const Sm=v.forwardRef(({className:e,...t},n)=>u.jsx(xm,{ref:n,className:se("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(pe.ChevronDown,{className:"h-4 w-4"})}));Sm.displayName=xm.displayName;const Pl=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(Fk,{children:u.jsxs(hm,{ref:o,className:se("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(bm,{}),u.jsx(zk,{className:se("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Sm,{})]})}));Pl.displayName=hm.displayName;const Uk=v.forwardRef(({className:e,...t},n)=>u.jsx(pm,{ref:n,className:se("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Uk.displayName=pm.displayName;const _r=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(mm,{ref:r,className:se("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Hk,{children:u.jsx(pe.Check,{className:"h-4 w-4"})})}),u.jsx(Bk,{children:t})]}));_r.displayName=mm.displayName;const Wk=v.forwardRef(({className:e,...t},n)=>u.jsx(ym,{ref:n,className:se("-mx-1 my-1 h-px bg-muted",e),...t}));Wk.displayName=ym.displayName;var Vk="Separator",Cm="horizontal",Kk=["horizontal","vertical"],km=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Cm,...o}=e,s=qk(r)?r:Cm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(De.div,{"data-orientation":s,...a,...o,ref:t})});km.displayName=Vk;function qk(e){return Kk.includes(e)}var Tm=km;const Em=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Tm,{ref:o,decorative:n,orientation:t,className:se("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Em.displayName=Tm.displayName;const Gk=Xd,Xk=hb,Yk=Yd,Im=v.forwardRef(({className:e,...t},n)=>u.jsx(Hs,{className:se("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));Im.displayName=Hs.displayName;const Jk=Uo.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"}}),Nm=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(Yk,{children:[u.jsx(Im,{}),u.jsxs(Us,{ref:o,className:se(Jk({side:e}),t),...r,children:[n,u.jsxs(Jd,{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(pe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Nm.displayName=Us.displayName;const Am=({className:e,...t})=>u.jsx("div",{className:se("flex flex-col space-y-2 text-center sm:text-left",e),...t});Am.displayName="SheetHeader";const _m=v.forwardRef(({className:e,...t},n)=>u.jsx(Cr,{ref:n,className:se("text-lg font-semibold text-foreground",e),...t}));_m.displayName=Cr.displayName;const jm=v.forwardRef(({className:e,...t},n)=>u.jsx(Ws,{ref:n,className:se("text-sm text-muted-foreground",e),...t}));jm.displayName=Ws.displayName;const Zk={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 Qk({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}=Na();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(Zk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const m=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${m.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(Gk,{open:r,onOpenChange:o,children:[u.jsx(Xk,{asChild:!0,children:u.jsxs(lt,{variant:"outline",size:"sm",className:n,children:[u.jsx(pe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(td,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Nm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Am,{children:[u.jsx(_m,{children:"Chat Settings"}),u.jsx(jm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(bo,{children:[u.jsx(So,{className:"pb-3",children:u.jsxs(Co,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(ko,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(vn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(mi,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(m=>({...m,api:{...m.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(lt,{variant:"outline",onClick:x,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(vn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(or,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(m=>({...m,api:{...m.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(vn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(mi,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(m=>({...m,api:{...m.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(lt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(pe.EyeOff,{className:"h-4 w-4"}):u.jsx(pe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(bo,{children:[u.jsx(So,{className:"pb-3",children:u.jsxs(Co,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(ko,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(vn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(vm,{value:a.ui.layout,onValueChange:y=>l(m=>({...m,ui:{...m.ui,layout:y}})),children:[u.jsx(Rl,{children:u.jsx(wm,{})}),u.jsxs(Pl,{children:[u.jsx(_r,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(_r,{value:"fullscreen",children:"Fullscreen"}),u.jsx(_r,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(vn,{htmlFor:"theme",children:"Theme"}),u.jsxs(vm,{value:a.ui.theme,onValueChange:y=>l(m=>({...m,ui:{...m.ui,theme:y}})),children:[u.jsx(Rl,{children:u.jsx(wm,{})}),u.jsxs(Pl,{children:[u.jsx(_r,{value:"light",children:"Light"}),u.jsx(_r,{value:"dark",children:"Dark"}),u.jsx(_r,{value:"system",children:"System"})]})]})]}),u.jsx(Em,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(vn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(or,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(m=>({...m,ui:{...m.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(vn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(or,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(m=>({...m,ui:{...m.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(vn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(or,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(m=>({...m,ui:{...m.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(bo,{children:[u.jsx(So,{className:"pb-3",children:u.jsxs(Co,{className:"text-lg flex items-center gap-2",children:[u.jsx(pe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(ko,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(vn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(or,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(m=>({...m,behavior:{...m.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(vn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(or,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(m=>({...m,behavior:{...m.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(vn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(or,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(m=>({...m,behavior:{...m.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(lt,{variant:"outline",onClick:p,children:[u.jsx(pe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(lt,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(lt,{onClick:h,disabled:!c,children:[u.jsx(pe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function eT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(ds,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(pi,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(ds,{...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(Tl,{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(pi,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(ds,{...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(Tl,{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(pi,{onError:s.onError,enableFileUpload:!0})})]})})}Pe.ChatApi=_c,Pe.ChatInterface=pi,Pe.ChatProviders=ds,Pe.ChatSettings=Qk,Pe.MarkdownContent=No,Pe.MessageComponent=qa,Pe.MessageList=Ga,Pe.ThreadManager=Tl,Pe.applySettings=sk,Pe.chatApiClient=Gn,Pe.default=eT,Pe.del=Ac,Pe.get=bn,Pe.getChatToken=Ec,Pe.getCurrentSettings=ok,Pe.getDefaultApiConfig=Tp,Pe.getDefaultChatSettings=Ep,Pe.onChatTokenChanged=Ic,Pe.post=zi,Pe.put=Nc,Pe.setChatToken=Fi,Pe.useApi=Bi,Pe.useChatStream=Vc,Pe.useMessagesReducer=Lc,Pe.useStream=tu,Pe.useThreadState=us,Pe.useThreads=cs,Object.defineProperties(Pe,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
137
+ `).trim():n.replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function Kb(e,t=ti){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 qb(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Kb(t),Vb(t)}function tl(e){const t=e+"CollectionProvider",[n,r]=Yn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:y,children:m}=x,b=w.useRef(null),S=w.useRef(new Map).current;return u.jsx(o,{scope:y,itemMap:S,collectionRef:b,children:m})};i.displayName=t;const a=e+"CollectionSlot",l=xr.createSlot(a),c=w.forwardRef((x,y)=>{const{scope:m,children:b}=x,S=s(a,m),T=Je(y,S.collectionRef);return u.jsx(l,{ref:T,children:b})});c.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=xr.createSlot(d),p=w.forwardRef((x,y)=>{const{scope:m,children:b,...S}=x,T=w.useRef(null),k=Je(y,T),C=s(d,m);return w.useEffect(()=>(C.itemMap.set(T,{ref:T,...S}),()=>void C.itemMap.delete(T))),u.jsx(h,{[f]:"",ref:k,children:b})});p.displayName=d;function g(x){const y=s(e+"CollectionConsumer",x);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((C,E)=>S.indexOf(C.ref.current)-S.indexOf(E.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},g,r]}var Gb=v.createContext(void 0);function ni(e){const t=v.useContext(Gb);return e||t||"ltr"}const Yb=["top","right","bottom","left"],lr=Math.min,pn=Math.max,ri=Math.round,oi=Math.floor,zn=e=>({x:e,y:e}),Xb={left:"right",right:"left",bottom:"top",top:"bottom"},Jb={start:"end",end:"start"};function nl(e,t,n){return pn(e,lr(t,n))}function Jn(e,t){return typeof e=="function"?e(t):e}function Zn(e){return e.split("-")[0]}function Yr(e){return e.split("-")[1]}function rl(e){return e==="x"?"y":"x"}function ol(e){return e==="y"?"height":"width"}const Zb=new Set(["top","bottom"]);function Bn(e){return Zb.has(Zn(e))?"y":"x"}function sl(e){return rl(Bn(e))}function Qb(e,t,n){n===void 0&&(n=!1);const r=Yr(e),o=sl(e),s=ol(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=si(i)),[i,si(i)]}function e0(e){const t=si(e);return[il(e),t,il(t)]}function il(e){return e.replace(/start|end/g,t=>Jb[t])}const Ef=["left","right"],If=["right","left"],t0=["top","bottom"],n0=["bottom","top"];function r0(e,t,n){switch(e){case"top":case"bottom":return n?t?If:Ef:t?Ef:If;case"left":case"right":return t?t0:n0;default:return[]}}function o0(e,t,n,r){const o=Yr(e);let s=r0(Zn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(il)))),s}function si(e){return e.replace(/left|right|bottom|top/g,t=>Xb[t])}function s0(e){return{top:0,right:0,bottom:0,left:0,...e}}function Nf(e){return typeof e!="number"?s0(e):{top:e,right:e,bottom:e,left:e}}function ii(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 Af(e,t,n){let{reference:r,floating:o}=e;const s=Bn(t),i=sl(t),a=ol(i),l=Zn(t),c=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Yr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const i0=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}=Af(c,r,l),h=r,p={},g=0;for(let x=0;x<a.length;x++){const{name:y,fn:m}=a[x],{x:b,y:S,data:T,reset:k}=await m({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[y]:{...p[y],...T}},k&&g<=50&&(g++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(c=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=Af(c,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function Po(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:h=!1,padding:p=0}=Jn(t,e),g=Nf(p),y=a[h?f==="floating"?"reference":"floating":f],m=ii(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)),T=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},k=ii(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(m.top-k.top+g.top)/T.y,bottom:(k.bottom-m.bottom+g.bottom)/T.y,left:(m.left-k.left+g.left)/T.x,right:(k.right-m.right+g.right)/T.x}}const a0=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}=Jn(e,t)||{};if(c==null)return{};const f=Nf(d),h={x:n,y:r},p=sl(o),g=ol(p),x=await i.getDimensions(c),y=p==="y",m=y?"top":"left",b=y?"bottom":"right",S=y?"clientHeight":"clientWidth",T=s.reference[g]+s.reference[p]-h[p]-s.floating[g],k=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=C?C[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(C)))&&(E=a.floating[S]||s.floating[g]);const R=T/2-k/2,_=E/2-x[g]/2-1,j=lr(f[m],_),D=lr(f[b],_),z=j,W=E-x[g]-D,O=E/2-x[g]/2+R,B=nl(z,O,W),P=!l.arrow&&Yr(o)!=null&&O!==B&&s.reference[g]/2-(O<z?j:D)-x[g]/2<0,V=P?O<z?O-z:O-W:0;return{[p]:h[p]+V,data:{[p]:B,centerOffset:O-B-V,...P&&{alignmentOffset:V}},reset:P}}}),l0=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:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:x=!0,...y}=Jn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const m=Zn(o),b=Bn(a),S=Zn(a)===a,T=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=h||(S||!x?[si(a)]:e0(a)),C=g!=="none";!h&&C&&k.push(...o0(a,x,g,T));const E=[a,...k],R=await Po(t,y),_=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(R[m]),f){const O=Qb(o,i,T);_.push(R[O[0]],R[O[1]])}if(j=[...j,{placement:o,overflows:_}],!_.every(O=>O<=0)){var D,z;const O=(((D=s.flip)==null?void 0:D.index)||0)+1,B=E[O];if(B&&(!(f==="alignment"?b!==Bn(B):!1)||j.every($=>Bn($.placement)===b?$.overflows[0]>0:!0)))return{data:{index:O,overflows:j},reset:{placement:B}};let P=(z=j.filter(V=>V.overflows[0]<=0).sort((V,$)=>V.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!P)switch(p){case"bestFit":{var W;const V=(W=j.filter($=>{if(C){const F=Bn($.placement);return F===b||F==="y"}return!0}).map($=>[$.placement,$.overflows.filter(F=>F>0).reduce((F,ee)=>F+ee,0)]).sort(($,F)=>$[1]-F[1])[0])==null?void 0:W[0];V&&(P=V);break}case"initialPlacement":P=a;break}if(o!==P)return{reset:{placement:P}}}return{}}}};function _f(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function jf(e){return Yb.some(t=>e[t]>=0)}const c0=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Jn(e,t);switch(r){case"referenceHidden":{const s=await Po(t,{...o,elementContext:"reference"}),i=_f(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:jf(i)}}}case"escaped":{const s=await Po(t,{...o,altBoundary:!0}),i=_f(s,n.floating);return{data:{escapedOffsets:i,escaped:jf(i)}}}default:return{}}}}},Rf=new Set(["left","top"]);async function u0(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Zn(n),a=Yr(n),l=Bn(n)==="y",c=Rf.has(i)?-1:1,d=s&&l?-1:1,f=Jn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*d,y:h*c}:{x:h*c,y:p*d}}const d0=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 u0(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}}}}},f0=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:m,y:b}=y;return{x:m,y:b}}},...l}=Jn(e,t),c={x:n,y:r},d=await Po(t,l),f=Bn(Zn(o)),h=rl(f);let p=c[h],g=c[f];if(s){const y=h==="y"?"top":"left",m=h==="y"?"bottom":"right",b=p+d[y],S=p-d[m];p=nl(b,p,S)}if(i){const y=f==="y"?"top":"left",m=f==="y"?"bottom":"right",b=g+d[y],S=g-d[m];g=nl(b,g,S)}const x=a.fn({...t,[h]:p,[f]:g});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},h0=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}=Jn(e,t),d={x:n,y:r},f=Bn(o),h=rl(f);let p=d[h],g=d[f];const x=Jn(a,t),y=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",T=s.reference[h]-s.floating[S]+y.mainAxis,k=s.reference[h]+s.reference[S]-y.mainAxis;p<T?p=T:p>k&&(p=k)}if(c){var m,b;const S=h==="y"?"width":"height",T=Rf.has(Zn(o)),k=s.reference[f]-s.floating[S]+(T&&((m=i.offset)==null?void 0:m[f])||0)+(T?0:y.crossAxis),C=s.reference[f]+s.reference[S]+(T?0:((b=i.offset)==null?void 0:b[f])||0)-(T?y.crossAxis:0);g<k?g=k:g>C&&(g=C)}return{[h]:p,[f]:g}}}},p0=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}=Jn(e,t),d=await Po(t,c),f=Zn(o),h=Yr(o),p=Bn(o)==="y",{width:g,height:x}=s.floating;let y,m;f==="top"||f==="bottom"?(y=f,m=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(m=f,y=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=g-d.left-d.right,T=lr(x-d[y],b),k=lr(g-d[m],S),C=!t.middlewareData.shift;let E=T,R=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(R=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),C&&!h){const j=pn(d.left,0),D=pn(d.right,0),z=pn(d.top,0),W=pn(d.bottom,0);p?R=g-2*(j!==0||D!==0?j+D:pn(d.left,d.right)):E=x-2*(z!==0||W!==0?z+W:pn(d.top,d.bottom))}await l({...t,availableWidth:R,availableHeight:E});const _=await i.getDimensions(a.floating);return g!==_.width||x!==_.height?{reset:{rects:!0}}:{}}}};function ai(){return typeof window<"u"}function Xr(e){return Pf(e)?(e.nodeName||"").toLowerCase():"#document"}function mn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Hn(e){var t;return(t=(Pf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Pf(e){return ai()?e instanceof Node||e instanceof mn(e).Node:!1}function jn(e){return ai()?e instanceof Element||e instanceof mn(e).Element:!1}function Un(e){return ai()?e instanceof HTMLElement||e instanceof mn(e).HTMLElement:!1}function Of(e){return!ai()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof mn(e).ShadowRoot}const m0=new Set(["inline","contents"]);function Oo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Rn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!m0.has(o)}const g0=new Set(["table","td","th"]);function x0(e){return g0.has(Xr(e))}const y0=[":popover-open",":modal"];function li(e){return y0.some(t=>{try{return e.matches(t)}catch{return!1}})}const v0=["transform","translate","scale","rotate","perspective"],w0=["transform","translate","scale","rotate","perspective","filter"],b0=["paint","layout","strict","content"];function al(e){const t=ll(),n=jn(e)?Rn(e):e;return v0.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)||w0.some(r=>(n.willChange||"").includes(r))||b0.some(r=>(n.contain||"").includes(r))}function S0(e){let t=cr(e);for(;Un(t)&&!Jr(t);){if(al(t))return t;if(li(t))return null;t=cr(t)}return null}function ll(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const C0=new Set(["html","body","#document"]);function Jr(e){return C0.has(Xr(e))}function Rn(e){return mn(e).getComputedStyle(e)}function ci(e){return jn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function cr(e){if(Xr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Of(e)&&e.host||Hn(e);return Of(t)?t.host:t}function Mf(e){const t=cr(e);return Jr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Un(t)&&Oo(t)?t:Mf(t)}function Mo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Mf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=mn(o);if(s){const a=cl(i);return t.concat(i,i.visualViewport||[],Oo(o)?o:[],a&&n?Mo(a):[])}return t.concat(o,Mo(o,[],n))}function cl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Df(e){const t=Rn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Un(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ri(n)!==s||ri(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ul(e){return jn(e)?e:e.contextElement}function Zr(e){const t=ul(e);if(!Un(t))return zn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Df(t);let i=(s?ri(n.width):n.width)/r,a=(s?ri(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const k0=zn(0);function Lf(e){const t=mn(e);return!ll()||!t.visualViewport?k0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function T0(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==mn(e)?!1:t}function Ar(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ul(e);let i=zn(1);t&&(r?jn(r)&&(i=Zr(r)):i=Zr(e));const a=T0(s,n,r)?Lf(s):zn(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 h=mn(s),p=r&&jn(r)?mn(r):r;let g=h,x=cl(g);for(;x&&r&&p!==g;){const y=Zr(x),m=x.getBoundingClientRect(),b=Rn(x),S=m.left+(x.clientLeft+parseFloat(b.paddingLeft))*y.x,T=m.top+(x.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,d*=y.x,f*=y.y,l+=S,c+=T,g=mn(x),x=cl(g)}}return ii({width:d,height:f,x:l,y:c})}function ui(e,t){const n=ci(e).scrollLeft;return t?t.left+n:Ar(Hn(e)).left+n}function Ff(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ui(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function E0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Hn(r),a=t?li(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=zn(1);const d=zn(0),f=Un(r);if((f||!f&&!s)&&((Xr(r)!=="body"||Oo(i))&&(l=ci(r)),Un(r))){const p=Ar(r);c=Zr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Ff(i,l):zn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+d.x+h.x,y:n.y*c.y-l.scrollTop*c.y+d.y+h.y}}function I0(e){return Array.from(e.getClientRects())}function N0(e){const t=Hn(e),n=ci(e),r=e.ownerDocument.body,o=pn(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=pn(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ui(e);const a=-n.scrollTop;return Rn(r).direction==="rtl"&&(i+=pn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const $f=25;function A0(e,t){const n=mn(e),r=Hn(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=ll();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=ui(r);if(c<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,g=Math.abs(r.clientWidth-f.clientWidth-p);g<=$f&&(s-=g)}else c<=$f&&(s+=c);return{width:s,height:i,x:a,y:l}}const _0=new Set(["absolute","fixed"]);function j0(e,t){const n=Ar(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Un(e)?Zr(e):zn(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 zf(e,t,n){let r;if(t==="viewport")r=A0(e,n);else if(t==="document")r=N0(Hn(e));else if(jn(t))r=j0(t,n);else{const o=Lf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ii(r)}function Bf(e,t){const n=cr(e);return n===t||!jn(n)||Jr(n)?!1:Rn(n).position==="fixed"||Bf(n,t)}function R0(e,t){const n=t.get(e);if(n)return n;let r=Mo(e,[],!1).filter(a=>jn(a)&&Xr(a)!=="body"),o=null;const s=Rn(e).position==="fixed";let i=s?cr(e):e;for(;jn(i)&&!Jr(i);){const a=Rn(i),l=al(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&_0.has(o.position)||Oo(i)&&!l&&Bf(e,i))?r=r.filter(d=>d!==i):o=a,i=cr(i)}return t.set(e,r),r}function P0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?li(t)?[]:R0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,d)=>{const f=zf(t,d,o);return c.top=pn(f.top,c.top),c.right=lr(f.right,c.right),c.bottom=lr(f.bottom,c.bottom),c.left=pn(f.left,c.left),c},zf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function O0(e){const{width:t,height:n}=Df(e);return{width:t,height:n}}function M0(e,t,n){const r=Un(t),o=Hn(t),s=n==="fixed",i=Ar(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=zn(0);function c(){l.x=ui(o)}if(r||!r&&!s)if((Xr(t)!=="body"||Oo(o))&&(a=ci(t)),r){const p=Ar(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const d=o&&!r&&!s?Ff(o,a):zn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function dl(e){return Rn(e).position==="static"}function Hf(e,t){if(!Un(e)||Rn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Hn(e)===n&&(n=n.ownerDocument.body),n}function Uf(e,t){const n=mn(e);if(li(e))return n;if(!Un(e)){let o=cr(e);for(;o&&!Jr(o);){if(jn(o)&&!dl(o))return o;o=cr(o)}return n}let r=Hf(e,t);for(;r&&x0(r)&&dl(r);)r=Hf(r,t);return r&&Jr(r)&&dl(r)&&!al(r)?n:r||S0(e)||n}const D0=async function(e){const t=this.getOffsetParent||Uf,n=this.getDimensions,r=await n(e.floating);return{reference:M0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function L0(e){return Rn(e).direction==="rtl"}const F0={convertOffsetParentRelativeRectToViewportRelativeRect:E0,getDocumentElement:Hn,getClippingRect:P0,getOffsetParent:Uf,getElementRects:D0,getClientRects:I0,getDimensions:O0,getScale:Zr,isElement:jn,isRTL:L0};function Wf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $0(e,t){let n=null,r;const o=Hn(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:h,height:p}=c;if(a||t(),!h||!p)return;const g=oi(f),x=oi(o.clientWidth-(d+h)),y=oi(o.clientHeight-(f+p)),m=oi(d),S={rootMargin:-g+"px "+-x+"px "+-y+"px "+-m+"px",threshold:pn(0,lr(1,l))||1};let T=!0;function k(C){const E=C[0].intersectionRatio;if(E!==l){if(!T)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Wf(c,e.getBoundingClientRect())&&i(),T=!1}try{n=new IntersectionObserver(k,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,S)}n.observe(e)}return i(!0),s}function z0(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=ul(e),d=o||s?[...c?Mo(c):[],...Mo(t)]:[];d.forEach(m=>{o&&m.addEventListener("scroll",n,{passive:!0}),s&&m.addEventListener("resize",n)});const f=c&&a?$0(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(m=>{let[b]=m;b&&b.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let g,x=l?Ar(e):null;l&&y();function y(){const m=Ar(e);x&&!Wf(x,m)&&n(),x=m,g=requestAnimationFrame(y)}return n(),()=>{var m;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(m=p)==null||m.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const B0=d0,H0=f0,U0=l0,W0=p0,V0=c0,Vf=a0,K0=h0,q0=(e,t,n)=>{const r=new Map,o={platform:F0,...n},s={...o.platform,_c:r};return i0(e,t,{...o,platform:s})};var G0=typeof document<"u",Y0=function(){},di=G0?w.useLayoutEffect:Y0;function fi(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(!fi(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)&&!fi(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Kf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function qf(e,t){const n=Kf(e);return Math.round(t*n)/n}function fl(e){const t=v.useRef(e);return di(()=>{t.current=e}),t}function X0(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}),[h,p]=v.useState(r);fi(h,r)||p(r);const[g,x]=v.useState(null),[y,m]=v.useState(null),b=v.useCallback($=>{$!==C.current&&(C.current=$,x($))},[]),S=v.useCallback($=>{$!==E.current&&(E.current=$,m($))},[]),T=s||g,k=i||y,C=v.useRef(null),E=v.useRef(null),R=v.useRef(d),_=l!=null,j=fl(l),D=fl(o),z=fl(c),W=v.useCallback(()=>{if(!C.current||!E.current)return;const $={placement:t,strategy:n,middleware:h};D.current&&($.platform=D.current),q0(C.current,E.current,$).then(F=>{const ee={...F,isPositioned:z.current!==!1};O.current&&!fi(R.current,ee)&&(R.current=ee,Yo.flushSync(()=>{f(ee)}))})},[h,t,n,D,z]);di(()=>{c===!1&&R.current.isPositioned&&(R.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const O=v.useRef(!1);di(()=>(O.current=!0,()=>{O.current=!1}),[]),di(()=>{if(T&&(C.current=T),k&&(E.current=k),T&&k){if(j.current)return j.current(T,k,W);W()}},[T,k,W,j,_]);const B=v.useMemo(()=>({reference:C,floating:E,setReference:b,setFloating:S}),[b,S]),P=v.useMemo(()=>({reference:T,floating:k}),[T,k]),V=v.useMemo(()=>{const $={position:n,left:0,top:0};if(!P.floating)return $;const F=qf(P.floating,d.x),ee=qf(P.floating,d.y);return a?{...$,transform:"translate("+F+"px, "+ee+"px)",...Kf(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:F,top:ee}},[n,a,P.floating,d.x,d.y]);return v.useMemo(()=>({...d,update:W,refs:B,elements:P,floatingStyles:V}),[d,W,B,P,V])}const J0=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?Vf({element:r.current,padding:o}).fn(n):{}:r?Vf({element:r,padding:o}).fn(n):{}}}},Z0=(e,t)=>({...B0(e),options:[e,t]}),Q0=(e,t)=>({...H0(e),options:[e,t]}),eS=(e,t)=>({...K0(e),options:[e,t]}),tS=(e,t)=>({...U0(e),options:[e,t]}),nS=(e,t)=>({...W0(e),options:[e,t]}),rS=(e,t)=>({...V0(e),options:[e,t]}),oS=(e,t)=>({...J0(e),options:[e,t]});var sS="Arrow",Gf=v.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return u.jsx(Oe.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"})})});Gf.displayName=sS;var iS=Gf;function Yf(e){const[t,n]=v.useState(void 0);return Kt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var hl="Popper",[Xf,hi]=Yn(hl),[aS,Jf]=Xf(hl),Zf=e=>{const{__scopePopper:t,children:n}=e,[r,o]=v.useState(null);return u.jsx(aS,{scope:t,anchor:r,onAnchorChange:o,children:n})};Zf.displayName=hl;var Qf="PopperAnchor",eh=v.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Jf(Qf,n),i=v.useRef(null),a=Je(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(Oe.div,{...o,ref:a})});eh.displayName=Qf;var pl="PopperContent",[lS,cS]=Xf(pl),th=v.forwardRef((e,t)=>{var ne,L,J,se,ue,le;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:h=!1,updatePositionStrategy:p="optimized",onPlaced:g,...x}=e,y=Jf(pl,n),[m,b]=v.useState(null),S=Je(t,Me=>b(Me)),[T,k]=v.useState(null),C=Yf(T),E=(C==null?void 0:C.width)??0,R=(C==null?void 0:C.height)??0,_=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},D=Array.isArray(c)?c:[c],z=D.length>0,W={padding:j,boundary:D.filter(dS),altBoundary:z},{refs:O,floatingStyles:B,placement:P,isPositioned:V,middlewareData:$}=X0({strategy:"fixed",placement:_,whileElementsMounted:(...Me)=>z0(...Me,{animationFrame:p==="always"}),elements:{reference:y.anchor},middleware:[Z0({mainAxis:o+R,alignmentAxis:i}),l&&Q0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?eS():void 0,...W}),l&&tS({...W}),nS({...W,apply:({elements:Me,rects:U,availableWidth:ye,availableHeight:_e})=>{const{width:Pe,height:et}=U.reference,nt=Me.floating.style;nt.setProperty("--radix-popper-available-width",`${ye}px`),nt.setProperty("--radix-popper-available-height",`${_e}px`),nt.setProperty("--radix-popper-anchor-width",`${Pe}px`),nt.setProperty("--radix-popper-anchor-height",`${et}px`)}}),T&&oS({element:T,padding:a}),fS({arrowWidth:E,arrowHeight:R}),h&&rS({strategy:"referenceHidden",...W})]}),[F,ee]=oh(P),te=qt(g);Kt(()=>{V&&(te==null||te())},[V,te]);const ve=(ne=$.arrow)==null?void 0:ne.x,Ie=(L=$.arrow)==null?void 0:L.y,Z=((J=$.arrow)==null?void 0:J.centerOffset)!==0,[de,we]=v.useState();return Kt(()=>{m&&we(window.getComputedStyle(m).zIndex)},[m]),u.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:V?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:de,"--radix-popper-transform-origin":[(se=$.transformOrigin)==null?void 0:se.x,(ue=$.transformOrigin)==null?void 0:ue.y].join(" "),...((le=$.hide)==null?void 0:le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(lS,{scope:n,placedSide:F,onArrowChange:k,arrowX:ve,arrowY:Ie,shouldHideArrow:Z,children:u.jsx(Oe.div,{"data-side":F,"data-align":ee,...x,ref:S,style:{...x.style,animation:V?void 0:"none"}})})})});th.displayName=pl;var nh="PopperArrow",uS={top:"bottom",right:"left",bottom:"top",left:"right"},rh=v.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=cS(nh,r),i=uS[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(iS,{...o,ref:n,style:{...o.style,display:"block"}})})});rh.displayName=nh;function dS(e){return e!==null}var fS=e=>({name:"transformOrigin",options:e,fn(t){var y,m,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]=oh(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((m=o.arrow)==null?void 0:m.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let g="",x="";return c==="bottom"?(g=i?f:`${h}px`,x=`${-l}px`):c==="top"?(g=i?f:`${h}px`,x=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,x=i?f:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:g,y:x}}}});function oh(e){const[t,n="center"]=e.split("-");return[t,n]}var sh=Zf,ih=eh,ah=th,lh=rh,ml="rovingFocusGroup.onEntryFocus",hS={bubbles:!1,cancelable:!0},Do="RovingFocusGroup",[gl,ch,pS]=tl(Do),[mS,uh]=Yn(Do,[pS]),[gS,xS]=mS(Do),dh=v.forwardRef((e,t)=>u.jsx(gl.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(gl.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(yS,{...e,ref:t})})}));dh.displayName=Do;var yS=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,h=v.useRef(null),p=Je(t,h),g=ni(s),[x,y]=Wr({prop:i,defaultProp:a??null,onChange:l,caller:Do}),[m,b]=v.useState(!1),S=qt(c),T=ch(n),k=v.useRef(!1),[C,E]=v.useState(0);return v.useEffect(()=>{const R=h.current;if(R)return R.addEventListener(ml,S),()=>R.removeEventListener(ml,S)},[S]),u.jsx(gS,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:x,onItemFocus:v.useCallback(R=>y(R),[y]),onItemShiftTab:v.useCallback(()=>b(!0),[]),onFocusableItemAdd:v.useCallback(()=>E(R=>R+1),[]),onFocusableItemRemove:v.useCallback(()=>E(R=>R-1),[]),children:u.jsx(Oe.div,{tabIndex:m||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ge(e.onMouseDown,()=>{k.current=!0}),onFocus:ge(e.onFocus,R=>{const _=!k.current;if(R.target===R.currentTarget&&_&&!m){const j=new CustomEvent(ml,hS);if(R.currentTarget.dispatchEvent(j),!j.defaultPrevented){const D=T().filter(P=>P.focusable),z=D.find(P=>P.active),W=D.find(P=>P.id===x),B=[z,W,...D].filter(Boolean).map(P=>P.ref.current);ph(B,d)}}k.current=!1}),onBlur:ge(e.onBlur,()=>b(!1))})})}),fh="RovingFocusGroupItem",hh=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Xn(),c=s||l,d=xS(fh,n),f=d.currentTabStopId===c,h=ch(n),{onFocusableItemAdd:p,onFocusableItemRemove:g,currentTabStopId:x}=d;return v.useEffect(()=>{if(r)return p(),()=>g()},[r,p,g]),u.jsx(gl.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:u.jsx(Oe.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ge(e.onMouseDown,y=>{r?d.onItemFocus(c):y.preventDefault()}),onFocus:ge(e.onFocus,()=>d.onItemFocus(c)),onKeyDown:ge(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){d.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const m=bS(y,d.orientation,d.dir);if(m!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=h().filter(T=>T.focusable).map(T=>T.ref.current);if(m==="last")S.reverse();else if(m==="prev"||m==="next"){m==="prev"&&S.reverse();const T=S.indexOf(y.currentTarget);S=d.loop?SS(S,T+1):S.slice(T+1)}setTimeout(()=>ph(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});hh.displayName=fh;var vS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function bS(e,t,n){const r=wS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return vS[r]}function ph(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function SS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var CS=dh,kS=hh,xl=["Enter"," "],TS=["ArrowDown","PageUp","Home"],mh=["ArrowUp","PageDown","End"],ES=[...TS,...mh],IS={ltr:[...xl,"ArrowRight"],rtl:[...xl,"ArrowLeft"]},NS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Lo="Menu",[Fo,AS,_S]=tl(Lo),[_r,gh]=Yn(Lo,[_S,hi,uh]),pi=hi(),xh=uh(),[jS,jr]=_r(Lo),[RS,$o]=_r(Lo),yh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=pi(t),[l,c]=v.useState(null),d=v.useRef(!1),f=qt(s),h=ni(o);return v.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.jsx(sh,{...a,children:u.jsx(jS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:u.jsx(RS,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};yh.displayName=Lo;var PS="MenuAnchor",yl=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=pi(n);return u.jsx(ih,{...o,...r,ref:t})});yl.displayName=PS;var vl="MenuPortal",[OS,vh]=_r(vl,{forceMount:void 0}),wh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=jr(vl,t);return u.jsx(OS,{scope:t,forceMount:n,children:u.jsx(wn,{present:n||s.open,children:u.jsx(Ms,{asChild:!0,container:o,children:r})})})};wh.displayName=vl;var bn="MenuContent",[MS,wl]=_r(bn),bh=v.forwardRef((e,t)=>{const n=vh(bn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=jr(bn,e.__scopeMenu),i=$o(bn,e.__scopeMenu);return u.jsx(Fo.Provider,{scope:e.__scopeMenu,children:u.jsx(wn,{present:r||s.open,children:u.jsx(Fo.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(DS,{...o,ref:t}):u.jsx(LS,{...o,ref:t})})})})}),DS=v.forwardRef((e,t)=>{const n=jr(bn,e.__scopeMenu),r=v.useRef(null),o=Je(t,r);return v.useEffect(()=>{const s=r.current;if(s)return qa(s)},[]),u.jsx(bl,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ge(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),LS=v.forwardRef((e,t)=>{const n=jr(bn,e.__scopeMenu);return u.jsx(bl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),FS=xr.createSlot("MenuContent.ScrollLock"),bl=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:h,onDismiss:p,disableOutsideScroll:g,...x}=e,y=jr(bn,n),m=$o(bn,n),b=pi(n),S=xh(n),T=AS(n),[k,C]=v.useState(null),E=v.useRef(null),R=Je(t,E,y.onContentChange),_=v.useRef(0),j=v.useRef(""),D=v.useRef(0),z=v.useRef(null),W=v.useRef("right"),O=v.useRef(0),B=g?Hs:v.Fragment,P=g?{as:FS,allowPinchZoom:!0}:void 0,V=F=>{var ne,L;const ee=j.current+F,te=T().filter(J=>!J.disabled),ve=document.activeElement,Ie=(ne=te.find(J=>J.ref.current===ve))==null?void 0:ne.textValue,Z=te.map(J=>J.textValue),de=XS(Z,ee,Ie),we=(L=te.find(J=>J.textValue===de))==null?void 0:L.ref.current;(function J(se){j.current=se,window.clearTimeout(_.current),se!==""&&(_.current=window.setTimeout(()=>J(""),1e3))})(ee),we&&setTimeout(()=>we.focus())};v.useEffect(()=>()=>window.clearTimeout(_.current),[]),Ba();const $=v.useCallback(F=>{var te,ve;return W.current===((te=z.current)==null?void 0:te.side)&&ZS(F,(ve=z.current)==null?void 0:ve.area)},[]);return u.jsx(MS,{scope:n,searchRef:j,onItemEnter:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),onItemLeave:v.useCallback(F=>{var ee;$(F)||((ee=E.current)==null||ee.focus(),C(null))},[$]),onTriggerLeave:v.useCallback(F=>{$(F)&&F.preventDefault()},[$]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(F=>{z.current=F},[]),children:u.jsx(B,{...P,children:u.jsx(Os,{asChild:!0,trapped:o,onMountAutoFocus:ge(s,F=>{var ee;F.preventDefault(),(ee=E.current)==null||ee.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Ps,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:u.jsx(CS,{asChild:!0,...S,dir:m.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:ge(l,F=>{m.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(ah,{role:"menu","aria-orientation":"vertical","data-state":Fh(y.open),"data-radix-menu-content":"",dir:m.dir,...b,...x,ref:R,style:{outline:"none",...x.style},onKeyDown:ge(x.onKeyDown,F=>{const te=F.target.closest("[data-radix-menu-content]")===F.currentTarget,ve=F.ctrlKey||F.altKey||F.metaKey,Ie=F.key.length===1;te&&(F.key==="Tab"&&F.preventDefault(),!ve&&Ie&&V(F.key));const Z=E.current;if(F.target!==Z||!ES.includes(F.key))return;F.preventDefault();const we=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);mh.includes(F.key)&&we.reverse(),GS(we)}),onBlur:ge(e.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(_.current),j.current="")}),onPointerMove:ge(e.onPointerMove,Bo(F=>{const ee=F.target,te=O.current!==F.clientX;if(F.currentTarget.contains(ee)&&te){const ve=F.clientX>O.current?"right":"left";W.current=ve,O.current=F.clientX}}))})})})})})})});bh.displayName=bn;var $S="MenuGroup",Sl=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Oe.div,{role:"group",...r,ref:t})});Sl.displayName=$S;var zS="MenuLabel",Sh=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Oe.div,{...r,ref:t})});Sh.displayName=zS;var mi="MenuItem",Ch="menu.itemSelect",gi=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=v.useRef(null),i=$o(mi,e.__scopeMenu),a=wl(mi,e.__scopeMenu),l=Je(t,s),c=v.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Ch,{bubbles:!0,cancelable:!0});f.addEventListener(Ch,p=>r==null?void 0:r(p),{once:!0}),md(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(kh,{...o,ref:l,disabled:n,onClick:ge(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ge(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ge(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||xl.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});gi.displayName=mi;var kh=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=wl(mi,n),a=xh(n),l=v.useRef(null),c=Je(t,l),[d,f]=v.useState(!1),[h,p]=v.useState("");return v.useEffect(()=>{const g=l.current;g&&p((g.textContent??"").trim())},[s.children]),u.jsx(Fo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:u.jsx(kS,{asChild:!0,...a,focusable:!r,children:u.jsx(Oe.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ge(e.onPointerMove,Bo(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ge(e.onPointerLeave,Bo(g=>i.onItemLeave(g))),onFocus:ge(e.onFocus,()=>f(!0)),onBlur:ge(e.onBlur,()=>f(!1))})})})}),BS="MenuCheckboxItem",Th=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return u.jsx(_h,{scope:e.__scopeMenu,checked:n,children:u.jsx(gi,{role:"menuitemcheckbox","aria-checked":xi(n)?"mixed":n,...o,ref:t,"data-state":kl(n),onSelect:ge(o.onSelect,()=>r==null?void 0:r(xi(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Th.displayName=BS;var Eh="MenuRadioGroup",[HS,US]=_r(Eh,{value:void 0,onValueChange:()=>{}}),Ih=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=qt(r);return u.jsx(HS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(Sl,{...o,ref:t})})});Ih.displayName=Eh;var Nh="MenuRadioItem",Ah=v.forwardRef((e,t)=>{const{value:n,...r}=e,o=US(Nh,e.__scopeMenu),s=n===o.value;return u.jsx(_h,{scope:e.__scopeMenu,checked:s,children:u.jsx(gi,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":kl(s),onSelect:ge(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Ah.displayName=Nh;var Cl="MenuItemIndicator",[_h,WS]=_r(Cl,{checked:!1}),jh=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=WS(Cl,n);return u.jsx(wn,{present:r||xi(s.checked)||s.checked===!0,children:u.jsx(Oe.span,{...o,ref:t,"data-state":kl(s.checked)})})});jh.displayName=Cl;var VS="MenuSeparator",Rh=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(Oe.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Rh.displayName=VS;var KS="MenuArrow",Ph=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=pi(n);return u.jsx(lh,{...o,...r,ref:t})});Ph.displayName=KS;var qS="MenuSub",[jT,Oh]=_r(qS),zo="MenuSubTrigger",Mh=v.forwardRef((e,t)=>{const n=jr(zo,e.__scopeMenu),r=$o(zo,e.__scopeMenu),o=Oh(zo,e.__scopeMenu),s=wl(zo,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(yl,{asChild:!0,...c,children:u.jsx(kh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Fh(n.open),...e,ref:Da(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ge(e.onPointerMove,Bo(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:ge(e.onPointerLeave,Bo(f=>{var p,g;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(g=n.content)==null?void 0:g.dataset.side,y=x==="right",m=y?-5:5,b=h[y?"left":"right"],S=h[y?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+m,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ge(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||IS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Mh.displayName=zo;var Dh="MenuSubContent",Lh=v.forwardRef((e,t)=>{const n=vh(bn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=jr(bn,e.__scopeMenu),i=$o(bn,e.__scopeMenu),a=Oh(Dh,e.__scopeMenu),l=v.useRef(null),c=Je(t,l);return u.jsx(Fo.Provider,{scope:e.__scopeMenu,children:u.jsx(wn,{present:r||s.open,children:u.jsx(Fo.Slot,{scope:e.__scopeMenu,children:u.jsx(bl,{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:ge(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ge(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ge(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=NS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Lh.displayName=Dh;function Fh(e){return e?"open":"closed"}function xi(e){return e==="indeterminate"}function kl(e){return xi(e)?"indeterminate":e?"checked":"unchecked"}function GS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function YS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function XS(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=YS(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 JS(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,h=l.y;d>r!=h>r&&n<(f-c)*(r-d)/(h-d)+c&&(o=!o)}return o}function ZS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return JS(n,t)}function Bo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var QS=yh,eC=yl,tC=wh,nC=bh,rC=Sl,oC=Sh,sC=gi,iC=Th,aC=Ih,lC=Ah,cC=jh,uC=Rh,dC=Ph,fC=Mh,hC=Lh,yi="DropdownMenu",[pC,RT]=Yn(yi,[gh]),rn=gh(),[mC,$h]=pC(yi),zh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=rn(t),c=v.useRef(null),[d,f]=Wr({prop:o,defaultProp:s??!1,onChange:i,caller:yi});return u.jsx(mC,{scope:t,triggerId:Xn(),triggerRef:c,contentId:Xn(),open:d,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:a,children:u.jsx(QS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};zh.displayName=yi;var Bh="DropdownMenuTrigger",Hh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=$h(Bh,n),i=rn(n);return u.jsx(eC,{asChild:!0,...i,children:u.jsx(Oe.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:Da(t,s.triggerRef),onPointerDown:ge(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ge(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Hh.displayName=Bh;var gC="DropdownMenuPortal",Uh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=rn(t);return u.jsx(tC,{...r,...n})};Uh.displayName=gC;var Wh="DropdownMenuContent",Vh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=$h(Wh,n),s=rn(n),i=v.useRef(!1);return u.jsx(nC,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ge(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ge(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)"}})});Vh.displayName=Wh;var xC="DropdownMenuGroup",yC=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(rC,{...o,...r,ref:t})});yC.displayName=xC;var vC="DropdownMenuLabel",Kh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(oC,{...o,...r,ref:t})});Kh.displayName=vC;var wC="DropdownMenuItem",qh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(sC,{...o,...r,ref:t})});qh.displayName=wC;var bC="DropdownMenuCheckboxItem",Gh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(iC,{...o,...r,ref:t})});Gh.displayName=bC;var SC="DropdownMenuRadioGroup",CC=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(aC,{...o,...r,ref:t})});CC.displayName=SC;var kC="DropdownMenuRadioItem",Yh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(lC,{...o,...r,ref:t})});Yh.displayName=kC;var TC="DropdownMenuItemIndicator",Xh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(cC,{...o,...r,ref:t})});Xh.displayName=TC;var EC="DropdownMenuSeparator",Jh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(uC,{...o,...r,ref:t})});Jh.displayName=EC;var IC="DropdownMenuArrow",NC=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(dC,{...o,...r,ref:t})});NC.displayName=IC;var AC="DropdownMenuSubTrigger",Zh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(fC,{...o,...r,ref:t})});Zh.displayName=AC;var _C="DropdownMenuSubContent",Qh=v.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=rn(n);return u.jsx(hC,{...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)"}})});Qh.displayName=_C;var jC=zh,RC=Hh,PC=Uh,ep=Vh,tp=Kh,np=qh,rp=Gh,op=Yh,sp=Xh,ip=Jh,ap=Zh,lp=Qh;const OC=jC,MC=RC,DC=v.forwardRef(({className:e,inset:t,children:n,...r},o)=>u.jsxs(ap,{ref:o,className:oe("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(he.ChevronRight,{className:"ml-auto h-4 w-4"})]}));DC.displayName=ap.displayName;const LC=v.forwardRef(({className:e,...t},n)=>u.jsx(lp,{ref:n,className:oe("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}));LC.displayName=lp.displayName;const cp=v.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(PC,{children:u.jsx(ep,{ref:r,sideOffset:t,className:oe("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})}));cp.displayName=ep.displayName;const Tl=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(np,{ref:r,className:oe("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}));Tl.displayName=np.displayName;const FC=v.forwardRef(({className:e,children:t,checked:n,...r},o)=>u.jsxs(rp,{ref:o,className:oe("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(sp,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),t]}));FC.displayName=rp.displayName;const $C=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(op,{ref:r,className:oe("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(sp,{children:u.jsx(he.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));$C.displayName=op.displayName;const zC=v.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(tp,{ref:r,className:oe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));zC.displayName=tp.displayName;const BC=v.forwardRef(({className:e,...t},n)=>u.jsx(ip,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));BC.displayName=ip.displayName;const up={value:""};function vi({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,customStyles:f={},onMessageSent:h,onExcelUploadSuccess:p,onError:g}){const{api:x}=qi(),{currentThreadId:y}=ps(),{threadId:m,messages:b,hasMore:S,isHistoryLoading:T,isLoading:k,loadOlder:C,navigateToCheckpoint:E,returnToLatest:R,checkpoint:_,checkpoints:j,interrupt:D,metadata:z}=ms(),{isStreaming:W,error:O,connectionState:B,submit:P,stop:V}=au(),$=m??y??null,F=(_==null?void 0:_.id)??null,ee=(_==null?void 0:_.namespace)??null,te=(z==null?void 0:z.assemblingMessageId)??null,ve=D,[Ie,Z]=w.useState(!1);w.useEffect(()=>{ve||Z(!1)},[ve]);const de=w.useCallback(()=>{Z(!0)},[]),we=w.useCallback(()=>{Z(!1)},[]),ne=!!ve||Ie,[L,J]=w.useState(null),[se,ue]=w.useState(""),[le,Me]=w.useState(null),[U,ye]=w.useState(null),[_e,Pe]=w.useState([]),[et,nt]=w.useState(0),[Ze,be]=w.useState(0),[Qe,it]=w.useState(!1),[rt,Be]=w.useState(null),[wt,mt]=w.useState(null),[jt,Dt]=w.useState(!1),[bt,He]=w.useState(null),[St,Ct]=w.useState(!1),Lt=w.useRef(!1),[Ft,at]=w.useState(()=>up.value),De=w.useRef(Ft),Rt=w.useRef(null),kt=w.useCallback(Y=>{up.value=Y,at(Y)},[]),[q,ke]=w.useState(!1),xe=w.useCallback(Y=>{if(!Array.isArray(Y))return{text:null,messageId:null};for(let fe=Y.length-1;fe>=0;fe--){const ce=Y[fe];if(!ce||ce.role!=="user")continue;const pt=(ce.content??[]).filter(lt=>(lt==null?void 0:lt.type)==="text").map(lt=>lt.text).filter(lt=>typeof lt=="string"&&lt.trim().length>0);return{text:pt.length?pt.join(" ").trim():null,messageId:ce.id??null}}return{text:null,messageId:null}},[]),ot=w.useCallback((Y,fe)=>{if(!Y||typeof Y!="object")return null;const ce=Y[fe];return typeof ce=="number"?ce:null},[]),ft=w.useCallback((Y,fe)=>{if(!Y||typeof Y!="object")return null;const ce=Y[fe];return typeof ce=="string"&&ce.trim()?ce:null},[]),tt=w.useMemo(()=>{const Y=Array.isArray(j)?[...j]:[];return Y.some(ce=>ot(ce.metadata,"step")!==null)&&Y.sort((ce,pt)=>{const At=ot(ce.metadata,"step"),lt=ot(pt.metadata,"step");if(At!==null||lt!==null)return(lt??Number.NEGATIVE_INFINITY)-(At??Number.NEGATIVE_INFINITY);const kn=Date.parse(ce.createdAt??""),dn=Date.parse(pt.createdAt??"");return Number.isNaN(kn)||Number.isNaN(dn)?0:dn-kn}),Y},[j,ot]),{checkpointMetaById:Fe,checkpointIndexByKey:en}=w.useMemo(()=>{const Y=new Map,fe=new Map;for(const ce of tt){const pt=ce.checkpointId??null;if(!pt)continue;const At=ot(ce.metadata,"step"),lt=ft(ce.metadata,"source"),kn={id:pt,step:At,source:lt,createdAt:ce.createdAt??null,namespace:ce.checkpointNs??null,parentId:ce.parentId??null};if(Y.set(pt,kn),At!==null&&lt){const dn=`${At}:${lt}`,on=fe.get(dn)??[];on.push(kn),fe.set(dn,on)}}for(const ce of fe.values())ce.sort((pt,At)=>{const lt=pt.createdAt??"";return(At.createdAt??"").localeCompare(lt)});return{checkpointMetaById:Y,checkpointIndexByKey:fe}},[tt,ot,ft]),$e=w.useMemo(()=>{if(!tt.length)return[];const Y=[...tt].reverse(),fe=pt=>{const At=[];for(const lt of Y){const kn=lt.checkpointId??null;if(!kn)continue;const dn=ft(lt.metadata,"source"),on=(dn==null?void 0:dn.toLowerCase())??null,Uo=on==="input"||on==="user_input"||on==="user";if(pt&&!Uo)continue;const{text:ro,messageId:Wo}=xe(lt.messages);if(!ro&&!Wo&&pt)continue;const Dr=ro&&ro.replace(/\s+/g," ").trim()||ft(lt.metadata,"title")||ft(lt.metadata,"label")||(Uo?"User input":dn??"Checkpoint"),_i=Dr?Dr.length>60?`${Dr.slice(0,57)}…`:Dr:"User input";At.push({id:kn,label:_i,messageId:Wo??null,createdAt:lt.createdAt??null,step:ot(lt.metadata,"step"),source:dn??null})}return At};let ce=fe(!0);return ce.length||(ce=fe(!1)),ce},[tt,xe,ot,ft]),ht=w.useRef(null),On=w.useRef(null),Vn=w.useCallback(()=>{ht.current&&(ht.current.value=""),On.current&&(On.current.value=""),nt(Y=>Y+1),be(Y=>Y+1)},[]),hr=w.useCallback(Y=>{kt(Y)},[kt]),pr=w.useRef(!1);w.useEffect(()=>{pr.current&&!W&&(Pe([]),Vn()),pr.current=W},[W,Vn]);const[Mr,Qn]=w.useState("desktop");w.useEffect(()=>{const Y=()=>{const fe=window.innerWidth;Qn(fe<640?"phone":fe<1024?"tablet":"desktop")};return Y(),window.addEventListener("resize",Y),()=>window.removeEventListener("resize",Y)},[]),w.useEffect(()=>{Ct(!1),Lt.current=!1},[$]),w.useEffect(()=>{De.current=Ft},[Ft]),w.useEffect(()=>{if(!L){Rt.current=null;return}Rt.current===null&&(Rt.current=De.current),kt(se??"")},[se,L,kt]);const no=w.useCallback(async()=>{if(!(!S||T||!St))try{await C()}catch(Y){console.warn("loadOlder failed",Y)}},[S,St,T,C]);w.useEffect(()=>{(async()=>{if(!x.baseUrl){He(null);return}try{const ce=(await x.getAgent("default")).uiDefaultMessage||"";He(ce||null)}catch(fe){console.warn("Failed to fetch default message:",fe),He(null)}})()},[x.baseUrl]),w.useEffect(()=>{O&&!jt&&(g==null||g(O))},[O,jt,g]);const I=Y=>{if(Y.length>ti)return`Message too long (${Y.length}/${ti} characters)`;try{return qb(Y),null}catch(fe){return(fe==null?void 0:fe.message)||"Invalid message"}},G=async Y=>{const fe=Y.trim();if(!(!fe&&_e.length===0)){if(fe){const ce=I(fe);if(ce){ye(ce);return}}try{const ce=F??void 0,pt=ee??void 0,At=L?{edit:!0,originalMessageId:L,...le!=null&&le.checkpointId?{originalCheckpointId:le.checkpointId}:{},...le!=null&&le.checkpointNs?{originalCheckpointNs:le.checkpointNs}:{}}:void 0;await P({text:fe||"",attachments:_e,messageAdditionalKwargs:At},{checkpointId:ce,checkpointNs:pt}),h==null||h(fe),kt(""),ye(null),Pe([]),Vn(),J(null),ue(""),Me(null)}catch(ce){const pt=(ce==null?void 0:ce.message)||"Failed to send message";ye(pt),g==null||g(pt)}}},ie=w.useCallback((Y,fe,ce)=>{c&&(Rt.current=Ft,J(Y),ue(fe),kt(fe),ye(null),Me({checkpointId:(ce==null?void 0:ce.checkpointId)??null,checkpointNs:(ce==null?void 0:ce.checkpointNs)??null}))},[Ft,c,kt]),Ce=w.useCallback(()=>{J(null),ue(""),Me(null),ye(null),kt(Rt.current??Ft),Rt.current=null},[Ft,kt]),Ye=w.useCallback((Y,fe,ce)=>{ie(Y,fe,ce)},[ie]),ct=w.useCallback(Y=>{for(let fe=Y-1;fe>=0;fe--)if(b[fe].role==="user"){const ce=b[fe].content||[],At=ce.filter(lt=>lt.type==="text").map(lt=>lt.text).join("")||(()=>{try{return JSON.stringify(ce,null,2)}catch{return String(ce)}})();At&&P({text:At},{checkpointId:F??void 0,checkpointNs:ee??void 0});break}},[b,P,F,ee]),Ke=Y=>{const fe=Array.from(Y.target.files||[]);Pe(ce=>[...ce,...fe]),Y.target.value=""},Ue=Y=>{Pe(fe=>{const ce=fe.filter((pt,At)=>Y!==At);return ce.length===0&&Vn(),ce})},Pt=async Y=>{const fe=(Y.target.files||[])[0];if(fe){Be(null),mt(null),it(!0);try{await P({attachments:[fe]},{checkpointId:F??void 0,checkpointNs:ee??void 0});const ce=`Uploaded ${fe.name} - processing through chat stream`;mt(ce)}catch(ce){const pt=ce instanceof Error?ce.message:"Failed to upload Excel file";console.error("Excel upload failed",ce),Be(pt),g==null||g(pt)}finally{it(!1),Y.target.value="",Vn()}}},gt=async Y=>{if(y){ke(!0);try{if(!Y){await R();return}const fe=tt.find(pt=>pt.checkpointId===Y),ce=(fe==null?void 0:fe.checkpointNs)??null;await E(Y,ce)}finally{ke(!1)}}},xt=w.useCallback(async Y=>{await gt(Y)},[gt]),Gt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,Yt=`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 ${f.messagesArea||""}`,un=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,Ut=w.useCallback(Y=>{if(!Y)return"Latest";const fe=[];Y.step!==null&&fe.push(`Step ${Y.step}`),Y.source&&fe.push(Y.source);const ce=Y.createdAt?new Date(Y.createdAt):null,pt=ce&&!Number.isNaN(ce.getTime())?ce.toLocaleString():Y.createdAt??Y.id,At=fe.length?` — ${fe.join(" • ")}`:"";return`${pt}${At}`},[]);return u.jsxs("div",{className:Gt,children:[!!O&&!jt&&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:O}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>Dt(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(he.X,{size:16})})]}),y&&tt.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:F??"",onChange:Y=>{const fe=Y.target.value||null;gt(fe)},children:[u.jsx("option",{value:"",children:"Latest"}),tt.map(Y=>{const fe=Fe.get(Y.checkpointId??"")??null;return u.jsx("option",{value:Y.checkpointId??void 0,children:Ut(fe)},Y.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${Yt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(el,{className:"h-full",style:{height:"100%"},messages:b,isStreaming:W,streamingAssistantId:te,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Mr,enableMessageEditing:c,editingMessageId:L,onStartReached:()=>{St&&no()},onScrollAway:Y=>{if(!Lt.current){Lt.current=!0;return}Y&&Ct(!0)},onEdit:Ye,onRegenerate:ct,onCancelEdit:Ce,emptyMessage:bt??void 0,isNavigatingCheckpoint:q,activeInterrupt:ve,disableInterruptActions:Ie,onInterruptActionStart:de,onInterruptActionEnd:we,showToolMessages:d,checkpointMetaById:Fe,checkpointIndexByKey:en,activeCheckpointId:F,onSelectCheckpoint:xt,timelineCheckpoints:$e}),(B==="reconnecting"||B==="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(he.Loader2,{className:"h-3 w-3 animate-spin"}),B==="reconnecting"?"Reconnecting…":"Connecting…"]})}),B==="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"}),k&&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(he.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),u.jsxs("div",{className:un,children:[L&&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(he.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:Ce,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(he.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:ht,type:"file",multiple:!0,onChange:Y=>Ke(Y),className:"hidden"},et),_e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:_e.map((Y,fe)=>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(he.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:Y.name}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>Ue(fe),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 ${Y.name}`,children:u.jsx(he.X,{size:12})})]},fe))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:On,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Pt,className:"hidden"},Ze),Qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(he.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),wt&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:wt}),rt&&!Qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:rt})]})]}),U&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:U}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(OC,{children:[u.jsx(MC,{asChild:!0,children:u.jsx(ut,{type:"button",size:"icon",variant:"outline",disabled:W||ne,title:"More input actions",className:f.moreButton||"",children:u.jsx(he.Plus,{size:16})})}),u.jsxs(cp,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Tl,{onClick:()=>{var Y;return(Y=ht.current)==null?void 0:Y.click()},className:"cursor-pointer",children:[u.jsx(he.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Tl,{onClick:()=>{var Y;Qe||(Y=On.current)==null||Y.click()},className:`cursor-pointer ${Qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(he.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(dy,{initialValue:se,editingMessageId:L,value:Ft,onValueChange:hr,placeholder:L?"Edit your message...":t,isStreaming:W,disabled:ne,maxLength:ti,onSend:G,onCancelEdit:Ce,onStop:V,allowEmptySend:_e.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${L?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${U?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const wi=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:oe("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}));wi.displayName="Input";function El(e,[t,n]){return Math.min(n,Math.max(t,e))}function HC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Il="ScrollArea",[dp,PT]=Yn(Il),[UC,Sn]=dp(Il),fp=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,h]=v.useState(null),[p,g]=v.useState(null),[x,y]=v.useState(null),[m,b]=v.useState(0),[S,T]=v.useState(0),[k,C]=v.useState(!1),[E,R]=v.useState(!1),_=Je(t,D=>l(D)),j=ni(o);return u.jsx(UC,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:g,scrollbarXEnabled:k,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:R,onCornerWidthChange:b,onCornerHeightChange:T,children:u.jsx(Oe.div,{dir:j,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":m+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});fp.displayName=Il;var hp="ScrollAreaViewport",pp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Sn(hp,n),a=v.useRef(null),l=Je(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(Oe.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})})]})});pp.displayName=hp;var Wn="ScrollAreaScrollbar",Nl=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sn(Wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(WC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(VC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(mp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Al,{...r,ref:t}):null});Nl.displayName=Wn;var WC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sn(Wn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(wn,{present:n||s,children:u.jsx(mp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),VC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Sn(Wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ki(()=>l("SCROLL_END"),100),[a,l]=HC("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(wn,{present:n||a!=="hidden",children:u.jsx(Al,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ge(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ge(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),mp=v.forwardRef((e,t)=>{const n=Sn(Wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=ki(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Qr(n.viewport,l),Qr(n.content,l),u.jsx(wn,{present:r||s,children:u.jsx(Al,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Al=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Sn(Wn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=wp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return JC(h,i.current,a,p)}return n==="horizontal"?u.jsx(KC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=bp(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(qC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=bp(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),KC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Sn(Wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Je(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(xp,{"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":Ci(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Cp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Si(i.paddingLeft),paddingEnd:Si(i.paddingRight)}})}})}),qC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Sn(Wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Je(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(xp,{"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":Ci(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Cp(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Si(i.paddingTop),paddingEnd:Si(i.paddingBottom)}})}})}),[GC,gp]=dp(Wn),xp=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,...h}=e,p=Sn(Wn,n),[g,x]=v.useState(null),y=Je(t,_=>x(_)),m=v.useRef(null),b=v.useRef(""),S=p.viewport,T=r.content-r.viewport,k=qt(d),C=qt(l),E=ki(f,10);function R(_){if(m.current){const j=_.clientX-m.current.left,D=_.clientY-m.current.top;c({x:j,y:D})}}return v.useEffect(()=>{const _=j=>{const D=j.target;(g==null?void 0:g.contains(D))&&k(j,T)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,g,T,k]),v.useEffect(C,[r,C]),Qr(g,E),Qr(p.content,E),u.jsx(GC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:qt(s),onThumbPointerUp:qt(i),onThumbPositionChange:C,onThumbPointerDown:qt(a),children:u.jsx(Oe.div,{...h,ref:y,style:{position:"absolute",...h.style},onPointerDown:ge(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),m.current=g.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),R(_))}),onPointerMove:ge(e.onPointerMove,R),onPointerUp:ge(e.onPointerUp,_=>{const j=_.target;j.hasPointerCapture(_.pointerId)&&j.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),m.current=null})})})}),bi="ScrollAreaThumb",yp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=gp(bi,e.__scopeScrollArea);return u.jsx(wn,{present:n||o.hasThumb,children:u.jsx(YC,{ref:t,...r})})}),YC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Sn(bi,n),i=gp(bi,n),{onThumbPositionChange:a}=i,l=Je(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=ki(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=ZC(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(Oe.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:ge(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),g=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:g,y:x})}),onPointerUp:ge(e.onPointerUp,i.onThumbPointerUp)})});yp.displayName=bi;var _l="ScrollAreaCorner",vp=v.forwardRef((e,t)=>{const n=Sn(_l,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(XC,{...e,ref:t}):null});vp.displayName=_l;var XC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Sn(_l,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Qr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Qr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Oe.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 Si(e){return e?parseInt(e,10):0}function wp(e,t){const n=e/t;return isNaN(n)?0:n}function Ci(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 JC(e,t,n,r="ltr"){const o=Ci(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 Sp([l,c],f)(e)}function bp(e,t,n="ltr"){const r=Ci(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=El(e,l);return Sp([0,i],[0,a])(c)}function Sp(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 Cp(e,t){return e>0&&e<t}var ZC=(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 ki(e,t){const n=qt(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 Qr(e,t){const n=qt(t);Kt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var kp=fp,QC=pp,ek=vp;const Tp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kp,{ref:r,className:oe("relative overflow-hidden",e),...n,children:[u.jsx(QC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ep,{}),u.jsx(ek,{})]}));Tp.displayName=kp.displayName;const Ep=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Nl,{ref:r,orientation:t,className:oe("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(yp,{className:"relative flex-1 rounded-full bg-border"})}));Ep.displayName=Nl.displayName;const Ip=25;function jl({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:h,isLoading:p,actions:g}=ps(),{loadThread:x}=ms(),{createThread:y,deleteThread:m,renameThread:b}=g,[S,T]=w.useState(Array.isArray(f)?f:[]),k=w.useRef(S.length>0),C=w.useRef(null),E=w.useRef(0),[R,_]=w.useState(null),[j,D]=w.useState(""),[z,W]=w.useState(!1);w.useEffect(()=>{const Z=Array.isArray(f)?f:[];if(Z.length>0){k.current=!0,T(Z);return}p||(k.current=!1,T(Z))},[f,p]),w.useEffect(()=>{if(!C.current)return;const Z=C.current.querySelector("[data-radix-scroll-area-viewport]");if(!Z)return;let de=null,we=null;return de=requestAnimationFrame(()=>{we=requestAnimationFrame(()=>{Z.scrollTop=E.current})}),()=>{de!==null&&cancelAnimationFrame(de),we!==null&&cancelAnimationFrame(we)}},[S]);const O=async Z=>{try{await x(Z),a==null||a(Z),l==null||l(Z)}catch(de){console.error("Failed to select thread:",de)}},B=async()=>{try{W(!0);const Z=await y();c==null||c(Z),a==null||a(Z)}catch(Z){console.error("Failed to create thread:",Z)}finally{W(!1)}},P=async(Z,de)=>{if(de.stopPropagation(),!!confirm("Delete this thread?")){if(C.current){const we=C.current.querySelector("[data-radix-scroll-area-viewport]");we&&(E.current=we.scrollTop)}try{await m(Z),d==null||d(Z)}catch(we){console.error("Failed to delete thread:",we)}}},V=(Z,de)=>{de.stopPropagation(),_(Z.threadId),D(Z.title||`Thread ${Z.threadId.slice(0,8)}`)},$=async Z=>{if(j.trim())try{await b(Z,j.trim()),_(null),D("")}catch(de){console.error("Failed to update title:",de)}},F=()=>{_(null),D("")},ee=(Z,de)=>{Z.key==="Enter"?$(de):Z.key==="Escape"&&F()},te=Z=>{if(!Z)return"";try{const de=new Date(Z),ne=new Date().getTime()-de.getTime(),L=Math.floor(ne/(1e3*60*60*24));return L===0?de.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):L===1?"Yesterday":L<7?`${L} days ago`:de.toLocaleDateString()}catch{return""}},ve=Z=>Z.title||`Thread ${Z.threadId.slice(0,8)}`,Ie=Z=>{const de=ve(Z);return de.length<=Ip?de:`${de.slice(0,Ip)}...`};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(ut,{onClick:B,disabled:z||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:z?"Creating...":"New Chat",children:u.jsx(he.MessageSquarePlus,{size:20})})}),u.jsx(Tp,{ref:C,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:p?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(he.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(he.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"})]}):S.slice().sort((Z,de)=>new Date(de.updatedAt||de.createdAt||"").getTime()-new Date(Z.updatedAt||Z.createdAt||"").getTime()).map(Z=>u.jsxs("div",{onClick:()=>O(Z.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Z.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:R===Z.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:de=>de.stopPropagation(),children:[u.jsx(wi,{value:j,onChange:de=>D(de.target.value),onKeyDown:de=>ee(de,Z.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:()=>$(Z.threadId),className:"h-6 w-6 p-0",children:u.jsx(he.Check,{size:12})}),u.jsx(ut,{variant:"ghost",size:"sm",onClick:F,className:"h-6 w-6 p-0",children:u.jsx(he.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Ie(Z)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(he.Calendar,{size:10}),u.jsx("span",{children:te(Z.updatedAt||Z.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&R!==Z.threadId&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:de=>V(Z,de),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(he.Edit3,{size:12})}),n&&u.jsx(ut,{variant:"ghost",size:"sm",onClick:de=>P(Z.threadId,de),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(he.Trash2,{size:12})})]})]}),i===Z.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Z.threadId))})})]})}function eo(e){if(!(typeof globalThis>"u"))return globalThis[e]}function tk(e){if(typeof e!="string")return;const t=e.trim();if(t)return qn(t)}function Np(){const e=[eo("__API_BASE_URL__"),eo("__CHAT_API_BASE_URL__"),eo("__CHAT_API_URL__")];for(const t of e){const n=tk(t);if(n)return n}}function Ap(){const e=[eo("__API_AUTH_TOKEN__"),eo("__CHAT_API_KEY__"),eo("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function _p(...e){for(const t of e)if(typeof t=="string"&&t.trim())return qn(t);return qn()}function jp(){const e={},t=Np(),n=Ap();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Rp(){const e=jp(),t=er.getAuthToken(),n=Np();return{apiBaseUrl:_p(e.baseUrl,er.baseUrl,n),apiKey:t||e.apiKey||Ap()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Pp="chat-settings";function nk(){try{const e=localStorage.getItem(Pp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function rk(e){try{const t={...e,apiBaseUrl:qn(e.apiBaseUrl)};localStorage.setItem(Pp,JSON.stringify(t)),t.apiKey&&er.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ok(){const e=Rp(),t=nk(),n=er.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:_p(er.baseUrl,r,e.apiBaseUrl)}}function sk(e){er.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),rk(e)}var ik="Label",Op=v.forwardRef((e,t)=>u.jsx(Oe.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=ik;var Mp=Op;const ak=Go.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Cn=v.forwardRef(({className:e,...t},n)=>u.jsx(Mp,{ref:n,className:oe(ak(),e),...t}));Cn.displayName=Mp.displayName;function Dp(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 Ti="Switch",[lk,OT]=Yn(Ti),[ck,uk]=lk(Ti),Lp=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,[h,p]=v.useState(null),g=Je(t,S=>p(S)),x=v.useRef(!1),y=h?d||!!h.closest("form"):!0,[m,b]=Wr({prop:o,defaultProp:s??!1,onChange:c,caller:Ti});return u.jsxs(ck,{scope:n,checked:m,disabled:a,children:[u.jsx(Oe.button,{type:"button",role:"switch","aria-checked":m,"aria-required":i,"data-state":Bp(m),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:ge(e.onClick,S=>{b(T=>!T),y&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),y&&u.jsx(zp,{control:h,bubbles:!x.current,name:r,value:l,checked:m,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Lp.displayName=Ti;var Fp="SwitchThumb",$p=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=uk(Fp,n);return u.jsx(Oe.span,{"data-state":Bp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$p.displayName=Fp;var dk="SwitchBubbleInput",zp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Je(i,s),l=Dp(n),c=Yf(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const g=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(g)}},[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}})});zp.displayName=dk;function Bp(e){return e?"checked":"unchecked"}var Hp=Lp,fk=$p;const ur=v.forwardRef(({className:e,...t},n)=>u.jsx(Hp,{className:oe("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(fk,{className:oe("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")})}));ur.displayName=Hp.displayName;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"}),hk="VisuallyHidden",pk=v.forwardRef((e,t)=>u.jsx(Oe.span,{...e,ref:t,style:{...Up,...e.style}}));pk.displayName=hk;var mk=[" ","Enter","ArrowUp","ArrowDown"],gk=[" ","Enter"],Rr="Select",[Ei,Ii,xk]=tl(Rr),[to,MT]=Yn(Rr,[xk,hi]),Ni=hi(),[yk,dr]=to(Rr),[vk,wk]=to(Rr),Wp=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:h,required:p,form:g}=e,x=Ni(t),[y,m]=v.useState(null),[b,S]=v.useState(null),[T,k]=v.useState(!1),C=ni(c),[E,R]=Wr({prop:r,defaultProp:o??!1,onChange:s,caller:Rr}),[_,j]=Wr({prop:i,defaultProp:a,onChange:l,caller:Rr}),D=v.useRef(null),z=y?g||!!y.closest("form"):!0,[W,O]=v.useState(new Set),B=Array.from(W).map(P=>P.props.value).join(";");return u.jsx(sh,{...x,children:u.jsxs(yk,{required:p,scope:t,trigger:y,onTriggerChange:m,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:T,onValueNodeHasChildrenChange:k,contentId:Xn(),value:_,onValueChange:j,open:E,onOpenChange:R,dir:C,triggerPointerDownPosRef:D,disabled:h,children:[u.jsx(Ei.Provider,{scope:t,children:u.jsx(vk,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(P=>{O(V=>new Set(V).add(P))},[]),onNativeOptionRemove:v.useCallback(P=>{O(V=>{const $=new Set(V);return $.delete(P),$})},[]),children:n})}),z?u.jsxs(pm,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:P=>j(P.target.value),disabled:h,form:g,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(W)]},B):null]})})};Wp.displayName=Rr;var Vp="SelectTrigger",Kp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ni(n),i=dr(Vp,n),a=i.disabled||r,l=Je(t,i.onTriggerChange),c=Ii(n),d=v.useRef("touch"),[f,h,p]=gm(x=>{const y=c().filter(S=>!S.disabled),m=y.find(S=>S.value===i.value),b=xm(y,x,m);b!==void 0&&i.onValueChange(b.value)}),g=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return u.jsx(ih,{asChild:!0,...s,children:u.jsx(Oe.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":mm(i.value)?"":void 0,...o,ref:l,onClick:ge(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&g(x)}),onPointerDown:ge(o.onPointerDown,x=>{d.current=x.pointerType;const y=x.target;y.hasPointerCapture(x.pointerId)&&y.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(g(x),x.preventDefault())}),onKeyDown:ge(o.onKeyDown,x=>{const y=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(y&&x.key===" ")&&mk.includes(x.key)&&(g(),x.preventDefault())})})})});Kp.displayName=Vp;var qp="SelectValue",Gp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=dr(qp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Je(t,l.onValueNodeChange);return Kt(()=>{c(d)},[c,d]),u.jsx(Oe.span,{...a,ref:f,style:{pointerEvents:"none"},children:mm(l.value)?u.jsx(u.Fragment,{children:i}):s})});Gp.displayName=qp;var bk="SelectIcon",Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Oe.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Yp.displayName=bk;var Sk="SelectPortal",Xp=e=>u.jsx(Ms,{asChild:!0,...e});Xp.displayName=Sk;var Pr="SelectContent",Jp=v.forwardRef((e,t)=>{const n=dr(Pr,e.__scopeSelect),[r,o]=v.useState();if(Kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Yo.createPortal(u.jsx(Zp,{scope:e.__scopeSelect,children:u.jsx(Ei.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Qp,{...e,ref:t})});Jp.displayName=Pr;var Pn=10,[Zp,fr]=to(Pr),Ck="SelectContentImpl",kk=xr.createSlot("SelectContent.RemoveScroll"),Qp=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:h,collisionPadding:p,sticky:g,hideWhenDetached:x,avoidCollisions:y,...m}=e,b=dr(Pr,n),[S,T]=v.useState(null),[k,C]=v.useState(null),E=Je(t,ne=>T(ne)),[R,_]=v.useState(null),[j,D]=v.useState(null),z=Ii(n),[W,O]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return qa(S)},[S]),Ba();const P=v.useCallback(ne=>{const[L,...J]=z().map(le=>le.ref.current),[se]=J.slice(-1),ue=document.activeElement;for(const le of ne)if(le===ue||(le==null||le.scrollIntoView({block:"nearest"}),le===L&&k&&(k.scrollTop=0),le===se&&k&&(k.scrollTop=k.scrollHeight),le==null||le.focus(),document.activeElement!==ue))return},[z,k]),V=v.useCallback(()=>P([R,S]),[P,R,S]);v.useEffect(()=>{W&&V()},[W,V]);const{onOpenChange:$,triggerPointerDownPosRef:F}=b;v.useEffect(()=>{if(S){let ne={x:0,y:0};const L=se=>{var ue,le;ne={x:Math.abs(Math.round(se.pageX)-(((ue=F.current)==null?void 0:ue.x)??0)),y:Math.abs(Math.round(se.pageY)-(((le=F.current)==null?void 0:le.y)??0))}},J=se=>{ne.x<=10&&ne.y<=10?se.preventDefault():S.contains(se.target)||$(!1),document.removeEventListener("pointermove",L),F.current=null};return F.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",J,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",J,{capture:!0})}}},[S,$,F]),v.useEffect(()=>{const ne=()=>$(!1);return window.addEventListener("blur",ne),window.addEventListener("resize",ne),()=>{window.removeEventListener("blur",ne),window.removeEventListener("resize",ne)}},[$]);const[ee,te]=gm(ne=>{const L=z().filter(ue=>!ue.disabled),J=L.find(ue=>ue.ref.current===document.activeElement),se=xm(L,ne,J);se&&setTimeout(()=>se.ref.current.focus())}),ve=v.useCallback((ne,L,J)=>{const se=!B.current&&!J;(b.value!==void 0&&b.value===L||se)&&(_(ne),se&&(B.current=!0))},[b.value]),Ie=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Z=v.useCallback((ne,L,J)=>{const se=!B.current&&!J;(b.value!==void 0&&b.value===L||se)&&D(ne)},[b.value]),de=r==="popper"?Rl:em,we=de===Rl?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:g,hideWhenDetached:x,avoidCollisions:y}:{};return u.jsx(Zp,{scope:n,content:S,viewport:k,onViewportChange:C,itemRefCallback:ve,selectedItem:R,onItemLeave:Ie,itemTextRefCallback:Z,focusSelectedItem:V,selectedItemText:j,position:r,isPositioned:W,searchRef:ee,children:u.jsx(Hs,{as:kk,allowPinchZoom:!0,children:u.jsx(Os,{asChild:!0,trapped:b.open,onMountAutoFocus:ne=>{ne.preventDefault()},onUnmountAutoFocus:ge(o,ne=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),ne.preventDefault()}),children:u.jsx(Ps,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:ne=>ne.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(de,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:ne=>ne.preventDefault(),...m,...we,onPlaced:()=>O(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...m.style},onKeyDown:ge(m.onKeyDown,ne=>{const L=ne.ctrlKey||ne.altKey||ne.metaKey;if(ne.key==="Tab"&&ne.preventDefault(),!L&&ne.key.length===1&&te(ne.key),["ArrowUp","ArrowDown","Home","End"].includes(ne.key)){let se=z().filter(ue=>!ue.disabled).map(ue=>ue.ref.current);if(["ArrowUp","End"].includes(ne.key)&&(se=se.slice().reverse()),["ArrowUp","ArrowDown"].includes(ne.key)){const ue=ne.target,le=se.indexOf(ue);se=se.slice(le+1)}setTimeout(()=>P(se)),ne.preventDefault()}})})})})})})});Qp.displayName=Ck;var Tk="SelectItemAlignedPosition",em=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=dr(Pr,n),i=fr(Pr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Je(t,E=>d(E)),h=Ii(n),p=v.useRef(!1),g=v.useRef(!0),{viewport:x,selectedItem:y,selectedItemText:m,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&y&&m){const E=s.trigger.getBoundingClientRect(),R=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),j=m.getBoundingClientRect();if(s.dir!=="rtl"){const ue=j.left-R.left,le=_.left-ue,Me=E.left-le,U=E.width+Me,ye=Math.max(U,R.width),_e=window.innerWidth-Pn,Pe=El(le,[Pn,Math.max(Pn,_e-ye)]);a.style.minWidth=U+"px",a.style.left=Pe+"px"}else{const ue=R.right-j.right,le=window.innerWidth-_.right-ue,Me=window.innerWidth-E.right-le,U=E.width+Me,ye=Math.max(U,R.width),_e=window.innerWidth-Pn,Pe=El(le,[Pn,Math.max(Pn,_e-ye)]);a.style.minWidth=U+"px",a.style.right=Pe+"px"}const D=h(),z=window.innerHeight-Pn*2,W=x.scrollHeight,O=window.getComputedStyle(c),B=parseInt(O.borderTopWidth,10),P=parseInt(O.paddingTop,10),V=parseInt(O.borderBottomWidth,10),$=parseInt(O.paddingBottom,10),F=B+P+W+$+V,ee=Math.min(y.offsetHeight*5,F),te=window.getComputedStyle(x),ve=parseInt(te.paddingTop,10),Ie=parseInt(te.paddingBottom,10),Z=E.top+E.height/2-Pn,de=z-Z,we=y.offsetHeight/2,ne=y.offsetTop+we,L=B+P+ne,J=F-L;if(L<=Z){const ue=D.length>0&&y===D[D.length-1].ref.current;a.style.bottom="0px";const le=c.clientHeight-x.offsetTop-x.offsetHeight,Me=Math.max(de,we+(ue?Ie:0)+le+V),U=L+Me;a.style.height=U+"px"}else{const ue=D.length>0&&y===D[0].ref.current;a.style.top="0px";const Me=Math.max(Z,B+x.offsetTop+(ue?ve:0)+we)+J;a.style.height=Me+"px",x.scrollTop=L-Z+x.offsetTop}a.style.margin=`${Pn}px 0`,a.style.minHeight=ee+"px",a.style.maxHeight=z+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,x,y,m,s.dir,r]);Kt(()=>S(),[S]);const[T,k]=v.useState();Kt(()=>{c&&k(window.getComputedStyle(c).zIndex)},[c]);const C=v.useCallback(E=>{E&&g.current===!0&&(S(),b==null||b(),g.current=!1)},[S,b]);return u.jsx(Ik,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:u.jsx(Oe.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});em.displayName=Tk;var Ek="SelectPopperPosition",Rl=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Pn,...s}=e,i=Ni(n);return u.jsx(ah,{...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)"}})});Rl.displayName=Ek;var[Ik,Pl]=to(Pr,{}),Ol="SelectViewport",tm=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=fr(Ol,n),i=Pl(Ol,n),a=Je(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(Ei.Slot,{scope:n,children:u.jsx(Oe.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ge(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const g=window.innerHeight-Pn*2,x=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),m=Math.max(x,y);if(m<g){const b=m+p,S=Math.min(g,b),T=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=T>0?T:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});tm.displayName=Ol;var nm="SelectGroup",[Nk,Ak]=to(nm),_k=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Xn();return u.jsx(Nk,{scope:n,id:o,children:u.jsx(Oe.div,{role:"group","aria-labelledby":o,...r,ref:t})})});_k.displayName=nm;var rm="SelectLabel",om=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ak(rm,n);return u.jsx(Oe.div,{id:o.id,...r,ref:t})});om.displayName=rm;var Ai="SelectItem",[jk,sm]=to(Ai),im=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=dr(Ai,n),l=fr(Ai,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),g=Je(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=Xn(),y=v.useRef("touch"),m=()=>{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(jk,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Ei.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Oe.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:g,onFocus:ge(i.onFocus,()=>p(!0)),onBlur:ge(i.onBlur,()=>p(!1)),onClick:ge(i.onClick,()=>{y.current!=="mouse"&&m()}),onPointerUp:ge(i.onPointerUp,()=>{y.current==="mouse"&&m()}),onPointerDown:ge(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:ge(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:ge(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ge(i.onKeyDown,b=>{var T;((T=l.searchRef)==null?void 0:T.current)!==""&&b.key===" "||(gk.includes(b.key)&&m(),b.key===" "&&b.preventDefault())})})})})});im.displayName=Ai;var Ho="SelectItemText",am=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=dr(Ho,n),a=fr(Ho,n),l=sm(Ho,n),c=wk(Ho,n),[d,f]=v.useState(null),h=Je(t,m=>f(m),l.onItemTextChange,m=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,m,l.value,l.disabled)}),p=d==null?void 0:d.textContent,g=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:y}=c;return Kt(()=>(x(g),()=>y(g)),[x,y,g]),u.jsxs(u.Fragment,{children:[u.jsx(Oe.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Yo.createPortal(s.children,i.valueNode):null]})});am.displayName=Ho;var lm="SelectItemIndicator",cm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return sm(lm,n).isSelected?u.jsx(Oe.span,{"aria-hidden":!0,...r,ref:t}):null});cm.displayName=lm;var Ml="SelectScrollUpButton",um=v.forwardRef((e,t)=>{const n=fr(Ml,e.__scopeSelect),r=Pl(Ml,e.__scopeSelect),[o,s]=v.useState(!1),i=Je(t,r.onScrollButtonChange);return Kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(fm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});um.displayName=Ml;var Dl="SelectScrollDownButton",dm=v.forwardRef((e,t)=>{const n=fr(Dl,e.__scopeSelect),r=Pl(Dl,e.__scopeSelect),[o,s]=v.useState(!1),i=Je(t,r.onScrollButtonChange);return Kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(fm,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});dm.displayName=Dl;var fm=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=fr("SelectScrollButton",n),i=v.useRef(null),a=Ii(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Kt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Oe.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ge(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ge(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ge(o.onPointerLeave,()=>{l()})})}),Rk="SelectSeparator",hm=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Oe.div,{"aria-hidden":!0,...r,ref:t})});hm.displayName=Rk;var Ll="SelectArrow",Pk=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ni(n),s=dr(Ll,n),i=fr(Ll,n);return s.open&&i.position==="popper"?u.jsx(lh,{...o,...r,ref:t}):null});Pk.displayName=Ll;var Ok="SelectBubbleInput",pm=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Je(r,o),i=Dp(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(Oe.select,{...n,style:{...Up,...n.style},ref:s,defaultValue:t})});pm.displayName=Ok;function mm(e){return e===""||e===void 0}function gm(e){const t=qt(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 xm(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=Mk(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 Mk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Dk=Wp,ym=Kp,Lk=Gp,Fk=Yp,$k=Xp,vm=Jp,zk=tm,wm=om,bm=im,Bk=am,Hk=cm,Sm=um,Cm=dm,km=hm;const Tm=Dk,Em=Lk,Fl=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ym,{ref:r,className:oe("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(Fk,{asChild:!0,children:u.jsx(he.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Fl.displayName=ym.displayName;const Im=v.forwardRef(({className:e,...t},n)=>u.jsx(Sm,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(he.ChevronUp,{className:"h-4 w-4"})}));Im.displayName=Sm.displayName;const Nm=v.forwardRef(({className:e,...t},n)=>u.jsx(Cm,{ref:n,className:oe("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(he.ChevronDown,{className:"h-4 w-4"})}));Nm.displayName=Cm.displayName;const $l=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx($k,{children:u.jsxs(vm,{ref:o,className:oe("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(Im,{}),u.jsx(zk,{className:oe("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Nm,{})]})}));$l.displayName=vm.displayName;const Uk=v.forwardRef(({className:e,...t},n)=>u.jsx(wm,{ref:n,className:oe("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Uk.displayName=wm.displayName;const Or=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bm,{ref:r,className:oe("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(Hk,{children:u.jsx(he.Check,{className:"h-4 w-4"})})}),u.jsx(Bk,{children:t})]}));Or.displayName=bm.displayName;const Wk=v.forwardRef(({className:e,...t},n)=>u.jsx(km,{ref:n,className:oe("-mx-1 my-1 h-px bg-muted",e),...t}));Wk.displayName=km.displayName;var Vk="Separator",Am="horizontal",Kk=["horizontal","vertical"],_m=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Am,...o}=e,s=qk(r)?r:Am,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Oe.div,{"data-orientation":s,...a,...o,ref:t})});_m.displayName=Vk;function qk(e){return Kk.includes(e)}var jm=_m;const Rm=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(jm,{ref:o,decorative:n,orientation:t,className:oe("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Rm.displayName=jm.displayName;const Gk=tf,Yk=hb,Xk=nf,Pm=v.forwardRef(({className:e,...t},n)=>u.jsx(qs,{className:oe("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}));Pm.displayName=qs.displayName;const Jk=Go.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"}}),Om=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(Xk,{children:[u.jsx(Pm,{}),u.jsxs(Gs,{ref:o,className:oe(Jk({side:e}),t),...r,children:[n,u.jsxs(rf,{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(he.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Om.displayName=Gs.displayName;const Mm=({className:e,...t})=>u.jsx("div",{className:oe("flex flex-col space-y-2 text-center sm:text-left",e),...t});Mm.displayName="SheetHeader";const Dm=v.forwardRef(({className:e,...t},n)=>u.jsx(Ir,{ref:n,className:oe("text-lg font-semibold text-foreground",e),...t}));Dm.displayName=Ir.displayName;const Lm=v.forwardRef(({className:e,...t},n)=>u.jsx(Ys,{ref:n,className:oe("text-sm text-muted-foreground",e),...t}));Lm.displayName=Ys.displayName;const Zk={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 Qk({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}=Oa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(Zk),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},g=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const m=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${m.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(Gk,{open:r,onOpenChange:o,children:[u.jsx(Yk,{asChild:!0,children:u.jsxs(ut,{variant:"outline",size:"sm",className:n,children:[u.jsx(he.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(ad,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Om,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Mm,{children:[u.jsx(Dm,{children:"Chat Settings"}),u.jsx(Lm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(To,{children:[u.jsx(Eo,{className:"pb-3",children:u.jsxs(Io,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(No,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Cn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(wi,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(m=>({...m,api:{...m.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(ut,{variant:"outline",onClick:x,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Cn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(ur,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(m=>({...m,api:{...m.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(Cn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(wi,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(m=>({...m,api:{...m.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(ut,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(he.EyeOff,{className:"h-4 w-4"}):u.jsx(he.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(To,{children:[u.jsx(Eo,{className:"pb-3",children:u.jsxs(Io,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(No,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Cn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Tm,{value:a.ui.layout,onValueChange:y=>l(m=>({...m,ui:{...m.ui,layout:y}})),children:[u.jsx(Fl,{children:u.jsx(Em,{})}),u.jsxs($l,{children:[u.jsx(Or,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(Or,{value:"fullscreen",children:"Fullscreen"}),u.jsx(Or,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Cn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Tm,{value:a.ui.theme,onValueChange:y=>l(m=>({...m,ui:{...m.ui,theme:y}})),children:[u.jsx(Fl,{children:u.jsx(Em,{})}),u.jsxs($l,{children:[u.jsx(Or,{value:"light",children:"Light"}),u.jsx(Or,{value:"dark",children:"Dark"}),u.jsx(Or,{value:"system",children:"System"})]})]})]}),u.jsx(Rm,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Cn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(ur,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(m=>({...m,ui:{...m.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Cn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(ur,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(m=>({...m,ui:{...m.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Cn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(ur,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(m=>({...m,ui:{...m.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(To,{children:[u.jsx(Eo,{className:"pb-3",children:u.jsxs(Io,{className:"text-lg flex items-center gap-2",children:[u.jsx(he.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(No,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Cn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(ur,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(m=>({...m,behavior:{...m.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Cn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(ur,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(m=>({...m,behavior:{...m.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Cn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(ur,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(m=>({...m,behavior:{...m.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(ut,{variant:"outline",onClick:p,children:[u.jsx(he.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(ut,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(ut,{onClick:h,disabled:!c,children:[u.jsx(he.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function eT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(gs,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(vi,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(gs,{...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(jl,{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(vi,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(gs,{...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(jl,{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(vi,{onError:s.onError,enableFileUpload:!0})})]})})}je.ChatApi=Dc,je.ChatInterface=vi,je.ChatProviders=gs,je.ChatSettings=Qk,je.MarkdownContent=Ro,je.MessageComponent=Qa,je.MessageList=el,je.ThreadManager=jl,je.applySettings=sk,je.chatApiClient=er,je.default=eT,je.del=Mc,je.get=En,je.getChatToken=Rc,je.getCurrentSettings=ok,je.getDefaultApiConfig=jp,je.getDefaultChatSettings=Rp,je.onChatTokenChanged=Pc,je.post=Ki,je.put=Oc,je.setChatToken=Vi,je.useApi=qi,je.useChatStream=Jc,je.useMessagesReducer=Uc,je.useStream=au,je.useThreadState=ms,je.useThreads=ps,Object.defineProperties(je,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});